[clang] [clang-tools-extra] [clang] Consistently use "load" to refer to populating clang::ModuleMap (PR #132970)
Michael Spencer via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 25 11:16:56 PDT 2025
https://github.com/Bigcheese created https://github.com/llvm/llvm-project/pull/132970
Now that we have ModuleMapFile.cpp which parses module maps, it's confusing what ModuleMap::parseModuleMapFile actually does. HeaderSearch already called this loading a module map, so consistently use that term in ModuleMap too.
An upcoming patch will allow just parsing a module map without loading the modules from it.
>From 985af1dfe88121beafad2c4eb976c685c6ea6d9c Mon Sep 17 00:00:00 2001
From: Michael Spencer <bigcheesegs at gmail.com>
Date: Tue, 25 Mar 2025 11:14:46 -0700
Subject: [PATCH] [clang] Consistently use "load" to refer to populating
clang::ModuleMap
Now that we have ModuleMapFile.cpp which parses module maps, it's
confusing what ModuleMap::parseModuleMapFile actually does.
HeaderSearch already called this loading a module map, so consistently
use that term in ModuleMap too.
An upcoming patch will allow just parsing a module map without loading
the modules from it.
---
.../modularize/ModuleAssistant.cpp | 4 +-
clang/include/clang/Lex/ModuleMap.h | 20 +++---
clang/lib/Lex/HeaderSearch.cpp | 4 +-
clang/lib/Lex/ModuleMap.cpp | 62 +++++++++----------
4 files changed, 45 insertions(+), 45 deletions(-)
diff --git a/clang-tools-extra/modularize/ModuleAssistant.cpp b/clang-tools-extra/modularize/ModuleAssistant.cpp
index c7259d70bd58f..b4ec96617449f 100644
--- a/clang-tools-extra/modularize/ModuleAssistant.cpp
+++ b/clang-tools-extra/modularize/ModuleAssistant.cpp
@@ -129,8 +129,8 @@ Module *Module::findSubModule(llvm::StringRef SubName) {
// Implementation functions:
// Reserved keywords in module.modulemap syntax.
-// Keep in sync with keywords in module map parser in Lex/ModuleMap.cpp,
-// such as in ModuleMapParser::consumeToken().
+// Keep in sync with keywords in module map parser in Lex/ModuleMapFile.cpp,
+// such as in ModuleMapFileParser::consumeToken().
static const char *const ReservedNames[] = {
"config_macros", "export", "module", "conflict", "framework",
"requires", "exclude", "header", "private", "explicit",
diff --git a/clang/include/clang/Lex/ModuleMap.h b/clang/include/clang/Lex/ModuleMap.h
index 3baeea08cc0e3..43c3890631bd1 100644
--- a/clang/include/clang/Lex/ModuleMap.h
+++ b/clang/include/clang/Lex/ModuleMap.h
@@ -43,7 +43,7 @@ class FileManager;
class HeaderSearch;
class SourceManager;
-/// A mechanism to observe the actions of the module map parser as it
+/// A mechanism to observe the actions of the module map loader as it
/// reads module map files.
class ModuleMapCallbacks {
virtual void anchor();
@@ -195,7 +195,7 @@ class ModuleMap {
using AdditionalModMapsSet = llvm::DenseSet<FileEntryRef>;
private:
- friend class ModuleMapParser;
+ friend class ModuleMapLoader;
using HeadersMap = llvm::DenseMap<FileEntryRef, SmallVector<KnownHeader, 1>>;
@@ -259,9 +259,9 @@ class ModuleMap {
llvm::DenseMap<const Module *, AdditionalModMapsSet> AdditionalModMaps;
- /// Describes whether we haved parsed a particular file as a module
+ /// Describes whether we haved loaded a particular file as a module
/// map.
- llvm::DenseMap<const FileEntry *, bool> ParsedModuleMap;
+ llvm::DenseMap<const FileEntry *, bool> LoadedModuleMap;
/// Resolve the given export declaration into an actual export
/// declaration.
@@ -693,10 +693,10 @@ class ModuleMap {
void addHeader(Module *Mod, Module::Header Header,
ModuleHeaderRole Role, bool Imported = false);
- /// Parse the given module map file, and record any modules we
+ /// Load the given module map file, and record any modules we
/// encounter.
///
- /// \param File The file to be parsed.
+ /// \param File The file to be loaded.
///
/// \param IsSystem Whether this module map file is in a system header
/// directory, and therefore should be considered a system module.
@@ -713,10 +713,10 @@ class ModuleMap {
/// that caused us to load this module map file, if any.
///
/// \returns true if an error occurred, false otherwise.
- bool parseModuleMapFile(FileEntryRef File, bool IsSystem,
- DirectoryEntryRef HomeDir, FileID ID = FileID(),
- unsigned *Offset = nullptr,
- SourceLocation ExternModuleLoc = SourceLocation());
+ bool loadModuleMapFile(FileEntryRef File, bool IsSystem,
+ DirectoryEntryRef HomeDir, FileID ID = FileID(),
+ unsigned *Offset = nullptr,
+ SourceLocation ExternModuleLoc = SourceLocation());
/// Dump the contents of the module map, for debugging purposes.
void dump();
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index ad9263f2994f2..95f294238a0d4 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -1783,7 +1783,7 @@ HeaderSearch::loadModuleMapFileImpl(FileEntryRef File, bool IsSystem,
if (!AddResult.second)
return AddResult.first->second ? LMM_AlreadyLoaded : LMM_InvalidModuleMap;
- if (ModMap.parseModuleMapFile(File, IsSystem, Dir, ID, Offset)) {
+ if (ModMap.loadModuleMapFile(File, IsSystem, Dir, ID, Offset)) {
LoadedModuleMaps[File] = false;
return LMM_InvalidModuleMap;
}
@@ -1791,7 +1791,7 @@ HeaderSearch::loadModuleMapFileImpl(FileEntryRef File, bool IsSystem,
// Try to load a corresponding private module map.
if (OptionalFileEntryRef PMMFile =
getPrivateModuleMap(File, FileMgr, Diags)) {
- if (ModMap.parseModuleMapFile(*PMMFile, IsSystem, Dir)) {
+ if (ModMap.loadModuleMapFile(*PMMFile, IsSystem, Dir)) {
LoadedModuleMaps[File] = false;
return LMM_InvalidModuleMap;
}
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index ea142bcc70f8f..ab51b3a103b07 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1051,7 +1051,7 @@ Module *ModuleMap::inferFrameworkModule(DirectoryEntryRef FrameworkDir,
bool IsFrameworkDir = Parent.ends_with(".framework");
if (OptionalFileEntryRef ModMapFile =
HeaderInfo.lookupModuleMapFile(*ParentDir, IsFrameworkDir)) {
- parseModuleMapFile(*ModMapFile, Attrs.IsSystem, *ParentDir);
+ loadModuleMapFile(*ModMapFile, Attrs.IsSystem, *ParentDir);
inferred = InferredDirectories.find(*ParentDir);
}
@@ -1354,7 +1354,7 @@ std::error_code
ModuleMap::canonicalizeModuleMapPath(SmallVectorImpl<char> &Path) {
StringRef Dir = llvm::sys::path::parent_path({Path.data(), Path.size()});
- // Do not canonicalize within the framework; the module map parser expects
+ // Do not canonicalize within the framework; the module map loader expects
// Modules/ not Versions/A/Modules.
if (llvm::sys::path::filename(Dir) == "Modules") {
StringRef Parent = llvm::sys::path::parent_path(Dir);
@@ -1453,11 +1453,11 @@ bool ModuleMap::resolveConflicts(Module *Mod, bool Complain) {
}
//----------------------------------------------------------------------------//
-// Module map file parser
+// Module map file loader
//----------------------------------------------------------------------------//
namespace clang {
-class ModuleMapParser {
+class ModuleMapLoader {
modulemap::ModuleMapFile &MMF;
SourceManager &SourceMgr;
@@ -1467,7 +1467,7 @@ class ModuleMapParser {
/// The current module map file.
FileID ModuleMapFID;
- /// Source location of most recent parsed module declaration
+ /// Source location of most recent loaded module declaration
SourceLocation CurrModuleDeclLoc;
/// The directory that file names in this module map file should
@@ -1515,13 +1515,13 @@ class ModuleMapParser {
using Attributes = ModuleMap::Attributes;
public:
- ModuleMapParser(modulemap::ModuleMapFile &MMF, SourceManager &SourceMgr,
+ ModuleMapLoader(modulemap::ModuleMapFile &MMF, SourceManager &SourceMgr,
DiagnosticsEngine &Diags, ModuleMap &Map, FileID ModuleMapFID,
DirectoryEntryRef Directory, bool IsSystem)
: MMF(MMF), SourceMgr(SourceMgr), Diags(Diags), Map(Map),
ModuleMapFID(ModuleMapFID), Directory(Directory), IsSystem(IsSystem) {}
- bool parseModuleMapFile();
+ bool loadModuleMapFile();
};
} // namespace clang
@@ -1530,7 +1530,7 @@ class ModuleMapParser {
/// module map search logic to find the appropriate private module when PCH
/// is used with implicit module maps. Warn when private modules are written
/// in other ways (FooPrivate and Foo.Private), providing notes and fixits.
-void ModuleMapParser::diagnosePrivateModules(SourceLocation StartLoc) {
+void ModuleMapLoader::diagnosePrivateModules(SourceLocation StartLoc) {
auto GenNoteAndFixIt = [&](StringRef BadName, StringRef Canonical,
const Module *M, SourceRange ReplLoc) {
auto D = Diags.Report(ActiveModule->DefinitionLoc,
@@ -1584,7 +1584,7 @@ void ModuleMapParser::diagnosePrivateModules(SourceLocation StartLoc) {
}
}
-void ModuleMapParser::handleModuleDecl(const modulemap::ModuleDecl &MD) {
+void ModuleMapLoader::handleModuleDecl(const modulemap::ModuleDecl &MD) {
if (MD.Id.front().first == "*")
return handleInferredModuleDecl(MD);
@@ -1763,7 +1763,7 @@ void ModuleMapParser::handleModuleDecl(const modulemap::ModuleDecl &MD) {
ActiveModule = PreviousActiveModule;
}
-void ModuleMapParser::handleExternModuleDecl(
+void ModuleMapLoader::handleExternModuleDecl(
const modulemap::ExternModuleDecl &EMD) {
StringRef FileNameRef = EMD.Path;
SmallString<128> ModuleMapFileName;
@@ -1773,7 +1773,7 @@ void ModuleMapParser::handleExternModuleDecl(
FileNameRef = ModuleMapFileName;
}
if (auto File = SourceMgr.getFileManager().getOptionalFileRef(FileNameRef))
- Map.parseModuleMapFile(
+ Map.loadModuleMapFile(
*File, IsSystem,
Map.HeaderInfo.getHeaderSearchOpts().ModuleMapFileHomeIsCwd
? Directory
@@ -1810,7 +1810,7 @@ static bool shouldAddRequirement(Module *M, StringRef Feature,
return true;
}
-void ModuleMapParser::handleRequiresDecl(const modulemap::RequiresDecl &RD) {
+void ModuleMapLoader::handleRequiresDecl(const modulemap::RequiresDecl &RD) {
for (const modulemap::RequiresFeature &RF : RD.Features) {
bool IsRequiresExcludedHack = false;
@@ -1828,7 +1828,7 @@ void ModuleMapParser::handleRequiresDecl(const modulemap::RequiresDecl &RD) {
}
}
-void ModuleMapParser::handleHeaderDecl(const modulemap::HeaderDecl &HD) {
+void ModuleMapLoader::handleHeaderDecl(const modulemap::HeaderDecl &HD) {
// We've already consumed the first token.
ModuleMap::ModuleHeaderRole Role = ModuleMap::NormalHeader;
@@ -1887,7 +1887,7 @@ static bool compareModuleHeaders(const Module::Header &A,
return A.NameAsWritten < B.NameAsWritten;
}
-void ModuleMapParser::handleUmbrellaDirDecl(
+void ModuleMapLoader::handleUmbrellaDirDecl(
const modulemap::UmbrellaDirDecl &UDD) {
std::string DirName = std::string(UDD.Path);
std::string DirNameAsWritten = DirName;
@@ -1919,7 +1919,7 @@ void ModuleMapParser::handleUmbrellaDirDecl(
if (UsesRequiresExcludedHack.count(ActiveModule)) {
// Mark this header 'textual' (see doc comment for
- // ModuleMapParser::UsesRequiresExcludedHack). Although iterating over the
+ // ModuleMapLoader::UsesRequiresExcludedHack). Although iterating over the
// directory is relatively expensive, in practice this only applies to the
// uncommonly used Tcl module on Darwin platforms.
std::error_code EC;
@@ -1953,12 +1953,12 @@ void ModuleMapParser::handleUmbrellaDirDecl(
Map.setUmbrellaDirAsWritten(ActiveModule, *Dir, DirNameAsWritten, DirName);
}
-void ModuleMapParser::handleExportDecl(const modulemap::ExportDecl &ED) {
+void ModuleMapLoader::handleExportDecl(const modulemap::ExportDecl &ED) {
Module::UnresolvedExportDecl Unresolved = {ED.Location, ED.Id, ED.Wildcard};
ActiveModule->UnresolvedExports.push_back(Unresolved);
}
-void ModuleMapParser::handleExportAsDecl(const modulemap::ExportAsDecl &EAD) {
+void ModuleMapLoader::handleExportAsDecl(const modulemap::ExportAsDecl &EAD) {
auto ModName = EAD.Id.front();
if (!ActiveModule->ExportAsModule.empty()) {
@@ -1976,19 +1976,19 @@ void ModuleMapParser::handleExportAsDecl(const modulemap::ExportAsDecl &EAD) {
Map.addLinkAsDependency(ActiveModule);
}
-void ModuleMapParser::handleUseDecl(const modulemap::UseDecl &UD) {
+void ModuleMapLoader::handleUseDecl(const modulemap::UseDecl &UD) {
if (ActiveModule->Parent)
Diags.Report(UD.Location, diag::err_mmap_use_decl_submodule);
else
ActiveModule->UnresolvedDirectUses.push_back(UD.Id);
}
-void ModuleMapParser::handleLinkDecl(const modulemap::LinkDecl &LD) {
+void ModuleMapLoader::handleLinkDecl(const modulemap::LinkDecl &LD) {
ActiveModule->LinkLibraries.push_back(
Module::LinkLibrary(std::string{LD.Library}, LD.Framework));
}
-void ModuleMapParser::handleConfigMacros(
+void ModuleMapLoader::handleConfigMacros(
const modulemap::ConfigMacrosDecl &CMD) {
if (ActiveModule->Parent) {
Diags.Report(CMD.Location, diag::err_mmap_config_macro_submodule);
@@ -2004,7 +2004,7 @@ void ModuleMapParser::handleConfigMacros(
CMD.Macros.begin(), CMD.Macros.end());
}
-void ModuleMapParser::handleConflict(const modulemap::ConflictDecl &CD) {
+void ModuleMapLoader::handleConflict(const modulemap::ConflictDecl &CD) {
Module::UnresolvedConflict Conflict;
Conflict.Id = CD.Id;
@@ -2013,7 +2013,7 @@ void ModuleMapParser::handleConflict(const modulemap::ConflictDecl &CD) {
ActiveModule->UnresolvedConflicts.push_back(Conflict);
}
-void ModuleMapParser::handleInferredModuleDecl(
+void ModuleMapLoader::handleInferredModuleDecl(
const modulemap::ModuleDecl &MD) {
SourceLocation StarLoc = MD.Id.front().second;
@@ -2103,7 +2103,7 @@ void ModuleMapParser::handleInferredModuleDecl(
}
}
-bool ModuleMapParser::parseModuleMapFile() {
+bool ModuleMapLoader::loadModuleMapFile() {
for (const auto &Decl : MMF.Decls) {
std::visit(
llvm::makeVisitor(
@@ -2116,14 +2116,14 @@ bool ModuleMapParser::parseModuleMapFile() {
return HadError;
}
-bool ModuleMap::parseModuleMapFile(FileEntryRef File, bool IsSystem,
+bool ModuleMap::loadModuleMapFile(FileEntryRef File, bool IsSystem,
DirectoryEntryRef Dir, FileID ID,
unsigned *Offset,
SourceLocation ExternModuleLoc) {
assert(Target && "Missing target information");
llvm::DenseMap<const FileEntry *, bool>::iterator Known
- = ParsedModuleMap.find(File);
- if (Known != ParsedModuleMap.end())
+ = LoadedModuleMap.find(File);
+ if (Known != LoadedModuleMap.end())
return Known->second;
// If the module map file wasn't already entered, do so now.
@@ -2136,7 +2136,7 @@ bool ModuleMap::parseModuleMapFile(FileEntryRef File, bool IsSystem,
assert(Target && "Missing target information");
std::optional<llvm::MemoryBufferRef> Buffer = SourceMgr.getBufferOrNone(ID);
if (!Buffer)
- return ParsedModuleMap[File] = true;
+ return LoadedModuleMap[File] = true;
assert((!Offset || *Offset <= Buffer->getBufferSize()) &&
"invalid buffer offset");
@@ -2144,12 +2144,12 @@ bool ModuleMap::parseModuleMapFile(FileEntryRef File, bool IsSystem,
modulemap::parseModuleMap(ID, Dir, SourceMgr, Diags, IsSystem, Offset);
bool Result = false;
if (MMF) {
- ModuleMapParser Parser(*MMF, SourceMgr, Diags, *this, ID, Dir, IsSystem);
- Result = Parser.parseModuleMapFile();
+ ModuleMapLoader Loader(*MMF, SourceMgr, Diags, *this, ID, Dir, IsSystem);
+ Result = Loader.loadModuleMapFile();
}
- ParsedModuleMap[File] = Result;
+ LoadedModuleMap[File] = Result;
- // Notify callbacks that we parsed it.
+ // Notify callbacks that we loaded it.
for (const auto &Cb : Callbacks)
Cb->moduleMapFileRead(MMF ? MMF->Start : SourceLocation(), File, IsSystem);
More information about the cfe-commits
mailing list