aboutsummaryrefslogtreecommitdiff
path: root/gcc/diagnostic-format-json.cc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2024-07-24 18:07:53 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2024-07-24 18:07:53 -0400
commit29522bff8f4940a6b4307da0021e257c98eeecea (patch)
treeaa504c550dc8f5b5c3b848f98dc460c3ef1b6b13 /gcc/diagnostic-format-json.cc
parent5342c63f4fb49c110c6252538cb954779c6ff156 (diff)
downloadgcc-29522bff8f4940a6b4307da0021e257c98eeecea.zip
gcc-29522bff8f4940a6b4307da0021e257c98eeecea.tar.gz
gcc-29522bff8f4940a6b4307da0021e257c98eeecea.tar.bz2
diagnostics: output formats: use references for non-null pointers
No functional change intended. gcc/ChangeLog: * diagnostic-format-json.cc (json_from_expanded_location): Make "static". Pass param "context" by reference, as it cannot be null. (json_from_location_range): Likewise for param "context". (json_from_fixit_hint): Likewise. (make_json_for_path): Likewise. (json_output_format::on_end_diagnostic): Update for above changes. (diagnostic_output_format_init_json::diagnostic_output_format_init_json): Pass param "context" by reference, as it cannot be null. (diagnostic_output_format_init_json_stderr): Likewise. (diagnostic_output_format_init_json_file): Likewise. (selftest::test_unknown_location): Update for above changes. (selftest::test_bad_endpoints): Likewise. * diagnostic-format-sarif.cc (sarif_builder::m_context): Convert from pointer to reference. (sarif_invocation::add_notification_for_ice): Convert both params from pointers to references. (sarif_invocation::prepare_to_flush): Likewise for "context". (sarif_result::on_nested_diagnostic): Likewise for "context" and "builder". (sarif_result::on_diagram): Likewise. (sarif_ice_notification::sarif_ice_notification): Likewise. (sarif_builder::sarif_builder): Likewise for "context". (sarif_builder::end_diagnostic): Likewise. (sarif_builder::emit_diagram): Likewise. (sarif_builder::make_result_object): Likewise. (make_reporting_descriptor_object_for_warning): Likewise. (sarif_builder::make_locations_arr): Update for change to m_context. (sarif_builder::get_sarif_column): Likewise. (sarif_builder::make_message_object_for_diagram): Convert "context" from pointer to reference. (sarif_builder::make_tool_object): Likewise for "m_context". (sarif_builder::make_driver_tool_component_object): Likewise. (sarif_builder::get_or_create_artifact): Likewise. (sarif_builder::maybe_make_artifact_content_object): Likewise. (sarif_builder::get_source_lines): Likewise. (sarif_output_format::on_end_diagnostic): Update for above changes. (sarif_output_format::on_diagram): Likewise. (sarif_output_format::sarif_output_format): Likewise. (diagnostic_output_format_init_sarif): Convert param "context" from pointer to reference. (diagnostic_output_format_init_sarif_stderr): Likewise. (diagnostic_output_format_init_sarif_file): Likewise. (diagnostic_output_format_init_sarif_stream): Likewise. * diagnostic.cc (diagnostic_output_format_init): Likewise. * diagnostic.h (diagnostic_output_format_init): Likewise. (diagnostic_output_format_init_json_stderr): Likewise. (diagnostic_output_format_init_json_file): Likewise. (diagnostic_output_format_init_sarif_stderr): Likewise. (diagnostic_output_format_init_sarif_file): Likewise. (diagnostic_output_format_init_sarif_stream): Likewise. (json_from_expanded_location): Delete decl. * gcc.cc (driver_handle_option): Update for change to diagnostic_output_format_init. * opts.cc (common_handle_option): Likewise. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/diagnostic-format-json.cc')
-rw-r--r--gcc/diagnostic-format-json.cc56
1 files changed, 28 insertions, 28 deletions
diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc
index 4dc0f26..1bf8da6 100644
--- a/gcc/diagnostic-format-json.cc
+++ b/gcc/diagnostic-format-json.cc
@@ -94,8 +94,8 @@ private:
/* Generate a JSON object for LOC. */
-json::value *
-json_from_expanded_location (diagnostic_context *context, location_t loc)
+static json::value *
+json_from_expanded_location (diagnostic_context &context, location_t loc)
{
expanded_location exploc = expand_location (loc);
json::object *result = new json::object ();
@@ -103,7 +103,7 @@ json_from_expanded_location (diagnostic_context *context, location_t loc)
result->set_string ("file", exploc.file);
result->set_integer ("line", exploc.line);
- const enum diagnostics_column_unit orig_unit = context->m_column_unit;
+ const enum diagnostics_column_unit orig_unit = context.m_column_unit;
struct
{
const char *name;
@@ -115,22 +115,22 @@ json_from_expanded_location (diagnostic_context *context, location_t loc)
int the_column = INT_MIN;
for (int i = 0; i != ARRAY_SIZE (column_fields); ++i)
{
- context->m_column_unit = column_fields[i].unit;
- const int col = context->converted_column (exploc);
+ context.m_column_unit = column_fields[i].unit;
+ const int col = context.converted_column (exploc);
result->set_integer (column_fields[i].name, col);
if (column_fields[i].unit == orig_unit)
the_column = col;
}
gcc_assert (the_column != INT_MIN);
result->set_integer ("column", the_column);
- context->m_column_unit = orig_unit;
+ context.m_column_unit = orig_unit;
return result;
}
/* Generate a JSON object for LOC_RANGE. */
static json::object *
-json_from_location_range (diagnostic_context *context,
+json_from_location_range (diagnostic_context &context,
const location_range *loc_range, unsigned range_idx)
{
location_t caret_loc = get_pure_location (loc_range->m_loc);
@@ -163,7 +163,7 @@ json_from_location_range (diagnostic_context *context,
/* Generate a JSON object for HINT. */
static json::object *
-json_from_fixit_hint (diagnostic_context *context, const fixit_hint *hint)
+json_from_fixit_hint (diagnostic_context &context, const fixit_hint *hint)
{
json::object *fixit_obj = new json::object ();
@@ -192,7 +192,7 @@ json_from_metadata (const diagnostic_metadata *metadata)
/* Make a JSON value for PATH. */
static json::value *
-make_json_for_path (diagnostic_context *context,
+make_json_for_path (diagnostic_context &context,
const diagnostic_path *path)
{
json::array *path_array = new json::array ();
@@ -288,7 +288,7 @@ json_output_format::on_end_diagnostic (const diagnostic_info &diagnostic,
{
const location_range *loc_range = richloc->get_range (i);
json::object *loc_obj
- = json_from_location_range (&m_context, loc_range, i);
+ = json_from_location_range (m_context, loc_range, i);
if (loc_obj)
loc_array->append (loc_obj);
}
@@ -300,7 +300,7 @@ json_output_format::on_end_diagnostic (const diagnostic_info &diagnostic,
for (unsigned int i = 0; i < richloc->get_num_fixit_hints (); i++)
{
const fixit_hint *hint = richloc->get_fixit_hint (i);
- json::object *fixit_obj = json_from_fixit_hint (&m_context, hint);
+ json::object *fixit_obj = json_from_fixit_hint (m_context, hint);
fixit_array->append (fixit_obj);
}
}
@@ -319,7 +319,7 @@ json_output_format::on_end_diagnostic (const diagnostic_info &diagnostic,
const diagnostic_path *path = richloc->get_path ();
if (path)
{
- json::value *path_value = make_json_for_path (&m_context, path);
+ json::value *path_value = make_json_for_path (m_context, path);
diag_obj->set ("path", path_value);
}
@@ -387,46 +387,46 @@ private:
to a file). */
static void
-diagnostic_output_format_init_json (diagnostic_context *context)
+diagnostic_output_format_init_json (diagnostic_context &context)
{
/* Suppress normal textual path output. */
- context->set_path_format (DPF_NONE);
+ context.set_path_format (DPF_NONE);
/* The metadata is handled in JSON format, rather than as text. */
- context->set_show_cwe (false);
- context->set_show_rules (false);
+ context.set_show_cwe (false);
+ context.set_show_rules (false);
/* The option is handled in JSON format, rather than as text. */
- context->set_show_option_requested (false);
+ context.set_show_option_requested (false);
/* Don't colorize the text. */
- pp_show_color (context->printer) = false;
- context->set_show_highlight_colors (false);
+ pp_show_color (context.printer) = false;
+ context.set_show_highlight_colors (false);
}
/* Populate CONTEXT in preparation for JSON output to stderr. */
void
-diagnostic_output_format_init_json_stderr (diagnostic_context *context,
+diagnostic_output_format_init_json_stderr (diagnostic_context &context,
bool formatted)
{
diagnostic_output_format_init_json (context);
- context->set_output_format (new json_stderr_output_format (*context,
- formatted));
+ context.set_output_format (new json_stderr_output_format (context,
+ formatted));
}
/* Populate CONTEXT in preparation for JSON output to a file named
BASE_FILE_NAME.gcc.json. */
void
-diagnostic_output_format_init_json_file (diagnostic_context *context,
+diagnostic_output_format_init_json_file (diagnostic_context &context,
bool formatted,
const char *base_file_name)
{
diagnostic_output_format_init_json (context);
- context->set_output_format (new json_file_output_format (*context,
- formatted,
- base_file_name));
+ context.set_output_format (new json_file_output_format (context,
+ formatted,
+ base_file_name));
}
#if CHECKING_P
@@ -440,7 +440,7 @@ static void
test_unknown_location ()
{
test_diagnostic_context dc;
- delete json_from_expanded_location (&dc, UNKNOWN_LOCATION);
+ delete json_from_expanded_location (dc, UNKNOWN_LOCATION);
}
/* Verify that we gracefully handle attempts to serialize bad
@@ -459,7 +459,7 @@ test_bad_endpoints ()
loc_range.m_label = NULL;
test_diagnostic_context dc;
- json::object *obj = json_from_location_range (&dc, &loc_range, 0);
+ json::object *obj = json_from_location_range (dc, &loc_range, 0);
/* We should have a "caret" value, but no "start" or "finish" values. */
ASSERT_TRUE (obj != NULL);
ASSERT_TRUE (obj->get ("caret") != NULL);