diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 13 | ||||
-rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Lex/Preprocessor.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 32 |
5 files changed, 50 insertions, 7 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 743a447c323..746c00a3619 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -1069,12 +1069,17 @@ static void compileModule(CompilerInstance &ImportingInstance, } Module *CompilerInstance::loadModule(SourceLocation ImportLoc, - ModuleIdPath Path) { + ModuleIdPath Path, + Module::NameVisibilityKind Visibility) { // 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. - if (!ImportLoc.isInvalid() && LastModuleImportLoc == ImportLoc) + if (!ImportLoc.isInvalid() && LastModuleImportLoc == ImportLoc) { + // Make the named module visible. + if (LastModuleImportResult) + ModuleManager->makeModuleVisible(LastModuleImportResult, Visibility); return LastModuleImportResult; + } // Determine what file we're searching from. SourceManager &SourceMgr = getSourceManager(); @@ -1253,7 +1258,9 @@ Module *CompilerInstance::loadModule(SourceLocation ImportLoc, } } - // FIXME: Tell the AST reader to make the named submodule visible. + // Make the named module visible. + if (Module) + ModuleManager->makeModuleVisible(Module, Visibility); LastModuleImportLoc = ImportLoc; LastModuleImportResult = Module; diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 81cb5262098..836d21b2047 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -1360,8 +1360,10 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, "__import_module__ " + PathString.str().str() + ";"); // Load the module. - // FIXME: Deal with __include_macros here. - TheModuleLoader.loadModule(IncludeTok.getLocation(), Path); + // 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); return; } diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index b01113041eb..180e1e2c258 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -593,7 +593,8 @@ void Preprocessor::LexAfterModuleImport(Token &Result) { // If we have a non-empty module path, load the named module. if (!ModuleImportPath.empty()) - (void)TheModuleLoader.loadModule(ModuleImportLoc, ModuleImportPath); + (void)TheModuleLoader.loadModule(ModuleImportLoc, ModuleImportPath, + Module::MacrosVisible); } void Preprocessor::AddCommentHandler(CommentHandler *Handler) { diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 48f4c4f0cba..1e57a00f1f1 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -9892,7 +9892,8 @@ Decl *Sema::ActOnFileScopeAsmDecl(Expr *expr, } DeclResult Sema::ActOnModuleImport(SourceLocation ImportLoc, ModuleIdPath Path) { - Module *Mod = PP.getModuleLoader().loadModule(ImportLoc, Path); + Module *Mod = PP.getModuleLoader().loadModule(ImportLoc, Path, + Module::AllVisible); if (!Mod) return true; diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index d43f8c1f45d..258baebc05c 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -2439,6 +2439,38 @@ ASTReader::ASTReadResult ASTReader::validateFileEntries(ModuleFile &M) { return Success; } +void ASTReader::makeModuleVisible(Module *Mod, + Module::NameVisibilityKind NameVisibility) { + llvm::SmallPtrSet<Module *, 4> Visited; + llvm::SmallVector<Module *, 4> Stack; + Stack.push_back(Mod); + while (!Stack.empty()) { + Mod = Stack.back(); + Stack.pop_back(); + + if (NameVisibility <= Mod->NameVisibility) { + // This module already has this level of visibility (or greater), so + // there is nothing more to do. + continue; + } + + // Update the module's name visibility. + Mod->NameVisibility = NameVisibility; + + // FIXME: If we've already deserialized any names from this module, + // mark them as visible. + + // Push any non-explicit submodules onto the stack to be marked as + // visible. + for (llvm::StringMap<Module *>::iterator Sub = Mod->SubModules.begin(), + SubEnd = Mod->SubModules.end(); + Sub != SubEnd; ++Sub) { + if (!Sub->getValue()->IsExplicit && Visited.insert(Sub->getValue())) + Stack.push_back(Sub->getValue()); + } + } +} + ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, ModuleKind Type) { switch(ReadASTCore(FileName, Type, /*ImportedBy=*/0)) { |