diff --git a/src/api/dotnet/Deprecated.cs b/src/api/dotnet/Deprecated.cs new file mode 100644 index 000000000..7282796ec --- /dev/null +++ b/src/api/dotnet/Deprecated.cs @@ -0,0 +1,105 @@ +/*++ +Copyright (c) 2012 Microsoft Corporation + +Module Name: + + Deprecated.cs + +Abstract: + + Expose deprecated features for use from the managed API + those who use them for experiments. + +Author: + + Christoph Wintersteiger (cwinter) 2012-03-15 + +Notes: + +--*/ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Diagnostics.Contracts; + +namespace Microsoft.Z3 +{ + /// + /// The main interaction with Z3 happens via the Context. + /// + [ContractVerification(true)] + public class Deprecated + { + + /// + /// Creates a backtracking point. + /// + /// + public static void Push(Context ctx) { + Native.Z3_push(ctx.nCtx); + } + + /// + /// Backtracks backtracking points. + /// + /// Note that an exception is thrown if is not smaller than NumScopes + /// + public static void Pop(Context ctx, uint n = 1) { + Native.Z3_pop(ctx.nCtx, n); + } + + /// + /// Assert a constraint (or multiple) into the solver. + /// + public static void Assert(Context ctx, params BoolExpr[] constraints) + { + Contract.Requires(constraints != null); + Contract.Requires(Contract.ForAll(constraints, c => c != null)); + + ctx.CheckContextMatch(constraints); + foreach (BoolExpr a in constraints) + { + Native.Z3_assert_cnstr(ctx.nCtx, a.NativeObject); + } + } + /// + /// Checks whether the assertions in the context are consistent or not. + /// + public static Status Check(Context ctx, List core, params Expr[] assumptions) + { + Z3_lbool r; + core = null; + if (assumptions == null || assumptions.Length == 0) + r = (Z3_lbool)Native.Z3_check(ctx.nCtx); + else { + IntPtr model = IntPtr.Zero, proof = IntPtr.Zero; + uint core_size = 0; + IntPtr[] native_core = new IntPtr[assumptions.Length]; + r = (Z3_lbool)Native.Z3_check_assumptions(ctx.nCtx, + (uint)assumptions.Length, AST.ArrayToNative(assumptions), + ref model, ref proof, ref core_size, native_core); + + for (uint i = 0; i < core_size; i++) + core.Add((BoolExpr)Expr.Create(ctx, native_core[i])); + + } + switch (r) + { + case Z3_lbool.Z3_L_TRUE: return Status.SATISFIABLE; + case Z3_lbool.Z3_L_FALSE: return Status.UNSATISFIABLE; + default: return Status.UNKNOWN; + } + } + + /// + /// Retrieves an assignment to atomic propositions for a satisfiable context. + /// + /// + public static BoolExpr GetAssignment(Context ctx) + { + IntPtr x = Native.Z3_get_context_assignment(ctx.nCtx); + return (BoolExpr)Expr.Create(ctx, x); + } + + } +} \ No newline at end of file