Skip to content

Commit 631aeb4

Browse files
committed
Add unary_minus_overflow_exprt
1 parent 98c80dc commit 631aeb4

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/util/bitvector_expr.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,44 @@ inline void validate_expr(const unary_overflow_exprt &value)
892892
value, 1, "unary overflow expression must have one operand");
893893
}
894894

895+
/// \brief A Boolean expression returning true, iff negation would result in an
896+
/// overflow when applied to the (single) operand.
897+
class unary_minus_overflow_exprt : public unary_overflow_exprt
898+
{
899+
public:
900+
explicit unary_minus_overflow_exprt(exprt _op)
901+
: unary_overflow_exprt(ID_unary_minus, std::move(_op))
902+
{
903+
}
904+
905+
static void check(
906+
const exprt &expr,
907+
const validation_modet vm = validation_modet::INVARIANT)
908+
{
909+
unary_exprt::check(expr, vm);
910+
}
911+
912+
static void validate(
913+
const exprt &expr,
914+
const namespacet &,
915+
const validation_modet vm = validation_modet::INVARIANT)
916+
{
917+
check(expr, vm);
918+
}
919+
};
920+
921+
template <>
922+
inline bool can_cast_expr<unary_minus_overflow_exprt>(const exprt &base)
923+
{
924+
return base.id() == ID_overflow_unary_minus;
925+
}
926+
927+
inline void validate_expr(const unary_minus_overflow_exprt &value)
928+
{
929+
validate_operands(
930+
value, 1, "unary minus overflow expression must have one operand");
931+
}
932+
895933
/// \brief Cast an exprt to a \ref unary_overflow_exprt
896934
///
897935
/// \a expr must be known to be \ref unary_overflow_exprt.

0 commit comments

Comments
 (0)