[llvm] r364986 - [VFS] Add reverse iterator to OverlayFileSystem

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 2 17:45:54 PDT 2019


Author: jdevlieghere
Date: Tue Jul  2 17:45:53 2019
New Revision: 364986

URL: http://llvm.org/viewvc/llvm-project?rev=364986&view=rev
Log:
[VFS] Add reverse iterator to OverlayFileSystem

Add a reverse iterator to the overlay file system. This makes it
possible to take overlays from one OverlayFileSystem, and add them to
another.

Differential revision: https://reviews.llvm.org/D64113

Modified:
    llvm/trunk/include/llvm/Support/VirtualFileSystem.h
    llvm/trunk/unittests/Support/VirtualFileSystemTest.cpp

Modified: llvm/trunk/include/llvm/Support/VirtualFileSystem.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/VirtualFileSystem.h?rev=364986&r1=364985&r2=364986&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/VirtualFileSystem.h (original)
+++ llvm/trunk/include/llvm/Support/VirtualFileSystem.h Tue Jul  2 17:45:53 2019
@@ -343,15 +343,24 @@ public:
 
   using iterator = FileSystemList::reverse_iterator;
   using const_iterator = FileSystemList::const_reverse_iterator;
+  using reverse_iterator = FileSystemList::iterator;
+  using const_reverse_iterator = FileSystemList::const_iterator;
 
   /// Get an iterator pointing to the most recently added file system.
   iterator overlays_begin() { return FSList.rbegin(); }
   const_iterator overlays_begin() const { return FSList.rbegin(); }
 
-  /// Get an iterator pointing one-past the least recently added file
-  /// system.
+  /// Get an iterator pointing one-past the least recently added file system.
   iterator overlays_end() { return FSList.rend(); }
   const_iterator overlays_end() const { return FSList.rend(); }
+
+  /// Get an iterator pointing to the least recently added file system.
+  reverse_iterator overlays_rbegin() { return FSList.begin(); }
+  const_reverse_iterator overlays_rbegin() const { return FSList.begin(); }
+
+  /// Get an iterator pointing one-past the most recently added file system.
+  reverse_iterator overlays_rend() { return FSList.end(); }
+  const_reverse_iterator overlays_rend() const { return FSList.end(); }
 };
 
 /// By default, this delegates all calls to the underlying file system. This

Modified: llvm/trunk/unittests/Support/VirtualFileSystemTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/VirtualFileSystemTest.cpp?rev=364986&r1=364985&r2=364986&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/VirtualFileSystemTest.cpp (original)
+++ llvm/trunk/unittests/Support/VirtualFileSystemTest.cpp Tue Jul  2 17:45:53 2019
@@ -342,6 +342,57 @@ TEST(VirtualFileSystemTest, MergedDirPer
   EXPECT_EQ(0200, Status->getPermissions());
 }
 
+TEST(VirtualFileSystemTest, OverlayIterator) {
+  IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
+  Lower->addRegularFile("/foo");
+  IntrusiveRefCntPtr<DummyFileSystem> Upper(new DummyFileSystem());
+
+  IntrusiveRefCntPtr<vfs::OverlayFileSystem> O(
+      new vfs::OverlayFileSystem(Lower));
+  O->pushOverlay(Upper);
+
+  ErrorOr<vfs::Status> Status((std::error_code()));
+  {
+    auto it = O->overlays_begin();
+    auto end = O->overlays_end();
+
+    EXPECT_NE(it, end);
+
+    Status = (*it)->status("/foo");
+    ASSERT_TRUE(Status.getError());
+
+    it++;
+    EXPECT_NE(it, end);
+
+    Status = (*it)->status("/foo");
+    ASSERT_FALSE(Status.getError());
+    EXPECT_TRUE(Status->exists());
+
+    it++;
+    EXPECT_EQ(it, end);
+  }
+
+  {
+    auto it = O->overlays_rbegin();
+    auto end = O->overlays_rend();
+
+    EXPECT_NE(it, end);
+
+    Status = (*it)->status("/foo");
+    ASSERT_FALSE(Status.getError());
+    EXPECT_TRUE(Status->exists());
+
+    it++;
+    EXPECT_NE(it, end);
+
+    Status = (*it)->status("/foo");
+    ASSERT_TRUE(Status.getError());
+
+    it++;
+    EXPECT_EQ(it, end);
+  }
+}
+
 namespace {
 struct ScopedDir {
   SmallString<128> Path;




More information about the llvm-commits mailing list