aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2025-07-25 15:13:37 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2025-07-25 15:13:37 -0400
commite31ec9ee65386a7cf978c204e123b9a97eb9c296 (patch)
tree8e24f260ed424ecf996334275b9616b00755d7e4
parent5ac3308484c78a7c4fa2a798df587a8bd507f030 (diff)
downloadgcc-e31ec9ee65386a7cf978c204e123b9a97eb9c296.zip
gcc-e31ec9ee65386a7cf978c204e123b9a97eb9c296.tar.gz
gcc-e31ec9ee65386a7cf978c204e123b9a97eb9c296.tar.bz2
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 <dmalcolm@redhat.com>
-rw-r--r--gcc/Makefile.in2
-rw-r--r--gcc/diagnostic.h16
-rw-r--r--gcc/diagnostics/paths-output.cc17
-rw-r--r--gcc/diagnostics/sarif-sink.cc2
-rw-r--r--gcc/diagnostics/selftest-source-printing.h (renamed from gcc/selftest-diagnostic-show-locus.h)6
-rw-r--r--gcc/diagnostics/source-printing-effects.h (renamed from gcc/diagnostic-label-effects.h)14
-rw-r--r--gcc/diagnostics/source-printing.cc (renamed from gcc/diagnostic-show-locus.cc)26
-rw-r--r--gcc/gcc-rich-location.h2
-rw-r--r--gcc/selftest-run-tests.cc2
-rw-r--r--gcc/selftest.h2
-rw-r--r--gcc/testsuite/g++.dg/plugin/show-template-tree-color-labels.C2
-rw-r--r--gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus.py2
-rw-r--r--libcpp/include/cpplib.h3
-rw-r--r--libcpp/include/rich-location.h5
14 files changed, 55 insertions, 46 deletions
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index f475a2e..6289dca 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 c9d4cc0..43732bb 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 8d9eb99..599d684 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 79c4bf3..d8b1d52 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
index 37a18b2..7b86d85 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
index 1d877b0d..3c4b1bd 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
index a688d9e..843f671 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 cbf59b7..1d85e7e 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 956be00..b442f53 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 d21abe3..99a574b 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 3e93126..71ae8f2 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 aca1b6c..eaca35a 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 7c147ae..75efdcd 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 caa9769..c74e80e 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;
}