summaryrefslogtreecommitdiffstats
path: root/utils/yaml-bench
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2013-10-18 22:38:04 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2013-10-18 22:38:04 +0000
commit44a4cfb63d87dc0ba778982a1796673ca1513e90 (patch)
tree812db96f331b2a915f60bd0e03fd6d225f1e3735 /utils/yaml-bench
parent630c3264a650af8e74f2b0b5ae7b57a17cb52061 (diff)
downloadexternal_llvm-44a4cfb63d87dc0ba778982a1796673ca1513e90.zip
external_llvm-44a4cfb63d87dc0ba778982a1796673ca1513e90.tar.gz
external_llvm-44a4cfb63d87dc0ba778982a1796673ca1513e90.tar.bz2
[Support][YAML] Add support for accessing tags and tag handle substitution.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193004 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/yaml-bench')
-rw-r--r--utils/yaml-bench/YAMLBench.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/utils/yaml-bench/YAMLBench.cpp b/utils/yaml-bench/YAMLBench.cpp
index eef4a72..f20a4cc 100644
--- a/utils/yaml-bench/YAMLBench.cpp
+++ b/utils/yaml-bench/YAMLBench.cpp
@@ -63,6 +63,20 @@ static raw_ostream &operator <<(raw_ostream &os, const indent &in) {
return os;
}
+/// \brief Pretty print a tag by replacing tag:yaml.org,2002: with !!.
+static std::string prettyTag(yaml::Node *N) {
+ std::string Tag = N->getVerbatimTag();
+ if (StringRef(Tag).startswith("tag:yaml.org,2002:")) {
+ std::string Ret = "!!";
+ Ret += StringRef(Tag).substr(18);
+ return std::move(Ret);
+ }
+ std::string Ret = "!<";
+ Ret += Tag;
+ Ret += ">";
+ return Ret;
+}
+
static void dumpNode( yaml::Node *n
, unsigned Indent = 0
, bool SuppressFirstIndent = false) {
@@ -76,9 +90,9 @@ static void dumpNode( yaml::Node *n
if (yaml::ScalarNode *sn = dyn_cast<yaml::ScalarNode>(n)) {
SmallString<32> Storage;
StringRef Val = sn->getValue(Storage);
- outs() << "!!str \"" << yaml::escape(Val) << "\"";
+ outs() << prettyTag(n) << " \"" << yaml::escape(Val) << "\"";
} else if (yaml::SequenceNode *sn = dyn_cast<yaml::SequenceNode>(n)) {
- outs() << "!!seq [\n";
+ outs() << prettyTag(n) << " [\n";
++Indent;
for (yaml::SequenceNode::iterator i = sn->begin(), e = sn->end();
i != e; ++i) {
@@ -88,7 +102,7 @@ static void dumpNode( yaml::Node *n
--Indent;
outs() << indent(Indent) << "]";
} else if (yaml::MappingNode *mn = dyn_cast<yaml::MappingNode>(n)) {
- outs() << "!!map {\n";
+ outs() << prettyTag(n) << " {\n";
++Indent;
for (yaml::MappingNode::iterator i = mn->begin(), e = mn->end();
i != e; ++i) {
@@ -104,7 +118,7 @@ static void dumpNode( yaml::Node *n
} else if (yaml::AliasNode *an = dyn_cast<yaml::AliasNode>(n)){
outs() << "*" << an->getName();
} else if (dyn_cast<yaml::NullNode>(n)) {
- outs() << "!!null null";
+ outs() << prettyTag(n) << " null";
}
}