[llvm-commits] [llvm] r71087 - /llvm/trunk/include/llvm/Support/ValueHandle.h

Dan Gohman gohman at apple.com
Wed May 6 10:12:50 PDT 2009


Author: djg
Date: Wed May  6 12:12:48 2009
New Revision: 71087

URL: http://llvm.org/viewvc/llvm-project?rev=71087&view=rev
Log:
Add simplify_type specializations to allow WeakVH, AssertingVH, and
CallbackVH to participate in dyn_cast, isa, etc. without needing
an explicit conversion.

Modified:
    llvm/trunk/include/llvm/Support/ValueHandle.h

Modified: llvm/trunk/include/llvm/Support/ValueHandle.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ValueHandle.h?rev=71087&r1=71086&r2=71087&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/ValueHandle.h (original)
+++ llvm/trunk/include/llvm/Support/ValueHandle.h Wed May  6 12:12:48 2009
@@ -126,8 +126,19 @@
   operator Value*() const {
     return getValPtr();
   }
-};  
-  
+};
+
+// Specialize simplify_type to allow WeakVH to participate in
+// dyn_cast, isa, etc.
+template<typename From> struct simplify_type;
+template<> struct simplify_type<const WeakVH> {
+  typedef Value* SimpleType;
+  static SimpleType getSimplifiedValue(const WeakVH &WVH) {
+    return static_cast<Value *>(WVH);
+  }
+};
+template<> struct simplify_type<WeakVH> : public simplify_type<const WeakVH> {};
+
 /// 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 @@
   ValueTy &operator*() const { return *getValPtr(); }
 };
 
+// Specialize simplify_type to allow AssertingVH to participate in
+// dyn_cast, isa, etc.
+template<typename From> struct simplify_type;
+template<> struct simplify_type<const AssertingVH<Value> > {
+  typedef Value* SimpleType;
+  static SimpleType getSimplifiedValue(const AssertingVH<Value> &AVH) {
+    return static_cast<Value *>(AVH);
+  }
+};
+template<> struct simplify_type<AssertingVH<Value> >
+  : public simplify_type<const AssertingVH<Value> > {};
+
 /// 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 @@
   virtual void allUsesReplacedWith(Value *new_value) {}
 };
 
+// Specialize simplify_type to allow CallbackVH to participate in
+// dyn_cast, isa, etc.
+template<typename From> struct simplify_type;
+template<> struct simplify_type<const CallbackVH> {
+  typedef Value* SimpleType;
+  static SimpleType getSimplifiedValue(const CallbackVH &CVH) {
+    return static_cast<Value *>(CVH);
+  }
+};
+template<> struct simplify_type<CallbackVH>
+  : public simplify_type<const CallbackVH> {};
+
 } // End llvm namespace
 
 #endif





More information about the llvm-commits mailing list