diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2019-08-26 18:29:51 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2019-08-26 18:29:51 +0000 |
commit | 9ef6c49baf45a06d5b54cc9c790c9397e584ba48 (patch) | |
tree | 6401921d31ed1ac3b53fb7de5daa7c09f5911f39 /clang/lib/Basic/FileManager.cpp | |
parent | 36d1588f017bb6e971cb14cc6e7094c3db9c0436 (diff) | |
download | bcm5719-llvm-9ef6c49baf45a06d5b54cc9c790c9397e584ba48.tar.gz bcm5719-llvm-9ef6c49baf45a06d5b54cc9c790c9397e584ba48.zip |
FileManager: Use llvm::Expected in new getFileRef API
`FileManager::getFileRef` is a modern API which we expect to convert to
over time. We should modernize the error handling as well, using
`llvm::Expected` instead of `llvm::ErrorOr`, to help clients that care
about errors to ensure nothing is missed.
However, not all clients care. I've also added another path for those
that don't:
- `FileEntryRef` is now copy- and move-assignable (using a pointer
instead of a reference).
- `FileManager::getOptionalFileRef` returns an `llvm::Optional` instead
of `llvm::Expected`.
- Added an `llvm::expectedToOptional` utility in case this is useful
elsewhere.
https://reviews.llvm.org/D66705
llvm-svn: 369943
Diffstat (limited to 'clang/lib/Basic/FileManager.cpp')
-rw-r--r-- | clang/lib/Basic/FileManager.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 649e4d2239b..8e186713a92 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -187,10 +187,10 @@ FileManager::getFile(StringRef Filename, bool openFile, bool CacheFailure) { auto Result = getFileRef(Filename, openFile, CacheFailure); if (Result) return &Result->getFileEntry(); - return Result.getError(); + return llvm::errorToErrorCode(Result.takeError()); } -llvm::ErrorOr<FileEntryRef> +llvm::Expected<FileEntryRef> FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) { ++NumFileLookups; @@ -199,7 +199,8 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) { SeenFileEntries.insert({Filename, std::errc::no_such_file_or_directory}); if (!SeenFileInsertResult.second) { if (!SeenFileInsertResult.first->second) - return SeenFileInsertResult.first->second.getError(); + return llvm::errorCodeToError( + SeenFileInsertResult.first->second.getError()); // Construct and return and FileEntryRef, unless it's a redirect to another // filename. SeenFileEntryOrRedirect Value = *SeenFileInsertResult.first->second; @@ -230,7 +231,7 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) { else SeenFileEntries.erase(Filename); - return DirInfoOrErr.getError(); + return llvm::errorCodeToError(DirInfoOrErr.getError()); } const DirectoryEntry *DirInfo = *DirInfoOrErr; @@ -249,7 +250,7 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) { else SeenFileEntries.erase(Filename); - return statError; + return llvm::errorCodeToError(statError); } assert((openFile || !F) && "undesired open file"); |