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

use propagation filter

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2019-10-20 15:59:10 -07:00
parent 423e084cda
commit e5504247e9
5 changed files with 217 additions and 29 deletions

View file

@ -109,3 +109,67 @@ bool subterms::iterator::operator!=(iterator const& other) const {
return !(*this == other);
}
subterms_postorder::subterms_postorder(expr_ref_vector const& es): m_es(es) {}
subterms_postorder::subterms_postorder(expr_ref& e) : m_es(e.m()) { m_es.push_back(e); }
subterms_postorder::iterator subterms_postorder::begin() { return iterator(*this, true); }
subterms_postorder::iterator subterms_postorder::end() { return iterator(*this, false); }
subterms_postorder::iterator::iterator(subterms_postorder& f, bool start): m_es(f.m_es) {
if (!start) m_es.reset();
next();
}
expr* subterms_postorder::iterator::operator*() {
return m_es.back();
}
subterms_postorder::iterator subterms_postorder::iterator::operator++(int) {
iterator tmp = *this;
++*this;
return tmp;
}
void subterms_postorder::iterator::next() {
while (!m_es.empty()) {
expr* e = m_es.back();
if (m_visited.is_marked(e)) {
m_es.pop_back();
continue;
}
bool all_visited = true;
if (is_app(e)) {
for (expr* arg : *to_app(e)) {
if (!m_visited.is_marked(arg)) {
m_es.push_back(arg);
all_visited = false;
}
}
}
if (all_visited) {
m_visited.mark(e, true);
break;
}
}
}
subterms_postorder::iterator& subterms_postorder::iterator::operator++() {
expr* e = m_es.back();
next();
return *this;
}
bool subterms_postorder::iterator::operator==(iterator const& other) const {
// ignore state of visited
if (other.m_es.size() != m_es.size()) {
return false;
}
for (unsigned i = m_es.size(); i-- > 0; ) {
if (m_es.get(i) != other.m_es.get(i))
return false;
}
return true;
}
bool subterms_postorder::iterator::operator!=(iterator const& other) const {
return !(*this == other);
}

View file

@ -167,6 +167,7 @@ unsigned get_num_exprs(expr * n, expr_fast_mark1 & visited);
bool has_skolem_functions(expr * n);
// pre-order traversal of subterms
class subterms {
expr_ref_vector m_es;
public:
@ -187,5 +188,26 @@ public:
iterator end();
};
class subterms_postorder {
expr_ref_vector m_es;
public:
class iterator {
expr_ref_vector m_es;
expr_mark m_visited, m_seen;
void next();
public:
iterator(subterms_postorder& f, bool start);
expr* operator*();
iterator operator++(int);
iterator& operator++();
bool operator==(iterator const& other) const;
bool operator!=(iterator const& other) const;
};
subterms_postorder(expr_ref_vector const& es);
subterms_postorder(expr_ref& e);
iterator begin();
iterator end();
};
#endif /* FOR_EACH_EXPR_H_ */