From 72d1aa3cff68617e40260dddbc5be002e8c1c7a2 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Wed, 3 Oct 2012 01:58:37 +0000 Subject: [PATCH] Introduce ASTConsumer::HandleImplicitImportDecl() callback that is invoked when an ImportDecl that was implicitly created due to an inclusion directive. llvm-svn: 165084 --- clang/include/clang/AST/ASTConsumer.h | 6 ++++++ clang/lib/AST/ASTConsumer.cpp | 5 +++++ clang/lib/Frontend/CompilerInstance.cpp | 9 ++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/AST/ASTConsumer.h b/clang/include/clang/AST/ASTConsumer.h index 69a3866..8418b5a 100644 --- a/clang/include/clang/AST/ASTConsumer.h +++ b/clang/include/clang/AST/ASTConsumer.h @@ -25,6 +25,7 @@ namespace clang { class TagDecl; class VarDecl; class FunctionDecl; + class ImportDecl; /// ASTConsumer - This is an abstract interface that should be implemented by /// clients that read ASTs. This abstraction layer allows the client to be @@ -79,6 +80,11 @@ public: /// The default implementation ignored them. virtual void HandleTopLevelDeclInObjCContainer(DeclGroupRef D); + /// \brief Handle an ImportDecl that was implicitly created due to an + /// inclusion directive. + /// The default implementation passes it to HandleTopLevelDecl. + virtual void HandleImplicitImportDecl(ImportDecl *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 1672bc8..a4e17c0 100644 --- a/clang/lib/AST/ASTConsumer.cpp +++ b/clang/lib/AST/ASTConsumer.cpp @@ -13,6 +13,7 @@ #include "clang/AST/ASTConsumer.h" #include "clang/AST/DeclGroup.h" +#include "clang/AST/Decl.h" using namespace clang; bool ASTConsumer::HandleTopLevelDecl(DeclGroupRef D) { @@ -24,3 +25,7 @@ void ASTConsumer::HandleInterestingDecl(DeclGroupRef D) { } void ASTConsumer::HandleTopLevelDeclInObjCContainer(DeclGroupRef D) {} + +void ASTConsumer::HandleImplicitImportDecl(ImportDecl *D) { + HandleTopLevelDecl(DeclGroupRef(D)); +} diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 4cc46b8..bf46e549 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -1082,9 +1082,12 @@ Module *CompilerInstance::loadModule(SourceLocation ImportLoc, // implicit import declaration to capture it in the AST. if (IsInclusionDirective && hasASTContext()) { TranslationUnitDecl *TU = getASTContext().getTranslationUnitDecl(); - TU->addDecl(ImportDecl::CreateImplicit(getASTContext(), TU, - ImportLoc, Module, - Path.back().second)); + ImportDecl *ImportD = ImportDecl::CreateImplicit(getASTContext(), TU, + ImportLoc, Module, + Path.back().second); + TU->addDecl(ImportD); + if (Consumer) + Consumer->HandleImplicitImportDecl(ImportD); } LastModuleImportLoc = ImportLoc; -- 2.7.4