@@ -82,6 +82,9 @@ Author: Martin Brain, martin.brain@diffblue.com
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+ // /
8588class invariant_failedt
8689{
8790 private:
@@ -196,6 +199,9 @@ std::string get_backtrace();
196199
197200void report_exception_to_stderr (const invariant_failedt &);
198201
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.
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,7 @@ std::string assemble_diagnostics(Diagnostics &&... args)
342349}
343350} // namespace detail
344351
352+ // / This is a wrapper function, used by the macro 'INVARIANT_WITH_DIAGNOSTICS'
345353template <typename ... Diagnostics>
346354CBMC_NORETURN void report_invariant_failure (
347355 const std::string &file,
@@ -387,6 +395,8 @@ CBMC_NORETURN void report_invariant_failure(
387395
388396// Short hand macros. The variants *_STRUCTURED below allow to specify a custom
389397// exception, and are equivalent to INVARIANT_STRUCTURED.
398+
399+ // / This macro uses the wrapper function 'invariant_violated_string'.
390400#define INVARIANT (CONDITION, REASON ) \
391401 do \
392402 { \
@@ -400,6 +410,7 @@ CBMC_NORETURN void report_invariant_failure(
400410// / Same as invariant, with one or more diagnostics attached
401411// / Diagnostics can be of any type that has a specialisation for
402412// / invariant_helpert
413+ // / This macro uses the wrapper function 'report_invariant_failure'.
403414#define INVARIANT_WITH_DIAGNOSTICS (CONDITION, REASON, ...) \
404415 do \
405416 { \
0 commit comments