summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/YAMLTraits.cpp
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2015-05-04 20:11:40 +0000
committerAlex Lorenz <arphaman@gmail.com>2015-05-04 20:11:40 +0000
commitb1225085012ad7fc8f45c3683a6220868273c284 (patch)
treea84b6034ebcbfd2fe713963e26fcb559f42f1829 /llvm/lib/Support/YAMLTraits.cpp
parentd71a17710beaa2c95aeaf51f264c7436a69a4b35 (diff)
downloadbcm5719-llvm-b1225085012ad7fc8f45c3683a6220868273c284.tar.gz
bcm5719-llvm-b1225085012ad7fc8f45c3683a6220868273c284.zip
YAML: Add an optional 'flow' field to the mapping trait to allow flow mapping output.
This patch adds an optional 'flow' field to the MappingTrait class so that yaml IO will be able to output flow mappings. Reviewers: Justin Bogner Differential Revision: http://reviews.llvm.org/D9450 llvm-svn: 236456
Diffstat (limited to 'llvm/lib/Support/YAMLTraits.cpp')
-rw-r--r--llvm/lib/Support/YAMLTraits.cpp50
1 files changed, 46 insertions, 4 deletions
diff --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp
index 16821738190..8ef36a33280 100644
--- a/llvm/lib/Support/YAMLTraits.cpp
+++ b/llvm/lib/Support/YAMLTraits.cpp
@@ -168,6 +168,10 @@ void Input::endMapping() {
}
}
+void Input::beginFlowMapping() { beginMapping(); }
+
+void Input::endFlowMapping() { endMapping(); }
+
unsigned Input::beginSequence() {
if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode))
return SQ->Entries.size();
@@ -393,6 +397,7 @@ Output::Output(raw_ostream &yout, void *context)
Out(yout),
Column(0),
ColumnAtFlowStart(0),
+ ColumnAtMapFlowStart(0),
NeedBitValueComma(false),
NeedFlowSequenceComma(false),
EnumerationMatchFound(false),
@@ -427,8 +432,13 @@ bool Output::preflightKey(const char *Key, bool Required, bool SameAsDefault,
bool &UseDefault, void *&) {
UseDefault = false;
if (Required || !SameAsDefault) {
- this->newLineCheck();
- this->paddedKey(Key);
+ auto State = StateStack.back();
+ if (State == inFlowMapFirstKey || State == inFlowMapOtherKey) {
+ flowKey(Key);
+ } else {
+ this->newLineCheck();
+ this->paddedKey(Key);
+ }
return true;
}
return false;
@@ -438,9 +448,24 @@ void Output::postflightKey(void *) {
if (StateStack.back() == inMapFirstKey) {
StateStack.pop_back();
StateStack.push_back(inMapOtherKey);
+ } else if (StateStack.back() == inFlowMapFirstKey) {
+ StateStack.pop_back();
+ StateStack.push_back(inFlowMapOtherKey);
}
}
+void Output::beginFlowMapping() {
+ StateStack.push_back(inFlowMapFirstKey);
+ this->newLineCheck();
+ ColumnAtMapFlowStart = Column;
+ output("{ ");
+}
+
+void Output::endFlowMapping() {
+ StateStack.pop_back();
+ this->outputUpToEndOfLine(" }");
+}
+
void Output::beginDocuments() {
this->outputUpToEndOfLine("---");
}
@@ -607,7 +632,9 @@ void Output::output(StringRef s) {
void Output::outputUpToEndOfLine(StringRef s) {
this->output(s);
- if (StateStack.empty() || StateStack.back() != inFlowSeq)
+ if (StateStack.empty() || (StateStack.back() != inFlowSeq &&
+ StateStack.back() != inFlowMapFirstKey &&
+ StateStack.back() != inFlowMapOtherKey))
NeedsNewLine = true;
}
@@ -634,7 +661,8 @@ void Output::newLineCheck() {
if (StateStack.back() == inSeq) {
OutputDash = true;
} else if ((StateStack.size() > 1) && ((StateStack.back() == inMapFirstKey) ||
- (StateStack.back() == inFlowSeq)) &&
+ (StateStack.back() == inFlowSeq) ||
+ (StateStack.back() == inFlowMapFirstKey)) &&
(StateStack[StateStack.size() - 2] == inSeq)) {
--Indent;
OutputDash = true;
@@ -659,6 +687,20 @@ void Output::paddedKey(StringRef key) {
output(" ");
}
+void Output::flowKey(StringRef Key) {
+ if (StateStack.back() == inFlowMapOtherKey)
+ output(", ");
+ if (Column > 70) {
+ output("\n");
+ for (int I = 0; I < ColumnAtMapFlowStart; ++I)
+ output(" ");
+ Column = ColumnAtMapFlowStart;
+ output(" ");
+ }
+ output(Key);
+ output(": ");
+}
+
//===----------------------------------------------------------------------===//
// traits for built-in types
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud