3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-27 02:45:51 +00:00

user propagator over the API

This commit is contained in:
Nikolaj Bjorner 2020-08-18 21:52:52 -07:00
parent c50e869e5a
commit 4857d60c99
13 changed files with 141 additions and 63 deletions

View file

@ -10505,17 +10505,44 @@ def TransitiveClosure(f):
return FuncDeclRef(Z3_mk_transitive_closure(f.ctx_ref(), f.ast), f.ctx)
"""
_user_propagate_bases = {}
def user_prop_push(ctx):
_user_propagate_bases[ctx].push();
def user_prop_pop(ctx, num_scopes):
_user_propagate_bases[ctx].pop(num_scopes)
def user_prop_fixed(ctx, id, value):
prop = _user_propagate_bases[ctx]
prop.fixed(id, _to_expr_ref(ctypes.c_void_p(value), prop.ctx))
def user_prop_fresh(ctx):
prop = _user_propagate_bases[ctx]
new_prop = prop.copy()
return ctypes.c_void_p(new_prop.id)
_user_prop_push = push_eh_type(user_prop_push)
_user_prop_pop = pop_eh_type(user_prop_pop)
_user_prop_fixed = fixed_eh_type(user_prop_fixed)
_user_prop_fresh = fresh_eh_type(user_prop_fresh)
class UserPropagateBase:
def __init__(self, s):
self.id = len(_user_propagate_bases) + 3
self.solver = s
self.ctx = s.ctx
Z3_user_propagate_init(self,
ctypes.CFUNCTYPE(None, ctypes.c_void_p)(_user_prop_push),
ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_uint())(_user_prop_pop),
ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_uint(), ctypes.c_void_p)(_user_prop_fixed))
_user_propagate_bases[self.id] = self
Z3_solver_propagate_init(s.ctx.ref(),
s.solver,
ctypes.c_void_p(self.id),
_user_prop_push,
_user_prop_pop,
_user_prop_fixed,
_user_prop_fresh)
def push(self):
raise Z3Exception("push has not been overwritten")
@ -10526,23 +10553,8 @@ class UserPropagateBase:
raise Z3Exception("fixed has not been overwritten")
def add(self, e):
return Z3_user_propagate_register(self.ctx.ref(), s.solver, e.ast)
return Z3_solver_propagate_register(self.ctx.ref(), self.solver.solver, e.ast)
def propagate(self, ids, e):
Z3_user_propagate_consequence(self.ctx.ref(), s.solver, ids, e.ast)
def _user_prop_push(ctx):
user_prop = ctx # need to access as python object.
user_prop.push()
def _user_prop_pop(ctx, num_scopes):
user_prop = ctx # need to access as python object
user_prop.pop(num_scopes)
def _user_prop_fixed(ctx, id, value):
user_prop = ctx # need to access as python object
user_prop.fixed(id, _to_expr_ref(value, user_prop.ctx))
"""
Z3_solver_propagate_consequence(self.ctx.ref(), self.solver.solver, ids, e.ast)

View file

@ -121,3 +121,6 @@ class FuncEntryObj(ctypes.c_void_p):
class RCFNumObj(ctypes.c_void_p):
def __init__(self, e): self._as_parameter_ = e
def from_param(obj): return obj