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_, bool formatted, enum sarif_version version)
 
 ~sarif_builder ()
 
void set_printer (pretty_printer &printer)
 
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, const 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)
 

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, const 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
 
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
 
enum sarif_version m_version
 
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
 
int m_tabstop
 
bool m_formatted
 
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 ( diagnostic_context & context,
pretty_printer & printer,
const line_maps * line_maps,
const char * main_input_filename_,
bool formatted,
enum sarif_version version )
class sarif_builder.   
sarif_builder's ctor.   

References analysis_target, gcc_assert, get_or_create_artifact(), and m_line_maps.

◆ ~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.

Referenced by sarif_output_format::on_diagram().

◆ end_group()

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

References m_cur_group_result, and m_results_array.

Referenced by sarif_output_format::on_end_group().

◆ 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_formatted.

Referenced by sarif_file_output_format::~sarif_file_output_format(), and sarif_stream_output_format::~sarif_stream_output_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

◆ get_context()

diagnostic_context & sarif_builder::get_context ( ) const
inline

◆ 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, ordered_hash_map< KeyId, Value, Traits >::get(), diagnostic_context::get_client_data_hooks(), m_context, m_filename_to_artifact_map, make_artifact_location_object(), ordered_hash_map< KeyId, Value, Traits >::put(), 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.

Referenced by sarif_output_format::get_result().

◆ get_sarif_column()

int sarif_builder::get_sarif_column ( expanded_location exploc) const
private

◆ 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(), diagnostic_context::get_file_cache(), file_cache::get_source_line(), 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

◆ get_version()

enum sarif_version sarif_builder::get_version ( ) const
inline

◆ 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(), make_replacement_object(), and make_unique().

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.   

References make_unique().

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, make_unique(), 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, make_pwd_uri_str(), and make_unique().

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_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(), diagnostic_context::get_client_data_hooks(), m_context, m_rules_arr, and make_unique().

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(), make_unique(), 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_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(), make_unique(), 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 diagnostic_context::get_client_data_hooks(), m_context, make_location_object(), and make_unique().

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, make_unique(), pp_clear_output_area(), pp_formatted_text(), pp_set_prefix(), and pp_take_prefix().

Referenced by sarif_result::on_diagram().

◆ 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 make_unique(), and msg.

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(), get_sarif_column(), and make_unique().

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(), make_unique(), 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(), make_unique(), 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(), m_context, diagnostic_context::make_option_url(), and make_unique().

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 hash_set< KeyId, Lazy, Traits >::add(), gcc_assert, m_cwe_id_set, make_tool_component_reference_object_for_cwe(), make_unique(), 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(), and make_unique().

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.   

References make_unique().

Referenced by make_reporting_descriptor_reference_object_for_cwe_id().

◆ make_tool_object()

◆ 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 m_version, make_run_object(), make_unique(), 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(), diagnostic_context::get_file_cache(), file_cache::get_source_file_content(), char_span::length(), m_context, and make_unique().

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(), make_unique(), 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 hash_set< KeyId, Lazy, Traits >::is_empty(), m_cwe_id_set, make_multiformat_message_string(), make_reporting_descriptor_object_for_cwe_id(), make_unique(), 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(), make_unique(), 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(), get_start(), and make_unique().

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(), make_unique(), 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 make_unique(), and maybe_make_cwe_taxonomy_object().

Referenced by make_run_object().

◆ num_results()

size_t sarif_builder::num_results ( ) const
inline

◆ 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,
const 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).   

References make_sarif_logical_location_object(), make_unique(), and json::object::set().

Referenced by make_location_object(), and make_location_object().

◆ set_printer()

void sarif_builder::set_printer ( pretty_printer & printer)
inline

◆ take_current_result()

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

Friends And Related Symbol Documentation

◆ diagnostic_sarif_format_buffer

friend class diagnostic_sarif_format_buffer
friend

Field Documentation

◆ 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_formatted

bool sarif_builder::m_formatted
private

Referenced by flush_to_file().

◆ 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_next_result_idx

unsigned sarif_builder::m_next_result_idx
private

Referenced by on_report_diagnostic().

◆ 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

Referenced by make_result_object().

◆ m_rules_arr

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

◆ m_seen_any_relative_paths

bool sarif_builder::m_seen_any_relative_paths
private

◆ m_tabstop

int sarif_builder::m_tabstop
private

Referenced by get_sarif_column().

◆ m_token_printer

sarif_token_printer sarif_builder::m_token_printer
private

Referenced by get_token_printer().

◆ m_version

enum sarif_version sarif_builder::m_version
private

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