aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/Type.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-02-09 05:40:24 +0000
committerChris Lattner <sabre@nondot.org>2004-02-09 05:40:24 +0000
commitf32f56862a550fed2c943c4a4acadc56ce13ab07 (patch)
tree6209785f3b6effcbf5b63c204395a20c2a6dea8e /include/llvm/Type.h
parent68b86f4f41f7a6c1c7d13609b162f19222102257 (diff)
Now that all of the derived types have disciplined interfaces, we can eliminate
all of the ad-hoc storage of contained types. This allows getContainedType to not be virtual, and allows us to entirely delete the TypeIterator class. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11230 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Type.h')
-rw-r--r--include/llvm/Type.h70
1 files changed, 19 insertions, 51 deletions
diff --git a/include/llvm/Type.h b/include/llvm/Type.h
index ba4ac3415f..d18d7096d3 100644
--- a/include/llvm/Type.h
+++ b/include/llvm/Type.h
@@ -36,6 +36,7 @@
#include "llvm/Value.h"
#include "Support/GraphTraits.h"
#include "Support/iterator"
+#include <vector>
namespace llvm {
@@ -106,6 +107,15 @@ protected:
/// to the more refined type. Only abstract types can be forwarded.
mutable const Type *ForwardType;
+ /// ContainedTys - The list of types contained by this one. For example, this
+ /// includes the arguments of a function type, the elements of the structure,
+ /// the pointee of a pointer, etc. Note that keeping this vector in the Type
+ /// class wastes some space for types that do not contain anything (such as
+ /// primitive types). However, keeping it here allows the subtype_* members
+ /// to be implemented MUCH more efficiently, and dynamically very few types do
+ /// not contain any elements (most are derived).
+ std::vector<PATypeHandle> ContainedTys;
+
public:
virtual void print(std::ostream &O) const;
@@ -204,22 +214,22 @@ public:
//===--------------------------------------------------------------------===//
// Type Iteration support
//
- class TypeIterator;
- typedef TypeIterator subtype_iterator;
- inline subtype_iterator subtype_begin() const; // DEFINED BELOW
- inline subtype_iterator subtype_end() const; // DEFINED BELOW
+ typedef std::vector<PATypeHandle>::const_iterator subtype_iterator;
+ subtype_iterator subtype_begin() const { return ContainedTys.begin(); }
+ subtype_iterator subtype_end() const { return ContainedTys.end(); }
/// getContainedType - This method is used to implement the type iterator
/// (defined a the end of the file). For derived types, this returns the
/// types 'contained' in the derived type.
///
- virtual const Type *getContainedType(unsigned i) const {
- assert(0 && "No contained types!");
- return 0;
+ const Type *getContainedType(unsigned i) const {
+ assert(i < ContainedTys.size() && "Index out of range!");
+ return ContainedTys[i];
}
- /// getNumContainedTypes - Return the number of types in the derived type
- virtual unsigned getNumContainedTypes() const { return 0; }
+ /// getNumContainedTypes - Return the number of types in the derived type.
+ ///
+ unsigned getNumContainedTypes() const { return ContainedTys.size(); }
//===--------------------------------------------------------------------===//
// Static members exported by the Type class itself. Useful for getting
@@ -249,50 +259,8 @@ public:
}
#include "llvm/Type.def"
-
-private:
- class TypeIterator : public bidirectional_iterator<const Type, ptrdiff_t> {
- const Type * const Ty;
- unsigned Idx;
-
- typedef TypeIterator _Self;
- public:
- TypeIterator(const Type *ty, unsigned idx) : Ty(ty), Idx(idx) {}
- ~TypeIterator() {}
-
- const _Self &operator=(const _Self &RHS) {
- assert(Ty == RHS.Ty && "Cannot assign from different types!");
- Idx = RHS.Idx;
- return *this;
- }
-
- bool operator==(const _Self& x) const { return Idx == x.Idx; }
- bool operator!=(const _Self& x) const { return !operator==(x); }
-
- pointer operator*() const { return Ty->getContainedType(Idx); }
- pointer operator->() const { return operator*(); }
-
- _Self& operator++() { ++Idx; return *this; } // Preincrement
- _Self operator++(int) { // Postincrement
- _Self tmp = *this; ++*this; return tmp;
- }
-
- _Self& operator--() { --Idx; return *this; } // Predecrement
- _Self operator--(int) { // Postdecrement
- _Self tmp = *this; --*this; return tmp;
- }
- };
};
-inline Type::TypeIterator Type::subtype_begin() const {
- return TypeIterator(this, 0);
-}
-
-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...