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) {
165 template<
class To,
class From,
class SimpleFrom>
173 template<
class To,
class FromTy>
179 template<
class To,
class From>
208 std::is_same<X, typename simplify_type<X>::SimpleType>
::value;
218 template <
class X,
class Y>
219 inline typename std::enable_if<!is_simple_type<Y>::value,
222 assert(isa<X>(Val) &&
"cast<Ty>() argument of incompatible type!");
227 template <
class X,
class Y>
229 assert(isa<X>(Val) &&
"cast<Ty>() argument of incompatible type!");
234 template <
class X,
class Y>
236 assert(isa<X>(Val) &&
"cast<Ty>() argument of incompatible type!");
244 template <
class X,
class Y>
246 typename std::enable_if<!is_simple_type<Y>::value,
247 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 typename std::enable_if<!is_simple_type<Y>::value,
258 typename cast_retty<X, Y>::ret_type>::type
262 assert(isa<X>(Val) &&
"cast_or_null<Ty>() argument of incompatible type!");
266 template <
class X,
class Y>
269 if (!Val)
return nullptr;
270 assert(isa<X>(Val) &&
"cast_or_null<Ty>() argument of incompatible type!");
283 template <
class X,
class Y>
285 typename std::enable_if<!is_simple_type<Y>::value,
286 typename cast_retty<X, const Y>::ret_type>::type
288 return isa<X>(Val) ? cast<X>(Val) :
nullptr;
291 template <
class X,
class Y>
293 return isa<X>(Val) ? cast<X>(Val) :
nullptr;
296 template <
class X,
class Y>
298 return isa<X>(Val) ? cast<X>(Val) :
nullptr;
304 template <
class X,
class Y>
306 typename std::enable_if<!is_simple_type<Y>::value,
307 typename cast_retty<X, const Y>::ret_type>::type
309 return (Val && isa<X>(Val)) ? cast<X>(Val) :
nullptr;
312 template <
class X,
class Y>
314 typename std::enable_if<!is_simple_type<Y>::value,
315 typename cast_retty<X, Y>::ret_type>::type
317 return (Val && isa<X>(Val)) ? cast<X>(Val) :
nullptr;
320 template <
class X,
class Y>
323 return (Val && isa<X>(Val)) ? cast<X>(Val) :
nullptr;
static bool doit(const From *Val)
static cast_retty< To, FromTy >::ret_type doit(const FromTy &Val)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type cast_or_null(const Y &Val)
static RetType getSimplifiedValue(const From &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_NODISCARD 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)
add_lvalue_reference_if_not_pointer< SimpleType >::type RetType
LLVM_NODISCARD bool isa(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
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static SimpleType & getSimplifiedValue(From &Val)
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
static bool doit(const From *Val)