diff options
author | Chris Lattner <sabre@nondot.org> | 2001-11-26 16:46:45 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-11-26 16:46:45 +0000 |
commit | 7c0cdc0cc813b0db8bb1348590443d24534cda3d (patch) | |
tree | 7566a6546d84342ede4a2d47dcd369423e1215ce /include/llvm | |
parent | 6fa90497b0e838a720eb67b1a4accb6214eeb86f (diff) | |
download | external_llvm-7c0cdc0cc813b0db8bb1348590443d24534cda3d.zip external_llvm-7c0cdc0cc813b0db8bb1348590443d24534cda3d.tar.gz external_llvm-7c0cdc0cc813b0db8bb1348590443d24534cda3d.tar.bz2 |
Add new CompositeType shared baseclass of ArrayType and StructType
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1329 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm')
-rw-r--r-- | include/llvm/DerivedTypes.h | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/include/llvm/DerivedTypes.h b/include/llvm/DerivedTypes.h index 8c6b4a5..d98d333 100644 --- a/include/llvm/DerivedTypes.h +++ b/include/llvm/DerivedTypes.h @@ -145,7 +145,40 @@ public: }; -class ArrayType : public DerivedType { +// CompositeType - Common super class of ArrayType and StructType... +// +class CompositeType : public DerivedType { +protected: + inline CompositeType(const string &Name, PrimitiveID id) + : DerivedType(Name, id) { } + +public: + + // getTypeAtIndex - Given an index value into the type, return the type of the + // element. + // + virtual const Type *getTypeAtIndex(const Value *V) const = 0; + virtual bool indexValid(const Value *V) const = 0; + + // getIndexType - Return the type required of indices for this composite. + // For structures, this is ubyte, for arrays, this is uint + // + virtual const Type *getIndexType() const = 0; + + + // Methods for support type inquiry through isa, cast, and dyn_cast: + static inline bool classof(const CompositeType *T) { return true; } + static inline bool classof(const Type *T) { + return T->getPrimitiveID() == ArrayTyID || + T->getPrimitiveID() == StructTyID; + } + static inline bool classof(const Value *V) { + return isa<Type>(V) && classof(cast<const Type>(V)); + } +}; + + +class ArrayType : public CompositeType { private: PATypeHandle<Type> ElementType; int NumElements; // >= 0 for sized array, -1 for unbounded/unknown array @@ -173,6 +206,21 @@ public: } virtual unsigned getNumContainedTypes() const { return 1; } + // getTypeAtIndex - Given an index value into the type, return the type of the + // element. For an arraytype, there is only one subtype... + // + virtual const Type *getTypeAtIndex(const Value *V) const { + return ElementType.get(); + } + virtual bool indexValid(const Value *V) const { + return V->getType() == Type::UIntTy; // Must be an unsigned int index + } + + // getIndexType - Return the type required of indices for this composite. + // For structures, this is ubyte, for arrays, this is uint + // + virtual const Type *getIndexType() const { return Type::UIntTy; } + // refineAbstractType - Called when a contained type is found to be more // concrete - this could potentially change us from an abstract type to a // concrete type. @@ -192,7 +240,7 @@ public: }; -class StructType : public DerivedType { +class StructType : public CompositeType { public: typedef vector<PATypeHandle<Type> > ElementTypes; @@ -218,6 +266,17 @@ public: } virtual unsigned getNumContainedTypes() const { return ETypes.size(); } + // getTypeAtIndex - Given an index value into the type, return the type of the + // element. For a structure type, this must be a constant value... + // + virtual const Type *getTypeAtIndex(const Value *V) const ; + virtual bool indexValid(const Value *V) const; + + // getIndexType - Return the type required of indices for this composite. + // For structures, this is ubyte, for arrays, this is uint + // + virtual const Type *getIndexType() const { return Type::UByteTy; } + // refineAbstractType - Called when a contained type is found to be more // concrete - this could potentially change us from an abstract type to a // concrete type. |