diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-12-02 23:42:12 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-12-02 23:42:12 +0000 |
commit | bcfc7d02293691a1050b76be2c99e008469644f9 (patch) | |
tree | c3384c75ffc01d79696207ff4aadb3bf4f237535 /clang/lib/Frontend/CompilerInstance.cpp | |
parent | 9dff9f4c41b2cea20d3a268307424d57583f5890 (diff) | |
download | bcm5719-llvm-bcfc7d02293691a1050b76be2c99e008469644f9.tar.gz bcm5719-llvm-bcfc7d02293691a1050b76be2c99e008469644f9.zip |
When we treat an #include or #import as a module import, create an
implicit ImportDecl in the translation unit to record the presence of
the import.
llvm-svn: 145727
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 746c00a3619..6a060e036fb 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -11,6 +11,7 @@ #include "clang/Sema/Sema.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/Decl.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" @@ -1070,7 +1071,8 @@ static void compileModule(CompilerInstance &ImportingInstance, Module *CompilerInstance::loadModule(SourceLocation ImportLoc, ModuleIdPath Path, - Module::NameVisibilityKind Visibility) { + Module::NameVisibilityKind Visibility, + bool IsInclusionDirective) { // If we've already handled this import, just return the cached result. // This one-element cache is important to eliminate redundant diagnostics // when both the preprocessor and parser see the same import declaration. @@ -1259,8 +1261,16 @@ Module *CompilerInstance::loadModule(SourceLocation ImportLoc, } // Make the named module visible. - if (Module) - ModuleManager->makeModuleVisible(Module, Visibility); + ModuleManager->makeModuleVisible(Module, Visibility); + + // If this module import was due to an inclusion directive, create an + // 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)); + } LastModuleImportLoc = ImportLoc; LastModuleImportResult = Module; |