This removes some deprecated uses of `DirectoryEntry::getName()`.
Depends on D151581.
Differential Revision: https://reviews.llvm.org/D151584
std::string PresumedModuleMapFile;
/// The umbrella header or directory.
- llvm::PointerUnion<const FileEntryRef::MapEntry *, const DirectoryEntry *>
+ llvm::PointerUnion<const FileEntryRef::MapEntry *,
+ const DirectoryEntryRef::MapEntry *>
Umbrella;
/// The module signature.
struct DirectoryName {
std::string NameAsWritten;
std::string PathRelativeToRootModuleDirectory;
- const DirectoryEntry *Entry;
+ OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr Entry;
- explicit operator bool() { return Entry; }
+ explicit operator bool() { return Entry.has_value(); }
};
/// The headers that are part of this module.
/// Retrieve the umbrella directory as written.
DirectoryName getUmbrellaDirAsWritten() const {
- if (const auto *ME = Umbrella.dyn_cast<const DirectoryEntry *>())
+ if (const auto *ME =
+ Umbrella.dyn_cast<const DirectoryEntryRef::MapEntry *>())
return DirectoryName{UmbrellaAsWritten,
- UmbrellaRelativeToRootModuleDirectory, ME};
+ UmbrellaRelativeToRootModuleDirectory,
+ DirectoryEntryRef(*ME)};
return DirectoryName{};
}
/// Get the effective umbrella directory for this module: either the one
/// explicitly written in the module map file, or the parent of the umbrella
/// header.
- const DirectoryEntry *getEffectiveUmbrellaDir() const;
-
- /// Determine whether this module has an umbrella directory that is
- /// not based on an umbrella header.
- bool hasUmbrellaDir() const {
- return Umbrella && Umbrella.is<const DirectoryEntry *>();
- }
+ OptionalDirectoryEntryRef getEffectiveUmbrellaDir() const;
/// Add a top-level header associated with this module.
void addTopHeader(const FileEntry *File);
const Twine &PathRelativeToRootModuleDirectory);
/// Sets the umbrella directory of the given module to the given directory.
- void setUmbrellaDirAsWritten(Module *Mod, const DirectoryEntry *UmbrellaDir,
+ void setUmbrellaDirAsWritten(Module *Mod, DirectoryEntryRef UmbrellaDir,
const Twine &NameAsWritten,
const Twine &PathRelativeToRootModuleDirectory);
return nameParts.empty();
}
-const DirectoryEntry *Module::getEffectiveUmbrellaDir() const {
+OptionalDirectoryEntryRef Module::getEffectiveUmbrellaDir() const {
if (const auto *ME = Umbrella.dyn_cast<const FileEntryRef::MapEntry *>())
return FileEntryRef(*ME).getDir();
- if (const auto *ME = Umbrella.dyn_cast<const DirectoryEntry *>())
- return ME;
- return nullptr;
+ if (const auto *ME = Umbrella.dyn_cast<const DirectoryEntryRef::MapEntry *>())
+ return DirectoryEntryRef(*ME);
+ return std::nullopt;
}
void Module::addTopHeader(const FileEntry *File) {
}
void ModuleMap::setUmbrellaDirAsWritten(
- Module *Mod, const DirectoryEntry *UmbrellaDir, const Twine &NameAsWritten,
+ Module *Mod, DirectoryEntryRef UmbrellaDir, const Twine &NameAsWritten,
const Twine &PathRelativeToRootModuleDirectory) {
- Mod->Umbrella = UmbrellaDir;
+ Mod->Umbrella = &UmbrellaDir.getMapEntry();
Mod->UmbrellaAsWritten = NameAsWritten.str();
Mod->UmbrellaRelativeToRootModuleDirectory =
PathRelativeToRootModuleDirectory.str();
}
// Look for this file.
- const DirectoryEntry *Dir = nullptr;
+ OptionalDirectoryEntryRef Dir;
if (llvm::sys::path::is_absolute(DirName)) {
- if (auto D = SourceMgr.getFileManager().getDirectory(DirName))
- Dir = *D;
+ Dir = SourceMgr.getFileManager().getOptionalDirectoryRef(DirName);
} else {
SmallString<128> PathName;
PathName = Directory->getName();
llvm::sys::path::append(PathName, DirName);
- if (auto D = SourceMgr.getFileManager().getDirectory(PathName))
- Dir = *D;
+ Dir = SourceMgr.getFileManager().getOptionalDirectoryRef(PathName);
}
if (!Dir) {
return;
}
- if (Module *OwningModule = Map.UmbrellaDirs[Dir]) {
+ if (Module *OwningModule = Map.UmbrellaDirs[*Dir]) {
Diags.Report(UmbrellaLoc, diag::err_mmap_umbrella_clash)
<< OwningModule->getFullModuleName();
HadError = true;
}
// Record this umbrella directory.
- Map.setUmbrellaDirAsWritten(ActiveModule, Dir, DirNameAsWritten, DirName);
+ Map.setUmbrellaDirAsWritten(ActiveModule, *Dir, DirNameAsWritten, DirName);
}
/// Parse a module export declaration.
return;
ModuleMap &ModMap = getHeaderSearchInfo().getModuleMap();
- const DirectoryEntry *Dir = Mod.getEffectiveUmbrellaDir();
+ OptionalDirectoryEntryRef Dir = Mod.getEffectiveUmbrellaDir();
llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem();
std::error_code EC;
for (llvm::vfs::recursive_directory_iterator Entry(FS, Dir->getName(), EC),
if (!ModMap.isHeaderInUnavailableModule(*Header)) {
// Find the relative path that would access this header.
SmallString<128> RelativePath;
- computeRelativePath(FileMgr, Dir, *Header, RelativePath);
+ computeRelativePath(FileMgr, *Dir, *Header, RelativePath);
Diag(ExpectedHeadersLoc, diag::warn_uncovered_module_header)
<< Mod.getFullModuleName() << RelativePath;
}
// See comments in SUBMODULE_UMBRELLA_HEADER
std::string Dirname = std::string(Blob);
ResolveImportedPath(F, Dirname);
- if (auto Umbrella = PP.getFileManager().getDirectory(Dirname)) {
+ if (auto Umbrella =
+ PP.getFileManager().getOptionalDirectoryRef(Dirname)) {
if (!CurrentModule->getUmbrellaDirAsWritten()) {
// FIXME: NameAsWritten
ModMap.setUmbrellaDirAsWritten(CurrentModule, *Umbrella, Blob, "");