r342976 - [VFS] Add a proxy FS that delegates calls to underlying FS by default.

Eric Liu via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 25 07:02:01 PDT 2018


Author: ioeric
Date: Tue Sep 25 07:02:01 2018
New Revision: 342976

URL: http://llvm.org/viewvc/llvm-project?rev=342976&view=rev
Log:
[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

Modified:
    cfe/trunk/include/clang/Basic/VirtualFileSystem.h

Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/VirtualFileSystem.h?rev=342976&r1=342975&r2=342976&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/VirtualFileSystem.h (original)
+++ cfe/trunk/include/clang/Basic/VirtualFileSystem.h Tue Sep 25 07:02:01 2018
@@ -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<FileSystem> FS)
+      : FS(std::move(FS)) {}
+
+  llvm::ErrorOr<Status> status(const Twine &Path) override {
+    return FS->status(Path);
+  }
+  llvm::ErrorOr<std::unique_ptr<File>>
+  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<std::string> 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<char> &Output) const override {
+    return FS->getRealPath(Path, Output);
+  }
+
+protected:
+  FileSystem &getUnderlyingFS() { return *FS; }
+
+private:
+  IntrusiveRefCntPtr<FileSystem> FS;
+};
+
 namespace detail {
 
 class InMemoryDirectory;




More information about the cfe-commits mailing list