Skip to content

Commit def20b5

Browse files
author
Sonny Martin
committed
Initial additional information about the invariant macros and hierarchy
1 parent 3469b19 commit def20b5

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/util/invariant.h

+14-2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ Author: Martin Brain, [email protected]
8282
/// family of macros, allowing constructs like
8383
/// `INVARIANT(x==y, my_invariantt, (T1)actual1, (T2)actual2, ...)`
8484
///
85+
/// \ref invariant_failedt is also the base class of any 'structured
86+
/// exceptions' - as found in file \ref base_exceptions.h
87+
///
8588
class invariant_failedt
8689
{
8790
private:
@@ -196,6 +199,9 @@ std::string get_backtrace();
196199

197200
void report_exception_to_stderr(const invariant_failedt &);
198201

202+
/// This function is the backbone of all the invariant types. Every instance of an
203+
/// invariant is ultimately generated by this function template, which is at times called
204+
/// via a wrapper function.
199205
/// Takes a backtrace, gives it to the reason structure, then aborts, printing
200206
/// reason.what() (which therefore includes the backtrace).
201207
/// In future this may throw `reason` instead of aborting.
@@ -230,8 +236,9 @@ CBMC_NORETURN
230236
abort();
231237
}
232238

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.
235242
/// In future this may throw rather than aborting.
236243
/// \param file : C string giving the name of the file.
237244
/// \param function : C string giving the name of the function.
@@ -342,6 +349,8 @@ std::string assemble_diagnostics(Diagnostics &&... args)
342349
}
343350
} // namespace detail
344351

352+
353+
/// This is a wrapper function, used by the macro 'INVARIANT_WITH_DIAGNOSTICS'
345354
template <typename... Diagnostics>
346355
CBMC_NORETURN void report_invariant_failure(
347356
const std::string &file,
@@ -387,6 +396,8 @@ CBMC_NORETURN void report_invariant_failure(
387396

388397
// Short hand macros. The variants *_STRUCTURED below allow to specify a custom
389398
// exception, and are equivalent to INVARIANT_STRUCTURED.
399+
400+
/// This macro uses the wrapper function 'invariant_violated_string'.
390401
#define INVARIANT(CONDITION, REASON) \
391402
do \
392403
{ \
@@ -400,6 +411,7 @@ CBMC_NORETURN void report_invariant_failure(
400411
/// Same as invariant, with one or more diagnostics attached
401412
/// Diagnostics can be of any type that has a specialisation for
402413
/// invariant_helpert
414+
/// This macro uses the wrapper function 'report_invariant_failure'.
403415
#define INVARIANT_WITH_DIAGNOSTICS(CONDITION, REASON, ...) \
404416
do \
405417
{ \

0 commit comments

Comments
 (0)