LLVM 22.0.0git
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  Path
 A "cursor" marking a position within a Value. More...
class  Value
 A Value is an JSON value of unknown type. More...

Functions

LLVM_ABI bool isUTF8 (llvm::StringRef S, size_t *ErrOffset=nullptr)
 Returns true if S is valid UTF-8, which is required for use as JSON.
LLVM_ABI std::string fixUTF8 (llvm::StringRef S)
 Replaces invalid UTF-8 sequences in S with the replacement character (U+FFFD).
template<typename T>
Value toJSON (const std::optional< T > &Opt)
LLVM_ABI bool operator== (const Object &LHS, const Object &RHS)
bool operator!= (const Object &LHS, const Object &RHS)
bool operator!= (const Array &L, const Array &R)
LLVM_ABI bool operator== (const Value &L, const Value &R)
bool operator!= (const Value &L, const Value &R)
bool operator== (const Array &L, const Array &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)
LLVM_ABI std::vector< const Object::value_type * > sortedElements (const Object &O)
bool fromJSON (const Value &E, std::string &Out, Path P)
bool fromJSON (const Value &E, int &Out, Path P)
bool fromJSON (const Value &E, int64_t &Out, Path P)
bool fromJSON (const Value &E, double &Out, Path P)
bool fromJSON (const Value &E, bool &Out, Path P)
bool fromJSON (const Value &E, unsigned int &Out, Path P)
bool fromJSON (const Value &E, uint64_t &Out, Path P)
bool fromJSON (const Value &E, std::nullptr_t &Out, Path P)
template<typename T>
bool fromJSON (const Value &E, std::optional< T > &Out, Path P)
template<typename T>
bool fromJSON (const Value &E, std::vector< T > &Out, Path P)
template<typename T>
bool fromJSON (const Value &E, std::map< std::string, T > &Out, Path P)
LLVM_ABI llvm::Expected< Valueparse (llvm::StringRef JSON)
 Parses the provided JSON source, or returns a ParseError.
template<typename T>
Expected< Tparse (const llvm::StringRef &JSON, const char *RootName="")
 Version of parse() that converts the parsed value to the type T.
llvm::raw_ostreamoperator<< (llvm::raw_ostream &OS, const Value &V)
 Serializes this Value to JSON, writing it to the provided stream.
bool fromJSON (const llvm::json::Value &E, Embedding &Out, llvm::json::Path P)
static void abbreviate (const Value &V, OStream &JOS)
static void abbreviateChildren (const Value &V, OStream &JOS)
static void encodeUtf8 (uint32_t Rune, std::string &Out)
static void quote (llvm::raw_ostream &OS, llvm::StringRef S)

Variables

template<typename T>
constexpr bool is_uint_64_bit_v

Function Documentation

◆ abbreviate()

◆ abbreviateChildren()

◆ encodeUtf8()

void llvm::json::encodeUtf8 ( uint32_t Rune,
std::string & Out )
static

Definition at line 573 of file JSON.cpp.

References llvm_unreachable.

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

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

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

◆ fromJSON() [1/12]

bool llvm::json::fromJSON ( const llvm::json::Value & E,
Embedding & Out,
llvm::json::Path P )
inline

Definition at line 74 of file IR2Vec.cpp.

References fromJSON(), and P.

◆ fromJSON() [2/12]

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

Definition at line 776 of file JSON.h.

References E(), and P.

◆ fromJSON() [3/12]

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

Definition at line 768 of file JSON.h.

References E(), and P.

◆ fromJSON() [4/12]

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

Definition at line 752 of file JSON.h.

References E(), and P.

◆ fromJSON() [5/12]

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

Definition at line 760 of file JSON.h.

References E(), and P.

◆ fromJSON() [6/12]

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

Definition at line 834 of file JSON.h.

References E(), fromJSON(), and P.

◆ fromJSON() [7/12]

bool llvm::json::fromJSON ( const Value & E,
std::nullptr_t & Out,
Path P )
inline

Definition at line 800 of file JSON.h.

References E(), and P.

◆ fromJSON() [8/12]

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

Definition at line 809 of file JSON.h.

References E(), fromJSON(), P, and T.

◆ fromJSON() [9/12]

◆ fromJSON() [10/12]

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

Definition at line 821 of file JSON.h.

References A(), E(), fromJSON(), I, and P.

◆ fromJSON() [11/12]

bool llvm::json::fromJSON ( const Value & E,
uint64_t & Out,
Path P )
inline

Definition at line 792 of file JSON.h.

References E(), and P.

◆ fromJSON() [12/12]

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

Definition at line 784 of file JSON.h.

References E(), and P.

◆ 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 686 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(), llvm::json::ObjectKey::ObjectKey(), llvm::json::Value::Value(), and llvm::json::Value::Value().

◆ operator!=() [1/4]

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

Definition at line 212 of file JSON.h.

◆ operator!=() [2/4]

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

Definition at line 160 of file JSON.h.

References LHS, and RHS.

◆ operator!=() [3/4]

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

Definition at line 636 of file JSON.h.

◆ operator!=() [4/4]

bool llvm::json::operator!= ( const Value & L,
const Value & 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 639 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 1110 of file JSON.h.

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

◆ operator==() [1/4]

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

Definition at line 584 of file JSON.h.

◆ operator==() [2/4]

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

Definition at line 87 of file JSON.cpp.

◆ operator==() [3/4]

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

Definition at line 633 of file JSON.h.

◆ operator==() [4/4]

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

Definition at line 178 of file JSON.cpp.

◆ parse() [1/2]

template<typename T>
Expected< T > llvm::json::parse ( const llvm::StringRef & JSON,
const char * RootName = "" )

Version of parse() that converts the parsed value to the type T.

RootName describes the root object and is used in error messages.

Definition at line 935 of file JSON.h.

References fromJSON(), parse(), and T.

◆ parse() [2/2]

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

References E(), and P.

Referenced by llvm::MachO::getInterfaceFileFromJSON(), parse(), llvm::offloading::readPropertiesFromJSON(), and llvm::lsp::JSONTransport::run().

◆ quote()

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

◆ sortedElements()

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

◆ toJSON()

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

Definition at line 848 of file JSON.h.

References llvm::Value.

Variable Documentation

◆ is_uint_64_bit_v

template<typename T>
bool llvm::json::is_uint_64_bit_v
constexpr
Initial value:
=
std::is_integral_v<T> && std::is_unsigned_v<T> &&
sizeof(T) == sizeof(uint64_t)
#define T

Definition at line 79 of file JSON.h.