[pushed] diagnostics: make m_text_callbacks private

Message ID 20231114191313.3709388-1-dmalcolm@redhat.com
State Unresolved
Headers
Series [pushed] diagnostics: make m_text_callbacks private |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

David Malcolm Nov. 14, 2023, 7:13 p.m. UTC
  No functional change intended.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r14-5458-g07e568d77f364e.

gcc/ChangeLog:
	* diagnostic-show-locus.cc (diagnostic_context::show_locus):
	Update for renaming of text callbacks fields.
	* diagnostic.cc (diagnostic_context::initialize): Likewise.
	* diagnostic.h (class diagnostic_context): Add "friend" for
	accessors to m_text_callbacks.
	(diagnostic_context::m_text_callbacks): Make private, and add an
	"m_" prefix to field names.
	(diagnostic_starter): Convert from macro to inline function.
	(diagnostic_start_span): New.
	(diagnostic_finalizer): Convert from macro to inline function.

gcc/fortran/ChangeLog:
	* error.cc (gfc_diagnostics_init): Use diagnostic_start_span.

gcc/ChangeLog:
	* selftest-diagnostic.cc
	(test_diagnostic_context::test_diagnostic_context): Use
	diagnostic_start_span.
	* tree-diagnostic-path.cc (struct event_range): Likewise.

gcc/testsuite:
	* gcc.dg/plugin/diagnostic_group_plugin.c: Use
	diagnostic_start_span.
---
 gcc/diagnostic-show-locus.cc                  |  2 +-
 gcc/diagnostic.cc                             |  6 +--
 gcc/diagnostic.h                              | 37 ++++++++++++++++---
 gcc/fortran/error.cc                          |  2 +-
 gcc/selftest-diagnostic.cc                    |  2 +-
 .../gcc.dg/plugin/diagnostic_group_plugin.c   |  2 +-
 gcc/tree-diagnostic-path.cc                   |  2 +-
 7 files changed, 39 insertions(+), 14 deletions(-)
  

Patch

diff --git a/gcc/diagnostic-show-locus.cc b/gcc/diagnostic-show-locus.cc
index 169f59cb0573..563d2826f249 100644
--- a/gcc/diagnostic-show-locus.cc
+++ b/gcc/diagnostic-show-locus.cc
@@ -2904,7 +2904,7 @@  diagnostic_context::show_locus (const rich_location &richloc,
 	    {
 	      expanded_location exploc
 		= layout.get_expanded_location (line_span);
-	      m_text_callbacks.start_span (this, exploc);
+	      m_text_callbacks.m_start_span (this, exploc);
 	    }
 	}
       /* Iterate over the lines within this span (using linenum_arith_t to
diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index 24212b9668eb..ccca2d2150f7 100644
--- a/gcc/diagnostic.cc
+++ b/gcc/diagnostic.cc
@@ -235,9 +235,9 @@  diagnostic_context::initialize (int n_opts)
   m_warn_system_headers = false;
   m_max_errors = 0;
   m_internal_error = nullptr;
-  m_text_callbacks.begin_diagnostic = default_diagnostic_starter;
-  m_text_callbacks.start_span = default_diagnostic_start_span_fn;
-  m_text_callbacks.end_diagnostic = default_diagnostic_finalizer;
+  m_text_callbacks.m_begin_diagnostic = default_diagnostic_starter;
+  m_text_callbacks.m_start_span = default_diagnostic_start_span_fn;
+  m_text_callbacks.m_end_diagnostic = default_diagnostic_finalizer;
   m_option_enabled = nullptr;
   m_option_state = nullptr;
   m_option_name = nullptr;
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index 2489855ae4a4..57c5ed4f582a 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -352,6 +352,14 @@  struct diagnostic_source_printing_options
 class diagnostic_context
 {
 public:
+  /* Give access to m_text_callbacks.  */
+  friend diagnostic_starter_fn &
+  diagnostic_starter (diagnostic_context *context);
+  friend diagnostic_start_span_fn &
+  diagnostic_start_span (diagnostic_context *context);
+  friend diagnostic_finalizer_fn &
+  diagnostic_finalizer (diagnostic_context *context);
+
   typedef void (*ice_handler_callback_t) (diagnostic_context *);
   typedef void (*set_locations_callback_t) (diagnostic_context *,
 					    diagnostic_info *);
@@ -574,7 +582,6 @@  private:
   /* Maximum number of errors to report.  */
   int m_max_errors;
 
-public:
   /* Client-supplied callbacks for use in text output.  */
   struct {
     /* This function is called before any message is printed out.  It is
@@ -584,17 +591,18 @@  public:
        from "/home/gdr/src/nifty_printer.h:56:
        ...
     */
-    diagnostic_starter_fn begin_diagnostic;
+    diagnostic_starter_fn m_begin_diagnostic;
 
     /* This function is called by diagnostic_show_locus in between
        disjoint spans of source code, so that the context can print
        something to indicate that a new span of source code has begun.  */
-    diagnostic_start_span_fn start_span;
+    diagnostic_start_span_fn m_start_span;
 
     /* This function is called after the diagnostic message is printed.  */
-    diagnostic_finalizer_fn end_diagnostic;
+    diagnostic_finalizer_fn m_end_diagnostic;
   } m_text_callbacks;
 
+public:
   /* Client hook to report an internal error.  */
   void (*m_internal_error) (diagnostic_context *, const char *, va_list *);
 
@@ -734,11 +742,28 @@  diagnostic_inhibit_notes (diagnostic_context * context)
 
 /* Client supplied function to announce a diagnostic
    (for text-based diagnostic output).  */
-#define diagnostic_starter(DC) (DC)->m_text_callbacks.begin_diagnostic
+inline diagnostic_starter_fn &
+diagnostic_starter (diagnostic_context *context)
+{
+  return context->m_text_callbacks.m_begin_diagnostic;
+}
+
+/* Client supplied function called between disjoint spans of source code,
+   so that the context can print
+   something to indicate that a new span of source code has begun.  */
+inline diagnostic_start_span_fn &
+diagnostic_start_span (diagnostic_context *context)
+{
+  return context->m_text_callbacks.m_start_span;
+}
 
 /* Client supplied function called after a diagnostic message is
    displayed (for text-based diagnostic output).  */
-#define diagnostic_finalizer(DC) (DC)->m_text_callbacks.end_diagnostic
+inline diagnostic_finalizer_fn &
+diagnostic_finalizer (diagnostic_context *context)
+{
+  return context->m_text_callbacks.m_end_diagnostic;
+}
 
 /* Extension hooks for client.  */
 #define diagnostic_context_auxiliary_data(DC) (DC)->m_client_aux_data
diff --git a/gcc/fortran/error.cc b/gcc/fortran/error.cc
index ca31775c2dc3..2ac51e95e4da 100644
--- a/gcc/fortran/error.cc
+++ b/gcc/fortran/error.cc
@@ -1637,7 +1637,7 @@  void
 gfc_diagnostics_init (void)
 {
   diagnostic_starter (global_dc) = gfc_diagnostic_starter;
-  global_dc->m_text_callbacks.start_span = gfc_diagnostic_start_span;
+  diagnostic_start_span (global_dc) = gfc_diagnostic_start_span;
   diagnostic_finalizer (global_dc) = gfc_diagnostic_finalizer;
   diagnostic_format_decoder (global_dc) = gfc_format_decoder;
   global_dc->m_source_printing.caret_chars[0] = '1';
diff --git a/gcc/selftest-diagnostic.cc b/gcc/selftest-diagnostic.cc
index 37e98ed33047..f9a1852f7680 100644
--- a/gcc/selftest-diagnostic.cc
+++ b/gcc/selftest-diagnostic.cc
@@ -39,7 +39,7 @@  test_diagnostic_context::test_diagnostic_context ()
   m_source_printing.enabled = true;
   m_source_printing.show_labels_p = true;
   m_show_column = true;
-  m_text_callbacks.start_span = start_span_cb;
+  diagnostic_start_span (this) = start_span_cb;
   m_source_printing.min_margin_width = 6;
   m_source_printing.max_width = 80;
 }
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.c
index e8903ba6ee32..ce0b3225dfca 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.c
@@ -224,7 +224,7 @@  plugin_init (struct plugin_name_args *plugin_info,
     return 1;
 
   diagnostic_starter (global_dc) = test_diagnostic_starter;
-  global_dc->m_text_callbacks.start_span = test_diagnostic_start_span_fn;
+  diagnostic_start_span (global_dc) = test_diagnostic_start_span_fn;
   global_dc->set_output_format (new test_output_format (*global_dc));
 
   pass_info.pass = new pass_test_groups (g);
diff --git a/gcc/tree-diagnostic-path.cc b/gcc/tree-diagnostic-path.cc
index d2345c8dae74..3cd9c210feaa 100644
--- a/gcc/tree-diagnostic-path.cc
+++ b/gcc/tree-diagnostic-path.cc
@@ -206,7 +206,7 @@  struct event_range
 	  = linemap_client_expand_location_to_spelling_point
 	  (line_table, initial_loc, LOCATION_ASPECT_CARET);
 	if (exploc.file != LOCATION_FILE (dc->m_last_location))
-	  dc->m_text_callbacks.start_span (dc, exploc);
+	  diagnostic_start_span (dc) (dc, exploc);
       }
 
     /* If we have an UNKNOWN_LOCATION (or BUILTINS_LOCATION) as the