[PATCH 6/7] diagnostics: eliminate diagnostic_context::m_print_path callback

David Malcolm dmalcolm@redhat.com
Tue Jun 18 15:08:18 GMT 2024


No functional change intended.

gcc/ChangeLog:
	* diagnostic-format-json.cc (diagnostic_output_format_init_json):
	Replace clearing of diagnostic_context::m_print_path callback with
	setting the path format to DPF_NONE.
	* diagnostic-format-sarif.cc
	(diagnostic_output_format_init_sarif): Likewise.
	* diagnostic.cc (diagnostic_context::show_any_path): Replace call
	to diagnostic_context::m_print_path callback with a direct call to
	diagnostic_context::print_path.
	* diagnostic.h (diagnostic_context::print_path): New decl.
	(diagnostic_context::m_print_path): Delete callback.
	* tree-diagnostic-path.cc (default_tree_diagnostic_path_printer):
	Convert to...
	(diagnostic_context::print_path): ...this.
	* tree-diagnostic.cc (tree_diagnostics_defaults): Delete
	initialization of m_print_path.
	* tree-diagnostic.h (default_tree_diagnostic_path_printer): Delete
	decl.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
 gcc/diagnostic-format-json.cc  |  4 ++--
 gcc/diagnostic-format-sarif.cc |  4 +++-
 gcc/diagnostic.cc              |  3 +--
 gcc/diagnostic.h               |  4 ++--
 gcc/tree-diagnostic-path.cc    | 23 +++++++++++------------
 gcc/tree-diagnostic.cc         |  1 -
 gcc/tree-diagnostic.h          |  3 ---
 7 files changed, 19 insertions(+), 23 deletions(-)

diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc
index 2bdc2c13d37..ec03ac15aeb 100644
--- a/gcc/diagnostic-format-json.cc
+++ b/gcc/diagnostic-format-json.cc
@@ -395,8 +395,8 @@ private:
 static void
 diagnostic_output_format_init_json (diagnostic_context *context)
 {
-  /* Override callbacks.  */
-  context->m_print_path = nullptr; /* handled in json_end_diagnostic.  */
+  /* Suppress normal textual path output.  */
+  context->set_path_format (DPF_NONE);
 
   /* The metadata is handled in JSON format, rather than as text.  */
   context->set_show_cwe (false);
diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc
index 79116f051bc..5f438dd38a8 100644
--- a/gcc/diagnostic-format-sarif.cc
+++ b/gcc/diagnostic-format-sarif.cc
@@ -1991,8 +1991,10 @@ private:
 static void
 diagnostic_output_format_init_sarif (diagnostic_context *context)
 {
+  /* Suppress normal textual path output.  */
+  context->set_path_format (DPF_NONE);
+
   /* Override callbacks.  */
-  context->m_print_path = nullptr; /* handled in sarif_end_diagnostic.  */
   context->set_ice_handler_callback (sarif_ice_handler);
 
   /* The metadata is handled in SARIF format, rather than as text.  */
diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index 844eb8e1048..471135f16de 100644
--- a/gcc/diagnostic.cc
+++ b/gcc/diagnostic.cc
@@ -915,8 +915,7 @@ diagnostic_context::show_any_path (const diagnostic_info &diagnostic)
   if (!path)
     return;
 
-  if (m_print_path)
-    m_print_path (this, path);
+  print_path (path);
 }
 
 /* class diagnostic_event.  */
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index ff2aa3dd9a3..c6846525da3 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -583,6 +583,8 @@ private:
 		   pretty_printer *pp,
 		   diagnostic_source_effect_info *effect_info);
 
+  void print_path (const diagnostic_path *path);
+
   /* Data members.
      Ideally, all of these would be private and have "m_" prefixes.  */
 
@@ -712,8 +714,6 @@ private:
   urlifier *m_urlifier;
 
 public:
-  void (*m_print_path) (diagnostic_context *, const diagnostic_path *);
-
   /* Auxiliary data for client.  */
   void *m_client_aux_data;
 
diff --git a/gcc/tree-diagnostic-path.cc b/gcc/tree-diagnostic-path.cc
index adaaf30b84f..35f8ea2b8b6 100644
--- a/gcc/tree-diagnostic-path.cc
+++ b/gcc/tree-diagnostic-path.cc
@@ -884,17 +884,16 @@ print_path_summary_as_text (const path_summary *ps, diagnostic_context *dc,
 
 } /* end of anonymous namespace for path-printing code.  */
 
-/* Print PATH to CONTEXT, according to CONTEXT's path_format.  */
+/* Print PATH according to this context's path_format.  */
 
 void
-default_tree_diagnostic_path_printer (diagnostic_context *context,
-				      const diagnostic_path *path)
+diagnostic_context::print_path (const diagnostic_path *path)
 {
   gcc_assert (path);
 
   const unsigned num_events = path->num_events ();
 
-  switch (context->get_path_format ())
+  switch (get_path_format ())
     {
     case DPF_NONE:
       /* Do nothing.  */
@@ -909,7 +908,7 @@ default_tree_diagnostic_path_printer (diagnostic_context *context,
 	    label_text event_text (event.get_desc (false));
 	    gcc_assert (event_text.get ());
 	    diagnostic_event_id_t event_id (i);
-	    if (context->show_path_depths_p ())
+	    if (this->show_path_depths_p ())
 	      {
 		int stack_depth = event.get_stack_depth ();
 		/* -fdiagnostics-path-format=separate-events doesn't print
@@ -941,13 +940,13 @@ default_tree_diagnostic_path_printer (diagnostic_context *context,
       {
 	/* Consolidate related events.  */
 	path_summary summary (*path, true,
-			      context->m_source_printing.show_event_links_p);
-	char *saved_prefix = pp_take_prefix (context->printer);
-	pp_set_prefix (context->printer, NULL);
-	print_path_summary_as_text (&summary, context,
-				    context->show_path_depths_p ());
-	pp_flush (context->printer);
-	pp_set_prefix (context->printer, saved_prefix);
+			      m_source_printing.show_event_links_p);
+	char *saved_prefix = pp_take_prefix (this->printer);
+	pp_set_prefix (this->printer, NULL);
+	print_path_summary_as_text (&summary, this,
+				    show_path_depths_p ());
+	pp_flush (this->printer);
+	pp_set_prefix (this->printer, saved_prefix);
       }
       break;
     }
diff --git a/gcc/tree-diagnostic.cc b/gcc/tree-diagnostic.cc
index f236f3db0b2..fc78231dfa4 100644
--- a/gcc/tree-diagnostic.cc
+++ b/gcc/tree-diagnostic.cc
@@ -179,7 +179,6 @@ tree_diagnostics_defaults (diagnostic_context *context)
   diagnostic_starter (context) = default_tree_diagnostic_starter;
   diagnostic_finalizer (context) = default_diagnostic_finalizer;
   diagnostic_format_decoder (context) = default_tree_printer;
-  context->m_print_path = default_tree_diagnostic_path_printer;
   context->set_set_locations_callback (set_inlining_locations);
   context->set_client_data_hooks (make_compiler_data_hooks ());
 }
diff --git a/gcc/tree-diagnostic.h b/gcc/tree-diagnostic.h
index 648d6e6ab91..6ebac381ace 100644
--- a/gcc/tree-diagnostic.h
+++ b/gcc/tree-diagnostic.h
@@ -55,7 +55,4 @@ void tree_diagnostics_defaults (diagnostic_context *context);
 bool default_tree_printer (pretty_printer *, text_info *, const char *,
 			   int, bool, bool, bool, bool *, const char **);
 
-extern void default_tree_diagnostic_path_printer (diagnostic_context *,
-						  const diagnostic_path *);
-
 #endif /* ! GCC_TREE_DIAGNOSTIC_H */
-- 
2.26.3



More information about the Gcc-patches mailing list