aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/FileManager.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2020-10-21 23:38:12 -0400
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2020-11-30 14:04:48 -0800
commitac40a2d8f16b8a8c68fc811d67f647740e965cb8 (patch)
treea1abc18b93bd7bf85a608ead3e4677bb2bd5744e /clang/lib/Basic/FileManager.cpp
parent9615890db576721fbd73ae77d81d39435e83b4b4 (diff)
downloadllvm-ac40a2d8f16b8a8c68fc811d67f647740e965cb8.zip
llvm-ac40a2d8f16b8a8c68fc811d67f647740e965cb8.tar.gz
llvm-ac40a2d8f16b8a8c68fc811d67f647740e965cb8.tar.bz2
Serialization: Change InputFile to use FileEntryRef and add getVirtualFileRef, NFC
Change the `InputFile` class to store `Optional<FileEntryRef>` instead of `FileEntry*`. This paged in a few API changes: - Added `FileManager::getVirtualFileRef`, and converted `getVirtualFile` to a wrapper of it. - Updated `SourceManager::bypassFileContentsOverride` to take `FileEntryRef` and return `Optional<FileEntryRef>` (`ASTReader::getInputFile` is the only caller). Differential Revision: https://reviews.llvm.org/D90053
Diffstat (limited to 'clang/lib/Basic/FileManager.cpp')
-rw-r--r--clang/lib/Basic/FileManager.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index 38d9403..ef0c69ae 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -335,9 +335,13 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) {
return ReturnedRef;
}
-const FileEntry *
-FileManager::getVirtualFile(StringRef Filename, off_t Size,
- time_t ModificationTime) {
+const FileEntry *FileManager::getVirtualFile(StringRef Filename, off_t Size,
+ time_t ModificationTime) {
+ return &getVirtualFileRef(Filename, Size, ModificationTime).getFileEntry();
+}
+
+FileEntryRef FileManager::getVirtualFileRef(StringRef Filename, off_t Size,
+ time_t ModificationTime) {
++NumFileLookups;
// See if there is already an entry in the map for an existing file.
@@ -345,12 +349,10 @@ FileManager::getVirtualFile(StringRef Filename, off_t Size,
{Filename, std::errc::no_such_file_or_directory}).first;
if (NamedFileEnt.second) {
FileEntryRef::MapValue Value = *NamedFileEnt.second;
- FileEntry *FE;
- if (LLVM_LIKELY(FE = Value.V.dyn_cast<FileEntry *>()))
- return FE;
- return &FileEntryRef(*reinterpret_cast<const FileEntryRef::MapEntry *>(
- Value.V.get<const void *>()))
- .getFileEntry();
+ if (LLVM_LIKELY(Value.V.is<FileEntry *>()))
+ return FileEntryRef(NamedFileEnt);
+ return FileEntryRef(*reinterpret_cast<const FileEntryRef::MapEntry *>(
+ Value.V.get<const void *>()));
}
// We've not seen this before, or the file is cached as non-existent.
@@ -389,7 +391,7 @@ FileManager::getVirtualFile(StringRef Filename, off_t Size,
// FIXME: Surely this should add a reference by the new name, and return
// it instead...
if (UFE->isValid())
- return UFE;
+ return FileEntryRef(NamedFileEnt);
UFE->UniqueID = Status.getUniqueID();
UFE->IsNamedPipe = Status.getType() == llvm::sys::fs::file_type::fifo_file;
@@ -407,7 +409,7 @@ FileManager::getVirtualFile(StringRef Filename, off_t Size,
UFE->UID = NextFileUID++;
UFE->IsValid = true;
UFE->File.reset();
- return UFE;
+ return FileEntryRef(NamedFileEnt);
}
llvm::Optional<FileEntryRef> FileManager::getBypassFile(FileEntryRef VF) {