3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-22 16:45:31 +00:00
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2019-12-25 21:06:26 -08:00
parent e73ce6e712
commit 5d3a4ee805
4 changed files with 25 additions and 37 deletions

View file

@ -2190,6 +2190,21 @@ bool ast_manager::coercion_needed(func_decl * decl, unsigned num_args, expr * co
return false;
}
expr* ast_manager::coerce_to(expr* e, sort* s) {
sort* se = get_sort(e);
if (s != se && s->get_family_id() == m_arith_family_id && se->get_family_id() == m_arith_family_id) {
if (s->get_decl_kind() == REAL_SORT) {
return mk_app(m_arith_family_id, OP_TO_REAL, e);
}
else {
return mk_app(m_arith_family_id, OP_TO_INT, e);
}
}
else {
return e;
}
}
app * ast_manager::mk_app_core(func_decl * decl, unsigned num_args, expr * const * args) {
app * r = nullptr;
app * new_node = nullptr;
@ -2198,35 +2213,9 @@ app * ast_manager::mk_app_core(func_decl * decl, unsigned num_args, expr * const
try {
if (m_int_real_coercions && coercion_needed(decl, num_args, args)) {
expr_ref_buffer new_args(*this);
if (decl->is_associative()) {
sort * d = decl->get_domain(0);
for (unsigned i = 0; i < num_args; i++) {
sort * s = get_sort(args[i]);
if (d != s && d->get_family_id() == m_arith_family_id && s->get_family_id() == m_arith_family_id) {
if (d->get_decl_kind() == REAL_SORT)
new_args.push_back(mk_app(m_arith_family_id, OP_TO_REAL, args[i]));
else
new_args.push_back(mk_app(m_arith_family_id, OP_TO_INT, args[i]));
}
else {
new_args.push_back(args[i]);
}
}
}
else {
for (unsigned i = 0; i < num_args; i++) {
sort * d = decl->get_domain(i);
sort * s = get_sort(args[i]);
if (d != s && d->get_family_id() == m_arith_family_id && s->get_family_id() == m_arith_family_id) {
if (d->get_decl_kind() == REAL_SORT)
new_args.push_back(mk_app(m_arith_family_id, OP_TO_REAL, args[i]));
else
new_args.push_back(mk_app(m_arith_family_id, OP_TO_INT, args[i]));
}
else {
new_args.push_back(args[i]);
}
}
for (unsigned i = 0; i < num_args; i++) {
sort * d = decl->is_associative() ? decl->get_domain(0) : decl->get_domain(i);
new_args.push_back(coerce_to(args[i], d));
}
check_args(decl, num_args, new_args.c_ptr());
SASSERT(new_args.size() == num_args);
@ -2446,10 +2435,9 @@ bool ast_manager::is_label_lit(expr const * n, buffer<symbol> & names) const {
}
app * ast_manager::mk_pattern(unsigned num_exprs, app * const * exprs) {
DEBUG_CODE({
for (unsigned i = 0; i < num_exprs; ++i) {
SASSERT(is_app(exprs[i]));
}});
for (unsigned i = 0; i < num_exprs; ++i) {
if (!is_app(exprs[i])) throw default_exception("patterns cannot be variables or quantifiers");
}
return mk_app(m_pattern_family_id, OP_PATTERN, 0, nullptr, num_exprs, (expr*const*)exprs);
}

View file

@ -1578,6 +1578,7 @@ public:
// Return true if s1 and s2 are equal, or coercions are enabled, and s1 and s2 are compatible.
bool compatible_sorts(sort * s1, sort * s2) const;
expr* coerce_to(expr* e, sort* s);
// For debugging purposes
void display_free_ids(std::ostream & out) { m_expr_id_gen.display_free_ids(out); out << "\n"; m_decl_id_gen.display_free_ids(out); }

View file

@ -324,7 +324,7 @@ bool cmd_context::macros_find(symbol const& s, unsigned n, expr*const* args, exp
if (d.m_domain.size() != n) continue;
bool eq = true;
for (unsigned i = 0; eq && i < n; ++i) {
eq = m().compatible_sorts(d.m_domain[i], m().get_sort(args[i]));
eq = d.m_domain[i] == m().get_sort(args[i]);
}
if (eq) {
t = d.m_body;
@ -1077,7 +1077,7 @@ void cmd_context::mk_app(symbol const & s, unsigned num_args, expr * const * arg
tout << "args:\n"; for (unsigned i = 0; i < num_args; i++) tout << mk_ismt2_pp(args[i], m()) << "\n" << mk_pp(m().get_sort(args[i]), m()) << "\n";);
var_subst subst(m());
scoped_rlimit no_limit(m().limit(), 0);
result = subst(_t, num_args, args);
result = subst(_t, num_args, args);
if (well_sorted_check_enabled() && !is_well_sorted(m(), result))
throw cmd_exception("invalid macro application, sort mismatch ", s);
return;
@ -1085,7 +1085,6 @@ void cmd_context::mk_app(symbol const & s, unsigned num_args, expr * const * arg
func_decls fs;
if (!m_func_decls.find(s, fs)) {
builtin_decl d;
if (m_builtin_decls.find(s, d)) {
family_id fid = d.m_fid;

View file

@ -300,7 +300,7 @@ psort_user_decl::psort_user_decl(unsigned id, unsigned num_params, pdecl_manager
m_def(p) {
m_psort_kind = PSORT_USER;
m.inc_ref(p);
SASSERT(p == 0 || num_params == p->get_num_params());
// SASSERT(p == 0 || num_params == p->get_num_params());
}
void psort_user_decl::finalize(pdecl_manager & m) {