From bbb11065cb90800d0c0b4531f9f15585d8ca0292 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Tue, 25 Sep 2018 14:02:01 +0000 Subject: [PATCH] [VFS] Add a proxy FS that delegates calls to underlying FS by default. Summary: This is useful when derived file systems want to override some calls and still proxy other calls. Reviewers: ilya-biryukov, sammccall Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D52462 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@342976 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/VirtualFileSystem.h | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/include/clang/Basic/VirtualFileSystem.h b/include/clang/Basic/VirtualFileSystem.h index fe660cc017..97e2941d05 100644 --- a/include/clang/Basic/VirtualFileSystem.h +++ b/include/clang/Basic/VirtualFileSystem.h @@ -335,6 +335,42 @@ public: const_iterator overlays_end() const { return FSList.rend(); } }; +/// By default, this delegates all calls to the underlying file system. This +/// is useful when derived file systems want to override some calls and still +/// proxy other calls. +class ProxyFileSystem : public FileSystem { +public: + explicit ProxyFileSystem(IntrusiveRefCntPtr FS) + : FS(std::move(FS)) {} + + llvm::ErrorOr status(const Twine &Path) override { + return FS->status(Path); + } + llvm::ErrorOr> + openFileForRead(const Twine &Path) override { + return FS->openFileForRead(Path); + } + directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override { + return FS->dir_begin(Dir, EC); + } + llvm::ErrorOr getCurrentWorkingDirectory() const override { + return FS->getCurrentWorkingDirectory(); + } + std::error_code setCurrentWorkingDirectory(const Twine &Path) override { + return FS->setCurrentWorkingDirectory(Path); + } + std::error_code getRealPath(const Twine &Path, + SmallVectorImpl &Output) const override { + return FS->getRealPath(Path, Output); + } + +protected: + FileSystem &getUnderlyingFS() { return *FS; } + +private: + IntrusiveRefCntPtr FS; +}; + namespace detail { class InMemoryDirectory; -- 2.50.1