Skip to content

Commit 7ae6ef2

Browse files
Yakir Vizelyvizel
authored andcommitted
Renaming types and function names, and adjusments to changes in API
1 parent 7672856 commit 7ae6ef2

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

src/cprover/chc_large_step.h

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,29 @@
99
#include <util/substitute_symbols.h>
1010
#include <util/format_expr.h>
1111

12-
class ResolutionVisitor : public wto_element_visitort
12+
/*
13+
* Traverses the clauses in order and resolving all predicates (symbols)
14+
* that are not a head (e.g. a head of a loop).
15+
* This is similar to variable elimination in SAT.
16+
*/
17+
class resolution_visitort : public wto_element_visitort
1318
{
1419
private:
15-
chc_db & m_db;
16-
chc_db m_new_db;
17-
std::unordered_map<std::size_t, std::vector<horn_clause>> m_def;
18-
std::set<std::size_t> m_heads;
20+
chc_dbt & m_db;
21+
chc_dbt m_new_db;
22+
std::unordered_map<std::size_t, std::vector<horn_clauset>> m_def;
23+
std::unordered_set<std::size_t> m_heads;
24+
bool m_verbose;
1925

2026
public:
21-
ResolutionVisitor(chc_db & db) : m_db(db) {}
27+
resolution_visitort(chc_dbt & db) : m_db(db), m_verbose(false) {}
2228

23-
chc_db &giveme_new_db() { return m_new_db; }
29+
chc_dbt &giveme_new_db() { return m_new_db; }
2430

2531
virtual void visit(const wto_singletont & s)
2632
{
2733
const symbol_exprt* symb = s.get();
28-
resolve(symb);
34+
eliminate(symb);
2935
}
3036

3137
virtual void visit(const wto_componentt & comp)
@@ -38,7 +44,7 @@ class ResolutionVisitor : public wto_element_visitort
3844
{
3945
it->get()->accept(this);
4046
}
41-
resolve(head);
47+
eliminate(head);
4248
}
4349

4450
void populate_new_db()
@@ -75,43 +81,41 @@ class ResolutionVisitor : public wto_element_visitort
7581
}
7682

7783
private:
78-
void resolve(const symbol_exprt *symb)
84+
void eliminate(const symbol_exprt *symb)
7985
{
80-
for (auto clause : m_db.def(*symb))
86+
for (auto idx : m_db.def(*symb))
8187
{
88+
auto & clause = m_db.get_clause(idx);
8289
std::vector<symbol_exprt> use;
83-
if (false)
84-
{
85-
std::cout << "Clause: " << format(clause->get_chc()) << "\n";
86-
}
87-
clause->used_relations(m_db,std::back_inserter(use));
90+
91+
clause.used_relations(m_db,std::back_inserter(use));
8892
if (use.size() > 1) {
8993
throw incorrect_goto_program_exceptiont("Non-linear CHCs not supported yet");
9094
}
9195

92-
if (clause->is_fact())
96+
if (clause.is_fact())
9397
{
9498
m_heads.insert(symb->hash());
95-
std::vector<horn_clause> def_chcs;
96-
def_chcs.push_back(clause->get_chc());
99+
std::vector<horn_clauset> def_chcs;
100+
def_chcs.push_back(clause.get_chc());
97101
m_def.insert(std::make_pair(symb->hash(), def_chcs));
98102
}
99103

100104
for (auto & p : use)
101105
{
102106
auto it = m_def.find(p.hash());
103-
std::vector<horn_clause> def_chcs;
107+
std::vector<horn_clauset> def_chcs;
104108
if (it == m_def.end() || m_heads.find(p.hash()) != m_heads.end())
105109
{
106-
def_chcs.push_back(*clause);
110+
def_chcs.push_back(clause);
107111
}
108112
else
109113
{
110114
for (auto cls_it = it->second.begin(); cls_it != it->second.end(); cls_it++)
111115
{
112-
forall_exprt resolvent = resolve_cls2((*cls_it), *clause);
113-
if (false)
114-
std::cout << "Result where:\n" << format(resolvent) << "\n";
116+
forall_exprt resolvent = resolve_clauses((*cls_it), clause);
117+
if (m_verbose)
118+
std::cout << "Result:\n" << format(resolvent) << "\n";
115119
def_chcs.push_back(resolvent);
116120
}
117121
}
@@ -127,7 +131,7 @@ class ResolutionVisitor : public wto_element_visitort
127131
}
128132
}
129133

130-
forall_exprt resolve_cls2(const horn_clause & c1, const horn_clause & c2)
134+
forall_exprt resolve_clauses(const horn_clauset & c1, const horn_clauset & c2)
131135
{
132136
const exprt &body1 = *c1.body();
133137
const exprt &head1 = *c1.head();
@@ -151,7 +155,7 @@ class ResolutionVisitor : public wto_element_visitort
151155
if (head1_pred == nullptr)
152156
throw analysis_exceptiont("Resolution not possible");
153157

154-
if (false)
158+
if (m_verbose)
155159
std::cout << "Resolving: \n" << format(c1.get_chc()) << "\nAnd: \n"
156160
<< format(c2.get_chc()) << "\n";
157161

@@ -179,9 +183,6 @@ class ResolutionVisitor : public wto_element_visitort
179183
if ((head_arg.id() != ID_symbol) ||
180184
(to_symbol_expr(head_arg).get_identifier() != body_arg.get_identifier()))
181185
{
182-
//std::cout << "body arg: " << format(body_arg)
183-
// << " head arg: " << format(head_arg) << "\n";
184-
185186
std::map<irep_idt, exprt> subs;
186187
subs.insert(std::make_pair(body_arg.get_identifier(), head_arg));
187188

0 commit comments

Comments
 (0)