Skip to content

Commit 0a1cf96

Browse files
committed
Replace some uses of {f,F}orall_goto_program_instructions by ranged-for
In some (but not all!) cases of {f,F}orall_goto_program_instructions we do not actually need the iterator.
1 parent 26b655b commit 0a1cf96

34 files changed

+215
-190
lines changed

jbmc/src/java_bytecode/remove_exceptions.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,17 @@ symbol_exprt remove_exceptionst::get_inflight_exception_global()
190190
bool remove_exceptionst::function_or_callees_may_throw(
191191
const goto_programt &goto_program) const
192192
{
193-
forall_goto_program_instructions(instr_it, goto_program)
193+
for(const auto &instruction : goto_program.instructions)
194194
{
195-
if(instr_it->is_throw())
195+
if(instruction.is_throw())
196196
{
197197
return true;
198198
}
199199

200-
if(instr_it->is_function_call())
200+
if(instruction.is_function_call())
201201
{
202-
const exprt &function_expr=
203-
to_code_function_call(instr_it->code).function();
202+
const exprt &function_expr =
203+
to_code_function_call(instruction.code).function();
204204
DATA_INVARIANT(
205205
function_expr.id()==ID_symbol,
206206
"identifier expected to be a symbol");

src/analyses/goto_check.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ void goto_checkt::collect_allocations(
290290
return;
291291

292292
forall_goto_functions(itf, goto_functions)
293-
forall_goto_program_instructions(it, itf->second.body)
293+
{
294+
for(const auto &instruction : itf->second.body.instructions)
294295
{
295-
const goto_programt::instructiont &instruction=*it;
296296
if(!instruction.is_function_call())
297297
continue;
298298

@@ -313,6 +313,7 @@ void goto_checkt::collect_allocations(
313313
assert(args[0].type()==args[1].type());
314314
allocations.push_back({args[0], args[1]});
315315
}
316+
}
316317
}
317318

318319
void goto_checkt::invalidate(const exprt &lhs)
@@ -2092,28 +2093,33 @@ void goto_checkt::goto_check(
20922093
}
20932094
}
20942095

2095-
Forall_goto_program_instructions(i_it, new_code)
2096+
for(auto &instruction : new_code.instructions)
20962097
{
2097-
if(i_it->source_location.is_nil())
2098+
if(instruction.source_location.is_nil())
20982099
{
2099-
i_it->source_location.id(irep_idt());
2100+
instruction.source_location.id(irep_idt());
21002101

21012102
if(!it->source_location.get_file().empty())
2102-
i_it->source_location.set_file(it->source_location.get_file());
2103+
instruction.source_location.set_file(it->source_location.get_file());
21032104

21042105
if(!it->source_location.get_line().empty())
2105-
i_it->source_location.set_line(it->source_location.get_line());
2106+
instruction.source_location.set_line(it->source_location.get_line());
21062107

21072108
if(!it->source_location.get_function().empty())
2108-
i_it->source_location.set_function(
2109+
instruction.source_location.set_function(
21092110
it->source_location.get_function());
21102111

21112112
if(!it->source_location.get_column().empty())
2112-
i_it->source_location.set_column(it->source_location.get_column());
2113+
{
2114+
instruction.source_location.set_column(
2115+
it->source_location.get_column());
2116+
}
21132117

21142118
if(!it->source_location.get_java_bytecode_index().empty())
2115-
i_it->source_location.set_java_bytecode_index(
2119+
{
2120+
instruction.source_location.set_java_bytecode_index(
21162121
it->source_location.get_java_bytecode_index());
2122+
}
21172123
}
21182124
}
21192125

src/analyses/local_bitvector_analysis.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,9 @@ void local_bitvector_analysist::output(
363363
{
364364
unsigned l=0;
365365

366-
forall_goto_program_instructions(i_it, goto_function.body)
366+
for(const auto &instruction : goto_function.body.instructions)
367367
{
368-
out << "**** " << i_it->source_location << "\n";
368+
out << "**** " << instruction.source_location << "\n";
369369

370370
const auto &loc_info=loc_infos[l];
371371

@@ -381,7 +381,7 @@ void local_bitvector_analysist::output(
381381
}
382382

383383
out << "\n";
384-
goto_function.body.output_instruction(ns, irep_idt(), out, *i_it);
384+
goto_function.body.output_instruction(ns, irep_idt(), out, instruction);
385385
out << "\n";
386386

387387
l++;

src/analyses/local_may_alias.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,9 @@ void local_may_aliast::output(
474474
{
475475
unsigned l=0;
476476

477-
forall_goto_program_instructions(i_it, goto_function.body)
477+
for(const auto &instruction : goto_function.body.instructions)
478478
{
479-
out << "**** " << i_it->source_location << "\n";
479+
out << "**** " << instruction.source_location << "\n";
480480

481481
const loc_infot &loc_info=loc_infos[l];
482482

@@ -502,7 +502,7 @@ void local_may_aliast::output(
502502
}
503503

504504
out << "\n";
505-
goto_function.body.output_instruction(ns, irep_idt(), out, *i_it);
505+
goto_function.body.output_instruction(ns, irep_idt(), out, instruction);
506506
out << "\n";
507507

508508
l++;

src/analyses/local_safe_pointers.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,14 @@ void local_safe_pointerst::output(
191191
const goto_programt &goto_program,
192192
const namespacet &ns)
193193
{
194-
forall_goto_program_instructions(i_it, goto_program)
194+
for(const auto &instruction : goto_program.instructions)
195195
{
196-
out << "**** " << i_it->location_number << " "
197-
<< i_it->source_location << "\n";
196+
out << "**** " << instruction.location_number << " "
197+
<< instruction.source_location << "\n";
198198

199199
out << "Non-null expressions: ";
200200

201-
auto findit = non_null_expressions.find(i_it->location_number);
201+
auto findit = non_null_expressions.find(instruction.location_number);
202202
if(findit == non_null_expressions.end())
203203
out << "{}";
204204
else
@@ -216,7 +216,7 @@ void local_safe_pointerst::output(
216216
}
217217

218218
out << '\n';
219-
goto_program.output_instruction(ns, irep_idt(), out, *i_it);
219+
goto_program.output_instruction(ns, irep_idt(), out, instruction);
220220
out << '\n';
221221
}
222222
}
@@ -235,21 +235,21 @@ void local_safe_pointerst::output_safe_dereferences(
235235
const goto_programt &goto_program,
236236
const namespacet &ns)
237237
{
238-
forall_goto_program_instructions(i_it, goto_program)
238+
for(const auto &instruction : goto_program.instructions)
239239
{
240-
out << "**** " << i_it->location_number << " "
241-
<< i_it->source_location << "\n";
240+
out << "**** " << instruction.location_number << " "
241+
<< instruction.source_location << "\n";
242242

243243
out << "Safe (known-not-null) dereferences: ";
244244

245-
auto findit = non_null_expressions.find(i_it->location_number);
245+
auto findit = non_null_expressions.find(instruction.location_number);
246246
if(findit == non_null_expressions.end())
247247
out << "{}";
248248
else
249249
{
250250
out << "{";
251251
bool first = true;
252-
i_it->apply([&first, &out](const exprt &e) {
252+
instruction.apply([&first, &out](const exprt &e) {
253253
for(auto subexpr_it = e.depth_begin(), subexpr_end = e.depth_end();
254254
subexpr_it != subexpr_end;
255255
++subexpr_it)
@@ -267,7 +267,7 @@ void local_safe_pointerst::output_safe_dereferences(
267267
}
268268

269269
out << '\n';
270-
goto_program.output_instruction(ns, irep_idt(), out, *i_it);
270+
goto_program.output_instruction(ns, irep_idt(), out, instruction);
271271
out << '\n';
272272
}
273273
}

src/analyses/locals.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ Date: March 2013
1717

1818
void localst::build(const goto_functiont &goto_function)
1919
{
20-
forall_goto_program_instructions(it, goto_function.body)
20+
for(const auto &instruction : goto_function.body.instructions)
2121
{
22-
if(it->is_decl())
23-
locals.insert(it->get_decl().get_identifier());
22+
if(instruction.is_decl())
23+
locals.insert(instruction.get_decl().get_identifier());
2424
}
2525

2626
locals.insert(

src/goto-cc/linker_script_merge.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,10 @@ int linker_script_merget::pointerize_linker_defined_symbols(
259259
for(auto &gf : goto_model.goto_functions.function_map)
260260
{
261261
goto_programt &program=gf.second.body;
262-
Forall_goto_program_instructions(iit, program)
262+
for(auto &instruction : program.instructions)
263263
{
264-
for(exprt *insts : std::list<exprt *>({&(iit->code), &(iit->guard)}))
264+
for(exprt *insts :
265+
std::list<exprt *>({&(instruction.code), &(instruction.guard)}))
265266
{
266267
std::list<symbol_exprt> to_pointerize;
267268
symbols_to_pointerize(linker_values, *insts, to_pointerize);
@@ -277,7 +278,7 @@ int linker_script_merget::pointerize_linker_defined_symbols(
277278
log.error() << " Could not pointerize '" << sym.get_identifier()
278279
<< "' in function " << gf.first << ". Pretty:\n"
279280
<< sym.pretty() << "\n";
280-
log.error().source_location = iit->source_location;
281+
log.error().source_location = instruction.source_location;
281282
}
282283
log.error() << messaget::eom;
283284
}

src/goto-instrument/accelerate/disjunctive_polynomial_acceleration.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -858,11 +858,11 @@ void disjunctive_polynomial_accelerationt::build_fixed()
858858

859859
fixed.copy_from(goto_program);
860860

861-
Forall_goto_program_instructions(it, fixed)
861+
for(auto &instruction : fixed.instructions)
862862
{
863-
if(it->is_assert())
863+
if(instruction.is_assert())
864864
{
865-
it->type=ASSUME;
865+
instruction.type = ASSUME;
866866
}
867867
}
868868

src/goto-instrument/accelerate/sat_path_enumerator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@ void sat_path_enumeratort::build_fixed()
216216

217217
fixed.copy_from(goto_program);
218218

219-
Forall_goto_program_instructions(it, fixed)
219+
for(auto &instruction : fixed.instructions)
220220
{
221-
if(it->is_assert())
222-
it->type=ASSUME;
221+
if(instruction.is_assert())
222+
instruction.type = ASSUME;
223223
}
224224

225225
// We're only interested in paths that loop back to the loop header.

src/goto-instrument/call_sequences.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,12 @@ static void list_calls_and_arguments(
272272
const namespacet &ns,
273273
const goto_programt &goto_program)
274274
{
275-
forall_goto_program_instructions(i_it, goto_program)
275+
for(const auto &instruction : goto_program.instructions)
276276
{
277-
if(!i_it->is_function_call())
277+
if(!instruction.is_function_call())
278278
continue;
279279

280-
const code_function_callt &call = to_code_function_call(i_it->code);
280+
const code_function_callt &call = to_code_function_call(instruction.code);
281281

282282
const exprt &f=call.function();
283283

src/goto-instrument/count_eloc.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,17 @@ static void collect_eloc(
3636
{
3737
forall_goto_functions(f_it, goto_model.goto_functions)
3838
{
39-
forall_goto_program_instructions(it, f_it->second.body)
39+
for(const auto &instruction : f_it->second.body.instructions)
4040
{
41-
filest &files=dest[it->source_location.get_working_directory()];
42-
const irep_idt &file=it->source_location.get_file();
41+
const auto &source_location = instruction.source_location;
4342

44-
if(!file.empty() &&
45-
!it->source_location.is_built_in())
46-
files[file].insert(it->source_location.get_line());
43+
filest &files = dest[source_location.get_working_directory()];
44+
const irep_idt &file = source_location.get_file();
45+
46+
if(!file.empty() && !source_location.is_built_in())
47+
{
48+
files[file].insert(source_location.get_line());
49+
}
4750
}
4851
}
4952
}

src/goto-instrument/cover_filter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,19 @@ bool trivial_functions_filtert::operator()(
102102
{
103103
(void)function; // unused parameter
104104
unsigned long count_assignments = 0, count_goto = 0;
105-
forall_goto_program_instructions(i_it, goto_function.body)
105+
for(const auto &instruction : goto_function.body.instructions)
106106
{
107-
if(i_it->is_goto())
107+
if(instruction.is_goto())
108108
{
109109
if((++count_goto) >= 2)
110110
return true;
111111
}
112-
else if(i_it->is_assign())
112+
else if(instruction.is_assign())
113113
{
114114
if((++count_assignments) >= 5)
115115
return true;
116116
}
117-
else if(i_it->is_decl())
117+
else if(instruction.is_decl())
118118
return true;
119119
}
120120

src/goto-instrument/document_properties.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,19 @@ void document_propertiest::doit()
278278
{
279279
const goto_programt &goto_program=f_it->second.body;
280280

281-
forall_goto_program_instructions(i_it, goto_program)
281+
for(const auto &instruction : goto_program.instructions)
282282
{
283-
if(i_it->is_assert())
283+
if(instruction.is_assert())
284284
{
285+
const auto &source_location = instruction.source_location;
285286
source_locationt new_source_location;
286287

287-
new_source_location.set_file(i_it->source_location.get_file());
288-
new_source_location.set_line(i_it->source_location.get_line());
289-
new_source_location.set_function(i_it->source_location.get_function());
288+
new_source_location.set_file(source_location.get_file());
289+
new_source_location.set_line(source_location.get_line());
290+
new_source_location.set_function(source_location.get_function());
290291

291-
claim_set[new_source_location].comment_set.
292-
insert(i_it->source_location.get_comment());
292+
claim_set[new_source_location].comment_set.insert(
293+
source_location.get_comment());
293294
}
294295
}
295296
}

src/goto-instrument/goto_program2code.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,26 @@ void goto_program2codet::build_dead_map()
9090
dead_map.clear();
9191

9292
// record last dead X
93-
forall_goto_program_instructions(target, goto_program)
94-
if(target->is_dead())
95-
dead_map[target->get_dead().get_identifier()] = target->location_number;
93+
for(const auto &instruction : goto_program.instructions)
94+
{
95+
if(instruction.is_dead())
96+
{
97+
dead_map[instruction.get_dead().get_identifier()] =
98+
instruction.location_number;
99+
}
100+
}
96101
}
97102

98103
void goto_program2codet::scan_for_varargs()
99104
{
100105
va_list_expr.clear();
101106

102-
forall_goto_program_instructions(target, goto_program)
103-
if(target->is_assign())
107+
for(const auto &instruction : goto_program.instructions)
108+
{
109+
if(instruction.is_assign())
104110
{
105-
const exprt &l = target->get_assign().lhs();
106-
const exprt &r = target->get_assign().rhs();
111+
const exprt &l = instruction.get_assign().lhs();
112+
const exprt &r = instruction.get_assign().rhs();
107113

108114
// find va_start
109115
if(
@@ -120,6 +126,7 @@ void goto_program2codet::scan_for_varargs()
120126
to_typecast_expr(r).op().id()==ID_address_of)
121127
va_list_expr.insert(l);
122128
}
129+
}
123130

124131
if(!va_list_expr.empty())
125132
system_headers.insert("stdarg.h");

src/goto-instrument/model_argc_argv.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ bool model_argc_argv(
151151
message_handler,
152152
main_symbol.mode);
153153

154-
Forall_goto_program_instructions(it, init_instructions)
155-
it->source_location.set_file("<built-in-library>");
154+
for(auto &instruction : init_instructions.instructions)
155+
instruction.source_location.set_file("<built-in-library>");
156156

157157
goto_functionst::function_mapt::iterator start_entry=
158158
goto_model.goto_functions.function_map.find(

0 commit comments

Comments
 (0)