summaryrefslogtreecommitdiff
path: root/include/clang/Basic/VirtualFileSystem.h
diff options
context:
space:
mode:
authorBen Langmuir <blangmuir@apple.com>2014-02-19 03:29:17 +0000
committerBen Langmuir <blangmuir@apple.com>2014-02-19 03:29:17 +0000
commit0d3cd059d7f9f37dcc8812e5e879502f4ec28283 (patch)
tree541d7ca71892b80f207c7167d4a37f6b4c4543c6 /include/clang/Basic/VirtualFileSystem.h
parentf9b4b1d7b0bb58088042ae413a27390645046fe8 (diff)
downloadclang-0d3cd059d7f9f37dcc8812e5e879502f4ec28283.tar.gz
clang-0d3cd059d7f9f37dcc8812e5e879502f4ec28283.tar.bz2
clang-0d3cd059d7f9f37dcc8812e5e879502f4ec28283.tar.xz
Add an OverlayFileSystem class
Provides a way to merge multiple vfs::FileSystem objects into a single filesystem. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201635 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/VirtualFileSystem.h')
-rw-r--r--include/clang/Basic/VirtualFileSystem.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/include/clang/Basic/VirtualFileSystem.h b/include/clang/Basic/VirtualFileSystem.h
index 9bd6b2bc63..6dd9bf73b3 100644
--- a/include/clang/Basic/VirtualFileSystem.h
+++ b/include/clang/Basic/VirtualFileSystem.h
@@ -122,6 +122,42 @@ public:
/// the operating system.
llvm::IntrusiveRefCntPtr<FileSystem> getRealFileSystem();
+/// \brief A file system that allows overlaying one \p AbstractFileSystem on top
+/// of another.
+///
+/// Consists of a stack of >=1 \p FileSytem objects, which are treated as being
+/// one merged file system. When there is a directory that exists in more than
+/// one file system, the \p OverlayFileSystem contains a directory containing
+/// the union of their contents. The attributes (permissions, etc.) of the
+/// top-most (most recently added) directory are used. When there is a file
+/// that exists in more than one file system, the file in the top-most file
+/// system overrides the other(s).
+class OverlayFileSystem : public FileSystem {
+ typedef llvm::SmallVector<llvm::IntrusiveRefCntPtr<FileSystem>, 1>
+ FileSystemList;
+ typedef FileSystemList::reverse_iterator iterator;
+
+ /// \brief The stack of file systems, implemented as a list in order of
+ /// their addition.
+ FileSystemList FSList;
+
+ /// \brief Get an iterator pointing to the most recently added file system.
+ iterator overlays_begin() { return FSList.rbegin(); }
+
+ /// \brief Get an iterator pointing one-past the least recently added file
+ /// system.
+ iterator overlays_end() { return FSList.rend(); }
+
+public:
+ OverlayFileSystem(llvm::IntrusiveRefCntPtr<FileSystem> Base);
+ /// \brief Pushes a file system on top of the stack.
+ void pushOverlay(llvm::IntrusiveRefCntPtr<FileSystem> FS);
+
+ llvm::ErrorOr<Status> status(const llvm::Twine &Path) LLVM_OVERRIDE;
+ llvm::error_code openFileForRead(const llvm::Twine &Path,
+ llvm::OwningPtr<File> &Result) LLVM_OVERRIDE;
+};
+
} // end namespace vfs
} // end namespace clang
#endif // LLVM_CLANG_BASIC_VIRTUAL_FILE_SYSTEM_H