Skip to content

Commit 680354a

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 f0a4e75 commit 680354a

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
@@ -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
@@ -449,9 +449,9 @@ optionalt<codet> java_bytecode_instrumentt::instrument_expr(const exprt &expr)
449449
{
450450
code_blockt result;
451451
// First check our operands:
452-
forall_operands(it, expr)
452+
for(const auto &op : expr.operands())
453453
{
454-
if(optionalt<codet> op_result = instrument_expr(*it))
454+
if(optionalt<codet> op_result = instrument_expr(op))
455455
result.add(std::move(*op_result));
456456
}
457457

src/analyses/constant_propagator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ bool constant_propagator_domaint::two_way_propagate_rec(
322322
{
323323
change_this_time = false;
324324

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

src/analyses/custom_bitvector_analysis.cpp

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

693-
forall_operands(it, src)
694-
if(has_get_must_or_may(*it))
693+
for(const auto &op : src.operands())
694+
{
695+
if(has_get_must_or_may(op))
695696
return true;
697+
}
696698

697699
return false;
698700
}

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
@@ -1733,8 +1733,8 @@ void goto_checkt::check_rec(const exprt &expr, guardt &guard)
17331733
return;
17341734
}
17351735

1736-
forall_operands(it, expr)
1737-
check_rec(*it, guard);
1736+
for(const auto &op : expr.operands())
1737+
check_rec(op, guard);
17381738

17391739
if(expr.type().id() == ID_c_enum_tag)
17401740
enum_range_check(expr, guard);

src/analyses/goto_rw.cpp

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

315315
return;
316316
}
@@ -320,15 +320,15 @@ void rw_range_sett::get_objects_array(
320320
range_spect full_r_e=
321321
size==-1 ? sub_size*expr.operands().size() : full_r_s+size;
322322

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

331-
get_objects_rec(mode, *it, cur_r_s, cur_r_e-cur_r_s);
331+
get_objects_rec(mode, op, cur_r_s, cur_r_e - cur_r_s);
332332
}
333333

334334
offset+=sub_size;
@@ -353,23 +353,23 @@ void rw_range_sett::get_objects_struct(
353353
range_spect full_r_s=range_start==-1 ? 0 : range_start;
354354
range_spect full_r_e=size==-1 || full_size==-1 ? -1 : full_r_s+size;
355355

356-
forall_operands(it, expr)
356+
for(const auto &op : expr.operands())
357357
{
358-
auto it_bits = pointer_offset_bits(it->type(), ns);
358+
auto it_bits = pointer_offset_bits(op.type(), ns);
359359

360360
range_spect sub_size = it_bits.has_value() ? to_range_spect(*it_bits) : -1;
361361

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

372-
get_objects_rec(mode, *it, cur_r_s, -1);
372+
get_objects_rec(mode, op, cur_r_s, -1);
373373
}
374374

375375
offset=-1;
@@ -380,7 +380,7 @@ void rw_range_sett::get_objects_struct(
380380
{
381381
range_spect cur_r_s=full_r_s<=offset ? 0 : full_r_s-offset;
382382

383-
get_objects_rec(mode, *it, cur_r_s, sub_size-cur_r_s);
383+
get_objects_rec(mode, op, cur_r_s, sub_size - cur_r_s);
384384
}
385385

386386
offset+=sub_size;
@@ -391,7 +391,7 @@ void rw_range_sett::get_objects_struct(
391391
range_spect cur_r_e=
392392
full_r_e>offset+sub_size ? sub_size : full_r_e-offset;
393393

394-
get_objects_rec(mode, *it, cur_r_s, cur_r_e-cur_r_s);
394+
get_objects_rec(mode, op, cur_r_s, cur_r_e - cur_r_s);
395395

396396
offset+=sub_size;
397397
}
@@ -576,8 +576,8 @@ void rw_range_sett::get_objects_rec(
576576
// possibly affects the full object size, even if range_start/size
577577
// are only a subset of the bytes (e.g., when using the result of
578578
// arithmetic operations)
579-
forall_operands(it, expr)
580-
get_objects_rec(mode, *it);
579+
for(const auto &op : expr.operands())
580+
get_objects_rec(mode, op);
581581
}
582582
else if(expr.id() == ID_null_object ||
583583
expr.id() == ID_string_constant)
@@ -586,8 +586,8 @@ void rw_range_sett::get_objects_rec(
586586
}
587587
else if(mode==get_modet::LHS_W)
588588
{
589-
forall_operands(it, expr)
590-
get_objects_rec(mode, *it);
589+
for(const auto &op : expr.operands())
590+
get_objects_rec(mode, op);
591591
}
592592
else
593593
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
@@ -410,8 +410,8 @@ void invariant_sett::strengthen_rec(const exprt &expr)
410410
}
411411
else if(expr.id()==ID_and)
412412
{
413-
forall_operands(it, expr)
414-
strengthen_rec(*it);
413+
for(const auto &op : expr.operands())
414+
strengthen_rec(op);
415415
}
416416
else if(expr.id()==ID_le ||
417417
expr.id()==ID_lt)
@@ -425,10 +425,10 @@ void invariant_sett::strengthen_rec(const exprt &expr)
425425
{
426426
const exprt &bitand_op = rel.op1();
427427

428-
forall_operands(it, bitand_op)
428+
for(const auto &op : bitand_op.operands())
429429
{
430430
auto tmp(rel);
431-
tmp.op1()=*it;
431+
tmp.op1() = op;
432432
strengthen_rec(tmp);
433433
}
434434

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

503-
forall_operands(it, bitand_op)
503+
for(const auto &op : bitand_op.operands())
504504
{
505505
auto tmp(equal_expr);
506-
tmp.op1()=*it;
506+
tmp.op1() = op;
507507
tmp.id(ID_le);
508508
strengthen_rec(tmp);
509509
}
@@ -603,17 +603,21 @@ tvt invariant_sett::implies_rec(const exprt &expr) const
603603
}
604604
else if(expr.id()==ID_and)
605605
{
606-
forall_operands(it, expr)
607-
if(implies_rec(*it)!=tvt(true))
606+
for(const auto &op : expr.operands())
607+
{
608+
if(implies_rec(op) != tvt(true))
608609
return tvt::unknown();
610+
}
609611

610612
return tvt(true);
611613
}
612614
else if(expr.id()==ID_or)
613615
{
614-
forall_operands(it, expr)
615-
if(implies_rec(*it)==tvt(true))
616+
for(const auto &op : expr.operands())
617+
{
618+
if(implies_rec(op) == tvt(true))
616619
return tvt(true);
620+
}
617621
}
618622
else if(expr.id()==ID_le ||
619623
expr.id()==ID_lt ||
@@ -1050,8 +1054,8 @@ void invariant_sett::apply_code(const codet &code)
10501054

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

src/ansi-c/ansi_c_convert_type.cpp

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

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

208208
if(id==ID_thread)
209209
c_storage_spec.is_thread_local=true;
210210
else if(id=="align")
211211
{
212212
aligned=true;
213-
alignment = to_unary_expr(*it).op();
213+
alignment = to_unary_expr(op).op();
214214
}
215215
}
216216
}

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(type.id()==ID_alias &&
5052
type.has_subtype() &&

src/ansi-c/c_typecheck_expr.cpp

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

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

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

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

594-
if(m_it->id()==ID_member)
594+
if(op.id() == ID_member)
595595
{
596596
if(type.id()!=ID_union && type.id()!=ID_struct)
597597
{
@@ -602,7 +602,7 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
602602
}
603603

604604
bool found=false;
605-
irep_idt component_name=m_it->get(ID_component_name);
605+
irep_idt component_name = op.get(ID_component_name);
606606

607607
while(!found)
608608
{
@@ -688,7 +688,7 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
688688
}
689689
}
690690
}
691-
else if(m_it->id()==ID_index)
691+
else if(op.id() == ID_index)
692692
{
693693
if(type.id()!=ID_array)
694694
{
@@ -697,7 +697,7 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
697697
throw 0;
698698
}
699699

700-
exprt index = to_unary_expr(*m_it).op();
700+
exprt index = to_unary_expr(op).op();
701701

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

src/ansi-c/c_typecheck_initializer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,9 +780,8 @@ designatort c_typecheck_baset::make_designator(
780780
typet type=src_type;
781781
designatort designator;
782782

783-
forall_operands(it, src)
783+
for(const auto &d_op : src.operands())
784784
{
785-
const exprt &d_op=*it;
786785
designatort::entryt entry(type);
787786
const typet &full_type=follow(entry.type);
788787

0 commit comments

Comments
 (0)