In particular, move the classic text output code to a diagnostic-text.cc (analogous to -json.cc and -sarif.cc).
No functional change intended. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r15-3201-g92c5265d22afaa. gcc/ChangeLog: * Makefile.in (OBJS-libcommon): Add diagnostic-format-text.o. * diagnostic-format-json.cc: Include "diagnostic-format.h". * diagnostic-format-sarif.cc: Likewise. * diagnostic-format-text.cc: New file, using material from diagnostics.cc. * diagnostic-global-context.cc: Include "diagnostic-format.h". * diagnostic-format-text.h: New file, using material from diagnostics.h. * diagnostic-format.h: New file, using material from diagnostics.h. * diagnostic.cc: Include "diagnostic-format.h" and "diagnostic-format-text.h". (diagnostic_text_output_format::~diagnostic_text_output_format): Move to diagnostic-format-text.cc. (diagnostic_text_output_format::on_report_diagnostic): Likewise. (diagnostic_text_output_format::on_diagram): Likewise. (diagnostic_text_output_format::print_any_cwe): Likewise. (diagnostic_text_output_format::print_any_rules): Likewise. (diagnostic_text_output_format::print_option_information): Likewise. * diagnostic.h (class diagnostic_output_format): Move to diagnostic-format.h. (class diagnostic_text_output_format): Move to diagnostic-format-text.h. (diagnostic_output_format_init): Move to diagnostic-format.h. (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. * gcc.cc: Include "diagnostic-format.h". * opts.cc: Include "diagnostic-format.h". gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_group_plugin.c: Include "diagnostic-format-text.h". Signed-off-by: David Malcolm <dmalc...@redhat.com> --- gcc/Makefile.in | 1 + gcc/diagnostic-format-json.cc | 1 + gcc/diagnostic-format-sarif.cc | 1 + gcc/diagnostic-format-text.cc | 209 ++++++++++++++++++ gcc/diagnostic-format-text.h | 56 +++++ gcc/diagnostic-format.h | 83 +++++++ gcc/diagnostic-global-context.cc | 1 + gcc/diagnostic.cc | 176 +-------------- gcc/diagnostic.h | 85 +------ gcc/gcc.cc | 1 + gcc/opts.cc | 1 + .../gcc.dg/plugin/diagnostic_group_plugin.c | 1 + 12 files changed, 359 insertions(+), 257 deletions(-) create mode 100644 gcc/diagnostic-format-text.cc create mode 100644 gcc/diagnostic-format-text.h create mode 100644 gcc/diagnostic-format.h diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 8fba8f7db6a2..68fda1a75918 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1821,6 +1821,7 @@ OBJS = \ OBJS-libcommon = diagnostic-spec.o diagnostic.o diagnostic-color.o \ diagnostic-format-json.o \ diagnostic-format-sarif.o \ + diagnostic-format-text.o \ diagnostic-global-context.o \ diagnostic-macro-unwinding.o \ diagnostic-path.o \ diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc index f2e9d0d79e51..c94f5f73bb5a 100644 --- a/gcc/diagnostic-format-json.cc +++ b/gcc/diagnostic-format-json.cc @@ -27,6 +27,7 @@ along with GCC; see the file COPYING3. If not see #include "selftest-diagnostic.h" #include "diagnostic-metadata.h" #include "diagnostic-path.h" +#include "diagnostic-format.h" #include "json.h" #include "selftest.h" #include "logical-location.h" diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc index 554bf3cb2d5c..59d9cd721839 100644 --- a/gcc/diagnostic-format-sarif.cc +++ b/gcc/diagnostic-format-sarif.cc @@ -29,6 +29,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic.h" #include "diagnostic-metadata.h" #include "diagnostic-path.h" +#include "diagnostic-format.h" #include "json.h" #include "cpplib.h" #include "logical-location.h" diff --git a/gcc/diagnostic-format-text.cc b/gcc/diagnostic-format-text.cc new file mode 100644 index 000000000000..b984803ff380 --- /dev/null +++ b/gcc/diagnostic-format-text.cc @@ -0,0 +1,209 @@ +/* Classic text-based output of diagnostics. + Copyright (C) 1999-2024 Free Software Foundation, Inc. + +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/>. */ + + +#include "config.h" +#define INCLUDE_VECTOR +#include "system.h" +#include "coretypes.h" +#include "version.h" +#include "intl.h" +#include "diagnostic.h" +#include "diagnostic-color.h" +#include "diagnostic-url.h" +#include "diagnostic-metadata.h" +#include "diagnostic-path.h" +#include "diagnostic-client-data-hooks.h" +#include "diagnostic-diagram.h" +#include "diagnostic-format-text.h" +#include "text-art/theme.h" + +/* class diagnostic_text_output_format : public diagnostic_output_format. */ + +diagnostic_text_output_format::~diagnostic_text_output_format () +{ + /* Some of the errors may actually have been warnings. */ + if (m_context.diagnostic_count (DK_WERROR)) + { + /* -Werror was given. */ + if (m_context.warning_as_error_requested_p ()) + pp_verbatim (m_context.printer, + _("%s: all warnings being treated as errors"), + progname); + /* At least one -Werror= was given. */ + else + pp_verbatim (m_context.printer, + _("%s: some warnings being treated as errors"), + progname); + pp_newline_and_flush (m_context.printer); + } +} + +/* Implementation of diagnostic_output_format::on_report_diagnostic vfunc + for GCC's standard textual output. */ + +void +diagnostic_text_output_format:: +on_report_diagnostic (const diagnostic_info &diagnostic, + diagnostic_t orig_diag_kind) +{ + (*diagnostic_starter (&m_context)) (&m_context, &diagnostic); + + pp_output_formatted_text (m_context.printer, m_context.get_urlifier ()); + + if (m_context.m_show_cwe) + print_any_cwe (diagnostic); + + if (m_context.m_show_rules) + print_any_rules (diagnostic); + + if (m_context.m_show_option_requested) + print_option_information (diagnostic, orig_diag_kind); + + (*diagnostic_finalizer (&m_context)) (&m_context, &diagnostic, + orig_diag_kind); +} + +void +diagnostic_text_output_format::on_diagram (const diagnostic_diagram &diagram) +{ + char *saved_prefix = pp_take_prefix (m_context.printer); + pp_set_prefix (m_context.printer, NULL); + /* Use a newline before and after and a two-space indent + to make the diagram stand out a little from the wall of text. */ + pp_newline (m_context.printer); + diagram.get_canvas ().print_to_pp (m_context.printer, " "); + pp_newline (m_context.printer); + pp_set_prefix (m_context.printer, saved_prefix); + pp_flush (m_context.printer); +} + +/* If DIAGNOSTIC has a CWE identifier, print it. + + For example, if the diagnostic metadata associates it with CWE-119, + " [CWE-119]" will be printed, suitably colorized, and with a URL of a + description of the security issue. */ + +void +diagnostic_text_output_format::print_any_cwe (const diagnostic_info &diagnostic) +{ + if (diagnostic.metadata == NULL) + return; + + int cwe = diagnostic.metadata->get_cwe (); + if (cwe) + { + pretty_printer * const pp = m_context.printer; + char *saved_prefix = pp_take_prefix (pp); + pp_string (pp, " ["); + const char *kind_color = diagnostic_get_color_for_kind (diagnostic.kind); + pp_string (pp, colorize_start (pp_show_color (pp), kind_color)); + if (pp->supports_urls_p ()) + { + char *cwe_url = get_cwe_url (cwe); + pp_begin_url (pp, cwe_url); + free (cwe_url); + } + pp_printf (pp, "CWE-%i", cwe); + pp_set_prefix (pp, saved_prefix); + if (pp->supports_urls_p ()) + pp_end_url (pp); + pp_string (pp, colorize_stop (pp_show_color (pp))); + pp_character (pp, ']'); + } +} + +/* If DIAGNOSTIC has any rules associated with it, print them. + + For example, if the diagnostic metadata associates it with a rule + named "STR34-C", then " [STR34-C]" will be printed, suitably colorized, + with any URL provided by the rule. */ + +void +diagnostic_text_output_format:: +print_any_rules (const diagnostic_info &diagnostic) +{ + if (diagnostic.metadata == NULL) + return; + + for (unsigned idx = 0; idx < diagnostic.metadata->get_num_rules (); idx++) + { + const diagnostic_metadata::rule &rule + = diagnostic.metadata->get_rule (idx); + if (char *desc = rule.make_description ()) + { + pretty_printer * const pp = m_context.printer; + char *saved_prefix = pp_take_prefix (pp); + pp_string (pp, " ["); + const char *kind_color + = diagnostic_get_color_for_kind (diagnostic.kind); + pp_string (pp, colorize_start (pp_show_color (pp), kind_color)); + char *url = NULL; + if (pp->supports_urls_p ()) + { + url = rule.make_url (); + if (url) + pp_begin_url (pp, url); + } + pp_string (pp, desc); + pp_set_prefix (pp, saved_prefix); + if (pp->supports_urls_p ()) + if (url) + pp_end_url (pp); + free (url); + pp_string (pp, colorize_stop (pp_show_color (pp))); + pp_character (pp, ']'); + free (desc); + } + } +} + +/* Print any metadata about the option used to control DIAGNOSTIC to CONTEXT's + printer, e.g. " [-Werror=uninitialized]". + Subroutine of diagnostic_context::report_diagnostic. */ + +void +diagnostic_text_output_format:: +print_option_information (const diagnostic_info &diagnostic, + diagnostic_t orig_diag_kind) +{ + if (char *option_text + = m_context.make_option_name (diagnostic.option_index, + orig_diag_kind, diagnostic.kind)) + { + char *option_url = nullptr; + pretty_printer * const pp = m_context.printer; + if (pp->supports_urls_p ()) + option_url = m_context.make_option_url (diagnostic.option_index); + pp_string (pp, " ["); + const char *kind_color = diagnostic_get_color_for_kind (diagnostic.kind); + pp_string (pp, colorize_start (pp_show_color (pp), kind_color)); + if (option_url) + pp_begin_url (pp, option_url); + pp_string (pp, option_text); + if (option_url) + { + pp_end_url (pp); + free (option_url); + } + pp_string (pp, colorize_stop (pp_show_color (pp))); + pp_character (pp, ']'); + free (option_text); + } +} diff --git a/gcc/diagnostic-format-text.h b/gcc/diagnostic-format-text.h new file mode 100644 index 000000000000..2db365e5d182 --- /dev/null +++ b/gcc/diagnostic-format-text.h @@ -0,0 +1,56 @@ +/* Classic text-based output of diagnostics. + Copyright (C) 2023-2024 Free Software Foundation, Inc. + Contributed by David Malcolm <dmalc...@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/>. */ + +#ifndef GCC_DIAGNOSTIC_FORMAT_TEXT_H +#define GCC_DIAGNOSTIC_FORMAT_TEXT_H + +#include "diagnostic-format.h" + +/* Subclass of diagnostic_output_format for classic text-based output + to stderr. + + Uses diagnostic_context.m_text_callbacks to provide client-specific + textual output (e.g. include paths, macro expansions, etc). */ + +class diagnostic_text_output_format : public diagnostic_output_format +{ +public: + diagnostic_text_output_format (diagnostic_context &context) + : diagnostic_output_format (context) + {} + ~diagnostic_text_output_format (); + void on_begin_group () override {} + void on_end_group () override {} + void on_report_diagnostic (const diagnostic_info &, + diagnostic_t orig_diag_kind) override; + void on_diagram (const diagnostic_diagram &diagram) override; + bool machine_readable_stderr_p () const final override + { + return false; + } + +private: + void print_any_cwe (const diagnostic_info &diagnostic); + void print_any_rules (const diagnostic_info &diagnostic); + void print_option_information (const diagnostic_info &diagnostic, + diagnostic_t orig_diag_kind); +}; + +#endif /* ! GCC_DIAGNOSTIC_FORMAT_TEXT_H */ diff --git a/gcc/diagnostic-format.h b/gcc/diagnostic-format.h new file mode 100644 index 000000000000..4a53949b2cdb --- /dev/null +++ b/gcc/diagnostic-format.h @@ -0,0 +1,83 @@ +/* Declarations for managing different output formats for diagnostics. + Copyright (C) 2023-2024 Free Software Foundation, Inc. + Contributed by David Malcolm <dmalc...@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/>. */ + +#ifndef GCC_DIAGNOSTIC_FORMAT_H +#define GCC_DIAGNOSTIC_FORMAT_H + +/* Abstract base class for a particular output format for diagnostics; + each value of -fdiagnostics-output-format= will have its own + implementation. */ + +class diagnostic_output_format +{ +public: + virtual ~diagnostic_output_format () {} + + virtual void on_begin_group () = 0; + virtual void on_end_group () = 0; + + /* Vfunc with responsibility for phase 3 of formatting the message + and "printing" the result. */ + virtual void on_report_diagnostic (const diagnostic_info &, + diagnostic_t orig_diag_kind) = 0; + + virtual void on_diagram (const diagnostic_diagram &diagram) = 0; + virtual bool machine_readable_stderr_p () const = 0; + +protected: + diagnostic_output_format (diagnostic_context &context) + : m_context (context) + {} + + diagnostic_context &m_context; +}; + +extern void +diagnostic_output_format_init (diagnostic_context &, + const char *main_input_filename_, + const char *base_file_name, + enum diagnostics_output_format, + bool json_formatting); +extern void +diagnostic_output_format_init_json_stderr (diagnostic_context &context, + bool formatted); +extern void +diagnostic_output_format_init_json_file (diagnostic_context &context, + bool formatted, + const char *base_file_name); +extern void +diagnostic_output_format_init_sarif_stderr (diagnostic_context &context, + const line_maps *line_maps, + const char *main_input_filename_, + bool formatted); +extern void +diagnostic_output_format_init_sarif_file (diagnostic_context &context, + const line_maps *line_maps, + const char *main_input_filename_, + bool formatted, + const char *base_file_name); +extern void +diagnostic_output_format_init_sarif_stream (diagnostic_context &context, + const line_maps *line_maps, + const char *main_input_filename_, + bool formatted, + FILE *stream); + +#endif /* ! GCC_DIAGNOSTIC_FORMAT_H */ diff --git a/gcc/diagnostic-global-context.cc b/gcc/diagnostic-global-context.cc index 497eb9e727ce..dc0741ec2ba5 100644 --- a/gcc/diagnostic-global-context.cc +++ b/gcc/diagnostic-global-context.cc @@ -27,6 +27,7 @@ along with GCC; see the file COPYING3. If not see #include "coretypes.h" #include "intl.h" #include "diagnostic.h" +#include "diagnostic-format.h" /* A diagnostic_context surrogate for stderr. */ static diagnostic_context global_diagnostic_context; diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index 497bbe79705c..381a050ab4c9 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -37,6 +37,8 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic-path.h" #include "diagnostic-client-data-hooks.h" #include "diagnostic-diagram.h" +#include "diagnostic-format.h" +#include "diagnostic-format-text.h" #include "edit-context.h" #include "selftest.h" #include "selftest-diagnostic.h" @@ -1678,180 +1680,6 @@ diagnostic_context::end_group () } } -/* class diagnostic_text_output_format : public diagnostic_output_format. */ - -diagnostic_text_output_format::~diagnostic_text_output_format () -{ - /* Some of the errors may actually have been warnings. */ - if (m_context.diagnostic_count (DK_WERROR)) - { - /* -Werror was given. */ - if (m_context.warning_as_error_requested_p ()) - pp_verbatim (m_context.printer, - _("%s: all warnings being treated as errors"), - progname); - /* At least one -Werror= was given. */ - else - pp_verbatim (m_context.printer, - _("%s: some warnings being treated as errors"), - progname); - pp_newline_and_flush (m_context.printer); - } -} - -/* Implementation of diagnostic_output_format::on_report_diagnostic vfunc - for GCC's standard textual output. */ - -void -diagnostic_text_output_format:: -on_report_diagnostic (const diagnostic_info &diagnostic, - diagnostic_t orig_diag_kind) -{ - (*diagnostic_starter (&m_context)) (&m_context, &diagnostic); - - pp_output_formatted_text (m_context.printer, m_context.get_urlifier ()); - - if (m_context.m_show_cwe) - print_any_cwe (diagnostic); - - if (m_context.m_show_rules) - print_any_rules (diagnostic); - - if (m_context.m_show_option_requested) - print_option_information (diagnostic, orig_diag_kind); - - (*diagnostic_finalizer (&m_context)) (&m_context, &diagnostic, - orig_diag_kind); -} - -void -diagnostic_text_output_format::on_diagram (const diagnostic_diagram &diagram) -{ - char *saved_prefix = pp_take_prefix (m_context.printer); - pp_set_prefix (m_context.printer, NULL); - /* Use a newline before and after and a two-space indent - to make the diagram stand out a little from the wall of text. */ - pp_newline (m_context.printer); - diagram.get_canvas ().print_to_pp (m_context.printer, " "); - pp_newline (m_context.printer); - pp_set_prefix (m_context.printer, saved_prefix); - pp_flush (m_context.printer); -} - -/* If DIAGNOSTIC has a CWE identifier, print it. - - For example, if the diagnostic metadata associates it with CWE-119, - " [CWE-119]" will be printed, suitably colorized, and with a URL of a - description of the security issue. */ - -void -diagnostic_text_output_format::print_any_cwe (const diagnostic_info &diagnostic) -{ - if (diagnostic.metadata == NULL) - return; - - int cwe = diagnostic.metadata->get_cwe (); - if (cwe) - { - pretty_printer * const pp = m_context.printer; - char *saved_prefix = pp_take_prefix (pp); - pp_string (pp, " ["); - pp_string (pp, colorize_start (pp_show_color (pp), - diagnostic_kind_color[diagnostic.kind])); - if (pp->supports_urls_p ()) - { - char *cwe_url = get_cwe_url (cwe); - pp_begin_url (pp, cwe_url); - free (cwe_url); - } - pp_printf (pp, "CWE-%i", cwe); - pp_set_prefix (pp, saved_prefix); - if (pp->supports_urls_p ()) - pp_end_url (pp); - pp_string (pp, colorize_stop (pp_show_color (pp))); - pp_character (pp, ']'); - } -} - -/* If DIAGNOSTIC has any rules associated with it, print them. - - For example, if the diagnostic metadata associates it with a rule - named "STR34-C", then " [STR34-C]" will be printed, suitably colorized, - with any URL provided by the rule. */ - -void -diagnostic_text_output_format:: -print_any_rules (const diagnostic_info &diagnostic) -{ - if (diagnostic.metadata == NULL) - return; - - for (unsigned idx = 0; idx < diagnostic.metadata->get_num_rules (); idx++) - { - const diagnostic_metadata::rule &rule - = diagnostic.metadata->get_rule (idx); - if (char *desc = rule.make_description ()) - { - pretty_printer * const pp = m_context.printer; - char *saved_prefix = pp_take_prefix (pp); - pp_string (pp, " ["); - pp_string (pp, - colorize_start (pp_show_color (pp), - diagnostic_kind_color[diagnostic.kind])); - char *url = NULL; - if (pp->supports_urls_p ()) - { - url = rule.make_url (); - if (url) - pp_begin_url (pp, url); - } - pp_string (pp, desc); - pp_set_prefix (pp, saved_prefix); - if (pp->supports_urls_p ()) - if (url) - pp_end_url (pp); - free (url); - pp_string (pp, colorize_stop (pp_show_color (pp))); - pp_character (pp, ']'); - free (desc); - } - } -} - -/* Print any metadata about the option used to control DIAGNOSTIC to CONTEXT's - printer, e.g. " [-Werror=uninitialized]". - Subroutine of diagnostic_context::report_diagnostic. */ - -void -diagnostic_text_output_format:: -print_option_information (const diagnostic_info &diagnostic, - diagnostic_t orig_diag_kind) -{ - if (char *option_text - = m_context.make_option_name (diagnostic.option_index, - orig_diag_kind, diagnostic.kind)) - { - char *option_url = nullptr; - pretty_printer * const pp = m_context.printer; - if (pp->supports_urls_p ()) - option_url = m_context.make_option_url (diagnostic.option_index); - pp_string (pp, " ["); - pp_string (pp, colorize_start (pp_show_color (pp), - diagnostic_kind_color[diagnostic.kind])); - if (option_url) - pp_begin_url (pp, option_url); - pp_string (pp, option_text); - if (option_url) - { - pp_end_url (pp); - free (option_url); - } - pp_string (pp, colorize_stop (pp_show_color (pp))); - pp_character (pp, ']'); - free (option_text); - } -} - /* Set the output format for CONTEXT to FORMAT, using BASE_FILE_NAME for file-based output formats. */ diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index 0a496e4bfab9..1d54e86dc089 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -196,64 +196,8 @@ class diagnostic_client_data_hooks; class logical_location; class diagnostic_diagram; class diagnostic_source_effect_info; - -/* Abstract base class for a particular output format for diagnostics; - each value of -fdiagnostics-output-format= will have its own - implementation. */ - -class diagnostic_output_format -{ -public: - virtual ~diagnostic_output_format () {} - - virtual void on_begin_group () = 0; - virtual void on_end_group () = 0; - - /* Vfunc with responsibility for phase 3 of formatting the message - and "printing" the result. */ - virtual void on_report_diagnostic (const diagnostic_info &, - diagnostic_t orig_diag_kind) = 0; - - virtual void on_diagram (const diagnostic_diagram &diagram) = 0; - virtual bool machine_readable_stderr_p () const = 0; - -protected: - diagnostic_output_format (diagnostic_context &context) - : m_context (context) - {} - - diagnostic_context &m_context; -}; - -/* Subclass of diagnostic_output_format for classic text-based output - to stderr. - - Uses diagnostic_context.m_text_callbacks to provide client-specific - textual output (e.g. include paths, macro expansions, etc). */ - -class diagnostic_text_output_format : public diagnostic_output_format -{ -public: - diagnostic_text_output_format (diagnostic_context &context) - : diagnostic_output_format (context) - {} - ~diagnostic_text_output_format (); - void on_begin_group () override {} - void on_end_group () override {} - void on_report_diagnostic (const diagnostic_info &, - diagnostic_t orig_diag_kind) override; - void on_diagram (const diagnostic_diagram &diagram) override; - bool machine_readable_stderr_p () const final override - { - return false; - } - -private: - void print_any_cwe (const diagnostic_info &diagnostic); - void print_any_rules (const diagnostic_info &diagnostic); - void print_option_information (const diagnostic_info &diagnostic, - diagnostic_t orig_diag_kind); -}; +class diagnostic_output_format; + class diagnostic_text_output_format; /* A stack of sets of classifications: each entry in the stack is a mapping from option index to diagnostic severity that can be changed @@ -1116,31 +1060,6 @@ extern char *file_name_as_prefix (diagnostic_context *, const char *); extern char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1; -extern void diagnostic_output_format_init (diagnostic_context &, - const char *main_input_filename_, - const char *base_file_name, - enum diagnostics_output_format, - bool json_formatting); -extern void diagnostic_output_format_init_json_stderr (diagnostic_context &context, - bool formatted); -extern void diagnostic_output_format_init_json_file (diagnostic_context &context, - bool formatted, - const char *base_file_name); -extern void diagnostic_output_format_init_sarif_stderr (diagnostic_context &context, - const line_maps *line_maps, - const char *main_input_filename_, - bool formatted); -extern void diagnostic_output_format_init_sarif_file (diagnostic_context &context, - const line_maps *line_maps, - const char *main_input_filename_, - bool formatted, - const char *base_file_name); -extern void diagnostic_output_format_init_sarif_stream (diagnostic_context &context, - const line_maps *line_maps, - const char *main_input_filename_, - bool formatted, - FILE *stream); - /* Compute the number of digits in the decimal representation of an integer. */ extern int num_digits (int); diff --git a/gcc/gcc.cc b/gcc/gcc.cc index abdb40bfe6e0..d07a8e172a47 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -40,6 +40,7 @@ compilation is specified by a string called a "spec". */ #include "opt-suggestions.h" #include "gcc.h" #include "diagnostic.h" +#include "diagnostic-format.h" #include "flags.h" #include "opts.h" #include "filenames.h" diff --git a/gcc/opts.cc b/gcc/opts.cc index 0b7b137c3763..b20c5da62933 100644 --- a/gcc/opts.cc +++ b/gcc/opts.cc @@ -32,6 +32,7 @@ along with GCC; see the file COPYING3. If not see #include "spellcheck.h" #include "opt-suggestions.h" #include "diagnostic-color.h" +#include "diagnostic-format.h" #include "version.h" #include "selftest.h" #include "file-prefix-map.h" diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.c index e9d4b7276ccd..a47fff715990 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.c @@ -27,6 +27,7 @@ #include "plugin-version.h" #include "c-family/c-common.h" #include "diagnostic.h" +#include "diagnostic-format-text.h" #include "context.h" int plugin_is_GPL_compatible; -- 2.26.3