GCC Middle and Back End API Reference
sarif_builder Class Reference
Collaboration diagram for sarif_builder:

Data Structures

class  sarif_token_printer
 

Public Member Functions

 sarif_builder (diagnostic_context &context, pretty_printer &printer, const line_maps *line_maps, const char *main_input_filename_, std::unique_ptr< sarif_serialization_format > serialization_format, const sarif_generation_options &sarif_gen_opts)
 
 ~sarif_builder ()
 
void set_printer (pretty_printer &printer)
 
const logical_location_managerget_logical_location_manager () const
 
void on_report_diagnostic (const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind, diagnostic_sarif_format_buffer *buffer)
 
void emit_diagram (const diagnostic_diagram &diagram)
 
void end_group ()
 
std::unique_ptr< sarif_resulttake_current_result ()
 
std::unique_ptr< sarif_logflush_to_object ()
 
void flush_to_file (FILE *outf)
 
std::unique_ptr< json::arraymake_locations_arr (sarif_location_manager &loc_mgr, const diagnostic_info &diagnostic, enum diagnostic_artifact_role role)
 
std::unique_ptr< sarif_locationmake_location_object (sarif_location_manager &loc_mgr, const rich_location &rich_loc, logical_location logical_loc, enum diagnostic_artifact_role role)
 
std::unique_ptr< sarif_locationmake_location_object (sarif_location_manager &loc_mgr, location_t where, enum diagnostic_artifact_role role)
 
std::unique_ptr< sarif_messagemake_message_object (const char *msg) const
 
std::unique_ptr< sarif_messagemake_message_object_for_diagram (const diagnostic_diagram &diagram)
 
std::unique_ptr< sarif_artifact_contentmaybe_make_artifact_content_object (const char *filename) const
 
std::unique_ptr< sarif_artifact_locationmake_artifact_location_object (const char *filename)
 
const sarif_code_flowget_code_flow_for_event_ids () const
 
diagnostic_contextget_context () const
 
pretty_printerget_printer () const
 
token_printerget_token_printer ()
 
enum sarif_version get_version () const
 
size_t num_results () const
 
sarif_resultget_result (size_t idx)
 
const sarif_generation_optionsget_opts () const
 
std::unique_ptr< sarif_logical_locationmake_minimal_sarif_logical_location (logical_location)
 

Private Member Functions

std::unique_ptr< sarif_resultmake_result_object (const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind, unsigned idx_within_parent)
 
void add_any_include_chain (sarif_location_manager &loc_mgr, sarif_location &location_obj, location_t where)
 
void set_any_logical_locs_arr (sarif_location &location_obj, logical_location logical_loc)
 
std::unique_ptr< sarif_locationmake_location_object (sarif_location_manager &loc_mgr, const diagnostic_event &event, enum diagnostic_artifact_role role)
 
std::unique_ptr< sarif_code_flowmake_code_flow_object (sarif_result &result, unsigned idx_within_parent, const diagnostic_path &path)
 
void populate_thread_flow_location_object (sarif_result &result, sarif_thread_flow_location &thread_flow_loc_obj, const diagnostic_event &event, int event_execution_idx)
 
std::unique_ptr< json::arraymaybe_make_kinds_array (diagnostic_event::meaning m) const
 
std::unique_ptr< sarif_physical_locationmaybe_make_physical_location_object (location_t loc, enum diagnostic_artifact_role role, int column_override, const content_renderer *snippet_renderer)
 
std::unique_ptr< sarif_artifact_locationmake_artifact_location_object (location_t loc)
 
std::unique_ptr< sarif_artifact_locationmake_artifact_location_object_for_pwd () const
 
std::unique_ptr< sarif_regionmaybe_make_region_object (location_t loc, int column_override) const
 
std::unique_ptr< sarif_regionmaybe_make_region_object_for_context (location_t loc, const content_renderer *snippet_renderer) const
 
std::unique_ptr< sarif_regionmake_region_object_for_hint (const fixit_hint &hint) const
 
int ensure_sarif_logical_location_for (logical_location k)
 
std::unique_ptr< sarif_multiformat_message_stringmake_multiformat_message_string (const char *msg) const
 
std::unique_ptr< sarif_logmake_top_level_object (std::unique_ptr< sarif_invocation > invocation_obj, std::unique_ptr< json::array > results)
 
std::unique_ptr< sarif_runmake_run_object (std::unique_ptr< sarif_invocation > invocation_obj, std::unique_ptr< json::array > results)
 
std::unique_ptr< sarif_toolmake_tool_object ()
 
std::unique_ptr< sarif_tool_componentmake_driver_tool_component_object ()
 
std::unique_ptr< json::arraymaybe_make_taxonomies_array () const
 
std::unique_ptr< sarif_tool_componentmaybe_make_cwe_taxonomy_object () const
 
std::unique_ptr< sarif_tool_component_referencemake_tool_component_reference_object_for_cwe () const
 
std::unique_ptr< sarif_reporting_descriptormake_reporting_descriptor_object_for_warning (const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind, const char *option_text)
 
std::unique_ptr< sarif_reporting_descriptormake_reporting_descriptor_object_for_cwe_id (int cwe_id) const
 
std::unique_ptr< sarif_reporting_descriptor_referencemake_reporting_descriptor_reference_object_for_cwe_id (int cwe_id)
 
sarif_artifactget_or_create_artifact (const char *filename, enum diagnostic_artifact_role role, bool embed_contents)
 
char * get_source_lines (const char *filename, int start_line, int end_line) const
 
std::unique_ptr< sarif_artifact_contentmaybe_make_artifact_content_object (const char *filename, int start_line, int end_line, const content_renderer *r) const
 
std::unique_ptr< sarif_fixmake_fix_object (const rich_location &rich_loc)
 
std::unique_ptr< sarif_artifact_changemake_artifact_change_object (const rich_location &richloc)
 
std::unique_ptr< sarif_replacementmake_replacement_object (const fixit_hint &hint) const
 
std::unique_ptr< sarif_artifact_contentmake_artifact_content_object (const char *text) const
 
int get_sarif_column (expanded_location exploc) const
 
std::unique_ptr< json::objectmake_stack_from_backtrace ()
 

Private Attributes

diagnostic_contextm_context
 
pretty_printerm_printer
 
const line_maps * m_line_maps
 
sarif_token_printer m_token_printer
 
const logical_location_managerm_logical_loc_mgr
 
std::unique_ptr< sarif_invocationm_invocation_obj
 
std::unique_ptr< json::arraym_results_array
 
std::unique_ptr< sarif_resultm_cur_group_result
 
ordered_hash_map< nofree_string_hash, sarif_artifact * > m_filename_to_artifact_map
 
bool m_seen_any_relative_paths
 
hash_set< free_string_hashm_rule_id_set
 
std::unique_ptr< json::arraym_rules_arr
 
hash_set< int_hash< int, 0, 1 > > m_cwe_id_set
 
std::unique_ptr< sarif_array_of_unique< sarif_logical_location > > m_cached_logical_locs
 
int m_tabstop
 
std::unique_ptr< sarif_serialization_formatm_serialization_format
 
const sarif_generation_options m_sarif_gen_opts
 
unsigned m_next_result_idx
 
sarif_code_flowm_current_code_flow
 

Friends

class diagnostic_sarif_format_buffer
 

Detailed Description

A class for managing SARIF output (for -fdiagnostics-format=sarif-stderr and -fdiagnostics-format=sarif-file). As diagnostics occur, we build "result" JSON objects, and accumulate state: - which source files are referenced - which warnings are emitted - which CWEs are used At the end of the compile, we use the above to build the full SARIF object tree, adding the result objects to the correct place, and creating objects for the various source files, warnings and CWEs referenced. Implemented: - fix-it hints - CWE metadata - diagnostic groups (see limitations below) - logical locations (e.g. cfun) - labelled ranges (as annotations) - secondary ranges without labels (as related locations) Known limitations: - GCC supports nesting of diagnostics (one-deep nesting via auto_diagnostic_group, and arbitrary nesting via auto_diagnostic_nesting_level). These are captured in the SARIF as related locations, and so we only capture location and message information from such nested diagnostics (e.g. we ignore fix-it hints on them). Diagnostics within an auto_diagnostic_nesting_level have their nesting level captured as a property. - although we capture command-line arguments (section 3.20.2), we don't yet capture response files. - doesn't capture "artifact.encoding" property (SARIF v2.1.0 section 3.24.9). - doesn't capture hashes of the source files ("artifact.hashes" property (SARIF v2.1.0 section 3.24.11). - doesn't capture the "analysisTarget" property (SARIF v2.1.0 section 3.27.13). - doesn't capture -Werror cleanly - doesn't capture inlining information (can SARIF handle this?) - doesn't capture macro expansion information (can SARIF handle this?). - doesn't capture any diagnostic_metadata::rules associated with a diagnostic.

Constructor & Destructor Documentation

◆ sarif_builder()

◆ ~sarif_builder()

sarif_builder::~sarif_builder ( )

Member Function Documentation

◆ add_any_include_chain()

void sarif_builder::add_any_include_chain ( sarif_location_manager & loc_mgr,
sarif_location & location_obj,
location_t where )
private
If WHERE was #included from somewhere, add a worklist item to LOC_MGR to lazily add a location for the #include location, and relationships between it and the LOCATION_OBJ. Compare with diagnostic_context::report_current_module, but rather than iterating the current chain, we add the next edge and iterate in the worklist, so that edges are only added once.

References sarif_location_manager::add_relationship_to_worklist(), BUILTINS_LOCATION, m_line_maps, and map.

Referenced by make_location_object(), make_location_object(), and make_location_object().

◆ emit_diagram()

void sarif_builder::emit_diagram ( const diagnostic_diagram & diagram)
Implementation of diagnostic_context::m_diagrams.m_emission_cb for SARIF output.

References gcc_assert, and m_cur_group_result.

◆ end_group()

void sarif_builder::end_group ( )
Implementation of "end_group_cb" for SARIF output.

References m_cur_group_result, and m_results_array.

◆ ensure_sarif_logical_location_for()

int sarif_builder::ensure_sarif_logical_location_for ( logical_location k)
private
Ensure that m_cached_logical_locs has a "logicalLocation" object (SARIF v2.1.0 section 3.33) for K, and return its index within the array.

References ensure_sarif_logical_location_for(), gcc_assert, m_cached_logical_locs, m_logical_loc_mgr, and maybe_get_sarif_kind().

Referenced by ensure_sarif_logical_location_for(), and make_minimal_sarif_logical_location().

◆ flush_to_file()

void sarif_builder::flush_to_file ( FILE * outf)
Create a top-level object, and add it to all the results (and other entities) we've seen so far. Flush it all to OUTF.

References flush_to_object(), and m_serialization_format.

◆ flush_to_object()

std::unique_ptr< sarif_log > sarif_builder::flush_to_object ( )
Create a top-level object, and add it to all the results (and other entities) we've seen so far, moving ownership to the object.

References m_invocation_obj, m_results_array, and make_top_level_object().

Referenced by flush_to_file().

◆ get_code_flow_for_event_ids()

const sarif_code_flow * sarif_builder::get_code_flow_for_event_ids ( ) const
inline

References m_current_code_flow.

◆ get_context()

diagnostic_context & sarif_builder::get_context ( ) const
inline

◆ get_logical_location_manager()

const logical_location_manager * sarif_builder::get_logical_location_manager ( ) const
inline

References m_logical_loc_mgr.

◆ get_opts()

const sarif_generation_options & sarif_builder::get_opts ( ) const
inline

References m_sarif_gen_opts.

◆ get_or_create_artifact()

sarif_artifact & sarif_builder::get_or_create_artifact ( const char * filename,
enum diagnostic_artifact_role role,
bool embed_contents )
private
Ensure that we have an "artifact" object (SARIF v2.1.0 section 3.24) for FILENAME, adding it to m_filename_to_artifact_map if not already found, and adding ROLE to it. If EMBED_CONTENTS is true, then flag that we will attempt to embed the contents of this artifact when writing it out.

References sarif_artifact::add_role(), analysis_target, debug_output_file, gcc_unreachable, m_context, m_filename_to_artifact_map, make_artifact_location_object(), result_file, scanned_file, json::object::set(), json::object::set_string(), and traced_file.

Referenced by maybe_make_physical_location_object(), and sarif_builder().

◆ get_printer()

◆ get_result()

sarif_result & sarif_builder::get_result ( size_t idx)
inline

References gcc_assert.

◆ get_sarif_column()

int sarif_builder::get_sarif_column ( expanded_location exploc) const
private
Get the column number within EXPLOC.

References location_compute_display_column(), m_context, and m_tabstop.

Referenced by make_region_object_for_hint(), and maybe_make_region_object().

◆ get_source_lines()

char * sarif_builder::get_source_lines ( const char * filename,
int start_line,
int end_line ) const
private
Attempt to read the given range of lines from FILENAME; return a freshly-allocated 0-terminated buffer containing them, or nullptr.

References char_span::get_buffer(), i, char_span::length(), and m_context.

Referenced by maybe_make_artifact_content_object().

◆ get_token_printer()

token_printer & sarif_builder::get_token_printer ( )
inline

References m_token_printer.

◆ get_version()

◆ make_artifact_change_object()

std::unique_ptr< sarif_artifact_change > sarif_builder::make_artifact_change_object ( const rich_location & richloc)
private
Make an "artifactChange" object (SARIF v2.1.0 section 3.56) for RICHLOC.

References i, make_artifact_location_object(), and make_replacement_object().

Referenced by make_fix_object().

◆ make_artifact_content_object()

std::unique_ptr< sarif_artifact_content > sarif_builder::make_artifact_content_object ( const char * text) const
private
Make an "artifactContent" object (SARIF v2.1.0 section 3.3) for TEXT.

Referenced by make_replacement_object().

◆ make_artifact_location_object() [1/2]

std::unique_ptr< sarif_artifact_location > sarif_builder::make_artifact_location_object ( const char * filename)
Make an "artifactLocation" object (SARIF v2.1.0 section 3.4) for FILENAME, or return nullptr.

References m_seen_any_relative_paths, and PWD_PROPERTY_NAME.

Referenced by get_or_create_artifact(), make_artifact_change_object(), make_artifact_location_object(), maybe_make_physical_location_object(), and sarif_invocation::sarif_invocation().

◆ make_artifact_location_object() [2/2]

std::unique_ptr< sarif_artifact_location > sarif_builder::make_artifact_location_object ( location_t loc)
private
Make an "artifactLocation" object (SARIF v2.1.0 section 3.4) for LOC, or return nullptr.

References LOCATION_FILE, and make_artifact_location_object().

◆ make_artifact_location_object_for_pwd()

std::unique_ptr< sarif_artifact_location > sarif_builder::make_artifact_location_object_for_pwd ( ) const
private
Make an "artifactLocation" object (SARIF v2.1.0 section 3.4) for the pwd, for use in the "run.originalUriBaseIds" property (SARIF v2.1.0 section 3.14.14) when we have any relative paths.

References free(), gcc_assert, and make_pwd_uri_str().

Referenced by make_run_object().

◆ make_code_flow_object()

std::unique_ptr< sarif_code_flow > sarif_builder::make_code_flow_object ( sarif_result & result,
unsigned idx_within_parent,
const diagnostic_path & path )
private
Make a "codeFlow" object (SARIF v2.1.0 section 3.36) for PATH.

References sarif_thread_flow::add_location(), i, m_current_code_flow, path, and populate_thread_flow_location_object().

Referenced by make_result_object().

◆ make_driver_tool_component_object()

std::unique_ptr< sarif_tool_component > sarif_builder::make_driver_tool_component_object ( )
private
Make a "toolComponent" object (SARIF v2.1.0 section 3.19) for what SARIF calls the "driver" (see SARIF v2.1.0 section 3.18.1).

References free(), m_context, and m_rules_arr.

Referenced by make_tool_object().

◆ make_fix_object()

std::unique_ptr< sarif_fix > sarif_builder::make_fix_object ( const rich_location & richloc)
private
Make a "fix" object (SARIF v2.1.0 section 3.55) for RICHLOC.

References make_artifact_change_object(), and json::object::set().

Referenced by make_result_object().

◆ make_location_object() [1/3]

std::unique_ptr< sarif_location > sarif_builder::make_location_object ( sarif_location_manager & loc_mgr,
const diagnostic_event & event,
enum diagnostic_artifact_role role )
private
Make a "location" object (SARIF v2.1.0 section 3.28) for EVENT within a diagnostic_path.

References add_any_include_chain(), pretty_printer::clone(), json::object::get(), get_printer(), make_message_object(), maybe_make_physical_location_object(), pp_formatted_text(), and set_any_logical_locs_arr().

◆ make_location_object() [2/3]

◆ make_location_object() [3/3]

std::unique_ptr< sarif_location > sarif_builder::make_location_object ( sarif_location_manager & loc_mgr,
location_t loc,
enum diagnostic_artifact_role role )
Make a "location" object (SARIF v2.1.0 section 3.28) for WHERE within an include chain.

References add_any_include_chain(), json::object::get(), and maybe_make_physical_location_object().

◆ make_locations_arr()

std::unique_ptr< json::array > sarif_builder::make_locations_arr ( sarif_location_manager & loc_mgr,
const diagnostic_info & diagnostic,
enum diagnostic_artifact_role role )
Make an array suitable for use as the "locations" property of: - a "result" object (SARIF v2.1.0 section 3.27.12), or - a "notification" object (SARIF v2.1.0 section 3.58.4). Use LOC_MGR for any locations that need "id" values.

References m_context, and make_location_object().

Referenced by make_result_object(), and sarif_ice_notification::sarif_ice_notification().

◆ make_message_object()

std::unique_ptr< sarif_message > sarif_builder::make_message_object ( const char * msg) const

◆ make_message_object_for_diagram()

std::unique_ptr< sarif_message > sarif_builder::make_message_object_for_diagram ( const diagnostic_diagram & diagram)
Make a "message" object (SARIF v2.1.0 section 3.11) for DIAGRAM. We emit the diagram as a code block within the Markdown part of the message.

References diagnostic_diagram::get_alt_text(), diagnostic_diagram::get_canvas(), m_printer, pp_clear_output_area(), pp_formatted_text(), pp_set_prefix(), pp_take_prefix(), and set_string_property_escaping_braces().

Referenced by sarif_result::on_diagram().

◆ make_minimal_sarif_logical_location()

std::unique_ptr< sarif_logical_location > sarif_builder::make_minimal_sarif_logical_location ( logical_location logical_loc)
Ensure that theRuns.logicalLocations (3.14.17) has a "logicalLocation" object (SARIF v2.1.0 section 3.33) for LOGICAL_LOC. Create and return a minimal logicalLocation object referring to the full object by index.

References ensure_sarif_logical_location_for(), gcc_assert, and m_logical_loc_mgr.

Referenced by set_any_logical_locs_arr(), and sarif_property_bag::set_logical_location().

◆ make_multiformat_message_string()

std::unique_ptr< sarif_multiformat_message_string > sarif_builder::make_multiformat_message_string ( const char * msg) const
private
Make a "multiformatMessageString object" (SARIF v2.1.0 section 3.12) for MSG.

References msg, and set_string_property_escaping_braces().

Referenced by make_location_object(), and maybe_make_cwe_taxonomy_object().

◆ make_region_object_for_hint()

std::unique_ptr< sarif_region > sarif_builder::make_region_object_for_hint ( const fixit_hint & hint) const
private
Make a "region" object (SARIF v2.1.0 section 3.30) for the deletion region of HINT (as per SARIF v2.1.0 section 3.57.3).

References expand_location(), and get_sarif_column().

Referenced by make_replacement_object().

◆ make_replacement_object()

std::unique_ptr< sarif_replacement > sarif_builder::make_replacement_object ( const fixit_hint & hint) const
private
Make a "replacement" object (SARIF v2.1.0 section 3.57) for HINT.

References make_artifact_content_object(), make_region_object_for_hint(), and json::object::set().

Referenced by make_artifact_change_object().

◆ make_reporting_descriptor_object_for_cwe_id()

std::unique_ptr< sarif_reporting_descriptor > sarif_builder::make_reporting_descriptor_object_for_cwe_id ( int cwe_id) const
private
Make a "reportingDescriptor" object (SARIF v2.1.0 section 3.49) for CWE_ID, for use within the CWE taxa array.

References free(), get_cwe_url(), pp_formatted_text(), and pp_printf().

Referenced by maybe_make_cwe_taxonomy_object().

◆ make_reporting_descriptor_object_for_warning()

std::unique_ptr< sarif_reporting_descriptor > sarif_builder::make_reporting_descriptor_object_for_warning ( const diagnostic_info & diagnostic,
diagnostic_t orig_diag_kind,
const char * option_text )
private
Make a "reportingDescriptor" object (SARIF v2.1.0 section 3.49) for a GCC warning.

References free(), and m_context.

Referenced by make_result_object().

◆ make_reporting_descriptor_reference_object_for_cwe_id()

std::unique_ptr< sarif_reporting_descriptor_reference > sarif_builder::make_reporting_descriptor_reference_object_for_cwe_id ( int cwe_id)
private
Make a "reportingDescriptorReference" object (SARIF v2.1.0 section 3.52) referencing CWE_ID, for use within a result object. Also, add CWE_ID to m_cwe_id_set.

References gcc_assert, m_cwe_id_set, make_tool_component_reference_object_for_cwe(), pp_formatted_text(), and pp_printf().

Referenced by make_result_object().

◆ make_result_object()

◆ make_run_object()

◆ make_stack_from_backtrace()

std::unique_ptr< json::object > sarif_builder::make_stack_from_backtrace ( )
private
Attempt to generate a JSON object representing a backtrace, for adding to ICE notifications.

References bt_callback().

Referenced by on_report_diagnostic().

◆ make_tool_component_reference_object_for_cwe()

std::unique_ptr< sarif_tool_component_reference > sarif_builder::make_tool_component_reference_object_for_cwe ( ) const
private
Make a "toolComponentReference" object (SARIF v2.1.0 section 3.54) that references the CWE taxonomy.

Referenced by make_reporting_descriptor_reference_object_for_cwe_id().

◆ make_tool_object()

std::unique_ptr< sarif_tool > sarif_builder::make_tool_object ( )
private

◆ make_top_level_object()

std::unique_ptr< sarif_log > sarif_builder::make_top_level_object ( std::unique_ptr< sarif_invocation > invocation_obj,
std::unique_ptr< json::array > results )
private
Make a top-level "sarifLog" object (SARIF v2.1.0 section 3.13).

References get_version(), make_run_object(), sarif_version_to_property(), sarif_version_to_url(), and json::object::set().

Referenced by flush_to_object().

◆ maybe_make_artifact_content_object() [1/2]

std::unique_ptr< sarif_artifact_content > sarif_builder::maybe_make_artifact_content_object ( const char * filename) const
Make an "artifactContent" object (SARIF v2.1.0 section 3.3) for the full contents of FILENAME.

References char_span::get_buffer(), char_span::length(), and m_context.

Referenced by maybe_make_region_object_for_context(), and sarif_artifact::populate_contents().

◆ maybe_make_artifact_content_object() [2/2]

std::unique_ptr< sarif_artifact_content > sarif_builder::maybe_make_artifact_content_object ( const char * filename,
int start_line,
int end_line,
const content_renderer * r ) const
private
Make an "artifactContent" object (SARIF v2.1.0 section 3.3) for the given run of lines within FILENAME (including the endpoints). If R is non-NULL, use it to potentially set the "rendered" property (3.3.4).

References free(), get_source_lines(), and r.

◆ maybe_make_cwe_taxonomy_object()

std::unique_ptr< sarif_tool_component > sarif_builder::maybe_make_cwe_taxonomy_object ( ) const
private
If we've seen any CWE IDs, make a "toolComponent" object (SARIF v2.1.0 section 3.19) representing the CWE taxonomy, as per 3.19.3. Populate the "taxa" property with all of the CWE IDs in m_cwe_id_set. Otherwise return nullptr.

References m_cwe_id_set, make_multiformat_message_string(), make_reporting_descriptor_object_for_cwe_id(), and json::object::set().

Referenced by maybe_make_taxonomies_array().

◆ maybe_make_kinds_array()

std::unique_ptr< json::array > sarif_builder::maybe_make_kinds_array ( diagnostic_event::meaning m) const
private

◆ maybe_make_physical_location_object()

std::unique_ptr< sarif_physical_location > sarif_builder::maybe_make_physical_location_object ( location_t loc,
enum diagnostic_artifact_role role,
int column_override,
const content_renderer * snippet_renderer )
private
Make a "physicalLocation" object (SARIF v2.1.0 section 3.29) for LOC. If COLUMN_OVERRIDE is non-zero, then use it as the column number if LOC has no column information. Ensure that we have an artifact object for the file, adding ROLE to it, and flagging that we will attempt to embed the contents of the artifact when writing it out.

References BUILTINS_LOCATION, get_or_create_artifact(), LOCATION_FILE, make_artifact_location_object(), maybe_make_region_object(), maybe_make_region_object_for_context(), and json::object::set().

Referenced by make_location_object(), make_location_object(), and make_location_object().

◆ maybe_make_region_object()

std::unique_ptr< sarif_region > sarif_builder::maybe_make_region_object ( location_t loc,
int column_override ) const
private
Make a "region" object (SARIF v2.1.0 section 3.30) for LOC, or return nullptr. If COLUMN_OVERRIDE is non-zero, then use it as the column number if LOC has no column information. We only support text properties of regions ("text regions"), not binary properties ("binary regions"); see 3.30.1.

References BUILTINS_LOCATION, expand_location(), get_finish(), get_pure_location(), get_sarif_column(), and get_start().

Referenced by make_location_object(), and maybe_make_physical_location_object().

◆ maybe_make_region_object_for_context()

std::unique_ptr< sarif_region > sarif_builder::maybe_make_region_object_for_context ( location_t loc,
const content_renderer * snippet_renderer ) const
private
Make a "region" object (SARIF v2.1.0 section 3.30) for the "contextRegion" property (SARIF v2.1.0 section 3.29.5) of a "physicalLocation". This is similar to maybe_make_region_object, but ignores column numbers, covering the line(s) as a whole, and including a "snippet" property embedding those source lines, making it easier for consumers to show the pertinent source.

References BUILTINS_LOCATION, expand_location(), get_finish(), get_pure_location(), get_start(), and maybe_make_artifact_content_object().

Referenced by maybe_make_physical_location_object().

◆ maybe_make_taxonomies_array()

std::unique_ptr< json::array > sarif_builder::maybe_make_taxonomies_array ( ) const
private
If we've seen any CWE IDs, make an array for the "taxonomies" property (SARIF v2.1.0 section 3.14.8) of a run object, containing a single "toolComponent" (3.19) as per 3.19.3, representing the CWE. Otherwise return nullptr.

References maybe_make_cwe_taxonomy_object().

Referenced by make_run_object().

◆ num_results()

size_t sarif_builder::num_results ( ) const
inline

References m_results_array.

◆ on_report_diagnostic()

◆ populate_thread_flow_location_object()

void sarif_builder::populate_thread_flow_location_object ( sarif_result & result,
sarif_thread_flow_location & tfl_obj,
const diagnostic_event & ev,
int event_execution_idx )
private

◆ set_any_logical_locs_arr()

void sarif_builder::set_any_logical_locs_arr ( sarif_location & location_obj,
logical_location logical_loc )
private
If LOGICAL_LOC is non-null, use it to create a "logicalLocations" property within LOCATION_OBJ (SARIF v2.1.0 section 3.28.4) with a minimal logical location object referencing theRuns.logicalLocations (3.33.3).

References gcc_assert, m_logical_loc_mgr, make_minimal_sarif_logical_location(), and json::object::set().

Referenced by make_location_object(), and make_location_object().

◆ set_printer()

void sarif_builder::set_printer ( pretty_printer & printer)
inline

References m_printer.

◆ take_current_result()

std::unique_ptr< sarif_result > sarif_builder::take_current_result ( )
inline

References m_cur_group_result.

Friends And Related Symbol Documentation

◆ diagnostic_sarif_format_buffer

Field Documentation

◆ m_cached_logical_locs

std::unique_ptr<sarif_array_of_unique<sarif_logical_location> > sarif_builder::m_cached_logical_locs
private

◆ m_context

◆ m_cur_group_result

std::unique_ptr<sarif_result> sarif_builder::m_cur_group_result
private

◆ m_current_code_flow

sarif_code_flow* sarif_builder::m_current_code_flow
private

◆ m_cwe_id_set

hash_set<int_hash <int, 0, 1> > sarif_builder::m_cwe_id_set
private

◆ m_filename_to_artifact_map

ordered_hash_map<nofree_string_hash, sarif_artifact *> sarif_builder::m_filename_to_artifact_map
private

◆ m_invocation_obj

std::unique_ptr<sarif_invocation> sarif_builder::m_invocation_obj
private

◆ m_line_maps

const line_maps* sarif_builder::m_line_maps
private

◆ m_logical_loc_mgr

◆ m_next_result_idx

unsigned sarif_builder::m_next_result_idx
private

◆ m_printer

◆ m_results_array

std::unique_ptr<json::array> sarif_builder::m_results_array
private

◆ m_rule_id_set

hash_set<free_string_hash> sarif_builder::m_rule_id_set
private

◆ m_rules_arr

std::unique_ptr<json::array> sarif_builder::m_rules_arr
private

◆ m_sarif_gen_opts

const sarif_generation_options sarif_builder::m_sarif_gen_opts
private

◆ m_seen_any_relative_paths

bool sarif_builder::m_seen_any_relative_paths
private

◆ m_serialization_format

std::unique_ptr<sarif_serialization_format> sarif_builder::m_serialization_format
private

Referenced by flush_to_file(), and sarif_builder().

◆ m_tabstop

int sarif_builder::m_tabstop
private

Referenced by get_sarif_column(), and sarif_builder().

◆ m_token_printer

sarif_token_printer sarif_builder::m_token_printer
private

Referenced by get_token_printer(), and sarif_builder().


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