3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-24 01:25:31 +00:00
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2019-09-02 09:59:58 -07:00
parent 000e485794
commit 68e4ed3c9c
5 changed files with 85 additions and 11 deletions

View file

@ -63,3 +63,49 @@ bool has_skolem_functions(expr * n) {
}
return false;
}
subterms::subterms(expr_ref_vector const& es): m_es(es) {}
subterms::subterms(expr_ref& e) : m_es(e.m()) { m_es.push_back(e); }
subterms::iterator subterms::begin() { return iterator(*this, true); }
subterms::iterator subterms::end() { return iterator(*this, false); }
subterms::iterator::iterator(subterms& f, bool start): m_es(f.m_es) {
if (!start) m_es.reset();
}
expr* subterms::iterator::operator*() {
return m_es.back();
}
subterms::iterator subterms::iterator::operator++(int) {
iterator tmp = *this;
++*this;
return tmp;
}
subterms::iterator& subterms::iterator::operator++() {
expr* e = m_es.back();
m_visited.mark(e, true);
if (is_app(e)) {
for (expr* arg : *to_app(e)) {
m_es.push_back(arg);
}
}
while (m_visited.is_marked(m_es.back())) {
m_es.pop_back();
}
return *this;
}
bool subterms::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::iterator::operator!=(iterator const& other) const {
return !(*this == other);
}

View file

@ -167,5 +167,25 @@ unsigned get_num_exprs(expr * n, expr_fast_mark1 & visited);
bool has_skolem_functions(expr * n);
class subterms {
expr_ref_vector m_es;
public:
class iterator {
expr_ref_vector m_es;
expr_mark m_visited;
public:
iterator(subterms& f, bool start);
expr* operator*();
iterator operator++(int);
iterator& operator++();
bool operator==(iterator const& other) const;
bool operator!=(iterator const& other) const;
};
subterms(expr_ref_vector const& es);
subterms(expr_ref& e);
iterator begin();
iterator end();
};
#endif /* FOR_EACH_EXPR_H_ */