Skip to content

Commit f35c5a5

Browse files
author
Dan Gohman
committed
Add simplify_type specializations to allow WeakVH, AssertingVH, and
CallbackVH to participate in dyn_cast, isa, etc. without needing an explicit conversion. llvm-svn: 71087
1 parent 49518d8 commit f35c5a5

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

llvm/include/llvm/Support/ValueHandle.h

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,19 @@ class WeakVH : public ValueHandleBase {
126126
operator Value*() const {
127127
return getValPtr();
128128
}
129-
};
130-
129+
};
130+
131+
// Specialize simplify_type to allow WeakVH to participate in
132+
// dyn_cast, isa, etc.
133+
template<typename From> struct simplify_type;
134+
template<> struct simplify_type<const WeakVH> {
135+
typedef Value* SimpleType;
136+
static SimpleType getSimplifiedValue(const WeakVH &WVH) {
137+
return static_cast<Value *>(WVH);
138+
}
139+
};
140+
template<> struct simplify_type<WeakVH> : public simplify_type<const WeakVH> {};
141+
131142
/// AssertingVH - This is a Value Handle that points to a value and asserts out
132143
/// if the value is destroyed while the handle is still live. This is very
133144
/// useful for catching dangling pointer bugs and other things which can be
@@ -188,6 +199,18 @@ class AssertingVH
188199
ValueTy &operator*() const { return *getValPtr(); }
189200
};
190201

202+
// Specialize simplify_type to allow AssertingVH to participate in
203+
// dyn_cast, isa, etc.
204+
template<typename From> struct simplify_type;
205+
template<> struct simplify_type<const AssertingVH<Value> > {
206+
typedef Value* SimpleType;
207+
static SimpleType getSimplifiedValue(const AssertingVH<Value> &AVH) {
208+
return static_cast<Value *>(AVH);
209+
}
210+
};
211+
template<> struct simplify_type<AssertingVH<Value> >
212+
: public simplify_type<const AssertingVH<Value> > {};
213+
191214
/// CallbackVH - This is a value handle that allows subclasses to define
192215
/// callbacks that run when the underlying Value has RAUW called on it or is
193216
/// destroyed. This class can be used as the key of a map, as long as the user
@@ -232,6 +255,18 @@ class CallbackVH : public ValueHandleBase {
232255
virtual void allUsesReplacedWith(Value *new_value) {}
233256
};
234257

258+
// Specialize simplify_type to allow CallbackVH to participate in
259+
// dyn_cast, isa, etc.
260+
template<typename From> struct simplify_type;
261+
template<> struct simplify_type<const CallbackVH> {
262+
typedef Value* SimpleType;
263+
static SimpleType getSimplifiedValue(const CallbackVH &CVH) {
264+
return static_cast<Value *>(CVH);
265+
}
266+
};
267+
template<> struct simplify_type<CallbackVH>
268+
: public simplify_type<const CallbackVH> {};
269+
235270
} // End llvm namespace
236271

237272
#endif

0 commit comments

Comments
 (0)