Data Structures | |
struct | worklist_item |
Public Member Functions | |
sarif_location_manager () | |
unsigned | allocate_location_id () |
virtual void | add_related_location (std::unique_ptr< sarif_location > location_obj, sarif_builder &builder) |
void | add_relationship_to_worklist (sarif_location &location_obj, enum worklist_item::kind kind, location_t where) |
void | process_worklist (sarif_builder &builder) |
void | process_worklist_item (sarif_builder &builder, const worklist_item &item) |
sarif_property_bag & | get_or_create_properties () |
enum kind | get_kind () const final override |
void | print (pretty_printer *pp, bool formatted) const 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) |
value * | get (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) |
void | dump (FILE *, bool formatted) const |
void DEBUG_FUNCTION | dump () const |
Private Types | |
typedef hash_map< char *, value *, simple_hashmap_traits< nofree_string_hash, value * > > | map_t |
Private Attributes | |
json::array * | m_related_locations_arr |
unsigned | m_next_location_id |
std::list< worklist_item > | m_worklist |
std::map< location_t, sarif_location * > | m_included_from_locations |
std::map< location_t, sarif_location * > | m_unlabelled_secondary_locations |
map_t | m_map |
auto_vec< const char * > | m_keys |
A class for sarif_objects that own a "namespace" of numeric IDs for managing location objects within them. Currently (SARIF v2.1.0) this is just for sarif_result (section 3.28.2), but it will likely eventually also be for notification objects; see https://github.com/oasis-tcs/sarif-spec/issues/540 Consider locations with chains of include information e.g. > include-chain-1.c: > #include "include-chain-1.h" include-chain-1.h: | // First set of decls, which will be referenced in notes | #include "include-chain-1-1.h" | | // Second set of decls, which will trigger the errors | #include "include-chain-1-2.h" include-chain-1-1.h: | int p; | int q; include-chain-1-1.h: | char p; | char q; GCC's textual output emits: | In file included from PATH/include-chain-1.h:5, | from PATH/include-chain-1.c:30: | PATH/include-chain-1-2.h:1:6: error: conflicting types for 'p'; have 'char' | 1 | char p; | | ^ | In file included from PATH/include-chain-1.h:2: | PATH/include-chain-1-1.h:1:5: note: previous declaration of 'p' with type 'int' | 1 | int p; | | ^ | PATH/include-chain-1-2.h:2:6: error: conflicting types for 'q'; have 'char' | 2 | char q; | | ^ | PATH/include-chain-1-1.h:2:5: note: previous declaration of 'q' with type 'int' | 2 | int q; | | ^ Whenever a SARIF location is added for a location_t that was #included from somewhere, we queue up the creation of a SARIF location for the location of the #include. The worklist of queued locations is flushed when the result is finished, which lazily creates any additional related locations for the include chain, and the relationships between the locations. Doing so can lead to further include locations being processed. The worklist approach allows us to lazily explore the relevant part of the directed graph of location_t values implicit in our line_maps structure, replicating it as a directed graph of SARIF locations within the SARIF result object, like this: [0]: error in include-chain-1-2.h ("conflicting types for 'p'; have 'char'") [1]: #include "include-chain-1-2.h" in include-chain-1.h [2]: note in include-chain-1-2.h ("previous declaration of 'p' with type 'int'") [3]: #include "include-chain-1-1.h" in include-chain-1.h [4]: #include "include-chain-1.h" in include-chain-1.c where we want to capture this "includes" graph in SARIF form: . +-----------------------------------+ +----------------------------------+ . |"id": 0 | |"id": 2 | . | error: "conflicting types for 'p';| | note: previous declaration of 'p'| . | have 'char'"| | | with type 'int'") | . | in include-chain-1-2.h | | in include-chain-1-1.h | . +-----------------------------------+ +----------------------------------+ . ^ | ^ | . includes | | included-by includes | | included-by . | V | V . +--------------------------------+ +--------------------------------+ . |"id": 1 | |"id": 3 | . | #include "include-chain-1-2.h" | | #include "include-chain-1-1.h" | . | in include-chain-1.h | | in include-chain-1.h | . +--------------------------------+ +--------------------------------+ . ^ | ^ | . includes | | included-by includes | | included-by . | V | V . +------------------------------------+ . |"id": 4 | . | The #include "include-chain-1.h" | . | in include-chain-1.c | . +------------------------------------+
|
privateinherited |
|
inline |
References m_next_location_id, and m_related_locations_arr.
|
virtual |
class sarif_location_manager : public sarif_object.
Base implementation of sarif_location_manager::add_related_location vfunc. Add LOCATION_OBJ to this object's "relatedLocations" array, creating it if it doesn't yet exist.
Reimplemented in sarif_ice_notification.
References m_related_locations_arr, and json::object::set().
Referenced by sarif_ice_notification::add_related_location(), sarif_result::on_diagram(), sarif_result::on_nested_diagnostic(), and process_worklist_item().
void sarif_location_manager::add_relationship_to_worklist | ( | sarif_location & | location_obj, |
enum worklist_item::kind | kind, | ||
location_t | where ) |
References m_worklist.
Referenced by sarif_builder::add_any_include_chain(), and sarif_builder::make_location_object().
|
inline |
References m_next_location_id.
Referenced by sarif_location::lazily_add_id().
|
inherited |
|
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 generate_results().
|
inherited |
Get the json::value * for KEY. The object retains ownership of the value.
References gcc_assert, get(), m_map, and NULL.
Referenced by get(), sarif_location::get_id(), sarif_code_flow::get_or_append_thread_flow(), sarif_object::get_or_create_properties(), sarif_location_relationship::get_target_id(), sarif_location_relationship::lazily_add_kind(), sarif_location::lazily_add_relationship_object(), sarif_location::lazily_add_relationships_array(), sarif_builder::make_location_object(), sarif_builder::make_location_object(), sarif_builder::make_location_object(), and sarif_location_manager::process_worklist_item().
|
inlinefinaloverridevirtualinherited |
Implements json::value.
References final(), and json::JSON_OBJECT.
|
inherited |
class sarif_object : public json::object.
References json::object::get(), json::value::get_kind(), json::JSON_OBJECT, and json::object::set().
Referenced by sarif_ice_notification::sarif_ice_notification().
|
finaloverridevirtualinherited |
Implementation of json::value::print for json::object.
Implements json::value.
References FOR_EACH_VEC_ELT, hash_map< KeyId, Value, Traits >::get(), i, m_keys, m_map, pp_character(), pp_indent(), pp_indentation(), pp_newline(), pp_space, pp_string(), json::value::print(), and print_escaped_json_string().
Referenced by generate_results().
void sarif_location_manager::process_worklist | ( | sarif_builder & | builder | ) |
Process all items in this result's worklist. Doing so may temporarily add new items to the end of the worklist. Handling any item should be "lazy", and thus we should eventually drain the queue and terminate.
References m_worklist, and process_worklist_item().
void sarif_location_manager::process_worklist_item | ( | sarif_builder & | builder, |
const worklist_item & | item ) |
Process one item in this result's worklist, potentially adding new items to the end of the worklist.
References add_related_location(), gcc_assert, gcc_unreachable, json::object::get(), sarif_location_manager::worklist_item::included_from, includes, is_included_by, sarif_location::lazily_add_relationship(), m_included_from_locations, sarif_location_manager::worklist_item::m_kind, sarif_location_manager::worklist_item::m_location_obj, m_unlabelled_secondary_locations, sarif_location_manager::worklist_item::m_where, sarif_builder::make_location_object(), relevant, scanned_file, and sarif_location_manager::worklist_item::unlabelled_secondary_location.
Referenced by process_worklist().
|
inlineinherited |
References set().
|
inherited |
Set the json::value * for KEY, taking ownership of V (and taking a copy of KEY if necessary).
References gcc_assert, m_keys, and m_map.
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(), 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(), json_output_format::on_report_diagnostic(), 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(), set_integer(), and set_string().
|
inherited |
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(), json_output_format::on_report_diagnostic(), output_intermediate_json_line(), and sarif_invocation::prepare_to_flush().
|
inherited |
Set value of KEY within this object to a JSON floating point value based on V.
References set().
|
inherited |
Set value of KEY within this object to a JSON integer value based on V.
References set().
Referenced by optrecord_json_writer::impl_location_to_json(), json_set_prime_path_coverage(), sarif_location::lazily_add_id(), optrecord_json_writer::location_to_json(), infinite_recursion_diagnostic::maybe_add_sarif_properties(), sarif_result::on_nested_diagnostic(), json_output_format::on_report_diagnostic(), output_intermediate_json_line(), optrecord_json_writer::pass_to_json(), sarif_builder::populate_thread_flow_location_object(), optrecord_json_writer::profile_count_to_json(), and sarif_location_relationship::sarif_location_relationship().
|
inherited |
Set value of KEY within this object to a JSON string value based on UTF8_VALUE.
References set().
Referenced by generate_results(), sarif_builder::get_or_create_artifact(), optrecord_json_writer::impl_location_to_json(), optrecord_json_writer::inlining_chain_to_json(), json_set_prime_path_coverage(), optrecord_json_writer::location_to_json(), json_output_format::on_report_diagnostic(), 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(), optrecord_json_writer::profile_count_to_json(), sarif_ice_notification::sarif_ice_notification(), sarif_thread_flow::sarif_thread_flow(), and set_string_property_escaping_braces().
|
private |
Referenced by process_worklist_item().
|
privateinherited |
Referenced by get(), is_empty(), print(), set(), and ~object().
|
private |
Referenced by allocate_location_id(), and sarif_location_manager().
|
private |
Referenced by add_related_location(), and sarif_location_manager().
|
private |
Referenced by process_worklist_item().
|
private |
Referenced by add_relationship_to_worklist(), and process_worklist().