-//===-- Support/Casting.h - Allow flexible, checked, casts -------*- C++ -*--=//
+//===-- llvm/Support/Casting.h - Allow flexible, checked, casts -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
//
// This file defines the isa<X>(), cast<X>(), dyn_cast<X>(), cast_or_null<X>(),
// and dyn_cast_or_null<X>() templates.
//
//===----------------------------------------------------------------------===//
-#ifndef SUPPORT_CASTING_H
-#define SUPPORT_CASTING_H
+#ifndef LLVM_SUPPORT_CASTING_H
+#define LLVM_SUPPORT_CASTING_H
+
+namespace llvm {
//===----------------------------------------------------------------------===//
// isa<x> Support Templates
template<typename From> struct simplify_type<const From> {
typedef const From SimpleType;
static SimpleType &getSimplifiedValue(const From &Val) {
- return simplify_type<From>::getSimplifiedValue((From&)Val);
+ return simplify_type<From>::getSimplifiedValue(static_cast<From&>(Val));
}
};
};
// isa_impl_cl - Use class partial specialization to transform types to a single
-// cannonical form for isa_impl.
+// canonical form for isa_impl.
//
template<typename FromCl>
struct isa_impl_cl {
template<class To, class FromTy> struct cast_convert_val<To,FromTy,FromTy> {
// This _is_ a simple type, just cast it.
static typename cast_retty<To, FromTy>::ret_type doit(const FromTy &Val) {
- return (typename cast_retty<To, FromTy>::ret_type)Val;
+ return reinterpret_cast<typename cast_retty<To, FromTy>::ret_type>(
+ const_cast<FromTy&>(Val));
}
};
//
template <class X, class Y>
inline typename cast_retty<X, Y>::ret_type cast(const Y &Val) {
- assert(isa<X>(Val) && "cast<Ty>() argument of uncompatible type!");
+ assert(isa<X>(Val) && "cast<Ty>() argument of incompatible type!");
return cast_convert_val<X, Y,
typename simplify_type<Y>::SimpleType>::doit(Val);
}
template <class X, class Y>
inline typename cast_retty<X, Y*>::ret_type cast_or_null(Y *Val) {
if (Val == 0) return 0;
- assert(isa<X>(Val) && "cast_or_null<Ty>() argument of uncompatible type!");
+ assert(isa<X>(Val) && "cast_or_null<Ty>() argument of incompatible type!");
return cast<X>(Val);
}
#endif
+} // End llvm namespace
+
#endif