Skip to content
Snippets Groups Projects
Commit ac707d30 authored by David Malcolm's avatar David Malcolm
Browse files

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: default avatarDavid Malcolm <dmalcolm@redhat.com>
parent 6a1c359e
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment