8#ifndef INCLUDE_UTIL_CASTING_H_
9#define INCLUDE_UTIL_CASTING_H_
34#ifndef LLVM_HAS_CPP_ATTRIBUTE
35#if defined(__cplusplus) && defined(__has_cpp_attribute)
36# define LLVM_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
38# define LLVM_HAS_CPP_ATTRIBUTE(x) 0
45#if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(nodiscard)
46#define LLVM_NODISCARD [[nodiscard]]
47#elif LLVM_HAS_CPP_ATTRIBUTE(clang::warn_unused_result)
48#define LLVM_NODISCARD [[clang::warn_unused_result]]
53#elif defined(__GNUC__) && LLVM_HAS_CPP_ATTRIBUTE(nodiscard)
54#define LLVM_NODISCARD [[nodiscard]]
69template<
typename T,
typename Enable =
void>
78 using type =
const std::remove_pointer_t<T> *;
82template<
typename T,
typename Enable =
void>
90 T, std::enable_if_t<std::is_pointer<T>::value>>
131template <
typename To,
typename From,
typename Enabler =
void>
134 static inline bool doit(
const From &Val)
136 return To::classof(&Val);
141template <
typename To,
typename From>
142struct isa_impl<To, From, std::enable_if_t<std::is_base_of<To, From>::value>>
144 static inline bool doit(
const From &)
152 static inline bool doit(
const From &Val)
158template <
typename To,
typename From>
struct isa_impl_cl<To, const From>
160 static inline bool doit(
const From &Val)
166template <
typename To,
typename From>
169 static inline bool doit(
const std::unique_ptr<From> &Val)
171 assert(Val &&
"SVFUtil::isa<> used on a null pointer");
176template <
typename To,
typename From>
struct isa_impl_cl<To, From*>
178 static inline bool doit(
const From *Val)
180 assert(Val &&
"SVFUtil::isa<> used on a null pointer");
185template <
typename To,
typename From>
struct isa_impl_cl<To, From*
const>
187 static inline bool doit(
const From *Val)
189 assert(Val &&
"SVFUtil::isa<> used on a null pointer");
194template <
typename To,
typename From>
struct isa_impl_cl<To, const From*>
196 static inline bool doit(
const From *Val)
198 assert(Val &&
"SVFUtil::isa<> used on a null pointer");
203template <
typename To,
typename From>
struct isa_impl_cl<To, const From*
const>
205 static inline bool doit(
const From *Val)
207 assert(Val &&
"SVFUtil::isa<> used on a null pointer");
212template<
typename To,
typename From,
typename SimpleFrom>
217 static bool doit(
const From &Val)
225template<
typename To,
typename FromTy>
229 static bool doit(
const FromTy &Val)
247template <
typename First,
typename Second,
typename... Rest,
typename Y>
257template<
class To,
class From>
struct cast_retty;
285template <
class To,
class From>
290 using ResultType =
typename std::remove_pointer<PointerType>::type;
296template<
class To,
class From,
class SimpleFrom>
305template<
class To,
class FromTy>
312template<
class To,
class From>
347 std::is_same<X, typename simplify_type<X>::SimpleType>
::value;
357template <
class X,
class Y>
358inline std::enable_if_t<!is_simple_type<Y>::value,
362 assert(
SVFUtil::isa<X>(Val) &&
"cast<Ty>() argument of incompatible type!");
367template <
class X,
class Y>
370 assert(
SVFUtil::isa<X>(Val) &&
"cast<Ty>() argument of incompatible type!");
375template <
class X,
class Y>
378 assert(
SVFUtil::isa<X>(Val) &&
"cast<Ty>() argument of incompatible type!");
383template <
class X,
class Y>
384inline typename cast_retty<X, std::unique_ptr<Y>>::ret_type
387 assert(
SVFUtil::isa<X>(Val.get()) &&
"cast<Ty>() argument of incompatible type!");
402template <
class X,
class Y>
410template <
class X,
class Y>
416template <
class X,
class Y>
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > cast(const Y &Val)
LLVM_NODISCARD bool isa(const Y &Val)
LLVM_NODISCARD std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
const std::remove_pointer_t< T > * type
If T is a pointer, just return it. If it is not, return T&.
static cast_retty< To, FromTy >::ret_type doit(const FromTy &Val)
static cast_retty< To, From >::ret_type doit(From &Val)
typename std::remove_pointer< PointerType >::type ResultType
std::unique_ptr< ResultType > ret_type
typename cast_retty_impl< To, From * >::ret_type PointerType
typename cast_retty_impl< To, FromTy >::ret_type ret_type
typename cast_retty< To, SimpleFrom >::ret_type ret_type
typename cast_retty_wrap< To, From, typename simplify_type< From >::SimpleType >::ret_type ret_type
static bool doit(const From &)
static bool doit(const From *Val)
static bool doit(const From *Val)
static bool doit(const From &Val)
static bool doit(const From *Val)
static bool doit(const From *Val)
static bool doit(const std::unique_ptr< From > &Val)
static bool doit(const From &Val)
static bool doit(const FromTy &Val)
static bool doit(const From &Val)
static bool doit(const From &Val)
typename SVFUtil::add_lvalue_reference_if_not_pointer< SimpleType >::type RetType
typename SVFUtil::add_const_past_pointer< NonConstSimpleType >::type SimpleType
typename simplify_type< From >::SimpleType NonConstSimpleType
static RetType getSimplifiedValue(const From &Val)
static SimpleType & getSimplifiedValue(From &Val)