3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-24 01:25:31 +00:00

Merge branch 'upstream-master' into release-1.0

Conflicts:
	src/cmd_context/check_logic.cpp
	src/cmd_context/cmd_context.cpp
	src/cmd_context/cmd_context.h
	src/smt/params/smt_params_helper.pyg
	src/smt/smt_context.cpp
This commit is contained in:
Murphy Berzish 2017-02-18 15:04:44 -05:00
commit 235ea79043
588 changed files with 21784 additions and 15202 deletions

View file

@ -7,7 +7,7 @@ Module Name:
Abstract:
Additional APIs for handling Z3 algebraic numbers encoded as
Additional APIs for handling Z3 algebraic numbers encoded as
Z3_ASTs
Author:
@ -15,9 +15,8 @@ Author:
Leonardo de Moura (leonardo) 2012-12-07
Notes:
--*/
#include<iostream>
#include"z3.h"
#include"api_log_macros.h"
#include"api_context.h"
@ -74,9 +73,9 @@ extern "C" {
bool Z3_algebraic_is_value_core(Z3_context c, Z3_ast a) {
api::context * _c = mk_c(c);
return
is_expr(a) &&
(_c->autil().is_numeral(to_expr(a)) ||
return
is_expr(a) &&
(_c->autil().is_numeral(to_expr(a)) ||
_c->autil().is_irrational_algebraic_numeral(to_expr(a)));
}
@ -162,9 +161,9 @@ extern "C" {
Z3_ast Z3_API Z3_algebraic_add(Z3_context c, Z3_ast a, Z3_ast b) {
Z3_TRY;
LOG_Z3_algebraic_add(c, a, b);
RESET_ERROR_CODE();
CHECK_IS_ALGEBRAIC_X(a, 0);
CHECK_IS_ALGEBRAIC_X(b, 0);
RESET_ERROR_CODE();
CHECK_IS_ALGEBRAIC_X(a, 0);
CHECK_IS_ALGEBRAIC_X(b, 0);
BIN_OP(+,add);
Z3_CATCH_RETURN(0);
}
@ -172,9 +171,9 @@ extern "C" {
Z3_ast Z3_API Z3_algebraic_sub(Z3_context c, Z3_ast a, Z3_ast b) {
Z3_TRY;
LOG_Z3_algebraic_sub(c, a, b);
RESET_ERROR_CODE();
CHECK_IS_ALGEBRAIC_X(a, 0);
CHECK_IS_ALGEBRAIC_X(b, 0);
RESET_ERROR_CODE();
CHECK_IS_ALGEBRAIC_X(a, 0);
CHECK_IS_ALGEBRAIC_X(b, 0);
BIN_OP(-,sub);
Z3_CATCH_RETURN(0);
}
@ -182,9 +181,9 @@ extern "C" {
Z3_ast Z3_API Z3_algebraic_mul(Z3_context c, Z3_ast a, Z3_ast b) {
Z3_TRY;
LOG_Z3_algebraic_mul(c, a, b);
RESET_ERROR_CODE();
CHECK_IS_ALGEBRAIC_X(a, 0);
CHECK_IS_ALGEBRAIC_X(b, 0);
RESET_ERROR_CODE();
CHECK_IS_ALGEBRAIC_X(a, 0);
CHECK_IS_ALGEBRAIC_X(b, 0);
BIN_OP(*,mul);
Z3_CATCH_RETURN(0);
}
@ -219,8 +218,8 @@ extern "C" {
algebraic_numbers::manager & _am = am(c);
scoped_anum _r(_am);
if (is_rational(c, a)) {
scoped_anum av(_am);
_am.set(av, get_rational(c, a).to_mpq());
scoped_anum av(_am);
_am.set(av, get_rational(c, a).to_mpq());
_am.root(av, k, _r);
}
else {
@ -241,8 +240,8 @@ extern "C" {
algebraic_numbers::manager & _am = am(c);
scoped_anum _r(_am);
if (is_rational(c, a)) {
scoped_anum av(_am);
_am.set(av, get_rational(c, a).to_mpq());
scoped_anum av(_am);
_am.set(av, get_rational(c, a).to_mpq());
_am.power(av, k, _r);
}
else {
@ -328,7 +327,7 @@ extern "C" {
scoped_anum tmp(_am);
for (unsigned i = 0; i < n; i++) {
if (is_rational(c, a[i])) {
_am.set(tmp, get_rational(c, a[i]).to_mpq());
_am.set(tmp, get_rational(c, a[i]).to_mpq());
as.push_back(tmp);
}
else if (is_irrational(c, a[i])) {
@ -378,7 +377,7 @@ extern "C" {
vector_var2anum v2a(as);
_am.isolate_roots(_p, v2a, roots);
}
Z3_ast_vector_ref* result = alloc(Z3_ast_vector_ref, mk_c(c)->m());
Z3_ast_vector_ref* result = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(result);
for (unsigned i = 0; i < roots.size(); i++) {
result->m_ast_vector.push_back(au(c).mk_numeral(roots.get(i), false));

View file

@ -15,7 +15,6 @@ Author:
Revision History:
--*/
#include<iostream>
#include"z3.h"
#include"api_log_macros.h"
#include"api_context.h"
@ -37,7 +36,7 @@ extern "C" {
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
}
Z3_sort Z3_API Z3_mk_real_sort(Z3_context c) {
Z3_TRY;
LOG_Z3_mk_real_sort(c);
@ -50,7 +49,7 @@ extern "C" {
Z3_ast Z3_API Z3_mk_real(Z3_context c, int num, int den) {
Z3_TRY;
LOG_Z3_mk_real(c, num, den);
RESET_ERROR_CODE();
RESET_ERROR_CODE();
if (den == 0) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
@ -60,7 +59,7 @@ extern "C" {
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
}
MK_ARITH_OP(Z3_mk_add, OP_ADD);
MK_ARITH_OP(Z3_mk_mul, OP_MUL);
MK_BINARY_ARITH_OP(Z3_mk_power, OP_POWER);
@ -70,17 +69,17 @@ extern "C" {
Z3_ast Z3_API Z3_mk_div(Z3_context c, Z3_ast n1, Z3_ast n2) {
Z3_TRY;
LOG_Z3_mk_div(c, n1, n2);
RESET_ERROR_CODE();
RESET_ERROR_CODE();
decl_kind k = OP_IDIV;
sort* ty = mk_c(c)->m().get_sort(to_expr(n1));
sort* real_ty = mk_c(c)->m().mk_sort(mk_c(c)->get_arith_fid(), REAL_SORT);
if (ty == real_ty) {
k = OP_DIV;
}
expr * args[2] = { to_expr(n1), to_expr(n2) };
ast* a = mk_c(c)->m().mk_app(mk_c(c)->get_arith_fid(), k, 0, 0, 2, args);
mk_c(c)->save_ast_trail(a);
check_sorts(c, a);
expr * args[2] = { to_expr(n1), to_expr(n2) };
ast* a = mk_c(c)->m().mk_app(mk_c(c)->get_arith_fid(), k, 0, 0, 2, args);
mk_c(c)->save_ast_trail(a);
check_sorts(c, a);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
}
@ -142,7 +141,7 @@ extern "C" {
rational l;
mk_c(c)->autil().am().get_lower(val, l, precision);
expr * r = mk_c(c)->autil().mk_numeral(l, false);
mk_c(c)->save_ast_trail(r);
mk_c(c)->save_ast_trail(r);
RETURN_Z3(of_expr(r));
Z3_CATCH_RETURN(0);
}
@ -160,7 +159,7 @@ extern "C" {
rational l;
mk_c(c)->autil().am().get_upper(val, l, precision);
expr * r = mk_c(c)->autil().mk_numeral(l, false);
mk_c(c)->save_ast_trail(r);
mk_c(c)->save_ast_trail(r);
RETURN_Z3(of_expr(r));
Z3_CATCH_RETURN(0);
}
@ -176,7 +175,7 @@ extern "C" {
RETURN_Z3(0);
}
expr * r = mk_c(c)->autil().mk_numeral(numerator(val), true);
mk_c(c)->save_ast_trail(r);
mk_c(c)->save_ast_trail(r);
RETURN_Z3(of_expr(r));
Z3_CATCH_RETURN(0);
}
@ -192,7 +191,7 @@ extern "C" {
RETURN_Z3(0);
}
expr * r = mk_c(c)->autil().mk_numeral(denominator(val), true);
mk_c(c)->save_ast_trail(r);
mk_c(c)->save_ast_trail(r);
RETURN_Z3(of_expr(r));
Z3_CATCH_RETURN(0);
}

View file

@ -15,7 +15,6 @@ Author:
Revision History:
--*/
#include<iostream>
#include"z3.h"
#include"api_log_macros.h"
#include"api_context.h"
@ -27,7 +26,7 @@ extern "C" {
Z3_sort Z3_API Z3_mk_array_sort(Z3_context c, Z3_sort domain, Z3_sort range) {
Z3_TRY;
LOG_Z3_mk_array_sort(c, domain, range);
RESET_ERROR_CODE();
RESET_ERROR_CODE();
parameter params[2] = { parameter(to_sort(domain)), parameter(to_sort(range)) };
sort * ty = mk_c(c)->m().mk_sort(mk_c(c)->get_array_fid(), ARRAY_SORT, 2, params);
mk_c(c)->save_ast_trail(ty);
@ -57,7 +56,7 @@ extern "C" {
RETURN_Z3(of_ast(r));
Z3_CATCH_RETURN(0);
}
Z3_ast Z3_API Z3_mk_store(Z3_context c, Z3_ast a, Z3_ast i, Z3_ast v) {
Z3_TRY;
LOG_Z3_mk_store(c, a, i, v);
@ -82,7 +81,7 @@ extern "C" {
RETURN_Z3(of_ast(r));
Z3_CATCH_RETURN(0);
}
Z3_ast Z3_API Z3_mk_map(Z3_context c, Z3_func_decl f, unsigned n, Z3_ast const* args) {
Z3_TRY;
LOG_Z3_mk_map(c, f, n, args);
@ -94,7 +93,7 @@ extern "C" {
ast_manager & m = mk_c(c)->m();
func_decl* _f = to_func_decl(f);
expr* const* _args = to_exprs(args);
ptr_vector<sort> domain;
for (unsigned i = 0; i < n; ++i) {
domain.push_back(m.get_sort(_args[i]));
@ -111,7 +110,7 @@ extern "C" {
Z3_ast Z3_API Z3_mk_const_array(Z3_context c, Z3_sort domain, Z3_ast v) {
Z3_TRY;
LOG_Z3_mk_const_array(c, domain, v);
RESET_ERROR_CODE();
RESET_ERROR_CODE();
ast_manager & m = mk_c(c)->m();
expr * _v = to_expr(v);
sort * _range = m.get_sort(_v);
@ -123,14 +122,14 @@ extern "C" {
app * r = m.mk_app(cd, 1, &_v);
mk_c(c)->save_ast_trail(r);
check_sorts(c, r);
RETURN_Z3(of_ast(r));
RETURN_Z3(of_ast(r));
Z3_CATCH_RETURN(0);
}
Z3_ast Z3_API Z3_mk_array_default(Z3_context c, Z3_ast array) {
Z3_TRY;
LOG_Z3_mk_array_default(c, array);
RESET_ERROR_CODE();
RESET_ERROR_CODE();
ast_manager & m = mk_c(c)->m();
expr * _a = to_expr(array);
@ -138,12 +137,12 @@ extern "C" {
app * r = m.mk_app(f, 1, &_a);
mk_c(c)->save_ast_trail(r);
check_sorts(c, r);
RETURN_Z3(of_ast(r));
RETURN_Z3(of_ast(r));
Z3_CATCH_RETURN(0);
}
Z3_ast mk_app_array_core(Z3_context c, Z3_sort domain, Z3_ast v) {
RESET_ERROR_CODE();
RESET_ERROR_CODE();
ast_manager & m = mk_c(c)->m();
expr * _v = to_expr(v);
sort * _range = m.get_sort(_v);
@ -178,7 +177,7 @@ extern "C" {
LOG_Z3_mk_full_set(c, domain);
RESET_ERROR_CODE();
Z3_ast r = mk_app_array_core(c, domain, Z3_mk_true(c));
RETURN_Z3(r);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
}
@ -205,8 +204,8 @@ extern "C" {
Z3_TRY;
LOG_Z3_get_array_sort_domain(c, t);
RESET_ERROR_CODE();
CHECK_VALID_AST(t, 0);
if (to_sort(t)->get_family_id() == mk_c(c)->get_array_fid() &&
CHECK_VALID_AST(t, 0);
if (to_sort(t)->get_family_id() == mk_c(c)->get_array_fid() &&
to_sort(t)->get_decl_kind() == ARRAY_SORT) {
Z3_sort r = reinterpret_cast<Z3_sort>(to_sort(t)->get_parameter(0).get_ast());
RETURN_Z3(r);
@ -215,13 +214,13 @@ extern "C" {
RETURN_Z3(0);
Z3_CATCH_RETURN(0);
}
Z3_sort Z3_API Z3_get_array_sort_range(Z3_context c, Z3_sort t) {
Z3_TRY;
LOG_Z3_get_array_sort_range(c, t);
RESET_ERROR_CODE();
RESET_ERROR_CODE();
CHECK_VALID_AST(t, 0);
if (to_sort(t)->get_family_id() == mk_c(c)->get_array_fid() &&
if (to_sort(t)->get_family_id() == mk_c(c)->get_array_fid() &&
to_sort(t)->get_decl_kind() == ARRAY_SORT) {
Z3_sort r = reinterpret_cast<Z3_sort>(to_sort(t)->get_parameter(1).get_ast());
RETURN_Z3(r);

View file

@ -335,7 +335,7 @@ extern "C" {
Z3_bool Z3_API Z3_is_app(Z3_context c, Z3_ast a) {
LOG_Z3_is_app(c, a);
RESET_ERROR_CODE();
return is_app(reinterpret_cast<ast*>(a));
return a != 0 && is_app(reinterpret_cast<ast*>(a));
}
Z3_app Z3_API Z3_to_app(Z3_context c, Z3_ast a) {
@ -727,7 +727,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_simplify_get_param_descrs(c);
RESET_ERROR_CODE();
Z3_param_descrs_ref * d = alloc(Z3_param_descrs_ref);
Z3_param_descrs_ref * d = alloc(Z3_param_descrs_ref, *mk_c(c));
mk_c(c)->save_object(d);
th_rewriter::get_param_descrs(d->m_descrs);
Z3_param_descrs r = of_param_descrs(d);
@ -970,8 +970,7 @@ extern "C" {
case PR_TH_LEMMA: return Z3_OP_PR_TH_LEMMA;
case PR_HYPER_RESOLVE: return Z3_OP_PR_HYPER_RESOLVE;
default:
UNREACHABLE();
return Z3_OP_UNINTERPRETED;
return Z3_OP_INTERNAL;
}
}
if (mk_c(c)->get_arith_fid() == _d->get_family_id()) {
@ -995,8 +994,7 @@ extern "C" {
case OP_TO_INT: return Z3_OP_TO_INT;
case OP_IS_INT: return Z3_OP_IS_INT;
default:
UNREACHABLE();
return Z3_OP_UNINTERPRETED;
return Z3_OP_INTERNAL;
}
}
if (mk_c(c)->get_array_fid() == _d->get_family_id()) {
@ -1014,8 +1012,7 @@ extern "C" {
case OP_AS_ARRAY: return Z3_OP_AS_ARRAY;
case OP_ARRAY_EXT: return Z3_OP_ARRAY_EXT;
default:
UNREACHABLE();
return Z3_OP_UNINTERPRETED;
return Z3_OP_INTERNAL;
}
}
@ -1072,17 +1069,17 @@ extern "C" {
case OP_BV2INT: return Z3_OP_BV2INT;
case OP_CARRY: return Z3_OP_CARRY;
case OP_XOR3: return Z3_OP_XOR3;
case OP_BIT2BOOL: return Z3_OP_BIT2BOOL;
case OP_BSMUL_NO_OVFL: return Z3_OP_BSMUL_NO_OVFL;
case OP_BUMUL_NO_OVFL: return Z3_OP_BUMUL_NO_OVFL;
case OP_BSMUL_NO_UDFL: return Z3_OP_BSMUL_NO_UDFL;
case OP_BSMUL_NO_UDFL: return Z3_OP_BSMUL_NO_UDFL;
case OP_BSDIV_I: return Z3_OP_BSDIV_I;
case OP_BUDIV_I: return Z3_OP_BUDIV_I;
case OP_BSREM_I: return Z3_OP_BSREM_I;
case OP_BUREM_I: return Z3_OP_BUREM_I;
case OP_BSMOD_I: return Z3_OP_BSMOD_I;
default:
UNREACHABLE();
return Z3_OP_UNINTERPRETED;
return Z3_OP_INTERNAL;
}
}
if (mk_c(c)->get_dt_fid() == _d->get_family_id()) {
@ -1092,8 +1089,7 @@ extern "C" {
case OP_DT_ACCESSOR: return Z3_OP_DT_ACCESSOR;
case OP_DT_UPDATE_FIELD: return Z3_OP_DT_UPDATE_FIELD;
default:
UNREACHABLE();
return Z3_OP_UNINTERPRETED;
return Z3_OP_INTERNAL;
}
}
if (mk_c(c)->get_datalog_fid() == _d->get_family_id()) {
@ -1114,34 +1110,40 @@ extern "C" {
case datalog::OP_DL_CONSTANT: return Z3_OP_FD_CONSTANT;
case datalog::OP_DL_LT: return Z3_OP_FD_LT;
default:
UNREACHABLE();
return Z3_OP_UNINTERPRETED;
return Z3_OP_INTERNAL;
}
}
if (mk_c(c)->get_seq_fid() == _d->get_family_id()) {
switch (_d->get_decl_kind()) {
case Z3_OP_SEQ_UNIT: return Z3_OP_SEQ_UNIT;
case Z3_OP_SEQ_EMPTY: return Z3_OP_SEQ_EMPTY;
case Z3_OP_SEQ_CONCAT: return Z3_OP_SEQ_CONCAT;
case Z3_OP_SEQ_PREFIX: return Z3_OP_SEQ_PREFIX;
case Z3_OP_SEQ_SUFFIX: return Z3_OP_SEQ_SUFFIX;
case Z3_OP_SEQ_CONTAINS: return Z3_OP_SEQ_CONTAINS;
case Z3_OP_SEQ_EXTRACT: return Z3_OP_SEQ_EXTRACT;
case Z3_OP_SEQ_REPLACE: return Z3_OP_SEQ_REPLACE;
case Z3_OP_SEQ_AT: return Z3_OP_SEQ_AT;
case Z3_OP_SEQ_LENGTH: return Z3_OP_SEQ_LENGTH;
case Z3_OP_SEQ_INDEX: return Z3_OP_SEQ_INDEX;
case Z3_OP_SEQ_TO_RE: return Z3_OP_SEQ_TO_RE;
case Z3_OP_SEQ_IN_RE: return Z3_OP_SEQ_IN_RE;
case OP_SEQ_UNIT: return Z3_OP_SEQ_UNIT;
case OP_SEQ_EMPTY: return Z3_OP_SEQ_EMPTY;
case OP_SEQ_CONCAT: return Z3_OP_SEQ_CONCAT;
case OP_SEQ_PREFIX: return Z3_OP_SEQ_PREFIX;
case OP_SEQ_SUFFIX: return Z3_OP_SEQ_SUFFIX;
case OP_SEQ_CONTAINS: return Z3_OP_SEQ_CONTAINS;
case OP_SEQ_EXTRACT: return Z3_OP_SEQ_EXTRACT;
case OP_SEQ_REPLACE: return Z3_OP_SEQ_REPLACE;
case OP_SEQ_AT: return Z3_OP_SEQ_AT;
case OP_SEQ_LENGTH: return Z3_OP_SEQ_LENGTH;
case OP_SEQ_INDEX: return Z3_OP_SEQ_INDEX;
case OP_SEQ_TO_RE: return Z3_OP_SEQ_TO_RE;
case OP_SEQ_IN_RE: return Z3_OP_SEQ_IN_RE;
case Z3_OP_RE_PLUS: return Z3_OP_RE_PLUS;
case Z3_OP_RE_STAR: return Z3_OP_RE_STAR;
case Z3_OP_RE_OPTION: return Z3_OP_RE_OPTION;
case Z3_OP_RE_CONCAT: return Z3_OP_RE_CONCAT;
case Z3_OP_RE_UNION: return Z3_OP_RE_UNION;
case OP_STRING_STOI: return Z3_OP_STR_TO_INT;
case OP_STRING_ITOS: return Z3_OP_INT_TO_STR;
case OP_RE_PLUS: return Z3_OP_RE_PLUS;
case OP_RE_STAR: return Z3_OP_RE_STAR;
case OP_RE_OPTION: return Z3_OP_RE_OPTION;
case OP_RE_CONCAT: return Z3_OP_RE_CONCAT;
case OP_RE_UNION: return Z3_OP_RE_UNION;
case OP_RE_INTERSECT: return Z3_OP_RE_INTERSECT;
case OP_RE_LOOP: return Z3_OP_RE_LOOP;
case OP_RE_FULL_SET: return Z3_OP_RE_FULL_SET;
case OP_RE_EMPTY_SET: return Z3_OP_RE_EMPTY_SET;
default:
return Z3_OP_UNINTERPRETED;
return Z3_OP_INTERNAL;
}
}
@ -1211,8 +1213,7 @@ extern "C" {
case OP_FPA_INTERNAL_TO_IEEE_BV_UNSPECIFIED:
return Z3_OP_UNINTERPRETED;
default:
UNREACHABLE();
return Z3_OP_UNINTERPRETED;
return Z3_OP_INTERNAL;
}
}
@ -1221,8 +1222,7 @@ extern "C" {
case OP_LABEL: return Z3_OP_LABEL;
case OP_LABEL_LIT: return Z3_OP_LABEL_LIT;
default:
UNREACHABLE();
return Z3_OP_UNINTERPRETED;
return Z3_OP_INTERNAL;
}
}
@ -1230,8 +1230,10 @@ extern "C" {
switch(_d->get_decl_kind()) {
case OP_PB_LE: return Z3_OP_PB_LE;
case OP_PB_GE: return Z3_OP_PB_GE;
case OP_PB_EQ: return Z3_OP_PB_EQ;
case OP_AT_MOST_K: return Z3_OP_PB_AT_MOST;
default: UNREACHABLE();
case OP_AT_LEAST_K: return Z3_OP_PB_AT_LEAST;
default: return Z3_OP_INTERNAL;
}
}

View file

@ -34,7 +34,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_mk_ast_map(c);
RESET_ERROR_CODE();
Z3_ast_map_ref * m = alloc(Z3_ast_map_ref, mk_c(c)->m());
Z3_ast_map_ref * m = alloc(Z3_ast_map_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(m);
Z3_ast_map r = of_ast_map(m);
RETURN_Z3(r);
@ -137,7 +137,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_ast_map_keys(c, m);
RESET_ERROR_CODE();
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, to_ast_map(m)->m);
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), to_ast_map(m)->m);
mk_c(c)->save_object(v);
obj_map<ast, ast*>::iterator it = to_ast_map_ref(m).begin();
obj_map<ast, ast*>::iterator end = to_ast_map_ref(m).end();

View file

@ -24,7 +24,7 @@ Revision History:
struct Z3_ast_map_ref : public api::object {
ast_manager & m;
obj_map<ast, ast*> m_map;
Z3_ast_map_ref(ast_manager & _m):m(_m) {}
Z3_ast_map_ref(api::context& c, ast_manager & _m): api::object(c), m(_m) {}
virtual ~Z3_ast_map_ref();
};

View file

@ -29,7 +29,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_mk_ast_vector(c);
RESET_ERROR_CODE();
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, mk_c(c)->m());
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(v);
Z3_ast_vector r = of_ast_vector(v);
RETURN_Z3(r);
@ -111,7 +111,7 @@ extern "C" {
RETURN_Z3(0);
}
ast_translation translator(mk_c(c)->m(), mk_c(t)->m());
Z3_ast_vector_ref * new_v = alloc(Z3_ast_vector_ref, mk_c(t)->m());
Z3_ast_vector_ref * new_v = alloc(Z3_ast_vector_ref, *mk_c(t), mk_c(t)->m());
mk_c(t)->save_object(new_v);
unsigned sz = to_ast_vector_ref(v).size();
for (unsigned i = 0; i < sz; i++) {

View file

@ -20,9 +20,13 @@ Revision History:
#include"api_util.h"
namespace api {
class context;
};
struct Z3_ast_vector_ref : public api::object {
ast_ref_vector m_ast_vector;
Z3_ast_vector_ref(ast_manager & m):m_ast_vector(m) {}
Z3_ast_vector_ref(api::context& c, ast_manager & m): api::object(c), m_ast_vector(m) {}
virtual ~Z3_ast_vector_ref() {}
};

View file

@ -15,7 +15,6 @@ Author:
Revision History:
--*/
#include<iostream>
#include"z3.h"
#include"api_log_macros.h"
#include"api_context.h"
@ -27,7 +26,7 @@ extern "C" {
Z3_sort Z3_API Z3_mk_bv_sort(Z3_context c, unsigned sz) {
Z3_TRY;
LOG_Z3_mk_bv_sort(c, sz);
RESET_ERROR_CODE();
RESET_ERROR_CODE();
if (sz == 0) {
SET_ERROR_CODE(Z3_INVALID_ARG);
}
@ -39,7 +38,7 @@ extern "C" {
#define MK_BV_UNARY(NAME, OP) MK_UNARY(NAME, mk_c(c)->get_bv_fid(), OP, SKIP)
#define MK_BV_BINARY(NAME, OP) MK_BINARY(NAME, mk_c(c)->get_bv_fid(), OP, SKIP)
MK_BV_UNARY(Z3_mk_bvnot, OP_BNOT);
MK_BV_UNARY(Z3_mk_bvredand, OP_BREDAND);
MK_BV_UNARY(Z3_mk_bvredor, OP_BREDOR);
@ -75,11 +74,11 @@ extern "C" {
expr * _n = to_expr(n);
parameter params[2] = { parameter(high), parameter(low) };
expr * a = mk_c(c)->m().mk_app(mk_c(c)->get_bv_fid(), OP_EXTRACT, 2, params, 1, &_n);
mk_c(c)->save_ast_trail(a);
mk_c(c)->save_ast_trail(a);
check_sorts(c, a);
return of_ast(a);
}
Z3_ast Z3_API Z3_mk_extract(Z3_context c, unsigned high, unsigned low, Z3_ast n) {
Z3_TRY;
LOG_Z3_mk_extract(c, high, low, n);
@ -88,7 +87,7 @@ extern "C" {
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
}
#define MK_BV_PUNARY(NAME, OP) \
Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
Z3_TRY; \
@ -113,7 +112,7 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
Z3_ast Z3_API Z3_mk_bv2int(Z3_context c, Z3_ast n, Z3_bool is_signed) {
Z3_TRY;
LOG_Z3_mk_bv2int(c, n, is_signed);
RESET_ERROR_CODE();
RESET_ERROR_CODE();
Z3_sort int_s = Z3_mk_int_sort(c);
if (is_signed) {
Z3_ast r = Z3_mk_bv2int(c, n, false);
@ -125,7 +124,7 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
Z3_inc_ref(c, bound);
Z3_ast zero = Z3_mk_int(c, 0, s);
Z3_inc_ref(c, zero);
Z3_ast pred = Z3_mk_bvslt(c, n, zero);
Z3_ast pred = Z3_mk_bvslt(c, n, zero);
Z3_inc_ref(c, pred);
// if n <_sigend 0 then r - s^sz else r
Z3_ast args[2] = { r, bound };
@ -140,19 +139,19 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
RETURN_Z3(res);
}
else {
expr * _n = to_expr(n);
parameter p(to_sort(int_s));
ast* a = mk_c(c)->m().mk_app(mk_c(c)->get_bv_fid(), OP_BV2INT, 1, &p, 1, &_n);
mk_c(c)->save_ast_trail(a);
check_sorts(c, a);
RETURN_Z3(of_ast(a));
expr * _n = to_expr(n);
parameter p(to_sort(int_s));
ast* a = mk_c(c)->m().mk_app(mk_c(c)->get_bv_fid(), OP_BV2INT, 1, &p, 1, &_n);
mk_c(c)->save_ast_trail(a);
check_sorts(c, a);
RETURN_Z3(of_ast(a));
}
Z3_CATCH_RETURN(0);
}
/**
\brief Create a bit-vector of sort \s with 1 in the most significant bit position.
The sort \s must be a bit-vector sort.
This function is a shorthand for <tt>shl(1, N-1)</tt>
@ -343,7 +342,7 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
return Z3_mk_not(c, eq);
Z3_CATCH_RETURN(0);
}
// only for signed machine integers
Z3_ast Z3_API Z3_mk_bvsdiv_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2) {
Z3_TRY;
@ -369,7 +368,7 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
return result;
Z3_CATCH_RETURN(0);
}
Z3_ast Z3_API Z3_mk_bvsub(Z3_context c, Z3_ast n1, Z3_ast n2) {
Z3_TRY;
LOG_Z3_mk_bvsub(c, n1, n2);
@ -389,7 +388,7 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
unsigned Z3_API Z3_get_bv_sort_size(Z3_context c, Z3_sort t) {
Z3_TRY;
LOG_Z3_get_bv_sort_size(c, t);
RESET_ERROR_CODE();
RESET_ERROR_CODE();
CHECK_VALID_AST(t, 0);
if (to_sort(t)->get_family_id() == mk_c(c)->get_bv_fid() && to_sort(t)->get_decl_kind() == BV_SORT) {
return to_sort(t)->get_parameter(0).get_int();
@ -398,5 +397,5 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
return 0;
Z3_CATCH_RETURN(0);
}
};

View file

@ -37,7 +37,7 @@ extern "C" {
catch (z3_exception & ex) {
// The error handler is only available for contexts
// Just throw a warning.
warning_msg(ex.msg());
warning_msg("%s", ex.msg());
}
}
@ -62,7 +62,7 @@ extern "C" {
catch (z3_exception & ex) {
// The error handler is only available for contexts
// Just throw a warning.
warning_msg(ex.msg());
warning_msg("%s", ex.msg());
return Z3_FALSE;
}
}
@ -88,7 +88,7 @@ extern "C" {
catch (z3_exception & ex) {
// The error handler is only available for contexts
// Just throw a warning.
warning_msg(ex.msg());
warning_msg("%s", ex.msg());
}
}

View file

@ -17,6 +17,7 @@ Author:
Revision History:
--*/
#include<typeinfo>
#include"api_context.h"
#include"smtparser.h"
#include"version.h"
@ -32,6 +33,28 @@ void install_tactics(tactic_manager & ctx);
namespace api {
object::object(context& c): m_ref_count(0), m_context(c) { this->m_id = m_context.add_object(this); }
void object::inc_ref() { m_ref_count++; }
void object::dec_ref() { SASSERT(m_ref_count > 0); m_ref_count--; if (m_ref_count == 0) m_context.del_object(this); }
unsigned context::add_object(api::object* o) {
unsigned id = m_allocated_objects.size();
if (!m_free_object_ids.empty()) {
id = m_free_object_ids.back();
m_free_object_ids.pop_back();
}
m_allocated_objects.insert(id, o);
return id;
}
void context::del_object(api::object* o) {
m_free_object_ids.push_back(o->id());
m_allocated_objects.remove(o->id());
dealloc(o);
}
static void default_error_handler(Z3_context ctx, Z3_error_code c) {
printf("Error: %s\n", Z3_get_error_msg(ctx, c));
exit(1);
@ -47,22 +70,6 @@ namespace api {
//
// ------------------------
context::set_interruptable::set_interruptable(context & ctx, event_handler & i):
m_ctx(ctx) {
#pragma omp critical (set_interruptable)
{
SASSERT(m_ctx.m_interruptable == 0);
m_ctx.m_interruptable = &i;
}
}
context::set_interruptable::~set_interruptable() {
#pragma omp critical (set_interruptable)
{
m_ctx.m_interruptable = 0;
}
}
context::context(context_params * p, bool user_ref_count):
m_params(p != 0 ? *p : context_params()),
m_user_ref_count(user_ref_count),
@ -83,11 +90,10 @@ namespace api {
m_print_mode = Z3_PRINT_SMTLIB_FULL;
m_searching = false;
m_interruptable = 0;
m_smtlib_parser = 0;
m_smtlib_parser_has_decls = false;
m_interruptable = 0;
m_error_handler = &default_error_handler;
m_basic_fid = m().get_basic_family_id();
@ -108,6 +114,30 @@ namespace api {
context::~context() {
reset_parser();
m_last_obj = 0;
u_map<api::object*>::iterator it = m_allocated_objects.begin();
while (it != m_allocated_objects.end()) {
DEBUG_CODE(warning_msg("Uncollected memory: %d: %s", it->m_key, typeid(*it->m_value).name()););
m_allocated_objects.remove(it->m_key);
dealloc(it->m_value);
it = m_allocated_objects.begin();
}
}
context::set_interruptable::set_interruptable(context & ctx, event_handler & i):
m_ctx(ctx) {
#pragma omp critical (set_interruptable)
{
SASSERT(m_ctx.m_interruptable == 0);
m_ctx.m_interruptable = &i;
}
}
context::set_interruptable::~set_interruptable() {
#pragma omp critical (set_interruptable)
{
m_ctx.m_interruptable = 0;
}
}
void context::interrupt() {
@ -386,6 +416,7 @@ extern "C" {
return;
}
mk_c(c)->m().dec_ref(to_ast(a));
Z3_CATCH;
}
@ -401,6 +432,11 @@ extern "C" {
*revision_number = Z3_REVISION_NUMBER;
}
Z3_string Z3_API Z3_get_full_version(void) {
LOG_Z3_get_full_version();
return Z3_FULL_VERSION;
}
void Z3_API Z3_enable_trace(Z3_string tag) {
memory::initialize(UINT_MAX);
LOG_Z3_enable_trace(tag);
@ -465,6 +501,10 @@ extern "C" {
return _get_error_msg(c, err);
}
Z3_API char const * Z3_get_error_msg_ex(Z3_context c, Z3_error_code err) {
return Z3_get_error_msg(c, err);
}
void Z3_API Z3_set_ast_print_mode(Z3_context c, Z3_ast_print_mode mode) {
Z3_TRY;

View file

@ -36,6 +36,7 @@ Revision History:
#include"tactic_manager.h"
#include"context_params.h"
#include"api_polynomial.h"
#include"hashtable.h"
namespace smtlib {
class parser;
@ -72,6 +73,8 @@ namespace api {
ast_ref_vector m_ast_trail; //!< used when m_user_ref_count == false
ref<api::object> m_last_obj; //!< reference to the last API object returned by the APIs
u_map<api::object*> m_allocated_objects; // !< table containing current set of allocated API objects
unsigned_vector m_free_object_ids; // !< free list of identifiers available for allocated objects.
family_id m_basic_fid;
family_id m_array_fid;
@ -95,7 +98,7 @@ namespace api {
event_handler * m_interruptable; // Reference to an object that can be interrupted by Z3_interrupt
public:
public:
// Scoped obj for setting m_interruptable
class set_interruptable {
context & m_ctx;
@ -147,6 +150,9 @@ namespace api {
// Sign an error if solver is searching
void check_searching();
unsigned add_object(api::object* o);
void del_object(api::object* o);
Z3_ast_print_mode get_print_mode() const { return m_print_mode; }
void set_print_mode(Z3_ast_print_mode m) { m_print_mode = m; }
@ -245,7 +251,7 @@ inline api::context * mk_c(Z3_context c) { return reinterpret_cast<api::context*
#define CHECK_VALID_AST(_a_, _ret_) { if (_a_ == 0 || !CHECK_REF_COUNT(_a_)) { SET_ERROR_CODE(Z3_INVALID_ARG); return _ret_; } }
#define CHECK_SEARCHING(c) mk_c(c)->check_searching();
inline bool is_expr(Z3_ast a) { return is_expr(to_ast(a)); }
#define CHECK_IS_EXPR(_p_, _ret_) { if (!is_expr(_p_)) { SET_ERROR_CODE(Z3_INVALID_ARG); return _ret_; } }
#define CHECK_IS_EXPR(_p_, _ret_) { if (_p_ == 0 || !is_expr(_p_)) { SET_ERROR_CODE(Z3_INVALID_ARG); return _ret_; } }
inline bool is_bool_expr(Z3_context c, Z3_ast a) { return is_expr(a) && mk_c(c)->m().is_bool(to_expr(a)); }
#define CHECK_FORMULA(_a_, _ret_) { if (_a_ == 0 || !CHECK_REF_COUNT(_a_) || !is_bool_expr(c, _a_)) { SET_ERROR_CODE(Z3_INVALID_ARG); return _ret_; } }
inline void check_sorts(Z3_context c, ast * n) { mk_c(c)->check_sorts(n); }

View file

@ -189,7 +189,7 @@ extern "C" {
Z3_CATCH_RETURN(0);
}
Z3_sort Z3_API Z3_mk_finite_domain_sort(Z3_context c, Z3_symbol name, unsigned __int64 size) {
Z3_sort Z3_API Z3_mk_finite_domain_sort(Z3_context c, Z3_symbol name, __uint64 size) {
Z3_TRY;
LOG_Z3_mk_finite_domain_sort(c, name, size);
RESET_ERROR_CODE();
@ -199,7 +199,7 @@ extern "C" {
Z3_CATCH_RETURN(0);
}
Z3_bool Z3_API Z3_get_finite_domain_sort_size(Z3_context c, Z3_sort s, unsigned __int64 * out) {
Z3_bool Z3_API Z3_get_finite_domain_sort_size(Z3_context c, Z3_sort s, __uint64 * out) {
Z3_TRY;
if (out) {
*out = 0;
@ -223,7 +223,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_mk_fixedpoint(c);
RESET_ERROR_CODE();
Z3_fixedpoint_ref * d = alloc(Z3_fixedpoint_ref);
Z3_fixedpoint_ref * d = alloc(Z3_fixedpoint_ref, *mk_c(c));
d->m_datalog = alloc(api::fixedpoint_context, mk_c(c)->m(), mk_c(c)->fparams());
mk_c(c)->save_object(d);
Z3_fixedpoint r = of_datalog(d);
@ -290,8 +290,8 @@ extern "C" {
r = to_fixedpoint_ref(d)->ctx().query(to_expr(q));
}
catch (z3_exception& ex) {
mk_c(c)->handle_exception(ex);
r = l_undef;
mk_c(c)->handle_exception(ex);
}
to_fixedpoint_ref(d)->ctx().cleanup();
}
@ -369,7 +369,7 @@ extern "C" {
return 0;
}
Z3_ast_vector_ref* v = alloc(Z3_ast_vector_ref, m);
Z3_ast_vector_ref* v = alloc(Z3_ast_vector_ref, *mk_c(c), m);
mk_c(c)->save_object(v);
for (unsigned i = 0; i < coll.m_queries.size(); ++i) {
v->m_ast_vector.push_back(coll.m_queries[i].get());
@ -421,7 +421,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_fixedpoint_get_statistics(c, d);
RESET_ERROR_CODE();
Z3_stats_ref * st = alloc(Z3_stats_ref);
Z3_stats_ref * st = alloc(Z3_stats_ref, (*mk_c(c)));
to_fixedpoint_ref(d)->ctx().collect_statistics(st->m_stats);
mk_c(c)->save_object(st);
Z3_stats r = of_stats(st);
@ -460,7 +460,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_fixedpoint_get_rules(c, d);
ast_manager& m = mk_c(c)->m();
Z3_ast_vector_ref* v = alloc(Z3_ast_vector_ref, m);
Z3_ast_vector_ref* v = alloc(Z3_ast_vector_ref, *mk_c(c), m);
mk_c(c)->save_object(v);
expr_ref_vector rules(m), queries(m);
svector<symbol> names;
@ -483,7 +483,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_fixedpoint_get_assertions(c, d);
ast_manager& m = mk_c(c)->m();
Z3_ast_vector_ref* v = alloc(Z3_ast_vector_ref, m);
Z3_ast_vector_ref* v = alloc(Z3_ast_vector_ref, *mk_c(c), m);
mk_c(c)->save_object(v);
unsigned num_asserts = to_fixedpoint_ref(d)->ctx().get_num_assertions();
for (unsigned i = 0; i < num_asserts; ++i) {
@ -568,7 +568,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_fixedpoint_get_param_descrs(c, f);
RESET_ERROR_CODE();
Z3_param_descrs_ref * d = alloc(Z3_param_descrs_ref);
Z3_param_descrs_ref * d = alloc(Z3_param_descrs_ref, *mk_c(c));
mk_c(c)->save_object(d);
to_fixedpoint_ref(f)->collect_param_descrs(d->m_descrs);
Z3_param_descrs r = of_param_descrs(d);

View file

@ -30,13 +30,14 @@ typedef void (*reduce_assign_callback_fptr)(void*, func_decl*, unsigned, expr*co
namespace api {
class fixedpoint_context;
class context;
};
struct Z3_fixedpoint_ref : public api::object {
api::fixedpoint_context * m_datalog;
params_ref m_params;
Z3_fixedpoint_ref():m_datalog(0) {}
Z3_fixedpoint_ref(api::context& c): api::object(c), m_datalog(0) {}
virtual ~Z3_fixedpoint_ref() { dealloc(m_datalog); }
};

View file

@ -15,7 +15,6 @@ Author:
Revision History:
--*/
#include<iostream>
#include"z3.h"
#include"api_log_macros.h"
#include"api_context.h"
@ -24,16 +23,16 @@ Revision History:
extern "C" {
Z3_sort Z3_API Z3_mk_tuple_sort(Z3_context c,
Z3_sort Z3_API Z3_mk_tuple_sort(Z3_context c,
Z3_symbol name,
unsigned num_fields,
unsigned num_fields,
Z3_symbol const field_names[],
Z3_sort const field_sorts[],
Z3_func_decl * mk_tuple_decl,
Z3_func_decl proj_decls[]) {
Z3_TRY;
LOG_Z3_mk_tuple_sort(c, name, num_fields, field_names, field_sorts, mk_tuple_decl, proj_decls);
RESET_ERROR_CODE();
RESET_ERROR_CODE();
mk_c(c)->reset_last_result();
ast_manager& m = mk_c(c)->m();
datatype_util& dt_util = mk_c(c)->dtutil();
@ -43,14 +42,14 @@ extern "C" {
std::string recognizer_s("is_");
recognizer_s += to_symbol(name).str();
symbol recognizer(recognizer_s.c_str());
ptr_vector<accessor_decl> acc;
for (unsigned i = 0; i < num_fields; ++i) {
acc.push_back(mk_accessor_decl(to_symbol(field_names[i]), type_ref(to_sort(field_sorts[i]))));
}
constructor_decl* constrs[1] = { mk_constructor_decl(to_symbol(name), recognizer, acc.size(), acc.c_ptr()) };
{
datatype_decl * dt = mk_datatype_decl(to_symbol(name), 1, constrs);
bool is_ok = mk_c(c)->get_dt_plugin()->mk_datatypes(1, &dt, tuples);
@ -63,7 +62,7 @@ extern "C" {
}
// create tuple type
SASSERT(tuples.size() == 1);
SASSERT(tuples.size() == 1);
tuple = tuples[0].get();
mk_c(c)->save_multiple_ast_trail(tuple);
@ -72,9 +71,9 @@ extern "C" {
SASSERT(!dt_util.is_recursive(tuple));
ptr_vector<func_decl> const * decls = dt_util.get_datatype_constructors(tuple);
func_decl* decl = (*decls)[0];
mk_c(c)->save_multiple_ast_trail(decl);
mk_c(c)->save_multiple_ast_trail(decl);
*mk_tuple_decl = of_func_decl(decl);
// Create projections
ptr_vector<func_decl> const * accs = dt_util.get_constructor_accessors(decl);
if (!accs) {
@ -90,8 +89,8 @@ extern "C" {
RETURN_Z3_mk_tuple_sort(of_sort(tuple));
Z3_CATCH_RETURN(0);
}
Z3_sort Z3_API Z3_mk_enumeration_sort(Z3_context c,
Z3_sort Z3_API Z3_mk_enumeration_sort(Z3_context c,
Z3_symbol name,
unsigned n,
Z3_symbol const enum_names[],
@ -106,7 +105,7 @@ extern "C" {
sort_ref_vector sorts(m);
sort* e;
ptr_vector<constructor_decl> constrs;
for (unsigned i = 0; i < n; ++i) {
symbol e_name(to_symbol(enum_names[i]));
@ -128,9 +127,9 @@ extern "C" {
RETURN_Z3(0);
}
}
// create enum type.
SASSERT(sorts.size() == 1);
SASSERT(sorts.size() == 1);
e = sorts[0].get();
mk_c(c)->save_multiple_ast_trail(e);
@ -141,10 +140,10 @@ extern "C" {
SASSERT(decls && decls->size() == n);
for (unsigned i = 0; i < n; ++i) {
func_decl* decl = (*decls)[i];
mk_c(c)->save_multiple_ast_trail(decl);
mk_c(c)->save_multiple_ast_trail(decl);
enum_consts[i] = of_func_decl(decl);
decl = dt_util.get_constructor_recognizer(decl);
mk_c(c)->save_multiple_ast_trail(decl);
mk_c(c)->save_multiple_ast_trail(decl);
enum_testers[i] = of_func_decl(decl);
}
@ -168,11 +167,11 @@ extern "C" {
ast_manager& m = mk_c(c)->m();
mk_c(c)->reset_last_result();
datatype_util data_util(m);
accessor_decl* head_tail[2] = {
accessor_decl* head_tail[2] = {
mk_accessor_decl(symbol("head"), type_ref(to_sort(elem_sort))),
mk_accessor_decl(symbol("tail"), type_ref(0))
};
constructor_decl* constrs[2] = {
constructor_decl* constrs[2] = {
mk_constructor_decl(symbol("nil"), symbol("is_nil"), 0, 0),
// Leo: SMT 2.0 document uses 'insert' instead of cons
mk_constructor_decl(symbol("cons"), symbol("is_cons"), 2, head_tail)
@ -197,22 +196,22 @@ extern "C" {
func_decl* f;
if (nil_decl) {
f = cnstrs[0];
mk_c(c)->save_multiple_ast_trail(f);
mk_c(c)->save_multiple_ast_trail(f);
*nil_decl = of_func_decl(f);
}
if (is_nil_decl) {
f = data_util.get_constructor_recognizer(cnstrs[0]);
mk_c(c)->save_multiple_ast_trail(f);
mk_c(c)->save_multiple_ast_trail(f);
*is_nil_decl = of_func_decl(f);
}
if (cons_decl) {
f = cnstrs[1];
mk_c(c)->save_multiple_ast_trail(f);
mk_c(c)->save_multiple_ast_trail(f);
*cons_decl = of_func_decl(f);
}
if (is_cons_decl) {
f = data_util.get_constructor_recognizer(cnstrs[1]);
mk_c(c)->save_multiple_ast_trail(f);
mk_c(c)->save_multiple_ast_trail(f);
*is_cons_decl = of_func_decl(f);
}
if (head_decl) {
@ -220,7 +219,7 @@ extern "C" {
SASSERT(acc);
SASSERT(acc->size() == 2);
f = (*acc)[0];
mk_c(c)->save_multiple_ast_trail(f);
mk_c(c)->save_multiple_ast_trail(f);
*head_decl = of_func_decl(f);
}
if (tail_decl) {
@ -228,7 +227,7 @@ extern "C" {
SASSERT(acc);
SASSERT(acc->size() == 2);
f = (*acc)[1];
mk_c(c)->save_multiple_ast_trail(f);
mk_c(c)->save_multiple_ast_trail(f);
*tail_decl = of_func_decl(f);
}
RETURN_Z3_mk_list_sort(of_sort(s));
@ -255,7 +254,7 @@ extern "C" {
) {
Z3_TRY;
LOG_Z3_mk_constructor(c, name, tester, num_fields, field_names, sorts, sort_refs);
RESET_ERROR_CODE();
RESET_ERROR_CODE();
ast_manager& m = mk_c(c)->m();
constructor* cnstr = alloc(constructor, m);
cnstr->m_name = to_symbol(name);
@ -291,7 +290,7 @@ extern "C" {
if (!f) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return;
}
}
if (constructor_decl) {
mk_c(c)->save_multiple_ast_trail(f);
*constructor_decl = of_func_decl(f);
@ -301,15 +300,15 @@ extern "C" {
mk_c(c)->save_multiple_ast_trail(f2);
*tester = of_func_decl(f2);
}
ptr_vector<func_decl> const* accs = data_util.get_constructor_accessors(f);
if (!accs && num_fields > 0) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return;
return;
}
for (unsigned i = 0; i < num_fields; ++i) {
func_decl* f2 = (*accs)[i];
mk_c(c)->save_multiple_ast_trail(f2);
mk_c(c)->save_multiple_ast_trail(f2);
accessors[i] = of_func_decl(f2);
}
RETURN_Z3_query_constructor;
@ -324,7 +323,7 @@ extern "C" {
Z3_CATCH;
}
static datatype_decl* mk_datatype_decl(Z3_context c,
static datatype_decl* mk_datatype_decl(Z3_context c,
Z3_symbol name,
unsigned num_constructors,
Z3_constructor constructors[]) {
@ -342,7 +341,7 @@ extern "C" {
}
constrs.push_back(mk_constructor_decl(cn->m_name, cn->m_tester, acc.size(), acc.c_ptr()));
}
return mk_datatype_decl(to_symbol(name), num_constructors, constrs.c_ptr());
return mk_datatype_decl(to_symbol(name), num_constructors, constrs.c_ptr());
}
Z3_sort Z3_API Z3_mk_datatype(Z3_context c,
@ -352,9 +351,9 @@ extern "C" {
Z3_TRY;
LOG_Z3_mk_datatype(c, name, num_constructors, constructors);
RESET_ERROR_CODE();
ast_manager& m = mk_c(c)->m();
ast_manager& m = mk_c(c)->m();
datatype_util data_util(m);
sort_ref_vector sorts(m);
{
datatype_decl * data = mk_datatype_decl(c, name, num_constructors, constructors);
@ -370,7 +369,7 @@ extern "C" {
mk_c(c)->save_ast_trail(s);
ptr_vector<func_decl> const* cnstrs = data_util.get_datatype_constructors(s);
for (unsigned i = 0; i < num_constructors; ++i) {
constructor* cn = reinterpret_cast<constructor*>(constructors[i]);
cn->m_constructor = (*cnstrs)[i];
@ -411,7 +410,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_mk_datatypes(c, num_sorts, sort_names, sorts, constructor_lists);
RESET_ERROR_CODE();
ast_manager& m = mk_c(c)->m();
ast_manager& m = mk_c(c)->m();
mk_c(c)->reset_last_result();
datatype_util data_util(m);
@ -423,7 +422,7 @@ extern "C" {
sort_ref_vector _sorts(m);
bool ok = mk_c(c)->get_dt_plugin()->mk_datatypes(datas.size(), datas.c_ptr(), _sorts);
del_datatype_decls(datas.size(), datas.c_ptr());
if (!ok) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return;
@ -437,8 +436,8 @@ extern "C" {
constructor_list* cl = reinterpret_cast<constructor_list*>(constructor_lists[i]);
ptr_vector<func_decl> const* cnstrs = data_util.get_datatype_constructors(s);
for (unsigned j = 0; j < cl->size(); ++j) {
constructor* cn = (*cl)[j];
cn->m_constructor = (*cnstrs)[j];
constructor* cn = (*cl)[j];
cn->m_constructor = (*cnstrs)[j];
}
}
RETURN_Z3_mk_datatypes;
@ -452,15 +451,15 @@ extern "C" {
CHECK_VALID_AST(t, 0);
sort * _t = to_sort(t);
datatype_util& dt_util = mk_c(c)->dtutil();
if (!dt_util.is_datatype(_t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
return 0;
}
ptr_vector<func_decl> const * decls = dt_util.get_datatype_constructors(_t);
if (!decls) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
return 0;
}
return decls->size();
Z3_CATCH_RETURN(0);
@ -468,7 +467,7 @@ extern "C" {
Z3_func_decl get_datatype_sort_constructor_core(Z3_context c, Z3_sort t, unsigned idx) {
RESET_ERROR_CODE();
CHECK_VALID_AST(t, 0);
CHECK_VALID_AST(t, 0);
sort * _t = to_sort(t);
datatype_util& dt_util = mk_c(c)->dtutil();
if (!dt_util.is_datatype(_t)) {
@ -497,10 +496,10 @@ extern "C" {
Z3_func_decl Z3_API Z3_get_datatype_sort_recognizer(Z3_context c, Z3_sort t, unsigned idx) {
Z3_TRY;
LOG_Z3_get_datatype_sort_recognizer(c, t, idx);
RESET_ERROR_CODE();
RESET_ERROR_CODE();
sort * _t = to_sort(t);
datatype_util& dt_util = mk_c(c)->dtutil();
if (!dt_util.is_datatype(_t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
@ -520,13 +519,13 @@ extern "C" {
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor_accessor(Z3_context c, Z3_sort t, unsigned idx_c, unsigned idx_a) {
Z3_TRY;
LOG_Z3_get_datatype_sort_constructor_accessor(c, t, idx_c, idx_a);
RESET_ERROR_CODE();
RESET_ERROR_CODE();
sort * _t = to_sort(t);
datatype_util& dt_util = mk_c(c)->dtutil();
if (!dt_util.is_datatype(_t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(0);
}
ptr_vector<func_decl> const * decls = dt_util.get_datatype_constructors(_t);
if (!decls || idx_c >= decls->size()) {
@ -536,24 +535,24 @@ extern "C" {
func_decl* decl = (*decls)[idx_c];
if (decl->get_arity() <= idx_a) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(0);
}
ptr_vector<func_decl> const * accs = dt_util.get_constructor_accessors(decl);
SASSERT(accs && accs->size() == decl->get_arity());
if (!accs || accs->size() <= idx_a) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(0);
}
decl = (*accs)[idx_a];
mk_c(c)->save_ast_trail(decl);
RETURN_Z3(of_func_decl(decl));
RETURN_Z3(of_func_decl(decl));
Z3_CATCH_RETURN(0);
}
Z3_func_decl Z3_API Z3_get_tuple_sort_mk_decl(Z3_context c, Z3_sort t) {
Z3_TRY;
LOG_Z3_get_tuple_sort_mk_decl(c, t);
RESET_ERROR_CODE();
RESET_ERROR_CODE();
sort * tuple = to_sort(t);
datatype_util& dt_util = mk_c(c)->dtutil();
if (!dt_util.is_datatype(tuple) || dt_util.is_recursive(tuple) || dt_util.get_datatype_num_constructors(tuple) != 1) {
@ -564,34 +563,34 @@ extern "C" {
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
}
unsigned Z3_API Z3_get_tuple_sort_num_fields(Z3_context c, Z3_sort t) {
Z3_TRY;
LOG_Z3_get_tuple_sort_num_fields(c, t);
RESET_ERROR_CODE();
RESET_ERROR_CODE();
sort * tuple = to_sort(t);
datatype_util& dt_util = mk_c(c)->dtutil();
if (!dt_util.is_datatype(tuple) || dt_util.is_recursive(tuple) || dt_util.get_datatype_num_constructors(tuple) != 1) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
return 0;
}
ptr_vector<func_decl> const * decls = dt_util.get_datatype_constructors(tuple);
if (!decls || decls->size() != 1) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
return 0;
}
ptr_vector<func_decl> const * accs = dt_util.get_constructor_accessors((*decls)[0]);
if (!accs) {
return 0;
return 0;
}
return accs->size();
Z3_CATCH_RETURN(0);
}
Z3_func_decl Z3_API Z3_get_tuple_sort_field_decl(Z3_context c, Z3_sort t, unsigned i) {
Z3_TRY;
LOG_Z3_get_tuple_sort_field_decl(c, t, i);
RESET_ERROR_CODE();
RESET_ERROR_CODE();
sort * tuple = to_sort(t);
datatype_util& dt_util = mk_c(c)->dtutil();
if (!dt_util.is_datatype(tuple) || dt_util.is_recursive(tuple) || dt_util.get_datatype_num_constructors(tuple) != 1) {
@ -619,14 +618,14 @@ extern "C" {
}
Z3_ast Z3_datatype_update_field(
Z3_context c, Z3_func_decl f, Z3_ast t, Z3_ast v) {
Z3_context c, Z3_func_decl f, Z3_ast t, Z3_ast v) {
Z3_TRY;
LOG_Z3_datatype_update_field(c, f, t, v);
RESET_ERROR_CODE();
ast_manager & m = mk_c(c)->m();
func_decl* _f = to_func_decl(f);
expr* _t = to_expr(t);
expr* _v = to_expr(v);
expr* _v = to_expr(v);
expr* args[2] = { _t, _v };
sort* domain[2] = { m.get_sort(_t), m.get_sort(_v) };
parameter param(_f);

View file

@ -909,12 +909,18 @@ extern "C" {
Z3_TRY;
LOG_Z3_fpa_get_numeral_sign(c, t, sgn);
RESET_ERROR_CODE();
CHECK_NON_NULL(t, 0);
CHECK_VALID_AST(t, 0);
if (sgn == 0) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
}
ast_manager & m = mk_c(c)->m();
mpf_manager & mpfm = mk_c(c)->fpautil().fm();
fpa_decl_plugin * plugin = (fpa_decl_plugin*)m.get_plugin(mk_c(c)->get_fpa_fid());
family_id fid = mk_c(c)->get_fpa_fid();
fpa_decl_plugin * plugin = (fpa_decl_plugin*)m.get_plugin(fid);
expr * e = to_expr(t);
if (!is_app(e) || is_app_of(e, fid, OP_FPA_NAN)) {
if (!is_app(e) || is_app_of(e, fid, OP_FPA_NAN) || !is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
}
@ -929,10 +935,44 @@ extern "C" {
Z3_CATCH_RETURN(0);
}
Z3_string Z3_API Z3_fpa_get_numeral_significand_string(Z3_context c, Z3_ast t) {
Z3_ast Z3_API Z3_fpa_get_numeral_sign_bv(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_fpa_get_numeral_significand_string(c, t);
LOG_Z3_fpa_get_numeral_sign_bv(c, t);
RESET_ERROR_CODE();
CHECK_NON_NULL(t, 0);
CHECK_VALID_AST(t, 0);
ast_manager & m = mk_c(c)->m();
mpf_manager & mpfm = mk_c(c)->fpautil().fm();
family_id fid = mk_c(c)->get_fpa_fid();
fpa_decl_plugin * plugin = (fpa_decl_plugin*)m.get_plugin(fid);
api::context * ctx = mk_c(c);
expr * e = to_expr(t);
if (!is_app(e) || is_app_of(e, fid, OP_FPA_NAN) || !is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
}
scoped_mpf val(mpfm);
bool r = plugin->is_numeral(to_expr(t), val);
if (!r || mpfm.is_nan(val)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
}
app * a;
if (mpfm.is_pos(val))
a = ctx->bvutil().mk_numeral(0, 1);
else
a = ctx->bvutil().mk_numeral(1, 1);
mk_c(c)->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
}
Z3_ast Z3_API Z3_fpa_get_numeral_significand_bv(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_fpa_get_numeral_significand_bv(c, t);
RESET_ERROR_CODE();
CHECK_NON_NULL(t, 0);
CHECK_VALID_AST(t, 0);
ast_manager & m = mk_c(c)->m();
mpf_manager & mpfm = mk_c(c)->fpautil().fm();
unsynch_mpq_manager & mpqm = mpfm.mpq_manager();
@ -940,17 +980,47 @@ extern "C" {
fpa_decl_plugin * plugin = (fpa_decl_plugin*)m.get_plugin(fid);
SASSERT(plugin != 0);
expr * e = to_expr(t);
if (!is_app(e) ||
is_app_of(e, fid, OP_FPA_NAN) ||
is_app_of(e, fid, OP_FPA_PLUS_INF) ||
is_app_of(e, fid, OP_FPA_MINUS_INF)) {
if (!is_app(e) || is_app_of(e, fid, OP_FPA_NAN) || !is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
}
scoped_mpf val(mpfm);
bool r = plugin->is_numeral(e, val);
if (!r || !(mpfm.is_normal(val) || mpfm.is_denormal(val) || mpfm.is_zero(val) || mpfm.is_inf(val))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
}
unsigned sbits = val.get().get_sbits();
scoped_mpq q(mpqm);
mpqm.set(q, mpfm.sig(val));
if (mpfm.is_inf(val)) mpqm.set(q, 0);
app * a = mk_c(c)->bvutil().mk_numeral(q.get(), sbits-1);
mk_c(c)->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
}
Z3_string Z3_API Z3_fpa_get_numeral_significand_string(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_fpa_get_numeral_significand_string(c, t);
RESET_ERROR_CODE();
CHECK_NON_NULL(t, 0);
CHECK_VALID_AST(t, 0);
ast_manager & m = mk_c(c)->m();
mpf_manager & mpfm = mk_c(c)->fpautil().fm();
unsynch_mpq_manager & mpqm = mpfm.mpq_manager();
family_id fid = mk_c(c)->get_fpa_fid();
fpa_decl_plugin * plugin = (fpa_decl_plugin*)m.get_plugin(fid);
SASSERT(plugin != 0);
expr * e = to_expr(t);
if (!is_app(e) || is_app_of(e, fid, OP_FPA_NAN) || !is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return "";
}
scoped_mpf val(mpfm);
bool r = plugin->is_numeral(e, val);
if (!r || !(mpfm.is_normal(val) || mpfm.is_denormal(val) || mpfm.is_zero(val))) {
SET_ERROR_CODE(Z3_INVALID_ARG)
if (!r || !(mpfm.is_normal(val) || mpfm.is_denormal(val) || mpfm.is_zero(val) || mpfm.is_inf(val))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return "";
}
unsigned sbits = val.get().get_sbits();
@ -958,6 +1028,7 @@ extern "C" {
mpqm.set(q, mpfm.sig(val));
if (!mpfm.is_denormal(val)) mpqm.add(q, mpfm.m_powers2(sbits - 1), q);
mpqm.div(q, mpfm.m_powers2(sbits - 1), q);
if (mpfm.is_inf(val)) mpqm.set(q, 0);
std::stringstream ss;
mpqm.display_decimal(ss, q, sbits);
return mk_c(c)->mk_external_string(ss.str());
@ -968,6 +1039,12 @@ extern "C" {
Z3_TRY;
LOG_Z3_fpa_get_numeral_significand_uint64(c, t, n);
RESET_ERROR_CODE();
CHECK_NON_NULL(t, 0);
CHECK_VALID_AST(t, 0);
if (n == 0) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
}
ast_manager & m = mk_c(c)->m();
mpf_manager & mpfm = mk_c(c)->fpautil().fm();
unsynch_mpz_manager & mpzm = mpfm.mpz_manager();
@ -975,10 +1052,7 @@ extern "C" {
fpa_decl_plugin * plugin = (fpa_decl_plugin*)m.get_plugin(fid);
SASSERT(plugin != 0);
expr * e = to_expr(t);
if (!is_app(e) ||
is_app_of(e, fid, OP_FPA_NAN) ||
is_app_of(e, fid, OP_FPA_PLUS_INF) ||
is_app_of(e, fid, OP_FPA_MINUS_INF)) {
if (!is_app(e) || is_app_of(e, fid, OP_FPA_NAN) || !is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
*n = 0;
return 0;
@ -987,7 +1061,7 @@ extern "C" {
bool r = plugin->is_numeral(e, val);
const mpz & z = mpfm.sig(val);
if (!r ||
!(mpfm.is_normal(val) || mpfm.is_denormal(val) || mpfm.is_zero(val)) ||
!(mpfm.is_normal(val) || mpfm.is_denormal(val) || mpfm.is_zero(val) || mpfm.is_inf(val)) ||
!mpzm.is_uint64(z)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
*n = 0;
@ -998,74 +1072,137 @@ extern "C" {
Z3_CATCH_RETURN(0);
}
Z3_string Z3_API Z3_fpa_get_numeral_exponent_string(Z3_context c, Z3_ast t) {
Z3_string Z3_API Z3_fpa_get_numeral_exponent_string(Z3_context c, Z3_ast t, Z3_bool biased) {
Z3_TRY;
LOG_Z3_fpa_get_numeral_exponent_string(c, t);
LOG_Z3_fpa_get_numeral_exponent_string(c, t, biased);
RESET_ERROR_CODE();
CHECK_NON_NULL(t, 0);
CHECK_VALID_AST(t, 0);
ast_manager & m = mk_c(c)->m();
mpf_manager & mpfm = mk_c(c)->fpautil().fm();
family_id fid = mk_c(c)->get_fpa_fid();
fpa_decl_plugin * plugin = (fpa_decl_plugin*)m.get_plugin(mk_c(c)->get_fpa_fid());
SASSERT(plugin != 0);
expr * e = to_expr(t);
if (!is_app(e) ||
is_app_of(e, fid, OP_FPA_NAN) ||
is_app_of(e, fid, OP_FPA_PLUS_INF) ||
is_app_of(e, fid, OP_FPA_MINUS_INF)) {
if (!is_app(e) || is_app_of(e, fid, OP_FPA_NAN) || !is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return "";
}
scoped_mpf val(mpfm);
bool r = plugin->is_numeral(e, val);
if (!r || !(mpfm.is_normal(val) || mpfm.is_denormal(val) || mpfm.is_zero(val))) {
if (!r || !(mpfm.is_normal(val) || mpfm.is_denormal(val) || mpfm.is_zero(val) || mpfm.is_inf(val))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return "";
}
mpf_exp_t exp = mpfm.is_zero(val) ? 0 :
mpfm.is_denormal(val) ? mpfm.mk_min_exp(val.get().get_ebits()) :
mpfm.exp(val);
unsigned ebits = val.get().get_ebits();
mpf_exp_t exp;
if (biased) {
exp = mpfm.is_zero(val) ? 0 :
mpfm.is_inf(val) ? mpfm.mk_top_exp(ebits) :
mpfm.bias_exp(ebits, mpfm.exp(val));
}
else {
exp = mpfm.is_zero(val) ? 0 :
mpfm.is_inf(val) ? mpfm.mk_top_exp(ebits) :
mpfm.is_denormal(val) ? mpfm.mk_min_exp(ebits) :
mpfm.exp(val);
}
std::stringstream ss;
ss << exp;
return mk_c(c)->mk_external_string(ss.str());
Z3_CATCH_RETURN("");
}
Z3_bool Z3_API Z3_fpa_get_numeral_exponent_int64(Z3_context c, Z3_ast t, __int64 * n) {
Z3_bool Z3_API Z3_fpa_get_numeral_exponent_int64(Z3_context c, Z3_ast t, __int64 * n, Z3_bool biased) {
Z3_TRY;
LOG_Z3_fpa_get_numeral_exponent_int64(c, t, n);
LOG_Z3_fpa_get_numeral_exponent_int64(c, t, n, biased);
RESET_ERROR_CODE();
CHECK_NON_NULL(t, 0);
CHECK_VALID_AST(t, 0);
if (n == 0) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
}
ast_manager & m = mk_c(c)->m();
mpf_manager & mpfm = mk_c(c)->fpautil().fm();
family_id fid = mk_c(c)->get_fpa_fid();
fpa_decl_plugin * plugin = (fpa_decl_plugin*)m.get_plugin(mk_c(c)->get_fpa_fid());
SASSERT(plugin != 0);
expr * e = to_expr(t);
if (!is_app(e) ||
is_app_of(e, fid, OP_FPA_NAN) ||
is_app_of(e, fid, OP_FPA_PLUS_INF) ||
is_app_of(e, fid, OP_FPA_MINUS_INF)) {
if (!is_app(e) || is_app_of(e, fid, OP_FPA_NAN) || !is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
*n = 0;
return 0;
}
scoped_mpf val(mpfm);
bool r = plugin->is_numeral(e, val);
if (!r || !(mpfm.is_normal(val) || mpfm.is_denormal(val) || mpfm.is_zero(val))) {
if (!r || !(mpfm.is_normal(val) || mpfm.is_denormal(val) || mpfm.is_zero(val) || mpfm.is_inf(val))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
*n = 0;
return 0;
}
*n = mpfm.is_zero(val) ? 0 :
mpfm.is_denormal(val) ? mpfm.mk_min_exp(val.get().get_ebits()) :
mpfm.exp(val);
unsigned ebits = val.get().get_ebits();
if (biased) {
*n = mpfm.is_zero(val) ? 0 :
mpfm.is_inf(val) ? mpfm.mk_top_exp(ebits) :
mpfm.bias_exp(ebits, mpfm.exp(val));
}
else {
*n = mpfm.is_zero(val) ? 0 :
mpfm.is_inf(val) ? mpfm.mk_top_exp(ebits) :
mpfm.is_denormal(val) ? mpfm.mk_min_exp(ebits) :
mpfm.exp(val);
}
return 1;
Z3_CATCH_RETURN(0);
}
Z3_ast Z3_API Z3_fpa_get_numeral_exponent_bv(Z3_context c, Z3_ast t, Z3_bool biased) {
Z3_TRY;
LOG_Z3_fpa_get_numeral_exponent_bv(c, t, biased);
RESET_ERROR_CODE();
CHECK_NON_NULL(t, 0);
CHECK_VALID_AST(t, 0);
ast_manager & m = mk_c(c)->m();
mpf_manager & mpfm = mk_c(c)->fpautil().fm();
family_id fid = mk_c(c)->get_fpa_fid();
fpa_decl_plugin * plugin = (fpa_decl_plugin*)m.get_plugin(fid);
expr * e = to_expr(t);
if (!is_app(e) || is_app_of(e, fid, OP_FPA_NAN) || !is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
}
scoped_mpf val(mpfm);
bool r = plugin->is_numeral(e, val);
if (!r || !(mpfm.is_normal(val) || mpfm.is_denormal(val) || mpfm.is_zero(val) || mpfm.is_inf(val))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
}
unsigned ebits = val.get().get_ebits();
mpf_exp_t exp;
if (biased) {
exp = mpfm.is_zero(val) ? 0 :
mpfm.is_inf(val) ? mpfm.mk_top_exp(ebits) :
mpfm.bias_exp(ebits, mpfm.exp(val));
}
else {
exp = mpfm.is_zero(val) ? 0 :
mpfm.is_inf(val) ? mpfm.mk_top_exp(ebits) :
mpfm.is_denormal(val) ? mpfm.mk_min_exp(ebits) :
mpfm.exp(val);
}
app * a = mk_c(c)->bvutil().mk_numeral(exp, ebits);
mk_c(c)->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
}
Z3_ast Z3_API Z3_mk_fpa_to_ieee_bv(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_mk_fpa_to_ieee_bv(c, t);
RESET_ERROR_CODE();
CHECK_NON_NULL(t, 0);
CHECK_VALID_AST(t, 0);
if (!is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
@ -1095,4 +1232,102 @@ extern "C" {
Z3_CATCH_RETURN(0);
}
Z3_bool Z3_API Z3_fpa_is_numeral_nan(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_fpa_is_numeral_nan(c, t);
RESET_ERROR_CODE();
api::context * ctx = mk_c(c);
fpa_util & fu = ctx->fpautil();
if (!is_expr(t) || !fu.is_numeral(to_expr(t))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
}
return fu.is_nan(to_expr(t));
Z3_CATCH_RETURN(Z3_FALSE);
}
Z3_bool Z3_API Z3_fpa_is_numeral_inf(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_fpa_is_numeral_inf(c, t);
RESET_ERROR_CODE();
api::context * ctx = mk_c(c);
fpa_util & fu = ctx->fpautil();
if (!is_expr(t) || !fu.is_numeral(to_expr(t))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
}
return fu.is_inf(to_expr(t));
Z3_CATCH_RETURN(Z3_FALSE);
}
Z3_bool Z3_API Z3_fpa_is_numeral_zero(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_fpa_is_numeral_zero(c, t);
RESET_ERROR_CODE();
api::context * ctx = mk_c(c);
fpa_util & fu = ctx->fpautil();
if (!is_expr(t) || !fu.is_numeral(to_expr(t))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
}
return fu.is_zero(to_expr(t));
Z3_CATCH_RETURN(Z3_FALSE);
}
Z3_bool Z3_API Z3_fpa_is_numeral_normal(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_fpa_is_numeral_normal(c, t);
RESET_ERROR_CODE();
api::context * ctx = mk_c(c);
fpa_util & fu = ctx->fpautil();
if (!is_expr(t) || !fu.is_numeral(to_expr(t))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
}
return fu.is_normal(to_expr(t));
Z3_CATCH_RETURN(Z3_FALSE);
}
Z3_bool Z3_API Z3_fpa_is_numeral_subnormal(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_fpa_is_numeral_subnormal(c, t);
RESET_ERROR_CODE();
api::context * ctx = mk_c(c);
fpa_util & fu = ctx->fpautil();
if (!is_expr(t) || !fu.is_numeral(to_expr(t))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
}
return fu.is_subnormal(to_expr(t));
Z3_CATCH_RETURN(Z3_FALSE);
}
Z3_bool Z3_API Z3_fpa_is_numeral_positive(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_fpa_is_numeral_positive(c, t);
RESET_ERROR_CODE();
api::context * ctx = mk_c(c);
fpa_util & fu = ctx->fpautil();
if (!is_expr(t) || !fu.is_numeral(to_expr(t))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
}
return fu.is_positive(to_expr(t));
Z3_CATCH_RETURN(Z3_FALSE);
}
Z3_bool Z3_API Z3_fpa_is_numeral_negative(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_fpa_is_numeral_negative(c, t);
RESET_ERROR_CODE();
api::context * ctx = mk_c(c);
fpa_util & fu = ctx->fpautil();
if (!is_expr(t) || !fu.is_numeral(to_expr(t))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
}
return fu.is_negative(to_expr(t));
Z3_CATCH_RETURN(Z3_FALSE);
}
};

View file

@ -32,7 +32,7 @@ extern "C" {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
}
Z3_goal_ref * g = alloc(Z3_goal_ref);
Z3_goal_ref * g = alloc(Z3_goal_ref, *mk_c(c));
g->m_goal = alloc(goal, mk_c(c)->m(), proofs != 0, models != 0, unsat_cores != 0);
mk_c(c)->save_object(g);
Z3_goal r = of_goal(g);
@ -156,7 +156,7 @@ extern "C" {
LOG_Z3_goal_translate(c, g, target);
RESET_ERROR_CODE();
ast_translation translator(mk_c(c)->m(), mk_c(target)->m());
Z3_goal_ref * _r = alloc(Z3_goal_ref);
Z3_goal_ref * _r = alloc(Z3_goal_ref, *mk_c(target));
_r->m_goal = to_goal_ref(g)->translate(translator);
mk_c(target)->save_object(_r);
Z3_goal r = of_goal(_r);

View file

@ -23,6 +23,7 @@ Revision History:
struct Z3_goal_ref : public api::object {
goal_ref m_goal;
Z3_goal_ref(api::context& c) : api::object(c) {}
virtual ~Z3_goal_ref() {}
};

View file

@ -15,7 +15,6 @@
Revision History:
--*/
#include<iostream>
#include<sstream>
#include<vector>
#include"z3.h"
@ -212,7 +211,7 @@ extern "C" {
LOG_Z3_get_interpolant(c, pf, pat, p);
RESET_ERROR_CODE();
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, mk_c(c)->m());
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(v);
ast *_pf = to_ast(pf);
@ -303,7 +302,7 @@ extern "C" {
if (_status == l_false){
// copy result back
v = alloc(Z3_ast_vector_ref, mk_c(c)->m());
v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(v);
for (unsigned i = 0; i < interp.size(); i++){
v->m_ast_vector.push_back(interp[i]);
@ -314,7 +313,7 @@ extern "C" {
model_ref mr;
m_solver.get()->get_model(mr);
if(mr.get()){
Z3_model_ref *tmp_val = alloc(Z3_model_ref);
Z3_model_ref *tmp_val = alloc(Z3_model_ref, *mk_c(c));
tmp_val->m_model = mr.get();
mk_c(c)->save_object(tmp_val);
*model = of_model(tmp_val);
@ -375,7 +374,7 @@ extern "C" {
for(int i = 0; i < num_theory; i++)
fmlas[i] = Z3_mk_implies(ctx,Z3_mk_true(ctx),fmlas[i]);
std::copy(cnsts,cnsts+num,fmlas.begin()+num_theory);
Z3_string smt = Z3_benchmark_to_smtlib_string(ctx,"none","AUFLIA","unknown","",num_fmlas-1,&fmlas[0],fmlas[num_fmlas-1]);
Z3_string smt = Z3_benchmark_to_smtlib_string(ctx,"none","AUFLIA","unknown","",num_fmlas-1,&fmlas[0],fmlas[num_fmlas-1]);
std::ofstream f(filename);
if(num_theory)
f << ";! THEORY=" << num_theory << "\n";
@ -469,7 +468,7 @@ extern "C" {
}
f.close();
#if 0
#if 0
if(!parents){

View file

@ -15,40 +15,75 @@ Author:
Revision History:
--*/
#include<iostream>
#include<fstream>
#include"z3.h"
#include"api_log_macros.h"
#include"util.h"
#include"version.h"
std::ostream * g_z3_log = 0;
bool g_z3_log_enabled = false;
extern "C" {
Z3_bool Z3_API Z3_open_log(Z3_string filename) {
if (g_z3_log != 0)
Z3_close_log();
g_z3_log = alloc(std::ofstream, filename);
g_z3_log_enabled = true;
if (g_z3_log->bad() || g_z3_log->fail()) {
dealloc(g_z3_log);
g_z3_log = 0;
return Z3_FALSE;
}
return Z3_TRUE;
}
void Z3_API Z3_append_log(Z3_string str) {
if (g_z3_log == 0)
return;
_Z3_append_log(static_cast<char const *>(str));
}
void Z3_API Z3_close_log(void) {
void Z3_close_log_unsafe(void) {
if (g_z3_log != 0) {
dealloc(g_z3_log);
g_z3_log_enabled = false;
g_z3_log = 0;
}
}
Z3_bool Z3_API Z3_open_log(Z3_string filename) {
Z3_bool res = Z3_TRUE;
#ifdef Z3_LOG_SYNC
#pragma omp critical (z3_log)
{
#endif
if (g_z3_log != 0)
Z3_close_log_unsafe();
g_z3_log = alloc(std::ofstream, filename);
if (g_z3_log->bad() || g_z3_log->fail()) {
dealloc(g_z3_log);
g_z3_log = 0;
res = Z3_FALSE;
}
else {
*g_z3_log << "V \"" << Z3_MAJOR_VERSION << "." << Z3_MINOR_VERSION << "." << Z3_BUILD_NUMBER << "." << Z3_REVISION_NUMBER << " " << __DATE__ << "\"\n";
g_z3_log->flush();
g_z3_log_enabled = true;
}
#ifdef Z3_LOG_SYNC
}
#endif
return res;
}
void Z3_API Z3_append_log(Z3_string str) {
if (g_z3_log == 0)
return;
#ifdef Z3_LOG_SYNC
#pragma omp critical (z3_log)
{
#endif
if (g_z3_log != 0)
_Z3_append_log(static_cast<char const *>(str));
#ifdef Z3_LOG_SYNC
}
#endif
}
void Z3_API Z3_close_log(void) {
if (g_z3_log != 0) {
#ifdef Z3_LOG_SYNC
#pragma omp critical (z3_log)
{
#endif
Z3_close_log_unsafe();
#ifdef Z3_LOG_SYNC
}
#endif
}
}
}

View file

@ -86,7 +86,7 @@ extern "C" {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
}
Z3_func_interp_ref * fi = alloc(Z3_func_interp_ref, to_model_ref(m));
Z3_func_interp_ref * fi = alloc(Z3_func_interp_ref, *mk_c(c), to_model_ref(m));
fi->m_func_interp = _fi;
mk_c(c)->save_object(fi);
RETURN_Z3(of_func_interp(fi));
@ -192,7 +192,7 @@ extern "C" {
RETURN_Z3(0);
}
ptr_vector<expr> const & universe = to_model_ref(m)->get_universe(to_sort(s));
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, mk_c(c)->m());
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(v);
unsigned sz = universe.size();
for (unsigned i = 0; i < sz; i++) {
@ -262,7 +262,7 @@ extern "C" {
SET_ERROR_CODE(Z3_IOB);
RETURN_Z3(0);
}
Z3_func_entry_ref * e = alloc(Z3_func_entry_ref, to_func_interp(f)->m_model.get());
Z3_func_entry_ref * e = alloc(Z3_func_entry_ref, *mk_c(c), to_func_interp(f)->m_model.get());
e->m_func_interp = to_func_interp_ref(f);
e->m_func_entry = to_func_interp_ref(f)->get_entry(i);
mk_c(c)->save_object(e);

View file

@ -23,7 +23,7 @@ Revision History:
struct Z3_model_ref : public api::object {
model_ref m_model;
Z3_model_ref() {}
Z3_model_ref(api::context& c): api::object(c) {}
virtual ~Z3_model_ref() {}
};
@ -34,7 +34,7 @@ inline model * to_model_ref(Z3_model s) { return to_model(s)->m_model.get(); }
struct Z3_func_interp_ref : public api::object {
model_ref m_model; // must have it to prevent reference to m_func_interp to be killed.
func_interp * m_func_interp;
Z3_func_interp_ref(model * m):m_model(m), m_func_interp(0) {}
Z3_func_interp_ref(api::context& c, model * m): api::object(c), m_model(m), m_func_interp(0) {}
virtual ~Z3_func_interp_ref() {}
};
@ -46,7 +46,7 @@ struct Z3_func_entry_ref : public api::object {
model_ref m_model; // must have it to prevent reference to m_func_entry to be killed.
func_interp * m_func_interp;
func_entry const * m_func_entry;
Z3_func_entry_ref(model * m):m_model(m), m_func_interp(0), m_func_entry(0) {}
Z3_func_entry_ref(api::context& c, model * m):api::object(c), m_model(m), m_func_interp(0), m_func_entry(0) {}
virtual ~Z3_func_entry_ref() {}
};

View file

@ -23,15 +23,17 @@ Revision History:
#include"api_util.h"
#include"api_model.h"
#include"opt_context.h"
#include"opt_cmds.h"
#include"cancel_eh.h"
#include"scoped_timer.h"
#include"smt2parser.h"
#include"api_ast_vector.h"
extern "C" {
struct Z3_optimize_ref : public api::object {
opt::context* m_opt;
Z3_optimize_ref():m_opt(0) {}
Z3_optimize_ref(api::context& c): api::object(c), m_opt(0) {}
virtual ~Z3_optimize_ref() { dealloc(m_opt); }
};
inline Z3_optimize_ref * to_optimize(Z3_optimize o) { return reinterpret_cast<Z3_optimize_ref *>(o); }
@ -42,7 +44,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_mk_optimize(c);
RESET_ERROR_CODE();
Z3_optimize_ref * o = alloc(Z3_optimize_ref);
Z3_optimize_ref * o = alloc(Z3_optimize_ref, *mk_c(c));
o->m_opt = alloc(opt::context,mk_c(c)->m());
mk_c(c)->save_object(o);
RETURN_Z3(of_optimize(o));
@ -158,7 +160,7 @@ extern "C" {
RESET_ERROR_CODE();
model_ref _m;
to_optimize_ptr(o)->get_model(_m);
Z3_model_ref * m_ref = alloc(Z3_model_ref);
Z3_model_ref * m_ref = alloc(Z3_model_ref, *mk_c(c));
if (_m) {
m_ref->m_model = _m;
}
@ -186,7 +188,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_optimize_get_param_descrs(c, o);
RESET_ERROR_CODE();
Z3_param_descrs_ref * d = alloc(Z3_param_descrs_ref);
Z3_param_descrs_ref * d = alloc(Z3_param_descrs_ref, *mk_c(c));
mk_c(c)->save_object(d);
to_optimize_ptr(o)->collect_param_descrs(d->m_descrs);
Z3_param_descrs r = of_param_descrs(d);
@ -240,7 +242,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_optimize_get_statistics(c, d);
RESET_ERROR_CODE();
Z3_stats_ref * st = alloc(Z3_stats_ref);
Z3_stats_ref * st = alloc(Z3_stats_ref, *mk_c(c));
to_optimize_ptr(d)->collect_statistics(st->m_stats);
mk_c(c)->save_object(st);
Z3_stats r = of_stats(st);
@ -248,6 +250,86 @@ extern "C" {
Z3_CATCH_RETURN(0);
}
static void Z3_optimize_from_stream(
Z3_context c,
Z3_optimize opt,
std::istream& s) {
ast_manager& m = mk_c(c)->m();
cmd_context ctx(false, &m);
install_opt_cmds(ctx, to_optimize_ptr(opt));
ctx.set_ignore_check(true);
if (!parse_smt2_commands(ctx, s)) {
SET_ERROR_CODE(Z3_PARSER_ERROR);
return;
}
ptr_vector<expr>::const_iterator it = ctx.begin_assertions();
ptr_vector<expr>::const_iterator end = ctx.end_assertions();
for (; it != end; ++it) {
to_optimize_ptr(opt)->add_hard_constraint(*it);
}
}
void Z3_API Z3_optimize_from_string(
Z3_context c,
Z3_optimize d,
Z3_string s) {
Z3_TRY;
//LOG_Z3_optimize_from_string(c, d, s);
std::string str(s);
std::istringstream is(str);
Z3_optimize_from_stream(c, d, is);
Z3_CATCH;
}
void Z3_API Z3_optimize_from_file(
Z3_context c,
Z3_optimize d,
Z3_string s) {
Z3_TRY;
//LOG_Z3_optimize_from_file(c, d, s);
std::ifstream is(s);
if (!is) {
std::ostringstream strm;
strm << "Could not open file " << s;
throw default_exception(strm.str());
SET_ERROR_CODE(Z3_PARSER_ERROR);
return;
}
Z3_optimize_from_stream(c, d, is);
Z3_CATCH;
}
Z3_ast_vector Z3_API Z3_optimize_get_assertions(Z3_context c, Z3_optimize o) {
Z3_TRY;
LOG_Z3_optimize_get_assertions(c, o);
RESET_ERROR_CODE();
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(v);
expr_ref_vector hard(mk_c(c)->m());
to_optimize_ptr(o)->get_hard_constraints(hard);
for (unsigned i = 0; i < hard.size(); i++) {
v->m_ast_vector.push_back(hard[i].get());
}
RETURN_Z3(of_ast_vector(v));
Z3_CATCH_RETURN(0);
}
Z3_ast_vector Z3_API Z3_optimize_get_objectives(Z3_context c, Z3_optimize o) {
Z3_TRY;
LOG_Z3_optimize_get_objectives(c, o);
RESET_ERROR_CODE();
unsigned n = to_optimize_ptr(o)->num_objectives();
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(v);
for (unsigned i = 0; i < n; i++) {
v->m_ast_vector.push_back(to_optimize_ptr(o)->get_objective(i));
}
RETURN_Z3(of_ast_vector(v));
Z3_CATCH_RETURN(0);
}
};

View file

@ -30,7 +30,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_mk_params(c);
RESET_ERROR_CODE();
Z3_params_ref * p = alloc(Z3_params_ref);
Z3_params_ref * p = alloc(Z3_params_ref, *mk_c(c));
mk_c(c)->save_object(p);
Z3_params r = of_params(p);
RETURN_Z3(r);

View file

@ -15,7 +15,6 @@ Author:
Revision History:
--*/
#include<iostream>
#include"z3.h"
#include"api_log_macros.h"
#include"api_context.h"
@ -23,8 +22,8 @@ Revision History:
#include"pb_decl_plugin.h"
extern "C" {
Z3_ast Z3_API Z3_mk_atmost(Z3_context c, unsigned num_args,
Z3_ast Z3_API Z3_mk_atmost(Z3_context c, unsigned num_args,
Z3_ast const args[], unsigned k) {
Z3_TRY;
LOG_Z3_mk_atmost(c, num_args, args, k);
@ -38,8 +37,21 @@ extern "C" {
Z3_CATCH_RETURN(0);
}
Z3_ast Z3_API Z3_mk_atleast(Z3_context c, unsigned num_args,
Z3_ast const args[], unsigned k) {
Z3_TRY;
LOG_Z3_mk_atmost(c, num_args, args, k);
RESET_ERROR_CODE();
parameter param(k);
pb_util util(mk_c(c)->m());
ast* a = util.mk_at_least_k(num_args, to_exprs(args), k);
mk_c(c)->save_ast_trail(a);
check_sorts(c, a);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
}
Z3_ast Z3_API Z3_mk_pble(Z3_context c, unsigned num_args,
Z3_ast Z3_API Z3_mk_pble(Z3_context c, unsigned num_args,
Z3_ast const args[], int _coeffs[],
int k) {
Z3_TRY;
@ -57,5 +69,41 @@ extern "C" {
Z3_CATCH_RETURN(0);
}
Z3_ast Z3_API Z3_mk_pbge(Z3_context c, unsigned num_args,
Z3_ast const args[], int _coeffs[],
int k) {
Z3_TRY;
LOG_Z3_mk_pble(c, num_args, args, _coeffs, k);
RESET_ERROR_CODE();
pb_util util(mk_c(c)->m());
vector<rational> coeffs;
for (unsigned i = 0; i < num_args; ++i) {
coeffs.push_back(rational(_coeffs[i]));
}
ast* a = util.mk_ge(num_args, coeffs.c_ptr(), to_exprs(args), rational(k));
mk_c(c)->save_ast_trail(a);
check_sorts(c, a);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
}
Z3_ast Z3_API Z3_mk_pbeq(Z3_context c, unsigned num_args,
Z3_ast const args[], int _coeffs[],
int k) {
Z3_TRY;
LOG_Z3_mk_pble(c, num_args, args, _coeffs, k);
RESET_ERROR_CODE();
pb_util util(mk_c(c)->m());
vector<rational> coeffs;
for (unsigned i = 0; i < num_args; ++i) {
coeffs.push_back(rational(_coeffs[i]));
}
ast* a = util.mk_eq(num_args, coeffs.c_ptr(), to_exprs(args), rational(k));
mk_c(c)->save_ast_trail(a);
check_sorts(c, a);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
}
};

View file

@ -14,9 +14,8 @@ Author:
Leonardo de Moura (leonardo) 2012-12-08
Notes:
--*/
#include<iostream>
#include"z3.h"
#include"api_log_macros.h"
#include"api_context.h"
@ -35,7 +34,7 @@ namespace api {
pmanager::~pmanager() {
}
};
extern "C" {
@ -53,7 +52,7 @@ extern "C" {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
}
Z3_ast_vector_ref* result = alloc(Z3_ast_vector_ref, mk_c(c)->m());
Z3_ast_vector_ref* result = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(result);
if (converter.is_var(to_expr(x))) {
expr2var const & mapping = converter.get_mapping();

View file

@ -15,7 +15,6 @@ Author:
Revision History:
--*/
#include<iostream>
#include"z3.h"
#include"api_log_macros.h"
#include"api_context.h"
@ -26,17 +25,17 @@ Revision History:
extern "C" {
Z3_ast Z3_API Z3_mk_quantifier(
Z3_context c,
Z3_bool is_forall,
unsigned weight,
unsigned num_patterns, Z3_pattern const patterns[],
unsigned num_decls, Z3_sort const sorts[],
Z3_symbol const decl_names[],
Z3_ast body)
Z3_context c,
Z3_bool is_forall,
unsigned weight,
unsigned num_patterns, Z3_pattern const patterns[],
unsigned num_decls, Z3_sort const sorts[],
Z3_symbol const decl_names[],
Z3_ast body)
{
return Z3_mk_quantifier_ex(
c,
is_forall,
c,
is_forall,
weight,
0,
0,
@ -50,15 +49,15 @@ extern "C" {
}
Z3_ast mk_quantifier_ex_core(
Z3_context c,
Z3_bool is_forall,
unsigned weight,
Z3_context c,
Z3_bool is_forall,
unsigned weight,
Z3_symbol quantifier_id,
Z3_symbol skolem_id,
unsigned num_patterns, Z3_pattern const patterns[],
unsigned num_no_patterns, Z3_ast const no_patterns[],
unsigned num_decls, Z3_sort const sorts[],
Z3_symbol const decl_names[],
unsigned num_patterns, Z3_pattern const patterns[],
unsigned num_no_patterns, Z3_ast const no_patterns[],
unsigned num_decls, Z3_sort const sorts[],
Z3_symbol const decl_names[],
Z3_ast body) {
Z3_TRY;
RESET_ERROR_CODE();
@ -86,9 +85,9 @@ extern "C" {
expr_ref result(mk_c(c)->m());
if (num_decls > 0) {
result = mk_c(c)->m().mk_quantifier(
(0 != is_forall),
names.size(), ts, names.c_ptr(), to_expr(body),
weight,
(0 != is_forall),
names.size(), ts, names.c_ptr(), to_expr(body),
weight,
to_symbol(quantifier_id),
to_symbol(skolem_id),
num_patterns, ps,
@ -104,44 +103,44 @@ extern "C" {
}
Z3_ast Z3_API Z3_mk_quantifier_ex(
Z3_context c,
Z3_bool is_forall,
unsigned weight,
Z3_context c,
Z3_bool is_forall,
unsigned weight,
Z3_symbol quantifier_id,
Z3_symbol skolem_id,
unsigned num_patterns, Z3_pattern const patterns[],
unsigned num_no_patterns, Z3_ast const no_patterns[],
unsigned num_decls, Z3_sort const sorts[],
Z3_symbol const decl_names[],
unsigned num_patterns, Z3_pattern const patterns[],
unsigned num_no_patterns, Z3_ast const no_patterns[],
unsigned num_decls, Z3_sort const sorts[],
Z3_symbol const decl_names[],
Z3_ast body)
{
LOG_Z3_mk_quantifier_ex(c, is_forall, weight, quantifier_id, skolem_id, num_patterns, patterns,
LOG_Z3_mk_quantifier_ex(c, is_forall, weight, quantifier_id, skolem_id, num_patterns, patterns,
num_no_patterns, no_patterns, num_decls, sorts, decl_names, body);
Z3_ast r = mk_quantifier_ex_core(c, is_forall, weight, quantifier_id, skolem_id, num_patterns, patterns,
Z3_ast r = mk_quantifier_ex_core(c, is_forall, weight, quantifier_id, skolem_id, num_patterns, patterns,
num_no_patterns, no_patterns, num_decls, sorts, decl_names, body);
RETURN_Z3(r);
}
Z3_ast Z3_API Z3_mk_forall(Z3_context c,
unsigned weight,
unsigned num_patterns, Z3_pattern const patterns[],
unsigned num_decls, Z3_sort const types[],
Z3_symbol const decl_names[],
Z3_ast Z3_API Z3_mk_forall(Z3_context c,
unsigned weight,
unsigned num_patterns, Z3_pattern const patterns[],
unsigned num_decls, Z3_sort const types[],
Z3_symbol const decl_names[],
Z3_ast body) {
return Z3_mk_quantifier(c, 1, weight, num_patterns, patterns, num_decls, types, decl_names, body);
}
Z3_ast Z3_API Z3_mk_exists(Z3_context c,
unsigned weight,
unsigned num_patterns, Z3_pattern const patterns[],
unsigned num_decls, Z3_sort const types[],
Z3_symbol const decl_names[],
Z3_ast Z3_API Z3_mk_exists(Z3_context c,
unsigned weight,
unsigned num_patterns, Z3_pattern const patterns[],
unsigned num_decls, Z3_sort const types[],
Z3_symbol const decl_names[],
Z3_ast body) {
return Z3_mk_quantifier(c, 0, weight, num_patterns, patterns, num_decls, types, decl_names, body);
}
Z3_ast Z3_API Z3_mk_quantifier_const_ex(Z3_context c,
Z3_ast Z3_API Z3_mk_quantifier_const_ex(Z3_context c,
Z3_bool is_forall,
unsigned weight,
Z3_symbol quantifier_id,
@ -166,7 +165,7 @@ extern "C" {
}
if (num_bound == 0) {
SET_ERROR_CODE(Z3_INVALID_USAGE);
RETURN_Z3(0);
RETURN_Z3(0);
}
for (unsigned i = 0; i < num_bound; ++i) {
app* a = to_app(bound[i]);
@ -191,7 +190,7 @@ extern "C" {
app* pat = to_pattern(patterns[i]);
SASSERT(mk_c(c)->m().is_pattern(pat));
expr_abstract(mk_c(c)->m(), 0, num_bound, bound_asts.c_ptr(), pat, result);
SASSERT(result.get()->get_kind() == AST_APP);
SASSERT(result.get()->get_kind() == AST_APP);
pinned.push_back(result.get());
SASSERT(mk_c(c)->m().is_pattern(result.get()));
_patterns.push_back(of_pattern(result.get()));
@ -205,25 +204,25 @@ extern "C" {
}
app* pat = to_app(to_expr(no_patterns[i]));
expr_abstract(mk_c(c)->m(), 0, num_bound, bound_asts.c_ptr(), pat, result);
SASSERT(result.get()->get_kind() == AST_APP);
SASSERT(result.get()->get_kind() == AST_APP);
pinned.push_back(result.get());
_no_patterns.push_back(of_ast(result.get()));
}
expr_ref abs_body(mk_c(c)->m());
expr_abstract(mk_c(c)->m(), 0, num_bound, bound_asts.c_ptr(), to_expr(body), abs_body);
Z3_ast result = mk_quantifier_ex_core(c, is_forall, weight,
Z3_ast result = mk_quantifier_ex_core(c, is_forall, weight,
quantifier_id,
skolem_id,
num_patterns, _patterns.c_ptr(),
num_patterns, _patterns.c_ptr(),
num_no_patterns, _no_patterns.c_ptr(),
names.size(), types.c_ptr(), names.c_ptr(),
names.size(), types.c_ptr(), names.c_ptr(),
of_ast(abs_body.get()));
RETURN_Z3(result);
Z3_CATCH_RETURN(0);
}
Z3_ast Z3_API Z3_mk_quantifier_const(Z3_context c,
Z3_ast Z3_API Z3_mk_quantifier_const(Z3_context c,
Z3_bool is_forall,
unsigned weight,
unsigned num_bound,
@ -231,14 +230,14 @@ extern "C" {
unsigned num_patterns,
Z3_pattern const patterns[],
Z3_ast body) {
return Z3_mk_quantifier_const_ex(c, is_forall, weight, 0, 0,
num_bound, bound,
return Z3_mk_quantifier_const_ex(c, is_forall, weight, 0, 0,
num_bound, bound,
num_patterns, patterns,
0, 0,
body);
}
Z3_ast Z3_API Z3_mk_forall_const(Z3_context c,
Z3_ast Z3_API Z3_mk_forall_const(Z3_context c,
unsigned weight,
unsigned num_bound,
Z3_app const bound[],
@ -248,7 +247,7 @@ extern "C" {
return Z3_mk_quantifier_const(c, true, weight, num_bound, bound, num_patterns, patterns, body);
}
Z3_ast Z3_API Z3_mk_exists_const(Z3_context c,
Z3_ast Z3_API Z3_mk_exists_const(Z3_context c,
unsigned weight,
unsigned num_bound,
Z3_app const bound[],
@ -257,7 +256,7 @@ extern "C" {
Z3_ast body) {
return Z3_mk_quantifier_const(c, false, weight, num_bound, bound, num_patterns, patterns, body);
}
Z3_pattern Z3_API Z3_mk_pattern(Z3_context c, unsigned num_patterns, Z3_ast const terms[]) {
Z3_TRY;
LOG_Z3_mk_pattern(c, num_patterns, terms);
@ -273,7 +272,7 @@ extern "C" {
RETURN_Z3(of_pattern(a));
Z3_CATCH_RETURN(0);
}
Z3_ast Z3_API Z3_mk_bound(Z3_context c, unsigned index, Z3_sort ty) {
Z3_TRY;
LOG_Z3_mk_bound(c, index, ty);
@ -436,7 +435,7 @@ extern "C" {
else {
SET_ERROR_CODE(Z3_SORT_ERROR);
return 0;
}
}
Z3_CATCH_RETURN(0);
}
@ -450,7 +449,7 @@ extern "C" {
}
else {
SET_ERROR_CODE(Z3_SORT_ERROR);
return 0;
return 0;
}
Z3_CATCH_RETURN(0);
}
@ -471,13 +470,13 @@ extern "C" {
Z3_CATCH_RETURN(0);
}
Z3_ast Z3_API Z3_pattern_to_ast(Z3_context c, Z3_pattern p) {
Z3_ast Z3_API Z3_pattern_to_ast(Z3_context c, Z3_pattern p) {
RESET_ERROR_CODE();
return (Z3_ast)(p);
}
return (Z3_ast)(p);
}
Z3_API char const * Z3_pattern_to_string(Z3_context c, Z3_pattern p) {
return Z3_ast_to_string(c, reinterpret_cast<Z3_ast>(p));
}
};

View file

@ -16,7 +16,6 @@ Author:
Revision History:
--*/
#include<iostream>
#include"z3.h"
#include"api_log_macros.h"
#include"api_context.h"
@ -28,7 +27,7 @@ extern "C" {
Z3_sort Z3_API Z3_mk_seq_sort(Z3_context c, Z3_sort domain) {
Z3_TRY;
LOG_Z3_mk_seq_sort(c, domain);
RESET_ERROR_CODE();
RESET_ERROR_CODE();
sort * ty = mk_c(c)->sutil().str.mk_seq(to_sort(domain));
mk_c(c)->save_ast_trail(ty);
RETURN_Z3(of_sort(ty));
@ -38,7 +37,7 @@ extern "C" {
Z3_sort Z3_API Z3_mk_re_sort(Z3_context c, Z3_sort domain) {
Z3_TRY;
LOG_Z3_mk_re_sort(c, domain);
RESET_ERROR_CODE();
RESET_ERROR_CODE();
sort * ty = mk_c(c)->sutil().re.mk_re(to_sort(domain));
mk_c(c)->save_ast_trail(ty);
RETURN_Z3(of_sort(ty));
@ -48,14 +47,14 @@ extern "C" {
Z3_ast Z3_API Z3_mk_string(Z3_context c, Z3_string str) {
Z3_TRY;
LOG_Z3_mk_string(c, str);
RESET_ERROR_CODE();
RESET_ERROR_CODE();
zstring s(str, zstring::ascii);
app* a = mk_c(c)->sutil().str.mk_string(s);
mk_c(c)->save_ast_trail(a);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
}
Z3_sort Z3_API Z3_mk_string_sort(Z3_context c) {
Z3_TRY;
LOG_Z3_mk_string_sort(c);
@ -71,8 +70,8 @@ extern "C" {
LOG_Z3_is_seq_sort(c, s);
RESET_ERROR_CODE();
bool result = mk_c(c)->sutil().is_seq(to_sort(s));
return result?Z3_TRUE:Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
return result?Z3_TRUE:Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
}
Z3_bool Z3_API Z3_is_re_sort(Z3_context c, Z3_sort s) {
@ -80,8 +79,8 @@ extern "C" {
LOG_Z3_is_re_sort(c, s);
RESET_ERROR_CODE();
bool result = mk_c(c)->sutil().is_re(to_sort(s));
return result?Z3_TRUE:Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
return result?Z3_TRUE:Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
}
Z3_bool Z3_API Z3_is_string_sort(Z3_context c, Z3_sort s) {
@ -89,8 +88,8 @@ extern "C" {
LOG_Z3_is_string_sort(c, s);
RESET_ERROR_CODE();
bool result = mk_c(c)->sutil().is_string(to_sort(s));
return result?Z3_TRUE:Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
return result?Z3_TRUE:Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
}
Z3_bool Z3_API Z3_is_string(Z3_context c, Z3_ast s) {
@ -98,7 +97,7 @@ extern "C" {
LOG_Z3_is_string(c, s);
RESET_ERROR_CODE();
bool result = mk_c(c)->sutil().str.is_string(to_expr(s));
return result?Z3_TRUE:Z3_FALSE;
return result?Z3_TRUE:Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
}
@ -116,16 +115,19 @@ extern "C" {
Z3_CATCH_RETURN("");
}
Z3_ast Z3_API Z3_mk_seq_empty(Z3_context c, Z3_sort seq) {
Z3_TRY;
LOG_Z3_mk_seq_empty(c, seq);
RESET_ERROR_CODE();
app* a = mk_c(c)->sutil().str.mk_empty(to_sort(seq));
mk_c(c)->save_ast_trail(a);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
#define MK_SORTED(NAME, FN ) \
Z3_ast Z3_API NAME(Z3_context c, Z3_sort s) { \
Z3_TRY; \
LOG_ ## NAME(c, s); \
RESET_ERROR_CODE(); \
app* a = FN(to_sort(s)); \
mk_c(c)->save_ast_trail(a); \
RETURN_Z3(of_ast(a)); \
Z3_CATCH_RETURN(0); \
}
MK_SORTED(Z3_mk_seq_empty, mk_c(c)->sutil().str.mk_empty);
MK_UNARY(Z3_mk_seq_unit, mk_c(c)->get_seq_fid(), OP_SEQ_UNIT, SKIP);
MK_NARY(Z3_mk_seq_concat, mk_c(c)->get_seq_fid(), OP_SEQ_CONCAT, SKIP);
MK_BINARY(Z3_mk_seq_prefix, mk_c(c)->get_seq_fid(), OP_SEQ_PREFIX, SKIP);
@ -139,12 +141,31 @@ extern "C" {
MK_UNARY(Z3_mk_seq_to_re, mk_c(c)->get_seq_fid(), OP_SEQ_TO_RE, SKIP);
MK_BINARY(Z3_mk_seq_in_re, mk_c(c)->get_seq_fid(), OP_SEQ_IN_RE, SKIP);
MK_UNARY(Z3_mk_int_to_str, mk_c(c)->get_seq_fid(), OP_STRING_ITOS, SKIP);
MK_UNARY(Z3_mk_str_to_int, mk_c(c)->get_seq_fid(), OP_STRING_STOI, SKIP);
Z3_ast Z3_API Z3_mk_re_loop(Z3_context c, Z3_ast r, unsigned lo, unsigned hi) {
Z3_TRY;
LOG_Z3_mk_re_loop(c, r, lo, hi);
RESET_ERROR_CODE();
app* a = hi == 0 ? mk_c(c)->sutil().re.mk_loop(to_expr(r), lo) : mk_c(c)->sutil().re.mk_loop(to_expr(r), lo, hi);
mk_c(c)->save_ast_trail(a);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
}
MK_UNARY(Z3_mk_re_plus, mk_c(c)->get_seq_fid(), OP_RE_PLUS, SKIP);
MK_UNARY(Z3_mk_re_star, mk_c(c)->get_seq_fid(), OP_RE_STAR, SKIP);
MK_UNARY(Z3_mk_re_option, mk_c(c)->get_seq_fid(), OP_RE_OPTION, SKIP);
MK_UNARY(Z3_mk_re_complement, mk_c(c)->get_seq_fid(), OP_RE_COMPLEMENT, SKIP);
MK_NARY(Z3_mk_re_union, mk_c(c)->get_seq_fid(), OP_RE_UNION, SKIP);
MK_NARY(Z3_mk_re_intersect, mk_c(c)->get_seq_fid(), OP_RE_INTERSECT, SKIP);
MK_NARY(Z3_mk_re_concat, mk_c(c)->get_seq_fid(), OP_RE_CONCAT, SKIP);
MK_BINARY(Z3_mk_re_range, mk_c(c)->get_seq_fid(), OP_RE_RANGE, SKIP);
MK_SORTED(Z3_mk_re_empty, mk_c(c)->sutil().re.mk_empty);
MK_SORTED(Z3_mk_re_full, mk_c(c)->sutil().re.mk_full);

View file

@ -32,6 +32,7 @@ Revision History:
#include"smt_strategic_solver.h"
#include"smt_solver.h"
#include"smt_implied_equalities.h"
#include"smt_logics.h"
extern "C" {
@ -58,7 +59,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_mk_simple_solver(c);
RESET_ERROR_CODE();
Z3_solver_ref * s = alloc(Z3_solver_ref, mk_smt_solver_factory());
Z3_solver_ref * s = alloc(Z3_solver_ref, *mk_c(c), mk_smt_solver_factory());
mk_c(c)->save_object(s);
Z3_solver r = of_solver(s);
RETURN_Z3(r);
@ -69,7 +70,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_mk_solver(c);
RESET_ERROR_CODE();
Z3_solver_ref * s = alloc(Z3_solver_ref, mk_smt_strategic_solver_factory());
Z3_solver_ref * s = alloc(Z3_solver_ref, *mk_c(c), mk_smt_strategic_solver_factory());
mk_c(c)->save_object(s);
Z3_solver r = of_solver(s);
RETURN_Z3(r);
@ -80,10 +81,18 @@ extern "C" {
Z3_TRY;
LOG_Z3_mk_solver_for_logic(c, logic);
RESET_ERROR_CODE();
Z3_solver_ref * s = alloc(Z3_solver_ref, mk_smt_strategic_solver_factory(to_symbol(logic)));
mk_c(c)->save_object(s);
Z3_solver r = of_solver(s);
RETURN_Z3(r);
if (!smt_logics::supported_logic(to_symbol(logic))) {
std::ostringstream strm;
strm << "logic '" << to_symbol(logic) << "' is not recognized";
throw default_exception(strm.str());
RETURN_Z3(0);
}
else {
Z3_solver_ref * s = alloc(Z3_solver_ref, *mk_c(c), mk_smt_strategic_solver_factory(to_symbol(logic)));
mk_c(c)->save_object(s);
Z3_solver r = of_solver(s);
RETURN_Z3(r);
}
Z3_CATCH_RETURN(0);
}
@ -91,7 +100,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_mk_solver_from_tactic(c, t);
RESET_ERROR_CODE();
Z3_solver_ref * s = alloc(Z3_solver_ref, mk_tactic2solver_factory(to_tactic_ref(t)));
Z3_solver_ref * s = alloc(Z3_solver_ref, *mk_c(c), mk_tactic2solver_factory(to_tactic_ref(t)));
mk_c(c)->save_object(s);
Z3_solver r = of_solver(s);
RETURN_Z3(r);
@ -103,7 +112,7 @@ extern "C" {
LOG_Z3_solver_translate(c, s, target);
RESET_ERROR_CODE();
params_ref const& p = to_solver(s)->m_params;
Z3_solver_ref * sr = alloc(Z3_solver_ref, 0);
Z3_solver_ref * sr = alloc(Z3_solver_ref, *mk_c(target), 0);
init_solver(c, s);
sr->m_solver = to_solver(s)->m_solver->translate(mk_c(target)->m(), p);
mk_c(target)->save_object(sr);
@ -134,7 +143,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_solver_get_param_descrs(c, s);
RESET_ERROR_CODE();
Z3_param_descrs_ref * d = alloc(Z3_param_descrs_ref);
Z3_param_descrs_ref * d = alloc(Z3_param_descrs_ref, *mk_c(c));
mk_c(c)->save_object(d);
bool initialized = to_solver(s)->m_solver.get() != 0;
if (!initialized)
@ -255,7 +264,7 @@ extern "C" {
LOG_Z3_solver_get_assertions(c, s);
RESET_ERROR_CODE();
init_solver(c, s);
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, mk_c(c)->m());
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(v);
unsigned sz = to_solver_ref(s)->get_num_assertions();
for (unsigned i = 0; i < sz; i++) {
@ -323,7 +332,7 @@ extern "C" {
SET_ERROR_CODE(Z3_INVALID_USAGE);
RETURN_Z3(0);
}
Z3_model_ref * m_ref = alloc(Z3_model_ref);
Z3_model_ref * m_ref = alloc(Z3_model_ref, *mk_c(c));
m_ref->m_model = _m;
mk_c(c)->save_object(m_ref);
RETURN_Z3(of_model(m_ref));
@ -352,7 +361,7 @@ extern "C" {
init_solver(c, s);
ptr_vector<expr> core;
to_solver_ref(s)->get_unsat_core(core);
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, mk_c(c)->m());
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(v);
for (unsigned i = 0; i < core.size(); i++) {
v->m_ast_vector.push_back(core[i]);
@ -375,7 +384,7 @@ extern "C" {
LOG_Z3_solver_get_statistics(c, s);
RESET_ERROR_CODE();
init_solver(c, s);
Z3_stats_ref * st = alloc(Z3_stats_ref);
Z3_stats_ref * st = alloc(Z3_stats_ref, *mk_c(c));
to_solver_ref(s)->collect_statistics(st->m_stats);
get_memory_statistics(st->m_stats);
get_rlimit_statistics(mk_c(c)->m().limit(), st->m_stats);
@ -413,4 +422,59 @@ extern "C" {
Z3_CATCH_RETURN(Z3_L_UNDEF);
}
Z3_lbool Z3_API Z3_solver_get_consequences(Z3_context c,
Z3_solver s,
Z3_ast_vector assumptions,
Z3_ast_vector variables,
Z3_ast_vector consequences) {
Z3_TRY;
LOG_Z3_solver_get_consequences(c, s, assumptions, variables, consequences);
ast_manager& m = mk_c(c)->m();
RESET_ERROR_CODE();
CHECK_SEARCHING(c);
init_solver(c, s);
expr_ref_vector _assumptions(m), _consequences(m), _variables(m);
ast_ref_vector const& __assumptions = to_ast_vector_ref(assumptions);
unsigned sz = __assumptions.size();
for (unsigned i = 0; i < sz; ++i) {
if (!is_expr(__assumptions[i])) {
SET_ERROR_CODE(Z3_INVALID_USAGE);
return Z3_L_UNDEF;
}
_assumptions.push_back(to_expr(__assumptions[i]));
}
ast_ref_vector const& __variables = to_ast_vector_ref(variables);
sz = __variables.size();
for (unsigned i = 0; i < sz; ++i) {
if (!is_expr(__variables[i])) {
SET_ERROR_CODE(Z3_INVALID_USAGE);
return Z3_L_UNDEF;
}
_variables.push_back(to_expr(__variables[i]));
}
lbool result = l_undef;
unsigned timeout = to_solver(s)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
unsigned rlimit = to_solver(s)->m_params.get_uint("rlimit", mk_c(c)->get_rlimit());
bool use_ctrl_c = to_solver(s)->m_params.get_bool("ctrl_c", false);
cancel_eh<reslimit> eh(mk_c(c)->m().limit());
api::context::set_interruptable si(*(mk_c(c)), eh);
{
scoped_ctrl_c ctrlc(eh, false, use_ctrl_c);
scoped_timer timer(timeout, &eh);
scoped_rlimit _rlimit(mk_c(c)->m().limit(), rlimit);
try {
result = to_solver_ref(s)->get_consequences(_assumptions, _variables, _consequences);
}
catch (z3_exception & ex) {
mk_c(c)->handle_exception(ex);
return Z3_L_UNDEF;
}
}
for (unsigned i = 0; i < _consequences.size(); ++i) {
to_ast_vector_ref(consequences).push_back(_consequences[i].get());
}
return static_cast<Z3_lbool>(result);
Z3_CATCH_RETURN(Z3_L_UNDEF);
}
};

View file

@ -26,7 +26,7 @@ struct Z3_solver_ref : public api::object {
ref<solver> m_solver;
params_ref m_params;
symbol m_logic;
Z3_solver_ref(solver_factory * f):m_solver_factory(f), m_solver(0), m_logic(symbol::null) {}
Z3_solver_ref(api::context& c, solver_factory * f): api::object(c), m_solver_factory(f), m_solver(0), m_logic(symbol::null) {}
virtual ~Z3_solver_ref() {}
};

View file

@ -23,6 +23,7 @@ Revision History:
struct Z3_stats_ref : public api::object {
statistics m_stats;
Z3_stats_ref(api::context& c): api::object(c) {}
virtual ~Z3_stats_ref() {}
};

View file

@ -25,13 +25,13 @@ Revision History:
#include"cancel_eh.h"
#include"scoped_timer.h"
Z3_apply_result_ref::Z3_apply_result_ref(ast_manager & m):m_core(m) {
Z3_apply_result_ref::Z3_apply_result_ref(api::context& c, ast_manager & m): api::object(c), m_core(m) {
}
extern "C" {
#define RETURN_TACTIC(_t_) { \
Z3_tactic_ref * _ref_ = alloc(Z3_tactic_ref); \
Z3_tactic_ref * _ref_ = alloc(Z3_tactic_ref, *mk_c(c)); \
_ref_->m_tactic = _t_; \
mk_c(c)->save_object(_ref_); \
Z3_tactic _result_ = of_tactic(_ref_); \
@ -39,7 +39,7 @@ extern "C" {
}
#define RETURN_PROBE(_t_) { \
Z3_probe_ref * _ref_ = alloc(Z3_probe_ref); \
Z3_probe_ref * _ref_ = alloc(Z3_probe_ref, *mk_c(c)); \
_ref_->m_probe = _t_; \
mk_c(c)->save_object(_ref_); \
Z3_probe _result_ = of_probe(_ref_); \
@ -367,7 +367,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_tactic_get_param_descrs(c, t);
RESET_ERROR_CODE();
Z3_param_descrs_ref * d = alloc(Z3_param_descrs_ref);
Z3_param_descrs_ref * d = alloc(Z3_param_descrs_ref, *mk_c(c));
mk_c(c)->save_object(d);
to_tactic_ref(t)->collect_param_descrs(d->m_descrs);
Z3_param_descrs r = of_param_descrs(d);
@ -404,7 +404,7 @@ extern "C" {
static Z3_apply_result _tactic_apply(Z3_context c, Z3_tactic t, Z3_goal g, params_ref p) {
goal_ref new_goal;
new_goal = alloc(goal, *to_goal_ref(g));
Z3_apply_result_ref * ref = alloc(Z3_apply_result_ref, mk_c(c)->m());
Z3_apply_result_ref * ref = alloc(Z3_apply_result_ref, (*mk_c(c)), mk_c(c)->m());
mk_c(c)->save_object(ref);
unsigned timeout = p.get_uint("timeout", UINT_MAX);
@ -505,7 +505,7 @@ extern "C" {
SET_ERROR_CODE(Z3_IOB);
RETURN_Z3(0);
}
Z3_goal_ref * g = alloc(Z3_goal_ref);
Z3_goal_ref * g = alloc(Z3_goal_ref, *mk_c(c));
g->m_goal = to_apply_result(r)->m_subgoals[i];
mk_c(c)->save_object(g);
Z3_goal result = of_goal(g);
@ -524,7 +524,7 @@ extern "C" {
model_ref new_m = to_model_ref(m)->copy();
if (to_apply_result(r)->m_mc)
to_apply_result(r)->m_mc->operator()(new_m, i);
Z3_model_ref * m_ref = alloc(Z3_model_ref);
Z3_model_ref * m_ref = alloc(Z3_model_ref, *mk_c(c));
m_ref->m_model = new_m;
mk_c(c)->save_object(m_ref);
RETURN_Z3(of_model(m_ref));

View file

@ -21,13 +21,20 @@ Revision History:
#include"api_goal.h"
#include"tactical.h"
namespace api {
class context;
}
struct Z3_tactic_ref : public api::object {
tactic_ref m_tactic;
Z3_tactic_ref(api::context& c): api::object(c) {}
virtual ~Z3_tactic_ref() {}
};
struct Z3_probe_ref : public api::object {
probe_ref m_probe;
Z3_probe_ref(api::context& c):api::object(c) {}
virtual ~Z3_probe_ref() {}
};
@ -44,7 +51,7 @@ struct Z3_apply_result_ref : public api::object {
model_converter_ref m_mc;
proof_converter_ref m_pc;
expr_dependency_ref m_core;
Z3_apply_result_ref(ast_manager & m);
Z3_apply_result_ref(api::context& c, ast_manager & m);
virtual ~Z3_apply_result_ref() {}
};

View file

@ -31,15 +31,20 @@ Revision History:
#define CHECK_REF_COUNT(a) (reinterpret_cast<ast const*>(a)->get_ref_count() > 0)
namespace api {
class context;
// Generic wrapper for ref-count objects exposed by the API
class object {
unsigned m_ref_count;
unsigned m_id;
context& m_context;
public:
object():m_ref_count(0) {}
object(context& c);
virtual ~object() {}
unsigned ref_count() const { return m_ref_count; }
void inc_ref() { m_ref_count++; }
void dec_ref() { SASSERT(m_ref_count > 0); m_ref_count--; if (m_ref_count == 0) dealloc(this); }
unsigned id() const { return m_id; }
void inc_ref();
void dec_ref();
};
};
@ -82,6 +87,7 @@ inline lbool to_lbool(Z3_lbool b) { return static_cast<lbool>(b); }
struct Z3_params_ref : public api::object {
params_ref m_params;
Z3_params_ref(api::context& c): api::object(c) {}
virtual ~Z3_params_ref() {}
};
@ -91,6 +97,7 @@ inline params_ref to_param_ref(Z3_params p) { return p == 0 ? params_ref() : to_
struct Z3_param_descrs_ref : public api::object {
param_descrs m_descrs;
Z3_param_descrs_ref(api::context& c): api::object(c) {}
virtual ~Z3_param_descrs_ref() {}
};

View file

@ -63,7 +63,6 @@ namespace z3 {
class func_entry;
class statistics;
class apply_result;
class fixedpoint;
template<typename T> class ast_vector_tpl;
typedef ast_vector_tpl<ast> ast_vector;
typedef ast_vector_tpl<expr> expr_vector;
@ -122,20 +121,30 @@ namespace z3 {
unsat, sat, unknown
};
inline check_result to_check_result(Z3_lbool l) {
if (l == Z3_L_TRUE) return sat;
else if (l == Z3_L_FALSE) return unsat;
return unknown;
}
/**
\brief A Context manages all other Z3 objects, global configuration options, etc.
*/
class context {
bool m_enable_exceptions;
Z3_context m_ctx;
static void error_handler(Z3_context c, Z3_error_code e) { /* do nothing */ }
static void error_handler(Z3_context /*c*/, Z3_error_code /*e*/) { /* do nothing */ }
void init(config & c) {
m_ctx = Z3_mk_context_rc(c);
m_enable_exceptions = true;
Z3_set_error_handler(m_ctx, error_handler);
Z3_set_ast_print_mode(m_ctx, Z3_PRINT_SMTLIB2_COMPLIANT);
}
void init_interp(config & c) {
m_ctx = Z3_mk_interpolation_context(c);
m_enable_exceptions = true;
Z3_set_error_handler(m_ctx, error_handler);
Z3_set_ast_print_mode(m_ctx, Z3_PRINT_SMTLIB2_COMPLIANT);
}
@ -146,19 +155,31 @@ namespace z3 {
struct interpolation {};
context() { config c; init(c); }
context(config & c) { init(c); }
context(config & c, interpolation) { init_interp(c); }
context(config & c, interpolation) { init_interp(c); }
~context() { Z3_del_context(m_ctx); }
operator Z3_context() const { return m_ctx; }
/**
\brief Auxiliary method used to check for API usage errors.
*/
void check_error() const {
Z3_error_code check_error() const {
Z3_error_code e = Z3_get_error_code(m_ctx);
if (e != Z3_OK)
if (e != Z3_OK && enable_exceptions())
throw exception(Z3_get_error_msg(m_ctx, e));
return e;
}
/**
\brief The C++ API uses by defaults exceptions on errors.
For applications that don't work well with exceptions (there should be only few)
you have the ability to turn off exceptions. The tradeoffs are that applications
have to very careful about using check_error() after calls that may result in an errornous
state.
*/
void set_enable_exceptions(bool f) { m_enable_exceptions = f; }
bool enable_exceptions() const { return m_enable_exceptions; }
/**
\brief Update global parameter \c param with string \c value.
*/
@ -279,6 +300,15 @@ namespace z3 {
expr num_val(int n, sort const & s);
/**
\brief parsing
*/
expr parse_string(char const* s);
expr parse_file(char const* file);
expr parse_string(char const* s, sort_vector const& sorts, func_decl_vector const& decls);
expr parse_file(char const* s, sort_vector const& sorts, func_decl_vector const& decls);
/**
\brief Interpolation support
*/
@ -315,7 +345,7 @@ namespace z3 {
object(context & c):m_ctx(&c) {}
object(object const & s):m_ctx(s.m_ctx) {}
context & ctx() const { return *m_ctx; }
void check_error() const { m_ctx->check_error(); }
Z3_error_code check_error() const { return m_ctx->check_error(); }
friend void check_context(object const & a, object const & b);
};
inline void check_context(object const & a, object const & b) { assert(a.m_ctx == b.m_ctx); }
@ -405,6 +435,8 @@ namespace z3 {
Z3_ast_kind kind() const { Z3_ast_kind r = Z3_get_ast_kind(ctx(), m_ast); check_error(); return r; }
unsigned hash() const { unsigned r = Z3_get_ast_hash(ctx(), m_ast); check_error(); return r; }
friend std::ostream & operator<<(std::ostream & out, ast const & n);
std::string to_string() const { return std::string(Z3_ast_to_string(ctx(), m_ast)); }
/**
\brief Return true if the ASTs are structurally identical.
@ -435,7 +467,10 @@ namespace z3 {
\brief Return the internal sort kind.
*/
Z3_sort_kind sort_kind() const { return Z3_get_sort_kind(*m_ctx, *this); }
/**
\brief Return name of sort.
*/
symbol name() const { Z3_symbol s = Z3_get_sort_name(ctx(), *this); check_error(); return symbol(ctx(), s); }
/**
\brief Return true if this sort is the Boolean sort.
*/
@ -654,12 +689,18 @@ namespace z3 {
/**
\brief Return int value of numeral, throw if result cannot fit in
machine int
It only makes sense to use this function if the caller can ensure that
the result is an integer or if exceptions are enabled.
If exceptions are disabled, then use the the is_numeral_i function.
\pre is_numeral()
*/
int get_numeral_int() const {
int result;
int result = 0;
if (!is_numeral_i(result)) {
assert(ctx().enable_exceptions());
if (!ctx().enable_exceptions()) return 0;
throw exception("numeral does not fit in machine int");
}
return result;
@ -668,13 +709,18 @@ namespace z3 {
/**
\brief Return uint value of numeral, throw if result cannot fit in
machine uint
It only makes sense to use this function if the caller can ensure that
the result is an integer or if exceptions are enabled.
If exceptions are disabled, then use the the is_numeral_u function.
\pre is_numeral()
*/
unsigned get_numeral_uint() const {
assert(is_numeral());
unsigned result;
unsigned result = 0;
if (!is_numeral_u(result)) {
assert(ctx().enable_exceptions());
if (!ctx().enable_exceptions()) return 0;
throw exception("numeral does not fit in machine uint");
}
return result;
@ -688,8 +734,10 @@ namespace z3 {
*/
__int64 get_numeral_int64() const {
assert(is_numeral());
__int64 result;
__int64 result = 0;
if (!is_numeral_i64(result)) {
assert(ctx().enable_exceptions());
if (!ctx().enable_exceptions()) return 0;
throw exception("numeral does not fit in machine __int64");
}
return result;
@ -703,13 +751,33 @@ namespace z3 {
*/
__uint64 get_numeral_uint64() const {
assert(is_numeral());
__uint64 result;
__uint64 result = 0;
if (!is_numeral_u64(result)) {
assert(ctx().enable_exceptions());
if (!ctx().enable_exceptions()) return 0;
throw exception("numeral does not fit in machine __uint64");
}
return result;
}
Z3_lbool bool_value() const {
return Z3_get_bool_value(ctx(), m_ast);
}
expr numerator() const {
assert(is_numeral());
Z3_ast r = Z3_get_numerator(ctx(), m_ast);
check_error();
return expr(ctx(),r);
}
expr denominator() const {
assert(is_numeral());
Z3_ast r = Z3_get_denominator(ctx(), m_ast);
check_error();
return expr(ctx(),r);
}
operator Z3_app() const { assert(is_app()); return reinterpret_cast<Z3_app>(m_ast); }
@ -802,6 +870,9 @@ namespace z3 {
friend expr implies(expr const & a, bool b);
friend expr implies(bool a, expr const & b);
friend expr mk_or(expr_vector const& args);
friend expr mk_and(expr_vector const& args);
friend expr ite(expr const & c, expr const & t, expr const & e);
friend expr distinct(expr_vector const& args);
@ -824,13 +895,23 @@ namespace z3 {
friend expr operator*(expr const & a, int b);
friend expr operator*(int a, expr const & b);
/**
\brief Power operator
*/
/* \brief Power operator */
friend expr pw(expr const & a, expr const & b);
friend expr pw(expr const & a, int b);
friend expr pw(int a, expr const & b);
/* \brief mod operator */
friend expr mod(expr const& a, expr const& b);
friend expr mod(expr const& a, int b);
friend expr mod(int a, expr const& b);
/* \brief rem operator */
friend expr rem(expr const& a, expr const& b);
friend expr rem(expr const& a, int b);
friend expr rem(int a, expr const& b);
friend expr is_int(expr const& e);
friend expr operator/(expr const & a, expr const & b);
friend expr operator/(expr const & a, int b);
friend expr operator/(int a, expr const & b);
@ -876,7 +957,7 @@ namespace z3 {
unsigned lo() const { assert (is_app() && Z3_get_decl_num_parameters(ctx(), decl()) == 2); return static_cast<unsigned>(Z3_get_decl_int_parameter(ctx(), decl(), 1)); }
unsigned hi() const { assert (is_app() && Z3_get_decl_num_parameters(ctx(), decl()) == 2); return static_cast<unsigned>(Z3_get_decl_int_parameter(ctx(), decl(), 0)); }
/**
/**
\brief sequence and regular expression operations.
+ is overloaeded as sequence concatenation and regular expression union.
concat is overloaded to handle sequences and regular expressions
@ -913,7 +994,31 @@ namespace z3 {
check_error();
return expr(ctx(), r);
}
expr stoi() const {
Z3_ast r = Z3_mk_str_to_int(ctx(), *this);
check_error();
return expr(ctx(), r);
}
expr itos() const {
Z3_ast r = Z3_mk_int_to_str(ctx(), *this);
check_error();
return expr(ctx(), r);
}
friend expr range(expr const& lo, expr const& hi);
/**
\brief create a looping regular expression.
*/
expr loop(unsigned lo) {
Z3_ast r = Z3_mk_re_loop(ctx(), m_ast, lo, 0);
check_error();
return expr(ctx(), r);
}
expr loop(unsigned lo, unsigned hi) {
Z3_ast r = Z3_mk_re_loop(ctx(), m_ast, lo, hi);
check_error();
return expr(ctx(), r);
}
/**
@ -937,33 +1042,46 @@ namespace z3 {
};
#define _Z3_MK_BIN_(a, b, binop) \
check_context(a, b); \
Z3_ast r = binop(a.ctx(), a, b); \
a.check_error(); \
return expr(a.ctx(), r); \
inline expr implies(expr const & a, expr const & b) {
check_context(a, b);
assert(a.is_bool() && b.is_bool());
Z3_ast r = Z3_mk_implies(a.ctx(), a, b);
a.check_error();
return expr(a.ctx(), r);
assert(a.is_bool() && b.is_bool());
_Z3_MK_BIN_(a, b, Z3_mk_implies);
}
inline expr implies(expr const & a, bool b) { return implies(a, a.ctx().bool_val(b)); }
inline expr implies(bool a, expr const & b) { return implies(b.ctx().bool_val(a), b); }
inline expr pw(expr const & a, expr const & b) {
assert(a.is_arith() && b.is_arith());
check_context(a, b);
Z3_ast r = Z3_mk_power(a.ctx(), a, b);
a.check_error();
return expr(a.ctx(), r);
}
inline expr pw(expr const & a, expr const & b) { _Z3_MK_BIN_(a, b, Z3_mk_power); }
inline expr pw(expr const & a, int b) { return pw(a, a.ctx().num_val(b, a.get_sort())); }
inline expr pw(int a, expr const & b) { return pw(b.ctx().num_val(a, b.get_sort()), b); }
inline expr mod(expr const& a, expr const& b) { _Z3_MK_BIN_(a, b, Z3_mk_mod); }
inline expr mod(expr const & a, int b) { return mod(a, a.ctx().num_val(b, a.get_sort())); }
inline expr mod(int a, expr const & b) { return mod(b.ctx().num_val(a, b.get_sort()), b); }
inline expr operator!(expr const & a) {
assert(a.is_bool());
Z3_ast r = Z3_mk_not(a.ctx(), a);
a.check_error();
return expr(a.ctx(), r);
}
inline expr rem(expr const& a, expr const& b) { _Z3_MK_BIN_(a, b, Z3_mk_rem); }
inline expr rem(expr const & a, int b) { return rem(a, a.ctx().num_val(b, a.get_sort())); }
inline expr rem(int a, expr const & b) { return rem(b.ctx().num_val(a, b.get_sort()), b); }
#undef _Z3_MK_BIN_
#define _Z3_MK_UN_(a, mkun) \
Z3_ast r = mkun(a.ctx(), a); \
a.check_error(); \
return expr(a.ctx(), r); \
inline expr operator!(expr const & a) { assert(a.is_bool()); _Z3_MK_UN_(a, Z3_mk_not); }
inline expr is_int(expr const& e) { _Z3_MK_UN_(e, Z3_mk_is_int); }
#undef _Z3_MK_UN_
inline expr operator&&(expr const & a, expr const & b) {
check_context(a, b);
@ -1205,7 +1323,6 @@ namespace z3 {
/**
\brief Create the if-then-else expression <tt>ite(c, t, e)</tt>
@ -1275,51 +1392,51 @@ namespace z3 {
inline expr udiv(expr const & a, int b) { return udiv(a, a.ctx().num_val(b, a.get_sort())); }
inline expr udiv(int a, expr const & b) { return udiv(b.ctx().num_val(a, b.get_sort()), b); }
/**
\brief signed reminder operator for bitvectors
*/
inline expr srem(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvsrem(a.ctx(), a, b)); }
inline expr srem(expr const & a, int b) { return srem(a, a.ctx().num_val(b, a.get_sort())); }
inline expr srem(int a, expr const & b) { return srem(b.ctx().num_val(a, b.get_sort()), b); }
/**
\brief unsigned reminder operator for bitvectors
*/
inline expr urem(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvurem(a.ctx(), a, b)); }
inline expr urem(expr const & a, int b) { return urem(a, a.ctx().num_val(b, a.get_sort())); }
inline expr urem(int a, expr const & b) { return urem(b.ctx().num_val(a, b.get_sort()), b); }
/**
\brief shift left operator for bitvectors
*/
inline expr shl(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvshl(a.ctx(), a, b)); }
inline expr shl(expr const & a, int b) { return shl(a, a.ctx().num_val(b, a.get_sort())); }
inline expr shl(int a, expr const & b) { return shl(b.ctx().num_val(a, b.get_sort()), b); }
/**
\brief logic shift right operator for bitvectors
*/
inline expr lshr(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvlshr(a.ctx(), a, b)); }
inline expr lshr(expr const & a, int b) { return lshr(a, a.ctx().num_val(b, a.get_sort())); }
inline expr lshr(int a, expr const & b) { return lshr(b.ctx().num_val(a, b.get_sort()), b); }
/**
\brief arithmetic shift right operator for bitvectors
*/
inline expr ashr(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvashr(a.ctx(), a, b)); }
inline expr ashr(expr const & a, int b) { return ashr(a, a.ctx().num_val(b, a.get_sort())); }
inline expr ashr(int a, expr const & b) { return ashr(b.ctx().num_val(a, b.get_sort()), b); }
/**
\brief Extend the given bit-vector with zeros to the (unsigned) equivalent bitvector of size m+i, where m is the size of the given bit-vector.
*/
inline expr zext(expr const & a, unsigned i) { return to_expr(a.ctx(), Z3_mk_zero_ext(a.ctx(), i, a)); }
/**
\brief Sign-extend of the given bit-vector to the (signed) equivalent bitvector of size m+i, where m is the size of the given bit-vector.
*/
inline expr sext(expr const & a, unsigned i) { return to_expr(a.ctx(), Z3_mk_sign_ext(a.ctx(), i, a)); }
/**
\brief signed reminder operator for bitvectors
*/
inline expr srem(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvsrem(a.ctx(), a, b)); }
inline expr srem(expr const & a, int b) { return srem(a, a.ctx().num_val(b, a.get_sort())); }
inline expr srem(int a, expr const & b) { return srem(b.ctx().num_val(a, b.get_sort()), b); }
/**
\brief unsigned reminder operator for bitvectors
*/
inline expr urem(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvurem(a.ctx(), a, b)); }
inline expr urem(expr const & a, int b) { return urem(a, a.ctx().num_val(b, a.get_sort())); }
inline expr urem(int a, expr const & b) { return urem(b.ctx().num_val(a, b.get_sort()), b); }
/**
\brief shift left operator for bitvectors
*/
inline expr shl(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvshl(a.ctx(), a, b)); }
inline expr shl(expr const & a, int b) { return shl(a, a.ctx().num_val(b, a.get_sort())); }
inline expr shl(int a, expr const & b) { return shl(b.ctx().num_val(a, b.get_sort()), b); }
/**
\brief logic shift right operator for bitvectors
*/
inline expr lshr(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvlshr(a.ctx(), a, b)); }
inline expr lshr(expr const & a, int b) { return lshr(a, a.ctx().num_val(b, a.get_sort())); }
inline expr lshr(int a, expr const & b) { return lshr(b.ctx().num_val(a, b.get_sort()), b); }
/**
\brief arithmetic shift right operator for bitvectors
*/
inline expr ashr(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvashr(a.ctx(), a, b)); }
inline expr ashr(expr const & a, int b) { return ashr(a, a.ctx().num_val(b, a.get_sort())); }
inline expr ashr(int a, expr const & b) { return ashr(b.ctx().num_val(a, b.get_sort()), b); }
/**
\brief Extend the given bit-vector with zeros to the (unsigned) equivalent bitvector of size m+i, where m is the size of the given bit-vector.
*/
inline expr zext(expr const & a, unsigned i) { return to_expr(a.ctx(), Z3_mk_zero_ext(a.ctx(), i, a)); }
/**
\brief Sign-extend of the given bit-vector to the (signed) equivalent bitvector of size m+i, where m is the size of the given bit-vector.
*/
inline expr sext(expr const & a, unsigned i) { return to_expr(a.ctx(), Z3_mk_sign_ext(a.ctx(), i, a)); }
template<typename T> class cast_ast;
template<> class cast_ast<ast> {
@ -1497,6 +1614,20 @@ namespace z3 {
return expr(ctx, r);
}
inline expr mk_or(expr_vector const& args) {
array<Z3_ast> _args(args);
Z3_ast r = Z3_mk_or(args.ctx(), _args.size(), _args.ptr());
args.check_error();
return expr(args.ctx(), r);
}
inline expr mk_and(expr_vector const& args) {
array<Z3_ast> _args(args);
Z3_ast r = Z3_mk_and(args.ctx(), _args.size(), _args.ptr());
args.check_error();
return expr(args.ctx(), r);
}
class func_entry : public object {
Z3_func_entry m_entry;
void init(Z3_func_entry e) {
@ -1567,7 +1698,7 @@ namespace z3 {
Z3_ast r = 0;
Z3_bool status = Z3_model_eval(ctx(), m_model, n, model_completion, &r);
check_error();
if (status == Z3_FALSE)
if (status == Z3_FALSE && ctx().enable_exceptions())
throw exception("failed to evaluate expression");
return expr(ctx(), r);
}
@ -1578,9 +1709,9 @@ namespace z3 {
func_decl get_func_decl(unsigned i) const { Z3_func_decl r = Z3_model_get_func_decl(ctx(), m_model, i); check_error(); return func_decl(ctx(), r); }
unsigned size() const { return num_consts() + num_funcs(); }
func_decl operator[](int i) const {
assert(0 <= i);
return static_cast<unsigned>(i) < num_consts() ? get_const_decl(i) : get_func_decl(i - num_consts());
}
assert(0 <= i);
return static_cast<unsigned>(i) < num_consts() ? get_const_decl(i) : get_func_decl(i - num_consts());
}
// returns interpretation of constant declaration c.
// If c is not assigned any value in the model it returns
@ -1597,6 +1728,13 @@ namespace z3 {
check_error();
return func_interp(ctx(), r);
}
// returns true iff the model contains an interpretation
// for function f.
bool has_interp(func_decl f) const {
check_context(*this, f);
return 0 != Z3_model_has_interp(ctx(), m_model, f);
}
friend std::ostream & operator<<(std::ostream & out, model const & m);
};
@ -1639,11 +1777,6 @@ namespace z3 {
return out;
}
inline check_result to_check_result(Z3_lbool l) {
if (l == Z3_L_TRUE) return sat;
else if (l == Z3_L_FALSE) return unsat;
return unknown;
}
class solver : public object {
Z3_solver m_solver;
@ -1705,6 +1838,11 @@ namespace z3 {
return to_check_result(r);
}
model get_model() const { Z3_model m = Z3_solver_get_model(ctx(), m_solver); check_error(); return model(ctx(), m); }
check_result consequences(expr_vector& assumptions, expr_vector& vars, expr_vector& conseq) {
Z3_lbool r = Z3_solver_get_consequences(ctx(), m_solver, assumptions, vars, conseq);
check_error();
return to_check_result(r);
}
std::string reason_unknown() const { Z3_string r = Z3_solver_get_reason_unknown(ctx(), m_solver); check_error(); return r; }
stats statistics() const { Z3_stats r = Z3_solver_get_statistics(ctx(), m_solver); check_error(); return stats(ctx(), r); }
expr_vector unsat_core() const { Z3_ast_vector r = Z3_solver_get_unsat_core(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
@ -1731,6 +1869,7 @@ namespace z3 {
fmls,
fml));
}
param_descrs get_param_descrs() { return param_descrs(ctx(), Z3_solver_get_param_descrs(ctx(), m_solver)); }
};
@ -1847,6 +1986,8 @@ namespace z3 {
friend tactic repeat(tactic const & t, unsigned max);
friend tactic with(tactic const & t, params const & p);
friend tactic try_for(tactic const & t, unsigned ms);
friend tactic par_or(unsigned n, tactic const* tactics);
friend tactic par_and_then(tactic const& t1, tactic const& t2);
param_descrs get_param_descrs() { return param_descrs(ctx(), Z3_tactic_get_param_descrs(ctx(), m_tactic)); }
};
@ -1880,7 +2021,21 @@ namespace z3 {
t.check_error();
return tactic(t.ctx(), r);
}
inline tactic par_or(unsigned n, tactic const* tactics) {
if (n == 0) {
throw exception("a non-zero number of tactics need to be passed to par_or");
}
array<Z3_tactic> buffer(n);
for (unsigned i = 0; i < n; ++i) buffer[i] = tactics[i];
return tactic(tactics[0].ctx(), Z3_tactic_par_or(tactics[0].ctx(), n, buffer.ptr()));
}
inline tactic par_and_then(tactic const & t1, tactic const & t2) {
check_context(t1, t2);
Z3_tactic r = Z3_tactic_par_and_then(t1.ctx(), t1, t2);
t1.check_error();
return tactic(t1.ctx(), r);
}
class probe : public object {
Z3_probe m_probe;
@ -2010,8 +2165,12 @@ namespace z3 {
check_error();
return expr(ctx(), r);
}
expr_vector assertions() const { Z3_ast_vector r = Z3_optimize_get_assertions(ctx(), m_opt); check_error(); return expr_vector(ctx(), r); }
expr_vector objectives() const { Z3_ast_vector r = Z3_optimize_get_objectives(ctx(), m_opt); check_error(); return expr_vector(ctx(), r); }
stats statistics() const { Z3_stats r = Z3_optimize_get_statistics(ctx(), m_opt); check_error(); return stats(ctx(), r); }
friend std::ostream & operator<<(std::ostream & out, optimize const & s);
void from_file(char const* filename) { Z3_optimize_from_file(ctx(), m_opt, filename); check_error(); }
void from_string(char const* constraints) { Z3_optimize_from_string(ctx(), m_opt, constraints); check_error(); }
std::string help() const { char const * r = Z3_optimize_get_help(ctx(), m_opt); check_error(); return r; }
};
inline std::ostream & operator<<(std::ostream & out, optimize const & s) { out << Z3_optimize_to_string(s.ctx(), s.m_opt); return out; }
@ -2297,11 +2456,68 @@ namespace z3 {
inline expr store(expr const & a, int i, int v) {
return store(a, a.ctx().num_val(i, a.get_sort().array_domain()), a.ctx().num_val(v, a.get_sort().array_range()));
}
#define MK_EXPR1(_fn, _arg) \
Z3_ast r = _fn(_arg.ctx(), _arg); \
_arg.check_error(); \
return expr(_arg.ctx(), r);
#define MK_EXPR2(_fn, _arg1, _arg2) \
check_context(_arg1, _arg2); \
Z3_ast r = _fn(_arg1.ctx(), _arg1, _arg2); \
_arg1.check_error(); \
return expr(_arg1.ctx(), r);
inline expr const_array(sort const & d, expr const & v) {
check_context(d, v);
Z3_ast r = Z3_mk_const_array(d.ctx(), d, v);
d.check_error();
return expr(d.ctx(), r);
MK_EXPR2(Z3_mk_const_array, d, v);
}
inline expr empty_set(sort const& s) {
MK_EXPR1(Z3_mk_empty_set, s);
}
inline expr full_set(sort const& s) {
MK_EXPR1(Z3_mk_full_set, s);
}
inline expr set_add(expr const& s, expr const& e) {
MK_EXPR2(Z3_mk_set_add, s, e);
}
inline expr set_del(expr const& s, expr const& e) {
MK_EXPR2(Z3_mk_set_del, s, e);
}
inline expr set_union(expr const& a, expr const& b) {
check_context(a, b);
Z3_ast es[2] = { a, b };
Z3_ast r = Z3_mk_set_union(a.ctx(), 2, es);
a.check_error();
return expr(a.ctx(), r);
}
inline expr set_intersect(expr const& a, expr const& b) {
check_context(a, b);
Z3_ast es[2] = { a, b };
Z3_ast r = Z3_mk_set_intersect(a.ctx(), 2, es);
a.check_error();
return expr(a.ctx(), r);
}
inline expr set_difference(expr const& a, expr const& b) {
MK_EXPR2(Z3_mk_set_difference, a, b);
}
inline expr set_complement(expr const& a) {
MK_EXPR1(Z3_mk_set_complement, a);
}
inline expr set_member(expr const& s, expr const& e) {
MK_EXPR2(Z3_mk_set_member, s, e);
}
inline expr set_subset(expr const& a, expr const& b) {
MK_EXPR2(Z3_mk_set_subset, a, b);
}
// sequence and regular expression operations.
@ -2332,37 +2548,101 @@ namespace z3 {
return expr(s.ctx(), r);
}
inline expr to_re(expr const& s) {
Z3_ast r = Z3_mk_seq_to_re(s.ctx(), s);
s.check_error();
return expr(s.ctx(), r);
MK_EXPR1(Z3_mk_seq_to_re, s);
}
inline expr in_re(expr const& s, expr const& re) {
check_context(s, re);
Z3_ast r = Z3_mk_seq_in_re(s.ctx(), s, re);
MK_EXPR2(Z3_mk_seq_in_re, s, re);
}
inline expr plus(expr const& re) {
MK_EXPR1(Z3_mk_re_plus, re);
}
inline expr option(expr const& re) {
MK_EXPR1(Z3_mk_re_option, re);
}
inline expr star(expr const& re) {
MK_EXPR1(Z3_mk_re_star, re);
}
inline expr re_empty(sort const& s) {
Z3_ast r = Z3_mk_re_empty(s.ctx(), s);
s.check_error();
return expr(s.ctx(), r);
}
inline expr plus(expr const& re) {
Z3_ast r = Z3_mk_re_plus(re.ctx(), re);
re.check_error();
return expr(re.ctx(), r);
inline expr re_full(sort const& s) {
Z3_ast r = Z3_mk_re_full(s.ctx(), s);
s.check_error();
return expr(s.ctx(), r);
}
inline expr option(expr const& re) {
Z3_ast r = Z3_mk_re_option(re.ctx(), re);
re.check_error();
return expr(re.ctx(), r);
inline expr re_intersect(expr_vector const& args) {
assert(args.size() > 0);
context& ctx = args[0].ctx();
array<Z3_ast> _args(args);
Z3_ast r = Z3_mk_re_intersect(ctx, _args.size(), _args.ptr());
ctx.check_error();
return expr(ctx, r);
}
inline expr star(expr const& re) {
Z3_ast r = Z3_mk_re_star(re.ctx(), re);
re.check_error();
return expr(re.ctx(), r);
inline expr re_complement(expr const& a) {
MK_EXPR1(Z3_mk_re_complement, a);
}
inline expr range(expr const& lo, expr const& hi) {
check_context(lo, hi);
Z3_ast r = Z3_mk_re_range(lo.ctx(), lo, hi);
lo.check_error();
return expr(lo.ctx(), r);
}
inline expr interpolant(expr const& a) {
return expr(a.ctx(), Z3_mk_interpolant(a.ctx(), a));
}
inline expr context::parse_string(char const* s) {
Z3_ast r = Z3_parse_smtlib2_string(*this, s, 0, 0, 0, 0, 0, 0);
check_error();
return expr(*this, r);
}
inline expr context::parse_file(char const* s) {
Z3_ast r = Z3_parse_smtlib2_file(*this, s, 0, 0, 0, 0, 0, 0);
check_error();
return expr(*this, r);
}
inline expr context::parse_string(char const* s, sort_vector const& sorts, func_decl_vector const& decls) {
array<Z3_symbol> sort_names(sorts.size());
array<Z3_symbol> decl_names(decls.size());
array<Z3_sort> sorts1(sorts);
array<Z3_func_decl> decls1(decls);
for (unsigned i = 0; i < sorts.size(); ++i) {
sort_names[i] = sorts[i].name();
}
for (unsigned i = 0; i < decls.size(); ++i) {
decl_names[i] = decls[i].name();
}
Z3_ast r = Z3_parse_smtlib2_string(*this, s, sorts.size(), sort_names.ptr(), sorts1.ptr(), decls.size(), decl_names.ptr(), decls1.ptr());
check_error();
return expr(*this, r);
}
inline expr context::parse_file(char const* s, sort_vector const& sorts, func_decl_vector const& decls) {
array<Z3_symbol> sort_names(sorts.size());
array<Z3_symbol> decl_names(decls.size());
array<Z3_sort> sorts1(sorts);
array<Z3_func_decl> decls1(decls);
for (unsigned i = 0; i < sorts.size(); ++i) {
sort_names[i] = sorts[i].name();
}
for (unsigned i = 0; i < decls.size(); ++i) {
decl_names[i] = decls[i].name();
}
Z3_ast r = Z3_parse_smtlib2_file(*this, s, sorts.size(), sort_names.ptr(), sorts1.ptr(), decls.size(), decl_names.ptr(), decls1.ptr());
check_error();
return expr(*this, r);
}
inline check_result context::compute_interpolant(expr const& pat, params const& p, expr_vector& i, model& m) {
Z3_ast_vector interp = 0;
Z3_model mdl = 0;

View file

@ -286,8 +286,8 @@ namespace Microsoft.Z3
Contract.Ensures(Contract.Result<TupleSort>() != null);
CheckContextMatch(name);
CheckContextMatch(fieldNames);
CheckContextMatch(fieldSorts);
CheckContextMatch<Symbol>(fieldNames);
CheckContextMatch<Sort>(fieldSorts);
return new TupleSort(this, name, (uint)fieldNames.Length, fieldNames, fieldSorts);
}
@ -303,7 +303,7 @@ namespace Microsoft.Z3
Contract.Ensures(Contract.Result<EnumSort>() != null);
CheckContextMatch(name);
CheckContextMatch(enumNames);
CheckContextMatch<Symbol>(enumNames);
return new EnumSort(this, name, enumNames);
}
@ -423,7 +423,7 @@ namespace Microsoft.Z3
Contract.Ensures(Contract.Result<DatatypeSort>() != null);
CheckContextMatch(name);
CheckContextMatch(constructors);
CheckContextMatch<Constructor>(constructors);
return new DatatypeSort(this, name, constructors);
}
@ -436,7 +436,7 @@ namespace Microsoft.Z3
Contract.Requires(Contract.ForAll(constructors, c => c != null));
Contract.Ensures(Contract.Result<DatatypeSort>() != null);
CheckContextMatch(constructors);
CheckContextMatch<Constructor>(constructors);
return new DatatypeSort(this, MkSymbol(name), constructors);
}
@ -454,7 +454,7 @@ namespace Microsoft.Z3
Contract.Requires(Contract.ForAll(names, name => name != null));
Contract.Ensures(Contract.Result<DatatypeSort[]>() != null);
CheckContextMatch(names);
CheckContextMatch<Symbol>(names);
uint n = (uint)names.Length;
ConstructorList[] cla = new ConstructorList[n];
IntPtr[] n_constr = new IntPtr[n];
@ -462,7 +462,7 @@ namespace Microsoft.Z3
{
Constructor[] constructor = c[i];
Contract.Assume(Contract.ForAll(constructor, arr => arr != null), "Clousot does not support yet quantified formula on multidimensional arrays");
CheckContextMatch(constructor);
CheckContextMatch<Constructor>(constructor);
cla[i] = new ConstructorList(this, constructor);
n_constr[i] = cla[i].NativeObject;
}
@ -520,7 +520,7 @@ namespace Microsoft.Z3
Contract.Ensures(Contract.Result<FuncDecl>() != null);
CheckContextMatch(name);
CheckContextMatch(domain);
CheckContextMatch<Sort>(domain);
CheckContextMatch(range);
return new FuncDecl(this, name, domain, range);
}
@ -551,7 +551,7 @@ namespace Microsoft.Z3
Contract.Requires(Contract.ForAll(domain, d => d != null));
Contract.Ensures(Contract.Result<FuncDecl>() != null);
CheckContextMatch(domain);
CheckContextMatch<Sort>(domain);
CheckContextMatch(range);
return new FuncDecl(this, MkSymbol(name), domain, range);
}
@ -582,7 +582,7 @@ namespace Microsoft.Z3
Contract.Requires(Contract.ForAll(domain, d => d != null));
Contract.Ensures(Contract.Result<FuncDecl>() != null);
CheckContextMatch(domain);
CheckContextMatch<Sort>(domain);
CheckContextMatch(range);
return new FuncDecl(this, prefix, domain, range);
}
@ -811,7 +811,7 @@ namespace Microsoft.Z3
Contract.Ensures(Contract.Result<Expr>() != null);
CheckContextMatch(f);
CheckContextMatch(args);
CheckContextMatch<Expr>(args);
return Expr.Create(this, f, args);
}
@ -884,7 +884,7 @@ namespace Microsoft.Z3
Contract.Ensures(Contract.Result<BoolExpr>() != null);
CheckContextMatch(args);
CheckContextMatch<Expr>(args);
return new BoolExpr(this, Native.Z3_mk_distinct(nCtx, (uint)args.Length, AST.ArrayToNative(args)));
}
@ -970,7 +970,7 @@ namespace Microsoft.Z3
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result<BoolExpr>() != null);
CheckContextMatch(t);
CheckContextMatch<BoolExpr>(t);
return new BoolExpr(this, Native.Z3_mk_and(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
}
@ -982,7 +982,7 @@ namespace Microsoft.Z3
Contract.Requires(t != null);
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result<BoolExpr>() != null);
CheckContextMatch(t);
CheckContextMatch<BoolExpr>(t);
return new BoolExpr(this, Native.Z3_mk_and(nCtx, (uint)t.Count(), AST.EnumToNative(t)));
}
@ -995,7 +995,7 @@ namespace Microsoft.Z3
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result<BoolExpr>() != null);
CheckContextMatch(t);
CheckContextMatch<BoolExpr>(t);
return new BoolExpr(this, Native.Z3_mk_or(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
}
@ -1025,7 +1025,7 @@ namespace Microsoft.Z3
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result<ArithExpr>() != null);
CheckContextMatch(t);
CheckContextMatch<ArithExpr>(t);
return (ArithExpr)Expr.Create(this, Native.Z3_mk_add(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
}
@ -1051,10 +1051,23 @@ namespace Microsoft.Z3
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result<ArithExpr>() != null);
CheckContextMatch(t);
CheckContextMatch<ArithExpr>(t);
return (ArithExpr)Expr.Create(this, Native.Z3_mk_mul(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
}
/// <summary>
/// Create an expression representing <c>t[0] * t[1] * ...</c>.
/// </summary>
public ArithExpr MkMul(IEnumerable<ArithExpr> t)
{
Contract.Requires(t != null);
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result<ArithExpr>() != null);
CheckContextMatch<ArithExpr>(t);
return (ArithExpr)Expr.Create(this, Native.Z3_mk_mul(nCtx, (uint)t.Count(), AST.EnumToNative(t)));
}
/// <summary>
/// Create an expression representing <c>t[0] - t[1] - ...</c>.
/// </summary>
@ -1064,7 +1077,7 @@ namespace Microsoft.Z3
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result<ArithExpr>() != null);
CheckContextMatch(t);
CheckContextMatch<ArithExpr>(t);
return (ArithExpr)Expr.Create(this, Native.Z3_mk_sub(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
}
@ -2192,7 +2205,7 @@ namespace Microsoft.Z3
Contract.Ensures(Contract.Result<ArrayExpr>() != null);
CheckContextMatch(f);
CheckContextMatch(args);
CheckContextMatch<ArrayExpr>(args);
return (ArrayExpr)Expr.Create(this, Native.Z3_mk_map(nCtx, f.NativeObject, AST.ArrayLength(args), AST.ArrayToNative(args)));
}
@ -2302,7 +2315,7 @@ namespace Microsoft.Z3
Contract.Requires(args != null);
Contract.Requires(Contract.ForAll(args, a => a != null));
CheckContextMatch(args);
CheckContextMatch<ArrayExpr>(args);
return (ArrayExpr)Expr.Create(this, Native.Z3_mk_set_union(nCtx, (uint)args.Length, AST.ArrayToNative(args)));
}
@ -2315,7 +2328,7 @@ namespace Microsoft.Z3
Contract.Requires(Contract.ForAll(args, a => a != null));
Contract.Ensures(Contract.Result<Expr>() != null);
CheckContextMatch(args);
CheckContextMatch<ArrayExpr>(args);
return (ArrayExpr)Expr.Create(this, Native.Z3_mk_set_intersect(nCtx, (uint)args.Length, AST.ArrayToNative(args)));
}
@ -2407,6 +2420,29 @@ namespace Microsoft.Z3
return new SeqExpr(this, Native.Z3_mk_string(nCtx, s));
}
/// <summary>
/// Convert an integer expression to a string.
/// </summary>
public SeqExpr IntToString(Expr e)
{
Contract.Requires(e != null);
Contract.Requires(e is ArithExpr);
Contract.Ensures(Contract.Result<SeqExpr>() != null);
return new SeqExpr(this, Native.Z3_mk_int_to_str(nCtx, e.NativeObject));
}
/// <summary>
/// Convert an integer expression to a string.
/// </summary>
public IntExpr StringToInt(Expr e)
{
Contract.Requires(e != null);
Contract.Requires(e is SeqExpr);
Contract.Ensures(Contract.Result<IntExpr>() != null);
return new IntExpr(this, Native.Z3_mk_str_to_int(nCtx, e.NativeObject));
}
/// <summary>
/// Concatentate sequences.
/// </summary>
@ -2416,7 +2452,7 @@ namespace Microsoft.Z3
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result<SeqExpr>() != null);
CheckContextMatch(t);
CheckContextMatch<SeqExpr>(t);
return new SeqExpr(this, Native.Z3_mk_seq_concat(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
}
@ -2551,10 +2587,20 @@ namespace Microsoft.Z3
return new ReExpr(this, Native.Z3_mk_re_star(nCtx, re.NativeObject));
}
/// <summary>
/// Take the bounded Kleene star of a regular expression.
/// </summary>
public ReExpr MkLoop(ReExpr re, uint lo, uint hi = 0)
{
Contract.Requires(re != null);
Contract.Ensures(Contract.Result<ReExpr>() != null);
return new ReExpr(this, Native.Z3_mk_re_loop(nCtx, re.NativeObject, lo, hi));
}
/// <summary>
/// Take the Kleene plus of a regular expression.
/// </summary>
public ReExpr MPlus(ReExpr re)
public ReExpr MkPlus(ReExpr re)
{
Contract.Requires(re != null);
Contract.Ensures(Contract.Result<ReExpr>() != null);
@ -2564,13 +2610,23 @@ namespace Microsoft.Z3
/// <summary>
/// Create the optional regular expression.
/// </summary>
public ReExpr MOption(ReExpr re)
public ReExpr MkOption(ReExpr re)
{
Contract.Requires(re != null);
Contract.Ensures(Contract.Result<ReExpr>() != null);
return new ReExpr(this, Native.Z3_mk_re_option(nCtx, re.NativeObject));
}
/// <summary>
/// Create the complement regular expression.
/// </summary>
public ReExpr MkComplement(ReExpr re)
{
Contract.Requires(re != null);
Contract.Ensures(Contract.Result<ReExpr>() != null);
return new ReExpr(this, Native.Z3_mk_re_complement(nCtx, re.NativeObject));
}
/// <summary>
/// Create the concatenation of regular languages.
/// </summary>
@ -2580,7 +2636,7 @@ namespace Microsoft.Z3
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result<ReExpr>() != null);
CheckContextMatch(t);
CheckContextMatch<ReExpr>(t);
return new ReExpr(this, Native.Z3_mk_re_concat(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
}
@ -2593,9 +2649,55 @@ namespace Microsoft.Z3
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result<ReExpr>() != null);
CheckContextMatch(t);
CheckContextMatch<ReExpr>(t);
return new ReExpr(this, Native.Z3_mk_re_union(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
}
/// <summary>
/// Create the intersection of regular languages.
/// </summary>
public ReExpr MkIntersect(params ReExpr[] t)
{
Contract.Requires(t != null);
Contract.Requires(Contract.ForAll(t, a => a != null));
Contract.Ensures(Contract.Result<ReExpr>() != null);
CheckContextMatch<ReExpr>(t);
return new ReExpr(this, Native.Z3_mk_re_intersect(nCtx, (uint)t.Length, AST.ArrayToNative(t)));
}
/// <summary>
/// Create the empty regular expression.
/// </summary>
public ReExpr MkEmptyRe(Sort s)
{
Contract.Requires(s != null);
Contract.Ensures(Contract.Result<SeqExpr>() != null);
return new ReExpr(this, Native.Z3_mk_re_empty(nCtx, s.NativeObject));
}
/// <summary>
/// Create the full regular expression.
/// </summary>
public ReExpr MkFullRe(Sort s)
{
Contract.Requires(s != null);
Contract.Ensures(Contract.Result<SeqExpr>() != null);
return new ReExpr(this, Native.Z3_mk_re_full(nCtx, s.NativeObject));
}
/// <summary>
/// Create a range expression.
/// </summary>
public ReExpr MkRange(SeqExpr lo, SeqExpr hi)
{
Contract.Requires(lo != null);
Contract.Requires(hi != null);
Contract.Ensures(Contract.Result<ReExpr>() != null);
CheckContextMatch(lo, hi);
return new ReExpr(this, Native.Z3_mk_re_range(nCtx, lo.NativeObject, hi.NativeObject));
}
#endregion
@ -2608,11 +2710,23 @@ namespace Microsoft.Z3
{
Contract.Requires(args != null);
Contract.Requires(Contract.Result<BoolExpr[]>() != null);
CheckContextMatch(args);
CheckContextMatch<BoolExpr>(args);
return new BoolExpr(this, Native.Z3_mk_atmost(nCtx, (uint) args.Length,
AST.ArrayToNative(args), k));
}
/// <summary>
/// Create an at-least-k constraint.
/// </summary>
public BoolExpr MkAtLeast(BoolExpr[] args, uint k)
{
Contract.Requires(args != null);
Contract.Requires(Contract.Result<BoolExpr[]>() != null);
CheckContextMatch<BoolExpr>(args);
return new BoolExpr(this, Native.Z3_mk_atleast(nCtx, (uint) args.Length,
AST.ArrayToNative(args), k));
}
/// <summary>
/// Create a pseudo-Boolean less-or-equal constraint.
/// </summary>
@ -2622,11 +2736,40 @@ namespace Microsoft.Z3
Contract.Requires(coeffs != null);
Contract.Requires(args.Length == coeffs.Length);
Contract.Requires(Contract.Result<BoolExpr[]>() != null);
CheckContextMatch(args);
CheckContextMatch<BoolExpr>(args);
return new BoolExpr(this, Native.Z3_mk_pble(nCtx, (uint) args.Length,
AST.ArrayToNative(args),
coeffs, k));
}
/// <summary>
/// Create a pseudo-Boolean greater-or-equal constraint.
/// </summary>
public BoolExpr MkPBGe(int[] coeffs, BoolExpr[] args, int k)
{
Contract.Requires(args != null);
Contract.Requires(coeffs != null);
Contract.Requires(args.Length == coeffs.Length);
Contract.Requires(Contract.Result<BoolExpr[]>() != null);
CheckContextMatch<BoolExpr>(args);
return new BoolExpr(this, Native.Z3_mk_pbge(nCtx, (uint) args.Length,
AST.ArrayToNative(args),
coeffs, k));
}
/// <summary>
/// Create a pseudo-Boolean equal constraint.
/// </summary>
public BoolExpr MkPBEq(int[] coeffs, BoolExpr[] args, int k)
{
Contract.Requires(args != null);
Contract.Requires(coeffs != null);
Contract.Requires(args.Length == coeffs.Length);
Contract.Requires(Contract.Result<BoolExpr[]>() != null);
CheckContextMatch<BoolExpr>(args);
return new BoolExpr(this, Native.Z3_mk_pbeq(nCtx, (uint) args.Length,
AST.ArrayToNative(args),
coeffs, k));
}
#endregion
#region Numerals
@ -3373,7 +3516,7 @@ namespace Microsoft.Z3
CheckContextMatch(t1);
CheckContextMatch(t2);
CheckContextMatch(ts);
CheckContextMatch<Tactic>(ts);
IntPtr last = IntPtr.Zero;
if (ts != null && ts.Length > 0)
@ -3564,7 +3707,7 @@ namespace Microsoft.Z3
Contract.Requires(t == null || Contract.ForAll(t, tactic => tactic != null));
Contract.Ensures(Contract.Result<Tactic>() != null);
CheckContextMatch(t);
CheckContextMatch<Tactic>(t);
return new Tactic(this, Native.Z3_tactic_par_or(nCtx, Tactic.ArrayLength(t), Tactic.ArrayToNative(t)));
}
@ -4797,7 +4940,7 @@ namespace Microsoft.Z3
}
[Pure]
internal void CheckContextMatch(IEnumerable<Z3Object> arr)
internal void CheckContextMatch<T>(IEnumerable<T> arr) where T : Z3Object
{
Contract.Requires(arr == null || Contract.ForAll(arr, a => a != null));
@ -4940,11 +5083,12 @@ namespace Microsoft.Z3
// Console.WriteLine("Context Finalizer from " + System.Threading.Thread.CurrentThread.ManagedThreadId);
Dispose();
if (refCount == 0)
if (refCount == 0 && m_ctx != IntPtr.Zero)
{
m_n_err_handler = null;
Native.Z3_del_context(m_ctx);
IntPtr ctx = m_ctx;
m_ctx = IntPtr.Zero;
Native.Z3_del_context(ctx);
}
else
GC.ReRegisterForFinalize(this);

View file

@ -98,7 +98,7 @@ namespace Microsoft.Z3
Contract.Requires(args != null);
Contract.Requires(Contract.ForAll(args, a => a != null));
Context.CheckContextMatch(args);
Context.CheckContextMatch<Expr>(args);
if (IsApp && args.Length != NumArgs)
throw new Z3Exception("Number of arguments does not match");
NativeObject = Native.Z3_update_term(Context.nCtx, NativeObject, (uint)args.Length, Expr.ArrayToNative(args));
@ -120,8 +120,8 @@ namespace Microsoft.Z3
Contract.Requires(Contract.ForAll(to, t => t != null));
Contract.Ensures(Contract.Result<Expr>() != null);
Context.CheckContextMatch(from);
Context.CheckContextMatch(to);
Context.CheckContextMatch<Expr>(from);
Context.CheckContextMatch<Expr>(to);
if (from.Length != to.Length)
throw new Z3Exception("Argument sizes do not match");
return Expr.Create(Context, Native.Z3_substitute(Context.nCtx, NativeObject, (uint)from.Length, Expr.ArrayToNative(from), Expr.ArrayToNative(to)));
@ -152,7 +152,7 @@ namespace Microsoft.Z3
Contract.Requires(Contract.ForAll(to, t => t != null));
Contract.Ensures(Contract.Result<Expr>() != null);
Context.CheckContextMatch(to);
Context.CheckContextMatch<Expr>(to);
return Expr.Create(Context, Native.Z3_substitute_vars(Context.nCtx, NativeObject, (uint)to.Length, Expr.ArrayToNative(to)));
}

View file

@ -14,7 +14,7 @@ Author:
Christoph Wintersteiger (cwinter) 2013-06-10
Notes:
--*/
using System;
using System.Diagnostics.Contracts;
@ -27,6 +27,20 @@ namespace Microsoft.Z3
[ContractVerification(true)]
public class FPNum : FPExpr
{
/// <summary>
/// The sign of a floating-point numeral as a bit-vector expression
/// </summary>
/// <remarks>
/// NaN's do not have a bit-vector sign, so they are invalid arguments.
/// </remarks>
public BitVecExpr SignBV
{
get
{
return new BitVecExpr(Context, Native.Z3_fpa_get_numeral_sign_bv(Context.nCtx, NativeObject));
}
}
/// <summary>
/// Retrieves the sign of a floating-point literal
/// </summary>
@ -38,7 +52,7 @@ namespace Microsoft.Z3
get
{
int res = 0;
if (Native.Z3_fpa_get_numeral_sign(Context.nCtx, NativeObject, ref res) == 0)
if (Native.Z3_fpa_get_numeral_sign(Context.nCtx, NativeObject, ref res) == 0)
throw new Z3Exception("Sign is not a Boolean value");
return res != 0;
}
@ -63,7 +77,7 @@ namespace Microsoft.Z3
/// The significand value of a floating-point numeral as a UInt64
/// </summary>
/// <remarks>
/// This function extracts the significand bits, without the
/// This function extracts the significand bits, without the
/// hidden bit or normalization. Throws an exception if the
/// significand does not fit into a UInt64.
/// </remarks>
@ -73,36 +87,90 @@ namespace Microsoft.Z3
{
UInt64 result = 0;
if (Native.Z3_fpa_get_numeral_significand_uint64(Context.nCtx, NativeObject, ref result) == 0)
throw new Z3Exception("Significand is not a 64 bit unsigned integer");
throw new Z3Exception("Significand is not a 64 bit unsigned integer");
return result;
}
}
/// <summary>
/// Return the exponent value of a floating-point numeral as a string
/// The significand of a floating-point numeral as a bit-vector expression
/// </summary>
public string Exponent
/// <remarks>
/// +oo, -oo and NaN's do not have a bit-vector significand, so they are invalid arguments.
/// </remarks>
public BitVecExpr SignificandBV
{
get
{
return Native.Z3_fpa_get_numeral_exponent_string(Context.nCtx, NativeObject);
return new BitVecExpr(Context, Native.Z3_fpa_get_numeral_significand_bv(Context.nCtx, NativeObject));
}
}
/// <summary>
/// Return the (biased) exponent value of a floating-point numeral as a string
/// </summary>
public string Exponent(bool biased = true)
{
return Native.Z3_fpa_get_numeral_exponent_string(Context.nCtx, NativeObject, biased ? 1 : 0);
}
/// <summary>
/// Return the exponent value of a floating-point numeral as a signed 64-bit integer
/// </summary>
public Int64 ExponentInt64
public Int64 ExponentInt64(bool biased = true)
{
get
{
Int64 result = 0;
if (Native.Z3_fpa_get_numeral_exponent_int64(Context.nCtx, NativeObject, ref result) == 0)
throw new Z3Exception("Exponent is not a 64 bit integer");
return result;
}
Int64 result = 0;
if (Native.Z3_fpa_get_numeral_exponent_int64(Context.nCtx, NativeObject, ref result, biased ? 1 : 0) == 0)
throw new Z3Exception("Exponent is not a 64 bit integer");
return result;
}
/// <summary>
/// The exponent of a floating-point numeral as a bit-vector expression
/// </summary>
/// <remarks>
/// +oo, -oo and NaN's do not have a bit-vector exponent, so they are invalid arguments.
/// </remarks>
public BitVecExpr ExponentBV(bool biased = true)
{
return new BitVecExpr(Context, Native.Z3_fpa_get_numeral_exponent_bv(Context.nCtx, NativeObject, biased ? 1 : 0));
}
/// <summary>
/// Indicates whether the numeral is a NaN.
/// </summary>
public bool IsNaN { get { return Native.Z3_fpa_is_numeral_nan(Context.nCtx, NativeObject) != 0; } }
/// <summary>
/// Indicates whether the numeral is a +oo or -oo.
/// </summary>
public bool IsInf { get { return Native.Z3_fpa_is_numeral_inf(Context.nCtx, NativeObject) != 0; } }
/// <summary>
/// Indicates whether the numeral is +zero or -zero.
/// </summary>
public bool IsZero{ get { return Native.Z3_fpa_is_numeral_zero(Context.nCtx, NativeObject) != 0; } }
/// <summary>
/// Indicates whether the numeral is normal.
/// </summary>
public bool IsNormal { get { return Native.Z3_fpa_is_numeral_normal(Context.nCtx, NativeObject) != 0; } }
/// <summary>
/// Indicates whether the numeral is subnormal.
/// </summary>
public bool IsSubnormal { get { return Native.Z3_fpa_is_numeral_subnormal(Context.nCtx, NativeObject) != 0; } }
/// <summary>
/// Indicates whether the numeral is positive.
/// </summary>
public bool IsPositive { get { return Native.Z3_fpa_is_numeral_positive(Context.nCtx, NativeObject) != 0; } }
/// <summary>
/// Indicates whether the numeral is negative.
/// </summary>
public bool IsNegative { get { return Native.Z3_fpa_is_numeral_negative(Context.nCtx, NativeObject) != 0; } }
#region Internal
internal FPNum(Context ctx, IntPtr obj)
: base(ctx, obj)
@ -113,7 +181,7 @@ namespace Microsoft.Z3
/// <summary>
/// Returns a string representation of the numeral.
/// </summary>
/// </summary>
public override string ToString()
{
return Native.Z3_get_numeral_string(Context.nCtx, NativeObject);

View file

@ -71,7 +71,7 @@ namespace Microsoft.Z3
Contract.Requires(constraints != null);
Contract.Requires(Contract.ForAll(constraints, c => c != null));
Context.CheckContextMatch(constraints);
Context.CheckContextMatch<BoolExpr>(constraints);
foreach (BoolExpr a in constraints)
{
Native.Z3_fixedpoint_assert(Context.nCtx, NativeObject, a.NativeObject);
@ -151,7 +151,7 @@ namespace Microsoft.Z3
Contract.Requires(relations != null);
Contract.Requires(Contract.ForAll(0, relations.Length, i => relations[i] != null));
Context.CheckContextMatch(relations);
Context.CheckContextMatch<FuncDecl>(relations);
Z3_lbool r = (Z3_lbool)Native.Z3_fixedpoint_query_relations(Context.nCtx, NativeObject,
AST.ArrayLength(relations), AST.ArrayToNative(relations));
switch (r)

View file

@ -339,7 +339,7 @@ namespace Microsoft.Z3
{
Contract.Requires(args == null || Contract.ForAll(args, a => a != null));
Context.CheckContextMatch(args);
Context.CheckContextMatch<Expr>(args);
return Expr.Create(Context, this, args);
}

View file

@ -82,7 +82,7 @@ namespace Microsoft.Z3
Contract.Requires(constraints != null);
Contract.Requires(Contract.ForAll(constraints, c => c != null));
Context.CheckContextMatch(constraints);
Context.CheckContextMatch<BoolExpr>(constraints);
foreach (BoolExpr c in constraints)
{
Contract.Assert(c != null); // It was an assume, now made an assert just to be sure we do not regress

View file

@ -30,7 +30,7 @@ namespace Microsoft.Z3
/// <summary>
/// Constructor.
/// </summary>
/// <remarks><seealso cref="Context.Context(Dictionary&lt;string, string&gt;)"/></remarks>
/// <remarks><seealso cref="Context"/></remarks>
public InterpolationContext(Dictionary<string, string> settings) : base(settings) { }
#region Terms

View file

@ -258,10 +258,13 @@ namespace Microsoft.Z3
/// <summary>
/// Return a string the describes why the last to check returned unknown
/// </summary>
public String getReasonUnknown()
public String ReasonUnknown
{
Contract.Ensures(Contract.Result<string>() != null);
return Native.Z3_optimize_get_reason_unknown(Context.nCtx, NativeObject);
get
{
Contract.Ensures(Contract.Result<string>() != null);
return Native.Z3_optimize_get_reason_unknown(Context.nCtx, NativeObject);
}
}
@ -273,6 +276,52 @@ namespace Microsoft.Z3
return Native.Z3_optimize_to_string(Context.nCtx, NativeObject);
}
/// <summary>
/// Parse an SMT-LIB2 file with optimization objectives and constraints.
/// The parsed constraints and objectives are added to the optimization context.
/// </summary>
public void FromFile(string file)
{
Native.Z3_optimize_from_file(Context.nCtx, NativeObject, file);
}
/// <summary>
/// Similar to FromFile. Instead it takes as argument a string.
/// </summary>
public void FromString(string s)
{
Native.Z3_optimize_from_string(Context.nCtx, NativeObject, s);
}
/// <summary>
/// The set of asserted formulas.
/// </summary>
public BoolExpr[] Assertions
{
get
{
Contract.Ensures(Contract.Result<BoolExpr[]>() != null);
ASTVector assertions = new ASTVector(Context, Native.Z3_optimize_get_assertions(Context.nCtx, NativeObject));
return assertions.ToBoolExprArray();
}
}
/// <summary>
/// The set of asserted formulas.
/// </summary>
public Expr[] Objectives
{
get
{
Contract.Ensures(Contract.Result<Expr[]>() != null);
ASTVector objectives = new ASTVector(Context, Native.Z3_optimize_get_objectives(Context.nCtx, NativeObject));
return objectives.ToExprArray();
}
}
/// <summary>
/// Optimize statistics.
/// </summary>

View file

@ -172,10 +172,10 @@ namespace Microsoft.Z3
Contract.Requires(patterns == null || Contract.ForAll(patterns, p => p != null));
Contract.Requires(noPatterns == null || Contract.ForAll(noPatterns, np => np != null));
Context.CheckContextMatch(patterns);
Context.CheckContextMatch(noPatterns);
Context.CheckContextMatch(sorts);
Context.CheckContextMatch(names);
Context.CheckContextMatch<Pattern>(patterns);
Context.CheckContextMatch<Expr>(noPatterns);
Context.CheckContextMatch<Sort>(sorts);
Context.CheckContextMatch<Symbol>(names);
Context.CheckContextMatch(body);
if (sorts.Length != names.Length)
@ -212,8 +212,8 @@ namespace Microsoft.Z3
Contract.Requires(noPatterns == null || Contract.ForAll(noPatterns, np => np != null));
Contract.Requires(bound == null || Contract.ForAll(bound, n => n != null));
Context.CheckContextMatch(noPatterns);
Context.CheckContextMatch(patterns);
Context.CheckContextMatch<Expr>(noPatterns);
Context.CheckContextMatch<Pattern>(patterns);
//Context.CheckContextMatch(bound);
Context.CheckContextMatch(body);

View file

@ -18,6 +18,8 @@ Notes:
--*/
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
@ -110,7 +112,7 @@ namespace Microsoft.Z3
Contract.Requires(constraints != null);
Contract.Requires(Contract.ForAll(constraints, c => c != null));
Context.CheckContextMatch(constraints);
Context.CheckContextMatch<BoolExpr>(constraints);
foreach (BoolExpr a in constraints)
{
Native.Z3_solver_assert(Context.nCtx, NativeObject, a.NativeObject);
@ -125,6 +127,14 @@ namespace Microsoft.Z3
Assert(constraints);
}
/// <summary>
/// Alias for Assert.
/// </summary>
public void Add(IEnumerable<BoolExpr> constraints)
{
Assert(constraints.ToArray());
}
/// <summary>
/// Assert multiple constraints into the solver, and track them (in the unsat) core
/// using the Boolean constants in ps.
@ -141,8 +151,8 @@ namespace Microsoft.Z3
Contract.Requires(constraints != null);
Contract.Requires(Contract.ForAll(constraints, c => c != null));
Contract.Requires(Contract.ForAll(ps, c => c != null));
Context.CheckContextMatch(constraints);
Context.CheckContextMatch(ps);
Context.CheckContextMatch<BoolExpr>(constraints);
Context.CheckContextMatch<BoolExpr>(ps);
if (constraints.Length != ps.Length)
throw new Z3Exception("Argument size mismatch");
@ -212,12 +222,34 @@ namespace Microsoft.Z3
r = (Z3_lbool)Native.Z3_solver_check(Context.nCtx, NativeObject);
else
r = (Z3_lbool)Native.Z3_solver_check_assumptions(Context.nCtx, NativeObject, (uint)assumptions.Length, AST.ArrayToNative(assumptions));
switch (r)
{
case Z3_lbool.Z3_L_TRUE: return Status.SATISFIABLE;
case Z3_lbool.Z3_L_FALSE: return Status.UNSATISFIABLE;
default: return Status.UNKNOWN;
}
return lboolToStatus(r);
}
/// <summary>
/// Retrieve fixed assignments to the set of variables in the form of consequences.
/// Each consequence is an implication of the form
///
/// relevant-assumptions Implies variable = value
///
/// where the relevant assumptions is a subset of the assumptions that are passed in
/// and the equality on the right side of the implication indicates how a variable
/// is fixed.
/// </summary>
/// <remarks>
/// <seealso cref="Model"/>
/// <seealso cref="UnsatCore"/>
/// <seealso cref="Proof"/>
/// </remarks>
public Status Consequences(IEnumerable<BoolExpr> assumptions, IEnumerable<Expr> variables, out BoolExpr[] consequences)
{
ASTVector result = new ASTVector(Context);
ASTVector asms = new ASTVector(Context);
ASTVector vars = new ASTVector(Context);
foreach (var asm in assumptions) asms.Push(asm);
foreach (var v in variables) vars.Push(v);
Z3_lbool r = (Z3_lbool)Native.Z3_solver_get_consequences(Context.nCtx, NativeObject, asms.NativeObject, vars.NativeObject, result.NativeObject);
consequences = result.ToBoolExprArray();
return lboolToStatus(r);
}
/// <summary>
@ -295,7 +327,7 @@ namespace Microsoft.Z3
/// </summary>
public Solver Translate(Context ctx)
{
Contract.Requires(ctx != null);
Contract.Requires(ctx != null);
Contract.Ensures(Contract.Result<Solver>() != null);
return new Solver(ctx, Native.Z3_solver_translate(Context.nCtx, NativeObject, ctx.nCtx));
}
@ -355,6 +387,17 @@ namespace Microsoft.Z3
Context.Solver_DRQ.Add(o);
base.DecRef(o);
}
private Status lboolToStatus(Z3_lbool r)
{
switch (r)
{
case Z3_lbool.Z3_L_TRUE: return Status.SATISFIABLE;
case Z3_lbool.Z3_L_FALSE: return Status.UNSATISFIABLE;
default: return Status.UNKNOWN;
}
}
#endregion
}
}

View file

@ -83,6 +83,17 @@ namespace Microsoft.Z3
}
}
/// <summary>
/// A full version string
/// </summary>
public static string FullVersion
{
get
{
return Native.Z3_get_full_version();
}
}
/// <summary>
/// A string representation of the version information.
/// </summary>

View file

@ -14,17 +14,20 @@ Author:
Christoph Wintersteiger (cwinter) 2012-03-15
Notes:
--*/
using System;
namespace Microsoft.Z3
{
/// <summary>
/// The exception base class for error reporting from Z3
/// </summary>
public class Z3Exception : Exception
/// <summary>
/// The exception base class for error reporting from Z3
/// </summary>
#if !DOTNET_CORE
[Serializable]
#endif
public class Z3Exception : Exception
{
/// <summary>
/// Constructor.

View file

@ -138,7 +138,7 @@ namespace Microsoft.Z3
}
[Pure]
internal static IntPtr[] EnumToNative(IEnumerable<Z3Object> a)
internal static IntPtr[] EnumToNative<T>(IEnumerable<T> a) where T : Z3Object
{
Contract.Ensures(a == null || Contract.Result<IntPtr[]>() != null);
Contract.Ensures(a == null || Contract.Result<IntPtr[]>().Length == a.Count());

View file

@ -0,0 +1,65 @@
/*++
Copyright (<c>) 2016 Microsoft Corporation
Module Name:
Contracts.cs
Abstract:
Z3 Managed API: Dummy Code Contracts class for .NET
frameworks that don't support them (e.g., CoreCLR).
Author:
Christoph Wintersteiger (cwinter) 2016-10-06
Notes:
--*/
namespace System.Diagnostics.Contracts
{
public class ContractClass : Attribute
{
public ContractClass(Type t) { }
}
public class ContractClassFor : Attribute
{
public ContractClassFor(Type t) { }
}
public class ContractInvariantMethod : Attribute
{
public ContractInvariantMethod() { }
}
public class ContractVerification : Attribute
{
public ContractVerification(bool b) { }
}
public class Pure : Attribute { }
public static class Contract
{
[Conditional("false")]
public static void Ensures(bool b) { }
[Conditional("false")]
public static void Requires(bool b) { }
[Conditional("false")]
public static void Assume(bool b, string msg) { }
[Conditional("false")]
public static void Assert(bool b) { }
public static bool ForAll(bool b) { return true; }
public static bool ForAll(Object c, Func<Object, bool> p) { return true; }
public static bool ForAll(int from, int to, Predicate<int> p) { return true; }
[Conditional("false")]
public static void Invariant(bool b) { }
public static T[] Result<T>() { return new T[1]; }
[Conditional("false")]
public static void EndContractBlock() { }
public static T ValueAtReturn<T>(out T v) { T[] t = new T[1]; v = t[0]; return v; }
}
}

View file

@ -0,0 +1,9 @@
Z3 API for .NET Core
Z3's .NET API uses Code Contracts, which are not included in .NET Core. The
enclosed file called DummyContracts.cs provides stubs for the Code Contracts
functions, so that the API will compile, but not perform any contract
checking. To build this using .NET core, run (in this directory):
dotnet restore
dotnet build project.json

View file

@ -0,0 +1,22 @@
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": false,
"outputName": "Microsoft.Z3",
"compile": [ "../*.cs", "*.cs" ],
"define": ["DOTNET_CORE"]
},
"dependencies": { },
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

View file

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2A8E577B-7B6D-4CA9-832A-CA2EEC314812}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Example</RootNamespace>
<AssemblyName>Example</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;FRAMEWORK_LT_4</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;FRAMEWORK_LT_4</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;FRAMEWORK_LT_4</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE;FRAMEWORK_LT_4</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\..\..\..\examples\dotnet\Program.cs">
<Link>Program.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.Z3.NET35.csproj">
<Project>{ec3db697-b734-42f7-9468-5b62821eeb5a}</Project>
<Name>Microsoft.Z3.NET35</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View file

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Example")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Example")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("2a8e577b-7b6d-4ca9-832a-ca2eec314812")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View file

@ -0,0 +1,347 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{EC3DB697-B734-42F7-9468-5B62821EEB5A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Z3</RootNamespace>
<AssemblyName>Microsoft.Z3</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<CodeContractsAssemblyMode>0</CodeContractsAssemblyMode>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;FRAMEWORK_LT_4</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile>Debug\Microsoft.Z3.XML</DocumentationFile>
<CodeContractsEnableRuntimeChecking>False</CodeContractsEnableRuntimeChecking>
<CodeContractsRuntimeOnlyPublicSurface>False</CodeContractsRuntimeOnlyPublicSurface>
<CodeContractsRuntimeThrowOnFailure>True</CodeContractsRuntimeThrowOnFailure>
<CodeContractsRuntimeCallSiteRequires>False</CodeContractsRuntimeCallSiteRequires>
<CodeContractsRuntimeSkipQuantifiers>False</CodeContractsRuntimeSkipQuantifiers>
<CodeContractsRunCodeAnalysis>True</CodeContractsRunCodeAnalysis>
<CodeContractsNonNullObligations>False</CodeContractsNonNullObligations>
<CodeContractsBoundsObligations>True</CodeContractsBoundsObligations>
<CodeContractsArithmeticObligations>True</CodeContractsArithmeticObligations>
<CodeContractsEnumObligations>False</CodeContractsEnumObligations>
<CodeContractsPointerObligations>False</CodeContractsPointerObligations>
<CodeContractsRedundantAssumptions>False</CodeContractsRedundantAssumptions>
<CodeContractsInferRequires>True</CodeContractsInferRequires>
<CodeContractsInferEnsures>False</CodeContractsInferEnsures>
<CodeContractsInferObjectInvariants>False</CodeContractsInferObjectInvariants>
<CodeContractsSuggestAssumptions>False</CodeContractsSuggestAssumptions>
<CodeContractsSuggestRequires>True</CodeContractsSuggestRequires>
<CodeContractsSuggestEnsures>False</CodeContractsSuggestEnsures>
<CodeContractsSuggestObjectInvariants>False</CodeContractsSuggestObjectInvariants>
<CodeContractsDisjunctiveRequires>True</CodeContractsDisjunctiveRequires>
<CodeContractsRunInBackground>True</CodeContractsRunInBackground>
<CodeContractsShowSquigglies>True</CodeContractsShowSquigglies>
<CodeContractsUseBaseLine>False</CodeContractsUseBaseLine>
<CodeContractsEmitXMLDocs>False</CodeContractsEmitXMLDocs>
<CodeContractsCustomRewriterAssembly />
<CodeContractsCustomRewriterClass />
<CodeContractsLibPaths />
<CodeContractsExtraRewriteOptions />
<CodeContractsExtraAnalysisOptions />
<CodeContractsBaseLineFile />
<CodeContractsCacheAnalysisResults>True</CodeContractsCacheAnalysisResults>
<CodeContractsRuntimeCheckingLevel>Full</CodeContractsRuntimeCheckingLevel>
<CodeContractsReferenceAssembly>%28none%29</CodeContractsReferenceAssembly>
<CodeContractsAnalysisWarningLevel>2</CodeContractsAnalysisWarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>Release\</OutputPath>
<DefineConstants>FRAMEWORK_LT_4</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile>Release\Microsoft.Z3.xml</DocumentationFile>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>
</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup>
<DelaySign>false</DelaySign>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;FRAMEWORK_LT_4</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile>Debug\Microsoft.Z3.XML</DocumentationFile>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>FRAMEWORK_LT_4</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile>Release\Microsoft.Z3.xml</DocumentationFile>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=736440c9b414ea16, processorArchitecture=MSIL">
<HintPath>packages\Code.Contract.1.0.0\lib\net35\Microsoft.Contracts.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\AlgebraicNum.cs">
<Link>AlgebraicNum.cs</Link>
</Compile>
<Compile Include="..\ApplyResult.cs">
<Link>ApplyResult.cs</Link>
</Compile>
<Compile Include="..\ArithExpr.cs">
<Link>ArithExpr.cs</Link>
</Compile>
<Compile Include="..\ArithSort.cs">
<Link>ArithSort.cs</Link>
</Compile>
<Compile Include="..\ArrayExpr.cs">
<Link>ArrayExpr.cs</Link>
</Compile>
<Compile Include="..\ArraySort.cs">
<Link>ArraySort.cs</Link>
</Compile>
<Compile Include="..\AST.cs">
<Link>AST.cs</Link>
</Compile>
<Compile Include="..\ASTMap.cs">
<Link>ASTMap.cs</Link>
</Compile>
<Compile Include="..\ASTVector.cs">
<Link>ASTVector.cs</Link>
</Compile>
<Compile Include="..\BitVecExpr.cs">
<Link>BitVecExpr.cs</Link>
</Compile>
<Compile Include="..\BitVecNum.cs">
<Link>BitVecNum.cs</Link>
</Compile>
<Compile Include="..\BitVecSort.cs">
<Link>BitVecSort.cs</Link>
</Compile>
<Compile Include="..\BoolExpr.cs">
<Link>BoolExpr.cs</Link>
</Compile>
<Compile Include="..\BoolSort.cs">
<Link>BoolSort.cs</Link>
</Compile>
<Compile Include="..\Constructor.cs">
<Link>Constructor.cs</Link>
</Compile>
<Compile Include="..\ConstructorList.cs">
<Link>ConstructorList.cs</Link>
</Compile>
<Compile Include="..\Context.cs">
<Link>Context.cs</Link>
</Compile>
<Compile Include="..\DatatypeExpr.cs">
<Link>DatatypeExpr.cs</Link>
</Compile>
<Compile Include="..\DatatypeSort.cs">
<Link>DatatypeSort.cs</Link>
</Compile>
<Compile Include="..\Deprecated.cs">
<Link>Deprecated.cs</Link>
</Compile>
<Compile Include="..\Enumerations.cs">
<Link>Enumerations.cs</Link>
</Compile>
<Compile Include="..\EnumSort.cs">
<Link>EnumSort.cs</Link>
</Compile>
<Compile Include="..\Expr.cs">
<Link>Expr.cs</Link>
</Compile>
<Compile Include="..\FiniteDomainExpr.cs">
<Link>FiniteDomainExpr.cs</Link>
</Compile>
<Compile Include="..\FiniteDomainNum.cs">
<Link>FiniteDomainNum.cs</Link>
</Compile>
<Compile Include="..\FiniteDomainSort.cs">
<Link>FiniteDomainSort.cs</Link>
</Compile>
<Compile Include="..\Fixedpoint.cs">
<Link>Fixedpoint.cs</Link>
</Compile>
<Compile Include="..\FPExpr.cs">
<Link>FPExpr.cs</Link>
</Compile>
<Compile Include="..\FPNum.cs">
<Link>FPNum.cs</Link>
</Compile>
<Compile Include="..\FPRMExpr.cs">
<Link>FPRMExpr.cs</Link>
</Compile>
<Compile Include="..\FPRMNum.cs">
<Link>FPRMNum.cs</Link>
</Compile>
<Compile Include="..\FPRMSort.cs">
<Link>FPRMSort.cs</Link>
</Compile>
<Compile Include="..\FPSort.cs">
<Link>FPSort.cs</Link>
</Compile>
<Compile Include="..\FuncDecl.cs">
<Link>FuncDecl.cs</Link>
</Compile>
<Compile Include="..\FuncInterp.cs">
<Link>FuncInterp.cs</Link>
</Compile>
<Compile Include="..\Global.cs">
<Link>Global.cs</Link>
</Compile>
<Compile Include="..\Goal.cs">
<Link>Goal.cs</Link>
</Compile>
<Compile Include="..\IDecRefQueue.cs">
<Link>IDecRefQueue.cs</Link>
</Compile>
<Compile Include="..\InterpolationContext.cs">
<Link>InterpolationContext.cs</Link>
</Compile>
<Compile Include="..\IntExpr.cs">
<Link>IntExpr.cs</Link>
</Compile>
<Compile Include="..\IntNum.cs">
<Link>IntNum.cs</Link>
</Compile>
<Compile Include="..\IntSort.cs">
<Link>IntSort.cs</Link>
</Compile>
<Compile Include="..\IntSymbol.cs">
<Link>IntSymbol.cs</Link>
</Compile>
<Compile Include="..\ListSort.cs">
<Link>ListSort.cs</Link>
</Compile>
<Compile Include="..\Log.cs">
<Link>Log.cs</Link>
</Compile>
<Compile Include="..\Model.cs">
<Link>Model.cs</Link>
</Compile>
<Compile Include="..\Native.cs">
<Link>Native.cs</Link>
</Compile>
<Compile Include="..\Optimize.cs">
<Link>Optimize.cs</Link>
</Compile>
<Compile Include="..\ParamDescrs.cs">
<Link>ParamDescrs.cs</Link>
</Compile>
<Compile Include="..\Params.cs">
<Link>Params.cs</Link>
</Compile>
<Compile Include="..\Pattern.cs">
<Link>Pattern.cs</Link>
</Compile>
<Compile Include="..\Probe.cs">
<Link>Probe.cs</Link>
</Compile>
<Compile Include="..\Quantifier.cs">
<Link>Quantifier.cs</Link>
</Compile>
<Compile Include="..\RatNum.cs">
<Link>RatNum.cs</Link>
</Compile>
<Compile Include="..\RealExpr.cs">
<Link>RealExpr.cs</Link>
</Compile>
<Compile Include="..\RealSort.cs">
<Link>RealSort.cs</Link>
</Compile>
<Compile Include="..\ReExpr.cs">
<Link>ReExpr.cs</Link>
</Compile>
<Compile Include="..\RelationSort.cs">
<Link>RelationSort.cs</Link>
</Compile>
<Compile Include="..\ReSort.cs">
<Link>ReSort.cs</Link>
</Compile>
<Compile Include="..\SeqExpr.cs">
<Link>SeqExpr.cs</Link>
</Compile>
<Compile Include="..\SeqSort.cs">
<Link>SeqSort.cs</Link>
</Compile>
<Compile Include="..\SetSort.cs">
<Link>SetSort.cs</Link>
</Compile>
<Compile Include="..\Solver.cs">
<Link>Solver.cs</Link>
</Compile>
<Compile Include="..\Sort.cs">
<Link>Sort.cs</Link>
</Compile>
<Compile Include="..\Statistics.cs">
<Link>Statistics.cs</Link>
</Compile>
<Compile Include="..\Status.cs">
<Link>Status.cs</Link>
</Compile>
<Compile Include="..\StringSymbol.cs">
<Link>StringSymbol.cs</Link>
</Compile>
<Compile Include="..\Symbol.cs">
<Link>Symbol.cs</Link>
</Compile>
<Compile Include="..\Tactic.cs">
<Link>Tactic.cs</Link>
</Compile>
<Compile Include="..\TupleSort.cs">
<Link>TupleSort.cs</Link>
</Compile>
<Compile Include="..\UninterpretedSort.cs">
<Link>UninterpretedSort.cs</Link>
</Compile>
<Compile Include="..\Version.cs">
<Link>Version.cs</Link>
</Compile>
<Compile Include="..\Z3Exception.cs">
<Link>Z3Exception.cs</Link>
</Compile>
<Compile Include="..\Z3Object.cs">
<Link>Z3Object.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View file

@ -0,0 +1,48 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Z3.NET35", "Microsoft.Z3.NET35.csproj", "{EC3DB697-B734-42F7-9468-5B62821EEB5A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example", "Example\Example.csproj", "{2A8E577B-7B6D-4CA9-832A-CA2EEC314812}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EC3DB697-B734-42F7-9468-5B62821EEB5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EC3DB697-B734-42F7-9468-5B62821EEB5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC3DB697-B734-42F7-9468-5B62821EEB5A}.Debug|x64.ActiveCfg = Debug|Any CPU
{EC3DB697-B734-42F7-9468-5B62821EEB5A}.Debug|x64.Build.0 = Debug|Any CPU
{EC3DB697-B734-42F7-9468-5B62821EEB5A}.Debug|x86.ActiveCfg = Debug|Any CPU
{EC3DB697-B734-42F7-9468-5B62821EEB5A}.Debug|x86.Build.0 = Debug|Any CPU
{EC3DB697-B734-42F7-9468-5B62821EEB5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC3DB697-B734-42F7-9468-5B62821EEB5A}.Release|Any CPU.Build.0 = Release|Any CPU
{EC3DB697-B734-42F7-9468-5B62821EEB5A}.Release|x64.ActiveCfg = Release|x64
{EC3DB697-B734-42F7-9468-5B62821EEB5A}.Release|x64.Build.0 = Release|x64
{EC3DB697-B734-42F7-9468-5B62821EEB5A}.Release|x86.ActiveCfg = Release|Any CPU
{EC3DB697-B734-42F7-9468-5B62821EEB5A}.Release|x86.Build.0 = Release|Any CPU
{2A8E577B-7B6D-4CA9-832A-CA2EEC314812}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A8E577B-7B6D-4CA9-832A-CA2EEC314812}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A8E577B-7B6D-4CA9-832A-CA2EEC314812}.Debug|x64.ActiveCfg = Debug|Any CPU
{2A8E577B-7B6D-4CA9-832A-CA2EEC314812}.Debug|x64.Build.0 = Debug|Any CPU
{2A8E577B-7B6D-4CA9-832A-CA2EEC314812}.Debug|x86.ActiveCfg = Debug|Any CPU
{2A8E577B-7B6D-4CA9-832A-CA2EEC314812}.Debug|x86.Build.0 = Debug|Any CPU
{2A8E577B-7B6D-4CA9-832A-CA2EEC314812}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A8E577B-7B6D-4CA9-832A-CA2EEC314812}.Release|Any CPU.Build.0 = Release|Any CPU
{2A8E577B-7B6D-4CA9-832A-CA2EEC314812}.Release|x64.ActiveCfg = Release|x64
{2A8E577B-7B6D-4CA9-832A-CA2EEC314812}.Release|x64.Build.0 = Release|x64
{2A8E577B-7B6D-4CA9-832A-CA2EEC314812}.Release|x86.ActiveCfg = Release|Any CPU
{2A8E577B-7B6D-4CA9-832A-CA2EEC314812}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,38 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Permissions;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Z3 .NET Interface")]
[assembly: AssemblyDescription(".NET Interface to the Z3 Theorem Prover")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyProduct("Z3")]
[assembly: AssemblyCopyright("Copyright (C) 2006-2015 Microsoft Corporation")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4853ed71-2078-40f4-8117-bc46646bce0e")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("4.2.0.0")]
[assembly: AssemblyVersion("4.5.1.6031")]
[assembly: AssemblyFileVersion("4.5.1.6031")]

View file

@ -0,0 +1,38 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Permissions;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Z3 .NET Interface")]
[assembly: AssemblyDescription(".NET Interface to the Z3 Theorem Prover")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyProduct("Z3")]
[assembly: AssemblyCopyright("Copyright (C) 2006-2015 Microsoft Corporation")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4853ed71-2078-40f4-8117-bc46646bce0e")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("4.2.0.0")]
[assembly: AssemblyVersion("@VER_MAJOR@.@VER_MINOR@.@VER_BUILD@.@VER_REVISION@")]
[assembly: AssemblyFileVersion("@VER_MAJOR@.@VER_MINOR@.@VER_BUILD@.@VER_REVISION@")]

View file

@ -6,4 +6,5 @@ In the project properties of Microsoft.Z3.csproj:
- Under 'Application': Change Target framework to .NET Framework 3.5
- Under 'Build': Add FRAMEWORK_LT_4 to the condidional compilation symbols
- Remove the reference to System.Numerics
- Install the NuGet Package "Microsoft Code Contracts for Net3.5"
- Install the NuGet Package "Microsoft Code Contracts for Net3.5":
In the Package Manager Console enter Install-Package Code.Contract

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Code.Contract" version="1.0.0" targetFramework="net35" />
</packages>

View file

@ -175,15 +175,8 @@ public class AST extends Z3Object implements Comparable<AST>
* A string representation of the AST.
**/
@Override
public String toString()
{
try
{
return Native.astToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
public String toString() {
return Native.astToString(getContext().nCtx(), getNativeObject());
}
/**
@ -194,34 +187,18 @@ public class AST extends Z3Object implements Comparable<AST>
return Native.astToString(getContext().nCtx(), getNativeObject());
}
AST(Context ctx)
{
super(ctx);
}
AST(Context ctx, long obj)
{
AST(Context ctx, long obj) {
super(ctx, obj);
}
@Override
void incRef(long o)
{
// Console.WriteLine("AST IncRef()");
if (getContext() == null || o == 0)
return;
getContext().getASTDRQ().incAndClear(getContext(), o);
super.incRef(o);
void incRef() {
Native.incRef(getContext().nCtx(), getNativeObject());
}
@Override
void decRef(long o)
{
// Console.WriteLine("AST DecRef()");
if (getContext() == null || o == 0)
return;
getContext().getASTDRQ().add(o);
super.decRef(o);
void addToReferenceQueue() {
getContext().getASTDRQ().storeReference(getContext(), this);
}
static AST create(Context ctx, long obj)

View file

@ -17,39 +17,15 @@ Notes:
package com.microsoft.z3;
class ASTDecRefQueue extends IDecRefQueue
class ASTDecRefQueue extends IDecRefQueue<AST>
{
public ASTDecRefQueue()
{
super();
}
public ASTDecRefQueue(int move_limit)
{
super(move_limit);
}
@Override
protected void incRef(Context ctx, long obj)
{
try
{
Native.incRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
@Override
protected void decRef(Context ctx, long obj)
{
try
{
Native.decRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
protected void decRef(Context ctx, long obj) {
Native.decRef(ctx.nCtx(), obj);
}
};

View file

@ -20,8 +20,7 @@ package com.microsoft.z3;
/**
* Map from AST to AST
**/
class ASTMap extends Z3Object
{
class ASTMap extends Z3Object {
/**
* Checks whether the map contains the key {@code k}.
* @param k An AST
@ -104,13 +103,7 @@ class ASTMap extends Z3Object
@Override
public String toString()
{
try
{
return Native.astMapToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
return Native.astMapToString(getContext().nCtx(), getNativeObject());
}
ASTMap(Context ctx, long obj)
@ -124,16 +117,12 @@ class ASTMap extends Z3Object
}
@Override
void incRef(long o)
{
getContext().getASTMapDRQ().incAndClear(getContext(), o);
super.incRef(o);
void incRef() {
Native.astMapIncRef(getContext().nCtx(), getNativeObject());
}
@Override
void decRef(long o)
{
getContext().getASTMapDRQ().add(o);
super.decRef(o);
void addToReferenceQueue() {
getContext().getASTMapDRQ().storeReference(getContext(), this);
}
}

View file

@ -20,8 +20,7 @@ package com.microsoft.z3;
/**
* Vectors of ASTs.
**/
public class ASTVector extends Z3Object
{
public class ASTVector extends Z3Object {
/**
* The size of the vector
**/
@ -88,15 +87,8 @@ public class ASTVector extends Z3Object
* Retrieves a string representation of the vector.
**/
@Override
public String toString()
{
try
{
return Native.astVectorToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
public String toString() {
return Native.astVectorToString(getContext().nCtx(), getNativeObject());
}
ASTVector(Context ctx, long obj)
@ -110,19 +102,15 @@ public class ASTVector extends Z3Object
}
@Override
void incRef(long o)
{
getContext().getASTVectorDRQ().incAndClear(getContext(), o);
super.incRef(o);
void incRef() {
Native.astVectorIncRef(getContext().nCtx(), getNativeObject());
}
@Override
void decRef(long o)
{
getContext().getASTVectorDRQ().add(o);
super.decRef(o);
void addToReferenceQueue() {
getContext().getASTVectorDRQ().storeReference(getContext(), this);
}
/**
* Translates the AST vector into an AST[]
* */

View file

@ -21,8 +21,7 @@ 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
{
public class ApplyResult extends Z3Object {
/**
* The number of Subgoals.
**/
@ -64,15 +63,8 @@ public class ApplyResult extends Z3Object
* A string representation of the ApplyResult.
**/
@Override
public String toString()
{
try
{
return Native.applyResultToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
public String toString() {
return Native.applyResultToString(getContext().nCtx(), getNativeObject());
}
ApplyResult(Context ctx, long obj)
@ -81,16 +73,12 @@ public class ApplyResult extends Z3Object
}
@Override
void incRef(long o)
{
getContext().getApplyResultDRQ().incAndClear(getContext(), o);
super.incRef(o);
void incRef() {
Native.applyResultIncRef(getContext().nCtx(), getNativeObject());
}
@Override
void decRef(long o)
{
getContext().getApplyResultDRQ().add(o);
super.decRef(o);
void addToReferenceQueue() {
getContext().getApplyResultDRQ().storeReference(getContext(), this);
}
}

View file

@ -17,39 +17,15 @@ Notes:
package com.microsoft.z3;
class ApplyResultDecRefQueue extends IDecRefQueue
class ApplyResultDecRefQueue extends IDecRefQueue<ApplyResult>
{
public ApplyResultDecRefQueue()
{
super();
}
public ApplyResultDecRefQueue(int move_limit)
{
super(move_limit);
}
@Override
protected void incRef(Context ctx, long obj)
{
try
{
Native.applyResultIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
@Override
protected void decRef(Context ctx, long obj)
{
try
{
Native.applyResultDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
protected void decRef(Context ctx, long obj) {
Native.applyResultDecRef(ctx.nCtx(), obj);
}
};

View file

@ -17,39 +17,14 @@ Notes:
package com.microsoft.z3;
class ASTMapDecRefQueue extends IDecRefQueue
{
class ASTMapDecRefQueue extends IDecRefQueue<ASTMap> {
public ASTMapDecRefQueue()
{
super();
}
public ASTMapDecRefQueue(int move_limit)
{
super(move_limit);
}
@Override
protected void incRef(Context ctx, long obj)
{
try
{
Native.astMapIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
protected void decRef(Context ctx, long obj) {
Native.astMapDecRef(ctx.nCtx(), obj);
}
@Override
protected void decRef(Context ctx, long obj)
{
try
{
Native.astMapDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
};
}

View file

@ -17,39 +17,14 @@ Notes:
package com.microsoft.z3;
class ASTVectorDecRefQueue extends IDecRefQueue
{
class ASTVectorDecRefQueue extends IDecRefQueue<ASTVector> {
public ASTVectorDecRefQueue()
{
super();
}
public ASTVectorDecRefQueue(int move_limit)
{
super(move_limit);
}
@Override
protected void incRef(Context ctx, long obj)
{
try
{
Native.astVectorIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
protected void decRef(Context ctx, long obj) {
Native.astVectorDecRef(ctx.nCtx(), obj);
}
@Override
protected void decRef(Context ctx, long obj)
{
try
{
Native.astVectorDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
};
}

View file

@ -66,13 +66,7 @@ public class BitVecNum extends BitVecExpr
@Override
public String toString()
{
try
{
return Native.getNumeralString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
return Native.getNumeralString(getContext().nCtx(), getNativeObject());
}
BitVecNum(Context ctx, long obj)

View file

@ -20,15 +20,7 @@ package com.microsoft.z3;
/**
* Boolean expressions
**/
public class BoolExpr extends Expr
{
/**
* Constructor for BoolExpr
**/
protected BoolExpr(Context ctx)
{
super(ctx);
}
public class BoolExpr extends Expr {
/**
* Constructor for BoolExpr

View file

@ -20,8 +20,14 @@ package com.microsoft.z3;
/**
* Constructors are used for datatype sorts.
**/
public class Constructor extends Z3Object
{
public class Constructor extends Z3Object {
private final int n;
Constructor(Context ctx, int n, long nativeObj) {
super(ctx, nativeObj);
this.n = n;
}
/**
* The number of fields of the constructor.
* @throws Z3Exception
@ -78,29 +84,19 @@ public class Constructor extends Z3Object
return t;
}
/**
* Destructor.
* @throws Throwable
* @throws Z3Exception on error
**/
protected void finalize() throws Throwable
{
try {
Native.delConstructor(getContext().nCtx(), getNativeObject());
} finally {
super.finalize();
}
@Override
void incRef() {
// Datatype constructors are not reference counted.
}
private int n = 0;
@Override
void addToReferenceQueue() {
getContext().getConstructorDRQ().storeReference(getContext(), this);
}
Constructor(Context ctx, Symbol name, Symbol recognizer,
Symbol[] fieldNames, Sort[] sorts, int[] sortRefs)
{
super(ctx);
n = AST.arrayLength(fieldNames);
static Constructor of(Context ctx, Symbol name, Symbol recognizer,
Symbol[] fieldNames, Sort[] sorts, int[] sortRefs) {
int n = AST.arrayLength(fieldNames);
if (n != AST.arrayLength(sorts))
throw new Z3Exception(
@ -112,9 +108,10 @@ public class Constructor extends Z3Object
if (sortRefs == null)
sortRefs = new int[n];
setNativeObject(Native.mkConstructor(ctx.nCtx(), name.getNativeObject(),
long nativeObj = Native.mkConstructor(ctx.nCtx(), name.getNativeObject(),
recognizer.getNativeObject(), n, Symbol.arrayToNative(fieldNames),
Sort.arrayToNative(sorts), sortRefs));
Sort.arrayToNative(sorts), sortRefs);
return new Constructor(ctx, n, nativeObj);
}
}

View file

@ -0,0 +1,12 @@
package com.microsoft.z3;
public class ConstructorDecRefQueue extends IDecRefQueue<Constructor> {
public ConstructorDecRefQueue() {
super();
}
@Override
protected void decRef(Context ctx, long obj) {
Native.delConstructor(ctx.nCtx(), obj);
}
}

View file

@ -20,32 +20,26 @@ package com.microsoft.z3;
/**
* Lists of constructors
**/
public class ConstructorList extends Z3Object
{
/**
* Destructor.
* @throws Throwable
* @throws Z3Exception on error
**/
protected void finalize() throws Throwable
{
try {
Native.delConstructorList(getContext().nCtx(), getNativeObject());
} finally {
super.finalize();
}
}
public class ConstructorList extends Z3Object {
ConstructorList(Context ctx, long obj)
{
super(ctx, obj);
}
@Override
void incRef() {
// Constructor lists are not reference counted.
}
@Override
void addToReferenceQueue() {
getContext().getConstructorListDRQ().storeReference(getContext(), this);
}
ConstructorList(Context ctx, Constructor[] constructors)
{
super(ctx);
setNativeObject(Native.mkConstructorList(getContext().nCtx(),
super(ctx, Native.mkConstructorList(ctx.nCtx(),
constructors.length,
Constructor.arrayToNative(constructors)));
}

View file

@ -0,0 +1,12 @@
package com.microsoft.z3;
public class ConstructorListDecRefQueue extends IDecRefQueue<ConstructorList> {
public ConstructorListDecRefQueue() {
super();
}
@Override
protected void decRef(Context ctx, long obj) {
Native.delConstructorList(ctx.nCtx(), obj);
}
}

View file

@ -17,34 +17,40 @@ Notes:
package com.microsoft.z3;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import static com.microsoft.z3.Constructor.of;
import com.microsoft.z3.enumerations.Z3_ast_print_mode;
import java.util.Map;
/**
* The main interaction with Z3 happens via the Context.
**/
public class Context extends IDisposable
{
/**
* Constructor.
**/
public Context()
{
super();
synchronized (creation_lock) {
public class Context implements AutoCloseable {
private final long m_ctx;
static final Object creation_lock = new Object();
public Context () {
synchronized (creation_lock) {
m_ctx = Native.mkContextRc(0);
initContext();
init();
}
}
protected Context (long m_ctx) {
synchronized (creation_lock) {
this.m_ctx = m_ctx;
init();
}
}
/**
* Constructor.
* Remarks:
* The following parameters can be set:
* The following parameters can be set:
* - proof (Boolean) Enable proof generation
* - debug_ref_count (Boolean) Enable debug support for Z3_ast reference counting
* - debug_ref_count (Boolean) Enable debug support for Z3_ast reference counting
* - trace (Boolean) Tracing support for VCC
* - trace_file_name (String) Trace out file for VCC traces
* - timeout (unsigned) default timeout (in milliseconds) used for solvers
@ -53,22 +59,26 @@ public class Context extends IDisposable
* - model model generation for solvers, this parameter can be overwritten when creating a solver
* - model_validate validate models produced by solvers
* - unsat_core unsat-core generation for solvers, this parameter can be overwritten when creating a solver
* Note that in previous versions of Z3, this constructor was also used to set global and
* Note that in previous versions of Z3, this constructor was also used to set global and
* module parameters. For this purpose we should now use {@code Global.setParameter}
**/
public Context(Map<String, String> settings)
{
super();
synchronized (creation_lock) {
public Context(Map<String, String> settings) {
synchronized (creation_lock) {
long cfg = Native.mkConfig();
for (Map.Entry<String, String> kv : settings.entrySet())
for (Map.Entry<String, String> kv : settings.entrySet()) {
Native.setParamValue(cfg, kv.getKey(), kv.getValue());
}
m_ctx = Native.mkContextRc(cfg);
Native.delConfig(cfg);
initContext();
init();
}
}
private void init() {
setPrintMode(Z3_ast_print_mode.Z3_PRINT_SMTLIB2_COMPLIANT);
Native.setInternalErrorHandler(m_ctx);
}
/**
* Creates a new symbol using an integer.
* Remarks: Not all integers can be passed to this function.
@ -242,7 +252,7 @@ public class Context extends IDisposable
checkContextMatch(name);
checkContextMatch(fieldNames);
checkContextMatch(fieldSorts);
return new TupleSort(this, name, (int) fieldNames.length, fieldNames,
return new TupleSort(this, name, fieldNames.length, fieldNames,
fieldSorts);
}
@ -319,8 +329,7 @@ public class Context extends IDisposable
Symbol[] fieldNames, Sort[] sorts, int[] sortRefs)
{
return new Constructor(this, name, recognizer, fieldNames, sorts,
return of(this, name, recognizer, fieldNames, sorts,
sortRefs);
}
@ -329,10 +338,8 @@ public class Context extends IDisposable
**/
public Constructor mkConstructor(String name, String recognizer,
String[] fieldNames, Sort[] sorts, int[] sortRefs)
{
return new Constructor(this, mkSymbol(name), mkSymbol(recognizer),
return of(this, mkSymbol(name), mkSymbol(recognizer),
mkSymbols(fieldNames), sorts, sortRefs);
}
@ -525,7 +532,7 @@ public class Context extends IDisposable
throw new Z3Exception("Cannot create a pattern from zero terms");
long[] termsNative = AST.arrayToNative(terms);
return new Pattern(this, Native.mkPattern(nCtx(), (int) terms.length,
return new Pattern(this, Native.mkPattern(nCtx(), terms.length,
termsNative));
}
@ -688,7 +695,7 @@ public class Context extends IDisposable
public BoolExpr mkDistinct(Expr... args)
{
checkContextMatch(args);
return new BoolExpr(this, Native.mkDistinct(nCtx(), (int) args.length,
return new BoolExpr(this, Native.mkDistinct(nCtx(), args.length,
AST.arrayToNative(args)));
}
@ -756,7 +763,7 @@ public class Context extends IDisposable
public BoolExpr mkAnd(BoolExpr... t)
{
checkContextMatch(t);
return new BoolExpr(this, Native.mkAnd(nCtx(), (int) t.length,
return new BoolExpr(this, Native.mkAnd(nCtx(), t.length,
AST.arrayToNative(t)));
}
@ -766,7 +773,7 @@ public class Context extends IDisposable
public BoolExpr mkOr(BoolExpr... t)
{
checkContextMatch(t);
return new BoolExpr(this, Native.mkOr(nCtx(), (int) t.length,
return new BoolExpr(this, Native.mkOr(nCtx(), t.length,
AST.arrayToNative(t)));
}
@ -777,7 +784,7 @@ public class Context extends IDisposable
{
checkContextMatch(t);
return (ArithExpr) Expr.create(this,
Native.mkAdd(nCtx(), (int) t.length, AST.arrayToNative(t)));
Native.mkAdd(nCtx(), t.length, AST.arrayToNative(t)));
}
/**
@ -787,7 +794,7 @@ public class Context extends IDisposable
{
checkContextMatch(t);
return (ArithExpr) Expr.create(this,
Native.mkMul(nCtx(), (int) t.length, AST.arrayToNative(t)));
Native.mkMul(nCtx(), t.length, AST.arrayToNative(t)));
}
/**
@ -797,7 +804,7 @@ public class Context extends IDisposable
{
checkContextMatch(t);
return (ArithExpr) Expr.create(this,
Native.mkSub(nCtx(), (int) t.length, AST.arrayToNative(t)));
Native.mkSub(nCtx(), t.length, AST.arrayToNative(t)));
}
/**
@ -1814,7 +1821,7 @@ public class Context extends IDisposable
{
checkContextMatch(args);
return (ArrayExpr)Expr.create(this,
Native.mkSetUnion(nCtx(), (int) args.length,
Native.mkSetUnion(nCtx(), args.length,
AST.arrayToNative(args)));
}
@ -1825,7 +1832,7 @@ public class Context extends IDisposable
{
checkContextMatch(args);
return (ArrayExpr)Expr.create(this,
Native.mkSetIntersect(nCtx(), (int) args.length,
Native.mkSetIntersect(nCtx(), args.length,
AST.arrayToNative(args)));
}
@ -1912,7 +1919,7 @@ public class Context extends IDisposable
public SeqExpr MkConcat(SeqExpr... t)
{
checkContextMatch(t);
return new SeqExpr(this, Native.mkSeqConcat(nCtx(), (int)t.length, AST.arrayToNative(t)));
return new SeqExpr(this, Native.mkSeqConcat(nCtx(), t.length, AST.arrayToNative(t)));
}
@ -2040,7 +2047,7 @@ public class Context extends IDisposable
public ReExpr MkConcat(ReExpr... t)
{
checkContextMatch(t);
return new ReExpr(this, Native.mkReConcat(nCtx(), (int)t.length, AST.arrayToNative(t)));
return new ReExpr(this, Native.mkReConcat(nCtx(), t.length, AST.arrayToNative(t)));
}
/**
@ -2049,7 +2056,7 @@ public class Context extends IDisposable
public ReExpr MkUnion(ReExpr... t)
{
checkContextMatch(t);
return new ReExpr(this, Native.mkReUnion(nCtx(), (int)t.length, AST.arrayToNative(t)));
return new ReExpr(this, Native.mkReUnion(nCtx(), t.length, AST.arrayToNative(t)));
}
@ -2258,7 +2265,7 @@ public class Context extends IDisposable
Symbol quantifierID, Symbol skolemID)
{
return new Quantifier(this, true, sorts, names, body, weight, patterns,
return Quantifier.of(this, true, sorts, names, body, weight, patterns,
noPatterns, quantifierID, skolemID);
}
@ -2271,7 +2278,7 @@ public class Context extends IDisposable
Symbol skolemID)
{
return new Quantifier(this, true, boundConstants, body, weight,
return Quantifier.of(this, true, boundConstants, body, weight,
patterns, noPatterns, quantifierID, skolemID);
}
@ -2284,7 +2291,7 @@ public class Context extends IDisposable
Symbol quantifierID, Symbol skolemID)
{
return new Quantifier(this, false, sorts, names, body, weight,
return Quantifier.of(this, false, sorts, names, body, weight,
patterns, noPatterns, quantifierID, skolemID);
}
@ -2297,7 +2304,7 @@ public class Context extends IDisposable
Symbol skolemID)
{
return new Quantifier(this, false, boundConstants, body, weight,
return Quantifier.of(this, false, boundConstants, body, weight,
patterns, noPatterns, quantifierID, skolemID);
}
@ -3814,7 +3821,7 @@ public class Context extends IDisposable
* must be a native object obtained from Z3 (e.g., through
* {@code UnwrapAST}) and that it must have a correct reference count.
* @see Native#incRef
* @see unwrapAST
* @see #unwrapAST
* @param nativeObject The native pointer to wrap.
**/
public AST wrapAST(long nativeObject)
@ -3869,19 +3876,12 @@ public class Context extends IDisposable
Native.updateParamValue(nCtx(), id, value);
}
protected long m_ctx = 0;
protected static final Object creation_lock = new Object();
long nCtx()
{
return m_ctx;
}
void initContext()
{
setPrintMode(Z3_ast_print_mode.Z3_PRINT_SMTLIB2_COMPLIANT);
Native.setInternalErrorHandler(nCtx());
}
void checkContextMatch(Z3Object other)
{
@ -3910,157 +3910,142 @@ public class Context extends IDisposable
}
private ASTDecRefQueue m_AST_DRQ = new ASTDecRefQueue();
private ASTMapDecRefQueue m_ASTMap_DRQ = new ASTMapDecRefQueue(10);
private ASTVectorDecRefQueue m_ASTVector_DRQ = new ASTVectorDecRefQueue(10);
private ApplyResultDecRefQueue m_ApplyResult_DRQ = new ApplyResultDecRefQueue(10);
private FuncInterpEntryDecRefQueue m_FuncEntry_DRQ = new FuncInterpEntryDecRefQueue(10);
private FuncInterpDecRefQueue m_FuncInterp_DRQ = new FuncInterpDecRefQueue(10);
private GoalDecRefQueue m_Goal_DRQ = new GoalDecRefQueue(10);
private ModelDecRefQueue m_Model_DRQ = new ModelDecRefQueue(10);
private ParamsDecRefQueue m_Params_DRQ = new ParamsDecRefQueue(10);
private ParamDescrsDecRefQueue m_ParamDescrs_DRQ = new ParamDescrsDecRefQueue(10);
private ProbeDecRefQueue m_Probe_DRQ = new ProbeDecRefQueue(10);
private SolverDecRefQueue m_Solver_DRQ = new SolverDecRefQueue(10);
private StatisticsDecRefQueue m_Statistics_DRQ = new StatisticsDecRefQueue(10);
private TacticDecRefQueue m_Tactic_DRQ = new TacticDecRefQueue(10);
private FixedpointDecRefQueue m_Fixedpoint_DRQ = new FixedpointDecRefQueue(10);
private OptimizeDecRefQueue m_Optimize_DRQ = new OptimizeDecRefQueue(10);
private ASTMapDecRefQueue m_ASTMap_DRQ = new ASTMapDecRefQueue();
private ASTVectorDecRefQueue m_ASTVector_DRQ = new ASTVectorDecRefQueue();
private ApplyResultDecRefQueue m_ApplyResult_DRQ = new ApplyResultDecRefQueue();
private FuncInterpEntryDecRefQueue m_FuncEntry_DRQ = new FuncInterpEntryDecRefQueue();
private FuncInterpDecRefQueue m_FuncInterp_DRQ = new FuncInterpDecRefQueue();
private GoalDecRefQueue m_Goal_DRQ = new GoalDecRefQueue();
private ModelDecRefQueue m_Model_DRQ = new ModelDecRefQueue();
private ParamsDecRefQueue m_Params_DRQ = new ParamsDecRefQueue();
private ParamDescrsDecRefQueue m_ParamDescrs_DRQ = new ParamDescrsDecRefQueue();
private ProbeDecRefQueue m_Probe_DRQ = new ProbeDecRefQueue();
private SolverDecRefQueue m_Solver_DRQ = new SolverDecRefQueue();
private StatisticsDecRefQueue m_Statistics_DRQ = new StatisticsDecRefQueue();
private TacticDecRefQueue m_Tactic_DRQ = new TacticDecRefQueue();
private FixedpointDecRefQueue m_Fixedpoint_DRQ = new FixedpointDecRefQueue();
private OptimizeDecRefQueue m_Optimize_DRQ = new OptimizeDecRefQueue();
private ConstructorDecRefQueue m_Constructor_DRQ = new ConstructorDecRefQueue();
private ConstructorListDecRefQueue m_ConstructorList_DRQ =
new ConstructorListDecRefQueue();
public IDecRefQueue getASTDRQ()
public IDecRefQueue<Constructor> getConstructorDRQ() {
return m_Constructor_DRQ;
}
public IDecRefQueue<ConstructorList> getConstructorListDRQ() {
return m_ConstructorList_DRQ;
}
public IDecRefQueue<AST> getASTDRQ()
{
return m_AST_DRQ;
}
public IDecRefQueue getASTMapDRQ()
public IDecRefQueue<ASTMap> getASTMapDRQ()
{
return m_ASTMap_DRQ;
}
public IDecRefQueue getASTVectorDRQ()
public IDecRefQueue<ASTVector> getASTVectorDRQ()
{
return m_ASTVector_DRQ;
}
public IDecRefQueue getApplyResultDRQ()
public IDecRefQueue<ApplyResult> getApplyResultDRQ()
{
return m_ApplyResult_DRQ;
}
public IDecRefQueue getFuncEntryDRQ()
public IDecRefQueue<FuncInterp.Entry> getFuncEntryDRQ()
{
return m_FuncEntry_DRQ;
}
public IDecRefQueue getFuncInterpDRQ()
public IDecRefQueue<FuncInterp> getFuncInterpDRQ()
{
return m_FuncInterp_DRQ;
}
public IDecRefQueue getGoalDRQ()
public IDecRefQueue<Goal> getGoalDRQ()
{
return m_Goal_DRQ;
}
public IDecRefQueue getModelDRQ()
public IDecRefQueue<Model> getModelDRQ()
{
return m_Model_DRQ;
}
public IDecRefQueue getParamsDRQ()
public IDecRefQueue<Params> getParamsDRQ()
{
return m_Params_DRQ;
}
public IDecRefQueue getParamDescrsDRQ()
public IDecRefQueue<ParamDescrs> getParamDescrsDRQ()
{
return m_ParamDescrs_DRQ;
}
public IDecRefQueue getProbeDRQ()
public IDecRefQueue<Probe> getProbeDRQ()
{
return m_Probe_DRQ;
}
public IDecRefQueue getSolverDRQ()
public IDecRefQueue<Solver> getSolverDRQ()
{
return m_Solver_DRQ;
}
public IDecRefQueue getStatisticsDRQ()
public IDecRefQueue<Statistics> getStatisticsDRQ()
{
return m_Statistics_DRQ;
}
public IDecRefQueue getTacticDRQ()
public IDecRefQueue<Tactic> getTacticDRQ()
{
return m_Tactic_DRQ;
}
public IDecRefQueue getFixedpointDRQ()
public IDecRefQueue<Fixedpoint> getFixedpointDRQ()
{
return m_Fixedpoint_DRQ;
}
public IDecRefQueue getOptimizeDRQ()
public IDecRefQueue<Optimize> getOptimizeDRQ()
{
return m_Optimize_DRQ;
}
protected AtomicInteger m_refCount = new AtomicInteger(0);
/**
* Finalizer.
* @throws Throwable
**/
protected void finalize() throws Throwable
{
try {
dispose();
}
catch (Throwable t) {
throw t;
}
finally {
super.finalize();
}
}
/**
* Disposes of the context.
**/
public void dispose()
@Override
public void close()
{
m_AST_DRQ.clear(this);
m_ASTMap_DRQ.clear(this);
m_ASTVector_DRQ.clear(this);
m_ApplyResult_DRQ.clear(this);
m_FuncEntry_DRQ.clear(this);
m_FuncInterp_DRQ.clear(this);
m_Goal_DRQ.clear(this);
m_Model_DRQ.clear(this);
m_Params_DRQ.clear(this);
m_Probe_DRQ.clear(this);
m_Solver_DRQ.clear(this);
m_Optimize_DRQ.clear(this);
m_Statistics_DRQ.clear(this);
m_Tactic_DRQ.clear(this);
m_Fixedpoint_DRQ.clear(this);
m_AST_DRQ.forceClear(this);
m_ASTMap_DRQ.forceClear(this);
m_ASTVector_DRQ.forceClear(this);
m_ApplyResult_DRQ.forceClear(this);
m_FuncEntry_DRQ.forceClear(this);
m_FuncInterp_DRQ.forceClear(this);
m_Goal_DRQ.forceClear(this);
m_Model_DRQ.forceClear(this);
m_Params_DRQ.forceClear(this);
m_Probe_DRQ.forceClear(this);
m_Solver_DRQ.forceClear(this);
m_Optimize_DRQ.forceClear(this);
m_Statistics_DRQ.forceClear(this);
m_Tactic_DRQ.forceClear(this);
m_Fixedpoint_DRQ.forceClear(this);
m_boolSort = null;
m_intSort = null;
m_realSort = null;
m_stringSort = null;
synchronized (creation_lock) {
if (m_refCount.get() == 0 && m_ctx != 0) {
try {
Native.delContext(m_ctx);
} catch (Z3Exception e) {
// OK?
System.out.println("Context deletion failed; memory leak possible.");
}
m_ctx = 0;
}
Native.delContext(m_ctx);
}
}
}

View file

@ -92,13 +92,9 @@ public class EnumSort extends Sort
EnumSort(Context ctx, Symbol name, Symbol[] enumNames)
{
super(ctx, 0);
int n = enumNames.length;
long[] n_constdecls = new long[n];
long[] n_testers = new long[n];
setNativeObject(Native.mkEnumerationSort(ctx.nCtx(),
name.getNativeObject(), n, Symbol.arrayToNative(enumNames),
n_constdecls, n_testers));
super(ctx, Native.mkEnumerationSort(ctx.nCtx(),
name.getNativeObject(), enumNames.length,
Symbol.arrayToNative(enumNames),
new long[enumNames.length], new long[enumNames.length]));
}
};

View file

@ -120,13 +120,13 @@ public class Expr extends AST
* @param args arguments
* @throws Z3Exception on error
**/
public void update(Expr[] args)
public Expr update(Expr[] args)
{
getContext().checkContextMatch(args);
if (isApp() && args.length != getNumArgs()) {
throw new Z3Exception("Number of arguments does not match");
}
setNativeObject(Native.updateTerm(getContext().nCtx(), getNativeObject(),
return new Expr(getContext(), Native.updateTerm(getContext().nCtx(), getNativeObject(),
args.length, Expr.arrayToNative(args)));
}
@ -2091,36 +2091,23 @@ public class Expr extends AST
**/
public int getIndex()
{
if (!isVar())
if (!isVar()) {
throw new Z3Exception("Term is not a bound variable.");
}
return Native.getIndexValue(getContext().nCtx(), getNativeObject());
}
/**
* Constructor for Expr
**/
protected Expr(Context ctx)
{
super(ctx);
{
}
}
/**
* Constructor for Expr
* @throws Z3Exception on error
**/
protected Expr(Context ctx, long obj)
{
protected Expr(Context ctx, long obj) {
super(ctx, obj);
{
}
}
@Override
void checkNativeObject(long obj)
{
void checkNativeObject(long obj) {
if (!Native.isApp(getContext().nCtx(), obj) &&
Native.getAstKind(getContext().nCtx(), obj) != Z3_ast_kind.Z3_VAR_AST.toInt() &&
Native.getAstKind(getContext().nCtx(), obj) != Z3_ast_kind.Z3_QUANTIFIER_AST.toInt()) {

View file

@ -20,7 +20,7 @@ package com.microsoft.z3;
* FloatingPoint Numerals
*/
public class FPNum extends FPExpr
{
{
/**
* Retrieves the sign of a floating-point literal
* Remarks: returns true if the numeral is negative
@ -28,11 +28,20 @@ public class FPNum extends FPExpr
*/
public boolean getSign() {
Native.IntPtr res = new Native.IntPtr();
if (Native.fpaGetNumeralSign(getContext().nCtx(), getNativeObject(), res) ^ true)
if (!Native.fpaGetNumeralSign(getContext().nCtx(), getNativeObject(), res))
throw new Z3Exception("Sign is not a Boolean value");
return res.value != 0;
}
/**
* The sign of a floating-point numeral as a bit-vector expression
* Remarks: NaN's do not have a bit-vector sign, so they are invalid arguments.
* @throws Z3Exception
*/
public BitVecExpr getSignBV() {
return new BitVecExpr(getContext(), Native.fpaGetNumeralSignBv(getContext().nCtx(), getNativeObject()));
}
/**
* The significand value of a floating-point numeral as a string
* Remarks: The significand s is always 0 &lt; s &lt; 2.0; the resulting string is long
@ -53,29 +62,121 @@ public class FPNum extends FPExpr
public long getSignificandUInt64()
{
Native.LongPtr res = new Native.LongPtr();
if (Native.fpaGetNumeralSignificandUint64(getContext().nCtx(), getNativeObject(), res) ^ true)
if (!Native.fpaGetNumeralSignificandUint64(getContext().nCtx(), getNativeObject(), res))
throw new Z3Exception("Significand is not a 64 bit unsigned integer");
return res.value;
}
/**
* The significand of a floating-point numeral as a bit-vector expression
* Remarks: NaN is an invalid argument.
* @throws Z3Exception
*/
public BitVecExpr getSignificandBV() {
return new BitVecExpr(getContext(), Native.fpaGetNumeralSignificandBv(getContext().nCtx(), getNativeObject()));
}
/**
* Return the exponent value of a floating-point numeral as a string
* Remarks: NaN is an invalid argument.
* @throws Z3Exception
*/
public String getExponent() {
return Native.fpaGetNumeralExponentString(getContext().nCtx(), getNativeObject());
public String getExponent(boolean biased) {
return Native.fpaGetNumeralExponentString(getContext().nCtx(), getNativeObject(), biased);
}
/**
* Return the exponent value of a floating-point numeral as a signed 64-bit integer
* Remarks: NaN is an invalid argument.
* @throws Z3Exception
*/
public long getExponentInt64() {
public long getExponentInt64(boolean biased) {
Native.LongPtr res = new Native.LongPtr();
if (Native.fpaGetNumeralExponentInt64(getContext().nCtx(), getNativeObject(), res) ^ true)
if (!Native.fpaGetNumeralExponentInt64(getContext().nCtx(), getNativeObject(), res, biased))
throw new Z3Exception("Exponent is not a 64 bit integer");
return res.value;
}
/**
* The exponent of a floating-point numeral as a bit-vector expression
* Remarks: NaN is an invalid argument.
* @throws Z3Exception
*/
public BitVecExpr getExponentBV(boolean biased) {
return new BitVecExpr(getContext(), Native.fpaGetNumeralExponentBv(getContext().nCtx(), getNativeObject(), biased));
}
/**
* Indicates whether the numeral is a NaN.
* @throws Z3Exception on error
* @return a boolean
**/
public boolean isNaN()
{
return Native.fpaIsNumeralNan(getContext().nCtx(), getNativeObject());
}
/**
* Indicates whether the numeral is a +oo or -oo.
* @throws Z3Exception on error
* @return a boolean
**/
public boolean isInf()
{
return Native.fpaIsNumeralInf(getContext().nCtx(), getNativeObject());
}
/**
* Indicates whether the numeral is +zero or -zero.
* @throws Z3Exception on error
* @return a boolean
**/
public boolean isZero()
{
return Native.fpaIsNumeralZero(getContext().nCtx(), getNativeObject());
}
/**
* Indicates whether the numeral is normal.
* @throws Z3Exception on error
* @return a boolean
**/
public boolean isNormal()
{
return Native.fpaIsNumeralNormal(getContext().nCtx(), getNativeObject());
}
/**
* Indicates whether the numeral is subnormal.
* @throws Z3Exception on error
* @return a boolean
**/
public boolean isSubnormal()
{
return Native.fpaIsNumeralSubnormal(getContext().nCtx(), getNativeObject());
}
/**
* Indicates whether the numeral is positive.
* @throws Z3Exception on error
* @return a boolean
**/
public boolean isPositive()
{
return Native.fpaIsNumeralPositive(getContext().nCtx(), getNativeObject());
}
/**
* Indicates whether the numeral is negative.
* @throws Z3Exception on error
* @return a boolean
**/
public boolean isNegative()
{
return Native.fpaIsNumeralNegative(getContext().nCtx(), getNativeObject());
}
public FPNum(Context ctx, long obj)
{
@ -87,13 +188,6 @@ public class FPNum extends FPExpr
*/
public String toString()
{
try
{
return Native.getNumeralString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
return Native.getNumeralString(getContext().nCtx(), getNativeObject());
}
}

View file

@ -68,12 +68,6 @@ public class FiniteDomainNum extends FiniteDomainExpr
@Override
public String toString()
{
try
{
return Native.getNumeralString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
return Native.getNumeralString(getContext().nCtx(), getNativeObject());
}
}

View file

@ -87,12 +87,11 @@ public class Fixedpoint extends Z3Object
/**
* Add rule into the fixedpoint solver.
*
*
* @param name Nullable rule name.
* @throws Z3Exception
**/
public void addRule(BoolExpr rule, Symbol name)
{
public void addRule(BoolExpr rule, Symbol name) {
getContext().checkContextMatch(rule);
Native.fixedpointAddRule(getContext().nCtx(), getNativeObject(),
rule.getNativeObject(), AST.getNativeObject(name));
@ -103,11 +102,10 @@ public class Fixedpoint extends Z3Object
*
* @throws Z3Exception
**/
public void addFact(FuncDecl pred, int ... args)
{
public void addFact(FuncDecl pred, int ... args) {
getContext().checkContextMatch(pred);
Native.fixedpointAddFact(getContext().nCtx(), getNativeObject(),
pred.getNativeObject(), (int) args.length, args);
pred.getNativeObject(), args.length, args);
}
/**
@ -119,9 +117,7 @@ public class Fixedpoint extends Z3Object
*
* @throws Z3Exception
**/
public Status query(BoolExpr query)
{
public Status query(BoolExpr query) {
getContext().checkContextMatch(query);
Z3_lbool r = Z3_lbool.fromInt(Native.fixedpointQuery(getContext().nCtx(),
getNativeObject(), query.getNativeObject()));
@ -144,9 +140,7 @@ public class Fixedpoint extends Z3Object
*
* @throws Z3Exception
**/
public Status query(FuncDecl[] relations)
{
public Status query(FuncDecl[] relations) {
getContext().checkContextMatch(relations);
Z3_lbool r = Z3_lbool.fromInt(Native.fixedpointQueryRelations(getContext()
.nCtx(), getNativeObject(), AST.arrayLength(relations), AST
@ -166,8 +160,7 @@ public class Fixedpoint extends Z3Object
* Creates a backtracking point.
* @see #pop
**/
public void push()
{
public void push() {
Native.fixedpointPush(getContext().nCtx(), getNativeObject());
}
@ -178,19 +171,17 @@ public class Fixedpoint extends Z3Object
*
* @see #push
**/
public void pop()
{
public void pop() {
Native.fixedpointPop(getContext().nCtx(), getNativeObject());
}
/**
* Update named rule into in the fixedpoint solver.
*
*
* @param name Nullable rule name.
* @throws Z3Exception
**/
public void updateRule(BoolExpr rule, Symbol name)
{
public void updateRule(BoolExpr rule, Symbol name) {
getContext().checkContextMatch(rule);
Native.fixedpointUpdateRule(getContext().nCtx(), getNativeObject(),
rule.getNativeObject(), AST.getNativeObject(name));
@ -255,14 +246,8 @@ public class Fixedpoint extends Z3Object
@Override
public String toString()
{
try
{
return Native.fixedpointToString(getContext().nCtx(), getNativeObject(),
return Native.fixedpointToString(getContext().nCtx(), getNativeObject(),
0, null);
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
}
/**
@ -355,16 +340,15 @@ public class Fixedpoint extends Z3Object
}
@Override
void incRef(long o)
{
getContext().getFixedpointDRQ().incAndClear(getContext(), o);
super.incRef(o);
void incRef() {
Native.fixedpointIncRef(getContext().nCtx(), getNativeObject());
}
@Override
void decRef(long o)
{
getContext().getFixedpointDRQ().add(o);
super.decRef(o);
void addToReferenceQueue() {
getContext().getFixedpointDRQ().storeReference(getContext(), this);
}
@Override
void checkNativeObject(long obj) { }
}

View file

@ -17,39 +17,15 @@ Notes:
package com.microsoft.z3;
class FixedpointDecRefQueue extends IDecRefQueue
{
class FixedpointDecRefQueue extends IDecRefQueue<Fixedpoint> {
public FixedpointDecRefQueue()
{
super();
}
public FixedpointDecRefQueue(int move_limit)
{
super(move_limit);
}
@Override
protected void incRef(Context ctx, long obj)
{
try
{
Native.fixedpointIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
@Override
protected void decRef(Context ctx, long obj)
{
try
{
Native.fixedpointDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
Native.fixedpointDecRef(ctx.nCtx(), obj);
}
};

View file

@ -47,13 +47,7 @@ public class FuncDecl extends AST
@Override
public String toString()
{
try
{
return Native.funcDeclToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
return Native.funcDeclToString(getContext().nCtx(), getNativeObject());
}
/**

View file

@ -22,20 +22,20 @@ package com.microsoft.z3;
* Each entry in the finite map represents the value of a function given a set
* of arguments.
**/
public class FuncInterp extends Z3Object
{
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
{
public static class Entry extends Z3Object {
/**
* Return the (symbolic) value of this entry.
*
*
* @throws Z3Exception
* @throws Z3Exception on error
**/
**/
public Expr getValue()
{
return Expr.create(getContext(),
@ -45,7 +45,7 @@ public class FuncInterp extends Z3Object
/**
* The number of arguments of the entry.
* @throws Z3Exception on error
**/
**/
public int getNumArgs()
{
return Native.funcEntryGetNumArgs(getContext().nCtx(), getNativeObject());
@ -53,10 +53,10 @@ public class FuncInterp extends Z3Object
/**
* The arguments of the function entry.
*
*
* @throws Z3Exception
* @throws Z3Exception on error
**/
**/
public Expr[] getArgs()
{
int n = getNumArgs();
@ -73,37 +73,26 @@ public class FuncInterp extends Z3Object
@Override
public String toString()
{
try
{
int n = getNumArgs();
String res = "[";
Expr[] args = getArgs();
for (int i = 0; i < n; i++)
res += args[i] + ", ";
return res + getValue() + "]";
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
int n = getNumArgs();
String res = "[";
Expr[] args = getArgs();
for (int i = 0; i < n; i++)
res += args[i] + ", ";
return res + getValue() + "]";
}
Entry(Context ctx, long obj)
{
Entry(Context ctx, long obj) {
super(ctx, obj);
}
@Override
void incRef(long o)
{
getContext().getFuncEntryDRQ().incAndClear(getContext(), o);
super.incRef(o);
void incRef() {
Native.funcEntryIncRef(getContext().nCtx(), getNativeObject());
}
@Override
void decRef(long o)
{
getContext().getFuncEntryDRQ().add(o);
super.decRef(o);
void addToReferenceQueue() {
getContext().getFuncEntryDRQ().storeReference(getContext(), this);
}
}
@ -161,33 +150,27 @@ public class FuncInterp extends Z3Object
**/
public String toString()
{
try
String res = "";
res += "[";
for (Entry e : getEntries())
{
String res = "";
res += "[";
for (Entry e : getEntries())
int n = e.getNumArgs();
if (n > 1)
res += "[";
Expr[] args = e.getArgs();
for (int i = 0; i < n; i++)
{
int n = e.getNumArgs();
if (n > 1)
res += "[";
Expr[] args = e.getArgs();
for (int i = 0; i < n; i++)
{
if (i != 0)
res += ", ";
res += args[i];
}
if (n > 1)
res += "]";
res += " -> " + e.getValue() + ", ";
if (i != 0)
res += ", ";
res += args[i];
}
res += "else -> " + getElse();
res += "]";
return res;
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
if (n > 1)
res += "]";
res += " -> " + e.getValue() + ", ";
}
res += "else -> " + getElse();
res += "]";
return res;
}
FuncInterp(Context ctx, long obj)
@ -196,16 +179,12 @@ public class FuncInterp extends Z3Object
}
@Override
void incRef(long o)
{
getContext().getFuncInterpDRQ().incAndClear(getContext(), o);
super.incRef(o);
void incRef() {
Native.funcInterpIncRef(getContext().nCtx(), getNativeObject());
}
@Override
void decRef(long o)
{
getContext().getFuncInterpDRQ().add(o);
super.decRef(o);
void addToReferenceQueue() {
getContext().getFuncInterpDRQ().storeReference(getContext(), this);
}
}

View file

@ -17,39 +17,15 @@ Notes:
package com.microsoft.z3;
class FuncInterpDecRefQueue extends IDecRefQueue
class FuncInterpDecRefQueue extends IDecRefQueue<FuncInterp>
{
public FuncInterpDecRefQueue()
{
super();
}
public FuncInterpDecRefQueue(int move_limit)
{
super(move_limit);
}
@Override
protected void incRef(Context ctx, long obj)
{
try
{
Native.funcInterpIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
@Override
protected void decRef(Context ctx, long obj)
{
try
{
Native.funcInterpDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
protected void decRef(Context ctx, long obj) {
Native.funcInterpDecRef(ctx.nCtx(), obj);
}
};

View file

@ -17,39 +17,14 @@ Notes:
package com.microsoft.z3;
class FuncInterpEntryDecRefQueue extends IDecRefQueue
{
class FuncInterpEntryDecRefQueue extends IDecRefQueue<FuncInterp.Entry> {
public FuncInterpEntryDecRefQueue()
{
super();
}
public FuncInterpEntryDecRefQueue(int move_limit)
{
super(move_limit);
}
@Override
protected void incRef(Context ctx, long obj)
{
try
{
Native.funcEntryIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
protected void decRef(Context ctx, long obj) {
Native.funcEntryDecRef(ctx.nCtx(), obj);
}
@Override
protected void decRef(Context ctx, long obj)
{
try
{
Native.funcEntryDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
};
}

View file

@ -23,8 +23,7 @@ import com.microsoft.z3.enumerations.Z3_goal_prec;
* 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
{
public class Goal extends Z3Object {
/**
* The precision of the goal.
* Remarks: Goals can be transformed using over
@ -211,15 +210,8 @@ public class Goal extends Z3Object
*
* @return A string representation of the Goal.
**/
public String toString()
{
try
{
return Native.goalToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
public String toString() {
return Native.goalToString(getContext().nCtx(), getNativeObject());
}
/**
@ -229,11 +221,11 @@ public class Goal extends Z3Object
**/
public BoolExpr AsBoolExpr() {
int n = size();
if (n == 0)
if (n == 0) {
return getContext().mkTrue();
else if (n == 1)
} else if (n == 1) {
return getFormulas()[0];
else {
} else {
return getContext().mkAnd(getFormulas());
}
}
@ -243,23 +235,18 @@ public class Goal extends Z3Object
super(ctx, obj);
}
Goal(Context ctx, boolean models, boolean unsatCores, boolean proofs)
{
Goal(Context ctx, boolean models, boolean unsatCores, boolean proofs) {
super(ctx, Native.mkGoal(ctx.nCtx(), (models),
(unsatCores), (proofs)));
}
void incRef(long o)
{
getContext().getGoalDRQ().incAndClear(getContext(), o);
super.incRef(o);
@Override
void incRef() {
Native.goalIncRef(getContext().nCtx(), getNativeObject());
}
void decRef(long o)
{
getContext().getGoalDRQ().add(o);
super.decRef(o);
@Override
void addToReferenceQueue() {
getContext().getGoalDRQ().storeReference(getContext(), this);
}
}

View file

@ -17,39 +17,14 @@ Notes:
package com.microsoft.z3;
class GoalDecRefQueue extends IDecRefQueue
{
class GoalDecRefQueue extends IDecRefQueue<Goal> {
public GoalDecRefQueue()
{
super();
}
public GoalDecRefQueue(int move_limit)
{
super(move_limit);
}
@Override
protected void incRef(Context ctx, long obj)
{
try
{
Native.goalIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
@Override
protected void decRef(Context ctx, long obj)
{
try
{
protected void decRef(Context ctx, long obj) {
Native.goalDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
};
}

View file

@ -17,55 +17,67 @@ Notes:
package com.microsoft.z3;
import java.util.LinkedList;
import java.lang.ref.PhantomReference;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.util.IdentityHashMap;
import java.util.Map;
public abstract class IDecRefQueue
{
protected final Object m_lock = new Object();
protected LinkedList<Long> m_queue = new LinkedList<Long>();
protected int m_move_limit;
/**
* A queue to handle management of native memory.
*
* <p><b>Mechanics: </b>once an object is created, a metadata is stored for it in
* {@code referenceMap}, and a {@link PhantomReference} is created with a
* reference to {@code referenceQueue}.
* Once the object becomes strongly unreachable, the phantom reference gets
* added by JVM to the {@code referenceQueue}.
* After each object creation, we iterate through the available objects in
* {@code referenceQueue} and decrement references for them.
*
* @param <T> Type of object stored in queue.
*/
public abstract class IDecRefQueue<T extends Z3Object> {
private final ReferenceQueue<T> referenceQueue = new ReferenceQueue<>();
private final Map<PhantomReference<T>, Long> referenceMap =
new IdentityHashMap<>();
protected IDecRefQueue()
{
m_move_limit = 1024;
}
protected IDecRefQueue(int move_limit)
{
m_move_limit = move_limit;
}
public void setLimit(int l) { m_move_limit = l; }
protected abstract void incRef(Context ctx, long obj);
protected IDecRefQueue() {}
/**
* An implementation of this method should decrement the reference on a
* given native object.
* This function should always be called on the {@code ctx} thread.
*
* @param ctx Z3 context.
* @param obj Pointer to a Z3 object.
*/
protected abstract void decRef(Context ctx, long obj);
protected void incAndClear(Context ctx, long o)
{
incRef(ctx, o);
if (m_queue.size() >= m_move_limit)
clear(ctx);
public void storeReference(Context ctx, T obj) {
PhantomReference<T> ref = new PhantomReference<>(obj, referenceQueue);
referenceMap.put(ref, obj.getNativeObject());
clear(ctx);
}
protected void add(long o)
/**
* Clean all references currently in {@code referenceQueue}.
*/
protected void clear(Context ctx)
{
if (o == 0)
return;
synchronized (m_lock)
{
m_queue.add(o);
Reference<? extends T> ref;
while ((ref = referenceQueue.poll()) != null) {
long z3ast = referenceMap.remove(ref);
decRef(ctx, z3ast);
}
}
protected void clear(Context ctx)
{
synchronized (m_lock)
{
for (Long o : m_queue)
decRef(ctx, o);
m_queue.clear();
/**
* Clean all references stored in {@code referenceMap},
* <b>regardless</b> of whether they are in {@code referenceMap} or not.
*/
public void forceClear(Context ctx) {
for (long ref : referenceMap.values()) {
decRef(ctx, ref);
}
}
}

View file

@ -1,25 +0,0 @@
/*++
Copyright (c) 2012 Microsoft Corporation
Module Name:
IDisposable.java
Abstract:
Compatability interface (C# -> Java)
Author:
Christoph Wintersteiger (cwinter) 2012-03-16
Notes:
--*/
package com.microsoft.z3;
public abstract class IDisposable
{
public abstract void dispose();
}

View file

@ -63,14 +63,7 @@ public class IntNum extends IntExpr
/**
* Returns a string representation of the numeral.
**/
public String toString()
{
try
{
return Native.getNumeralString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
public String toString() {
return Native.getNumeralString(getContext().nCtx(), getNativeObject());
}
}

View file

@ -17,11 +17,10 @@ Notes:
package com.microsoft.z3;
import java.util.Map;
import java.lang.String;
import com.microsoft.z3.enumerations.Z3_lbool;
import java.util.Map;
/**
* The InterpolationContext is suitable for generation of interpolants.
*
@ -33,13 +32,13 @@ public class InterpolationContext extends Context
/**
* Constructor.
**/
public InterpolationContext()
public static InterpolationContext mkContext()
{
super();
long m_ctx;
synchronized(creation_lock) {
m_ctx = Native.mkInterpolationContext(0);
initContext();
}
return new InterpolationContext(m_ctx);
}
/**
@ -49,17 +48,21 @@ public class InterpolationContext extends Context
* Remarks:
* @see Context#Context
**/
public InterpolationContext(Map<String, String> settings)
public static InterpolationContext mkContext(Map<String, String> settings)
{
super();
long m_ctx;
synchronized(creation_lock) {
long cfg = Native.mkConfig();
for (Map.Entry<String, String> kv : settings.entrySet())
Native.setParamValue(cfg, kv.getKey(), kv.getValue());
m_ctx = Native.mkInterpolationContext(cfg);
Native.delConfig(cfg);
initContext();
}
return new InterpolationContext(m_ctx);
}
private InterpolationContext(long m_ctx) {
super(m_ctx);
}
/**

View file

@ -17,6 +17,8 @@ Notes:
package com.microsoft.z3;
import com.microsoft.z3.Native.LongPtr;
/**
* List sorts.
**/
@ -88,14 +90,9 @@ public class ListSort extends Sort
ListSort(Context ctx, Symbol name, Sort elemSort)
{
super(ctx, 0);
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.getNativeObject(),
elemSort.getNativeObject(), inil, iisnil, icons, iiscons, ihead,
itail));
super(ctx, Native.mkListSort(ctx.nCtx(), name.getNativeObject(),
elemSort.getNativeObject(),
new LongPtr(), new Native.LongPtr(), new LongPtr(),
new LongPtr(), new LongPtr(), new LongPtr()));
}
};

View file

@ -22,8 +22,7 @@ import com.microsoft.z3.enumerations.Z3_sort_kind;
/**
* A Model contains interpretations (assignments) of constants and functions.
**/
public class Model extends Z3Object
{
public class Model extends Z3Object {
/**
* Retrieves the interpretation (the assignment) of {@code a} in
* the model.
@ -283,15 +282,8 @@ public class Model extends Z3Object
* @return A string representation of the model.
**/
@Override
public String toString()
{
try
{
return Native.modelToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
public String toString() {
return Native.modelToString(getContext().nCtx(), getNativeObject());
}
Model(Context ctx, long obj)
@ -300,16 +292,12 @@ public class Model extends Z3Object
}
@Override
void incRef(long o)
{
getContext().getModelDRQ().incAndClear(getContext(), o);
super.incRef(o);
void incRef() {
Native.modelIncRef(getContext().nCtx(), getNativeObject());
}
@Override
void decRef(long o)
{
getContext().getModelDRQ().add(o);
super.decRef(o);
void addToReferenceQueue() {
getContext().getModelDRQ().storeReference(getContext(), this);
}
}

View file

@ -17,39 +17,14 @@ Notes:
package com.microsoft.z3;
class ModelDecRefQueue extends IDecRefQueue
{
class ModelDecRefQueue extends IDecRefQueue<Model> {
public ModelDecRefQueue()
{
super();
}
public ModelDecRefQueue(int move_limit)
{
super(move_limit);
}
@Override
protected void incRef(Context ctx, long obj)
{
try
{
Native.modelIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
protected void decRef(Context ctx, long obj) {
Native.modelDecRef(ctx.nCtx(), obj);
}
@Override
protected void decRef(Context ctx, long obj)
{
try
{
Native.modelDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
};
}

View file

@ -266,17 +266,12 @@ public class Optimize extends Z3Object
}
@Override
void incRef(long o)
{
getContext().getOptimizeDRQ().incAndClear(getContext(), o);
super.incRef(o);
void incRef() {
Native.optimizeIncRef(getContext().nCtx(), getNativeObject());
}
@Override
void decRef(long o)
{
getContext().getOptimizeDRQ().add(o);
super.decRef(o);
void addToReferenceQueue() {
getContext().getOptimizeDRQ().storeReference(getContext(), this);
}
}

View file

@ -17,39 +17,14 @@ Notes:
package com.microsoft.z3;
class OptimizeDecRefQueue extends IDecRefQueue
{
class OptimizeDecRefQueue extends IDecRefQueue<Optimize> {
public OptimizeDecRefQueue()
{
super();
}
public OptimizeDecRefQueue(int move_limit)
{
super(move_limit);
}
@Override
protected void incRef(Context ctx, long obj)
{
try
{
Native.fixedpointIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
@Override
protected void decRef(Context ctx, long obj)
{
try
{
Native.fixedpointDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
protected void decRef(Context ctx, long obj) {
Native.optimizeDecRef(ctx.nCtx(), obj);
}
};

View file

@ -22,8 +22,7 @@ import com.microsoft.z3.enumerations.Z3_param_kind;
/**
* A ParamDescrs describes a set of parameters.
**/
public class ParamDescrs extends Z3Object
{
public class ParamDescrs extends Z3Object {
/**
* validate a set of parameters.
**/
@ -82,15 +81,8 @@ public class ParamDescrs extends Z3Object
* Retrieves a string representation of the ParamDescrs.
**/
@Override
public String toString()
{
try
{
return Native.paramDescrsToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
public String toString() {
return Native.paramDescrsToString(getContext().nCtx(), getNativeObject());
}
ParamDescrs(Context ctx, long obj)
@ -99,16 +91,12 @@ public class ParamDescrs extends Z3Object
}
@Override
void incRef(long o)
{
getContext().getParamDescrsDRQ().incAndClear(getContext(), o);
super.incRef(o);
void incRef() {
Native.paramDescrsIncRef(getContext().nCtx(), getNativeObject());
}
@Override
void decRef(long o)
{
getContext().getParamDescrsDRQ().add(o);
super.decRef(o);
void addToReferenceQueue() {
getContext().getParamDescrsDRQ().storeReference(getContext(), this);
}
}

View file

@ -17,39 +17,15 @@ Notes:
package com.microsoft.z3;
class ParamDescrsDecRefQueue extends IDecRefQueue
{
class ParamDescrsDecRefQueue extends IDecRefQueue<ParamDescrs> {
public ParamDescrsDecRefQueue()
{
super();
}
public ParamDescrsDecRefQueue(int move_limit)
{
super(move_limit);
}
@Override
protected void incRef(Context ctx, long obj)
{
try
{
Native.paramDescrsIncRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
}
@Override
protected void decRef(Context ctx, long obj)
{
try
{
Native.paramDescrsDecRef(ctx.nCtx(), obj);
} catch (Z3Exception e)
{
// OK.
}
Native.paramDescrsDecRef(ctx.nCtx(), obj);
}
};
}

View file

@ -21,8 +21,7 @@ package com.microsoft.z3;
/**
* A ParameterSet represents a configuration in the form of Symbol/value pairs.
**/
public class Params extends Z3Object
{
public class Params extends Z3Object {
/**
* Adds a parameter setting.
**/
@ -115,13 +114,7 @@ public class Params extends Z3Object
@Override
public String toString()
{
try
{
return Native.paramsToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
return Native.paramsToString(getContext().nCtx(), getNativeObject());
}
Params(Context ctx)
@ -129,17 +122,14 @@ public class Params extends Z3Object
super(ctx, Native.mkParams(ctx.nCtx()));
}
@Override
void incRef(long o)
{
getContext().getParamsDRQ().incAndClear(getContext(), o);
super.incRef(o);
void incRef() {
Native.paramsIncRef(getContext().nCtx(), getNativeObject());
}
@Override
void decRef(long o)
{
getContext().getParamsDRQ().add(o);
super.decRef(o);
void addToReferenceQueue() {
getContext().getParamsDRQ().storeReference(getContext(), this);
}
}

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