jansvoboda11 created this revision.
jansvoboda11 added a reviewer: bnbarham.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.
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 <https://reviews.llvm.org/D127648>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D127651
Files:
clang-tools-extra/modularize/ModularizeUtilities.cpp
clang/include/clang/Lex/ModuleMap.h
clang/lib/Lex/ModuleMap.cpp
Index: clang/lib/Lex/ModuleMap.cpp
===================================================================
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -1451,7 +1451,7 @@
/// 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;
@@ -1517,7 +1517,7 @@
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) {
@@ -2189,16 +2189,16 @@
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);
}
@@ -2453,7 +2453,7 @@
Dir = *D;
} else {
SmallString<128> PathName;
- PathName = Directory->getName();
+ PathName = Directory.getName();
llvm::sys::path::append(PathName, DirName);
if (auto D = SourceMgr.getFileManager().getDirectory(PathName))
Dir = *D;
@@ -3016,7 +3016,7 @@
}
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");
Index: clang/include/clang/Lex/ModuleMap.h
===================================================================
--- clang/include/clang/Lex/ModuleMap.h
+++ clang/include/clang/Lex/ModuleMap.h
@@ -703,8 +703,8 @@
///
/// \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.
Index: clang-tools-extra/modularize/ModularizeUtilities.cpp
===================================================================
--- clang-tools-extra/modularize/ModularizeUtilities.cpp
+++ clang-tools-extra/modularize/ModularizeUtilities.cpp
@@ -258,31 +258,26 @@
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();
+ Optional<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;
- }
+ if (DirName.endswith(".framework"))
+ Dir = FileMgr->getOptionalDirectoryRef(DirName);
// 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");
@@ -293,7 +288,7 @@
Target.get(), *HeaderInfo));
// Parse module.modulemap file into module map.
- if (ModMap->parseModuleMapFile(ModuleMapEntry, false, Dir)) {
+ if (ModMap->parseModuleMapFile(ModuleMapEntry, false, *Dir)) {
return std::error_code(1, std::generic_category());
}
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits