Skip to content

Commit 409c492

Browse files
authored
Merge pull request #4593 from smowton/smowton/feature/ssa-exprt-can-cast-expr
Add can_cast_expr specialisation for ssa_exprt
2 parents 0475c87 + d6666cd commit 409c492

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/util/ssa_expr.h

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,33 +152,38 @@ class ssa_exprt:public symbol_exprt
152152
}
153153
};
154154

155-
/// Cast a generic exprt to an \ref ssa_exprt. This is an unchecked conversion.
156-
/// \a expr must be known to be \ref ssa_exprt.
155+
inline bool is_ssa_expr(const exprt &expr)
156+
{
157+
return expr.id() == ID_symbol && expr.get_bool(ID_C_SSA_symbol);
158+
}
159+
160+
template <>
161+
inline bool can_cast_expr<ssa_exprt>(const exprt &base)
162+
{
163+
return is_ssa_expr(base);
164+
}
165+
166+
inline void validate_expr(const ssa_exprt &expr)
167+
{
168+
ssa_exprt::check(expr);
169+
}
170+
171+
/// Cast a generic exprt to an \ref ssa_exprt.
157172
/// \param expr: Source expression
158173
/// \return Object of type \ref ssa_exprt
159174
/// \ingroup gr_std_expr
160175
inline const ssa_exprt &to_ssa_expr(const exprt &expr)
161176
{
162-
PRECONDITION(
163-
expr.id() == ID_symbol && expr.get_bool(ID_C_SSA_symbol) &&
164-
!expr.has_operands());
177+
ssa_exprt::check(expr);
165178
return static_cast<const ssa_exprt &>(expr);
166179
}
167180

168181
/// \copydoc to_ssa_expr(const exprt &)
169182
/// \ingroup gr_std_expr
170183
inline ssa_exprt &to_ssa_expr(exprt &expr)
171184
{
172-
PRECONDITION(
173-
expr.id() == ID_symbol && expr.get_bool(ID_C_SSA_symbol) &&
174-
!expr.has_operands());
185+
ssa_exprt::check(expr);
175186
return static_cast<ssa_exprt &>(expr);
176187
}
177188

178-
inline bool is_ssa_expr(const exprt &expr)
179-
{
180-
return expr.id()==ID_symbol &&
181-
expr.get_bool(ID_C_SSA_symbol);
182-
}
183-
184189
#endif // CPROVER_UTIL_SSA_EXPR_H

0 commit comments

Comments
 (0)