cprover
show_symbol_table.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Show the symbol table
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #include "show_symbol_table.h"
13 
14 #include <iostream>
15 #include <memory>
16 
17 #include <langapi/language.h>
18 #include <langapi/mode.h>
19 
20 #include "goto_model.h"
21 
23 {
24 }
25 
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  for(const auto &symbol_pair : symbol_table.symbols)
34  {
35  symbols.insert(id2string(symbol_pair.first));
36  }
37 
38  const namespacet ns(symbol_table);
39 
40  for(const std::string &id : symbols)
41  {
42  const symbolt &symbol=ns.lookup(id);
43 
44  std::unique_ptr<languaget> ptr;
45 
46  if(symbol.mode=="")
48  else
49  {
50  ptr=get_language_from_mode(symbol.mode);
51  if(ptr==nullptr)
52  throw "symbol "+id2string(symbol.name)+" has unknown mode";
53  }
54 
55  std::string type_str;
56 
57  if(symbol.type.is_not_nil())
58  ptr->from_type(symbol.type, type_str, ns);
59 
60  out << symbol.name << " " << type_str << '\n';
61  }
62 }
63 
65  const symbol_tablet &symbol_table,
66  std::ostream &out)
67 {
68  out << '\n' << "Symbols:" << '\n' << '\n';
69 
70  // we want to sort alphabetically
71  std::set<std::string> symbols;
72 
73  for(const auto &symbol_pair : symbol_table.symbols)
74  {
75  symbols.insert(id2string(symbol_pair.first));
76  }
77 
78  const namespacet ns(symbol_table);
79 
80  for(const std::string &id : symbols)
81  {
82  const symbolt &symbol=ns.lookup(id);
83 
84  std::unique_ptr<languaget> ptr;
85 
86  if(symbol.mode=="")
87  {
89  }
90  else
91  {
92  ptr=get_language_from_mode(symbol.mode);
93  }
94 
95  if(!ptr)
96  throw "symbol "+id2string(symbol.name)+" has unknown mode";
97 
98  std::string type_str, value_str;
99 
100  if(symbol.type.is_not_nil())
101  ptr->from_type(symbol.type, type_str, ns);
102 
103  if(symbol.value.is_not_nil())
104  ptr->from_expr(symbol.value, value_str, ns);
105 
106  out << "Symbol......: " << symbol.name << '\n' << std::flush;
107  out << "Pretty name.: " << symbol.pretty_name << '\n';
108  out << "Module......: " << symbol.module << '\n';
109  out << "Base name...: " << symbol.base_name << '\n';
110  out << "Mode........: " << symbol.mode << '\n';
111  out << "Type........: " << type_str << '\n';
112  out << "Value.......: " << value_str << '\n';
113  out << "Flags.......:";
114 
115  if(symbol.is_lvalue)
116  out << " lvalue";
117  if(symbol.is_static_lifetime)
118  out << " static_lifetime";
119  if(symbol.is_thread_local)
120  out << " thread_local";
121  if(symbol.is_file_local)
122  out << " file_local";
123  if(symbol.is_type)
124  out << " type";
125  if(symbol.is_extern)
126  out << " extern";
127  if(symbol.is_input)
128  out << " input";
129  if(symbol.is_output)
130  out << " output";
131  if(symbol.is_macro)
132  out << " macro";
133  if(symbol.is_parameter)
134  out << " parameter";
135  if(symbol.is_auxiliary)
136  out << " auxiliary";
137  if(symbol.is_weak)
138  out << " weak";
139  if(symbol.is_property)
140  out << " property";
141  if(symbol.is_state_var)
142  out << " state_var";
143  if(symbol.is_exported)
144  out << " exported";
145  if(symbol.is_volatile)
146  out << " volatile";
147 
148  out << '\n';
149  out << "Location....: " << symbol.location << '\n';
150 
151  out << '\n' << std::flush;
152  }
153 }
154 
156  const symbol_tablet &symbol_table,
158 {
159  switch(ui)
160  {
162  show_symbol_table_plain(symbol_table, std::cout);
163  break;
164 
167  break;
168 
169  default:
170  break;
171  }
172 }
173 
175  const goto_modelt &goto_model,
177 {
178  show_symbol_table(goto_model.symbol_table, ui);
179 }
180 
182  const symbol_tablet &symbol_table,
184 {
185  switch(ui)
186  {
188  show_symbol_table_brief_plain(symbol_table, std::cout);
189  break;
190 
193  break;
194 
195  default:
196  break;
197  }
198 }
199 
201  const goto_modelt &goto_model,
203 {
204  show_symbol_table_brief(goto_model.symbol_table, ui);
205 }
irep_idt name
The unique identifier.
Definition: symbol.h:43
bool is_output
Definition: symbol.h:63
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
bool is_not_nil() const
Definition: irep.h:173
bool is_thread_local
Definition: symbol.h:67
irep_idt mode
Language mode.
Definition: symbol.h:52
std::unique_ptr< languaget > get_default_language()
Returns the default language.
Definition: mode.cpp:138
std::unique_ptr< languaget > get_language_from_mode(const irep_idt &mode)
Get the language corresponding to the given mode.
Definition: mode.cpp:50
Show the symbol table.
exprt value
Initial value of symbol.
Definition: symbol.h:37
irep_idt module
Name of module the symbol belongs to.
Definition: symbol.h:46
irep_idt pretty_name
Language-specific display name.
Definition: symbol.h:55
symbol_tablet symbol_table
Symbol table.
Definition: goto_model.h:29
Symbol table entry.This is a symbol in the symbol table, stored in an object of type symbol_tablet...
Definition: symbol.h:30
bool is_static_lifetime
Definition: symbol.h:67
bool is_input
Definition: symbol.h:63
void show_symbol_table_brief(const symbol_tablet &symbol_table, ui_message_handlert::uit ui)
void show_symbol_table(const symbol_tablet &symbol_table, ui_message_handlert::uit ui)
Symbol Table + CFG.
bool is_exported
Definition: symbol.h:63
void show_symbol_table_brief_plain(const symbol_tablet &symbol_table, std::ostream &out)
bool is_parameter
Definition: symbol.h:68
The symbol table.
Definition: symbol_table.h:19
TO_BE_DOCUMENTED.
Definition: namespace.h:74
Abstract interface to support a programming language.
const symbolst & symbols
bool is_volatile
Definition: symbol.h:68
bool is_extern
Definition: symbol.h:68
virtual bool from_type(const typet &type, std::string &code, const namespacet &ns)
Formats the given type in a language-specific way.
Definition: language.cpp:46
typet type
Type of symbol.
Definition: symbol.h:34
source_locationt location
Source code location of definition of symbol.
Definition: symbol.h:40
bool is_state_var
Definition: symbol.h:63
irep_idt base_name
Base (non-scoped) name.
Definition: symbol.h:49
bool is_file_local
Definition: symbol.h:68
void show_symbol_table_xml_ui()
bool is_weak
Definition: symbol.h:68
bool is_auxiliary
Definition: symbol.h:68
virtual bool from_expr(const exprt &expr, std::string &code, const namespacet &ns)
Formats the given expression in a language-specific way.
Definition: language.cpp:37
bool is_type
Definition: symbol.h:63
bool is_property
Definition: symbol.h:63
void show_symbol_table_plain(const symbol_tablet &symbol_table, std::ostream &out)
bool is_macro
Definition: symbol.h:63
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See namespace_baset::lookup().
Definition: namespace.cpp:136
bool is_lvalue
Definition: symbol.h:68