From decd69ac738d3407e0796c3f26ab663cb231b324 Mon Sep 17 00:00:00 2001 From: Nikolaj Bjorner Date: Sun, 26 Apr 2020 21:22:14 -0700 Subject: [PATCH] move to util Signed-off-by: Nikolaj Bjorner --- src/ast/ast_util.cpp | 21 +++++++++++++++++++++ src/ast/ast_util.h | 15 +++++---------- src/qe/qe.cpp | 30 ++++++------------------------ 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/ast/ast_util.cpp b/src/ast/ast_util.cpp index 6ca9d3797..18ce1145c 100644 --- a/src/ast/ast_util.cpp +++ b/src/ast/ast_util.cpp @@ -17,6 +17,8 @@ Revision History: --*/ #include "ast/ast_util.h" +#include "ast/ast_pp.h" +#include "ast/for_each_expr.h" #include "ast/arith_decl_plugin.h" app * mk_list_assoc_app(ast_manager & m, func_decl * f, unsigned num_args, expr * const * args) { @@ -372,3 +374,22 @@ static app_ref plus(ast_manager& m, expr* a, expr* b) { app_ref operator+(expr_ref& a, expr_ref& b) { return plus(a.m(), a.get(), b.get()); } + +bool has_uninterpreted(ast_manager& m, expr* _e) { + expr_ref e(_e, m); + arith_util au(m); + func_decl_ref f_out(m); + for (expr* arg : subterms(e)) { + if (!is_app(arg)) + continue; + app* a = to_app(arg); + func_decl* f = a->get_decl(); + if (a->get_num_args() == 0) + continue; + if (m.is_considered_uninterpreted(f)) + return true; + if (au.is_considered_uninterpreted(f, a->get_num_args(), a->get_args(), f_out)) + return true; + } + return false; +} diff --git a/src/ast/ast_util.h b/src/ast/ast_util.h index 58cfa48b9..72ae3e74b 100644 --- a/src/ast/ast_util.h +++ b/src/ast/ast_util.h @@ -67,20 +67,14 @@ inline bool depth_leq_one(app * n) { template void dec_ref(ast_manager & m, obj_hashtable & s) { - typename obj_hashtable::iterator it = s.begin(); - typename obj_hashtable::iterator end = s.end(); - for (;it != end; ++it) { - m.dec_ref(*it); - } + for (auto a : s) + m.dec_ref(a); } template void inc_ref(ast_manager & m, obj_hashtable & s) { - typename obj_hashtable::iterator it = s.begin(); - typename obj_hashtable::iterator end = s.end(); - for (;it != end; ++it) { - m.inc_ref(*it); - } + for (auto a : s) + m.inc_ref(a); } // ----------------------------------- @@ -174,5 +168,6 @@ void flatten_or(expr_ref_vector& result); void flatten_or(expr* fml, expr_ref_vector& result); +bool has_uninterpreted(ast_manager& m, expr* e); #endif /* AST_UTIL_H_ */ diff --git a/src/qe/qe.cpp b/src/qe/qe.cpp index cb61c2c97..ccefcb095 100644 --- a/src/qe/qe.cpp +++ b/src/qe/qe.cpp @@ -929,10 +929,9 @@ namespace qe { CHECK_COND(m_children.empty() || fml()); CHECK_COND(!is_root() || fml()); CHECK_COND(!fml() || has_var() || m_num_branches.is_zero() || is_unit()); - branch_map::iterator it = m_branch_index.begin(), end = m_branch_index.end(); - for (; it != end; ++it) { - CHECK_COND(it->m_value < m_children.size()); - CHECK_COND(it->m_key < get_num_branches()); + for (auto const & kv : m_branch_index) { + CHECK_COND(kv.m_value < m_children.size()); + CHECK_COND(kv.m_key < get_num_branches()); } for (unsigned i = 0; i < m_children.size(); ++i) { CHECK_COND(m_children[i]); @@ -1388,9 +1387,8 @@ namespace qe { void reset() { m_free_vars.reset(); m_trail.reset(); - obj_map::iterator it = m_var2contains.begin(), end = m_var2contains.end(); - for (; it != end; ++it) { - dealloc(it->m_value); + for (auto & kv : m_var2contains) { + dealloc(kv.m_value); } m_var2contains.reset(); m_var2branch.reset(); @@ -1406,22 +1404,6 @@ namespace qe { m_conjs.add_plugin(p); } - bool has_uninterpreted(expr* _e) { - expr_ref e(_e, m); - arith_util au(m); - func_decl_ref f_out(m); - for (expr* arg : subterms(e)) { - if (!is_app(arg)) continue; - app* a = to_app(arg); - func_decl* f = a->get_decl(); - if (m.is_considered_uninterpreted(f)) - return true; - if (au.is_considered_uninterpreted(f, a->get_num_args(), a->get_args(), f_out)) - return true; - } - return false; - } - void check(unsigned num_vars, app* const* vars, expr* assumption, expr_ref& fml, bool get_first, app_ref_vector& free_vars, guarded_defs* defs) { @@ -1462,7 +1444,7 @@ namespace qe { lbool res = l_true; while (res == l_true) { res = m_solver.check(); - if (res == l_true && has_uninterpreted(m_fml)) + if (res == l_true && has_uninterpreted(m, m_fml)) res = l_undef; if (res == l_true) { is_sat = true;