summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic/VirtualFileSystem.cpp
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2018-07-24 16:00:55 +0000
committerSam McCall <sam.mccall@gmail.com>2018-07-24 16:00:55 +0000
commit33b78c5d24ecafeff93d9345e7dc21c9005985d6 (patch)
tree8c4b1967bbba7d092d09073a25413e97839b5521 /clang/lib/Basic/VirtualFileSystem.cpp
parentf8f2a788f06ea811503dbf035b0de182e2700b04 (diff)
downloadbcm5719-llvm-33b78c5d24ecafeff93d9345e7dc21c9005985d6.tar.gz
bcm5719-llvm-33b78c5d24ecafeff93d9345e7dc21c9005985d6.zip
[VFS] Cleanups to VFS interfaces.
Summary: - add comments clarifying semantics - Status::copyWithNewName(Status, Name) --> instance method - Status::copyWithNewName(fs::file_status, Name) --> constructor (it's not a copy) - File::getName() -> getRealPath(), reflecting its actual behavior/function and stop returning status().getName() in the base class (callers can do this fallback if they want to, it complicates the contracts). This is mostly NFC, but the behavior of File::getName() affects FileManager's FileEntry::tryGetRealPathName(), which now fails in more cases: - non-real file cases - real-file cases where the underlying vfs::File was opened in a way that doesn't call realpath(). (In these cases we don't know a distinct real name, so in principle it seems OK) Reviewers: klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D49724 llvm-svn: 337834
Diffstat (limited to 'clang/lib/Basic/VirtualFileSystem.cpp')
-rw-r--r--clang/lib/Basic/VirtualFileSystem.cpp37
1 files changed, 19 insertions, 18 deletions
diff --git a/clang/lib/Basic/VirtualFileSystem.cpp b/clang/lib/Basic/VirtualFileSystem.cpp
index bcfcbdbb901..b269a9fcc00 100644
--- a/clang/lib/Basic/VirtualFileSystem.cpp
+++ b/clang/lib/Basic/VirtualFileSystem.cpp
@@ -73,16 +73,14 @@ Status::Status(StringRef Name, UniqueID UID, sys::TimePoint<> MTime,
: Name(Name), UID(UID), MTime(MTime), User(User), Group(Group), Size(Size),
Type(Type), Perms(Perms) {}
-Status Status::copyWithNewName(const Status &In, StringRef NewName) {
- return Status(NewName, In.getUniqueID(), In.getLastModificationTime(),
- In.getUser(), In.getGroup(), In.getSize(), In.getType(),
- In.getPermissions());
-}
+Status::Status(const file_status &In, StringRef NewName)
+ : Status(NewName, In.getUniqueID(), In.getLastModificationTime(),
+ In.getUser(), In.getGroup(), In.getSize(), In.type(),
+ In.permissions()) {}
-Status Status::copyWithNewName(const file_status &In, StringRef NewName) {
- return Status(NewName, In.getUniqueID(), In.getLastModificationTime(),
- In.getUser(), In.getGroup(), In.getSize(), In.type(),
- In.permissions());
+Status Status::copyWithNewName(StringRef NewName) {
+ return Status(NewName, getUniqueID(), getLastModificationTime(), getUser(),
+ getGroup(), getSize(), getType(), getPermissions());
}
bool Status::equivalent(const Status &Other) const {
@@ -178,6 +176,7 @@ class RealFile : public File {
Status S;
std::string RealName;
+ // NewRealPathName is used only if non-empty.
RealFile(int FD, StringRef NewName, StringRef NewRealPathName)
: FD(FD), S(NewName, {}, {}, {}, {}, {},
llvm::sys::fs::file_type::status_error, {}),
@@ -189,7 +188,7 @@ public:
~RealFile() override;
ErrorOr<Status> status() override;
- ErrorOr<std::string> getName() override;
+ Optional<std::string> getRealPath() override;
ErrorOr<std::unique_ptr<MemoryBuffer>> getBuffer(const Twine &Name,
int64_t FileSize,
bool RequiresNullTerminator,
@@ -207,13 +206,15 @@ ErrorOr<Status> RealFile::status() {
file_status RealStatus;
if (std::error_code EC = sys::fs::status(FD, RealStatus))
return EC;
- S = Status::copyWithNewName(RealStatus, S.getName());
+ S = Status(RealStatus, S.getName());
}
return S;
}
-ErrorOr<std::string> RealFile::getName() {
- return RealName.empty() ? S.getName().str() : RealName;
+Optional<std::string> RealFile::getRealPath() {
+ if (RealName.empty())
+ return llvm::None;
+ return RealName;
}
ErrorOr<std::unique_ptr<MemoryBuffer>>
@@ -251,7 +252,7 @@ ErrorOr<Status> RealFileSystem::status(const Twine &Path) {
sys::fs::file_status RealStatus;
if (std::error_code EC = sys::fs::status(Path, RealStatus))
return EC;
- return Status::copyWithNewName(RealStatus, Path.str());
+ return Status(RealStatus, Path.str());
}
ErrorOr<std::unique_ptr<File>>
@@ -303,7 +304,7 @@ public:
if (Iter != llvm::sys::fs::directory_iterator()) {
llvm::sys::fs::file_status S;
std::error_code ErrorCode = llvm::sys::fs::status(Iter->path(), S, true);
- CurrentEntry = Status::copyWithNewName(S, Iter->path());
+ CurrentEntry = Status(S, Iter->path());
if (!EC)
EC = ErrorCode;
}
@@ -317,7 +318,7 @@ public:
} else {
llvm::sys::fs::file_status S;
std::error_code ErrorCode = llvm::sys::fs::status(Iter->path(), S, true);
- CurrentEntry = Status::copyWithNewName(S, Iter->path());
+ CurrentEntry = Status(S, Iter->path());
if (!EC)
EC = ErrorCode;
}
@@ -1641,7 +1642,7 @@ static Status getRedirectedFileStatus(const Twine &Path, bool UseExternalNames,
Status ExternalStatus) {
Status S = ExternalStatus;
if (!UseExternalNames)
- S = Status::copyWithNewName(S, Path.str());
+ S = S.copyWithNewName(Path.str());
S.IsVFSMapped = true;
return S;
}
@@ -1657,7 +1658,7 @@ ErrorOr<Status> RedirectingFileSystem::status(const Twine &Path, Entry *E) {
return S;
} else { // directory
auto *DE = cast<RedirectingDirectoryEntry>(E);
- return Status::copyWithNewName(DE->getStatus(), Path.str());
+ return DE->getStatus().copyWithNewName(Path.str());
}
}
OpenPOWER on IntegriCloud