https://gcc.gnu.org/g:e31ec9ee65386a7cf978c204e123b9a97eb9c296
commit r16-2530-ge31ec9ee65386a7cf978c204e123b9a97eb9c296 Author: David Malcolm <dmalc...@redhat.com> Date: Fri Jul 25 15:13:37 2025 -0400 diagnostics: introduce diagnostics/source-printing.cc Move diagnostic-show-locus.cc to diagnostics/source-printing.cc Move diagnostic-label-effects.h to diagnostics/source-printing-effects.h Move selftest-diagnostic-show-locus.h to diagnostics/selftest-source-printing.h No functional change intended. gcc/ChangeLog: * Makefile.in (OBJS): Replace diagnostic-show-locus.o with diagnostics/source-printing.o. * diagnostic.h (class diagnostic_source_effect_info): Replace with... (class diagnotics::source_effect_info): ...this. * diagnostics/paths-output.cc: Likewise. Update for move of "diagnostic-label-effects.h" to "diagnostics/source-printing-effects.h". * diagnostics/sarif-sink.cc: Update for move of "selftest-diagnostic-show-locus.h" to "diagnostics/selftest-source-printing.h". * selftest-diagnostic-show-locus.h: Move to... * diagnostics/selftest-source-printing.h: ...here. * diagnostic-label-effects.h: Move to... * diagnostics/source-printing-effects.h: ...here, updating for above changes. * diagnostic-show-locus.cc: Move to... * diagnostics/source-printing.cc: ...here. * gcc-rich-location.h: Likewise. * selftest-run-tests.cc: Likewise. * selftest.h: Likewise. gcc/testsuite/ChangeLog: * g++.dg/plugin/show-template-tree-color-labels.C: Update for moves to "source-printing". * gcc.dg/plugin/diagnostic-test-show-locus.py: Likewise. libcpp/ChangeLog: * include/cpplib.h: Update for moves to "source-printing". * include/rich-location.h (class label_effects): Move to... (class diagnostics::label_effects): ...here. Signed-off-by: David Malcolm <dmalc...@redhat.com> Diff: --- gcc/Makefile.in | 2 +- gcc/diagnostic.h | 16 ++++++------- gcc/diagnostics/paths-output.cc | 17 +++++++------- gcc/diagnostics/sarif-sink.cc | 2 +- .../selftest-source-printing.h} | 6 ++--- .../source-printing-effects.h} | 14 +++++++----- .../source-printing.cc} | 26 ++++++++++++---------- gcc/gcc-rich-location.h | 2 +- gcc/selftest-run-tests.cc | 2 +- gcc/selftest.h | 2 +- .../plugin/show-template-tree-color-labels.C | 2 +- .../gcc.dg/plugin/diagnostic-test-show-locus.py | 2 +- libcpp/include/cpplib.h | 3 ++- libcpp/include/rich-location.h | 5 +++-- 14 files changed, 55 insertions(+), 46 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index f475a2e7dde6..6289dcae8f25 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1855,7 +1855,6 @@ OBJS = \ OBJS-libcommon = diagnostic-spec.o diagnostic.o diagnostic-color.o \ diagnostic-global-context.o \ diagnostic-macro-unwinding.o \ - diagnostic-show-locus.o \ diagnostics/digraphs.o \ diagnostics/edit-context.o \ diagnostics/output-spec.o \ @@ -1864,6 +1863,7 @@ OBJS-libcommon = diagnostic-spec.o diagnostic.o diagnostic-color.o \ diagnostics/text-sink.o \ diagnostics/paths.o \ diagnostics/paths-output.o \ + diagnostics/source-printing.o \ diagnostics/state-graphs.o \ diagnostics/state-graphs-to-dot.o \ diagnostics/selftest-logical-locations.o \ diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index c9d4cc04b0ee..43732bba3218 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -45,6 +45,8 @@ namespace diagnostics { class sink; class text_sink; + class source_effect_info; + } // namespace diagnostics namespace text_art @@ -240,8 +242,6 @@ public: virtual char *make_option_url (diagnostic_option_id option_id) const = 0; }; -class diagnostic_source_effect_info; - /* A stack of sets of classifications: each entry in the stack is a mapping from option index to diagnostic severity that can be changed via pragmas. The stack can be pushed and popped. */ @@ -451,13 +451,13 @@ public: print (pretty_printer &pp, const rich_location &richloc, diagnostic_t diagnostic_kind, - diagnostic_source_effect_info *effect_info) const; + diagnostics::source_effect_info *effect_info) const; void print_as_html (xml::printer &xp, const rich_location &richloc, diagnostic_t diagnostic_kind, - diagnostic_source_effect_info *effect_info, + diagnostics::source_effect_info *effect_info, html_label_writer *label_writer) const; const diagnostic_source_printing_options & @@ -659,12 +659,12 @@ public: const diagnostic_source_printing_options &opts, diagnostic_t diagnostic_kind, pretty_printer &pp, - diagnostic_source_effect_info *effect_info); + diagnostics::source_effect_info *effect_info); void maybe_show_locus_as_html (const rich_location &richloc, const diagnostic_source_printing_options &opts, diagnostic_t diagnostic_kind, xml::printer &xp, - diagnostic_source_effect_info *effect_info, + diagnostics::source_effect_info *effect_info, html_label_writer *label_writer); void emit_diagram (const diagnostics::diagram &diag); @@ -1217,7 +1217,7 @@ diagnostic_show_locus (diagnostic_context *context, rich_location *richloc, diagnostic_t diagnostic_kind, pretty_printer *pp, - diagnostic_source_effect_info *effect_info = nullptr) + diagnostics::source_effect_info *effect_info = nullptr) { gcc_assert (context); gcc_assert (richloc); @@ -1231,7 +1231,7 @@ diagnostic_show_locus_as_html (diagnostic_context *context, rich_location *richloc, diagnostic_t diagnostic_kind, xml::printer &xp, - diagnostic_source_effect_info *effect_info = nullptr, + diagnostics::source_effect_info *effect_info = nullptr, html_label_writer *label_writer = nullptr) { gcc_assert (context); diff --git a/gcc/diagnostics/paths-output.cc b/gcc/diagnostics/paths-output.cc index 8d9eb99b8d01..599d6849cfc7 100644 --- a/gcc/diagnostics/paths-output.cc +++ b/gcc/diagnostics/paths-output.cc @@ -32,7 +32,7 @@ along with GCC; see the file COPYING3. If not see #include "gcc-rich-location.h" #include "diagnostic-color.h" #include "diagnostics/event-id.h" -#include "diagnostic-label-effects.h" +#include "diagnostics/source-printing-effects.h" #include "pretty-print-markup.h" #include "selftest.h" #include "selftest-diagnostic.h" @@ -137,7 +137,8 @@ class path_label : public range_label return result; } - const label_effects *get_effects (unsigned /*range_idx*/) const final override + const diagnostics::label_effects * + get_effects (unsigned /*range_idx*/) const final override { return &m_effects; } @@ -594,7 +595,7 @@ struct event_range void print_as_text (pretty_printer &pp, diagnostics::text_sink &text_output, - diagnostic_source_effect_info *effect_info) + diagnostics::source_effect_info *effect_info) { location_t initial_loc = m_initial_event.get_location (); @@ -653,7 +654,7 @@ struct event_range void print_as_html (xml::printer &xp, diagnostic_context &dc, - diagnostic_source_effect_info *effect_info, + diagnostics::source_effect_info *effect_info, html_label_writer *event_label_writer) { location_t initial_loc = m_initial_event.get_location (); @@ -887,7 +888,7 @@ public: pretty_printer *pp, const logical_locations::manager &logical_loc_mgr, event_range *range, - diagnostic_source_effect_info *effect_info) + diagnostics::source_effect_info *effect_info) { gcc_assert (pp); const char *const line_color = "path"; @@ -1047,7 +1048,7 @@ public: xml::printer &xp, html_label_writer *event_label_writer, event_range *range, - diagnostic_source_effect_info *effect_info) + diagnostics::source_effect_info *effect_info) { range->print_as_html (xp, dc, effect_info, event_label_writer); m_num_printed++; @@ -1137,7 +1138,7 @@ print_path_summary_as_text (const path_summary &ps, thread_event_printer &tep = thread_event_printers[swimlane_idx]; /* Wire up any trailing out-edge from previous range to leading in-edge of this range. */ - diagnostic_source_effect_info effect_info; + diagnostics::source_effect_info effect_info; effect_info.m_leading_in_edge_column = last_out_edge_column; tep.print_swimlane_for_event_range_as_text (text_output, pp, @@ -1263,7 +1264,7 @@ print_path_summary_as_html (const path_summary &ps, thread_event_printer &tep = thread_event_printers[swimlane_idx]; /* Wire up any trailing out-edge from previous range to leading in-edge of this range. */ - diagnostic_source_effect_info effect_info; + diagnostics::source_effect_info effect_info; effect_info.m_leading_in_edge_column = last_out_edge_column; tep.print_swimlane_for_event_range_as_html (dc, xp, event_label_writer, range, &effect_info); diff --git a/gcc/diagnostics/sarif-sink.cc b/gcc/diagnostics/sarif-sink.cc index 79c4bf3e6789..d8b1d52906f0 100644 --- a/gcc/diagnostics/sarif-sink.cc +++ b/gcc/diagnostics/sarif-sink.cc @@ -45,7 +45,7 @@ along with GCC; see the file COPYING3. If not see #include "sbitmap.h" #include "selftest.h" #include "selftest-diagnostic.h" -#include "selftest-diagnostic-show-locus.h" +#include "diagnostics/selftest-source-printing.h" #include "selftest-json.h" #include "text-range-label.h" #include "pretty-print-format-impl.h" diff --git a/gcc/selftest-diagnostic-show-locus.h b/gcc/diagnostics/selftest-source-printing.h similarity index 94% rename from gcc/selftest-diagnostic-show-locus.h rename to gcc/diagnostics/selftest-source-printing.h index 37a18b23c7d5..7b86d85adc12 100644 --- a/gcc/selftest-diagnostic-show-locus.h +++ b/gcc/diagnostics/selftest-source-printing.h @@ -17,8 +17,8 @@ You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see <http://www.gnu.org/licenses/>. */ -#ifndef GCC_SELFTEST_DIAGNOSTIC_SHOW_LOCUS_H -#define GCC_SELFTEST_DIAGNOSTIC_SHOW_LOCUS_H +#ifndef GCC_DIAGNOSTICS_SELFTEST_SOURCE_PRINTING_H +#define GCC_DIAGNOSTICS_SELFTEST_SOURCE_PRINTING_H #include "selftest.h" @@ -79,4 +79,4 @@ struct diagnostic_show_locus_fixture_one_liner_utf8 #endif /* #if CHECKING_P */ -#endif /* GCC_SELFTEST_DIAGNOSTIC_SHOW_LOCUS_H */ +#endif /* GCC_DIAGNOSTICS_SELFTEST_SOURCE_PRINTING_H */ diff --git a/gcc/diagnostic-label-effects.h b/gcc/diagnostics/source-printing-effects.h similarity index 86% rename from gcc/diagnostic-label-effects.h rename to gcc/diagnostics/source-printing-effects.h index 1d877b0d2685..3c4b1bd222ca 100644 --- a/gcc/diagnostic-label-effects.h +++ b/gcc/diagnostics/source-printing-effects.h @@ -18,8 +18,10 @@ You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see <http://www.gnu.org/licenses/>. */ -#ifndef GCC_DIAGNOSTIC_LABEL_EFFECTS_H -#define GCC_DIAGNOSTIC_LABEL_EFFECTS_H +#ifndef GCC_DIAGNOSTICS_SOURCE_PRINTING_EFFECTS_H +#define GCC_DIAGNOSTICS_SOURCE_PRINTING_EFFECTS_H + +namespace diagnostics { /* Abstract base class for describing special effects when printing a label when quoting source code. */ @@ -37,10 +39,10 @@ public: /* A class to hold state when quoting a run of lines of source code. */ -class diagnostic_source_effect_info +class source_effect_info { public: - diagnostic_source_effect_info () + source_effect_info () : m_leading_in_edge_column (-1), m_trailing_out_edge_column (-1) { @@ -55,4 +57,6 @@ public: int m_trailing_out_edge_column; }; -#endif /* GCC_DIAGNOSTIC_LABEL_EFFECTS_H */ +} // namespace diagnostics + +#endif /* GCC_DIAGNOSTICS_SOURCE_PRINTING_EFFECTS_H */ diff --git a/gcc/diagnostic-show-locus.cc b/gcc/diagnostics/source-printing.cc similarity index 99% rename from gcc/diagnostic-show-locus.cc rename to gcc/diagnostics/source-printing.cc index a688d9e4bb68..843f6712df74 100644 --- a/gcc/diagnostic-show-locus.cc +++ b/gcc/diagnostics/source-printing.cc @@ -34,11 +34,11 @@ along with GCC; see the file COPYING3. If not see #include "text-range-label.h" #include "selftest.h" #include "selftest-diagnostic.h" -#include "selftest-diagnostic-show-locus.h" +#include "diagnostics/selftest-source-printing.h" #include "cpplib.h" #include "text-art/types.h" #include "text-art/theme.h" -#include "diagnostic-label-effects.h" +#include "diagnostics/source-printing-effects.h" #include "xml.h" #include "xml-printer.h" @@ -766,7 +766,7 @@ class layout layout (const diagnostic_source_print_policy &source_policy, const rich_location &richloc, - diagnostic_source_effect_info *effect_info = nullptr); + diagnostics::source_effect_info *effect_info = nullptr); bool maybe_add_location_range (const location_range *loc_range, unsigned original_idx, @@ -816,7 +816,7 @@ class layout file_cache &m_file_cache; const text_art::ascii_theme m_fallback_theme; const text_art::theme &m_theme; - diagnostic_source_effect_info *m_effect_info; + diagnostics::source_effect_info *m_effect_info; char_display_policy m_char_policy; location_t m_primary_loc; exploc_with_display_col m_exploc; @@ -1206,7 +1206,8 @@ layout_range::has_in_edge () const { if (!m_label) return false; - const label_effects *effects = m_label->get_effects (m_original_idx); + const diagnostics::label_effects *effects + = m_label->get_effects (m_original_idx); if (!effects) return false; @@ -1220,7 +1221,8 @@ layout_range::has_out_edge () const { if (!m_label) return false; - const label_effects *effects = m_label->get_effects (m_original_idx); + const diagnostics::label_effects *effects + = m_label->get_effects (m_original_idx); if (!effects) return false; @@ -1739,7 +1741,7 @@ make_char_policy (const diagnostic_source_print_policy &source_policy, layout::layout (const diagnostic_source_print_policy &source_policy, const rich_location &richloc, - diagnostic_source_effect_info *effect_info) + diagnostics::source_effect_info *effect_info) : m_options (source_policy.get_options ()), m_line_table (richloc.get_line_table ()), m_file_cache (source_policy.get_file_cache ()), @@ -3845,7 +3847,7 @@ diagnostic_context::maybe_show_locus (const rich_location &richloc, const diagnostic_source_printing_options &opts, diagnostic_t diagnostic_kind, pretty_printer &pp, - diagnostic_source_effect_info *effects) + diagnostics::source_effect_info *effects) { const location_t loc = richloc.get_loc (); /* Do nothing if source-printing has been disabled. */ @@ -3878,7 +3880,7 @@ diagnostic_context::maybe_show_locus_as_html (const rich_location &richloc, const diagnostic_source_printing_options &opts, diagnostic_t diagnostic_kind, xml::printer &xp, - diagnostic_source_effect_info *effects, + diagnostics::source_effect_info *effects, html_label_writer *label_writer) { const location_t loc = richloc.get_loc (); @@ -3939,7 +3941,7 @@ void diagnostic_source_print_policy::print (pretty_printer &pp, const rich_location &richloc, diagnostic_t diagnostic_kind, - diagnostic_source_effect_info *effects) + diagnostics::source_effect_info *effects) const { layout layout (*this, richloc, effects); @@ -3957,7 +3959,7 @@ void diagnostic_source_print_policy::print_as_html (xml::printer &xp, const rich_location &richloc, diagnostic_t diagnostic_kind, - diagnostic_source_effect_info *effects, + diagnostics::source_effect_info *effects, html_label_writer *label_writer) const { @@ -6973,7 +6975,7 @@ test_line_numbers_multiline_range () /* Run all of the selftests within this file. */ void -diagnostic_show_locus_cc_tests () +diagnostics_source_printing_cc_tests () { test_line_span (); diff --git a/gcc/gcc-rich-location.h b/gcc/gcc-rich-location.h index cbf59b745544..1d85e7e434d1 100644 --- a/gcc/gcc-rich-location.h +++ b/gcc/gcc-rich-location.h @@ -79,7 +79,7 @@ class gcc_rich_location : public rich_location if (!added secondary) inform (secondary_loc, "message for secondary"); - Implemented in diagnostic-show-locus.cc. */ + Implemented in diagnostics/source-printing.cc. */ bool add_location_if_nearby (const diagnostic_source_print_policy &policy, location_t loc, diff --git a/gcc/selftest-run-tests.cc b/gcc/selftest-run-tests.cc index 956be00114be..b442f5325847 100644 --- a/gcc/selftest-run-tests.cc +++ b/gcc/selftest-run-tests.cc @@ -99,7 +99,7 @@ selftest::run_tests () /* Higher-level tests, or for components that other selftests don't rely on. */ diagnostic_color_cc_tests (); - diagnostic_show_locus_cc_tests (); + diagnostics_source_printing_cc_tests (); diagnostics_html_sink_cc_tests (); diagnostics_sarif_sink_cc_tests (); diagnostics_digraphs_cc_tests (); diff --git a/gcc/selftest.h b/gcc/selftest.h index d21abe369187..99a574bf3dd7 100644 --- a/gcc/selftest.h +++ b/gcc/selftest.h @@ -222,7 +222,6 @@ extern void cgraph_cc_tests (); extern void convert_cc_tests (); extern void dbgcnt_cc_tests (); extern void diagnostic_color_cc_tests (); -extern void diagnostic_show_locus_cc_tests (); extern void diagnostics_digraphs_cc_tests (); extern void diagnostics_html_sink_cc_tests (); extern void diagnostics_lazy_paths_cc_tests (); @@ -230,6 +229,7 @@ extern void diagnostics_output_spec_cc_tests (); extern void diagnostics_paths_output_cc_tests (); extern void diagnostics_sarif_sink_cc_tests (); extern void diagnostics_selftest_logical_locations_cc_tests (); +extern void diagnostics_source_printing_cc_tests (); extern void diagnostics_state_graphs_cc_tests (); extern void digraph_cc_tests (); extern void dumpfile_cc_tests (); diff --git a/gcc/testsuite/g++.dg/plugin/show-template-tree-color-labels.C b/gcc/testsuite/g++.dg/plugin/show-template-tree-color-labels.C index 3e9312665c79..71ae8f2806c9 100644 --- a/gcc/testsuite/g++.dg/plugin/show-template-tree-color-labels.C +++ b/gcc/testsuite/g++.dg/plugin/show-template-tree-color-labels.C @@ -1,4 +1,4 @@ -/* Verify colorization of the labels in diagnostic-show-locus.c +/* Verify colorization of the labels in diagnostics/source-printing.cc for template comparisons. Doing so requires a plugin; see the comments in the plugin for the rationale. */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus.py b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus.py index aca1b6cdaccd..eaca35a46b10 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus.py +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus.py @@ -1,4 +1,4 @@ -# Verify that diagnostic-show-locus.cc works with HTML output. +# Verify that diagnostics/source-printing.cc works with HTML output. from htmltest import * diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 7c147ae58477..75efdcd55d5a 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -1610,7 +1610,8 @@ struct cpp_decoded_char This is a tabstop value, along with a callback for getting the widths of characters. Normally this callback is cpp_wcwidth, but we support other schemes for escaping non-ASCII unicode as a series of - ASCII chars when printing the user's source code in diagnostic-show-locus.cc + ASCII chars when printing the user's source code in + gcc/diagnostics/source-printing.cc For example, consider: - the Unicode character U+03C0 "GREEK SMALL LETTER PI" (UTF-8: 0xCF 0x80) diff --git a/libcpp/include/rich-location.h b/libcpp/include/rich-location.h index caa976929472..c74e80e9f61e 100644 --- a/libcpp/include/rich-location.h +++ b/libcpp/include/rich-location.h @@ -25,7 +25,7 @@ along with this program; see the file COPYING3. If not see #include "label-text.h" class range_label; -class label_effects; +namespace diagnostics { class label_effects; } /* A hint to diagnostic_show_locus on how to print a source range within a rich_location. @@ -596,7 +596,8 @@ class range_label virtual label_text get_text (unsigned range_idx) const = 0; /* Get any special effects for the label (e.g. links to other labels). */ - virtual const label_effects *get_effects (unsigned /*range_idx*/) const + virtual const diagnostics::label_effects * + get_effects (unsigned /*range_idx*/) const { return nullptr; }