mirror of
https://github.com/Z3Prover/z3
synced 2025-06-16 19:06:17 +00:00
use IEnumerator and format
This commit is contained in:
parent
556f0d7b5f
commit
798a4ee86e
1 changed files with 205 additions and 179 deletions
|
@ -76,70 +76,83 @@ namespace Microsoft.Z3
|
|||
CreatedEh created_eh;
|
||||
DecideEh decide_eh;
|
||||
|
||||
void Callback(Action fn, Z3_solver_callback cb) {
|
||||
void Callback(Action fn, Z3_solver_callback cb)
|
||||
{
|
||||
this.callback = cb;
|
||||
try {
|
||||
try
|
||||
{
|
||||
fn();
|
||||
}
|
||||
catch {
|
||||
catch
|
||||
{
|
||||
// TBD: add debug log or exception handler
|
||||
}
|
||||
finally {
|
||||
finally
|
||||
{
|
||||
this.callback = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void _push(voidp ctx, Z3_solver_callback cb) {
|
||||
static void _push(voidp ctx, Z3_solver_callback cb)
|
||||
{
|
||||
var prop = propagators[ctx.ToInt32()];
|
||||
prop.Callback(() => prop.Push(), cb);
|
||||
}
|
||||
|
||||
static void _pop(voidp ctx, Z3_solver_callback cb, uint num_scopes) {
|
||||
static void _pop(voidp ctx, Z3_solver_callback cb, uint num_scopes)
|
||||
{
|
||||
var prop = propagators[ctx.ToInt32()];
|
||||
prop.Callback(() => prop.Pop(num_scopes), cb);
|
||||
}
|
||||
|
||||
static voidp _fresh(voidp _ctx, Z3_context new_context) {
|
||||
static voidp _fresh(voidp _ctx, Z3_context new_context)
|
||||
{
|
||||
var prop = propagators[_ctx.ToInt32()];
|
||||
var ctx = new Context(new_context);
|
||||
var prop1 = prop.Fresh(prop.ctx);
|
||||
return new IntPtr(prop1.id);
|
||||
}
|
||||
|
||||
static void _fixed(voidp ctx, Z3_solver_callback cb, Z3_ast _term, Z3_ast _value) {
|
||||
static void _fixed(voidp ctx, Z3_solver_callback cb, Z3_ast _term, Z3_ast _value)
|
||||
{
|
||||
var prop = propagators[ctx.ToInt32()];
|
||||
using var term = Expr.Create(prop.ctx, _term);
|
||||
using var value = Expr.Create(prop.ctx, _value);
|
||||
prop.Callback(() => prop.fixed_eh(term, value), cb);
|
||||
}
|
||||
|
||||
static void _final(voidp ctx, Z3_solver_callback cb) {
|
||||
static void _final(voidp ctx, Z3_solver_callback cb)
|
||||
{
|
||||
var prop = propagators[ctx.ToInt32()];
|
||||
prop.Callback(() => prop.final_eh(), cb);
|
||||
}
|
||||
|
||||
static void _eq(voidp ctx, Z3_solver_callback cb, Z3_ast a, Z3_ast b) {
|
||||
static void _eq(voidp ctx, Z3_solver_callback cb, Z3_ast a, Z3_ast b)
|
||||
{
|
||||
var prop = propagators[ctx.ToInt32()];
|
||||
using var s = Expr.Create(prop.ctx, a);
|
||||
using var t = Expr.Create(prop.ctx, b);
|
||||
prop.Callback(() => prop.eq_eh(s, t), cb);
|
||||
}
|
||||
|
||||
static void _diseq(voidp ctx, Z3_solver_callback cb, Z3_ast a, Z3_ast b) {
|
||||
static void _diseq(voidp ctx, Z3_solver_callback cb, Z3_ast a, Z3_ast b)
|
||||
{
|
||||
var prop = propagators[ctx.ToInt32()];
|
||||
using var s = Expr.Create(prop.ctx, a);
|
||||
using var t = Expr.Create(prop.ctx, b);
|
||||
prop.Callback(() => prop.diseq_eh(s, t), cb);
|
||||
}
|
||||
|
||||
static void _created(voidp ctx, Z3_solver_callback cb, Z3_ast a) {
|
||||
static void _created(voidp ctx, Z3_solver_callback cb, Z3_ast a)
|
||||
{
|
||||
var prop = propagators[ctx.ToInt32()];
|
||||
using var t = Expr.Create(prop.ctx, a);
|
||||
prop.Callback(() => prop.created_eh(t), cb);
|
||||
}
|
||||
|
||||
static void _decide(voidp ctx, Z3_solver_callback cb, ref Z3_ast a, ref uint idx, ref int phase) {
|
||||
static void _decide(voidp ctx, Z3_solver_callback cb, ref Z3_ast a, ref uint idx, ref int phase)
|
||||
{
|
||||
var prop = propagators[ctx.ToInt32()];
|
||||
var t = Expr.Create(prop.ctx, a);
|
||||
var u = t;
|
||||
|
@ -201,15 +214,25 @@ namespace Microsoft.Z3
|
|||
/// <summary>
|
||||
/// Declare combination of assigned expressions a conflict
|
||||
/// </summary>
|
||||
public void Conflict(params Expr[] terms) {
|
||||
public void Conflict(params Expr[] terms)
|
||||
{
|
||||
Propagate(terms, ctx.MkFalse());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Declare combination of assigned expressions a conflict
|
||||
/// </summary>
|
||||
public void Conflict(IEnumerable<Expr> terms)
|
||||
{
|
||||
Propagate(terms, ctx.MkFalse());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Propagate consequence
|
||||
/// </summary>
|
||||
public void Propagate(Expr[] terms, Expr conseq) {
|
||||
var nTerms = Z3Object.ArrayToNative(terms);
|
||||
public void Propagate(IEnumerable<Expr> terms, Expr conseq)
|
||||
{
|
||||
var nTerms = Z3Object.ArrayToNative(terms.ToArray());
|
||||
Native.Z3_solver_propagate_consequence(ctx.nCtx, this.callback, (uint)nTerms.Length, nTerms, 0u, null, null, conseq.NativeObject);
|
||||
}
|
||||
|
||||
|
@ -304,11 +327,14 @@ namespace Microsoft.Z3
|
|||
/// <summary>
|
||||
/// Track assignments to a term
|
||||
/// </summary>
|
||||
public void Register(Expr term) {
|
||||
if (this.callback != IntPtr.Zero) {
|
||||
public void Register(Expr term)
|
||||
{
|
||||
if (this.callback != IntPtr.Zero)
|
||||
{
|
||||
Native.Z3_solver_propagate_register_cb(ctx.nCtx, callback, term.NativeObject);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
Native.Z3_solver_propagate_register(ctx.nCtx, solver.NativeObject, term.NativeObject);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue