diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-09-15 01:21:15 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-09-15 01:21:15 +0000 |
commit | 84853833c24ba9c1b5196d4c556e353781b8d789 (patch) | |
tree | 9c8b0dac6d49a4523ed41b86d2404375d31a462c /lib/Lex | |
parent | 74afe0c6779c6ae024d076636230605f92675f39 (diff) |
[modules] Frontend support for building a header module from a list of
headaer files.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@342304 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex')
-rw-r--r-- | lib/Lex/ModuleMap.cpp | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/lib/Lex/ModuleMap.cpp b/lib/Lex/ModuleMap.cpp index a1e9138217..b6a6e26d6a 100644 --- a/lib/Lex/ModuleMap.cpp +++ b/lib/Lex/ModuleMap.cpp @@ -806,12 +806,11 @@ std::pair<Module *, bool> ModuleMap::findOrCreateModule(StringRef Name, } Module *ModuleMap::createGlobalModuleForInterfaceUnit(SourceLocation Loc) { - assert(!PendingGlobalModule && "created multiple global modules"); - PendingGlobalModule.reset( + PendingSubmodules.emplace_back( new Module("<global>", Loc, nullptr, /*IsFramework*/ false, /*IsExplicit*/ true, NumCreatedModules++)); - PendingGlobalModule->Kind = Module::GlobalModuleFragment; - return PendingGlobalModule.get(); + PendingSubmodules.back()->Kind = Module::GlobalModuleFragment; + return PendingSubmodules.back().get(); } Module *ModuleMap::createModuleForInterfaceUnit(SourceLocation Loc, @@ -827,10 +826,11 @@ Module *ModuleMap::createModuleForInterfaceUnit(SourceLocation Loc, Modules[Name] = SourceModule = Result; // Reparent the current global module fragment as a submodule of this module. - assert(GlobalModule == PendingGlobalModule.get() && - "unexpected global module"); - GlobalModule->setParent(Result); - PendingGlobalModule.release(); // now owned by parent + for (auto &Submodule : PendingSubmodules) { + Submodule->setParent(Result); + Submodule.release(); // now owned by parent + } + PendingSubmodules.clear(); // Mark the main source file as being within the newly-created module so that // declarations and macros are properly visibility-restricted to it. @@ -841,6 +841,29 @@ Module *ModuleMap::createModuleForInterfaceUnit(SourceLocation Loc, return Result; } +Module *ModuleMap::createHeaderModule(StringRef Name, + ArrayRef<Module::Header> Headers) { + assert(LangOpts.CurrentModule == Name && "module name mismatch"); + assert(!Modules[Name] && "redefining existing module"); + + auto *Result = + new Module(Name, SourceLocation(), nullptr, /*IsFramework*/ false, + /*IsExplicit*/ false, NumCreatedModules++); + Result->Kind = Module::ModuleInterfaceUnit; + Modules[Name] = SourceModule = Result; + + for (const Module::Header &H : Headers) { + auto *M = new Module(H.NameAsWritten, SourceLocation(), Result, + /*IsFramework*/ false, + /*IsExplicit*/ true, NumCreatedModules++); + // Header modules are implicitly 'export *'. + M->Exports.push_back(Module::ExportDecl(nullptr, true)); + addHeader(M, H, NormalHeader); + } + + return Result; +} + /// For a framework module, infer the framework against which we /// should link. static void inferFrameworkLink(Module *Mod, const DirectoryEntry *FrameworkDir, |