aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/ADT
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-03-29 07:03:30 +0000
committerChris Lattner <sabre@nondot.org>2009-03-29 07:03:30 +0000
commitbfbb0e62ca30e60214a7423836c2a4ffc833bbde (patch)
treeee83cce56aba14d58f641d2614a5610b7eb78783 /include/llvm/ADT
parentc913e7242f319846697339610fb4f66512b1d669 (diff)
downloadexternal_llvm-bfbb0e62ca30e60214a7423836c2a4ffc833bbde.zip
external_llvm-bfbb0e62ca30e60214a7423836c2a4ffc833bbde.tar.gz
external_llvm-bfbb0e62ca30e60214a7423836c2a4ffc833bbde.tar.bz2
add some comments, add a dyn_cast method.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@67992 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT')
-rw-r--r--include/llvm/ADT/PointerUnion.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/llvm/ADT/PointerUnion.h b/include/llvm/ADT/PointerUnion.h
index 7a4de65..01272b8 100644
--- a/include/llvm/ADT/PointerUnion.h
+++ b/include/llvm/ADT/PointerUnion.h
@@ -78,18 +78,34 @@ namespace llvm {
Val.setInt(1);
}
+ /// isNull - Return true if the pointer help in the union is null,
+ /// regardless of which type it is.
bool isNull() const { return Val.getPointer() == 0; }
+ /// is<T>() return true if the Union currently holds the type matching T.
template<typename T>
int is() const {
return Val.getInt() == ::llvm::getPointerUnionTypeNum<PT1, PT2>((T*)0);
}
+
+ /// get<T>() - Return the value of the specified pointer type. If the
+ /// specified pointer type is incorrect, assert.
template<typename T>
T get() const {
assert(is<T>() && "Invalid accessor called");
return static_cast<T>(Val.getPointer());
}
+ /// dyn_cast<T>() - If the current value is of the specified pointer type,
+ /// return it, otherwise return null.
+ template<typename T>
+ T dyn_cast() const {
+ if (is<T>()) return static_cast<T>(Val.getPointer());
+ return T();
+ }
+
+ /// Assignment operators - Allow assigning into this union from either
+ /// pointer type, setting the discriminator to remember what it came from.
const PointerUnion &operator=(const PT1 &RHS) {
Val.setPointer(RHS);
Val.setInt(0);