[PATCH] D95280: [YAML I/O] Fix bug in emission of empty sequence
Jonas Devlieghere via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 25 13:35:52 PST 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf50b8ee71fae: [YAML I/O] Fix bug in emission of empty sequence (authored by JDevlieghere).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D95280/new/
https://reviews.llvm.org/D95280
Files:
llvm/include/llvm/Support/YAMLTraits.h
llvm/lib/Support/YAMLTraits.cpp
llvm/unittests/Support/YAMLIOTest.cpp
Index: llvm/unittests/Support/YAMLIOTest.cpp
===================================================================
--- llvm/unittests/Support/YAMLIOTest.cpp
+++ llvm/unittests/Support/YAMLIOTest.cpp
@@ -2691,12 +2691,23 @@
}
TEST(YAMLIO, TestEmptySequenceWrite) {
- FooBarContainer cont;
- std::string str;
- llvm::raw_string_ostream OS(str);
- Output yout(OS);
- yout << cont;
- EXPECT_EQ(OS.str(), "---\nfbs: []\n...\n");
+ {
+ FooBarContainer cont;
+ std::string str;
+ llvm::raw_string_ostream OS(str);
+ Output yout(OS);
+ yout << cont;
+ EXPECT_EQ(OS.str(), "---\nfbs: []\n...\n");
+ }
+
+ {
+ FooBarSequence seq;
+ std::string str;
+ llvm::raw_string_ostream OS(str);
+ Output yout(OS);
+ yout << seq;
+ EXPECT_EQ(OS.str(), "---\n[]\n...\n");
+ }
}
static void TestEscaped(llvm::StringRef Input, llvm::StringRef Expected) {
Index: llvm/lib/Support/YAMLTraits.cpp
===================================================================
--- llvm/lib/Support/YAMLTraits.cpp
+++ llvm/lib/Support/YAMLTraits.cpp
@@ -592,7 +592,7 @@
// If we did not emit anything, we should explicitly emit an empty sequence
if (StateStack.back() == inSeqFirstElement) {
Padding = PaddingBeforeContainer;
- newLineCheck();
+ newLineCheck(/*EmptySequence=*/true);
output("[]");
Padding = "\n";
}
@@ -798,7 +798,7 @@
// if seq in middle, use "- " if firstKey, else use " "
//
-void Output::newLineCheck() {
+void Output::newLineCheck(bool EmptySequence) {
if (Padding != "\n") {
output(Padding);
Padding = {};
@@ -807,7 +807,7 @@
outputNewLine();
Padding = {};
- if (StateStack.size() == 0)
+ if (StateStack.size() == 0 || EmptySequence)
return;
unsigned Indent = StateStack.size() - 1;
@@ -831,7 +831,6 @@
if (OutputDash) {
output("- ");
}
-
}
void Output::paddedKey(StringRef key) {
Index: llvm/include/llvm/Support/YAMLTraits.h
===================================================================
--- llvm/include/llvm/Support/YAMLTraits.h
+++ llvm/include/llvm/Support/YAMLTraits.h
@@ -1586,7 +1586,7 @@
private:
void output(StringRef s);
void outputUpToEndOfLine(StringRef s);
- void newLineCheck();
+ void newLineCheck(bool EmptySequence = false);
void outputNewLine();
void paddedKey(StringRef key);
void flowKey(StringRef Key);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95280.319106.patch
Type: text/x-patch
Size: 2391 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210125/c0449ac7/attachment.bin>
More information about the llvm-commits
mailing list