From cdb8b3f7ec3f3ab8e1b3db8da384f2444492e5b3 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Sun, 4 Jul 2010 21:44:00 +0000 Subject: [PATCH] Read/write specialization info of static data members for PCH. llvm-svn: 107593 --- clang/include/clang/AST/ASTContext.h | 3 ++- clang/include/clang/AST/DeclTemplate.h | 5 +++-- clang/lib/AST/ASTContext.cpp | 5 +++-- clang/lib/Frontend/PCHReaderDecl.cpp | 7 +++++++ clang/lib/Frontend/PCHWriterDecl.cpp | 13 +++++++++++++ 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 2b65f3155ea1..0a6b6cd45e66 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -331,7 +331,8 @@ public: /// \brief Note that the static data member \p Inst is an instantiation of /// the static data member template \p Tmpl of a class template. void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl, - TemplateSpecializationKind TSK); + TemplateSpecializationKind TSK, + SourceLocation PointOfInstantiation = SourceLocation()); /// \brief If the given using decl is an instantiation of a /// (possibly unresolved) using decl from a template instantiation, diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index 84e755302af4..9e6cf0c38fa9 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -379,8 +379,9 @@ class MemberSpecializationInfo { public: explicit - MemberSpecializationInfo(NamedDecl *IF, TemplateSpecializationKind TSK) - : MemberAndTSK(IF, TSK - 1), PointOfInstantiation() { + MemberSpecializationInfo(NamedDecl *IF, TemplateSpecializationKind TSK, + SourceLocation POI = SourceLocation()) + : MemberAndTSK(IF, TSK - 1), PointOfInstantiation(POI) { assert(TSK != TSK_Undeclared && "Cannot encode undeclared template specializations for members"); } diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 2d52bd08d557..f8f568cbb489 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -392,13 +392,14 @@ ASTContext::getInstantiatedFromStaticDataMember(const VarDecl *Var) { void ASTContext::setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl, - TemplateSpecializationKind TSK) { + TemplateSpecializationKind TSK, + SourceLocation PointOfInstantiation) { assert(Inst->isStaticDataMember() && "Not a static data member"); assert(Tmpl->isStaticDataMember() && "Not a static data member"); assert(!InstantiatedFromStaticDataMember[Inst] && "Already noted what static data member was instantiated from"); InstantiatedFromStaticDataMember[Inst] - = new (*this) MemberSpecializationInfo(Tmpl, TSK); + = new (*this) MemberSpecializationInfo(Tmpl, TSK, PointOfInstantiation); } NamedDecl * diff --git a/clang/lib/Frontend/PCHReaderDecl.cpp b/clang/lib/Frontend/PCHReaderDecl.cpp index 9de002b0e6e6..ab7485ce7947 100644 --- a/clang/lib/Frontend/PCHReaderDecl.cpp +++ b/clang/lib/Frontend/PCHReaderDecl.cpp @@ -522,6 +522,13 @@ void PCHDeclReader::VisitVarDecl(VarDecl *VD) { cast_or_null(Reader.GetDecl(Record[Idx++]))); if (Record[Idx++]) VD->setInit(Reader.ReadExpr()); + + if (Record[Idx++]) { // HasMemberSpecializationInfo. + VarDecl *Tmpl = cast(Reader.GetDecl(Record[Idx++])); + TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; + SourceLocation POI = Reader.ReadSourceLocation(Record, Idx); + Reader.getContext()->setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI); + } } void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) { diff --git a/clang/lib/Frontend/PCHWriterDecl.cpp b/clang/lib/Frontend/PCHWriterDecl.cpp index 2383a75bd040..f52302336574 100644 --- a/clang/lib/Frontend/PCHWriterDecl.cpp +++ b/clang/lib/Frontend/PCHWriterDecl.cpp @@ -492,6 +492,16 @@ void PCHDeclWriter::VisitVarDecl(VarDecl *D) { Record.push_back(D->getInit() ? 1 : 0); if (D->getInit()) Writer.AddStmt(D->getInit()); + + MemberSpecializationInfo *SpecInfo + = D->isStaticDataMember() ? D->getMemberSpecializationInfo() : 0; + Record.push_back(SpecInfo != 0); + if (SpecInfo) { + Writer.AddDeclRef(SpecInfo->getInstantiatedFrom(), Record); + Record.push_back(SpecInfo->getTemplateSpecializationKind()); + Writer.AddSourceLocation(SpecInfo->getPointOfInstantiation(), Record); + } + Code = pch::DECL_VAR; } @@ -530,6 +540,8 @@ void PCHDeclWriter::VisitParmVarDecl(ParmVarDecl *D) { assert(!D->isDeclaredInCondition() && "PARM_VAR_DECL can't be in condition"); assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var"); assert(D->getPreviousDeclaration() == 0 && "PARM_VAR_DECL can't be redecl"); + assert(!D->isStaticDataMember() && + "PARM_VAR_DECL can't be static data member"); } void PCHDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) { @@ -974,6 +986,7 @@ void PCHWriter::WriteDeclsBlockAbbrevs() { Abv->Add(BitCodeAbbrevOp(0)); // isNRVOVariable Abv->Add(BitCodeAbbrevOp(0)); // PrevDecl Abv->Add(BitCodeAbbrevOp(0)); // HasInit + Abv->Add(BitCodeAbbrevOp(0)); // HasMemberSpecializationInfo // ParmVarDecl Abv->Add(BitCodeAbbrevOp(0)); // ObjCDeclQualifier Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedDefaultArg