9#ifndef CPROVER_UTIL_EXPR_CAST_H
10#define CPROVER_UTIL_EXPR_CAST_H
54template<
typename Ret,
typename T>
58 !std::is_reference<Ret>::value,
59 "Ret must not be a reference, i.e. expr_try_dynamic_cast<const thingt> "
60 "rather than expr_try_dynamic_cast<const thing &>");
63 typename std::conditional<
64 std::is_const<T>::value,
65 typename std::add_const<Ret>::type,
80template <
typename T,
typename TExpr>
88 std::is_base_of<exprt, typename std::decay<TExpr>::type>::value,
89 "Tried to expr_try_dynamic_cast from something that wasn't an exprt");
91 std::is_base_of<exprt, T>::value,
92 "The template argument T must be derived from exprt.");
106template <
typename T,
typename TExpr>
110 std::is_rvalue_reference<
decltype(base)>::value,
111 "This template overload must only match where base is an rvalue.");
113 std::is_base_of<exprt, typename std::decay<TExpr>::type>::value,
114 "Tried to expr_try_dynamic_cast from something that wasn't an exprt.");
116 std::is_base_of<exprt, T>::value,
117 "The template argument T must be derived from exprt.");
118 static_assert(!std::is_const<TExpr>::value,
"Attempted to move from const.");
121 std::optional<T>
ret{
static_cast<T &&
>(base)};
134template <
typename T,
typename TType>
141 std::is_base_of<typet, typename std::decay<TType>::type>::value,
142 "Tried to type_try_dynamic_cast from something that wasn't an typet");
144 std::is_base_of<typet, T>::value,
145 "The template argument T must be derived from typet.");
146 if(!
can_cast_type<
typename std::remove_const<T>::type>(base))
149 return static_cast<returnt>(&base);
158template <
typename T,
typename TType>
162 std::is_rvalue_reference<
decltype(base)>::value,
163 "This template overload must only match where base is an rvalue.");
165 std::is_base_of<typet, typename std::decay<TType>::type>::value,
166 "Tried to type_try_dynamic_cast from something that wasn't an typet.");
168 std::is_base_of<typet, T>::value,
169 "The template argument T must be derived from typet.");
170 static_assert(!std::is_const<TType>::value,
"Attempted to move from const.");
174 std::optional<T>
ret{
static_cast<T &&
>(base)};
181template<
typename Ret,
typename T>
185 !std::is_reference<Ret>::value,
186 "Ret must not be a reference, i.e. expr_dynamic_cast<const thingt> rather "
187 "than expr_dynamic_cast<const thing &>");
190 typename std::conditional<
191 std::is_const<T>::value,
192 typename std::add_const<Ret>::type,
206template<
typename T,
typename TExpr>
212 throw std::bad_cast();
226template<
typename T,
typename TExpr>
241template <
typename T,
typename TType>
252 exprt::operandst::size_type number,
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Base class for all expressions.
The type of an expression, extends irept.
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 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...
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.
void validate_operands(const exprt &value, exprt::operandst::size_type number, const char *message, bool allow_more=false)
void validate_expr(const exprt &)
Called after casting.
bool can_cast_type(const typet &base)
Check whether a reference to a generic typet 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.
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.
#define CHECK_RETURN(CONDITION)
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
std::conditional< std::is_const< T >::value, typenamestd::add_const< Ret >::type, Ret >::type & type
std::conditional< std::is_const< T >::value, typenamestd::add_const< Ret >::type, Ret >::type * type