From bd8b150dfca4d03a4fba4407b3fad852425fdf3d Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Mon, 17 Oct 2011 19:48:13 +0000 Subject: [PATCH] Introduce ASTConsumer::HandleTopLevelDeclInObjCContainer which accepts top-level declarations that occurred inside an ObjC container. This is useful to keep track of such decls otherwise when e.g. a function is declared inside an objc interface, it is not passed to HandleTopLevelDecl and it is not inside the DeclContext of the interface that is returned. llvm-svn: 142232 --- clang/include/clang/AST/ASTConsumer.h | 5 +++++ clang/lib/AST/ASTConsumer.cpp | 2 ++ clang/lib/Sema/SemaDeclObjC.cpp | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/clang/include/clang/AST/ASTConsumer.h b/clang/include/clang/AST/ASTConsumer.h index fcc91768dac3..300e4f26d332 100644 --- a/clang/include/clang/AST/ASTConsumer.h +++ b/clang/include/clang/AST/ASTConsumer.h @@ -65,6 +65,11 @@ public: /// can be defined in declspecs). virtual void HandleTagDeclDefinition(TagDecl *D) {} + /// \brief Handle the specified top-level declaration that occurred inside + /// and ObjC container. + /// The default implementation ignored them. + virtual void HandleTopLevelDeclInObjCContainer(DeclGroupRef D); + /// CompleteTentativeDefinition - Callback invoked at the end of a translation /// unit to notify the consumer that the given tentative definition should be /// completed. diff --git a/clang/lib/AST/ASTConsumer.cpp b/clang/lib/AST/ASTConsumer.cpp index 04a084a06a44..062f1103e91f 100644 --- a/clang/lib/AST/ASTConsumer.cpp +++ b/clang/lib/AST/ASTConsumer.cpp @@ -20,3 +20,5 @@ void ASTConsumer::HandleTopLevelDecl(DeclGroupRef D) {} void ASTConsumer::HandleInterestingDecl(DeclGroupRef D) { HandleTopLevelDecl(D); } + +void ASTConsumer::HandleTopLevelDeclInObjCContainer(DeclGroupRef D) {} diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index 1de17d213181..669ea8f32a93 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -2302,6 +2302,11 @@ void Sema::ActOnAtEnd(Scope *S, SourceRange AtEnd, } } ActOnObjCContainerFinishDefinition(); + + for (unsigned i = 0; i != tuvNum; i++) { + DeclGroupRef DG = allTUVars[i].getAsVal(); + Consumer.HandleTopLevelDeclInObjCContainer(DG); + } }