From 7c0cdc0cc813b0db8bb1348590443d24534cda3d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 26 Nov 2001 16:46:45 +0000 Subject: [PATCH] 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 --- include/llvm/DerivedTypes.h | 63 +++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/include/llvm/DerivedTypes.h b/include/llvm/DerivedTypes.h index 8c6b4a533b7..d98d3336325 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(V) && classof(cast(V)); + } +}; + + +class ArrayType : public CompositeType { private: PATypeHandle 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 > 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. -- 2.34.1