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 <util/language.h>
18 #include <langapi/mode.h>
19 
20 #include "goto_model.h"
21 
23 {
24 }
25 
27  const goto_modelt &goto_model,
28  std::ostream &out)
29 {
30  out << '\n' << "Symbols:" << '\n' << '\n';
31 
32  // we want to sort alphabetically
33  std::set<std::string> symbols;
34 
35  forall_symbols(it, goto_model.symbol_table.symbols)
36  symbols.insert(id2string(it->first));
37 
38  const namespacet ns(goto_model.symbol_table);
39 
40  for(const std::string &id : symbols)
41  {
42  const symbolt &symbol=ns.lookup(id);
43 
44  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::unique_ptr<languaget> p(ptr);
56  std::string type_str, value_str;
57 
58  if(symbol.type.is_not_nil())
59  p->from_type(symbol.type, type_str, ns);
60 
61  if(symbol.value.is_not_nil())
62  p->from_expr(symbol.value, value_str, ns);
63 
64  out << "Symbol......: " << symbol.name << '\n' << std::flush;
65  out << "Pretty name.: " << symbol.pretty_name << '\n';
66  out << "Module......: " << symbol.module << '\n';
67  out << "Base name...: " << symbol.base_name << '\n';
68  out << "Mode........: " << symbol.mode << '\n';
69  out << "Type........: " << type_str << '\n';
70  out << "Value.......: " << value_str << '\n';
71  out << "Flags.......:";
72 
73  if(symbol.is_lvalue)
74  out << " lvalue";
75  if(symbol.is_static_lifetime)
76  out << " static_lifetime";
77  if(symbol.is_thread_local)
78  out << " thread_local";
79  if(symbol.is_file_local)
80  out << " file_local";
81  if(symbol.is_type)
82  out << " type";
83  if(symbol.is_extern)
84  out << " extern";
85  if(symbol.is_input)
86  out << " input";
87  if(symbol.is_output)
88  out << " output";
89  if(symbol.is_macro)
90  out << " macro";
91  if(symbol.is_parameter)
92  out << " parameter";
93  if(symbol.is_auxiliary)
94  out << " auxiliary";
95  if(symbol.is_weak)
96  out << " weak";
97  if(symbol.is_property)
98  out << " property";
99  if(symbol.is_state_var)
100  out << " state_var";
101  if(symbol.is_exported)
102  out << " exported";
103  if(symbol.is_volatile)
104  out << " volatile";
105 
106  out << '\n';
107  out << "Location....: " << symbol.location << '\n';
108 
109  out << '\n' << std::flush;
110  }
111 }
112 
114  const goto_modelt &goto_model,
116 {
117  switch(ui)
118  {
120  show_symbol_table_plain(goto_model, std::cout);
121  break;
122 
125  break;
126 
127  default:
128  break;
129  }
130 }
irep_idt name
The unique identifier.
Definition: symbol.h:46
virtual bool lookup(const irep_idt &name, const symbolt *&symbol) const
Definition: namespace.cpp:139
bool is_output
Definition: symbol.h:66
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
bool is_not_nil() const
Definition: irep.h:104
bool is_thread_local
Definition: symbol.h:70
#define forall_symbols(it, expr)
Definition: symbol_table.h:28
irep_idt mode
Language mode.
Definition: symbol.h:55
Show the symbol table.
exprt value
Initial value of symbol.
Definition: symbol.h:40
void show_symbol_table_plain(const goto_modelt &goto_model, std::ostream &out)
irep_idt module
Name of module the symbol belongs to.
Definition: symbol.h:49
irep_idt pretty_name
Language-specific display name.
Definition: symbol.h:58
symbol_tablet symbol_table
Definition: goto_model.h:25
Symbol table entry.This is a symbol in the symbol table, stored in an object of type symbol_tablet...
Definition: symbol.h:33
bool is_static_lifetime
Definition: symbol.h:70
bool is_input
Definition: symbol.h:66
Symbol Table + CFG.
symbolst symbols
Definition: symbol_table.h:57
bool is_exported
Definition: symbol.h:66
bool is_parameter
Definition: symbol.h:71
TO_BE_DOCUMENTED.
Definition: namespace.h:62
Abstract interface to support a programming language.
languaget * get_default_language()
Definition: mode.cpp:85
bool is_volatile
Definition: symbol.h:71
bool is_extern
Definition: symbol.h:71
virtual bool from_type(const typet &type, std::string &code, const namespacet &ns)
Definition: language.cpp:41
typet type
Type of symbol.
Definition: symbol.h:37
source_locationt location
Source code location of definition of symbol.
Definition: symbol.h:43
languaget * get_language_from_mode(const irep_idt &mode)
Definition: mode.cpp:40
bool is_state_var
Definition: symbol.h:66
irep_idt base_name
Base (non-scoped) name.
Definition: symbol.h:52
bool is_file_local
Definition: symbol.h:71
void show_symbol_table_xml_ui()
bool is_weak
Definition: symbol.h:71
bool is_auxiliary
Definition: symbol.h:71
virtual bool from_expr(const exprt &expr, std::string &code, const namespacet &ns)
Definition: language.cpp:32
void show_symbol_table(const goto_modelt &goto_model, ui_message_handlert::uit ui)
bool is_type
Definition: symbol.h:66
bool is_property
Definition: symbol.h:66
bool is_macro
Definition: symbol.h:66
bool is_lvalue
Definition: symbol.h:71