Author: jmolenda Date: Tue Jul 19 22:49:02 2016 New Revision: 276079 URL: http://llvm.org/viewvc/llvm-project?rev=276079&view=rev Log: 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.
Modified: lldb/trunk/include/lldb/Core/StructuredData.h lldb/trunk/source/Core/StructuredData.cpp lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h Modified: lldb/trunk/include/lldb/Core/StructuredData.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/StructuredData.h?rev=276079&r1=276078&r2=276079&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/StructuredData.h (original) +++ lldb/trunk/include/lldb/Core/StructuredData.h Tue Jul 19 22:49:02 2016 @@ -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; Modified: lldb/trunk/source/Core/StructuredData.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/StructuredData.cpp?rev=276079&r1=276078&r2=276079&view=diff ============================================================================== --- lldb/trunk/source/Core/StructuredData.cpp (original) +++ lldb/trunk/source/Core/StructuredData.cpp Tue Jul 19 22:49:02 2016 @@ -203,50 +203,64 @@ StructuredData::Object::GetObjectForDotS } 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 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) } 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; } Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp?rev=276079&r1=276078&r2=276079&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp (original) +++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp Tue Jul 19 22:49:02 2016 @@ -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(); } Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h?rev=276079&r1=276078&r2=276079&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h (original) +++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h Tue Jul 19 22:49:02 2016 @@ -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); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits