Skip to content

Commit c56da40

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 a7b652c commit c56da40

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
@@ -766,7 +766,7 @@ inline bool can_cast_expr<binary_exprt>(const exprt &base)
766766

767767
inline void validate_expr(const binary_exprt &value)
768768
{
769-
validate_operands(value, 2, "Binary expressions must have two operands");
769+
binary_exprt::check(value);
770770
}
771771

772772
/// \brief Cast an exprt to a \ref binary_exprt
@@ -777,18 +777,14 @@ inline void validate_expr(const binary_exprt &value)
777777
/// \return Object of type \ref binary_exprt
778778
inline const binary_exprt &to_binary_expr(const exprt &expr)
779779
{
780-
DATA_INVARIANT(
781-
expr.operands().size()==2,
782-
"Binary expressions must have two operands");
780+
binary_exprt::check(expr);
783781
return static_cast<const binary_exprt &>(expr);
784782
}
785783

786784
/// \copydoc to_binary_expr(const exprt &)
787785
inline binary_exprt &to_binary_expr(exprt &expr)
788786
{
789-
DATA_INVARIANT(
790-
expr.operands().size()==2,
791-
"Binary expressions must have two operands");
787+
binary_exprt::check(expr);
792788
return static_cast<binary_exprt &>(expr);
793789
}
794790

@@ -904,7 +900,7 @@ inline bool can_cast_expr<binary_relation_exprt>(const exprt &base)
904900

905901
inline void validate_expr(const binary_relation_exprt &value)
906902
{
907-
validate_operands(value, 2, "Binary relations must have two operands");
903+
binary_relation_exprt::check(value);
908904
}
909905

910906
/// \brief Cast an exprt to a \ref binary_relation_exprt
@@ -915,18 +911,14 @@ inline void validate_expr(const binary_relation_exprt &value)
915911
/// \return Object of type \ref binary_relation_exprt
916912
inline const binary_relation_exprt &to_binary_relation_expr(const exprt &expr)
917913
{
918-
DATA_INVARIANT(
919-
expr.operands().size()==2,
920-
"Binary relations must have two operands");
914+
binary_relation_exprt::check(expr);
921915
return static_cast<const binary_relation_exprt &>(expr);
922916
}
923917

924918
/// \copydoc to_binary_relation_expr(const exprt &)
925919
inline binary_relation_exprt &to_binary_relation_expr(exprt &expr)
926920
{
927-
DATA_INVARIANT(
928-
expr.operands().size()==2,
929-
"Binary relations must have two operands");
921+
binary_relation_exprt::check(expr);
930922
return static_cast<binary_relation_exprt &>(expr);
931923
}
932924

@@ -1420,7 +1412,7 @@ inline bool can_cast_expr<equal_exprt>(const exprt &base)
14201412

14211413
inline void validate_expr(const equal_exprt &value)
14221414
{
1423-
validate_operands(value, 2, "Equality must have two operands");
1415+
equal_exprt::check(value);
14241416
}
14251417

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

0 commit comments

Comments
 (0)