cprover
symbol.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 #include "symbol.h"
10 
11 #include <ostream>
12 
13 #include "source_location.h"
14 #include "std_expr.h"
15 
16 void symbolt::show(std::ostream &out) const
17 {
18  out << " " << name << '\n';
19  out << " type: " << type.pretty(4) << '\n'
20  << " value: " << value.pretty(4) << '\n';
21 
22  out << " flags:";
23  if(is_lvalue)
24  out << " lvalue";
26  out << " static_lifetime";
27  if(is_thread_local)
28  out << " thread_local";
29  if(is_file_local)
30  out << " file_local";
31  if(is_type)
32  out << " type";
33  if(is_extern)
34  out << " extern";
35  if(is_input)
36  out << " input";
37  if(is_output)
38  out << " output";
39  if(is_macro)
40  out << " macro";
41  if(is_parameter)
42  out << " parameter";
43  if(is_auxiliary)
44  out << " auxiliary";
45  if(is_weak)
46  out << " weak";
47  if(is_property)
48  out << " property";
49  if(is_state_var)
50  out << " state_var";
51  if(is_exported)
52  out << " exported";
53  if(is_volatile)
54  out << " volatile";
55  if(!mode.empty())
56  out << " mode=" << mode;
57  if(!base_name.empty())
58  out << " base_name=" << base_name;
59  if(!module.empty())
60  out << " module=" << module;
61  if(!pretty_name.empty())
62  out << " pretty_name=" << pretty_name;
63  out << '\n';
64  out << " location: " << location << '\n';
65 
66  out << '\n';
67 }
68 
69 std::ostream &operator<<(std::ostream &out,
70  const symbolt &symbol)
71 {
72  symbol.show(out);
73  return out;
74 }
75 
77 {
78  irept dest;
79 
80  dest.clear();
81  dest.add(ID_type)=type;
82  dest.add(ID_value)=value;
83  dest.add(ID_location)=location;
84  dest.set(ID_name, name);
85  dest.set(ID_module, module);
86  dest.set(ID_base_name, base_name);
87  dest.set(ID_mode, mode);
88  dest.set(ID_pretty_name, pretty_name);
89 
90  if(is_type)
91  dest.set("is_type", true);
92  if(is_macro)
93  dest.set("is_macro", true);
94  if(is_exported)
95  dest.set("is_exported", true);
96  if(is_input)
97  dest.set("is_input", true);
98  if(is_output)
99  dest.set("is_output", true);
100  if(is_state_var)
101  dest.set("is_statevar", true);
102  if(is_parameter)
103  dest.set("is_parameter", true);
104  if(is_auxiliary)
105  dest.set("is_auxiliary", true);
106  if(is_weak)
107  dest.set("is_weak", true);
108  if(is_property)
109  dest.set("is_property", true);
110  if(is_lvalue)
111  dest.set("is_lvalue", true);
113  dest.set("is_static_lifetime", true);
114  if(is_thread_local)
115  dest.set("is_thread_local", true);
116  if(is_file_local)
117  dest.set("is_file_local", true);
118  if(is_extern)
119  dest.set("is_extern", true);
120  if(is_volatile)
121  dest.set("is_volatile", true);
122 
123  return dest;
124 }
125 
126 void symbolt::from_irep(const irept &src)
127 {
128  type=static_cast<const typet &>(src.find(ID_type));
129  value=static_cast<const exprt &>(src.find(ID_value));
130  location=static_cast<const source_locationt &>(src.find(ID_location));
131 
132  name=src.get(ID_name);
133  module=src.get(ID_module);
134  base_name=src.get(ID_base_name);
135  mode=src.get(ID_mode);
136  pretty_name=src.get(ID_pretty_name);
137 
138  is_type=src.get_bool("is_type");
139  is_macro=src.get_bool("is_macro");
140  is_exported=src.get_bool("is_exported");
141  is_input=src.get_bool("is_input");
142  is_output=src.get_bool("is_output");
143  is_state_var=src.get_bool("is_state_var");
144  is_parameter=src.get_bool("is_parameter");
145  is_auxiliary=src.get_bool("is_auxiliary");
146  is_weak=src.get_bool("is_weak");
147  is_property=src.get_bool("property");
148  is_lvalue=src.get_bool("lvalue");
149  is_static_lifetime=src.get_bool("static_lifetime");
150  is_thread_local=src.get_bool("thread_local");
151  is_file_local=src.get_bool("file_local");
152  is_extern=src.get_bool("is_extern");
153  is_volatile=src.get_bool("is_volatile");
154 }
155 
157 {
158  #define SYM_SWAP1(x) x.swap(b.x)
159 
160  SYM_SWAP1(type);
161  SYM_SWAP1(value);
162  SYM_SWAP1(name);
164  SYM_SWAP1(module);
166  SYM_SWAP1(mode);
168 
169  #define SYM_SWAP2(x) std::swap(x, b.x)
170 
187 }
188 
192 {
193  return symbol_exprt(name, type);
194 }
The type of an expression.
Definition: type.h:20
irep_idt name
The unique identifier.
Definition: symbol.h:46
bool is_output
Definition: symbol.h:66
bool is_thread_local
Definition: symbol.h:70
void show(std::ostream &out) const
Definition: symbol.cpp:16
Symbol table entry.
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
Definition: irep.cpp:641
irep_idt mode
Language mode.
Definition: symbol.h:55
exprt value
Initial value of symbol.
Definition: symbol.h:40
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 table entry.This is a symbol in the symbol table, stored in an object of type symbol_tablet...
Definition: symbol.h:33
bool get_bool(const irep_namet &name) const
Definition: irep.cpp:240
bool is_static_lifetime
Definition: symbol.h:70
bool is_input
Definition: symbol.h:66
#define SYM_SWAP1(x)
class symbol_exprt symbol_expr() const
produces a symbol_exprt for a symbol
Definition: symbol.cpp:191
bool is_exported
Definition: symbol.h:66
bool is_parameter
Definition: symbol.h:71
API to expression classes.
const irep_idt & get(const irep_namet &name) const
Definition: irep.cpp:213
std::ostream & operator<<(std::ostream &out, const symbolt &symbol)
Definition: symbol.cpp:69
Base class for tree-like data structures with sharing.
Definition: irep.h:87
void swap(symbolt &b)
Definition: symbol.cpp:156
bool is_volatile
Definition: symbol.h:71
bool is_extern
Definition: symbol.h:71
typet type
Type of symbol.
Definition: symbol.h:37
source_locationt location
Source code location of definition of symbol.
Definition: symbol.h:43
Base class for all expressions.
Definition: expr.h:46
bool is_state_var
Definition: symbol.h:66
irep_idt base_name
Base (non-scoped) name.
Definition: symbol.h:52
#define SYM_SWAP2(x)
void clear()
Definition: irep.h:241
bool is_file_local
Definition: symbol.h:71
irept & add(const irep_namet &name)
Definition: irep.cpp:306
bool is_weak
Definition: symbol.h:71
void from_irep(const irept &src)
Definition: symbol.cpp:126
Expression to hold a symbol (variable)
Definition: std_expr.h:82
bool is_auxiliary
Definition: symbol.h:71
bool is_type
Definition: symbol.h:66
bool is_property
Definition: symbol.h:66
irept to_irep() const
Definition: symbol.cpp:76
bool empty() const
Definition: dstring.h:61
const irept & find(const irep_namet &name) const
Definition: irep.cpp:285
bool is_macro
Definition: symbol.h:66
void set(const irep_namet &name, const irep_idt &value)
Definition: irep.h:214
bool is_lvalue
Definition: symbol.h:71