diff options
author | Ben Langmuir <blangmuir@apple.com> | 2014-06-25 20:25:40 +0000 |
---|---|---|
committer | Ben Langmuir <blangmuir@apple.com> | 2014-06-25 20:25:40 +0000 |
commit | 6f641ccd0e64bbfd28794eb2fbbf50169d7898b7 (patch) | |
tree | 3be1a17df6a4f1acfef8f98d7dcff870ec8a85bc /include/clang/Basic/VirtualFileSystem.h | |
parent | e5fdb78baffc29df6c772dbe80c113bc22bd72c6 (diff) | |
download | clang-6f641ccd0e64bbfd28794eb2fbbf50169d7898b7.tar.gz clang-6f641ccd0e64bbfd28794eb2fbbf50169d7898b7.tar.bz2 clang-6f641ccd0e64bbfd28794eb2fbbf50169d7898b7.tar.xz |
Add vfs::recursive_directory_iterator
For now, this is only used by its unit tests. It is similar to the API
in llvm::sys::fs::recursive_directory_iterator, but without some of the
more complex features like requesting that the iterator not recurse into
the next directory, for example.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211732 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/VirtualFileSystem.h')
-rw-r--r-- | include/clang/Basic/VirtualFileSystem.h | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/include/clang/Basic/VirtualFileSystem.h b/include/clang/Basic/VirtualFileSystem.h index 3b43d1e75f..882ebdb12b 100644 --- a/include/clang/Basic/VirtualFileSystem.h +++ b/include/clang/Basic/VirtualFileSystem.h @@ -149,6 +149,37 @@ public: } }; +class FileSystem; + +/// \brief An input iterator over the recursive contents of a virtual path, +/// similar to llvm::sys::fs::recursive_directory_iterator. +class recursive_directory_iterator { + typedef std::stack<directory_iterator, std::vector<directory_iterator>> + IterState; + + FileSystem *FS; + std::shared_ptr<IterState> State; // Input iterator semantics on copy. + +public: + recursive_directory_iterator(FileSystem &FS, const Twine &Path, + std::error_code &EC); + /// \brief Construct an 'end' iterator. + recursive_directory_iterator() { } + + /// \brief Equivalent to operator++, with an error code. + recursive_directory_iterator &increment(std::error_code &EC); + + const Status &operator*() const { return *State->top(); } + const Status *operator->() const { return &*State->top(); } + + bool operator==(const recursive_directory_iterator &Other) const { + return State == Other.State; // identity + } + bool operator!=(const recursive_directory_iterator &RHS) const { + return !(*this == RHS); + } +}; + /// \brief The virtual file system interface. class FileSystem : public llvm::ThreadSafeRefCountedBase<FileSystem> { public: @@ -172,8 +203,6 @@ public: /// \note The 'end' iterator is directory_iterator() virtual directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) = 0; - - // TODO: recursive directory iterators }; /// \brief Gets an \p vfs::FileSystem for the 'real' file system, as seen by |