From 554e6aa2da082575514607c3639c246c04b3232a Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Thu, 22 Jul 2010 16:04:10 +0000 Subject: [PATCH] Read/write FriendTemplateDecl for PCH. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109113 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DeclTemplate.h | 10 ++++++++++ lib/AST/DeclTemplate.cpp | 5 +++++ lib/Frontend/PCHReaderDecl.cpp | 14 ++++++++++++-- lib/Frontend/PCHWriterDecl.cpp | 12 +++++++++++- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/include/clang/AST/DeclTemplate.h b/include/clang/AST/DeclTemplate.h index f6421736cd..0b3727e50c 100644 --- a/include/clang/AST/DeclTemplate.h +++ b/include/clang/AST/DeclTemplate.h @@ -1651,6 +1651,12 @@ private: FriendLoc(FriendLoc) {} + FriendTemplateDecl(EmptyShell Empty) + : Decl(Decl::FriendTemplate, Empty), + NumParams(0), + Params(0) + {} + public: static FriendTemplateDecl *Create(ASTContext &Context, DeclContext *DC, SourceLocation Loc, @@ -1659,6 +1665,8 @@ public: FriendUnion Friend, SourceLocation FriendLoc); + static FriendTemplateDecl *Create(ASTContext &Context, EmptyShell Empty); + /// If this friend declaration names a templated type (or /// a dependent member type of a templated type), return that /// type; otherwise return null. @@ -1691,6 +1699,8 @@ public: static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { return K == Decl::FriendTemplate; } static bool classof(const FriendTemplateDecl *D) { return true; } + + friend class PCHDeclReader; }; /// Implementation of inline functions that require the template declarations diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp index f308d71d5f..7b44b4681e 100644 --- a/lib/AST/DeclTemplate.cpp +++ b/lib/AST/DeclTemplate.cpp @@ -631,3 +631,8 @@ FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context, = new (Context) FriendTemplateDecl(DC, L, NParams, Params, Friend, FLoc); return Result; } + +FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context, + EmptyShell Empty) { + return new (Context) FriendTemplateDecl(Empty); +} diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp index 8ea75b7270..d562d6f621 100644 --- a/lib/Frontend/PCHReaderDecl.cpp +++ b/lib/Frontend/PCHReaderDecl.cpp @@ -853,7 +853,17 @@ void PCHDeclReader::VisitFriendDecl(FriendDecl *D) { } void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) { - assert(false && "cannot read FriendTemplateDecl"); + VisitDecl(D); + unsigned NumParams = Record[Idx++]; + D->NumParams = NumParams; + D->Params = new TemplateParameterList*[NumParams]; + for (unsigned i = 0; i != NumParams; ++i) + D->Params[i] = Reader.ReadTemplateParameterList(Record, Idx); + if (Record[Idx++]) // HasFriendDecl + D->Friend = cast(Reader.GetDecl(Record[Idx++])); + else + D->Friend = Reader.GetTypeSourceInfo(Record, Idx); + D->FriendLoc = Reader.ReadSourceLocation(Record, Idx); } void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) { @@ -1374,7 +1384,7 @@ Decl *PCHReader::ReadDeclRecord(unsigned Index) { D = FriendDecl::Create(*Context, Decl::EmptyShell()); break; case pch::DECL_FRIEND_TEMPLATE: - assert(false && "cannot read FriendTemplateDecl"); + D = FriendTemplateDecl::Create(*Context, Decl::EmptyShell()); break; case pch::DECL_CLASS_TEMPLATE: D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(), diff --git a/lib/Frontend/PCHWriterDecl.cpp b/lib/Frontend/PCHWriterDecl.cpp index eb7c52ae95..122bd3dea1 100644 --- a/lib/Frontend/PCHWriterDecl.cpp +++ b/lib/Frontend/PCHWriterDecl.cpp @@ -818,7 +818,17 @@ void PCHDeclWriter::VisitFriendDecl(FriendDecl *D) { } void PCHDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) { - assert(false && "cannot write FriendTemplateDecl"); + VisitDecl(D); + Record.push_back(D->getNumTemplateParameters()); + for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i) + Writer.AddTemplateParameterList(D->getTemplateParameterList(i), Record); + Record.push_back(D->getFriendDecl() != 0); + if (D->getFriendDecl()) + Writer.AddDeclRef(D->getFriendDecl(), Record); + else + Writer.AddTypeSourceInfo(D->getFriendType(), Record); + Writer.AddSourceLocation(D->getFriendLoc(), Record); + Code = pch::DECL_FRIEND_TEMPLATE; } void PCHDeclWriter::VisitTemplateDecl(TemplateDecl *D) { -- 2.40.0