diff mbox series

[4/7] diagnostics: eliminate diagnostic_context::m_make_json_for_path

Message ID 20240618150819.946820-5-dmalcolm@redhat.com
State New
Headers show
Series diagnostics: remove "tree" dependency from diagnostic paths | expand

Commit Message

David Malcolm June 18, 2024, 3:08 p.m. UTC
Now that the path-handling code for json_output_format no longer
needs "tree", and thus can be in OBJS-libcommon we can move it
from tree-diagnostic-path.cc to diagnostic-format-json.cc where it
should have been all along.

No functional change intended.

gcc/ChangeLog:
	* diagnostic-format-json.cc: Include "diagnostic-path.h" and
	"logical-location.h".
	(make_json_for_path): Move tree-diagnostic-path.cc's
	default_tree_make_json_for_path here, renaming it and making it
	static.
	(json_output_format::on_end_diagnostic): Replace call of
	m_context's m_make_json_for_path callback with a direct call to
	make_json_for_path.
	* diagnostic.h (diagnostic_context::m_make_json_for_path): Drop
	field.
	* tree-diagnostic-path.cc: Drop include of "json.h".
	(default_tree_make_json_for_path): Rename to make_json_for_path
	and move to diagnostic-format-json.cc.
	* tree-diagnostic.cc (tree_diagnostics_defaults): Drop
	initialization of m_make_json_for_path.
	* tree-diagnostic.h (default_tree_make_json_for): Delete decl.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
 gcc/diagnostic-format-json.cc | 37 ++++++++++++++++++++++++++++++++---
 gcc/diagnostic.h              |  2 --
 gcc/tree-diagnostic-path.cc   | 32 ------------------------------
 gcc/tree-diagnostic.cc        |  1 -
 gcc/tree-diagnostic.h         |  2 --
 5 files changed, 34 insertions(+), 40 deletions(-)
diff mbox series

Patch

diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc
index 0782ae831eb..2bdc2c13d37 100644
--- a/gcc/diagnostic-format-json.cc
+++ b/gcc/diagnostic-format-json.cc
@@ -25,8 +25,10 @@  along with GCC; see the file COPYING3.  If not see
 #include "diagnostic.h"
 #include "selftest-diagnostic.h"
 #include "diagnostic-metadata.h"
+#include "diagnostic-path.h"
 #include "json.h"
 #include "selftest.h"
+#include "logical-location.h"
 
 /* Subclass of diagnostic_output_format for JSON output.  */
 
@@ -187,6 +189,36 @@  json_from_metadata (const diagnostic_metadata *metadata)
   return metadata_obj;
 }
 
+/* Make a JSON value for PATH.  */
+
+static json::value *
+make_json_for_path (diagnostic_context *context,
+		    const diagnostic_path *path)
+{
+  json::array *path_array = new json::array ();
+  for (unsigned i = 0; i < path->num_events (); i++)
+    {
+      const diagnostic_event &event = path->get_event (i);
+
+      json::object *event_obj = new json::object ();
+      if (event.get_location ())
+	event_obj->set ("location",
+			json_from_expanded_location (context,
+						     event.get_location ()));
+      label_text event_text (event.get_desc (false));
+      event_obj->set_string ("description", event_text.get ());
+      if (const logical_location *logical_loc = event.get_logical_location ())
+	{
+	  label_text name (logical_loc->get_name_for_path_output ());
+	  event_obj->set_string ("function", name.get ());
+	}
+      event_obj->set_integer ("depth", event.get_stack_depth ());
+      path_array->append (event_obj);
+    }
+  return path_array;
+}
+
+
 /* Implementation of "on_end_diagnostic" vfunc for JSON output.
    Generate a JSON object for DIAGNOSTIC, and store for output
    within current diagnostic group.  */
@@ -291,10 +323,9 @@  json_output_format::on_end_diagnostic (const diagnostic_info &diagnostic,
     }
 
   const diagnostic_path *path = richloc->get_path ();
-  if (path && m_context.m_make_json_for_path)
+  if (path)
     {
-      json::value *path_value
-	= m_context.m_make_json_for_path (&m_context, path);
+      json::value *path_value = make_json_for_path (&m_context, path);
       diag_obj->set ("path", path_value);
     }
 
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index 9a9571bb76d..ff2aa3dd9a3 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -713,8 +713,6 @@  private:
 
 public:
   void (*m_print_path) (diagnostic_context *, const diagnostic_path *);
-  json::value *(*m_make_json_for_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 39a85d33015..40b197d971c 100644
--- a/gcc/tree-diagnostic-path.cc
+++ b/gcc/tree-diagnostic-path.cc
@@ -30,7 +30,6 @@  along with GCC; see the file COPYING3.  If not see
 #include "tree-diagnostic.h"
 #include "intl.h"
 #include "diagnostic-path.h"
-#include "json.h"
 #include "gcc-rich-location.h"
 #include "diagnostic-color.h"
 #include "diagnostic-event-id.h"
@@ -954,37 +953,6 @@  default_tree_diagnostic_path_printer (diagnostic_context *context,
     }
 }
 
-/* This has to be here, rather than diagnostic-format-json.cc,
-   since diagnostic-format-json.o is within OBJS-libcommon and thus
-   doesn't have access to trees (for m_fndecl).  */
-
-json::value *
-default_tree_make_json_for_path (diagnostic_context *context,
-				 const diagnostic_path *path)
-{
-  json::array *path_array = new json::array ();
-  for (unsigned i = 0; i < path->num_events (); i++)
-    {
-      const diagnostic_event &event = path->get_event (i);
-
-      json::object *event_obj = new json::object ();
-      if (event.get_location ())
-	event_obj->set ("location",
-			json_from_expanded_location (context,
-						     event.get_location ()));
-      label_text event_text (event.get_desc (false));
-      event_obj->set_string ("description", event_text.get ());
-      if (const logical_location *logical_loc = event.get_logical_location ())
-	{
-	  label_text name (logical_loc->get_name_for_path_output ());
-	  event_obj->set_string ("function", name.get ());
-	}
-      event_obj->set_integer ("depth", event.get_stack_depth ());
-      path_array->append (event_obj);
-    }
-  return path_array;
-}
-
 #if CHECKING_P
 
 namespace selftest {
diff --git a/gcc/tree-diagnostic.cc b/gcc/tree-diagnostic.cc
index a660c7d0785..f6e2a73497a 100644
--- a/gcc/tree-diagnostic.cc
+++ b/gcc/tree-diagnostic.cc
@@ -375,7 +375,6 @@  tree_diagnostics_defaults (diagnostic_context *context)
   diagnostic_finalizer (context) = default_diagnostic_finalizer;
   diagnostic_format_decoder (context) = default_tree_printer;
   context->m_print_path = default_tree_diagnostic_path_printer;
-  context->m_make_json_for_path = default_tree_make_json_for_path;
   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 1d13368537a..7959294f489 100644
--- a/gcc/tree-diagnostic.h
+++ b/gcc/tree-diagnostic.h
@@ -59,8 +59,6 @@  bool default_tree_printer (pretty_printer *, text_info *, const char *,
 
 extern void default_tree_diagnostic_path_printer (diagnostic_context *,
 						  const diagnostic_path *);
-extern json::value *default_tree_make_json_for_path (diagnostic_context *,
-						     const diagnostic_path *);
 
 extern void maybe_unwind_expanded_macro_loc (diagnostic_context *context,
 					     location_t where);