aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/VirtualFileSystem.cpp
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2022-01-20 15:05:38 +0100
committerJan Svoboda <jan_svoboda@apple.com>2022-01-20 15:48:02 +0100
commit9e24d14ac89f44bb6c9141561ca849ccdd09e6a8 (patch)
treee0364f9bdad4e413da53a870321b7a5e50fc93ba /llvm/lib/Support/VirtualFileSystem.cpp
parent6d45284618f08fa28dc515cab96fa573c4c4479e (diff)
downloadllvm-9e24d14ac89f44bb6c9141561ca849ccdd09e6a8.zip
llvm-9e24d14ac89f44bb6c9141561ca849ccdd09e6a8.tar.gz
llvm-9e24d14ac89f44bb6c9141561ca849ccdd09e6a8.tar.bz2
[llvm][vfs] NFC: Virtualize in-memory `getStatus`
This patch virtualizes the `getStatus` function on `InMemoryNode` in LLVM VFS. Currently, this is implemented via top-level function `getNodeStatus` that tries to cast `InMemoryNode *` into each subtype. Virtual functions seem to be the simpler solution here. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D117649
Diffstat (limited to 'llvm/lib/Support/VirtualFileSystem.cpp')
-rw-r--r--llvm/lib/Support/VirtualFileSystem.cpp29
1 files changed, 12 insertions, 17 deletions
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp
index 7b752b5..1536f4d 100644
--- a/llvm/lib/Support/VirtualFileSystem.cpp
+++ b/llvm/lib/Support/VirtualFileSystem.cpp
@@ -574,6 +574,11 @@ public:
}
virtual ~InMemoryNode() = default;
+ /// Return the \p Status for this node. \p RequestedName should be the name
+ /// through which the caller referred to this node. It will override
+ /// \p Status::Name in the return value, to mimic the behavior of \p RealFile.
+ virtual Status getStatus(const Twine &RequestedName) const = 0;
+
/// Get the filename of this node (the name without the directory part).
StringRef getFileName() const { return FileName; }
InMemoryNodeKind getKind() const { return Kind; }
@@ -589,10 +594,7 @@ public:
: InMemoryNode(Stat.getName(), IME_File), Stat(std::move(Stat)),
Buffer(std::move(Buffer)) {}
- /// Return the \p Status for this node. \p RequestedName should be the name
- /// through which the caller referred to this node. It will override
- /// \p Status::Name in the return value, to mimic the behavior of \p RealFile.
- Status getStatus(const Twine &RequestedName) const {
+ Status getStatus(const Twine &RequestedName) const override {
return Status::copyWithNewName(Stat, RequestedName);
}
llvm::MemoryBuffer *getBuffer() const { return Buffer.get(); }
@@ -616,6 +618,10 @@ public:
: InMemoryNode(Path, IME_HardLink), ResolvedFile(ResolvedFile) {}
const InMemoryFile &getResolvedFile() const { return ResolvedFile; }
+ Status getStatus(const Twine &RequestedName) const override {
+ return ResolvedFile.getStatus(RequestedName);
+ }
+
std::string toString(unsigned Indent) const override {
return std::string(Indent, ' ') + "HardLink to -> " +
ResolvedFile.toString(0);
@@ -668,7 +674,7 @@ public:
/// Return the \p Status for this node. \p RequestedName should be the name
/// through which the caller referred to this node. It will override
/// \p Status::Name in the return value, to mimic the behavior of \p RealFile.
- Status getStatus(const Twine &RequestedName) const {
+ Status getStatus(const Twine &RequestedName) const override {
return Status::copyWithNewName(Stat, RequestedName);
}
@@ -704,17 +710,6 @@ public:
}
};
-namespace {
-Status getNodeStatus(const InMemoryNode *Node, const Twine &RequestedName) {
- if (auto Dir = dyn_cast<detail::InMemoryDirectory>(Node))
- return Dir->getStatus(RequestedName);
- if (auto File = dyn_cast<detail::InMemoryFile>(Node))
- return File->getStatus(RequestedName);
- if (auto Link = dyn_cast<detail::InMemoryHardLink>(Node))
- return Link->getResolvedFile().getStatus(RequestedName);
- llvm_unreachable("Unknown node type");
-}
-} // namespace
} // namespace detail
// The UniqueID of in-memory files is derived from path and content.
@@ -923,7 +918,7 @@ bool InMemoryFileSystem::addHardLink(const Twine &FromPath,
llvm::ErrorOr<Status> InMemoryFileSystem::status(const Twine &Path) {
auto Node = lookupInMemoryNode(*this, Root.get(), Path);
if (Node)
- return detail::getNodeStatus(*Node, Path);
+ return (*Node)->getStatus(Path);
return Node.getError();
}