12#include "llvm/Support/MemoryBuffer.h"
26 llvm::Expected<json::Value> value = json::parse(json_text);
28 llvm::consumeError(value.takeError());
38 auto buffer_or_error = llvm::MemoryBuffer::getFile(input_spec.
GetPath());
39 if (!buffer_or_error) {
40 error.SetErrorStringWithFormatv(
"could not open input file: {0} - {1}.",
42 buffer_or_error.getError().message());
45 llvm::Expected<json::Value> value =
46 json::parse(buffer_or_error.get()->getBuffer().str());
59 if (json::Object *O = value.getAsObject())
62 if (json::Array *A = value.getAsArray())
65 if (
auto s = value.getAsString())
66 return std::make_shared<StructuredData::String>(*s);
68 if (
auto b = value.getAsBoolean())
69 return std::make_shared<StructuredData::Boolean>(*b);
71 if (
auto i = value.getAsInteger())
72 return std::make_shared<StructuredData::Integer>(*i);
74 if (
auto d = value.getAsNumber())
75 return std::make_shared<StructuredData::Float>(*d);
77 if (
auto n = value.getAsNull())
78 return std::make_shared<StructuredData::Null>();
84 auto dict_up = std::make_unique<StructuredData::Dictionary>();
85 for (
auto &KV : *
object) {
86 StringRef key = KV.first;
87 json::Value value = KV.second;
89 dict_up->AddItem(key, value_sp);
91 return std::move(dict_up);
95 auto array_up = std::make_unique<StructuredData::Array>();
96 for (json::Value &value : *array) {
98 array_up->AddItem(value_sp);
100 return std::move(array_up);
106 std::pair<llvm::StringRef, llvm::StringRef> match = path.split(
'.');
107 std::string key = match.first.str();
112 if (match.second.empty()) {
115 return value->GetObjectForDotSeparatedPath(match.second);
122 std::pair<llvm::StringRef, llvm::StringRef> match = path.split(
'[');
123 if (match.second.empty()) {
124 return this->shared_from_this();
127 uint64_t val = strtoul(match.second.str().c_str(),
nullptr, 10);
134 return this->shared_from_this();
138 json::OStream stream(llvm::outs(), pretty_print ? 2 : 0);
144 for (
const auto &item_sp : m_items) {
145 item_sp->Serialize(s);
151 s.value(
static_cast<int64_t
>(m_value));
168 for (
const auto &pair : m_dict) {
169 s.attributeBegin(pair.first.GetStringRef());
170 pair.second->Serialize(s);
181 s.value(llvm::formatv(
"{0:X}", m_object));
185 s.
Printf(
"%" PRId64,
static_cast<int64_t
>(m_value));
193 s.
Printf(m_value ?
"True" :
"False");
197 s.
Printf(
"%s", m_value.empty() ?
"\"\"" : m_value.c_str());
203 for (
const auto &item_sp : m_items) {
213 s.
Printf(
"[%zu]:", index++);
226 item_sp->GetDescription(s);
227 if (item_sp != *(--m_items.end()))
238 for (
const auto &pair : m_dict) {
240 if (pair.first.IsNull() || pair.first.IsEmpty() || !pair.second)
248 s.
Printf(
"%s:", pair.first.AsCString());
261 pair.second->GetDescription(s);
262 if (pair != *(--m_dict.end()))
static llvm::raw_ostream & error(Stream &strm)
static StructuredData::ObjectSP ParseJSONValue(json::Value &value)
static StructuredData::ObjectSP ParseJSONObject(json::Object *object)
static StructuredData::ObjectSP ParseJSONArray(json::Array *array)
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
A stream class that can stream formatted output to a file.
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
void SetIndentLevel(unsigned level)
Set the current indentation level.
size_t EOL()
Output and End of Line character to the stream.
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
void IndentMore(unsigned amount=2)
Increment the current indentation level.
unsigned GetIndentLevel() const
Get the current indentation level.
void Serialize(llvm::json::OStream &s) const override
ObjectSP GetItemAtIndex(size_t idx) const
void GetDescription(lldb_private::Stream &s) const override
void Serialize(llvm::json::OStream &s) const override
void GetDescription(lldb_private::Stream &s) const override
void Serialize(llvm::json::OStream &s) const override
ObjectSP GetValueForKey(llvm::StringRef key) const
void GetDescription(lldb_private::Stream &s) const override
void Serialize(llvm::json::OStream &s) const override
void GetDescription(lldb_private::Stream &s) const override
void GetDescription(lldb_private::Stream &s) const override
void Serialize(llvm::json::OStream &s) const override
void Serialize(llvm::json::OStream &s) const override
void GetDescription(lldb_private::Stream &s) const override
void GetDescription(lldb_private::Stream &s) const override
void Serialize(llvm::json::OStream &s) const override
Dictionary * GetAsDictionary()
void DumpToStdout(bool pretty_print=true) const
lldb::StructuredDataType GetType() const
ObjectSP GetObjectForDotSeparatedPath(llvm::StringRef path)
void GetDescription(lldb_private::Stream &s) const override
void Serialize(llvm::json::OStream &s) const override
static bool IsRecordType(const ObjectSP object_sp)
std::shared_ptr< Object > ObjectSP
static ObjectSP ParseJSON(const std::string &json_text)
static ObjectSP ParseJSONFromFile(const FileSpec &file, Status &error)
A class that represents a running process on the host machine.
const char * toString(AppleArm64ExceptionClass EC)
@ eStructuredDataTypeDictionary
@ eStructuredDataTypeArray