Skip to content

Commit 78b3f53

Browse files
Merge pull request diffblue#213 from diffblue/feature/recording-symbol-table
Recording symbol table
2 parents 63d1f68 + 2a1fa87 commit 78b3f53

Some content is hidden

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

47 files changed

+365
-242
lines changed

cbmc/src/analyses/is_threaded.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class is_threaded_domaint:public ai_domain_baset
8585
void is_threadedt::compute(const goto_functionst &goto_functions)
8686
{
8787
// the analysis doesn't actually use the namespace, fake one
88-
symbol_tablet symbol_table;
88+
concrete_symbol_tablet symbol_table;
8989
const namespacet ns(symbol_table);
9090

9191
ait<is_threaded_domaint> is_threaded_analysis;

cbmc/src/ansi-c/ansi_c_entry_point.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ bool generate_ansi_c_start_function(
478478
new_symbol.value.swap(init_code);
479479
new_symbol.mode=symbol.mode;
480480

481-
if(!symbol_table.insert(std::move(new_symbol)))
481+
if(!symbol_table.insert(std::move(new_symbol)).second)
482482
{
483483
messaget message;
484484
message.set_message_handler(message_handler);

cbmc/src/ansi-c/ansi_c_language.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ bool ansi_c_languaget::typecheck(
106106
symbol_tablet &symbol_table,
107107
const std::string &module)
108108
{
109-
symbol_tablet new_symbol_table;
109+
concrete_symbol_tablet new_symbol_table;
110110

111111
if(ansi_c_typecheck(
112112
parse_tree,

cbmc/src/ansi-c/ansi_c_typecheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bool ansi_c_typecheck(
4242
const unsigned errors_before=
4343
message_handler.get_message_count(messaget::M_ERROR);
4444

45-
symbol_tablet symbol_table;
45+
concrete_symbol_tablet symbol_table;
4646
ansi_c_parse_treet ansi_c_parse_tree;
4747

4848
ansi_c_typecheckt ansi_c_typecheck(

cbmc/src/ansi-c/type2name.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,6 @@ std::string type2name(const typet &type, const namespacet &ns)
266266

267267
std::string type2name(const typet &type)
268268
{
269-
symbol_tablet symbol_table;
269+
concrete_symbol_tablet symbol_table;
270270
return type2name(type, namespacet(symbol_table));
271271
}

cbmc/src/cbmc/bmc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class bmct:public safety_checkert
6868

6969
protected:
7070
const optionst &options;
71-
symbol_tablet new_symbol_table;
71+
concrete_symbol_tablet new_symbol_table;
7272
namespacet ns;
7373
symex_target_equationt equation;
7474
symex_bmct symex;

cbmc/src/cpp/cpp_language.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ bool cpp_languaget::typecheck(
126126
if(module=="")
127127
return false;
128128

129-
symbol_tablet new_symbol_table;
129+
concrete_symbol_tablet new_symbol_table;
130130

131131
if(cpp_typecheck(
132132
cpp_parse_tree, new_symbol_table, module, get_message_handler()))

cbmc/src/cpp/cpp_typecheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ bool cpp_typecheck(
102102
const unsigned errors_before=
103103
message_handler.get_message_count(messaget::M_ERROR);
104104

105-
symbol_tablet symbol_table;
105+
concrete_symbol_tablet symbol_table;
106106
cpp_parse_treet cpp_parse_tree;
107107

108108
cpp_typecheckt cpp_typecheck(cpp_parse_tree, symbol_table,

cbmc/src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ void cpp_typecheckt::typecheck_compound_declarator(
536536
vt_symb_type.type.set(ID_name, vt_symb_type.name);
537537
vt_symb_type.is_type=true;
538538

539-
const bool failed=!symbol_table.insert(std::move(vt_symb_type));
539+
const bool failed=!symbol_table.insert(std::move(vt_symb_type)).second;
540540
assert(!failed);
541541

542542
// add a virtual-table pointer
@@ -612,7 +612,7 @@ void cpp_typecheckt::typecheck_compound_declarator(
612612
arg.set(ID_C_identifier, arg_symb.name);
613613

614614
// add the parameter to the symbol table
615-
const bool failed=!symbol_table.insert(std::move(arg_symb));
615+
const bool failed=!symbol_table.insert(std::move(arg_symb)).second;
616616
assert(!failed);
617617
}
618618

@@ -670,7 +670,7 @@ void cpp_typecheckt::typecheck_compound_declarator(
670670

671671
// add the function to the symbol table
672672
{
673-
bool failed=!symbol_table.insert(std::move(func_symb));
673+
bool failed=!symbol_table.insert(std::move(func_symb)).second;
674674
assert(!failed);
675675
}
676676

cbmc/src/cpp/cpp_typecheck_namespace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void cpp_typecheckt::convert(cpp_namespace_spect &namespace_spec)
7373
symbol.module=module;
7474
symbol.type=typet(ID_namespace);
7575

76-
if(!symbol_table.insert(std::move(symbol)))
76+
if(!symbol_table.insert(std::move(symbol)).second)
7777
{
7878
error().source_location=symbol.location;
7979
error() << "cpp_typecheckt::convert_namespace: symbol_table.move() failed"

cbmc/src/cpp/cpp_typecheck_virtual_table.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void cpp_typecheckt::do_virtual_table(const symbolt &symbol)
9595
}
9696
vt_symb_var.value=values;
9797

98-
bool failed=!symbol_table.insert(std::move(vt_symb_var));
98+
bool failed=!symbol_table.insert(std::move(vt_symb_var)).second;
9999
assert(!failed);
100100
}
101101
}

cbmc/src/goto-cc/linker_script_merge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int linker_script_merget::add_linker_script_definitions()
5353
return fail;
5454
}
5555

56-
symbol_tablet original_st;
56+
concrete_symbol_tablet original_st;
5757
goto_functionst original_gf;
5858
fail=read_goto_binary(goto_file, original_st, original_gf,
5959
get_message_handler());

cbmc/src/goto-instrument/dump_c.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void dump_ct::operator()(std::ostream &os)
4646

4747
// add copies of struct types when ID_C_transparent_union is only
4848
// annotated to parameter
49-
symbol_tablet symbols_transparent;
49+
concrete_symbol_tablet symbols_transparent;
5050
for(const auto &named_symbol : copied_symbol_table.symbols)
5151
{
5252
const symbolt &symbol=named_symbol.second;

cbmc/src/goto-instrument/dump_c_class.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class dump_ct
4848

4949
protected:
5050
const goto_functionst &goto_functions;
51-
symbol_tablet copied_symbol_table;
51+
concrete_symbol_tablet copied_symbol_table;
5252
const namespacet ns;
5353
std::unique_ptr<languaget> language;
5454
const bool harness;

cbmc/src/goto-instrument/model_argc_argv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ bool model_argc_argv(
106106
ansi_c_language.parse(iss, "");
107107
config.ansi_c.preprocessor=pp;
108108

109-
symbol_tablet tmp_symbol_table;
109+
concrete_symbol_tablet tmp_symbol_table;
110110
ansi_c_language.typecheck(tmp_symbol_table, "<built-in-library>");
111111

112112
goto_programt init_instructions;

cbmc/src/goto-programs/goto_model.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Author: Daniel Kroening, [email protected]
2222
class goto_modelt
2323
{
2424
public:
25-
symbol_tablet symbol_table;
25+
concrete_symbol_tablet symbol_table;
2626
goto_functionst goto_functions;
2727

2828
void clear()

cbmc/src/goto-programs/goto_program_template.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ class goto_program_templatet
495495
/// Output goto-program to given stream
496496
std::ostream &output(std::ostream &out) const
497497
{
498-
return output(namespacet(symbol_tablet()), "", out);
498+
return output(namespacet(concrete_symbol_tablet()), "", out);
499499
}
500500

501501
/// Output a single instruction

cbmc/src/goto-programs/read_goto_binary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ bool read_object_and_link(
251251
/// \return true on error, false otherwise
252252
bool read_object_and_link(
253253
const std::string &file_name,
254-
symbol_tablet &dest_symbol_table,
254+
concrete_symbol_tablet &dest_symbol_table,
255255
goto_functionst &dest_functions,
256256
message_handlert &message_handler)
257257
{

cbmc/src/goto-programs/read_goto_binary.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class goto_functionst;
1818
class goto_modelt;
1919
class message_handlert;
2020
class symbol_tablet;
21+
class concrete_symbol_tablet;
2122

2223
bool read_goto_binary(
2324
const std::string &filename,
@@ -34,7 +35,7 @@ bool is_goto_binary(const std::string &filename);
3435

3536
bool read_object_and_link(
3637
const std::string &file_name,
37-
symbol_tablet &,
38+
concrete_symbol_tablet &,
3839
goto_functionst &,
3940
message_handlert &);
4041

cbmc/src/goto-symex/symex_target_equation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ std::ostream &operator<<(
723723
const symex_target_equationt::SSA_stept &step)
724724
{
725725
// may cause lookup failures, since it's blank
726-
symbol_tablet symbol_table;
726+
concrete_symbol_tablet symbol_table;
727727
namespacet ns(symbol_table);
728728
step.output(ns, out);
729729
return out;

cbmc/src/java_bytecode/ci_lazy_methods.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ bool ci_lazy_methodst::operator()(
172172
while(any_new_methods);
173173

174174
// Remove symbols for methods that were declared but never used:
175-
symbol_tablet keep_symbols;
175+
std::unordered_set<irep_idt, irep_id_hash> unreachable_symbols;
176+
for(const auto &sym : symbol_table.symbols)
177+
unreachable_symbols.insert(sym.first);
176178

177179
for(const auto &sym : symbol_table.symbols)
178180
{
@@ -184,16 +186,16 @@ bool ci_lazy_methodst::operator()(
184186
continue;
185187
}
186188
if(sym.second.type.id()==ID_code)
187-
gather_needed_globals(sym.second.value, symbol_table, keep_symbols);
188-
keep_symbols.add(sym.second);
189+
gather_needed_globals(sym.second.value, symbol_table, unreachable_symbols);
190+
unreachable_symbols.erase(sym.first);
189191
}
190192

191-
debug() << "CI lazy methods: removed "
192-
<< symbol_table.symbols.size() - keep_symbols.symbols.size()
193-
<< " unreaclass_hierarchyable methods and globals"
194-
<< eom;
193+
debug()
194+
<< "CI lazy methods: removed " << unreachable_symbols.size()
195+
<< " unreachable methods and globals" << eom;
195196

196-
symbol_table.swap(keep_symbols);
197+
for(const irep_idt &symbol_name : unreachable_symbols)
198+
symbol_table.remove(symbol_name);
197199

198200
return false;
199201
}
@@ -425,7 +427,7 @@ void ci_lazy_methodst::get_virtual_method_targets(
425427
void ci_lazy_methodst::gather_needed_globals(
426428
const exprt &e,
427429
const symbol_tablet &symbol_table,
428-
symbol_tablet &needed)
430+
std::unordered_set<irep_idt, irep_id_hash> &unreachable)
429431
{
430432
if(e.id()==ID_symbol)
431433
{
@@ -438,12 +440,12 @@ void ci_lazy_methodst::gather_needed_globals(
438440
if(findit!=symbol_table.symbols.end() &&
439441
findit->second.is_static_lifetime)
440442
{
441-
needed.add(findit->second);
443+
unreachable.erase(findit->first);
442444
}
443445
}
444446
else
445447
forall_operands(opit, e)
446-
gather_needed_globals(*opit, symbol_table, needed);
448+
gather_needed_globals(*opit, symbol_table, unreachable);
447449
}
448450

449451
/// See param lazy_methods

cbmc/src/java_bytecode/ci_lazy_methods.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define CPROVER_JAVA_BYTECODE_GATHER_METHODS_LAZILY_H
1414

1515
#include <map>
16+
#include <unordered_set>
1617
#include <functional>
1718

1819
#include <util/irep.h>
@@ -90,7 +91,7 @@ class ci_lazy_methodst:public messaget
9091
void gather_needed_globals(
9192
const exprt &e,
9293
const symbol_tablet &symbol_table,
93-
symbol_tablet &needed);
94+
std::unordered_set<irep_idt, irep_id_hash> &unreachable);
9495

9596
void gather_field_types(const typet &class_type,
9697
const namespacet &ns,

cbmc/src/java_bytecode/java_bytecode_parse_tree.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void java_bytecode_parse_treet::classt::output(std::ostream &out) const
8282

8383
void java_bytecode_parse_treet::annotationt::output(std::ostream &out) const
8484
{
85-
symbol_tablet symbol_table;
85+
concrete_symbol_tablet symbol_table;
8686
namespacet ns(symbol_table);
8787

8888
out << '@' << type2java(type, ns);
@@ -108,7 +108,7 @@ void java_bytecode_parse_treet::annotationt::output(std::ostream &out) const
108108
void java_bytecode_parse_treet::annotationt::element_value_pairt::output(
109109
std::ostream &out) const
110110
{
111-
symbol_tablet symbol_table;
111+
concrete_symbol_tablet symbol_table;
112112
namespacet ns(symbol_table);
113113

114114
out << '"' << element_name << '"' << '=';
@@ -117,7 +117,7 @@ void java_bytecode_parse_treet::annotationt::element_value_pairt::output(
117117

118118
void java_bytecode_parse_treet::methodt::output(std::ostream &out) const
119119
{
120-
symbol_tablet symbol_table;
120+
concrete_symbol_tablet symbol_table;
121121
namespacet ns(symbol_table);
122122

123123
for(const auto &annotation : annotations)

cbmc/src/java_bytecode/java_entry_point.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ bool generate_java_start_function(
669669
new_symbol.value.swap(init_code);
670670
new_symbol.mode=ID_java;
671671

672-
if(!symbol_table.insert(std::move(new_symbol)))
672+
if(!symbol_table.insert(std::move(new_symbol)).second)
673673
{
674674
message.error() << "failed to move main symbol" << messaget::eom;
675675
return true;

cbmc/src/java_bytecode/java_utils.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,9 @@ void generate_class_stub(
8686
new_symbol.mode=ID_java;
8787
new_symbol.is_type=true;
8888

89-
optionalt<std::reference_wrapper<symbolt>> res=
90-
symbol_table.insert(std::move(new_symbol));
89+
std::pair<symbolt &, bool> res=symbol_table.insert(std::move(new_symbol));
9190

92-
if(!res)
91+
if(!res.second)
9392
{
9493
messaget message(message_handler);
9594
message.warning() <<
@@ -100,7 +99,7 @@ void generate_class_stub(
10099
else
101100
{
102101
// create the class identifier etc
103-
java_root_class(*res);
102+
java_root_class(res.first);
104103
}
105104
}
106105

cbmc/src/jsil/jsil_entry_point.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ bool jsil_entry_point(
162162
new_symbol.type.swap(main_type);
163163
new_symbol.value.swap(init_code);
164164

165-
if(!symbol_table.insert(std::move(new_symbol)))
165+
if(!symbol_table.insert(std::move(new_symbol)).second)
166166
{
167167
messaget message;
168168
message.set_message_handler(message_handler);

cbmc/src/jsil/jsil_language.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ bool jsil_languaget::to_expr(
152152
result=true;
153153
else
154154
{
155-
symbol_tablet symbol_table;
155+
concrete_symbol_tablet symbol_table;
156156
result=
157157
jsil_convert(parse_tree, symbol_table, get_message_handler());
158158

cbmc/src/jsil/jsil_typecheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ bool jsil_typecheck(
927927
const unsigned errors_before=
928928
message_handler.get_message_count(messaget::M_ERROR);
929929

930-
symbol_tablet symbol_table;
930+
concrete_symbol_tablet symbol_table;
931931

932932
jsil_typecheckt jsil_typecheck(
933933
symbol_table,

cbmc/src/langapi/language_ui.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class language_uit:public messaget
2121
{
2222
public:
2323
language_filest language_files;
24-
symbol_tablet symbol_table;
24+
concrete_symbol_tablet symbol_table;
2525

2626
language_uit(
2727
const cmdlinet &cmdline,

cbmc/src/langapi/language_util.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ std::string type_to_name(
153153

154154
std::string from_expr(const exprt &expr)
155155
{
156-
symbol_tablet symbol_table;
156+
concrete_symbol_tablet symbol_table;
157157
return from_expr(namespacet(symbol_table), "", expr);
158158
}
159159

160160
std::string from_type(const typet &type)
161161
{
162-
symbol_tablet symbol_table;
162+
concrete_symbol_tablet symbol_table;
163163
return from_type(namespacet(symbol_table), "", type);
164164
}
165165

@@ -185,6 +185,6 @@ exprt to_expr(
185185

186186
std::string type_to_name(const typet &type)
187187
{
188-
symbol_tablet symbol_table;
188+
concrete_symbol_tablet symbol_table;
189189
return type_to_name(namespacet(symbol_table), "", type);
190190
}

0 commit comments

Comments
 (0)