Skip to content

Commit 22a59fb

Browse files
committed
Remove {f,F}orall_subtypes
This was useful in the past, but with C++-11 we can use a ranged-for to avoid the iterator altogether. As subtypes are no longer stored in a named sub (removing the corresponding #if-0-disabled code), the ranged-for can be used directly without testing for the existence of subtypes beforehand, as the forall macro did.
1 parent 2c11501 commit 22a59fb

14 files changed

+49
-54
lines changed

.clang-format

+1-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ ForEachMacros: [
3838
'Forall_operands',
3939
'forall_expr',
4040
'Forall_expr',
41-
'forall_symbol_base_map',
42-
'forall_subtypes',
43-
'Forall_subtypes']
41+
'forall_symbol_base_map']
4442
IndentCaseLabels: 'false'
4543
IndentPPDirectives: AfterHash
4644
IndentWidth: '2'

src/ansi-c/ansi_c_convert_type.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ void ansi_c_convert_typet::read_rec(const typet &type)
3232
{
3333
if(type.id()==ID_merged_type)
3434
{
35-
forall_subtypes(it, type)
36-
read_rec(*it);
35+
for(const typet &subtype : to_type_with_subtypes(type).subtypes())
36+
read_rec(subtype);
3737
}
3838
else if(type.id()==ID_signed)
3939
signed_cnt++;

src/ansi-c/ansi_c_parser.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,11 @@ ansi_c_id_classt ansi_c_parsert::get_class(const typet &type)
164164
return ansi_c_id_classt::ANSI_C_TAG;
165165
else if(type.id()==ID_merged_type)
166166
{
167-
forall_subtypes(it, type)
168-
if(get_class(*it)==ansi_c_id_classt::ANSI_C_TYPEDEF)
167+
for(const typet &subtype : to_type_with_subtypes(type).subtypes())
168+
{
169+
if(get_class(subtype) == ansi_c_id_classt::ANSI_C_TYPEDEF)
169170
return ansi_c_id_classt::ANSI_C_TYPEDEF;
171+
}
170172
}
171173
else if(type.has_subtype())
172174
return get_class(type.subtype());

src/ansi-c/c_storage_spec.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ void c_storage_spect::read(const typet &type)
1616
if(type.id()==ID_merged_type ||
1717
type.id()==ID_code)
1818
{
19-
forall_subtypes(it, type)
20-
read(*it);
19+
for(const typet &subtype : to_type_with_subtypes(type).subtypes())
20+
read(subtype);
2121
}
2222
else if(type.id()==ID_static)
2323
is_static=true;

src/ansi-c/type2name.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ static std::string type2name(
258258
if(type.has_subtypes())
259259
{
260260
result+='$';
261-
forall_subtypes(it, type)
261+
for(const typet &subtype : to_type_with_subtypes(type).subtypes())
262262
{
263-
result+=type2name(*it, ns, symbol_number);
263+
result += type2name(subtype, ns, symbol_number);
264264
result+='|';
265265
}
266266
result[result.size()-1]='$';

src/cpp/cpp_declaration.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void cpp_declarationt::name_anon_struct_union(typet &dest)
5757
}
5858
else if(dest.id()==ID_merged_type)
5959
{
60-
Forall_subtypes(it, dest)
61-
name_anon_struct_union(*it);
60+
for(typet &subtype : to_type_with_subtypes(dest).subtypes())
61+
name_anon_struct_union(subtype);
6262
}
6363
}

src/cpp/cpp_storage_spec.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ void cpp_storage_spect::read(const typet &type)
1212
{
1313
if(type.id() == ID_merged_type || type.id() == ID_function_type)
1414
{
15-
forall_subtypes(it, type)
16-
read(*it);
15+
for(const typet &subtype : to_type_with_subtypes(type).subtypes())
16+
read(subtype);
1717
}
1818
else if(type.id() == ID_static)
1919
set_static();

src/cpp/cpp_typecheck_compound_type.cpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ bool cpp_typecheckt::has_const(const typet &type)
3535
return true;
3636
else if(type.id()==ID_merged_type)
3737
{
38-
forall_subtypes(it, type)
39-
if(has_const(*it))
38+
for(const typet &subtype : to_type_with_subtypes(type).subtypes())
39+
{
40+
if(has_const(subtype))
4041
return true;
42+
}
4143

4244
return false;
4345
}
@@ -51,9 +53,11 @@ bool cpp_typecheckt::has_volatile(const typet &type)
5153
return true;
5254
else if(type.id()==ID_merged_type)
5355
{
54-
forall_subtypes(it, type)
55-
if(has_volatile(*it))
56+
for(const typet &subtype : to_type_with_subtypes(type).subtypes())
57+
{
58+
if(has_volatile(subtype))
5659
return true;
60+
}
5761

5862
return false;
5963
}
@@ -69,9 +73,11 @@ bool cpp_typecheckt::has_auto(const typet &type)
6973
type.id() == ID_merged_type || type.id() == ID_frontend_pointer ||
7074
type.id() == ID_pointer)
7175
{
72-
forall_subtypes(it, type)
73-
if(has_auto(*it))
76+
for(const typet &subtype : to_type_with_subtypes(type).subtypes())
77+
{
78+
if(has_auto(subtype))
7479
return true;
80+
}
7581

7682
return false;
7783
}

src/cpp/template_map.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ void template_mapt::apply(typet &type) const
6262
}
6363
else if(type.id()==ID_merged_type)
6464
{
65-
Forall_subtypes(it, type)
66-
apply(*it);
65+
for(typet &subtype : to_type_with_subtypes(type).subtypes())
66+
apply(subtype);
6767
}
6868
}
6969

src/goto-instrument/dump_c.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1475,8 +1475,8 @@ void dump_ct::cleanup_expr(exprt &expr)
14751475

14761476
void dump_ct::cleanup_type(typet &type)
14771477
{
1478-
Forall_subtypes(it, type)
1479-
cleanup_type(*it);
1478+
for(typet &subtype : to_type_with_subtypes(type).subtypes())
1479+
cleanup_type(subtype);
14801480

14811481
if(type.id()==ID_code)
14821482
{

src/util/find_symbols.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ void find_symbols(kindt kind, const typet &src, find_symbols_sett &dest)
124124
if(src.has_subtype())
125125
find_symbols(kind, to_type_with_subtype(src).subtype(), dest);
126126

127-
forall_subtypes(it, src)
128-
find_symbols(kind, *it, dest);
127+
for(const typet &subtype : to_type_with_subtypes(src).subtypes())
128+
find_symbols(kind, subtype, dest);
129129

130130
const irep_idt &typedef_name=src.get(ID_C_typedef);
131131
if(!typedef_name.empty())

src/util/rename_symbol.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ bool rename_symbolt::rename(typet &dest) const
129129
if(!rename(dest.subtype()))
130130
result=false;
131131

132-
Forall_subtypes(it, dest)
133-
if(!rename(*it))
132+
for(typet &subtype : to_type_with_subtypes(dest).subtypes())
133+
{
134+
if(!rename(subtype))
134135
result=false;
136+
}
135137

136138
if(dest.id()==ID_struct ||
137139
dest.id()==ID_union)
@@ -193,9 +195,11 @@ bool rename_symbolt::have_to_rename(const typet &dest) const
193195
if(have_to_rename(dest.subtype()))
194196
return true;
195197

196-
forall_subtypes(it, dest)
197-
if(have_to_rename(*it))
198+
for(const typet &subtype : to_type_with_subtypes(dest).subtypes())
199+
{
200+
if(have_to_rename(subtype))
198201
return true;
202+
}
199203

200204
if(dest.id()==ID_struct ||
201205
dest.id()==ID_union)

src/util/replace_symbol.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@ bool replace_symbolt::replace(typet &dest) const
170170
if(!replace(dest.subtype()))
171171
result=false;
172172

173-
Forall_subtypes(it, dest)
174-
if(!replace(*it))
173+
for(typet &subtype : to_type_with_subtypes(dest).subtypes())
174+
{
175+
if(!replace(subtype))
175176
result=false;
177+
}
176178

177179
if(dest.id()==ID_struct ||
178180
dest.id()==ID_union)
@@ -212,9 +214,11 @@ bool replace_symbolt::have_to_replace(const typet &dest) const
212214
if(have_to_replace(dest.subtype()))
213215
return true;
214216

215-
forall_subtypes(it, dest)
216-
if(have_to_replace(*it))
217+
for(const typet &subtype : to_type_with_subtypes(dest).subtypes())
218+
{
219+
if(have_to_replace(subtype))
217220
return true;
221+
}
218222

219223
if(dest.id()==ID_struct ||
220224
dest.id()==ID_union)

src/util/type.h

-19
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,6 @@ class type_with_subtypet:public typet
149149
: typet(std::move(_id), std::move(_subtype))
150150
{
151151
}
152-
153-
#if 0
154-
const typet &subtype() const
155-
{ return (typet &)find(ID_subtype); }
156-
157-
typet &subtype()
158-
{ return (typet &)add(ID_subtype); }
159-
#endif
160152
};
161153

162154
inline const type_with_subtypet &to_type_with_subtype(const typet &type)
@@ -213,17 +205,6 @@ inline type_with_subtypest &to_type_with_subtypes(typet &type)
213205
return static_cast<type_with_subtypest &>(type);
214206
}
215207

216-
#define forall_subtypes(it, type) \
217-
if((type).has_subtypes()) /* NOLINT(readability/braces) */ \
218-
for(type_with_subtypest::subtypest::const_iterator it=to_type_with_subtypes(type).subtypes().begin(), \
219-
it##_end=to_type_with_subtypes(type).subtypes().end(); \
220-
it!=it##_end; ++it)
221-
222-
#define Forall_subtypes(it, type) \
223-
if((type).has_subtypes()) /* NOLINT(readability/braces) */ \
224-
for(type_with_subtypest::subtypest::iterator it=to_type_with_subtypes(type).subtypes().begin(); \
225-
it!=to_type_with_subtypes(type).subtypes().end(); ++it)
226-
227208
/// Remove const qualifier from type (if any).
228209
/// Returns type as is if there is no const qualifier.
229210
typet remove_const(typet type);

0 commit comments

Comments
 (0)