Detemplatize the PATypeHandle class, which was only really instantiated on 'Type'.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6774 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2003-06-18 19:22:36 +00:00
parent c500cf2fab
commit 893f025262
7 changed files with 45 additions and 47 deletions

View File

@ -58,9 +58,8 @@ public:
// example. This class is a simple class used to keep the use list of abstract // example. This class is a simple class used to keep the use list of abstract
// types up-to-date. // types up-to-date.
// //
template <class TypeSubClass>
class PATypeHandle { class PATypeHandle {
const TypeSubClass *Ty; const Type *Ty;
AbstractTypeUser * const User; AbstractTypeUser * const User;
// These functions are defined at the bottom of Type.h. See the comment there // These functions are defined at the bottom of Type.h. See the comment there
@ -69,7 +68,7 @@ class PATypeHandle {
inline void removeUser(); inline void removeUser();
public: public:
// ctor - Add use to type if abstract. Note that Ty must not be null // ctor - Add use to type if abstract. Note that Ty must not be null
inline PATypeHandle(const TypeSubClass *ty, AbstractTypeUser *user) inline PATypeHandle(const Type *ty, AbstractTypeUser *user)
: Ty(ty), User(user) { : Ty(ty), User(user) {
addUser(); addUser();
} }
@ -83,11 +82,11 @@ public:
inline ~PATypeHandle() { removeUser(); } inline ~PATypeHandle() { removeUser(); }
// Automatic casting operator so that the handle may be used naturally // Automatic casting operator so that the handle may be used naturally
inline operator const TypeSubClass *() const { return Ty; } inline operator const Type *() const { return Ty; }
inline const TypeSubClass *get() const { return Ty; } inline const Type *get() const { return Ty; }
// operator= - Allow assignment to handle // operator= - Allow assignment to handle
inline const TypeSubClass *operator=(const TypeSubClass *ty) { inline const Type *operator=(const Type *ty) {
if (Ty != ty) { // Ensure we don't accidentally drop last ref to Ty if (Ty != ty) { // Ensure we don't accidentally drop last ref to Ty
removeUser(); removeUser();
Ty = ty; Ty = ty;
@ -97,16 +96,16 @@ public:
} }
// operator= - Allow assignment to handle // operator= - Allow assignment to handle
inline const TypeSubClass *operator=(const PATypeHandle &T) { inline const Type *operator=(const PATypeHandle &T) {
return operator=(T.Ty); return operator=(T.Ty);
} }
inline bool operator==(const TypeSubClass *ty) { inline bool operator==(const Type *ty) {
return Ty == ty; return Ty == ty;
} }
// operator-> - Allow user to dereference handle naturally... // operator-> - Allow user to dereference handle naturally...
inline const TypeSubClass *operator->() const { return Ty; } inline const Type *operator->() const { return Ty; }
// removeUserFromConcrete - This function should be called when the User is // removeUserFromConcrete - This function should be called when the User is
// notified that our type is refined... and the type is being refined to // notified that our type is refined... and the type is being refined to
@ -122,10 +121,10 @@ public:
// as both a handle (as above) and an AbstractTypeUser. It uses the callback to // as both a handle (as above) and an AbstractTypeUser. It uses the callback to
// keep its pointer member updated to the current version of the type. // keep its pointer member updated to the current version of the type.
// //
struct PATypeHolder : public AbstractTypeUser, public PATypeHandle<Type> { struct PATypeHolder : public AbstractTypeUser, public PATypeHandle {
inline PATypeHolder(const Type *ty) : PATypeHandle<Type>(ty, this) {} inline PATypeHolder(const Type *ty) : PATypeHandle(ty, this) {}
inline PATypeHolder(const PATypeHolder &T) inline PATypeHolder(const PATypeHolder &T)
: AbstractTypeUser(T), PATypeHandle<Type>(T, this) {} : AbstractTypeUser(T), PATypeHandle(T, this) {}
// refineAbstractType - All we do is update our PATypeHandle member to point // refineAbstractType - All we do is update our PATypeHandle member to point
// to the new type. // to the new type.
@ -138,20 +137,20 @@ struct PATypeHolder : public AbstractTypeUser, public PATypeHandle<Type> {
removeUserFromConcrete(); removeUserFromConcrete();
if ((const Type*)OldTy != NewTy) if ((const Type*)OldTy != NewTy)
PATypeHandle<Type>::operator=(NewTy); PATypeHandle::operator=(NewTy);
} }
// operator= - Allow assignment to handle // operator= - Allow assignment to handle
inline const Type *operator=(const Type *ty) { inline const Type *operator=(const Type *ty) {
return PATypeHandle<Type>::operator=(ty); return PATypeHandle::operator=(ty);
} }
// operator= - Allow assignment to handle // operator= - Allow assignment to handle
inline const Type *operator=(const PATypeHandle<Type> &T) { inline const Type *operator=(const PATypeHandle &T) {
return PATypeHandle<Type>::operator=(T); return PATypeHandle::operator=(T);
} }
inline const Type *operator=(const PATypeHolder &H) { inline const Type *operator=(const PATypeHolder &H) {
return PATypeHandle<Type>::operator=(H); return PATypeHandle::operator=(H);
} }
void dump() const; void dump() const;

View File

@ -86,9 +86,9 @@ public:
class FunctionType : public DerivedType { class FunctionType : public DerivedType {
public: public:
typedef std::vector<PATypeHandle<Type> > ParamTypes; typedef std::vector<PATypeHandle> ParamTypes;
private: private:
PATypeHandle<Type> ResultType; PATypeHandle ResultType;
ParamTypes ParamTys; ParamTypes ParamTys;
bool isVarArgs; bool isVarArgs;
@ -181,7 +181,7 @@ public:
class StructType : public CompositeType { class StructType : public CompositeType {
public: public:
typedef std::vector<PATypeHandle<Type> > ElementTypes; typedef std::vector<PATypeHandle> ElementTypes;
private: private:
ElementTypes ETypes; // Element types of struct ElementTypes ETypes; // Element types of struct
@ -245,10 +245,10 @@ class SequentialType : public CompositeType {
SequentialType(const SequentialType &); // Do not implement! SequentialType(const SequentialType &); // Do not implement!
const SequentialType &operator=(const SequentialType &); // Do not implement! const SequentialType &operator=(const SequentialType &); // Do not implement!
protected: protected:
PATypeHandle<Type> ElementType; PATypeHandle ElementType;
SequentialType(PrimitiveID TID, const Type *ElType) SequentialType(PrimitiveID TID, const Type *ElType)
: CompositeType(TID), ElementType(PATypeHandle<Type>(ElType, this)) { : CompositeType(TID), ElementType(PATypeHandle(ElType, this)) {
} }
public: public:
@ -390,18 +390,17 @@ public:
// contains an AbstractTypeUser instance, so there is no good way to factor out // contains an AbstractTypeUser instance, so there is no good way to factor out
// the code. Hence this bit of uglyness. // the code. Hence this bit of uglyness.
// //
template <class TypeSubClass> void PATypeHandle<TypeSubClass>::addUser() { inline void PATypeHandle::addUser() {
assert(Ty && "Type Handle has a null type!"); assert(Ty && "Type Handle has a null type!");
if (Ty->isAbstract()) if (Ty->isAbstract())
cast<DerivedType>(Ty)->addAbstractTypeUser(User); cast<DerivedType>(Ty)->addAbstractTypeUser(User);
} }
template <class TypeSubClass> void PATypeHandle<TypeSubClass>::removeUser() { inline void PATypeHandle::removeUser() {
if (Ty->isAbstract()) if (Ty->isAbstract())
cast<DerivedType>(Ty)->removeAbstractTypeUser(User); cast<DerivedType>(Ty)->removeAbstractTypeUser(User);
} }
template <class TypeSubClass> inline void PATypeHandle::removeUserFromConcrete() {
void PATypeHandle<TypeSubClass>::removeUserFromConcrete() {
if (!Ty->isAbstract()) if (!Ty->isAbstract())
cast<DerivedType>(Ty)->removeAbstractTypeUser(User); cast<DerivedType>(Ty)->removeAbstractTypeUser(User);
} }

View File

@ -50,7 +50,7 @@ public:
private: private:
std::vector<User *> Uses; std::vector<User *> Uses;
std::string Name; std::string Name;
PATypeHandle<Type> Ty; PATypeHandle Ty;
ValueTy VTy; ValueTy VTy;
void operator=(const Value &); // Do not implement void operator=(const Value &); // Do not implement

View File

@ -816,7 +816,7 @@ UpRTypes : '\\' EUINT64VAL { // Type UpReference
| UpRTypesV '(' ArgTypeListI ')' { // Function derived type? | UpRTypesV '(' ArgTypeListI ')' { // Function derived type?
std::vector<const Type*> Params; std::vector<const Type*> Params;
mapto($3->begin(), $3->end(), std::back_inserter(Params), mapto($3->begin(), $3->end(), std::back_inserter(Params),
std::mem_fun_ref(&PATypeHandle<Type>::get)); std::mem_fun_ref(&PATypeHandle::get));
bool isVarArg = Params.size() && Params.back() == Type::VoidTy; bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
if (isVarArg) Params.pop_back(); if (isVarArg) Params.pop_back();
@ -831,7 +831,7 @@ UpRTypes : '\\' EUINT64VAL { // Type UpReference
| '{' TypeListI '}' { // Structure type? | '{' TypeListI '}' { // Structure type?
std::vector<const Type*> Elements; std::vector<const Type*> Elements;
mapto($2->begin(), $2->end(), std::back_inserter(Elements), mapto($2->begin(), $2->end(), std::back_inserter(Elements),
std::mem_fun_ref(&PATypeHandle<Type>::get)); std::mem_fun_ref(&PATypeHandle::get));
$$ = new PATypeHolder(HandleUpRefs(StructType::get(Elements))); $$ = new PATypeHolder(HandleUpRefs(StructType::get(Elements)));
delete $2; delete $2;

View File

@ -139,7 +139,7 @@ bool BytecodeParser::parseTypeConstants(const unsigned char *&Buf,
// Insert a bunch of opaque types to be resolved later... // Insert a bunch of opaque types to be resolved later...
for (unsigned i = 0; i < NumEntries; ++i) for (unsigned i = 0; i < NumEntries; ++i)
Tab.push_back(PATypeHandle<Type>(OpaqueType::get(), this)); Tab.push_back(PATypeHandle(OpaqueType::get(), this));
// Loop through reading all of the types. Forward types will make use of the // Loop through reading all of the types. Forward types will make use of the
// opaque types just inserted. // opaque types just inserted.

View File

@ -104,7 +104,7 @@ private: // All of this data is transient across calls to ParseBytecode
// TypesLoaded - This vector mirrors the Values[TypeTyID] plane. It is used // TypesLoaded - This vector mirrors the Values[TypeTyID] plane. It is used
// to deal with forward references to types. // to deal with forward references to types.
// //
typedef std::vector<PATypeHandle<Type> > TypeValuesListTy; typedef std::vector<PATypeHandle> TypeValuesListTy;
TypeValuesListTy ModuleTypeValues; TypeValuesListTy ModuleTypeValues;
TypeValuesListTy FunctionTypeValues; TypeValuesListTy FunctionTypeValues;

View File

@ -216,11 +216,11 @@ Type *Type::LabelTy = &TheLabelTy;
FunctionType::FunctionType(const Type *Result, FunctionType::FunctionType(const Type *Result,
const std::vector<const Type*> &Params, const std::vector<const Type*> &Params,
bool IsVarArgs) : DerivedType(FunctionTyID), bool IsVarArgs) : DerivedType(FunctionTyID),
ResultType(PATypeHandle<Type>(Result, this)), ResultType(PATypeHandle(Result, this)),
isVarArgs(IsVarArgs) { isVarArgs(IsVarArgs) {
ParamTys.reserve(Params.size()); ParamTys.reserve(Params.size());
for (unsigned i = 0; i < Params.size(); ++i) for (unsigned i = 0; i < Params.size(); ++i)
ParamTys.push_back(PATypeHandle<Type>(Params[i], this)); ParamTys.push_back(PATypeHandle(Params[i], this));
setDerivedTypeProperties(); setDerivedTypeProperties();
} }
@ -230,7 +230,7 @@ StructType::StructType(const std::vector<const Type*> &Types)
ETypes.reserve(Types.size()); ETypes.reserve(Types.size());
for (unsigned i = 0; i < Types.size(); ++i) { for (unsigned i = 0; i < Types.size(); ++i) {
assert(Types[i] != Type::VoidTy && "Void type in method prototype!!"); assert(Types[i] != Type::VoidTy && "Void type in method prototype!!");
ETypes.push_back(PATypeHandle<Type>(Types[i], this)); ETypes.push_back(PATypeHandle(Types[i], this));
} }
setDerivedTypeProperties(); setDerivedTypeProperties();
} }
@ -427,20 +427,20 @@ static bool TypesEqual(const Type *Ty, const Type *Ty2) {
// //
template<class ValType, class TypeClass> template<class ValType, class TypeClass>
class TypeMap : public AbstractTypeUser { class TypeMap : public AbstractTypeUser {
typedef std::map<ValType, PATypeHandle<TypeClass> > MapTy; typedef std::map<ValType, PATypeHandle> MapTy;
MapTy Map; MapTy Map;
public: public:
~TypeMap() { print("ON EXIT"); } ~TypeMap() { print("ON EXIT"); }
inline TypeClass *get(const ValType &V) { inline TypeClass *get(const ValType &V) {
typename std::map<ValType, PATypeHandle<TypeClass> >::iterator I typename std::map<ValType, PATypeHandle>::iterator I
= Map.find(V); = Map.find(V);
// TODO: FIXME: When Types are not CONST. // TODO: FIXME: When Types are not CONST.
return (I != Map.end()) ? (TypeClass*)I->second.get() : 0; return (I != Map.end()) ? (TypeClass*)I->second.get() : 0;
} }
inline void add(const ValType &V, TypeClass *T) { inline void add(const ValType &V, TypeClass *T) {
Map.insert(std::make_pair(V, PATypeHandle<TypeClass>(T, this))); Map.insert(std::make_pair(V, PATypeHandle(T, this)));
print("add"); print("add");
} }
@ -521,7 +521,7 @@ protected:
TypeMap<ValType, TypeClass> &Table = MyTable; // Copy MyTable reference TypeMap<ValType, TypeClass> &Table = MyTable; // Copy MyTable reference
ValType Tmp(*(ValType*)this); // Copy this. ValType Tmp(*(ValType*)this); // Copy this.
PATypeHandle<TypeClass> OldType(Table.get(*(ValType*)this), this); PATypeHandle OldType(Table.get(*(ValType*)this), this);
Table.remove(*(ValType*)this); // Destroy's this! Table.remove(*(ValType*)this); // Destroy's this!
// Refine temporary to new state... // Refine temporary to new state...
@ -546,8 +546,8 @@ protected:
// FunctionValType - Define a class to hold the key that goes into the TypeMap // FunctionValType - Define a class to hold the key that goes into the TypeMap
// //
class FunctionValType : public ValTypeBase<FunctionValType, FunctionType> { class FunctionValType : public ValTypeBase<FunctionValType, FunctionType> {
PATypeHandle<Type> RetTy; PATypeHandle RetTy;
std::vector<PATypeHandle<Type> > ArgTypes; std::vector<PATypeHandle> ArgTypes;
bool isVarArg; bool isVarArg;
public: public:
FunctionValType(const Type *ret, const std::vector<const Type*> &args, FunctionValType(const Type *ret, const std::vector<const Type*> &args,
@ -555,7 +555,7 @@ public:
: ValTypeBase<FunctionValType, FunctionType>(Tab), RetTy(ret, this), : ValTypeBase<FunctionValType, FunctionType>(Tab), RetTy(ret, this),
isVarArg(IVA) { isVarArg(IVA) {
for (unsigned i = 0; i < args.size(); ++i) for (unsigned i = 0; i < args.size(); ++i)
ArgTypes.push_back(PATypeHandle<Type>(args[i], this)); ArgTypes.push_back(PATypeHandle(args[i], this));
} }
// We *MUST* have an explicit copy ctor so that the TypeHandles think that // We *MUST* have an explicit copy ctor so that the TypeHandles think that
@ -566,7 +566,7 @@ public:
isVarArg(MVT.isVarArg) { isVarArg(MVT.isVarArg) {
ArgTypes.reserve(MVT.ArgTypes.size()); ArgTypes.reserve(MVT.ArgTypes.size());
for (unsigned i = 0; i < MVT.ArgTypes.size(); ++i) for (unsigned i = 0; i < MVT.ArgTypes.size(); ++i)
ArgTypes.push_back(PATypeHandle<Type>(MVT.ArgTypes[i], this)); ArgTypes.push_back(PATypeHandle(MVT.ArgTypes[i], this));
} }
// Subclass should override this... to update self as usual // Subclass should override this... to update self as usual
@ -615,7 +615,7 @@ FunctionType *FunctionType::get(const Type *ReturnType,
// Array Type Factory... // Array Type Factory...
// //
class ArrayValType : public ValTypeBase<ArrayValType, ArrayType> { class ArrayValType : public ValTypeBase<ArrayValType, ArrayType> {
PATypeHandle<Type> ValTy; PATypeHandle ValTy;
unsigned Size; unsigned Size;
public: public:
ArrayValType(const Type *val, int sz, TypeMap<ArrayValType, ArrayType> &Tab) ArrayValType(const Type *val, int sz, TypeMap<ArrayValType, ArrayType> &Tab)
@ -671,14 +671,14 @@ ArrayType *ArrayType::get(const Type *ElementType, unsigned NumElements) {
// StructValType - Define a class to hold the key that goes into the TypeMap // StructValType - Define a class to hold the key that goes into the TypeMap
// //
class StructValType : public ValTypeBase<StructValType, StructType> { class StructValType : public ValTypeBase<StructValType, StructType> {
std::vector<PATypeHandle<Type> > ElTypes; std::vector<PATypeHandle> ElTypes;
public: public:
StructValType(const std::vector<const Type*> &args, StructValType(const std::vector<const Type*> &args,
TypeMap<StructValType, StructType> &Tab) TypeMap<StructValType, StructType> &Tab)
: ValTypeBase<StructValType, StructType>(Tab) { : ValTypeBase<StructValType, StructType>(Tab) {
ElTypes.reserve(args.size()); ElTypes.reserve(args.size());
for (unsigned i = 0, e = args.size(); i != e; ++i) for (unsigned i = 0, e = args.size(); i != e; ++i)
ElTypes.push_back(PATypeHandle<Type>(args[i], this)); ElTypes.push_back(PATypeHandle(args[i], this));
} }
// We *MUST* have an explicit copy ctor so that the TypeHandles think that // We *MUST* have an explicit copy ctor so that the TypeHandles think that
@ -688,7 +688,7 @@ public:
: ValTypeBase<StructValType, StructType>(SVT){ : ValTypeBase<StructValType, StructType>(SVT){
ElTypes.reserve(SVT.ElTypes.size()); ElTypes.reserve(SVT.ElTypes.size());
for (unsigned i = 0, e = SVT.ElTypes.size(); i != e; ++i) for (unsigned i = 0, e = SVT.ElTypes.size(); i != e; ++i)
ElTypes.push_back(PATypeHandle<Type>(SVT.ElTypes[i], this)); ElTypes.push_back(PATypeHandle(SVT.ElTypes[i], this));
} }
// Subclass should override this... to update self as usual // Subclass should override this... to update self as usual
@ -731,7 +731,7 @@ StructType *StructType::get(const std::vector<const Type*> &ETypes) {
// PointerValType - Define a class to hold the key that goes into the TypeMap // PointerValType - Define a class to hold the key that goes into the TypeMap
// //
class PointerValType : public ValTypeBase<PointerValType, PointerType> { class PointerValType : public ValTypeBase<PointerValType, PointerType> {
PATypeHandle<Type> ValTy; PATypeHandle ValTy;
public: public:
PointerValType(const Type *val, TypeMap<PointerValType, PointerType> &Tab) PointerValType(const Type *val, TypeMap<PointerValType, PointerType> &Tab)
: ValTypeBase<PointerValType, PointerType>(Tab), ValTy(val, this) {} : ValTypeBase<PointerValType, PointerType>(Tab), ValTy(val, this) {}