From 0ec4146db70916c31281e091bb3b447aab497246 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 6 May 2009 17:12:48 +0000 Subject: [PATCH] Add simplify_type specializations to allow WeakVH, AssertingVH, and CallbackVH to participate in dyn_cast, isa, etc. without needing an explicit conversion. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71087 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/ValueHandle.h | 39 ++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/include/llvm/Support/ValueHandle.h b/include/llvm/Support/ValueHandle.h index 5c6fb74c1f5..a97a5e88142 100644 --- a/include/llvm/Support/ValueHandle.h +++ b/include/llvm/Support/ValueHandle.h @@ -126,8 +126,19 @@ public: operator Value*() const { return getValPtr(); } -}; - +}; + +// Specialize simplify_type to allow WeakVH to participate in +// dyn_cast, isa, etc. +template struct simplify_type; +template<> struct simplify_type { + typedef Value* SimpleType; + static SimpleType getSimplifiedValue(const WeakVH &WVH) { + return static_cast(WVH); + } +}; +template<> struct simplify_type : public simplify_type {}; + /// AssertingVH - This is a Value Handle that points to a value and asserts out /// if the value is destroyed while the handle is still live. This is very /// useful for catching dangling pointer bugs and other things which can be @@ -188,6 +199,18 @@ public: ValueTy &operator*() const { return *getValPtr(); } }; +// Specialize simplify_type to allow AssertingVH to participate in +// dyn_cast, isa, etc. +template struct simplify_type; +template<> struct simplify_type > { + typedef Value* SimpleType; + static SimpleType getSimplifiedValue(const AssertingVH &AVH) { + return static_cast(AVH); + } +}; +template<> struct simplify_type > + : public simplify_type > {}; + /// CallbackVH - This is a value handle that allows subclasses to define /// callbacks that run when the underlying Value has RAUW called on it or is /// destroyed. This class can be used as the key of a map, as long as the user @@ -232,6 +255,18 @@ public: virtual void allUsesReplacedWith(Value *new_value) {} }; +// Specialize simplify_type to allow CallbackVH to participate in +// dyn_cast, isa, etc. +template struct simplify_type; +template<> struct simplify_type { + typedef Value* SimpleType; + static SimpleType getSimplifiedValue(const CallbackVH &CVH) { + return static_cast(CVH); + } +}; +template<> struct simplify_type + : public simplify_type {}; + } // End llvm namespace #endif