diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-02-05 23:33:38 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-02-05 23:33:38 +0000 |
commit | fab9d67cebb87be968e7ae31a3b549a5279b5d51 (patch) | |
tree | e6e71ce878f610e0f9539097db19e55df64e566e /lib/AST/ASTContext.cpp | |
parent | 4a3aed942bd6e4e73679b1676bc1ac82248b592d (diff) |
Improve the representation of template type parameters. We now
canonicalize by template parameter depth, index, and name, and the
unnamed version of a template parameter serves as the canonical.
TemplateTypeParmDecl no longer needs to inherit from
TemplateParmPosition, since depth and index information is present
within the type.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63899 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ASTContext.cpp')
-rw-r--r-- | lib/AST/ASTContext.cpp | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 7784aed764..a87a902d06 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -1144,9 +1144,9 @@ QualType ASTContext::getTypeDeclType(TypeDecl *Decl, TypeDecl* PrevDecl) { if (TypedefDecl *Typedef = dyn_cast<TypedefDecl>(Decl)) return getTypedefType(Typedef); - else if (TemplateTypeParmDecl *TP = dyn_cast<TemplateTypeParmDecl>(Decl)) - return getTemplateTypeParmType(TP); - else if (ObjCInterfaceDecl *ObjCInterface = dyn_cast<ObjCInterfaceDecl>(Decl)) + else if (isa<TemplateTypeParmDecl>(Decl)) { + assert(false && "Template type parameter types are always available."); + } else if (ObjCInterfaceDecl *ObjCInterface = dyn_cast<ObjCInterfaceDecl>(Decl)) return getObjCInterfaceType(ObjCInterface); if (CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(Decl)) { @@ -1185,16 +1185,6 @@ QualType ASTContext::getTypedefType(TypedefDecl *Decl) { return QualType(Decl->TypeForDecl, 0); } -/// getTemplateTypeParmType - Return the unique reference to the type -/// for the specified template type parameter declaration. -QualType ASTContext::getTemplateTypeParmType(TemplateTypeParmDecl *Decl) { - if (!Decl->TypeForDecl) { - Decl->TypeForDecl = new (*this,8) TemplateTypeParmType(Decl); - Types.push_back(Decl->TypeForDecl); - } - return QualType(Decl->TypeForDecl, 0); -} - /// getObjCInterfaceType - Return the unique reference to the type for the /// specified ObjC interface decl. QualType ASTContext::getObjCInterfaceType(ObjCInterfaceDecl *Decl) { @@ -1205,6 +1195,31 @@ QualType ASTContext::getObjCInterfaceType(ObjCInterfaceDecl *Decl) { return QualType(Decl->TypeForDecl, 0); } +/// \brief Retrieve the template type parameter type for a template +/// parameter with the given depth, index, and (optionally) name. +QualType ASTContext::getTemplateTypeParmType(unsigned Depth, unsigned Index, + IdentifierInfo *Name) { + llvm::FoldingSetNodeID ID; + TemplateTypeParmType::Profile(ID, Depth, Index, Name); + void *InsertPos = 0; + TemplateTypeParmType *TypeParm + = TemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos); + + if (TypeParm) + return QualType(TypeParm, 0); + + if (Name) + TypeParm = new (*this, 8) TemplateTypeParmType(Depth, Index, Name, + getTemplateTypeParmType(Depth, Index)); + else + TypeParm = new (*this, 8) TemplateTypeParmType(Depth, Index); + + Types.push_back(TypeParm); + TemplateTypeParmTypes.InsertNode(TypeParm, InsertPos); + + return QualType(TypeParm, 0); +} + /// CmpProtocolNames - Comparison predicate for sorting protocols /// alphabetically. static bool CmpProtocolNames(const ObjCProtocolDecl *LHS, |