bool serialize(raw_ostream &OS);
virtual Module *loadModule(SourceLocation ImportLoc, ModuleIdPath Path,
- Module::NameVisibilityKind Visibility) {
+ Module::NameVisibilityKind Visibility,
+ bool IsInclusionDirective) {
// ASTUnit doesn't know how to load modules (not that this matters).
return 0;
}
/// }
virtual Module *loadModule(SourceLocation ImportLoc, ModuleIdPath Path,
- Module::NameVisibilityKind Visibility);
+ Module::NameVisibilityKind Visibility,
+ bool IsInclusionDirective);
};
} // end namespace clang
/// \param Visibility The visibility provided for the names in the loaded
/// module.
///
+ /// \param IsInclusionDirective Indicates that this module is being loaded
+ /// implicitly, due to the presence of an inclusion directive. Otherwise,
+ /// it is being loaded due to an import declaration.
+ ///
/// \returns If successful, returns the loaded module. Otherwise, returns
/// NULL to indicate that the module could not be loaded.
virtual Module *loadModule(SourceLocation ImportLoc, ModuleIdPath Path,
- Module::NameVisibilityKind Visibility) = 0;
+ Module::NameVisibilityKind Visibility,
+ bool IsInclusionDirective) = 0;
};
}
Module *Imported,
SourceLocation EndLoc) {
void *Mem = C.Allocate(sizeof(ImportDecl) + sizeof(SourceLocation));
- ImportDecl *Import
- = new (Mem) ImportDecl(DC, ImportLoc, Imported,
- ArrayRef<SourceLocation>(&EndLoc, 1));
+ ImportDecl *Import = new (Mem) ImportDecl(DC, ImportLoc, Imported, EndLoc);
Import->setImplicit();
return Import;
}
#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"
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.
}
// 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;
// If this was an #__include_macros directive, only make macros visible.
Module::NameVisibilityKind Visibility
= (IncludeKind == 3)? Module::MacrosVisible : Module::AllVisible;
- TheModuleLoader.loadModule(IncludeTok.getLocation(), Path, Visibility);
+ TheModuleLoader.loadModule(IncludeTok.getLocation(), Path, Visibility,
+ /*IsIncludeDirective=*/true);
return;
}
// If we have a non-empty module path, load the named module.
if (!ModuleImportPath.empty())
(void)TheModuleLoader.loadModule(ModuleImportLoc, ModuleImportPath,
- Module::MacrosVisible);
+ Module::MacrosVisible,
+ /*IsIncludeDirective=*/false);
}
void Preprocessor::AddCommentHandler(CommentHandler *Handler) {
DeclResult Sema::ActOnModuleImport(SourceLocation ImportLoc, ModuleIdPath Path) {
Module *Mod = PP.getModuleLoader().loadModule(ImportLoc, Path,
- Module::AllVisible);
+ Module::AllVisible,
+ /*IsIncludeDirective=*/false);
if (!Mod)
return true;