diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-05-15 20:05:43 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-05-15 20:05:43 +0000 |
commit | 42413141641e26462a0d0c95f62b09fea5df78e9 (patch) | |
tree | dfcc51b854345c51e563fdbb5f28c1e7cb24310a /clang/lib/Lex/PPLexerChange.cpp | |
parent | e70f8103781f1c4749b0de99aab050637bb5bd67 (diff) | |
download | bcm5719-llvm-42413141641e26462a0d0c95f62b09fea5df78e9.tar.gz bcm5719-llvm-42413141641e26462a0d0c95f62b09fea5df78e9.zip |
[modules] Add local submodule visibility support for declarations.
With this change, enabling -fmodules-local-submodule-visibility results in name
visibility rules being applied to submodules of the current module in addition
to imported modules (that is, names no longer "leak" between submodules of the
same top-level module). This also makes it much safer to textually include a
non-modular library into a module: each submodule that textually includes that
library will get its own "copy" of that library, and so the library becomes
visible no matter which including submodule you import.
llvm-svn: 237473
Diffstat (limited to 'clang/lib/Lex/PPLexerChange.cpp')
-rw-r--r-- | clang/lib/Lex/PPLexerChange.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp index 4af68b0b80a..ddc3fa646b9 100644 --- a/clang/lib/Lex/PPLexerChange.cpp +++ b/clang/lib/Lex/PPLexerChange.cpp @@ -615,9 +615,21 @@ void Preprocessor::EnterSubmodule(Module *M, SourceLocation ImportLoc) { auto &Info = BuildingSubmoduleStack.back(); Info.Macros.swap(Macros); // Save our visible modules set. This is guaranteed to clear the set. - if (getLangOpts().ModulesLocalVisibility) + if (getLangOpts().ModulesLocalVisibility) { Info.VisibleModules = std::move(VisibleModules); + // Resolve as much of the module definition as we can now, before we enter + // one if its headers. + // FIXME: Can we enable Complain here? + ModuleMap &ModMap = getHeaderSearchInfo().getModuleMap(); + ModMap.resolveExports(M, /*Complain=*/false); + ModMap.resolveUses(M, /*Complain=*/false); + ModMap.resolveConflicts(M, /*Complain=*/false); + + // This module is visible to itself. + makeModuleVisible(M, ImportLoc); + } + // Determine the set of starting macros for this submodule. // FIXME: If we re-enter a submodule, should we restore its MacroDirectives? auto &StartingMacros = getLangOpts().ModulesLocalVisibility @@ -628,7 +640,7 @@ void Preprocessor::EnterSubmodule(Module *M, SourceLocation ImportLoc) { // FIXME: Do this lazily, when each macro name is first referenced. for (auto &Macro : StartingMacros) { MacroState MS(Macro.second.getLatest()); - MS.setOverriddenMacros(*this, MS.getOverriddenMacros()); + MS.setOverriddenMacros(*this, Macro.second.getOverriddenMacros()); Macros.insert(std::make_pair(Macro.first, std::move(MS))); } } @@ -712,6 +724,7 @@ void Preprocessor::LeaveSubmodule() { BuildingSubmoduleStack.pop_back(); // A nested #include makes the included submodule visible. - if (!BuildingSubmoduleStack.empty() || !getLangOpts().ModulesLocalVisibility) + if (!BuildingSubmoduleStack.empty() || + !getLangOpts().ModulesLocalVisibility) makeModuleVisible(LeavingMod, ImportLoc); } |