GCC Middle and Back End API Reference
json::object Class Reference

#include <json.h>

Inheritance diagram for json::object:
Collaboration diagram for json::object:

Public Member Functions

 ~object ()
enum kind get_kind () const final override
void print (pretty_printer *pp, bool formatted) const final override
std::unique_ptr< valueclone () const final override
objectdyn_cast_object () final override
bool is_empty () const
void set (const char *key, value *v)
template<typename JsonType>
void set (const char *key, std::unique_ptr< JsonType > v)
valueget (const char *key) const
void set_string (const char *key, const char *utf8_value)
void set_integer (const char *key, long v)
void set_float (const char *key, double v)
void set_bool (const char *key, bool v)
size_t get_num_keys () const
const char * get_key (size_t i) const
std::unique_ptr< objectclone_as_object () const
void dump (FILE *, bool formatted) const
void DEBUG_FUNCTION dump () const
virtual stringdyn_cast_string ()
const pointer::tokenget_pointer_token () const

Static Public Member Functions

static int compare (const json::object &obj_a, const json::object &obj_b)
static int compare (const json::value &val_a, const json::value &val_b)

Data Fields

pointer::token m_pointer_token

Private Types

typedef hash_map< char *, value *, simple_hashmap_traits< nofree_string_hash, value * > > map_t

Private Attributes

map_t m_map
auto_vec< const char * > m_keys

Detailed Description

Subclass of value for objects: a collection of key/value pairs
preserving the ordering in which keys were inserted.

Preserving the order eliminates non-determinism in the output,
making it easier for the user to compare repeated invocations.   

Member Typedef Documentation

◆ map_t

Constructor & Destructor Documentation

◆ ~object()

object::~object ( )
class json::object, a subclass of json::value, representing
an ordered collection of key/value pairs.   
json:object's dtor.   

References free(), and m_map.

Member Function Documentation

◆ clone()

std::unique_ptr< value > object::clone ( ) const
finaloverridevirtual

Implements json::value.

References clone_as_object().

◆ clone_as_object()

std::unique_ptr< object > object::clone_as_object ( ) const

◆ compare() [1/2]

int object::compare ( const json::object & obj_a,
const json::object & obj_b )
static
Subroutine of json::compare for comparing a pairs of objects.   

References json::value::compare(), gcc_assert, get(), m_keys, and m_map.

Referenced by json::value::compare().

◆ compare() [2/2]

int value::compare ( const json::value & val_a,
const json::value & val_b )
staticinherited
A deterministic total ordering for comparing json values, so that we
can e.g. put them in std::map.

This is intended to follow the condition for equality described in
the JSON Schema standard (§4.3, “Instance equality”), as referenced
by SARIF v2.1.0 (§3.7.3 "Array properties with unique values"), but has
the following limitations:
- numbers are supposed to be checked for "the same mathematical value",
but in this implementation int vs float numbers won't compare as equal,
and float number comparison is bitwise
- strings are supposed to be "the same codepoint-for-codepoint", but
this implementation doesn't take into account canonicalization issues.   

References json::object::compare(), compare(), gcc_unreachable, json::float_number::get(), json::integer_number::get(), get_kind(), json::string::get_string(), json::JSON_ARRAY, json::JSON_FALSE, json::JSON_FLOAT, json::JSON_INTEGER, json::JSON_NULL, json::JSON_OBJECT, json::JSON_STRING, json::JSON_TRUE, and json::array::size().

Referenced by json::object::compare(), compare(), and sarif_array_of_unique< JsonElementType >::comparator_t::operator()().

◆ dump() [1/2]

void value::dump ( ) const
inherited
A convenience function for debugging.
Dump to stderr with formatting, and a trailing newline.  

References dump().

◆ dump() [2/2]

void value::dump ( FILE * outf,
bool formatted ) const
inherited
class json::value.   
Dump this json::value tree to OUTF.

The key/value pairs of json::objects are printed in the order
in which the keys were originally inserted.   

References output_buffer::m_stream, pp_buffer(), pp_flush(), and print().

Referenced by dump(), generate_results(), and sarif_serialization_format_json::write_to_file().

◆ dyn_cast_object()

object * json::object::dyn_cast_object ( )
inlinefinaloverridevirtual

Reimplemented from json::value.

References dyn_cast_object(), and final().

Referenced by dyn_cast_object().

◆ dyn_cast_string()

virtual string * json::value::dyn_cast_string ( )
inlinevirtualinherited

Reimplemented in json::string.

◆ get()

◆ get_key()

const char * json::object::get_key ( size_t i) const
inline

References i, and m_keys.

Referenced by copy_any_property_bag().

◆ get_kind()

enum kind json::object::get_kind ( ) const
inlinefinaloverridevirtual

Implements json::value.

References final(), and json::JSON_OBJECT.

◆ get_num_keys()

size_t json::object::get_num_keys ( ) const
inline

References m_keys.

Referenced by copy_any_property_bag().

◆ get_pointer_token()

const pointer::token & json::value::get_pointer_token ( ) const
inlineinherited

References m_pointer_token.

◆ is_empty()

bool json::object::is_empty ( ) const
inline

References m_map.

◆ print()

void object::print ( pretty_printer * pp,
bool formatted ) const
finaloverridevirtual

◆ set() [1/2]

template<typename JsonType>
void json::object::set ( const char * key,
std::unique_ptr< JsonType > v )
inline

References set().

◆ set() [2/2]

void object::set ( const char * key,
value * v )
Set the json::value * for KEY, taking ownership of V
(and taking a copy of KEY if necessary).   

References gcc_assert, m_keys, m_map, and json::value::m_pointer_token.

Referenced by optrecord_json_writer::add_pass_list(), optrecord_json_writer::add_record(), sarif_location_manager::add_related_location(), compiler_data_hooks::add_sarif_invocation_properties(), copy_any_property_bag(), generate_results(), sarif_builder::get_or_create_artifact(), sarif_object::get_or_create_properties(), optrecord_json_writer::inlining_chain_to_json(), json_set_prime_path_coverage(), sarif_location_relationship::lazily_add_kind(), sarif_location::lazily_add_relationships_array(), sarif_builder::make_fix_object(), sarif_builder::make_replacement_object(), sarif_builder::make_result_object(), sarif_builder::make_run_object(), sarif_builder::make_tool_object(), sarif_builder::make_top_level_object(), infinite_loop_diagnostic::maybe_add_sarif_properties(), sarif_builder::maybe_make_cwe_taxonomy_object(), sarif_builder::maybe_make_physical_location_object(), optrecord_json_writer::optinfo_to_json(), optrecord_json_writer::optrecord_json_writer(), output_intermediate_json_line(), output_json_intermediate_file(), optrecord_json_writer::pass_to_json(), sarif_artifact::populate_contents(), sarif_artifact::populate_roles(), sarif_builder::populate_thread_flow_location_object(), sarif_invocation::prepare_to_flush(), sarif_code_flow::sarif_code_flow(), sarif_ice_notification::sarif_ice_notification(), sarif_invocation::sarif_invocation(), sarif_thread_flow::sarif_thread_flow(), set(), sarif_builder::set_any_logical_locs_arr(), set_bool(), set_float(), sarif_property_bag::set_graph(), set_integer(), sarif_property_bag::set_logical_location(), and set_string().

◆ set_bool()

void object::set_bool ( const char * key,
bool v )
Set value of KEY within this object to the JSON
literal true or false, based on V.   

References set().

Referenced by sarif_builder::make_location_object(), output_intermediate_json_line(), and sarif_invocation::prepare_to_flush().

◆ set_float()

void object::set_float ( const char * key,
double v )
Set value of KEY within this object to a JSON
floating point value based on V.   

References set().

◆ set_integer()

◆ set_string()

Field Documentation

◆ m_keys

auto_vec<const char *> json::object::m_keys
private

◆ m_map

map_t json::object::m_map
private

◆ m_pointer_token

pointer::token json::value::m_pointer_token
inherited

The documentation for this class was generated from the following files: