Skip to content

Commit 990e6f6

Browse files
committed
add nullary_exprt::check(expr)
This adds nullary_exprt::check(expr), which checks that the expression is indeed nullary. This follows the same pattern as binary_exprt::check and ternary_exprt::check.
1 parent a18c481 commit 990e6f6

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

src/util/std_expr.h

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ class nullary_exprt : public expr_protectedt
2626
{
2727
}
2828

29+
static void check(
30+
const exprt &expr,
31+
const validation_modet vm = validation_modet::INVARIANT)
32+
{
33+
DATA_CHECK(
34+
vm,
35+
expr.operands().size() == 0,
36+
"nullary expression must not have operands");
37+
}
38+
39+
static void validate(
40+
const exprt &expr,
41+
const namespacet &,
42+
const validation_modet vm = validation_modet::INVARIANT)
43+
{
44+
check(expr, vm);
45+
}
46+
2947
/// remove all operand methods
3048
operandst &operands() = delete;
3149
const operandst &operands() const = delete;
@@ -293,19 +311,16 @@ inline void validate_expr(const nondet_symbol_exprt &value)
293311
inline const nondet_symbol_exprt &to_nondet_symbol_expr(const exprt &expr)
294312
{
295313
PRECONDITION(expr.id()==ID_nondet_symbol);
296-
const nondet_symbol_exprt &ret =
297-
static_cast<const nondet_symbol_exprt &>(expr);
298-
validate_expr(ret);
299-
return ret;
314+
nondet_symbol_exprt::check(expr);
315+
return static_cast<const nondet_symbol_exprt &>(expr);
300316
}
301317

302318
/// \copydoc to_nondet_symbol_expr(const exprt &)
303319
inline nondet_symbol_exprt &to_nondet_symbol_expr(exprt &expr)
304320
{
305321
PRECONDITION(expr.id()==ID_symbol);
306-
nondet_symbol_exprt &ret = static_cast<nondet_symbol_exprt &>(expr);
307-
validate_expr(ret);
308-
return ret;
322+
nondet_symbol_exprt::check(expr);
323+
return static_cast<nondet_symbol_exprt &>(expr);
309324
}
310325

311326

@@ -1804,18 +1819,16 @@ inline void validate_expr(const empty_union_exprt &value)
18041819
inline const empty_union_exprt &to_empty_union_expr(const exprt &expr)
18051820
{
18061821
PRECONDITION(expr.id() == ID_empty_union);
1807-
const empty_union_exprt &ret = static_cast<const empty_union_exprt &>(expr);
1808-
validate_expr(ret);
1809-
return ret;
1822+
empty_union_exprt::check(expr);
1823+
return static_cast<const empty_union_exprt &>(expr);
18101824
}
18111825

18121826
/// \copydoc to_empty_union_expr(const exprt &)
18131827
inline empty_union_exprt &to_empty_union_expr(exprt &expr)
18141828
{
18151829
PRECONDITION(expr.id() == ID_empty_union);
1816-
empty_union_exprt &ret = static_cast<empty_union_exprt &>(expr);
1817-
validate_expr(ret);
1818-
return ret;
1830+
empty_union_exprt::check(expr);
1831+
return static_cast<empty_union_exprt &>(expr);
18191832
}
18201833

18211834
/// \brief Struct constructor from list of elements
@@ -2921,16 +2934,16 @@ inline bool can_cast_expr<type_exprt>(const exprt &base)
29212934
inline const type_exprt &to_type_expr(const exprt &expr)
29222935
{
29232936
PRECONDITION(can_cast_expr<type_exprt>(expr));
2924-
const type_exprt &ret = static_cast<const type_exprt &>(expr);
2925-
return ret;
2937+
type_exprt::check(expr);
2938+
return static_cast<const type_exprt &>(expr);
29262939
}
29272940

29282941
/// \copydoc to_type_expr(const exprt &)
29292942
inline type_exprt &to_type_expr(exprt &expr)
29302943
{
29312944
PRECONDITION(can_cast_expr<type_exprt>(expr));
2932-
type_exprt &ret = static_cast<type_exprt &>(expr);
2933-
return ret;
2945+
type_exprt::check(expr);
2946+
return static_cast<type_exprt &>(expr);
29342947
}
29352948

29362949
/// \brief A constant literal expression
@@ -2988,13 +3001,15 @@ inline void validate_expr(const constant_exprt &value)
29883001
inline const constant_exprt &to_constant_expr(const exprt &expr)
29893002
{
29903003
PRECONDITION(expr.is_constant());
3004+
constant_exprt::check(expr);
29913005
return static_cast<const constant_exprt &>(expr);
29923006
}
29933007

29943008
/// \copydoc to_constant_expr(const exprt &)
29953009
inline constant_exprt &to_constant_expr(exprt &expr)
29963010
{
29973011
PRECONDITION(expr.is_constant());
3012+
constant_exprt::check(expr);
29983013
return static_cast<constant_exprt &>(expr);
29993014
}
30003015

@@ -3534,10 +3549,8 @@ inline const class_method_descriptor_exprt &
35343549
to_class_method_descriptor_expr(const exprt &expr)
35353550
{
35363551
PRECONDITION(expr.id() == ID_virtual_function);
3537-
const class_method_descriptor_exprt &ret =
3538-
static_cast<const class_method_descriptor_exprt &>(expr);
3539-
validate_expr(ret);
3540-
return ret;
3552+
class_method_descriptor_exprt::check(expr);
3553+
return static_cast<const class_method_descriptor_exprt &>(expr);
35413554
}
35423555

35433556
template <>

0 commit comments

Comments
 (0)