2003-09-30 18:37:50 +00:00
|
|
|
//===-- llvm/DerivedTypes.h - Classes for handling data types ---*- C++ -*-===//
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
|
|
|
// This file contains the declarations of classes that represent "derived
|
|
|
|
// types". These are things like "arrays of x" or "structure of x, y, z" or
|
|
|
|
// "method returning x taking (y,z) as parameters", etc...
|
|
|
|
//
|
|
|
|
// The implementations of these classes live in the Type.cpp file.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_DERIVED_TYPES_H
|
|
|
|
#define LLVM_DERIVED_TYPES_H
|
|
|
|
|
|
|
|
#include "llvm/Type.h"
|
|
|
|
|
2003-09-05 02:30:18 +00:00
|
|
|
template<class ValType, class TypeClass> class TypeMap;
|
|
|
|
class FunctionValType;
|
|
|
|
class ArrayValType;
|
|
|
|
class StructValType;
|
|
|
|
class PointerValType;
|
|
|
|
|
2003-10-02 19:44:23 +00:00
|
|
|
class DerivedType : public Type, public AbstractTypeUser {
|
2003-10-02 23:35:57 +00:00
|
|
|
/// RefCount - This counts the number of PATypeHolders that are pointing to
|
|
|
|
/// this type. When this number falls to zero, if the type is abstract and
|
|
|
|
/// has no AbstractTypeUsers, the type is deleted.
|
|
|
|
///
|
|
|
|
mutable unsigned RefCount;
|
|
|
|
|
2001-09-07 16:19:29 +00:00
|
|
|
// AbstractTypeUsers - Implement a list of the users that need to be notified
|
|
|
|
// if I am a type, and I get resolved into a more concrete type.
|
|
|
|
//
|
|
|
|
///// FIXME: kill mutable nonsense when Type's are not const
|
2002-01-20 22:54:45 +00:00
|
|
|
mutable std::vector<AbstractTypeUser *> AbstractTypeUsers;
|
2001-09-07 16:19:29 +00:00
|
|
|
|
|
|
|
protected:
|
2003-10-03 18:46:24 +00:00
|
|
|
DerivedType(PrimitiveID id) : Type("", id), RefCount(0) {
|
2002-04-05 22:21:08 +00:00
|
|
|
}
|
|
|
|
~DerivedType() {
|
|
|
|
assert(AbstractTypeUsers.empty());
|
2001-09-07 16:19:29 +00:00
|
|
|
}
|
|
|
|
|
2003-10-03 18:46:24 +00:00
|
|
|
/// notifyUsesThatTypeBecameConcrete - Notify AbstractTypeUsers of this type
|
|
|
|
/// that the current type has transitioned from being abstract to being
|
|
|
|
/// concrete.
|
|
|
|
///
|
|
|
|
void notifyUsesThatTypeBecameConcrete();
|
2003-09-05 02:15:36 +00:00
|
|
|
|
|
|
|
// dropAllTypeUses - When this (abstract) type is resolved to be equal to
|
|
|
|
// another (more concrete) type, we must eliminate all references to other
|
2003-10-03 18:57:54 +00:00
|
|
|
// types, to avoid some circular reference problems.
|
|
|
|
virtual void dropAllTypeUses() = 0;
|
2001-09-07 16:19:29 +00:00
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
public:
|
2001-09-07 16:19:29 +00:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Abstract Type handling methods - These types have special lifetimes, which
|
|
|
|
// are managed by (add|remove)AbstractTypeUser. See comments in
|
|
|
|
// AbstractTypeUser.h for more information.
|
|
|
|
|
|
|
|
// addAbstractTypeUser - Notify an abstract type that there is a new user of
|
|
|
|
// it. This function is called primarily by the PATypeHandle class.
|
|
|
|
//
|
2003-10-02 23:35:57 +00:00
|
|
|
void addAbstractTypeUser(AbstractTypeUser *U) const {
|
|
|
|
assert(isAbstract() && "addAbstractTypeUser: Current type not abstract!");
|
|
|
|
AbstractTypeUsers.push_back(U);
|
|
|
|
}
|
2001-09-07 16:19:29 +00:00
|
|
|
|
|
|
|
// removeAbstractTypeUser - Notify an abstract type that a user of the class
|
|
|
|
// no longer has a handle to the type. This function is called primarily by
|
|
|
|
// the PATypeHandle class. When there are no users of the abstract type, it
|
2003-09-01 16:35:30 +00:00
|
|
|
// is annihilated, because there is no way to get a reference to it ever
|
|
|
|
// again.
|
2001-09-07 16:19:29 +00:00
|
|
|
//
|
|
|
|
void removeAbstractTypeUser(AbstractTypeUser *U) const;
|
|
|
|
|
|
|
|
// refineAbstractTypeTo - This function is used to when it is discovered that
|
|
|
|
// the 'this' abstract type is actually equivalent to the NewType specified.
|
|
|
|
// This causes all users of 'this' to switch to reference the more concrete
|
|
|
|
// type NewType and for 'this' to be deleted.
|
|
|
|
//
|
2003-10-03 18:57:54 +00:00
|
|
|
void refineAbstractTypeTo(const Type *NewType);
|
2001-10-01 18:26:53 +00:00
|
|
|
|
2003-10-02 23:35:57 +00:00
|
|
|
void addRef() const {
|
|
|
|
assert(isAbstract() && "Cannot add a reference to a non-abstract type!");
|
|
|
|
++RefCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dropRef() const {
|
|
|
|
assert(isAbstract() && "Cannot drop a refernce to a non-abstract type!");
|
|
|
|
assert(RefCount && "No objects are currently referencing this object!");
|
|
|
|
|
|
|
|
// If this is the last PATypeHolder using this object, and there are no
|
|
|
|
// PATypeHandles using it, the type is dead, delete it now.
|
|
|
|
if (--RefCount == 0 && AbstractTypeUsers.empty())
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-02 19:44:23 +00:00
|
|
|
void dump() const { Value::dump(); }
|
|
|
|
|
2001-10-01 18:26:53 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const DerivedType *T) { return true; }
|
|
|
|
static inline bool classof(const Type *T) {
|
2001-10-01 18:26:53 +00:00
|
|
|
return T->isDerivedType();
|
|
|
|
}
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const Value *V) {
|
2002-06-25 16:12:52 +00:00
|
|
|
return isa<Type>(V) && classof(cast<Type>(V));
|
2001-10-01 18:26:53 +00:00
|
|
|
}
|
2001-09-07 16:19:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-09-01 16:38:43 +00:00
|
|
|
struct FunctionType : public DerivedType {
|
2003-06-18 19:22:36 +00:00
|
|
|
typedef std::vector<PATypeHandle> ParamTypes;
|
2003-09-05 02:30:18 +00:00
|
|
|
friend class TypeMap<FunctionValType, FunctionType>;
|
2001-06-06 20:29:01 +00:00
|
|
|
private:
|
2003-06-18 19:22:36 +00:00
|
|
|
PATypeHandle ResultType;
|
2001-06-06 20:29:01 +00:00
|
|
|
ParamTypes ParamTys;
|
2001-07-25 22:47:55 +00:00
|
|
|
bool isVarArgs;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2002-03-29 03:15:32 +00:00
|
|
|
FunctionType(const FunctionType &); // Do not implement
|
|
|
|
const FunctionType &operator=(const FunctionType &); // Do not implement
|
2001-06-06 20:29:01 +00:00
|
|
|
protected:
|
|
|
|
// This should really be private, but it squelches a bogus warning
|
2002-03-29 03:15:32 +00:00
|
|
|
// from GCC to make them protected: warning: `class FunctionType' only
|
2001-06-06 20:29:01 +00:00
|
|
|
// defines private constructors and has no friends
|
|
|
|
|
|
|
|
// Private ctor - Only can be created by a static member...
|
2002-03-29 03:15:32 +00:00
|
|
|
FunctionType(const Type *Result, const std::vector<const Type*> &Params,
|
|
|
|
bool IsVarArgs);
|
2001-09-07 16:19:29 +00:00
|
|
|
|
2003-09-05 02:15:36 +00:00
|
|
|
// dropAllTypeUses - When this (abstract) type is resolved to be equal to
|
|
|
|
// another (more concrete) type, we must eliminate all references to other
|
2003-10-03 18:57:54 +00:00
|
|
|
// types, to avoid some circular reference problems.
|
|
|
|
virtual void dropAllTypeUses();
|
2003-09-05 02:15:36 +00:00
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
public:
|
2003-10-03 18:46:24 +00:00
|
|
|
/// FunctionType::get - This static method is the primary way of constructing
|
|
|
|
/// a FunctionType
|
|
|
|
static FunctionType *get(const Type *Result,
|
|
|
|
const std::vector<const Type*> &Params,
|
|
|
|
bool isVarArg);
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-07-25 22:47:55 +00:00
|
|
|
inline bool isVarArg() const { return isVarArgs; }
|
2001-06-06 20:29:01 +00:00
|
|
|
inline const Type *getReturnType() const { return ResultType; }
|
|
|
|
inline const ParamTypes &getParamTypes() const { return ParamTys; }
|
|
|
|
|
2002-03-29 19:04:19 +00:00
|
|
|
// Parameter type accessors...
|
|
|
|
const Type *getParamType(unsigned i) const { return ParamTys[i]; }
|
|
|
|
|
|
|
|
// getNumParams - Return the number of fixed parameters this function type
|
|
|
|
// requires. This does not consider varargs.
|
|
|
|
//
|
|
|
|
unsigned getNumParams() const { return ParamTys.size(); }
|
|
|
|
|
2001-09-07 16:19:29 +00:00
|
|
|
|
|
|
|
virtual const Type *getContainedType(unsigned i) const {
|
2001-10-13 06:12:30 +00:00
|
|
|
return i == 0 ? ResultType :
|
|
|
|
(i <= ParamTys.size() ? ParamTys[i-1].get() : 0);
|
2001-07-20 19:09:11 +00:00
|
|
|
}
|
2001-09-07 16:19:29 +00:00
|
|
|
virtual unsigned getNumContainedTypes() const { return ParamTys.size()+1; }
|
|
|
|
|
2003-10-03 18:46:24 +00:00
|
|
|
// Implement the AbstractTypeUser interface.
|
2001-09-07 16:19:29 +00:00
|
|
|
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
|
2003-10-03 18:46:24 +00:00
|
|
|
virtual void typeBecameConcrete(const DerivedType *AbsTy);
|
|
|
|
|
2001-10-01 16:18:37 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2002-03-29 03:15:32 +00:00
|
|
|
static inline bool classof(const FunctionType *T) { return true; }
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const Type *T) {
|
2002-03-29 03:44:36 +00:00
|
|
|
return T->getPrimitiveID() == FunctionTyID;
|
2001-10-01 16:18:37 +00:00
|
|
|
}
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const Value *V) {
|
2003-07-23 15:30:06 +00:00
|
|
|
return isa<Type>(V) && classof(cast<Type>(V));
|
2001-10-01 16:18:37 +00:00
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-12-14 16:20:21 +00:00
|
|
|
// CompositeType - Common super class of ArrayType, StructType, and PointerType
|
2001-11-26 16:46:45 +00:00
|
|
|
//
|
|
|
|
class CompositeType : public DerivedType {
|
|
|
|
protected:
|
2001-12-14 16:20:21 +00:00
|
|
|
inline CompositeType(PrimitiveID id) : DerivedType(id) { }
|
2001-11-26 16:46:45 +00:00
|
|
|
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 ||
|
2001-12-14 16:20:21 +00:00
|
|
|
T->getPrimitiveID() == StructTyID ||
|
|
|
|
T->getPrimitiveID() == PointerTyID;
|
2001-11-26 16:46:45 +00:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
2003-07-23 15:30:06 +00:00
|
|
|
return isa<Type>(V) && classof(cast<Type>(V));
|
2001-11-26 16:46:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-09-05 02:30:18 +00:00
|
|
|
struct StructType : public CompositeType {
|
|
|
|
friend class TypeMap<StructValType, StructType>;
|
2003-06-18 19:22:36 +00:00
|
|
|
typedef std::vector<PATypeHandle> ElementTypes;
|
2001-12-14 16:20:21 +00:00
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
private:
|
2001-12-14 16:20:21 +00:00
|
|
|
ElementTypes ETypes; // Element types of struct
|
|
|
|
|
|
|
|
StructType(const StructType &); // Do not implement
|
|
|
|
const StructType &operator=(const StructType &); // Do not implement
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// This should really be private, but it squelches a bogus warning
|
2001-12-14 16:20:21 +00:00
|
|
|
// from GCC to make them protected: warning: `class StructType' only
|
2001-06-06 20:29:01 +00:00
|
|
|
// defines private constructors and has no friends
|
|
|
|
|
|
|
|
// Private ctor - Only can be created by a static member...
|
2002-01-20 22:54:45 +00:00
|
|
|
StructType(const std::vector<const Type*> &Types);
|
2003-09-05 02:15:36 +00:00
|
|
|
|
|
|
|
// dropAllTypeUses - When this (abstract) type is resolved to be equal to
|
|
|
|
// another (more concrete) type, we must eliminate all references to other
|
2003-10-03 18:57:54 +00:00
|
|
|
// types, to avoid some circular reference problems.
|
|
|
|
virtual void dropAllTypeUses();
|
2001-12-14 16:20:21 +00:00
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
public:
|
2003-10-03 18:46:24 +00:00
|
|
|
/// StructType::get - This static method is the primary way to create a
|
|
|
|
/// StructType.
|
|
|
|
static StructType *get(const std::vector<const Type*> &Params);
|
|
|
|
|
2001-12-14 16:20:21 +00:00
|
|
|
inline const ElementTypes &getElementTypes() const { return ETypes; }
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-09-07 16:19:29 +00:00
|
|
|
virtual const Type *getContainedType(unsigned i) const {
|
2001-12-14 16:20:21 +00:00
|
|
|
return i < ETypes.size() ? ETypes[i].get() : 0;
|
2001-07-20 19:09:11 +00:00
|
|
|
}
|
2001-12-14 16:20:21 +00:00
|
|
|
virtual unsigned getNumContainedTypes() const { return ETypes.size(); }
|
2001-09-07 16:19:29 +00:00
|
|
|
|
2001-11-26 16:46:45 +00:00
|
|
|
// getTypeAtIndex - Given an index value into the type, return the type of the
|
2001-12-14 16:20:21 +00:00
|
|
|
// element. For a structure type, this must be a constant value...
|
2001-11-26 16:46:45 +00:00
|
|
|
//
|
2001-12-14 16:20:21 +00:00
|
|
|
virtual const Type *getTypeAtIndex(const Value *V) const ;
|
|
|
|
virtual bool indexValid(const Value *V) const;
|
2001-11-26 16:46:45 +00:00
|
|
|
|
|
|
|
// getIndexType - Return the type required of indices for this composite.
|
|
|
|
// For structures, this is ubyte, for arrays, this is uint
|
|
|
|
//
|
2001-12-14 16:20:21 +00:00
|
|
|
virtual const Type *getIndexType() const { return Type::UByteTy; }
|
2001-11-26 16:46:45 +00:00
|
|
|
|
2003-10-03 18:46:24 +00:00
|
|
|
// Implement the AbstractTypeUser interface.
|
2001-09-07 16:19:29 +00:00
|
|
|
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
|
2003-10-03 18:46:24 +00:00
|
|
|
virtual void typeBecameConcrete(const DerivedType *AbsTy);
|
2001-10-01 18:26:53 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2001-12-14 16:20:21 +00:00
|
|
|
static inline bool classof(const StructType *T) { return true; }
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const Type *T) {
|
2001-12-14 16:20:21 +00:00
|
|
|
return T->getPrimitiveID() == StructTyID;
|
2001-10-01 18:26:53 +00:00
|
|
|
}
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const Value *V) {
|
2003-07-23 15:30:06 +00:00
|
|
|
return isa<Type>(V) && classof(cast<Type>(V));
|
2001-10-01 18:26:53 +00:00
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
2001-07-23 05:03:15 +00:00
|
|
|
|
2001-12-14 16:20:21 +00:00
|
|
|
// 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!
|
2001-06-06 20:29:01 +00:00
|
|
|
protected:
|
2003-06-18 19:22:36 +00:00
|
|
|
PATypeHandle ElementType;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-12-14 16:20:21 +00:00
|
|
|
SequentialType(PrimitiveID TID, const Type *ElType)
|
2003-06-18 19:22:36 +00:00
|
|
|
: CompositeType(TID), ElementType(PATypeHandle(ElType, this)) {
|
2001-12-14 16:20:21 +00:00
|
|
|
}
|
2003-09-05 02:15:36 +00:00
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
public:
|
2001-12-14 16:20:21 +00:00
|
|
|
inline const Type *getElementType() const { return ElementType; }
|
2001-09-07 16:19:29 +00:00
|
|
|
|
|
|
|
virtual const Type *getContainedType(unsigned i) const {
|
2001-12-14 16:20:21 +00:00
|
|
|
return i == 0 ? ElementType.get() : 0;
|
2001-07-20 19:09:11 +00:00
|
|
|
}
|
2001-12-14 16:20:21 +00:00
|
|
|
virtual unsigned getNumContainedTypes() const { return 1; }
|
2001-09-07 16:19:29 +00:00
|
|
|
|
2001-11-26 16:46:45 +00:00
|
|
|
// getTypeAtIndex - Given an index value into the type, return the type of the
|
2001-12-14 16:20:21 +00:00
|
|
|
// element. For sequential types, there is only one subtype...
|
2001-11-26 16:46:45 +00:00
|
|
|
//
|
2001-12-14 16:20:21 +00:00
|
|
|
virtual const Type *getTypeAtIndex(const Value *V) const {
|
|
|
|
return ElementType.get();
|
|
|
|
}
|
|
|
|
virtual bool indexValid(const Value *V) const {
|
2002-09-11 01:16:19 +00:00
|
|
|
return V->getType() == Type::LongTy; // Must be a 'long' index
|
2001-12-14 16:20:21 +00:00
|
|
|
}
|
2001-11-26 16:46:45 +00:00
|
|
|
|
2001-12-14 16:20:21 +00:00
|
|
|
// getIndexType() - Return the type required of indices for this composite.
|
2001-11-26 16:46:45 +00:00
|
|
|
// For structures, this is ubyte, for arrays, this is uint
|
|
|
|
//
|
2002-09-11 01:16:19 +00:00
|
|
|
virtual const Type *getIndexType() const { return Type::LongTy; }
|
2001-12-14 16:20:21 +00:00
|
|
|
|
|
|
|
// 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) {
|
2003-07-23 15:30:06 +00:00
|
|
|
return isa<Type>(V) && classof(cast<Type>(V));
|
2001-12-14 16:20:21 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ArrayType : public SequentialType {
|
2003-09-05 02:30:18 +00:00
|
|
|
friend class TypeMap<ArrayValType, ArrayType>;
|
2001-12-14 16:20:21 +00:00
|
|
|
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 ArrayType' only
|
|
|
|
// defines private constructors and has no friends
|
|
|
|
|
|
|
|
// Private ctor - Only can be created by a static member...
|
|
|
|
ArrayType(const Type *ElType, unsigned NumEl);
|
2003-09-05 02:15:36 +00:00
|
|
|
|
|
|
|
// dropAllTypeUses - When this (abstract) type is resolved to be equal to
|
|
|
|
// another (more concrete) type, we must eliminate all references to other
|
2003-10-03 18:57:54 +00:00
|
|
|
// types, to avoid some circular reference problems.
|
|
|
|
virtual void dropAllTypeUses();
|
2003-09-05 02:15:36 +00:00
|
|
|
|
2001-12-14 16:20:21 +00:00
|
|
|
public:
|
2003-10-03 18:46:24 +00:00
|
|
|
/// ArrayType::get - This static method is the primary way to construct an
|
|
|
|
/// ArrayType
|
|
|
|
static ArrayType *get(const Type *ElementType, unsigned NumElements);
|
|
|
|
|
2001-12-14 16:20:21 +00:00
|
|
|
inline unsigned getNumElements() const { return NumElements; }
|
2001-11-26 16:46:45 +00:00
|
|
|
|
2003-10-03 18:46:24 +00:00
|
|
|
// Implement the AbstractTypeUser interface.
|
2001-09-07 16:19:29 +00:00
|
|
|
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
|
2003-10-03 18:46:24 +00:00
|
|
|
virtual void typeBecameConcrete(const DerivedType *AbsTy);
|
2001-10-01 18:26:53 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2001-12-14 16:20:21 +00:00
|
|
|
static inline bool classof(const ArrayType *T) { return true; }
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const Type *T) {
|
2001-12-14 16:20:21 +00:00
|
|
|
return T->getPrimitiveID() == ArrayTyID;
|
2001-10-01 18:26:53 +00:00
|
|
|
}
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const Value *V) {
|
2003-07-23 15:30:06 +00:00
|
|
|
return isa<Type>(V) && classof(cast<Type>(V));
|
2001-10-01 18:26:53 +00:00
|
|
|
}
|
2001-07-23 05:03:15 +00:00
|
|
|
};
|
2001-07-20 21:09:17 +00:00
|
|
|
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-12-14 16:20:21 +00:00
|
|
|
class PointerType : public SequentialType {
|
2003-09-05 02:30:18 +00:00
|
|
|
friend class TypeMap<PointerValType, PointerType>;
|
2001-06-06 20:29:01 +00:00
|
|
|
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);
|
2003-09-05 02:15:36 +00:00
|
|
|
|
|
|
|
// dropAllTypeUses - When this (abstract) type is resolved to be equal to
|
|
|
|
// another (more concrete) type, we must eliminate all references to other
|
2003-10-03 18:57:54 +00:00
|
|
|
// types, to avoid some circular reference problems.
|
|
|
|
virtual void dropAllTypeUses();
|
2001-06-06 20:29:01 +00:00
|
|
|
public:
|
2003-10-03 18:46:24 +00:00
|
|
|
/// PointerType::get - This is the only way to construct a new pointer type.
|
2001-09-07 16:19:29 +00:00
|
|
|
static PointerType *get(const Type *ElementType);
|
|
|
|
|
2003-10-03 18:46:24 +00:00
|
|
|
// Implement the AbstractTypeUser interface.
|
2001-09-07 16:19:29 +00:00
|
|
|
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
|
2003-10-03 18:46:24 +00:00
|
|
|
virtual void typeBecameConcrete(const DerivedType *AbsTy);
|
2001-10-01 18:26:53 +00:00
|
|
|
|
2003-10-03 18:46:24 +00:00
|
|
|
// Implement support type inquiry through isa, cast, and dyn_cast:
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const PointerType *T) { return true; }
|
|
|
|
static inline bool classof(const Type *T) {
|
2001-10-01 18:26:53 +00:00
|
|
|
return T->getPrimitiveID() == PointerTyID;
|
|
|
|
}
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const Value *V) {
|
2003-07-23 15:30:06 +00:00
|
|
|
return isa<Type>(V) && classof(cast<Type>(V));
|
2001-10-01 18:26:53 +00:00
|
|
|
}
|
2001-09-07 16:19:29 +00:00
|
|
|
};
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-09-07 16:19:29 +00:00
|
|
|
class OpaqueType : public DerivedType {
|
2003-09-01 16:38:43 +00:00
|
|
|
OpaqueType(const OpaqueType &); // DO NOT IMPLEMENT
|
|
|
|
const OpaqueType &operator=(const OpaqueType &); // DO NOT IMPLEMENT
|
2001-09-07 16:19:29 +00:00
|
|
|
protected:
|
|
|
|
// This should really be private, but it squelches a bogus warning
|
|
|
|
// from GCC to make them protected: warning: `class OpaqueType' only
|
|
|
|
// defines private constructors and has no friends
|
|
|
|
|
|
|
|
// Private ctor - Only can be created by a static member...
|
|
|
|
OpaqueType();
|
2003-09-05 02:15:36 +00:00
|
|
|
|
|
|
|
// dropAllTypeUses - When this (abstract) type is resolved to be equal to
|
|
|
|
// another (more concrete) type, we must eliminate all references to other
|
|
|
|
// types, to avoid some circular reference problems.
|
2003-10-03 18:57:54 +00:00
|
|
|
virtual void dropAllTypeUses() {
|
|
|
|
// FIXME: THIS IS NOT AN ABSTRACT TYPE USER!
|
|
|
|
} // No type uses
|
2003-09-05 02:15:36 +00:00
|
|
|
|
2001-09-07 16:19:29 +00:00
|
|
|
public:
|
2003-10-03 18:46:24 +00:00
|
|
|
// OpaqueType::get - Static factory method for the OpaqueType class...
|
2001-09-07 16:19:29 +00:00
|
|
|
static OpaqueType *get() {
|
|
|
|
return new OpaqueType(); // All opaque types are distinct
|
2001-07-20 19:09:11 +00:00
|
|
|
}
|
2001-10-01 18:26:53 +00:00
|
|
|
|
2003-10-03 18:46:24 +00:00
|
|
|
// Implement the AbstractTypeUser interface.
|
2003-10-02 19:44:23 +00:00
|
|
|
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
|
2003-10-03 18:46:24 +00:00
|
|
|
abort(); // FIXME: this is not really an AbstractTypeUser!
|
|
|
|
}
|
|
|
|
virtual void typeBecameConcrete(const DerivedType *AbsTy) {
|
|
|
|
abort(); // FIXME: this is not really an AbstractTypeUser!
|
2003-10-02 19:44:23 +00:00
|
|
|
}
|
|
|
|
|
2003-10-03 18:46:24 +00:00
|
|
|
// Implement support for type inquiry through isa, cast, and dyn_cast:
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const OpaqueType *T) { return true; }
|
|
|
|
static inline bool classof(const Type *T) {
|
2001-10-01 18:26:53 +00:00
|
|
|
return T->getPrimitiveID() == OpaqueTyID;
|
|
|
|
}
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const Value *V) {
|
2002-06-25 16:12:52 +00:00
|
|
|
return isa<Type>(V) && classof(cast<Type>(V));
|
2001-10-01 18:26:53 +00:00
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
2001-09-07 16:19:29 +00:00
|
|
|
|
|
|
|
// Define some inline methods for the AbstractTypeUser.h:PATypeHandle class.
|
2003-08-21 22:14:26 +00:00
|
|
|
// These are defined here because they MUST be inlined, yet are dependent on
|
2001-09-07 16:19:29 +00:00
|
|
|
// the definition of the Type class. Of course Type derives from Value, which
|
|
|
|
// contains an AbstractTypeUser instance, so there is no good way to factor out
|
|
|
|
// the code. Hence this bit of uglyness.
|
|
|
|
//
|
2003-06-18 19:22:36 +00:00
|
|
|
inline void PATypeHandle::addUser() {
|
2001-12-14 16:20:21 +00:00
|
|
|
assert(Ty && "Type Handle has a null type!");
|
2001-09-07 16:19:29 +00:00
|
|
|
if (Ty->isAbstract())
|
2001-10-01 18:26:53 +00:00
|
|
|
cast<DerivedType>(Ty)->addAbstractTypeUser(User);
|
2001-09-07 16:19:29 +00:00
|
|
|
}
|
2003-06-18 19:22:36 +00:00
|
|
|
inline void PATypeHandle::removeUser() {
|
2001-09-07 16:19:29 +00:00
|
|
|
if (Ty->isAbstract())
|
2001-10-01 18:26:53 +00:00
|
|
|
cast<DerivedType>(Ty)->removeAbstractTypeUser(User);
|
2001-09-07 16:19:29 +00:00
|
|
|
}
|
|
|
|
|
2003-06-18 19:22:36 +00:00
|
|
|
inline void PATypeHandle::removeUserFromConcrete() {
|
2001-11-03 03:27:53 +00:00
|
|
|
if (!Ty->isAbstract())
|
|
|
|
cast<DerivedType>(Ty)->removeAbstractTypeUser(User);
|
|
|
|
}
|
|
|
|
|
2003-10-02 23:35:57 +00:00
|
|
|
// Define inline methods for PATypeHolder...
|
|
|
|
|
|
|
|
inline void PATypeHolder::addRef() {
|
|
|
|
if (Ty->isAbstract())
|
|
|
|
cast<DerivedType>(Ty)->addRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void PATypeHolder::dropRef() {
|
|
|
|
if (Ty->isAbstract())
|
|
|
|
cast<DerivedType>(Ty)->dropRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// get - This implements the forwarding part of the union-find algorithm for
|
|
|
|
/// abstract types. Before every access to the Type*, we check to see if the
|
|
|
|
/// type we are pointing to is forwarding to a new type. If so, we drop our
|
|
|
|
/// reference to the type.
|
|
|
|
inline const Type* PATypeHolder::get() const {
|
|
|
|
const Type *NewTy = Ty->getForwardedType();
|
|
|
|
if (!NewTy) return Ty;
|
|
|
|
return *const_cast<PATypeHolder*>(this) = NewTy;
|
|
|
|
}
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
#endif
|