aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/AST/ASTContext.cpp41
-rw-r--r--lib/AST/DeclSerialization.cpp12
-rw-r--r--lib/AST/DeclTemplate.cpp3
-rw-r--r--lib/AST/Type.cpp7
-rw-r--r--lib/AST/TypeSerialization.cpp20
5 files changed, 49 insertions, 34 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,
diff --git a/lib/AST/DeclSerialization.cpp b/lib/AST/DeclSerialization.cpp
index dcb8cda33b..ea027df1df 100644
--- a/lib/AST/DeclSerialization.cpp
+++ b/lib/AST/DeclSerialization.cpp
@@ -598,21 +598,17 @@ TypedefDecl* TypedefDecl::CreateImpl(Deserializer& D, ASTContext& C) {
//===----------------------------------------------------------------------===//
void TemplateTypeParmDecl::EmitImpl(Serializer& S) const {
- S.EmitInt(Depth);
- S.EmitInt(Position);
S.EmitBool(Typename);
- NamedDecl::EmitInRec(S);
+ TypeDecl::EmitInRec(S);
}
TemplateTypeParmDecl *
TemplateTypeParmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
- unsigned Depth = D.ReadInt();
- unsigned Position = D.ReadInt();
bool Typename = D.ReadBool();
TemplateTypeParmDecl *decl
- = new (C) TemplateTypeParmDecl(0, SourceLocation(), Depth, Position,
- 0, Typename);
- decl->NamedDecl::ReadInRec(D, C);
+ = new (C) TemplateTypeParmDecl(0, SourceLocation(), 0, Typename,
+ QualType());
+ decl->TypeDecl::ReadInRec(D, C);
return decl;
}
diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp
index 08cd5b377d..394939569e 100644
--- a/lib/AST/DeclTemplate.cpp
+++ b/lib/AST/DeclTemplate.cpp
@@ -78,7 +78,8 @@ TemplateTypeParmDecl *
TemplateTypeParmDecl::Create(ASTContext &C, DeclContext *DC,
SourceLocation L, unsigned D, unsigned P,
IdentifierInfo *Id, bool Typename) {
- return new (C) TemplateTypeParmDecl(DC, L, D, P, Id, Typename);
+ QualType Type = C.getTemplateTypeParmType(D, P, Id);
+ return new (C) TemplateTypeParmDecl(DC, L, Id, Typename, Type);
}
//===----------------------------------------------------------------------===//
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp
index f39a325e0d..199ad29ec6 100644
--- a/lib/AST/Type.cpp
+++ b/lib/AST/Type.cpp
@@ -1138,7 +1138,12 @@ void TypedefType::getAsStringInternal(std::string &InnerString) const {
void TemplateTypeParmType::getAsStringInternal(std::string &InnerString) const {
if (!InnerString.empty()) // Prefix the basic type, e.g. 'parmname X'.
InnerString = ' ' + InnerString;
- InnerString = getDecl()->getIdentifier()->getName() + InnerString;
+
+ if (!Name)
+ InnerString = "type-parameter-" + llvm::utostr_32(Depth) + '-' +
+ llvm::utostr_32(Index) + InnerString;
+ else
+ InnerString = Name->getName() + InnerString;
}
void ObjCInterfaceType::getAsStringInternal(std::string &InnerString) const {
diff --git a/lib/AST/TypeSerialization.cpp b/lib/AST/TypeSerialization.cpp
index 12c3d03c12..57598d3afc 100644
--- a/lib/AST/TypeSerialization.cpp
+++ b/lib/AST/TypeSerialization.cpp
@@ -127,7 +127,7 @@ void Type::Create(ASTContext& Context, unsigned i, Deserializer& D) {
break;
case Type::TemplateTypeParm:
- D.RegisterPtr(PtrID,TemplateTypeParmType::CreateImpl(Context, D));
+ D.RegisterPtr(PtrID, TemplateTypeParmType::CreateImpl(Context, D));
break;
case Type::VariableArray:
@@ -364,20 +364,18 @@ Type* TypeOfType::CreateImpl(ASTContext& Context, Deserializer& D) {
//===----------------------------------------------------------------------===//
void TemplateTypeParmType::EmitImpl(Serializer& S) const {
- S.EmitPtr(getDecl());
+ S.EmitInt(Depth);
+ S.EmitInt(Index);
+ S.EmitPtr(Name);
}
Type* TemplateTypeParmType::CreateImpl(ASTContext& Context, Deserializer& D) {
- std::vector<Type*>& Types =
- const_cast<std::vector<Type*>&>(Context.getTypes());
-
- TemplateTypeParmType* T = new TemplateTypeParmType(NULL);
- Types.push_back(T);
-
- D.ReadPtr(T->Decl); // May be backpatched.
- return T;
+ unsigned Depth = D.ReadInt();
+ unsigned Index = D.ReadInt();
+ IdentifierInfo *Name = D.ReadPtr<IdentifierInfo>();
+ return Context.getTemplateTypeParmType(Depth, Index, Name).getTypePtr();
}
-
+
//===----------------------------------------------------------------------===//
// VariableArrayType
//===----------------------------------------------------------------------===//