13
13
// / \file util/std_expr.h
14
14
// / API to expression classes
15
15
16
+ #include " base_type.h"
16
17
#include " expr_cast.h"
17
18
#include " invariant.h"
18
19
#include " mathematical_types.h"
@@ -1414,6 +1415,26 @@ class equal_exprt:public binary_relation_exprt
1414
1415
binary_relation_exprt (_lhs, ID_equal, _rhs)
1415
1416
{
1416
1417
}
1418
+
1419
+ void check (const validation_modet vm = validation_modet::INVARIANT) const
1420
+ {
1421
+ DATA_CHECK (operands ().size () == 2 , " equality must have two operands" );
1422
+ }
1423
+
1424
+ void validate (
1425
+ const namespacet &ns,
1426
+ const validation_modet vm = validation_modet::INVARIANT) const
1427
+ {
1428
+ check (vm);
1429
+
1430
+ // check types
1431
+ DATA_CHECK (
1432
+ base_type_eq (lhs ().type (), rhs ().type (), ns),
1433
+ " lhs and rhs should have same type" );
1434
+ DATA_CHECK (
1435
+ type ().id () == ID_bool,
1436
+ " result of equal expression should be of type bool" );
1437
+ }
1417
1438
};
1418
1439
1419
1440
// / \brief Cast an exprt to an \ref equal_exprt
@@ -1425,16 +1446,18 @@ class equal_exprt:public binary_relation_exprt
1425
1446
inline const equal_exprt &to_equal_expr (const exprt &expr)
1426
1447
{
1427
1448
PRECONDITION (expr.id ()==ID_equal);
1428
- DATA_INVARIANT (expr.operands ().size ()==2 , " Equality must have two operands" );
1429
- return static_cast <const equal_exprt &>(expr);
1449
+ const equal_exprt &ret = static_cast <const equal_exprt &>(expr);
1450
+ ret.check ();
1451
+ return ret;
1430
1452
}
1431
1453
1432
1454
// / \copydoc to_equal_expr(const exprt &)
1433
1455
inline equal_exprt &to_equal_expr (exprt &expr)
1434
1456
{
1435
1457
PRECONDITION (expr.id ()==ID_equal);
1436
- DATA_INVARIANT (expr.operands ().size ()==2 , " Equality must have two operands" );
1437
- return static_cast <equal_exprt &>(expr);
1458
+ equal_exprt &ret = static_cast <equal_exprt &>(expr);
1459
+ ret.check ();
1460
+ return ret;
1438
1461
}
1439
1462
1440
1463
template <> inline bool can_cast_expr<equal_exprt>(const exprt &base)
0 commit comments