Skip to content

Commit 9e0c3ed

Browse files
author
Owen
committed
Add some function comments
1 parent f104d38 commit 9e0c3ed

File tree

3 files changed

+80
-39
lines changed

3 files changed

+80
-39
lines changed

src/analyses/ai.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ void ai_baset::output(
6060
}
6161
}
6262

63-
/// Output the domains for the whole program as JSON
64-
/// \param ns: The namespace
65-
/// \param goto_functions: The goto functions
66-
/// \return The JSON object
6763
jsont ai_baset::output_json(
6864
const namespacet &ns,
6965
const goto_functionst &goto_functions) const
@@ -120,10 +116,6 @@ jsont ai_baset::output_json(
120116
return std::move(contents);
121117
}
122118

123-
/// Output the domains for the whole program as XML
124-
/// \param ns: The namespace
125-
/// \param goto_functions: The goto functions
126-
/// \return The XML object
127119
xmlt ai_baset::output_xml(
128120
const namespacet &ns,
129121
const goto_functionst &goto_functions) const

src/analyses/ai.h

Lines changed: 79 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ Author: Daniel Kroening, [email protected]
2727

2828
/// The basic interface of an abstract interpreter. This should be enough
2929
/// 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.
3232
class ai_baset
3333
{
3434
public:
@@ -43,7 +43,7 @@ class ai_baset
4343
{
4444
}
4545

46-
/// Running the interpreter
46+
/// Run abstract interpretation on a single function
4747
void operator()(
4848
const irep_idt &function_identifier,
4949
const goto_programt &goto_program,
@@ -56,6 +56,7 @@ class ai_baset
5656
finalize();
5757
}
5858

59+
/// Run abstract interpretation on a whole program
5960
void operator()(
6061
const goto_functionst &goto_functions,
6162
const namespacet &ns)
@@ -66,6 +67,7 @@ class ai_baset
6667
finalize();
6768
}
6869

70+
/// Run abstract interpretation on a whole program
6971
void operator()(const goto_modelt &goto_model)
7072
{
7173
const namespacet ns(goto_model.symbol_table);
@@ -75,6 +77,7 @@ class ai_baset
7577
finalize();
7678
}
7779

80+
/// Run abstract interpretation on a single function
7881
void operator()(
7982
const irep_idt &function_identifier,
8083
const goto_functionst::goto_functiont &goto_function,
@@ -87,17 +90,23 @@ class ai_baset
8790
finalize();
8891
}
8992

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.
9796
/// 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.
98101
virtual std::unique_ptr<statet> abstract_state_before(locationt l) const = 0;
99102

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.
101110
virtual std::unique_ptr<statet> abstract_state_after(locationt l) const
102111
{
103112
/// PRECONDITION(l is dereferenceable && std::next(l) is dereferenceable)
@@ -106,16 +115,18 @@ class ai_baset
106115
return abstract_state_before(std::next(l));
107116
}
108117

109-
/// Resets the domain
118+
/// Reset the domain
110119
virtual void clear()
111120
{
112121
}
113122

123+
/// Output the domains for a whole program
114124
virtual void output(
115125
const namespacet &ns,
116126
const goto_functionst &goto_functions,
117127
std::ostream &out) const;
118128

129+
/// Output the domains for a whole program
119130
void output(
120131
const goto_modelt &goto_model,
121132
std::ostream &out) const
@@ -124,6 +135,7 @@ class ai_baset
124135
output(ns, goto_model.goto_functions, out);
125136
}
126137

138+
/// Output the domains for a function
127139
void output(
128140
const namespacet &ns,
129141
const goto_programt &goto_program,
@@ -132,6 +144,7 @@ class ai_baset
132144
output(ns, goto_program, "", out);
133145
}
134146

147+
/// Output the domains for a function
135148
void output(
136149
const namespacet &ns,
137150
const goto_functionst::goto_functiont &goto_function,
@@ -140,51 +153,57 @@ class ai_baset
140153
output(ns, goto_function.body, "", out);
141154
}
142155

143-
156+
/// Output the domains for the whole program as JSON
144157
virtual jsont output_json(
145158
const namespacet &ns,
146159
const goto_functionst &goto_functions) const;
147160

161+
/// Output the domains for a whole program as JSON
148162
jsont output_json(
149163
const goto_modelt &goto_model) const
150164
{
151165
const namespacet ns(goto_model.symbol_table);
152166
return output_json(ns, goto_model.goto_functions);
153167
}
154168

169+
/// Output the domains for a single function as JSON
155170
jsont output_json(
156171
const namespacet &ns,
157172
const goto_programt &goto_program) const
158173
{
159174
return output_json(ns, goto_program, "");
160175
}
161176

177+
/// Output the domains for a single function as JSON
162178
jsont output_json(
163179
const namespacet &ns,
164180
const goto_functionst::goto_functiont &goto_function) const
165181
{
166182
return output_json(ns, goto_function.body, "");
167183
}
168184

169-
185+
/// Output the domains for the whole program as XML
170186
virtual xmlt output_xml(
171187
const namespacet &ns,
172188
const goto_functionst &goto_functions) const;
173189

190+
/// Output the domains for the whole program as XML
174191
xmlt output_xml(
175192
const goto_modelt &goto_model) const
176193
{
177194
const namespacet ns(goto_model.symbol_table);
178195
return output_xml(ns, goto_model.goto_functions);
179196
}
180197

198+
/// Output the domains for a single function as XML
181199
xmlt output_xml(
182200
const namespacet &ns,
183201
const goto_programt &goto_program) const
184202
{
185203
return output_xml(ns, goto_program, "");
186204
}
187205

206+
/// Output the domains for a single function as XML
188207
xmlt output_xml(
189208
const namespacet &ns,
190209
const goto_functionst::goto_functiont &goto_function) const
@@ -193,37 +212,65 @@ class ai_baset
193212
}
194213

195214
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);
200222

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
202228
virtual void finalize();
203229

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);
206235

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
207242
virtual void output(
208243
const namespacet &ns,
209244
const goto_programt &goto_program,
210245
const irep_idt &identifier,
211246
std::ostream &out) const;
212247

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
213254
virtual jsont output_json(
214255
const namespacet &ns,
215256
const goto_programt &goto_program,
216257
const irep_idt &identifier) const;
217258

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
218265
virtual xmlt output_xml(
219266
const namespacet &ns,
220267
const goto_programt &goto_program,
221268
const irep_idt &identifier) const;
222269

223-
224-
// the work-queue is sorted by location number
270+
/// The work queue, sorted by location number
225271
typedef std::map<unsigned, locationt> working_sett;
226272

273+
/// Get the next location from the work queue
227274
locationt get_next(working_sett &working_set);
228275

229276
void put_in_working_set(
@@ -234,7 +281,8 @@ class ai_baset
234281
std::pair<unsigned, locationt>(l->location_number, l));
235282
}
236283

237-
// true = found something new
284+
/// Run the fixedpoint algorithm until it reaches a fixed point
285+
/// \return True if we found something new
238286
bool fixedpoint(
239287
const irep_idt &function_identifier,
240288
const goto_programt &goto_program,
@@ -253,10 +301,10 @@ class ai_baset
253301
const goto_functionst &goto_functions,
254302
const namespacet &ns);
255303

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
260308
bool visit(
261309
const irep_idt &function_identifier,
262310
locationt l,
@@ -389,10 +437,11 @@ class ait:public ai_baset
389437
}
390438

391439
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
393442
void dummy(const domainT &s) { const statet &x=s; (void)x; }
394443

395-
// not implemented in sequential analyses
444+
/// This function should not be implemented in sequential analyses
396445
bool merge_shared(const statet &, locationt, locationt, const namespacet &)
397446
override
398447
{

src/analyses/ai_domain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class ai_domain_baset
7878
/// and domains may refuse to implement it.
7979
virtual void make_top() = 0;
8080

81-
/// a reasonable entry-point state
81+
/// Make this domain a reasonable entry-point state
8282
virtual void make_entry() = 0;
8383

8484
virtual bool is_bottom() const = 0;

0 commit comments

Comments
 (0)