Skip to content

Commit 837cd1b

Browse files
authored
Merge pull request #5790 from tautschnig/forall-operands
Replace some uses of forall_operands by ranged-for
2 parents 7b5945b + 7cb1f5b commit 837cd1b

File tree

70 files changed

+412
-348
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+412
-348
lines changed

jbmc/src/java_bytecode/ci_lazy_methods.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,10 @@ void ci_lazy_methodst::gather_needed_globals(
537537
}
538538
}
539539
else
540-
forall_operands(opit, e)
541-
gather_needed_globals(*opit, symbol_table, needed);
540+
{
541+
for(const auto &op : e.operands())
542+
gather_needed_globals(op, symbol_table, needed);
543+
}
542544
}
543545

544546
/// Find a virtual callee, if one is defined and the callee type is known to

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -971,8 +971,8 @@ static void gather_symbol_live_ranges(
971971
}
972972
else
973973
{
974-
forall_operands(it, e)
975-
gather_symbol_live_ranges(pc, *it, result);
974+
for(const auto &op : e.operands())
975+
gather_symbol_live_ranges(pc, op, result);
976976
}
977977
}
978978

jbmc/src/java_bytecode/java_bytecode_instrument.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,9 @@ optionalt<codet> java_bytecode_instrumentt::instrument_expr(const exprt &expr)
451451
{
452452
code_blockt result;
453453
// First check our operands:
454-
forall_operands(it, expr)
454+
for(const auto &op : expr.operands())
455455
{
456-
if(optionalt<codet> op_result = instrument_expr(*it))
456+
if(optionalt<codet> op_result = instrument_expr(op))
457457
result.add(std::move(*op_result));
458458
}
459459

src/analyses/constant_propagator.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,9 @@ bool constant_propagator_domaint::two_way_propagate_rec(
324324
{
325325
change_this_time = false;
326326

327-
forall_operands(it, expr)
327+
for(const auto &op : expr.operands())
328328
{
329-
change_this_time |= two_way_propagate_rec(*it, ns, cp);
329+
change_this_time |= two_way_propagate_rec(op, ns, cp);
330330
if(change_this_time)
331331
change = true;
332332
}

src/analyses/custom_bitvector_analysis.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -687,9 +687,11 @@ bool custom_bitvector_domaint::has_get_must_or_may(const exprt &src)
687687
if(src.id() == ID_get_must || src.id() == ID_get_may)
688688
return true;
689689

690-
forall_operands(it, src)
691-
if(has_get_must_or_may(*it))
690+
for(const auto &op : src.operands())
691+
{
692+
if(has_get_must_or_may(op))
692693
return true;
694+
}
693695

694696
return false;
695697
}

src/analyses/dirty.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ void dirtyt::search_other(const goto_programt::instructiont &instruction)
4444
statement == ID_array_replace || statement == ID_havoc_object ||
4545
statement == ID_input || statement == ID_output)
4646
{
47-
forall_operands(it, code)
48-
find_dirty(*it);
47+
for(const auto &op : code.operands())
48+
find_dirty(op);
4949
}
5050
// other possible cases according to goto_programt::instructiont::output
5151
// and goto_symext::symex_other:
@@ -66,8 +66,8 @@ void dirtyt::find_dirty(const exprt &expr)
6666
return;
6767
}
6868

69-
forall_operands(it, expr)
70-
find_dirty(*it);
69+
for(const auto &op : expr.operands())
70+
find_dirty(op);
7171
}
7272

7373
void dirtyt::find_dirty_address_of(const exprt &expr)

src/analyses/goto_rw.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ void rw_range_sett::get_objects_array(
330330

331331
if(!subtype_bits.has_value())
332332
{
333-
forall_operands(it, expr)
334-
get_objects_rec(mode, *it, range_spect{0}, range_spect::unknown());
333+
for(const auto &op : expr.operands())
334+
get_objects_rec(mode, op, range_spect{0}, range_spect::unknown());
335335

336336
return;
337337
}
@@ -346,7 +346,7 @@ void rw_range_sett::get_objects_array(
346346
? sub_size * range_spect::to_range_spect(expr.operands().size())
347347
: full_r_s + size;
348348

349-
forall_operands(it, expr)
349+
for(const auto &op : expr.operands())
350350
{
351351
if(full_r_s<=offset+sub_size && full_r_e>offset)
352352
{
@@ -355,7 +355,7 @@ void rw_range_sett::get_objects_array(
355355
range_spect cur_r_e=
356356
full_r_e>offset+sub_size ? sub_size : full_r_e-offset;
357357

358-
get_objects_rec(mode, *it, cur_r_s, cur_r_e-cur_r_s);
358+
get_objects_rec(mode, op, cur_r_s, cur_r_e - cur_r_s);
359359
}
360360

361361
offset+=sub_size;
@@ -384,17 +384,17 @@ void rw_range_sett::get_objects_struct(
384384
? range_spect::unknown()
385385
: full_r_s + size;
386386

387-
forall_operands(it, expr)
387+
for(const auto &op : expr.operands())
388388
{
389-
auto it_bits = pointer_offset_bits(it->type(), ns);
389+
auto it_bits = pointer_offset_bits(op.type(), ns);
390390

391391
range_spect sub_size = it_bits.has_value()
392392
? range_spect::to_range_spect(*it_bits)
393393
: range_spect::unknown();
394394

395395
if(offset.is_unknown())
396396
{
397-
get_objects_rec(mode, *it, range_spect{0}, sub_size);
397+
get_objects_rec(mode, op, range_spect{0}, sub_size);
398398
}
399399
else if(sub_size.is_unknown())
400400
{
@@ -403,7 +403,7 @@ void rw_range_sett::get_objects_struct(
403403
range_spect cur_r_s =
404404
full_r_s <= offset ? range_spect{0} : full_r_s - offset;
405405

406-
get_objects_rec(mode, *it, cur_r_s, range_spect::unknown());
406+
get_objects_rec(mode, op, cur_r_s, range_spect::unknown());
407407
}
408408

409409
offset = range_spect::unknown();
@@ -415,7 +415,7 @@ void rw_range_sett::get_objects_struct(
415415
range_spect cur_r_s =
416416
full_r_s <= offset ? range_spect{0} : full_r_s - offset;
417417

418-
get_objects_rec(mode, *it, cur_r_s, sub_size-cur_r_s);
418+
get_objects_rec(mode, op, cur_r_s, sub_size - cur_r_s);
419419
}
420420

421421
offset+=sub_size;
@@ -427,7 +427,7 @@ void rw_range_sett::get_objects_struct(
427427
range_spect cur_r_e=
428428
full_r_e>offset+sub_size ? sub_size : full_r_e-offset;
429429

430-
get_objects_rec(mode, *it, cur_r_s, cur_r_e-cur_r_s);
430+
get_objects_rec(mode, op, cur_r_s, cur_r_e - cur_r_s);
431431

432432
offset+=sub_size;
433433
}
@@ -619,8 +619,8 @@ void rw_range_sett::get_objects_rec(
619619
// possibly affects the full object size, even if range_start/size
620620
// are only a subset of the bytes (e.g., when using the result of
621621
// arithmetic operations)
622-
forall_operands(it, expr)
623-
get_objects_rec(mode, *it);
622+
for(const auto &op : expr.operands())
623+
get_objects_rec(mode, op);
624624
}
625625
else if(expr.id() == ID_null_object ||
626626
expr.id() == ID_string_constant)
@@ -629,8 +629,8 @@ void rw_range_sett::get_objects_rec(
629629
}
630630
else if(mode==get_modet::LHS_W)
631631
{
632-
forall_operands(it, expr)
633-
get_objects_rec(mode, *it);
632+
for(const auto &op : expr.operands())
633+
get_objects_rec(mode, op);
634634
}
635635
else
636636
throw "rw_range_sett: assignment to '" + expr.id_string() + "' not handled";

src/analyses/interval_domain.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -390,14 +390,18 @@ void interval_domaint::assume_rec(
390390
else if(cond.id()==ID_and)
391391
{
392392
if(!negation)
393-
forall_operands(it, cond)
394-
assume_rec(*it, false);
393+
{
394+
for(const auto &op : cond.operands())
395+
assume_rec(op, false);
396+
}
395397
}
396398
else if(cond.id()==ID_or)
397399
{
398400
if(negation)
399-
forall_operands(it, cond)
400-
assume_rec(*it, true);
401+
{
402+
for(const auto &op : cond.operands())
403+
assume_rec(op, true);
404+
}
401405
}
402406
}
403407

src/analyses/invariant_set.cpp

+16-12
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ void invariant_sett::strengthen_rec(const exprt &expr)
409409
}
410410
else if(expr.id()==ID_and)
411411
{
412-
forall_operands(it, expr)
413-
strengthen_rec(*it);
412+
for(const auto &op : expr.operands())
413+
strengthen_rec(op);
414414
}
415415
else if(expr.id()==ID_le ||
416416
expr.id()==ID_lt)
@@ -424,10 +424,10 @@ void invariant_sett::strengthen_rec(const exprt &expr)
424424
{
425425
const exprt &bitand_op = rel.op1();
426426

427-
forall_operands(it, bitand_op)
427+
for(const auto &op : bitand_op.operands())
428428
{
429429
auto tmp(rel);
430-
tmp.op1()=*it;
430+
tmp.op1() = op;
431431
strengthen_rec(tmp);
432432
}
433433

@@ -499,10 +499,10 @@ void invariant_sett::strengthen_rec(const exprt &expr)
499499
{
500500
const exprt &bitand_op = equal_expr.op1();
501501

502-
forall_operands(it, bitand_op)
502+
for(const auto &op : bitand_op.operands())
503503
{
504504
auto tmp(equal_expr);
505-
tmp.op1()=*it;
505+
tmp.op1() = op;
506506
tmp.id(ID_le);
507507
strengthen_rec(tmp);
508508
}
@@ -602,17 +602,21 @@ tvt invariant_sett::implies_rec(const exprt &expr) const
602602
}
603603
else if(expr.id()==ID_and)
604604
{
605-
forall_operands(it, expr)
606-
if(implies_rec(*it)!=tvt(true))
605+
for(const auto &op : expr.operands())
606+
{
607+
if(implies_rec(op) != tvt(true))
607608
return tvt::unknown();
609+
}
608610

609611
return tvt(true);
610612
}
611613
else if(expr.id()==ID_or)
612614
{
613-
forall_operands(it, expr)
614-
if(implies_rec(*it)==tvt(true))
615+
for(const auto &op : expr.operands())
616+
{
617+
if(implies_rec(op) == tvt(true))
615618
return tvt(true);
619+
}
616620
}
617621
else if(expr.id()==ID_le ||
618622
expr.id()==ID_lt ||
@@ -1049,8 +1053,8 @@ void invariant_sett::apply_code(const codet &code)
10491053

10501054
if(statement==ID_block)
10511055
{
1052-
forall_operands(it, code)
1053-
apply_code(to_code(*it));
1056+
for(const auto &op : code.operands())
1057+
apply_code(to_code(op));
10541058
}
10551059
else if(statement==ID_assign)
10561060
{

src/ansi-c/ansi_c_convert_type.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,17 @@ void ansi_c_convert_typet::read_rec(const typet &type)
202202
const exprt &as_expr=
203203
static_cast<const exprt &>(static_cast<const irept &>(type));
204204

205-
forall_operands(it, as_expr)
205+
for(const auto &op : as_expr.operands())
206206
{
207207
// these are symbols
208-
const irep_idt &id=it->get(ID_identifier);
208+
const irep_idt &id = op.get(ID_identifier);
209209

210210
if(id==ID_thread)
211211
c_storage_spec.is_thread_local=true;
212212
else if(id=="align")
213213
{
214214
aligned=true;
215-
alignment = to_unary_expr(*it).op();
215+
alignment = to_unary_expr(op).op();
216216
}
217217
}
218218
}

src/ansi-c/c_storage_spec.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ void c_storage_spect::read(const typet &type)
4242
{
4343
const exprt &as_expr=
4444
static_cast<const exprt &>(static_cast<const irept &>(type));
45-
forall_operands(it, as_expr)
46-
if(it->id()==ID_thread)
45+
for(const auto &op : as_expr.operands())
46+
{
47+
if(op.id() == ID_thread)
4748
is_thread_local=true;
49+
}
4850
}
4951
else if(
5052
type.id() == ID_alias && type.has_subtype() &&

src/ansi-c/c_typecheck_expr.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -584,15 +584,15 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
584584
typet &type=static_cast<typet &>(expr.add(ID_type_arg));
585585
typecheck_type(type);
586586

587-
exprt &member=static_cast<exprt &>(expr.add(ID_designator));
587+
const exprt &member = static_cast<const exprt &>(expr.add(ID_designator));
588588

589589
exprt result=from_integer(0, size_type());
590590

591-
forall_operands(m_it, member)
591+
for(const auto &op : member.operands())
592592
{
593593
type = follow(type);
594594

595-
if(m_it->id()==ID_member)
595+
if(op.id() == ID_member)
596596
{
597597
if(type.id()!=ID_union && type.id()!=ID_struct)
598598
{
@@ -603,7 +603,7 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
603603
}
604604

605605
bool found=false;
606-
irep_idt component_name=m_it->get(ID_component_name);
606+
irep_idt component_name = op.get(ID_component_name);
607607

608608
while(!found)
609609
{
@@ -689,7 +689,7 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
689689
}
690690
}
691691
}
692-
else if(m_it->id()==ID_index)
692+
else if(op.id() == ID_index)
693693
{
694694
if(type.id()!=ID_array)
695695
{
@@ -698,7 +698,7 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
698698
throw 0;
699699
}
700700

701-
exprt index = to_unary_expr(*m_it).op();
701+
exprt index = to_unary_expr(op).op();
702702

703703
// still need to typecheck index
704704
typecheck_expr(index);

src/ansi-c/c_typecheck_initializer.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -775,9 +775,8 @@ designatort c_typecheck_baset::make_designator(
775775
typet type=src_type;
776776
designatort designator;
777777

778-
forall_operands(it, src)
778+
for(const auto &d_op : src.operands())
779779
{
780-
const exprt &d_op=*it;
781780
designatort::entryt entry(type);
782781
const typet &full_type=follow(entry.type);
783782

0 commit comments

Comments
 (0)