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
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;
///
/// \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.
/// 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;
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) {
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);
}
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);
}
}
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");