Skip to content

Commit 011bc44

Browse files
committed
Replace some uses of forall_operands by ranged-for
In some (but not all!) cases of forall_operands we do not actually need the iterator.
1 parent 02d698e commit 011bc44

File tree

71 files changed

+406
-342
lines changed

Some content is hidden

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

71 files changed

+406
-342
lines changed

jbmc/src/java_bytecode/ci_lazy_methods.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,10 @@ void ci_lazy_methodst::gather_needed_globals(
526526
}
527527
}
528528
else
529-
forall_operands(opit, e)
530-
gather_needed_globals(*opit, symbol_table, needed);
529+
{
530+
for(const auto &op : e.operands())
531+
gather_needed_globals(op, symbol_table, needed);
532+
}
531533
}
532534

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

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -976,8 +976,8 @@ static void gather_symbol_live_ranges(
976976
}
977977
else
978978
{
979-
forall_operands(it, e)
980-
gather_symbol_live_ranges(pc, *it, result);
979+
for(const auto &op : e.operands())
980+
gather_symbol_live_ranges(pc, op, result);
981981
}
982982
}
983983

jbmc/src/java_bytecode/java_bytecode_instrument.cpp

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,9 @@ bool constant_propagator_domaint::two_way_propagate_rec(
325325
{
326326
change_this_time = false;
327327

328-
forall_operands(it, expr)
328+
for(const auto &op : expr.operands())
329329
{
330-
change_this_time |= two_way_propagate_rec(*it, ns, cp);
330+
change_this_time |= two_way_propagate_rec(op, ns, cp);
331331
if(change_this_time)
332332
change = true;
333333
}

src/analyses/custom_bitvector_analysis.cpp

Lines changed: 4 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ void rw_range_sett::get_objects_array(
331331

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

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

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

359-
get_objects_rec(mode, *it, cur_r_s, cur_r_e-cur_r_s);
359+
get_objects_rec(mode, op, cur_r_s, cur_r_e - cur_r_s);
360360
}
361361

362362
offset+=sub_size;
@@ -385,17 +385,17 @@ void rw_range_sett::get_objects_struct(
385385
? range_spect::unknown()
386386
: full_r_s + size;
387387

388-
forall_operands(it, expr)
388+
for(const auto &op : expr.operands())
389389
{
390-
auto it_bits = pointer_offset_bits(it->type(), ns);
390+
auto it_bits = pointer_offset_bits(op.type(), ns);
391391

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

396396
if(offset.is_unknown())
397397
{
398-
get_objects_rec(mode, *it, range_spect{0}, sub_size);
398+
get_objects_rec(mode, op, range_spect{0}, sub_size);
399399
}
400400
else if(sub_size.is_unknown())
401401
{
@@ -404,7 +404,7 @@ void rw_range_sett::get_objects_struct(
404404
range_spect cur_r_s =
405405
full_r_s <= offset ? range_spect{0} : full_r_s - offset;
406406

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

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

419-
get_objects_rec(mode, *it, cur_r_s, sub_size-cur_r_s);
419+
get_objects_rec(mode, op, cur_r_s, sub_size - cur_r_s);
420420
}
421421

422422
offset+=sub_size;
@@ -428,7 +428,7 @@ void rw_range_sett::get_objects_struct(
428428
range_spect cur_r_e=
429429
full_r_e>offset+sub_size ? sub_size : full_r_e-offset;
430430

431-
get_objects_rec(mode, *it, cur_r_s, cur_r_e-cur_r_s);
431+
get_objects_rec(mode, op, cur_r_s, cur_r_e - cur_r_s);
432432

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

src/analyses/interval_domain.cpp

Lines changed: 8 additions & 4 deletions
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

Lines changed: 16 additions & 12 deletions
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,17 @@ void ansi_c_convert_typet::read_rec(const typet &type)
209209
const exprt &as_expr=
210210
static_cast<const exprt &>(static_cast<const irept &>(type));
211211

212-
forall_operands(it, as_expr)
212+
for(const auto &op : as_expr.operands())
213213
{
214214
// these are symbols
215-
const irep_idt &id=it->get(ID_identifier);
215+
const irep_idt &id = op.get(ID_identifier);
216216

217217
if(id==ID_thread)
218218
c_storage_spec.is_thread_local=true;
219219
else if(id=="align")
220220
{
221221
aligned=true;
222-
alignment = to_unary_expr(*it).op();
222+
alignment = to_unary_expr(op).op();
223223
}
224224
}
225225
}

src/ansi-c/c_storage_spec.cpp

Lines changed: 4 additions & 2 deletions
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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -587,15 +587,15 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
587587
typet &type=static_cast<typet &>(expr.add(ID_type_arg));
588588
typecheck_type(type);
589589

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

592592
exprt result=from_integer(0, size_type());
593593

594-
forall_operands(m_it, member)
594+
for(const auto &op : member.operands())
595595
{
596596
type = follow(type);
597597

598-
if(m_it->id()==ID_member)
598+
if(op.id() == ID_member)
599599
{
600600
if(type.id()!=ID_union && type.id()!=ID_struct)
601601
{
@@ -606,7 +606,7 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
606606
}
607607

608608
bool found=false;
609-
irep_idt component_name=m_it->get(ID_component_name);
609+
irep_idt component_name = op.get(ID_component_name);
610610

611611
while(!found)
612612
{
@@ -692,7 +692,7 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
692692
}
693693
}
694694
}
695-
else if(m_it->id()==ID_index)
695+
else if(op.id() == ID_index)
696696
{
697697
if(type.id()!=ID_array)
698698
{
@@ -701,7 +701,7 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
701701
throw 0;
702702
}
703703

704-
exprt index = to_unary_expr(*m_it).op();
704+
exprt index = to_unary_expr(op).op();
705705

706706
// still need to typecheck index
707707
typecheck_expr(index);

src/ansi-c/c_typecheck_initializer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,9 +774,8 @@ designatort c_typecheck_baset::make_designator(
774774
typet type=src_type;
775775
designatort designator;
776776

777-
forall_operands(it, src)
777+
for(const auto &d_op : src.operands())
778778
{
779-
const exprt &d_op=*it;
780779
designatort::entryt entry(type);
781780
const typet &full_type=follow(entry.type);
782781

0 commit comments

Comments
 (0)