aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Lex/ModuleMap.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2020-10-29 15:29:42 -0400
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2020-11-30 17:13:03 -0800
commitf85db7f7ba683b2450892fde247311d7a48adbd0 (patch)
treefdee3e3a97d05816fec1d718822a00cc52a0d748 /clang/lib/Lex/ModuleMap.cpp
parent774f1d3ffd458d6cb82d5039758ef1cf6370957f (diff)
downloadllvm-f85db7f7ba683b2450892fde247311d7a48adbd0.zip
llvm-f85db7f7ba683b2450892fde247311d7a48adbd0.tar.gz
llvm-f85db7f7ba683b2450892fde247311d7a48adbd0.tar.bz2
Lex: Update Module::findHeader to return FileEntryRef, NFC
Update `Module::findHeader` to return `Optional<FileEntryRef>` and fix its one caller. Differential Revision: https://reviews.llvm.org/D90485
Diffstat (limited to 'clang/lib/Lex/ModuleMap.cpp')
-rw-r--r--clang/lib/Lex/ModuleMap.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index cb49173..28dd7ed 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -171,23 +171,23 @@ static void appendSubframeworkPaths(Module *Mod,
llvm::sys::path::append(Path, "Frameworks", Paths[I-1] + ".framework");
}
-const FileEntry *ModuleMap::findHeader(
+Optional<FileEntryRef> ModuleMap::findHeader(
Module *M, const Module::UnresolvedHeaderDirective &Header,
SmallVectorImpl<char> &RelativePathName, bool &NeedsFramework) {
// Search for the header file within the module's home directory.
auto *Directory = M->Directory;
SmallString<128> FullPathName(Directory->getName());
- auto GetFile = [&](StringRef Filename) -> const FileEntry * {
- auto File = SourceMgr.getFileManager().getFile(Filename);
- if (!File ||
- (Header.Size && (*File)->getSize() != *Header.Size) ||
- (Header.ModTime && (*File)->getModificationTime() != *Header.ModTime))
- return nullptr;
+ auto GetFile = [&](StringRef Filename) -> Optional<FileEntryRef> {
+ auto File =
+ expectedToOptional(SourceMgr.getFileManager().getFileRef(Filename));
+ if (!File || (Header.Size && File->getSize() != *Header.Size) ||
+ (Header.ModTime && File->getModificationTime() != *Header.ModTime))
+ return None;
return *File;
};
- auto GetFrameworkFile = [&]() -> const FileEntry * {
+ auto GetFrameworkFile = [&]() -> Optional<FileEntryRef> {
unsigned FullPathLength = FullPathName.size();
appendSubframeworkPaths(M, RelativePathName);
unsigned RelativePathLength = RelativePathName.size();
@@ -195,7 +195,7 @@ const FileEntry *ModuleMap::findHeader(
// Check whether this file is in the public headers.
llvm::sys::path::append(RelativePathName, "Headers", Header.FileName);
llvm::sys::path::append(FullPathName, RelativePathName);
- if (auto *File = GetFile(FullPathName))
+ if (auto File = GetFile(FullPathName))
return File;
// Check whether this file is in the private headers.
@@ -227,7 +227,7 @@ const FileEntry *ModuleMap::findHeader(
// Lookup for normal headers.
llvm::sys::path::append(RelativePathName, Header.FileName);
llvm::sys::path::append(FullPathName, RelativePathName);
- auto *NormalHdrFile = GetFile(FullPathName);
+ auto NormalHdrFile = GetFile(FullPathName);
if (!NormalHdrFile && Directory->getName().endswith(".framework")) {
// The lack of 'framework' keyword in a module declaration it's a simple
@@ -241,7 +241,7 @@ const FileEntry *ModuleMap::findHeader(
<< Header.FileName << M->getFullModuleName();
NeedsFramework = true;
}
- return nullptr;
+ return None;
}
return NormalHdrFile;
@@ -251,18 +251,18 @@ void ModuleMap::resolveHeader(Module *Mod,
const Module::UnresolvedHeaderDirective &Header,
bool &NeedsFramework) {
SmallString<128> RelativePathName;
- if (const FileEntry *File =
+ if (Optional<FileEntryRef> File =
findHeader(Mod, Header, RelativePathName, NeedsFramework)) {
if (Header.IsUmbrella) {
- const DirectoryEntry *UmbrellaDir = File->getDir();
+ const DirectoryEntry *UmbrellaDir = &File->getDir().getDirEntry();
if (Module *UmbrellaMod = UmbrellaDirs[UmbrellaDir])
Diags.Report(Header.FileNameLoc, diag::err_mmap_umbrella_clash)
<< UmbrellaMod->getFullModuleName();
else
// Record this umbrella header.
- setUmbrellaHeader(Mod, File, RelativePathName.str());
+ setUmbrellaHeader(Mod, *File, RelativePathName.str());
} else {
- Module::Header H = {std::string(RelativePathName.str()), File};
+ Module::Header H = {std::string(RelativePathName.str()), *File};
if (Header.Kind == Module::HK_Excluded)
excludeHeader(Mod, H);
else