3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-29 11:55:51 +00:00

Added conversion functions to ASTVectors in .NET and Java.

Fixes #108
This commit is contained in:
Christoph M. Wintersteiger 2015-05-26 11:20:19 +01:00
parent 9912b2cd67
commit 91352369a9
8 changed files with 239 additions and 23 deletions

View file

@ -112,7 +112,7 @@ namespace Microsoft.Z3
}
/// <summary>
/// Translates an AST vector into an Expr[]
/// Translates an ASTVector into an Expr[]
/// </summary>
public Expr[] ToExprArray()
{
@ -123,6 +123,114 @@ namespace Microsoft.Z3
return res;
}
/// <summary>
/// Translates an ASTVector into a BoolExpr[]
/// </summary>
public BoolExpr[] ToBoolExprArray()
{
uint n = Size;
BoolExpr[] res = new BoolExpr[n];
for (uint i = 0; i < n; i++)
res[i] = (BoolExpr) Expr.Create(this.Context, this[i].NativeObject);
return res;
}
/// <summary>
/// Translates an ASTVector into a BitVecExpr[]
/// </summary>
public BitVecExpr[] ToBitVecExprArray()
{
uint n = Size;
BitVecExpr[] res = new BitVecExpr[n];
for (uint i = 0; i < n; i++)
res[i] = (BitVecExpr)Expr.Create(this.Context, this[i].NativeObject);
return res;
}
/// <summary>
/// Translates an ASTVector into a ArithExpr[]
/// </summary>
public ArithExpr[] ToArithExprArray()
{
uint n = Size;
ArithExpr[] res = new ArithExpr[n];
for (uint i = 0; i < n; i++)
res[i] = (ArithExpr)Expr.Create(this.Context, this[i].NativeObject);
return res;
}
/// <summary>
/// Translates an ASTVector into a ArrayExpr[]
/// </summary>
public ArrayExpr[] ToArrayExprArray()
{
uint n = Size;
ArrayExpr[] res = new ArrayExpr[n];
for (uint i = 0; i < n; i++)
res[i] = (ArrayExpr)Expr.Create(this.Context, this[i].NativeObject);
return res;
}
/// <summary>
/// Translates an ASTVector into a DatatypeExpr[]
/// </summary>
public DatatypeExpr[] ToDatatypeExprArray()
{
uint n = Size;
DatatypeExpr[] res = new DatatypeExpr[n];
for (uint i = 0; i < n; i++)
res[i] = (DatatypeExpr)Expr.Create(this.Context, this[i].NativeObject);
return res;
}
/// <summary>
/// Translates an ASTVector into a FPExpr[]
/// </summary>
public FPExpr[] ToFPExprArray()
{
uint n = Size;
FPExpr[] res = new FPExpr[n];
for (uint i = 0; i < n; i++)
res[i] = (FPExpr)Expr.Create(this.Context, this[i].NativeObject);
return res;
}
/// <summary>
/// Translates an ASTVector into a FPRMExpr[]
/// </summary>
public FPRMExpr[] ToFPRMExprArray()
{
uint n = Size;
FPRMExpr[] res = new FPRMExpr[n];
for (uint i = 0; i < n; i++)
res[i] = (FPRMExpr)Expr.Create(this.Context, this[i].NativeObject);
return res;
}
/// <summary>
/// Translates an ASTVector into a IntExpr[]
/// </summary>
public IntExpr[] ToIntExprArray()
{
uint n = Size;
IntExpr[] res = new IntExpr[n];
for (uint i = 0; i < n; i++)
res[i] = (IntExpr)Expr.Create(this.Context, this[i].NativeObject);
return res;
}
/// <summary>
/// Translates an ASTVector into a RealExpr[]
/// </summary>
public RealExpr[] ToRealExprArray()
{
uint n = Size;
RealExpr[] res = new RealExpr[n];
for (uint i = 0; i < n; i++)
res[i] = (RealExpr)Expr.Create(this.Context, this[i].NativeObject);
return res;
}
#region Internal
internal ASTVector(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
internal ASTVector(Context ctx) : base(ctx, Native.Z3_mk_ast_vector(ctx.nCtx)) { Contract.Requires(ctx != null); }

View file

@ -279,7 +279,7 @@ namespace Microsoft.Z3
Contract.Ensures(Contract.Result<BoolExpr[]>() != null);
ASTVector av = new ASTVector(Context, Native.Z3_fixedpoint_get_rules(Context.nCtx, NativeObject));
return (BoolExpr[])av.ToExprArray();
return av.ToBoolExprArray();
}
}
@ -293,7 +293,7 @@ namespace Microsoft.Z3
Contract.Ensures(Contract.Result<BoolExpr[]>() != null);
ASTVector av = new ASTVector(Context, Native.Z3_fixedpoint_get_assertions(Context.nCtx, NativeObject));
return (BoolExpr[])av.ToExprArray();
return av.ToBoolExprArray();
}
}
@ -318,7 +318,7 @@ namespace Microsoft.Z3
public BoolExpr[] ParseFile(string file)
{
ASTVector av = new ASTVector(Context, Native.Z3_fixedpoint_from_file(Context.nCtx, NativeObject, file));
return (BoolExpr[])av.ToExprArray();
return av.ToBoolExprArray();
}
/// <summary>
@ -327,7 +327,7 @@ namespace Microsoft.Z3
public BoolExpr[] ParseString(string s)
{
ASTVector av = new ASTVector(Context, Native.Z3_fixedpoint_from_string(Context.nCtx, NativeObject, s));
return (BoolExpr[])av.ToExprArray();
return av.ToBoolExprArray();
}

View file

@ -47,7 +47,7 @@ namespace Microsoft.Z3
/// <remarks>For more information on interpolation please refer
/// too the function Z3_get_interpolant in the C/C++ API, which is
/// well documented.</remarks>
public Expr[] GetInterpolant(Expr pf, Expr pat, Params p)
public BoolExpr[] GetInterpolant(Expr pf, Expr pat, Params p)
{
Contract.Requires(pf != null);
Contract.Requires(pat != null);
@ -59,7 +59,7 @@ namespace Microsoft.Z3
CheckContextMatch(p);
ASTVector seq = new ASTVector(this, Native.Z3_get_interpolant(nCtx, pf.NativeObject, pat.NativeObject, p.NativeObject));
return seq.ToExprArray();
return seq.ToBoolExprArray();
}
/// <summary>
@ -68,7 +68,7 @@ namespace Microsoft.Z3
/// <remarks>For more information on interpolation please refer
/// too the function Z3_compute_interpolant in the C/C++ API, which is
/// well documented.</remarks>
public Z3_lbool ComputeInterpolant(Expr pat, Params p, out Expr[] interp, out Model model)
public Z3_lbool ComputeInterpolant(Expr pat, Params p, out BoolExpr[] interp, out Model model)
{
Contract.Requires(pat != null);
Contract.Requires(p != null);
@ -80,7 +80,7 @@ namespace Microsoft.Z3
IntPtr i = IntPtr.Zero, m = IntPtr.Zero;
int r = Native.Z3_compute_interpolant(nCtx, pat.NativeObject, p.NativeObject, ref i, ref m);
interp = new ASTVector(this, i).ToExprArray();
interp = new ASTVector(this, i).ToBoolExprArray();
model = new Model(this, m);
return (Z3_lbool)r;
}
@ -102,7 +102,7 @@ namespace Microsoft.Z3
/// <remarks>For more information on interpolation please refer
/// too the function Z3_check_interpolant in the C/C++ API, which is
/// well documented.</remarks>
public int CheckInterpolant(Expr[] cnsts, uint[] parents, Expr[] interps, out string error, Expr[] theory)
public int CheckInterpolant(Expr[] cnsts, uint[] parents, BoolExpr[] interps, out string error, Expr[] theory)
{
Contract.Requires(cnsts.Length == parents.Length);
Contract.Requires(cnsts.Length == interps.Length + 1);

View file

@ -193,7 +193,7 @@ namespace Microsoft.Z3
Contract.Ensures(Contract.Result<BoolExpr[]>() != null);
ASTVector assertions = new ASTVector(Context, Native.Z3_solver_get_assertions(Context.nCtx, NativeObject));
return (BoolExpr[])assertions.ToExprArray();
return assertions.ToBoolExprArray();
}
}
@ -273,7 +273,7 @@ namespace Microsoft.Z3
Contract.Ensures(Contract.Result<Expr[]>() != null);
ASTVector core = new ASTVector(Context, Native.Z3_solver_get_unsat_core(Context.nCtx, NativeObject));
return (BoolExpr[])core.ToExprArray();
return core.ToBoolExprArray();
}
}