@@ -225,15 +225,26 @@ inline void invariant_violated_string(
225
225
// for INVARIANT.
226
226
227
227
// The condition should only contain (unmodified) arguments to the method.
228
+ // Inputs include arguments passed to the function, as well as member
229
+ // variables that the function may read.
228
230
// "The design of the system means that the arguments to this method
229
231
// will always meet this condition".
232
+ //
233
+ // It is also supposed to signal that even though an object is in a
234
+ // valid state, a particular function may not be operating on objects
235
+ // with the particular properties this one has.
230
236
#define PRECONDITION (CONDITION ) INVARIANT(CONDITION, " Precondition" )
231
237
#define PRECONDITION_STRUCTURED (CONDITION, TYPENAME, ...) \
232
238
INVARIANT_STRUCTURED (CONDITION, TYPENAME, __VA_ARGS__)
233
239
234
240
// The condition should only contain variables that will be returned /
235
241
// output without further modification.
236
242
// "The implementation of this method means that the condition will hold".
243
+ //
244
+ // A POSTCONDITION documents what the function can guarantee about its
245
+ // output when it returns, given that it was called with valid inputs.
246
+ // Outputs include the return value of the function, as well as member
247
+ // variables that the function may write.
237
248
#define POSTCONDITION (CONDITION ) INVARIANT(CONDITION, " Postcondition" )
238
249
#define POSTCONDITION_STRUCTURED (CONDITION, TYPENAME, ...) \
239
250
INVARIANT_STRUCTURED (CONDITION, TYPENAME, __VA_ARGS__)
@@ -242,6 +253,10 @@ inline void invariant_violated_string(
242
253
// changed by a previous method call.
243
254
// "The contract of the previous method call means the following
244
255
// condition holds".
256
+ //
257
+ // A difference between CHECK_RETURN and POSTCONDITION is that CHECK_RETURN is
258
+ // a statement about what the caller expects from a function, whereas a
259
+ // POSTCONDITION is a statement about guarantees made by the function itself.
245
260
#define CHECK_RETURN (CONDITION ) INVARIANT(CONDITION, " Check return value" )
246
261
#define CHECK_RETURN_STRUCTURED (CONDITION, TYPENAME, ...) \
247
262
INVARIANT_STRUCTURED (CONDITION, TYPENAME, __VA_ARGS__)
@@ -254,14 +269,18 @@ inline void invariant_violated_string(
254
269
// This condition should be used to document that assumptions that are
255
270
// made on goto_functions, goto_programs, exprts, etc. being well formed.
256
271
// "The data structure is corrupt or malformed"
272
+ //
273
+ // It is okay for a DATA_INVARIANT to have an empty string as a reason string
274
+ // if you can't state the reason, or doing so doesn't add any information -
275
+ // just restates the condition.
257
276
#define DATA_INVARIANT (CONDITION, REASON ) INVARIANT(CONDITION, REASON)
258
277
#define DATA_INVARIANT_STRUCTURED (CONDITION, TYPENAME, ...) \
259
278
INVARIANT_STRUCTURED (CONDITION, TYPENAME, __VA_ARGS__)
260
279
261
280
// Legacy annotations
262
281
263
282
// The following should not be used in new code and are only intended
264
- // to migrate documentation and "error handling" in older code
283
+ // to migrate documentation and "error handling" in older code.
265
284
#define TODO INVARIANT (false , " Todo" )
266
285
#define UNIMPLEMENTED INVARIANT (false , " Unimplemented" )
267
286
#define UNHANDLED_CASE INVARIANT (false , " Unhandled case" )
0 commit comments