Skip to content

Commit 476fb51

Browse files
author
Daniel Kroening
authored
Merge pull request #333 from tautschnig/ranged-for
RFC: Ranged for
2 parents f142077 + e85e808 commit 476fb51

File tree

139 files changed

+1407
-2105
lines changed

Some content is hidden

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

139 files changed

+1407
-2105
lines changed

regression/ansi-c/struct7/main.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct S
2+
{
3+
int x;
4+
int x;
5+
};
6+
7+
int main()
8+
{
9+
struct S s;
10+
return s.x;
11+
}

regression/ansi-c/struct7/test.desc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=\(64\|1\)$
5+
^SIGNAL=0$
6+
^file main.c line 4: duplicate member x$
7+
^CONVERSION ERROR$
8+
--

src/aa-path-symex/path_symex_history.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ void path_symex_stept::output(std::ostream &out) const
2929
out << "PCs:";
3030

3131
/*
32-
for(pc_vectort::const_iterator p_it=s_it->pc_vector.begin();
33-
p_it!=pc_vector.end();
34-
p_it++)
35-
out << " " << *p_it;
32+
for(const auto &pc : s_it->pc_vector)
33+
out << " " << pc;
3634
*/
3735
out << "\n";
3836

src/aa-path-symex/path_symex_state.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,8 @@ void path_symex_statet::output(const threadt &thread, std::ostream &out) const
8585
{
8686
out << " PC: " << thread.pc << std::endl;
8787
out << " Call stack:";
88-
for(call_stackt::const_iterator
89-
it=thread.call_stack.begin();
90-
it!=thread.call_stack.end();
91-
it++)
92-
out << " " << it->return_location << std::endl;
88+
for(const auto &call : thread.call_stack)
89+
out << " " << call.return_location << std::endl;
9390
out << std::endl;
9491
}
9592

src/aa-symex/path_search.cpp

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,11 @@ void path_searcht::do_show_vcc(
346346
std::vector<path_symex_step_reft> steps;
347347
state.history.build_history(steps);
348348

349-
for(std::vector<path_symex_step_reft>::const_iterator
350-
s_it=steps.begin();
351-
s_it!=steps.end();
352-
s_it++)
349+
for(const auto &step_ref : steps)
353350
{
354-
if((*s_it)->guard.is_not_nil())
351+
if(step_ref->guard.is_not_nil())
355352
{
356-
std::string string_value=from_expr(ns, "", (*s_it)->guard);
353+
std::string string_value=from_expr(ns, "", step_ref->guard);
357354
out << "{-" << count << "} " << string_value << "\n";
358355
count++;
359356
}
@@ -403,22 +400,16 @@ bool path_searcht::drop_state(const statet &state) const
403400
// unwinding limit -- loops
404401
if(unwind_limit!=-1 && state.get_instruction()->is_backwards_goto())
405402
{
406-
for(path_symex_statet::unwinding_mapt::const_iterator
407-
it=state.unwinding_map.begin();
408-
it!=state.unwinding_map.end();
409-
it++)
410-
if(it->second>unwind_limit)
403+
for(const auto &loop_info : state.unwinding_map)
404+
if(loop_info.second>unwind_limit)
411405
return true;
412406
}
413407

414408
// unwinding limit -- recursion
415409
if(unwind_limit!=-1 && state.get_instruction()->is_function_call())
416410
{
417-
for(path_symex_statet::recursion_mapt::const_iterator
418-
it=state.recursion_map.begin();
419-
it!=state.recursion_map.end();
420-
it++)
421-
if(it->second>unwind_limit)
411+
for(const auto &rec_info : state.recursion_map)
412+
if(rec_info.second>unwind_limit)
422413
return true;
423414
}
424415

@@ -500,23 +491,17 @@ Function: path_searcht::initialize_property_map
500491
void path_searcht::initialize_property_map(
501492
const goto_functionst &goto_functions)
502493
{
503-
for(goto_functionst::function_mapt::const_iterator
504-
it=goto_functions.function_map.begin();
505-
it!=goto_functions.function_map.end();
506-
it++)
494+
forall_goto_functions(it, goto_functions)
507495
if(!it->second.is_inlined())
508496
{
509497
const goto_programt &goto_program=it->second.body;
510498

511-
for(goto_programt::instructionst::const_iterator
512-
it=goto_program.instructions.begin();
513-
it!=goto_program.instructions.end();
514-
it++)
499+
forall_goto_program_instructions(i_it, goto_program)
515500
{
516-
if(!it->is_assert())
501+
if(!i_it->is_assert())
517502
continue;
518503

519-
const locationt &location=it->location;
504+
const locationt &location=i_it->location;
520505

521506
irep_idt property_name=location.get_property_id();
522507

src/aa-symex/symex_parseoptions.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -541,15 +541,12 @@ Function: symex_parseoptionst::report_properties
541541
void symex_parseoptionst::report_properties(
542542
const path_searcht::property_mapt &property_map)
543543
{
544-
for(path_searcht::property_mapt::const_iterator
545-
it=property_map.begin();
546-
it!=property_map.end();
547-
it++)
544+
for(const auto &prop_pair : property_map)
548545
{
549546
if(get_ui()==ui_message_handlert::XML_UI)
550547
{
551548
xmlt xml_result("result");
552-
xml_result.set_attribute("claim", id2string(it->first));
549+
xml_result.set_attribute("claim", id2string(prop_pair.first));
553550

554551
std::string status_string;
555552

@@ -566,9 +563,9 @@ void symex_parseoptionst::report_properties(
566563
}
567564
else
568565
{
569-
status() << "[" << it->first << "] "
570-
<< it->second.description << ": ";
571-
switch(it->second.status)
566+
status() << "[" << prop_pair.first << "] "
567+
<< prop_pair.second.description << ": ";
568+
switch(prop_pair.second.status)
572569
{
573570
case path_searcht::PASS: status() << "OK"; break;
574571
case path_searcht::FAIL: status() << "FAILED"; break;
@@ -578,8 +575,8 @@ void symex_parseoptionst::report_properties(
578575
}
579576

580577
if(cmdline.isset("show-trace") &&
581-
it->second.status==path_searcht::FAIL)
582-
show_counterexample(it->second.error_trace);
578+
prop_pair.second.status==path_searcht::FAIL)
579+
show_counterexample(prop_pair.second.error_trace);
583580
}
584581

585582
if(!cmdline.isset("property"))
@@ -588,11 +585,8 @@ void symex_parseoptionst::report_properties(
588585

589586
unsigned failed=0;
590587

591-
for(path_searcht::property_mapt::const_iterator
592-
it=property_map.begin();
593-
it!=property_map.end();
594-
it++)
595-
if(it->second.status==path_searcht::FAIL)
588+
for(const auto &prop_pair : property_map)
589+
if(prop_pair.second.status==path_searcht::FAIL)
596590
failed++;
597591

598592
status() << "** " << failed

src/analyses/ai.cpp

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ void ai_baset::output(
3434
const goto_functionst &goto_functions,
3535
std::ostream &out) const
3636
{
37-
for(goto_functionst::function_mapt::const_iterator
38-
f_it=goto_functions.function_map.begin();
39-
f_it!=goto_functions.function_map.end();
40-
f_it++)
37+
forall_goto_functions(f_it, goto_functions)
4138
{
4239
if(f_it->second.body_available())
4340
{
@@ -175,10 +172,7 @@ Function: ai_baset::initialize
175172

176173
void ai_baset::initialize(const goto_functionst &goto_functions)
177174
{
178-
for(goto_functionst::function_mapt::const_iterator
179-
it=goto_functions.function_map.begin();
180-
it!=goto_functions.function_map.end();
181-
it++)
175+
forall_goto_functions(it, goto_functions)
182176
initialize(it->second);
183177
}
184178

@@ -271,13 +265,8 @@ bool ai_baset::visit(
271265

272266
goto_program.get_successors(l, successors);
273267

274-
for(goto_programt::const_targetst::const_iterator
275-
it=successors.begin();
276-
it!=successors.end();
277-
it++)
268+
for(const auto &to_l : successors)
278269
{
279-
locationt to_l=*it;
280-
281270
if(to_l==goto_program.instructions.end())
282271
continue;
283272

@@ -512,10 +501,7 @@ void ai_baset::sequential_fixedpoint(
512501
{
513502
// do each function at least once
514503

515-
for(goto_functionst::function_mapt::const_iterator
516-
it=goto_functions.function_map.begin();
517-
it!=goto_functions.function_map.end();
518-
it++)
504+
forall_goto_functions(it, goto_functions)
519505
fixedpoint(it->second.body, goto_functions, ns);
520506
}
521507

@@ -572,21 +558,19 @@ void ai_baset::concurrent_fixedpoint(
572558
{
573559
new_shared=false;
574560

575-
for(thread_wlt::const_iterator it=thread_wl.begin();
576-
it!=thread_wl.end();
577-
++it)
561+
for(const auto &wl_pair : thread_wl)
578562
{
579563
working_sett working_set;
580-
put_in_working_set(working_set, it->second);
564+
put_in_working_set(working_set, wl_pair.second);
581565

582-
statet &begin_state=get_state(it->second);
583-
merge(begin_state, sh_target, it->second);
566+
statet &begin_state=get_state(wl_pair.second);
567+
merge(begin_state, sh_target, wl_pair.second);
584568

585569
while(!working_set.empty())
586570
{
587571
goto_programt::const_targett l=get_next(working_set);
588572

589-
visit(l, working_set, *(it->first), goto_functions, ns);
573+
visit(l, working_set, *(wl_pair.first), goto_functions, ns);
590574

591575
// the underlying domain must make sure that the final state
592576
// carries all possible values; otherwise we would need to

src/analyses/call_graph.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,10 @@ void call_grapht::output_dot(std::ostream &out) const
110110
{
111111
out << "digraph call_graph {\n";
112112

113-
for(grapht::const_iterator it=graph.begin();
114-
it!=graph.end();
115-
it++)
113+
for(const auto &edge : graph)
116114
{
117-
out << " \"" << it->first << "\" -> "
118-
<< "\"" << it->second << "\" "
115+
out << " \"" << edge.first << "\" -> "
116+
<< "\"" << edge.second << "\" "
119117
<< " [arrowhead=\"vee\"];"
120118
<< "\n";
121119
}
@@ -137,12 +135,9 @@ Function: call_grapht::output
137135

138136
void call_grapht::output(std::ostream &out) const
139137
{
140-
for(grapht::const_iterator
141-
it=graph.begin();
142-
it!=graph.end();
143-
it++)
138+
for(const auto &edge : graph)
144139
{
145-
out << it->first << " -> " << it->second << "\n";
140+
out << edge.first << " -> " << edge.second << "\n";
146141
}
147142
}
148143

@@ -160,15 +155,12 @@ Function: call_grapht::output_xml
160155

161156
void call_grapht::output_xml(std::ostream &out) const
162157
{
163-
for(grapht::const_iterator
164-
it=graph.begin();
165-
it!=graph.end();
166-
it++)
158+
for(const auto &edge : graph)
167159
{
168160
out << "<call_graph_edge caller=\"";
169-
xmlt::escape_attribute(id2string(it->first), out);
161+
xmlt::escape_attribute(id2string(edge.first), out);
170162
out << "\" callee=\"";
171-
xmlt::escape_attribute(id2string(it->second), out);
163+
xmlt::escape_attribute(id2string(edge.second), out);
172164
out << "\">\n";
173165
}
174166
}

src/analyses/cfg_dominators.h

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,8 @@ void cfg_dominators_templatet<P, T, post_dom>::initialise(P &program)
103103
cfg(program);
104104

105105
// initialise top element
106-
for(typename cfgt::entry_mapt::const_iterator
107-
e_it=cfg.entry_map.begin();
108-
e_it!=cfg.entry_map.end(); ++e_it)
109-
top.insert(cfg[e_it->second].PC);
106+
for(const auto &node : cfg.entry_map)
107+
top.insert(cfg[node.second].PC);
110108
}
111109

112110
/*******************************************************************\
@@ -151,24 +149,18 @@ void cfg_dominators_templatet<P, T, post_dom>::fixedpoint(P &program)
151149
bool changed=false;
152150
typename cfgt::nodet &node=cfg[cfg.entry_map[current]];
153151
if(node.dominators.empty())
154-
for(typename cfgt::edgest::const_iterator
155-
p_it=(post_dom?node.out:node.in).begin();
156-
!changed && p_it!=(post_dom?node.out:node.in).end();
157-
++p_it)
158-
if(!cfg[p_it->first].dominators.empty())
152+
for(const auto & edge : (post_dom?node.out:node.in))
153+
if(!cfg[edge.first].dominators.empty())
159154
{
160-
node.dominators=cfg[p_it->first].dominators;
155+
node.dominators=cfg[edge.first].dominators;
161156
node.dominators.insert(current);
162157
changed=true;
163158
}
164159

165160
// compute intersection of predecessors
166-
for(typename cfgt::edgest::const_iterator
167-
p_it=(post_dom?node.out:node.in).begin();
168-
p_it!=(post_dom?node.out:node.in).end();
169-
++p_it)
161+
for(const auto & edge : (post_dom?node.out:node.in))
170162
{
171-
const target_sett &other=cfg[p_it->first].dominators;
163+
const target_sett &other=cfg[edge.first].dominators;
172164
if(other.empty())
173165
continue;
174166

@@ -198,12 +190,9 @@ void cfg_dominators_templatet<P, T, post_dom>::fixedpoint(P &program)
198190

199191
if(changed) // fixed point for node reached?
200192
{
201-
for(typename cfgt::edgest::const_iterator
202-
s_it=(post_dom?node.in:node.out).begin();
203-
s_it!=(post_dom?node.in:node.out).end();
204-
++s_it)
193+
for(const auto & edge : (post_dom?node.in:node.out))
205194
{
206-
worklist.push_back(cfg[s_it->first].PC);
195+
worklist.push_back(cfg[edge.first].PC);
207196
}
208197
}
209198
}
@@ -224,21 +213,21 @@ Function: cfg_dominators_templatet::output
224213
template <class P, class T, bool post_dom>
225214
void cfg_dominators_templatet<P, T, post_dom>::output(std::ostream &out) const
226215
{
227-
for(typename cfgt::entry_mapt::const_iterator
228-
it=cfg.entry_map.begin();
229-
it!=cfg.entry_map.end(); ++it)
216+
for(const auto &node : cfg.entry_map)
230217
{
231-
unsigned n=it->first->location_number;
218+
unsigned n=node.first->location_number;
232219

233220
if(post_dom)
234221
out << n << " post-dominated by ";
235222
else
236223
out << n << " dominated by ";
237-
for(typename target_sett::const_iterator d_it=it->second.dominators.begin();
238-
d_it!=it->second.dominators.end();)
224+
for(typename target_sett::const_iterator
225+
d_it=node.second.dominators.begin();
226+
d_it!=node.second.dominators.end();
227+
) // no d_it++
239228
{
240229
out << (*d_it)->location_number;
241-
if (++d_it!=it->second.dominators.end())
230+
if (++d_it!=node.second.dominators.end())
242231
out << ", ";
243232
}
244233
out << "\n";

0 commit comments

Comments
 (0)