From c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Sun, 4 Jul 2010 21:44:35 +0000 Subject: [PATCH] Read/write more information of ASTContext for PCH. Overriden methods and instantiated-from information. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107597 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ASTContext.h | 2 ++ include/clang/AST/DeclCXX.h | 1 + lib/AST/ASTContext.cpp | 10 ++++++++++ lib/AST/DeclCXX.cpp | 4 ++++ lib/Frontend/PCHReaderDecl.cpp | 19 +++++++++++++++++++ lib/Frontend/PCHWriterDecl.cpp | 9 +++++++++ 6 files changed, 45 insertions(+) diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 0c36ad7b93..816d59512c 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -362,6 +362,8 @@ public: overridden_cxx_method_iterator overridden_methods_end(const CXXMethodDecl *Method) const; + unsigned overridden_methods_size(const CXXMethodDecl *Method) const; + /// \brief Note that the given C++ \p Method overrides the given \p /// Overridden method. void addOverriddenMethod(const CXXMethodDecl *Method, diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index 98ab83c6a6..1b7958a5fd 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -1114,6 +1114,7 @@ public: method_iterator begin_overridden_methods() const; method_iterator end_overridden_methods() const; + unsigned size_overridden_methods() const; /// getParent - Returns the parent of this method declaration, which /// is the class in which this method is defined. diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 24ddb127bd..4fb9d369de 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -478,6 +478,16 @@ ASTContext::overridden_methods_end(const CXXMethodDecl *Method) const { return Pos->second.end(); } +unsigned +ASTContext::overridden_methods_size(const CXXMethodDecl *Method) const { + llvm::DenseMap::const_iterator Pos + = OverriddenMethods.find(Method); + if (Pos == OverriddenMethods.end()) + return 0; + + return Pos->second.size(); +} + void ASTContext::addOverriddenMethod(const CXXMethodDecl *Method, const CXXMethodDecl *Overridden) { OverriddenMethods[Method].push_back(Overridden); diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index 7ce9c64de0..19c3ac1011 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -716,6 +716,10 @@ CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const { return getASTContext().overridden_methods_end(this); } +unsigned CXXMethodDecl::size_overridden_methods() const { + return getASTContext().overridden_methods_size(this); +} + QualType CXXMethodDecl::getThisType(ASTContext &C) const { // C++ 9.3.2p1: The type of this in a member function of a class X is X*. // If the member function is declared const, the type of this is const X*, diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp index c9bf4470eb..be4f72ec3b 100644 --- a/lib/Frontend/PCHReaderDecl.cpp +++ b/lib/Frontend/PCHReaderDecl.cpp @@ -507,6 +507,11 @@ void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) { FD->setMutable(Record[Idx++]); if (Record[Idx++]) FD->setBitWidth(Reader.ReadExpr()); + if (!FD->getDeclName()) { + FieldDecl *Tmpl = cast_or_null(Reader.GetDecl(Record[Idx++])); + if (Tmpl) + Reader.getContext()->setInstantiatedFromUnnamedFieldDecl(FD, Tmpl); + } } void PCHDeclReader::VisitVarDecl(VarDecl *VD) { @@ -603,12 +608,19 @@ void PCHDeclReader::VisitUsingDecl(UsingDecl *D) { D->addShadowDecl(cast(Reader.GetDecl(Record[Idx++]))); } D->setTypeName(Record[Idx++]); + NamedDecl *Pattern = cast_or_null(Reader.GetDecl(Record[Idx++])); + if (Pattern) + Reader.getContext()->setInstantiatedFromUsingDecl(D, Pattern); } void PCHDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) { VisitNamedDecl(D); D->setTargetDecl(cast(Reader.GetDecl(Record[Idx++]))); D->setUsingDecl(cast(Reader.GetDecl(Record[Idx++]))); + UsingShadowDecl *Pattern + = cast_or_null(Reader.GetDecl(Record[Idx++])); + if (Pattern) + Reader.getContext()->setInstantiatedFromUsingShadowDecl(D, Pattern); } void PCHDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { @@ -715,6 +727,13 @@ void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) { void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) { VisitFunctionDecl(D); + unsigned NumOverridenMethods = Record[Idx++]; + while (NumOverridenMethods--) { + CXXMethodDecl *MD = cast(Reader.GetDecl(Record[Idx++])); + // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod, + // MD may be initializing. + Reader.getContext()->addOverriddenMethod(D, MD); + } } void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) { diff --git a/lib/Frontend/PCHWriterDecl.cpp b/lib/Frontend/PCHWriterDecl.cpp index 24777966b1..deca4b22ec 100644 --- a/lib/Frontend/PCHWriterDecl.cpp +++ b/lib/Frontend/PCHWriterDecl.cpp @@ -476,6 +476,8 @@ void PCHDeclWriter::VisitFieldDecl(FieldDecl *D) { Record.push_back(D->getBitWidth()? 1 : 0); if (D->getBitWidth()) Writer.AddStmt(D->getBitWidth()); + if (!D->getDeclName()) + Writer.AddDeclRef(Context.getInstantiatedFromUnnamedFieldDecl(D), Record); Code = pch::DECL_FIELD; } @@ -609,6 +611,7 @@ void PCHDeclWriter::VisitUsingDecl(UsingDecl *D) { PEnd = D->shadow_end(); P != PEnd; ++P) Writer.AddDeclRef(*P, Record); Record.push_back(D->isTypeName()); + Writer.AddDeclRef(Context.getInstantiatedFromUsingDecl(D), Record); Code = pch::DECL_USING; } @@ -616,6 +619,7 @@ void PCHDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) { VisitNamedDecl(D); Writer.AddDeclRef(D->getTargetDecl(), Record); Writer.AddDeclRef(D->getUsingDecl(), Record); + Writer.AddDeclRef(Context.getInstantiatedFromUsingShadowDecl(D), Record); Code = pch::DECL_USING_SHADOW; } @@ -714,6 +718,11 @@ void PCHDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) { void PCHDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) { VisitFunctionDecl(D); + Record.push_back(D->size_overridden_methods()); + for (CXXMethodDecl::method_iterator + I = D->begin_overridden_methods(), E = D->end_overridden_methods(); + I != E; ++I) + Writer.AddDeclRef(*I, Record); Code = pch::DECL_CXX_METHOD; } -- 2.50.1