Skip to content

Commit a55065a

Browse files
author
Daniel Kroening
committed
added to_shl_expr
Uses standard pattern, enables stronger typing.
1 parent d32ab69 commit a55065a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/util/std_expr.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2960,6 +2960,29 @@ class shl_exprt:public shift_exprt
29602960
}
29612961
};
29622962

2963+
/// \brief Cast an exprt to a \ref shl_exprt
2964+
///
2965+
/// \a expr must be known to be \ref shl_exprt.
2966+
///
2967+
/// \param expr: Source expression
2968+
/// \return Object of type \ref shl_exprt
2969+
inline const shl_exprt &to_shl_expr(const exprt &expr)
2970+
{
2971+
PRECONDITION(expr.id() == ID_shl);
2972+
DATA_INVARIANT(
2973+
expr.operands().size() == 2, "Bit-wise shl must have two operands");
2974+
return static_cast<const shl_exprt &>(expr);
2975+
}
2976+
2977+
/// \copydoc to_shl_expr(const exprt &)
2978+
inline shl_exprt &to_shl_expr(exprt &expr)
2979+
{
2980+
PRECONDITION(expr.id() == ID_shl);
2981+
DATA_INVARIANT(
2982+
expr.operands().size() == 2, "Bit-wise shl must have two operands");
2983+
return static_cast<shl_exprt &>(expr);
2984+
}
2985+
29632986
/// \brief Arithmetic right shift
29642987
class ashr_exprt:public shift_exprt
29652988
{

0 commit comments

Comments
 (0)