Skip to content

Commit 76d864c

Browse files
committed
add to_ternary_expr
This adds to_ternary_expr, to upcast expressions with three operands.
1 parent 5d89f25 commit 76d864c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/util/std_expr.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,37 @@ class ternary_exprt : public expr_protectedt
6969

7070
const exprt &op3() const = delete;
7171
exprt &op3() = delete;
72+
73+
static void check(
74+
const exprt &expr,
75+
const validation_modet vm = validation_modet::INVARIANT)
76+
{
77+
DATA_CHECK(
78+
vm,
79+
expr.operands().size() == 3,
80+
"ternary expression must have three operands");
81+
}
7282
};
7383

84+
/// \brief Cast an exprt to a \ref ternary_exprt
85+
///
86+
/// \a expr must be known to be \ref ternary_exprt.
87+
///
88+
/// \param expr: Source expression
89+
/// \return Object of type \ref ternary_exprt
90+
inline const ternary_exprt &to_ternary_expr(const exprt &expr)
91+
{
92+
ternary_exprt::check(expr);
93+
return static_cast<const ternary_exprt &>(expr);
94+
}
95+
96+
/// \copydoc to_ternary_expr(const exprt &)
97+
inline ternary_exprt &to_ternary_expr(exprt &expr)
98+
{
99+
ternary_exprt::check(expr);
100+
return static_cast<ternary_exprt &>(expr);
101+
}
102+
74103
/// Expression to hold a symbol (variable)
75104
class symbol_exprt : public nullary_exprt
76105
{

0 commit comments

Comments
 (0)