Skip to content

Replace some uses of forall_operands by ranged-for #5790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions jbmc/src/java_bytecode/ci_lazy_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,10 @@ void ci_lazy_methodst::gather_needed_globals(
}
}
else
forall_operands(opit, e)
gather_needed_globals(*opit, symbol_table, needed);
{
for(const auto &op : e.operands())
gather_needed_globals(op, symbol_table, needed);
}
}

/// Find a virtual callee, if one is defined and the callee type is known to
Expand Down
4 changes: 2 additions & 2 deletions jbmc/src/java_bytecode/java_bytecode_convert_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,8 +978,8 @@ static void gather_symbol_live_ranges(
}
else
{
forall_operands(it, e)
gather_symbol_live_ranges(pc, *it, result);
for(const auto &op : e.operands())
gather_symbol_live_ranges(pc, op, result);
}
}

Expand Down
4 changes: 2 additions & 2 deletions jbmc/src/java_bytecode/java_bytecode_instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,9 @@ optionalt<codet> java_bytecode_instrumentt::instrument_expr(const exprt &expr)
{
code_blockt result;
// First check our operands:
forall_operands(it, expr)
for(const auto &op : expr.operands())
{
if(optionalt<codet> op_result = instrument_expr(*it))
if(optionalt<codet> op_result = instrument_expr(op))
result.add(std::move(*op_result));
}

Expand Down
4 changes: 2 additions & 2 deletions src/analyses/constant_propagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,9 @@ bool constant_propagator_domaint::two_way_propagate_rec(
{
change_this_time = false;

forall_operands(it, expr)
for(const auto &op : expr.operands())
{
change_this_time |= two_way_propagate_rec(*it, ns, cp);
change_this_time |= two_way_propagate_rec(op, ns, cp);
if(change_this_time)
change = true;
}
Expand Down
6 changes: 4 additions & 2 deletions src/analyses/custom_bitvector_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,11 @@ bool custom_bitvector_domaint::has_get_must_or_may(const exprt &src)
if(src.id() == ID_get_must || src.id() == ID_get_may)
return true;

forall_operands(it, src)
if(has_get_must_or_may(*it))
for(const auto &op : src.operands())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW this is just std::any(src.operands.begin(), src.operands.end(), has_get_must_or_may)

{
if(has_get_must_or_may(op))
return true;
}

return false;
}
Expand Down
8 changes: 4 additions & 4 deletions src/analyses/dirty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ void dirtyt::search_other(const goto_programt::instructiont &instruction)
statement == ID_array_replace || statement == ID_havoc_object ||
statement == ID_input || statement == ID_output)
{
forall_operands(it, code)
find_dirty(*it);
for(const auto &op : code.operands())
find_dirty(op);
}
// other possible cases according to goto_programt::instructiont::output
// and goto_symext::symex_other:
Expand All @@ -66,8 +66,8 @@ void dirtyt::find_dirty(const exprt &expr)
return;
}

forall_operands(it, expr)
find_dirty(*it);
for(const auto &op : expr.operands())
find_dirty(op);
}

void dirtyt::find_dirty_address_of(const exprt &expr)
Expand Down
28 changes: 14 additions & 14 deletions src/analyses/goto_rw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ void rw_range_sett::get_objects_array(

if(!subtype_bits.has_value())
{
forall_operands(it, expr)
get_objects_rec(mode, *it, range_spect{0}, range_spect::unknown());
for(const auto &op : expr.operands())
get_objects_rec(mode, op, range_spect{0}, range_spect::unknown());

return;
}
Expand All @@ -346,7 +346,7 @@ void rw_range_sett::get_objects_array(
? sub_size * range_spect::to_range_spect(expr.operands().size())
: full_r_s + size;

forall_operands(it, expr)
for(const auto &op : expr.operands())
{
if(full_r_s<=offset+sub_size && full_r_e>offset)
{
Expand All @@ -355,7 +355,7 @@ void rw_range_sett::get_objects_array(
range_spect cur_r_e=
full_r_e>offset+sub_size ? sub_size : full_r_e-offset;

get_objects_rec(mode, *it, cur_r_s, cur_r_e-cur_r_s);
get_objects_rec(mode, op, cur_r_s, cur_r_e - cur_r_s);
}

offset+=sub_size;
Expand Down Expand Up @@ -384,17 +384,17 @@ void rw_range_sett::get_objects_struct(
? range_spect::unknown()
: full_r_s + size;

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

range_spect sub_size = it_bits.has_value()
? range_spect::to_range_spect(*it_bits)
: range_spect::unknown();

if(offset.is_unknown())
{
get_objects_rec(mode, *it, range_spect{0}, sub_size);
get_objects_rec(mode, op, range_spect{0}, sub_size);
}
else if(sub_size.is_unknown())
{
Expand All @@ -403,7 +403,7 @@ void rw_range_sett::get_objects_struct(
range_spect cur_r_s =
full_r_s <= offset ? range_spect{0} : full_r_s - offset;

get_objects_rec(mode, *it, cur_r_s, range_spect::unknown());
get_objects_rec(mode, op, cur_r_s, range_spect::unknown());
}

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

get_objects_rec(mode, *it, cur_r_s, sub_size-cur_r_s);
get_objects_rec(mode, op, cur_r_s, sub_size - cur_r_s);
}

offset+=sub_size;
Expand All @@ -427,7 +427,7 @@ void rw_range_sett::get_objects_struct(
range_spect cur_r_e=
full_r_e>offset+sub_size ? sub_size : full_r_e-offset;

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

offset+=sub_size;
}
Expand Down Expand Up @@ -619,8 +619,8 @@ void rw_range_sett::get_objects_rec(
// possibly affects the full object size, even if range_start/size
// are only a subset of the bytes (e.g., when using the result of
// arithmetic operations)
forall_operands(it, expr)
get_objects_rec(mode, *it);
for(const auto &op : expr.operands())
get_objects_rec(mode, op);
}
else if(expr.id() == ID_null_object ||
expr.id() == ID_string_constant)
Expand All @@ -629,8 +629,8 @@ void rw_range_sett::get_objects_rec(
}
else if(mode==get_modet::LHS_W)
{
forall_operands(it, expr)
get_objects_rec(mode, *it);
for(const auto &op : expr.operands())
get_objects_rec(mode, op);
}
else
throw "rw_range_sett: assignment to '" + expr.id_string() + "' not handled";
Expand Down
12 changes: 8 additions & 4 deletions src/analyses/interval_domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,18 @@ void interval_domaint::assume_rec(
else if(cond.id()==ID_and)
{
if(!negation)
forall_operands(it, cond)
assume_rec(*it, false);
{
for(const auto &op : cond.operands())
assume_rec(op, false);
}
}
else if(cond.id()==ID_or)
{
if(negation)
forall_operands(it, cond)
assume_rec(*it, true);
{
for(const auto &op : cond.operands())
assume_rec(op, true);
}
}
}

Expand Down
28 changes: 16 additions & 12 deletions src/analyses/invariant_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ void invariant_sett::strengthen_rec(const exprt &expr)
}
else if(expr.id()==ID_and)
{
forall_operands(it, expr)
strengthen_rec(*it);
for(const auto &op : expr.operands())
strengthen_rec(op);
}
else if(expr.id()==ID_le ||
expr.id()==ID_lt)
Expand All @@ -424,10 +424,10 @@ void invariant_sett::strengthen_rec(const exprt &expr)
{
const exprt &bitand_op = rel.op1();

forall_operands(it, bitand_op)
for(const auto &op : bitand_op.operands())
{
auto tmp(rel);
tmp.op1()=*it;
tmp.op1() = op;
strengthen_rec(tmp);
}

Expand Down Expand Up @@ -499,10 +499,10 @@ void invariant_sett::strengthen_rec(const exprt &expr)
{
const exprt &bitand_op = equal_expr.op1();

forall_operands(it, bitand_op)
for(const auto &op : bitand_op.operands())
{
auto tmp(equal_expr);
tmp.op1()=*it;
tmp.op1() = op;
tmp.id(ID_le);
strengthen_rec(tmp);
}
Expand Down Expand Up @@ -602,17 +602,21 @@ tvt invariant_sett::implies_rec(const exprt &expr) const
}
else if(expr.id()==ID_and)
{
forall_operands(it, expr)
if(implies_rec(*it)!=tvt(true))
for(const auto &op : expr.operands())
{
if(implies_rec(op) != tvt(true))
return tvt::unknown();
}

return tvt(true);
}
else if(expr.id()==ID_or)
{
forall_operands(it, expr)
if(implies_rec(*it)==tvt(true))
for(const auto &op : expr.operands())
{
if(implies_rec(op) == tvt(true))
return tvt(true);
}
}
else if(expr.id()==ID_le ||
expr.id()==ID_lt ||
Expand Down Expand Up @@ -1049,8 +1053,8 @@ void invariant_sett::apply_code(const codet &code)

if(statement==ID_block)
{
forall_operands(it, code)
apply_code(to_code(*it));
for(const auto &op : code.operands())
apply_code(to_code(op));
}
else if(statement==ID_assign)
{
Expand Down
6 changes: 3 additions & 3 deletions src/ansi-c/ansi_c_convert_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,17 @@ void ansi_c_convert_typet::read_rec(const typet &type)
const exprt &as_expr=
static_cast<const exprt &>(static_cast<const irept &>(type));

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

if(id==ID_thread)
c_storage_spec.is_thread_local=true;
else if(id=="align")
{
aligned=true;
alignment = to_unary_expr(*it).op();
alignment = to_unary_expr(op).op();
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/ansi-c/c_storage_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ void c_storage_spect::read(const typet &type)
{
const exprt &as_expr=
static_cast<const exprt &>(static_cast<const irept &>(type));
forall_operands(it, as_expr)
if(it->id()==ID_thread)
for(const auto &op : as_expr.operands())
{
if(op.id() == ID_thread)
is_thread_local=true;
}
}
else if(
type.id() == ID_alias && type.has_subtype() &&
Expand Down
12 changes: 6 additions & 6 deletions src/ansi-c/c_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,15 +587,15 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
typet &type=static_cast<typet &>(expr.add(ID_type_arg));
typecheck_type(type);

exprt &member=static_cast<exprt &>(expr.add(ID_designator));
const exprt &member = static_cast<const exprt &>(expr.add(ID_designator));

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

forall_operands(m_it, member)
for(const auto &op : member.operands())
{
type = follow(type);

if(m_it->id()==ID_member)
if(op.id() == ID_member)
{
if(type.id()!=ID_union && type.id()!=ID_struct)
{
Expand All @@ -606,7 +606,7 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
}

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

while(!found)
{
Expand Down Expand Up @@ -692,7 +692,7 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
}
}
}
else if(m_it->id()==ID_index)
else if(op.id() == ID_index)
{
if(type.id()!=ID_array)
{
Expand All @@ -701,7 +701,7 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
throw 0;
}

exprt index = to_unary_expr(*m_it).op();
exprt index = to_unary_expr(op).op();

// still need to typecheck index
typecheck_expr(index);
Expand Down
3 changes: 1 addition & 2 deletions src/ansi-c/c_typecheck_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,9 +775,8 @@ designatort c_typecheck_baset::make_designator(
typet type=src_type;
designatort designator;

forall_operands(it, src)
for(const auto &d_op : src.operands())
{
const exprt &d_op=*it;
designatort::entryt entry(type);
const typet &full_type=follow(entry.type);

Expand Down
Loading