Skip to content

Commit 0d0dca4

Browse files
author
Daniel Kroening
authored
Merge pull request #1839 from thomasspriggs/tidy_up1
Refactoring usage of `forall_symbols` macro into c++11 loops and replacement of asserts.
2 parents 1b24851 + 4d33a91 commit 0d0dca4

23 files changed

+228
-196
lines changed

src/analyses/invariant_propagation.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,13 @@ void invariant_propagationt::get_globals(
173173
object_listt &dest)
174174
{
175175
// static ones
176-
forall_symbols(it, ns.get_symbol_table().symbols)
177-
if(it->second.is_lvalue &&
178-
it->second.is_static_lifetime)
179-
get_objects(it->second, dest);
176+
for(const auto &symbol_pair : ns.get_symbol_table().symbols)
177+
{
178+
if(symbol_pair.second.is_lvalue && symbol_pair.second.is_static_lifetime)
179+
{
180+
get_objects(symbol_pair.second, dest);
181+
}
182+
}
180183
}
181184

182185
bool invariant_propagationt::check_type(const typet &type) const

src/goto-instrument/alignment_checks.cpp

+28-28
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ void print_struct_alignment_problems(
1919
const symbol_tablet &symbol_table,
2020
std::ostream &out)
2121
{
22-
forall_symbols(it, symbol_table.symbols)
23-
if(it->second.is_type && it->second.type.id()==ID_struct)
22+
for(const auto &symbol_pair : symbol_table.symbols)
23+
{
24+
if(symbol_pair.second.is_type && symbol_pair.second.type.id() == ID_struct)
2425
{
25-
const struct_typet &str=to_struct_type(it->second.type);
26-
const struct_typet::componentst &components=str.components();
26+
const struct_typet &str = to_struct_type(symbol_pair.second.type);
27+
const struct_typet::componentst &components = str.components();
2728

28-
bool first_time_seen_in_struct=true;
29+
bool first_time_seen_in_struct = true;
2930

30-
for(struct_typet::componentst::const_iterator
31-
it_mem=components.begin();
32-
it_mem!=components.end();
31+
for(struct_typet::componentst::const_iterator it_mem = components.begin();
32+
it_mem != components.end();
3333
it_mem++)
3434
{
35-
mp_integer cumulated_length=0;
36-
bool first_time_seen_from=true;
35+
mp_integer cumulated_length = 0;
36+
bool first_time_seen_from = true;
3737

3838
// if the instruction cannot be aligned to the address,
3939
// try the next one
@@ -42,40 +42,39 @@ void print_struct_alignment_problems(
4242
// || alignment(it_mem->type())%config.ansi_c.alignment!=0)
4343
continue;
4444

45-
for(struct_typet::componentst::const_iterator
46-
it_next=it_mem;
47-
it_next!=components.end();
45+
for(struct_typet::componentst::const_iterator it_next = it_mem;
46+
it_next != components.end();
4847
it_next++)
4948
{
50-
const typet &it_type=it_next->type();
49+
const typet &it_type = it_next->type();
5150
const namespacet ns(symbol_table);
52-
mp_integer size=pointer_offset_size(it_type, ns);
51+
mp_integer size = pointer_offset_size(it_type, ns);
5352

54-
if(size<0)
55-
throw "type of unknown size:\n"+it_type.pretty();
53+
if(size < 0)
54+
throw "type of unknown size:\n" + it_type.pretty();
5655

57-
cumulated_length+=size;
56+
cumulated_length += size;
5857
// [it_mem;it_next] cannot be covered by an instruction
59-
if(cumulated_length>config.ansi_c.memory_operand_size)
58+
if(cumulated_length > config.ansi_c.memory_operand_size)
6059
{
6160
// if interferences have been found, no need to check with
6261
// starting from an already covered member
6362
if(!first_time_seen_from)
64-
it_mem=it_next-1;
63+
it_mem = it_next - 1;
6564
break;
6665
}
6766

68-
if(it_mem!=it_next && !it_next->get_is_padding())
67+
if(it_mem != it_next && !it_next->get_is_padding())
6968
{
7069
if(first_time_seen_in_struct)
7170
{
72-
first_time_seen_in_struct=false;
73-
first_time_seen_from=false;
71+
first_time_seen_in_struct = false;
72+
first_time_seen_from = false;
7473

7574
out << "\nWARNING: "
7675
<< "declaration of structure "
77-
<< str.find_type(ID_tag).pretty()
78-
<< " at " << it->second.location << '\n';
76+
<< str.find_type(ID_tag).pretty() << " at "
77+
<< symbol_pair.second.location << '\n';
7978
}
8079

8180
out << "members " << it_mem->get_pretty_name() << " and "
@@ -84,12 +83,12 @@ void print_struct_alignment_problems(
8483
}
8584
}
8685
}
87-
else if(it->second.type.id()==ID_array)
86+
else if(symbol_pair.second.type.id() == ID_array)
8887
{
8988
// is this structure likely to introduce data races?
9089
#if 0
9190
const namespacet ns(symbol_table);
92-
const array_typet array=to_array_type(it->second.type);
91+
const array_typet array=to_array_type(symbol_pair.second.type);
9392
const mp_integer size=
9493
pointer_offset_size(array.subtype(), ns);
9594

@@ -100,9 +99,10 @@ void print_struct_alignment_problems(
10099
{
101100
out << "\nWARNING: "
102101
<< "declaration of an array at "
103-
<< it->second.location <<
102+
<< symbol_pair.second.location <<
104103
<< "\nmight be concurrently accessed\n";
105104
}
106105
#endif
107106
}
107+
}
108108
}

src/goto-instrument/dump_c.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ void dump_ct::operator()(std::ostream &os)
8282
}
8383
}
8484
}
85-
forall_symbols(it, symbols_transparent.symbols)
86-
copied_symbol_table.add(it->second);
85+
for(const auto &symbol_pair : symbols_transparent.symbols)
86+
{
87+
copied_symbol_table.add(symbol_pair.second);
88+
}
8789

8890
typedef std::unordered_map<irep_idt, unsigned, irep_id_hash> unique_tagst;
8991
unique_tagst unique_tags;

src/goto-instrument/model_argc_argv.cpp

+12-10
Original file line numberDiff line numberDiff line change
@@ -114,25 +114,27 @@ bool model_argc_argv(
114114
// locate the body of the newly built start function as well as any
115115
// additional declarations we might need; the body will then be
116116
// converted and inserted into the start function
117-
forall_symbols(it, tmp_symbol_table.symbols)
117+
for(const auto &symbol_pair : tmp_symbol_table.symbols)
118118
{
119119
// add __CPROVER_assume if necessary (it might exist already)
120-
if(it->first==CPROVER_PREFIX "assume" ||
121-
it->first==CPROVER_PREFIX "input")
122-
goto_model.symbol_table.add(it->second);
123-
else if(it->first==goto_model.goto_functions.entry_point())
120+
if(
121+
symbol_pair.first == CPROVER_PREFIX "assume" ||
122+
symbol_pair.first == CPROVER_PREFIX "input")
123+
goto_model.symbol_table.add(symbol_pair.second);
124+
else if(symbol_pair.first == goto_model.goto_functions.entry_point())
124125
{
125-
value=it->second.value;
126+
value = symbol_pair.second.value;
126127

127128
replace_symbolt replace;
128129
replace.insert("ARGC", ns.lookup("argc'").symbol_expr());
129130
replace.insert("ARGV", ns.lookup("argv'").symbol_expr());
130131
replace(value);
131132
}
132-
else if(has_prefix(
133-
id2string(it->first),
134-
id2string(goto_model.goto_functions.entry_point())+"::") &&
135-
goto_model.symbol_table.add(it->second))
133+
else if(
134+
has_prefix(
135+
id2string(symbol_pair.first),
136+
id2string(goto_model.goto_functions.entry_point()) + "::") &&
137+
goto_model.symbol_table.add(symbol_pair.second))
136138
UNREACHABLE;
137139
}
138140
POSTCONDITION(value.is_not_nil());

src/goto-programs/class_hierarchy.cpp

+16-14
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ Date: April 2016
2424
/// \param symbol_table: The symbol table to analyze
2525
void class_hierarchyt::operator()(const symbol_tablet &symbol_table)
2626
{
27-
forall_symbols(it, symbol_table.symbols)
27+
for(const auto &symbol_pair : symbol_table.symbols)
2828
{
29-
if(it->second.is_type && it->second.type.id()==ID_struct)
29+
if(symbol_pair.second.is_type && symbol_pair.second.type.id() == ID_struct)
3030
{
31-
const struct_typet &struct_type=
32-
to_struct_type(it->second.type);
31+
const struct_typet &struct_type = to_struct_type(symbol_pair.second.type);
3332

3433
const irept::subt &bases=
3534
struct_type.find(ID_bases).get_sub();
@@ -40,8 +39,8 @@ void class_hierarchyt::operator()(const symbol_tablet &symbol_table)
4039
if(parent.empty())
4140
continue;
4241

43-
class_map[parent].children.push_back(it->first);
44-
class_map[it->first].parents.push_back(parent);
42+
class_map[parent].children.push_back(symbol_pair.first);
43+
class_map[symbol_pair.first].parents.push_back(parent);
4544
}
4645
}
4746
}
@@ -55,28 +54,31 @@ void class_hierarchyt::operator()(const symbol_tablet &symbol_table)
5554
void class_hierarchy_grapht::populate(const symbol_tablet &symbol_table)
5655
{
5756
// Add nodes for all classes:
58-
forall_symbols(it, symbol_table.symbols)
57+
for(const auto &symbol_pair : symbol_table.symbols)
5958
{
60-
if(it->second.is_type && it->second.type.id() == ID_struct)
59+
if(symbol_pair.second.is_type && symbol_pair.second.type.id() == ID_struct)
6160
{
6261
node_indext new_node_index = add_node();
63-
nodes_by_name[it->first] = new_node_index;
64-
(*this)[new_node_index].class_identifier = it->first;
62+
nodes_by_name[symbol_pair.first] = new_node_index;
63+
(*this)[new_node_index].class_identifier = symbol_pair.first;
6564
}
6665
}
6766

6867
// Add parent -> child edges:
69-
forall_symbols(it, symbol_table.symbols)
68+
for(const auto &symbol_pair : symbol_table.symbols)
7069
{
71-
if(it->second.is_type && it->second.type.id() == ID_struct)
70+
if(symbol_pair.second.is_type && symbol_pair.second.type.id() == ID_struct)
7271
{
73-
const class_typet &class_type = to_class_type(it->second.type);
72+
const class_typet &class_type = to_class_type(symbol_pair.second.type);
7473

7574
for(const auto &base : class_type.bases())
7675
{
7776
const irep_idt &parent = to_symbol_type(base.type()).get_identifier();
7877
if(!parent.empty())
79-
add_edge(nodes_by_name.at(parent), nodes_by_name.at(it->first));
78+
{
79+
add_edge(
80+
nodes_by_name.at(parent), nodes_by_name.at(symbol_pair.first));
81+
}
8082
}
8183
}
8284
}

src/goto-programs/goto_convert_functions.cpp

+16-14
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ void goto_convert_functionst::goto_convert(goto_functionst &functions)
3838
typedef std::list<irep_idt> symbol_listt;
3939
symbol_listt symbol_list;
4040

41-
forall_symbols(it, symbol_table.symbols)
41+
for(const auto &symbol_pair : symbol_table.symbols)
4242
{
43-
if(!it->second.is_type &&
44-
!it->second.is_macro &&
45-
it->second.type.id()==ID_code &&
46-
(it->second.mode==ID_C ||
47-
it->second.mode==ID_cpp ||
48-
it->second.mode==ID_java ||
49-
it->second.mode=="jsil"))
50-
symbol_list.push_back(it->first);
43+
if(
44+
!symbol_pair.second.is_type && !symbol_pair.second.is_macro &&
45+
symbol_pair.second.type.id() == ID_code &&
46+
(symbol_pair.second.mode == ID_C || symbol_pair.second.mode == ID_cpp ||
47+
symbol_pair.second.mode == ID_java || symbol_pair.second.mode == "jsil"))
48+
{
49+
symbol_list.push_back(symbol_pair.first);
50+
}
5151
}
5252

5353
for(const auto &id : symbol_list)
@@ -59,12 +59,14 @@ void goto_convert_functionst::goto_convert(goto_functionst &functions)
5959

6060
// this removes the parse tree of the bodies from memory
6161
#if 0
62-
Forall_symbols(it, symbol_table.symbols)
62+
for(const auto &symbol_pair, symbol_table.symbols)
6363
{
64-
if(!it->second.is_type &&
65-
it->second.type.id()==ID_code &&
66-
it->second.value.is_not_nil())
67-
it->second.value=codet();
64+
if(!symbol_pair.second.is_type &&
65+
symbol_pair.second.type.id()==ID_code &&
66+
symbol_pair.second.value.is_not_nil())
67+
{
68+
symbol_pair.second.value=codet();
69+
}
6870
}
6971
#endif
7072
}

src/goto-programs/link_goto_model.cpp

+12-8
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,14 @@ static bool link_functions(
110110
// apply macros
111111
rename_symbolt macro_application;
112112

113-
forall_symbols(it, dest_symbol_table.symbols)
114-
if(it->second.is_macro && !it->second.is_type)
113+
for(const auto &symbol_pair : dest_symbol_table.symbols)
114+
{
115+
if(symbol_pair.second.is_macro && !symbol_pair.second.is_type)
115116
{
116-
const symbolt &symbol=it->second;
117+
const symbolt &symbol = symbol_pair.second;
117118

118-
INVARIANT(symbol.value.id()==ID_symbol, "must have symbol");
119-
const irep_idt &id=to_symbol_expr(symbol.value).get_identifier();
119+
INVARIANT(symbol.value.id() == ID_symbol, "must have symbol");
120+
const irep_idt &id = to_symbol_expr(symbol.value).get_identifier();
120121

121122
#if 0
122123
if(!base_type_eq(symbol.type, ns.lookup(id).type, ns))
@@ -130,6 +131,7 @@ static bool link_functions(
130131

131132
macro_application.insert_expr(symbol.name, id);
132133
}
134+
}
133135

134136
if(!macro_application.expr_map.empty())
135137
Forall_goto_functions(dest_it, dest_functions)
@@ -159,9 +161,11 @@ void link_goto_model(
159161
typedef std::unordered_set<irep_idt, irep_id_hash> id_sett;
160162
id_sett weak_symbols;
161163

162-
forall_symbols(it, dest.symbol_table.symbols)
163-
if(it->second.is_weak)
164-
weak_symbols.insert(it->first);
164+
for(const auto &symbol_pair : dest.symbol_table.symbols)
165+
{
166+
if(symbol_pair.second.is_weak)
167+
weak_symbols.insert(symbol_pair.first);
168+
}
165169

166170
linkingt linking(dest.symbol_table,
167171
src.symbol_table,

src/goto-programs/show_symbol_table.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ void show_symbol_table_brief_plain(
3030
// we want to sort alphabetically
3131
std::set<std::string> symbols;
3232

33-
forall_symbols(it, symbol_table.symbols)
34-
symbols.insert(id2string(it->first));
33+
for(const auto &symbol_pair : symbol_table.symbols)
34+
{
35+
symbols.insert(id2string(symbol_pair.first));
36+
}
3537

3638
const namespacet ns(symbol_table);
3739

@@ -68,8 +70,10 @@ void show_symbol_table_plain(
6870
// we want to sort alphabetically
6971
std::set<std::string> symbols;
7072

71-
forall_symbols(it, symbol_table.symbols)
72-
symbols.insert(id2string(it->first));
73+
for(const auto &symbol_pair : symbol_table.symbols)
74+
{
75+
symbols.insert(id2string(symbol_pair.first));
76+
}
7377

7478
const namespacet ns(symbol_table);
7579

src/goto-programs/write_goto_binary.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ bool write_goto_binary_v3(
3030

3131
write_gb_word(out, symbol_table.symbols.size());
3232

33-
forall_symbols(it, symbol_table.symbols)
33+
for(const auto &symbol_pair : symbol_table.symbols)
3434
{
3535
// Since version 2, symbols are not converted to ireps,
3636
// instead they are saved in a custom binary format
3737

38-
const symbolt &sym = it->second;
38+
const symbolt &sym = symbol_pair.second;
3939

4040
irepconverter.reference_convert(sym.type, out);
4141
irepconverter.reference_convert(sym.value, out);

src/goto-symex/symex_start_thread.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ void goto_symext::symex_start_thread(statet &state)
9797
// initialize all variables marked thread-local
9898
const symbol_tablet &symbol_table=ns.get_symbol_table();
9999

100-
forall_symbols(it, symbol_table.symbols)
100+
for(const auto &symbol_pair : symbol_table.symbols)
101101
{
102-
const symbolt &symbol=it->second;
102+
const symbolt &symbol = symbol_pair.second;
103103

104104
if(!symbol.is_thread_local ||
105105
!symbol.is_static_lifetime ||

0 commit comments

Comments
 (0)