[PATCH] D79809: [YAMLVFSWriter] Fix for delimiters

Jan Korous via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 12 15:40:34 PDT 2020


jkorous updated this revision to Diff 263547.
jkorous marked an inline comment as done.
jkorous added a comment.

Renamed local var


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79809/new/

https://reviews.llvm.org/D79809

Files:
  llvm/lib/Support/VirtualFileSystem.cpp
  llvm/unittests/Support/VirtualFileSystemTest.cpp


Index: llvm/unittests/Support/VirtualFileSystemTest.cpp
===================================================================
--- llvm/unittests/Support/VirtualFileSystemTest.cpp
+++ llvm/unittests/Support/VirtualFileSystemTest.cpp
@@ -2267,8 +2267,7 @@
 
   IntrusiveRefCntPtr<ErrorDummyFileSystem> Lower(new ErrorDummyFileSystem());
   IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLRawString(Buffer, Lower);
-  // FIXME: Missing comma separator between file entries.
-  EXPECT_FALSE(FS.get() != nullptr);
+  EXPECT_TRUE(FS.get() != nullptr);
 }
 
 TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest3) {
@@ -2301,8 +2300,7 @@
 
   IntrusiveRefCntPtr<ErrorDummyFileSystem> Lower(new ErrorDummyFileSystem());
   IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLRawString(Buffer, Lower);
-  // FIXME: Spurious comma separator before first file entry in directory.
-  EXPECT_FALSE(FS.get() != nullptr);
+  EXPECT_TRUE(FS.get() != nullptr);
 }
 
 TEST_F(VFSFromYAMLTest, YAMLVFSWriterTestHandleDirs) {
Index: llvm/lib/Support/VirtualFileSystem.cpp
===================================================================
--- llvm/lib/Support/VirtualFileSystem.cpp
+++ llvm/lib/Support/VirtualFileSystem.cpp
@@ -2027,10 +2027,10 @@
 
   if (!Entries.empty()) {
     const YAMLVFSEntry &Entry = Entries.front();
-    bool first_entry_is_directory = Entry.IsDirectory;
-    StringRef Dir =
-        first_entry_is_directory ? Entry.VPath : path::parent_path(Entry.VPath);
-    startDirectory(Dir);
+
+    startDirectory(
+      Entry.IsDirectory ? Entry.VPath : path::parent_path(Entry.VPath)
+    );
 
     StringRef RPath = Entry.RPath;
     if (UseOverlayRelative) {
@@ -2040,24 +2040,31 @@
       RPath = RPath.slice(OverlayDirLen, RPath.size());
     }
 
-    if (!first_entry_is_directory)
+    bool IsCurrentDirEmpty = true;
+    if (!Entry.IsDirectory) {
       writeEntry(path::filename(Entry.VPath), RPath);
+      IsCurrentDirEmpty = false;
+    }
 
     for (const auto &Entry : Entries.slice(1)) {
       StringRef Dir =
           Entry.IsDirectory ? Entry.VPath : path::parent_path(Entry.VPath);
       if (Dir == DirStack.back()) {
-        if (!first_entry_is_directory) {
+        if (!IsCurrentDirEmpty) {
           OS << ",\n";
-          first_entry_is_directory = false;
         }
       } else {
+        bool IsDirPoppedFromStack = false;
         while (!DirStack.empty() && !containedIn(DirStack.back(), Dir)) {
           OS << "\n";
           endDirectory();
+          IsDirPoppedFromStack = true;
+        }
+        if (IsDirPoppedFromStack || !IsCurrentDirEmpty) {
+          OS << ",\n";
         }
-        OS << ",\n";
         startDirectory(Dir);
+        IsCurrentDirEmpty = true;
       }
       StringRef RPath = Entry.RPath;
       if (UseOverlayRelative) {
@@ -2066,8 +2073,10 @@
                "Overlay dir must be contained in RPath");
         RPath = RPath.slice(OverlayDirLen, RPath.size());
       }
-      if (!Entry.IsDirectory)
+      if (!Entry.IsDirectory) {
         writeEntry(path::filename(Entry.VPath), RPath);
+        IsCurrentDirEmpty = false;
+      }
     }
 
     while (!DirStack.empty()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79809.263547.patch
Type: text/x-patch
Size: 3146 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200512/703a0706/attachment.bin>


More information about the llvm-commits mailing list