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 /lib | |
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 'lib')
-rw-r--r-- | lib/Basic/VirtualFileSystem.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/Basic/VirtualFileSystem.cpp b/lib/Basic/VirtualFileSystem.cpp index 253680e855..3d5e1ad24a 100644 --- a/lib/Basic/VirtualFileSystem.cpp +++ b/lib/Basic/VirtualFileSystem.cpp @@ -1168,3 +1168,38 @@ std::error_code VFSFromYamlDirIterImpl::increment() { } return std::error_code(); } + +vfs::recursive_directory_iterator::recursive_directory_iterator(FileSystem &FS_, + const Twine &Path, + std::error_code &EC) + : FS(&FS_) { + directory_iterator I = FS->dir_begin(Path, EC); + if (!EC && I != directory_iterator()) { + State = std::make_shared<IterState>(); + State->push(I); + } +} + +vfs::recursive_directory_iterator & +recursive_directory_iterator::increment(std::error_code &EC) { + assert(FS && State && !State->empty() && "incrementing past end"); + assert(State->top()->isStatusKnown() && "non-canonical end iterator"); + vfs::directory_iterator End; + if (State->top()->isDirectory()) { + vfs::directory_iterator I = FS->dir_begin(State->top()->getName(), EC); + if (EC) + return *this; + if (I != End) { + State->push(I); + return *this; + } + } + + while (!State->empty() && State->top().increment(EC) == End) + State->pop(); + + if (State->empty()) + State.reset(); // end iterator + + return *this; +}
\ No newline at end of file |