22using System.Diagnostics;
24using System.Collections.Generic;
25using System.Runtime.InteropServices;
34 using Z3_ast = System.IntPtr;
66 public delegate
void DecideEh(ref
Expr term, ref uint idx, ref
int phase);
74 int callbackNesting = 0;
82 Native.Z3_push_eh push_eh;
83 Native.Z3_pop_eh pop_eh;
84 Native.Z3_fresh_eh fresh_eh;
86 Native.Z3_fixed_eh fixed_wrapper;
87 Native.Z3_final_eh final_wrapper;
88 Native.Z3_eq_eh eq_wrapper;
89 Native.Z3_eq_eh diseq_wrapper;
90 Native.Z3_decide_eh decide_wrapper;
91 Native.Z3_created_eh created_wrapper;
95 this.callbackNesting++;
108 if (callbackNesting == 0)
109 this.callback = IntPtr.Zero;
117 prop.Callback(() => prop.Push(), cb);
123 prop.Callback(() => prop.Pop(num_scopes), cb);
129 var ctx =
new Context(new_context);
130 var prop1 = prop.Fresh(prop.ctx);
131 return GCHandle.ToIntPtr(prop1.gch);
137 using var term = Expr.Create(prop.ctx, _term);
138 using var value = Expr.Create(prop.ctx, _value);
139 prop.Callback(() => prop.fixed_eh(term, value), cb);
145 prop.Callback(() => prop.final_eh(), cb);
151 using var s = Expr.Create(prop.ctx, a);
152 using var t = Expr.Create(prop.ctx, b);
153 prop.Callback(() => prop.eq_eh(s, t), cb);
159 using var s = Expr.Create(prop.ctx, a);
160 using var t = Expr.Create(prop.ctx, b);
161 prop.Callback(() => prop.diseq_eh(s, t), cb);
167 using var t = Expr.Create(prop.ctx, a);
168 prop.Callback(() => prop.created_eh(t), cb);
174 var t = Expr.Create(prop.ctx, a);
177 prop.decide_eh(ref t, ref idx, ref phase);
178 prop.callback = IntPtr.Zero;
188 gch = GCHandle.Alloc(
this);
194 Native.Z3_solver_propagate_init(ctx.nCtx, solver.NativeObject, GCHandle.ToIntPtr(gch), push_eh, pop_eh, fresh_eh);
202 gch = GCHandle.Alloc(
this);
220 public virtual void Push() {
throw new Z3Exception(
"Push method should be overwritten"); }
225 public virtual void Pop(uint n) {
throw new Z3Exception(
"Pop method should be overwritten"); }
253 var nTerms =
Z3Object.ArrayToNative(terms.ToArray());
254 Native.Z3_solver_propagate_consequence(ctx.nCtx,
this.callback, (uint)nTerms.Length, nTerms, 0u,
null,
null, conseq.NativeObject);
265 this.fixed_wrapper = _fixed;
266 this.fixed_eh = value;
268 Native.Z3_solver_propagate_fixed(ctx.nCtx, solver.NativeObject, fixed_wrapper);
279 this.final_wrapper = _final;
280 this.final_eh = value;
282 Native.Z3_solver_propagate_final(ctx.nCtx, solver.NativeObject, final_wrapper);
293 this.eq_wrapper = _eq;
296 Native.Z3_solver_propagate_eq(ctx.nCtx, solver.NativeObject, eq_wrapper);
307 this.diseq_wrapper = _diseq;
308 this.diseq_eh = value;
310 Native.Z3_solver_propagate_diseq(ctx.nCtx, solver.NativeObject, diseq_wrapper);
321 this.created_wrapper = _created;
322 this.created_eh = value;
324 Native.Z3_solver_propagate_created(ctx.nCtx, solver.NativeObject, created_wrapper);
335 this.decide_wrapper = _decide;
336 this.decide_eh = value;
338 Native.Z3_solver_propagate_decide(ctx.nCtx, solver.NativeObject, decide_wrapper);
348 Native.Z3_solver_next_split(ctx.nCtx,
this.callback, e.NativeObject, idx, phase);
356 if (this.callback != IntPtr.Zero)
358 Native.Z3_solver_propagate_register_cb(ctx.nCtx, callback, term.NativeObject);
362 Native.Z3_solver_propagate_register(ctx.nCtx, solver.NativeObject, term.NativeObject);
The main interaction with Z3 happens via the Context.
Propagator context for .Net
EqEh Diseq
Set disequality event callback
void Conflict(IEnumerable< Expr > terms)
Declare combination of assigned expressions a conflict
delegate void CreatedEh(Expr term)
Delegate type for when a new term using a registered function symbol is created internally
void Propagate(IEnumerable< Expr > terms, Expr conseq)
Propagate consequence
delegate void FixedEh(Expr term, Expr value)
Delegate type for fixed callback Note that the life-time of the term and value only applies within th...
UserPropagator(Solver s)
Propagator constructor from a solver class.
virtual UserPropagator Fresh(Context ctx)
Virtual method for fresh. It can be overwritten by inherited class.
void Register(Expr term)
Track assignments to a term
virtual void Pop(uint n)
Virtual method for pop. It must be overwritten by inherited class.
delegate void EqEh(Expr term, Expr value)
Delegate type for equality or disequality callback
void Conflict(params Expr[] terms)
Declare combination of assigned expressions a conflict
void NextSplit(Expr e, uint idx, int phase)
Set the next decision
virtual void Push()
Virtual method for push. It must be overwritten by inherited class.
EqEh Eq
Set equality event callback
CreatedEh Created
Set created callback
FixedEh Fixed
Set fixed callback
UserPropagator(Context _ctx)
Propagator constructor from a context. It is used from inside of Fresh.
DecideEh Decide
Set decision callback
Action Final
Set final callback
delegate void DecideEh(ref Expr term, ref uint idx, ref int phase)
Delegate type for callback into solver's branching A bit-vector or Boolean used for branchingIf the t...
The exception base class for error reporting from Z3
Internal base class for interfacing with native Z3 objects. Should not be used externally.
Context Context
Access Context object
System.IntPtr Z3_solver_callback