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 | d5f33aa33fbf865e15a3dced11b847e88f6a8239 (patch) | |
tree | 65d3258017f450661a509f07c4553aa4609aff93 /lib/Support/YAMLTraits.cpp | |
parent | a630cb032cc09aaec92fa4ce26891abfa7fa1348 (diff) | |
download | external_llvm-d5f33aa33fbf865e15a3dced11b847e88f6a8239.zip external_llvm-d5f33aa33fbf865e15a3dced11b847e88f6a8239.tar.gz external_llvm-d5f33aa33fbf865e15a3dced11b847e88f6a8239.tar.bz2 |
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
Diffstat (limited to 'lib/Support/YAMLTraits.cpp')
-rw-r--r-- | lib/Support/YAMLTraits.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Support/YAMLTraits.cpp b/lib/Support/YAMLTraits.cpp index b0cd415..ae7f7dc 100644 --- a/lib/Support/YAMLTraits.cpp +++ b/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; |