3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-12 12:08:18 +00:00
This commit is contained in:
Nikolaj Bjorner 2021-06-17 13:18:19 -07:00
parent f7d1cce69a
commit 4a0a678e3f
4 changed files with 41 additions and 9 deletions

View file

@ -32,6 +32,12 @@ namespace q {
<< mk_bounded_pp(rhs, m, 2); << mk_bounded_pp(rhs, m, 2);
} }
std::ostream& binding::display(euf::solver& ctx, unsigned num_nodes, std::ostream& out) const {
for (unsigned i = 0; i < num_nodes; ++i)
out << ctx.bpp((*this)[i]) << " ";
return out;
}
std::ostream& clause::display(euf::solver& ctx, std::ostream& out) const { std::ostream& clause::display(euf::solver& ctx, std::ostream& out) const {
out << "clause:\n"; out << "clause:\n";
for (auto const& lit : m_lits) for (auto const& lit : m_lits)
@ -39,9 +45,7 @@ namespace q {
binding* b = m_bindings; binding* b = m_bindings;
if (b) { if (b) {
do { do {
for (unsigned i = 0; i < num_decls(); ++i) b->display(ctx, num_decls(), out) << " - " << b << "\n";
out << ctx.bpp((*b)[i]) << " ";
out << "\n";
b = b->next(); b = b->next();
} }
while (b != m_bindings); while (b != m_bindings);

View file

@ -49,6 +49,8 @@ namespace q {
euf::enode* const* nodes() { return m_nodes; } euf::enode* const* nodes() { return m_nodes; }
euf::enode* operator[](unsigned i) const { return m_nodes[i]; } euf::enode* operator[](unsigned i) const { return m_nodes[i]; }
std::ostream& display(euf::solver& ctx, unsigned num_nodes, std::ostream& out) const;
}; };
struct clause { struct clause {

View file

@ -192,20 +192,26 @@ namespace q {
} }
struct ematch::remove_binding : public trail { struct ematch::remove_binding : public trail {
euf::solver& ctx;
clause& c; clause& c;
binding* b; binding* b;
remove_binding(clause& c, binding* b): c(c), b(b) {} remove_binding(euf::solver& ctx, clause& c, binding* b): ctx(ctx), c(c), b(b) {}
void undo() override { void undo() override {
SASSERT(binding::contains(c.m_bindings, b));
binding::remove_from(c.m_bindings, b); binding::remove_from(c.m_bindings, b);
binding::detach(b);
} }
}; };
struct ematch::insert_binding : public trail { struct ematch::insert_binding : public trail {
euf::solver& ctx;
clause& c; clause& c;
binding* b; binding* b;
insert_binding(clause& c, binding* b): c(c), b(b) {} insert_binding(euf::solver& ctx, clause& c, binding* b): ctx(ctx), c(c), b(b) {}
void undo() override { void undo() override {
SASSERT(!c.m_bindings || c.m_bindings->invariant());
binding::push_to_front(c.m_bindings, b); binding::push_to_front(c.m_bindings, b);
SASSERT(!c.m_bindings || c.m_bindings->invariant());
} }
}; };
@ -230,7 +236,7 @@ namespace q {
for (unsigned i = 0; i < n; ++i) for (unsigned i = 0; i < n; ++i)
b->m_nodes[i] = _binding[i]; b->m_nodes[i] = _binding[i];
binding::push_to_front(c.m_bindings, b); binding::push_to_front(c.m_bindings, b);
ctx.push(remove_binding(c, b)); ctx.push(remove_binding(ctx, c, b));
} }
void ematch::on_binding(quantifier* q, app* pat, euf::enode* const* _binding, unsigned max_generation, unsigned min_gen, unsigned max_gen) { void ematch::on_binding(quantifier* q, app* pat, euf::enode* const* _binding, unsigned max_generation, unsigned min_gen, unsigned max_gen) {
@ -503,8 +509,10 @@ namespace q {
while (b != c.m_bindings); while (b != c.m_bindings);
for (auto* b : to_remove) { for (auto* b : to_remove) {
SASSERT(binding::contains(c.m_bindings, b));
binding::remove_from(c.m_bindings, b); binding::remove_from(c.m_bindings, b);
ctx.push(insert_binding(c, b)); binding::detach(b);
ctx.push(insert_binding(ctx, c, b));
} }
to_remove.reset(); to_remove.reset();
} }

View file

@ -74,6 +74,10 @@ public:
} }
} }
static void detach(T* elem) {
elem->init(elem);
}
bool invariant() const { bool invariant() const {
auto* e = this; auto* e = this;
do { do {
@ -84,6 +88,20 @@ public:
while (e != this); while (e != this);
return true; return true;
} }
static bool contains(T* list, T* elem) {
if (!list)
return false;
T* first = list;
do {
if (list == elem)
return true;
list = list->m_next;
}
while (list != first);
return false;
}
}; };