Skip to content

Commit 57f2e76

Browse files
authored
[clang] Consistently use "load" to refer to populating clang::ModuleMap (#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.
1 parent bdbad3e commit 57f2e76

File tree

4 files changed

+50
-49
lines changed

4 files changed

+50
-49
lines changed

clang-tools-extra/modularize/ModuleAssistant.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ Module *Module::findSubModule(llvm::StringRef SubName) {
129129
// Implementation functions:
130130

131131
// Reserved keywords in module.modulemap syntax.
132-
// Keep in sync with keywords in module map parser in Lex/ModuleMap.cpp,
133-
// such as in ModuleMapParser::consumeToken().
132+
// Keep in sync with keywords in module map parser in Lex/ModuleMapFile.cpp,
133+
// such as in ModuleMapFileParser::consumeToken().
134134
static const char *const ReservedNames[] = {
135135
"config_macros", "export", "module", "conflict", "framework",
136136
"requires", "exclude", "header", "private", "explicit",

clang/include/clang/Lex/ModuleMap.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class FileManager;
4343
class HeaderSearch;
4444
class SourceManager;
4545

46-
/// A mechanism to observe the actions of the module map parser as it
46+
/// A mechanism to observe the actions of the module map loader as it
4747
/// reads module map files.
4848
class ModuleMapCallbacks {
4949
virtual void anchor();
@@ -195,7 +195,7 @@ class ModuleMap {
195195
using AdditionalModMapsSet = llvm::DenseSet<FileEntryRef>;
196196

197197
private:
198-
friend class ModuleMapParser;
198+
friend class ModuleMapLoader;
199199

200200
using HeadersMap = llvm::DenseMap<FileEntryRef, SmallVector<KnownHeader, 1>>;
201201

@@ -259,9 +259,9 @@ class ModuleMap {
259259

260260
llvm::DenseMap<const Module *, AdditionalModMapsSet> AdditionalModMaps;
261261

262-
/// Describes whether we haved parsed a particular file as a module
262+
/// Describes whether we haved loaded a particular file as a module
263263
/// map.
264-
llvm::DenseMap<const FileEntry *, bool> ParsedModuleMap;
264+
llvm::DenseMap<const FileEntry *, bool> LoadedModuleMap;
265265

266266
/// Resolve the given export declaration into an actual export
267267
/// declaration.
@@ -693,10 +693,10 @@ class ModuleMap {
693693
void addHeader(Module *Mod, Module::Header Header,
694694
ModuleHeaderRole Role, bool Imported = false);
695695

696-
/// Parse the given module map file, and record any modules we
696+
/// Load the given module map file, and record any modules we
697697
/// encounter.
698698
///
699-
/// \param File The file to be parsed.
699+
/// \param File The file to be loaded.
700700
///
701701
/// \param IsSystem Whether this module map file is in a system header
702702
/// directory, and therefore should be considered a system module.
@@ -713,10 +713,10 @@ class ModuleMap {
713713
/// that caused us to load this module map file, if any.
714714
///
715715
/// \returns true if an error occurred, false otherwise.
716-
bool parseModuleMapFile(FileEntryRef File, bool IsSystem,
717-
DirectoryEntryRef HomeDir, FileID ID = FileID(),
718-
unsigned *Offset = nullptr,
719-
SourceLocation ExternModuleLoc = SourceLocation());
716+
bool loadModuleMapFile(FileEntryRef File, bool IsSystem,
717+
DirectoryEntryRef HomeDir, FileID ID = FileID(),
718+
unsigned *Offset = nullptr,
719+
SourceLocation ExternModuleLoc = SourceLocation());
720720

721721
/// Dump the contents of the module map, for debugging purposes.
722722
void dump();

clang/lib/Lex/HeaderSearch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,15 +1782,15 @@ HeaderSearch::loadModuleMapFileImpl(FileEntryRef File, bool IsSystem,
17821782
if (!AddResult.second)
17831783
return AddResult.first->second ? LMM_AlreadyLoaded : LMM_InvalidModuleMap;
17841784

1785-
if (ModMap.parseModuleMapFile(File, IsSystem, Dir, ID, Offset)) {
1785+
if (ModMap.loadModuleMapFile(File, IsSystem, Dir, ID, Offset)) {
17861786
LoadedModuleMaps[File] = false;
17871787
return LMM_InvalidModuleMap;
17881788
}
17891789

17901790
// Try to load a corresponding private module map.
17911791
if (OptionalFileEntryRef PMMFile =
17921792
getPrivateModuleMap(File, FileMgr, Diags)) {
1793-
if (ModMap.parseModuleMapFile(*PMMFile, IsSystem, Dir)) {
1793+
if (ModMap.loadModuleMapFile(*PMMFile, IsSystem, Dir)) {
17941794
LoadedModuleMaps[File] = false;
17951795
return LMM_InvalidModuleMap;
17961796
}

clang/lib/Lex/ModuleMap.cpp

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ Module *ModuleMap::inferFrameworkModule(DirectoryEntryRef FrameworkDir,
10511051
bool IsFrameworkDir = Parent.ends_with(".framework");
10521052
if (OptionalFileEntryRef ModMapFile =
10531053
HeaderInfo.lookupModuleMapFile(*ParentDir, IsFrameworkDir)) {
1054-
parseModuleMapFile(*ModMapFile, Attrs.IsSystem, *ParentDir);
1054+
loadModuleMapFile(*ModMapFile, Attrs.IsSystem, *ParentDir);
10551055
inferred = InferredDirectories.find(*ParentDir);
10561056
}
10571057

@@ -1354,7 +1354,7 @@ std::error_code
13541354
ModuleMap::canonicalizeModuleMapPath(SmallVectorImpl<char> &Path) {
13551355
StringRef Dir = llvm::sys::path::parent_path({Path.data(), Path.size()});
13561356

1357-
// Do not canonicalize within the framework; the module map parser expects
1357+
// Do not canonicalize within the framework; the module map loader expects
13581358
// Modules/ not Versions/A/Modules.
13591359
if (llvm::sys::path::filename(Dir) == "Modules") {
13601360
StringRef Parent = llvm::sys::path::parent_path(Dir);
@@ -1453,11 +1453,11 @@ bool ModuleMap::resolveConflicts(Module *Mod, bool Complain) {
14531453
}
14541454

14551455
//----------------------------------------------------------------------------//
1456-
// Module map file parser
1456+
// Module map file loader
14571457
//----------------------------------------------------------------------------//
14581458

14591459
namespace clang {
1460-
class ModuleMapParser {
1460+
class ModuleMapLoader {
14611461
modulemap::ModuleMapFile &MMF;
14621462
SourceManager &SourceMgr;
14631463

@@ -1467,7 +1467,7 @@ class ModuleMapParser {
14671467
/// The current module map file.
14681468
FileID ModuleMapFID;
14691469

1470-
/// Source location of most recent parsed module declaration
1470+
/// Source location of most recent loaded module declaration
14711471
SourceLocation CurrModuleDeclLoc;
14721472

14731473
/// The directory that file names in this module map file should
@@ -1515,13 +1515,13 @@ class ModuleMapParser {
15151515
using Attributes = ModuleMap::Attributes;
15161516

15171517
public:
1518-
ModuleMapParser(modulemap::ModuleMapFile &MMF, SourceManager &SourceMgr,
1518+
ModuleMapLoader(modulemap::ModuleMapFile &MMF, SourceManager &SourceMgr,
15191519
DiagnosticsEngine &Diags, ModuleMap &Map, FileID ModuleMapFID,
15201520
DirectoryEntryRef Directory, bool IsSystem)
15211521
: MMF(MMF), SourceMgr(SourceMgr), Diags(Diags), Map(Map),
15221522
ModuleMapFID(ModuleMapFID), Directory(Directory), IsSystem(IsSystem) {}
15231523

1524-
bool parseModuleMapFile();
1524+
bool loadModuleMapFile();
15251525
};
15261526

15271527
} // namespace clang
@@ -1530,7 +1530,7 @@ class ModuleMapParser {
15301530
/// module map search logic to find the appropriate private module when PCH
15311531
/// is used with implicit module maps. Warn when private modules are written
15321532
/// in other ways (FooPrivate and Foo.Private), providing notes and fixits.
1533-
void ModuleMapParser::diagnosePrivateModules(SourceLocation StartLoc) {
1533+
void ModuleMapLoader::diagnosePrivateModules(SourceLocation StartLoc) {
15341534
auto GenNoteAndFixIt = [&](StringRef BadName, StringRef Canonical,
15351535
const Module *M, SourceRange ReplLoc) {
15361536
auto D = Diags.Report(ActiveModule->DefinitionLoc,
@@ -1584,7 +1584,7 @@ void ModuleMapParser::diagnosePrivateModules(SourceLocation StartLoc) {
15841584
}
15851585
}
15861586

1587-
void ModuleMapParser::handleModuleDecl(const modulemap::ModuleDecl &MD) {
1587+
void ModuleMapLoader::handleModuleDecl(const modulemap::ModuleDecl &MD) {
15881588
if (MD.Id.front().first == "*")
15891589
return handleInferredModuleDecl(MD);
15901590

@@ -1763,7 +1763,7 @@ void ModuleMapParser::handleModuleDecl(const modulemap::ModuleDecl &MD) {
17631763
ActiveModule = PreviousActiveModule;
17641764
}
17651765

1766-
void ModuleMapParser::handleExternModuleDecl(
1766+
void ModuleMapLoader::handleExternModuleDecl(
17671767
const modulemap::ExternModuleDecl &EMD) {
17681768
StringRef FileNameRef = EMD.Path;
17691769
SmallString<128> ModuleMapFileName;
@@ -1773,7 +1773,7 @@ void ModuleMapParser::handleExternModuleDecl(
17731773
FileNameRef = ModuleMapFileName;
17741774
}
17751775
if (auto File = SourceMgr.getFileManager().getOptionalFileRef(FileNameRef))
1776-
Map.parseModuleMapFile(
1776+
Map.loadModuleMapFile(
17771777
*File, IsSystem,
17781778
Map.HeaderInfo.getHeaderSearchOpts().ModuleMapFileHomeIsCwd
17791779
? Directory
@@ -1810,7 +1810,7 @@ static bool shouldAddRequirement(Module *M, StringRef Feature,
18101810
return true;
18111811
}
18121812

1813-
void ModuleMapParser::handleRequiresDecl(const modulemap::RequiresDecl &RD) {
1813+
void ModuleMapLoader::handleRequiresDecl(const modulemap::RequiresDecl &RD) {
18141814

18151815
for (const modulemap::RequiresFeature &RF : RD.Features) {
18161816
bool IsRequiresExcludedHack = false;
@@ -1828,7 +1828,7 @@ void ModuleMapParser::handleRequiresDecl(const modulemap::RequiresDecl &RD) {
18281828
}
18291829
}
18301830

1831-
void ModuleMapParser::handleHeaderDecl(const modulemap::HeaderDecl &HD) {
1831+
void ModuleMapLoader::handleHeaderDecl(const modulemap::HeaderDecl &HD) {
18321832
// We've already consumed the first token.
18331833
ModuleMap::ModuleHeaderRole Role = ModuleMap::NormalHeader;
18341834

@@ -1887,7 +1887,7 @@ static bool compareModuleHeaders(const Module::Header &A,
18871887
return A.NameAsWritten < B.NameAsWritten;
18881888
}
18891889

1890-
void ModuleMapParser::handleUmbrellaDirDecl(
1890+
void ModuleMapLoader::handleUmbrellaDirDecl(
18911891
const modulemap::UmbrellaDirDecl &UDD) {
18921892
std::string DirName = std::string(UDD.Path);
18931893
std::string DirNameAsWritten = DirName;
@@ -1919,7 +1919,7 @@ void ModuleMapParser::handleUmbrellaDirDecl(
19191919

19201920
if (UsesRequiresExcludedHack.count(ActiveModule)) {
19211921
// Mark this header 'textual' (see doc comment for
1922-
// ModuleMapParser::UsesRequiresExcludedHack). Although iterating over the
1922+
// ModuleMapLoader::UsesRequiresExcludedHack). Although iterating over the
19231923
// directory is relatively expensive, in practice this only applies to the
19241924
// uncommonly used Tcl module on Darwin platforms.
19251925
std::error_code EC;
@@ -1953,12 +1953,12 @@ void ModuleMapParser::handleUmbrellaDirDecl(
19531953
Map.setUmbrellaDirAsWritten(ActiveModule, *Dir, DirNameAsWritten, DirName);
19541954
}
19551955

1956-
void ModuleMapParser::handleExportDecl(const modulemap::ExportDecl &ED) {
1956+
void ModuleMapLoader::handleExportDecl(const modulemap::ExportDecl &ED) {
19571957
Module::UnresolvedExportDecl Unresolved = {ED.Location, ED.Id, ED.Wildcard};
19581958
ActiveModule->UnresolvedExports.push_back(Unresolved);
19591959
}
19601960

1961-
void ModuleMapParser::handleExportAsDecl(const modulemap::ExportAsDecl &EAD) {
1961+
void ModuleMapLoader::handleExportAsDecl(const modulemap::ExportAsDecl &EAD) {
19621962
auto ModName = EAD.Id.front();
19631963

19641964
if (!ActiveModule->ExportAsModule.empty()) {
@@ -1976,19 +1976,19 @@ void ModuleMapParser::handleExportAsDecl(const modulemap::ExportAsDecl &EAD) {
19761976
Map.addLinkAsDependency(ActiveModule);
19771977
}
19781978

1979-
void ModuleMapParser::handleUseDecl(const modulemap::UseDecl &UD) {
1979+
void ModuleMapLoader::handleUseDecl(const modulemap::UseDecl &UD) {
19801980
if (ActiveModule->Parent)
19811981
Diags.Report(UD.Location, diag::err_mmap_use_decl_submodule);
19821982
else
19831983
ActiveModule->UnresolvedDirectUses.push_back(UD.Id);
19841984
}
19851985

1986-
void ModuleMapParser::handleLinkDecl(const modulemap::LinkDecl &LD) {
1986+
void ModuleMapLoader::handleLinkDecl(const modulemap::LinkDecl &LD) {
19871987
ActiveModule->LinkLibraries.push_back(
19881988
Module::LinkLibrary(std::string{LD.Library}, LD.Framework));
19891989
}
19901990

1991-
void ModuleMapParser::handleConfigMacros(
1991+
void ModuleMapLoader::handleConfigMacros(
19921992
const modulemap::ConfigMacrosDecl &CMD) {
19931993
if (ActiveModule->Parent) {
19941994
Diags.Report(CMD.Location, diag::err_mmap_config_macro_submodule);
@@ -2004,7 +2004,7 @@ void ModuleMapParser::handleConfigMacros(
20042004
CMD.Macros.begin(), CMD.Macros.end());
20052005
}
20062006

2007-
void ModuleMapParser::handleConflict(const modulemap::ConflictDecl &CD) {
2007+
void ModuleMapLoader::handleConflict(const modulemap::ConflictDecl &CD) {
20082008
Module::UnresolvedConflict Conflict;
20092009

20102010
Conflict.Id = CD.Id;
@@ -2013,7 +2013,7 @@ void ModuleMapParser::handleConflict(const modulemap::ConflictDecl &CD) {
20132013
ActiveModule->UnresolvedConflicts.push_back(Conflict);
20142014
}
20152015

2016-
void ModuleMapParser::handleInferredModuleDecl(
2016+
void ModuleMapLoader::handleInferredModuleDecl(
20172017
const modulemap::ModuleDecl &MD) {
20182018
SourceLocation StarLoc = MD.Id.front().second;
20192019

@@ -2103,7 +2103,7 @@ void ModuleMapParser::handleInferredModuleDecl(
21032103
}
21042104
}
21052105

2106-
bool ModuleMapParser::parseModuleMapFile() {
2106+
bool ModuleMapLoader::loadModuleMapFile() {
21072107
for (const auto &Decl : MMF.Decls) {
21082108
std::visit(
21092109
llvm::makeVisitor(
@@ -2116,14 +2116,14 @@ bool ModuleMapParser::parseModuleMapFile() {
21162116
return HadError;
21172117
}
21182118

2119-
bool ModuleMap::parseModuleMapFile(FileEntryRef File, bool IsSystem,
2120-
DirectoryEntryRef Dir, FileID ID,
2121-
unsigned *Offset,
2122-
SourceLocation ExternModuleLoc) {
2119+
bool ModuleMap::loadModuleMapFile(FileEntryRef File, bool IsSystem,
2120+
DirectoryEntryRef Dir, FileID ID,
2121+
unsigned *Offset,
2122+
SourceLocation ExternModuleLoc) {
21232123
assert(Target && "Missing target information");
2124-
llvm::DenseMap<const FileEntry *, bool>::iterator Known
2125-
= ParsedModuleMap.find(File);
2126-
if (Known != ParsedModuleMap.end())
2124+
llvm::DenseMap<const FileEntry *, bool>::iterator Known =
2125+
LoadedModuleMap.find(File);
2126+
if (Known != LoadedModuleMap.end())
21272127
return Known->second;
21282128

21292129
// If the module map file wasn't already entered, do so now.
@@ -2136,20 +2136,21 @@ bool ModuleMap::parseModuleMapFile(FileEntryRef File, bool IsSystem,
21362136
assert(Target && "Missing target information");
21372137
std::optional<llvm::MemoryBufferRef> Buffer = SourceMgr.getBufferOrNone(ID);
21382138
if (!Buffer)
2139-
return ParsedModuleMap[File] = true;
2139+
return LoadedModuleMap[File] = true;
21402140
assert((!Offset || *Offset <= Buffer->getBufferSize()) &&
21412141
"invalid buffer offset");
21422142

21432143
std::optional<modulemap::ModuleMapFile> MMF =
21442144
modulemap::parseModuleMap(ID, Dir, SourceMgr, Diags, IsSystem, Offset);
21452145
bool Result = false;
21462146
if (MMF) {
2147-
ModuleMapParser Parser(*MMF, SourceMgr, Diags, *this, ID, Dir, IsSystem);
2148-
Result = Parser.parseModuleMapFile();
2147+
ModuleMapLoader Loader(*MMF, SourceMgr, Diags, *this, ID, Dir, IsSystem);
2148+
Result = Loader.loadModuleMapFile();
21492149
}
2150-
ParsedModuleMap[File] = Result;
2150+
LoadedModuleMap[File] = Result;
21512151

2152-
// Notify callbacks that we parsed it.
2152+
// Notify callbacks that we observed it.
2153+
// FIXME: We should only report module maps that were actually used.
21532154
for (const auto &Cb : Callbacks)
21542155
Cb->moduleMapFileRead(MMF ? MMF->Start : SourceLocation(), File, IsSystem);
21552156

0 commit comments

Comments
 (0)