Author: Michael Spencer Date: 2025-03-25T12:32:58-07:00 New Revision: 57f2e76e3010e7b089ebc5dd96aef5966f13b6c5
URL: https://github.com/llvm/llvm-project/commit/57f2e76e3010e7b089ebc5dd96aef5966f13b6c5 DIFF: https://github.com/llvm/llvm-project/commit/57f2e76e3010e7b089ebc5dd96aef5966f13b6c5.diff LOG: [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. Added: Modified: clang-tools-extra/modularize/ModuleAssistant.cpp clang/include/clang/Lex/ModuleMap.h clang/lib/Lex/HeaderSearch.cpp clang/lib/Lex/ModuleMap.cpp Removed: ################################################################################ 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 1b6de76d260ff..9283a0f4fce55 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -1782,7 +1782,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; } @@ -1790,7 +1790,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..a1394fd3900b0 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, - DirectoryEntryRef Dir, FileID ID, - unsigned *Offset, - SourceLocation ExternModuleLoc) { +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()) + llvm::DenseMap<const FileEntry *, bool>::iterator Known = + 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,13 @@ 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 observed it. + // FIXME: We should only report module maps that were actually used. for (const auto &Cb : Callbacks) Cb->moduleMapFileRead(MMF ? MMF->Start : SourceLocation(), File, IsSystem); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits