Skip to content

Commit c5aa37a

Browse files
author
Daniel Kroening
committed
use ranged for over components
1 parent 02ebaee commit c5aa37a

21 files changed

+120
-251
lines changed

src/ansi-c/c_typecheck_type.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -913,15 +913,12 @@ void c_typecheck_baset::typecheck_compound_body(
913913
{
914914
std::unordered_set<irep_idt> members;
915915

916-
for(struct_union_typet::componentst::iterator
917-
it=components.begin();
918-
it!=components.end();
919-
it++)
916+
for(const auto &c : components)
920917
{
921-
if(!members.insert(it->get_name()).second)
918+
if(!members.insert(c.get_name()).second)
922919
{
923-
error().source_location=it->source_location();
924-
error() << "duplicate member '" << it->get_name() << '\'' << eom;
920+
error().source_location = c.source_location();
921+
error() << "duplicate member '" << c.get_name() << '\'' << eom;
925922
throw 0;
926923
}
927924
}

src/ansi-c/expr2c.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,10 @@ std::string expr2ct::convert_rec(
353353
dest+=" "+id2string(tag);
354354
dest+=" {";
355355

356-
for(union_typet::componentst::const_iterator
357-
it=union_type.components().begin();
358-
it!=union_type.components().end();
359-
it++)
356+
for(const auto &c : union_type.components())
360357
{
361358
dest+=' ';
362-
dest+=convert_rec(it->type(), c_qualifierst(), id2string(it->get_name()));
359+
dest += convert_rec(c.type(), c_qualifierst(), id2string(c.get_name()));
363360
dest+=';';
364361
}
365362

@@ -724,8 +721,7 @@ std::string expr2ct::convert_struct_type(
724721
{
725722
dest+=" {";
726723

727-
for(const struct_union_typet::componentt &component :
728-
struct_type.components())
724+
for(const auto &component : struct_type.components())
729725
{
730726
// Skip padding parameters unless we including them
731727
if(component.get_is_padding() && !inc_padding_components)
@@ -2071,8 +2067,7 @@ std::string expr2ct::convert_struct(
20712067
bool newline=false;
20722068
size_t last_size=0;
20732069

2074-
for(const struct_union_typet::componentt &component :
2075-
struct_type.components())
2070+
for(const auto &component : struct_type.components())
20762071
{
20772072
if(o_it->type().id()==ID_code)
20782073
continue;

src/cpp/cpp_constructor.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,18 +213,15 @@ optionalt<codet> cpp_typecheckt::cpp_constructor(
213213

214214
irep_idt constructor_name;
215215

216-
for(struct_typet::componentst::const_iterator
217-
it=components.begin();
218-
it!=components.end();
219-
it++)
216+
for(const auto &c : components)
220217
{
221-
const typet &type=it->type();
218+
const typet &type = c.type();
222219

223-
if(!it->get_bool(ID_from_base) &&
224-
type.id()==ID_code &&
225-
type.find(ID_return_type).id()==ID_constructor)
220+
if(
221+
!c.get_bool(ID_from_base) && type.id() == ID_code &&
222+
type.find(ID_return_type).id() == ID_constructor)
226223
{
227-
constructor_name=it->get(ID_base_name);
224+
constructor_name = c.get(ID_base_name);
228225
break;
229226
}
230227
}

src/cpp/cpp_destructor.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,15 @@ optionalt<codet> cpp_typecheckt::cpp_destructor(
8686

8787
irep_idt dtor_name;
8888

89-
for(struct_typet::componentst::const_iterator
90-
it=components.begin();
91-
it!=components.end();
92-
it++)
89+
for(const auto &c : components)
9390
{
94-
const typet &type=it->type();
91+
const typet &type = c.type();
9592

96-
if(!it->get_bool(ID_from_base) &&
97-
type.id()==ID_code &&
98-
type.find(ID_return_type).id()==ID_destructor)
93+
if(
94+
!c.get_bool(ID_from_base) && type.id() == ID_code &&
95+
type.find(ID_return_type).id() == ID_destructor)
9996
{
100-
dtor_name=it->get(ID_base_name);
97+
dtor_name = c.get(ID_base_name);
10198
break;
10299
}
103100
}

src/cpp/cpp_is_pod.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,22 @@ bool cpp_typecheckt::cpp_is_pod(const typet &type) const
3131
const struct_typet::componentst &components=
3232
struct_type.components();
3333

34-
for(struct_typet::componentst::const_iterator
35-
it=components.begin();
36-
it!=components.end();
37-
it++)
34+
for(const auto &c : components)
3835
{
39-
if(it->get_bool(ID_is_type))
36+
if(c.get_bool(ID_is_type))
4037
continue;
4138

42-
if(it->get_base_name()=="operator=")
39+
if(c.get_base_name() == "operator=")
4340
return false;
4441

45-
if(it->get_bool(ID_is_virtual))
42+
if(c.get_bool(ID_is_virtual))
4643
return false;
4744

48-
const typet &sub_type=it->type();
45+
const typet &sub_type = c.type();
4946

5047
if(sub_type.id()==ID_code)
5148
{
52-
if(it->get_bool(ID_is_virtual))
49+
if(c.get_bool(ID_is_virtual))
5350
return false;
5451

5552
const typet &return_type=to_code_type(sub_type).return_type();
@@ -58,8 +55,7 @@ bool cpp_typecheckt::cpp_is_pod(const typet &type) const
5855
return_type.id()==ID_destructor)
5956
return false;
6057
}
61-
else if(it->get(ID_access)!=ID_public &&
62-
!it->get_bool(ID_is_static))
58+
else if(c.get(ID_access) != ID_public && !c.get_bool(ID_is_static))
6359
return false;
6460

6561
if(!cpp_is_pod(sub_type))

src/cpp/cpp_typecheck_bases.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,15 @@ void cpp_typecheckt::add_base_components(
169169
}
170170

171171
// add the components
172-
const struct_typet::componentst &src_c=from.components();
173172
struct_typet::componentst &dest_c=to.components();
174173

175-
for(struct_typet::componentst::const_iterator
176-
it=src_c.begin();
177-
it!=src_c.end();
178-
it++)
174+
for(const auto &c : from.components())
179175
{
180-
if(it->get_bool(ID_from_base))
176+
if(c.get_bool(ID_from_base))
181177
continue;
182178

183179
// copy the component
184-
dest_c.push_back(*it);
180+
dest_c.push_back(c);
185181

186182
// now twiddle the copy
187183
struct_typet::componentt &component=dest_c.back();

src/cpp/cpp_typecheck_constructor.cpp

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -283,48 +283,47 @@ void cpp_typecheckt::default_cpctor(
283283
// Then, we add the member initializers
284284
const struct_typet::componentst &components=
285285
to_struct_type(symbol.type).components();
286-
for(struct_typet::componentst::const_iterator mem_it=components.begin();
287-
mem_it!=components.end(); mem_it++)
286+
287+
for(const auto &mem_c : components)
288288
{
289289
// Take care of virtual tables
290-
if(mem_it->get_bool("is_vtptr"))
290+
if(mem_c.get_bool("is_vtptr"))
291291
{
292292
exprt name(ID_name);
293-
name.set(ID_identifier, mem_it->get(ID_base_name));
293+
name.set(ID_identifier, mem_c.get(ID_base_name));
294294
name.add_source_location()=source_location;
295295

296296
cpp_namet cppname;
297297
cppname.move_to_sub(name);
298298

299299
const symbolt &virtual_table_symbol_type =
300-
lookup(mem_it->type().subtype().get(ID_identifier));
300+
lookup(mem_c.type().subtype().get(ID_identifier));
301301

302302
const symbolt &virtual_table_symbol_var = lookup(
303303
id2string(virtual_table_symbol_type.name) + "@" +
304304
id2string(symbol.name));
305305

306306
exprt var=virtual_table_symbol_var.symbol_expr();
307307
address_of_exprt address(var);
308-
assert(address.type()==mem_it->type());
308+
assert(address.type() == mem_c.type());
309309

310310
already_typechecked(address);
311311

312312
exprt ptrmember(ID_ptrmember);
313-
ptrmember.set(ID_component_name, mem_it->get(ID_name));
313+
ptrmember.set(ID_component_name, mem_c.get(ID_name));
314314
ptrmember.operands().push_back(exprt("cpp-this"));
315315

316316
code_assignt assign(ptrmember, address);
317317
initializers.move_to_sub(assign);
318318
continue;
319319
}
320320

321-
if( mem_it->get_bool("from_base")
322-
|| mem_it->get_bool(ID_is_type)
323-
|| mem_it->get_bool(ID_is_static)
324-
|| mem_it->type().id()==ID_code)
325-
continue;
321+
if(
322+
mem_c.get_bool("from_base") || mem_c.get_bool(ID_is_type) ||
323+
mem_c.get_bool(ID_is_static) || mem_c.type().id() == ID_code)
324+
continue;
326325

327-
irep_idt mem_name=mem_it->get(ID_base_name);
326+
irep_idt mem_name = mem_c.get(ID_base_name);
328327

329328
exprt name(ID_name);
330329
name.set(ID_identifier, mem_name);
@@ -343,7 +342,7 @@ void cpp_typecheckt::default_cpctor(
343342
static_cast<const exprt &>(static_cast<const irept &>(cpp_parameter)));
344343
memberexpr.add_source_location()=source_location;
345344

346-
if(mem_it->type().id()==ID_array)
345+
if(mem_c.type().id() == ID_array)
347346
memberexpr.set(ID_C_array_ini, true);
348347

349348
mem_init.move_to_operands(memberexpr);
@@ -563,27 +562,24 @@ void cpp_typecheckt::check_member_initializers(
563562
irep_idt base_name=member_name.get_base_name();
564563
bool ok=false;
565564

566-
for(struct_typet::componentst::const_iterator
567-
c_it=components.begin();
568-
c_it!=components.end();
569-
c_it++)
565+
for(const auto &c : components)
570566
{
571-
if(c_it->get(ID_base_name)!=base_name)
567+
if(c.get(ID_base_name) != base_name)
572568
continue;
573569

574570
// Data member
575-
if(!c_it->get_bool(ID_from_base) &&
576-
!c_it->get_bool(ID_is_static) &&
577-
c_it->get(ID_type)!=ID_code)
571+
if(
572+
!c.get_bool(ID_from_base) && !c.get_bool(ID_is_static) &&
573+
c.get(ID_type) != ID_code)
578574
{
579575
ok=true;
580576
break;
581577
}
582578

583579
// Maybe it is a parent constructor?
584-
if(c_it->get_bool("is_type"))
580+
if(c.get_bool("is_type"))
585581
{
586-
typet type=static_cast<const typet&>(c_it->find(ID_type));
582+
typet type = static_cast<const typet &>(c.find(ID_type));
587583
if(type.id() != ID_symbol_type)
588584
continue;
589585

@@ -605,11 +601,10 @@ void cpp_typecheckt::check_member_initializers(
605601
}
606602

607603
// Parent constructor
608-
if(c_it->get_bool(ID_from_base) &&
609-
!c_it->get_bool(ID_is_type) &&
610-
!c_it->get_bool(ID_is_static) &&
611-
c_it->get(ID_type)==ID_code &&
612-
c_it->find(ID_type).get(ID_return_type)==ID_constructor)
604+
if(
605+
c.get_bool(ID_from_base) && !c.get_bool(ID_is_type) &&
606+
!c.get_bool(ID_is_static) && c.get(ID_type) == ID_code &&
607+
c.find(ID_type).get(ID_return_type) == ID_constructor)
613608
{
614609
typet member_type=(typet&) initializer.find(ID_member);
615610
typecheck_type(member_type);
@@ -743,12 +738,11 @@ void cpp_typecheckt::full_member_initialization(
743738
// check if the initializer is a data
744739
bool is_data=false;
745740

746-
for(struct_typet::componentst::const_iterator c_it =
747-
components.begin(); c_it!=components.end(); c_it++)
741+
for(const auto &c : components)
748742
{
749-
if(c_it->get(ID_base_name)==base_name &&
750-
c_it->get(ID_type)!=ID_code &&
751-
!c_it->get_bool(ID_is_type))
743+
if(
744+
c.get(ID_base_name) == base_name && c.get(ID_type) != ID_code &&
745+
!c.get_bool(ID_is_type))
752746
{
753747
is_data=true;
754748
break;

src/cpp/cpp_typecheck_resolve.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -647,16 +647,9 @@ void cpp_typecheck_resolvet::make_constructors(
647647
{
648648
const struct_typet &struct_type=to_struct_type(symbol_type);
649649

650-
const struct_typet::componentst &components =
651-
struct_type.components();
652-
653650
// go over components
654-
for(struct_typet::componentst::const_iterator
655-
itc=components.begin();
656-
itc!=components.end();
657-
itc++)
651+
for(const auto &component : struct_type.components())
658652
{
659-
const struct_typet::componentt &component=*itc;
660653
const typet &type=component.type();
661654

662655
if(component.get_bool(ID_from_base))

src/cpp/expr2cpp.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,9 @@ std::string expr2cppt::convert_struct(
6868
bool first=true;
6969
size_t last_size=0;
7070

71-
for(struct_typet::componentst::const_iterator
72-
c_it=components.begin();
73-
c_it!=components.end();
74-
c_it++)
71+
for(const auto &c : components)
7572
{
76-
if(c_it->type().id()==ID_code)
73+
if(c.type().id() == ID_code)
7774
{
7875
}
7976
else
@@ -96,7 +93,7 @@ std::string expr2cppt::convert_struct(
9693

9794
dest+=sep;
9895
dest+='.';
99-
dest+=c_it->get_string(ID_pretty_name);
96+
dest += c.get_string(ID_pretty_name);
10097
dest+='=';
10198
dest+=tmp;
10299
}

src/solvers/flattening/boolbv.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,11 @@ bool boolbvt::literal(
8888

8989
std::size_t offset=0;
9090

91-
for(struct_typet::componentst::const_iterator
92-
it=components.begin();
93-
it!=components.end();
94-
it++)
91+
for(const auto &c : components)
9592
{
96-
const typet &subtype=it->type();
93+
const typet &subtype = c.type();
9794

98-
if(it->get_name()==component_name)
95+
if(c.get_name() == component_name)
9996
return literal(expr.op0(), bit+offset, dest);
10097

10198
std::size_t element_width=boolbv_width(subtype);

src/solvers/flattening/boolbv_get.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,9 @@ exprt boolbvt::bv_get_rec(
141141
exprt::operandst op;
142142
op.reserve(components.size());
143143

144-
for(struct_typet::componentst::const_iterator
145-
it=components.begin();
146-
it!=components.end();
147-
it++)
144+
for(const auto &c : components)
148145
{
149-
const typet &subtype=ns.follow(it->type());
146+
const typet &subtype = ns.follow(c.type());
150147
op.push_back(nil_exprt());
151148

152149
std::size_t sub_width=boolbv_width(subtype);

0 commit comments

Comments
 (0)