Skip to content

Commit e01fcff

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 a6a0729 commit e01fcff

File tree

74 files changed

+417
-353
lines changed

Some content is hidden

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

74 files changed

+417
-353
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
@@ -984,8 +984,8 @@ static void gather_symbol_live_ranges(
984984
}
985985
else
986986
{
987-
forall_operands(it, e)
988-
gather_symbol_live_ranges(pc, *it, result);
987+
for(const auto &op : e.operands())
988+
gather_symbol_live_ranges(pc, op, result);
989989
}
990990
}
991991

jbmc/src/java_bytecode/java_bytecode_instrument.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,9 @@ optionalt<codet> java_bytecode_instrumentt::instrument_expr(const exprt &expr)
452452
{
453453
code_blockt result;
454454
// First check our operands:
455-
forall_operands(it, expr)
455+
for(const auto &op : expr.operands())
456456
{
457-
if(optionalt<codet> op_result = instrument_expr(*it))
457+
if(optionalt<codet> op_result = instrument_expr(op))
458458
result.add(std::move(*op_result));
459459
}
460460

src/analyses/constant_propagator.cpp

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

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

src/analyses/custom_bitvector_analysis.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,11 @@ bool custom_bitvector_domaint::has_get_must_or_may(const exprt &src)
693693
if(src.id() == ID_get_must || src.id() == ID_get_may)
694694
return true;
695695

696-
forall_operands(it, src)
697-
if(has_get_must_or_may(*it))
696+
for(const auto &op : src.operands())
697+
{
698+
if(has_get_must_or_may(op))
698699
return true;
700+
}
699701

700702
return false;
701703
}

src/analyses/dirty.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ void dirtyt::find_dirty(const exprt &expr)
3131
return;
3232
}
3333

34-
forall_operands(it, expr)
35-
find_dirty(*it);
34+
for(const auto &op : expr.operands())
35+
find_dirty(op);
3636
}
3737

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

src/analyses/goto_check.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,8 +1685,8 @@ void goto_checkt::check_rec(const exprt &expr, guardt &guard)
16851685
return;
16861686
}
16871687

1688-
forall_operands(it, expr)
1689-
check_rec(*it, guard);
1688+
for(const auto &op : expr.operands())
1689+
check_rec(op, guard);
16901690

16911691
if(expr.type().id() == ID_c_enum_tag)
16921692
enum_range_check(expr, guard);

src/analyses/goto_rw.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ void rw_range_sett::get_objects_array(
312312
sub_size = to_range_spect(*subtype_bits);
313313
else
314314
{
315-
forall_operands(it, expr)
316-
get_objects_rec(mode, *it, 0, -1);
315+
for(const auto &op : expr.operands())
316+
get_objects_rec(mode, op, 0, -1);
317317

318318
return;
319319
}
@@ -323,15 +323,15 @@ void rw_range_sett::get_objects_array(
323323
range_spect full_r_e=
324324
size==-1 ? sub_size*expr.operands().size() : full_r_s+size;
325325

326-
forall_operands(it, expr)
326+
for(const auto &op : expr.operands())
327327
{
328328
if(full_r_s<=offset+sub_size && full_r_e>offset)
329329
{
330330
range_spect cur_r_s=full_r_s<=offset ? 0 : full_r_s-offset;
331331
range_spect cur_r_e=
332332
full_r_e>offset+sub_size ? sub_size : full_r_e-offset;
333333

334-
get_objects_rec(mode, *it, cur_r_s, cur_r_e-cur_r_s);
334+
get_objects_rec(mode, op, cur_r_s, cur_r_e - cur_r_s);
335335
}
336336

337337
offset+=sub_size;
@@ -356,23 +356,23 @@ void rw_range_sett::get_objects_struct(
356356
range_spect full_r_s=range_start==-1 ? 0 : range_start;
357357
range_spect full_r_e=size==-1 || full_size==-1 ? -1 : full_r_s+size;
358358

359-
forall_operands(it, expr)
359+
for(const auto &op : expr.operands())
360360
{
361-
auto it_bits = pointer_offset_bits(it->type(), ns);
361+
auto it_bits = pointer_offset_bits(op.type(), ns);
362362

363363
range_spect sub_size = it_bits.has_value() ? to_range_spect(*it_bits) : -1;
364364

365365
if(offset==-1)
366366
{
367-
get_objects_rec(mode, *it, 0, sub_size);
367+
get_objects_rec(mode, op, 0, sub_size);
368368
}
369369
else if(sub_size==-1)
370370
{
371371
if(full_r_e==-1 || full_r_e>offset)
372372
{
373373
range_spect cur_r_s=full_r_s<=offset ? 0 : full_r_s-offset;
374374

375-
get_objects_rec(mode, *it, cur_r_s, -1);
375+
get_objects_rec(mode, op, cur_r_s, -1);
376376
}
377377

378378
offset=-1;
@@ -383,7 +383,7 @@ void rw_range_sett::get_objects_struct(
383383
{
384384
range_spect cur_r_s=full_r_s<=offset ? 0 : full_r_s-offset;
385385

386-
get_objects_rec(mode, *it, cur_r_s, sub_size-cur_r_s);
386+
get_objects_rec(mode, op, cur_r_s, sub_size - cur_r_s);
387387
}
388388

389389
offset+=sub_size;
@@ -394,7 +394,7 @@ void rw_range_sett::get_objects_struct(
394394
range_spect cur_r_e=
395395
full_r_e>offset+sub_size ? sub_size : full_r_e-offset;
396396

397-
get_objects_rec(mode, *it, cur_r_s, cur_r_e-cur_r_s);
397+
get_objects_rec(mode, op, cur_r_s, cur_r_e - cur_r_s);
398398

399399
offset+=sub_size;
400400
}
@@ -579,8 +579,8 @@ void rw_range_sett::get_objects_rec(
579579
// possibly affects the full object size, even if range_start/size
580580
// are only a subset of the bytes (e.g., when using the result of
581581
// arithmetic operations)
582-
forall_operands(it, expr)
583-
get_objects_rec(mode, *it);
582+
for(const auto &op : expr.operands())
583+
get_objects_rec(mode, op);
584584
}
585585
else if(expr.id() == ID_null_object ||
586586
expr.id() == ID_string_constant)
@@ -589,8 +589,8 @@ void rw_range_sett::get_objects_rec(
589589
}
590590
else if(mode==get_modet::LHS_W)
591591
{
592-
forall_operands(it, expr)
593-
get_objects_rec(mode, *it);
592+
for(const auto &op : expr.operands())
593+
get_objects_rec(mode, op);
594594
}
595595
else
596596
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
@@ -391,14 +391,18 @@ void interval_domaint::assume_rec(
391391
else if(cond.id()==ID_and)
392392
{
393393
if(!negation)
394-
forall_operands(it, cond)
395-
assume_rec(*it, false);
394+
{
395+
for(const auto &op : cond.operands())
396+
assume_rec(op, false);
397+
}
396398
}
397399
else if(cond.id()==ID_or)
398400
{
399401
if(negation)
400-
forall_operands(it, cond)
401-
assume_rec(*it, true);
402+
{
403+
for(const auto &op : cond.operands())
404+
assume_rec(op, true);
405+
}
402406
}
403407
}
404408

src/analyses/invariant_set.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,8 @@ void invariant_sett::strengthen_rec(const exprt &expr)
412412
}
413413
else if(expr.id()==ID_and)
414414
{
415-
forall_operands(it, expr)
416-
strengthen_rec(*it);
415+
for(const auto &op : expr.operands())
416+
strengthen_rec(op);
417417
}
418418
else if(expr.id()==ID_le ||
419419
expr.id()==ID_lt)
@@ -427,10 +427,10 @@ void invariant_sett::strengthen_rec(const exprt &expr)
427427
{
428428
const exprt &bitand_op = rel.op1();
429429

430-
forall_operands(it, bitand_op)
430+
for(const auto &op : bitand_op.operands())
431431
{
432432
auto tmp(rel);
433-
tmp.op1()=*it;
433+
tmp.op1() = op;
434434
strengthen_rec(tmp);
435435
}
436436

@@ -502,10 +502,10 @@ void invariant_sett::strengthen_rec(const exprt &expr)
502502
{
503503
const exprt &bitand_op = equal_expr.op1();
504504

505-
forall_operands(it, bitand_op)
505+
for(const auto &op : bitand_op.operands())
506506
{
507507
auto tmp(equal_expr);
508-
tmp.op1()=*it;
508+
tmp.op1() = op;
509509
tmp.id(ID_le);
510510
strengthen_rec(tmp);
511511
}
@@ -605,17 +605,21 @@ tvt invariant_sett::implies_rec(const exprt &expr) const
605605
}
606606
else if(expr.id()==ID_and)
607607
{
608-
forall_operands(it, expr)
609-
if(implies_rec(*it)!=tvt(true))
608+
for(const auto &op : expr.operands())
609+
{
610+
if(implies_rec(op) != tvt(true))
610611
return tvt::unknown();
612+
}
611613

612614
return tvt(true);
613615
}
614616
else if(expr.id()==ID_or)
615617
{
616-
forall_operands(it, expr)
617-
if(implies_rec(*it)==tvt(true))
618+
for(const auto &op : expr.operands())
619+
{
620+
if(implies_rec(op) == tvt(true))
618621
return tvt(true);
622+
}
619623
}
620624
else if(expr.id()==ID_le ||
621625
expr.id()==ID_lt ||
@@ -1055,8 +1059,8 @@ void invariant_sett::apply_code(const codet &code)
10551059

10561060
if(statement==ID_block)
10571061
{
1058-
forall_operands(it, code)
1059-
apply_code(to_code(*it));
1062+
for(const auto &op : code.operands())
1063+
apply_code(to_code(op));
10601064
}
10611065
else if(statement==ID_assign)
10621066
{

src/ansi-c/ansi_c_convert_type.cpp

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

206-
forall_operands(it, as_expr)
206+
for(const auto &op : as_expr.operands())
207207
{
208208
// these are symbols
209-
const irep_idt &id=it->get(ID_identifier);
209+
const irep_idt &id = op.get(ID_identifier);
210210

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

src/ansi-c/c_storage_spec.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ void c_storage_spect::read(const typet &type)
4343
{
4444
const exprt &as_expr=
4545
static_cast<const exprt &>(static_cast<const irept &>(type));
46-
forall_operands(it, as_expr)
47-
if(it->id()==ID_thread)
46+
for(const auto &op : as_expr.operands())
47+
{
48+
if(op.id() == ID_thread)
4849
is_thread_local=true;
50+
}
4951
}
5052
else if(type.id()==ID_alias &&
5153
type.has_subtype() &&

src/ansi-c/c_typecheck_expr.cpp

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

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

581581
exprt result=from_integer(0, size_type());
582582

583-
forall_operands(m_it, member)
583+
for(const auto &op : member.operands())
584584
{
585585
type = follow(type);
586586

587-
if(m_it->id()==ID_member)
587+
if(op.id() == ID_member)
588588
{
589589
if(type.id()!=ID_union && type.id()!=ID_struct)
590590
{
@@ -595,7 +595,7 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
595595
}
596596

597597
bool found=false;
598-
irep_idt component_name=m_it->get(ID_component_name);
598+
irep_idt component_name = op.get(ID_component_name);
599599

600600
while(!found)
601601
{
@@ -681,7 +681,7 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
681681
}
682682
}
683683
}
684-
else if(m_it->id()==ID_index)
684+
else if(op.id() == ID_index)
685685
{
686686
if(type.id()!=ID_array)
687687
{
@@ -690,7 +690,7 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
690690
throw 0;
691691
}
692692

693-
exprt index = to_unary_expr(*m_it).op();
693+
exprt index = to_unary_expr(op).op();
694694

695695
// still need to typecheck index
696696
typecheck_expr(index);

src/ansi-c/c_typecheck_initializer.cpp

Lines changed: 1 addition & 2 deletions
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)