Tighten up the yamilizer so it stops eliding empty sequences if the embedded empty sequence is the first key/value in a map which is itself in a sequence.

Patch with help from Nick Kledzik.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188508 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Aaron Ballman
2013-08-15 23:17:53 +00:00
parent a630cb032c
commit d5f33aa33f
3 changed files with 84 additions and 2 deletions
+17
View File
@@ -334,6 +334,10 @@ void Input::setError(const Twine &Message) {
this->setError(CurrentNode, Message);
}
bool Input::canElideEmptySequence() {
return false;
}
Input::MapHNode::~MapHNode() {
for (MapHNode::NameToNode::iterator i = Mapping.begin(), End = Mapping.end();
i != End; ++i) {
@@ -532,6 +536,19 @@ void Output::scalarString(StringRef &S) {
void Output::setError(const Twine &message) {
}
bool Output::canElideEmptySequence() {
// Normally, with an optional key/value where the value is an empty sequence,
// the whole key/value can be not written. But, that produces wrong yaml
// if the key/value is the only thing in the map and the map is used in
// a sequence. This detects if the this sequence is the first key/value
// in map that itself is embedded in a sequnce.
if (StateStack.size() < 2)
return true;
if (StateStack.back() != inMapFirstKey)
return true;
return (StateStack[StateStack.size()-2] != inSeq);
}
void Output::output(StringRef s) {
Column += s.size();
Out << s;