jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, ahoppen.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch extracts the construction of `Module` within `ModuleMap` into a 
separate function.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116751

Files:
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Lex/ModuleMap.cpp

Index: clang/lib/Lex/ModuleMap.cpp
===================================================================
--- clang/lib/Lex/ModuleMap.cpp
+++ 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("<global>", Loc, Parent, /*IsFramework*/ false,
+  auto *Result = makeModule("<global>", 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("<private>", Loc, Parent, /*IsFramework*/ false,
+      makeModule("<private>", 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);
Index: clang/include/clang/Lex/ModuleMap.h
===================================================================
--- clang/include/clang/Lex/ModuleMap.h
+++ clang/include/clang/Lex/ModuleMap.h
@@ -279,6 +279,11 @@
   /// map.
   llvm::DenseMap<const FileEntry *, bool> 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.
   ///
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to