diff options
author | David Malcolm <dmalcolm@redhat.com> | 2024-08-26 12:24:22 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2024-08-26 12:24:22 -0400 |
commit | ac707d30ce449f30c6018829d443956fdd653f4c (patch) | |
tree | 92a5892d12391302c4b62754f46e1cc2eb207c6d /gcc/diagnostic-format-json.cc | |
parent | 6a1c359e28442cb86ed40e0d432814b5807e7640 (diff) | |
download | gcc-ac707d30ce449f30c6018829d443956fdd653f4c.zip gcc-ac707d30ce449f30c6018829d443956fdd653f4c.tar.gz gcc-ac707d30ce449f30c6018829d443956fdd653f4c.tar.bz2 |
diagnostics: consolidate on_{begin,end}_diagnostic into on_report_diagnostic
Previously diagnostic_context::report_diagnostic had, after the call to
pp_format (phases 1 and 2 of formatting the message):
m_output_format->on_begin_diagnostic (*diagnostic);
pp_output_formatted_text (this->printer, m_urlifier);
if (m_show_cwe)
print_any_cwe (*diagnostic);
if (m_show_rules)
print_any_rules (*diagnostic);
if (m_show_option_requested)
print_option_information (*diagnostic, orig_diag_kind);
m_output_format->on_end_diagnostic (*diagnostic, orig_diag_kind);
This patch replaces all of the above with a single call to
m_output_format->on_report_diagnostic (*diagnostic, orig_diag_kind);
moving responsibility for phase 3 of formatting and printing the result
from diagnostic_context to the output format.
This simplifies diagnostic_context::report_diagnostic and allows us to
move the code that prints CWEs, rules, and option information in textual
form from diagnostic_context to diagnostic_text_output_format, where it
belongs.
No functional change intended.
gcc/ChangeLog:
* diagnostic-format-json.cc
(json_output_format::on_begin_diagnostic): Delete.
(json_output_format::on_end_diagnostic): Rename to...
(json_output_format::on_report_diagnostic): ...this and add call
to pp_output_formatted_text.
(diagnostic_output_format_init_json): Drop unnecessary calls
to disable textual printing of CWEs, rules, and options.
* diagnostic-format-sarif.cc (sarif_builder::end_diagnostic):
Rename to...
(sarif_builder::on_report_diagnostic): ...this and add call to
pp_output_formatted_text.
(sarif_output_format::on_begin_diagnostic): Delete.
(sarif_output_format::on_end_diagnostic): Rename to...
(sarif_output_format::on_report_diagnostic): ...this and update
call to m_builder accordingly.
(diagnostic_output_format_init_sarif): Drop unnecessary calls
to disable textual printing of CWEs, rules, and options.
* diagnostic.cc (diagnostic_context::print_any_cwe): Convert to...
(diagnostic_text_output_format::print_any_cwe): ...this.
(diagnostic_context::print_any_rules): Convert to...
(diagnostic_text_output_format::print_any_rules): ...this.
(diagnostic_context::print_option_information): Convert to...
(diagnostic_text_output_format::print_option_information):
...this.
(diagnostic_context::report_diagnostic): Replace calls to the
output format's on_begin_diagnostic, to pp_output_formatted_text,
printing CWE, rules, option info, and the call to the format's
on_end_diagnostic with a call to the format's
on_report_diagnostic.
(diagnostic_text_output_format::on_begin_diagnostic): Delete.
(diagnostic_text_output_format::on_end_diagnostic): Delete.
(diagnostic_text_output_format::on_report_diagnostic): New vfunc,
which effectively does the on_begin_diagnostic, the call to
pp_output_formatted_text, the calls for printing CWE, rules,
option info, and the call to the diagnostic_finalizer.
* diagnostic.h (diagnostic_output_format::on_begin_diagnostic):
Delete.
(diagnostic_output_format::on_end_diagnostic): Delete.
(diagnostic_output_format::on_report_diagnostic): New.
(diagnostic_text_output_format::on_begin_diagnostic): Delete.
(diagnostic_text_output_format::on_end_diagnostic): Delete.
(diagnostic_text_output_format::on_report_diagnostic): New.
(class diagnostic_context): Add friend class
diagnostic_text_output_format.
(diagnostic_context::get_urlifier): New accessor.
(diagnostic_context::print_any_cwe): Move decl...
(diagnostic_text_output_format::print_any_cwe): ...to here.
(diagnostic_context::print_any_rules): Move decl...
(diagnostic_text_output_format::print_any_rules): ...to here.
(diagnostic_context::print_option_information): Move decl...
(diagnostic_text_output_format::print_option_information): ...to
here.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/diagnostic-format-json.cc')
-rw-r--r-- | gcc/diagnostic-format-json.cc | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc index b78cb92..f2e9d0d 100644 --- a/gcc/diagnostic-format-json.cc +++ b/gcc/diagnostic-format-json.cc @@ -47,13 +47,8 @@ public: m_cur_children_array = nullptr; } void - on_begin_diagnostic (const diagnostic_info &) final override - { - /* No-op. */ - } - void - on_end_diagnostic (const diagnostic_info &diagnostic, - diagnostic_t orig_diag_kind) final override; + on_report_diagnostic (const diagnostic_info &diagnostic, + diagnostic_t orig_diag_kind) final override; void on_diagram (const diagnostic_diagram &) final override { /* No-op. */ @@ -225,14 +220,16 @@ make_json_for_path (diagnostic_context &context, } -/* Implementation of "on_end_diagnostic" vfunc for JSON output. +/* Implementation of "on_report_diagnostic" vfunc for JSON output. Generate a JSON object for DIAGNOSTIC, and store for output within current diagnostic group. */ void -json_output_format::on_end_diagnostic (const diagnostic_info &diagnostic, - diagnostic_t orig_diag_kind) +json_output_format::on_report_diagnostic (const diagnostic_info &diagnostic, + diagnostic_t orig_diag_kind) { + pp_output_formatted_text (m_context.printer, m_context.get_urlifier ()); + json::object *diag_obj = new json::object (); /* Get "kind" of diagnostic. */ @@ -395,13 +392,6 @@ diagnostic_output_format_init_json (diagnostic_context &context) /* Suppress normal textual path output. */ 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); - - /* The option is handled in JSON format, rather than as text. */ - context.set_show_option_requested (false); - /* Don't colorize the text. */ pp_show_color (context.printer) = false; context.set_show_highlight_colors (false); |