Skip to content

Commit ddfa911

Browse files
committed
Make validation mode parameter explicit in DATA_CHECK() macros
1 parent 5e68531 commit ddfa911

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

src/util/std_code.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class code_assignt:public codet
291291
const validation_modet vm = validation_modet::INVARIANT)
292292
{
293293
DATA_CHECK(
294-
code.operands().size() == 2, "assignment must have two operands");
294+
vm, code.operands().size() == 2, "assignment must have two operands");
295295
}
296296

297297
static void validate(
@@ -302,6 +302,7 @@ class code_assignt:public codet
302302
check(code, vm);
303303

304304
DATA_CHECK(
305+
vm,
305306
base_type_eq(code.op0().type(), code.op1().type(), ns),
306307
"lhs and rhs of assignment must have same type");
307308
}

src/util/std_expr.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,9 @@ class binary_exprt:public exprt
777777
const validation_modet vm = validation_modet::INVARIANT)
778778
{
779779
DATA_CHECK(
780-
expr.operands().size() == 2, "binary expression must have two operands");
780+
vm,
781+
expr.operands().size() == 2,
782+
"binary expression must have two operands");
781783
}
782784

783785
static void validate(
@@ -859,6 +861,7 @@ class binary_predicate_exprt:public binary_exprt
859861
binary_exprt::validate(expr, ns, vm);
860862

861863
DATA_CHECK(
864+
vm,
862865
expr.type().id() == ID_bool,
863866
"result of binary predicate expression should be of type bool");
864867
}
@@ -901,6 +904,7 @@ class binary_relation_exprt:public binary_predicate_exprt
901904

902905
// check types
903906
DATA_CHECK(
907+
vm,
904908
base_type_eq(expr.op0().type(), expr.op1().type(), ns),
905909
"lhs and rhs of binary relation expression should have same type");
906910
}

src/util/std_types.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,8 @@ class bitvector_typet : public typet
11491149
const typet &type,
11501150
const validation_modet vm = validation_modet::INVARIANT)
11511151
{
1152-
DATA_CHECK(!type.get(ID_width).empty(), "bitvector type must have width");
1152+
DATA_CHECK(
1153+
vm, !type.get(ID_width).empty(), "bitvector type must have width");
11531154
}
11541155
};
11551156

src/util/symbol_table.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ void symbol_tablet::validate(const validation_modet vm) const
130130

131131
// Check that symbols[id].name == id
132132
DATA_CHECK_WITH_DIAGNOSTICS(
133+
vm,
133134
symbol.name == symbol_key,
134135
"Symbol table entry must map to a symbol with the correct identifier",
135136
"Symbol table key '",
@@ -152,6 +153,7 @@ void symbol_tablet::validate(const validation_modet vm) const
152153
}) != symbol_base_map.end();
153154

154155
DATA_CHECK_WITH_DIAGNOSTICS(
156+
vm,
155157
base_map_matches_symbol,
156158
"The base_name of a symbol should map to itself",
157159
"Symbol table key '",
@@ -174,6 +176,7 @@ void symbol_tablet::validate(const validation_modet vm) const
174176
}) != symbol_module_map.end();
175177

176178
DATA_CHECK_WITH_DIAGNOSTICS(
179+
vm,
177180
module_map_matches_symbol,
178181
"Symbol table module map should map to symbol",
179182
"Symbol table key '",
@@ -188,6 +191,7 @@ void symbol_tablet::validate(const validation_modet vm) const
188191
for(auto base_map_entry : symbol_base_map)
189192
{
190193
DATA_CHECK_WITH_DIAGNOSTICS(
194+
vm,
191195
has_symbol(base_map_entry.second),
192196
"Symbol table base_name map entries must map to a symbol name",
193197
"base_name map entry '",
@@ -201,6 +205,7 @@ void symbol_tablet::validate(const validation_modet vm) const
201205
for(auto module_map_entry : symbol_module_map)
202206
{
203207
DATA_CHECK_WITH_DIAGNOSTICS(
208+
vm,
204209
has_symbol(module_map_entry.second),
205210
"Symbol table module map entries must map to a symbol name",
206211
"base_name map entry '",

src/util/validate.h

+6-16
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,13 @@ Author: Daniel Poetzl
1515
#include "validation_mode.h"
1616

1717
/// This macro takes a condition which denotes a well-formedness criterion on
18-
/// goto programs, expressions, instructions, etc. When invoking the macro, a
19-
/// variable named `vm` of type `const validation_modet` should be in scope. It
20-
/// indicates whether DATA_INVARIANT() is used to check the condition, or if an
21-
/// exception is thrown when the condition does not hold.
22-
#define DATA_CHECK(condition, message) \
18+
/// goto programs, expressions, instructions, etc. The first parameter should be
19+
/// of type `validate_modet` and indicates whether DATA_INVARIANT() is used to
20+
/// check the condition, or if an exception is thrown when the condition does
21+
/// not hold.
22+
#define DATA_CHECK(vm, condition, message) \
2323
do \
2424
{ \
25-
static_assert( \
26-
std::is_same<decltype(vm), const validation_modet>::value, \
27-
"when invoking the macro DATA_CHECK(), a variable named `vm` of type " \
28-
"`const validation_modet` should be in scope which indicates the " \
29-
"validation mode (see `validate.h`"); \
3025
switch(vm) \
3126
{ \
3227
case validation_modet::INVARIANT: \
@@ -39,14 +34,9 @@ Author: Daniel Poetzl
3934
} \
4035
} while(0)
4136

42-
#define DATA_CHECK_WITH_DIAGNOSTICS(condition, message, ...) \
37+
#define DATA_CHECK_WITH_DIAGNOSTICS(vm, condition, message, ...) \
4338
do \
4439
{ \
45-
static_assert( \
46-
std::is_same<decltype(vm), const validation_modet>::value, \
47-
"when invoking the macro DATA_CHECK_WITH_DIAGNOSTICS(), a variable " \
48-
"named `vm` of type `const validation_modet` should be in scope which " \
49-
"indicates the validation mode (see `validate.h`"); \
5040
switch(vm) \
5141
{ \
5242
case validation_modet::INVARIANT: \

0 commit comments

Comments
 (0)