Skip to content

Commit 1afce22

Browse files
author
Daniel Kroening
committed
modernize loops in slice_by_trace
Includes use of ranged for and use of existing library functions.
1 parent 0f7a99d commit 1afce22

File tree

1 file changed

+43
-64
lines changed

1 file changed

+43
-64
lines changed

src/goto-symex/slice_by_trace.cpp

Lines changed: 43 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -55,31 +55,15 @@ void symex_slice_by_tracet::slice_by_trace(
5555
idx=next;
5656
}
5757

58-
exprt trace_condition;
59-
60-
if(trace_conditions.size()==1)
61-
{
62-
trace_condition=trace_conditions[0];
63-
}
64-
else
65-
{
66-
trace_condition=exprt(ID_and, typet(ID_bool));
67-
trace_condition.operands().reserve(trace_conditions.size());
68-
for(std::vector<exprt>::iterator i=trace_conditions.begin();
69-
i!=trace_conditions.end(); i++)
70-
{
71-
trace_condition.move_to_operands(*i);
72-
}
73-
}
58+
exprt trace_condition = conjunction(trace_conditions);
7459

7560
simplify(trace_condition, ns);
7661

7762
std::set<exprt> implications=implied_guards(trace_condition);
7863

79-
for(std::set<exprt>::iterator i=sliced_guards.begin(); i !=
80-
sliced_guards.end(); i++)
64+
for(const auto &guard : sliced_guards)
8165
{
82-
exprt g_copy(*i);
66+
exprt g_copy(guard);
8367

8468
DATA_INVARIANT(
8569
g_copy.id() == ID_symbol || g_copy.id() == ID_not ||
@@ -300,27 +284,29 @@ void symex_slice_by_tracet::compute_ts_back(
300284
{
301285
std::list<exprt> eq_conds;
302286
std::list<exprt>::iterator pvi=i->io_args.begin();
303-
for(std::vector<irep_idt>::iterator k=sigma_vals[j].begin();
304-
k!=sigma_vals[j].end(); k++)
287+
288+
for(const auto &sigma_val : sigma_vals[j])
305289
{
306290
exprt equal_cond=exprt(ID_equal, bool_typet());
307291
equal_cond.operands().reserve(2);
308292
equal_cond.copy_to_operands(*pvi);
309293
// Should eventually change to handle non-bv types!
310-
exprt constant_value=
311-
from_integer(unsafe_string2int(id2string(*k)), (*pvi).type());
294+
exprt constant_value = from_integer(
295+
unsafe_string2int(id2string(sigma_val)), (*pvi).type());
312296
equal_cond.move_to_operands(constant_value);
313297
eq_conds.push_back(equal_cond);
314298
pvi++;
315299
}
300+
316301
exprt val_merge=exprt(ID_and, typet(ID_bool));
317302
val_merge.operands().reserve(eq_conds.size()+1);
318303
val_merge.copy_to_operands(merge[j+1]);
319-
for(std::list<exprt>::iterator k=eq_conds.begin();
320-
k!= eq_conds.end(); k++)
304+
305+
for(const auto &eq_cond : eq_conds)
321306
{
322-
val_merge.copy_to_operands(*k);
307+
val_merge.copy_to_operands(eq_cond);
323308
}
309+
324310
u_lhs.move_to_operands(val_merge);
325311
}
326312
else
@@ -384,23 +370,20 @@ void symex_slice_by_tracet::slice_SSA_steps(
384370
size_t location_SSA_steps=0;
385371
size_t trace_loc_sliced=0;
386372

387-
for(symex_target_equationt::SSA_stepst::iterator
388-
it=equation.SSA_steps.begin();
389-
it!=equation.SSA_steps.end();
390-
it++)
373+
for(auto &SSA_step : equation.SSA_steps)
391374
{
392-
if(it->is_output())
375+
if(SSA_step.is_output())
393376
trace_SSA_steps++;
394-
if(it->is_location())
377+
if(SSA_step.is_location())
395378
location_SSA_steps++;
396379
bool sliced_SSA_step=false;
397-
exprt guard=it->guard;
380+
exprt guard = SSA_step.guard;
398381

399382
simplify(guard, ns);
400383

401384
if(!guard.is_true())
402385
potential_SSA_steps++;
403-
// it->output(ns,std::cout);
386+
// SSA_step.output(ns,std::cout);
404387
// std::cout << "-----------------\n";
405388

406389
if((guard.id()==ID_symbol) || (guard.id() == ID_not))
@@ -409,11 +392,11 @@ void symex_slice_by_tracet::slice_SSA_steps(
409392

410393
if(implications.count(guard)!=0)
411394
{
412-
it->cond_expr=true_exprt();
413-
it->ssa_rhs=true_exprt();
414-
it->guard=false_exprt();
395+
SSA_step.cond_expr = true_exprt();
396+
SSA_step.ssa_rhs = true_exprt();
397+
SSA_step.guard = false_exprt();
415398
sliced_SSA_steps++;
416-
if(it->is_output() || it->is_location())
399+
if(SSA_step.is_output() || SSA_step.is_location())
417400
trace_loc_sliced++;
418401
sliced_SSA_step=true;
419402
}
@@ -427,11 +410,11 @@ void symex_slice_by_tracet::slice_SSA_steps(
427410

428411
if(implications.count(neg_expr)!=0)
429412
{
430-
it->cond_expr=true_exprt();
431-
it->ssa_rhs=true_exprt();
432-
it->guard=false_exprt();
413+
SSA_step.cond_expr = true_exprt();
414+
SSA_step.ssa_rhs = true_exprt();
415+
SSA_step.guard = false_exprt();
433416
sliced_SSA_steps++;
434-
if(it->is_output() || it->is_location())
417+
if(SSA_step.is_output() || SSA_step.is_location())
435418
trace_loc_sliced++;
436419
sliced_SSA_step=true;
437420
break; // Sliced, so no need to consider the rest
@@ -443,32 +426,32 @@ void symex_slice_by_tracet::slice_SSA_steps(
443426
}
444427
}
445428

446-
if(!sliced_SSA_step && it->is_assignment())
429+
if(!sliced_SSA_step && SSA_step.is_assignment())
447430
{
448-
if(it->ssa_rhs.id()==ID_if)
431+
if(SSA_step.ssa_rhs.id() == ID_if)
449432
{
450433
conds_seen++;
451-
exprt cond_copy(to_if_expr(it->ssa_rhs).cond());
434+
exprt cond_copy(to_if_expr(SSA_step.ssa_rhs).cond());
452435
simplify(cond_copy, ns);
453436

454437
if(implications.count(cond_copy)!=0)
455438
{
456439
sliced_conds++;
457-
exprt t_copy1(to_if_expr(it->ssa_rhs).true_case());
458-
exprt t_copy2(to_if_expr(it->ssa_rhs).true_case());
459-
it->ssa_rhs=t_copy1;
460-
it->cond_expr.op1().swap(t_copy2);
440+
exprt t_copy1(to_if_expr(SSA_step.ssa_rhs).true_case());
441+
exprt t_copy2(to_if_expr(SSA_step.ssa_rhs).true_case());
442+
SSA_step.ssa_rhs = t_copy1;
443+
SSA_step.cond_expr.op1().swap(t_copy2);
461444
}
462445
else
463446
{
464447
cond_copy = simplify_expr(boolean_negate(cond_copy), ns);
465448
if(implications.count(cond_copy)!=0)
466449
{
467450
sliced_conds++;
468-
exprt f_copy1(to_if_expr(it->ssa_rhs).false_case());
469-
exprt f_copy2(to_if_expr(it->ssa_rhs).false_case());
470-
it->ssa_rhs=f_copy1;
471-
it->cond_expr.op1().swap(f_copy2);
451+
exprt f_copy1(to_if_expr(SSA_step.ssa_rhs).false_case());
452+
exprt f_copy2(to_if_expr(SSA_step.ssa_rhs).false_case());
453+
SSA_step.ssa_rhs = f_copy1;
454+
SSA_step.cond_expr.op1().swap(f_copy2);
472455
}
473456
}
474457
}
@@ -565,15 +548,13 @@ std::set<exprt> symex_slice_by_tracet::implied_guards(exprt e)
565548
}
566549
else if(e.id()==ID_and)
567550
{ // Descend into and
568-
Forall_operands(it, e)
551+
for(const auto &conjunct : e.operands())
569552
{
570-
std::set<exprt> r=implied_guards(*it);
571-
for(std::set<exprt>::iterator i=r.begin();
572-
i!=r.end(); i++)
573-
{
574-
s.insert(*i);
575-
}
553+
const auto imps = implied_guards(conjunct);
554+
for(const auto &guard : imps)
555+
s.insert(guard);
576556
}
557+
577558
return s;
578559
}
579560
else if(e.id()==ID_or)
@@ -611,11 +592,9 @@ bool symex_slice_by_tracet::implies_false(const exprt e)
611592
{
612593
std::set<exprt> imps=implied_guards(e);
613594

614-
for(std::set<exprt>::iterator
615-
i=imps.begin();
616-
i!=imps.end(); i++)
595+
for(const auto &implied_guard : imps)
617596
{
618-
exprt i_copy = boolean_negate(*i);
597+
exprt i_copy = boolean_negate(implied_guard);
619598
simplify(i_copy, ns);
620599
if(imps.count(i_copy)!=0)
621600
return true;

0 commit comments

Comments
 (0)