@@ -101,19 +101,90 @@ 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 \typet). For function or method symbols
110
+ 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 exactly two symbol tables, in which case any lookup operation checks
138
+ the 'top' symbol table before looking in the 'bottom' symbol table if nothing
139
+ is found in the top. The namespace wrapper class also provides the
140
+ \ref namespacet::follow operation, which dereferences a ` symbol_typet ` to
141
+ retrieve the type it refers to, including following a symbol_typet which refers
142
+ to another symbol which eventually refers to a 'real' type.
143
+
144
+ \subsubsection symbolt_lifetime Symbol lifetimes
145
+
146
+ Symbols with \ref symbolt::is_static_lifetime set are global variables; they
147
+ are initialised before a program's entry-point is called and live until it ends.
148
+ They may be marked dead using a \ref code_deadt instruction, but this does not
149
+ render the variable inaccessible, it only indicates that the variable's current
150
+ value will not be read without an intervening write.
151
+
152
+ Symbols with function type (those whose type is a \ref code_typet
153
+ Non-type, non-global symbols (those with \ref symbolt::is_static_lifetime and
154
+ \ref symbolt::is_type not set) are local variables, and their lifespan
155
+ description varies depending on context.
156
+
157
+ In symbol table function definitions (the values of function-typed symbols),
158
+ local variables are created using a \ref code_declt instruction, and live until
159
+ their enclosing \ref code_blockt ends (similar to the C idiom
160
+ ` { int x; ... } // x lifespan ends ` ). By contrast in GOTO programs locals are
161
+ declared using a DECL instruction and live until a DEAD instruction referring
162
+ to the same symbol. Explicit DEAD instructions are always used rather than
163
+ killing implicitly by exiting a function.
164
+
165
+ Multiple instances of the same local may be live at the same time by virtue of
166
+ recursive function calls; a dead instruction or scope end always targets the
167
+ most recently allocated instance.
168
+
169
+ Scoping rules are particular to source languages and are not enforced by
170
+ CPROVER. For example, in standard C it is not possible to refer to a local
171
+ variable across functions without using a pointer, but in some possible source
172
+ languages this is permitted.
173
+
174
+ \subsubsection symbolt_details symbol modes, name, base-name, pretty-name
175
+
176
+ Symbols have:
177
+ * A mode, which indicates the source language frontend responsible for creating
178
+ them. This is mainly used in pretty-printing the symbol table, to indicate
179
+ the appropriate language frontend to use rendering the symbol's value and/or
180
+ type.
181
+ * A base-name and pretty-name, which are a short and user-friendly version of
182
+ the symbol's definitive name respectively.
183
+ * Several flags (see \ref symbolt for full details), including
184
+ \ref symbolt::is_static_lifetime (is this a global variable symbol?),
185
+ \ref symbolt::is_type (is this a type definition),
186
+ \ref symbolt::is_thread_local (of a variable, are there implicitly instances
187
+ of this variable per-thread?).
117
188
118
189
\subsection cmdlinet
119
190
0 commit comments