Skip to content

Commit 8e69d6d

Browse files
author
Lukasz A.J. Wrona
committed
Make functions static
1 parent 2b2a841 commit 8e69d6d

File tree

2 files changed

+58
-39
lines changed

2 files changed

+58
-39
lines changed

src/solvers/refinement/string_refinement.cpp

+58-31
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ Author: Alberto Griggio, [email protected]
3535
#include <java_bytecode/java_types.h>
3636
#include <util/optional.h>
3737

38+
static exprt instantiate(
39+
const string_constraintt &axiom, const exprt &str, const exprt &val);
40+
exprt simplify_sum(const exprt &f);
41+
3842
/// Convert exprt to a specific type. Throw bad_cast if conversion
3943
/// cannot be performed
4044
/// Generic case doesn't exist, specialize for different types accordingly
@@ -97,59 +101,72 @@ string_refinementt::string_refinementt(const infot &info):
97101

98102
/// display the current index set, for debugging
99103
static void display_index_set(
100-
const messaget& message,
104+
messaget::mstreamt stream,
101105
const namespacet& ns,
102106
const std::map<exprt, std::set<exprt>>& current_index_set,
103107
const std::map<exprt, std::set<exprt>>& index_set)
104108
{
109+
const auto eom = messaget::eom;
105110
std::size_t count=0;
106111
std::size_t count_current=0;
107112
for(const auto &i : index_set)
108113
{
109114
const exprt &s=i.first;
110-
message.debug() << "IS(" << from_expr(ns, "", s) << ")=={" << message.eom;
115+
stream << "IS(" << from_expr(ns, "", s) << ")=={" << eom;
111116

112117
for(auto j : i.second)
113118
{
114119
const auto it=current_index_set.find(i.first);
115120
if(it!=current_index_set.end() && it->second.find(j)!=it->second.end())
116121
{
117122
count_current++;
118-
message.debug() << "**";
123+
stream << "**";
119124
}
120-
message.debug() << " " << from_expr(ns, "", j) << ";" << message.eom;
125+
stream << " " << from_expr(ns, "", j) << ";" << eom;
121126
count++;
122127
}
123-
message.debug() << "}" << message.eom;
128+
stream << "}" << eom;
124129
}
125-
message.debug() << count << " elements in index set (" << count_current
126-
<< " newly added)" << message.eom;
130+
stream << count << " elements in index set (" << count_current
131+
<< " newly added)" << eom;
127132
}
128133

129134
/// compute the index set for all formulas, instantiate the formulas with the
130135
/// found indexes, and add them as lemmas.
131-
void string_refinementt::add_instantiations()
136+
137+
static void display_current_index_set(
138+
messaget::mstreamt &stream,
139+
const namespacet &ns,
140+
const std::map<exprt, std::set<exprt>> &current_index_set)
132141
{
133-
debug() << "string_constraint_generatort::add_instantiations: "
134-
<< "going through the current index set:" << eom;
142+
const auto eom=messaget::eom;
143+
stream << "string_constraint_generatort::add_instantiations: "
144+
<< "going through the current index set:" << eom;
135145
for(const auto &i : current_index_set)
136146
{
137147
const exprt &s=i.first;
138-
debug() << "IS(" << from_expr(ns, "", s) << ")=={";
148+
stream << "IS(" << from_expr(ns, "", s) << ")=={";
139149

140150
for(const auto &j : i.second)
141-
debug() << from_expr(ns, "", j) << "; ";
142-
debug() << "}" << eom;
151+
stream << from_expr(ns, "", j) << "; ";
152+
stream << "}" << eom;
153+
}
154+
}
143155

156+
static std::vector<exprt> generate_instantiations(
157+
const std::map<exprt, std::set<exprt>> &current_index_set,
158+
const std::vector<string_constraintt>& universal_axioms)
159+
{
160+
std::vector<exprt> lemmas;
161+
for(const auto &i : current_index_set)
162+
{
144163
for(const auto &ua : universal_axioms)
145164
{
146165
for(const auto &j : i.second)
147-
{
148-
exprt lemma=instantiate(ua, s, j);
149-
add_lemma(lemma);
150-
}
166+
lemmas.push_back(instantiate(ua, i.first, j));
151167
}
152168
}
169+
return lemmas;
153170
}
154171

155172
/// List the simple expressions on which the expression depends in the
@@ -381,7 +398,10 @@ void string_refinementt::concretize_results()
381398
concretize_string(it.second);
382399
for(const auto &it : generator.get_created_strings())
383400
concretize_string(it);
384-
add_instantiations();
401+
for (const auto& lemma :
402+
generate_instantiations(current_index_set, universal_axioms))
403+
add_lemma(lemma);
404+
display_current_index_set(debug(), ns, current_index_set);
385405
}
386406

387407
/// For each string whose length has been solved, add constants to the map
@@ -551,7 +571,10 @@ decision_proceduret::resultt string_refinementt::dec_solve()
551571
initial_index_set(universal_axioms);
552572
update_index_set(cur);
553573
cur.clear();
554-
add_instantiations();
574+
for (const auto& lemma :
575+
generate_instantiations(current_index_set, universal_axioms))
576+
add_lemma(lemma);
577+
display_current_index_set(debug(), ns, current_index_set);
555578

556579
while((loop_bound_--)>0)
557580
{
@@ -579,7 +602,10 @@ decision_proceduret::resultt string_refinementt::dec_solve()
579602
current_index_set.clear();
580603
update_index_set(cur);
581604
cur.clear();
582-
add_instantiations();
605+
for (const auto& lemma :
606+
generate_instantiations(current_index_set, universal_axioms))
607+
add_lemma(lemma);
608+
display_current_index_set(debug(), ns, current_index_set);
583609

584610
if(current_index_set.empty())
585611
{
@@ -597,7 +623,7 @@ decision_proceduret::resultt string_refinementt::dec_solve()
597623
}
598624
}
599625

600-
display_index_set(*this, ns, current_index_set, index_set);
626+
display_index_set(debug(), ns, current_index_set, index_set);
601627
debug()<< "instantiating NOT_CONTAINS constraints" << eom;
602628
for(unsigned i=0; i<not_contains_axioms.size(); i++)
603629
{
@@ -1254,8 +1280,7 @@ bool string_refinementt::check_axioms()
12541280
/// \return a map where each leaf of the input is mapped to the number of times
12551281
/// it is added. For instance, expression $x + x - y$ would give the map x ->
12561282
/// 2, y -> -1.
1257-
std::map<exprt, int> string_refinementt::map_representation_of_sum(
1258-
const exprt &f) const
1283+
static std::map<exprt, int> map_representation_of_sum(const exprt &f)
12591284
{
12601285
// number of time the leaf should be added (can be negative)
12611286
std::map<exprt, int> elems;
@@ -1297,8 +1322,10 @@ std::map<exprt, int> string_refinementt::map_representation_of_sum(
12971322
/// \return a expression for the sum of each element in the map a number of
12981323
/// times given by the corresponding integer in the map. For a map x -> 2, y
12991324
/// -> -1 would give an expression $x + x - y$.
1300-
exprt string_refinementt::sum_over_map(
1301-
std::map<exprt, int> &m, const typet &type, bool negated) const
1325+
static exprt sum_over_map(
1326+
std::map<exprt, int> &m,
1327+
const typet &type,
1328+
bool negated = false)
13021329
{
13031330
exprt sum=nil_exprt();
13041331
mp_integer constants=0;
@@ -1368,7 +1395,7 @@ exprt string_refinementt::sum_over_map(
13681395

13691396
/// \par parameters: an expression with only plus and minus expr
13701397
/// \return an equivalent expression in a canonical form
1371-
exprt string_refinementt::simplify_sum(const exprt &f) const
1398+
exprt simplify_sum(const exprt &f)
13721399
{
13731400
std::map<exprt, int> map=map_representation_of_sum(f);
13741401
return sum_over_map(map, f.type());
@@ -1381,7 +1408,7 @@ exprt string_refinementt::simplify_sum(const exprt &f) const
13811408
/// a function of $qvar$, i.e. the value that is necessary for qvar for f to
13821409
/// be equal to val. For instance, if `f` corresponds to the expression $q +
13831410
/// x$, `compute_inverse_function(q,v,f)` returns an expression for $v - x$.
1384-
exprt string_refinementt::compute_inverse_function(
1411+
static exprt compute_inverse_function(
13851412
const exprt &qvar, const exprt &val, const exprt &f)
13861413
{
13871414
exprt positive, negative;
@@ -1409,8 +1436,8 @@ exprt string_refinementt::compute_inverse_function(
14091436
string_refinement_invariantt("a proper function must have exactly one "
14101437
"occurrences after reduction, or it canceled out, and it does not have "
14111438
" one"));
1412-
debug() << "in string_refinementt::compute_inverse_function:"
1413-
<< " warning: occurrences of qvar canceled out " << eom;
1439+
// debug() << "in string_refinementt::compute_inverse_function:"
1440+
// << " warning: occurrences of qvar canceled out " << eom;
14141441
}
14151442

14161443
elems.erase(it);
@@ -1605,7 +1632,7 @@ class find_index_visitort: public const_expr_visitort
16051632
/// \param [in] str: the string which must be indexed
16061633
/// \param [in] qvar: the universal variable that must be in the index
16071634
/// \return an index expression in `expr` on `str` containing `qvar`
1608-
exprt find_index(const exprt &expr, const exprt &str, const symbol_exprt &qvar)
1635+
static exprt find_index(const exprt &expr, const exprt &str, const symbol_exprt &qvar)
16091636
{
16101637
find_index_visitort v(str, qvar);
16111638
expr.visit(v);
@@ -1619,7 +1646,7 @@ exprt find_index(const exprt &expr, const exprt &str, const symbol_exprt &qvar)
16191646
/// For instance, if `axiom` corresponds to $\forall q. s[q+x]='a' &&
16201647
/// t[q]='b'$, `instantiate(axiom,s,v)` would return an expression for
16211648
/// $s[v]='a' && t[v-x]='b'$.
1622-
exprt string_refinementt::instantiate(
1649+
static exprt instantiate(
16231650
const string_constraintt &axiom, const exprt &str, const exprt &val)
16241651
{
16251652
exprt idx=find_index(axiom.body(), str, axiom.univ_var());

src/solvers/refinement/string_refinement.h

-8
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ class string_refinementt final: public bv_refinementt
113113
bool add_axioms_for_string_assigns(const exprt &lhs, const exprt &rhs);
114114
void set_to(const exprt &expr, bool value) override;
115115

116-
void add_instantiations();
117116
void debug_model();
118117
bool check_axioms();
119118
bool is_axiom_sat(
@@ -126,23 +125,16 @@ class string_refinementt final: public bv_refinementt
126125
void initial_index_set(const std::vector<string_constraintt> &string_axioms);
127126
void add_to_index_set(const exprt &s, exprt i);
128127

129-
exprt instantiate(
130-
const string_constraintt &axiom, const exprt &str, const exprt &val);
131-
132128
std::vector<exprt> instantiate_not_contains(
133129
const string_not_contains_constraintt &axiom);
134130

135131
exprt compute_inverse_function(
136132
const exprt &qvar, const exprt &val, const exprt &f);
137133

138134
std::map<exprt, int> map_representation_of_sum(const exprt &f) const;
139-
exprt sum_over_map(
140-
std::map<exprt, int> &m, const typet &type, bool negated=false) const;
141135

142136
bool is_valid_string_constraint(const string_constraintt &expr);
143137

144-
exprt simplify_sum(const exprt &f) const;
145-
146138
void concretize_string(const exprt &expr);
147139
void concretize_results();
148140
void concretize_lengths();

0 commit comments

Comments
 (0)