-
Notifications
You must be signed in to change notification settings - Fork 288
Expand file tree
/
Copy pathsymbol.h
More file actions
191 lines (156 loc) · 4.26 KB
/
symbol.h
File metadata and controls
191 lines (156 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*******************************************************************\
Module:
Author: Daniel Kroening, kroening@kroening.com
\*******************************************************************/
#ifndef CPROVER_UTIL_SYMBOL_H
#define CPROVER_UTIL_SYMBOL_H
/// \file util/symbol.h
/// \brief Symbol table entry
/// \author Daniel Kroening <kroening@kroening.com>
/// \date Sun Jul 31 21:54:44 BST 2011
#include <iosfwd>
#include "expr.h"
#include "invariant.h"
/// \brief Symbol table entry.
/// \ingroup gr_symbol_table
/// This is a symbol in the symbol table, stored in an
/// object of type symbol_tablet.
class symbolt
{
public:
/// Type of symbol
typet type;
/// Initial value of symbol
exprt value;
/// Source code location of definition of symbol
source_locationt location;
/// The unique identifier
irep_idt name;
/// Name of module the symbol belongs to
irep_idt module;
/// Base (non-scoped) name
irep_idt base_name;
/// Language mode
irep_idt mode;
/// Language-specific display name
irep_idt pretty_name;
/// Return language specific display name if present.
const irep_idt &display_name() const
{
return pretty_name.empty()?name:pretty_name;
}
// global use
bool is_type = false;
bool is_macro = false;
bool is_exported = false;
bool is_input = false;
bool is_output = false;
bool is_state_var = false;
bool is_property = false;
// ANSI-C
bool is_static_lifetime = false;
bool is_thread_local = false;
bool is_lvalue = false;
bool is_file_local = false;
bool is_extern = false;
bool is_volatile = false;
bool is_parameter = false;
bool is_auxiliary = false;
bool is_weak = false;
symbolt()
: type(static_cast<const typet &>(get_nil_irep())),
value(static_cast<const exprt &>(get_nil_irep())),
location(source_locationt::nil())
{
}
symbolt(const irep_idt &_name, typet _type, const irep_idt &_mode)
: type(std::move(_type)),
value(static_cast<const exprt &>(get_nil_irep())),
location(source_locationt::nil()),
name(_name),
mode(_mode)
{
}
void swap(symbolt &b);
void show(std::ostream &out) const;
class symbol_exprt symbol_expr() const;
bool is_shared() const
{
return !is_thread_local;
}
bool is_function() const
{
return !is_type && !is_macro && type.id()==ID_code;
}
/// Returns true iff the the symbol's value has been compiled to a goto
/// program.
bool is_compiled() const
{
return type.id() == ID_code && value == exprt(ID_compiled);
}
/// Set the symbol's value to "compiled"; to be used once the code-typed value
/// has been converted to a goto program.
void set_compiled()
{
PRECONDITION(type.id() == ID_code);
value = exprt(ID_compiled);
}
/// Check that a symbol is well formed.
bool is_well_formed() const;
bool operator==(const symbolt &other) const;
bool operator!=(const symbolt &other) const;
};
std::ostream &operator<<(std::ostream &out, const symbolt &symbol);
/// \brief Symbol table entry describing a data type
/// \ingroup gr_symbol_table
/// This is a symbol generated as part of type checking.
class type_symbolt:public symbolt
{
public:
type_symbolt(const irep_idt &_name, typet _type, const irep_idt &_mode)
: symbolt(_name, _type, _mode)
{
is_type = true;
}
};
/// \brief Internally generated symbol table entry
/// \ingroup gr_symbol_table
/// This is a symbol generated as part of translation to or
/// modification of the intermediate representation.
class auxiliary_symbolt:public symbolt
{
public:
auxiliary_symbolt()
{
is_lvalue=true;
is_state_var=true;
is_thread_local=true;
is_file_local=true;
is_auxiliary=true;
}
auxiliary_symbolt(const irep_idt &name, typet type, const irep_idt &mode)
: symbolt(name, type, mode)
{
is_lvalue = true;
is_state_var = true;
is_thread_local = true;
is_file_local = true;
is_auxiliary = true;
}
};
/// \brief Symbol table entry of function parameter
/// \ingroup gr_symbol_table
/// This is a symbol generated as part of type checking.
class parameter_symbolt:public symbolt
{
public:
parameter_symbolt()
{
is_lvalue=true;
is_state_var=true;
is_thread_local=true;
is_file_local=true;
is_parameter=true;
}
};
#endif // CPROVER_UTIL_SYMBOL_H