27
27
28
28
// / The basic interface of an abstract interpreter. This should be enough
29
29
// / to create, run and query an abstract interpreter.
30
- // don't use me -- I am just a base class
31
- // use ait instead
30
+ // /
31
+ // / Note: this is just a base class. \ref ait should be used instead.
32
32
class ai_baset
33
33
{
34
34
public:
@@ -43,7 +43,7 @@ class ai_baset
43
43
{
44
44
}
45
45
46
- // / Running the interpreter
46
+ // / Run abstract interpretation on a single function
47
47
void operator ()(
48
48
const irep_idt &function_identifier,
49
49
const goto_programt &goto_program,
@@ -56,6 +56,7 @@ class ai_baset
56
56
finalize ();
57
57
}
58
58
59
+ // / Run abstract interpretation on a whole program
59
60
void operator ()(
60
61
const goto_functionst &goto_functions,
61
62
const namespacet &ns)
@@ -66,6 +67,7 @@ class ai_baset
66
67
finalize ();
67
68
}
68
69
70
+ // / Run abstract interpretation on a whole program
69
71
void operator ()(const goto_modelt &goto_model)
70
72
{
71
73
const namespacet ns (goto_model.symbol_table );
@@ -75,6 +77,7 @@ class ai_baset
75
77
finalize ();
76
78
}
77
79
80
+ // / Run abstract interpretation on a single function
78
81
void operator ()(
79
82
const irep_idt &function_identifier,
80
83
const goto_functionst::goto_functiont &goto_function,
@@ -87,17 +90,23 @@ class ai_baset
87
90
finalize ();
88
91
}
89
92
90
- // / Accessing individual domains at particular locations
91
- // / (without needing to know what kind of domain or history is used)
92
- // / A pointer to a copy as the method should be const and
93
- // / there are some non-trivial cases including merging domains, etc.
94
- // / Intended for users of the abstract interpreter; don't use internally.
95
-
96
- // / Returns the abstract state before the given instruction
93
+ // / Get the abstract state before the given instruction, without needing to
94
+ // / know what kind of domain or history is used. Note: intended for
95
+ // / users of the abstract interpreter; don't use internally.
97
96
// / PRECONDITION(l is dereferenceable)
97
+ // / \param l: The location we want the domain before
98
+ // / \return The domain before `l`. We return a pointer to a copy as the method
99
+ // / should be const and there are some non-trivial cases including merging
100
+ // / domains, etc.
98
101
virtual std::unique_ptr<statet> abstract_state_before (locationt l) const = 0;
99
102
100
- // / Returns the abstract state after the given instruction
103
+ // / Get the abstract state after the given instruction, without needing to
104
+ // / know what kind of domain or history is used. Note: intended for
105
+ // / users of the abstract interpreter; don't use internally.
106
+ // / \param l: The location we want the domain after
107
+ // / \return The domain after `l`. We return a pointer to a copy as the method
108
+ // / should be const and there are some non-trivial cases including merging
109
+ // / domains, etc.
101
110
virtual std::unique_ptr<statet> abstract_state_after (locationt l) const
102
111
{
103
112
// / PRECONDITION(l is dereferenceable && std::next(l) is dereferenceable)
@@ -106,16 +115,18 @@ class ai_baset
106
115
return abstract_state_before (std::next (l));
107
116
}
108
117
109
- // / Resets the domain
118
+ // / Reset the domain
110
119
virtual void clear ()
111
120
{
112
121
}
113
122
123
+ // / Output the domains for a whole program
114
124
virtual void output (
115
125
const namespacet &ns,
116
126
const goto_functionst &goto_functions,
117
127
std::ostream &out) const ;
118
128
129
+ // / Output the domains for a whole program
119
130
void output (
120
131
const goto_modelt &goto_model,
121
132
std::ostream &out) const
@@ -124,6 +135,7 @@ class ai_baset
124
135
output (ns, goto_model.goto_functions , out);
125
136
}
126
137
138
+ // / Output the domains for a function
127
139
void output (
128
140
const namespacet &ns,
129
141
const goto_programt &goto_program,
@@ -132,6 +144,7 @@ class ai_baset
132
144
output (ns, goto_program, " " , out);
133
145
}
134
146
147
+ // / Output the domains for a function
135
148
void output (
136
149
const namespacet &ns,
137
150
const goto_functionst::goto_functiont &goto_function,
@@ -140,51 +153,57 @@ class ai_baset
140
153
output (ns, goto_function.body , " " , out);
141
154
}
142
155
143
-
156
+ // / Output the domains for the whole program as JSON
144
157
virtual jsont output_json (
145
158
const namespacet &ns,
146
159
const goto_functionst &goto_functions) const ;
147
160
161
+ // / Output the domains for a whole program as JSON
148
162
jsont output_json (
149
163
const goto_modelt &goto_model) const
150
164
{
151
165
const namespacet ns (goto_model.symbol_table );
152
166
return output_json (ns, goto_model.goto_functions );
153
167
}
154
168
169
+ // / Output the domains for a single function as JSON
155
170
jsont output_json (
156
171
const namespacet &ns,
157
172
const goto_programt &goto_program) const
158
173
{
159
174
return output_json (ns, goto_program, " " );
160
175
}
161
176
177
+ // / Output the domains for a single function as JSON
162
178
jsont output_json (
163
179
const namespacet &ns,
164
180
const goto_functionst::goto_functiont &goto_function) const
165
181
{
166
182
return output_json (ns, goto_function.body , " " );
167
183
}
168
184
169
-
185
+ // / Output the domains for the whole program as XML
170
186
virtual xmlt output_xml (
171
187
const namespacet &ns,
172
188
const goto_functionst &goto_functions) const ;
173
189
190
+ // / Output the domains for the whole program as XML
174
191
xmlt output_xml (
175
192
const goto_modelt &goto_model) const
176
193
{
177
194
const namespacet ns (goto_model.symbol_table );
178
195
return output_xml (ns, goto_model.goto_functions );
179
196
}
180
197
198
+ // / Output the domains for a single function as XML
181
199
xmlt output_xml (
182
200
const namespacet &ns,
183
201
const goto_programt &goto_program) const
184
202
{
185
203
return output_xml (ns, goto_program, " " );
186
204
}
187
205
206
+ // / Output the domains for a single function as XML
188
207
xmlt output_xml (
189
208
const namespacet &ns,
190
209
const goto_functionst::goto_functiont &goto_function) const
@@ -193,37 +212,65 @@ class ai_baset
193
212
}
194
213
195
214
protected:
196
- // overload to add a factory
197
- virtual void initialize (const goto_programt &);
198
- virtual void initialize (const goto_functionst::goto_functiont &);
199
- virtual void initialize (const goto_functionst &);
215
+ // / Initialize all the domains for a single function. Overloaded this to add a
216
+ // / factory.
217
+ virtual void initialize (const goto_programt &goto_program);
218
+
219
+ // / Initialize all the domains for a single function. Overloaded this to add a
220
+ // / factory.
221
+ virtual void initialize (const goto_functionst::goto_functiont &goto_function);
200
222
201
- // override to add a cleanup step after fixedpoint has run
223
+ // / Initialize all the domains for a whole program. Overloaded this to add a
224
+ // / factory.
225
+ virtual void initialize (const goto_functionst &goto_functions);
226
+
227
+ // / Override this to add a cleanup step after fixedpoint has run
202
228
virtual void finalize ();
203
229
204
- void entry_state (const goto_programt &);
205
- void entry_state (const goto_functionst &);
230
+ // / Ensure the entry point to a single function has a reasonable state
231
+ void entry_state (const goto_programt &goto_functions);
232
+
233
+ // / Ensure the entry point to a whole program has a reasonable state
234
+ void entry_state (const goto_functionst &goto_program);
206
235
236
+ // / Output the domains for a single function
237
+ // / \param ns: The namespace
238
+ // / \param goto_program: The goto program
239
+ // / \param identifier: the identifier used to find a symbol to identify the
240
+ // / source language
241
+ // / \param out: The ostream to direct output to
207
242
virtual void output (
208
243
const namespacet &ns,
209
244
const goto_programt &goto_program,
210
245
const irep_idt &identifier,
211
246
std::ostream &out) const ;
212
247
248
+ // / Output the domains for a single function as JSON
249
+ // / \param ns: The namespace
250
+ // / \param goto_program: The goto program
251
+ // / \param identifier: the identifier used to find a symbol to identify the
252
+ // / source language
253
+ // / \return The JSON object
213
254
virtual jsont output_json (
214
255
const namespacet &ns,
215
256
const goto_programt &goto_program,
216
257
const irep_idt &identifier) const ;
217
258
259
+ // / Output the domains for a single function as XML
260
+ // / \param ns: The namespace
261
+ // / \param goto_program: The goto program
262
+ // / \param identifier: the identifier used to find a symbol to identify the
263
+ // / source language
264
+ // / \return The XML object
218
265
virtual xmlt output_xml (
219
266
const namespacet &ns,
220
267
const goto_programt &goto_program,
221
268
const irep_idt &identifier) const ;
222
269
223
-
224
- // the work-queue is sorted by location number
270
+ // / The work queue, sorted by location number
225
271
typedef std::map<unsigned , locationt> working_sett;
226
272
273
+ // / Get the next location from the work queue
227
274
locationt get_next (working_sett &working_set);
228
275
229
276
void put_in_working_set (
@@ -234,7 +281,8 @@ class ai_baset
234
281
std::pair<unsigned , locationt>(l->location_number , l));
235
282
}
236
283
237
- // true = found something new
284
+ // / Run the fixedpoint algorithm until it reaches a fixed point
285
+ // / \return True if we found something new
238
286
bool fixedpoint (
239
287
const irep_idt &function_identifier,
240
288
const goto_programt &goto_program,
@@ -253,10 +301,10 @@ class ai_baset
253
301
const goto_functionst &goto_functions,
254
302
const namespacet &ns);
255
303
256
- // Visit performs one step of abstract interpretation from location l
257
- // Depending on the instruction type it may compute a number of "edges"
258
- // or applications of the abstract transformer
259
- // true = found something new
304
+ // / Perform one step of abstract interpretation from location l
305
+ // / Depending on the instruction type it may compute a number of "edges"
306
+ // / or applications of the abstract transformer
307
+ // / \return True if the state was changed
260
308
bool visit (
261
309
const irep_idt &function_identifier,
262
310
locationt l,
@@ -389,10 +437,11 @@ class ait:public ai_baset
389
437
}
390
438
391
439
private:
392
- // to enforce that domainT is derived from ai_domain_baset
440
+ // / This function exists to enforce that `domainT` is derived from
441
+ // / \ref ai_domain_baset
393
442
void dummy (const domainT &s) { const statet &x=s; (void )x; }
394
443
395
- // not implemented in sequential analyses
444
+ // / This function should not be implemented in sequential analyses
396
445
bool merge_shared (const statet &, locationt, locationt, const namespacet &)
397
446
override
398
447
{
0 commit comments