Skip to content

Commit d768a65

Browse files
author
Daniel Kroening
committed
brief list of symbols, from language_uit
1 parent cb62309 commit d768a65

File tree

3 files changed

+88
-5
lines changed

3 files changed

+88
-5
lines changed

src/goto-instrument/goto_instrument_parse_options.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Author: Daniel Kroening, [email protected]
4141
#include <goto-programs/remove_unused_functions.h>
4242
#include <goto-programs/parameter_assignments.h>
4343
#include <goto-programs/slice_global_inits.h>
44+
#include <goto-programs/show_symbol_table.h>
4445

4546
#include <pointer-analysis/value_set_analysis.h>
4647
#include <pointer-analysis/goto_program_dereference.h>
@@ -467,7 +468,7 @@ int goto_instrument_parse_optionst::doit()
467468

468469
if(cmdline.isset("show-symbol-table"))
469470
{
470-
show_symbol_table(goto_model, get_ui());
471+
::show_symbol_table(goto_model, get_ui());
471472
return 0;
472473
}
473474

src/goto-programs/show_symbol_table.cpp

+73-4
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,55 @@ void show_symbol_table_xml_ui()
2323
{
2424
}
2525

26+
void show_symbol_table_brief_plain(
27+
const symbol_tablet &symbol_table,
28+
std::ostream &out)
29+
{
30+
// we want to sort alphabetically
31+
std::set<std::string> symbols;
32+
33+
forall_symbols(it, symbol_table.symbols)
34+
symbols.insert(id2string(it->first));
35+
36+
const namespacet ns(symbol_table);
37+
38+
for(const std::string &id : symbols)
39+
{
40+
const symbolt &symbol=ns.lookup(id);
41+
42+
std::unique_ptr<languaget> ptr;
43+
44+
if(symbol.mode=="")
45+
ptr=get_default_language();
46+
else
47+
{
48+
ptr=get_language_from_mode(symbol.mode);
49+
if(ptr==nullptr)
50+
throw "symbol "+id2string(symbol.name)+" has unknown mode";
51+
}
52+
53+
std::string type_str;
54+
55+
if(symbol.type.is_not_nil())
56+
ptr->from_type(symbol.type, type_str, ns);
57+
58+
out << symbol.name << " " << type_str << '\n';
59+
}
60+
}
61+
2662
void show_symbol_table_plain(
27-
const goto_modelt &goto_model,
63+
const symbol_tablet &symbol_table,
2864
std::ostream &out)
2965
{
3066
out << '\n' << "Symbols:" << '\n' << '\n';
3167

3268
// we want to sort alphabetically
3369
std::set<std::string> symbols;
3470

35-
forall_symbols(it, goto_model.symbol_table.symbols)
71+
forall_symbols(it, symbol_table.symbols)
3672
symbols.insert(id2string(it->first));
3773

38-
const namespacet ns(goto_model.symbol_table);
74+
const namespacet ns(symbol_table);
3975

4076
for(const std::string &id : symbols)
4177
{
@@ -112,14 +148,40 @@ void show_symbol_table_plain(
112148
}
113149
}
114150

151+
void show_symbol_table(
152+
const symbol_tablet &symbol_table,
153+
ui_message_handlert::uit ui)
154+
{
155+
switch(ui)
156+
{
157+
case ui_message_handlert::uit::PLAIN:
158+
show_symbol_table_plain(symbol_table, std::cout);
159+
break;
160+
161+
case ui_message_handlert::uit::XML_UI:
162+
show_symbol_table_xml_ui();
163+
break;
164+
165+
default:
166+
break;
167+
}
168+
}
169+
115170
void show_symbol_table(
116171
const goto_modelt &goto_model,
117172
ui_message_handlert::uit ui)
173+
{
174+
show_symbol_table(goto_model.symbol_table, ui);
175+
}
176+
177+
void show_symbol_table_brief(
178+
const symbol_tablet &symbol_table,
179+
ui_message_handlert::uit ui)
118180
{
119181
switch(ui)
120182
{
121183
case ui_message_handlert::uit::PLAIN:
122-
show_symbol_table_plain(goto_model, std::cout);
184+
show_symbol_table_brief_plain(symbol_table, std::cout);
123185
break;
124186

125187
case ui_message_handlert::uit::XML_UI:
@@ -130,3 +192,10 @@ void show_symbol_table(
130192
break;
131193
}
132194
}
195+
196+
void show_symbol_table_brief(
197+
const goto_modelt &goto_model,
198+
ui_message_handlert::uit ui)
199+
{
200+
show_symbol_table_brief(goto_model.symbol_table, ui);
201+
}

src/goto-programs/show_symbol_table.h

+13
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,22 @@ Author: Daniel Kroening, [email protected]
1414

1515
#include <util/ui_message.h>
1616

17+
class symbol_tablet;
1718
class goto_modelt;
1819

1920
void show_symbol_table(
21+
const symbol_tablet &,
22+
ui_message_handlert::uit ui);
23+
24+
void show_symbol_table_brief(
25+
const symbol_tablet &,
26+
ui_message_handlert::uit ui);
27+
28+
void show_symbol_table(
29+
const goto_modelt &,
30+
ui_message_handlert::uit ui);
31+
32+
void show_symbol_table_brief(
2033
const goto_modelt &,
2134
ui_message_handlert::uit ui);
2235

0 commit comments

Comments
 (0)