25
25
26
26
#include " ai_domain.h"
27
27
28
- // / The basic interface of an abstract interpreter. This should be enough
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,27 @@ 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 a copy of the abstract state before the given instruction, without
94
+ // / needing to know what kind of domain or history is used. Note: intended
95
+ // / for users of the abstract interpreter; derived classes should
96
+ // / use \ref get_state or \ref find_state to access the actual underlying
97
+ // / state.
97
98
// / PRECONDITION(l is dereferenceable)
99
+ // / \param l: The location before which we want the abstract state
100
+ // / \return The abstract state before `l`. We return a pointer to a copy as
101
+ // / the method should be const and there are some non-trivial cases
102
+ // / including merging abstract states, etc.
98
103
virtual std::unique_ptr<statet> abstract_state_before (locationt l) const = 0;
99
104
100
- // / Returns the abstract state after the given instruction
105
+ // / Get a copy of the abstract state after the given instruction, without
106
+ // / needing to know what kind of domain or history is used. Note: intended
107
+ // / for users of the abstract interpreter; derived classes should
108
+ // / use \ref get_state or \ref find_state to access the actual underlying
109
+ // / state.
110
+ // / \param l: The location before which we want the abstract state
111
+ // / \return The abstract state after `l`. We return a pointer to a copy as
112
+ // / the method should be const and there are some non-trivial cases
113
+ // / including merging abstract states, etc.
101
114
virtual std::unique_ptr<statet> abstract_state_after (locationt l) const
102
115
{
103
116
// / PRECONDITION(l is dereferenceable && std::next(l) is dereferenceable)
@@ -106,16 +119,18 @@ class ai_baset
106
119
return abstract_state_before (std::next (l));
107
120
}
108
121
109
- // / Resets the domain
122
+ // / Reset the abstract state
110
123
virtual void clear ()
111
124
{
112
125
}
113
126
127
+ // / Output the abstract states for a whole program
114
128
virtual void output (
115
129
const namespacet &ns,
116
130
const goto_functionst &goto_functions,
117
131
std::ostream &out) const ;
118
132
133
+ // / Output the abstract states for a whole program
119
134
void output (
120
135
const goto_modelt &goto_model,
121
136
std::ostream &out) const
@@ -124,6 +139,7 @@ class ai_baset
124
139
output (ns, goto_model.goto_functions , out);
125
140
}
126
141
142
+ // / Output the abstract states for a function
127
143
void output (
128
144
const namespacet &ns,
129
145
const goto_programt &goto_program,
@@ -132,6 +148,7 @@ class ai_baset
132
148
output (ns, goto_program, " " , out);
133
149
}
134
150
151
+ // / Output the abstract states for a function
135
152
void output (
136
153
const namespacet &ns,
137
154
const goto_functionst::goto_functiont &goto_function,
@@ -140,51 +157,57 @@ class ai_baset
140
157
output (ns, goto_function.body , " " , out);
141
158
}
142
159
143
-
160
+ // / Output the abstract states for the whole program as JSON
144
161
virtual jsont output_json (
145
162
const namespacet &ns,
146
163
const goto_functionst &goto_functions) const ;
147
164
165
+ // / Output the abstract states for a whole program as JSON
148
166
jsont output_json (
149
167
const goto_modelt &goto_model) const
150
168
{
151
169
const namespacet ns (goto_model.symbol_table );
152
170
return output_json (ns, goto_model.goto_functions );
153
171
}
154
172
173
+ // / Output the abstract states for a single function as JSON
155
174
jsont output_json (
156
175
const namespacet &ns,
157
176
const goto_programt &goto_program) const
158
177
{
159
178
return output_json (ns, goto_program, " " );
160
179
}
161
180
181
+ // / Output the abstract states for a single function as JSON
162
182
jsont output_json (
163
183
const namespacet &ns,
164
184
const goto_functionst::goto_functiont &goto_function) const
165
185
{
166
186
return output_json (ns, goto_function.body , " " );
167
187
}
168
188
169
-
189
+ // / Output the abstract states for the whole program as XML
170
190
virtual xmlt output_xml (
171
191
const namespacet &ns,
172
192
const goto_functionst &goto_functions) const ;
173
193
194
+ // / Output the abstract states for the whole program as XML
174
195
xmlt output_xml (
175
196
const goto_modelt &goto_model) const
176
197
{
177
198
const namespacet ns (goto_model.symbol_table );
178
199
return output_xml (ns, goto_model.goto_functions );
179
200
}
180
201
202
+ // / Output the abstract states for a single function as XML
181
203
xmlt output_xml (
182
204
const namespacet &ns,
183
205
const goto_programt &goto_program) const
184
206
{
185
207
return output_xml (ns, goto_program, " " );
186
208
}
187
209
210
+ // / Output the abstract states for a single function as XML
188
211
xmlt output_xml (
189
212
const namespacet &ns,
190
213
const goto_functionst::goto_functiont &goto_function) const
@@ -193,37 +216,67 @@ class ai_baset
193
216
}
194
217
195
218
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 &);
219
+ // / Initialize all the abstract states for a single function. Override this to
220
+ // / do custom per-domain initialization.
221
+ virtual void initialize (const goto_programt &goto_program);
222
+
223
+ // / Initialize all the abstract states for a single function.
224
+ virtual void initialize (const goto_functionst::goto_functiont &goto_function);
225
+
226
+ // / Initialize all the abstract states for a whole program. Override this to
227
+ // / do custom per-analysis initialization.
228
+ virtual void initialize (const goto_functionst &goto_functions);
200
229
201
- // override to add a cleanup step after fixedpoint has run
230
+ // / Override this to add a cleanup or post-processing step after fixedpoint
231
+ // / has run
202
232
virtual void finalize ();
203
233
204
- void entry_state (const goto_programt &);
205
- void entry_state (const goto_functionst &);
234
+ // / Set the abstract state of the entry location of a single function to the
235
+ // / entry state required by the analysis
236
+ void entry_state (const goto_programt &goto_program);
206
237
238
+ // / Set the abstract state of the entry location of a whole program to the
239
+ // / entry state required by the analysis
240
+ void entry_state (const goto_functionst &goto_functions);
241
+
242
+ // / Output the abstract states for a single function
243
+ // / \param ns: The namespace
244
+ // / \param goto_program: The goto program
245
+ // / \param identifier: The identifier used to find a symbol to identify the
246
+ // / source language
247
+ // / \param out: The ostream to direct output to
207
248
virtual void output (
208
249
const namespacet &ns,
209
250
const goto_programt &goto_program,
210
251
const irep_idt &identifier,
211
252
std::ostream &out) const ;
212
253
254
+ // / Output the abstract states for a single function as JSON
255
+ // / \param ns: The namespace
256
+ // / \param goto_program: The goto program
257
+ // / \param identifier: The identifier used to find a symbol to identify the
258
+ // / source language
259
+ // / \return The JSON object
213
260
virtual jsont output_json (
214
261
const namespacet &ns,
215
262
const goto_programt &goto_program,
216
263
const irep_idt &identifier) const ;
217
264
265
+ // / Output the abstract states for a single function as XML
266
+ // / \param ns: The namespace
267
+ // / \param goto_program: The goto program
268
+ // / \param identifier: The identifier used to find a symbol to identify the
269
+ // / source language
270
+ // / \return The XML object
218
271
virtual xmlt output_xml (
219
272
const namespacet &ns,
220
273
const goto_programt &goto_program,
221
274
const irep_idt &identifier) const ;
222
275
223
-
224
- // the work-queue is sorted by location number
276
+ // / The work queue, sorted by location number
225
277
typedef std::map<unsigned , locationt> working_sett;
226
278
279
+ // / Get the next location from the work queue
227
280
locationt get_next (working_sett &working_set);
228
281
229
282
void put_in_working_set (
@@ -234,7 +287,8 @@ class ai_baset
234
287
std::pair<unsigned , locationt>(l->location_number , l));
235
288
}
236
289
237
- // true = found something new
290
+ // / Run the fixedpoint algorithm until it reaches a fixed point
291
+ // / \return True if we found something new
238
292
bool fixedpoint (
239
293
const irep_idt &function_identifier,
240
294
const goto_programt &goto_program,
@@ -253,10 +307,10 @@ class ai_baset
253
307
const goto_functionst &goto_functions,
254
308
const namespacet &ns);
255
309
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
310
+ // / Perform one step of abstract interpretation from location l
311
+ // / Depending on the instruction type it may compute a number of "edges"
312
+ // / or applications of the abstract transformer
313
+ // / \return True if the state was changed
260
314
bool visit (
261
315
const irep_idt &function_identifier,
262
316
locationt l,
@@ -293,8 +347,16 @@ class ai_baset
293
347
locationt from,
294
348
locationt to,
295
349
const namespacet &ns)=0;
350
+
351
+ // / Get the state for the given location, creating it in a default way if it
352
+ // / doesn't exist
296
353
virtual statet &get_state (locationt l)=0;
354
+
355
+ // / Get the state for the given location if it already exists; throw an
356
+ // / exception if it doesn't
297
357
virtual const statet &find_state (locationt l) const =0;
358
+
359
+ // / Make a copy of a state
298
360
virtual std::unique_ptr<statet> make_temporary_state (const statet &s)=0;
299
361
};
300
362
@@ -389,10 +451,11 @@ class ait:public ai_baset
389
451
}
390
452
391
453
private:
392
- // to enforce that domainT is derived from ai_domain_baset
454
+ // / This function exists to enforce that `domainT` is derived from
455
+ // / \ref ai_domain_baset
393
456
void dummy (const domainT &s) { const statet &x=s; (void )x; }
394
457
395
- // not implemented in sequential analyses
458
+ // / This function should not be implemented in sequential analyses
396
459
bool merge_shared (const statet &, locationt, locationt, const namespacet &)
397
460
override
398
461
{
0 commit comments