public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-4367] diagnostics: group together source printing fields of diagnostic_context
@ 2023-10-02 16:25 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2023-10-02 16:25 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:c5c565eff6277ac176d6c5c94f55859d0eb28938

commit r14-4367-gc5c565eff6277ac176d6c5c94f55859d0eb28938
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Mon Oct 2 12:16:55 2023 -0400

    diagnostics: group together source printing fields of diagnostic_context
    
    struct diagnostic_context has > 60 fields.
    
    Try to tame some of the complexity by grouping together the 8
    source-printing fields into a struct, the "m_source_printing" field.
    
    No functional change intended.
    
    gcc/ada/ChangeLog:
            * gcc-interface/misc.cc (gnat_post_options): Update for renaming
            of diagnostic_context's show_caret to m_source_printing.enabled.
    
    gcc/analyzer/ChangeLog:
            * program-point.cc: Update for grouping of source printing fields
            within diagnostic_context.
    
    gcc/c-family/ChangeLog:
            * c-common.cc (maybe_add_include_fixit): Update for renaming of
            diagnostic_context's show_caret to m_source_printing.enabled.
            * c-opts.cc (c_common_init_options): Update for renaming of
            diagnostic_context's colorize_source_p to
            m_source_printing.colorize_source_p.
    
    gcc/ChangeLog:
            * diagnostic-show-locus.cc: Update for reorganization of
            source-printing fields of diagnostic_context.
            * diagnostic.cc (diagnostic_set_caret_max_width): Likewise.
            (diagnostic_initialize): Likewise.
            * diagnostic.h (diagnostic_context::show_caret): Move to...
            (diagnostic_context::m_source_printing::enabled): ...here.
            (diagnostic_context::caret_max_width): Move to...
            (diagnostic_context::m_source_printing::max_width): ...here.
            (diagnostic_context::caret_chars): Move to...
            (diagnostic_context::m_source_printing::caret_chars): ...here.
            (diagnostic_context::colorize_source_p): Move to...
            (diagnostic_context::m_source_printing::colorize_source_p): ...here.
            (diagnostic_context::show_labels_p): Move to...
            (diagnostic_context::m_source_printing::show_labels_p): ...here.
            (diagnostic_context::show_line_numbers_p): Move to...
            (diagnostic_context::m_source_printing::show_line_numbers_p): ...here.
            (diagnostic_context::min_margin_width): Move to...
            (diagnostic_context::m_source_printing::min_margin_width): ...here.
            (diagnostic_context::show_ruler_p): Move to...
            (diagnostic_context::m_source_printing::show_ruler_p): ...here.
            (diagnostic_same_line): Update for above changes.
            * opts.cc (common_handle_option): Update for reorganization of
            source-printing fields of diagnostic_context.
            * selftest-diagnostic.cc
            (test_diagnostic_context::test_diagnostic_context): Likewise.
            * toplev.cc (general_init): Likewise.
            * tree-diagnostic-path.cc (struct event_range): Likewise.
    
    gcc/fortran/ChangeLog:
            * error.cc (gfc_diagnostic_starter): Update for reorganization of
            source-printing fields of diagnostic_context.
            (gfc_diagnostics_init): Likewise.
            (gfc_diagnostics_finish): Likewise.
    
    gcc/testsuite/ChangeLog:
            * gcc.dg/plugin/diagnostic_plugin_show_trees.c: Update for
            reorganization of source-printing fields of diagnostic_context.
            * gcc.dg/plugin/diagnostic_plugin_test_inlining.c: Likewise.
            * gcc.dg/plugin/diagnostic_plugin_test_paths.c: Likewise.
            * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Likewise.
            * gcc.dg/plugin/diagnostic_plugin_test_string_literals.c: Likewise.
            * gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.c:
            Likewise.
    
    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

Diff:
---
 gcc/ada/gcc-interface/misc.cc                      |  2 +-
 gcc/analyzer/program-point.cc                      |  4 +-
 gcc/c-family/c-common.cc                           |  2 +-
 gcc/c-family/c-opts.cc                             |  2 +-
 gcc/diagnostic-show-locus.cc                       | 93 ++++++++++++----------
 gcc/diagnostic.cc                                  | 16 ++--
 gcc/diagnostic.h                                   | 73 +++++++++--------
 gcc/fortran/error.cc                               | 10 +--
 gcc/opts.cc                                        |  8 +-
 gcc/selftest-diagnostic.cc                         |  8 +-
 .../gcc.dg/plugin/diagnostic_plugin_show_trees.c   |  2 +-
 .../plugin/diagnostic_plugin_test_inlining.c       |  2 +-
 .../gcc.dg/plugin/diagnostic_plugin_test_paths.c   |  2 +-
 .../plugin/diagnostic_plugin_test_show_locus.c     | 26 +++---
 .../diagnostic_plugin_test_string_literals.c       |  2 +-
 .../diagnostic_plugin_test_tree_expression_range.c |  2 +-
 gcc/toplev.cc                                      |  8 +-
 gcc/tree-diagnostic-path.cc                        |  2 +-
 18 files changed, 140 insertions(+), 124 deletions(-)

diff --git a/gcc/ada/gcc-interface/misc.cc b/gcc/ada/gcc-interface/misc.cc
index 3b21bf5b43a..269c15e4b0d 100644
--- a/gcc/ada/gcc-interface/misc.cc
+++ b/gcc/ada/gcc-interface/misc.cc
@@ -269,7 +269,7 @@ gnat_post_options (const char **pfilename ATTRIBUTE_UNUSED)
 
   /* No caret by default for Ada.  */
   if (!OPTION_SET_P (flag_diagnostics_show_caret))
-    global_dc->show_caret = false;
+    global_dc->m_source_printing.enabled = false;
 
   /* Copy global settings to local versions.  */
   gnat_encodings = global_options.x_gnat_encodings;
diff --git a/gcc/analyzer/program-point.cc b/gcc/analyzer/program-point.cc
index d7db2f52239..914d49f0314 100644
--- a/gcc/analyzer/program-point.cc
+++ b/gcc/analyzer/program-point.cc
@@ -256,8 +256,8 @@ public:
   debug_diagnostic_context ()
   {
     diagnostic_initialize (this, 0);
-    show_line_numbers_p = true;
-    show_caret = true;
+    m_source_printing.show_line_numbers_p = true;
+    m_source_printing.enabled = true;
   }
   ~debug_diagnostic_context ()
   {
diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index aae57260097..f044db5b797 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -9569,7 +9569,7 @@ maybe_add_include_fixit (rich_location *richloc, const char *header,
   richloc->add_fixit_insert_before (include_insert_loc, text);
   free (text);
 
-  if (override_location && global_dc->show_caret)
+  if (override_location && global_dc->m_source_printing.enabled)
     {
       /* Replace the primary location with that of the insertion point for the
 	 fix-it hint.
diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
index fe2d14307f4..ce2e021e69d 100644
--- a/gcc/c-family/c-opts.cc
+++ b/gcc/c-family/c-opts.cc
@@ -272,7 +272,7 @@ c_common_init_options (unsigned int decoded_options_count,
   if (c_dialect_cxx ())
     set_std_cxx17 (/*ISO*/false);
 
-  global_dc->colorize_source_p = true;
+  global_dc->m_source_printing.colorize_source_p = true;
 }
 
 /* Handle switch SCODE with argument ARG.  VALUE is true, unless no-
diff --git a/gcc/diagnostic-show-locus.cc b/gcc/diagnostic-show-locus.cc
index 31ef85151fd..0778223ccb5 100644
--- a/gcc/diagnostic-show-locus.cc
+++ b/gcc/diagnostic-show-locus.cc
@@ -1193,9 +1193,9 @@ layout::layout (diagnostic_context * context,
   m_exploc (richloc->get_expanded_location (0), m_policy,
 	    LOCATION_ASPECT_CARET),
   m_colorizer (context, diagnostic_kind),
-  m_colorize_source_p (context->colorize_source_p),
-  m_show_labels_p (context->show_labels_p),
-  m_show_line_numbers_p (context->show_line_numbers_p),
+  m_colorize_source_p (context->m_source_printing.colorize_source_p),
+  m_show_labels_p (context->m_source_printing.show_labels_p),
+  m_show_line_numbers_p (context->m_source_printing.show_line_numbers_p),
   m_diagnostic_path_p (diagnostic_kind == DK_DIAGNOSTIC_PATH),
   m_layout_ranges (richloc->get_num_locations ()),
   m_fixit_hints (richloc->get_num_fixit_hints ()),
@@ -1229,8 +1229,8 @@ layout::layout (diagnostic_context * context,
   calculate_linenum_width ();
   calculate_x_offset_display ();
 
-  if (context->show_ruler_p)
-    show_ruler (m_x_offset_display + m_context->caret_max_width);
+  if (context->m_source_printing.show_ruler_p)
+    show_ruler (m_x_offset_display + m_context->m_source_printing.max_width);
 }
 
 
@@ -1595,7 +1595,8 @@ layout::calculate_linenum_width ()
     m_linenum_width = MAX (m_linenum_width, 3);
   /* If there's a minimum margin width, apply it (subtracting 1 for the space
      after the line number.  */
-  m_linenum_width = MAX (m_linenum_width, m_context->min_margin_width - 1);
+  m_linenum_width = MAX (m_linenum_width,
+			 m_context->m_source_printing.min_margin_width - 1);
 }
 
 /* Calculate m_x_offset_display, which improves readability in case the source
@@ -1609,7 +1610,7 @@ layout::calculate_x_offset_display ()
 {
   m_x_offset_display = 0;
 
-  const int max_width = m_context->caret_max_width;
+  const int max_width = m_context->m_source_printing.max_width;
   if (!max_width)
     {
       /* Nothing to do, the width is not capped.  */
@@ -1851,7 +1852,8 @@ layout::print_annotation_line (linenum_type row, const line_bounds lbounds)
 	      /* Draw the caret.  */
 	      char caret_char;
 	      if (state.range_idx < rich_location::STATICALLY_ALLOCATED_RANGES)
-		caret_char = m_context->caret_chars[state.range_idx];
+		caret_char
+		  = m_context->m_source_printing.caret_chars[state.range_idx];
 	      else
 		caret_char = '^';
 	      pp_character (m_pp, caret_char);
@@ -2838,7 +2840,7 @@ diagnostic_show_locus (diagnostic_context * context,
 {
   location_t loc = richloc->get_loc ();
   /* Do nothing if source-printing has been disabled.  */
-  if (!context->show_caret)
+  if (!context->m_source_printing.enabled)
     return;
 
   /* Don't attempt to print source for UNKNOWN_LOCATION and for builtins.  */
@@ -2860,7 +2862,7 @@ diagnostic_show_locus (diagnostic_context * context,
        line_span_idx++)
     {
       const line_span *line_span = layout.get_line_span (line_span_idx);
-      if (context->show_line_numbers_p)
+      if (context->m_source_printing.show_line_numbers_p)
 	{
 	  /* With line numbers, we should show whenever the line-numbering
 	     "jumps".  */
@@ -2959,11 +2961,11 @@ test_offset_impl (int caret_byte_col, int max_width,
 		  int left_margin = test_left_margin)
 {
   test_diagnostic_context dc;
-  dc.caret_max_width = max_width;
+  dc.m_source_printing.max_width = max_width;
   /* diagnostic_context::min_margin_width sets the minimum space reserved for
      the line number plus one space after.  */
-  dc.min_margin_width = left_margin - test_linenum_sep + 1;
-  dc.show_line_numbers_p = true;
+  dc.m_source_printing.min_margin_width = left_margin - test_linenum_sep + 1;
+  dc.m_source_printing.show_line_numbers_p = true;
   rich_location richloc (line_table,
 			 linemap_position_for_column (line_table,
 						      caret_byte_col));
@@ -3074,10 +3076,11 @@ test_layout_x_offset_display_utf8 (const line_table_case &case_)
   /* Test that the source line is offset as expected when printed.  */
   {
     test_diagnostic_context dc;
-    dc.caret_max_width = small_width - 6;
-    dc.min_margin_width = test_left_margin - test_linenum_sep + 1;
-    dc.show_line_numbers_p = true;
-    dc.show_ruler_p = true;
+    dc.m_source_printing.max_width = small_width - 6;
+    dc.m_source_printing.min_margin_width
+      = test_left_margin - test_linenum_sep + 1;
+    dc.m_source_printing.show_line_numbers_p = true;
+    dc.m_source_printing.show_ruler_p = true;
     rich_location richloc (line_table,
 			   linemap_position_for_column (line_table,
 							emoji_col));
@@ -3098,10 +3101,11 @@ test_layout_x_offset_display_utf8 (const line_table_case &case_)
      it with a padding space in this case.  */
   {
     test_diagnostic_context dc;
-    dc.caret_max_width = small_width - 5;
-    dc.min_margin_width = test_left_margin - test_linenum_sep + 1;
-    dc.show_line_numbers_p = true;
-    dc.show_ruler_p = true;
+    dc.m_source_printing.max_width = small_width - 5;
+    dc.m_source_printing.min_margin_width
+      = test_left_margin - test_linenum_sep + 1;
+    dc.m_source_printing.show_line_numbers_p = true;
+    dc.m_source_printing.show_ruler_p = true;
     rich_location richloc (line_table,
 			   linemap_position_for_column (line_table,
 							emoji_col + 2));
@@ -3201,9 +3205,10 @@ test_layout_x_offset_display_tab (const line_table_case &case_)
       test_diagnostic_context dc;
       dc.tabstop = tabstop;
       static const int small_width = 24;
-      dc.caret_max_width = small_width - 4;
-      dc.min_margin_width = test_left_margin - test_linenum_sep + 1;
-      dc.show_line_numbers_p = true;
+      dc.m_source_printing.max_width = small_width - 4;
+      dc.m_source_printing.min_margin_width
+	= test_left_margin - test_linenum_sep + 1;
+      dc.m_source_printing.show_line_numbers_p = true;
       layout test_layout (&dc, &richloc, DK_ERROR);
       test_layout.print_line (1);
 
@@ -3287,19 +3292,19 @@ test_one_liner_multiple_carets_and_ranges ()
     = make_location (linemap_position_for_column (line_table, 2),
 		     linemap_position_for_column (line_table, 1),
 		     linemap_position_for_column (line_table, 3));
-  dc.caret_chars[0] = 'A';
+  dc.m_source_printing.caret_chars[0] = 'A';
 
   location_t bar
     = make_location (linemap_position_for_column (line_table, 8),
 		     linemap_position_for_column (line_table, 7),
 		     linemap_position_for_column (line_table, 9));
-  dc.caret_chars[1] = 'B';
+  dc.m_source_printing.caret_chars[1] = 'B';
 
   location_t field
     = make_location (linemap_position_for_column (line_table, 13),
 		     linemap_position_for_column (line_table, 11),
 		     linemap_position_for_column (line_table, 15));
-  dc.caret_chars[2] = 'C';
+  dc.m_source_printing.caret_chars[2] = 'C';
 
   rich_location richloc (line_table, foo);
   richloc.add_range (bar, SHOW_RANGE_WITH_CARET);
@@ -3382,8 +3387,8 @@ test_one_liner_fixit_remove ()
   /* Normal, with ruler.  */
   {
     test_diagnostic_context dc;
-    dc.show_ruler_p = true;
-    dc.caret_max_width = 104;
+    dc.m_source_printing.show_ruler_p = true;
+    dc.m_source_printing.max_width = 104;
     diagnostic_show_locus (&dc, &richloc, DK_ERROR);
     ASSERT_STREQ ("          0         0         0         0         0         0         0         0         0         1    \n"
 		  "          1         2         3         4         5         6         7         8         9         0    \n"
@@ -3397,8 +3402,8 @@ test_one_liner_fixit_remove ()
   /* Test of adding a prefix, with ruler.  */
   {
     test_diagnostic_context dc;
-    dc.show_ruler_p = true;
-    dc.caret_max_width = 50;
+    dc.m_source_printing.show_ruler_p = true;
+    dc.m_source_printing.max_width = 50;
     pp_prefixing_rule (dc.printer) = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
     pp_set_prefix (dc.printer, xstrdup ("TEST PREFIX:"));
     diagnostic_show_locus (&dc, &richloc, DK_ERROR);
@@ -3413,9 +3418,9 @@ test_one_liner_fixit_remove ()
   /* Test of adding a prefix, with ruler and line numbers.  */
   {
     test_diagnostic_context dc;
-    dc.show_ruler_p = true;
-    dc.caret_max_width = 50;
-    dc.show_line_numbers_p = true;
+    dc.m_source_printing.show_ruler_p = true;
+    dc.m_source_printing.max_width = 50;
+    dc.m_source_printing.show_line_numbers_p = true;
     pp_prefixing_rule (dc.printer) = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
     pp_set_prefix (dc.printer, xstrdup ("TEST PREFIX:"));
     diagnostic_show_locus (&dc, &richloc, DK_ERROR);
@@ -3641,7 +3646,7 @@ test_one_liner_labels ()
     /* Verify that we can disable label-printing.  */
     {
       test_diagnostic_context dc;
-      dc.show_labels_p = false;
+      dc.m_source_printing.show_labels_p = false;
       diagnostic_show_locus (&dc, &richloc, DK_ERROR);
       ASSERT_STREQ (" foo = bar.field;\n"
 		    " ^~~   ~~~ ~~~~~\n",
@@ -3895,19 +3900,19 @@ test_one_liner_multiple_carets_and_ranges_utf8 ()
     = make_location (linemap_position_for_column (line_table, 7),
 		     linemap_position_for_column (line_table, 1),
 		     linemap_position_for_column (line_table, 8));
-  dc.caret_chars[0] = 'A';
+  dc.m_source_printing.caret_chars[0] = 'A';
 
   location_t bar
     = make_location (linemap_position_for_column (line_table, 16),
 		     linemap_position_for_column (line_table, 12),
 		     linemap_position_for_column (line_table, 17));
-  dc.caret_chars[1] = 'B';
+  dc.m_source_printing.caret_chars[1] = 'B';
 
   location_t field
     = make_location (linemap_position_for_column (line_table, 26),
 		     linemap_position_for_column (line_table, 19),
 		     linemap_position_for_column (line_table, 30));
-  dc.caret_chars[2] = 'C';
+  dc.m_source_printing.caret_chars[2] = 'C';
   rich_location richloc (line_table, foo);
   richloc.add_range (bar, SHOW_RANGE_WITH_CARET);
   richloc.add_range (field, SHOW_RANGE_WITH_CARET);
@@ -4348,7 +4353,7 @@ static void
 test_one_liner_colorized_utf8 ()
 {
   test_diagnostic_context dc;
-  dc.colorize_source_p = true;
+  dc.m_source_printing.colorize_source_p = true;
   diagnostic_color_init (&dc, DIAGNOSTICS_COLOR_YES);
   const location_t pi = linemap_position_for_column (line_table, 12);
   rich_location richloc (line_table, pi);
@@ -4563,7 +4568,7 @@ test_diagnostic_show_locus_fixit_lines (const line_table_case &case_)
     richloc.add_fixit_insert_before (y, ".");
     richloc.add_fixit_replace (colon, "=");
     test_diagnostic_context dc;
-    dc.show_line_numbers_p = true;
+    dc.m_source_printing.show_line_numbers_p = true;
     diagnostic_show_locus (&dc, &richloc, DK_ERROR);
     ASSERT_STREQ ("    3 |                        y\n"
 		  "      |                        .\n"
@@ -5304,7 +5309,7 @@ test_fixit_insert_containing_newline (const line_table_case &case_)
     /* With line numbers.  */
     {
       test_diagnostic_context dc;
-      dc.show_line_numbers_p = true;
+      dc.m_source_printing.show_line_numbers_p = true;
       diagnostic_show_locus (&dc, &richloc, DK_ERROR);
       ASSERT_STREQ ("    2 |       x = a;\n"
 		    "  +++ |+      break;\n"
@@ -5383,7 +5388,7 @@ test_fixit_insert_containing_newline_2 (const line_table_case &case_)
      consolidated, since it makes little sense to skip line 2.  */
   {
     test_diagnostic_context dc;
-    dc.show_line_numbers_p = true;
+    dc.m_source_printing.show_line_numbers_p = true;
     diagnostic_show_locus (&dc, &richloc, DK_ERROR);
     ASSERT_STREQ ("  +++ |+#include <stdio.h>\n"
 		  "    1 | test (int ch)\n"
@@ -5679,8 +5684,8 @@ test_line_numbers_multiline_range ()
   location_t loc = make_location (caret, start, finish);
 
   test_diagnostic_context dc;
-  dc.show_line_numbers_p = true;
-  dc.min_margin_width = 0;
+  dc.m_source_printing.show_line_numbers_p = true;
+  dc.m_source_printing.min_margin_width = 0;
   gcc_rich_location richloc (loc);
   diagnostic_show_locus (&dc, &richloc, DK_ERROR);
   ASSERT_STREQ (" 9 | this is line 9\n"
diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index 28ab74ff23e..b4bbd60590b 100644
--- a/gcc/diagnostic.cc
+++ b/gcc/diagnostic.cc
@@ -147,7 +147,7 @@ diagnostic_set_caret_max_width (diagnostic_context *context, int value)
   if (value <= 0) 
     value = INT_MAX;
 
-  context->caret_max_width = value;
+  context->m_source_printing.max_width = value;
 }
 
 /* Default implementation of final_cb.  */
@@ -189,10 +189,10 @@ diagnostic_initialize (diagnostic_context *context, int n_opts)
   context->classify_diagnostic = XNEWVEC (diagnostic_t, n_opts);
   for (i = 0; i < n_opts; i++)
     context->classify_diagnostic[i] = DK_UNSPECIFIED;
-  context->show_caret = false;
+  context->m_source_printing.enabled = false;
   diagnostic_set_caret_max_width (context, pp_line_cutoff (context->printer));
   for (i = 0; i < rich_location::STATICALLY_ALLOCATED_RANGES; i++)
-    context->caret_chars[i] = '^';
+    context->m_source_printing.caret_chars[i] = '^';
   context->show_cwe = false;
   context->show_rules = false;
   context->path_format = DPF_NONE;
@@ -220,11 +220,11 @@ diagnostic_initialize (diagnostic_context *context, int n_opts)
   context->x_data = NULL;
   context->lock = 0;
   context->inhibit_notes_p = false;
-  context->colorize_source_p = false;
-  context->show_labels_p = false;
-  context->show_line_numbers_p = false;
-  context->min_margin_width = 0;
-  context->show_ruler_p = false;
+  context->m_source_printing.colorize_source_p = false;
+  context->m_source_printing.show_labels_p = false;
+  context->m_source_printing.show_line_numbers_p = false;
+  context->m_source_printing.min_margin_width = 0;
+  context->m_source_printing.show_ruler_p = false;
   context->report_bug = false;
 
   if (const char *var = getenv ("GCC_EXTRA_DIAGNOSTIC_OUTPUT"))
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index 4ec83a988d5..1f2d93c3d00 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -219,16 +219,6 @@ struct diagnostic_context
   int *push_list;
   int n_push;
 
-  /* True if we should print the source line with a caret indicating
-     the location.  */
-  bool show_caret;
-
-  /* Maximum width of the source line printed.  */
-  int caret_max_width;
-
-  /* Character used for caret diagnostics.  */
-  char caret_chars[rich_location::STATICALLY_ALLOCATED_RANGES];
-
   /* True if we should print any CWE identifiers associated with
      diagnostics.  */
   bool show_cwe;
@@ -336,29 +326,49 @@ struct diagnostic_context
 
   bool inhibit_notes_p;
 
-  /* When printing source code, should the characters at carets and ranges
-     be colorized? (assuming colorization is on at all).
-     This should be true for frontends that generate range information
-     (so that the ranges of code are colorized),
-     and false for frontends that merely specify points within the
-     source code (to avoid e.g. colorizing just the first character in
-     a token, which would look strange).  */
-  bool colorize_source_p;
+  /* Fields relating to printing the user's source code (potentially with
+     a margin, underlining, labels, etc).  */
+  struct {
+
+    /* True if we should print the source line with a caret indicating
+       the location.
+       Corresponds to -fdiagnostics-show-caret.  */
+    bool enabled;
+
+    /* Maximum width of the source line printed.  */
+    int max_width;
+
+    /* Character used at the caret when printing source locations.  */
+    char caret_chars[rich_location::STATICALLY_ALLOCATED_RANGES];
+
+    /* When printing source code, should the characters at carets and ranges
+       be colorized? (assuming colorization is on at all).
+       This should be true for frontends that generate range information
+       (so that the ranges of code are colorized),
+       and false for frontends that merely specify points within the
+       source code (to avoid e.g. colorizing just the first character in
+       a token, which would look strange).  */
+    bool colorize_source_p;
+
+    /* When printing source code, should labelled ranges be printed?
+       Corresponds to -fdiagnostics-show-labels.  */
+    bool show_labels_p;
 
-  /* When printing source code, should labelled ranges be printed?  */
-  bool show_labels_p;
+    /* When printing source code, should there be a left-hand margin
+       showing line numbers?
+       Corresponds to -fdiagnostics-show-line-numbers.  */
+    bool show_line_numbers_p;
 
-  /* When printing source code, should there be a left-hand margin
-     showing line numbers?  */
-  bool show_line_numbers_p;
+    /* If printing source code, what should the minimum width of the margin
+       be?  Line numbers will be right-aligned, and padded to this width.
+       Corresponds to -fdiagnostics-minimum-margin-width=VALUE.  */
+    int min_margin_width;
 
-  /* If printing source code, what should the minimum width of the margin
-     be?  Line numbers will be right-aligned, and padded to this width.  */
-  int min_margin_width;
+    /* Usable by plugins; if true, print a debugging ruler above the
+       source output.  */
+    bool show_ruler_p;
 
-  /* Usable by plugins; if true, print a debugging ruler above the
-     source output.  */
-  bool show_ruler_p;
+  } m_source_printing;
 
   /* True if -freport-bug option is used.  */
   bool report_bug;
@@ -605,8 +615,9 @@ inline bool
 diagnostic_same_line (const diagnostic_context *context,
 		       expanded_location s1, expanded_location s2)
 {
-  return s2.column && s1.line == s2.line 
-    && context->caret_max_width - CARET_LINE_MARGIN > abs (s1.column - s2.column);
+  return (s2.column && s1.line == s2.line
+	  && (context->m_source_printing.max_width - CARET_LINE_MARGIN
+	      > abs (s1.column - s2.column)));
 }
 
 extern const char *diagnostic_get_color_for_kind (diagnostic_t kind);
diff --git a/gcc/fortran/error.cc b/gcc/fortran/error.cc
index 6cae6726f91..378f7393133 100644
--- a/gcc/fortran/error.cc
+++ b/gcc/fortran/error.cc
@@ -1222,7 +1222,7 @@ gfc_diagnostic_starter (diagnostic_context *context,
     ? gfc_diagnostic_build_locus_prefix (context, s1)
     : gfc_diagnostic_build_locus_prefix (context, s1, s2);
 
-  if (!context->show_caret
+  if (!context->m_source_printing.enabled
       || diagnostic_location (diagnostic, 0) <= BUILTINS_LOCATION
       || diagnostic_location (diagnostic, 0) == context->last_location)
     {
@@ -1640,8 +1640,8 @@ gfc_diagnostics_init (void)
   global_dc->start_span = gfc_diagnostic_start_span;
   diagnostic_finalizer (global_dc) = gfc_diagnostic_finalizer;
   diagnostic_format_decoder (global_dc) = gfc_format_decoder;
-  global_dc->caret_chars[0] = '1';
-  global_dc->caret_chars[1] = '2';
+  global_dc->m_source_printing.caret_chars[0] = '1';
+  global_dc->m_source_printing.caret_chars[1] = '2';
   pp_warning_buffer = new (XNEW (output_buffer)) output_buffer ();
   pp_warning_buffer->flush_p = false;
   /* pp_error_buffer is statically allocated.  This simplifies memory
@@ -1658,6 +1658,6 @@ gfc_diagnostics_finish (void)
      defaults.  */
   diagnostic_starter (global_dc) = gfc_diagnostic_starter;
   diagnostic_finalizer (global_dc) = gfc_diagnostic_finalizer;
-  global_dc->caret_chars[0] = '^';
-  global_dc->caret_chars[1] = '^';
+  global_dc->m_source_printing.caret_chars[0] = '^';
+  global_dc->m_source_printing.caret_chars[1] = '^';
 }
diff --git a/gcc/opts.cc b/gcc/opts.cc
index ac81d4e4294..573dcf8e497 100644
--- a/gcc/opts.cc
+++ b/gcc/opts.cc
@@ -2864,15 +2864,15 @@ common_handle_option (struct gcc_options *opts,
       break;
  
     case OPT_fdiagnostics_show_caret:
-      dc->show_caret = value;
+      dc->m_source_printing.enabled = value;
       break;
 
     case OPT_fdiagnostics_show_labels:
-      dc->show_labels_p = value;
+      dc->m_source_printing.show_labels_p = value;
       break;
 
     case OPT_fdiagnostics_show_line_numbers:
-      dc->show_line_numbers_p = value;
+      dc->m_source_printing.show_line_numbers_p = value;
       break;
 
     case OPT_fdiagnostics_color_:
@@ -2936,7 +2936,7 @@ common_handle_option (struct gcc_options *opts,
       break;
 
     case OPT_fdiagnostics_minimum_margin_width_:
-      dc->min_margin_width = value;
+      dc->m_source_printing.min_margin_width = value;
       break;
 
     case OPT_fdump_:
diff --git a/gcc/selftest-diagnostic.cc b/gcc/selftest-diagnostic.cc
index 6d1bd1bd792..5469e555fc0 100644
--- a/gcc/selftest-diagnostic.cc
+++ b/gcc/selftest-diagnostic.cc
@@ -36,12 +36,12 @@ namespace selftest {
 test_diagnostic_context::test_diagnostic_context ()
 {
   diagnostic_initialize (this, 0);
-  show_caret = true;
-  show_labels_p = true;
+  m_source_printing.enabled = true;
+  m_source_printing.show_labels_p = true;
   show_column = true;
   start_span = start_span_cb;
-  min_margin_width = 6;
-  caret_max_width = 80;
+  m_source_printing.min_margin_width = 6;
+  m_source_printing.max_width = 80;
 }
 
 test_diagnostic_context::~test_diagnostic_context ()
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c
index d81fa571c97..f5c6fc5202f 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c
@@ -115,7 +115,7 @@ plugin_init (struct plugin_name_args *plugin_info,
   if (!plugin_default_version_check (version, &gcc_version))
     return 1;
 
-  global_dc->caret_max_width = 80;
+  global_dc->m_source_printing.max_width = 80;
 
   register_callback (plugin_name,
 		     PLUGIN_PRE_GENERICIZE,
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_inlining.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_inlining.c
index 3627f7a2b7f..7edce1fe2d4 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_inlining.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_inlining.c
@@ -169,7 +169,7 @@ plugin_init (struct plugin_name_args *plugin_info,
   if (!plugin_default_version_check (version, &gcc_version))
     return 1;
 
-  global_dc->caret_max_width = 80;
+  global_dc->m_source_printing.max_width = 80;
 
   pass_info.pass = new pass_test_inlining (g);
   pass_info.reference_pass_name = "*warn_function_noreturn";
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.c
index 62558bede95..bf665005c8b 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.c
@@ -534,7 +534,7 @@ plugin_init (struct plugin_name_args *plugin_info,
   if (!plugin_default_version_check (version, &gcc_version))
     return 1;
 
-  global_dc->caret_max_width = 80;
+  global_dc->m_source_printing.max_width = 80;
 
   pass_info.pass = make_pass_test_show_path (g);
   pass_info.reference_pass_name = "whole-program";
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
index baa6b629b83..2b8cbc952eb 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
@@ -175,7 +175,7 @@ test_show_locus (function *fun)
 
   /* Hardcode the "terminal width", to verify the behavior of
      very wide lines.  */
-  global_dc->caret_max_width = 71;
+  global_dc->m_source_printing.max_width = 71;
 
   if (0 == strcmp (fnname, "test_simple"))
     {
@@ -246,7 +246,7 @@ test_show_locus (function *fun)
   if (0 == strcmp (fnname, "test_very_wide_line"))
     {
       const int line = fnstart_line + 2;
-      global_dc->show_ruler_p = true;
+      global_dc->m_source_printing.show_ruler_p = true;
       text_range_label label0 ("label 0");
       text_range_label label1 ("label 1");
       rich_location richloc (line_table,
@@ -258,7 +258,7 @@ test_show_locus (function *fun)
 			 &label1);
       richloc.add_fixit_replace ("bar * foo");
       warning_at (&richloc, 0, "test");
-      global_dc->show_ruler_p = false;
+      global_dc->m_source_printing.show_ruler_p = false;
     }
 
   /* Likewise, but with a secondary location that's immediately before
@@ -266,7 +266,7 @@ test_show_locus (function *fun)
   if (0 == strcmp (fnname, "test_very_wide_line_2"))
     {
       const int line = fnstart_line + 2;
-      global_dc->show_ruler_p = true;
+      global_dc->m_source_printing.show_ruler_p = true;
       text_range_label label0 ("label 0");
       text_range_label label1 ("label 1");
       rich_location richloc (line_table,
@@ -278,7 +278,7 @@ test_show_locus (function *fun)
       richloc.add_range (get_loc (line, 34), SHOW_RANGE_WITHOUT_CARET,
 			 &label1);
       warning_at (&richloc, 0, "test");
-      global_dc->show_ruler_p = false;
+      global_dc->m_source_printing.show_ruler_p = false;
     }
 
   /* Example of multiple carets.  */
@@ -289,11 +289,11 @@ test_show_locus (function *fun)
       location_t caret_b = get_loc (line, 11);
       rich_location richloc (line_table, caret_a);
       add_range (&richloc, caret_b, caret_b, SHOW_RANGE_WITH_CARET);
-      global_dc->caret_chars[0] = 'A';
-      global_dc->caret_chars[1] = 'B';
+      global_dc->m_source_printing.caret_chars[0] = 'A';
+      global_dc->m_source_printing.caret_chars[1] = 'B';
       warning_at (&richloc, 0, "test");
-      global_dc->caret_chars[0] = '^';
-      global_dc->caret_chars[1] = '^';
+      global_dc->m_source_printing.caret_chars[0] = '^';
+      global_dc->m_source_printing.caret_chars[1] = '^';
     }
 
   /* Tests of rendering fixit hints.  */
@@ -407,11 +407,11 @@ test_show_locus (function *fun)
       location_t caret_b = get_loc (line - 1, 19);
       rich_location richloc (line_table, caret_a);
       richloc.add_range (caret_b, SHOW_RANGE_WITH_CARET);
-      global_dc->caret_chars[0] = '1';
-      global_dc->caret_chars[1] = '2';
+      global_dc->m_source_printing.caret_chars[0] = '1';
+      global_dc->m_source_printing.caret_chars[1] = '2';
       warning_at (&richloc, 0, "test");
-      global_dc->caret_chars[0] = '^';
-      global_dc->caret_chars[1] = '^';
+      global_dc->m_source_printing.caret_chars[0] = '^';
+      global_dc->m_source_printing.caret_chars[1] = '^';
     }
 
   /* Example of using the "%q+D" format code, which as well as printing
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.c
index 0269f728a93..1b5fad2bc66 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.c
@@ -208,7 +208,7 @@ plugin_init (struct plugin_name_args *plugin_info,
   if (!plugin_default_version_check (version, &gcc_version))
     return 1;
 
-  global_dc->caret_max_width = 80;
+  global_dc->m_source_printing.max_width = 80;
 
   pass_info.pass = new pass_test_string_literals (g);
   pass_info.reference_pass_name = "ssa";
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.c
index f5468636e06..fbdb2f899d6 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.c
@@ -89,7 +89,7 @@ plugin_init (struct plugin_name_args *plugin_info,
   if (!plugin_default_version_check (version, &gcc_version))
     return 1;
 
-  global_dc->caret_max_width = 130;
+  global_dc->m_source_printing.max_width = 130;
 
   register_callback (plugin_name,
 		     PLUGIN_PRE_GENERICIZE,
diff --git a/gcc/toplev.cc b/gcc/toplev.cc
index db62e3e995e..626cc435c8b 100644
--- a/gcc/toplev.cc
+++ b/gcc/toplev.cc
@@ -1023,11 +1023,11 @@ general_init (const char *argv0, bool init_signals)
      override it later.  */
   tree_diagnostics_defaults (global_dc);
 
-  global_dc->show_caret
+  global_dc->m_source_printing.enabled
     = global_options_init.x_flag_diagnostics_show_caret;
-  global_dc->show_labels_p
+  global_dc->m_source_printing.show_labels_p
     = global_options_init.x_flag_diagnostics_show_labels;
-  global_dc->show_line_numbers_p
+  global_dc->m_source_printing.show_line_numbers_p
     = global_options_init.x_flag_diagnostics_show_line_numbers;
   global_dc->show_cwe
     = global_options_init.x_flag_diagnostics_show_cwe;
@@ -1039,7 +1039,7 @@ general_init (const char *argv0, bool init_signals)
     = global_options_init.x_flag_diagnostics_show_path_depths;
   global_dc->show_option_requested
     = global_options_init.x_flag_diagnostics_show_option;
-  global_dc->min_margin_width
+  global_dc->m_source_printing.min_margin_width
     = global_options_init.x_diagnostics_minimum_margin_width;
   global_dc->show_column
     = global_options_init.x_flag_show_column;
diff --git a/gcc/tree-diagnostic-path.cc b/gcc/tree-diagnostic-path.cc
index 84148da53af..b1b483a27aa 100644
--- a/gcc/tree-diagnostic-path.cc
+++ b/gcc/tree-diagnostic-path.cc
@@ -200,7 +200,7 @@ struct event_range
     /* Emit a span indicating the filename (and line/column) if the
        line has changed relative to the last call to
        diagnostic_show_locus.  */
-    if (dc->show_caret)
+    if (dc->m_source_printing.enabled)
       {
 	expanded_location exploc
 	  = linemap_client_expand_location_to_spelling_point

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-10-02 16:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-02 16:25 [gcc r14-4367] diagnostics: group together source printing fields of diagnostic_context David Malcolm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).