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  #define SYM_SWAP1(x) x.swap(b.x)
79 
80  SYM_SWAP1(type);
82  SYM_SWAP1(name);
86  SYM_SWAP1(mode);
88 
89  #define SYM_SWAP2(x) std::swap(x, b.x)
90 
107 }
108 
112 {
113  return symbol_exprt(name, type);
114 }
irep_idt name
The unique identifier.
Definition: symbol.h:43
bool is_output
Definition: symbol.h:63
bool is_thread_local
Definition: symbol.h:67
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:52
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 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
#define SYM_SWAP1(x)
class symbol_exprt symbol_expr() const
produces a symbol_exprt for a symbol
Definition: symbol.cpp:111
bool is_exported
Definition: symbol.h:63
bool is_parameter
Definition: symbol.h:68
API to expression classes.
std::ostream & operator<<(std::ostream &out, const symbolt &symbol)
Definition: symbol.cpp:69
void swap(symbolt &b)
Definition: symbol.cpp:76
bool is_volatile
Definition: symbol.h:68
bool is_extern
Definition: symbol.h:68
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
#define SYM_SWAP2(x)
bool is_file_local
Definition: symbol.h:68
bool is_weak
Definition: symbol.h:68
Expression to hold a symbol (variable)
Definition: std_expr.h:90
bool is_auxiliary
Definition: symbol.h:68
bool is_type
Definition: symbol.h:63
bool is_property
Definition: symbol.h:63
bool empty() const
Definition: dstring.h:73
bool is_macro
Definition: symbol.h:63
bool is_lvalue
Definition: symbol.h:68