82
82
// / family of macros, allowing constructs like
83
83
// / `INVARIANT(x==y, my_invariantt, (T1)actual1, (T2)actual2, ...)`
84
84
// /
85
+ // / \ref invariant_failedt is also the base class of any 'structured
86
+ // / exceptions' - as found in file \ref base_exceptions.h
87
+ // /
85
88
class invariant_failedt
86
89
{
87
90
private:
@@ -196,6 +199,9 @@ std::string get_backtrace();
196
199
197
200
void report_exception_to_stderr (const invariant_failedt &);
198
201
202
+ // / This function is the backbone of all the invariant types.
203
+ // / Every instance of an invariant is ultimately generated by this
204
+ // / function template, which is at times called via a wrapper function.
199
205
// / Takes a backtrace, gives it to the reason structure, then aborts, printing
200
206
// / reason.what() (which therefore includes the backtrace).
201
207
// / In future this may throw `reason` instead of aborting.
@@ -230,8 +236,9 @@ CBMC_NORETURN
230
236
abort ();
231
237
}
232
238
233
- // / Takes a backtrace, constructs an invariant_violatedt from reason and the
234
- // / backtrace, aborts printing the invariant's description.
239
+ // / This is a wrapper function used by the macro 'INVARIANT(CONDITION, REASON)'.
240
+ // / It constructs an invariant_violatedt from reason and the
241
+ // / backtrace, then aborts after printing the invariant's description.
235
242
// / In future this may throw rather than aborting.
236
243
// / \param file : C string giving the name of the file.
237
244
// / \param function : C string giving the name of the function.
@@ -342,6 +349,7 @@ std::string assemble_diagnostics(Diagnostics &&... args)
342
349
}
343
350
} // namespace detail
344
351
352
+ // / This is a wrapper function, used by the macro 'INVARIANT_WITH_DIAGNOSTICS'
345
353
template <typename ... Diagnostics>
346
354
CBMC_NORETURN void report_invariant_failure (
347
355
const std::string &file,
@@ -387,6 +395,8 @@ CBMC_NORETURN void report_invariant_failure(
387
395
388
396
// Short hand macros. The variants *_STRUCTURED below allow to specify a custom
389
397
// exception, and are equivalent to INVARIANT_STRUCTURED.
398
+
399
+ // / This macro uses the wrapper function 'invariant_violated_string'.
390
400
#define INVARIANT (CONDITION, REASON ) \
391
401
do \
392
402
{ \
@@ -400,6 +410,7 @@ CBMC_NORETURN void report_invariant_failure(
400
410
// / Same as invariant, with one or more diagnostics attached
401
411
// / Diagnostics can be of any type that has a specialisation for
402
412
// / invariant_helpert
413
+ // / This macro uses the wrapper function 'report_invariant_failure'.
403
414
#define INVARIANT_WITH_DIAGNOSTICS (CONDITION, REASON, ...) \
404
415
do \
405
416
{ \
0 commit comments