LLVM  8.0.1
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  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)
 
llvm::raw_ostreamoperator<< (llvm::raw_ostream &, const Value &)
 
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...
 
static std::vector< const Object::value_type * > sortedElements (const Object &O)
 

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 547 of file JSON.cpp.

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

Referenced by 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 566 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 573 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 580 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 587 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 594 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 601 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 612 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 624 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 533 of file JSON.cpp.

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

Referenced by 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 146 of file JSON.h.

◆ operator!=() [2/4]

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

Definition at line 205 of file JSON.h.

◆ operator!=() [3/4]

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

Definition at line 488 of file JSON.h.

References operator<<().

◆ operator!=() [4/4]

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

Definition at line 541 of file JSON.h.

◆ operator<()

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

Definition at line 544 of file JSON.h.

◆ operator<<()

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

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

Definition at line 696 of file JSON.cpp.

Referenced by llvm::json::Value::getAsArray(), and operator!=().

◆ 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 538 of file JSON.h.

◆ parse()

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

◆ sortedElements()

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

Definition at line 522 of file JSON.cpp.

References E, and llvm::sort().

◆ toJSON()

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

Definition at line 636 of file JSON.h.

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