Skip to content

Commit d4dc77f

Browse files
committed
Re-use *_exprt::check in validate_expr and to_*exprt
Prefer code re-use over duplicated (and possibly inconsistent) implementations.
1 parent 4b5d356 commit d4dc77f

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

src/util/std_expr.h

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ inline bool can_cast_expr<binary_exprt>(const exprt &base)
778778

779779
inline void validate_expr(const binary_exprt &value)
780780
{
781-
validate_operands(value, 2, "Binary expressions must have two operands");
781+
binary_exprt::check(value);
782782
}
783783

784784
/// \brief Cast an exprt to a \ref binary_exprt
@@ -789,18 +789,14 @@ inline void validate_expr(const binary_exprt &value)
789789
/// \return Object of type \ref binary_exprt
790790
inline const binary_exprt &to_binary_expr(const exprt &expr)
791791
{
792-
DATA_INVARIANT(
793-
expr.operands().size()==2,
794-
"Binary expressions must have two operands");
792+
binary_exprt::check(expr);
795793
return static_cast<const binary_exprt &>(expr);
796794
}
797795

798796
/// \copydoc to_binary_expr(const exprt &)
799797
inline binary_exprt &to_binary_expr(exprt &expr)
800798
{
801-
DATA_INVARIANT(
802-
expr.operands().size()==2,
803-
"Binary expressions must have two operands");
799+
binary_exprt::check(expr);
804800
return static_cast<binary_exprt &>(expr);
805801
}
806802

@@ -921,7 +917,7 @@ inline bool can_cast_expr<binary_relation_exprt>(const exprt &base)
921917

922918
inline void validate_expr(const binary_relation_exprt &value)
923919
{
924-
validate_operands(value, 2, "Binary relations must have two operands");
920+
binary_relation_exprt::check(value);
925921
}
926922

927923
/// \brief Cast an exprt to a \ref binary_relation_exprt
@@ -932,18 +928,14 @@ inline void validate_expr(const binary_relation_exprt &value)
932928
/// \return Object of type \ref binary_relation_exprt
933929
inline const binary_relation_exprt &to_binary_relation_expr(const exprt &expr)
934930
{
935-
DATA_INVARIANT(
936-
expr.operands().size()==2,
937-
"Binary relations must have two operands");
931+
binary_relation_exprt::check(expr);
938932
return static_cast<const binary_relation_exprt &>(expr);
939933
}
940934

941935
/// \copydoc to_binary_relation_expr(const exprt &)
942936
inline binary_relation_exprt &to_binary_relation_expr(exprt &expr)
943937
{
944-
DATA_INVARIANT(
945-
expr.operands().size()==2,
946-
"Binary relations must have two operands");
938+
binary_relation_exprt::check(expr);
947939
return static_cast<binary_relation_exprt &>(expr);
948940
}
949941

@@ -1457,7 +1449,7 @@ inline bool can_cast_expr<equal_exprt>(const exprt &base)
14571449

14581450
inline void validate_expr(const equal_exprt &value)
14591451
{
1460-
validate_operands(value, 2, "Equality must have two operands");
1452+
equal_exprt::check(value);
14611453
}
14621454

14631455
/// \brief Cast an exprt to an \ref equal_exprt

0 commit comments

Comments
 (0)