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
This commit is contained in:
Jason Molenda
2016-07-20 03:49:02 +00:00
parent 074f8d7777
commit d9c9da536f
4 changed files with 64 additions and 38 deletions

View File

@@ -193,10 +193,10 @@ public:
ObjectSP
GetObjectForDotSeparatedPath (llvm::StringRef path);
void DumpToStdout() const;
void DumpToStdout(bool pretty_print = true) const;
virtual void
Dump (Stream &s) const = 0;
Dump (Stream &s, bool pretty_print = true) const = 0;
private:
Type m_type;
@@ -357,7 +357,7 @@ public:
m_items.push_back(item);
}
void Dump(Stream &s) const override;
void Dump(Stream &s, bool pretty_print = true) const override;
protected:
typedef std::vector<ObjectSP> collection;
@@ -387,7 +387,7 @@ public:
return m_value;
}
void Dump(Stream &s) const override;
void Dump(Stream &s, bool pretty_print = true) const override;
protected:
uint64_t m_value;
@@ -416,7 +416,7 @@ public:
return m_value;
}
void Dump(Stream &s) const override;
void Dump(Stream &s, bool pretty_print = true) const override;
protected:
double m_value;
@@ -445,7 +445,7 @@ public:
return m_value;
}
void Dump(Stream &s) const override;
void Dump(Stream &s, bool pretty_print = true) const override;
protected:
bool m_value;
@@ -486,7 +486,7 @@ public:
return m_value;
}
void Dump(Stream &s) const override;
void Dump(Stream &s, bool pretty_print = true) const override;
protected:
std::string m_value;
@@ -697,7 +697,7 @@ public:
AddItem (key, ObjectSP (new Boolean(value)));
}
void Dump(Stream &s) const override;
void Dump(Stream &s, bool pretty_print = true) const override;
protected:
typedef std::map<ConstString, ObjectSP> collection;
@@ -720,7 +720,7 @@ public:
return false;
}
void Dump(Stream &s) const override;
void Dump(Stream &s, bool pretty_print = true) const override;
};
class Generic : public Object
@@ -750,7 +750,7 @@ public:
return m_object != nullptr;
}
void Dump(Stream &s) const override;
void Dump(Stream &s, bool pretty_print = true) const override;
private:
void *m_object;

View File

@@ -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";
}
s.Indent();
item_sp->Dump(s);
if (pretty_print)
s.Indent();
item_sp->Dump(s, pretty_print);
}
if (pretty_print)
{
s.IndentLess();
s.EOL();
s.Indent();
}
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;
}

View File

@@ -32,7 +32,7 @@ using namespace lldb_private;
using namespace lldb;
void
StructuredPythonObject::Dump(Stream &s) const
StructuredPythonObject::Dump(Stream &s, bool pretty_print) const
{
s << "Python Obj: 0x" << GetValue();
}

View File

@@ -60,7 +60,7 @@ public:
return GetValue() && GetValue() != Py_None;
}
void Dump(Stream &s) const override;
void Dump(Stream &s, bool pretty_print = true) const override;
private:
DISALLOW_COPY_AND_ASSIGN(StructuredPythonObject);