simplify RecursiveResolveTypes and ResolveTypes by pulling the naming out of

ResolveTypes into the one place that needs it.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52338 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2008-06-16 18:11:40 +00:00
parent e846db6675
commit 371ca83d8b

View File

@ -52,7 +52,6 @@ static std::string ToStr(const Type *Ty, const Module *M) {
// Inputs: // Inputs:
// DestTy - The type to which we wish to resolve. // DestTy - The type to which we wish to resolve.
// SrcTy - The original type which we want to resolve. // SrcTy - The original type which we want to resolve.
// Name - The name of the type.
// //
// Outputs: // Outputs:
// DestST - The symbol table in which the new type should be placed. // DestST - The symbol table in which the new type should be placed.
@ -62,7 +61,7 @@ static std::string ToStr(const Type *Ty, const Module *M) {
// false - No errors. // false - No errors.
// //
static bool ResolveTypes(const Type *DestTy, const Type *SrcTy, static bool ResolveTypes(const Type *DestTy, const Type *SrcTy,
TypeSymbolTable *DestST, const std::string &Name) { TypeSymbolTable *DestST) {
if (DestTy == SrcTy) return false; // If already equal, noop if (DestTy == SrcTy) return false; // If already equal, noop
// Does the type already exist in the module? // Does the type already exist in the module?
@ -76,8 +75,6 @@ static bool ResolveTypes(const Type *DestTy, const Type *SrcTy,
if (DestTy) // Type _is_ in module, just opaque... if (DestTy) // Type _is_ in module, just opaque...
const_cast<OpaqueType*>(cast<OpaqueType>(DestTy)) const_cast<OpaqueType*>(cast<OpaqueType>(DestTy))
->refineAbstractTypeTo(SrcTy); ->refineAbstractTypeTo(SrcTy);
else if (!Name.empty())
DestST->insert(Name, const_cast<Type*>(SrcTy));
} }
return false; return false;
} }
@ -94,8 +91,7 @@ static const StructType *getST(const PATypeHolder &TH) {
// are compatible. // are compatible.
static bool RecursiveResolveTypesI(const PATypeHolder &DestTy, static bool RecursiveResolveTypesI(const PATypeHolder &DestTy,
const PATypeHolder &SrcTy, const PATypeHolder &SrcTy,
TypeSymbolTable *DestST, TypeSymbolTable *DestST,
const std::string &Name,
std::vector<std::pair<PATypeHolder, PATypeHolder> > &Pointers) { std::vector<std::pair<PATypeHolder, PATypeHolder> > &Pointers) {
const Type *SrcTyT = SrcTy.get(); const Type *SrcTyT = SrcTy.get();
const Type *DestTyT = DestTy.get(); const Type *DestTyT = DestTy.get();
@ -103,7 +99,7 @@ static bool RecursiveResolveTypesI(const PATypeHolder &DestTy,
// If we found our opaque type, resolve it now! // If we found our opaque type, resolve it now!
if (isa<OpaqueType>(DestTyT) || isa<OpaqueType>(SrcTyT)) if (isa<OpaqueType>(DestTyT) || isa<OpaqueType>(SrcTyT))
return ResolveTypes(DestTyT, SrcTyT, DestST, Name); return ResolveTypes(DestTyT, SrcTyT, DestST);
// Two types cannot be resolved together if they are of different primitive // Two types cannot be resolved together if they are of different primitive
// type. For example, we cannot resolve an int to a float. // type. For example, we cannot resolve an int to a float.
@ -125,7 +121,7 @@ static bool RecursiveResolveTypesI(const PATypeHolder &DestTy,
return true; return true;
for (unsigned i = 0, e = getFT(DestTy)->getNumContainedTypes(); i != e; ++i) for (unsigned i = 0, e = getFT(DestTy)->getNumContainedTypes(); i != e; ++i)
if (RecursiveResolveTypesI(getFT(DestTy)->getContainedType(i), if (RecursiveResolveTypesI(getFT(DestTy)->getContainedType(i),
getFT(SrcTy)->getContainedType(i), DestST, "", getFT(SrcTy)->getContainedType(i), DestST,
Pointers)) Pointers))
return true; return true;
return false; return false;
@ -135,7 +131,7 @@ static bool RecursiveResolveTypesI(const PATypeHolder &DestTy,
getST(SrcTy)->getNumContainedTypes()) return 1; getST(SrcTy)->getNumContainedTypes()) return 1;
for (unsigned i = 0, e = getST(DestTy)->getNumContainedTypes(); i != e; ++i) for (unsigned i = 0, e = getST(DestTy)->getNumContainedTypes(); i != e; ++i)
if (RecursiveResolveTypesI(getST(DestTy)->getContainedType(i), if (RecursiveResolveTypesI(getST(DestTy)->getContainedType(i),
getST(SrcTy)->getContainedType(i), DestST, "", getST(SrcTy)->getContainedType(i), DestST,
Pointers)) Pointers))
return true; return true;
return false; return false;
@ -145,7 +141,7 @@ static bool RecursiveResolveTypesI(const PATypeHolder &DestTy,
const ArrayType *SAT = cast<ArrayType>(SrcTy.get()); const ArrayType *SAT = cast<ArrayType>(SrcTy.get());
if (DAT->getNumElements() != SAT->getNumElements()) return true; if (DAT->getNumElements() != SAT->getNumElements()) return true;
return RecursiveResolveTypesI(DAT->getElementType(), SAT->getElementType(), return RecursiveResolveTypesI(DAT->getElementType(), SAT->getElementType(),
DestST, "", Pointers); DestST, Pointers);
} }
case Type::PointerTyID: { case Type::PointerTyID: {
// If this is a pointer type, check to see if we have already seen it. If // If this is a pointer type, check to see if we have already seen it. If
@ -162,7 +158,7 @@ static bool RecursiveResolveTypesI(const PATypeHolder &DestTy,
bool Result = bool Result =
RecursiveResolveTypesI(cast<PointerType>(DestTy.get())->getElementType(), RecursiveResolveTypesI(cast<PointerType>(DestTy.get())->getElementType(),
cast<PointerType>(SrcTy.get())->getElementType(), cast<PointerType>(SrcTy.get())->getElementType(),
DestST, "", Pointers); DestST, Pointers);
Pointers.pop_back(); Pointers.pop_back();
return Result; return Result;
} }
@ -172,10 +168,9 @@ static bool RecursiveResolveTypesI(const PATypeHolder &DestTy,
static bool RecursiveResolveTypes(const PATypeHolder &DestTy, static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
const PATypeHolder &SrcTy, const PATypeHolder &SrcTy,
TypeSymbolTable *DestST, TypeSymbolTable *DestST){
const std::string &Name){
std::vector<std::pair<PATypeHolder, PATypeHolder> > PointerTypes; std::vector<std::pair<PATypeHolder, PATypeHolder> > PointerTypes;
return RecursiveResolveTypesI(DestTy, SrcTy, DestST, Name, PointerTypes); return RecursiveResolveTypesI(DestTy, SrcTy, DestST, PointerTypes);
} }
@ -203,7 +198,9 @@ static bool LinkTypes(Module *Dest, const Module *Src, std::string *Err) {
// Check to see if this type name is already in the dest module... // Check to see if this type name is already in the dest module...
Type *Entry = DestST->lookup(Name); Type *Entry = DestST->lookup(Name);
if (ResolveTypes(Entry, RHS, DestST, Name)) { if (Entry == 0 && !Name.empty())
DestST->insert(Name, const_cast<Type*>(RHS));
else if (ResolveTypes(Entry, RHS, DestST)) {
// They look different, save the types 'till later to resolve. // They look different, save the types 'till later to resolve.
DelayedTypesToResolve.push_back(Name); DelayedTypesToResolve.push_back(Name);
} }
@ -219,7 +216,7 @@ static bool LinkTypes(Module *Dest, const Module *Src, std::string *Err) {
const std::string &Name = DelayedTypesToResolve[i]; const std::string &Name = DelayedTypesToResolve[i];
Type *T1 = SrcST->lookup(Name); Type *T1 = SrcST->lookup(Name);
Type *T2 = DestST->lookup(Name); Type *T2 = DestST->lookup(Name);
if (!ResolveTypes(T2, T1, DestST, Name)) { if (!ResolveTypes(T2, T1, DestST)) {
// We are making progress! // We are making progress!
DelayedTypesToResolve.erase(DelayedTypesToResolve.begin()+i); DelayedTypesToResolve.erase(DelayedTypesToResolve.begin()+i);
--i; --i;
@ -235,7 +232,7 @@ static bool LinkTypes(Module *Dest, const Module *Src, std::string *Err) {
PATypeHolder T1(SrcST->lookup(Name)); PATypeHolder T1(SrcST->lookup(Name));
PATypeHolder T2(DestST->lookup(Name)); PATypeHolder T2(DestST->lookup(Name));
if (!RecursiveResolveTypes(T2, T1, DestST, Name)) { if (!RecursiveResolveTypes(T2, T1, DestST)) {
// We are making progress! // We are making progress!
DelayedTypesToResolve.erase(DelayedTypesToResolve.begin()+i); DelayedTypesToResolve.erase(DelayedTypesToResolve.begin()+i);
@ -463,7 +460,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
if (DGV && DGV->getType() != SGV->getType()) if (DGV && DGV->getType() != SGV->getType())
// If types don't agree due to opaque types, try to resolve them. // If types don't agree due to opaque types, try to resolve them.
RecursiveResolveTypes(SGV->getType(), DGV->getType(), RecursiveResolveTypes(SGV->getType(), DGV->getType(),
&Dest->getTypeSymbolTable(), ""); &Dest->getTypeSymbolTable());
} }
// Check to see if may have to link the global with the alias // Check to see if may have to link the global with the alias
@ -472,7 +469,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
if (DGV && DGV->getType() != SGV->getType()) if (DGV && DGV->getType() != SGV->getType())
// If types don't agree due to opaque types, try to resolve them. // If types don't agree due to opaque types, try to resolve them.
RecursiveResolveTypes(SGV->getType(), DGV->getType(), RecursiveResolveTypes(SGV->getType(), DGV->getType(),
&Dest->getTypeSymbolTable(), ""); &Dest->getTypeSymbolTable());
} }
if (DGV && DGV->hasInternalLinkage()) if (DGV && DGV->hasInternalLinkage())
@ -633,7 +630,7 @@ static bool LinkAlias(Module *Dest, const Module *Src,
// If types don't agree due to opaque types, try to resolve them. // If types don't agree due to opaque types, try to resolve them.
if (DGV && DGV->getType() != SGA->getType()) if (DGV && DGV->getType() != SGA->getType())
if (RecursiveResolveTypes(SGA->getType(), DGV->getType(), if (RecursiveResolveTypes(SGA->getType(), DGV->getType(),
&Dest->getTypeSymbolTable(), "")) &Dest->getTypeSymbolTable()))
return Error(Err, "Alias Collision on '" + SGA->getName()+ return Error(Err, "Alias Collision on '" + SGA->getName()+
"': aliases have different types"); "': aliases have different types");
} }
@ -644,7 +641,7 @@ static bool LinkAlias(Module *Dest, const Module *Src,
// If types don't agree due to opaque types, try to resolve them. // If types don't agree due to opaque types, try to resolve them.
if (DGV && DGV->getType() != SGA->getType()) if (DGV && DGV->getType() != SGA->getType())
if (RecursiveResolveTypes(SGA->getType(), DGV->getType(), if (RecursiveResolveTypes(SGA->getType(), DGV->getType(),
&Dest->getTypeSymbolTable(), "")) &Dest->getTypeSymbolTable()))
return Error(Err, "Alias Collision on '" + SGA->getName()+ return Error(Err, "Alias Collision on '" + SGA->getName()+
"': aliases have different types"); "': aliases have different types");
} }
@ -655,7 +652,7 @@ static bool LinkAlias(Module *Dest, const Module *Src,
// If types don't agree due to opaque types, try to resolve them. // If types don't agree due to opaque types, try to resolve them.
if (DGV && DGV->getType() != SGA->getType()) if (DGV && DGV->getType() != SGA->getType())
if (RecursiveResolveTypes(SGA->getType(), DGV->getType(), if (RecursiveResolveTypes(SGA->getType(), DGV->getType(),
&Dest->getTypeSymbolTable(), "")) &Dest->getTypeSymbolTable()))
return Error(Err, "Alias Collision on '" + SGA->getName()+ return Error(Err, "Alias Collision on '" + SGA->getName()+
"': aliases have different types"); "': aliases have different types");
} }
@ -854,7 +851,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// If types don't agree because of opaque, try to resolve them. // If types don't agree because of opaque, try to resolve them.
if (SF->getType() != DF->getType()) if (SF->getType() != DF->getType())
RecursiveResolveTypes(SF->getType(), DF->getType(), RecursiveResolveTypes(SF->getType(), DF->getType(),
&Dest->getTypeSymbolTable(), ""); &Dest->getTypeSymbolTable());
// Check visibility, merging if a definition overrides a prototype. // Check visibility, merging if a definition overrides a prototype.
if (SF->getVisibility() != DF->getVisibility()) { if (SF->getVisibility() != DF->getVisibility()) {