Skip to content

Commit 7dd2aa5

Browse files
danpoePetr Bauch
authored and
Petr Bauch
committed
Add macros for goto model validation
1 parent 150cf46 commit 7dd2aa5

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

src/util/validate.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*******************************************************************\
2+
3+
Module: Goto program validation
4+
5+
Author: Daniel Poetzl
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_UTIL_VALIDATE_H
10+
#define CPROVER_UTIL_VALIDATE_H
11+
12+
#include <type_traits>
13+
14+
#include "exception_utils.h"
15+
#include "invariant.h"
16+
#include "irep.h"
17+
18+
enum class validation_modet
19+
{
20+
INVARIANT,
21+
EXCEPTION
22+
};
23+
24+
#define GET_FIRST(A, ...) A
25+
26+
/// This macro takes a condition which denotes a well-formedness criterion on
27+
/// goto programs, expressions, instructions, etc. Based on the value of the
28+
/// variable vm (the validation mode), it either uses DATA_INVARIANT() to check
29+
/// those conditions, or throws an exception when a condition does not hold.
30+
#define DATA_CHECK(condition, message) \
31+
do \
32+
{ \
33+
switch(vm) \
34+
{ \
35+
case validation_modet::INVARIANT: \
36+
DATA_INVARIANT(condition, message); \
37+
break; \
38+
case validation_modet::EXCEPTION: \
39+
if(!(condition)) \
40+
throw incorrect_goto_program_exceptiont(message); \
41+
break; \
42+
} \
43+
} while(0)
44+
45+
#define DATA_CHECK_WITH_DIAGNOSTICS(condition, message, ...) \
46+
do \
47+
{ \
48+
switch(vm) \
49+
{ \
50+
case validation_modet::INVARIANT: \
51+
DATA_INVARIANT_WITH_DIAGNOSTICS(condition, message, __VA_ARGS__); \
52+
break; \
53+
case validation_modet::EXCEPTION: \
54+
if(!(condition)) \
55+
throw incorrect_goto_program_exceptiont( \
56+
message, GET_FIRST(__VA_ARGS__, dummy)); \
57+
break; \
58+
} \
59+
} while(0)
60+
61+
#endif /* CPROVER_UTIL_VALIDATE_H */

0 commit comments

Comments
 (0)