3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-13 20:38:43 +00:00
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2012-12-06 11:05:49 -08:00
commit 9ab1210cc2
518 changed files with 21452 additions and 22650 deletions

13
.gitignore vendored
View file

@ -1,5 +1,7 @@
*~
*.pyc
# .hpp files are automatically generated
*.hpp
.z3-trace
# OCaml generated files
*.a
@ -7,6 +9,9 @@
*.cmi
*.cmxa
ocamlz3
# Java generated files
*.class
*.jar
# Emacs temp files
\#*\#
# Directories with generated code and documentation
@ -31,12 +36,15 @@ ncscope.out
# Commonly used directories for code
bld_dbg/*
bld_rel/*
bld_dbg_x64/*
bld_rel_x64/*
# Auto generated files.
config.log
config.status
configure
install_tactic.cpp
mem_initializer.cpp
gparams_register_modules.cpp
scripts/config-debug.mk
scripts/config-release.mk
src/api/api_commands.cpp
@ -49,5 +57,6 @@ src/api/python/z3consts.py
src/api/python/z3core.py
src/ast/pattern/database.h
src/util/version.h
src/api/java/Z3Native.c
src/api/java/Z3Native.java
src/api/java/Native.cpp
src/api/java/Native.java
src/api/java/enumerations/*.java

View file

@ -14,6 +14,12 @@ Version 4.3.2
- Removed 'autoconf' dependency. We do not need to execute 'autoconf' and './configure' anymore to build Z3.
- Fixed incorrect result returned by Z3_solver_get_num_scopes. (Thanks to Herman Venter). This bug was introduced in Z3 4.3.0
- Java bindings. To enable them, we must use the option `--java` when executing the `mk_make.py` script. Example: `python scripts/mk_make.py --java`
- Fixed crash when parsing incorrect formulas. The crash was introduced when support for "arithmetic coercions" was added in Z3 4.3.0.
Version 4.3.1
=============

View file

@ -143,7 +143,7 @@ void prove_example2() {
void nonlinear_example1() {
std::cout << "nonlinear example 1\n";
config cfg;
cfg.set(":auto-config", true);
cfg.set("auto_config", true);
context c(cfg);
expr x = c.real_const("x");
@ -158,12 +158,13 @@ void nonlinear_example1() {
std::cout << s.check() << "\n";
model m = s.get_model();
std::cout << m << "\n";
c.set(":pp-decimal", true); // set decimal notation
set_param("pp.decimal", true); // set decimal notation
std::cout << "model in decimal notation\n";
std::cout << m << "\n";
c.set(":pp-decimal-precision", 50); // increase number of decimal places to 50.
set_param("pp.decimal-precision", 50); // increase number of decimal places to 50.
std::cout << "model using 50 decimal places\n";
std::cout << m << "\n";
set_param("pp.decimal", false); // disable decimal notation
}
/**
@ -352,7 +353,7 @@ void quantifier_example() {
// making sure model based quantifier instantiation is enabled.
params p(c);
p.set(":mbqi", true);
p.set("mbqi", true);
s.set(p);
s.add(forall(x, y, f(x, y) >= 0));
@ -468,7 +469,7 @@ void unsat_core_example3() {
// enabling unsat core tracking
params p(c);
p.set(":unsat-core", true);
p.set("unsat_core", true);
s.set(p);
// The following assertion will not be tracked.
@ -585,7 +586,7 @@ void tactic_example4() {
std::cout << "tactic example 4\n";
context c;
params p(c);
p.set(":mul2concat", true);
p.set("mul2concat", true);
tactic t =
with(tactic(c, "simplify"), p) &
tactic(c, "solve-eqs") &
@ -628,8 +629,8 @@ void tactic_example6() {
std::cout << "tactic example 6\n";
context c;
params p(c);
p.set(":arith-lhs", true);
p.set(":som", true); // sum-of-monomials normal form
p.set("arith_lhs", true);
p.set("som", true); // sum-of-monomials normal form
solver s =
(with(tactic(c, "simplify"), p) &
tactic(c, "normalize-bounds") &

View file

@ -70,7 +70,7 @@ Z3_context mk_context_custom(Z3_config cfg, Z3_error_handler err)
{
Z3_context ctx;
Z3_set_param_value(cfg, "MODEL", "true");
Z3_set_param_value(cfg, "model", "true");
ctx = Z3_mk_context(cfg);
Z3_set_error_handler(ctx, err);
@ -105,7 +105,7 @@ Z3_context mk_context()
Z3_context mk_proof_context() {
Z3_config cfg = Z3_mk_config();
Z3_context ctx;
Z3_set_param_value(cfg, "PROOF_MODE", "2");
Z3_set_param_value(cfg, "proof", "true");
ctx = mk_context_custom(cfg, throw_z3_error);
Z3_del_config(cfg);
return ctx;
@ -1038,12 +1038,12 @@ void quantifier_example1()
/* If quantified formulas are asserted in a logical context, then
Z3 may return L_UNDEF. In this case, the model produced by Z3 should be viewed as a potential/candidate model.
*/
Z3_set_param_value(cfg, "MODEL", "true");
/*
The current model finder for quantified formulas cannot handle injectivity.
So, we are limiting the number of iterations to avoid a long "wait".
*/
Z3_set_param_value(cfg, "MBQI_MAX_ITERATIONS", "10");
Z3_global_param_set("smt.mbqi.max_iterations", "10");
ctx = mk_context_custom(cfg, error_handler);
Z3_del_config(cfg);
@ -1087,8 +1087,9 @@ void quantifier_example1()
if (Z3_get_search_failure(ctx) != Z3_QUANTIFIERS) {
exitf("unexpected result");
}
Z3_del_context(ctx);
/* reset global parameters set by this function */
Z3_global_param_reset_all();
}
/**
@ -1646,7 +1647,7 @@ void parser_example3()
cfg = Z3_mk_config();
/* See quantifer_example1 */
Z3_set_param_value(cfg, "MODEL", "true");
Z3_set_param_value(cfg, "model", "true");
ctx = mk_context_custom(cfg, error_handler);
Z3_del_config(cfg);
@ -2249,57 +2250,6 @@ void unsat_core_and_proof_example() {
Z3_del_context(ctx);
}
/**
\brief Extract classes of implied equalities.
This example illustrates the use of #Z3_get_implied_equalities.
*/
void get_implied_equalities_example() {
Z3_config cfg = Z3_mk_config();
Z3_context ctx;
printf("\nget_implied_equalities example\n");
LOG_MSG("get_implied_equalities example");
Z3_set_param_value(cfg, "ARITH_PROCESS_ALL_EQS", "true");
Z3_set_param_value(cfg, "ARITH_EQ_BOUNDS", "true");
ctx = Z3_mk_context(cfg);
Z3_del_config(cfg);
{
Z3_sort int_ty = Z3_mk_int_sort(ctx);
Z3_ast a = mk_int_var(ctx,"a");
Z3_ast b = mk_int_var(ctx,"b");
Z3_ast c = mk_int_var(ctx,"c");
Z3_ast d = mk_int_var(ctx,"d");
Z3_func_decl f = Z3_mk_func_decl(ctx, Z3_mk_string_symbol(ctx,"f"), 1, &int_ty, int_ty);
Z3_ast fa = Z3_mk_app(ctx, f, 1, &a);
Z3_ast fb = Z3_mk_app(ctx, f, 1, &b);
Z3_ast fc = Z3_mk_app(ctx, f, 1, &c);
unsigned const num_terms = 7;
unsigned i;
Z3_ast terms[7] = { a, b, c, d, fa, fb, fc };
unsigned class_ids[7] = { 0, 0, 0, 0, 0, 0, 0 };
Z3_assert_cnstr(ctx, Z3_mk_eq(ctx, a, b));
Z3_assert_cnstr(ctx, Z3_mk_eq(ctx, b, c));
Z3_assert_cnstr(ctx, Z3_mk_le(ctx, fc, b));
Z3_assert_cnstr(ctx, Z3_mk_le(ctx, b, fa));
Z3_get_implied_equalities(ctx, num_terms, terms, class_ids);
for (i = 0; i < num_terms; ++i) {
printf("Class %s |-> %d\n", Z3_ast_to_string(ctx, terms[i]), class_ids[i]);
}
printf("asserting f(a) <= b\n");
Z3_assert_cnstr(ctx, Z3_mk_le(ctx, fa, b));
Z3_get_implied_equalities(ctx, num_terms, terms, class_ids);
for (i = 0; i < num_terms; ++i) {
printf("Class %s |-> %d\n", Z3_ast_to_string(ctx, terms[i]), class_ids[i]);
}
}
/* delete logical context */
Z3_del_context(ctx);
}
#define MAX_RETRACTABLE_ASSERTIONS 1024
/**
@ -2504,7 +2454,7 @@ void reference_counter_example() {
LOG_MSG("reference_counter_example");
cfg = Z3_mk_config();
Z3_set_param_value(cfg, "MODEL", "true");
Z3_set_param_value(cfg, "model", "true");
// Create a Z3 context where the user is reponsible for managing
// Z3_ast reference counters.
ctx = Z3_mk_context_rc(cfg);
@ -2685,7 +2635,6 @@ int main() {
binary_tree_example();
enum_example();
unsat_core_and_proof_example();
get_implied_equalities_example();
incremental_example1();
reference_counter_example();
smt2parser_example();

View file

@ -248,10 +248,13 @@ namespace test_mapi
return res;
}
static void Prove(Context ctx, BoolExpr f, params BoolExpr[] assumptions)
static void Prove(Context ctx, BoolExpr f, bool useMBQI = false, params BoolExpr[] assumptions)
{
Console.WriteLine("Proving: " + f);
Solver s = ctx.MkSolver();
Params p = ctx.MkParams();
p.Add("mbqi", useMBQI);
s.Parameters = p;
foreach (BoolExpr a in assumptions)
s.Assert(a);
s.Assert(ctx.MkNot(f));
@ -270,10 +273,13 @@ namespace test_mapi
}
}
static void Disprove(Context ctx, BoolExpr f, params BoolExpr[] assumptions)
static void Disprove(Context ctx, BoolExpr f, bool useMBQI = false, params BoolExpr[] assumptions)
{
Console.WriteLine("Disproving: " + f);
Solver s = ctx.MkSolver();
Params p = ctx.MkParams();
p.Add("mbqi", useMBQI);
s.Parameters = p;
foreach (BoolExpr a in assumptions)
s.Assert(a);
s.Assert(ctx.MkNot(f));
@ -298,7 +304,7 @@ namespace test_mapi
ArithExpr xr = (ArithExpr)ctx.MkConst(ctx.MkSymbol("x"), ctx.MkRealSort());
ArithExpr yr = (ArithExpr)ctx.MkConst(ctx.MkSymbol("y"), ctx.MkRealSort());
Goal g4 = ctx.MkGoal(true, false, true);
Goal g4 = ctx.MkGoal(true);
g4.Assert(ctx.MkGt(xr, ctx.MkReal(10, 1)));
g4.Assert(ctx.MkEq(yr, ctx.MkAdd(xr, ctx.MkReal(1, 1))));
g4.Assert(ctx.MkGt(yr, ctx.MkReal(1, 1)));
@ -330,7 +336,7 @@ namespace test_mapi
{
Console.WriteLine("ArrayExample1");
Goal g = ctx.MkGoal(true, false, false);
Goal g = ctx.MkGoal(true);
ArraySort asort = ctx.MkArraySort(ctx.IntSort, ctx.MkBitVecSort(32));
ArrayExpr aex = (ArrayExpr)ctx.MkConst(ctx.MkSymbol("MyArray"), asort);
Expr sel = ctx.MkSelect(aex, ctx.MkInt(0));
@ -640,95 +646,76 @@ namespace test_mapi
/// Prove that <tt>f(x, y) = f(w, v) implies y = v</tt> when
/// <code>f</code> is injective in the second argument. <seealso cref="inj_axiom"/>
/// </summary>
public static void QuantifierExample3()
public static void QuantifierExample3(Context ctx)
{
Console.WriteLine("QuantifierExample3");
Dictionary<string, string> cfg = new Dictionary<string, string>() {
{ "MBQI", "false" },
{ "PROOF_MODE", "2" },
{ "AUTO_CONFIG", "false" }
};
/* If quantified formulas are asserted in a logical context, then
the model produced by Z3 should be viewed as a potential model. */
using (Context ctx = new Context(cfg))
{
/* declare function f */
Sort I = ctx.IntSort;
FuncDecl f = ctx.MkFuncDecl("f", new Sort[] { I, I }, I);
/* declare function f */
Sort I = ctx.IntSort;
FuncDecl f = ctx.MkFuncDecl("f", new Sort[] { I, I }, I);
/* f is injective in the second argument. */
BoolExpr inj = InjAxiom(ctx, f, 1);
/* f is injective in the second argument. */
BoolExpr inj = InjAxiom(ctx, f, 1);
/* create x, y, v, w, fxy, fwv */
Expr x = ctx.MkIntConst("x");
Expr y = ctx.MkIntConst("y");
Expr v = ctx.MkIntConst("v");
Expr w = ctx.MkIntConst("w");
Expr fxy = ctx.MkApp(f, x, y);
Expr fwv = ctx.MkApp(f, w, v);
/* create x, y, v, w, fxy, fwv */
Expr x = ctx.MkIntConst("x");
Expr y = ctx.MkIntConst("y");
Expr v = ctx.MkIntConst("v");
Expr w = ctx.MkIntConst("w");
Expr fxy = ctx.MkApp(f, x, y);
Expr fwv = ctx.MkApp(f, w, v);
/* f(x, y) = f(w, v) */
BoolExpr p1 = ctx.MkEq(fxy, fwv);
/* f(x, y) = f(w, v) */
BoolExpr p1 = ctx.MkEq(fxy, fwv);
/* prove f(x, y) = f(w, v) implies y = v */
BoolExpr p2 = ctx.MkEq(y, v);
Prove(ctx, p2, inj, p1);
/* prove f(x, y) = f(w, v) implies y = v */
BoolExpr p2 = ctx.MkEq(y, v);
Prove(ctx, p2, false, inj, p1);
/* disprove f(x, y) = f(w, v) implies x = w */
BoolExpr p3 = ctx.MkEq(x, w);
Disprove(ctx, p3, inj, p1);
}
/* disprove f(x, y) = f(w, v) implies x = w */
BoolExpr p3 = ctx.MkEq(x, w);
Disprove(ctx, p3, false, inj, p1);
}
/// <summary>
/// Prove that <tt>f(x, y) = f(w, v) implies y = v</tt> when
/// <code>f</code> is injective in the second argument. <seealso cref="inj_axiom"/>
/// </summary>
public static void QuantifierExample4()
public static void QuantifierExample4(Context ctx)
{
Console.WriteLine("QuantifierExample4");
Dictionary<string, string> cfg = new Dictionary<string, string>() {
{ "MBQI", "false" },
{ "PROOF_MODE", "2" },
{ "AUTO_CONFIG","false" }};
/* If quantified formulas are asserted in a logical context, then
the model produced by Z3 should be viewed as a potential model. */
using (Context ctx = new Context(cfg))
{
/* declare function f */
Sort I = ctx.IntSort;
FuncDecl f = ctx.MkFuncDecl("f", new Sort[] { I, I }, I);
/* declare function f */
Sort I = ctx.IntSort;
FuncDecl f = ctx.MkFuncDecl("f", new Sort[] { I, I }, I);
/* f is injective in the second argument. */
BoolExpr inj = InjAxiomAbs(ctx, f, 1);
/* f is injective in the second argument. */
BoolExpr inj = InjAxiomAbs(ctx, f, 1);
/* create x, y, v, w, fxy, fwv */
Expr x = ctx.MkIntConst("x");
Expr y = ctx.MkIntConst("y");
Expr v = ctx.MkIntConst("v");
Expr w = ctx.MkIntConst("w");
Expr fxy = ctx.MkApp(f, x, y);
Expr fwv = ctx.MkApp(f, w, v);
/* create x, y, v, w, fxy, fwv */
Expr x = ctx.MkIntConst("x");
Expr y = ctx.MkIntConst("y");
Expr v = ctx.MkIntConst("v");
Expr w = ctx.MkIntConst("w");
Expr fxy = ctx.MkApp(f, x, y);
Expr fwv = ctx.MkApp(f, w, v);
/* f(x, y) = f(w, v) */
BoolExpr p1 = ctx.MkEq(fxy, fwv);
/* f(x, y) = f(w, v) */
BoolExpr p1 = ctx.MkEq(fxy, fwv);
/* prove f(x, y) = f(w, v) implies y = v */
BoolExpr p2 = ctx.MkEq(y, v);
Prove(ctx, p2, inj, p1);
/* prove f(x, y) = f(w, v) implies y = v */
BoolExpr p2 = ctx.MkEq(y, v);
Prove(ctx, p2, false, inj, p1);
/* disprove f(x, y) = f(w, v) implies x = w */
BoolExpr p3 = ctx.MkEq(x, w);
Disprove(ctx, p3, inj, p1);
}
/* disprove f(x, y) = f(w, v) implies x = w */
BoolExpr p3 = ctx.MkEq(x, w);
Disprove(ctx, p3, false, inj, p1);
}
/// <summary>
@ -756,7 +743,7 @@ namespace test_mapi
BoolExpr trivial_eq = ctx.MkEq(fapp, fapp);
BoolExpr nontrivial_eq = ctx.MkEq(fapp, fapp2);
Goal g = ctx.MkGoal(true, false, true);
Goal g = ctx.MkGoal(true);
g.Assert(trivial_eq);
g.Assert(nontrivial_eq);
Console.WriteLine("Goal: " + g);
@ -784,18 +771,18 @@ namespace test_mapi
throw new TestFailedException();
Goal g2 = ctx.MkGoal(true, true, false);
Goal g2 = ctx.MkGoal(true, true);
ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g2);
if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedSat)
throw new TestFailedException();
g2 = ctx.MkGoal(true, true, false);
g2 = ctx.MkGoal(true, true);
g2.Assert(ctx.MkFalse());
ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g2);
if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat)
throw new TestFailedException();
Goal g3 = ctx.MkGoal(true, true, false);
Goal g3 = ctx.MkGoal(true, true);
Expr xc = ctx.MkConst(ctx.MkSymbol("x"), ctx.IntSort);
Expr yc = ctx.MkConst(ctx.MkSymbol("y"), ctx.IntSort);
g3.Assert(ctx.MkEq(xc, ctx.MkNumeral(1, ctx.IntSort)));
@ -839,7 +826,7 @@ namespace test_mapi
// Error handling test.
try
{
Expr plus_ri = ctx.MkAdd(ctx.MkInt(1), ctx.MkReal(2));
IntExpr i = ctx.MkInt("1/2");
throw new TestFailedException(); // unreachable
}
catch (Z3Exception)
@ -1063,7 +1050,7 @@ namespace test_mapi
// Or perhaps a tactic for QF_BV
Goal g = ctx.MkGoal(true, false, true);
Goal g = ctx.MkGoal(true);
g.Assert(eq);
Tactic t = ctx.MkTactic("qfbv");
@ -1086,7 +1073,7 @@ namespace test_mapi
Expr y = ctx.MkConst("y", bvs);
BoolExpr q = ctx.MkEq(x, y);
Goal g = ctx.MkGoal(true, false, true);
Goal g = ctx.MkGoal(true);
g.Assert(q);
Tactic t1 = ctx.MkTactic("qfbv");
@ -1128,7 +1115,7 @@ namespace test_mapi
/// </summary>
public static void FindModelExample2(Context ctx)
{
Console.WriteLine("find_model_example2");
Console.WriteLine("FindModelExample2");
IntExpr x = ctx.MkIntConst("x");
IntExpr y = ctx.MkIntConst("y");
@ -1250,13 +1237,13 @@ namespace test_mapi
/* prove z < 0 */
BoolExpr f = ctx.MkLt(z, zero);
Console.WriteLine("prove: not(g(g(x) - g(y)) = g(z)), x + z <= y <= x implies z < 0");
Prove(ctx, f, c1, c2, c3);
Prove(ctx, f, false, c1, c2, c3);
/* disprove z < -1 */
IntExpr minus_one = ctx.MkInt(-1);
f = ctx.MkLt(z, minus_one);
Console.WriteLine("disprove: not(g(g(x) - g(y)) = g(z)), x + z <= y <= x implies z < -1");
Disprove(ctx, f, c1, c2, c3);
Disprove(ctx, f, false, c1, c2, c3);
}
/// <summary>
@ -1448,7 +1435,7 @@ namespace test_mapi
BoolExpr thm = ctx.SMTLIBFormulas[0];
Console.WriteLine("formula: {0}", thm);
Prove(ctx, thm, ca);
Prove(ctx, thm, false, ca);
}
/// <summary>
@ -1979,45 +1966,40 @@ namespace test_mapi
/// <summary>
/// Extract unsatisfiable core example
/// </summary>
public static void UnsatCoreAndProofExample()
public static void UnsatCoreAndProofExample(Context ctx)
{
Console.WriteLine("UnsatCoreAndProofExample");
Dictionary<string, string> cfg = new Dictionary<string, string>() { { "PROOF_MODE", "2" } };
Solver solver = ctx.MkSolver();
using (Context ctx = new Context(cfg))
BoolExpr pa = ctx.MkBoolConst("PredA");
BoolExpr pb = ctx.MkBoolConst("PredB");
BoolExpr pc = ctx.MkBoolConst("PredC");
BoolExpr pd = ctx.MkBoolConst("PredD");
BoolExpr p1 = ctx.MkBoolConst("P1");
BoolExpr p2 = ctx.MkBoolConst("P2");
BoolExpr p3 = ctx.MkBoolConst("P3");
BoolExpr p4 = ctx.MkBoolConst("P4");
BoolExpr[] assumptions = new BoolExpr[] { ctx.MkNot(p1), ctx.MkNot(p2), ctx.MkNot(p3), ctx.MkNot(p4) };
BoolExpr f1 = ctx.MkAnd(new BoolExpr[] { pa, pb, pc });
BoolExpr f2 = ctx.MkAnd(new BoolExpr[] { pa, ctx.MkNot(pb), pc });
BoolExpr f3 = ctx.MkOr(ctx.MkNot(pa), ctx.MkNot(pc));
BoolExpr f4 = pd;
solver.Assert(ctx.MkOr(f1, p1));
solver.Assert(ctx.MkOr(f2, p2));
solver.Assert(ctx.MkOr(f3, p3));
solver.Assert(ctx.MkOr(f4, p4));
Status result = solver.Check(assumptions);
if (result == Status.UNSATISFIABLE)
{
Solver solver = ctx.MkSolver();
BoolExpr pa = ctx.MkBoolConst("PredA");
BoolExpr pb = ctx.MkBoolConst("PredB");
BoolExpr pc = ctx.MkBoolConst("PredC");
BoolExpr pd = ctx.MkBoolConst("PredD");
BoolExpr p1 = ctx.MkBoolConst("P1");
BoolExpr p2 = ctx.MkBoolConst("P2");
BoolExpr p3 = ctx.MkBoolConst("P3");
BoolExpr p4 = ctx.MkBoolConst("P4");
BoolExpr[] assumptions = new BoolExpr[] { ctx.MkNot(p1), ctx.MkNot(p2), ctx.MkNot(p3), ctx.MkNot(p4) };
BoolExpr f1 = ctx.MkAnd(new BoolExpr[] { pa, pb, pc });
BoolExpr f2 = ctx.MkAnd(new BoolExpr[] { pa, ctx.MkNot(pb), pc });
BoolExpr f3 = ctx.MkOr(ctx.MkNot(pa), ctx.MkNot(pc));
BoolExpr f4 = pd;
solver.Assert(ctx.MkOr(f1, p1));
solver.Assert(ctx.MkOr(f2, p2));
solver.Assert(ctx.MkOr(f3, p3));
solver.Assert(ctx.MkOr(f4, p4));
Status result = solver.Check(assumptions);
if (result == Status.UNSATISFIABLE)
Console.WriteLine("unsat");
Console.WriteLine("proof: {0}", solver.Proof);
Console.WriteLine("core: ");
foreach (Expr c in solver.UnsatCore)
{
Console.WriteLine("unsat");
Console.WriteLine("proof: {0}", solver.Proof);
Console.WriteLine("core: ");
foreach (Expr c in solver.UnsatCore)
{
Console.WriteLine("{0}", c);
}
Console.WriteLine("{0}", c);
}
}
}
@ -2054,9 +2036,8 @@ namespace test_mapi
SimpleExample();
using (Context ctx = new Context(new Dictionary<string, string>()
{ { "MODEL", "true"},
{ "PROOF_MODE", "2"} }))
// These examples need model generation turned on.
using (Context ctx = new Context(new Dictionary<string, string>() { { "model", "true" } }))
{
BasicTests(ctx);
CastingTest(ctx);
@ -2067,25 +2048,16 @@ namespace test_mapi
ParOrExample(ctx);
FindModelExample1(ctx);
FindModelExample2(ctx);
ProveExample1(ctx);
ProveExample2(ctx);
PushPopExample1(ctx);
ArrayExample1(ctx);
ArrayExample2(ctx);
ArrayExample3(ctx);
TupleExample(ctx);
BitvectorExample1(ctx);
BitvectorExample2(ctx);
ParserExample1(ctx);
ParserExample2(ctx);
ParserExample3(ctx);
ParserExample4(ctx);
ParserExample5(ctx);
ITEExample(ctx);
EnumExample(ctx);
ListExample(ctx);
TreeExample(ctx);
ForestExample(ctx);
EvalExample1(ctx);
EvalExample2(ctx);
FindSmallModelExample(ctx);
@ -2093,9 +2065,29 @@ namespace test_mapi
FiniteDomainExample(ctx);
}
QuantifierExample3();
QuantifierExample4();
UnsatCoreAndProofExample();
// These examples need proof generation turned on.
using (Context ctx = new Context(new Dictionary<string, string>() { { "proof", "true" } }))
{
ProveExample1(ctx);
ProveExample2(ctx);
ArrayExample2(ctx);
TupleExample(ctx);
ParserExample3(ctx);
EnumExample(ctx);
ListExample(ctx);
TreeExample(ctx);
ForestExample(ctx);
UnsatCoreAndProofExample(ctx);
}
// These examples need proof generation turned on and auto-config set to false.
using (Context ctx = new Context(new Dictionary<string, string>()
{ {"proof", "true" },
{"auto-config", "false" } }))
{
QuantifierExample3(ctx);
QuantifierExample4(ctx);
}
Log.Close();
if (Log.isOpen())

File diff suppressed because it is too large Load diff

15
examples/java/README Normal file
View file

@ -0,0 +1,15 @@
### This is work-in-progress and does not work yet.
Small example using the Z3 Java bindings.
To build the example execute
make examples
in the build directory.
It will create JavaExample.class in the build directory,
which can be run on Windows via
java -cp com.microsoft.z3.jar;. JavaExample
On Linux and FreeBSD, we must use
LD_LIBRARY_PATH=. java -cp com.microsoft.z3.jar:. JavaExample

View file

@ -18,34 +18,32 @@ def init_project_def():
add_lib('subpaving', ['interval'], 'math/subpaving')
add_lib('ast', ['util', 'polynomial'])
add_lib('rewriter', ['ast', 'polynomial'], 'ast/rewriter')
add_lib('normal_forms', ['rewriter'], 'ast/normal_forms')
add_lib('model', ['rewriter'])
add_lib('tactic', ['ast', 'model'])
add_lib('substitution', ['ast'], 'ast/substitution')
add_lib('parser_util', ['ast'], 'parsers/util')
add_lib('grobner', ['ast'], 'math/grobner')
add_lib('euclid', ['util'], 'math/euclid')
# Front-end-params module still contain a lot of parameters for smt solver component.
# This should be fixed
add_lib('front_end_params', ['ast'])
# Simplifier module will be deleted in the future.
# It has been replaced with rewriter module.
add_lib('simplifier', ['rewriter', 'front_end_params'], 'ast/simplifier')
add_lib('normal_forms', ['rewriter', 'front_end_params'], 'ast/normal_forms')
add_lib('core_tactics', ['tactic', 'normal_forms'], 'tactic/core')
add_lib('sat_tactic', ['tactic', 'sat'], 'sat/tactic')
add_lib('arith_tactics', ['core_tactics', 'sat'], 'tactic/arith')
add_lib('nlsat_tactic', ['nlsat', 'sat_tactic', 'arith_tactics'], 'nlsat/tactic')
add_lib('subpaving_tactic', ['core_tactics', 'subpaving'], 'math/subpaving/tactic')
add_lib('aig_tactic', ['tactic'], 'tactic/aig')
add_lib('solver', ['model', 'tactic', 'front_end_params'])
add_lib('solver', ['model', 'tactic'])
add_lib('cmd_context', ['solver', 'rewriter'])
add_lib('extra_cmds', ['cmd_context', 'subpaving_tactic', 'arith_tactics'], 'cmd_context/extra_cmds')
add_lib('smt2parser', ['cmd_context', 'parser_util'], 'parsers/smt2')
add_lib('proof_checker', ['rewriter'], 'ast/proof_checker')
# Simplifier module will be deleted in the future.
# It has been replaced with rewriter module.
add_lib('simplifier', ['rewriter'], 'ast/simplifier')
add_lib('macros', ['simplifier'], 'ast/macros')
add_lib('pattern', ['normal_forms', 'smt2parser', 'simplifier'], 'ast/pattern')
add_lib('macros', ['simplifier', 'front_end_params'], 'ast/macros')
add_lib('proof_checker', ['rewriter', 'front_end_params'], 'ast/proof_checker')
add_lib('bit_blaster', ['rewriter', 'simplifier', 'front_end_params'], 'ast/rewriter/bit_blaster')
add_lib('proto_model', ['model', 'simplifier', 'front_end_params'], 'smt/proto_model')
add_lib('bit_blaster', ['rewriter', 'simplifier'], 'ast/rewriter/bit_blaster')
add_lib('smt_params', ['ast', 'simplifier', 'pattern', 'bit_blaster'], 'smt/params')
add_lib('proto_model', ['model', 'simplifier', 'smt_params'], 'smt/proto_model')
add_lib('smt', ['bit_blaster', 'macros', 'normal_forms', 'cmd_context', 'proto_model',
'substitution', 'grobner', 'euclid', 'proof_checker', 'pattern', 'parser_util'])
add_lib('user_plugin', ['smt'], 'smt/user_plugin')
@ -71,7 +69,7 @@ def init_project_def():
static=build_static_lib(),
export_files=API_files)
add_dot_net_dll('dotnet', ['api_dll'], 'api/dotnet', dll_name='Microsoft.Z3', assembly_info_dir='Properties')
add_java_dll('java', ['api_dll'], 'api/java', dll_name='libz3java', package_name="com.Microsoft.Z3")
add_java_dll('java', ['api_dll'], 'api/java', dll_name='libz3java', package_name="com.microsoft.z3", manifest_file='manifest')
add_hlib('cpp', 'api/c++', includes2install=['z3++.h'])
set_z3py_dir('api/python')
# Examples
@ -79,6 +77,7 @@ def init_project_def():
add_c_example('c_example', 'c')
add_c_example('maxsat')
add_dotnet_example('dotnet_example', 'dotnet')
add_java_example('java_example', 'java')
add_z3py_example('py_example', 'python')
return API_files

View file

@ -56,6 +56,8 @@ JAVA_COMPONENT='java'
CPP_COMPONENT='cpp'
#####################
IS_WINDOWS=False
IS_LINUX=False
IS_OSX=False
VERBOSE=True
DEBUG_MODE=False
SHOW_CPPS = True
@ -75,7 +77,13 @@ PREFIX='/usr'
GMP=False
def is_windows():
return IS_WINDOWS
return IS_WINDOWS
def is_linux():
return IS_LINUX
def is_osx():
return IS_OSX
def unix_path2dos(path):
return string.join(path.split('/'), '\\')
@ -317,6 +325,11 @@ if os.name == 'nt':
SHOW_CPPS=False
# Enable .Net bindings by default on windows
DOTNET_ENABLED=True
elif os.name == 'posix':
if os.uname()[0] == 'Darwin':
IS_OSX=True
elif os.uname()[0] == 'Linux':
IS_LINUX=True
def display_help(exit_code):
print "mk_make.py: Z3 Makefile generator\n"
@ -484,6 +497,32 @@ def is_verbose():
def is_java_enabled():
return JAVA_ENABLED
def is_compiler(given, expected):
"""
Return True if the 'given' compiler is the expected one.
>>> is_compiler('g++', 'g++')
True
>>> is_compiler('/home/g++', 'g++')
True
>>> is_compiler(os.path.join('home', 'g++'), 'g++')
True
>>> is_compiler('clang++', 'g++')
False
>>> is_compiler(os.path.join('home', 'clang++'), 'clang++')
True
"""
if given == expected:
return True
if len(expected) < len(given):
return given[len(given) - len(expected) - 1] == os.sep and given[len(given) - len(expected):] == expected
return False
def is_CXX_gpp():
return is_compiler(CXX, 'g++')
def is_CXX_clangpp():
return is_compiler(CXX, 'clang++')
def get_cpp_files(path):
return filter(lambda f: f.endswith('.cpp'), os.listdir(path))
@ -493,6 +532,9 @@ def get_c_files(path):
def get_cs_files(path):
return filter(lambda f: f.endswith('.cs'), os.listdir(path))
def get_java_files(path):
return filter(lambda f: f.endswith('.java'), os.listdir(path))
def find_all_deps(name, deps):
new_deps = []
for dep in deps:
@ -922,29 +964,48 @@ class DotNetDLLComponent(Component):
class JavaDLLComponent(Component):
def __init__(self, name, dll_name, package_name, path, deps):
def __init__(self, name, dll_name, package_name, manifest_file, path, deps):
Component.__init__(self, name, path, deps)
if dll_name == None:
dll_name = name
self.dll_name = dll_name
self.package_name = package_name
self.manifest_file = manifest_file
def mk_makefile(self, out):
if is_java_enabled():
dllfile = '%s$(SO_EXT)' % self.dll_name
out.write('%s: %s/Z3Native.java %s$(SO_EXT)\n' % (dllfile, self.to_src_dir, get_component('api_dll').dll_name))
if IS_WINDOWS:
out.write('\tcd %s && %s Z3Native.java\n' % (unix_path2dos(self.to_src_dir), JAVAC))
out.write('\tmove %s\\*.class .\n' % unix_path2dos(self.to_src_dir))
out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)Z3Native$(OBJ_EXT) -I"%s/include" -I"%s/include/win32" -I%s %s/Z3Native.c\n' % (JAVA_HOME, JAVA_HOME, get_component('api').to_src_dir, self.to_src_dir))
out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) Z3Native$(OBJ_EXT) libz3.lib\n' % dllfile)
mk_dir(BUILD_DIR+'/api/java/classes')
dllfile = '%s$(SO_EXT)' % self.dll_name
out.write('libz3java$(SO_EXT): libz3$(SO_EXT) %s/Native.cpp\n' % self.to_src_dir)
t = '\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/java/Native$(OBJ_EXT) -I"%s/include" -I"%s/include/PLATFORM" -I%s %s/Native.cpp\n' % (JAVA_HOME, JAVA_HOME, get_component('api').to_src_dir, self.to_src_dir)
if IS_OSX:
t = t.replace('PLATFORM', 'darwin')
elif IS_LINUX:
t = t.replace('PLATFORM', 'linux')
else:
out.write('\tcd %s; %s Z3Native.java\n' % (self.to_src_dir, JAVAC))
out.write('\tmv %s/*.class .\n' % self.to_src_dir)
out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)Z3Native$(OBJ_EXT) -I"%s/include" -I%s %s/Z3Native.c\n' % (JAVA_HOME, get_component('api').to_src_dir, self.to_src_dir))
out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) -L. Z3Native$(OBJ_EXT) -lz3\n' % dllfile)
out.write('%s: %s\n\n' % (self.name, dllfile))
# TODO: Compile and package all the .class files.
t = t.replace('PLATFORM', 'win32')
out.write(t)
if IS_WINDOWS: # On Windows, CL creates a .lib file to link against.
out.write('\t$(SLINK) $(SLINK_OUT_FLAG)libz3java$(SO_EXT) $(SLINK_FLAGS) api/java/Native$(OBJ_EXT) libz3$(LIB_EXT)\n')
else:
out.write('\t$(SLINK) $(SLINK_OUT_FLAG)libz3java$(SO_EXT) $(SLINK_FLAGS) api/java/Native$(OBJ_EXT) libz3$(SO_EXT)\n')
out.write('%s.jar: libz3java$(SO_EXT) ' % self.package_name)
deps = ''
for jfile in get_java_files(self.src_dir):
deps += ('%s/%s ' % (self.to_src_dir, jfile))
for jfile in get_java_files((self.src_dir + "/enumerations")):
deps += ('%s/enumerations/%s ' % (self.to_src_dir, jfile))
if IS_WINDOWS: deps = deps.replace('/', '\\')
out.write(deps)
out.write('\n')
t = ('\t%s %s/enumerations/*.java -d api/java/classes\n' % (JAVAC, self.to_src_dir))
if IS_WINDOWS: t = t.replace('/','\\')
out.write(t)
t = ('\t%s -cp api/java/classes %s/*.java -d api/java/classes\n' % (JAVAC, self.to_src_dir))
if IS_WINDOWS: t = t.replace('/','\\')
out.write(t)
out.write('\tjar cfm %s.jar %s/manifest -C api/java/classes .\n' % (self.package_name, self.to_src_dir))
out.write('java: %s.jar\n\n' % self.package_name)
def main_component(self):
return is_java_enabled()
@ -1015,7 +1076,7 @@ class DotNetExampleComponent(ExampleComponent):
if DOTNET_ENABLED:
dll_name = get_component(DOTNET_COMPONENT).dll_name
dll = '%s.dll' % dll_name
exefile = '%s.exe' % self.name
exefile = '%s$(EXE_EXT)' % self.name
out.write('%s: %s' % (exefile, dll))
for csfile in get_cs_files(self.ex_dir):
out.write(' ')
@ -1034,6 +1095,30 @@ class DotNetExampleComponent(ExampleComponent):
out.write('\n')
out.write('_ex_%s: %s\n\n' % (self.name, exefile))
class JavaExampleComponent(ExampleComponent):
def __init__(self, name, path):
ExampleComponent.__init__(self, name, path)
def is_example(self):
return JAVA_ENABLED
def mk_makefile(self, out):
if JAVA_ENABLED:
pkg = get_component(JAVA_COMPONENT).package_name + '.jar'
out.write('_ex_%s: %s' % (self.name, pkg))
deps = ''
for jfile in get_java_files(self.ex_dir):
out.write(' %s/%s' % (self.to_ex_dir, jfile))
if IS_WINDOWS:
deps = deps.replace('/', '\\')
out.write('%s\n' % deps)
out.write('\t%s -cp %s ' % (JAVAC, pkg))
win_ex_dir = self.to_ex_dir
for javafile in get_java_files(self.ex_dir):
out.write(' ')
out.write('%s/%s' % (win_ex_dir, javafile))
out.write(' -d .\n\n')
class PythonExampleComponent(ExampleComponent):
def __init__(self, name, path):
ExampleComponent.__init__(self, name, path)
@ -1083,8 +1168,8 @@ def add_dot_net_dll(name, deps=[], path=None, dll_name=None, assembly_info_dir=N
c = DotNetDLLComponent(name, dll_name, path, deps, assembly_info_dir)
reg_component(name, c)
def add_java_dll(name, deps=[], path=None, dll_name=None, package_name=None):
c = JavaDLLComponent(name, dll_name, package_name, path, deps)
def add_java_dll(name, deps=[], path=None, dll_name=None, package_name=None, manifest_file=None):
c = JavaDLLComponent(name, dll_name, package_name, manifest_file, path, deps)
reg_component(name, c)
def add_cpp_example(name, path=None):
@ -1099,6 +1184,10 @@ def add_dotnet_example(name, path=None):
c = DotNetExampleComponent(name, path)
reg_component(name, c)
def add_java_example(name, path=None):
c = JavaExampleComponent(name, path)
reg_component(name, c)
def add_z3py_example(name, path=None):
c = PythonExampleComponent(name, path)
reg_component(name, c)
@ -1179,7 +1268,7 @@ def mk_config():
else:
CPPFLAGS = '%s -D_MP_INTERNAL' % CPPFLAGS
CXXFLAGS = '%s -c' % CXXFLAGS
if CXX == 'g++':
if is_CXX_gpp():
CXXFLAGS = '%s -fopenmp -mfpmath=sse' % CXXFLAGS
LDFLAGS = '%s -fopenmp' % LDFLAGS
SLIBEXTRAFLAGS = '-fopenmp'
@ -1193,7 +1282,7 @@ def mk_config():
SLIBFLAGS = '-dynamiclib'
elif sysname == 'Linux':
CXXFLAGS = '%s -fno-strict-aliasing -D_LINUX_' % CXXFLAGS
if CXX == 'clang++':
if is_CXX_clangpp():
CXXFLAGS = '%s -Wno-unknown-pragmas -Wno-overloaded-virtual -Wno-unused-value' % CXXFLAGS
SO_EXT = '.so'
LDFLAGS = '%s -lrt' % LDFLAGS
@ -1331,9 +1420,113 @@ def mk_makefile():
# Generate automatically generated source code
def mk_auto_src():
if not ONLY_MAKEFILES:
exec_pyg_scripts()
mk_pat_db()
mk_all_install_tactic_cpps()
mk_all_mem_initializer_cpps()
mk_all_gparams_register_modules()
UINT = 0
BOOL = 1
DOUBLE = 2
STRING = 3
SYMBOL = 4
UINT_MAX = 4294967295
CURR_PYG = None
def get_curr_pyg():
return CURR_PYG
TYPE2CPK = { UINT : 'CPK_UINT', BOOL : 'CPK_BOOL', DOUBLE : 'CPK_DOUBLE', STRING : 'CPK_STRING', SYMBOL : 'CPK_SYMBOL' }
TYPE2CTYPE = { UINT : 'unsigned', BOOL : 'bool', DOUBLE : 'double', STRING : 'char const *', SYMBOL : 'symbol' }
TYPE2GETTER = { UINT : 'get_uint', BOOL : 'get_bool', DOUBLE : 'get_double', STRING : 'get_str', SYMBOL : 'get_sym' }
def pyg_default(p):
if p[1] == BOOL:
if p[2]:
return "true"
else:
return "false"
return p[2]
def pyg_default_as_c_literal(p):
if p[1] == BOOL:
if p[2]:
return "true"
else:
return "false"
elif p[1] == STRING:
return '"%s"' % p[2]
elif p[1] == SYMBOL:
return 'symbol("%s")' % p[2]
return p[2]
def to_c_method(s):
return s.replace('.', '_')
def def_module_params(module_name, export, params, class_name=None, description=None):
pyg = get_curr_pyg()
dirname = os.path.split(get_curr_pyg())[0]
if class_name == None:
class_name = '%s_params' % module_name
hpp = os.path.join(dirname, '%s.hpp' % class_name)
out = open(hpp, 'w')
out.write('// Automatically generated file\n')
out.write('#include"params.h"\n')
if export:
out.write('#include"gparams.h"\n')
out.write('struct %s {\n' % class_name)
out.write(' params_ref const & p;\n')
if export:
out.write(' params_ref g;\n')
out.write(' %s(params_ref const & _p = params_ref()):\n' % class_name)
out.write(' p(_p)')
if export:
out.write(', g(gparams::get_module("%s"))' % module_name)
out.write(' {}\n')
out.write(' static void collect_param_descrs(param_descrs & d) {\n')
for param in params:
out.write(' d.insert("%s", %s, "%s", "%s");\n' % (param[0], TYPE2CPK[param[1]], param[3], pyg_default(param)))
out.write(' }\n')
if export:
out.write(' /*\n')
out.write(" REG_MODULE_PARAMS('%s', '%s::collect_param_descrs')\n" % (module_name, class_name))
if description != None:
out.write(" REG_MODULE_DESCRIPTION('%s', '%s')\n" % (module_name, description))
out.write(' */\n')
# Generated accessors
for param in params:
if export:
out.write(' %s %s() const { return p.%s("%s", g, %s); }\n' %
(TYPE2CTYPE[param[1]], to_c_method(param[0]), TYPE2GETTER[param[1]], param[0], pyg_default_as_c_literal(param)))
else:
out.write(' %s %s() const { return p.%s("%s", %s); }\n' %
(TYPE2CTYPE[param[1]], to_c_method(param[0]), TYPE2GETTER[param[1]], param[0], pyg_default_as_c_literal(param)))
out.write('};\n')
if is_verbose():
print "Generated '%s'" % hpp
def max_memory_param():
return ('max_memory', UINT, UINT_MAX, 'maximum amount of memory in megabytes')
def max_steps_param():
return ('max_steps', UINT, UINT_MAX, 'maximum number of steps')
PYG_GLOBALS = { 'UINT' : UINT, 'BOOL' : BOOL, 'DOUBLE' : DOUBLE, 'STRING' : STRING, 'SYMBOL' : SYMBOL,
'UINT_MAX' : UINT_MAX,
'max_memory_param' : max_memory_param,
'max_steps_param' : max_steps_param,
'def_module_params' : def_module_params }
# Execute python auxiliary scripts that generate extra code for Z3.
def exec_pyg_scripts():
global CURR_PYG
for root, dirs, files in os.walk('src'):
for f in files:
if f.endswith('.pyg'):
script = os.path.join(root, f)
CURR_PYG = script
execfile(script, PYG_GLOBALS)
# TODO: delete after src/ast/pattern/expr_pattern_match
# database.smt ==> database.h
@ -1458,7 +1651,7 @@ def mk_install_tactic_cpp(cnames, path):
probe_pat = re.compile('[ \t]*ADD_PROBE\(.*\)')
for cname in cnames:
c = get_component(cname)
h_files = filter(lambda f: f.endswith('.h'), os.listdir(c.src_dir))
h_files = filter(lambda f: f.endswith('.h') or f.endswith('.hpp'), os.listdir(c.src_dir))
for h_file in h_files:
added_include = False
fin = open("%s/%s" % (c.src_dir, h_file), 'r')
@ -1510,18 +1703,20 @@ def mk_all_install_tactic_cpps():
# This file implements the procedures
# void mem_initialize()
# void mem_finalize()
# This procedures are invoked by the Z3 memory_manager
# These procedures are invoked by the Z3 memory_manager
def mk_mem_initializer_cpp(cnames, path):
initializer_cmds = []
finalizer_cmds = []
fullname = '%s/mem_initializer.cpp' % path
fout = open(fullname, 'w')
fout.write('// Automatically generated file.\n')
initializer_pat = re.compile('[ \t]*ADD_INITIALIZER\(\'([^\']*)\'\)')
finalizer_pat = re.compile('[ \t]*ADD_FINALIZER\(\'([^\']*)\'\)')
initializer_pat = re.compile('[ \t]*ADD_INITIALIZER\(\'([^\']*)\'\)')
# ADD_INITIALIZER with priority
initializer_prio_pat = re.compile('[ \t]*ADD_INITIALIZER\(\'([^\']*)\',[ \t]*(-?[0-9]*)\)')
finalizer_pat = re.compile('[ \t]*ADD_FINALIZER\(\'([^\']*)\'\)')
for cname in cnames:
c = get_component(cname)
h_files = filter(lambda f: f.endswith('.h'), os.listdir(c.src_dir))
h_files = filter(lambda f: f.endswith('.h') or f.endswith('.hpp'), os.listdir(c.src_dir))
for h_file in h_files:
added_include = False
fin = open("%s/%s" % (c.src_dir, h_file), 'r')
@ -1531,15 +1726,22 @@ def mk_mem_initializer_cpp(cnames, path):
if not added_include:
added_include = True
fout.write('#include"%s"\n' % h_file)
initializer_cmds.append(m.group(1))
initializer_cmds.append((m.group(1), 0))
m = initializer_prio_pat.match(line)
if m:
if not added_include:
added_include = True
fout.write('#include"%s"\n' % h_file)
initializer_cmds.append((m.group(1), int(m.group(2))))
m = finalizer_pat.match(line)
if m:
if not added_include:
added_include = True
fout.write('#include"%s"\n' % h_file)
finalizer_cmds.append(m.group(1))
initializer_cmds.sort(key=lambda tup: tup[1])
fout.write('void mem_initialize() {\n')
for cmd in initializer_cmds:
for (cmd, prio) in initializer_cmds:
fout.write(cmd)
fout.write('\n')
fout.write('}\n')
@ -1560,6 +1762,63 @@ def mk_all_mem_initializer_cpps():
cnames.append(c.name)
mk_mem_initializer_cpp(cnames, c.src_dir)
# Generate an mem_initializer.cpp at path.
# This file implements the procedure
# void gparams_register_modules()
# This procedure is invoked by gparams::init()
def mk_gparams_register_modules(cnames, path):
cmds = []
mod_cmds = []
mod_descrs = []
fullname = '%s/gparams_register_modules.cpp' % path
fout = open(fullname, 'w')
fout.write('// Automatically generated file.\n')
fout.write('#include"gparams.h"\n')
reg_pat = re.compile('[ \t]*REG_PARAMS\(\'([^\']*)\'\)')
reg_mod_pat = re.compile('[ \t]*REG_MODULE_PARAMS\(\'([^\']*)\', *\'([^\']*)\'\)')
reg_mod_descr_pat = re.compile('[ \t]*REG_MODULE_DESCRIPTION\(\'([^\']*)\', *\'([^\']*)\'\)')
for cname in cnames:
c = get_component(cname)
h_files = filter(lambda f: f.endswith('.h') or f.endswith('.hpp'), os.listdir(c.src_dir))
for h_file in h_files:
added_include = False
fin = open("%s/%s" % (c.src_dir, h_file), 'r')
for line in fin:
m = reg_pat.match(line)
if m:
if not added_include:
added_include = True
fout.write('#include"%s"\n' % h_file)
cmds.append((m.group(1)))
m = reg_mod_pat.match(line)
if m:
if not added_include:
added_include = True
fout.write('#include"%s"\n' % h_file)
mod_cmds.append((m.group(1), m.group(2)))
m = reg_mod_descr_pat.match(line)
if m:
mod_descrs.append((m.group(1), m.group(2)))
fout.write('void gparams_register_modules() {\n')
for code in cmds:
fout.write('{ param_descrs d; %s(d); gparams::register_global(d); }\n' % code)
for (mod, code) in mod_cmds:
fout.write('{ param_descrs * d = alloc(param_descrs); %s(*d); gparams::register_module("%s", d); }\n' % (code, mod))
for (mod, descr) in mod_descrs:
fout.write('gparams::register_module_descr("%s", "%s");\n' % (mod, descr))
fout.write('}\n')
if VERBOSE:
print "Generated '%s'" % fullname
def mk_all_gparams_register_modules():
if not ONLY_MAKEFILES:
for c in get_components():
if c.require_mem_initializer():
cnames = []
cnames.extend(c.deps)
cnames.append(c.name)
mk_gparams_register_modules(cnames, c.src_dir)
# Generate a .def based on the files at c.export_files slot.
def mk_def_file(c):
pat1 = re.compile(".*Z3_API.*")
@ -1796,7 +2055,7 @@ def mk_z3consts_java(api_files):
java = get_component(JAVA_COMPONENT)
DeprecatedEnums = [ 'Z3_search_failure' ]
gendir = java.src_dir + "/" + java.package_name.replace(".", "/") + "/Enumerations"
gendir = java.src_dir + "/enumerations"
if not os.path.exists(gendir):
os.mkdir(gendir)
@ -1847,15 +2106,32 @@ def mk_z3consts_java(api_files):
if name not in DeprecatedEnums:
efile = open('%s/%s.java' % (gendir, name), 'w')
efile.write('/**\n * Automatically generated file\n **/\n\n')
efile.write('package %s;\n\n' % java.package_name);
efile.write('package %s.enumerations;\n\n' % java.package_name);
efile.write('/**\n')
efile.write(' * %s\n' % name)
efile.write(' **/\n')
efile.write('public enum %s {\n' % name)
efile.write
first = True
for k, i in decls.iteritems():
efile.write('%s (%s),\n' % (k, i))
if first:
first = False
else:
efile.write(',\n')
efile.write(' %s (%s)' % (k, i))
efile.write(";\n")
efile.write('\n private final int intValue;\n\n')
efile.write(' %s(int v) {\n' % name)
efile.write(' this.intValue = v;\n')
efile.write(' }\n\n')
efile.write(' public static final %s fromInt(int v) {\n' % name)
efile.write(' for (%s k: values()) \n' % name)
efile.write(' if (k.intValue == v) return k;\n')
efile.write(' return values()[0];\n')
efile.write(' }\n\n')
efile.write(' public final int toInt() { return this.intValue; }\n')
# efile.write(';\n %s(int v) {}\n' % name)
efile.write('}\n\n')
efile.close()
mode = SEARCHING
@ -1965,3 +2241,8 @@ def mk_win_dist(build_path, dist_path):
for pyc in filter(lambda f: f.endswith('.pyc'), os.listdir(build_path)):
shutil.copy('%s/%s' % (build_path, pyc),
'%s/bin/%s' % (dist_path, pyc))
if __name__ == '__main__':
import doctest
doctest.testmod()

View file

@ -252,11 +252,11 @@ def param2java(p):
k = param_kind(p)
if k == OUT:
if param_type(p) == INT or param_type(p) == UINT:
return "Integer"
return "IntPtr"
elif param_type(p) == INT64 or param_type(p) == UINT64 or param_type(p) >= FIRST_OBJ_ID:
return "Long"
return "LongPtr"
elif param_type(p) == STRING:
return "String"
return "StringPtr"
else:
print "ERROR: unreachable code"
assert(False)
@ -468,54 +468,35 @@ def java_method_name(name):
i = i + 1
return result
# Return the Java method name used to retrieve the elements of the given parameter
def java_get_array_elements(p):
if param_type(p) == INT or param_type(p) == UINT:
return 'GetIntArrayElements'
else:
return 'GetLongArrayElements'
# Return the Java method name used to release the elements of the given parameter
def java_release_array_elements(p):
if param_type(p) == INT or param_type(p) == UINT:
return 'ReleaseIntArrayElements'
else:
return 'ReleaseLongArrayElements'
# Return the type of the java array elements
def java_array_element_type(p):
if param_type(p) == INT or param_type(p) == UINT:
return 'jint'
else:
return 'jlong'
def java_set_array_region(p):
if param_type(p) == INT or param_type(p) == UINT:
return 'SetIntArrayRegion'
else:
return 'SetLongArrayRegion'
def mk_java():
if not is_java_enabled():
return
java_dir = get_component('java').src_dir
try:
os.mkdir('%s/com/Microsoft/Z3/' % java_dir)
except:
pass # OK if it exists already.
java_nativef = '%s/com/Microsoft/Z3/Native.java' % java_dir
java_wrapperf = '%s/com/Microsoft/Z3/Native.c' % java_dir
java_nativef = '%s/Native.java' % java_dir
java_wrapperf = '%s/Native.cpp' % java_dir
java_native = open(java_nativef, 'w')
java_native.write('// Automatically generated file\n')
java_native.write('package com.Microsoft.Z3;\n')
java_native.write('package %s;\n' % get_component('java').package_name)
java_native.write('import %s.enumerations.*;\n' % get_component('java').package_name)
java_native.write('public final class Native {\n')
java_native.write(' public static class IntPtr { public int value; }\n')
java_native.write(' public static class LongPtr { public long value; }\n')
java_native.write(' public static class StringPtr { public String value; }\n')
if is_windows():
java_native.write(' static { System.loadLibrary("%s"); }\n' % get_component('java'))
java_native.write(' public static native void setInternalErrorHandler(long ctx);\n\n')
if IS_WINDOWS:
java_native.write(' static { System.loadLibrary("%s"); }\n' % get_component('java').dll_name)
else:
java_native.write(' static { System.loadLibrary("%s"); }\n' % get_component('java').dll_name[3:]) # We need 3: to extract the prexi 'lib' form the dll_name
java_native.write('\n')
for name, result, params in _dotnet_decls:
java_native.write(' public static native %s %s(' % (type2java(result), java_method_name(name)))
java_native.write(' protected static native %s INTERNAL%s(' % (type2java(result), java_method_name(name)))
first = True
i = 0;
for param in params:
@ -526,22 +507,108 @@ def mk_java():
java_native.write('%s a%d' % (param2java(param), i))
i = i + 1
java_native.write(');\n')
java_native.write(' public static void main(String[] args) {\n')
java_native.write(' IntPtr major = new IntPtr(), minor = new IntPtr(), build = new IntPtr(), revision = new IntPtr();\n')
java_native.write(' getVersion(major, minor, build, revision);\n')
java_native.write(' System.out.format("Z3 (for Java) %d.%d.%d%n", major.value, minor.value, build.value);\n')
java_native.write(' }\n')
java_native.write('}\n');
java_native.write('\n\n')
# Exception wrappers
for name, result, params in _dotnet_decls:
java_native.write(' public static %s %s(' % (type2java(result), java_method_name(name)))
first = True
i = 0;
for param in params:
if first:
first = False
else:
java_native.write(', ')
java_native.write('%s a%d' % (param2java(param), i))
i = i + 1
java_native.write(')')
if len(params) > 0 and param_type(params[0]) == CONTEXT:
java_native.write(' throws Z3Exception')
java_native.write('\n')
java_native.write(' {\n')
java_native.write(' ')
if result != VOID:
java_native.write('%s res = ' % type2java(result))
java_native.write('INTERNAL%s(' % (java_method_name(name)))
first = True
i = 0;
for param in params:
if first:
first = False
else:
java_native.write(', ')
java_native.write('a%d' % i)
i = i + 1
java_native.write(');\n')
if len(params) > 0 and param_type(params[0]) == CONTEXT:
java_native.write(' Z3_error_code err = Z3_error_code.fromInt(INTERNALgetErrorCode(a0));\n')
java_native.write(' if (err != Z3_error_code.Z3_OK)\n')
java_native.write(' throw new Z3Exception(INTERNALgetErrorMsgEx(a0, err.toInt()));\n')
if result != VOID:
java_native.write(' return res;\n')
java_native.write(' }\n\n')
java_native.write('}\n')
java_wrapper = open(java_wrapperf, 'w')
pkg_str = get_component('java').package_name.replace('.', '_')
java_wrapper.write('// Automatically generated file\n')
java_wrapper.write('#include<jni.h>\n')
java_wrapper.write('#include<stdlib.h>\n')
java_wrapper.write('#include"z3.h"\n')
java_wrapper.write('#ifdef __cplusplus\n')
java_wrapper.write('extern "C" {\n')
java_wrapper.write('#endif\n')
java_wrapper.write('#endif\n\n')
java_wrapper.write('#if defined(_M_X64) || defined(_AMD64_)\n\n')
java_wrapper.write('#define GETLONGAELEMS(T,OLD,NEW) \\\n')
java_wrapper.write(' T * NEW = (OLD == 0) ? 0 : (T*) jenv->GetLongArrayElements(OLD, NULL);\n')
java_wrapper.write('#define RELEASELONGAELEMS(OLD,NEW) \\\n')
java_wrapper.write(' if (OLD != 0) jenv->ReleaseLongArrayElements(OLD, (jlong *) NEW, JNI_ABORT); \n\n')
java_wrapper.write('#define GETLONGAREGION(T,OLD,Z,SZ,NEW) \\\n')
java_wrapper.write(' jenv->GetLongArrayRegion(OLD,Z,(jsize)SZ,(jlong*)NEW); \n')
java_wrapper.write('#define SETLONGAREGION(OLD,Z,SZ,NEW) \\\n')
java_wrapper.write(' jenv->SetLongArrayRegion(OLD,Z,(jsize)SZ,(jlong*)NEW) \n\n')
java_wrapper.write('#else\n\n')
java_wrapper.write('#define GETLONGAELEMS(T,OLD,NEW) \\\n')
java_wrapper.write(' T * NEW = 0; { \\\n')
java_wrapper.write(' jlong * temp = (OLD == 0) ? 0 : jenv->GetLongArrayElements(OLD, NULL); \\\n')
java_wrapper.write(' unsigned int size = (OLD == 0) ? 0 :jenv->GetArrayLength(OLD); \\\n')
java_wrapper.write(' if (OLD != 0) { \\\n')
java_wrapper.write(' NEW = (T*) (new int[size]); \\\n')
java_wrapper.write(' for (unsigned i=0; i < size; i++) \\\n')
java_wrapper.write(' NEW[i] = reinterpret_cast<T>(temp[i]); \\\n')
java_wrapper.write(' jenv->ReleaseLongArrayElements(OLD, temp, JNI_ABORT); \\\n')
java_wrapper.write(' } \\\n')
java_wrapper.write(' } \n\n')
java_wrapper.write('#define RELEASELONGAELEMS(OLD,NEW) \\\n')
java_wrapper.write(' delete [] NEW; \n\n')
java_wrapper.write('#define GETLONGAREGION(T,OLD,Z,SZ,NEW) \\\n')
java_wrapper.write(' { \\\n')
java_wrapper.write(' jlong * temp = new jlong[SZ]; \\\n')
java_wrapper.write(' jenv->GetLongArrayRegion(OLD,Z,(jsize)SZ,(jlong*)temp); \\\n')
java_wrapper.write(' for (int i = 0; i < (SZ); i++) \\\n')
java_wrapper.write(' NEW[i] = reinterpret_cast<T>(temp[i]); \\\n')
java_wrapper.write(' delete [] temp; \\\n')
java_wrapper.write(' }\n\n')
java_wrapper.write('#define SETLONGAREGION(OLD,Z,SZ,NEW) \\\n')
java_wrapper.write(' { \\\n')
java_wrapper.write(' jlong * temp = new jlong[SZ]; \\\n')
java_wrapper.write(' for (int i = 0; i < (SZ); i++) \\\n')
java_wrapper.write(' temp[i] = reinterpret_cast<jlong>(NEW[i]); \\\n')
java_wrapper.write(' jenv->SetLongArrayRegion(OLD,Z,(jsize)SZ,temp); \\\n')
java_wrapper.write(' delete [] temp; \\\n')
java_wrapper.write(' }\n\n')
java_wrapper.write('#endif\n\n')
java_wrapper.write('void Z3JavaErrorHandler(Z3_context c, Z3_error_code e)\n')
java_wrapper.write('{\n')
java_wrapper.write(' // Internal do-nothing error handler. This is required to avoid that Z3 calls exit()\n')
java_wrapper.write(' // upon errors, but the actual error handling is done by throwing exceptions in the\n')
java_wrapper.write(' // wrappers below.\n')
java_wrapper.write('}\n\n')
java_wrapper.write('JNIEXPORT void JNICALL Java_%s_Native_setInternalErrorHandler(JNIEnv * jenv, jclass cls, jlong a0)\n' % pkg_str)
java_wrapper.write('{\n')
java_wrapper.write(' Z3_set_error_handler((Z3_context)a0, Z3JavaErrorHandler);\n')
java_wrapper.write('}\n\n')
java_wrapper.write('')
for name, result, params in _dotnet_decls:
java_wrapper.write('JNIEXPORT %s JNICALL Java_Z3Native_%s(JNIEnv * jenv, jclass cls' % (type2javaw(result), java_method_name(name)))
java_wrapper.write('JNIEXPORT %s JNICALL Java_%s_Native_INTERNAL%s(JNIEnv * jenv, jclass cls' % (type2javaw(result), pkg_str, java_method_name(name)))
i = 0;
for param in params:
java_wrapper.write(', ')
@ -555,17 +622,20 @@ def mk_java():
if k == OUT or k == INOUT:
java_wrapper.write(' %s _a%s;\n' % (type2str(param_type(param)), i))
elif k == IN_ARRAY or k == INOUT_ARRAY:
java_wrapper.write(' %s * _a%s = (%s *) jenv->%s(a%s, NULL);\n' % (type2str(param_type(param)),
i,
type2str(param_type(param)),
java_get_array_elements(param),
i))
if param_type(param) == INT or param_type(param) == UINT:
java_wrapper.write(' %s * _a%s = (%s*) jenv->GetIntArrayElements(a%s, NULL);\n' % (type2str(param_type(param)), i, type2str(param_type(param)), i))
else:
java_wrapper.write(' GETLONGAELEMS(%s, a%s, _a%s);\n' % (type2str(param_type(param)), i, i))
elif k == OUT_ARRAY:
java_wrapper.write(' %s * _a%s = (%s *) malloc(((unsigned)a%s) * sizeof(%s));\n' % (type2str(param_type(param)),
i,
type2str(param_type(param)),
param_array_capacity_pos(param),
type2str(param_type(param))))
if param_type(param) == INT or param_type(param) == UINT:
java_wrapper.write(' jenv->GetIntArrayRegion(a%s, 0, (jsize)a%s, (jint*)_a%s);\n' % (i, param_array_capacity_pos(param), i))
else:
java_wrapper.write(' GETLONGAREGION(%s, a%s, 0, a%s, _a%s);\n' % (type2str(param_type(param)), i, param_array_capacity_pos(param), i))
elif k == IN and param_type(param) == STRING:
java_wrapper.write(' Z3_string _a%s = (Z3_string) jenv->GetStringUTFChars(a%s, NULL);\n' % (i, i))
i = i + 1
@ -597,17 +667,17 @@ def mk_java():
for param in params:
k = param_kind(param)
if k == OUT_ARRAY:
java_wrapper.write(' jenv->%s(a%s, 0, (jsize)a%s, (%s *) _a%s);\n' % (java_set_array_region(param),
i,
param_array_capacity_pos(param),
java_array_element_type(param),
i))
if param_type(param) == INT or param_type(param) == UINT:
java_wrapper.write(' jenv->SetIntArrayRegion(a%s, 0, (jsize)a%s, (jint*)_a%s);\n' % (i, param_array_capacity_pos(param), i))
else:
java_wrapper.write(' SETLONGAREGION(a%s, 0, a%s, _a%s);\n' % (i, param_array_capacity_pos(param), i))
java_wrapper.write(' free(_a%s);\n' % i)
elif k == IN_ARRAY or k == OUT_ARRAY:
java_wrapper.write(' jenv->%s(a%s, (%s *) _a%s, JNI_ABORT);\n' % (java_release_array_elements(param),
i,
java_array_element_type(param),
i))
if param_type(param) == INT or param_type(param) == UINT:
java_wrapper.write(' jenv->ReleaseIntArrayElements(a%s, (jint*)_a%s, JNI_ABORT);\n' % (i, i))
else:
java_wrapper.write(' RELEASELONGAELEMS(a%s, _a%s);\n' % (i, i))
elif k == OUT or k == INOUT:
if param_type(param) == INT or param_type(param) == UINT:
java_wrapper.write(' {\n')
@ -626,7 +696,7 @@ def mk_java():
if result == STRING:
java_wrapper.write(' return jenv->NewStringUTF(result);\n')
elif result != VOID:
java_wrapper.write(' return (%s) result;\n' % type2javaw(result))
java_wrapper.write(' return (%s) result;\n' % type2javaw(result))
java_wrapper.write('}\n')
java_wrapper.write('#ifdef __cplusplus\n')
java_wrapper.write('}\n')

View file

@ -36,6 +36,7 @@ Revision History:
#include"scoped_ctrl_c.h"
#include"cancel_eh.h"
#include"scoped_timer.h"
#include"pp_params.hpp"
extern "C" {
@ -674,8 +675,8 @@ extern "C" {
ast_manager & m = mk_c(c)->m();
expr * a = to_expr(_a);
params_ref p = to_param_ref(_p);
unsigned timeout = p.get_uint(":timeout", UINT_MAX);
bool use_ctrl_c = p.get_bool(":ctrl-c", false);
unsigned timeout = p.get_uint("timeout", mk_c(c)->get_timeout());
bool use_ctrl_c = p.get_bool("ctrl_c", false);
th_rewriter m_rw(m, p);
expr_ref result(m);
cancel_eh<th_rewriter> eh(m_rw);
@ -833,7 +834,8 @@ extern "C" {
break;
case Z3_PRINT_SMTLIB_COMPLIANT: {
ast_smt_pp pp(mk_c(c)->m());
pp.set_simplify_implies(get_pp_default_params().m_pp_simplify_implies);
pp_params params;
pp.set_simplify_implies(params.simplify_implies());
ast* a1 = to_ast(a);
pp.set_logic(mk_c(c)->fparams().m_smtlib_logic.c_str());
if (!is_expr(a1)) {
@ -886,7 +888,8 @@ extern "C" {
pp.set_logic(logic);
pp.set_status(status);
pp.add_attributes(attributes);
pp.set_simplify_implies(get_pp_default_params().m_pp_simplify_implies);
pp_params params;
pp.set_simplify_implies(params.simplify_implies());
for (unsigned i = 0; i < num_assumptions; ++i) {
pp.add_assumption(to_expr(assumptions[i]));
}

View file

@ -17,106 +17,99 @@ Revision History:
--*/
#include"z3.h"
#include"api_context.h"
#include"api_config_params.h"
#include"pp.h"
#include"api_log_macros.h"
#include"api_util.h"
#include"cmd_context.h"
#include"symbol.h"
namespace api {
config_params::config_params():
m_ini(false /* do not abort on errors */) {
register_verbosity_level(m_ini);
register_warning(m_ini);
m_params.register_params(m_ini);
register_pp_params(m_ini);
}
config_params::config_params(front_end_params const & p):m_params(p) {
register_verbosity_level(m_ini);
register_warning(m_ini);
register_pp_params(m_ini);
}
};
extern std::string smt_keyword2opt_name(symbol const & opt);
#include"gparams.h"
#include"env_params.h"
#include"context_params.h"
extern "C" {
void Z3_API Z3_global_param_set(Z3_string param_id, Z3_string param_value) {
memory::initialize(UINT_MAX);
LOG_Z3_global_param_set(param_id, param_value);
try {
gparams::set(param_id, param_value);
env_params::updt_params();
}
catch (z3_exception & ex) {
// The error handler is only available for contexts
// Just throw a warning.
std::ostringstream buffer;
buffer << "Error setting " << param_id << ", " << ex.msg();
warning_msg(buffer.str().c_str());
}
}
void Z3_API Z3_global_param_reset_all() {
memory::initialize(UINT_MAX);
LOG_Z3_global_param_reset_all();
gparams::reset();
env_params::updt_params();
}
std::string g_Z3_global_param_get_buffer;
Z3_bool_opt Z3_API Z3_global_param_get(Z3_string param_id, Z3_string_ptr param_value) {
memory::initialize(UINT_MAX);
LOG_Z3_global_param_get(param_id, param_value);
*param_value = 0;
try {
g_Z3_global_param_get_buffer = gparams::get_value(param_id);
*param_value = g_Z3_global_param_get_buffer.c_str();
return Z3_TRUE;
}
catch (z3_exception & ex) {
// The error handler is only available for contexts
// Just throw a warning.
std::ostringstream buffer;
buffer << "Error setting " << param_id << ": " << ex.msg();
warning_msg(buffer.str().c_str());
return Z3_FALSE;
}
}
Z3_config Z3_API Z3_mk_config() {
memory::initialize(UINT_MAX);
LOG_Z3_mk_config();
memory::initialize(0);
Z3_config r = reinterpret_cast<Z3_config>(alloc(api::config_params));
Z3_config r = reinterpret_cast<Z3_config>(alloc(context_params));
RETURN_Z3(r);
}
void Z3_API Z3_del_config(Z3_config c) {
LOG_Z3_del_config(c);
dealloc((reinterpret_cast<api::config_params*>(c)));
dealloc((reinterpret_cast<context_params*>(c)));
}
void Z3_API Z3_set_param_value(Z3_config c, char const * param_id, char const * param_value) {
try {
LOG_Z3_set_param_value(c, param_id, param_value);
api::config_params* p = reinterpret_cast<api::config_params*>(c);
if (param_id != 0 && param_id[0] == ':') {
// Allow SMT2 style paramater names such as :model, :relevancy, etc
std::string new_param_id = smt_keyword2opt_name(symbol(param_id));
p->m_ini.set_param_value(new_param_id.c_str(), param_value);
}
else {
p->m_ini.set_param_value(param_id, param_value);
}
LOG_Z3_set_param_value(c, param_id, param_value);
try {
context_params * p = reinterpret_cast<context_params*>(c);
p->set(param_id, param_value);
}
catch (set_get_param_exception & ex) {
// The error handler was not set yet.
catch (z3_exception & ex) {
// The error handler is only available for contexts
// Just throw a warning.
std::ostringstream buffer;
buffer << "Error setting " << param_id << ", " << ex.get_msg();
buffer << "Error setting " << param_id << ": " << ex.msg();
warning_msg(buffer.str().c_str());
}
}
void Z3_API Z3_update_param_value(Z3_context c, Z3_string param_id, Z3_string param_value) {
Z3_TRY;
LOG_Z3_update_param_value(c, param_id, param_value);
RESET_ERROR_CODE();
ini_params ini;
mk_c(c)->fparams().register_params(ini);
register_pp_params(ini);
register_verbosity_level(ini);
register_warning(ini);
if (mk_c(c)->has_solver()) {
ini.freeze();
}
if (param_id != 0 && param_id[0] == ':') {
// Allow SMT2 style paramater names such as :model, :relevancy, etc
std::string new_param_id = smt_keyword2opt_name(symbol(param_id));
ini.set_param_value(new_param_id.c_str(), param_value);
}
else {
ini.set_param_value(param_id, param_value);
}
memory::set_high_watermark(static_cast<size_t>(mk_c(c)->fparams().m_memory_high_watermark)*1024*1024);
memory::set_max_size(static_cast<size_t>(mk_c(c)->fparams().m_memory_max_size)*1024*1024);
mk_c(c)->params().set(param_id, param_value);
Z3_CATCH;
}
Z3_bool Z3_API Z3_get_param_value(Z3_context c, Z3_string param_id, Z3_string* param_value) {
LOG_Z3_get_param_value(c, param_id, param_value);
ini_params ini;
mk_c(c)->fparams().register_params(ini);
register_verbosity_level(ini);
register_pp_params(ini);
register_warning(ini);
std::string param_value_s;
if (!ini.get_param_value(param_id, param_value_s)) {
if (param_value) *param_value = 0;
return false;
}
if (param_value) {
*param_value = mk_c(c)->mk_external_string(param_value_s);
}
return true;
// TODO
return Z3_FALSE;
}
};

View file

@ -1,36 +0,0 @@
/*++
Copyright (c) 2012 Microsoft Corporation
Module Name:
api_config_params.h
Abstract:
Configuration parameters
Author:
Leonardo de Moura (leonardo) 2012-02-29.
Revision History:
--*/
#ifndef _API_CONFIG_PARAMS_H_
#define _API_CONFIG_PARAMS_H_
#include"ini_file.h"
#include"front_end_params.h"
namespace api {
class config_params {
public:
ini_params m_ini;
front_end_params m_params;
config_params();
config_params(front_end_params const & p);
};
};
#endif

View file

@ -18,7 +18,6 @@ Revision History:
--*/
#include"api_context.h"
#include"api_config_params.h"
#include"smtparser.h"
#include"version.h"
#include"ast_pp.h"
@ -54,14 +53,6 @@ namespace api {
return static_cast<Z3_search_failure>(f);
}
context::param_ini::param_ini(front_end_params & p) : m_params(p) {
p.open_trace_file();
}
context::param_ini::~param_ini() {
m_params.close_trace_file();
}
context::add_plugins::add_plugins(ast_manager & m) {
reg_decl_plugins(m);
}
@ -88,11 +79,10 @@ namespace api {
}
}
context::context(config_params * p, bool user_ref_count):
m_params(p ? p->m_params : front_end_params()),
m_param_ini(m_params),
context::context(context_params * p, bool user_ref_count):
m_params(p != 0 ? *p : context_params()),
m_user_ref_count(user_ref_count),
m_manager(m_params.m_proof_mode, m_params.m_trace_stream),
m_manager(m_params.m_proof ? PGM_FINE : PGM_DISABLED, m_params.m_trace ? m_params.m_trace_file_name.c_str() : 0),
m_plugins(m_manager),
m_arith_util(m_manager),
m_bv_util(m_manager),
@ -115,8 +105,6 @@ namespace api {
//
// Configuration parameter settings.
//
memory::set_high_watermark(static_cast<size_t>(m_params.m_memory_high_watermark)*1024*1024);
memory::set_max_size(static_cast<size_t>(m_params.m_memory_max_size)*1024*1024);
if (m_params.m_debug_ref_count) {
m_manager.debug_ref_count();
}
@ -335,7 +323,8 @@ namespace api {
smt::kernel & context::get_smt_kernel() {
if (!m_solver) {
m_solver = alloc(smt::kernel, m_manager, m_params);
m_fparams.updt_params(m_params);
m_solver = alloc(smt::kernel, m_manager, m_fparams);
}
return *m_solver;
}
@ -420,15 +409,15 @@ extern "C" {
Z3_context Z3_API Z3_mk_context(Z3_config c) {
LOG_Z3_mk_context(c);
memory::initialize(0);
Z3_context r = reinterpret_cast<Z3_context>(alloc(api::context, reinterpret_cast<api::config_params*>(c), false));
memory::initialize(UINT_MAX);
Z3_context r = reinterpret_cast<Z3_context>(alloc(api::context, reinterpret_cast<context_params*>(c), false));
RETURN_Z3(r);
}
Z3_context Z3_API Z3_mk_context_rc(Z3_config c) {
LOG_Z3_mk_context_rc(c);
memory::initialize(0);
Z3_context r = reinterpret_cast<Z3_context>(alloc(api::context, reinterpret_cast<api::config_params*>(c), true));
memory::initialize(UINT_MAX);
Z3_context r = reinterpret_cast<Z3_context>(alloc(api::context, reinterpret_cast<context_params*>(c), true));
RETURN_Z3(r);
}
@ -574,11 +563,4 @@ ast_manager & Z3_API Z3_get_manager(__in Z3_context c) {
return mk_c(c)->m();
}
front_end_params& Z3_API Z3_get_parameters(__in Z3_context c) {
return mk_c(c)->fparams();
}
Z3_context Z3_mk_context_from_params(front_end_params const& p) {
api::config_params cp(p);
return reinterpret_cast<Z3_context>(alloc(api::context, &cp));
}

View file

@ -28,32 +28,22 @@ Revision History:
#include"datatype_decl_plugin.h"
#include"dl_decl_plugin.h"
#include"smt_kernel.h"
#include"front_end_params.h"
#include"smt_params.h"
#include"event_handler.h"
#include"tactic_manager.h"
#include"context_params.h"
namespace smtlib {
class parser;
};
namespace api {
class config_params;
Z3_search_failure mk_Z3_search_failure(smt::failure f);
class context : public tactic_manager {
class param_ini {
front_end_params & m_params;
public:
param_ini(front_end_params & p);
~param_ini();
};
struct add_plugins { add_plugins(ast_manager & m); };
front_end_params m_params;
param_ini m_param_ini;
context_params m_params;
bool m_user_ref_count; //!< if true, the user is responsible for managing referenc counters.
ast_manager m_manager;
add_plugins m_plugins;
@ -62,8 +52,11 @@ namespace api {
bv_util m_bv_util;
datalog::dl_decl_util m_datalog_util;
// Support for old solver API
smt_params m_fparams;
smt::kernel * m_solver; // General purpose solver for backward compatibility
// -------------------------------
ast_ref_vector m_last_result; //!< used when m_user_ref_count == true
ast_ref_vector m_ast_trail; //!< used when m_user_ref_count == false
unsigned_vector m_ast_lim;
@ -103,11 +96,16 @@ namespace api {
//
// ------------------------
context(config_params * p, bool user_ref_count = false);
context(context_params * p, bool user_ref_count = false);
~context();
front_end_params & fparams() { return m_params; }
ast_manager & m() { return m_manager; }
context_params & params() { return m_params; }
bool produce_proofs() const { return m_manager.proofs_enabled(); }
bool produce_models() const { return m_params.m_model; }
bool produce_unsat_cores() const { return m_params.m_unsat_core; }
bool use_auto_config() const { return m_params.m_auto_config; }
unsigned get_timeout() const { return m_params.m_timeout; }
arith_util & autil() { return m_arith_util; }
bv_util & bvutil() { return m_bv_util; }
datalog::dl_decl_util & datalog_util() { return m_datalog_util; }
@ -168,12 +166,13 @@ namespace api {
static void out_of_memory_handler(void * _ctx);
void check_sorts(ast * n);
// ------------------------
//
// Solver interface for backward compatibility
//
// ------------------------
smt_params & fparams() { return m_fparams; }
bool has_solver() const { return m_solver != 0; }
smt::kernel & get_smt_kernel();
void assert_cnstr(expr * a);

View file

@ -32,7 +32,7 @@ Revision History:
namespace api {
fixedpoint_context::fixedpoint_context(ast_manager& m, front_end_params& p) :
fixedpoint_context::fixedpoint_context(ast_manager& m, smt_params& p) :
m_state(0),
m_reduce_app(0),
m_reduce_assign(0),
@ -48,7 +48,7 @@ namespace api {
if (!m.has_plugin(name)) {
m.register_plugin(name, alloc(datalog::dl_decl_plugin));
}
datalog::relation_manager& r = m_context.get_rmanager();
datalog::relation_manager& r = m_context.get_rel_context().get_rmanager();
r.register_plugin(alloc(datalog::external_relation_plugin, *this, r));
}
@ -265,7 +265,7 @@ extern "C" {
RESET_ERROR_CODE();
lbool r = l_undef;
cancel_eh<api::fixedpoint_context> eh(*to_fixedpoint_ref(d));
unsigned timeout = to_fixedpoint(d)->m_params.get_uint(":timeout", UINT_MAX);
unsigned timeout = to_fixedpoint(d)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
api::context::set_interruptable(*(mk_c(c)), eh);
{
scoped_timer timer(timeout, &eh);
@ -289,13 +289,13 @@ extern "C" {
LOG_Z3_fixedpoint_query_relations(c, d, num_relations, relations);
RESET_ERROR_CODE();
lbool r = l_undef;
unsigned timeout = to_fixedpoint(d)->m_params.get_uint(":timeout", UINT_MAX);
unsigned timeout = to_fixedpoint(d)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
cancel_eh<api::fixedpoint_context> eh(*to_fixedpoint_ref(d));
api::context::set_interruptable(*(mk_c(c)), eh);
{
scoped_timer timer(timeout, &eh);
try {
r = to_fixedpoint_ref(d)->ctx().dl_query(num_relations, to_func_decls(relations));
r = to_fixedpoint_ref(d)->ctx().rel_query(num_relations, to_func_decls(relations));
}
catch (z3_exception& ex) {
mk_c(c)->handle_exception(ex);
@ -344,7 +344,7 @@ extern "C" {
std::istream& s) {
ast_manager& m = mk_c(c)->m();
dl_collected_cmds coll(m);
cmd_context ctx(&mk_c(c)->fparams(), false, &m);
cmd_context ctx(false, &m);
install_dl_collect_cmds(coll, ctx);
ctx.set_ignore_check(true);
if (!parse_smt2_commands(ctx, s)) {

View file

@ -21,7 +21,7 @@ Revision History:
#include"z3.h"
#include"ast.h"
#include"front_end_params.h"
#include"smt_params.h"
#include"dl_external_relation.h"
#include"dl_decl_plugin.h"
#include"smt_kernel.h"
@ -40,7 +40,7 @@ namespace api {
datalog::context m_context;
ast_ref_vector m_trail;
public:
fixedpoint_context(ast_manager& m, front_end_params& p);
fixedpoint_context(ast_manager& m, smt_params& p);
virtual ~fixedpoint_context() {}
family_id get_family_id() const { return const_cast<datalog::context&>(m_context).get_decl_util().get_family_id(); }
void set_state(void* state);

View file

@ -25,6 +25,7 @@ Revision History:
#include"model.h"
#include"model_v2_pp.h"
#include"model_smt2_pp.h"
#include"model_params.hpp"
extern "C" {
@ -200,7 +201,7 @@ extern "C" {
LOG_Z3_get_as_array_func_decl(c, a);
RESET_ERROR_CODE();
if (is_expr(to_ast(a)) && is_app_of(to_expr(a), mk_c(c)->get_array_fid(), OP_AS_ARRAY)) {
return of_func_decl(to_func_decl(to_app(a)->get_decl()->get_parameter(0).get_ast()));
RETURN_Z3(of_func_decl(to_func_decl(to_app(a)->get_decl()->get_parameter(0).get_ast())));
}
else {
SET_ERROR_CODE(Z3_INVALID_ARG);
@ -488,7 +489,8 @@ extern "C" {
Z3_model m,
Z3_ast t,
Z3_ast * v) {
return Z3_model_eval(c, m, t, mk_c(c)->fparams().m_model_completion, v);
model_params p;
return Z3_model_eval(c, m, t, p.completion(), v);
}
Z3_bool Z3_API Z3_eval_func_decl(Z3_context c,
@ -660,7 +662,8 @@ extern "C" {
result.resize(result.size()-1);
}
else {
model_v2_pp(buffer, *(to_model_ref(m)), mk_c(c)->fparams().m_model_partial);
model_params p;
model_v2_pp(buffer, *(to_model_ref(m)), p.partial());
result = buffer.str();
}
return mk_c(c)->mk_external_string(result);

View file

@ -66,7 +66,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_params_set_bool(c, p, k, v);
RESET_ERROR_CODE();
to_params(p)->m_params.set_bool(to_symbol(k), v != 0);
to_params(p)->m_params.set_bool(norm_param_name(to_symbol(k)).c_str(), v != 0);
Z3_CATCH;
}
@ -77,7 +77,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_params_set_uint(c, p, k, v);
RESET_ERROR_CODE();
to_params(p)->m_params.set_uint(to_symbol(k), v);
to_params(p)->m_params.set_uint(norm_param_name(to_symbol(k)).c_str(), v);
Z3_CATCH;
}
@ -88,7 +88,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_params_set_double(c, p, k, v);
RESET_ERROR_CODE();
to_params(p)->m_params.set_double(to_symbol(k), v);
to_params(p)->m_params.set_double(norm_param_name(to_symbol(k)).c_str(), v);
Z3_CATCH;
}
@ -99,7 +99,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_params_set_symbol(c, p, k, v);
RESET_ERROR_CODE();
to_params(p)->m_params.set_sym(to_symbol(k), to_symbol(v));
to_params(p)->m_params.set_sym(norm_param_name(to_symbol(k)).c_str(), to_symbol(v));
Z3_CATCH;
}

View file

@ -296,7 +296,7 @@ extern "C" {
Z3_symbol const decl_names[],
Z3_func_decl const decls[]) {
Z3_TRY;
cmd_context ctx(&mk_c(c)->fparams(), false, &(mk_c(c)->m()));
cmd_context ctx(false, &(mk_c(c)->m()));
ctx.set_ignore_check(true);
if (exec) {
ctx.set_solver(alloc(z3_context_solver, *mk_c(c)));
@ -362,7 +362,7 @@ extern "C" {
Z3_symbol decl_names[],
Z3_func_decl decls[]) {
Z3_TRY;
cmd_context ctx(&mk_c(c)->fparams(), false, &(mk_c(c)->m()));
cmd_context ctx(false, &(mk_c(c)->m()));
std::string s(str);
std::istringstream is(s);
// No logging for this one, since it private.

View file

@ -36,11 +36,17 @@ extern "C" {
static void init_solver_core(Z3_context c, Z3_solver _s) {
ast_manager & m = mk_c(c)->m();
Z3_solver_ref * s = to_solver(_s);
s->m_solver->set_produce_proofs(m.proofs_enabled());
s->m_solver->set_produce_unsat_cores(s->m_params.get_bool(":unsat-core", false));
s->m_solver->set_produce_models(s->m_params.get_bool(":model", true));
s->m_solver->set_front_end_params(mk_c(c)->fparams());
s->m_solver->updt_params(s->m_params);
s->m_solver->set_produce_proofs(mk_c(c)->produce_proofs());
s->m_solver->set_produce_unsat_cores(s->m_params.get_bool("unsat_core", mk_c(c)->produce_unsat_cores()));
s->m_solver->set_produce_models(s->m_params.get_bool("model", mk_c(c)->produce_models()));
if (!mk_c(c)->use_auto_config()) {
params_ref p = s->m_params;
p.set_bool("auto_config", false);
s->m_solver->updt_params(p);
}
else {
s->m_solver->updt_params(s->m_params);
}
s->m_solver->init(m, s->m_logic);
s->m_initialized = true;
}
@ -127,8 +133,8 @@ extern "C" {
LOG_Z3_solver_set_params(c, s, p);
RESET_ERROR_CODE();
if (to_solver(s)->m_initialized) {
bool old_model = to_solver(s)->m_params.get_bool(":model", true);
bool new_model = to_param_ref(p).get_bool(":model", true);
bool old_model = to_solver(s)->m_params.get_bool("model", true);
bool new_model = to_param_ref(p).get_bool("model", true);
if (old_model != new_model)
to_solver_ref(s)->set_produce_models(new_model);
to_solver_ref(s)->updt_params(to_param_ref(p));
@ -238,8 +244,8 @@ extern "C" {
}
}
expr * const * _assumptions = to_exprs(assumptions);
unsigned timeout = to_solver(s)->m_params.get_uint(":timeout", UINT_MAX);
bool use_ctrl_c = to_solver(s)->m_params.get_bool(":ctrl-c", false);
unsigned timeout = to_solver(s)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
bool use_ctrl_c = to_solver(s)->m_params.get_bool("ctrl_c", false);
cancel_eh<solver> eh(*to_solver_ref(s));
api::context::set_interruptable(*(mk_c(c)), eh);
lbool result;

View file

@ -404,8 +404,8 @@ extern "C" {
Z3_apply_result_ref * ref = alloc(Z3_apply_result_ref, mk_c(c)->m());
mk_c(c)->save_object(ref);
unsigned timeout = p.get_uint(":timeout", UINT_MAX);
bool use_ctrl_c = p.get_bool(":ctrl-c", false);
unsigned timeout = p.get_uint("timeout", UINT_MAX);
bool use_ctrl_c = p.get_bool("ctrl_c", false);
cancel_eh<tactic> eh(*to_tactic_ref(t));
to_tactic_ref(t)->updt_params(p);

View file

@ -64,6 +64,11 @@ namespace z3 {
class apply_result;
class fixedpoint;
inline void set_param(char const * param, char const * value) { Z3_global_param_set(param, value); }
inline void set_param(char const * param, bool value) { Z3_global_param_set(param, value ? "true" : "false"); }
inline void set_param(char const * param, int value) { std::ostringstream oss; oss << value; Z3_global_param_set(param, oss.str().c_str()); }
inline void reset_params() { Z3_global_param_reset_all(); }
/**
\brief Exception used to sign API usage errors.
*/

View file

@ -37,7 +37,6 @@ namespace Microsoft.Z3
#region Internal
internal BitVecSort(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
internal BitVecSort(Context ctx, uint size) : base(ctx, Native.Z3_mk_bv_sort(ctx.nCtx, size)) { Contract.Requires(ctx != null); }
#endregion
};
}

View file

@ -113,7 +113,6 @@ namespace Microsoft.Z3
get
{
Contract.Ensures(Contract.Result<BoolSort>() != null);
if (m_boolSort == null) m_boolSort = new BoolSort(this); return m_boolSort;
}
}
@ -134,7 +133,14 @@ namespace Microsoft.Z3
/// <summary>
/// Retrieves the Real sort of the context.
/// </summary>
public RealSort RealSort { get { Contract.Ensures(Contract.Result<RealSort>() != null); if (m_realSort == null) m_realSort = new RealSort(this); return m_realSort; } }
public RealSort RealSort
{
get
{
Contract.Ensures(Contract.Result<RealSort>() != null);
if (m_realSort == null) m_realSort = new RealSort(this); return m_realSort;
}
}
/// <summary>
/// Create a new Boolean sort.
@ -193,7 +199,7 @@ namespace Microsoft.Z3
{
Contract.Ensures(Contract.Result<BitVecSort>() != null);
return new BitVecSort(this, size);
return new BitVecSort(this, Native.Z3_mk_bv_sort(nCtx, size));
}
/// <summary>
@ -388,7 +394,7 @@ namespace Microsoft.Z3
IntPtr[] n_constr = new IntPtr[n];
for (uint i = 0; i < n; i++)
{
var constructor = c[i];
Constructor[] constructor = c[i];
Contract.Assume(Contract.ForAll(constructor, arr => arr != null), "Clousot does not support yet quantified formula on multidimensional arrays");
CheckContextMatch(constructor);
cla[i] = new ConstructorList(this, constructor);
@ -3651,6 +3657,7 @@ namespace Microsoft.Z3
Goal_DRQ.Clear(this);
Model_DRQ.Clear(this);
Params_DRQ.Clear(this);
ParamDescrs_DRQ.Clear(this);
Probe_DRQ.Clear(this);
Solver_DRQ.Clear(this);
Statistics_DRQ.Clear(this);

View file

@ -433,7 +433,8 @@ namespace Microsoft.Z3
get
{
return (Native.Z3_is_app(Context.nCtx, NativeObject) != 0 &&
(Z3_sort_kind)Native.Z3_get_sort_kind(Context.nCtx, Native.Z3_get_sort(Context.nCtx, NativeObject)) == Z3_sort_kind.Z3_ARRAY_SORT);
(Z3_sort_kind)Native.Z3_get_sort_kind(Context.nCtx, Native.Z3_get_sort(Context.nCtx, NativeObject))
== Z3_sort_kind.Z3_ARRAY_SORT);
}
}
@ -1308,7 +1309,8 @@ namespace Microsoft.Z3
get
{
return (Native.Z3_is_app(Context.nCtx, NativeObject) != 0 &&
(Z3_sort_kind)Native.Z3_get_sort_kind(Context.nCtx, Native.Z3_get_sort(Context.nCtx, NativeObject)) == Z3_sort_kind.Z3_RELATION_SORT);
Native.Z3_get_sort_kind(Context.nCtx, Native.Z3_get_sort(Context.nCtx, NativeObject))
== (uint)Z3_sort_kind.Z3_RELATION_SORT);
}
}
@ -1429,7 +1431,7 @@ namespace Microsoft.Z3
get
{
return (Native.Z3_is_app(Context.nCtx, NativeObject) != 0 &&
(Z3_sort_kind)Native.Z3_get_sort_kind(Context.nCtx, Native.Z3_get_sort(Context.nCtx, NativeObject)) == Z3_sort_kind.Z3_FINITE_DOMAIN_SORT);
Native.Z3_get_sort_kind(Context.nCtx, Native.Z3_get_sort(Context.nCtx, NativeObject)) == (uint)Z3_sort_kind.Z3_FINITE_DOMAIN_SORT);
}
}
@ -1489,8 +1491,8 @@ namespace Microsoft.Z3
internal override void CheckNativeObject(IntPtr obj)
{
if (Native.Z3_is_app(Context.nCtx, obj) == 0 &&
(Z3_ast_kind)Native.Z3_get_ast_kind(Context.nCtx, obj) != Z3_ast_kind.Z3_VAR_AST &&
(Z3_ast_kind)Native.Z3_get_ast_kind(Context.nCtx, obj) != Z3_ast_kind.Z3_QUANTIFIER_AST)
Native.Z3_get_ast_kind(Context.nCtx, obj) != (uint)Z3_ast_kind.Z3_VAR_AST &&
Native.Z3_get_ast_kind(Context.nCtx, obj) != (uint)Z3_ast_kind.Z3_QUANTIFIER_AST)
throw new Z3Exception("Underlying object is not a term");
base.CheckNativeObject(obj);
}
@ -1530,7 +1532,7 @@ namespace Microsoft.Z3
{
case Z3_sort_kind.Z3_INT_SORT: return new IntNum(ctx, obj);
case Z3_sort_kind.Z3_REAL_SORT: return new RatNum(ctx, obj);
case Z3_sort_kind.Z3_BV_SORT: return new BitVecNum(ctx, obj);
case Z3_sort_kind.Z3_BV_SORT: return new BitVecNum(ctx, obj);
}
}
@ -1541,7 +1543,7 @@ namespace Microsoft.Z3
case Z3_sort_kind.Z3_REAL_SORT: return new RealExpr(ctx, obj);
case Z3_sort_kind.Z3_BV_SORT: return new BitVecExpr(ctx, obj);
case Z3_sort_kind.Z3_ARRAY_SORT: return new ArrayExpr(ctx, obj);
case Z3_sort_kind.Z3_DATATYPE_SORT: return new DatatypeExpr(ctx, obj);
case Z3_sort_kind.Z3_DATATYPE_SORT: return new DatatypeExpr(ctx, obj);
}
return new Expr(ctx, obj);

View file

@ -110,7 +110,7 @@ namespace Microsoft.Z3
{
Contract.Ensures(Contract.Result<Sort[]>() != null);
var n = DomainSize;
uint n = DomainSize;
Sort[] res = new Sort[n];
for (uint i = 0; i < n; i++)

View file

@ -184,10 +184,10 @@ namespace Microsoft.Z3
{
Tactic t = Context.MkTactic("simplify");
ApplyResult res = t.Apply(this, p);
if (res.NumSubgoals == 0)
return Context.MkGoal();
else
throw new Z3Exception("No subgoals");
else
return res.Subgoals[0];
}

View file

@ -24,7 +24,7 @@ using System.Threading;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
{
[ContractClass(typeof(DecRefQueueContracts))]
internal abstract class IDecRefQueue
{
@ -35,7 +35,7 @@ namespace Microsoft.Z3
{
Contract.Invariant(this.m_queue != null);
}
#endregion
readonly internal protected Object m_lock = new Object();

View file

@ -252,6 +252,71 @@
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules;C:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<CodeAnalysisLogFile>..\Debug\Microsoft.Z3.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile>..\external\Microsoft.Z3.xml</DocumentationFile>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<CodeAnalysisLogFile>..\external\Microsoft.Z3.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'external|x86'">
<OutputPath>bin\x86\external\</OutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile>..\external\Microsoft.Z3.xml</DocumentationFile>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<CodeAnalysisLogFile>bin\Release\Microsoft.Z3.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSetDirectories>;C:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisRuleDirectories>;C:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release_delaysign|x86'">
<OutputPath>bin\x86\Release_delaysign\</OutputPath>
<DefineConstants>DELAYSIGN</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile>..\Release_delaysign\Microsoft.Z3.xml</DocumentationFile>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<CodeAnalysisLogFile>..\release\Microsoft.Z3.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSetDirectories>;C:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisRuleDirectories>;C:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />

View file

@ -165,8 +165,8 @@ namespace Microsoft.Z3
{
Contract.Ensures(Contract.Result<FuncDecl[]>() != null);
var nFuncs = NumFuncs;
var nConsts = NumConsts;
uint nFuncs = NumFuncs;
uint nConsts = NumConsts;
uint n = nFuncs + nConsts;
FuncDecl[] res = new FuncDecl[n];
for (uint i = 0; i < nConsts; i++)

View file

@ -181,8 +181,6 @@ namespace Microsoft.Z3
if (sorts.Length != names.Length)
throw new Z3Exception("Number of sorts does not match number of names");
IntPtr[] _patterns = AST.ArrayToNative(patterns);
if (noPatterns == null && quantifierID == null && skolemID == null)
{
NativeObject = Native.Z3_mk_quantifier(ctx.nCtx, (isForall) ? 1 : 0, weight,

245
src/api/java/AST.java Normal file
View file

@ -0,0 +1,245 @@
/**
* This file was automatically generated from AST.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
import com.microsoft.z3.enumerations.*;
/**
* The abstract syntax tree (AST) class.
**/
public class AST extends Z3Object
{
/**
* Comparison operator. <param name="a">An AST</param> <param name="b">An
* AST</param>
*
* @return True if <paramref name="a"/> and <paramref name="b"/> are from
* the same context and represent the same sort; false otherwise.
**/
/* Overloaded operators are not translated. */
/**
* Comparison operator. <param name="a">An AST</param> <param name="b">An
* AST</param>
*
* @return True if <paramref name="a"/> and <paramref name="b"/> are not
* from the same context or represent different sorts; false
* otherwise.
**/
/* Overloaded operators are not translated. */
/**
* Object comparison.
**/
public boolean equals(Object o)
{
AST casted = null;
try
{
casted = AST.class.cast(o);
} catch (ClassCastException e)
{
return false;
}
return this.NativeObject() == casted.NativeObject();
}
/**
* Object Comparison. <param name="other">Another AST</param>
*
* @return Negative if the object should be sorted before <paramref
* name="other"/>, positive if after else zero.
**/
public int compareTo(Object other) throws Z3Exception
{
if (other == null)
return 1;
AST oAST = null;
try
{
oAST = AST.class.cast(other);
} catch (ClassCastException e)
{
return 1;
}
if (Id() < oAST.Id())
return -1;
else if (Id() > oAST.Id())
return +1;
else
return 0;
}
/**
* The AST's hash code.
*
* @return A hash code
**/
public int GetHashCode() throws Z3Exception
{
return (int) Native.getAstHash(Context().nCtx(), NativeObject());
}
/**
* A unique identifier for the AST (unique among all ASTs).
**/
public int Id() throws Z3Exception
{
return Native.getAstId(Context().nCtx(), NativeObject());
}
/**
* Translates (copies) the AST to the Context <paramref name="ctx"/>. <param
* name="ctx">A context</param>
*
* @return A copy of the AST which is associated with <paramref name="ctx"/>
**/
public AST Translate(Context ctx) throws Z3Exception
{
if (Context() == ctx)
return this;
else
return new AST(ctx, Native.translate(Context().nCtx(),
NativeObject(), ctx.nCtx()));
}
/**
* The kind of the AST.
**/
public Z3_ast_kind ASTKind() throws Z3Exception
{
return Z3_ast_kind.fromInt(Native.getAstKind(Context().nCtx(),
NativeObject()));
}
/**
* Indicates whether the AST is an Expr
**/
public boolean IsExpr() throws Z3Exception
{
switch (ASTKind())
{
case Z3_APP_AST:
case Z3_NUMERAL_AST:
case Z3_QUANTIFIER_AST:
case Z3_VAR_AST:
return true;
default:
return false;
}
}
/**
* Indicates whether the AST is a BoundVariable
**/
public boolean IsVar() throws Z3Exception
{
return this.ASTKind() == Z3_ast_kind.Z3_VAR_AST;
}
/**
* Indicates whether the AST is a Quantifier
**/
public boolean IsQuantifier() throws Z3Exception
{
return this.ASTKind() == Z3_ast_kind.Z3_QUANTIFIER_AST;
}
/**
* Indicates whether the AST is a Sort
**/
public boolean IsSort() throws Z3Exception
{
return this.ASTKind() == Z3_ast_kind.Z3_SORT_AST;
}
/**
* Indicates whether the AST is a FunctionDeclaration
**/
public boolean IsFuncDecl() throws Z3Exception
{
return this.ASTKind() == Z3_ast_kind.Z3_FUNC_DECL_AST;
}
/**
* A string representation of the AST.
**/
public String toString()
{
try
{
return Native.astToString(Context().nCtx(), NativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
/**
* A string representation of the AST in s-expression notation.
**/
public String SExpr() throws Z3Exception
{
return Native.astToString(Context().nCtx(), NativeObject());
}
AST(Context ctx)
{
super(ctx);
}
AST(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
void IncRef(long o) throws Z3Exception
{
// Console.WriteLine("AST IncRef()");
if (Context() == null)
throw new Z3Exception("inc() called on null context");
if (o == 0)
throw new Z3Exception("inc() called on null AST");
Context().AST_DRQ().IncAndClear(Context(), o);
super.IncRef(o);
}
void DecRef(long o) throws Z3Exception
{
// Console.WriteLine("AST DecRef()");
if (Context() == null)
throw new Z3Exception("dec() called on null context");
if (o == 0)
throw new Z3Exception("dec() called on null AST");
Context().AST_DRQ().Add(o);
super.DecRef(o);
}
static AST Create(Context ctx, long obj) throws Z3Exception
{
switch (Z3_ast_kind.fromInt(Native.getAstKind(ctx.nCtx(), obj)))
{
case Z3_FUNC_DECL_AST:
return new FuncDecl(ctx, obj);
case Z3_QUANTIFIER_AST:
return new Quantifier(ctx, obj);
case Z3_SORT_AST:
return Sort.Create(ctx, obj);
case Z3_APP_AST:
case Z3_NUMERAL_AST:
case Z3_VAR_AST:
return Expr.Create(ctx, obj);
default:
throw new Z3Exception("Unknown AST kind");
}
}
}

View file

@ -0,0 +1,31 @@
/**
* Copyright (c) 2012 Microsoft Corporation
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
public class ASTDecRefQueue extends IDecRefQueue
{
public void IncRef(Context ctx, long obj)
{
try
{
Native.incRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
public void DecRef(Context ctx, long obj)
{
try
{
Native.decRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
};

124
src/api/java/ASTMap.java Normal file
View file

@ -0,0 +1,124 @@
/**
* This file was automatically generated from ASTMap.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Map from AST to AST
**/
class ASTMap extends Z3Object
{
/**
* Checks whether the map contains the key <paramref name="k"/>. <param
* name="k">An AST</param>
*
* @return True if <paramref name="k"/> is a key in the map, false
* otherwise.
**/
public boolean Contains(AST k) throws Z3Exception
{
return Native.astMapContains(Context().nCtx(), NativeObject(),
k.NativeObject());
}
/**
* Finds the value associated with the key <paramref name="k"/>. <remarks>
* This function signs an error when <paramref name="k"/> is not a key in
* the map. </remarks> <param name="k">An AST</param>
*
* @throws Z3Exception
**/
public AST Find(AST k) throws Z3Exception
{
return new AST(Context(), Native.astMapFind(Context().nCtx(),
NativeObject(), k.NativeObject()));
}
/**
* Stores or replaces a new key/value pair in the map. <param name="k">The
* key AST</param> <param name="v">The value AST</param>
**/
public void Insert(AST k, AST v) throws Z3Exception
{
Native.astMapInsert(Context().nCtx(), NativeObject(), k.NativeObject(),
v.NativeObject());
}
/**
* Erases the key <paramref name="k"/> from the map. <param name="k">An
* AST</param>
**/
public void Erase(AST k) throws Z3Exception
{
Native.astMapErase(Context().nCtx(), NativeObject(), k.NativeObject());
}
/**
* Removes all keys from the map.
**/
public void Reset() throws Z3Exception
{
Native.astMapReset(Context().nCtx(), NativeObject());
}
/**
* The size of the map
**/
public int Size() throws Z3Exception
{
return Native.astMapSize(Context().nCtx(), NativeObject());
}
/**
* The keys stored in the map.
*
* @throws Z3Exception
**/
public ASTVector Keys() throws Z3Exception
{
return new ASTVector(Context(), Native.astMapKeys(Context().nCtx(),
NativeObject()));
}
/**
* Retrieves a string representation of the map.
**/
public String toString()
{
try
{
return Native.astMapToString(Context().nCtx(), NativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
ASTMap(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
ASTMap(Context ctx) throws Z3Exception
{
super(ctx, Native.mkAstMap(ctx.nCtx()));
}
void IncRef(long o) throws Z3Exception
{
Context().ASTMap_DRQ().IncAndClear(Context(), o);
super.IncRef(o);
}
void DecRef(long o) throws Z3Exception
{
Context().ASTMap_DRQ().Add(o);
super.DecRef(o);
}
}

109
src/api/java/ASTVector.java Normal file
View file

@ -0,0 +1,109 @@
/**
* This file was automatically generated from ASTVector.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Vectors of ASTs.
**/
class ASTVector extends Z3Object
{
/**
* The size of the vector
**/
public int Size() throws Z3Exception
{
return Native.astVectorSize(Context().nCtx(), NativeObject());
}
/**
* Retrieves the i-th object in the vector. <remarks>May throw an
* IndexOutOfBoundsException when <paramref name="i"/> is out of
* range.</remarks> <param name="i">Index</param>
*
* @return An AST
* @throws Z3Exception
**/
public AST get(int i) throws Z3Exception
{
return new AST(Context(), Native.astVectorGet(Context().nCtx(),
NativeObject(), i));
}
public void set(int i, AST value) throws Z3Exception
{
Native.astVectorSet(Context().nCtx(), NativeObject(), i,
value.NativeObject());
}
/**
* Resize the vector to <paramref name="newSize"/>. <param
* name="newSize">The new size of the vector.</param>
**/
public void Resize(int newSize) throws Z3Exception
{
Native.astVectorResize(Context().nCtx(), NativeObject(), newSize);
}
/**
* Add the AST <paramref name="a"/> to the back of the vector. The size is
* increased by 1. <param name="a">An AST</param>
**/
public void Push(AST a) throws Z3Exception
{
Native.astVectorPush(Context().nCtx(), NativeObject(), a.NativeObject());
}
/**
* Translates all ASTs in the vector to <paramref name="ctx"/>. <param
* name="ctx">A context</param>
*
* @return A new ASTVector
* @throws Z3Exception
**/
public ASTVector Translate(Context ctx) throws Z3Exception
{
return new ASTVector(Context(), Native.astVectorTranslate(Context()
.nCtx(), NativeObject(), ctx.nCtx()));
}
/**
* Retrieves a string representation of the vector.
**/
public String toString()
{
try
{
return Native.astVectorToString(Context().nCtx(), NativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
ASTVector(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
ASTVector(Context ctx) throws Z3Exception
{
super(ctx, Native.mkAstVector(ctx.nCtx()));
}
void IncRef(long o) throws Z3Exception
{
Context().ASTVector_DRQ().IncAndClear(Context(), o);
super.IncRef(o);
}
void DecRef(long o) throws Z3Exception
{
Context().ASTVector_DRQ().Add(o);
super.DecRef(o);
}
}

View file

@ -0,0 +1,59 @@
/**
* This file was automatically generated from AlgebraicNum.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Algebraic numbers
**/
public class AlgebraicNum extends ArithExpr
{
/**
* Return a upper bound for a given real algebraic number. The interval
* isolating the number is smaller than 1/10^<paramref name="precision"/>.
* <seealso cref="Expr.IsAlgebraicNumber"/> <param name="precision">the
* precision of the result</param>
*
* @return A numeral Expr of sort Real
**/
public RatNum ToUpper(int precision) throws Z3Exception
{
return new RatNum(Context(), Native.getAlgebraicNumberUpper(Context()
.nCtx(), NativeObject(), precision));
}
/**
* Return a lower bound for the given real algebraic number. The interval
* isolating the number is smaller than 1/10^<paramref name="precision"/>.
* <seealso cref="Expr.IsAlgebraicNumber"/> <param name="precision"></param>
*
* @return A numeral Expr of sort Real
**/
public RatNum ToLower(int precision) throws Z3Exception
{
return new RatNum(Context(), Native.getAlgebraicNumberLower(Context()
.nCtx(), NativeObject(), precision));
}
/**
* Returns a string representation in decimal notation. <remarks>The result
* has at most <paramref name="precision"/> decimal places.</remarks>
**/
public String ToDecimal(int precision) throws Z3Exception
{
return Native.getNumeralDecimalString(Context().nCtx(), NativeObject(),
precision);
}
AlgebraicNum(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
}

View file

@ -0,0 +1,82 @@
/**
* This file was automatically generated from ApplyResult.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* ApplyResult objects represent the result of an application of a tactic to a
* goal. It contains the subgoals that were produced.
**/
public class ApplyResult extends Z3Object
{
/**
* The number of Subgoals.
**/
public int NumSubgoals() throws Z3Exception
{
return Native.applyResultGetNumSubgoals(Context().nCtx(),
NativeObject());
}
/**
* Retrieves the subgoals from the ApplyResult.
*
* @throws Z3Exception
**/
public Goal[] Subgoals() throws Z3Exception
{
int n = NumSubgoals();
Goal[] res = new Goal[n];
for (int i = 0; i < n; i++)
res[i] = new Goal(Context(), Native.applyResultGetSubgoal(Context()
.nCtx(), NativeObject(), i));
return res;
}
/**
* Convert a model for the subgoal <paramref name="i"/> into a model for the
* original goal <code>g</code>, that the ApplyResult was obtained from.
*
* @return A model for <code>g</code>
* @throws Z3Exception
**/
public Model ConvertModel(int i, Model m) throws Z3Exception
{
return new Model(Context(), Native.applyResultConvertModel(Context()
.nCtx(), NativeObject(), i, m.NativeObject()));
}
/**
* A string representation of the ApplyResult.
**/
public String toString()
{
try
{
return Native.applyResultToString(Context().nCtx(), NativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
ApplyResult(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
void IncRef(long o) throws Z3Exception
{
Context().ApplyResult_DRQ().IncAndClear(Context(), o);
super.IncRef(o);
}
void DecRef(long o) throws Z3Exception
{
Context().ApplyResult_DRQ().Add(o);
super.DecRef(o);
}
}

View file

@ -0,0 +1,31 @@
/**
* Copyright (c) 2012 Microsoft Corporation
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
class ApplyResultDecRefQueue extends IDecRefQueue
{
public void IncRef(Context ctx, long obj)
{
try
{
Native.applyResultIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
public void DecRef(Context ctx, long obj)
{
try
{
Native.applyResultDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
};

View file

@ -0,0 +1,26 @@
/**
* This file was automatically generated from ArithExpr.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
* **/
package com.microsoft.z3;
/**
* Arithmetic expressions (int/real)
**/
public class ArithExpr extends Expr
{
/**
* Constructor for ArithExpr </summary>
**/
protected ArithExpr(Context ctx)
{
super(ctx);
}
ArithExpr(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
}

View file

@ -0,0 +1,18 @@
/**
* This file was automatically generated from ArithSort.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* An arithmetic sort, i.e., Int or Real.
**/
public class ArithSort extends Sort
{
ArithSort(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
};

View file

@ -0,0 +1,27 @@
/**
* This file was automatically generated from ArrayExpr.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Array expressions
**/
public class ArrayExpr extends Expr
{
/**
* Constructor for ArrayExpr </summary>
**/
protected ArrayExpr(Context ctx)
{
super(ctx);
}
ArrayExpr(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
}

View file

@ -0,0 +1,44 @@
/**
* This file was automatically generated from ArraySort.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Array sorts.
**/
public class ArraySort extends Sort
{
/**
* The domain of the array sort.
* @throws Z3Exception
**/
public Sort Domain() throws Z3Exception
{
return Sort.Create(Context(),
Native.getArraySortDomain(Context().nCtx(), NativeObject()));
}
/**
* The range of the array sort.
* @throws Z3Exception
**/
public Sort Range() throws Z3Exception
{
return Sort.Create(Context(),
Native.getArraySortRange(Context().nCtx(), NativeObject()));
}
ArraySort(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
ArraySort(Context ctx, Sort domain, Sort range) throws Z3Exception
{
super(ctx, Native.mkArraySort(ctx.nCtx(), domain.NativeObject(),
range.NativeObject()));
}
};

View file

@ -0,0 +1,31 @@
/**
* Copyright (c) 2012 Microsoft Corporation
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
class ASTMapDecRefQueue extends IDecRefQueue
{
public void IncRef(Context ctx, long obj)
{
try
{
Native.astMapIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
public void DecRef(Context ctx, long obj)
{
try
{
Native.astMapDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
};

View file

@ -0,0 +1,31 @@
/**
* Copyright (c) 2012 Microsoft Corporation
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
class ASTVectorDecRefQueue extends IDecRefQueue
{
public void IncRef(Context ctx, long obj)
{
try
{
Native.astVectorIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
public void DecRef(Context ctx, long obj)
{
try
{
Native.astVectorDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
};

View file

@ -0,0 +1,36 @@
/**
* This file was automatically generated from BitVecExpr.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Bit-vector expressions
**/
public class BitVecExpr extends Expr
{
/**
* The size of the sort of a bit-vector term.
* @throws Z3Exception
**/
public int SortSize() throws Z3Exception
{
return ((BitVecSort) Sort()).Size();
}
/**
* Constructor for BitVecExpr </summary>
**/
protected BitVecExpr(Context ctx)
{
super(ctx);
}
BitVecExpr(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
}

View file

@ -0,0 +1,68 @@
/**
* This file was automatically generated from BitVecNum.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
import java.math.BigInteger;
/**
* Bit-vector numerals
**/
public class BitVecNum extends BitVecExpr
{
/**
* Retrieve the int value.
*
* @throws Z3Exception
**/
public int Int() throws Z3Exception
{
Native.IntPtr res = new Native.IntPtr();
if (Native.getNumeralInt(Context().nCtx(), NativeObject(), res) ^ true)
throw new Z3Exception("Numeral is not an int");
return res.value;
}
/**
* Retrieve the 64-bit int value.
*
* @throws Z3Exception
**/
public long Long() throws Z3Exception
{
Native.LongPtr res = new Native.LongPtr();
if (Native.getNumeralInt64(Context().nCtx(), NativeObject(), res) ^ true)
throw new Z3Exception("Numeral is not an int64");
return res.value;
}
/**
* Retrieve the BigInteger value.
**/
public BigInteger BigInteger()
{
return new BigInteger(this.toString());
}
/**
* Returns a string representation of the numeral.
**/
public String toString()
{
try
{
return Native.getNumeralString(Context().nCtx(), NativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
BitVecNum(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
}

View file

@ -0,0 +1,25 @@
/**
* This file was automatically generated from BitVecSort.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Bit-vector sorts.
**/
public class BitVecSort extends Sort
{
/**
* The size of the bit-vector sort.
**/
public int Size() throws Z3Exception
{
return Native.getBvSortSize(Context().nCtx(), NativeObject());
}
BitVecSort(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
};

View file

@ -0,0 +1,30 @@
/**
* This file was automatically generated from BoolExpr.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Boolean expressions
**/
public class BoolExpr extends Expr
{
/**
* Constructor for BoolExpr </summary>
**/
protected BoolExpr(Context ctx)
{
super(ctx);
}
/**
* Constructor for BoolExpr </summary>
* @throws Z3Exception
**/
BoolExpr(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
}

View file

@ -0,0 +1,16 @@
/**
* This file was automatically generated from BoolSort.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* A Boolean sort.
**/
public class BoolSort extends Sort
{
BoolSort(Context ctx, long obj) throws Z3Exception { super(ctx, obj); { }}
BoolSort(Context ctx) throws Z3Exception { super(ctx, Native.mkBoolSort(ctx.nCtx())); { }}
};

View file

@ -0,0 +1,107 @@
/**
* This file was automatically generated from Constructor.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Constructors are used for datatype sorts.
**/
public class Constructor extends Z3Object
{
/**
* The number of fields of the constructor.
* @throws Z3Exception
**/
public int NumFields() throws Z3Exception
{
init();
return n;
}
/**
* The function declaration of the constructor.
* @throws Z3Exception
**/
public FuncDecl ConstructorDecl() throws Z3Exception
{
init();
return m_constructorDecl;
}
/**
* The function declaration of the tester.
* @throws Z3Exception
**/
public FuncDecl TesterDecl() throws Z3Exception
{
init();
return m_testerDecl;
}
/**
* The function declarations of the accessors
* @throws Z3Exception
**/
public FuncDecl[] AccessorDecls() throws Z3Exception
{
init();
return m_accessorDecls;
}
/**
* Destructor.
**/
protected void finalize() throws Z3Exception
{
Native.delConstructor(Context().nCtx(), NativeObject());
}
private int n = 0;
private FuncDecl m_testerDecl = null;
private FuncDecl m_constructorDecl = null;
private FuncDecl[] m_accessorDecls = null;
Constructor(Context ctx, Symbol name, Symbol recognizer,
Symbol[] fieldNames, Sort[] sorts, int[] sortRefs)
throws Z3Exception
{
super(ctx);
n = AST.ArrayLength(fieldNames);
if (n != AST.ArrayLength(sorts))
throw new Z3Exception(
"Number of field names does not match number of sorts");
if (sortRefs != null && sortRefs.length != n)
throw new Z3Exception(
"Number of field names does not match number of sort refs");
if (sortRefs == null)
sortRefs = new int[n];
setNativeObject(Native.mkConstructor(ctx.nCtx(), name.NativeObject(),
recognizer.NativeObject(), n, Symbol.ArrayToNative(fieldNames),
Sort.ArrayToNative(sorts), sortRefs));
}
private void init() throws Z3Exception
{
if (m_testerDecl != null)
return;
Native.LongPtr constructor = new Native.LongPtr();
Native.LongPtr tester = new Native.LongPtr();
long[] accessors = new long[n];
Native.queryConstructor(Context().nCtx(), NativeObject(), n,
constructor, tester, accessors);
m_constructorDecl = new FuncDecl(Context(), constructor.value);
m_testerDecl = new FuncDecl(Context(), tester.value);
m_accessorDecls = new FuncDecl[n];
for (int i = 0; i < n; i++)
m_accessorDecls[i] = new FuncDecl(Context(), accessors[i]);
}
}

View file

@ -0,0 +1,35 @@
/**
* This file was automatically generated from ConstructorList.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Lists of constructors
**/
public class ConstructorList extends Z3Object
{
/**
* Destructor.
**/
protected void finalize() throws Z3Exception
{
Native.delConstructorList(Context().nCtx(), NativeObject());
}
ConstructorList(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
ConstructorList(Context ctx, Constructor[] constructors) throws Z3Exception
{
super(ctx);
setNativeObject(Native.mkConstructorList(Context().nCtx(),
(int) constructors.length,
Constructor.ArrayToNative(constructors)));
}
}

3102
src/api/java/Context.java Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,26 @@
/**
* This file was automatically generated from DatatypeExpr.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Datatype expressions
**/
public class DatatypeExpr extends Expr
{
/**
* Constructor for DatatypeExpr </summary>
**/
protected DatatypeExpr(Context ctx)
{
super(ctx);
}
DatatypeExpr(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
}

View file

@ -0,0 +1,91 @@
/**
* This file was automatically generated from DatatypeSort.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Datatype sorts.
**/
public class DatatypeSort extends Sort
{
/**
* The number of constructors of the datatype sort.
**/
public int NumConstructors() throws Z3Exception
{
return Native.getDatatypeSortNumConstructors(Context().nCtx(),
NativeObject());
}
/**
* The constructors.
*
* @throws Z3Exception
**/
public FuncDecl[] Constructors() throws Z3Exception
{
int n = NumConstructors();
FuncDecl[] res = new FuncDecl[n];
for (int i = 0; i < n; i++)
res[i] = new FuncDecl(Context(), Native.getDatatypeSortConstructor(
Context().nCtx(), NativeObject(), i));
return res;
}
/**
* The recognizers.
*
* @throws Z3Exception
**/
public FuncDecl[] Recognizers() throws Z3Exception
{
int n = NumConstructors();
FuncDecl[] res = new FuncDecl[n];
for (int i = 0; i < n; i++)
res[i] = new FuncDecl(Context(), Native.getDatatypeSortRecognizer(
Context().nCtx(), NativeObject(), i));
return res;
}
/**
* The constructor accessors.
*
* @throws Z3Exception
**/
public FuncDecl[][] Accessors() throws Z3Exception
{
int n = NumConstructors();
FuncDecl[][] res = new FuncDecl[n][];
for (int i = 0; i < n; i++)
{
FuncDecl fd = new FuncDecl(Context(),
Native.getDatatypeSortConstructor(Context().nCtx(),
NativeObject(), i));
int ds = fd.DomainSize();
FuncDecl[] tmp = new FuncDecl[ds];
for (int j = 0; j < ds; j++)
tmp[j] = new FuncDecl(Context(),
Native.getDatatypeSortConstructorAccessor(Context()
.nCtx(), NativeObject(), i, j));
res[i] = tmp;
}
return res;
}
DatatypeSort(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
DatatypeSort(Context ctx, Symbol name, Constructor[] constructors)
throws Z3Exception
{
super(ctx, Native.mkDatatype(ctx.nCtx(), name.NativeObject(),
(int) constructors.length, ArrayToNative(constructors)));
}
};

View file

@ -0,0 +1,61 @@
/**
* This file was automatically generated from EnumSort.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Enumeration sorts.
**/
public class EnumSort extends Sort
{
/**
* The function declarations of the constants in the enumeration.
**/
public FuncDecl[] ConstDecls()
{
return _constdecls;
}
/**
* The constants in the enumeration.
**/
public Expr[] Consts()
{
return _consts;
}
/**
* The test predicates for the constants in the enumeration.
**/
public FuncDecl[] TesterDecls()
{
return _testerdecls;
}
private FuncDecl[] _constdecls = null, _testerdecls = null;
private Expr[] _consts = null;
EnumSort(Context ctx, Symbol name, Symbol[] enumNames) throws Z3Exception
{
super(ctx);
int n = enumNames.length;
long[] n_constdecls = new long[n];
long[] n_testers = new long[n];
setNativeObject(Native.mkEnumerationSort(ctx.nCtx(),
name.NativeObject(), (int) n, Symbol.ArrayToNative(enumNames),
n_constdecls, n_testers));
_constdecls = new FuncDecl[n];
for (int i = 0; i < n; i++)
_constdecls[i] = new FuncDecl(ctx, n_constdecls[i]);
_testerdecls = new FuncDecl[n];
for (int i = 0; i < n; i++)
_testerdecls[i] = new FuncDecl(ctx, n_testers[i]);
_consts = new Expr[n];
for (int i = 0; i < n; i++)
_consts[i] = ctx.MkApp(_constdecls[i], (Expr[])null);
}
};

1812
src/api/java/Expr.java Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,34 @@
/**
* This file was automatically generated from FiniteDomainSort.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Finite domain sorts.
**/
public class FiniteDomainSort extends Sort
{
/**
* The size of the finite domain sort.
**/
public long Size() throws Z3Exception
{
Native.LongPtr res = new Native.LongPtr();
Native.getFiniteDomainSortSize(Context().nCtx(), NativeObject(), res);
return res.value;
}
FiniteDomainSort(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
FiniteDomainSort(Context ctx, Symbol name, long size) throws Z3Exception
{
super(ctx, Native.mkFiniteDomainSort(ctx.nCtx(), name.NativeObject(),
size));
}
}

View file

@ -0,0 +1,333 @@
/**
* This file was automatically generated from Fixedpoint.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
import com.microsoft.z3.enumerations.*;
/**
* Object for managing fixedpoints
**/
public class Fixedpoint extends Z3Object
{
/**
* A string that describes all available fixedpoint solver parameters.
**/
public String Help() throws Z3Exception
{
return Native.fixedpointGetHelp(Context().nCtx(), NativeObject());
}
/**
* Sets the fixedpoint solver parameters.
*
* @throws Z3Exception
**/
public void setParameters(Params value) throws Z3Exception
{
Context().CheckContextMatch(value);
Native.fixedpointSetParams(Context().nCtx(), NativeObject(),
value.NativeObject());
}
/**
* Retrieves parameter descriptions for Fixedpoint solver.
*
* @throws Z3Exception
**/
public ParamDescrs ParameterDescriptions() throws Z3Exception
{
return new ParamDescrs(Context(), Native.fixedpointGetParamDescrs(
Context().nCtx(), NativeObject()));
}
/**
* Assert a constraint (or multiple) into the fixedpoint solver.
*
* @throws Z3Exception
**/
public void Assert(BoolExpr[] constraints) throws Z3Exception
{
Context().CheckContextMatch(constraints);
for (BoolExpr a : constraints)
{
Native.fixedpointAssert(Context().nCtx(), NativeObject(),
a.NativeObject());
}
}
/**
* Register predicate as recursive relation.
*
* @throws Z3Exception
**/
public void RegisterRelation(FuncDecl f) throws Z3Exception
{
Context().CheckContextMatch(f);
Native.fixedpointRegisterRelation(Context().nCtx(), NativeObject(),
f.NativeObject());
}
/**
* Add rule into the fixedpoint solver.
*
* @throws Z3Exception
**/
public void AddRule(BoolExpr rule, Symbol name) throws Z3Exception
{
Context().CheckContextMatch(rule);
Native.fixedpointAddRule(Context().nCtx(), NativeObject(),
rule.NativeObject(), AST.GetNativeObject(name));
}
/**
* Add table fact to the fixedpoint solver.
*
* @throws Z3Exception
**/
public void AddFact(FuncDecl pred, int[] args) throws Z3Exception
{
Context().CheckContextMatch(pred);
Native.fixedpointAddFact(Context().nCtx(), NativeObject(),
pred.NativeObject(), (int) args.length, args);
}
/**
* Query the fixedpoint solver. A query is a conjunction of constraints. The
* constraints may include the recursively defined relations. The query is
* satisfiable if there is an instance of the query variables and a
* derivation for it. The query is unsatisfiable if there are no derivations
* satisfying the query variables.
*
* @throws Z3Exception
**/
public Status Query(BoolExpr query) throws Z3Exception
{
Context().CheckContextMatch(query);
Z3_lbool r = Z3_lbool.fromInt(Native.fixedpointQuery(Context().nCtx(),
NativeObject(), query.NativeObject()));
switch (r)
{
case Z3_L_TRUE:
return Status.SATISFIABLE;
case Z3_L_FALSE:
return Status.UNSATISFIABLE;
default:
return Status.UNKNOWN;
}
}
/**
* Query the fixedpoint solver. A query is an array of relations. The query
* is satisfiable if there is an instance of some relation that is
* non-empty. The query is unsatisfiable if there are no derivations
* satisfying any of the relations.
*
* @throws Z3Exception
**/
public Status Query(FuncDecl[] relations) throws Z3Exception
{
Context().CheckContextMatch(relations);
Z3_lbool r = Z3_lbool.fromInt(Native.fixedpointQueryRelations(Context()
.nCtx(), NativeObject(), AST.ArrayLength(relations), AST
.ArrayToNative(relations)));
switch (r)
{
case Z3_L_TRUE:
return Status.SATISFIABLE;
case Z3_L_FALSE:
return Status.UNSATISFIABLE;
default:
return Status.UNKNOWN;
}
}
/**
* Creates a backtracking point. <seealso cref="Pop"/>
**/
public void Push() throws Z3Exception
{
Native.fixedpointPush(Context().nCtx(), NativeObject());
}
/**
* Backtrack one backtracking point. <remarks>Note that an exception is
* thrown if Pop is called without a corresponding <code>Push</code>
* </remarks> <seealso cref="Push"/>
**/
public void Pop() throws Z3Exception
{
Native.fixedpointPop(Context().nCtx(), NativeObject());
}
/**
* Update named rule into in the fixedpoint solver.
*
* @throws Z3Exception
**/
public void UpdateRule(BoolExpr rule, Symbol name) throws Z3Exception
{
Context().CheckContextMatch(rule);
Native.fixedpointUpdateRule(Context().nCtx(), NativeObject(),
rule.NativeObject(), AST.GetNativeObject(name));
}
/**
* Retrieve satisfying instance or instances of solver, or definitions for
* the recursive predicates that show unsatisfiability.
*
* @throws Z3Exception
**/
public Expr GetAnswer() throws Z3Exception
{
long ans = Native.fixedpointGetAnswer(Context().nCtx(), NativeObject());
return (ans == 0) ? null : Expr.Create(Context(), ans);
}
/**
* Retrieve explanation why fixedpoint engine returned status Unknown.
**/
public String GetReasonUnknown() throws Z3Exception
{
return Native.fixedpointGetReasonUnknown(Context().nCtx(),
NativeObject());
}
/**
* Retrieve the number of levels explored for a given predicate.
**/
public int GetNumLevels(FuncDecl predicate) throws Z3Exception
{
return Native.fixedpointGetNumLevels(Context().nCtx(), NativeObject(),
predicate.NativeObject());
}
/**
* Retrieve the cover of a predicate.
*
* @throws Z3Exception
**/
public Expr GetCoverDelta(int level, FuncDecl predicate) throws Z3Exception
{
long res = Native.fixedpointGetCoverDelta(Context().nCtx(),
NativeObject(), level, predicate.NativeObject());
return (res == 0) ? null : Expr.Create(Context(), res);
}
/**
* Add <tt>property</tt> about the <tt>predicate</tt>. The property is added
* at <tt>level</tt>.
**/
public void AddCover(int level, FuncDecl predicate, Expr property)
throws Z3Exception
{
Native.fixedpointAddCover(Context().nCtx(), NativeObject(), level,
predicate.NativeObject(), property.NativeObject());
}
/**
* Retrieve internal string representation of fixedpoint object.
**/
public String toString()
{
try
{
return Native.fixedpointToString(Context().nCtx(), NativeObject(),
0, null);
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
/**
* Instrument the Datalog engine on which table representation to use for
* recursive predicate.
**/
public void SetPredicateRepresentation(FuncDecl f, Symbol[] kinds) throws Z3Exception
{
Native.fixedpointSetPredicateRepresentation(Context().nCtx(),
NativeObject(), f.NativeObject(), AST.ArrayLength(kinds),
Symbol.ArrayToNative(kinds));
}
/**
* Convert benchmark given as set of axioms, rules and queries to a string.
**/
public String toString(BoolExpr[] queries) throws Z3Exception
{
return Native.fixedpointToString(Context().nCtx(), NativeObject(),
AST.ArrayLength(queries), AST.ArrayToNative(queries));
}
/**
* Retrieve set of rules added to fixedpoint context.
*
* @throws Z3Exception
**/
public BoolExpr[] Rules() throws Z3Exception
{
ASTVector v = new ASTVector(Context(), Native.fixedpointGetRules(
Context().nCtx(), NativeObject()));
int n = v.Size();
BoolExpr[] res = new BoolExpr[n];
for (int i = 0; i < n; i++)
res[i] = new BoolExpr(Context(), v.get(i).NativeObject());
return res;
}
/**
* Retrieve set of assertions added to fixedpoint context.
*
* @throws Z3Exception
**/
public BoolExpr[] Assertions() throws Z3Exception
{
ASTVector v = new ASTVector(Context(), Native.fixedpointGetAssertions(
Context().nCtx(), NativeObject()));
int n = v.Size();
BoolExpr[] res = new BoolExpr[n];
for (int i = 0; i < n; i++)
res[i] = new BoolExpr(Context(), v.get(i).NativeObject());
return res;
}
Fixedpoint(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
Fixedpoint(Context ctx) throws Z3Exception
{
super(ctx, Native.mkFixedpoint(ctx.nCtx()));
}
void IncRef(long o) throws Z3Exception
{
Context().Fixedpoint_DRQ().IncAndClear(Context(), o);
super.IncRef(o);
}
void DecRef(long o) throws Z3Exception
{
Context().Fixedpoint_DRQ().Add(o);
super.DecRef(o);
}
}

View file

@ -0,0 +1,31 @@
/**
* Copyright (c) 2012 Microsoft Corporation
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
class FixedpointDecRefQueue extends IDecRefQueue
{
public void IncRef(Context ctx, long obj)
{
try
{
Native.fixedpointIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
public void DecRef(Context ctx, long obj)
{
try
{
Native.fixedpointDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
};

397
src/api/java/FuncDecl.java Normal file
View file

@ -0,0 +1,397 @@
/**
* This file was automatically generated from FuncDecl.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
import com.microsoft.z3.enumerations.*;
/**
* Function declarations.
**/
public class FuncDecl extends AST
{
/**
* Comparison operator.
*
* @return True if <paramref name="a"/> and <paramref name="b"/> share the
* same context and are equal, false otherwise.
**/
/* Overloaded operators are not translated. */
/**
* Comparison operator.
*
* @return True if <paramref name="a"/> and <paramref name="b"/> do not
* share the same context or are not equal, false otherwise.
**/
/* Overloaded operators are not translated. */
/**
* Object comparison.
**/
public boolean Equals(Object o)
{
FuncDecl casted = (FuncDecl) o;
if (casted == null)
return false;
return this == casted;
}
/**
* A hash code.
**/
public int GetHashCode() throws Z3Exception
{
return super.GetHashCode();
}
/**
* A string representations of the function declaration.
**/
public String toString()
{
try
{
return Native.funcDeclToString(Context().nCtx(), NativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
/**
* Returns a unique identifier for the function declaration.
**/
public int Id() throws Z3Exception
{
return Native.getFuncDeclId(Context().nCtx(), NativeObject());
}
/**
* The arity of the function declaration
**/
public int Arity() throws Z3Exception
{
return Native.getArity(Context().nCtx(), NativeObject());
}
/**
* The size of the domain of the function declaration <seealso
* cref="Arity"/>
**/
public int DomainSize() throws Z3Exception
{
return Native.getDomainSize(Context().nCtx(), NativeObject());
}
/**
* The domain of the function declaration
**/
public Sort[] Domain() throws Z3Exception
{
int n = DomainSize();
Sort[] res = new Sort[n];
for (int i = 0; i < n; i++)
res[i] = Sort.Create(Context(),
Native.getDomain(Context().nCtx(), NativeObject(), i));
return res;
}
/**
* The range of the function declaration
**/
public Sort Range() throws Z3Exception
{
return Sort.Create(Context(),
Native.getRange(Context().nCtx(), NativeObject()));
}
/**
* The kind of the function declaration.
**/
public Z3_decl_kind DeclKind() throws Z3Exception
{
return Z3_decl_kind.fromInt(Native.getDeclKind(Context().nCtx(),
NativeObject()));
}
/**
* The name of the function declaration
**/
public Symbol Name() throws Z3Exception
{
return Symbol.Create(Context(),
Native.getDeclName(Context().nCtx(), NativeObject()));
}
/**
* The number of parameters of the function declaration
**/
public int NumParameters() throws Z3Exception
{
return Native.getDeclNumParameters(Context().nCtx(), NativeObject());
}
/**
* The parameters of the function declaration
**/
public Parameter[] Parameters() throws Z3Exception
{
int num = NumParameters();
Parameter[] res = new Parameter[num];
for (int i = 0; i < num; i++)
{
Z3_parameter_kind k = Z3_parameter_kind.fromInt(Native
.getDeclParameterKind(Context().nCtx(), NativeObject(), i));
switch (k)
{
case Z3_PARAMETER_INT:
res[i] = new Parameter(k, Native.getDeclIntParameter(Context()
.nCtx(), NativeObject(), i));
break;
case Z3_PARAMETER_DOUBLE:
res[i] = new Parameter(k, Native.getDeclDoubleParameter(
Context().nCtx(), NativeObject(), i));
break;
case Z3_PARAMETER_SYMBOL:
res[i] = new Parameter(k, Symbol.Create(Context(), Native
.getDeclSymbolParameter(Context().nCtx(),
NativeObject(), i)));
break;
case Z3_PARAMETER_SORT:
res[i] = new Parameter(k, Sort.Create(Context(), Native
.getDeclSortParameter(Context().nCtx(), NativeObject(),
i)));
break;
case Z3_PARAMETER_AST:
res[i] = new Parameter(k, new AST(Context(),
Native.getDeclAstParameter(Context().nCtx(),
NativeObject(), i)));
break;
case Z3_PARAMETER_FUNC_DECL:
res[i] = new Parameter(k, new FuncDecl(Context(),
Native.getDeclFuncDeclParameter(Context().nCtx(),
NativeObject(), i)));
break;
case Z3_PARAMETER_RATIONAL:
res[i] = new Parameter(k, Native.getDeclRationalParameter(
Context().nCtx(), NativeObject(), i));
break;
default:
throw new Z3Exception(
"Unknown function declaration parameter kind encountered");
}
}
return res;
}
/**
* Function declarations can have Parameters associated with them.
**/
public class Parameter
{
private Z3_parameter_kind kind;
private int i;
private double d;
private Symbol sym;
private Sort srt;
private AST ast;
private FuncDecl fd;
private String r;
/**
* The int value of the parameter.</summary>
**/
public int Int() throws Z3Exception
{
if (ParameterKind() != Z3_parameter_kind.Z3_PARAMETER_INT)
throw new Z3Exception("parameter is not an int");
return i;
}
/**
* The double value of the parameter.</summary>
**/
public double Double() throws Z3Exception
{
if (ParameterKind() != Z3_parameter_kind.Z3_PARAMETER_DOUBLE)
throw new Z3Exception("parameter is not a double ");
return d;
}
/**
* The Symbol value of the parameter.</summary>
**/
public Symbol Symbol() throws Z3Exception
{
if (ParameterKind() != Z3_parameter_kind.Z3_PARAMETER_SYMBOL)
throw new Z3Exception("parameter is not a Symbol");
return sym;
}
/**
* The Sort value of the parameter.</summary>
**/
public Sort Sort() throws Z3Exception
{
if (ParameterKind() != Z3_parameter_kind.Z3_PARAMETER_SORT)
throw new Z3Exception("parameter is not a Sort");
return srt;
}
/**
* The AST value of the parameter.</summary>
**/
public AST AST() throws Z3Exception
{
if (ParameterKind() != Z3_parameter_kind.Z3_PARAMETER_AST)
throw new Z3Exception("parameter is not an AST");
return ast;
}
/**
* The FunctionDeclaration value of the parameter.</summary>
**/
public FuncDecl FuncDecl() throws Z3Exception
{
if (ParameterKind() != Z3_parameter_kind.Z3_PARAMETER_FUNC_DECL)
throw new Z3Exception("parameter is not a function declaration");
return fd;
}
/**
* The rational string value of the parameter.</summary>
**/
public String Rational() throws Z3Exception
{
if (ParameterKind() != Z3_parameter_kind.Z3_PARAMETER_RATIONAL)
throw new Z3Exception("parameter is not a rational String");
return r;
}
/**
* The kind of the parameter.
**/
public Z3_parameter_kind ParameterKind() throws Z3Exception
{
return kind;
}
Parameter(Z3_parameter_kind k, int i)
{
this.kind = k;
this.i = i;
}
Parameter(Z3_parameter_kind k, double d)
{
this.kind = k;
this.d = d;
}
Parameter(Z3_parameter_kind k, Symbol s)
{
this.kind = k;
this.sym = s;
}
Parameter(Z3_parameter_kind k, Sort s)
{
this.kind = k;
this.srt = s;
}
Parameter(Z3_parameter_kind k, AST a)
{
this.kind = k;
this.ast = a;
}
Parameter(Z3_parameter_kind k, FuncDecl fd)
{
this.kind = k;
this.fd = fd;
}
Parameter(Z3_parameter_kind k, String r)
{
this.kind = k;
this.r = r;
}
}
FuncDecl(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
FuncDecl(Context ctx, Symbol name, Sort[] domain, Sort range)
throws Z3Exception
{
super(ctx, Native.mkFuncDecl(ctx.nCtx(), name.NativeObject(),
AST.ArrayLength(domain), AST.ArrayToNative(domain),
range.NativeObject()));
}
FuncDecl(Context ctx, String prefix, Sort[] domain, Sort range)
throws Z3Exception
{
super(ctx, Native.mkFreshFuncDecl(ctx.nCtx(), prefix,
AST.ArrayLength(domain), AST.ArrayToNative(domain),
range.NativeObject()));
}
void CheckNativeObject(long obj) throws Z3Exception
{
if (Native.getAstKind(Context().nCtx(), obj) != Z3_ast_kind.Z3_FUNC_DECL_AST
.toInt())
throw new Z3Exception(
"Underlying object is not a function declaration");
super.CheckNativeObject(obj);
}
/**
* Create expression that applies function to arguments. <param
* name="args"></param>
*
* @return
**/
/* operator this[] not translated */
/**
* Create expression that applies function to arguments. <param
* name="args"></param>
*
* @return
**/
public Expr Apply(Expr[] args) throws Z3Exception
{
Context().CheckContextMatch(args);
return Expr.Create(Context(), this, args);
}
/**
* Create expression that applies function to one argument. <param
* name="arg"></param>
*
* @return
**/
public Expr Apply(Expr arg) throws Z3Exception
{
Context().CheckContextMatch(arg);
Expr[] a = { arg };
return Expr.Create(Context(), this, a);
}
}

View file

@ -0,0 +1,185 @@
/**
* This file was automatically generated from FuncInterp.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* A function interpretation is represented as a finite map and an 'else' value.
* Each entry in the finite map represents the value of a function given a set
* of arguments.
**/
public class FuncInterp extends Z3Object
{
/**
* An Entry object represents an element in the finite map used to encode a
* function interpretation.
**/
public class Entry extends Z3Object
{
/**
* Return the (symbolic) value of this entry.
*
* @throws Z3Exception
**/
public Expr Value() throws Z3Exception
{
return Expr.Create(Context(),
Native.funcEntryGetValue(Context().nCtx(), NativeObject()));
}
/**
* The number of arguments of the entry.
**/
public int NumArgs() throws Z3Exception
{
return Native.funcEntryGetNumArgs(Context().nCtx(), NativeObject());
}
/**
* The arguments of the function entry.
*
* @throws Z3Exception
**/
public Expr[] Args() throws Z3Exception
{
int n = NumArgs();
Expr[] res = new Expr[n];
for (int i = 0; i < n; i++)
res[i] = Expr.Create(Context(), Native.funcEntryGetArg(
Context().nCtx(), NativeObject(), i));
return res;
}
/**
* A string representation of the function entry.
**/
public String toString()
{
try
{
int n = NumArgs();
String res = "[";
Expr[] args = Args();
for (int i = 0; i < n; i++)
res += args[i] + ", ";
return res + Value() + "]";
} catch (Z3Exception e)
{
return new String("Z3Exception: " + e.getMessage());
}
}
Entry(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
void IncRef(long o) throws Z3Exception
{
Context().FuncEntry_DRQ().IncAndClear(Context(), o);
super.IncRef(o);
}
void DecRef(long o) throws Z3Exception
{
Context().FuncEntry_DRQ().Add(o);
super.DecRef(o);
}
};
/**
* The number of entries in the function interpretation.
**/
public int NumEntries() throws Z3Exception
{
return Native.funcInterpGetNumEntries(Context().nCtx(), NativeObject());
}
/**
* The entries in the function interpretation
*
* @throws Z3Exception
**/
public Entry[] Entries() throws Z3Exception
{
int n = NumEntries();
Entry[] res = new Entry[n];
for (int i = 0; i < n; i++)
res[i] = new Entry(Context(), Native.funcInterpGetEntry(Context()
.nCtx(), NativeObject(), i));
return res;
}
/**
* The (symbolic) `else' value of the function interpretation.
*
* @throws Z3Exception
**/
public Expr Else() throws Z3Exception
{
return Expr.Create(Context(),
Native.funcInterpGetElse(Context().nCtx(), NativeObject()));
}
/**
* The arity of the function interpretation
**/
public int Arity() throws Z3Exception
{
return Native.funcInterpGetArity(Context().nCtx(), NativeObject());
}
/**
* A string representation of the function interpretation.
**/
public String toString()
{
try
{
String res = "";
res += "[";
for (Entry e : Entries())
{
int n = e.NumArgs();
if (n > 1)
res += "[";
Expr[] args = e.Args();
for (int i = 0; i < n; i++)
{
if (i != 0)
res += ", ";
res += args[i];
}
if (n > 1)
res += "]";
res += " -> " + e.Value() + ", ";
}
res += "else -> " + Else();
res += "]";
return res;
} catch (Z3Exception e)
{
return new String("Z3Exception: " + e.getMessage());
}
}
FuncInterp(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
void IncRef(long o) throws Z3Exception
{
Context().FuncInterp_DRQ().IncAndClear(Context(), o);
super.IncRef(o);
}
void DecRef(long o) throws Z3Exception
{
Context().FuncInterp_DRQ().Add(o);
super.DecRef(o);
}
}

View file

@ -0,0 +1,31 @@
/**
* Copyright (c) 2012 Microsoft Corporation
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
class FuncInterpDecRefQueue extends IDecRefQueue
{
public void IncRef(Context ctx, long obj)
{
try
{
Native.funcInterpIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
public void DecRef(Context ctx, long obj)
{
try
{
Native.funcInterpDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
};

View file

@ -0,0 +1,31 @@
/**
* Copyright (c) 2012 Microsoft Corporation
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
class FuncInterpEntryDecRefQueue extends IDecRefQueue
{
public void IncRef(Context ctx, long obj)
{
try
{
Native.funcEntryIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
public void DecRef(Context ctx, long obj)
{
try
{
Native.funcEntryDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
};

231
src/api/java/Goal.java Normal file
View file

@ -0,0 +1,231 @@
/**
* This file was automatically generated from Goal.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
import com.microsoft.z3.enumerations.*;
/**
* A goal (aka problem). A goal is essentially a set of formulas, that can be
* solved and/or transformed using tactics and solvers.
**/
public class Goal extends Z3Object
{
/**
* The precision of the goal. <remarks> Goals can be transformed using over
* and under approximations. An under approximation is applied when the
* objective is to find a model for a given goal. An over approximation is
* applied when the objective is to find a proof for a given goal.
* </remarks>
**/
public Z3_goal_prec Precision() throws Z3Exception
{
return Z3_goal_prec.fromInt(Native.goalPrecision(Context().nCtx(),
NativeObject()));
}
/**
* Indicates whether the goal is precise.
**/
public boolean IsPrecise() throws Z3Exception
{
return Precision() == Z3_goal_prec.Z3_GOAL_PRECISE;
}
/**
* Indicates whether the goal is an under-approximation.
**/
public boolean IsUnderApproximation() throws Z3Exception
{
return Precision() == Z3_goal_prec.Z3_GOAL_UNDER;
}
/**
* Indicates whether the goal is an over-approximation.
**/
public boolean IsOverApproximation() throws Z3Exception
{
return Precision() == Z3_goal_prec.Z3_GOAL_OVER;
}
/**
* Indicates whether the goal is garbage (i.e., the product of over- and
* under-approximations).
**/
public boolean IsGarbage() throws Z3Exception
{
return Precision() == Z3_goal_prec.Z3_GOAL_UNDER_OVER;
}
/**
* Adds the <paramref name="constraints"/> to the given goal.
*
* @throws Z3Exception
**/
public void Assert(BoolExpr[] constraints) throws Z3Exception
{
Context().CheckContextMatch(constraints);
for (BoolExpr c : constraints)
{
Native.goalAssert(Context().nCtx(), NativeObject(),
c.NativeObject());
}
}
/**
* Adds a <paramref name="constraint"/> to the given goal.
*
* @throws Z3Exception
**/
public void Assert(BoolExpr constraint) throws Z3Exception
{
Context().CheckContextMatch(constraint);
Native.goalAssert(Context().nCtx(), NativeObject(),
constraint.NativeObject());
}
/**
* Indicates whether the goal contains `false'.
**/
public boolean Inconsistent() throws Z3Exception
{
return Native.goalInconsistent(Context().nCtx(), NativeObject());
}
/**
* The depth of the goal. <remarks> This tracks how many transformations
* were applied to it. </remarks>
**/
public int Depth() throws Z3Exception
{
return Native.goalDepth(Context().nCtx(), NativeObject());
}
/**
* Erases all formulas from the given goal.
**/
public void Reset() throws Z3Exception
{
Native.goalReset(Context().nCtx(), NativeObject());
}
/**
* The number of formulas in the goal.
**/
public int Size() throws Z3Exception
{
return Native.goalSize(Context().nCtx(), NativeObject());
}
/**
* The formulas in the goal.
*
* @throws Z3Exception
**/
public BoolExpr[] Formulas() throws Z3Exception
{
int n = Size();
BoolExpr[] res = new BoolExpr[n];
for (int i = 0; i < n; i++)
res[i] = new BoolExpr(Context(), Native.goalFormula(Context()
.nCtx(), NativeObject(), i));
return res;
}
/**
* The number of formulas, subformulas and terms in the goal.
**/
public int NumExprs() throws Z3Exception
{
return Native.goalNumExprs(Context().nCtx(), NativeObject());
}
/**
* Indicates whether the goal is empty, and it is precise or the product of
* an under approximation.
**/
public boolean IsDecidedSat() throws Z3Exception
{
return Native.goalIsDecidedSat(Context().nCtx(), NativeObject());
}
/**
* Indicates whether the goal contains `false', and it is precise or the
* product of an over approximation.
**/
public boolean IsDecidedUnsat() throws Z3Exception
{
return Native.goalIsDecidedUnsat(Context().nCtx(), NativeObject());
}
/**
* Translates (copies) the Goal to the target Context <paramref
* name="ctx"/>.
*
* @throws Z3Exception
**/
public Goal Translate(Context ctx) throws Z3Exception
{
return new Goal(ctx, Native.goalTranslate(Context().nCtx(),
NativeObject(), ctx.nCtx()));
}
/**
* Simplifies the goal. <remarks>Essentially invokes the `simplify' tactic
* on the goal.</remarks>
**/
public Goal Simplify(Params p) throws Z3Exception
{
Tactic t = Context().MkTactic("simplify");
ApplyResult res = t.Apply(this, p);
if (res.NumSubgoals() == 0)
throw new Z3Exception("No subgoals");
else
return res.Subgoals()[0];
}
/**
* Goal to string conversion.
*
* @return A string representation of the Goal.
**/
public String toString()
{
try
{
return Native.goalToString(Context().nCtx(), NativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
Goal(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
Goal(Context ctx, boolean models, boolean unsatCores, boolean proofs)
throws Z3Exception
{
super(ctx, Native.mkGoal(ctx.nCtx(), (models) ? true : false,
(unsatCores) ? true : false, (proofs) ? true : false));
}
void IncRef(long o) throws Z3Exception
{
Context().Goal_DRQ().IncAndClear(Context(), o);
super.IncRef(o);
}
void DecRef(long o) throws Z3Exception
{
Context().Goal_DRQ().Add(o);
super.DecRef(o);
}
}

View file

@ -0,0 +1,31 @@
/**
* Copyright (c) 2012 Microsoft Corporation
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
class GoalDecRefQueue extends IDecRefQueue
{
public void IncRef(Context ctx, long obj)
{
try
{
Native.goalIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
public void DecRef(Context ctx, long obj)
{
try
{
Native.goalDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
};

View file

@ -0,0 +1,48 @@
/**
* This file was automatically generated from IDecRefQueue.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
import java.util.*;
abstract class IDecRefQueue
{
protected Object m_lock = new Object();
protected LinkedList<Long> m_queue = new LinkedList<Long>();
final int m_move_limit = 1024;
public abstract void IncRef(Context ctx, long obj);
public abstract void DecRef(Context ctx, long obj);
public void IncAndClear(Context ctx, long o)
{
IncRef(ctx, o);
if (m_queue.size() >= m_move_limit)
Clear(ctx);
}
public void Add(long o)
{
if (o == 0)
return;
synchronized (m_lock)
{
m_queue.add(o);
}
}
public void Clear(Context ctx)
{
synchronized (m_lock)
{
for (Long o : m_queue)
DecRef(ctx, o);
m_queue.clear();
}
}
}

View file

@ -17,9 +17,11 @@ Notes:
--*/
package com.Microsoft.Z3;
package com.microsoft.z3;
public class IDisposable
{
public void Dispose() {}
public void Dispose() throws Z3Exception
{
}
}

26
src/api/java/IntExpr.java Normal file
View file

@ -0,0 +1,26 @@
/**
* This file was automatically generated from IntExpr.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Int expressions
**/
public class IntExpr extends ArithExpr
{
/**
* Constructor for IntExpr </summary>
**/
protected IntExpr(Context ctx) throws Z3Exception
{
super(ctx);
}
IntExpr(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
}

65
src/api/java/IntNum.java Normal file
View file

@ -0,0 +1,65 @@
/**
* This file was automatically generated from IntNum.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
import java.math.BigInteger;
/**
* Integer Numerals
**/
public class IntNum extends IntExpr
{
IntNum(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
/**
* Retrieve the int value.
**/
public int Int() throws Z3Exception
{
Native.IntPtr res = new Native.IntPtr();
if (Native.getNumeralInt(Context().nCtx(), NativeObject(), res) ^ true)
throw new Z3Exception("Numeral is not an int");
return res.value;
}
/**
* Retrieve the 64-bit int value.
**/
public long Int64() throws Z3Exception
{
Native.LongPtr res = new Native.LongPtr();
if (Native.getNumeralInt64(Context().nCtx(), NativeObject(), res) ^ true)
throw new Z3Exception("Numeral is not an int64");
return res.value;
}
/**
* Retrieve the BigInteger value.
**/
public BigInteger BigInteger() throws Z3Exception
{
return new BigInteger(this.toString());
}
/**
* Returns a string representation of the numeral.
**/
public String toString()
{
try
{
return Native.getNumeralString(Context().nCtx(), NativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
}

23
src/api/java/IntSort.java Normal file
View file

@ -0,0 +1,23 @@
/**
* This file was automatically generated from IntSort.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* An Integer sort
**/
public class IntSort extends ArithSort
{
IntSort(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
IntSort(Context ctx) throws Z3Exception
{
super(ctx, Native.mkIntSort(ctx.nCtx()));
}
}

View file

@ -0,0 +1,44 @@
/**
* This file was automatically generated from IntSymbol.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
import com.microsoft.z3.enumerations.*;
/**
* Numbered symbols
**/
public class IntSymbol extends Symbol
{
/**
* The int value of the symbol. <remarks>Throws an exception if the symbol
* is not of int kind. </remarks>
**/
public int Int() throws Z3Exception
{
if (!IsIntSymbol())
throw new Z3Exception("Int requested from non-Int symbol");
return Native.getSymbolInt(Context().nCtx(), NativeObject());
}
IntSymbol(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
IntSymbol(Context ctx, int i) throws Z3Exception
{
super(ctx, Native.mkIntSymbol(ctx.nCtx(), i));
}
void CheckNativeObject(long obj) throws Z3Exception
{
if (Native.getSymbolKind(Context().nCtx(), obj) != Z3_symbol_kind.Z3_INT_SYMBOL
.toInt())
throw new Z3Exception("Symbol is not of integer kind");
super.CheckNativeObject(obj);
}
}

101
src/api/java/ListSort.java Normal file
View file

@ -0,0 +1,101 @@
/**
* This file was automatically generated from ListSort.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* List sorts.
**/
public class ListSort extends Sort
{
/**
* The declaration of the nil function of this list sort.
**/
public FuncDecl NilDecl()
{
return nilDecl;
}
/**
* The empty list.
**/
public Expr Nil()
{
return nilConst;
}
/**
* The declaration of the isNil function of this list sort.
**/
public FuncDecl IsNilDecl()
{
return isNilDecl;
}
/**
* The declaration of the cons function of this list sort.
**/
public FuncDecl ConsDecl()
{
return consDecl;
}
/**
* The declaration of the isCons function of this list sort.
*
**/
public FuncDecl IsConsDecl()
{
return isConsDecl;
}
/**
* The declaration of the head function of this list sort.
**/
public FuncDecl HeadDecl()
{
return headDecl;
}
/**
* The declaration of the tail function of this list sort.
**/
public FuncDecl TailDecl()
{
return tailDecl;
}
private FuncDecl nilDecl, isNilDecl, consDecl, isConsDecl, headDecl,
tailDecl;
private Expr nilConst;
ListSort(Context ctx, Symbol name, Sort elemSort) throws Z3Exception
{
super(ctx);
Native.LongPtr inil = new Native.LongPtr(), iisnil = new Native.LongPtr();
Native.LongPtr icons = new Native.LongPtr(), iiscons = new Native.LongPtr();
Native.LongPtr ihead = new Native.LongPtr(), itail = new Native.LongPtr();
setNativeObject(Native.mkListSort(ctx.nCtx(), name.NativeObject(),
elemSort.NativeObject(), inil, iisnil, icons, iiscons, ihead,
itail));
nilDecl = new FuncDecl(ctx, inil.value);
isNilDecl = new FuncDecl(ctx, iisnil.value);
consDecl = new FuncDecl(ctx, icons.value);
isConsDecl = new FuncDecl(ctx, iiscons.value);
headDecl = new FuncDecl(ctx, ihead.value);
tailDecl = new FuncDecl(ctx, itail.value);
nilConst = ctx.MkConst(nilDecl);
}
};

60
src/api/java/Log.java Normal file
View file

@ -0,0 +1,60 @@
/**
* This file was automatically generated from Log.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Interaction logging for Z3. <remarks> Note that this is a global, static log
* and if multiple Context objects are created, it logs the interaction with all
* of them. </remarks>
**/
public final class Log
{
private static boolean m_is_open = false;
/**
* Open an interaction log file. <param name="filename">the name of the file
* to open</param>
*
* @return True if opening the log file succeeds, false otherwise.
**/
public static boolean Open(String filename)
{
m_is_open = true;
return Native.openLog(filename) == 1;
}
/**
* Closes the interaction log.
**/
public static void Close()
{
m_is_open = false;
Native.closeLog();
}
/**
* Appends the user-provided string <paramref name="s"/> to the interaction
* log.
* @throws Z3Exception
**/
public static void Append(String s) throws Z3Exception
{
if (!m_is_open)
throw new Z3Exception("Log cannot be closed.");
Native.appendLog(s);
}
/**
* Checks whether the interaction log is opened.
*
* @return True if the interaction log is open, false otherwise.
**/
public static boolean isOpen()
{
return m_is_open;
}
}

302
src/api/java/Model.java Normal file
View file

@ -0,0 +1,302 @@
/**
* This file was automatically generated from Model.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
import com.microsoft.z3.enumerations.*;
/**
* A Model contains interpretations (assignments) of constants and functions.
**/
public class Model extends Z3Object
{
/**
* Retrieves the interpretation (the assignment) of <paramref name="a"/> in
* the model. <param name="a">A Constant</param>
*
* @return An expression if the constant has an interpretation in the model,
* null otherwise.
* @throws Z3Exception
**/
public Expr ConstInterp(Expr a) throws Z3Exception
{
Context().CheckContextMatch(a);
return ConstInterp(a.FuncDecl());
}
/**
* Retrieves the interpretation (the assignment) of <paramref name="f"/> in
* the model. <param name="f">A function declaration of zero arity</param>
*
* @return An expression if the function has an interpretation in the model,
* null otherwise.
* @throws Z3Exception
**/
public Expr ConstInterp(FuncDecl f) throws Z3Exception
{
Context().CheckContextMatch(f);
if (f.Arity() != 0
|| Native.getSortKind(Context().nCtx(),
Native.getRange(Context().nCtx(), f.NativeObject())) == Z3_sort_kind.Z3_ARRAY_SORT
.toInt())
throw new Z3Exception(
"Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp.");
long n = Native.modelGetConstInterp(Context().nCtx(), NativeObject(),
f.NativeObject());
if (n == 0)
return null;
else
return Expr.Create(Context(), n);
}
/**
* Retrieves the interpretation (the assignment) of a non-constant <paramref
* name="f"/> in the model. <param name="f">A function declaration of
* non-zero arity</param>
*
* @return A FunctionInterpretation if the function has an interpretation in
* the model, null otherwise.
* @throws Z3Exception
**/
public FuncInterp FuncInterp(FuncDecl f) throws Z3Exception
{
Context().CheckContextMatch(f);
Z3_sort_kind sk = Z3_sort_kind.fromInt(Native.getSortKind(Context()
.nCtx(), Native.getRange(Context().nCtx(), f.NativeObject())));
if (f.Arity() == 0)
{
long n = Native.modelGetConstInterp(Context().nCtx(),
NativeObject(), f.NativeObject());
if (sk == Z3_sort_kind.Z3_ARRAY_SORT)
{
if (n == 0)
return null;
else
{
if (Native.isAsArray(Context().nCtx(), n) ^ true)
throw new Z3Exception(
"Argument was not an array constant");
long fd = Native.getAsArrayFuncDecl(Context().nCtx(), n);
return FuncInterp(new FuncDecl(Context(), fd));
}
} else
{
throw new Z3Exception(
"Constant functions do not have a function interpretation; use ConstInterp");
}
} else
{
long n = Native.modelGetFuncInterp(Context().nCtx(),
NativeObject(), f.NativeObject());
if (n == 0)
return null;
else
return new FuncInterp(Context(), n);
}
}
/**
* The number of constants that have an interpretation in the model.
**/
public int NumConsts() throws Z3Exception
{
return Native.modelGetNumConsts(Context().nCtx(), NativeObject());
}
/**
* The function declarations of the constants in the model.
*
* @throws Z3Exception
**/
public FuncDecl[] ConstDecls() throws Z3Exception
{
int n = NumConsts();
FuncDecl[] res = new FuncDecl[n];
for (int i = 0; i < n; i++)
res[i] = new FuncDecl(Context(), Native.modelGetConstDecl(Context()
.nCtx(), NativeObject(), i));
return res;
}
/**
* The number of function interpretations in the model.
**/
public int NumFuncs() throws Z3Exception
{
return Native.modelGetNumFuncs(Context().nCtx(), NativeObject());
}
/**
* The function declarations of the function interpretations in the model.
*
* @throws Z3Exception
**/
public FuncDecl[] FuncDecls() throws Z3Exception
{
int n = NumFuncs();
FuncDecl[] res = new FuncDecl[n];
for (int i = 0; i < n; i++)
res[i] = new FuncDecl(Context(), Native.modelGetFuncDecl(Context()
.nCtx(), NativeObject(), i));
return res;
}
/**
* All symbols that have an interpretation in the model.
*
* @throws Z3Exception
**/
public FuncDecl[] Decls() throws Z3Exception
{
int nFuncs = NumFuncs();
int nConsts = NumConsts();
int n = nFuncs + nConsts;
FuncDecl[] res = new FuncDecl[n];
for (int i = 0; i < nConsts; i++)
res[i] = new FuncDecl(Context(), Native.modelGetConstDecl(Context()
.nCtx(), NativeObject(), i));
for (int i = 0; i < nFuncs; i++)
res[nConsts + i] = new FuncDecl(Context(), Native.modelGetFuncDecl(
Context().nCtx(), NativeObject(), i));
return res;
}
/**
* A ModelEvaluationFailedException is thrown when an expression cannot be
* evaluated by the model.
**/
@SuppressWarnings("serial")
public class ModelEvaluationFailedException extends Z3Exception
{
/**
* An exception that is thrown when model evaluation fails.
**/
public ModelEvaluationFailedException()
{
super();
}
}
/**
* Evaluates the expression <paramref name="t"/> in the current model.
* <remarks> This function may fail if <paramref name="t"/> contains
* quantifiers, is partial (MODEL_PARTIAL enabled), or if <paramref
* name="t"/> is not well-sorted. In this case a
* <code>ModelEvaluationFailedException</code> is thrown. </remarks> <param
* name="t">An expression</param> <param name="completion"> When this flag
* is enabled, a model value will be assigned to any constant or function
* that does not have an interpretation in the model. </param>
*
* @return The evaluation of <paramref name="t"/> in the model.
* @throws Z3Exception
**/
public Expr Eval(Expr t, boolean completion) throws Z3Exception
{
Native.LongPtr v = new Native.LongPtr();
if (Native.modelEval(Context().nCtx(), NativeObject(),
t.NativeObject(), (completion) ? true : false, v) ^ true)
throw new ModelEvaluationFailedException();
else
return Expr.Create(Context(), v.value);
}
/**
* Alias for <code>Eval</code>.
*
* @throws Z3Exception
**/
public Expr Evaluate(Expr t, boolean completion) throws Z3Exception
{
return Eval(t, completion);
}
/**
* The number of uninterpreted sorts that the model has an interpretation
* for.
**/
public int NumSorts() throws Z3Exception
{
return Native.modelGetNumSorts(Context().nCtx(), NativeObject());
}
/**
* The uninterpreted sorts that the model has an interpretation for.
* <remarks> Z3 also provides an intepretation for uninterpreted sorts used
* in a formula. The interpretation for a sort is a finite set of distinct
* values. We say this finite set is the "universe" of the sort. </remarks>
* <seealso cref="NumSorts"/> <seealso cref="SortUniverse"/>
*
* @throws Z3Exception
**/
public Sort[] Sorts() throws Z3Exception
{
int n = NumSorts();
Sort[] res = new Sort[n];
for (int i = 0; i < n; i++)
res[i] = Sort.Create(Context(),
Native.modelGetSort(Context().nCtx(), NativeObject(), i));
return res;
}
/**
* The finite set of distinct values that represent the interpretation for
* sort <paramref name="s"/>. <seealso cref="Sorts"/> <param name="s">An
* uninterpreted sort</param>
*
* @return An array of expressions, where each is an element of the universe
* of <paramref name="s"/>
* @throws Z3Exception
**/
public Expr[] SortUniverse(Sort s) throws Z3Exception
{
ASTVector nUniv = new ASTVector(Context(), Native.modelGetSortUniverse(
Context().nCtx(), NativeObject(), s.NativeObject()));
int n = nUniv.Size();
Expr[] res = new Expr[n];
for (int i = 0; i < n; i++)
res[i] = Expr.Create(Context(), nUniv.get(i).NativeObject());
return res;
}
/**
* Conversion of models to strings.
*
* @return A string representation of the model.
**/
public String toString()
{
try
{
return Native.modelToString(Context().nCtx(), NativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
Model(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
void IncRef(long o) throws Z3Exception
{
Context().Model_DRQ().IncAndClear(Context(), o);
super.IncRef(o);
}
void DecRef(long o) throws Z3Exception
{
Context().Model_DRQ().Add(o);
super.DecRef(o);
}
}

View file

@ -0,0 +1,31 @@
/**
* Copyright (c) 2012 Microsoft Corporation
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
class ModelDecRefQueue extends IDecRefQueue
{
public void IncRef(Context ctx, long obj)
{
try
{
Native.modelIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
public void DecRef(Context ctx, long obj)
{
try
{
Native.modelDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
};

View file

@ -0,0 +1,91 @@
/**
* This file was automatically generated from ParamDescrs.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
import com.microsoft.z3.enumerations.*;
/**
* A ParamDescrs describes a set of parameters.
**/
public class ParamDescrs extends Z3Object
{
/**
* validate a set of parameters.
**/
public void Validate(Params p) throws Z3Exception
{
Native.paramsValidate(Context().nCtx(), p.NativeObject(),
NativeObject());
}
/**
* Retrieve kind of parameter.
**/
public Z3_param_kind GetKind(Symbol name) throws Z3Exception
{
return Z3_param_kind.fromInt(Native.paramDescrsGetKind(
Context().nCtx(), NativeObject(), name.NativeObject()));
}
/**
* Retrieve all names of parameters.
*
* @throws Z3Exception
**/
public Symbol[] Names() throws Z3Exception
{
int sz = Native.paramDescrsSize(Context().nCtx(), NativeObject());
Symbol[] names = new Symbol[sz];
for (int i = 0; i < sz; ++i)
{
names[i] = Symbol.Create(Context(), Native.paramDescrsGetName(
Context().nCtx(), NativeObject(), i));
}
return names;
}
/**
* The size of the ParamDescrs.
**/
public int Size() throws Z3Exception
{
return Native.paramDescrsSize(Context().nCtx(), NativeObject());
}
/**
* Retrieves a string representation of the ParamDescrs.
**/
public String toString()
{
try
{
return Native.paramDescrsToString(Context().nCtx(), NativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
ParamDescrs(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
void IncRef(long o) throws Z3Exception
{
Context().ParamDescrs_DRQ().IncAndClear(Context(), o);
super.IncRef(o);
}
void DecRef(long o) throws Z3Exception
{
Context().ParamDescrs_DRQ().Add(o);
super.DecRef(o);
}
}

View file

@ -0,0 +1,31 @@
/**
* Copyright (c) 2012 Microsoft Corporation
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
class ParamDescrsDecRefQueue extends IDecRefQueue
{
public void IncRef(Context ctx, long obj)
{
try
{
Native.paramDescrsIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
public void DecRef(Context ctx, long obj)
{
try
{
Native.paramDescrsDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
};

108
src/api/java/Params.java Normal file
View file

@ -0,0 +1,108 @@
/**
* This file was automatically generated from Params.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* A ParameterSet represents a configuration in the form of Symbol/value pairs.
**/
public class Params extends Z3Object
{
/**
* Adds a parameter setting.
**/
public void Add(Symbol name, boolean value) throws Z3Exception
{
Native.paramsSetBool(Context().nCtx(), NativeObject(),
name.NativeObject(), (value) ? true : false);
}
/**
* Adds a parameter setting.
**/
public void Add(Symbol name, double value) throws Z3Exception
{
Native.paramsSetDouble(Context().nCtx(), NativeObject(),
name.NativeObject(), value);
}
/**
* Adds a parameter setting.
**/
public void Add(Symbol name, Symbol value) throws Z3Exception
{
Native.paramsSetSymbol(Context().nCtx(), NativeObject(),
name.NativeObject(), value.NativeObject());
}
/**
* Adds a parameter setting.
**/
public void Add(String name, boolean value) throws Z3Exception
{
Native.paramsSetBool(Context().nCtx(), NativeObject(),
Context().MkSymbol(name).NativeObject(), value);
}
/**
* Adds a parameter setting.
**/
public void Add(String name, int value) throws Z3Exception
{
Native.paramsSetUint(Context().nCtx(), NativeObject(), Context()
.MkSymbol(name).NativeObject(), value);
}
/**
* Adds a parameter setting.
**/
public void Add(String name, double value) throws Z3Exception
{
Native.paramsSetDouble(Context().nCtx(), NativeObject(), Context()
.MkSymbol(name).NativeObject(), value);
}
/**
* Adds a parameter setting.
**/
public void Add(String name, Symbol value) throws Z3Exception
{
Native.paramsSetSymbol(Context().nCtx(), NativeObject(), Context()
.MkSymbol(name).NativeObject(), value.NativeObject());
}
/**
* A string representation of the parameter set.
**/
public String toString()
{
try
{
return Native.paramsToString(Context().nCtx(), NativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
Params(Context ctx) throws Z3Exception
{
super(ctx, Native.mkParams(ctx.nCtx()));
}
void IncRef(long o) throws Z3Exception
{
Context().Params_DRQ().IncAndClear(Context(), o);
super.IncRef(o);
}
void DecRef(long o) throws Z3Exception
{
Context().Params_DRQ().Add(o);
super.DecRef(o);
}
}

View file

@ -0,0 +1,31 @@
/**
* Copyright (c) 2012 Microsoft Corporation
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
class ParamsDecRefQueue extends IDecRefQueue
{
public void IncRef(Context ctx, long obj)
{
try
{
Native.paramsIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
public void DecRef(Context ctx, long obj)
{
try
{
Native.paramsDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
};

57
src/api/java/Pattern.java Normal file
View file

@ -0,0 +1,57 @@
/**
* This file was automatically generated from Pattern.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Patterns comprise a list of terms. The list should be non-empty. If the list
* comprises of more than one term, it is also called a multi-pattern.
**/
public class Pattern extends AST
{
/**
* The number of terms in the pattern.
**/
public int NumTerms() throws Z3Exception
{
return Native.getPatternNumTerms(Context().nCtx(), NativeObject());
}
/**
* The terms in the pattern.
*
* @throws Z3Exception
**/
public Expr[] Terms() throws Z3Exception
{
int n = NumTerms();
Expr[] res = new Expr[n];
for (int i = 0; i < n; i++)
res[i] = Expr.Create(Context(),
Native.getPattern(Context().nCtx(), NativeObject(), i));
return res;
}
/**
* A string representation of the pattern.
**/
public String toString()
{
try
{
return Native.patternToString(Context().nCtx(), NativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
Pattern(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
}

63
src/api/java/Probe.java Normal file
View file

@ -0,0 +1,63 @@
/**
* This file was automatically generated from Probe.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Probes are used to inspect a goal (aka problem) and collect information that
* may be used to decide which solver and/or preprocessing step will be used.
* The complete list of probes may be obtained using the procedures
* <code>Context.NumProbes</code> and <code>Context.ProbeNames</code>. It may
* also be obtained using the command <code>(help-tactics)</code> in the SMT 2.0
* front-end.
**/
public class Probe extends Z3Object
{
/**
* Execute the probe over the goal.
*
* @return A probe always produce a double value. "Boolean" probes return
* 0.0 for false, and a value different from 0.0 for true.
* @throws Z3Exception
**/
public double Apply(Goal g) throws Z3Exception
{
Context().CheckContextMatch(g);
return Native.probeApply(Context().nCtx(), NativeObject(),
g.NativeObject());
}
/**
* Apply the probe to a goal.
* @throws Z3Exception
**/
public double get(Goal g) throws Z3Exception
{
return Apply(g);
}
Probe(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
Probe(Context ctx, String name) throws Z3Exception
{
super(ctx, Native.mkProbe(ctx.nCtx(), name));
}
void IncRef(long o) throws Z3Exception
{
Context().Probe_DRQ().IncAndClear(Context(), o);
super.IncRef(o);
}
void DecRef(long o) throws Z3Exception
{
Context().Probe_DRQ().Add(o);
super.DecRef(o);
}
}

View file

@ -0,0 +1,31 @@
/**
* Copyright (c) 2012 Microsoft Corporation
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
class ProbeDecRefQueue extends IDecRefQueue
{
public void IncRef(Context ctx, long obj)
{
try
{
Native.probeIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
public void DecRef(Context ctx, long obj)
{
try
{
Native.probeDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
};

View file

@ -0,0 +1,214 @@
/**
* This file was automatically generated from Quantifier.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
import com.microsoft.z3.enumerations.*;
/**
* Quantifier expressions.
**/
public class Quantifier extends BoolExpr
{
/**
* Indicates whether the quantifier is universal.
**/
public boolean IsUniversal() throws Z3Exception
{
return Native.isQuantifierForall(Context().nCtx(), NativeObject());
}
/**
* Indicates whether the quantifier is existential.
**/
public boolean IsExistential() throws Z3Exception
{
return !IsUniversal();
}
/**
* The weight of the quantifier.
**/
public int Weight() throws Z3Exception
{
return Native.getQuantifierWeight(Context().nCtx(), NativeObject());
}
/**
* The number of patterns.
**/
public int NumPatterns() throws Z3Exception
{
return Native
.getQuantifierNumPatterns(Context().nCtx(), NativeObject());
}
/**
* The patterns.
*
* @throws Z3Exception
**/
public Pattern[] Patterns() throws Z3Exception
{
int n = NumPatterns();
Pattern[] res = new Pattern[n];
for (int i = 0; i < n; i++)
res[i] = new Pattern(Context(), Native.getQuantifierPatternAst(
Context().nCtx(), NativeObject(), i));
return res;
}
/**
* The number of no-patterns.
**/
public int NumNoPatterns() throws Z3Exception
{
return Native.getQuantifierNumNoPatterns(Context().nCtx(),
NativeObject());
}
/**
* The no-patterns.
*
* @throws Z3Exception
**/
public Pattern[] NoPatterns() throws Z3Exception
{
int n = NumNoPatterns();
Pattern[] res = new Pattern[n];
for (int i = 0; i < n; i++)
res[i] = new Pattern(Context(), Native.getQuantifierNoPatternAst(
Context().nCtx(), NativeObject(), i));
return res;
}
/**
* The number of bound variables.
**/
public int NumBound() throws Z3Exception
{
return Native.getQuantifierNumBound(Context().nCtx(), NativeObject());
}
/**
* The symbols for the bound variables.
*
* @throws Z3Exception
**/
public Symbol[] BoundVariableNames() throws Z3Exception
{
int n = NumBound();
Symbol[] res = new Symbol[n];
for (int i = 0; i < n; i++)
res[i] = Symbol.Create(Context(), Native.getQuantifierBoundName(
Context().nCtx(), NativeObject(), i));
return res;
}
/**
* The sorts of the bound variables.
*
* @throws Z3Exception
**/
public Sort[] BoundVariableSorts() throws Z3Exception
{
int n = NumBound();
Sort[] res = new Sort[n];
for (int i = 0; i < n; i++)
res[i] = Sort.Create(Context(), Native.getQuantifierBoundSort(
Context().nCtx(), NativeObject(), i));
return res;
}
/**
* The body of the quantifier.
*
* @throws Z3Exception
**/
public BoolExpr Body() throws Z3Exception
{
return new BoolExpr(Context(), Native.getQuantifierBody(Context()
.nCtx(), NativeObject()));
}
Quantifier(Context ctx, boolean isForall, Sort[] sorts, Symbol[] names,
Expr body, int weight, Pattern[] patterns, Expr[] noPatterns,
Symbol quantifierID, Symbol skolemID) throws Z3Exception
{
super(ctx);
Context().CheckContextMatch(patterns);
Context().CheckContextMatch(noPatterns);
Context().CheckContextMatch(sorts);
Context().CheckContextMatch(names);
Context().CheckContextMatch(body);
if (sorts.length != names.length)
throw new Z3Exception(
"Number of sorts does not match number of names");
if (noPatterns == null && quantifierID == null && skolemID == null)
{
setNativeObject(Native.mkQuantifier(ctx.nCtx(), (isForall) ? true
: false, weight, AST.ArrayLength(patterns), AST
.ArrayToNative(patterns), AST.ArrayLength(sorts), AST
.ArrayToNative(sorts), Symbol.ArrayToNative(names), body
.NativeObject()));
} else
{
setNativeObject(Native.mkQuantifierEx(ctx.nCtx(),
(isForall) ? true : false, weight, AST.GetNativeObject(quantifierID),
AST.GetNativeObject(skolemID),
AST.ArrayLength(patterns), AST.ArrayToNative(patterns),
AST.ArrayLength(noPatterns), AST.ArrayToNative(noPatterns),
AST.ArrayLength(sorts), AST.ArrayToNative(sorts),
Symbol.ArrayToNative(names),
body.NativeObject()));
}
}
Quantifier(Context ctx, boolean isForall, Expr[] bound, Expr body,
int weight, Pattern[] patterns, Expr[] noPatterns,
Symbol quantifierID, Symbol skolemID) throws Z3Exception
{
super(ctx);
Context().CheckContextMatch(noPatterns);
Context().CheckContextMatch(patterns);
// Context().CheckContextMatch(bound);
Context().CheckContextMatch(body);
if (noPatterns == null && quantifierID == null && skolemID == null)
{
setNativeObject(Native.mkQuantifierConst(ctx.nCtx(),
(isForall) ? true : false, weight, AST.ArrayLength(bound),
AST.ArrayToNative(bound), AST.ArrayLength(patterns),
AST.ArrayToNative(patterns), body.NativeObject()));
} else
{
setNativeObject(Native.mkQuantifierConstEx(ctx.nCtx(),
(isForall) ? true : false, weight,
AST.GetNativeObject(quantifierID),
AST.GetNativeObject(skolemID), AST.ArrayLength(bound),
AST.ArrayToNative(bound), AST.ArrayLength(patterns),
AST.ArrayToNative(patterns), AST.ArrayLength(noPatterns),
AST.ArrayToNative(noPatterns), body.NativeObject()));
}
}
Quantifier(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
void CheckNativeObject(long obj) throws Z3Exception
{
if (Native.getAstKind(Context().nCtx(), obj) != Z3_ast_kind.Z3_QUANTIFIER_AST
.toInt())
throw new Z3Exception("Underlying object is not a quantifier");
super.CheckNativeObject(obj);
}
}

80
src/api/java/RatNum.java Normal file
View file

@ -0,0 +1,80 @@
/**
* This file was automatically generated from RatNum.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
import java.math.BigInteger;
/**
* Rational Numerals
**/
public class RatNum extends RealExpr
{
/**
* The numerator of a rational numeral.
**/
public IntNum Numerator() throws Z3Exception
{
return new IntNum(Context(), Native.getNumerator(Context().nCtx(),
NativeObject()));
}
/**
* The denominator of a rational numeral.
**/
public IntNum Denominator() throws Z3Exception
{
return new IntNum(Context(), Native.getDenominator(Context().nCtx(),
NativeObject()));
}
/**
* Converts the numerator of the rational to a BigInteger
**/
public BigInteger BigIntNumerator() throws Z3Exception
{
IntNum n = Numerator();
return new BigInteger(n.toString());
}
/**
* Converts the denominator of the rational to a BigInteger
**/
public BigInteger BigIntDenominator() throws Z3Exception
{
IntNum n = Denominator();
return new BigInteger(n.toString());
}
/**
* Returns a string representation in decimal notation. <remarks>The result
* has at most <paramref name="precision"/> decimal places.</remarks>
**/
public String ToDecimalString(int precision) throws Z3Exception
{
return Native.getNumeralDecimalString(Context().nCtx(), NativeObject(),
precision);
}
/**
* Returns a string representation of the numeral.
**/
public String toString()
{
try
{
return Native.getNumeralString(Context().nCtx(), NativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
RatNum(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
}

View file

@ -0,0 +1,26 @@
/**
* This file was automatically generated from RealExpr.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Real expressions
**/
public class RealExpr extends ArithExpr
{
/**
* Constructor for RealExpr </summary>
**/
protected RealExpr(Context ctx)
{
super(ctx);
}
RealExpr(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
}

View file

@ -0,0 +1,23 @@
/**
* This file was automatically generated from RealSort.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* A real sort
**/
public class RealSort extends ArithSort
{
RealSort(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
RealSort(Context ctx) throws Z3Exception
{
super(ctx, Native.mkRealSort(ctx.nCtx()));
}
}

View file

@ -0,0 +1,46 @@
/**
* This file was automatically generated from RelationSort.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Relation sorts.
**/
public class RelationSort extends Sort
{
/**
* The arity of the relation sort.
**/
public int Arity() throws Z3Exception
{
return Native.getRelationArity(Context().nCtx(), NativeObject());
}
/**
* The sorts of the columns of the relation sort.
* @throws Z3Exception
**/
public Sort[] ColumnSorts() throws Z3Exception
{
if (m_columnSorts != null)
return m_columnSorts;
int n = Arity();
Sort[] res = new Sort[n];
for (int i = 0; i < n; i++)
res[i] = Sort.Create(Context(), Native.getRelationColumn(Context()
.nCtx(), NativeObject(), i));
return res;
}
private Sort[] m_columnSorts = null;
RelationSort(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
}

23
src/api/java/SetSort.java Normal file
View file

@ -0,0 +1,23 @@
/**
* This file was automatically generated from SetSort.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Set sorts.
**/
public class SetSort extends Sort
{
SetSort(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
SetSort(Context ctx, Sort ty) throws Z3Exception
{
super(ctx, Native.mkSetSort(ctx.nCtx(), ty.NativeObject()));
}
}

286
src/api/java/Solver.java Normal file
View file

@ -0,0 +1,286 @@
/**
* This file was automatically generated from Solver.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
import com.microsoft.z3.enumerations.*;
/**
* Solvers.
**/
public class Solver extends Z3Object
{
/**
* A string that describes all available solver parameters.
**/
public String Help() throws Z3Exception
{
return Native.solverGetHelp(Context().nCtx(), NativeObject());
}
/**
* Sets the solver parameters.
*
* @throws Z3Exception
**/
public void setParameters(Params value) throws Z3Exception
{
Context().CheckContextMatch(value);
Native.solverSetParams(Context().nCtx(), NativeObject(),
value.NativeObject());
}
/**
* Retrieves parameter descriptions for solver.
*
* @throws Z3Exception
**/
public ParamDescrs ParameterDescriptions() throws Z3Exception
{
return new ParamDescrs(Context(), Native.solverGetParamDescrs(Context()
.nCtx(), NativeObject()));
}
/**
* The current number of backtracking points (scopes). <seealso cref="Pop"/>
* <seealso cref="Push"/>
**/
public int NumScopes() throws Z3Exception
{
return Native.solverGetNumScopes(Context().nCtx(), NativeObject());
}
/**
* Creates a backtracking point. <seealso cref="Pop"/>
**/
public void Push() throws Z3Exception
{
Native.solverPush(Context().nCtx(), NativeObject());
}
/**
* Backtracks one backtracking point. <remarks>.
**/
public void Pop() throws Z3Exception
{
Pop(1);
}
/**
* Backtracks <paramref name="n"/> backtracking points. <remarks>Note that
* an exception is thrown if <paramref name="n"/> is not smaller than
* <code>NumScopes</code></remarks> <seealso cref="Push"/>
**/
public void Pop(int n) throws Z3Exception
{
Native.solverPop(Context().nCtx(), NativeObject(), n);
}
/**
* Resets the Solver. <remarks>This removes all assertions from the
* solver.</remarks>
**/
public void Reset() throws Z3Exception
{
Native.solverReset(Context().nCtx(), NativeObject());
}
/**
* Assert a multiple constraints into the solver.
*
* @throws Z3Exception
**/
public void Assert(BoolExpr[] constraints) throws Z3Exception
{
Context().CheckContextMatch(constraints);
for (BoolExpr a : constraints)
{
Native.solverAssert(Context().nCtx(), NativeObject(),
a.NativeObject());
}
}
/**
* Assert one constraint into the solver.
*
* @throws Z3Exception
**/
public void Assert(BoolExpr constraint) throws Z3Exception
{
Context().CheckContextMatch(constraint);
Native.solverAssert(Context().nCtx(), NativeObject(),
constraint.NativeObject());
}
/**
* The number of assertions in the solver.
*
* @throws Z3Exception
**/
public int NumAssertions() throws Z3Exception
{
ASTVector ass = new ASTVector(Context(), Native.solverGetAssertions(
Context().nCtx(), NativeObject()));
return ass.Size();
}
/**
* The set of asserted formulas.
*
* @throws Z3Exception
**/
public BoolExpr[] Assertions() throws Z3Exception
{
ASTVector ass = new ASTVector(Context(), Native.solverGetAssertions(
Context().nCtx(), NativeObject()));
int n = ass.Size();
BoolExpr[] res = new BoolExpr[n];
for (int i = 0; i < n; i++)
res[i] = new BoolExpr(Context(), ass.get(i).NativeObject());
return res;
}
/**
* Checks whether the assertions in the solver are consistent or not.
* <remarks> <seealso cref="Model"/> <seealso cref="UnsatCore"/> <seealso
* cref="Proof"/> </remarks>
**/
public Status Check(Expr[] assumptions) throws Z3Exception
{
Z3_lbool r;
if (assumptions == null)
r = Z3_lbool.fromInt(Native.solverCheck(Context().nCtx(),
NativeObject()));
else
r = Z3_lbool.fromInt(Native.solverCheckAssumptions(
Context().nCtx(), NativeObject(), (int) assumptions.length,
AST.ArrayToNative(assumptions)));
switch (r)
{
case Z3_L_TRUE:
return Status.SATISFIABLE;
case Z3_L_FALSE:
return Status.UNSATISFIABLE;
default:
return Status.UNKNOWN;
}
}
/**
* Checks whether the assertions in the solver are consistent or not.
* <remarks> <seealso cref="Model"/> <seealso cref="UnsatCore"/> <seealso
* cref="Proof"/> </remarks>
**/
public Status Check() throws Z3Exception
{
return Check(null);
}
/**
* The model of the last <code>Check</code>. <remarks> The result is
* <code>null</code> if <code>Check</code> was not invoked before, if its
* results was not <code>SATISFIABLE</code>, or if model production is not
* enabled. </remarks>
*
* @throws Z3Exception
**/
public Model Model() throws Z3Exception
{
long x = Native.solverGetModel(Context().nCtx(), NativeObject());
if (x == 0)
return null;
else
return new Model(Context(), x);
}
/**
* The proof of the last <code>Check</code>. <remarks> The result is
* <code>null</code> if <code>Check</code> was not invoked before, if its
* results was not <code>UNSATISFIABLE</code>, or if proof production is
* disabled. </remarks>
*
* @throws Z3Exception
**/
public Expr Proof() throws Z3Exception
{
long x = Native.solverGetProof(Context().nCtx(), NativeObject());
if (x == 0)
return null;
else
return Expr.Create(Context(), x);
}
/**
* The unsat core of the last <code>Check</code>. <remarks> The unsat core
* is a subset of <code>Assertions</code> The result is empty if
* <code>Check</code> was not invoked before, if its results was not
* <code>UNSATISFIABLE</code>, or if core production is disabled. </remarks>
*
* @throws Z3Exception
**/
public Expr[] UnsatCore() throws Z3Exception
{
ASTVector core = new ASTVector(Context(), Native.solverGetUnsatCore(
Context().nCtx(), NativeObject()));
int n = core.Size();
Expr[] res = new Expr[n];
for (int i = 0; i < n; i++)
res[i] = Expr.Create(Context(), core.get(i).NativeObject());
return res;
}
/**
* A brief justification of why the last call to <code>Check</code> returned
* <code>UNKNOWN</code>.
**/
public String ReasonUnknown() throws Z3Exception
{
return Native.solverGetReasonUnknown(Context().nCtx(), NativeObject());
}
/**
* Solver statistics.
*
* @throws Z3Exception
**/
public Statistics Statistics() throws Z3Exception
{
return new Statistics(Context(), Native.solverGetStatistics(Context()
.nCtx(), NativeObject()));
}
/**
* A string representation of the solver.
**/
public String toString()
{
try
{
return Native.solverToString(Context().nCtx(), NativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
Solver(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
void IncRef(long o) throws Z3Exception
{
Context().Solver_DRQ().IncAndClear(Context(), o);
super.IncRef(o);
}
void DecRef(long o) throws Z3Exception
{
Context().Solver_DRQ().Add(o);
super.DecRef(o);
}
}

View file

@ -0,0 +1,31 @@
/**
* Copyright (c) 2012 Microsoft Corporation
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
class SolverDecRefQueue extends IDecRefQueue
{
public void IncRef(Context ctx, long obj)
{
try
{
Native.solverIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
public void DecRef(Context ctx, long obj)
{
try
{
Native.solverDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
};

154
src/api/java/Sort.java Normal file
View file

@ -0,0 +1,154 @@
/**
* This file was automatically generated from Sort.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
import com.microsoft.z3.enumerations.*;
/**
* The Sort class implements type information for ASTs.
**/
public class Sort extends AST
{
/**
* Comparison operator. <param name="a">A Sort</param> <param name="b">A
* Sort</param>
*
* @return True if <paramref name="a"/> and <paramref name="b"/> are from
* the same context and represent the same sort; false otherwise.
**/
/* Overloaded operators are not translated. */
/**
* Comparison operator. <param name="a">A Sort</param> <param name="b">A
* Sort</param>
*
* @return True if <paramref name="a"/> and <paramref name="b"/> are not
* from the same context or represent different sorts; false
* otherwise.
**/
/* Overloaded operators are not translated. */
/**
* Equality operator for objects of type Sort. <param name="o"></param>
*
* @return
**/
public boolean equals(Object o)
{
Sort casted = null;
try {
casted = Sort.class.cast(o);
} catch (ClassCastException e) {
return false;
}
return this.NativeObject() == casted.NativeObject();
}
/**
* Hash code generation for Sorts
*
* @return A hash code
**/
public int GetHashCode() throws Z3Exception
{
return super.GetHashCode();
}
/**
* Returns a unique identifier for the sort.
**/
public int Id() throws Z3Exception
{
return Native.getSortId(Context().nCtx(), NativeObject());
}
/**
* The kind of the sort.
**/
public Z3_sort_kind SortKind() throws Z3Exception
{
return Z3_sort_kind.fromInt(Native.getSortKind(Context().nCtx(),
NativeObject()));
}
/**
* The name of the sort
**/
public Symbol Name() throws Z3Exception
{
return Symbol.Create(Context(),
Native.getSortName(Context().nCtx(), NativeObject()));
}
/**
* A string representation of the sort.
**/
public String toString()
{
try
{
return Native.sortToString(Context().nCtx(), NativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
/**
* Sort constructor
**/
protected Sort(Context ctx) throws Z3Exception
{
super(ctx);
{
}
}
Sort(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
{
}
}
void CheckNativeObject(long obj) throws Z3Exception
{
if (Native.getAstKind(Context().nCtx(), obj) != Z3_ast_kind.Z3_SORT_AST
.toInt())
throw new Z3Exception("Underlying object is not a sort");
super.CheckNativeObject(obj);
}
static Sort Create(Context ctx, long obj) throws Z3Exception
{
switch (Z3_sort_kind.fromInt(Native.getSortKind(ctx.nCtx(), obj)))
{
case Z3_ARRAY_SORT:
return new ArraySort(ctx, obj);
case Z3_BOOL_SORT:
return new BoolSort(ctx, obj);
case Z3_BV_SORT:
return new BitVecSort(ctx, obj);
case Z3_DATATYPE_SORT:
return new DatatypeSort(ctx, obj);
case Z3_INT_SORT:
return new IntSort(ctx, obj);
case Z3_REAL_SORT:
return new RealSort(ctx, obj);
case Z3_UNINTERPRETED_SORT:
return new UninterpretedSort(ctx, obj);
case Z3_FINITE_DOMAIN_SORT:
return new FiniteDomainSort(ctx, obj);
case Z3_RELATION_SORT:
return new RelationSort(ctx, obj);
default:
throw new Z3Exception("Unknown sort kind");
}
}
}

View file

@ -0,0 +1,199 @@
/**
* This file was automatically generated from Statistics.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Objects of this class track statistical information about solvers.
**/
public class Statistics extends Z3Object
{
/**
* Statistical data is organized into pairs of [Key, Entry], where every
* Entry is either a <code>DoubleEntry</code> or a <code>UIntEntry</code>
**/
public class Entry
{
/**
* The key of the entry.
**/
public String Key;
/**
* The uint-value of the entry.
**/
public int UIntValue()
{
return m_int;
}
/**
* The double-value of the entry.
**/
public double DoubleValue()
{
return m_double;
}
/**
* True if the entry is uint-valued.
**/
public boolean IsUInt()
{
return m_is_int;
}
/**
* True if the entry is double-valued.
**/
public boolean IsDouble()
{
return m_is_double;
}
/**
* The string representation of the the entry's value.
*
* @throws Z3Exception
**/
public String Value() throws Z3Exception
{
if (IsUInt())
return Integer.toString(m_int);
else if (IsDouble())
return Double.toString(m_double);
else
throw new Z3Exception("Unknown statistical entry type");
}
/**
* The string representation of the Entry.
**/
public String toString()
{
try
{
return Key + ": " + Value();
} catch (Z3Exception e)
{
return new String("Z3Exception: " + e.getMessage());
}
}
private boolean m_is_int = false;
private boolean m_is_double = false;
private int m_int = 0;
private double m_double = 0.0;
Entry(String k, int v)
{
Key = k;
m_is_int = true;
m_int = v;
}
Entry(String k, double v)
{
Key = k;
m_is_double = true;
m_double = v;
}
}
/**
* A string representation of the statistical data.
**/
public String toString()
{
try
{
return Native.statsToString(Context().nCtx(), NativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
/**
* The number of statistical data.
**/
public int Size() throws Z3Exception
{
return Native.statsSize(Context().nCtx(), NativeObject());
}
/**
* The data entries.
*
* @throws Z3Exception
**/
public Entry[] Entries() throws Z3Exception
{
int n = Size();
Entry[] res = new Entry[n];
for (int i = 0; i < n; i++)
{
Entry e;
String k = Native.statsGetKey(Context().nCtx(), NativeObject(), i);
if (Native.statsIsUint(Context().nCtx(), NativeObject(), i))
e = new Entry(k, Native.statsGetUintValue(Context().nCtx(),
NativeObject(), i));
else if (Native.statsIsDouble(Context().nCtx(), NativeObject(), i))
e = new Entry(k, Native.statsGetDoubleValue(Context().nCtx(),
NativeObject(), i));
else
throw new Z3Exception("Unknown data entry value");
res[i] = e;
}
return res;
}
/**
* The statistical counters.
**/
public String[] Keys() throws Z3Exception
{
int n = Size();
String[] res = new String[n];
for (int i = 0; i < n; i++)
res[i] = Native.statsGetKey(Context().nCtx(), NativeObject(), i);
return res;
}
/**
* The value of a particular statistical counter. <remarks>Returns null if
* the key is unknown.</remarks>
*
* @throws Z3Exception
**/
public Entry get(String key) throws Z3Exception
{
int n = Size();
Entry[] es = Entries();
for (int i = 0; i < n; i++)
if (es[i].Key == key)
return es[i];
return null;
}
Statistics(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
void IncRef(long o) throws Z3Exception
{
Context().Statistics_DRQ().IncAndClear(Context(), o);
super.IncRef(o);
}
void DecRef(long o) throws Z3Exception
{
Context().Statistics_DRQ().Add(o);
super.DecRef(o);
}
}

View file

@ -0,0 +1,31 @@
/**
* Copyright (c) 2012 Microsoft Corporation
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
class StatisticsDecRefQueue extends IDecRefQueue
{
public void IncRef(Context ctx, long obj)
{
try
{
Native.statsIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
public void DecRef(Context ctx, long obj)
{
try
{
Native.statsDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
};

42
src/api/java/Status.java Normal file
View file

@ -0,0 +1,42 @@
/**
* This file was automatically generated from Status.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Status values.
**/
public enum Status
{
// / Used to signify an unsatisfiable status.
UNSATISFIABLE(1),
// / Used to signify an unknown status.
UNKNOWN(0),
// / Used to signify a satisfiable status.
SATISFIABLE(1);
private final int intValue;
Status(int v)
{
this.intValue = v;
}
public static final Status fromInt(int v)
{
for (Status k : values())
if (k.intValue == v)
return k;
return values()[0];
}
public final int toInt()
{
return this.intValue;
}
}

View file

@ -0,0 +1,43 @@
/**
* This file was automatically generated from StringSymbol.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
import com.microsoft.z3.enumerations.*;
/**
* Named symbols
**/
public class StringSymbol extends Symbol
{
/**
* The string value of the symbol. <remarks>Throws an exception if the
* symbol is not of string kind.</remarks>
**/
public String String() throws Z3Exception
{
return Native.getSymbolString(Context().nCtx(), NativeObject());
}
StringSymbol(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
StringSymbol(Context ctx, String s) throws Z3Exception
{
super(ctx, Native.mkStringSymbol(ctx.nCtx(), s));
}
void CheckNativeObject(long obj) throws Z3Exception
{
if (Native.getSymbolKind(Context().nCtx(), obj) != Z3_symbol_kind.Z3_STRING_SYMBOL
.toInt())
throw new Z3Exception("Symbol is not of String kind");
super.CheckNativeObject(obj);
}
}

81
src/api/java/Symbol.java Normal file
View file

@ -0,0 +1,81 @@
/**
* This file was automatically generated from Symbol.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
import com.microsoft.z3.enumerations.*;
/**
* Symbols are used to name several term and type constructors.
**/
public class Symbol extends Z3Object
{
/**
* The kind of the symbol (int or string)
**/
protected Z3_symbol_kind Kind() throws Z3Exception
{
return Z3_symbol_kind.fromInt(Native.getSymbolKind(Context().nCtx(),
NativeObject()));
}
/**
* Indicates whether the symbol is of Int kind
**/
public boolean IsIntSymbol() throws Z3Exception
{
return Kind() == Z3_symbol_kind.Z3_INT_SYMBOL;
}
/**
* Indicates whether the symbol is of string kind.
**/
public boolean IsStringSymbol() throws Z3Exception
{
return Kind() == Z3_symbol_kind.Z3_STRING_SYMBOL;
}
/**
* A string representation of the symbol.
**/
public String toString()
{
try
{
if (IsIntSymbol())
return Integer.toString(((IntSymbol) this).Int());
else if (IsStringSymbol())
return ((StringSymbol) this).String();
else
return new String(
"Z3Exception: Unknown symbol kind encountered.");
} catch (Z3Exception ex)
{
return new String("Z3Exception: " + ex.getMessage());
}
}
/**
* Symbol constructor
**/
protected Symbol(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
static Symbol Create(Context ctx, long obj) throws Z3Exception
{
switch (Z3_symbol_kind.fromInt(Native.getSymbolKind(ctx.nCtx(), obj)))
{
case Z3_INT_SYMBOL:
return new IntSymbol(ctx, obj);
case Z3_STRING_SYMBOL:
return new StringSymbol(ctx, obj);
default:
throw new Z3Exception("Unknown symbol kind encountered");
}
}
}

107
src/api/java/Tactic.java Normal file
View file

@ -0,0 +1,107 @@
/**
* This file was automatically generated from Tactic.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Tactics are the basic building block for creating custom solvers for specific
* problem domains. The complete list of tactics may be obtained using
* <code>Context.NumTactics</code> and <code>Context.TacticNames</code>. It may
* also be obtained using the command <code>(help-tactics)</code> in the SMT 2.0
* front-end.
**/
public class Tactic extends Z3Object
{
/**
* A string containing a description of parameters accepted by the tactic.
**/
public String Help() throws Z3Exception
{
return Native.tacticGetHelp(Context().nCtx(), NativeObject());
}
/**
* Retrieves parameter descriptions for Tactics.
* @throws Z3Exception
**/
public ParamDescrs ParameterDescriptions() throws Z3Exception
{
return new ParamDescrs(Context(), Native.tacticGetParamDescrs(Context()
.nCtx(), NativeObject()));
}
/**
* Execute the tactic over the goal.
* @throws Z3Exception
**/
public ApplyResult Apply(Goal g) throws Z3Exception
{
return Apply(g, null);
}
/**
* Execute the tactic over the goal.
* @throws Z3Exception
**/
public ApplyResult Apply(Goal g, Params p) throws Z3Exception
{
Context().CheckContextMatch(g);
if (p == null)
return new ApplyResult(Context(), Native.tacticApply(Context()
.nCtx(), NativeObject(), g.NativeObject()));
else
{
Context().CheckContextMatch(p);
return new ApplyResult(Context(),
Native.tacticApplyEx(Context().nCtx(), NativeObject(),
g.NativeObject(), p.NativeObject()));
}
}
/**
* Apply the tactic to a goal.
* @throws Z3Exception
**/
public ApplyResult get(Goal g) throws Z3Exception
{
return Apply(g, null);
}
/**
* Creates a solver that is implemented using the given tactic. <seealso
* cref="Context.MkSolver(Tactic)"/>
* @throws Z3Exception
**/
public Solver Solver() throws Z3Exception
{
return Context().MkSolver(this);
}
Tactic(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
Tactic(Context ctx, String name) throws Z3Exception
{
super(ctx, Native.mkTactic(ctx.nCtx(), name));
}
void IncRef(long o) throws Z3Exception
{
Context().Tactic_DRQ().IncAndClear(Context(), o);
super.IncRef(o);
}
void DecRef(long o) throws Z3Exception
{
Context().Tactic_DRQ().Add(o);
super.DecRef(o);
}
}

View file

@ -0,0 +1,31 @@
/**
* Copyright (c) 2012 Microsoft Corporation
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
class TacticDecRefQueue extends IDecRefQueue
{
public void IncRef(Context ctx, long obj)
{
try
{
Native.tacticIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
public void DecRef(Context ctx, long obj)
{
try
{
Native.tacticDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
};

View file

@ -0,0 +1,58 @@
/**
* This file was automatically generated from TupleSort.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
/**
* Tuple sorts.
**/
public class TupleSort extends Sort
{
/**
* The constructor function of the tuple.
* @throws Z3Exception
**/
public FuncDecl MkDecl() throws Z3Exception
{
return new FuncDecl(Context(), Native.getTupleSortMkDecl(Context()
.nCtx(), NativeObject()));
}
/**
* The number of fields in the tuple.
**/
public int NumFields() throws Z3Exception
{
return Native.getTupleSortNumFields(Context().nCtx(), NativeObject());
}
/**
* The field declarations.
* @throws Z3Exception
**/
public FuncDecl[] FieldDecls() throws Z3Exception
{
int n = NumFields();
FuncDecl[] res = new FuncDecl[n];
for (int i = 0; i < n; i++)
res[i] = new FuncDecl(Context(), Native.getTupleSortFieldDecl(
Context().nCtx(), NativeObject(), i));
return res;
}
TupleSort(Context ctx, Symbol name, int numFields, Symbol[] fieldNames,
Sort[] fieldSorts) throws Z3Exception
{
super(ctx);
Native.LongPtr t = new Native.LongPtr();
setNativeObject(Native.mkTupleSort(ctx.nCtx(), name.NativeObject(),
numFields, Symbol.ArrayToNative(fieldNames),
AST.ArrayToNative(fieldSorts), t, new long[numFields]));
}
};

Some files were not shown because too many files have changed in this diff Show more