LLVM  10.0.0svn
Classes | Functions
llvm::json Namespace Reference

Classes

class  Array
 An Array is a JSON array, which contains heterogeneous JSON values. More...
 
class  Object
 An Object is a JSON object, which maps strings to heterogenous JSON values. More...
 
class  ObjectKey
 ObjectKey is a used to capture keys in Object. More...
 
class  ObjectMapper
 Helper for mapping JSON objects onto protocol structs. More...
 
class  OStream
 json::OStream allows writing well-formed JSON without materializing all structures as json::Value ahead of time. More...
 
class  ParseError
 
class  Value
 A Value is an JSON value of unknown type. More...
 

Functions

bool isUTF8 (llvm::StringRef S, size_t *ErrOffset=nullptr)
 Returns true if S is valid UTF-8, which is required for use as JSON. More...
 
std::string fixUTF8 (llvm::StringRef S)
 Replaces invalid UTF-8 sequences in S with the replacement character (U+FFFD). More...
 
template<typename T >
Value toJSON (const llvm::Optional< T > &Opt)
 
bool operator== (const Object &LHS, const Object &RHS)
 
bool operator!= (const Object &LHS, const Object &RHS)
 
bool operator!= (const Array &L, const Array &R)
 
bool operator== (const Value &, const Value &)
 
bool operator!= (const Value &L, const Value &R)
 
bool operator== (const ObjectKey &L, const ObjectKey &R)
 
bool operator!= (const ObjectKey &L, const ObjectKey &R)
 
bool operator< (const ObjectKey &L, const ObjectKey &R)
 
bool fromJSON (const Value &E, std::string &Out)
 
bool fromJSON (const Value &E, int &Out)
 
bool fromJSON (const Value &E, int64_t &Out)
 
bool fromJSON (const Value &E, double &Out)
 
bool fromJSON (const Value &E, bool &Out)
 
template<typename T >
bool fromJSON (const Value &E, llvm::Optional< T > &Out)
 
template<typename T >
bool fromJSON (const Value &E, std::vector< T > &Out)
 
template<typename T >
bool fromJSON (const Value &E, std::map< std::string, T > &Out)
 
llvm::Expected< Valueparse (llvm::StringRef JSON)
 Parses the provided JSON source, or returns a ParseError. More...
 
llvm::raw_ostreamoperator<< (llvm::raw_ostream &OS, const Value &V)
 Serializes this Value to JSON, writing it to the provided stream. More...
 
static std::vector< const Object::value_type * > sortedElements (const Object &O)
 
static void quote (llvm::raw_ostream &OS, llvm::StringRef S)
 

Function Documentation

◆ fixUTF8()

std::string llvm::json::fixUTF8 ( llvm::StringRef  S)

Replaces invalid UTF-8 sequences in S with the replacement character (U+FFFD).

The returned string is valid UTF-8. This is much slower than isUTF8, so test that first.

Definition at line 546 of file JSON.cpp.

References llvm::ConvertUTF32toUTF8(), llvm::ConvertUTF8toUTF32(), llvm::StringRef::data(), llvm::lenientConversion, llvm::StringRef::size(), and llvm::strictConversion.

Referenced by llvm::json::OStream::attributeBegin(), llvm::json::ObjectKey::ObjectKey(), and llvm::json::Value::Value().

◆ fromJSON() [1/8]

bool llvm::json::fromJSON ( const Value E,
std::string &  Out 
)
inline

Definition at line 561 of file JSON.h.

References llvm::json::Value::getAsString().

Referenced by fromJSON(), and llvm::json::ObjectMapper::map().

◆ fromJSON() [2/8]

bool llvm::json::fromJSON ( const Value E,
int &  Out 
)
inline

Definition at line 568 of file JSON.h.

References llvm::json::Value::getAsInteger().

◆ fromJSON() [3/8]

bool llvm::json::fromJSON ( const Value E,
int64_t &  Out 
)
inline

Definition at line 575 of file JSON.h.

References llvm::json::Value::getAsInteger().

◆ fromJSON() [4/8]

bool llvm::json::fromJSON ( const Value E,
double &  Out 
)
inline

Definition at line 582 of file JSON.h.

References llvm::json::Value::getAsNumber().

◆ fromJSON() [5/8]

bool llvm::json::fromJSON ( const Value E,
bool Out 
)
inline

Definition at line 589 of file JSON.h.

References llvm::json::Value::getAsBoolean().

◆ fromJSON() [6/8]

template<typename T >
bool llvm::json::fromJSON ( const Value E,
llvm::Optional< T > &  Out 
)

Definition at line 596 of file JSON.h.

References fromJSON(), llvm::json::Value::getAsNull(), and llvm::None.

◆ fromJSON() [7/8]

template<typename T >
bool llvm::json::fromJSON ( const Value E,
std::vector< T > &  Out 
)

Definition at line 607 of file JSON.h.

References fromJSON(), llvm::json::Value::getAsArray(), and I.

◆ fromJSON() [8/8]

template<typename T >
bool llvm::json::fromJSON ( const Value E,
std::map< std::string, T > &  Out 
)

Definition at line 619 of file JSON.h.

References fromJSON(), llvm::json::Value::getAsObject(), and llvm::RISCVFenceField::O.

◆ isUTF8()

bool llvm::json::isUTF8 ( llvm::StringRef  S,
size_t ErrOffset = nullptr 
)

Returns true if S is valid UTF-8, which is required for use as JSON.

If it returns false, Offset is set to a byte offset near the first error.

Definition at line 532 of file JSON.cpp.

References llvm::Data, llvm::StringRef::data(), llvm::isASCII(), llvm::isLegalUTF8String(), LLVM_LIKELY, and llvm::StringRef::size().

Referenced by llvm::json::OStream::attributeBegin(), llvm::json::ObjectKey::ObjectKey(), and llvm::json::Value::Value().

◆ operator!=() [1/4]

bool llvm::json::operator!= ( const Object LHS,
const Object RHS 
)
inline

Definition at line 148 of file JSON.h.

◆ operator!=() [2/4]

bool llvm::json::operator!= ( const Array L,
const Array R 
)
inline

Definition at line 208 of file JSON.h.

◆ operator!=() [3/4]

bool llvm::json::operator!= ( const Value L,
const Value R 
)
inline

Definition at line 484 of file JSON.h.

References llvm::RISCVFenceField::R.

◆ operator!=() [4/4]

bool llvm::json::operator!= ( const ObjectKey L,
const ObjectKey R 
)
inline

Definition at line 536 of file JSON.h.

◆ operator<()

bool llvm::json::operator< ( const ObjectKey L,
const ObjectKey R 
)
inline

Definition at line 539 of file JSON.h.

◆ operator<<()

llvm::raw_ostream& llvm::json::operator<< ( llvm::raw_ostream OS,
const Value V 
)
inline

Serializes this Value to JSON, writing it to the provided stream.

The formatting is compact (no extra whitespace) and deterministic. For pretty-printing, use the formatv() format_provider below.

Definition at line 841 of file JSON.h.

References llvm::json::OStream::value().

◆ operator==() [1/3]

bool llvm::json::operator== ( const Object LHS,
const Object RHS 
)

◆ operator==() [2/3]

bool llvm::json::operator== ( const Value L,
const Value R 
)

◆ operator==() [3/3]

bool llvm::json::operator== ( const ObjectKey L,
const ObjectKey R 
)
inline

Definition at line 533 of file JSON.h.

◆ parse()

Expected< Value > llvm::json::parse ( llvm::StringRef  JSON)

Parses the provided JSON source, or returns a ParseError.

The returned Value is self-contained and owns its strings (they do not refer to the original source).

Definition at line 510 of file JSON.cpp.

Referenced by llvm::json::ObjectMapper::map().

◆ quote()

static void llvm::json::quote ( llvm::raw_ostream OS,
llvm::StringRef  S 
)
static

Definition at line 563 of file JSON.cpp.

References C, llvm::Lower, and llvm::write_hex().

Referenced by llvm::json::OStream::attributeBegin(), and llvm::json::OStream::value().

◆ sortedElements()

static std::vector<const Object::value_type *> llvm::json::sortedElements ( const Object O)
static

Definition at line 521 of file JSON.cpp.

References E, and llvm::sort().

Referenced by llvm::json::OStream::value().

◆ toJSON()

template<typename T >
Value llvm::json::toJSON ( const llvm::Optional< T > &  Opt)

Definition at line 631 of file JSON.h.

Referenced by llvm::json::Value::Value().