diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2013-08-15 23:17:53 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2013-08-15 23:17:53 +0000 |
commit | 0e63e53da1b144c9a1b8752db3215c55f39446d1 (patch) | |
tree | 2f90c575f637e27c0c0792e1c93f168537e465ae /llvm/lib/Support/YAMLTraits.cpp | |
parent | 1de76773bc3b0ac640d03104680659b99dab18cf (diff) | |
download | bcm5719-llvm-0e63e53da1b144c9a1b8752db3215c55f39446d1.tar.gz bcm5719-llvm-0e63e53da1b144c9a1b8752db3215c55f39446d1.zip |
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.
llvm-svn: 188508
Diffstat (limited to 'llvm/lib/Support/YAMLTraits.cpp')
-rw-r--r-- | llvm/lib/Support/YAMLTraits.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp index b0cd4151863..ae7f7dcb0d0 100644 --- a/llvm/lib/Support/YAMLTraits.cpp +++ b/llvm/lib/Support/YAMLTraits.cpp @@ -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; |