3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-11 21:50:52 +00:00

move theory_var_list into id_var_list and utilities from smt-enode into it, prepare for theory variables in egraph

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2020-09-01 04:26:31 -07:00
parent fa9cf0fa0c
commit d4e92d4aca
11 changed files with 332 additions and 193 deletions

View file

@ -93,13 +93,7 @@ namespace smt {
}
unsigned enode::get_num_th_vars() const {
unsigned r = 0;
theory_var_list const * l = get_th_var_list();
while(l) {
r++;
l = l->get_next();
}
return r;
return m_th_var_list.size();
}
/**
@ -109,44 +103,14 @@ namespace smt {
with a variable of theory th_id
*/
theory_var enode::get_th_var(theory_id th_id) const {
if (m_th_var_list.get_th_var() == null_theory_var)
return null_theory_var;
theory_var_list const * l = &m_th_var_list;
while (l) {
if (l->get_th_id() == th_id) {
return l->get_th_var();
}
l = l->get_next();
}
return null_theory_var;
return m_th_var_list.find(th_id);
}
/**
\brief Add the entry (v, id) to the list of theory variables.
*/
void enode::add_th_var(theory_var v, theory_id id, region & r) {
#ifdef Z3DEBUG
unsigned old_size = get_num_th_vars();
#endif
SASSERT(get_th_var(id) == null_theory_var);
if (m_th_var_list.get_th_var() == null_theory_var) {
m_th_var_list.set_th_var(v);
m_th_var_list.set_th_id(id);
m_th_var_list.set_next(nullptr);
}
else {
theory_var_list * l = &m_th_var_list;
while (l->get_next() != nullptr) {
SASSERT(l->get_th_id() != id);
l = l->get_next();
}
SASSERT(l);
SASSERT(l->get_next() == 0);
theory_var_list * new_cell = new (r) theory_var_list(id, v);
l->set_next(new_cell);
}
SASSERT(get_num_th_vars() == old_size + 1);
SASSERT(get_th_var(id) == v);
m_th_var_list.add_var(v, id, r);
}
/**
@ -154,16 +118,7 @@ namespace smt {
The enode must have an entry (v', id)
*/
void enode::replace_th_var(theory_var v, theory_id id) {
SASSERT(get_th_var(id) != null_theory_var);
theory_var_list * l = get_th_var_list();
while (l) {
if (l->get_th_id() == id) {
l->set_th_var(v);
return;
}
l = l->get_next();
}
UNREACHABLE();
m_th_var_list.replace(v, id);
}
/**
@ -171,33 +126,7 @@ namespace smt {
enode is associated with a variable of the given theory.
*/
void enode::del_th_var(theory_id id) {
SASSERT(get_th_var(id) != null_theory_var);
if (m_th_var_list.get_th_id() == id) {
theory_var_list * next = m_th_var_list.get_next();
if (next == nullptr) {
// most common case
m_th_var_list.set_th_var(null_theory_var);
m_th_var_list.set_th_id(null_theory_id);
m_th_var_list.set_next(nullptr);
}
else {
m_th_var_list = *next;
}
}
else {
theory_var_list * prev = get_th_var_list();
theory_var_list * l = prev->get_next();
while (l) {
SASSERT(prev->get_next() == l);
if (l->get_th_id() == id) {
prev->set_next(l->get_next());
return;
}
prev = l;
l = l->get_next();
}
UNREACHABLE();
}
m_th_var_list.del_var(id);
}