[clang-tools-extra] d574e91 - [clang][lex] NFCI: Use DirectoryEntryRef in ModuleMap::parseModuleMapFile()
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Tue May 30 13:54:16 PDT 2023
Author: Jan Svoboda
Date: 2023-05-30T13:54:06-07:00
New Revision: d574e918dba31e670a87c46e7de281819b3c0ea9
URL: https://github.com/llvm/llvm-project/commit/d574e918dba31e670a87c46e7de281819b3c0ea9
DIFF: https://github.com/llvm/llvm-project/commit/d574e918dba31e670a87c46e7de281819b3c0ea9.diff
LOG: [clang][lex] NFCI: Use DirectoryEntryRef in ModuleMap::parseModuleMapFile()
This patch changes the argument type of `ModuleMap::parseModuleMapFile()` from `const DirectoryEntry *` to `DirectoryEntryRef` in order to remove the deprecated uses of `DirectoryEntry::getName()`.
Depends on D127648.
Reviewed By: bnbarham
Differential Revision: https://reviews.llvm.org/D127651
Added:
Modified:
clang-tools-extra/modularize/ModularizeUtilities.cpp
clang/include/clang/Lex/ModuleMap.h
clang/lib/Lex/ModuleMap.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/modularize/ModularizeUtilities.cpp b/clang-tools-extra/modularize/ModularizeUtilities.cpp
index a7cadf818664a..5b09c916606d9 100644
--- a/clang-tools-extra/modularize/ModularizeUtilities.cpp
+++ b/clang-tools-extra/modularize/ModularizeUtilities.cpp
@@ -258,34 +258,33 @@ std::error_code ModularizeUtilities::loadProblemHeaderList(
std::error_code ModularizeUtilities::loadModuleMap(
llvm::StringRef InputPath) {
// Get file entry for module.modulemap file.
- auto ModuleMapEntryOrErr =
- SourceMgr->getFileManager().getFile(InputPath);
+ auto ModuleMapEntryOrErr = SourceMgr->getFileManager().getFileRef(InputPath);
// return error if not found.
if (!ModuleMapEntryOrErr) {
llvm::errs() << "error: File \"" << InputPath << "\" not found.\n";
- return ModuleMapEntryOrErr.getError();
+ return errorToErrorCode(ModuleMapEntryOrErr.takeError());
}
- const FileEntry *ModuleMapEntry = *ModuleMapEntryOrErr;
+ FileEntryRef ModuleMapEntry = *ModuleMapEntryOrErr;
// Because the module map parser uses a ForwardingDiagnosticConsumer,
// which doesn't forward the BeginSourceFile call, we do it explicitly here.
DC.BeginSourceFile(*LangOpts, nullptr);
// Figure out the home directory for the module map file.
- const DirectoryEntry *Dir = ModuleMapEntry->getDir();
- StringRef DirName(Dir->getName());
+ DirectoryEntryRef Dir = ModuleMapEntry.getDir();
+ StringRef DirName(Dir.getName());
if (llvm::sys::path::filename(DirName) == "Modules") {
DirName = llvm::sys::path::parent_path(DirName);
if (DirName.endswith(".framework")) {
- if (auto DirEntry = FileMgr->getDirectory(DirName))
- Dir = *DirEntry;
- else
- Dir = nullptr;
+ auto FrameworkDirOrErr = FileMgr->getDirectoryRef(DirName);
+ if (!FrameworkDirOrErr) {
+ // This can happen if there's a race between the above check and the
+ // removal of the directory.
+ return errorToErrorCode(FrameworkDirOrErr.takeError());
+ }
+ Dir = *FrameworkDirOrErr;
}
- // FIXME: This assert can fail if there's a race between the above check
- // and the removal of the directory.
- assert(Dir && "parent must exist");
}
std::unique_ptr<ModuleMap> ModMap;
diff --git a/clang/include/clang/Lex/ModuleMap.h b/clang/include/clang/Lex/ModuleMap.h
index d291afa70619e..79cf0afc46271 100644
--- a/clang/include/clang/Lex/ModuleMap.h
+++ b/clang/include/clang/Lex/ModuleMap.h
@@ -729,8 +729,8 @@ class ModuleMap {
///
/// \returns true if an error occurred, false otherwise.
bool parseModuleMapFile(const FileEntry *File, bool IsSystem,
- const DirectoryEntry *HomeDir,
- FileID ID = FileID(), unsigned *Offset = nullptr,
+ DirectoryEntryRef HomeDir, FileID ID = FileID(),
+ unsigned *Offset = nullptr,
SourceLocation ExternModuleLoc = SourceLocation());
/// Dump the contents of the module map, for debugging purposes.
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index efe2df0323ecc..833287c665167 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1518,7 +1518,7 @@ namespace clang {
/// The directory that file names in this module map file should
/// be resolved relative to.
- const DirectoryEntry *Directory;
+ DirectoryEntryRef Directory;
/// Whether this module map is in a system header directory.
bool IsSystem;
@@ -1584,7 +1584,7 @@ namespace clang {
explicit ModuleMapParser(Lexer &L, SourceManager &SourceMgr,
const TargetInfo *Target, DiagnosticsEngine &Diags,
ModuleMap &Map, const FileEntry *ModuleMapFile,
- const DirectoryEntry *Directory, bool IsSystem)
+ DirectoryEntryRef Directory, bool IsSystem)
: L(L), SourceMgr(SourceMgr), Target(Target), Diags(Diags), Map(Map),
ModuleMapFile(ModuleMapFile), Directory(Directory),
IsSystem(IsSystem) {
@@ -2254,16 +2254,16 @@ void ModuleMapParser::parseExternModuleDecl() {
StringRef FileNameRef = FileName;
SmallString<128> ModuleMapFileName;
if (llvm::sys::path::is_relative(FileNameRef)) {
- ModuleMapFileName += Directory->getName();
+ ModuleMapFileName += Directory.getName();
llvm::sys::path::append(ModuleMapFileName, FileName);
FileNameRef = ModuleMapFileName;
}
- if (auto File = SourceMgr.getFileManager().getFile(FileNameRef))
+ if (auto File = SourceMgr.getFileManager().getOptionalFileRef(FileNameRef))
Map.parseModuleMapFile(
*File, IsSystem,
Map.HeaderInfo.getHeaderSearchOpts().ModuleMapFileHomeIsCwd
? Directory
- : (*File)->getDir(),
+ : File->getDir(),
FileID(), nullptr, ExternLoc);
}
@@ -2518,7 +2518,7 @@ void ModuleMapParser::parseUmbrellaDirDecl(SourceLocation UmbrellaLoc) {
Dir = SourceMgr.getFileManager().getOptionalDirectoryRef(DirName);
} else {
SmallString<128> PathName;
- PathName = Directory->getName();
+ PathName = Directory.getName();
llvm::sys::path::append(PathName, DirName);
Dir = SourceMgr.getFileManager().getOptionalDirectoryRef(PathName);
}
@@ -3080,7 +3080,7 @@ bool ModuleMapParser::parseModuleMapFile() {
}
bool ModuleMap::parseModuleMapFile(const FileEntry *File, bool IsSystem,
- const DirectoryEntry *Dir, FileID ID,
+ DirectoryEntryRef Dir, FileID ID,
unsigned *Offset,
SourceLocation ExternModuleLoc) {
assert(Target && "Missing target information");
More information about the cfe-commits
mailing list