diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-05-01 01:53:09 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-05-01 01:53:09 +0000 |
| commit | a7e2cc684fee41abe367205521bf225dd3d582c0 (patch) | |
| tree | 181a89be83c538a615bd2a1cf9200826c848960a /clang/lib/Lex | |
| parent | 65ace9daa36051aeeb8140bce8e154c61374938f (diff) | |
| download | bcm5719-llvm-a7e2cc684fee41abe367205521bf225dd3d582c0.tar.gz bcm5719-llvm-a7e2cc684fee41abe367205521bf225dd3d582c0.zip | |
[modules] Start moving the module visibility information off the Module itself.
It has no place there; it's not a property of the Module, and it makes
restoring the visibility set when we leave a submodule more difficult.
llvm-svn: 236300
Diffstat (limited to 'clang/lib/Lex')
| -rw-r--r-- | clang/lib/Lex/ModuleMap.cpp | 7 | ||||
| -rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 6 | ||||
| -rw-r--r-- | clang/lib/Lex/PPLexerChange.cpp | 8 | ||||
| -rw-r--r-- | clang/lib/Lex/PPMacroExpansion.cpp | 8 | ||||
| -rw-r--r-- | clang/lib/Lex/Preprocessor.cpp | 26 |
5 files changed, 36 insertions, 19 deletions
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index a4f1c05dc16..29594994ff6 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -89,7 +89,7 @@ ModuleMap::ModuleMap(SourceManager &SourceMgr, DiagnosticsEngine &Diags, HeaderSearch &HeaderInfo) : SourceMgr(SourceMgr), Diags(Diags), LangOpts(LangOpts), Target(Target), HeaderInfo(HeaderInfo), BuiltinIncludeDir(nullptr), - CompilingModule(nullptr), SourceModule(nullptr) { + CompilingModule(nullptr), SourceModule(nullptr), NumCreatedModules(0) { MMapLangOpts.LineComment = true; } @@ -563,7 +563,7 @@ ModuleMap::findOrCreateModule(StringRef Name, Module *Parent, bool IsFramework, // Create a new module with this name. Module *Result = new Module(Name, SourceLocation(), Parent, - IsFramework, IsExplicit); + IsFramework, IsExplicit, NumCreatedModules++); if (LangOpts.CurrentModule == Name) { SourceModule = Result; SourceModuleName = Name; @@ -693,7 +693,8 @@ Module *ModuleMap::inferFrameworkModule(StringRef ModuleName, return nullptr; Module *Result = new Module(ModuleName, SourceLocation(), Parent, - /*IsFramework=*/true, /*IsExplicit=*/false); + /*IsFramework=*/true, /*IsExplicit=*/false, + NumCreatedModules++); InferredModuleAllowedBy[Result] = ModuleMapFile; Result->IsInferred = true; if (LangOpts.CurrentModule == ModuleName) { diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 1c66aac533b..7de6c14ef36 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -1686,7 +1686,8 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, ModuleLoadResult Imported = TheModuleLoader.loadModule(IncludeTok.getLocation(), Path, Visibility, /*IsIncludeDirective=*/true); - ++MacroVisibilityGeneration; + if (Imported) + makeModuleVisible(Imported, IncludeTok.getLocation()); assert((Imported == nullptr || Imported == SuggestedModule.getModule()) && "the imported module is different than the suggested one"); @@ -1766,6 +1767,9 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, assert(!FID.isInvalid() && "Expected valid file ID"); // Determine if we're switching to building a new submodule, and which one. + // + // FIXME: If we've already processed this header, just make it visible rather + // than entering it again. ModuleMap::KnownHeader BuildingModule; if (getLangOpts().Modules && !getLangOpts().CurrentModule.empty()) { Module *RequestingModule = getModuleForLocation(FilenameLoc); diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp index dc1b5bed049..6766fdfcd07 100644 --- a/clang/lib/Lex/PPLexerChange.cpp +++ b/clang/lib/Lex/PPLexerChange.cpp @@ -671,13 +671,7 @@ void Preprocessor::LeaveSubmodule() { Macro.second.setOverriddenMacros(SavedInfo.Overridden); } - if (Info.M->NameVisibility < Module::MacrosVisible) { - Info.M->NameVisibility = Module::MacrosVisible; - Info.M->MacroVisibilityLoc = Info.ImportLoc; - ++MacroVisibilityGeneration; - // FIXME: Also mark any exported modules as visible, and check for - // conflicts. - } + makeModuleVisible(Info.M, Info.ImportLoc); BuildingSubmoduleStack.pop_back(); } diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index fca3f8b97ce..edeed42c17e 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -124,9 +124,9 @@ ModuleMacro *Preprocessor::getModuleMacro(Module *Mod, IdentifierInfo *II) { void Preprocessor::updateModuleMacroInfo(const IdentifierInfo *II, ModuleMacroInfo &Info) { - assert(Info.ActiveModuleMacrosGeneration != MacroVisibilityGeneration && + assert(Info.ActiveModuleMacrosGeneration != VisibleModules.getGeneration() && "don't need to update this macro name info"); - Info.ActiveModuleMacrosGeneration = MacroVisibilityGeneration; + Info.ActiveModuleMacrosGeneration = VisibleModules.getGeneration(); auto Leaf = LeafModuleMacros.find(II); if (Leaf == LeafModuleMacros.end()) { @@ -146,7 +146,7 @@ void Preprocessor::updateModuleMacroInfo(const IdentifierInfo *II, Leaf->second.end()); while (!Worklist.empty()) { auto *MM = Worklist.pop_back_val(); - if (MM->getOwningModule()->NameVisibility >= Module::MacrosVisible) { + if (VisibleModules.isVisible(MM->getOwningModule())) { // We only care about collecting definitions; undefinitions only act // to override other definitions. if (MM->getMacroInfo()) @@ -236,7 +236,7 @@ void Preprocessor::dumpMacroInfo(const IdentifierInfo *II) { if (Active.count(MM)) llvm::errs() << " active"; - else if (MM->getOwningModule()->NameVisibility < Module::MacrosVisible) + else if (!VisibleModules.isVisible(MM->getOwningModule())) llvm::errs() << " hidden"; else llvm::errs() << " overridden"; diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 231720b8db1..2db109565af 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -107,9 +107,6 @@ Preprocessor::Preprocessor(IntrusiveRefCntPtr<PreprocessorOptions> PPOpts, // We haven't read anything from the external source. ReadMacrosFromExternalSource = false; - // We might already have some macros from an imported module (via a PCH or - // preamble) if modules is enabled. - MacroVisibilityGeneration = LangOpts.Modules ? 1 : 0; // "Poison" __VA_ARGS__, which can only appear in the expansion of a macro. // This gets unpoisoned where it is allowed. @@ -757,13 +754,34 @@ void Preprocessor::LexAfterModuleImport(Token &Result) { ModuleImportPath, Module::MacrosVisible, /*IsIncludeDirective=*/false); - ++MacroVisibilityGeneration; + if (Imported) + makeModuleVisible(Imported, ModuleImportLoc); } if (Callbacks && (getLangOpts().Modules || getLangOpts().DebuggerSupport)) Callbacks->moduleImport(ModuleImportLoc, ModuleImportPath, Imported); } } +void Preprocessor::makeModuleVisible(Module *M, SourceLocation Loc) { + if (VisibleModules.isVisible(M)) + return; + + VisibleModules.setVisible( + M, Loc, [](Module *) {}, + [&](ArrayRef<Module *> Path, Module *Conflict, StringRef Message) { + // FIXME: Include the path in the diagnostic. + // FIXME: Include the import location for the conflicting module. + Diag(ModuleImportLoc, diag::warn_module_conflict) + << Path[0]->getFullModuleName() + << Conflict->getFullModuleName() + << Message; + }); + + // Add this module to the imports list of the currently-built submodule. + if (!BuildingSubmoduleStack.empty()) + BuildingSubmoduleStack.back().M->Imports.push_back(M); +} + bool Preprocessor::FinishLexStringLiteral(Token &Result, std::string &String, const char *DiagnosticTag, bool AllowMacroExpansion) { |

