From 710f96fcccc74c4e525399c3a5768fd358731303 Mon Sep 17 00:00:00 2001 From: Yakir Vizel Date: Sun, 22 Sep 2024 15:15:38 +0300 Subject: [PATCH] Extracting new chcs after transformation --- src/cprover/chc_large_step.h | 40 ++++++++++++++++++++++++---------- src/cprover/state_encoding.cpp | 28 ++++-------------------- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/src/cprover/chc_large_step.h b/src/cprover/chc_large_step.h index b3edd52e59e..15c06de0c80 100644 --- a/src/cprover/chc_large_step.h +++ b/src/cprover/chc_large_step.h @@ -20,6 +20,8 @@ class ResolutionVisitor : public wto_element_visitort public: ResolutionVisitor(chc_db & db) : m_db(db) {} + chc_db &giveme_new_db() { return m_new_db; } + virtual void visit(const wto_singletont & s) { const symbol_exprt* symb = s.get(); @@ -39,23 +41,37 @@ class ResolutionVisitor : public wto_element_visitort resolve(head); } - std::vector getClauses() + void populate_new_db() { - std::vector all; - for (auto it = m_heads.begin(); it != m_heads.end(); it++) + std::vector rels; + for (auto &clause : m_db) + { + if(clause.is_query()) + { + clause.used_relations(m_db, std::back_inserter(rels)); + } + } + + std::set preds_hash(m_heads.begin(), m_heads.end()); + for (auto p : rels) { + preds_hash.insert(p.hash()); + } + + for (auto it : preds_hash) { - auto c = m_def.find(*it); + auto c = m_def.find(it); INVARIANT(c != m_def.end(), "No clauses"); - all.insert(all.begin(), c->second.begin(), c->second.end()); + for (auto clause : c->second) + m_new_db.add_clause(clause.get_chc()); } - return all; - } - const std::vector& getClauses(const symbol_exprt* symb) - { - auto it = m_def.find(symb->hash()); - INVARIANT(it != m_def.end(), "No clauses"); - return it->second; + for (auto &clause : m_db) + { + if(clause.is_query()) + { + m_new_db.add_clause(clause.get_chc()); + } + } } private: diff --git a/src/cprover/state_encoding.cpp b/src/cprover/state_encoding.cpp index 18bb8773558..c35610bbde9 100644 --- a/src/cprover/state_encoding.cpp +++ b/src/cprover/state_encoding.cpp @@ -1261,7 +1261,6 @@ void large_step_encoding(const container_encoding_targett & small_step_container { db.add_state_pred(s); } - } chc_graph chc_g(db); chc_g.build_graph(); @@ -1269,15 +1268,6 @@ void large_step_encoding(const container_encoding_targett & small_step_container chc_wtot wto(chc_g); wto.build_wto(); - SimpleVisitor v; - for (auto it = wto.begin(); it != wto.end(); it++) - { - auto x = (*it); - x->accept(&v); - } - - std::cout << "\n"; - ResolutionVisitor rv(db); for (auto it = wto.begin(); it != wto.end(); it++) { @@ -1285,21 +1275,11 @@ void large_step_encoding(const container_encoding_targett & small_step_container x->accept(&rv); } - std::vector all = rv.getClauses(); - for (auto &clause : db) { - if (clause.is_query()) { - std::vector rels; - clause.used_relations(db, std::back_inserter(rels)); - for (auto pred : rels) - { - all.insert(all.end(), rv.getClauses(&pred).begin(), rv.getClauses(&pred).end()); - } - all.push_back(clause.get_chc()); - } - - } + rv.populate_new_db(); - for (auto ce : all) + container_encoding_targett container2; + std::vector all2; + for (auto & ce : rv.giveme_new_db()) { large_step_container << ce.get_chc(); }