Add cast_or_null & dyn_cast_or_null

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@824 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2001-10-15 13:41:37 +00:00
parent 39bb5b4ee9
commit 3ef77fcd55

View File

@ -204,8 +204,17 @@ inline bool isa(Y Val) {
//
template <class X, class Y>
inline X *cast(Y Val) {
assert(isa<X>(Val) && "cast<Ty>() argument of uncompatible type!");
return (X*)(real_type<Y>::Type)Val;
}
// cast_or_null<X> - Functionally identical to cast, except that a null value is
// accepted.
//
template <class X, class Y>
inline X *cast_or_null(Y Val) {
assert((Val == 0 || isa<X>(Val)) &&
"cast<Ty>() argument of uncompatible type!");
"cast_or_null<Ty>() argument of uncompatible type!");
return (X*)(real_type<Y>::Type)Val;
}
@ -223,6 +232,16 @@ inline X *dyn_cast(Y Val) {
return isa<X>(Val) ? cast<X>(Val) : 0;
}
// dyn_cast_or_null<X> - Functionally identical to dyn_cast, except that a null
// value is accepted.
//
template <class X, class Y>
inline X *dyn_cast_or_null(Y Val) {
assert((Val == 0 || isa<X>(Val)) &&
"cast_or_null<Ty>() argument of uncompatible type!");
return (Val && isa<X>(Val)) ? cast<X>(Val) : 0;
}
// isa - Provide some specializations of isa so that we have to include the
// subtype header files to test to see if the value is a subclass...