12#include "llvm/ADT/StringExtras.h" 
   13#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) {
 
   41        "could not open input file: {0} - {1}.", input_spec.
GetPath(),
 
   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 u = value.getAsUINT64())
 
   72    return std::make_shared<StructuredData::UnsignedInteger>(*u);
 
   74  if (
auto i = value.getAsInteger())
 
   75    return std::make_shared<StructuredData::SignedInteger>(*i);
 
   77  if (
auto d = value.getAsNumber())
 
   78    return std::make_shared<StructuredData::Float>(*d);
 
   80  if (
auto n = value.getAsNull())
 
   81    return std::make_shared<StructuredData::Null>();
 
 
   87  auto dict_up = std::make_unique<StructuredData::Dictionary>();
 
   88  for (
auto &KV : *
object) {
 
   89    StringRef key = KV.first;
 
   90    json::Value value = KV.second;
 
   92      dict_up->AddItem(key, value_sp);
 
   94  return std::move(dict_up);
 
 
   98  auto array_up = std::make_unique<StructuredData::Array>();
 
   99  for (json::Value &value : *array) {
 
  101      array_up->AddItem(value_sp);
 
  103  return std::move(array_up);
 
 
  109    std::pair<llvm::StringRef, llvm::StringRef> match = path.split(
'.');
 
  110    llvm::StringRef key = match.first;
 
  117    if (match.second.empty())
 
  120    return value->GetObjectForDotSeparatedPath(match.second);
 
  124    std::pair<llvm::StringRef, llvm::StringRef> match = path.split(
'[');
 
  125    if (match.second.empty())
 
  126      return shared_from_this();
 
  129    if (!llvm::to_integer(match.second, val,  10))
 
  135  return shared_from_this();
 
 
  139  json::OStream stream(llvm::outs(), pretty_print ? 2 : 0);
 
 
  145  for (
const auto &item_sp : 
m_items) {
 
  146    item_sp->Serialize(s);
 
 
  168  using Entry = std::pair<llvm::StringRef, ObjectSP>;
 
  169  std::vector<Entry> sorted_entries;
 
  170  for (
const auto &pair : 
m_dict)
 
  171    sorted_entries.push_back({pair.first(), pair.second});
 
  173  llvm::sort(sorted_entries);
 
  175  for (
const auto &pair : sorted_entries) {
 
  176    s.attributeBegin(pair.first);
 
  177    pair.second->Serialize(s);
 
 
  188  s.value(llvm::formatv(
"{0:X}", 
m_object));
 
 
  206  for (
const auto &item_sp : 
m_items) {
 
  216    s.
Printf(
"[%zu]:", index++);
 
  229    item_sp->GetDescription(s);
 
  230    if (item_sp != *(--
m_items.end()))
 
 
  244  using Entry = std::pair<llvm::StringRef, ObjectSP>;
 
  245  std::vector<Entry> sorted_entries;
 
  246  for (
const auto &pair : 
m_dict)
 
  247    sorted_entries.push_back({pair.first(), pair.second});
 
  249  llvm::sort(sorted_entries);
 
  251  for (
auto iter = sorted_entries.begin(); iter != sorted_entries.end();
 
  254    if (iter->first.empty() || !iter->second)
 
  262    s.
Format(
"{0}:", iter->first);
 
  275    iter->second->GetDescription(s);
 
  276    if (std::next(iter) != sorted_entries.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.
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
A stream class that can stream formatted output to a file.
void Format(const char *format, Args &&... args)
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
llvm::StringMap< ObjectSP > m_dict
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 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(llvm::StringRef json_text)
static ObjectSP ParseJSONFromFile(const FileSpec &file, Status &error)
A class that represents a running process on the host machine.
StructuredData::ObjectSP Serialize(llvm::ArrayRef< DiagnosticDetail > details)
@ eStructuredDataTypeDictionary
@ eStructuredDataTypeArray