aboutsummaryrefslogtreecommitdiff
path: root/gcc/diagnostic-format-json.cc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2024-09-30 11:48:29 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2024-09-30 11:48:29 -0400
commitcce52867d1892c08386f780107288473ec0033b7 (patch)
tree6435dca029e3ba371f3f8ea0317e2250207ba8a4 /gcc/diagnostic-format-json.cc
parent3d3d20ccd8365970f34002bfe0a632f2868bc95b (diff)
downloadgcc-cce52867d1892c08386f780107288473ec0033b7.zip
gcc-cce52867d1892c08386f780107288473ec0033b7.tar.gz
gcc-cce52867d1892c08386f780107288473ec0033b7.tar.bz2
diagnostics: avoid using diagnostic_context's m_printer [PR116613]
As work towards supporting multiple diagnostic outputs (where each output has its own pretty_printer), avoid using diagnostic_context's m_printer field. Instead, use the output format's printer. Currently this *is* the dc's printer, but eventually it might not be. No functional change intended. gcc/ChangeLog: PR other/116613 * diagnostic-format-json.cc (diagnostic_output_format_init_json): Pass in the format. Use the format's printer when disabling colorization. Move the call to set_output_format into here. (diagnostic_output_format_init_json_stderr): Update for above change. (diagnostic_output_format_init_json_file): Likewise. * diagnostic-format-sarif.cc (diagnostic_output_format_init_sarif): Use the format's printer when disabling colorization. * diagnostic-path.cc (selftest::test_empty_path): Use the text_output's printer. (selftest::test_intraprocedural_path): Likewise. (selftest::test_interprocedural_path_1): Likewise. (selftest::test_interprocedural_path_2): Likewise. (selftest::test_recursion): Likewise. (selftest::test_control_flow_1): Likewise. (selftest::test_control_flow_2): Likewise. (selftest::test_control_flow_3): Likewise. (selftest::assert_cfg_edge_path_streq): Likewise. (selftest::test_control_flow_5): Likewise. (selftest::test_control_flow_6): Likewise. gcc/testsuite/ChangeLog: PR other/116613 * gcc.dg/plugin/diagnostic_group_plugin.c (test_output_format::on_begin_group): Use get_printer () rather than accessing m_context.m_printer. (test_output_format::on_end_group): Likewise. * gcc.dg/plugin/diagnostic_plugin_xhtml_format.c (xhtml_builder::m_printer): New field. (xhtml_builder::xhtml_builder): Add "pp" param and use it to initialize m_printer. (xhtml_builder::on_report_diagnostic): Drop "context" param. (xhtml_builder::make_element_for_diagnostic): Likewise. Use this->m_printer rather than the context's m_printer. Pass m_printer to call to diagnostic_show_locus. (xhtml_builder::emit_diagram): Drop "context" param. (xhtml_output_format::on_report_diagnostic): Drop context param from call to m_builder. (xhtml_output_format::on_diagram): Likewise. (xhtml_output_format::xhtml_output_format): Pass result of get_printer as printer for builder. (diagnostic_output_format_init_xhtml): Use the fmt's printer rather than the context's. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/diagnostic-format-json.cc')
-rw-r--r--gcc/diagnostic-format-json.cc23
1 files changed, 14 insertions, 9 deletions
diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc
index 448b6cb..cf900a9 100644
--- a/gcc/diagnostic-format-json.cc
+++ b/gcc/diagnostic-format-json.cc
@@ -393,14 +393,17 @@ private:
to a file). */
static void
-diagnostic_output_format_init_json (diagnostic_context &context)
+diagnostic_output_format_init_json (diagnostic_context &context,
+ std::unique_ptr<json_output_format> fmt)
{
/* Suppress normal textual path output. */
context.set_path_format (DPF_NONE);
/* Don't colorize the text. */
- pp_show_color (context.m_printer) = false;
+ pp_show_color (fmt->get_printer ()) = false;
context.set_show_highlight_colors (false);
+
+ context.set_output_format (fmt.release ());
}
/* Populate CONTEXT in preparation for JSON output to stderr. */
@@ -409,9 +412,10 @@ void
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));
+ diagnostic_output_format_init_json
+ (context,
+ ::make_unique<json_stderr_output_format> (context,
+ formatted));
}
/* Populate CONTEXT in preparation for JSON output to a file named
@@ -422,10 +426,11 @@ 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));
+ diagnostic_output_format_init_json
+ (context,
+ ::make_unique<json_file_output_format> (context,
+ formatted,
+ base_file_name));
}
#if CHECKING_P