Skip to content

Commit ed7ca4e

Browse files
author
Daniel Kroening
committed
use instructiont::apply
1 parent 797f69c commit ed7ca4e

8 files changed

+26
-75
lines changed

src/analyses/dirty.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,8 @@ Date: March 2013
1717

1818
void dirtyt::build(const goto_functiont &goto_function)
1919
{
20-
forall_goto_program_instructions(it, goto_function.body)
21-
{
22-
find_dirty(it->code);
23-
24-
if(it->has_condition())
25-
find_dirty(it->get_condition());
26-
}
20+
for(const auto &i : goto_function.body.instructions)
21+
i.apply([this](const exprt &e) { find_dirty(e); });
2722
}
2823

2924
void dirtyt::find_dirty(const exprt &expr)

src/analyses/interval_analysis.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ void instrument_intervals(
3232
{
3333
std::set<symbol_exprt> symbols;
3434

35-
forall_goto_program_instructions(i_it, goto_function.body)
36-
{
37-
find_symbols(i_it->code, symbols);
38-
find_symbols(i_it->guard, symbols);
39-
}
35+
for(const auto &i : goto_function.body.instructions)
36+
i.apply([&symbols](const exprt &e) { find_symbols(e, symbols); });
4037

4138
Forall_goto_program_instructions(i_it, goto_function.body)
4239
{

src/analyses/local_safe_pointers.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,15 @@ void local_safe_pointerst::output_safe_dereferences(
237237
{
238238
out << "{";
239239
bool first = true;
240-
for(auto subexpr_it = i_it->code.depth_begin(),
241-
subexpr_end = i_it->code.depth_end();
242-
subexpr_it != subexpr_end;
243-
++subexpr_it)
244-
{
245-
if(subexpr_it->id() == ID_dereference)
240+
i_it->apply([&first, &out](const exprt &e) {
241+
if(e.id() == ID_dereference)
246242
{
247243
if(!first)
248244
out << ", ";
249245
first = true;
250-
format_rec(out, subexpr_it->op0());
246+
format_rec(out, to_dereference_expr(e).pointer());
251247
}
252-
}
248+
});
253249
out << "}";
254250
}
255251

src/goto-instrument/concurrency.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,7 @@ void concurrency_instrumentationt::collect(
186186
forall_goto_program_instructions(i_it, goto_program)
187187
{
188188
if(is_threaded(i_it))
189-
{
190-
if(i_it->is_assign())
191-
collect(i_it->code);
192-
else if(i_it->is_assume() || i_it->is_assert() || i_it->is_goto())
193-
collect(i_it->guard);
194-
else if(i_it->is_function_call())
195-
collect(i_it->code);
196-
}
189+
i_it->apply([this](const exprt &e) { collect(e); });
197190
}
198191
}
199192

src/goto-instrument/cover_util.cpp

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,11 @@ std::set<exprt> collect_conditions(const exprt &src)
4848

4949
std::set<exprt> collect_conditions(const goto_programt::const_targett t)
5050
{
51-
switch(t->type)
52-
{
53-
case GOTO:
54-
case ASSERT:
55-
return collect_conditions(t->guard);
51+
std::set<exprt> result;
5652

57-
case ASSIGN:
58-
case FUNCTION_CALL:
59-
return collect_conditions(t->code);
53+
t->apply([&result](const exprt &e) { collect_conditions_rec(e, result); });
6054

61-
default:
62-
{
63-
}
64-
}
65-
66-
return std::set<exprt>();
55+
return result;
6756
}
6857

6958
void collect_operands(const exprt &src, std::vector<exprt> &dest)
@@ -115,20 +104,9 @@ std::set<exprt> collect_decisions(const exprt &src)
115104

116105
std::set<exprt> collect_decisions(const goto_programt::const_targett t)
117106
{
118-
switch(t->type)
119-
{
120-
case GOTO:
121-
case ASSERT:
122-
return collect_decisions(t->guard);
107+
std::set<exprt> result;
123108

124-
case ASSIGN:
125-
case FUNCTION_CALL:
126-
return collect_decisions(t->code);
109+
t->apply([&result](const exprt &e) { collect_decisions_rec(e, result); });
127110

128-
default:
129-
{
130-
}
131-
}
132-
133-
return std::set<exprt>();
111+
return result;
134112
}

src/goto-instrument/full_slicer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ void full_slicert::add_decl_dead(
6666
return;
6767

6868
find_symbols_sett syms;
69-
find_symbols(node.PC->code, syms);
70-
find_symbols(node.PC->guard, syms);
69+
70+
node.PC->apply([&syms](const exprt &e) { find_symbols(e, syms); });
7171

7272
for(find_symbols_sett::const_iterator
7373
it=syms.begin();

src/goto-programs/compute_called_functions.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,10 @@ void compute_address_taken_functions(
5454
const goto_programt &goto_program,
5555
std::unordered_set<irep_idt> &address_taken)
5656
{
57-
forall_goto_program_instructions(it, goto_program)
58-
{
59-
if(it->has_condition())
60-
compute_address_taken_functions(it->get_condition(), address_taken);
61-
62-
compute_address_taken_functions(it->code, address_taken);
63-
}
57+
for(const auto &i : goto_program.instructions)
58+
i.apply([&address_taken](const exprt &expr) {
59+
compute_address_taken_functions(expr, address_taken);
60+
});
6461
}
6562

6663
/// get all functions whose address is taken

src/goto-programs/slice_global_inits.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,17 @@ void slice_global_inits(goto_modelt &goto_model)
6161
if(it == goto_functions.function_map.end())
6262
continue;
6363

64-
const goto_programt &goto_program = it->second.body;
65-
66-
forall_goto_program_instructions(i_it, goto_program)
67-
{
68-
const codet &code = i_it->code;
69-
find_symbols(code, symbols, true, false);
70-
71-
if(i_it->has_condition())
72-
find_symbols(i_it->get_condition(), symbols, true, false);
73-
}
64+
for(const auto &i : it->second.body.instructions)
65+
i.apply([&symbols](const exprt &expr) {
66+
find_symbols(expr, symbols, true, false);
67+
});
7468
}
7569

7670
// now remove unnecessary initializations
7771

7872
goto_functionst::function_mapt::iterator f_it;
7973
f_it=goto_functions.function_map.find(INITIALIZE_FUNCTION);
74+
8075
if(f_it == goto_functions.function_map.end())
8176
throw incorrect_goto_program_exceptiont("initialize function not found");
8277

0 commit comments

Comments
 (0)