// if I am a type, and I get resolved into a more concrete type.
//
///// FIXME: kill mutable nonsense when Type's are not const
- mutable vector<AbstractTypeUser *> AbstractTypeUsers;
+ mutable std::vector<AbstractTypeUser *> AbstractTypeUsers;
char isRefining; // Used for recursive types
protected:
- inline DerivedType(const string &Name, PrimitiveID id) : Type(Name, id) {
+ inline DerivedType(PrimitiveID id) : Type("", id) {
isRefining = false;
}
class MethodType : public DerivedType {
public:
- typedef vector<PATypeHandle<Type> > ParamTypes;
+ typedef std::vector<PATypeHandle<Type> > ParamTypes;
private:
PATypeHandle<Type> ResultType;
ParamTypes ParamTys;
// defines private constructors and has no friends
// Private ctor - Only can be created by a static member...
- MethodType(const Type *Result, const vector<const Type*> &Params,
+ MethodType(const Type *Result, const std::vector<const Type*> &Params,
bool IsVarArgs);
public:
//
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
- static MethodType *get(const Type *Result, const vector<const Type*> &Params,
+ static MethodType *get(const Type *Result,
+ const std::vector<const Type*> &Params,
bool isVarArg);
};
-class ArrayType : public DerivedType {
-private:
- PATypeHandle<Type> ElementType;
- int NumElements; // >= 0 for sized array, -1 for unbounded/unknown array
-
- ArrayType(const ArrayType &); // Do not implement
- const ArrayType &operator=(const ArrayType &); // Do not implement
+// CompositeType - Common super class of ArrayType, StructType, and PointerType
+//
+class CompositeType : public DerivedType {
protected:
- // This should really be private, but it squelches a bogus warning
- // from GCC to make them protected: warning: `class ArrayType' only
- // defines private constructors and has no friends
-
-
- // Private ctor - Only can be created by a static member...
- ArrayType(const Type *ElType, int NumEl);
+ inline CompositeType(PrimitiveID id) : DerivedType(id) { }
public:
- inline const Type *getElementType() const { return ElementType; }
- inline int getNumElements() const { return NumElements; }
-
- inline bool isSized() const { return NumElements >= 0; }
- inline bool isUnsized() const { return NumElements == -1; }
-
- virtual const Type *getContainedType(unsigned i) const {
- return i == 0 ? ElementType.get() : 0;
- }
- virtual unsigned getNumContainedTypes() const { return 1; }
+ // 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;
- // 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.
+ // getIndexType - Return the type required of indices for this composite.
+ // For structures, this is ubyte, for arrays, this is uint
//
- virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
+ virtual const Type *getIndexType() const = 0;
- static ArrayType *get(const Type *ElementType, int NumElements = -1);
// Methods for support type inquiry through isa, cast, and dyn_cast:
- static inline bool classof(const ArrayType *T) { return true; }
+ static inline bool classof(const CompositeType *T) { return true; }
static inline bool classof(const Type *T) {
- return T->getPrimitiveID() == ArrayTyID;
+ return T->getPrimitiveID() == ArrayTyID ||
+ T->getPrimitiveID() == StructTyID ||
+ T->getPrimitiveID() == PointerTyID;
}
static inline bool classof(const Value *V) {
return isa<Type>(V) && classof(cast<const Type>(V));
};
-class StructType : public DerivedType {
+class StructType : public CompositeType {
public:
- typedef vector<PATypeHandle<Type> > ElementTypes;
+ typedef std::vector<PATypeHandle<Type> > ElementTypes;
private:
ElementTypes ETypes; // Element types of struct
// defines private constructors and has no friends
// Private ctor - Only can be created by a static member...
- StructType(const vector<const Type*> &Types);
+ StructType(const std::vector<const Type*> &Types);
public:
inline const ElementTypes &getElementTypes() const { return ETypes; }
}
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.
//
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
- static StructType *get(const vector<const Type*> &Params);
+ static StructType *get(const std::vector<const Type*> &Params);
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const StructType *T) { return true; }
};
-class PointerType : public DerivedType {
-private:
- PATypeHandle<Type> ValueType;
+// SequentialType - This is the superclass of the array and pointer type
+// classes. Both of these represent "arrays" in memory. The array type
+// represents a specifically sized array, pointer types are unsized/unknown size
+// arrays. SequentialType holds the common features of both, which stem from
+// the fact that both lay their components out in memory identically.
+//
+class SequentialType : public CompositeType {
+ SequentialType(const SequentialType &); // Do not implement!
+ const SequentialType &operator=(const SequentialType &); // Do not implement!
+protected:
+ PATypeHandle<Type> ElementType;
- PointerType(const PointerType &); // Do not implement
- const PointerType &operator=(const PointerType &); // Do not implement
+ SequentialType(PrimitiveID TID, const Type *ElType)
+ : CompositeType(TID), ElementType(PATypeHandle<Type>(ElType, this)) {
+ }
+public:
+
+ inline const Type *getElementType() const { return ElementType; }
+
+ virtual const Type *getContainedType(unsigned i) const {
+ return i == 0 ? ElementType.get() : 0;
+ }
+ virtual unsigned getNumContainedTypes() const { return 1; }
+
+ // getTypeAtIndex - Given an index value into the type, return the type of the
+ // element. For sequential types, 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; }
+
+ // Methods for support type inquiry through isa, cast, and dyn_cast:
+ static inline bool classof(const SequentialType *T) { return true; }
+ static inline bool classof(const Type *T) {
+ return T->getPrimitiveID() == ArrayTyID ||
+ T->getPrimitiveID() == PointerTyID;
+ }
+ static inline bool classof(const Value *V) {
+ return isa<Type>(V) && classof(cast<const Type>(V));
+ }
+};
+
+
+class ArrayType : public SequentialType {
+ unsigned NumElements;
+
+ ArrayType(const ArrayType &); // Do not implement
+ const ArrayType &operator=(const ArrayType &); // Do not implement
protected:
// This should really be private, but it squelches a bogus warning
- // from GCC to make them protected: warning: `class PointerType' only
+ // from GCC to make them protected: warning: `class ArrayType' only
// defines private constructors and has no friends
// Private ctor - Only can be created by a static member...
- PointerType(const Type *ElType);
-
+ ArrayType(const Type *ElType, unsigned NumEl);
public:
+ inline unsigned getNumElements() const { return NumElements; }
+
+ // 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.
+ //
+ virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
- inline const Type *getValueType() const { return ValueType; }
+ static ArrayType *get(const Type *ElementType, unsigned NumElements);
- virtual const Type *getContainedType(unsigned i) const {
- return i == 0 ? ValueType.get() : 0;
+ // Methods for support type inquiry through isa, cast, and dyn_cast:
+ static inline bool classof(const ArrayType *T) { return true; }
+ static inline bool classof(const Type *T) {
+ return T->getPrimitiveID() == ArrayTyID;
}
- virtual unsigned getNumContainedTypes() const { return 1; }
+ static inline bool classof(const Value *V) {
+ return isa<Type>(V) && classof(cast<const Type>(V));
+ }
+};
+
+
+class PointerType : public SequentialType {
+ PointerType(const PointerType &); // Do not implement
+ const PointerType &operator=(const PointerType &); // Do not implement
+protected:
+ // This should really be private, but it squelches a bogus warning
+ // from GCC to make them protected: warning: `class PointerType' only
+ // defines private constructors and has no friends
+
+
+ // Private ctor - Only can be created by a static member...
+ PointerType(const Type *ElType);
+public:
+ // PointerType::get - Named constructor for pointer types...
static PointerType *get(const Type *ElementType);
// refineAbstractType - Called when a contained type is found to be more
// the code. Hence this bit of uglyness.
//
template <class TypeSubClass> void PATypeHandle<TypeSubClass>::addUser() {
+ assert(Ty && "Type Handle has a null type!");
if (Ty->isAbstract())
cast<DerivedType>(Ty)->addAbstractTypeUser(User);
}
cast<DerivedType>(Ty)->removeAbstractTypeUser(User);
}
+template <class TypeSubClass>
+void PATypeHandle<TypeSubClass>::removeUserFromConcrete() {
+ if (!Ty->isAbstract())
+ cast<DerivedType>(Ty)->removeAbstractTypeUser(User);
+}
+
#endif