aboutsummaryrefslogtreecommitdiff
path: root/gcc/diagnostic-format-text.h
AgeCommit message (Collapse)AuthorFilesLines
2025-01-02Update copyright years.Jakub Jelinek1-1/+1
2024-12-16diagnostics: move libgdiagnostics dc from sinks into diagnostic_managerDavid Malcolm1-0/+15
libgdiagnostics was written before the fixes for PR other/116613 allowed a diagnostic_context to have multiple output sinks. Hence each libgdiagnostics sink had its own diagnostic_context with just one diagnostic_output_format. This wart is no longer necessary and makes it harder to move state into the manager/context; in particular for quoting source code from the .sarif file (PR sarif-replay/117943). Simplify, by making libgdiagnostics' implementation more similar to GCC's implementation, by moving the diagnostic_context from sink into diagnostic_manager. Doing so requires generalizing where the diagnostic_source_printing_options comes from in class diagnostic_text_output_format: for GCC we use the instance within the diagnostic_context, whereas for libgdiagnostics each diagnostic_text_sink has its own instance. No functional change intended. gcc/c-family/ChangeLog: PR sarif-replay/117943 * c-format.cc (selftest::test_type_mismatch_range_labels): Use dc.m_source_printing. * c-opts.cc (c_diagnostic_text_finalizer): Use source-printing options from text_output. gcc/cp/ChangeLog: PR sarif-replay/117943 * error.cc (auto_context_line::~auto_context_line): Use source-printing options from text_output. gcc/ChangeLog: PR sarif-replay/117943 * diagnostic-format-text.cc (diagnostic_text_output_format::append_note): Use source-printing options from text_output. (diagnostic_text_output_format::update_printer): Copy source-printing options from dc. (default_diagnostic_text_finalizer): Use source-printing options from text_output. * diagnostic-format-text.h (diagnostic_text_output_format::diagnostic_text_output_format): Add optional diagnostic_source_printing_options param, using the context's if null. (diagnostic_text_output_format::get_source_printing_options): New accessor. (diagnostic_text_output_format::m_source_printing): New field. * diagnostic-path.cc (event_range::print): Use source-printing options from text_output. (selftest::test_interprocedural_path_1): Use source-printing options from dc. * diagnostic-show-locus.cc (gcc_rich_location::add_location_if_nearby): Likewise. (diagnostic_context::maybe_show_locus): Add "opts" param and use in place of m_source_printing. Pass it to source_policy ctor. (diagnostic_source_print_policy::diagnostic_source_print_policy): Add overload taking a const diagnostic_source_printing_options &. * diagnostic.cc (diagnostic_context::initialize): Pass nullptr for source options when creating text sink, so that it uses the dc's options. (diagnostic_context::dump): Add an "output sinks:" heading and print "(none)" if there aren't any. (diagnostic_context::set_output_format): Split out code into... (diagnostic_context::remove_all_output_sinks): ...this new function. * diagnostic.h (diagnostic_source_print_policy::diagnostic_source_print_policy): Add overload taking a const diagnostic_source_printing_options &. (diagnostic_context::maybe_show_locus): Add "opts" param. (diagnostic_context::remove_all_output_sinks): New decl. (diagnostic_context::m_source_printing): New field. (diagnostic_show_locus): Add "opts" param and pass to maybe_show_locus. * libgdiagnostics.cc (sink::~sink): Delete. (sink::begin_group): Delete. (sink::end_group): Delete. (sink::emit): Delete. (sink::m_dc): Drop field. (diagnostic_text_sink::on_begin_text_diagnostic): Delete. (diagnostic_text_sink::get_source_printing_options): Use m_souece_printing. (diagnostic_text_sink::m_current_logical_loc): Drop field. (diagnostic_text_sink::m_inner_sink): New field. (diagnostic_text_sink::m_source_printing): New field. (diagnostic_manager::diagnostic_manager): Update for changes to fields. Initialize m_dc. (diagnostic_manager::~diagnostic_manager): Call diagnostic_finish. (diagnostic_manager::get_file_cache): Drop. (diagnostic_manager::get_dc): New accessor. (diagnostic_manager::begin_group): Reimplement. (diagnostic_manager::end_group): Reimplement. (diagnostic_manager::get_prev_diag_logical_loc): New accessor. (diagnostic_manager::m_dc): New field. (diagnostic_manager::m_file_cache): Drop field. (diagnostic_manager::m_edit_context): Convert to a std::unique_ptr so that object can be constructed after m_dc is initialized. (diagnostic_manager::m_prev_diag_logical_loc): New field. (diagnostic_text_sink::diagnostic_text_sink): Reimplement. (get_color_rule): Delete. (diagnostic_text_sink::set_colorize): Reimplement. (diagnostic_text_sink::text_starter): New. (sarif_sink::sarif_sink): Reimplement. (diagnostic_manager::write_patch): Update for change to m_edit_context. (diagnostic_manager::emit): Update now that each sink has a corresponding diagnostic_output_format object within m_dc. gcc/fortran/ChangeLog: PR sarif-replay/117943 * error.cc (gfc_diagnostic_text_starter): Use source-printing options from text_output. gcc/testsuite/ChangeLog: PR sarif-replay/117943 * gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc (custom_diagnostic_text_finalizer): Use source-printing options from text_output. * gcc.dg/plugin/diagnostic_plugin_xhtml_format.cc (xhtml_builder::make_element_for_diagnostic): Use source-printing options from diagnostic_context. * gcc.dg/plugin/expensive_selftests_plugin.cc (test_richloc): Likewise. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-11-18Add libdiagnostics (v4)David Malcolm1-1/+2
This patch adds a new libdiagnostics shared library available as part of the GCC build via --enable-libdiagnostics when configuring GCC. It combines the following patches from: https://gcc.gnu.org/pipermail/gcc-patches/2024-November/668632.html [PATCH 1/8] libdiagnostics v4: header [PATCH 2/8] libdiagnostics v4: implementation [PATCH 3/8] libdiagnostics: add API docs [PATCH 4/8] libdiagnostics v4: add C++ wrapper API [PATCH 6/8] libdiagnostics v4: test suite ChangeLog: * configure.ac (--enable-libdiagnostics): New. * configure: Regenerate. gcc/ChangeLog: * configure.ac (check_languages): Add check-libdiagnostics. (--enable-libdiagnostics): New. * configure: Regenerate. * Makefile.in (enable_libdiagnostics): New. (lang_checks): If libdiagnostics is enabled, add check-libdiagnostics. (ALL_HOST_OBJS): If libdiagnostics is enabled, add $(libdiagnostics_OBJS). (start.encap): Add LIBDIAGNOSTICS. (libdiagnostics_OBJS): New. (LIBDIAGNOSTICS_VERSION_NUM): New, adapted from code in jit/Make-lang.in. (LIBDIAGNOSTICS_MINOR_NUM): Likewise. (LIBDIAGNOSTICS_RELEASE_NUM): Likewise. (LIBDIAGNOSTICS_FILENAME): Likewise. (LIBDIAGNOSTICS_IMPORT_LIB): Likewise. (libdiagnostics): Likewise. (LIBDIAGNOSTICS_AGE): Likewise. (LIBDIAGNOSTICS_BASENAME): Likewise. (LIBDIAGNOSTICS_SONAME): Likewise. (LIBDIAGNOSTICS_LINKER_NAME): Likewise. (LIBDIAGNOSTICS_COMMA): Likewise. (LIBDIAGNOSTICS_VERSION_SCRIPT_OPTION): Likewise. (LIBDIAGNOSTICS_SONAME_OPTION): Likewise. (LIBDIAGNOSTICS_SONAME_SYMLINK): Likewise. (LIBDIAGNOSTICS_LINKER_NAME_SYMLINK): Likewise. (LIBDIAGNOSTICS_FILENAME): Likewise. (libdiagnostics.serial): Likewise. (LIBDIAGNOSTICS_EXTRA_OPTS): Likewise. (install): If libdiagnostics is enabled, add install-libdiagnostics. (libdiagnostics.install-headers): New. (libdiagnostics.install-common): New, adapted from code in jit/Make-lang.in. (install-libdiagnostics): New. * diagnostic-format-text.h (diagnostic_text_output_format::get_location_text): Make public. * doc/install.texi (--enable-libdiagnostics): New. * doc/libdiagnostics/Makefile: New file. * doc/libdiagnostics/conf.py: New file. * doc/libdiagnostics/index.rst: New file. * doc/libdiagnostics/make.bat: New file. * doc/libdiagnostics/topics/diagnostic-manager.rst: New file. * doc/libdiagnostics/topics/diagnostics.rst: New file. * doc/libdiagnostics/topics/execution-paths.rst: New file. * doc/libdiagnostics/topics/fix-it-hints.rst: New file. * doc/libdiagnostics/topics/index.rst: New file. * doc/libdiagnostics/topics/logical-locations.rst: New file. * doc/libdiagnostics/topics/message-formatting.rst: New file. * doc/libdiagnostics/topics/metadata.rst: New file. * doc/libdiagnostics/topics/physical-locations.rst: New file. * doc/libdiagnostics/topics/retrofitting.rst: New file. * doc/libdiagnostics/topics/sarif.rst: New file. * doc/libdiagnostics/topics/text-output.rst: New file. * doc/libdiagnostics/topics/ux.rst: New file. * doc/libdiagnostics/tutorial/01-hello-world.rst: New file. * doc/libdiagnostics/tutorial/02-physical-locations.rst: New file. * doc/libdiagnostics/tutorial/03-logical-locations.rst: New file. * doc/libdiagnostics/tutorial/04-notes.rst: New file. * doc/libdiagnostics/tutorial/05-warnings.rst: New file. * doc/libdiagnostics/tutorial/06-fix-it-hints.rst: New file. * doc/libdiagnostics/tutorial/07-execution-paths.rst: New file. * doc/libdiagnostics/tutorial/index.rst: New file. * libdiagnostics++.h: New file. * libdiagnostics.cc: New file. * libdiagnostics.h: New file. * libdiagnostics.map: New file. gcc/testsuite/ChangeLog: * libdiagnostics.dg/libdiagnostics.exp: New, adapted from jit.exp. * libdiagnostics.dg/sarif.py: New. * libdiagnostics.dg/test-dump.c: New test. * libdiagnostics.dg/test-error-c.py: New test. * libdiagnostics.dg/test-error-with-note-c.py: New test. * libdiagnostics.dg/test-error-with-note.c: New test. * libdiagnostics.dg/test-error-with-note.cc: New test. * libdiagnostics.dg/test-error.c: New test. * libdiagnostics.dg/test-error.cc: New test. * libdiagnostics.dg/test-example-1.c: New test. * libdiagnostics.dg/test-fix-it-hint-c.py: New test. * libdiagnostics.dg/test-fix-it-hint.c: New test. * libdiagnostics.dg/test-fix-it-hint.cc: New test. * libdiagnostics.dg/test-helpers++.h: New test. * libdiagnostics.dg/test-helpers.h: New test. * libdiagnostics.dg/test-labelled-ranges.c: New test. * libdiagnostics.dg/test-labelled-ranges.cc: New test. * libdiagnostics.dg/test-labelled-ranges.py: New test. * libdiagnostics.dg/test-logical-location-c.py: New test. * libdiagnostics.dg/test-logical-location.c: New test. * libdiagnostics.dg/test-metadata-c.py: New test. * libdiagnostics.dg/test-metadata.c: New test. * libdiagnostics.dg/test-multiple-lines-c.py: New test. * libdiagnostics.dg/test-multiple-lines.c: New test. * libdiagnostics.dg/test-no-column-c.py: New test. * libdiagnostics.dg/test-no-column.c: New test. * libdiagnostics.dg/test-no-diagnostics-c.py: New test. * libdiagnostics.dg/test-no-diagnostics.c: New test. * libdiagnostics.dg/test-note-with-fix-it-hint-c.py: New test. * libdiagnostics.dg/test-note-with-fix-it-hint.c: New test. * libdiagnostics.dg/test-text-sink-options.c: New test. * libdiagnostics.dg/test-warning-c.py: New test. * libdiagnostics.dg/test-warning-with-path-c.py: New test. * libdiagnostics.dg/test-warning-with-path.c: New test. * libdiagnostics.dg/test-warning.c: New test. * libdiagnostics.dg/test-write-sarif-to-file-c.py: New test. * libdiagnostics.dg/test-write-sarif-to-file.c: New test. * libdiagnostics.dg/test-write-text-to-file.c: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-11-18diagnostics: add support for nested diagnostics [PR116253]David Malcolm1-1/+33
Previously the diagnostic subsystem supported a one-deep hierarchy via auto_diagnostic_group, for associating notes with the warning/error they annotate; this only affects SARIF output, not text output. This patch adds support to the diagnostics subsystem for capturing arbitrarily deep nesting structure within diagnostic messages. This patch: * adds the ability to express nesting internally when building diagnostics * captures the nesting in SARIF output in the form documented in SG15's P3358R0 ("SARIF for Structured Diagnostics") via a "nestingLevel" property * adds a new experimental mode to text output to see the hierarchy, via: -fdiagnostics-set-output=text:experimental-nesting=yes * adds test coverage via a plugin, which with the above option emits: • note: child 0 • note: grandchild 0 0 • note: grandchild 0 1 • note: grandchild 0 2 • note: child 1 • note: grandchild 1 0 • note: grandchild 1 1 • note: grandchild 1 2 • note: child 2 • note: grandchild 2 0 • note: grandchild 2 1 • note: grandchild 2 2 using '*' rather than '•' if the text_art::theme is ascii-only. My hope is to eventually: (a) use this to improve C++'s template diagnostics (b) remove the "experimental" caveat from the the text output mode but this patch doesn't touch the C++ frontend, leaving both of these to followup work. gcc/c-family/ChangeLog: PR other/116253 * c-opts.cc (c_diagnostic_text_finalizer): Use text_output.build_indent_prefix for prefix to diagnostic_show_locus. gcc/ChangeLog: PR other/116253 * diagnostic-core.h (class auto_diagnostic_nesting_level): New. * diagnostic-format-sarif.cc (class sarif_builder): Update leading comment re nesting of diagnostics. (sarif_result::on_nested_diagnostic): Add nestingLevel property. * diagnostic-format-text.cc (on_report_diagnostic): If we're showing nested diagnostics, then print changes of location on a new line, indented, and update m_last_location. (diagnostic_text_output_format::build_prefix): If m_show_nesting, then potentially add indentation and a bullet point. (get_bullet_point_unichar): New. (use_unicode_p): New. (diagnostic_text_output_format::build_indent_prefix): New. * diagnostic-format-text.h (diagnostic_text_output_format::diagnostic_text_output_format): Initialize m_show_nesting and m_show_nesting_levels. (diagnostic_text_output_format::build_indent_prefix): New decl. (diagnostic_text_output_format::show_nesting_p): New accessor (diagnostic_text_output_format::show_locations_in_nesting_p): Likewise. (diagnostic_text_output_format::set_show_nesting): New. (diagnostic_text_output_format::set_show_locations_in_nesting): New. (diagnostic_text_output_format::set_show_nesting_levels): New. (diagnostic_text_output_format::m_show_nesting): New field. (diagnostic_text_output_format::m_show_locations_in_nesting): New field. (diagnostic_text_output_format::m_show_nesting_levels): New field. * diagnostic-global-context.cc (auto_diagnostic_nesting_level::auto_diagnostic_nesting_level): New. (auto_diagnostic_nesting_level::~auto_diagnostic_nesting_level): New. * diagnostic-show-locus.cc (layout_printer::print): Temporarily set DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE. * diagnostic.cc (diagnostic_context::initialize): Update for renaming of m_nesting_depth to m_group_nesting_depth and initialize m_diagnostic_nesting_level. (diagnostic_context::finish): Update for renaming of m_nesting_depth to m_group_nesting_depth. (diagnostic_context::report_diagnostic): Likewise. (diagnostic_context::begin_group): Likewise. (diagnostic_context::end_group): Likewise. (diagnostic_context::push_nesting_level): New. (diagnostic_context::pop_nesting_level): New. (diagnostic_context::set_diagnostic_buffer): Update for renaming of m_nesting_depth to m_group_nesting_depth. Assert that we don't have nested diagnostics. * diagnostic.h (diagnostic_context::push_nesting_level): New decl. (diagnostic_context::pop_nesting_level): New decl. (diagnostic_context::get_diagnostic_nesting_level): New accessor. (diagnostic_context::build_indent_prefix): New decl. (diagnostic_context::m_diagnostic_groups): Rename m_nesting_depth to m_group_nesting_depth and add field m_diagnostic_nesting_level. * doc/invoke.texi (fdiagnostics-add-output): Add note about "experimental" schemes, keys, and values. Add keys "experimental-nesting", "experimental-nesting-show-locations", and "experimental-nesting-show-levels" to text scheme. * opts-diagnostic.cc (text_scheme_handler::make_sink): Add keys "experimental-nesting", "experimental-nesting-show-locations", and "experimental-nesting-show-levels". gcc/testsuite/ChangeLog: PR other/116253 * gcc.dg/plugin/diagnostic-test-nesting-sarif.c: New test. * gcc.dg/plugin/diagnostic-test-nesting-sarif.py: New test. * gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c: New test. * gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c: New test. * gcc.dg/plugin/diagnostic-test-nesting-text-indented.c: New test. * gcc.dg/plugin/diagnostic-test-nesting-text-plain.c: New test. * gcc.dg/plugin/diagnostic_plugin_test_nesting.c: New test plugin. * gcc.dg/plugin/plugin.exp: Add the above. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-10-29diagnostics: support multiple output formats simultaneously [PR116613]David Malcolm1-4/+18
This patch generalizes diagnostic_context so that rather than having a single output format, it has a vector of zero or more. It adds new two options: -fdiagnostics-add-output=DIAGNOSTICS-OUTPUT-SPEC -fdiagnostics-set-output=DIAGNOSTICS-OUTPUT-SPEC which both take a new configuration syntax of the form SCHEME ("text" or "sarif"), optionally followed by ":" and one or more KEY=VALUE pairs, in this form: <SCHEME> <SCHEME>:<KEY>=<VALUE> <SCHEME>:<KEY>=<VALUE>,<KEY2>=<VALUE2> ...etc where each SCHEME supports some set of keys. For example, it's now possible to use: -fdiagnostics-add-output=sarif:version=2.1,file=foo.2.1.sarif \ -fdiagnostics-add-output=sarif:version=2.2-prerelease,file=foo.2.2.sarif to add a pair of outputs, each writing to a different file, using versions 2.1 and 2.2 of the SARIF standard respectively, whilst also emitting the classic text form of the diagnostics to stderr. I hope the new syntax gives us room to potentially add new kinds of output sink in the future (e.g. RPC notifications), and to add new key/value pairs as needed by the different sinks. Implementation-wise, the diagnostic_context's m_printer which previously was used directly by the single output format now becomes a "reference printer", created by the client (such as the frontend), with defaults modified by command-line options. Each of the multiple output sinks has its own pretty_printer instance, created by cloning the context's reference printer. gcc/ChangeLog: PR other/116613 * Makefile.in (OBJS-libcommon-target): Add opts-diagnostic.o. * common.opt (fdiagnostics-add-output=): New. (fdiagnostics-set-output=): New. (diagnostics_output_format): Drop sarif-file-2.2-prerelease from enum. * common.opt.urls: Regenerate. * diagnostic-buffer.h (diagnostic_buffer::~diagnostic_buffer): New. (diagnostic_buffer::ensure_per_format_buffer): Rename to... (diagnostic_buffer::ensure_per_format_buffers): ...this. (diagnostic_buffer::m_per_format_buffer): Replace with... (diagnostic_buffer::m_per_format_buffers): ...this, updating type. * diagnostic-format-json.cc (json_output_format::update_printer): New. (json_output_format::follows_reference_printer_p): New. (diagnostic_output_format_init_json): Drop redundant call to set_path_format, as this is not a text output format. * diagnostic-format-sarif.cc: Include "diagnostic-format-text.h". (sarif_builder::set_printer): New. (sarif_builder::sarif_builder): Add "printer" param and use it for m_printer. (sarif_builder::make_location_object::escape_nonascii_renderer::render): Rather than using dc.m_printer, create a diagnostic_text_output_format instance and use its printer. (sarif_output_format::follows_reference_printer_p): New. (sarif_output_format::update_printer): New. (sarif_output_format::sarif_output_format): Pass in correct printer to m_builder's ctor. (diagnostic_output_format_init_sarif): Drop redundant call to set_path_format, as this is not a text output format. Replace calls to pp_show_color and set_token_printer with call to update_printer. Drop redundant call to set_show_highlight_colors, as this printer does not show colors. (diagnostic_output_format_init_sarif_file): Split out file opening into... (diagnostic_output_format_open_sarif_file): ...this new function. (make_sarif_sink): New. (selftest::test_make_location_object): Provide a pp for the builder. * diagnostic-format-sarif.h (diagnostic_output_format_open_sarif_file): New decl. (make_sarif_sink): New decl. * diagnostic-format-text.cc (diagnostic_text_output_format::dump): Dump sm_follows_reference_printer. (diagnostic_text_output_format::on_report_verbatim): New. (diagnostic_text_output_format::follows_reference_printer_p): New. (diagnostic_text_output_format::update_printer): New. * diagnostic-format-text.h (diagnostic_text_output_format::diagnostic_text_output_format): Add optional "follows_reference_printer" param. (diagnostic_text_output_format::on_report_verbatim): New decl. (diagnostic_text_output_format::after_diagnostic): Drop "final". (diagnostic_text_output_format::follows_reference_printer_p): New decl. (class diagnostic_text_output_format): Convert private members to protected. (diagnostic_text_output_format::m_follows_reference_printer): New field. * diagnostic-format.h (diagnostic_output_format::on_report_verbatim): New vfunc. (diagnostic_output_format::follows_reference_printer_p): New vfunc. (diagnostic_output_format::update_printer): New vfunc. (diagnostic_output_format::get_printer): Use m_printer rather than a printer from m_context. (diagnostic_output_format::diagnostic_output_format): Initialize m_printer by cloning the context's printer. (diagnostic_output_format::m_printer): New field. * diagnostic-global-context.cc (verbatim): Reimplement in terms of global_dc->report_verbatim, moving existing implementation to diagnostic_text_output_format::on_report_verbatim. (fnotice): Support multiple output sinks by using a new global_dc->supports_fnotice_on_stderr_p. * diagnostic-output-file.h (diagnostic_output_file::diagnostic_output_file): New default ctor. (diagnostic_output_file::operator=): Implement move assignment. * diagnostic-path.cc (selftest::test_interprocedural_path_1): Pass false for new param of text_output's ctor. * diagnostic-show-locus.cc (selftest::test_layout_x_offset_display_utf8): Use reference printer. (selftest::test_layout_x_offset_display_tab): Likewise. (selftest::test_one_liner_fixit_remove): Likewise. * diagnostic.cc: Include "pretty-print-urlifier.h". (diagnostic_set_caret_max_width): Update for global_dc's m_printer becoming reference printer. (diagnostic_context::initialize): Update for m_printer becoming m_reference_printer. Use ::make_unique to create it. Update for m_output_format becoming m_output_sinks. (diagnostic_context::color_init): Update the reference printer, then update the printers for any output sinks that follow it. (diagnostic_context::urls_init): Likewise. (diagnostic_context::finish): Update comment. Update for m_output_format becoming m_output_sinks. Update for m_printer becoming m_reference_printer and use "delete" on it rather than XDELETE. (diagnostic_context::dump): Update for m_printer becoming reference printer, and for multiple output sinks. (diagnostic_context::set_output_format): Reimplement for supporting multiple output sinks. (diagnostic_context::get_output_format): Likewise. (diagnostic_context::add_sink): New. (diagnostic_context::supports_fnotice_on_stderr_p): New. (diagnostic_context::set_pretty_printer): New. (diagnostic_context::refresh_output_sinks): New. (diagnostic_context::set_format_decoder): New. (diagnostic_context::set_show_highlight_colors): New. (diagnostic_context::set_prefixing_rule): New. (diagnostic_context::report_diagnostic): Update to support multiple output sinks. (diagnostic_context::report_verbatim): New. (diagnostic_context::emit_diagram): Update to support multiple output sinks. (diagnostic_context::error_recursion): Update to use m_reference_printer. (fancy_abort): Likewise. (diagnostic_context::end_group): Update to support multiple output sinks. (diagnostic_output_format::dump): Implement. (diagnostic_output_format::on_report_verbatim): Likewise. (diagnostic_output_format_init): Drop DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE_2_2_PRERELEASE. (diagnostic_context::set_diagnostic_buffer): Reimplement to support multiple output sinks. (diagnostic_context::clear_diagnostic_buffer): Likewise. (diagnostic_context::flush_diagnostic_buffer): Likewise. (diagnostic_buffer::diagnostic_buffer): Initialize m_per_format_buffers. (diagnostic_buffer::~diagnostic_buffer): New dtor. (diagnostic_buffer::dump): Reimplement to support multiple output sinks. (diagnostic_buffer::empty_p): Likewise. (diagnostic_buffer::move_to): Likewise. (diagnostic_buffer::ensure_per_format_buffer): Likewise, renaming to... (diagnostic_buffer::ensure_per_format_buffers): ...this. * diagnostic.h (DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE_2_2_PRERELEASE): Delete. (class diagnostic_context): Add friend class diagnostic_buffer. (diagnostic_context::set_pretty_printer): New decl. (diagnostic_context::refresh_output_sinks): New decl. (diagnostic_context::report_verbatim): New decl. (diagnostic_context::get_output_format): Drop. (diagnostic_context::set_show_highlight_colors): Drop body. (diagnostic_context::set_format_decoder): New decl. (diagnostic_context::set_prefixing_rule): New decl. (diagnostic_context::clone_printer): Reimplement. (diagnostic_context::get_reference_printer): New accessor. (diagnostic_context::add_sink): New decl. (diagnostic_context::supports_fnotice_on_stderr_p): New decl. (diagnostic_context::m_printer): Replace with... (diagnostic_context::m_reference_printer): ...this, and make private. (diagnostic_context::m_output_format): Replace with... (diagnostic_context::m_output_sinks): ...this. (diagnostic_format_decoder): Delete. (diagnostic_prefixing_rule): Delete. (diagnostic_ready_p): Delete. * doc/invoke.texi: Document -fdiagnostics-add-output= and -fdiagnostics-set-output=. * gcc.cc: Include "opts-diagnostic.h". (driver_handle_option): Handle cases OPT_fdiagnostics_add_output_ and OPT_fdiagnostics_set_output_. * opts-diagnostic.cc: New file. * opts-diagnostic.h (handle_OPT_fdiagnostics_add_output_): New decl. (handle_OPT_fdiagnostics_set_output_): New decl. * opts-global.cc (init_options_once): Update for global_dc's m_printer becoming reference printer. Call global_dc->refresh_output_sinks. * opts.cc (common_handle_option): Replace use of diagnostic_prefixing_rule with dc->set_prefixing_rule. Handle cases OPT_fdiagnostics_add_output_ and OPT_fdiagnostics_set_output_. Update for m_printer becoming reference printer. * selftest-diagnostic.cc (selftest::test_diagnostic_context::test_diagnostic_context): Update for m_printer becoming reference printer. (test_diagnostic_context::test_show_locus): Likewise. * selftest-run-tests.cc (selftest::run_tests): Call selftest::opts_diagnostic_cc_tests. * selftest.h (selftest::opts_diagnostic_cc_tests): New decl. * simple-diagnostic-path.cc (selftest::simple_diagnostic_path_cc_tests): Use reference printer. * toplev.cc (announce_function): Update for global_dc's m_printer becoming reference printer. (toplev::main): Likewise. * tree-diagnostic.cc (tree_diagnostics_defaults): Replace use of diagnostic_format_decoder with context->set_format_decoder. * tree-diagnostic.h (tree_dump_pretty_printer::tree_dump_pretty_printer): Update for global_dc's m_printer becoming reference printer. * tree.cc (escaped_string::escape): Likewise. (selftest::test_escaped_strings): Likewise. gcc/ada/ChangeLog: PR other/116613 * gcc-interface/misc.cc (internal_error_function): Update for m_printer becoming reference printer. gcc/analyzer/ChangeLog: PR other/116613 * analyzer-language.cc (on_finish_translation_unit): Update for m_printer becoming reference printer. * engine.cc (run_checkers): Likewise. * program-point.cc (function_point::print_source_line): Likewise. gcc/c-family/ChangeLog: PR other/116613 * c-format.cc (selftest::test_type_mismatch_range_labels): Update for m_printer becoming reference printer. (selftest::test_type_mismatch_range_labels): Likewise. gcc/c/ChangeLog: PR other/116613 * c-objc-common.cc: Include "make-unique.h". (c_initialize_diagnostics): Use unique_ptr for pretty_printer. Use context->set_format_decoder. gcc/cp/ChangeLog: PR other/116613 * error.cc (cxx_initialize_diagnostics): Use unique_ptr for pretty_printer. Use context->set_format_decoder. * module.cc (noisy_p): Update for global_dc's m_printer becoming reference printer. gcc/d/ChangeLog: PR other/116613 * d-diagnostic.cc (d_diagnostic_report_diagnostic): Update for m_printer becoming reference printer. gcc/fortran/ChangeLog: PR other/116613 * error.cc (gfc_diagnostic_build_kind_prefix): Update for global_dc's m_printer becoming reference printer. (gfc_diagnostics_init): Replace usage of diagnostic_format_decoder with global_dc->set_format_decoder. gcc/jit/ChangeLog: PR other/116613 * dummy-frontend.cc: Include "make-unique.h". (class jit_diagnostic_listener): New. (jit_begin_diagnostic): Update comment. (jit_end_diagnostic): Drop call to add_diagnostic. (jit_langhook_init): Set the output format to a new jit_diagnostic_listener. * jit-playback.cc (playback::context::add_diagnostic): Add "text" param and use that rather than trying to get the text from a pretty_printer. * jit-playback.h (playback::context::add_diagnostic): Add "text" param. gcc/testsuite/ChangeLog: PR other/116613 * gcc.dg/plugin/analyzer_cpython_plugin.c (dump_refcnt_info): Update for global_dc's m_printer becoming reference printer. * gcc.dg/plugin/crash-test-ice-in-header-sarif-2.2.c: Replace usage of -fdiagnostics-format=sarif-file-2.2-prerelease with -fdiagnostics-set-output=sarif:version=2.2-prerelease. * gcc.dg/plugin/diagnostic_plugin_test_paths.c: Update for global_dc's m_printer becoming reference printer. * gcc.dg/plugin/diagnostic_plugin_xhtml_format.c: Update for changes to output formats. * gcc.dg/plugin/expensive_selftests_plugin.c: Update for global_dc's m_printer becoming reference printer. * gcc.dg/sarif-output/add-output-sarif-defaults.c: New test. * gcc.dg/sarif-output/bad-binary-op.c: New test. * gcc.dg/sarif-output/bad-binary-op.py: New support script. * gcc.dg/sarif-output/multiple-outputs.c: New test. * gcc.dg/sarif-output/multiple-outputs.py: New support script. * lib/scansarif.exp (verify-sarif-file): Add an optional second argument specifying the expected filename of the .sarif file. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-10-24Use unique_ptr in more places in pretty_printer/diagnostics [PR116613]David Malcolm1-1/+2
My forthcoming patches for PR other/116613 make much more use of cloning of pretty_printers than before, so it makes sense as a preliminary patch for the result of pretty_printer::clone to be a std::unique_ptr, rather than add more manual uses of "delete". On doing so, I noticed various other places where naked new/delete is used for run-time configuration of diagnostics: * the output format (text vs SARIF) * client data hooks * the option manager * the URLifier Hence this patch also makes use of std::unique_ptr and ::make_unique for managing such client policy classes, and also for diagnostic_buffer's per-format implementations. Unfortunately we can't directly include <memory> in our internal headers but instead any of our TUs that make use of std::unique_ptr must #define INCLUDE_MEMORY before including system.h. Hence the bulk of this patch is taken up with adding a define of INCLUDE_MEMORY to hundreds of source files: everything that includes diagnostic.h or pretty-print.h (and thus anything transitively such as includers of lto-wrapper.h, c-tree.h, cp-tree.h and rtl-ssa.h). Thanks to Gaius Mulley for the parts of the patch that regenerated the m2 files. gcc/ada/ChangeLog: PR other/116613 * gcc-interface/misc.cc: Add #define INCLUDE_MEMORY * gcc-interface/trans.cc: Likewise. * gcc-interface/utils.cc: Likewise. gcc/analyzer/ChangeLog: PR other/116613 * analyzer-logging.cc: Add #define INCLUDE_MEMORY (logger::logger): Update for m_pp becoming a unique_ptr. (logger::~logger): Likewise. (logger::log_va_partial): Likewise. (logger::end_log_line): Likewise. * analyzer-logging.h (logger::get_printer): Likewise. (logger::m_pp): Convert to a unique_ptr. * analyzer.cc (make_label_text): Use diagnostic_context::clone_printer and use unique_ptr. (make_label_text_n): Likewise. * bar-chart.cc: Add #define INCLUDE_MEMORY * pending-diagnostic.cc (evdesc::event_desc::formatted_print): Use diagnostic_context::clone_printer and use unique_ptr. * sm-malloc.cc (sufficiently_similar_p): Likewise. * supergraph.cc (supergraph::dump_dot_to_file): Likewise. gcc/c-family/ChangeLog: PR other/116613 * c-ada-spec.cc: Add #define INCLUDE_MEMORY. * c-attribs.cc: Likewise. * c-common.cc: Likewise. * c-format.cc: Likewise. * c-gimplify.cc: Likewise. * c-indentation.cc: Likewise. * c-opts.cc: Likewise. * c-pch.cc: Likewise. * c-pragma.cc: Likewise. * c-pretty-print.cc: Likewise. Add #include "make-unique.h". (c_pretty_printer::clone): Use std::unique_ptr and ::make_unique. * c-pretty-print.h (c_pretty_printer::clone): Use std::unique_ptr. * c-type-mismatch.cc: Add #define INCLUDE_MEMORY. * c-warn.cc: Likewise. gcc/c/ChangeLog: PR other/116613 * c-aux-info.cc: Add #define INCLUDE_MEMORY. * c-convert.cc: Likewise. * c-errors.cc: Likewise. * c-fold.cc: Likewise. * c-lang.cc: Likewise. * c-objc-common.cc: Likewise. (pp_markup::element_quoted_type::print_type): Use unique_ptr. * c-typeck.cc: Add #define INCLUDE_MEMORY. * gimple-parser.cc: Likewise. gcc/cp/ChangeLog: PR other/116613 * call.cc: Add #define INCLUDE_MEMORY. * class.cc: Likewise. * constexpr.cc: Likewise. * constraint.cc: Likewise. * contracts.cc: Likewise. * coroutines.cc: Likewise. * cp-gimplify.cc: Likewise. * cp-lang.cc: Likewise. * cp-objcp-common.cc: Likewise. * cp-ubsan.cc: Likewise. * cvt.cc: Likewise. * cxx-pretty-print.cc: Likewise. Add #include "cp-tree.h". (cxx_pretty_printer::clone): Use std::unique_ptr and ::make_unique. * cxx-pretty-print.h (cxx_pretty_printer::clone): Use std::unique_ptr. * decl2.cc: Add #define INCLUDE_MEMORY. * dump.cc: Likewise. * except.cc: Likewise. * expr.cc: Likewise. * friend.cc: Likewise. * init.cc: Likewise. * lambda.cc: Likewise. * logic.cc: Likewise. * mangle.cc: Likewise. * method.cc: Likewise. * optimize.cc: Likewise. * pt.cc: Likewise. * ptree.cc: Likewise. * rtti.cc: Likewise. * search.cc: Likewise. * semantics.cc: Likewise. * tree.cc: Likewise. * typeck.cc: Likewise. * typeck2.cc: Likewise. * vtable-class-hierarchy.cc: Likewise. gcc/d/ChangeLog: PR other/116613 * d-attribs.cc: Add #define INCLUDE_MEMORY. * d-builtins.cc: Likewise. * d-codegen.cc: Likewise. * d-convert.cc: Likewise. * d-diagnostic.cc: Likewise. * d-frontend.cc: Likewise. * d-lang.cc: Likewise. * d-longdouble.cc: Likewise. * d-target.cc: Likewise. * decl.cc: Likewise. * expr.cc: Likewise. * intrinsics.cc: Likewise. * modules.cc: Likewise. * toir.cc: Likewise. * typeinfo.cc: Likewise. * types.cc: Likewise. gcc/fortran/ChangeLog: PR other/116613 * arith.cc: Add #define INCLUDE_MEMORY. * array.cc: Likewise. * bbt.cc: Likewise. * check.cc: Likewise. * class.cc: Likewise. * constructor.cc: Likewise. * convert.cc: Likewise. * cpp.cc: Likewise. * data.cc: Likewise. * decl.cc: Likewise. * dependency.cc: Likewise. * dump-parse-tree.cc: Likewise. * error.cc: Likewise. * expr.cc: Likewise. * f95-lang.cc: Likewise. * frontend-passes.cc: Likewise. * interface.cc: Likewise. * intrinsic.cc: Likewise. * io.cc: Likewise. * iresolve.cc: Likewise. * match.cc: Likewise. * matchexp.cc: Likewise. * misc.cc: Likewise. * module.cc: Likewise. * openmp.cc: Likewise. * options.cc: Likewise. * parse.cc: Likewise. * primary.cc: Likewise. * resolve.cc: Likewise. * scanner.cc: Likewise. * simplify.cc: Likewise. * st.cc: Likewise. * symbol.cc: Likewise. * target-memory.cc: Likewise. * trans-array.cc: Likewise. * trans-common.cc: Likewise. * trans-const.cc: Likewise. * trans-decl.cc: Likewise. * trans-expr.cc: Likewise. * trans-intrinsic.cc: Likewise. * trans-io.cc: Likewise. * trans-openmp.cc: Likewise. * trans-stmt.cc: Likewise. * trans-types.cc: Likewise. * trans.cc: Likewise. gcc/go/ChangeLog: PR other/116613 * go-backend.cc: Add #define INCLUDE_MEMORY. * go-lang.cc: Likewise. gcc/jit/ChangeLog: PR other/116613 * dummy-frontend.cc: Add #define INCLUDE_MEMORY. * jit-playback.cc: Likewise. * jit-recording.cc: Likewise. gcc/lto/ChangeLog: PR other/116613 * lto-common.cc: Add #define INCLUDE_MEMORY. * lto-dump.cc: Likewise. * lto-partition.cc: Likewise. * lto-symtab.cc: Likewise. * lto.cc: Likewise. gcc/m2/ChangeLog: PR other/116613 * gm2-gcc/gcc-consolidation.h: Add #define INCLUDE_MEMORY. * gm2-gcc/m2configure.cc: Likewise. * mc-boot/GASCII.cc: Regenerate. * mc-boot/GASCII.h: Ditto. * mc-boot/GArgs.cc: Ditto. * mc-boot/GArgs.h: Ditto. * mc-boot/GAssertion.cc: Ditto. * mc-boot/GAssertion.h: Ditto. * mc-boot/GBreak.cc: Ditto. * mc-boot/GBreak.h: Ditto. * mc-boot/GCOROUTINES.h: Ditto. * mc-boot/GCmdArgs.cc: Ditto. * mc-boot/GCmdArgs.h: Ditto. * mc-boot/GDebug.cc: Ditto. * mc-boot/GDebug.h: Ditto. * mc-boot/GDynamicStrings.cc: Ditto. * mc-boot/GDynamicStrings.h: Ditto. * mc-boot/GEnvironment.cc: Ditto. * mc-boot/GEnvironment.h: Ditto. * mc-boot/GFIO.cc: Ditto. * mc-boot/GFIO.h: Ditto. * mc-boot/GFormatStrings.cc: Ditto. * mc-boot/GFormatStrings.h: Ditto. * mc-boot/GFpuIO.cc: Ditto. * mc-boot/GFpuIO.h: Ditto. * mc-boot/GIO.cc: Ditto. * mc-boot/GIO.h: Ditto. * mc-boot/GIndexing.cc: Ditto. * mc-boot/GIndexing.h: Ditto. * mc-boot/GM2Dependent.cc: Ditto. * mc-boot/GM2Dependent.h: Ditto. * mc-boot/GM2EXCEPTION.cc: Ditto. * mc-boot/GM2EXCEPTION.h: Ditto. * mc-boot/GM2RTS.cc: Ditto. * mc-boot/GM2RTS.h: Ditto. * mc-boot/GMemUtils.cc: Ditto. * mc-boot/GMemUtils.h: Ditto. * mc-boot/GNumberIO.cc: Ditto. * mc-boot/GNumberIO.h: Ditto. * mc-boot/GPushBackInput.cc: Ditto. * mc-boot/GPushBackInput.h: Ditto. * mc-boot/GRTExceptions.cc: Ditto. * mc-boot/GRTExceptions.h: Ditto. * mc-boot/GRTco.h: Ditto. * mc-boot/GRTentity.h: Ditto. * mc-boot/GRTint.cc: Ditto. * mc-boot/GRTint.h: Ditto. * mc-boot/GSArgs.cc: Ditto. * mc-boot/GSArgs.h: Ditto. * mc-boot/GSFIO.cc: Ditto. * mc-boot/GSFIO.h: Ditto. * mc-boot/GSYSTEM.h: Ditto. * mc-boot/GSelective.h: Ditto. * mc-boot/GStdIO.cc: Ditto. * mc-boot/GStdIO.h: Ditto. * mc-boot/GStorage.cc: Ditto. * mc-boot/GStorage.h: Ditto. * mc-boot/GStrCase.cc: Ditto. * mc-boot/GStrCase.h: Ditto. * mc-boot/GStrIO.cc: Ditto. * mc-boot/GStrIO.h: Ditto. * mc-boot/GStrLib.cc: Ditto. * mc-boot/GStrLib.h: Ditto. * mc-boot/GStringConvert.cc: Ditto. * mc-boot/GStringConvert.h: Ditto. * mc-boot/GSysExceptions.h: Ditto. * mc-boot/GSysStorage.cc: Ditto. * mc-boot/GSysStorage.h: Ditto. * mc-boot/GTimeString.cc: Ditto. * mc-boot/GTimeString.h: Ditto. * mc-boot/GUnixArgs.h: Ditto. * mc-boot/Galists.cc: Ditto. * mc-boot/Galists.h: Ditto. * mc-boot/Gdecl.cc: Ditto. * mc-boot/Gdecl.h: Ditto. * mc-boot/Gdtoa.h: Ditto. * mc-boot/Gerrno.h: Ditto. * mc-boot/Gkeyc.cc: Ditto. * mc-boot/Gkeyc.h: Ditto. * mc-boot/Gldtoa.h: Ditto. * mc-boot/Glibc.h: Ditto. * mc-boot/Glibm.h: Ditto. * mc-boot/Glists.cc: Ditto. * mc-boot/Glists.h: Ditto. * mc-boot/GmcComment.cc: Ditto. * mc-boot/GmcComment.h: Ditto. * mc-boot/GmcComp.cc: Ditto. * mc-boot/GmcComp.h: Ditto. * mc-boot/GmcDebug.cc: Ditto. * mc-boot/GmcDebug.h: Ditto. * mc-boot/GmcError.cc: Ditto. * mc-boot/GmcError.h: Ditto. * mc-boot/GmcFileName.cc: Ditto. * mc-boot/GmcFileName.h: Ditto. * mc-boot/GmcLexBuf.cc: Ditto. * mc-boot/GmcLexBuf.h: Ditto. * mc-boot/GmcMetaError.cc: Ditto. * mc-boot/GmcMetaError.h: Ditto. * mc-boot/GmcOptions.cc: Ditto. * mc-boot/GmcOptions.h: Ditto. * mc-boot/GmcPreprocess.cc: Ditto. * mc-boot/GmcPreprocess.h: Ditto. * mc-boot/GmcPretty.cc: Ditto. * mc-boot/GmcPretty.h: Ditto. * mc-boot/GmcPrintf.cc: Ditto. * mc-boot/GmcPrintf.h: Ditto. * mc-boot/GmcQuiet.cc: Ditto. * mc-boot/GmcQuiet.h: Ditto. * mc-boot/GmcReserved.cc: Ditto. * mc-boot/GmcReserved.h: Ditto. * mc-boot/GmcSearch.cc: Ditto. * mc-boot/GmcSearch.h: Ditto. * mc-boot/GmcStack.cc: Ditto. * mc-boot/GmcStack.h: Ditto. * mc-boot/GmcStream.cc: Ditto. * mc-boot/GmcStream.h: Ditto. * mc-boot/Gmcflex.h: Ditto. * mc-boot/Gmcp1.cc: Ditto. * mc-boot/Gmcp1.h: Ditto. * mc-boot/Gmcp2.cc: Ditto. * mc-boot/Gmcp2.h: Ditto. * mc-boot/Gmcp3.cc: Ditto. * mc-boot/Gmcp3.h: Ditto. * mc-boot/Gmcp4.cc: Ditto. * mc-boot/Gmcp4.h: Ditto. * mc-boot/Gmcp5.cc: Ditto. * mc-boot/Gmcp5.h: Ditto. * mc-boot/GnameKey.cc: Ditto. * mc-boot/GnameKey.h: Ditto. * mc-boot/GsymbolKey.cc: Ditto. * mc-boot/GsymbolKey.h: Ditto. * mc-boot/Gtermios.h: Ditto. * mc-boot/Gtop.cc: Ditto. * mc-boot/Gvarargs.cc: Ditto. * mc-boot/Gvarargs.h: Ditto. * mc-boot/Gwlists.cc: Ditto. * mc-boot/Gwlists.h: Ditto. * mc-boot/Gwrapc.h: Ditto. * mc/keyc.mod (checkGccConfigSystem): Add #define INCLUDE_MEMORY. * pge-boot/GASCII.cc: Regenerate. * pge-boot/GASCII.h: Ditto. * pge-boot/GArgs.cc: Ditto. * pge-boot/GArgs.h: Ditto. * pge-boot/GAssertion.cc: Ditto. * pge-boot/GAssertion.h: Ditto. * pge-boot/GBreak.h: Ditto. * pge-boot/GCmdArgs.h: Ditto. * pge-boot/GDebug.cc: Ditto. * pge-boot/GDebug.h: Ditto. * pge-boot/GDynamicStrings.cc: Ditto. * pge-boot/GDynamicStrings.h: Ditto. * pge-boot/GEnvironment.h: Ditto. * pge-boot/GFIO.cc: Ditto. * pge-boot/GFIO.h: Ditto. * pge-boot/GFormatStrings.h: Ditto. * pge-boot/GFpuIO.h: Ditto. * pge-boot/GIO.cc: Ditto. * pge-boot/GIO.h: Ditto. * pge-boot/GIndexing.cc: Ditto. * pge-boot/GIndexing.h: Ditto. * pge-boot/GLists.cc: Ditto. * pge-boot/GLists.h: Ditto. * pge-boot/GM2Dependent.cc: Ditto. * pge-boot/GM2Dependent.h: Ditto. * pge-boot/GM2EXCEPTION.cc: Ditto. * pge-boot/GM2EXCEPTION.h: Ditto. * pge-boot/GM2RTS.cc: Ditto. * pge-boot/GM2RTS.h: Ditto. * pge-boot/GNameKey.cc: Ditto. * pge-boot/GNameKey.h: Ditto. * pge-boot/GNumberIO.cc: Ditto. * pge-boot/GNumberIO.h: Ditto. * pge-boot/GOutput.cc: Ditto. * pge-boot/GOutput.h: Ditto. * pge-boot/GPushBackInput.cc: Ditto. * pge-boot/GPushBackInput.h: Ditto. * pge-boot/GRTExceptions.cc: Ditto. * pge-boot/GRTExceptions.h: Ditto. * pge-boot/GSArgs.h: Ditto. * pge-boot/GSEnvironment.h: Ditto. * pge-boot/GSFIO.cc: Ditto. * pge-boot/GSFIO.h: Ditto. * pge-boot/GSYSTEM.h: Ditto. * pge-boot/GScan.h: Ditto. * pge-boot/GStdIO.cc: Ditto. * pge-boot/GStdIO.h: Ditto. * pge-boot/GStorage.cc: Ditto. * pge-boot/GStorage.h: Ditto. * pge-boot/GStrCase.cc: Ditto. * pge-boot/GStrCase.h: Ditto. * pge-boot/GStrIO.cc: Ditto. * pge-boot/GStrIO.h: Ditto. * pge-boot/GStrLib.cc: Ditto. * pge-boot/GStrLib.h: Ditto. * pge-boot/GStringConvert.h: Ditto. * pge-boot/GSymbolKey.cc: Ditto. * pge-boot/GSymbolKey.h: Ditto. * pge-boot/GSysExceptions.h: Ditto. * pge-boot/GSysStorage.cc: Ditto. * pge-boot/GSysStorage.h: Ditto. * pge-boot/GTimeString.h: Ditto. * pge-boot/GUnixArgs.h: Ditto. * pge-boot/Gbnflex.cc: Ditto. * pge-boot/Gbnflex.h: Ditto. * pge-boot/Gdtoa.h: Ditto. * pge-boot/Gerrno.h: Ditto. * pge-boot/Gldtoa.h: Ditto. * pge-boot/Glibc.h: Ditto. * pge-boot/Glibm.h: Ditto. * pge-boot/Gpge.cc: Ditto. * pge-boot/Gtermios.h: Ditto. * pge-boot/Gwrapc.h: Ditto. gcc/objc/ChangeLog: PR other/116613 * objc-act.cc: Add #define INCLUDE_MEMORY. * objc-encoding.cc: Likewise. * objc-gnu-runtime-abi-01.cc: Likewise. * objc-lang.cc: Likewise. * objc-next-runtime-abi-01.cc: Likewise. * objc-next-runtime-abi-02.cc: Likewise. * objc-runtime-shared-support.cc: Likewise. gcc/objcp/ChangeLog:: Add #define INCLUDE_MEMORY. PR other/116613 * objcp-decl.cc * objcp-lang.cc: Likewise. gcc/rust/ChangeLog: PR other/116613 * resolve/rust-ast-resolve-expr.cc: Add #define INCLUDE_MEMORY. * rust-attribs.cc: Likewise. * rust-system.h: Likewise. gcc/ChangeLog: PR other/116613 * asan.cc: Add #define INCLUDE_MEMORY. * attribs.cc: Likewise. (attr_access::array_as_string): Use diagnostic_context::clone_printer and use unique_ptr. * auto-profile.cc: Add #define INCLUDE_MEMORY. * calls.cc: Likewise. * cfganal.cc: Likewise. * cfgexpand.cc: Likewise. * cfghooks.cc: Likewise. * cfgloop.cc: Likewise. * cgraph.cc: Likewise. * cgraphclones.cc: Likewise. * cgraphunit.cc: Likewise. * collect-utils.cc: Likewise. * collect2.cc: Likewise. * common/config/aarch64/aarch64-common.cc: Likewise. * common/config/arm/arm-common.cc: Likewise. * common/config/avr/avr-common.cc: Likewise. * config/aarch64/aarch64-cc-fusion.cc: Likewise. * config/aarch64/aarch64-early-ra.cc: Likewise. * config/aarch64/aarch64-sve-builtins.cc: Likewise. * config/arc/arc.cc: Likewise. * config/arm/aarch-common.cc: Likewise. * config/arm/arm-mve-builtins.cc: Likewise. * config/avr/avr-devices.cc: Likewise. * config/avr/driver-avr.cc: Likewise. * config/bpf/bpf.cc: Likewise. * config/bpf/btfext-out.cc: Likewise. * config/bpf/core-builtins.cc: Likewise. * config/darwin.cc: Likewise. * config/i386/driver-i386.cc: Likewise. * config/i386/i386-builtins.cc: Likewise. * config/i386/i386-expand.cc: Likewise. * config/i386/i386-features.cc: Likewise. * config/i386/i386-options.cc: Likewise. * config/loongarch/loongarch-builtins.cc: Likewise. * config/mingw/winnt-cxx.cc: Likewise. * config/mingw/winnt.cc: Likewise. * config/mips/mips.cc: Likewise. * config/msp430/driver-msp430.cc: Likewise. * config/nvptx/mkoffload.cc: Likewise. * config/nvptx/nvptx.cc: Likewise. * config/riscv/riscv-avlprop.cc: Likewise. * config/riscv/riscv-vector-builtins.cc: Likewise. * config/riscv/riscv-vsetvl.cc: Likewise. * config/rs6000/driver-rs6000.cc: Likewise. * config/rs6000/host-darwin.cc: Likewise. * config/rs6000/rs6000-c.cc: Likewise. * config/s390/s390-c.cc: Likewise. * config/s390/s390.cc: Likewise. * config/sol2-cxx.cc: Likewise. * config/vms/vms-c.cc: Likewise. * config/xtensa/xtensa-dynconfig.cc: Likewise. * coroutine-passes.cc: Likewise. * coverage.cc: Likewise. * data-streamer-in.cc: Likewise. * data-streamer-out.cc: Likewise. * data-streamer.cc: Likewise. * diagnostic-buffer.h (diagnostic_buffer::~diagnostic_buffer): Delete. (diagnostic_buffer::m_per_format_buffer): Use std::unique_ptr. * diagnostic-client-data-hooks.h (make_compiler_data_hooks): Use std::unique_ptr for return type. * diagnostic-format-json.cc (json_output_format::make_per_format_buffer): Likewise. (diagnostic_output_format_init_json): Update for usage of std::unique_ptr in set_output_format. * diagnostic-format-sarif.cc (sarif_output_format::make_per_format_buffer): Use std::unique_ptr for return type. (diagnostic_output_format_init_sarif): Update for usage of std::unique_ptr. (test_message_with_embedded_link): Likewise for set_urlifier. * diagnostic-format-text.cc: Add #define INCLUDE_MEMORY. Include "make-unique.h". (diagnostic_text_output_format::set_buffer): Use std::unique_ptr. * diagnostic-format-text.h (diagnostic_text_output_format::set_buffer): Likewise. * diagnostic-format.h (diagnostic_output_format::make_per_format_buffer): Likewise. * diagnostic-global-context.cc: * diagnostic-macro-unwinding.cc: Likewise. * diagnostic-show-locus.cc: Likewise. * diagnostic-spec.cc: Likewise. * diagnostic.cc (diagnostic_context::set_output_format): Use std::unique_ptr for input. (diagnostic_context::set_client_data_hooks): Likewise. (diagnostic_context::set_option_manager): Likewise. (diagnostic_context::set_urlifier): Likewise. (diagnostic_context::set_diagnostic_buffer): Update for use of std::unique_ptr. (diagnostic_buffer::diagnostic_buffer): Likewise. (diagnostic_buffer::~diagnostic_buffer): Delete. * diagnostic.h: Complain if INCLUDE_MEMORY was not defined. (diagnostic_context::set_output_format): Use std::unique_ptr for input. (diagnostic_context::set_client_data_hooks): Likewise. (diagnostic_context::set_option_manager): Likewise. (diagnostic_context::set_urlifier): Likewise. (diagnostic_context::clone_printer): New. (diagnostic_context::m_printer): Update comment. (diagnostic_context::m_option_mgr): Likewise. (diagnostic_context::m_urlifier): Likewise. (diagnostic_context::m_edit_context_ptr): Likewise. (diagnostic_context::m_output_format): Likewise. (diagnostic_context::m_client_data_hooks): Likewise. (diagnostic_context::m_theme): Likewise. * digraph.cc: Add #define INCLUDE_MEMORY. * dwarf2out.cc: Likewise. * edit-context.cc: Likewise. * except.cc: Likewise. * expr.cc: Likewise. * file-prefix-map.cc: Likewise. * final.cc: Likewise. * fwprop.cc: Likewise. * gcc-plugin.h: Likewise. * gcc-rich-location.cc: Likewise. * gcc-urlifier.cc: Likewise. Add #include "make-unique.h". (make_gcc_urlifier): Use std::unique_ptr and ::make_unique. * gcc-urlifier.h (make_gcc_urlifier): Use std::unique_ptr. * gcc.cc: Add #define INCLUDE_MEMORY. Include "pretty-print-urlifier.h". * gcov-dump.cc: Add #define INCLUDE_MEMORY. * gcov-tool.cc: Likewise. * gengtype.cc (open_base_files): Likewise to output. * genmatch.cc: Likewise. * gimple-fold.cc: Likewise. * gimple-harden-conditionals.cc: Likewise. * gimple-harden-control-flow.cc: Likewise. * gimple-if-to-switch.cc: Likewise. * gimple-lower-bitint.cc: Likewise. * gimple-predicate-analysis.cc: Likewise. * gimple-pretty-print.cc: Likewise. * gimple-range-cache.cc: Likewise. * gimple-range-edge.cc: Likewise. * gimple-range-fold.cc: Likewise. * gimple-range-gori.cc: Likewise. * gimple-range-infer.cc: Likewise. * gimple-range-op.cc: Likewise. * gimple-range-path.cc: Likewise. * gimple-range-phi.cc: Likewise. * gimple-range-trace.cc: Likewise. * gimple-range.cc: Likewise. * gimple-ssa-backprop.cc: Likewise. * gimple-ssa-sprintf.cc: Likewise. * gimple-ssa-store-merging.cc: Likewise. * gimple-ssa-strength-reduction.cc: Likewise. * gimple-ssa-warn-access.cc: Likewise. * gimple-ssa-warn-alloca.cc: Likewise. * gimple-ssa-warn-restrict.cc: Likewise. * gimple-streamer-in.cc: Likewise. * gimple-streamer-out.cc: Likewise. * gimple.cc: Likewise. * gimplify.cc: Likewise. * graph.cc: Likewise. * graphviz.cc: Likewise. * input.cc: Likewise. * ipa-cp.cc: Likewise. * ipa-devirt.cc: Likewise. * ipa-fnsummary.cc: Likewise. * ipa-free-lang-data.cc: Likewise. * ipa-icf-gimple.cc: Likewise. * ipa-icf.cc: Likewise. * ipa-inline-analysis.cc: Likewise. * ipa-inline.cc: Likewise. * ipa-modref-tree.cc: Likewise. * ipa-modref.cc: Likewise. * ipa-param-manipulation.cc: Likewise. * ipa-polymorphic-call.cc: Likewise. * ipa-predicate.cc: Likewise. * ipa-profile.cc: Likewise. * ipa-prop.cc: Likewise. * ipa-pure-const.cc: Likewise. * ipa-reference.cc: Likewise. * ipa-split.cc: Likewise. * ipa-sra.cc: Likewise. * ipa-strub.cc: Likewise. * ipa-utils.cc: Likewise. * langhooks.cc: Likewise. * late-combine.cc: Likewise. * lto-cgraph.cc: Likewise. * lto-compress.cc: Likewise. * lto-opts.cc: Likewise. * lto-section-in.cc: Likewise. * lto-section-out.cc: Likewise. * lto-streamer-in.cc: Likewise. * lto-streamer-out.cc: Likewise. * lto-streamer.cc: Likewise. * lto-wrapper.cc: Likewise. Include "make-unique.h". (main): Use ::make_unique when creating option manager. * multiple_target.cc: Likewise. * omp-expand.cc: Likewise. * omp-general.cc: Likewise. * omp-low.cc: Likewise. * omp-oacc-neuter-broadcast.cc: Likewise. * omp-offload.cc: Likewise. * omp-simd-clone.cc: Likewise. * optc-gen.awk: Likewise in output. * optc-save-gen.awk: Likewise in output. * options-urls-cc-gen.awk: Likewise in output. * opts-common.cc: Likewise. * opts-global.cc: Likewise. * opts.cc: Likewise. * pair-fusion.cc: Likewise. * passes.cc: Likewise. * pointer-query.cc: Likewise. * predict.cc: Likewise. * pretty-print.cc (pretty_printer::clone): Use std::unique_ptr and ::make_unique. * pretty-print.h: Complain if INCLUDE_MEMORY is not defined. (pretty_printer::clone): Use std::unique_ptr. * print-rtl.cc: Add #define INCLUDE_MEMORY. * print-tree.cc: Likewise. * profile-count.cc: Likewise. * range-op-float.cc: Likewise. * range-op-ptr.cc: Likewise. * range-op.cc: Likewise. * range.cc: Likewise. * read-rtl-function.cc: Likewise. * rtl-error.cc: Likewise. * rtl-ssa/accesses.cc: Likewise. * rtl-ssa/blocks.cc: Likewise. * rtl-ssa/changes.cc: Likewise. * rtl-ssa/functions.cc: Likewise. * rtl-ssa/insns.cc: Likewise. * rtl-ssa/movement.cc: Likewise. * rtl-tests.cc: Likewise. * sanopt.cc: Likewise. * sched-rgn.cc: Likewise. * selftest-diagnostic-path.cc: Likewise. * selftest-diagnostic.cc: Likewise. * splay-tree-utils.cc: Likewise. * sreal.cc: Likewise. * stmt.cc: Likewise. * substring-locations.cc: Likewise. * symtab-clones.cc: Likewise. * symtab-thunks.cc: Likewise. * symtab.cc: Likewise. * text-art/box-drawing.cc: Likewise. * text-art/canvas.cc: Likewise. * text-art/ruler.cc: Likewise. * text-art/selftests.cc: Likewise. * text-art/theme.cc: Likewise. * toplev.cc: Likewise. Include "make-unique.h". (general_init): Use ::make_unique when setting option_manager. * trans-mem.cc: Add #define INCLUDE_MEMORY. * tree-affine.cc: Likewise. * tree-call-cdce.cc: Likewise. * tree-cfg.cc: Likewise. * tree-chrec.cc: Likewise. * tree-dfa.cc: Likewise. * tree-diagnostic-client-data-hooks.cc: Include "make-unique.h". (make_compiler_data_hooks): Use std::unique_ptr and ::make_unique. * tree-diagnostic.cc: Add #define INCLUDE_MEMORY. * tree-dump.cc: Likewise. * tree-inline.cc: Likewise. * tree-into-ssa.cc: Likewise. * tree-logical-location.cc: Likewise. * tree-nested.cc: Likewise. * tree-nrv.cc: Likewise. * tree-object-size.cc: Likewise. * tree-outof-ssa.cc: Likewise. * tree-pretty-print.cc: Likewise. * tree-profile.cc: Likewise. * tree-scalar-evolution.cc: Likewise. * tree-sra.cc: Likewise. * tree-ssa-address.cc: Likewise. * tree-ssa-alias.cc: Likewise. * tree-ssa-ccp.cc: Likewise. * tree-ssa-coalesce.cc: Likewise. * tree-ssa-copy.cc: Likewise. * tree-ssa-dce.cc: Likewise. * tree-ssa-dom.cc: Likewise. * tree-ssa-forwprop.cc: Likewise. * tree-ssa-ifcombine.cc: Likewise. * tree-ssa-loop-ch.cc: Likewise. * tree-ssa-loop-im.cc: Likewise. * tree-ssa-loop-manip.cc: Likewise. * tree-ssa-loop-niter.cc: Likewise. * tree-ssa-loop-split.cc: Likewise. * tree-ssa-math-opts.cc: Likewise. * tree-ssa-operands.cc: Likewise. * tree-ssa-phiprop.cc: Likewise. * tree-ssa-pre.cc: Likewise. * tree-ssa-propagate.cc: Likewise. * tree-ssa-reassoc.cc: Likewise. * tree-ssa-sccvn.cc: Likewise. * tree-ssa-scopedtables.cc: Likewise. * tree-ssa-sink.cc: Likewise. * tree-ssa-strlen.cc: Likewise. * tree-ssa-structalias.cc: Likewise. * tree-ssa-ter.cc: Likewise. * tree-ssa-uninit.cc: Likewise. * tree-ssa.cc: Likewise. * tree-ssanames.cc: Likewise. * tree-stdarg.cc: Likewise. * tree-streamer-in.cc: Likewise. * tree-streamer-out.cc: Likewise. * tree-streamer.cc: Likewise. * tree-switch-conversion.cc: Likewise. * tree-tailcall.cc: Likewise. * tree-vrp.cc: Likewise. * tree.cc: Likewise. * ubsan.cc: Likewise. * value-pointer-equiv.cc: Likewise. * value-prof.cc: Likewise. * value-query.cc: Likewise. * value-range-pretty-print.cc: Likewise. * value-range-storage.cc: Likewise. * value-range.cc: Likewise. * value-relation.cc: Likewise. * var-tracking.cc: Likewise. * varpool.cc: Likewise. * vr-values.cc: Likewise. * wide-int-print.cc: Likewise. gcc/testsuite/ChangeLog: PR other/116613 * gcc.dg/plugin/diagnostic_group_plugin.c: Update for use of std::unique_ptr. * gcc.dg/plugin/diagnostic_plugin_xhtml_format.c: Likewise. * gcc.dg/plugin/ggcplug.c: Likewise. libgcc/ChangeLog: PR other/116613 * libgcov-util.c: Add #define INCLUDE_MEMORY. Signed-off-by: David Malcolm <dmalcolm@redhat.com> Co-authored-by: Gaius Mulley <gaiusmod2@gmail.com> Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-10-23diagnostics: implement buffering for non-textual formats [PR105916]David Malcolm1-0/+7
PR fortran/105916 reports stray diagnostics appearing in JSON and SARIF output from gfortran. In order to handle various awkard parsing issues, the Fortran frontend implements buffering of diagnostics, so that diagnostics reported to global_dc can be either: (a) immediately issued, or (b) speculatively reported to global_dc, and stored in a buffer, to either be issued later or discarded. This buffering code in gcc/fortran/error.cc directly manipulates implementation details of the diagnostic_context such as the pretty_printer's buffer, and the counts of how many diagnostics have been issued. The issue is that this manipulation of pretty_printer's buffer doesn't work for formats such as JSON and SARIF where diagnostics are handled in a different way (such as by accumulating json::object instances in an array). This patch moves responsibility for such buffering of diagnostics from fortran's error.cc to the diagnostic subsystem. It introduces a new class diagnostic_buffer representing a particular buffer of diagnostics that have been reported but not yet issued. Each diagnostic output format implements buffering in a different way, and so there is a new class hierarchy, diagnostic_per_format_buffer, representing the various format-specific ways that buffering is to be implemented. This is hidden as an implementation detail of diagnostic_buffer. The patch also updates how diagnostics of each kind (e.g. warnings vs errors) are counted, so that if buffering is enabled, the count is incremented within the buffer, and the counts in the diagnostic_context are only updated if and when the buffer is flushed; checking for max_errors is similarly updated to support both buffered and unbuffered cases. For ease of debugging, the patch extends the "dump" functions within the diagnostics subsystem, so that e.g. global_dc->dump () now prints the buffering status, e.g.: (gdb) call global_dc->dump() diagnostic_context: counts: (none) output format: sarif_output_format printer: m_show_color: false m_url_format: bel m_buffer: m_formatted_obstack current object: length 0: m_chunk_obstack current object: length 0: diagnostic buffer: m_per_format_buffer: counts: error: 1 diagnostic_sarif_format_buffer: result[0]: {"ruleId": "error", "level": "error", "message": {"text": "Function ‘program’ requires an argument list at (1)"}, "locations": [{"physicalLocation": {"artifactLocation": {"uri": "../../src/gcc/testsuite/gfortran.dg/pr105954.f90", "uriBaseId": "PWD"}, "region": {"startLine": 6, "startColumn": 8, "endColumn": 9}, "contextRegion": {"startLine": 6, "snippet": {"text": "program p\n"}}}}]} which shows that no diagnostics have been issued yet, but the active diagnostic_buffer has a single error buffered within it, in SARIF form. Similarly, it's possible to use "dump" on a diagnostic_buffer to directly query its contents; here's the same example, this time with the text output format: (gdb) call error_buffer.buffer.dump() m_per_format_buffer: counts: error: 1 diagnostic_text_format_buffer: m_formatted_obstack current object: length 232: 00000000: 1b 5b 30 31 6d 1b 5b 4b 2e 2e 2f 2e 2e 2f 73 72 | .[01m.[K../../sr 00000010: 63 2f 67 63 63 2f 74 65 73 74 73 75 69 74 65 2f | c/gcc/testsuite/ 00000020: 67 66 6f 72 74 72 61 6e 2e 64 67 2f 70 72 31 30 | gfortran.dg/pr10 00000030: 35 39 35 34 2e 66 39 30 3a 36 3a 38 3a 1b 5b 6d | 5954.f90:6:8:.[m 00000040: 1b 5b 4b 0a 0a 20 20 20 20 36 20 7c 20 70 72 6f | .[K.. 6 | pro 00000050: 67 72 61 6d 20 70 0a 20 20 20 20 20 20 7c 20 20 | gram p. | 00000060: 20 20 20 20 20 20 1b 5b 30 31 3b 33 31 6d 1b 5b | .[01;31m.[ 00000070: 4b 31 1b 5b 6d 1b 5b 4b 0a 1b 5b 30 31 3b 33 31 | K1.[m.[K..[01;31 00000080: 6d 1b 5b 4b 45 72 72 6f 72 3a 1b 5b 6d 1b 5b 4b | m.[KError:.[m.[K 00000090: 20 46 75 6e 63 74 69 6f 6e 20 e2 80 98 1b 5b 30 | Function ....[0 000000a0: 31 6d 1b 5b 4b 70 72 6f 67 72 61 6d 1b 5b 6d 1b | 1m.[Kprogram.[m. 000000b0: 5b 4b e2 80 99 20 72 65 71 75 69 72 65 73 20 61 | [K... requires a 000000c0: 6e 20 61 72 67 75 6d 65 6e 74 20 6c 69 73 74 20 | n argument list 000000d0: 61 74 20 1b 5b 30 31 3b 33 31 6d 1b 5b 4b 28 31 | at .[01;31m.[K(1 000000e0: 29 1b 5b 6d 1b 5b 4b 0a | ).[m.[K. m_chunk_obstack current object: length 0: showing that we have an error in error_buffer, with colorized text. gcc/ChangeLog: PR fortran/105916 * diagnostic-buffer.h: New file. * diagnostic-format-json.cc: Define INCLUDE_VECTOR. Include "diagnostic-buffer.h". (class diagnostic_json_format_buffer): New subclass. (class json_output_format): Add friend class diagnostic_json_format_buffer. (json_output_format::make_per_format_buffer): New vfunc implementation. (json_output_format::set_buffer): New vfunc implementation. (json_output_format::json_output_format): Initialize m_buffer. (json_output_format::m_buffer): New field. (diagnostic_json_format_buffer::dump): New. (diagnostic_json_format_buffer::empty_p): New. (diagnostic_json_format_buffer::move_to): New. (diagnostic_json_format_buffer::clear): New. (diagnostic_json_format_buffer::flush): New. (json_output_format::on_report_diagnostic): Implement optional buffering. * diagnostic-format-sarif.cc: Include "diagnostic-buffer.h". (class diagnostic_sarif_format_buffer): New subclass. (class sarif_builder): Add friend class diagnostic_sarif_format_buffer. (sarif_builder::num_results): New accessor. (sarif_builder::get_result): New accessor. (sarif_builder::on_report_diagnostic): Add param "buffer"; use it to implement optional buffering. (diagnostic_sarif_format_buffer::dump): New. (diagnostic_sarif_format_buffer::empty_p): New. (diagnostic_sarif_format_buffer::move_to): New. (diagnostic_sarif_format_buffer::clear): New. (diagnostic_sarif_format_buffer::flush): New. (sarif_output_format::make_per_format_buffer): New vfunc implementation. (sarif_output_format::set_buffer): New vfunc implementation. (sarif_output_format::on_report_diagnostic): Pass m_buffer to sarif_builder::on_report_diagnostic. (sarif_output_format::num_results): New accessor. (sarif_output_format::get_result): New accessor. (diagnostic_output_format::diagnostic_output_format): Initialize m_buffer. (diagnostic_output_format::m_buffer): New field. (diagnostic_output_format::num_results): Get accessor. (diagnostic_output_format::get_result): Get accessor. (selftest::get_message_from_result): New. (selftest::test_buffering): New. (selftest::diagnostic_format_sarif_cc_tests): Call it. * diagnostic-format-text.cc: Include "diagnostic-client-data-hooks.h". (class diagnostic_text_format_buffer): New subclass. (diagnostic_text_format_buffer::diagnostic_text_format_buffer): New. (diagnostic_text_format_buffer::dump): New. (diagnostic_text_format_buffer::empty_p): New. (diagnostic_text_format_buffer::move_to): New. (diagnostic_text_format_buffer::clear): New. (diagnostic_text_format_buffer::flush): New. (diagnostic_text_output_format::dump): Dump m_saved_output_buffer. (diagnostic_text_output_format::set_buffer): New. (diagnostic_text_output_format::make_per_format_buffer): New. * diagnostic-format-text.h (diagnostic_text_output_format::diagnostic_text_output_format): Initialize m_saved_output_buffer. (diagnostic_text_output_format::set_buffer): New decl. (diagnostic_text_output_format::make_per_format_buffer): New decl. (diagnostic_text_output_format::m_saved_output_buffer): New field. * diagnostic-format.h (class diagnostic_per_format_buffer): New forward decl. (diagnostic_output_format::make_per_format_buffer): New vfunc. (diagnostic_output_format::set_buffer): New vfunc. * diagnostic.cc: Include "diagnostic-buffer.h". (diagnostic_context::initialize): Replace memset with call to "clear" on m_diagnostic_counters. Initializer m_diagnostic_buffer. (diagnostic_context::finish): Call set_diagnostic_buffer with nullptr. (diagnostic_context::dump): Update for encapsulation of counts into m_diagnostic_counters. Dump m_diagnostic_buffer. (diagnostic_context::execution_failed_p): Update for encapsulation of counts into m_diagnostic_counters. (diagnostic_context::check_max_errors): Likewise. (diagnostic_context::report_diagnostic): Likewise. Eliminate diagnostic_check_max_errors in favor of check_max_errors. Update increment of counter to support buffering. Eliminate diagnostic_action_after_output in favor of action_after_output. Only add fixits to m_edit_context_ptr if buffering is disabled. Only call diagnostic_output_format::after_diagnostic if buffering is disabled. (diagnostic_context::error_recursion): Eliminate diagnostic_action_after_output in favor of action_after_output. (diagnostic_context::set_diagnostic_buffer): New. (diagnostic_context::clear_diagnostic_buffer): New. (diagnostic_context::flush_diagnostic_buffer): New. (diagnostic_counters::diagnostic_counters): New. (diagnostic_counters::dump): New. (diagnostic_counters::move_to): New. (diagnostic_counters::clear): New. (diagnostic_buffer::diagnostic_buffer): New. (diagnostic_buffer::~diagnostic_buffer): New. (diagnostic_buffer::dump): New. (diagnostic_buffer::empty_p): New. (diagnostic_buffer::move_to): New. (diagnostic_buffer::ensure_per_format_buffer): New. (c_diagnostic_cc_tests): Remove stray newline. * diagnostic.h (class diagnostic_buffer): New forward decl. (struct diagnostic_counters): New. (diagnostic_context::check_max_errors): Make private. (diagnostic_context::action_after_output): Make private. (diagnostic_context::get_output_format): Make non-const. (diagnostic_context::diagnostic_count): Update for change to m_diagnostic_counters. (diagnostic_context::set_diagnostic_buffer): New decl. (diagnostic_context::get_diagnostic_buffer): New decl. (diagnostic_context::clear_diagnostic_buffer): New decl. (diagnostic_context::flush_diagnostic_buffer): New decl. (diagnostic_context::m_diagnostic_count): Replace array with... (diagnostic_context::m_diagnostic_counters): ...this. (diagnostic_context::m_diagnostic_buffer): New field. (diagnostic_action_after_output): Delete. (diagnostic_check_max_errors): Delete. gcc/fortran/ChangeLog: PR fortran/105916 * error.cc (pp_error_buffer, pp_warning_buffer): Convert from output_buffer * to diagnostic_buffer *. (warningcount_buffered, werrorcount_buffered): Eliminate. (gfc_error_buffer::gfc_error_buffer): Move constructor definition here, and initialize "buffer" using *global_dc. (gfc_output_buffer_empty_p): Delete in favor of diagnostic_buffer::empty_p. (gfc_clear_pp_buffer): Replace with... (gfc_clear_diagnostic_buffer): ...this, moving implementation details to diagnostic_context::clear_diagnostic_buffer. (gfc_warning): Replace buffering implementation with calls to global_dc->get_diagnostic_buffer and global_dc->set_diagnostic_buffer. (gfc_clear_warning): Update for renaming of gfc_clear_pp_buffer and elimination of warningcount_buffered and werrorcount_buffered. (gfc_warning_check): Replace buffering implementation with calls to pp_warning_buffer->empty_p and global_dc->flush_diagnostic_buffer. (gfc_error_opt): Replace buffering implementation with calls to global_dc->get_diagnostic_buffer and set_diagnostic_buffer. (gfc_clear_error): Update for renaming of gfc_clear_pp_buffer. (gfc_error_flag_test): Replace call to gfc_output_buffer_empty_p with call to diagnostic_buffer::empty_p. (gfc_error_check): Replace buffering implementation with calls to pp_error_buffer->empty_p and global_dc->flush_diagnostic_buffer. (gfc_move_error_buffer_from_to): Replace buffering implementation with usage of diagnostic_buffer. (gfc_free_error): Update for renaming of gfc_clear_pp_buffer. (gfc_diagnostics_init): Use "new" directly when creating pp_warning_buffer. Remove setting of m_flush_p on the two buffers, as this is handled by diagnostic_buffer and by diagnostic_text_format_buffer's constructor. * gfortran.h: Replace #include "pretty-print.h" for output_buffer with #include "diagnostic-buffer.h" for diagnostic_buffer. (struct gfc_error_buffer): Change type of field "buffer" from output_buffer to diagnostic_buffer. Move definition of constructor into error.cc so that it can use global_dc. gcc/testsuite/ChangeLog: PR fortran/105916 * gcc.dg/plugin/diagnostic_plugin_xhtml_format.c: Include "diagnostic-buffer.h". (class diagnostic_xhtml_format_buffer): New subclass. (class xhtml_builder): Add friend class diagnostic_xhtml_format_buffer. (diagnostic_xhtml_format_buffer::dump): New. (diagnostic_xhtml_format_buffer::empty_p): New. (diagnostic_xhtml_format_buffer::move_to): New. (diagnostic_xhtml_format_buffer::clear): New. (diagnostic_xhtml_format_buffer::flush): New. (xhtml_builder::on_report_diagnostic): Add "buffer" param, and use it. (xhtml_output_format::dump): Fix typo. (xhtml_output_format::make_per_format_buffer): New. (xhtml_output_format::set_buffer): New. (xhtml_output_format::on_report_diagnostic): Fix whitespace. Pass m_buffer to xhtml_builder::on_report_diagnostic. (xhtml_output_format::xhtml_output_format): Initialize m_buffer. (xhtml_output_format::m_buffer): New field. * gfortran.dg/diagnostic-format-json-pr105916.F90: New test. * gfortran.dg/diagnostic-format-sarif-1.F90: New test. * gfortran.dg/diagnostic-format-sarif-1.py: New support script. * gfortran.dg/diagnostic-format-sarif-pr105916.f90: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-10-18diagnostics: add debug dump functionsDavid Malcolm1-0/+3
This commit expands on r15-3973-g4c7a58ac2617e2, which added debug "dump" member functiosn to pretty_printer and output_buffer. This followup adds "dump" member functions to diagnostic_context and diagnostic_format, extends the existing dump functions and adds indentation to make it much easier to see the various relationships between context, format, printer, etc. Hence you can now do: (gdb) call global_dc->dump () and get a useful summary of what the diagnostic subsystem is doing; for example: (gdb) call global_dc->dump() diagnostic_context: counts: output format: sarif_output_format printer: m_show_color: false m_url_format: bel m_buffer: m_formatted_obstack current object: length 0: m_chunk_obstack current object: length 0: pp_formatted_chunks: depth 0 0: TEXT("Function ")] 1: BEGIN_QUOTE, TEXT("program"), END_QUOTE] 2: TEXT(" requires an argument list at ")] 3: TEXT("(1)")] showing the counts of all diagnostic kind that are non-zero (none yet), that we have a sarif output format, and the printer is part-way through formatting a string. gcc/ChangeLog: * diagnostic-format-json.cc (json_output_format::dump): New. * diagnostic-format-sarif.cc (sarif_output_format::dump): New. (sarif_file_output_format::dump): New. * diagnostic-format-text.cc (diagnostic_text_output_format::dump): New. * diagnostic-format-text.h (diagnostic_text_output_format::dump): New decl. * diagnostic-format.h (diagnostic_output_format::dump): New decls. * diagnostic.cc (diagnostic_context::dump): New. (diagnostic_output_format::dump): New. * diagnostic.h (diagnostic_context::dump): New decls. * pretty-print-format-impl.h (pp_formatted_chunks::dump): Add "indent" param. * pretty-print.cc (bytes_per_hexdump_line): New constant. (print_hexdump_line): New. (print_hexdump): New. (output_buffer::dump): Add "indent" param and use it. Add hexdump of current object in m_formatted_obstack and m_chunk_obstack. (pp_formatted_chunks::dump): Add "indent" param and use it. (pretty_printer::dump): Likewise. Add dumping of m_show_color and m_url_format. * pretty-print.h (output_buffer::dump): Add "indent" param. (pretty_printer::dump): Likewise. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_plugin_xhtml_format.c (xhtml_output_format::dump): New. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-10-09diagnostics: move text output member functions to correct fileDavid Malcolm1-2/+0
No functional change intended. gcc/ChangeLog: * diagnostic-format-text.cc (diagnostic_text_output_format::after_diagnostic): Replace call to show_any_path with body, taken from diagnostic.cc. (diagnostic_text_output_format::build_prefix): Move here from diagnostic.cc, updating to use get_diagnostic_kind_text and diagnostic_get_color_for_kind. (diagnostic_text_output_format::file_name_as_prefix): Move here from diagnostic.cc (diagnostic_text_output_format::append_note): Likewise. * diagnostic-format-text.h (diagnostic_text_output_format::show_any_path): Drop decl. * diagnostic.cc (diagnostic_text_output_format::file_name_as_prefix): Move to diagnostic-format-text.cc. (diagnostic_text_output_format::build_prefix): Likewise. (diagnostic_text_output_format::show_any_path): Move to body of diagnostic_text_output_format::after_diagnostic. (diagnostic_text_output_format::append_note): Move to diagnostic-format-text.cc. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-09-30diagnostics: isolate diagnostic_context with interface classes [PR116613]David Malcolm1-0/+9
As work towards supporting multiple diagnostic outputs (where each output has its own pretty_printer), avoid passing around diagnostic_context to the various printing routines, so that we can be more explicit about which pretty_printer is in use. Introduce a set of "policy" classes that capture the parts of diagnostic_context that are needed, and use these rather than diagnostic_context *. Pass around pretty_printer & rather than taking value from context. Split out the pretty_printer-using code from class layout into a new class layout_printer, separating the responsibilities of determining layout when quoting source versus actually printing the source. No functional change intended. gcc/analyzer/ChangeLog: PR other/116613 * program-point.cc (function_point::print_source_line): Replace call to diagnostic_show_locus with a call to diagnostic_source_print_policy::print. gcc/ChangeLog: PR other/116613 * diagnostic-format-json.cc (json_from_expanded_location): Replace call to diagnostic_context::converted_column with call to diagnostic_column_policy::converted_column. * diagnostic-format-sarif.cc (sarif_builder::make_location_object): Replace call to diagnostic_show_locus with call to diagnostic_source_print_policy::print. * diagnostic-format-text.cc (get_location_text): Replace call to diagnostic_context::get_location_text with call to diagnostic_column_policy::get_location_text. (diagnostic_text_output_format::report_current_module): Replace call to diagnostic_context::converted_column with call to diagnostic_column_policy::converted_column. * diagnostic-format-text.h (diagnostic_text_output_format::diagnostic_output_format): Initialize m_column_policy. (diagnostic_text_output_format::get_column_policy): New. (diagnostic_text_output_format::m_column_policy): New. * diagnostic-path.cc (class path_print_policy): New. (event_range::maybe_add_event): Replace diagnostic_context param with path_print_policy. (event_range::print): Convert "pp" from * to &. Convert first param of start_span callback from diagnostic_context to diagnostic_location_print_policy. (path_summary::path_summary): Convert first param from diagnostic_text_output_format to path_print_policy. Add colorize param. Update for changes to event_range::maybe_add_event. (thread_event_printer::print_swimlane_for_event_range): Assert that pp is non-null. Update for change to event_range::print. (diagnostic_text_output_format::print_path): Pass path_print_policy to path_summary's ctor. (selftest::test_empty_path): Likewise. (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. * diagnostic-show-locus.cc (colorizer::set_range): Update for change to m_pp. (colorizer::m_pp): Convert from * to &. (class layout): Add friend class layout_printer and move various decls to it. (layout::m_pp): Drop field. (layout::m_policy): Rename to... (layout::m_char_policy): ...this. (layout::m_colorizer): Move field to class layout_printer. (layout::m_diagnostic_path_p): Drop field. (class layout_printer): New class, by refactoring class layout. (colorizer::colorizer): Convert "pp" param from * to &. (colorizer::set_named_color): Update for above change. (colorizer::begin_state): Likewise. (colorizer::finish_state): Likewise. (make_policy): Rename to... (make_char_policy): ...this, and update param from diagnostic_context to diagnostic_source_print_policy. (layout::layout): Update param from diagnostic_context to diagnostic_source_print_policy. Drop params "diagnostic_kind" and "pp", moving these and other material to class layout_printer. (layout::maybe_add_location_range): Update for renamed field. (layout::print_gap_in_line_numbering): Convert to... (layout_printer::print_gap_in_line_numbering): ...this. (layout::calculate_x_offset_display): Update for renamed field. (layout::print_source_line): Convert to... (layout_printer::print_source_line): ...this. (layout::print_leftmost_column): Convert to... (layout_printer::print_leftmost_column): ...this. (layout::start_annotation_line): Convert to... (layout_printer::start_annotation_line): ...this. (layout::print_annotation_line): Convert to... (layout_printer::print_annotation_line): ...this. (layout::print_any_labels): Convert to... (layout_printer::print_any_labels): ...this. (layout::print_leading_fixits): Convert to... (layout_printer::print_leading_fixits): ...this. (layout::print_trailing_fixits): Convert to... (layout_printer::print_trailing_fixits): ...this. (layout::print_newline): Convert to... (layout_printer::print_newline): ...this. (layout::get_state_at_point): Make const. (layout::get_x_bound_for_row): Make const. (layout::move_to_column): Convert to... (layout_printer::move_to_column): ...this. (layout::show_ruler): Convert to... (layout_printer::show_ruler): ...this. (layout::print_line): Convert to... (layout_printer::print_line): ...this. (layout::print_any_right_to_left_edge_lines): Convert to... (layout_printer::print_any_right_to_left_edge_lines): ...this. (layout::print_any_right_to_left_edge_lines): Likewise. (layout_printer::layout_printer): New. (layout::update_any_effects): Delete, moving logic to layout_printer::print. (gcc_rich_location::add_location_if_nearby): Update param from diagnostic_context to diagnostic_source_print_policy. Add overload taking a diagnostic_context. (diagnostic_context::maybe_show_locus): Move handling of null pretty_printer here, from layout ctor. Convert call to diagnostic_context::show_locus to diagnostic_source_print_policy::print. (diagnostic_source_print_policy::diagnostic_source_print_policy): New. (diagnostic_context::show_locus): Convert to... (diagnostic_source_print_policy::print): ...this. Convert pp from * to &. (layout_printer::print): New, based on material in diagnostic_context::show_locus. (selftest::make_char_policy): New. (selftest::test_display_widths): Update for above changes. (selftest::test_offset_impl): Likewise. (selftest::test_layout_x_offset_display_utf8): Likewise. (selftest::test_layout_x_offset_display_tab): Likewise. (selftest::test_diagnostic_show_locus_unknown_location): Use test_diagnostic_context::test_show_locus rather than diagnostic_show_locus. (selftest::test_one_liner_no_column): Likewise. (selftest::test_one_liner_caret_and_range): Likewise. (selftest::test_one_liner_multiple_carets_and_ranges): Likewise. (selftest::test_one_liner_fixit_insert_before): Likewise. (selftest::test_one_liner_fixit_insert_after): Likewise. (selftest::test_one_liner_fixit_remove): Likewise. (selftest::test_one_liner_fixit_replace): Likewise. (selftest::test_one_liner_fixit_replace_non_equal_range): Likewise. (selftest::test_one_liner_fixit_replace_equal_secondary_range): Likewise. (selftest::test_one_liner_fixit_validation_adhoc_locations): Likewise. (selftest::test_one_liner_many_fixits_1): Likewise. (selftest::test_one_liner_many_fixits_2): Likewise. (selftest::test_one_liner_labels): Likewise. (selftest::test_one_liner_simple_caret_utf8): Likewise. (selftest::test_one_liner_caret_and_range_utf8): Likewise. (selftest::test_one_liner_multiple_carets_and_ranges_utf8): Likewise. (selftest::test_one_liner_fixit_insert_before_utf8): Likewise. (selftest::test_one_liner_fixit_insert_after_utf8): Likewise. (selftest::test_one_liner_fixit_remove_utf8): Likewise. (selftest::test_one_liner_fixit_replace_utf8): Likewise. (selftest::test_one_liner_fixit_replace_non_equal_range_utf8): Likewise. (selftest::test_one_liner_fixit_replace_equal_secondary_range_utf8): Likewise. (selftest::test_one_liner_fixit_validation_adhoc_locations_utf8): Likewise. (selftest::test_one_liner_many_fixits_1_utf8): Likewise. (selftest::test_one_liner_many_fixits_2_utf8): Likewise. (selftest::test_one_liner_labels_utf8): Likewise. (selftest::test_one_liner_colorized_utf8): Likewise. (selftest::test_add_location_if_nearby): Likewise. (selftest::test_diagnostic_show_locus_fixit_lines): Likewise. (selftest::test_overlapped_fixit_printing): Likewise. (selftest::test_overlapped_fixit_printing_utf8): Likewise. (selftest::test_overlapped_fixit_printing_2): Likewise. (selftest::test_fixit_insert_containing_newline): Likewise. (selftest::test_fixit_insert_containing_newline_2): Likewise. (selftest::test_fixit_replace_containing_newline): Likewise. (selftest::test_fixit_deletion_affecting_newline): Likewise. (selftest::test_tab_expansion): Likewise. (selftest::test_escaping_bytes_1): Likewise. (selftest::test_escaping_bytes_2): Likewise. (selftest::test_line_numbers_multiline_range): Likewise. * diagnostic.cc (diagnostic_column_policy::diagnostic_column_policy): New. (diagnostic_context::converted_column): Convert to... (diagnostic_column_policy::converted_column): ...this. (diagnostic_context::get_location_text): Convert to... (diagnostic_column_policy::get_location_text): ...this, adding "show_column" param. (diagnostic_location_print_policy::diagnostic_location_print_policy): New ctors. (default_diagnostic_start_span_fn): Convert param from diagnostic_context * to const diagnostic_location_print_policy &. Add "pp" param. (selftest::assert_location_text): Update for above changes. (selftest::test_diagnostic_get_location_text): Rename to... (selftest::test_get_location_text): ...this. (selftest::c_diagnostic_cc_tests): Update for renaming. * diagnostic.h (class diagnostic_location_print_policy): New forward decl. (class diagnostic_source_print_policy): New forward decl. (diagnostic_start_span_fn): Convert first param from diagnostic_context * to const diagnostic_location_print_policy & and add pretty_printer * param. (class diagnostic_column_policy): New. (class diagnostic_location_print_policy): New. (class diagnostic_source_print_policy): New. (class diagnostic_context): Add friend class diagnostic_source_print_policy. (diagnostic_context::converted_column): Drop decl in favor of diagnostic_column_policy::converted_column. (diagnostic_context::get_location_text): Drop decl in favor of diagnostic_column_policy::get_location_text. (diagnostic_context::show_locus): Drop decl in favor of diagnostic_source_print_policy::print. (default_diagnostic_start_span_fn): Update for change to diagnostic_start_span_fn. * gcc-rich-location.h (class diagnostic_source_print_policy): New forward decl. (gcc_rich_location::add_location_if_nearby): Convert first param from diagnostic_context to diagnostic_source_print_policy. Add overload taking diagnostic_context. * selftest-diagnostic.cc (selftest::test_diagnostic_context::test_diagnostic_context): Turn off colorization. (selftest::test_diagnostic_context::start_span_cb): Update for change to callback type. (test_diagnostic_context::test_show_locus): New. * selftest-diagnostic.h (selftest::test_diagnostic_context::start_span_cb): Update for change to callback type. (test_diagnostic_context::test_show_locus): New decl. gcc/fortran/ChangeLog: PR other/116613 * error.cc (gfc_diagnostic_build_locus_prefix): Convert first param from diagnostic_context * to const diagnostic_location_print_policy &. Add colorize param. Likewise for the "two expanded_locations" overload. (gfc_diagnostic_text_starter): Update for above changes. (gfc_diagnostic_start_span): Update for change to callback type. gcc/testsuite/ChangeLog: PR other/116613 * gcc.dg/plugin/diagnostic_group_plugin.c (test_diagnostic_start_span_fn): Update for change to callback type. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-09-20diagnostics: convert text hooks to use diagnostic_text_output_format [PR116613]David Malcolm1-1/+30
The diagnostic_starter and diagnostic_finalizer callbacks and most of their support subroutines are only used by the "text" output format. Emphasize this and reduce the binding with diagnostic_context by renaming the callbacks to add "_text" in their names, and converting the first param from diagnostic_context * to diagnostic_text_output_output &. Update the various subroutines used by diagnostic starter/finalizer callbacks to also take a diagnostic_text_output_output & rather than a diagnostic_context *. Move m_includes and m_last_seen from the context to the text output. Use the text_output's get_printer () rather than the context's m_printer, which should ease the transition to multiple output sinks. No functional change intended. gcc/c-family/ChangeLog: PR other/116613 * c-opts.cc: Include "diagnostic-format-text.h". (c_diagnostic_finalizer): Rename to... (c_diagnostic_text_finalizer): ...this. Convert first param from diagnostic_context * to diagnostic_text_output_format & and update accordingly. (c_common_diagnostics_set_defaults): Update for renamings. gcc/ChangeLog: PR other/116613 * coretypes.h (class diagnostic_text_output_format): Add forward decl. * diagnostic-format-json.cc (json_output_format::after_diagnostic): New. * diagnostic-format-sarif.cc (sarif_output_format::after_diagnostic): New. * diagnostic-format-text.cc: Use pragmas to ignore -Wformat-diag. (diagnostic_text_output_format::~diagnostic_text_output_format): Use get_printer. Clean up m_includes_seen here, rather than in ~diagnostic_context. (diagnostic_text_output_format::on_report_diagnostic): Use get_printer. Update for callback renamings and pass *this to them, rather than &m_context. (diagnostic_text_output_format::after_diagnostic): New. (diagnostic_text_output_format::includes_seen_p): Move here from diagnostic_context/diagnostic.cc. (diagnostic_text_output_format::get_location_text): New. (maybe_line_and_column): Move here from diagnostic.cc and make non-static. (diagnostic_text_output_format::report_current_module): Move here from diagnostic_context/diagnostic.cc. (default_diagnostic_text_starter): Move here from diagnostic.cc, renaming from default_diagnostic_starter. (default_diagnostic_text_finalizer): Likewise, renaming from default_diagnostic_finalizer. * diagnostic-format-text.h (diagnostic_text_output_format::diagnostic_text_output_format): Initialize m_last_module and m_includes_seen. (diagnostic_text_output_format::after_diagnostic): New decl. (diagnostic_text_output_format::build_prefix): New decl. (diagnostic_text_output_format::report_current_module): New decl. (diagnostic_text_output_format::append_note): New decl. (diagnostic_text_output_format::file_name_as_prefix): New decl. (diagnostic_text_output_format::print_path): New decl. (diagnostic_text_output_format::show_column_p): New decl. (diagnostic_text_output_format::get_location_text): New decl. (diagnostic_text_output_format::includes_seen_p): New decl. (diagnostic_text_output_format::show_any_path): New decl. (diagnostic_text_output_format::m_last_module): New field. (diagnostic_text_output_format::m_includes_seen): New field. * diagnostic-format.h (diagnostic_output_format::after_diagnostic): New vfunc. (diagnostic_output_format::get_context): New. (diagnostic_output_format::get_diagram_theme): New. * diagnostic-macro-unwinding.cc: Include "diagnostic-format-text.h". (maybe_unwind_expanded_macro_loc): Convert first param from diagnostic_context * to diagnostic_text_output_format & and update accordingly. (virt_loc_aware_diagnostic_finalizer): Likewise. * diagnostic-macro-unwinding.h (virt_loc_aware_diagnostic_finalizer): Likewise. (maybe_unwind_expanded_macro_loc): Likewise. * diagnostic-path.cc: Include "diagnostic-format-text.h". (path_label::path_label): Drop "ctxt" param and add "colorize" and "allow_emojis" params. Update initializations. (path_label::get_text): Use m_colorize rather than querying m_ctxt.m_printer. Use m_allow_emojis rather than querying m_ctxt's diagram theme. (path_label::m_ctxt): Drop field. (path_label::m_colorize): Drop field. (path_label::m_allow_emojis): Drop field. (event_range::event_range): Drop param "ctxt". Add params "colorize_labels" and "allow_emojis". (event_range::print): Convert first param from diagnostic_context & to diagnostic_text_output_format & and update accordingly. (path_summary::path_summary): Likewise. (path_summary::print_swimlane_for_event_range): Likewise. (print_path_summary_as_text): Likewise for 3rd param. (diagnostic_context::print_path): Convert to... (diagnostic_text_output_format::print_path): ...this. (selftest::test_empty_path): Update to use a diagnostic_text_output_format. (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. * diagnostic.cc (file_name_as_prefix): Convert to... (diagnostic_text_output_format::file_name_as_prefix): ...this. (diagnostic_context::initialize): Update for renamings. Move m_last_module and m_includes_seen into text output. (diagnostic_context::finish): Likewise. (diagnostic_context::get_location_text): Add "colorize" param. (diagnostic_build_prefix): Convert to... (diagnostic_text_output_format::build_prefix): ...this. (diagnostic_context::includes_seen_p): Move from here to diagnostic_text_output_format/diagnostic-format-text.cc. (diagnostic_context::report_current_module): Likewise. (diagnostic_context::show_any_path): Convert to... (diagnostic_text_output_format::show_any_path): ...this. (default_diagnostic_starter): Rename and move to diagnostic-format-text.cc. (default_diagnostic_start_span_fn): Pass colorize bool to get_location_text. (default_diagnostic_finalizer): Rename and move to diagnostic-format-text.cc. (diagnostic_context::report_diagnostic): Replace call to show_any_path with call to new output format "after_diagnostic" vfunc, moving show_any_path call to the text output format. (diagnostic_append_note): Convert to... (diagnostic_text_output_format::append_note): ...this. (selftest::assert_location_text): Pass in false for colorization. * diagnostic.h (diagnostic_starter_fn): Rename to... (diagnostic_text_starter_fn): ...this. Convert first param from diagnostic_context * to diagnostic_text_output_format &. (diagnostic_finalizer_fn, diagnostic_text_finalizer_fn): Likewise. (diagnostic_context): Update friends for renamings. (diagnostic_context::report_current_module): Move to text output format. (diagnostic_context::get_location_text): Add "colorize" bool. (diagnostic_context::includes_seen_p): Move to text output format. (diagnostic_context::show_any_path): Likewise. (diagnostic_context::print_path): Likewise. (diagnostic_context::m_text_callbacks): Update for renamings. (diagnostic_context::m_last_module): Move to text output format. (diagnostic_context::m_includes_seen): Likewise. (diagnostic_starter): Rename to... (diagnostic_text_starter): ...this and update return type. (diagnostic_finalizer): Rename to... (diagnostic_text_finalizer): ...this and update return type. (diagnostic_report_current_module): Drop decl in favor of a member function of diagnostic_text_output_format. (diagnostic_append_note): Likewise. (default_diagnostic_starter): Rename to... (default_diagnostic_text_starter): ...this, updating type. (default_diagnostic_finalizer): Rename to... (default_diagnostic_text_finalizer): ...this, updating type. (file_name_as_prefix): Drop decl. * langhooks-def.h (lhd_print_error_function): Convert first param from diagnostic_context * to diagnostic_text_output_format &. * langhooks.cc: Include "diagnostic-format-text.h". (lhd_print_error_function): Likewise. Update accordingly * langhooks.h (lang_hooks::print_error_function): Convert first param from diagnostic_context * to diagnostic_text_output_format &. * tree-diagnostic.cc: Include "diagnostic-format-text.h". (diagnostic_report_current_function): Convert first param from diagnostic_context * to diagnostic_text_output_format & and update accordingly. (default_tree_diagnostic_starter): Rename to... (default_tree_diagnostic_text_starter): ...this. Convert first param from diagnostic_context * to diagnostic_text_output_format & and update accordingly. (tree_diagnostics_defaults): Update for renamings. gcc/cp/ChangeLog: PR other/116613 * cp-tree.h (cxx_print_error_function): Convert first param from diagnostic_context * to diagnostic_text_output_format &. * error.cc: Include "diagnostic-format-text.h". (cxx_initialize_diagnostics): Update for renamings. (cxx_print_error_function): Convert first param from diagnostic_context * to diagnostic_text_output_format & and update accordingly (cp_diagnostic_starter): Rename to... (cp_diagnostic_text_starter): ...this. Convert first param from diagnostic_context * to diagnostic_text_output_format & and update accordingly. (cp_print_error_function): Likewise. (print_instantiation_full_context): Likewise. (print_instantiation_partial_context_line): Likewise. (print_instantiation_partial_context): Likewise. (maybe_print_instantiation_context): Likewise. (maybe_print_constexpr_context): Likewise. (print_location): Likewise. (print_constrained_decl_info): Likewise. (print_concept_check_info): Likewise. (print_constraint_context_head): Likewise. (print_requires_expression_info): Likewise. (maybe_print_single_constraint_context): Likewise. gcc/fortran/ChangeLog: PR other/116613 * error.cc: Include "diagnostic-format-text.h". (gfc_diagnostic_starter): Rename to... (gfc_diagnostic_text_starter): ...this. Convert first param from diagnostic_context * to diagnostic_text_output_format & and update accordingly. (gfc_diagnostic_finalizer, gfc_diagnostic_text_finalizer): Likewise. (gfc_diagnostics_init): Update for renamings. (gfc_diagnostics_finish): Likewise. gcc/jit/ChangeLog: PR other/116613 * dummy-frontend.cc: Include "diagnostic-format-text.h". (jit_begin_diagnostic): Convert first param from diagnostic_context * to diagnostic_text_output_format & (jit_end_diagnostic): Likewise. Update accordingly. (jit_langhook_init): Update for renamings. gcc/rust/ChangeLog: PR other/116613 * resolve/rust-ast-resolve-expr.cc (funny_ice_finalizer): : Convert first param from diagnostic_context * to diagnostic_text_output_format &. (ResolveExpr::visit): Update for renaming. gcc/testsuite/ChangeLog: PR other/116613 * g++.dg/plugin/show_template_tree_color_plugin.c (noop_starter_fn): Rename to... (noop_text_starter_fn): ...this. Update first param from dc to text_output. (plugin_init): Update for renamings. * gcc.dg/plugin/diagnostic_group_plugin.c (test_diagnostic_starter): Rename to... (test_diagnostic_text_starter): ...this. Update first param from dc to text_output. (plugin_init): Update for renaming. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Include "diagnostic-format-text.h". (custom_diagnostic_finalizer): Rename to... (custom_diagnostic_text_finalizer): ...this. Update first param from dc to text_output. (test_show_locus): Update for renamings. * gcc.dg/plugin/location_overflow_plugin.c: Include "diagnostic-format-text.h". (original_finalizer): Rename to... (original_text_finalizer): ...this and update type. (verify_unpacked_ranges): Update first param from dc to text_output. Update for this and for renamings. (verify_no_columns): Likewise. (plugin_init): Update for renamings. libcc1/ChangeLog: PR other/116613 * context.cc: Include "diagnostic-format-text.h". (plugin_print_error_function): Update first param from diagnostic_context * to diagnostic_text_output_format &. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-08-26diagnostics: move output formats from diagnostic.{c,h} to their own filesDavid Malcolm1-0/+56
In particular, move the classic text output code to a diagnostic-text.cc (analogous to -json.cc and -sarif.cc). No functional change intended. 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 <dmalcolm@redhat.com>