Go to the documentation of this file.
9 #ifndef CPROVER_UTIL_EXPR_CAST_H
10 #define CPROVER_UTIL_EXPR_CAST_H
16 #include <type_traits>
64 template<
typename Ret,
typename T>
68 !std::is_reference<Ret>::value,
69 "Ret must not be a reference, i.e. expr_try_dynamic_cast<const thingt> "
70 "rather than expr_try_dynamic_cast<const thing &>");
73 typename std::conditional<
74 std::is_const<T>::value,
75 typename std::add_const<Ret>::type,
90 template <
typename T,
typename TExpr>
98 std::is_base_of<
exprt,
typename std::decay<TExpr>::type>::value,
99 "Tried to expr_try_dynamic_cast from something that wasn't an exprt");
101 std::is_base_of<exprt, T>::value,
102 "The template argument T must be derived from exprt.");
103 if(!
can_cast_expr<
typename std::remove_const<T>::type>(base))
105 const auto ret=
static_cast<returnt
>(&base);
118 template <
typename T,
typename TType>
125 std::is_base_of<
typet,
typename std::decay<TType>::type>::value,
126 "Tried to type_try_dynamic_cast from something that wasn't an typet");
128 std::is_base_of<typet, T>::value,
129 "The template argument T must be derived from typet.");
130 if(!
can_cast_type<
typename std::remove_const<T>::type>(base))
132 const auto ret =
static_cast<returnt
>(&base);
140 template<
typename Ret,
typename T>
144 !std::is_reference<Ret>::value,
145 "Ret must not be a reference, i.e. expr_dynamic_cast<const thingt> rather "
146 "than expr_dynamic_cast<const thing &>");
149 typename std::conditional<
150 std::is_const<T>::value,
151 typename std::add_const<Ret>::type,
164 template<
typename T,
typename TExpr>
168 const auto ret=expr_try_dynamic_cast<T>(base);
170 throw std::bad_cast();
183 template<
typename T,
typename TExpr>
188 return expr_dynamic_cast<T>(base);
197 template <
typename T,
typename TType>
201 auto result = type_try_dynamic_cast<T>(base);
210 bool allow_more=
false)
219 #endif // CPROVER_UTIL_EXPR_CAST_H
#define PRECONDITION(CONDITION)
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
The type of an expression, extends irept.
void validate_operands(const exprt &value, exprt::operandst::size_type number, const char *message, bool allow_more=false)
Base class for all expressions.
bool can_cast_type(const typet &base)
Check whether a reference to a generic typet is of a specific derived class.
auto expr_dynamic_cast(TExpr &base) -> typename detail::expr_dynamic_cast_return_typet< T, TExpr >::type
Cast a reference to a generic exprt to a specific derived class.
auto type_checked_cast(TType &base) -> typename detail::expr_dynamic_cast_return_typet< T, TType >::type
Cast a reference to a generic typet to a specific derived class and checks that the type could be con...
void validate_type(const typet &)
Called after casting.
std::conditional< std::is_const< T >::value, typename std::add_const< Ret >::type, Ret >::type & type
auto type_try_dynamic_cast(TType &base) -> typename detail::expr_try_dynamic_cast_return_typet< T, TType >::type
Try to cast a reference to a generic typet to a specific derived class.
auto expr_checked_cast(TExpr &base) -> typename detail::expr_dynamic_cast_return_typet< T, TExpr >::type
Cast a reference to a generic exprt to a specific derived class.
bool can_cast_expr(const exprt &base)
Check whether a reference to a generic exprt is of a specific derived class.
auto expr_try_dynamic_cast(TExpr &base) -> typename detail::expr_try_dynamic_cast_return_typet< T, TExpr >::type
Try to cast a reference to a generic exprt to a specific derived class.
void validate_expr(const exprt &)
Called after casting.
unsignedbv_typet size_type()
std::conditional< std::is_const< T >::value, typename std::add_const< Ret >::type, Ret >::type * type
#define CHECK_RETURN(CONDITION)