GCC Middle and Back End API Reference
diagnostic-format-sarif.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "diagnostic.h"
#include "diagnostic-metadata.h"
#include "diagnostic-path.h"
#include "json.h"
#include "cpplib.h"
#include "logical-location.h"
#include "diagnostic-client-data-hooks.h"
#include "diagnostic-diagram.h"
#include "text-art/canvas.h"
#include "diagnostic-format-sarif.h"
#include "diagnostic.def"
Include dependency graph for diagnostic-format-sarif.cc:

Data Structures

class  sarif_invocation
 
class  sarif_result
 
class  sarif_ice_notification
 
class  sarif_thread_flow
 
class  sarif_builder
 
class  sarif_output_format
 
class  sarif_stream_output_format
 
class  sarif_file_output_format
 

Macros

#define INCLUDE_VECTOR
 
#define DEFINE_DIAGNOSTIC_KIND(K, T, C)   (T),
 
#define PWD_PROPERTY_NAME   ("PWD")
 
#define FILE_PREFIX   ("file://")
 
#define SARIF_SCHEMA   "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json"
 
#define SARIF_VERSION   "2.1.0"
 

Functions

static const charmaybe_get_sarif_level (diagnostic_t diag_kind)
 
static charmake_rule_id_for_diagnostic_kind (diagnostic_t diag_kind)
 
static charmake_pwd_uri_str ()
 
static const charmaybe_get_sarif_kind (enum logical_location_kind kind)
 
json::objectmake_sarif_logical_location_object (const logical_location &logical_loc)
 
static void sarif_ice_handler (diagnostic_context *context)
 
static void diagnostic_output_format_init_sarif (diagnostic_context *context)
 
void diagnostic_output_format_init_sarif_stderr (diagnostic_context *context, bool formatted)
 
void diagnostic_output_format_init_sarif_file (diagnostic_context *context, bool formatted, const char *base_file_name)
 
void diagnostic_output_format_init_sarif_stream (diagnostic_context *context, bool formatted, FILE *stream)
 

Macro Definition Documentation

◆ DEFINE_DIAGNOSTIC_KIND

#define DEFINE_DIAGNOSTIC_KIND ( K,
T,
C )   (T),

◆ FILE_PREFIX

#define FILE_PREFIX   ("file://")

◆ INCLUDE_VECTOR

#define INCLUDE_VECTOR
SARIF output for diagnostics
   Copyright (C) 2018-2024 Free Software Foundation, Inc.
   Contributed by David Malcolm <dmalcolm@redhat.com>.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.   

◆ PWD_PROPERTY_NAME

#define PWD_PROPERTY_NAME   ("PWD")
The ID value for use in "uriBaseId" properties (SARIF v2.1.0 section 3.4.4)
for when we need to express paths relative to PWD.   

Referenced by sarif_builder::make_artifact_location_object(), and sarif_builder::make_run_object().

◆ SARIF_SCHEMA

#define SARIF_SCHEMA   "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json"

◆ SARIF_VERSION

#define SARIF_VERSION   "2.1.0"

Function Documentation

◆ diagnostic_output_format_init_sarif()

◆ diagnostic_output_format_init_sarif_file()

void diagnostic_output_format_init_sarif_file ( diagnostic_context * context,
bool formatted,
const char * base_file_name )
Populate CONTEXT in preparation for SARIF output to a file named
BASE_FILE_NAME.sarif.   

References base_file_name(), diagnostic_output_format_init_sarif(), ggc_alloc(), and diagnostic_context::set_output_format().

Referenced by diagnostic_output_format_init().

◆ diagnostic_output_format_init_sarif_stderr()

void diagnostic_output_format_init_sarif_stderr ( diagnostic_context * context,
bool formatted )
Populate CONTEXT in preparation for SARIF output to stderr.   

References diagnostic_output_format_init_sarif(), ggc_alloc(), and diagnostic_context::set_output_format().

Referenced by diagnostic_output_format_init().

◆ diagnostic_output_format_init_sarif_stream()

void diagnostic_output_format_init_sarif_stream ( diagnostic_context * context,
bool formatted,
FILE * stream )
Populate CONTEXT in preparation for SARIF output to STREAM.   

References diagnostic_output_format_init_sarif(), ggc_alloc(), and diagnostic_context::set_output_format().

◆ make_pwd_uri_str()

static char * make_pwd_uri_str ( )
static
Get the PWD, or NULL, as an absolute file-based URI,
adding a trailing forward slash (as required by SARIF v2.1.0
section 3.14.14).   

References FILE_PREFIX, gcc_assert, ggc_alloc(), and NULL.

Referenced by sarif_builder::make_artifact_location_object_for_pwd().

◆ make_rule_id_for_diagnostic_kind()

static char * make_rule_id_for_diagnostic_kind ( diagnostic_t diag_kind)
static
Make a string for DIAG_KIND suitable for use a ruleId
(SARIF v2.1.0 section 3.27.5) as a fallback for when we don't
have anything better to use.   

References diagnostic_kind_text, gcc_assert, and ggc_alloc().

Referenced by sarif_builder::make_result_object().

◆ make_sarif_logical_location_object()

json::object * make_sarif_logical_location_object ( const logical_location & logical_loc)
Make a logicalLocation object (SARIF v2.1.0 section 3.33) for LOGICAL_LOC,
or return NULL.   

References ggc_alloc(), and maybe_get_sarif_kind().

Referenced by sarif_builder::set_any_logical_locs_arr().

◆ maybe_get_sarif_kind()

◆ maybe_get_sarif_level()

static const char * maybe_get_sarif_level ( diagnostic_t diag_kind)
static
Attempt to convert DIAG_KIND to a suitable value for the "level"
property (SARIF v2.1.0 section 3.27.10).

Return NULL if there isn't one.   

References ggc_alloc(), and NULL.

Referenced by sarif_builder::make_result_object().

◆ sarif_ice_handler()

static void sarif_ice_handler ( diagnostic_context * context)
static
Callback for diagnostic_context::ice_handler_cb for when an ICE
occurs.   

References diagnostic_finish(), fnotice(), and ggc_alloc().

Referenced by diagnostic_output_format_init_sarif().