Skip to content

Commit 178a87e

Browse files
committed
Remove {f,F}orall_named_irep
This was useful in the past, but with C++-11 we can use a ranged-for to avoid the iterator altogether.
1 parent 3f41c03 commit 178a87e

9 files changed

+63
-62
lines changed

.clang-format

-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ ForEachMacros: [
4444
'Forall_expr',
4545
'forall_irep',
4646
'Forall_irep',
47-
'forall_named_irep',
48-
'Forall_named_irep',
4947
'forall_symbol_base_map',
5048
'forall_subtypes',
5149
'Forall_subtypes']

src/cpp/cpp_type2name.cpp

+14-10
Original file line numberDiff line numberDiff line change
@@ -52,33 +52,37 @@ static std::string irep2name(const irept &irep)
5252
result+='(';
5353
bool first=true;
5454

55-
forall_named_irep(it, irep.get_named_sub())
56-
if(!irept::is_comment(it->first))
55+
for(const auto &named_sub : irep.get_named_sub())
56+
{
57+
if(!irept::is_comment(named_sub.first))
5758
{
5859
if(first)
5960
first = false;
6061
else
6162
result += ',';
6263

63-
result += do_prefix(name2string(it->first));
64+
result += do_prefix(name2string(named_sub.first));
6465

6566
result += '=';
66-
result += irep2name(it->second);
67+
result += irep2name(named_sub.second);
6768
}
69+
}
6870

69-
forall_named_irep(it, irep.get_named_sub())
70-
if(it->first==ID_C_constant ||
71-
it->first==ID_C_volatile ||
72-
it->first==ID_C_restricted)
71+
for(const auto &named_sub : irep.get_named_sub())
72+
{
73+
if(
74+
named_sub.first == ID_C_constant || named_sub.first == ID_C_volatile ||
75+
named_sub.first == ID_C_restricted)
7376
{
7477
if(first)
7578
first=false;
7679
else
7780
result+=',';
78-
result+=do_prefix(name2string(it->first));
81+
result += do_prefix(name2string(named_sub.first));
7982
result+='=';
80-
result += irep2name(it->second);
83+
result += irep2name(named_sub.second);
8184
}
85+
}
8286

8387
forall_irep(it, irep.get_sub())
8488
{

src/util/irep.cpp

+12-10
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,15 @@ std::size_t irept::hash() const
438438

439439
std::size_t number_of_named_ireps = 0;
440440

441-
forall_named_irep(it, named_sub)
442-
if(!is_comment(it->first)) // this variant ignores comments
441+
for(const auto &irep_entry : named_sub)
442+
{
443+
if(!is_comment(irep_entry.first)) // this variant ignores comments
443444
{
444-
result = hash_combine(result, hash_string(it->first));
445-
result = hash_combine(result, it->second.hash());
445+
result = hash_combine(result, hash_string(irep_entry.first));
446+
result = hash_combine(result, irep_entry.second.hash());
446447
number_of_named_ireps++;
447448
}
449+
}
448450

449451
result = hash_finalize(result, sub.size() + number_of_named_ireps);
450452

@@ -467,10 +469,10 @@ std::size_t irept::full_hash() const
467469
forall_irep(it, sub) result=hash_combine(result, it->full_hash());
468470

469471
// this variant includes all named_sub elements
470-
forall_named_irep(it, named_sub)
472+
for(const auto &irep_entry : named_sub)
471473
{
472-
result=hash_combine(result, hash_string(it->first));
473-
result=hash_combine(result, it->second.full_hash());
474+
result = hash_combine(result, hash_string(irep_entry.first));
475+
result = hash_combine(result, irep_entry.second.full_hash());
474476
}
475477

476478
const std::size_t named_sub_size = named_sub.size();
@@ -498,16 +500,16 @@ std::string irept::pretty(unsigned indent, unsigned max_indent) const
498500
indent+=2;
499501
}
500502

501-
forall_named_irep(it, get_named_sub())
503+
for(const auto &irep_entry : get_named_sub())
502504
{
503505
result+="\n";
504506
indent_str(result, indent);
505507

506508
result+="* ";
507-
result+=id2string(it->first);
509+
result += id2string(irep_entry.first);
508510
result+=": ";
509511

510-
result+=it->second.pretty(indent+2, max_indent);
512+
result += irep_entry.second.pretty(indent + 2, max_indent);
511513
}
512514

513515
std::size_t count=0;

src/util/irep.h

-8
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,6 @@ inline const std::string &name2string(const irep_namet &n)
7272
for(irept::subt::iterator it=(irep).begin(); \
7373
it!=(irep).end(); ++it)
7474

75-
#define forall_named_irep(it, irep) \
76-
for(irept::named_subt::const_iterator it=(irep).begin(); \
77-
it!=(irep).end(); ++it)
78-
79-
#define Forall_named_irep(it, irep) \
80-
for(irept::named_subt::iterator it=(irep).begin(); \
81-
it!=(irep).end(); ++it)
82-
8375
#ifdef IREP_DEBUG
8476
#include <iostream>
8577
#endif

src/util/irep_serialization.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ void irep_serializationt::write_irep(
3131
reference_convert(*it, out);
3232
}
3333

34-
forall_named_irep(it, irep.get_named_sub())
34+
for(const auto &sub_irep_entry : irep.get_named_sub())
3535
{
3636
out.put('N');
37-
write_string_ref(out, it->first);
38-
reference_convert(it->second, out);
37+
write_string_ref(out, sub_irep_entry.first);
38+
reference_convert(sub_irep_entry.second, out);
3939
}
4040

4141
out.put(0); // terminator

src/util/lispirep.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ void irep2lisp(const irept &src, lispexprt &dest)
7474
dest.push_back(sub);
7575
}
7676

77-
forall_named_irep(it, src.get_named_sub())
77+
for(const auto &irep_entry : src.get_named_sub())
7878
{
7979
lispexprt name;
8080
name.type=lispexprt::String;
81-
name.value=name2string(it->first);
81+
name.value = name2string(irep_entry.first);
8282
dest.push_back(name);
8383

8484
lispexprt sub;
8585

86-
irep2lisp(it->second, sub);
86+
irep2lisp(irep_entry.second, sub);
8787
dest.push_back(sub);
8888
}
8989

src/util/merge_irep.cpp

+16-15
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ std::size_t to_be_merged_irept::hash() const
2020
forall_irep(it, sub)
2121
result=hash_combine(result, static_cast<const merged_irept &>(*it).hash());
2222

23-
forall_named_irep(it, named_sub)
23+
for(const auto &irep_entry : named_sub)
2424
{
25-
result=hash_combine(result, hash_string(it->first));
26-
result=
27-
hash_combine(
28-
result, static_cast<const merged_irept &>(it->second).hash());
25+
result = hash_combine(result, hash_string(irep_entry.first));
26+
result = hash_combine(
27+
result, static_cast<const merged_irept &>(irep_entry.second).hash());
2928
}
3029

3130
const std::size_t named_sub_size = named_sub.size();
@@ -108,14 +107,15 @@ const merged_irept &merged_irepst::merged(const irept &irep)
108107
#if NAMED_SUB_IS_FORWARD_LIST
109108
irept::named_subt::iterator before = dest_named_sub.before_begin();
110109
#endif
111-
forall_named_irep(it, src_named_sub)
110+
for(const auto &irep_entry : src_named_sub)
112111
{
113112
#if NAMED_SUB_IS_FORWARD_LIST
114113
dest_named_sub.emplace_after(
115-
before, it->first, merged(it->second)); // recursive call
114+
before, irep_entry.first, merged(irep_entry.second)); // recursive call
116115
++before;
117116
#else
118-
dest_named_sub[it->first]=merged(it->second); // recursive call
117+
dest_named_sub[irep_entry.first] =
118+
merged(irep_entry.second); // recursive call
119119
#endif
120120
}
121121

@@ -164,12 +164,12 @@ const irept &merge_irept::merged(const irept &irep)
164164
irept::named_subt *dest_named_sub_ptr = nullptr;
165165

166166
std::ptrdiff_t advance_by = 0;
167-
forall_named_irep(it, src_named_sub)
167+
for(const auto &irep_entry : src_named_sub)
168168
{
169-
if(!irept::is_comment(it->first))
169+
if(!irept::is_comment(irep_entry.first))
170170
{
171-
const irept &op = merged(it->second); // recursive call
172-
if(&op.read() != &(it->second.read()))
171+
const irept &op = merged(irep_entry.second); // recursive call
172+
if(&op.read() != &(irep_entry.second.read()))
173173
{
174174
if(!dest_named_sub_ptr)
175175
dest_named_sub_ptr =
@@ -212,14 +212,15 @@ const irept &merge_full_irept::merged(const irept &irep)
212212
#if NAMED_SUB_IS_FORWARD_LIST
213213
irept::named_subt::iterator before = dest_named_sub.before_begin();
214214
#endif
215-
forall_named_irep(it, src_named_sub)
215+
for(const auto &irep_entry : src_named_sub)
216216
{
217217
#if NAMED_SUB_IS_FORWARD_LIST
218218
dest_named_sub.emplace_after(
219-
before, it->first, merged(it->second)); // recursive call
219+
before, irep_entry.first, merged(irep_entry.second)); // recursive call
220220
++before;
221221
#else
222-
dest_named_sub[it->first]=merged(it->second); // recursive call
222+
dest_named_sub[irep_entry.first] =
223+
merged(irep_entry.second); // recursive call
223224
#endif
224225
}
225226

src/util/source_location.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ std::string source_locationt::as_string(bool print_cwd) const
7272

7373
void source_locationt::merge(const source_locationt &from)
7474
{
75-
forall_named_irep(it, from.get_named_sub())
75+
for(const auto &irep_entry : from.get_named_sub())
7676
{
77-
if(get(it->first).empty())
78-
set(it->first, it->second);
77+
if(get(irep_entry.first).empty())
78+
set(irep_entry.first, irep_entry.second);
7979
}
8080
}
8181

src/util/xml_irep.cpp

+12-8
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,25 @@ void convert(
2929
convert(*it, x_sub);
3030
}
3131

32-
forall_named_irep(it, irep.get_named_sub())
33-
if(!irept::is_comment(it->first))
32+
for(const auto &irep_entry : irep.get_named_sub())
33+
{
34+
if(!irept::is_comment(irep_entry.first))
3435
{
3536
xmlt &x_nsub = xml.new_element("named_sub");
36-
x_nsub.set_attribute("name", name2string(it->first));
37-
convert(it->second, x_nsub);
37+
x_nsub.set_attribute("name", name2string(irep_entry.first));
38+
convert(irep_entry.second, x_nsub);
3839
}
40+
}
3941

40-
forall_named_irep(it, irep.get_named_sub())
41-
if(!irept::is_comment(it->first))
42+
for(const auto &irep_entry : irep.get_named_sub())
43+
{
44+
if(!irept::is_comment(irep_entry.first))
4245
{
4346
xmlt &x_com = xml.new_element("comment");
44-
x_com.set_attribute("name", name2string(it->first));
45-
convert(it->second, x_com);
47+
x_com.set_attribute("name", name2string(irep_entry.first));
48+
convert(irep_entry.second, x_com);
4649
}
50+
}
4751
}
4852

4953
void convert(

0 commit comments

Comments
 (0)