@@ -101,19 +101,98 @@ of a while loop is a statement.
101
101
102
102
\subsection symbolt_section symbolt, symbol_tablet, and namespacet
103
103
104
- To be documented.
105
-
106
- \subsubsection symbol_lifetimes_section Symbol lifetimes, symbol modes, name, base-name, pretty-name; semantic of lifetimes for symex?
107
-
108
- To be documented.
109
-
110
- \subsubsection storing_symbols_section Storing symbols and hiding symbols (namespacet)
111
-
112
- To be documented.
113
-
114
- \subsubsection ns_follow_section ns.follow
115
-
116
- To be documented.
104
+ A symbol table is a mapping from symbol names to \ref symbolt objects, which
105
+ store a symbol's name, attributes, type and perhaps value. They are used to
106
+ describe local and global variables, type definitions and function prototypes
107
+ and definitions.
108
+
109
+ All symbols store a type (an instance of \ref typet). For function or method
110
+ symbols these are \ref code_typet instances.
111
+
112
+ Global variable symbols may have a value (an \ref exprt), in which case it is
113
+ used to initialise the global. Method or function symbols may also have a value,
114
+ in which case it is a \ref codet and gives the function definition. A method or
115
+ function symbol without a value is a prototype (for example, it might be an
116
+ ` extern ` declaration in C). Local variables' symbol values are always ignored;
117
+ any initialiser must be explicitly assigned after they are instantiated by a
118
+ declaration (\ref code_declt).
119
+
120
+ Symbol expressions (\ref symbol_exprt) and types (\ref symbol_typet) refer to
121
+ symbols stored in a symbol table. Symbol expressions can be thought of as
122
+ referring to the table for more detail about a symbol (for example, is it a
123
+ local or a global variable, or perhaps a function?), and have a type which must
124
+ match the type given in the symbol table. Symbol types can be thought of as
125
+ shorthands or aliases for a type given in more detail in the symbol table, for
126
+ example permitting a shorthand for a large structure type, as well as permitting
127
+ the construction of expressions referring to that type before its full
128
+ definition is known.
129
+
130
+ Note the implementation of \ref symbol_tablet is split into a base interface
131
+ (\ref symbol_table_baset) and an implementation (\ref symbol_tablet). There is
132
+ one alternate implementation (\ref journalling_symbol_tablet) which additionally
133
+ maintains a log or journal of symbol creation, modification and deletions.
134
+
135
+ Namespaces (\ref namespacet) provide a read-only view on one or more symbol
136
+ tables, and provide helper functions that aid accessing the table. A namespace
137
+ may layer one or more symbol tables, in which case any lookup operation checks
138
+ the 'top' symbol table before moving down the layers towards the 'bottom' symbol
139
+ table, looking up the target symbol name in each successive table until one is
140
+ found. Note class \ref multi_namespacet can layer arbitrary numbers of symbol
141
+ tables, while for historical reasons \ref namespacet can layer up to two.
142
+
143
+ The namespace wrapper class also provides the \ref namespacet::follow
144
+ operation, which dereferences a ` symbol_typet ` to retrieve the type it refers
145
+ to, including following a symbol_typet which refers to another symbol which
146
+ eventually refers to a 'real' type.
147
+
148
+ \subsubsection symbolt_lifetime Symbol lifetimes
149
+
150
+ Symbols with \ref symbolt::is_static_lifetime set are initialised before a
151
+ program's entry-point is called and live until it ends. Such long-lived
152
+ variables are used to implement globals, but also C's procedure-local static
153
+ variables, which have restricted visiblity but the lifetime of a global.
154
+ They may be marked dead using a \ref code_deadt instruction, but this does not
155
+ render the variable inaccessible, it only indicates that the variable's current
156
+ value will not be read without an intervening write.
157
+
158
+ Symbols with function type (those whose type is a \ref code_typet
159
+ Non-type, non-global symbols (those with \ref symbolt::is_static_lifetime and
160
+ \ref symbolt::is_type not set) are local variables, and their lifespan
161
+ description varies depending on context.
162
+
163
+ In symbol table function definitions (the values of function-typed symbols),
164
+ local variables are created using a \ref code_declt instruction, and live until
165
+ their enclosing \ref code_blockt ends (similar to the C idiom
166
+ ` { int x; ... } // x lifespan ends ` ). By contrast in GOTO programs locals are
167
+ declared using a DECL instruction and live until a DEAD instruction referring
168
+ to the same symbol. Explicit DEAD instructions are always used rather than
169
+ killing implicitly by exiting a function.
170
+
171
+ Multiple instances of the same local may be live at the same time by virtue of
172
+ recursive function calls; a dead instruction or scope end always targets the
173
+ most recently allocated instance.
174
+
175
+ Scoping rules are particular to source languages and are not enforced by
176
+ CPROVER. For example, in standard C it is not possible to refer to a local
177
+ variable across functions without using a pointer, but in some possible source
178
+ languages this is permitted.
179
+
180
+ \subsubsection symbolt_details Symbol details
181
+
182
+ Symbols have:
183
+ * A mode, which indicates the source language frontend responsible for creating
184
+ them. This is mainly used in pretty-printing the symbol table, to indicate
185
+ the appropriate language frontend to use rendering the symbol's value and/or
186
+ type. For example, mode == ID_C == "C" indicates that \ref ansi_ct, the C
187
+ front-end, should be used to pretty-print, which in turn delegates to
188
+ \ref expr2ct.
189
+ * A base-name and pretty-name, which are a short and user-friendly version of
190
+ the symbol's definitive name respectively.
191
+ * Several flags (see \ref symbolt for full details), including
192
+ \ref symbolt::is_static_lifetime (is this a global variable symbol?),
193
+ \ref symbolt::is_type (is this a type definition),
194
+ \ref symbolt::is_thread_local (of a variable, are there implicitly instances
195
+ of this variable per-thread?).
117
196
118
197
\subsection cmdlinet
119
198
0 commit comments