[clang] [clang][modules] Separate parsing of modulemaps (PR #119740)

Ben Langmuir via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 10 15:16:45 PST 2025


================
@@ -3157,25 +2140,18 @@ bool ModuleMap::parseModuleMapFile(FileEntryRef File, bool IsSystem,
   assert((!Offset || *Offset <= Buffer->getBufferSize()) &&
          "invalid buffer offset");
 
-  // Parse this module map file.
-  Lexer L(SourceMgr.getLocForStartOfFile(ID), MMapLangOpts,
-          Buffer->getBufferStart(),
-          Buffer->getBufferStart() + (Offset ? *Offset : 0),
-          Buffer->getBufferEnd());
-  SourceLocation Start = L.getSourceLocation();
-  ModuleMapParser Parser(L, SourceMgr, Target, Diags, *this, ID, Dir, IsSystem);
-  bool Result = Parser.parseModuleMapFile();
-  ParsedModuleMap[File] = Result;
-
-  if (Offset) {
-    auto Loc = SourceMgr.getDecomposedLoc(Parser.getLocation());
-    assert(Loc.first == ID && "stopped in a different file?");
-    *Offset = Loc.second;
+  std::optional<modulemap::ModuleMapFile> MMF =
+      modulemap::parseModuleMap(File, SourceMgr, Diags, IsSystem, Offset);
+  bool Result = false;
+  if (MMF) {
+    ModuleMapParser Parser(*MMF, SourceMgr, Diags, *this, ID, Dir, IsSystem);
+    Result = Parser.parseModuleMapFile();
   }
+  ParsedModuleMap[File] = Result;
 
   // Notify callbacks that we parsed it.
   for (const auto &Cb : Callbacks)
-    Cb->moduleMapFileRead(Start, File, IsSystem);
+    Cb->moduleMapFileRead(SourceLocation(), File, IsSystem);
----------------
benlangmuir wrote:

The empty source loc deserves a comment (a TODO maybe since you plan to change this?)

https://github.com/llvm/llvm-project/pull/119740


More information about the cfe-commits mailing list