Skip to content

Commit 9a4e3e6

Browse files
committed
Deprecate find_symbols_or_nexts
Make the two Boolean parameters of find_symbols(expr, set, bool, bool) optional so that each existing users can safely use that function (or another, even more suitable, function) instead.
1 parent 0be1e87 commit 9a4e3e6

File tree

9 files changed

+66
-58
lines changed

9 files changed

+66
-58
lines changed

src/goto-instrument/accelerate/accelerate.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -379,21 +379,16 @@ void acceleratet::add_dirty_checks()
379379

380380
// Find which symbols are read, i.e. those appearing in a guard or on
381381
// the right hand side of an assignment. Assume each is not dirty.
382-
find_symbols_sett read;
382+
std::set<symbol_exprt> read;
383383

384384
if(it->has_condition())
385-
find_symbols_or_nexts(it->get_condition(), read);
385+
find_symbols(it->get_condition(), read);
386386

387387
if(it->is_assign())
388-
{
389-
find_symbols_or_nexts(it->assign_rhs(), read);
390-
}
388+
find_symbols(it->assign_rhs(), read);
391389

392-
for(find_symbols_sett::iterator jt=read.begin();
393-
jt!=read.end();
394-
++jt)
390+
for(const auto &var : read)
395391
{
396-
const exprt &var=ns.lookup(*jt).symbol_expr();
397392
expr_mapt::iterator dirty_var=dirty_vars_map.find(var);
398393

399394
if(dirty_var==dirty_vars_map.end())

src/goto-instrument/accelerate/acceleration_utils.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,19 @@ void acceleration_utilst::stash_variables(
198198
expr_sett modified,
199199
substitutiont &substitution)
200200
{
201-
find_symbols_sett vars =
202-
find_symbols_or_nexts(modified.begin(), modified.end());
203-
const irep_idt &loop_counter_name =
204-
to_symbol_expr(loop_counter).get_identifier();
205-
vars.erase(loop_counter_name);
201+
const symbol_exprt &loop_counter_sym = to_symbol_expr(loop_counter);
206202

207-
for(const irep_idt &symbol : vars)
203+
std::set<symbol_exprt> vars;
204+
for(const exprt &expr : modified)
205+
find_symbols(expr, vars);
206+
207+
vars.erase(loop_counter_sym);
208+
209+
for(const symbol_exprt &orig : vars)
208210
{
209-
const symbolt &orig = symbol_table.lookup_ref(symbol);
210-
symbolt stashed_sym=fresh_symbol("polynomial::stash", orig.type);
211-
substitution[orig.symbol_expr()]=stashed_sym.symbol_expr();
212-
program.assign(stashed_sym.symbol_expr(), orig.symbol_expr());
211+
symbolt stashed_sym = fresh_symbol("polynomial::stash", orig.type());
212+
substitution[orig] = stashed_sym.symbol_expr();
213+
program.assign(stashed_sym.symbol_expr(), orig);
213214
}
214215
}
215216

src/goto-instrument/dump_c.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -913,9 +913,7 @@ void dump_ct::convert_global_variable(
913913

914914
code_frontend_declt d(symbol.symbol_expr());
915915

916-
find_symbols_sett syms;
917-
if(symbol.value.is_not_nil())
918-
find_symbols_or_nexts(symbol.value, syms);
916+
find_symbols_sett syms = find_symbol_identifiers(symbol.value);
919917

920918
// add a tentative declaration to cater for symbols in the initializer
921919
// relying on it this symbol

src/goto-instrument/full_slicer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void full_slicert::add_decl_dead(
6262

6363
find_symbols_sett syms;
6464

65-
node.PC->apply([&syms](const exprt &e) { find_symbols_or_nexts(e, syms); });
65+
node.PC->apply([&syms](const exprt &e) { find_symbols(e, syms); });
6666

6767
for(find_symbols_sett::const_iterator
6868
it=syms.begin();

src/goto-programs/goto_program.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,7 @@ void goto_programt::instructiont::validate(
760760

761761
auto expr_symbol_finder = [&](const exprt &e) {
762762
find_symbols_sett typetags;
763-
find_type_symbols(e.type(), typetags);
764-
find_symbols_or_nexts(e, typetags);
763+
find_type_and_expr_symbols(e, typetags);
765764
const symbolt *symbol;
766765
for(const auto &identifier : typetags)
767766
{
@@ -873,7 +872,7 @@ void goto_programt::instructiont::validate(
873872
"assert instruction should not have a target",
874873
source_location());
875874

876-
std::for_each(guard.depth_begin(), guard.depth_end(), expr_symbol_finder);
875+
expr_symbol_finder(guard);
877876
std::for_each(guard.depth_begin(), guard.depth_end(), type_finder);
878877
break;
879878
case OTHER:
@@ -940,7 +939,7 @@ void goto_programt::instructiont::validate(
940939
"function call instruction should contain a call statement",
941940
source_location());
942941

943-
std::for_each(code.depth_begin(), code.depth_end(), expr_symbol_finder);
942+
expr_symbol_finder(code);
944943
std::for_each(code.depth_begin(), code.depth_end(), type_finder);
945944
break;
946945
case THROW:

src/goto-symex/postcondition.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,13 @@ bool postconditiont::is_used(
164164
else if(expr.id()==ID_dereference)
165165
{
166166
// aliasing may happen here
167-
const std::vector<exprt> expr_set =
168-
value_set.get_value_set(to_dereference_expr(expr).pointer(), ns);
169-
const auto original_names = make_range(expr_set).map(
170-
[](const exprt &e) { return get_original_name(e); });
171-
const std::unordered_set<irep_idt> symbols =
172-
find_symbols_or_nexts(original_names.begin(), original_names.end());
167+
find_symbols_sett symbols;
168+
for(const exprt &e :
169+
value_set.get_value_set(to_dereference_expr(expr).pointer(), ns))
170+
{
171+
find_symbols(get_original_name(e), symbols);
172+
}
173+
173174
return symbols.find(identifier)!=symbols.end();
174175
}
175176
else

src/goto-symex/precondition.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,12 @@ void preconditiont::compute_rec(exprt &dest)
113113

114114
// aliasing may happen here
115115

116-
const std::vector<exprt> expr_set = value_sets.get_values(
117-
SSA_step.source.function_id, target, deref_expr.pointer());
118-
const std::unordered_set<irep_idt> symbols =
119-
find_symbols_or_nexts(expr_set.begin(), expr_set.end());
116+
find_symbols_sett symbols;
117+
for(const exprt &e : value_sets.get_values(
118+
SSA_step.source.function_id, target, deref_expr.pointer()))
119+
{
120+
find_symbols(e, symbols);
121+
}
120122

121123
if(symbols.find(lhs_identifier)!=symbols.end())
122124
{

src/util/find_symbols.cpp

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,6 @@ enum class kindt
2323
F_ALL
2424
};
2525

26-
void find_symbols_or_nexts(const exprt &src, find_symbols_sett &dest)
27-
{
28-
find_symbols(src, dest, true, true);
29-
}
30-
31-
void find_symbols(
32-
const exprt &src,
33-
find_symbols_sett &dest,
34-
bool current,
35-
bool next)
36-
{
37-
src.visit_pre([&dest, current, next](const exprt &e) {
38-
if(e.id() == ID_symbol && current)
39-
dest.insert(to_symbol_expr(e).get_identifier());
40-
else if(e.id() == ID_next_symbol && next)
41-
dest.insert(e.get(ID_identifier));
42-
});
43-
}
44-
4526
bool has_symbol(
4627
const exprt &src,
4728
const find_symbols_sett &symbols,
@@ -218,3 +199,25 @@ void find_type_and_expr_symbols(const typet &src, find_symbols_sett &dest)
218199
{
219200
find_symbols(kindt::F_ALL, src, dest);
220201
}
202+
203+
void find_symbols_or_nexts(const exprt &src, find_symbols_sett &dest)
204+
{
205+
find_symbols(kindt::F_EXPR_BOTH, src, dest);
206+
}
207+
208+
void find_symbols(
209+
const exprt &src,
210+
find_symbols_sett &dest,
211+
bool current,
212+
bool next)
213+
{
214+
if(current)
215+
{
216+
if(next)
217+
find_symbols(kindt::F_EXPR_BOTH, src, dest);
218+
else
219+
find_symbols(kindt::F_EXPR_CURRENT, src, dest);
220+
}
221+
else if(next)
222+
find_symbols(kindt::F_EXPR_NEXT, src, dest);
223+
}

src/util/find_symbols.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,30 @@ class typet;
2323

2424
typedef std::unordered_set<irep_idt> find_symbols_sett;
2525

26+
DEPRECATED(SINCE(2022, 3, 14, "use find_symbols"))
2627
/// Add to the set \p dest the sub-expressions of \p src with id ID_symbol or
2728
/// ID_next_symbol
2829
void find_symbols_or_nexts(const exprt &src, find_symbols_sett &dest);
2930

31+
/// Add to the set \p dest the sub-expressions of \p src with id ID_symbol if
32+
/// \p current is true, and ID_next_symbol if \p next is true
33+
void find_symbols(
34+
const exprt &src,
35+
find_symbols_sett &dest,
36+
bool current = true,
37+
bool next = true);
38+
3039
/// \return set of sub-expressions of the expressions contained in the range
3140
/// defined by \p begin and \p end which have id ID_symbol or ID_next_symbol
3241
template <typename iteratort>
42+
DEPRECATED(SINCE(2022, 3, 14, "use find_symbols and a local iteration"))
3343
find_symbols_sett find_symbols_or_nexts(iteratort begin, iteratort end)
3444
{
3545
static_assert(
3646
std::is_base_of<exprt, typename iteratort::value_type>::value,
3747
"find_symbols takes exprt iterators as arguments");
3848
find_symbols_sett result;
39-
std::for_each(
40-
begin, end, [&](const exprt &e) { find_symbols_or_nexts(e, result); });
49+
std::for_each(begin, end, [&](const exprt &e) { find_symbols(e, result); });
4150
return result;
4251
}
4352

0 commit comments

Comments
 (0)