15 #ifndef LLVM_SUPPORT_CASTING_H
16 #define LLVM_SUPPORT_CASTING_H
32 template<
typename From>
struct simplify_type {
53 template <
typename To,
typename From,
typename Enabler =
void>
55 static inline bool doit(
const From &Val) {
56 return To::classof(&Val);
61 template <
typename To,
typename From>
63 To, From, typename std::enable_if<std::is_base_of<To, From>::value>::type> {
64 static inline bool doit(
const From &) {
return true; }
68 static inline bool doit(
const From &Val) {
74 static inline bool doit(
const From &Val) {
79 template <
typename To,
typename From>
struct isa_impl_cl<To, From*> {
80 static inline bool doit(
const From *Val) {
81 assert(Val &&
"isa<> used on a null pointer");
86 template <
typename To,
typename From>
struct isa_impl_cl<To, From*
const> {
87 static inline bool doit(
const From *Val) {
88 assert(Val &&
"isa<> used on a null pointer");
94 static inline bool doit(
const From *Val) {
95 assert(Val &&
"isa<> used on a null pointer");
101 static inline bool doit(
const From *Val) {
102 assert(Val &&
"isa<> used on a null pointer");
107 template<
typename To,
typename From,
typename SimpleFrom>
111 static bool doit(
const From &Val) {
118 template<
typename To,
typename FromTy>
121 static bool doit(
const FromTy &Val) {
131 template <
class X,
class Y>
166 template<
class To,
class From,
class SimpleFrom>
174 template<
class To,
class FromTy>
180 template<
class To,
class From>
209 std::is_same<X, typename simplify_type<X>::SimpleType>
::value;
219 template <
class X,
class Y>
220 inline typename std::enable_if<!is_simple_type<Y>::value,
223 assert(isa<X>(Val) &&
"cast<Ty>() argument of incompatible type!");
228 template <
class X,
class Y>
230 assert(isa<X>(Val) &&
"cast<Ty>() argument of incompatible type!");
235 template <
class X,
class Y>
237 assert(isa<X>(Val) &&
"cast<Ty>() argument of incompatible type!");
245 template <
class X,
class Y>
247 !is_simple_type<Y>::value,
typename cast_retty<X, const Y>::ret_type>::type
251 assert(isa<X>(Val) &&
"cast_or_null<Ty>() argument of incompatible type!");
255 template <
class X,
class Y>
257 !is_simple_type<Y>::value,
typename cast_retty<X, Y>::ret_type>::type
261 assert(isa<X>(Val) &&
"cast_or_null<Ty>() argument of incompatible type!");
265 template <
class X,
class Y>
268 if (!Val)
return nullptr;
269 assert(isa<X>(Val) &&
"cast_or_null<Ty>() argument of incompatible type!");
282 template <
class X,
class Y>
284 !is_simple_type<Y>::value,
typename cast_retty<X, const Y>::ret_type>::type
286 return isa<X>(Val) ? cast<X>(Val) :
nullptr;
289 template <
class X,
class Y>
292 return isa<X>(Val) ? cast<X>(Val) :
nullptr;
295 template <
class X,
class Y>
298 return isa<X>(Val) ? cast<X>(Val) :
nullptr;
304 template <
class X,
class Y>
306 !is_simple_type<Y>::value,
typename cast_retty<X, const Y>::ret_type>::type
308 return (Val && isa<X>(Val)) ? cast<X>(Val) :
nullptr;
311 template <
class X,
class Y>
313 !is_simple_type<Y>::value,
typename cast_retty<X, Y>::ret_type>::type
315 return (Val && isa<X>(Val)) ? cast<X>(Val) :
nullptr;
318 template <
class X,
class Y>
321 return (Val && isa<X>(Val)) ? cast<X>(Val) :
nullptr;
static bool doit(const From *Val)
#define LLVM_ATTRIBUTE_UNUSED_RESULT
static cast_retty< To, FromTy >::ret_type doit(const FromTy &Val)
static RetType getSimplifiedValue(const From &Val)
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast_or_null(const Y &Val)
static bool doit(const From &Val)
static bool doit(const From &)
static bool doit(const From *Val)
static bool doit(const From &Val)
std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type cast(const Y &Val)
static cast_retty< To, From >::ret_type doit(From &Val)
static bool doit(const From *Val)
simplify_type< From >::SimpleType NonConstSimpleType
static bool doit(const From &Val)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
LLVM_ATTRIBUTE_UNUSED_RESULT bool isa(const Y &Val)
static bool doit(const From &Val)
add_lvalue_reference_if_not_pointer< SimpleType >::type RetType
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static bool doit(const FromTy &Val)
add_const_past_pointer< NonConstSimpleType >::type SimpleType
cast_retty_wrap< To, From, typename simplify_type< From >::SimpleType >::ret_type ret_type
cast_retty_impl< To, FromTy >::ret_type ret_type
cast_retty< To, SimpleFrom >::ret_type ret_type
static SimpleType & getSimplifiedValue(From &Val)
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type cast_or_null(const Y &Val)
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
static bool doit(const From *Val)