Skip to content

Commit 8107404

Browse files
Merge pull request diffblue#205 from diffblue/feature/restrict-symbol-table
Restrict symbol table
2 parents b7f8b12 + e4fc45a commit 8107404

File tree

66 files changed

+513
-473
lines changed

Some content is hidden

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

66 files changed

+513
-473
lines changed

src/ansi-c/ansi_c_entry_point.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void record_function_outputs(
7272
codet output(ID_output);
7373
output.operands().resize(2);
7474

75-
const symbolt &return_symbol=symbol_table.lookup("return'");
75+
const symbolt &return_symbol=*symbol_table.lookup("return'");
7676

7777
output.op0()=
7878
address_of_exprt(
@@ -212,7 +212,7 @@ bool generate_ansi_c_start_function(
212212
// build call to initialization function
213213

214214
{
215-
symbol_tablet::symbolst::iterator init_it=
215+
symbol_tablet::symbolst::const_iterator init_it=
216216
symbol_table.symbols.find(INITIALIZE_FUNCTION);
217217

218218
if(init_it==symbol_table.symbols.end())
@@ -478,11 +478,11 @@ bool generate_ansi_c_start_function(
478478
new_symbol.value.swap(init_code);
479479
new_symbol.mode=symbol.mode;
480480

481-
if(symbol_table.move(new_symbol))
481+
if(!symbol_table.insert(std::move(new_symbol)))
482482
{
483483
messaget message;
484484
message.set_message_handler(message_handler);
485-
message.error() << "failed to move main symbol" << messaget::eom;
485+
message.error() << "failed to insert main symbol" << messaget::eom;
486486
return true;
487487
}
488488

src/ansi-c/c_typecheck_base.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void c_typecheck_baset::typecheck_symbol(symbolt &symbol)
100100
}
101101

102102
// see if we have it already
103-
symbol_tablet::symbolst::iterator old_it=
103+
symbol_tablet::symbolst::const_iterator old_it=
104104
symbol_table.symbols.find(symbol.name);
105105

106106
if(old_it==symbol_table.symbols.end())
@@ -121,10 +121,11 @@ void c_typecheck_baset::typecheck_symbol(symbolt &symbol)
121121
throw 0;
122122
}
123123

124+
symbolt & existing_symbol=*symbol_table.get_writeable(symbol.name);
124125
if(symbol.is_type)
125-
typecheck_redefinition_type(old_it->second, symbol);
126+
typecheck_redefinition_type(existing_symbol, symbol);
126127
else
127-
typecheck_redefinition_non_type(old_it->second, symbol);
128+
typecheck_redefinition_non_type(existing_symbol, symbol);
128129
}
129130
}
130131

@@ -350,10 +351,10 @@ void c_typecheck_baset::typecheck_redefinition_non_type(
350351
{
351352
const irep_idt &identifier=p_it->get_identifier();
352353

353-
symbol_tablet::symbolst::iterator p_s_it=
354+
symbol_tablet::symbolst::const_iterator p_s_it=
354355
symbol_table.symbols.find(identifier);
355356
if(p_s_it!=symbol_table.symbols.end())
356-
symbol_table.symbols.erase(p_s_it);
357+
symbol_table.erase(p_s_it);
357358
}
358359
}
359360
else
@@ -732,10 +733,7 @@ void c_typecheck_baset::typecheck_declaration(
732733
// add code contract (if any); we typecheck this after the
733734
// function body done above, so as to have parameter symbols
734735
// available
735-
symbol_tablet::symbolst::iterator s_it=
736-
symbol_table.symbols.find(identifier);
737-
assert(s_it!=symbol_table.symbols.end());
738-
symbolt &new_symbol=s_it->second;
736+
symbolt &new_symbol=*symbol_table.get_writeable(identifier);
739737

740738
typecheck_spec_expr(contract, ID_C_spec_requires);
741739

src/ansi-c/c_typecheck_code.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ void c_typecheck_baset::typecheck_decl(codet &code)
287287
irep_idt identifier=d_it->get_name();
288288

289289
// look it up
290-
symbol_tablet::symbolst::iterator s_it=
290+
symbol_tablet::symbolst::const_iterator s_it=
291291
symbol_table.symbols.find(identifier);
292292

293293
if(s_it==symbol_table.symbols.end())
@@ -298,7 +298,7 @@ void c_typecheck_baset::typecheck_decl(codet &code)
298298
throw 0;
299299
}
300300

301-
symbolt &symbol=s_it->second;
301+
const symbolt &symbol=s_it->second;
302302

303303
// This must not be an incomplete type, unless it's 'extern'
304304
// or a typedef.

src/ansi-c/c_typecheck_expr.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ void c_typecheck_baset::typecheck_expr_builtin_va_arg(exprt &expr)
485485
symbol.name=ID_gcc_builtin_va_arg;
486486
symbol.type=symbol_type;
487487

488-
symbol_table.move(symbol);
488+
symbol_table.insert(std::move(symbol));
489489
}
490490

491491
void c_typecheck_baset::typecheck_expr_cw_va_arg_typeof(exprt &expr)
@@ -704,7 +704,7 @@ void c_typecheck_baset::typecheck_expr_operands(exprt &expr)
704704
declaration.declarators().front().get_name();
705705

706706
// look it up
707-
symbol_tablet::symbolst::iterator s_it=
707+
symbol_tablet::symbolst::const_iterator s_it=
708708
symbol_table.symbols.find(identifier);
709709

710710
if(s_it==symbol_table.symbols.end())
@@ -715,7 +715,7 @@ void c_typecheck_baset::typecheck_expr_operands(exprt &expr)
715715
throw 0;
716716
}
717717

718-
symbolt &symbol=s_it->second;
718+
const symbolt &symbol=s_it->second;
719719

720720
if(symbol.is_type || symbol.is_extern || symbol.is_static_lifetime ||
721721
!is_complete_type(symbol.type) || symbol.type.id()==ID_code)

src/ansi-c/c_typecheck_type.cpp

+6-11
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,7 @@ void c_typecheck_baset::typecheck_type(typet &type)
208208
{
209209
const irep_idt &tag_name=
210210
to_c_enum_tag_type(type.subtype()).get_identifier();
211-
212-
symbol_tablet::symbolst::iterator entry=
213-
symbol_table.symbols.find(tag_name);
214-
assert(entry!=symbol_table.symbols.end());
215-
216-
entry->second.type.subtype()=result;
211+
symbol_table.get_writeable(tag_name)->get().type.subtype()=result;
217212
}
218213

219214
type=result;
@@ -736,7 +731,7 @@ void c_typecheck_baset::typecheck_compound_type(struct_union_typet &type)
736731
identifier=type.find(ID_tag).get(ID_identifier);
737732

738733
// does it exist already?
739-
symbol_tablet::symbolst::iterator s_it=
734+
symbol_tablet::symbolst::const_iterator s_it=
740735
symbol_table.symbols.find(identifier);
741736

742737
if(s_it==symbol_table.symbols.end())
@@ -787,7 +782,7 @@ void c_typecheck_baset::typecheck_compound_type(struct_union_typet &type)
787782
type.set(ID_tag, base_name);
788783

789784
typecheck_compound_body(type);
790-
s_it->second.type.swap(type);
785+
symbol_table.get_writeable(s_it->first)->get().type.swap(type);
791786
}
792787
}
793788
else if(have_body)
@@ -1213,19 +1208,19 @@ void c_typecheck_baset::typecheck_c_enum_type(typet &type)
12131208
enum_tag_symbol.type.subtype()=underlying_type;
12141209

12151210
// is it in the symbol table already?
1216-
symbol_tablet::symbolst::iterator s_it=
1211+
symbol_tablet::symbolst::const_iterator s_it=
12171212
symbol_table.symbols.find(identifier);
12181213

12191214
if(s_it!=symbol_table.symbols.end())
12201215
{
12211216
// Yes.
1222-
symbolt &symbol=s_it->second;
1217+
const symbolt &symbol=s_it->second;
12231218

12241219
if(symbol.type.id()==ID_incomplete_c_enum)
12251220
{
12261221
// Ok, overwrite the type in the symbol table.
12271222
// This gives us the members and the subtype.
1228-
symbol.type=enum_tag_symbol.type;
1223+
symbol_table.get_writeable(symbol.name)->get().type=enum_tag_symbol.type;
12291224
}
12301225
else if(symbol.type.id()==ID_c_enum)
12311226
{

src/cpp/cpp_declarator_converter.cpp

+10-15
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ symbolt &cpp_declarator_convertert::convert(
9898
}
9999

100100
// try static first
101-
symbol_tablet::symbolst::iterator c_it=
102-
cpp_typecheck.symbol_table.symbols.find(final_identifier);
101+
symbol_tablet::opt_symbol_reft maybe_symbol=
102+
cpp_typecheck.symbol_table.get_writeable(final_identifier);
103103

104-
if(c_it==cpp_typecheck.symbol_table.symbols.end())
104+
if(!maybe_symbol)
105105
{
106106
// adjust type if it's a non-static member function
107107
if(final_type.id()==ID_code)
@@ -111,9 +111,8 @@ symbolt &cpp_declarator_convertert::convert(
111111
get_final_identifier();
112112

113113
// try again
114-
c_it=cpp_typecheck.symbol_table.symbols.find(final_identifier);
115-
116-
if(c_it==cpp_typecheck.symbol_table.symbols.end())
114+
maybe_symbol=cpp_typecheck.symbol_table.get_writeable(final_identifier);
115+
if(!maybe_symbol)
117116
{
118117
cpp_typecheck.error().source_location=
119118
declarator.name().source_location();
@@ -125,9 +124,7 @@ symbolt &cpp_declarator_convertert::convert(
125124
}
126125
}
127126

128-
assert(c_it!=cpp_typecheck.symbol_table.symbols.end());
129-
130-
symbolt &symbol=c_it->second;
127+
symbolt &symbol=*maybe_symbol;
131128

132129
combine_types(declarator.name().source_location(), final_type, symbol);
133130
enforce_rules(symbol);
@@ -194,13 +191,11 @@ symbolt &cpp_declarator_convertert::convert(
194191
}
195192

196193
// already there?
197-
symbol_tablet::symbolst::iterator c_it=
198-
cpp_typecheck.symbol_table.symbols.find(final_identifier);
199-
200-
if(c_it==cpp_typecheck.symbol_table.symbols.end())
194+
symbol_tablet::opt_symbol_reft maybe_symbol=
195+
cpp_typecheck.symbol_table.get_writeable(final_identifier);
196+
if(!maybe_symbol)
201197
return convert_new_symbol(storage_spec, member_spec, declarator);
202-
203-
symbolt &symbol=c_it->second;
198+
symbolt &symbol=*maybe_symbol;
204199

205200
if(!storage_spec.is_extern())
206201
symbol.is_extern = false;

src/cpp/cpp_instantiate_template.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ const symbolt &cpp_typecheckt::instantiate_template(
372372
// been instantiated using these arguments
373373
{
374374
// need non-const handle on template symbol
375-
symbolt &s=symbol_table.symbols.find(template_symbol.name)->second;
375+
symbolt &s=*symbol_table.get_writeable(template_symbol.name);
376376
irept &instantiated_with=s.value.add("instantiated_with");
377377
instantiated_with.get_sub().push_back(specialization_template_args);
378378
}
@@ -451,12 +451,7 @@ const symbolt &cpp_typecheckt::instantiate_template(
451451

452452
if(is_template_method)
453453
{
454-
symbol_tablet::symbolst::iterator it =
455-
symbol_table.symbols.find(class_name);
456-
457-
assert(it!=symbol_table.symbols.end());
458-
459-
symbolt &symb = it->second;
454+
symbolt &symb=*symbol_table.get_writeable(class_name);
460455

461456
assert(new_decl.declarators().size() == 1);
462457

src/cpp/cpp_typecheck.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ void cpp_typecheckt::static_and_dynamic_initialization()
151151

152152
disable_access_control = true;
153153

154-
for(const auto &d_it : dynamic_initializations)
154+
for(const irep_idt &d_it : dynamic_initializations)
155155
{
156-
symbolt &symbol=symbol_table.symbols.find(d_it)->second;
156+
const symbolt &symbol=*symbol_table.lookup(d_it);
157157

158158
if(symbol.is_extern)
159159
continue;
@@ -178,7 +178,7 @@ void cpp_typecheckt::static_and_dynamic_initialization()
178178

179179
// Make it nil to get zero initialization by
180180
// __CPROVER_initialize
181-
symbol.value.make_nil();
181+
symbol_table.get_writeable(d_it)->get().value.make_nil();
182182
}
183183
else
184184
{
@@ -210,7 +210,7 @@ void cpp_typecheckt::static_and_dynamic_initialization()
210210
init_symbol.is_type=false;
211211
init_symbol.is_macro=false;
212212

213-
symbol_table.move(init_symbol);
213+
symbol_table.insert(std::move(init_symbol));
214214

215215
disable_access_control=false;
216216
}
@@ -223,14 +223,15 @@ void cpp_typecheckt::do_not_typechecked()
223223
{
224224
cont = false;
225225

226-
Forall_symbols(s_it, symbol_table.symbols)
226+
for(const auto &named_symbol : symbol_table.symbols)
227227
{
228-
symbolt &symbol=s_it->second;
228+
const symbolt &symbol=named_symbol.second;
229229

230230
if(symbol.value.id()=="cpp_not_typechecked" &&
231231
symbol.value.get_bool("is_used"))
232232
{
233233
assert(symbol.type.id()==ID_code);
234+
symbolt &symbol=*symbol_table.get_writeable(named_symbol.first);
234235

235236
if(symbol.base_name=="operator=")
236237
{
@@ -256,37 +257,36 @@ void cpp_typecheckt::do_not_typechecked()
256257
}
257258
while(cont);
258259

259-
Forall_symbols(s_it, symbol_table.symbols)
260+
for(const auto &named_symbol : symbol_table.symbols)
260261
{
261-
symbolt &symbol=s_it->second;
262-
if(symbol.value.id()=="cpp_not_typechecked")
263-
symbol.value.make_nil();
262+
if(named_symbol.second.value.id()=="cpp_not_typechecked")
263+
symbol_table.get_writeable(named_symbol.first)->get().value.make_nil();
264264
}
265265
}
266266

267267
void cpp_typecheckt::clean_up()
268268
{
269-
symbol_tablet::symbolst::iterator it=symbol_table.symbols.begin();
269+
symbol_tablet::symbolst::const_iterator it=symbol_table.symbols.begin();
270270

271271
while(it!=symbol_table.symbols.end())
272272
{
273-
symbol_tablet::symbolst::iterator cur_it = it;
273+
symbol_tablet::symbolst::const_iterator cur_it = it;
274274
it++;
275275

276-
symbolt &symbol = cur_it->second;
276+
const symbolt &symbol=cur_it->second;
277277

278278
// erase templates
279279
if(symbol.type.get_bool(ID_is_template))
280280
{
281-
symbol_table.symbols.erase(cur_it);
281+
symbol_table.erase(cur_it);
282282
continue;
283283
}
284284
else if(symbol.type.id()==ID_struct ||
285285
symbol.type.id()==ID_union)
286286
{
287287
// remove methods from 'components'
288-
struct_union_typet &struct_union_type=
289-
to_struct_union_type(symbol.type);
288+
struct_union_typet &struct_union_type=to_struct_union_type(
289+
symbol_table.get_writeable(cur_it->first)->get().type);
290290

291291
const struct_union_typet::componentst &components=
292292
struct_union_type.components();

0 commit comments

Comments
 (0)