summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core/StructuredData.cpp
diff options
context:
space:
mode:
authorJason Molenda <jmolenda@apple.com>2016-07-20 03:49:02 +0000
committerJason Molenda <jmolenda@apple.com>2016-07-20 03:49:02 +0000
commitd9c9da536f0df0efa4dfd95e1797c0edc1950589 (patch)
treef69ee6d0cd9556d8d94f65d3f5b222a594e84923 /lldb/source/Core/StructuredData.cpp
parent074f8d7777c9eb13489982ecbfff198248f5ad57 (diff)
downloadbcm5719-llvm-d9c9da536f0df0efa4dfd95e1797c0edc1950589.tar.gz
bcm5719-llvm-d9c9da536f0df0efa4dfd95e1797c0edc1950589.zip
Add a default-value bool flag pretty_print to the StructuredData Dump methods.
They will dump pretty-print (indentation, extra whitepsace) by default. I'll make a change to ProcessGDBRemote soon so it stops sending JSON strings to debugserver pretty-printed; it's unnecessary extra bytes being sent between the two. llvm-svn: 276079
Diffstat (limited to 'lldb/source/Core/StructuredData.cpp')
-rw-r--r--lldb/source/Core/StructuredData.cpp76
1 files changed, 51 insertions, 25 deletions
diff --git a/lldb/source/Core/StructuredData.cpp b/lldb/source/Core/StructuredData.cpp
index efc104f1f3e..000dacb5f57 100644
--- a/lldb/source/Core/StructuredData.cpp
+++ b/lldb/source/Core/StructuredData.cpp
@@ -203,50 +203,64 @@ StructuredData::Object::GetObjectForDotSeparatedPath (llvm::StringRef path)
}
void
-StructuredData::Object::DumpToStdout() const
+StructuredData::Object::DumpToStdout(bool pretty_print) const
{
StreamString stream;
- Dump(stream);
+ Dump(stream, pretty_print);
printf("%s\n", stream.GetString().c_str());
}
void
-StructuredData::Array::Dump(Stream &s) const
+StructuredData::Array::Dump(Stream &s, bool pretty_print) const
{
bool first = true;
- s << "[\n";
- s.IndentMore();
+ s << "[";
+ if (pretty_print)
+ {
+ s << "\n";
+ s.IndentMore();
+ }
for (const auto &item_sp : m_items)
{
if (first)
+ {
first = false;
+ }
else
- s << ",\n";
+ {
+ s << ",";
+ if (pretty_print)
+ s << "\n";
+ }
+ if (pretty_print)
+ s.Indent();
+ item_sp->Dump(s, pretty_print);
+ }
+ if (pretty_print)
+ {
+ s.IndentLess();
+ s.EOL();
s.Indent();
- item_sp->Dump(s);
}
- s.IndentLess();
- s.EOL();
- s.Indent();
s << "]";
}
void
-StructuredData::Integer::Dump (Stream &s) const
+StructuredData::Integer::Dump (Stream &s, bool pretty_print) const
{
s.Printf ("%" PRIu64, m_value);
}
void
-StructuredData::Float::Dump (Stream &s) const
+StructuredData::Float::Dump (Stream &s, bool pretty_print) const
{
s.Printf ("%lg", m_value);
}
void
-StructuredData::Boolean::Dump (Stream &s) const
+StructuredData::Boolean::Dump (Stream &s, bool pretty_print) const
{
if (m_value == true)
s.PutCString ("true");
@@ -256,7 +270,7 @@ StructuredData::Boolean::Dump (Stream &s) const
void
-StructuredData::String::Dump (Stream &s) const
+StructuredData::String::Dump (Stream &s, bool pretty_print) const
{
std::string quoted;
const size_t strsize = m_value.size();
@@ -271,35 +285,47 @@ StructuredData::String::Dump (Stream &s) const
}
void
-StructuredData::Dictionary::Dump (Stream &s) const
+StructuredData::Dictionary::Dump (Stream &s, bool pretty_print) const
{
bool first = true;
- s << "{\n";
- s.IndentMore();
+ s << "{";
+ if (pretty_print)
+ {
+ s << "{\n";
+ s.IndentMore();
+ }
for (const auto &pair : m_dict)
{
if (first)
first = false;
else
- s << ",\n";
- s.Indent();
+ {
+ s << ",";
+ if (pretty_print)
+ s << "\n";
+ }
+ if (pretty_print)
+ s.Indent();
s << "\"" << pair.first.AsCString() << "\" : ";
- pair.second->Dump(s);
+ pair.second->Dump(s, pretty_print);
+ }
+ if (pretty_print)
+ {
+ s.IndentLess();
+ s.EOL();
+ s.Indent();
}
- s.IndentLess();
- s.EOL();
- s.Indent();
s << "}";
}
void
-StructuredData::Null::Dump (Stream &s) const
+StructuredData::Null::Dump (Stream &s, bool pretty_print) const
{
s << "null";
}
void
-StructuredData::Generic::Dump(Stream &s) const
+StructuredData::Generic::Dump(Stream &s, bool pretty_print) const
{
s << "0x" << m_object;
}
OpenPOWER on IntegriCloud