diff options
author | Jan Korous <jkorous@apple.com> | 2020-05-12 14:42:22 -0700 |
---|---|---|
committer | Jan Korous <jkorous@apple.com> | 2020-05-12 15:43:10 -0700 |
commit | 759465ee34c0c0118fbd21cad87de17bb3be13e0 (patch) | |
tree | 603f105d6a73350ee422101cbb647d833be07045 /llvm/lib/Support/VirtualFileSystem.cpp | |
parent | f490ca76b0ee69dd091a5535dbb948f123a96e2e (diff) | |
download | llvm-759465ee34c0c0118fbd21cad87de17bb3be13e0.zip llvm-759465ee34c0c0118fbd21cad87de17bb3be13e0.tar.gz llvm-759465ee34c0c0118fbd21cad87de17bb3be13e0.tar.bz2 |
[YAMLVFSWriter] Fix for delimiters
Differential Revision: https://reviews.llvm.org/D79809
Diffstat (limited to 'llvm/lib/Support/VirtualFileSystem.cpp')
-rw-r--r-- | llvm/lib/Support/VirtualFileSystem.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp index e71b92b..5b757c9 100644 --- a/llvm/lib/Support/VirtualFileSystem.cpp +++ b/llvm/lib/Support/VirtualFileSystem.cpp @@ -2027,10 +2027,10 @@ void JSONWriter::write(ArrayRef<YAMLVFSEntry> Entries, 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 @@ void JSONWriter::write(ArrayRef<YAMLVFSEntry> Entries, 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 @@ void JSONWriter::write(ArrayRef<YAMLVFSEntry> Entries, "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()) { |