diff options
Diffstat (limited to 'include/llvm/Type.h')
-rw-r--r-- | include/llvm/Type.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/include/llvm/Type.h b/include/llvm/Type.h index ed39d120ec..5854062df0 100644 --- a/include/llvm/Type.h +++ b/include/llvm/Type.h @@ -27,6 +27,7 @@ #define LLVM_TYPE_H #include "llvm/Value.h" +#include "llvm/Support/GraphTraits.h" class DerivedType; class MethodType; @@ -264,4 +265,34 @@ inline Type::TypeIterator Type::subtype_end() const { return TypeIterator(this, getNumContainedTypes()); } + +// Provide specializations of GraphTraits to be able to treat a type as a +// graph of sub types... + +template <> struct GraphTraits<Type*> { + typedef Type NodeType; + typedef Type::subtype_iterator ChildIteratorType; + + static inline NodeType *getEntryNode(Type *T) { return T; } + static inline ChildIteratorType child_begin(NodeType *N) { + return N->subtype_begin(); + } + static inline ChildIteratorType child_end(NodeType *N) { + return N->subtype_end(); + } +}; + +template <> struct GraphTraits<const Type*> { + typedef const Type NodeType; + typedef Type::subtype_iterator ChildIteratorType; + + static inline NodeType *getEntryNode(const Type *T) { return T; } + static inline ChildIteratorType child_begin(NodeType *N) { + return N->subtype_begin(); + } + static inline ChildIteratorType child_end(NodeType *N) { + return N->subtype_end(); + } +}; + #endif |