From db215964732a3a43718133083222e62fed7c3ee7 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Fri, 14 Oct 2011 17:41:52 +0000 Subject: [PATCH] [PCH] Serialize info about redeclared objc methods. llvm-svn: 141964 --- clang/include/clang/AST/ASTContext.h | 3 ++- clang/include/clang/AST/DeclObjC.h | 7 +++++-- clang/lib/AST/DeclObjC.cpp | 6 ++++-- clang/lib/Serialization/ASTReaderDecl.cpp | 7 +++++++ clang/lib/Serialization/ASTWriterDecl.cpp | 8 ++++++++ 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 05311ff0bf37..616045c7b4d1 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -1592,7 +1592,8 @@ public: /// \brief Get the duplicate declaration of a ObjCMethod in the same /// interface, or null if non exists. - const ObjCMethodDecl *getObjCMethodRedeclaration(ObjCMethodDecl *MD) const { + const ObjCMethodDecl *getObjCMethodRedeclaration( + const ObjCMethodDecl *MD) const { llvm::DenseMap::const_iterator I = ObjCMethodRedecls.find(MD); if (I == ObjCMethodRedecls.end()) diff --git a/clang/include/clang/AST/DeclObjC.h b/clang/include/clang/AST/DeclObjC.h index ea36914eb779..425c89d290a6 100644 --- a/clang/include/clang/AST/DeclObjC.h +++ b/clang/include/clang/AST/DeclObjC.h @@ -128,9 +128,12 @@ private: // Method has a definition. unsigned IsDefined : 1; - // Method redeclaration in the same interface. + /// \brief Method redeclaration in the same interface. unsigned IsRedeclaration : 1; + /// \brief Is redeclared in the same interface. + mutable unsigned HasRedeclaration : 1; + // NOTE: VC++ treats enums as signed, avoid using ImplementationControl enum /// @required/@optional unsigned DeclImplementation : 2; @@ -223,7 +226,7 @@ private: DeclContext(ObjCMethod), Family(InvalidObjCMethodFamily), IsInstance(isInstance), IsVariadic(isVariadic), IsSynthesized(isSynthesized), - IsDefined(isDefined), IsRedeclaration(0), + IsDefined(isDefined), IsRedeclaration(0), HasRedeclaration(0), DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None), RelatedResultType(HasRelatedResultType), SelLocsKind(SelLoc_StandardNoSpace), diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp index 170cdf43fc42..a589b7f9d3e9 100644 --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/lib/AST/DeclObjC.cpp @@ -355,6 +355,7 @@ void ObjCMethodDecl::setAsRedeclaration(const ObjCMethodDecl *PrevMethod) { assert(PrevMethod); getASTContext().setObjCMethodRedeclaration(PrevMethod, this); IsRedeclaration = true; + PrevMethod->HasRedeclaration = true; } void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C, @@ -398,8 +399,9 @@ void ObjCMethodDecl::setMethodParams(ASTContext &C, /// Otherwise it will return itself. ObjCMethodDecl *ObjCMethodDecl::getNextRedeclaration() { ASTContext &Ctx = getASTContext(); - ObjCMethodDecl *Redecl = - const_cast(Ctx.getObjCMethodRedeclaration(this)); + ObjCMethodDecl *Redecl = 0; + if (HasRedeclaration) + Redecl = const_cast(Ctx.getObjCMethodRedeclaration(this)); if (Redecl) return Redecl; diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index 3e6188be4d2b..6cc3f0a70bc1 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -482,6 +482,13 @@ void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { MD->setVariadic(Record[Idx++]); MD->setSynthesized(Record[Idx++]); MD->setDefined(Record[Idx++]); + + MD->IsRedeclaration = Record[Idx++]; + MD->HasRedeclaration = Record[Idx++]; + if (MD->HasRedeclaration) + Reader.getContext().setObjCMethodRedeclaration(MD, + ReadDeclAs(Record, Idx)); + MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]); MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]); MD->SetRelatedResultType(Record[Idx++]); diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp index 9b29fa60fec9..a8243e502e30 100644 --- a/clang/lib/Serialization/ASTWriterDecl.cpp +++ b/clang/lib/Serialization/ASTWriterDecl.cpp @@ -402,6 +402,14 @@ void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) { Record.push_back(D->isVariadic()); Record.push_back(D->isSynthesized()); Record.push_back(D->isDefined()); + + Record.push_back(D->IsRedeclaration); + Record.push_back(D->HasRedeclaration); + if (D->HasRedeclaration) { + assert(Context.getObjCMethodRedeclaration(D)); + Writer.AddDeclRef(Context.getObjCMethodRedeclaration(D), Record); + } + // FIXME: stable encoding for @required/@optional Record.push_back(D->getImplementationControl()); // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway