diff --git a/clang/include/clang/Lex/ModuleMap.h b/clang/include/clang/Lex/ModuleMap.h --- a/clang/include/clang/Lex/ModuleMap.h +++ b/clang/include/clang/Lex/ModuleMap.h @@ -279,6 +279,11 @@ /// map. llvm::DenseMap ParsedModuleMap; + /// Creates new Module. + Module *makeModule(StringRef Name, SourceLocation DefinitionLoc, + Module *Parent, bool IsFramework, bool IsExplicit, + unsigned VisibilityID); + /// Resolve the given export declaration into an actual export /// declaration. /// diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -104,6 +104,13 @@ llvm_unreachable("unknown header kind"); } +Module *ModuleMap::makeModule(StringRef Name, SourceLocation DefinitionLoc, + Module *Parent, bool IsFramework, bool IsExplicit, + unsigned VisibilityID) { + return new Module(Name, DefinitionLoc, Parent, IsFramework, IsExplicit, + VisibilityID); +} + Module::ExportDecl ModuleMap::resolveExport(Module *Mod, const Module::UnresolvedExportDecl &Unresolved, @@ -821,7 +828,7 @@ return std::make_pair(Sub, false); // Create a new module with this name. - Module *Result = new Module(Name, SourceLocation(), Parent, IsFramework, + Module *Result = makeModule(Name, SourceLocation(), Parent, IsFramework, IsExplicit, NumCreatedModules++); if (!Parent) { if (LangOpts.CurrentModule == Name) @@ -834,7 +841,7 @@ Module *ModuleMap::createGlobalModuleFragmentForModuleUnit(SourceLocation Loc, Module *Parent) { - auto *Result = new Module("", Loc, Parent, /*IsFramework*/ false, + auto *Result = makeModule("", Loc, Parent, /*IsFramework*/ false, /*IsExplicit*/ true, NumCreatedModules++); Result->Kind = Module::GlobalModuleFragment; // If the created module isn't owned by a parent, send it to PendingSubmodules @@ -848,7 +855,7 @@ ModuleMap::createPrivateModuleFragmentForInterfaceUnit(Module *Parent, SourceLocation Loc) { auto *Result = - new Module("", Loc, Parent, /*IsFramework*/ false, + makeModule("", Loc, Parent, /*IsFramework*/ false, /*IsExplicit*/ true, NumCreatedModules++); Result->Kind = Module::PrivateModuleFragment; return Result; @@ -861,7 +868,7 @@ assert(!Modules[Name] && "redefining existing module"); auto *Result = - new Module(Name, Loc, nullptr, /*IsFramework*/ false, + makeModule(Name, Loc, nullptr, /*IsFramework*/ false, /*IsExplicit*/ false, NumCreatedModules++); Result->Kind = Module::ModuleInterfaceUnit; Modules[Name] = SourceModule = Result; @@ -888,13 +895,13 @@ assert(!Modules[Name] && "redefining existing module"); auto *Result = - new Module(Name, SourceLocation(), nullptr, /*IsFramework*/ false, + makeModule(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, + auto *M = makeModule(H.NameAsWritten, SourceLocation(), Result, /*IsFramework*/ false, /*IsExplicit*/ true, NumCreatedModules++); // Header modules are implicitly 'export *'. @@ -1023,7 +1030,7 @@ if (!UmbrellaHeader) return nullptr; - Module *Result = new Module(ModuleName, SourceLocation(), Parent, + Module *Result = makeModule(ModuleName, SourceLocation(), Parent, /*IsFramework=*/true, /*IsExplicit=*/false, NumCreatedModules++); InferredModuleAllowedBy[Result] = ModuleMapFile; @@ -1116,7 +1123,7 @@ // Create a new module with this name. Module *Result = - new Module(Name, SourceLocation(), /*Parent=*/nullptr, IsFramework, + makeModule(Name, SourceLocation(), /*Parent=*/nullptr, IsFramework, /*IsExplicit=*/false, NumCreatedModules++); Result->ShadowingModule = ShadowingModule; Result->markUnavailable(/*Unimportable*/true);