diff mbox series

[pushed] diagnostics: move diagnostic_{event, path} functions to diagnostic-path.cc

Message ID 20240621222828.1167350-1-dmalcolm@redhat.com
State New
Headers show
Series [pushed] diagnostics: move diagnostic_{event, path} functions to diagnostic-path.cc | expand

Commit Message

David Malcolm June 21, 2024, 10:28 p.m. UTC
No functional change intended.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Successful run of analyzer integration tests on x86_64-pc-linux-gnu.
Pushed to trunk as r15-1555-g4819dc7d4b84af.

gcc/ChangeLog:
	* diagnostic-path.cc (diagnostic_event::meaning::dump_to_pp): Move
	here from diagnostic.cc.
	(diagnostic_event::meaning::maybe_get_verb_str): Likewise.
	(diagnostic_event::meaning::maybe_get_noun_str): Likewise.
	(diagnostic_event::meaning::maybe_get_property_str): Likewise.
	(diagnostic_path::get_first_event_in_a_function): Likewise.
	(diagnostic_path::interprocedural_p): Likewise.
	(debug): Likewise for diagnostic_path * overload.
	* diagnostic.cc (diagnostic_event::meaning::dump_to_pp): Move from
	here to diagnostic-path.cc.
	(diagnostic_event::meaning::maybe_get_verb_str): Likewise.
	(diagnostic_event::meaning::maybe_get_noun_str): Likewise.
	(diagnostic_event::meaning::maybe_get_property_str): Likewise.
	(diagnostic_path::get_first_event_in_a_function): Likewise.
	(diagnostic_path::interprocedural_p): Likewise.
	(debug): Likewise for diagnostic_path * overload.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
 gcc/diagnostic-path.cc | 168 +++++++++++++++++++++++++++++++++++++++++
 gcc/diagnostic.cc      | 168 -----------------------------------------
 2 files changed, 168 insertions(+), 168 deletions(-)
diff mbox series

Patch

diff --git a/gcc/diagnostic-path.cc b/gcc/diagnostic-path.cc
index 882dc1c5805..ea5b1f65e02 100644
--- a/gcc/diagnostic-path.cc
+++ b/gcc/diagnostic-path.cc
@@ -45,6 +45,174 @@  along with GCC; see the file COPYING3.  If not see
 #  pragma GCC diagnostic ignored "-Wformat-diag"
 #endif
 
+/* class diagnostic_event.  */
+
+/* struct diagnostic_event::meaning.  */
+
+void
+diagnostic_event::meaning::dump_to_pp (pretty_printer *pp) const
+{
+  bool need_comma = false;
+  pp_character (pp, '{');
+  if (const char *verb_str = maybe_get_verb_str (m_verb))
+    {
+      pp_printf (pp, "verb: %qs", verb_str);
+      need_comma = true;
+    }
+  if (const char *noun_str = maybe_get_noun_str (m_noun))
+    {
+      if (need_comma)
+	pp_string (pp, ", ");
+      pp_printf (pp, "noun: %qs", noun_str);
+      need_comma = true;
+    }
+  if (const char *property_str = maybe_get_property_str (m_property))
+    {
+      if (need_comma)
+	pp_string (pp, ", ");
+      pp_printf (pp, "property: %qs", property_str);
+      need_comma = true;
+    }
+  pp_character (pp, '}');
+}
+
+/* Get a string (or NULL) for V suitable for use within a SARIF
+   threadFlowLocation "kinds" property (SARIF v2.1.0 section 3.38.8).  */
+
+const char *
+diagnostic_event::meaning::maybe_get_verb_str (enum verb v)
+{
+  switch (v)
+    {
+    default:
+      gcc_unreachable ();
+    case VERB_unknown:
+      return NULL;
+    case VERB_acquire:
+      return "acquire";
+    case VERB_release:
+      return "release";
+    case VERB_enter:
+      return "enter";
+    case VERB_exit:
+      return "exit";
+    case VERB_call:
+      return "call";
+    case VERB_return:
+      return "return";
+    case VERB_branch:
+      return "branch";
+    case VERB_danger:
+      return "danger";
+    }
+}
+
+/* Get a string (or NULL) for N suitable for use within a SARIF
+   threadFlowLocation "kinds" property (SARIF v2.1.0 section 3.38.8).  */
+
+const char *
+diagnostic_event::meaning::maybe_get_noun_str (enum noun n)
+{
+  switch (n)
+    {
+    default:
+      gcc_unreachable ();
+    case NOUN_unknown:
+      return NULL;
+    case NOUN_taint:
+      return "taint";
+    case NOUN_sensitive:
+      return "sensitive";
+    case NOUN_function:
+      return "function";
+    case NOUN_lock:
+      return "lock";
+    case NOUN_memory:
+      return "memory";
+    case NOUN_resource:
+      return "resource";
+    }
+}
+
+/* Get a string (or NULL) for P suitable for use within a SARIF
+   threadFlowLocation "kinds" property (SARIF v2.1.0 section 3.38.8).  */
+
+const char *
+diagnostic_event::meaning::maybe_get_property_str (enum property p)
+{
+  switch (p)
+    {
+    default:
+      gcc_unreachable ();
+    case PROPERTY_unknown:
+      return NULL;
+    case PROPERTY_true:
+      return "true";
+    case PROPERTY_false:
+      return "false";
+    }
+}
+
+/* class diagnostic_path.  */
+
+/* Subroutine of diagnostic_path::interprocedural_p.
+   Look for the first event in this path that is within a function
+   i.e. has a non-null logical location for which function_p is true.
+   If found, write its index to *OUT_IDX and return true.
+   Otherwise return false.  */
+
+bool
+diagnostic_path::get_first_event_in_a_function (unsigned *out_idx) const
+{
+  const unsigned num = num_events ();
+  for (unsigned i = 0; i < num; i++)
+    {
+      const diagnostic_event &event = get_event (i);
+      if (const logical_location *logical_loc = event.get_logical_location ())
+	if (logical_loc->function_p ())
+	  {
+	    *out_idx = i;
+	    return true;
+	  }
+    }
+  return false;
+}
+
+/* Return true if the events in this path involve more than one
+   function, or false if it is purely intraprocedural.  */
+
+bool
+diagnostic_path::interprocedural_p () const
+{
+  /* Ignore leading events that are outside of any function.  */
+  unsigned first_fn_event_idx;
+  if (!get_first_event_in_a_function (&first_fn_event_idx))
+    return false;
+
+  const diagnostic_event &first_fn_event = get_event (first_fn_event_idx);
+  int first_fn_stack_depth = first_fn_event.get_stack_depth ();
+
+  const unsigned num = num_events ();
+  for (unsigned i = first_fn_event_idx + 1; i < num; i++)
+    {
+      if (!same_function_p (first_fn_event_idx, i))
+	return true;
+      if (get_event (i).get_stack_depth () != first_fn_stack_depth)
+	return true;
+    }
+  return false;
+}
+
+/* Print PATH by emitting a dummy "note" associated with it.  */
+
+DEBUG_FUNCTION
+void debug (diagnostic_path *path)
+{
+  rich_location richloc (line_table, UNKNOWN_LOCATION);
+  richloc.set_path (path);
+  inform (&richloc, "debug path");
+}
+
 /* Anonymous namespace for path-printing code.  */
 
 namespace {
diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index 471135f16de..c66aa5af5ff 100644
--- a/gcc/diagnostic.cc
+++ b/gcc/diagnostic.cc
@@ -918,164 +918,6 @@  diagnostic_context::show_any_path (const diagnostic_info &diagnostic)
   print_path (path);
 }
 
-/* class diagnostic_event.  */
-
-/* struct diagnostic_event::meaning.  */
-
-void
-diagnostic_event::meaning::dump_to_pp (pretty_printer *pp) const
-{
-  bool need_comma = false;
-  pp_character (pp, '{');
-  if (const char *verb_str = maybe_get_verb_str (m_verb))
-    {
-      pp_printf (pp, "verb: %qs", verb_str);
-      need_comma = true;
-    }
-  if (const char *noun_str = maybe_get_noun_str (m_noun))
-    {
-      if (need_comma)
-	pp_string (pp, ", ");
-      pp_printf (pp, "noun: %qs", noun_str);
-      need_comma = true;
-    }
-  if (const char *property_str = maybe_get_property_str (m_property))
-    {
-      if (need_comma)
-	pp_string (pp, ", ");
-      pp_printf (pp, "property: %qs", property_str);
-      need_comma = true;
-    }
-  pp_character (pp, '}');
-}
-
-/* Get a string (or NULL) for V suitable for use within a SARIF
-   threadFlowLocation "kinds" property (SARIF v2.1.0 section 3.38.8).  */
-
-const char *
-diagnostic_event::meaning::maybe_get_verb_str (enum verb v)
-{
-  switch (v)
-    {
-    default:
-      gcc_unreachable ();
-    case VERB_unknown:
-      return NULL;
-    case VERB_acquire:
-      return "acquire";
-    case VERB_release:
-      return "release";
-    case VERB_enter:
-      return "enter";
-    case VERB_exit:
-      return "exit";
-    case VERB_call:
-      return "call";
-    case VERB_return:
-      return "return";
-    case VERB_branch:
-      return "branch";
-    case VERB_danger:
-      return "danger";
-    }
-}
-
-/* Get a string (or NULL) for N suitable for use within a SARIF
-   threadFlowLocation "kinds" property (SARIF v2.1.0 section 3.38.8).  */
-
-const char *
-diagnostic_event::meaning::maybe_get_noun_str (enum noun n)
-{
-  switch (n)
-    {
-    default:
-      gcc_unreachable ();
-    case NOUN_unknown:
-      return NULL;
-    case NOUN_taint:
-      return "taint";
-    case NOUN_sensitive:
-      return "sensitive";
-    case NOUN_function:
-      return "function";
-    case NOUN_lock:
-      return "lock";
-    case NOUN_memory:
-      return "memory";
-    case NOUN_resource:
-      return "resource";
-    }
-}
-
-/* Get a string (or NULL) for P suitable for use within a SARIF
-   threadFlowLocation "kinds" property (SARIF v2.1.0 section 3.38.8).  */
-
-const char *
-diagnostic_event::meaning::maybe_get_property_str (enum property p)
-{
-  switch (p)
-    {
-    default:
-      gcc_unreachable ();
-    case PROPERTY_unknown:
-      return NULL;
-    case PROPERTY_true:
-      return "true";
-    case PROPERTY_false:
-      return "false";
-    }
-}
-
-/* class diagnostic_path.  */
-
-/* Subroutine of diagnostic_path::interprocedural_p.
-   Look for the first event in this path that is within a function
-   i.e. has a non-null logical location for which function_p is true.
-   If found, write its index to *OUT_IDX and return true.
-   Otherwise return false.  */
-
-bool
-diagnostic_path::get_first_event_in_a_function (unsigned *out_idx) const
-{
-  const unsigned num = num_events ();
-  for (unsigned i = 0; i < num; i++)
-    {
-      const diagnostic_event &event = get_event (i);
-      if (const logical_location *logical_loc = event.get_logical_location ())
-	if (logical_loc->function_p ())
-	  {
-	    *out_idx = i;
-	    return true;
-	  }
-    }
-  return false;
-}
-
-/* Return true if the events in this path involve more than one
-   function, or false if it is purely intraprocedural.  */
-
-bool
-diagnostic_path::interprocedural_p () const
-{
-  /* Ignore leading events that are outside of any function.  */
-  unsigned first_fn_event_idx;
-  if (!get_first_event_in_a_function (&first_fn_event_idx))
-    return false;
-
-  const diagnostic_event &first_fn_event = get_event (first_fn_event_idx);
-  int first_fn_stack_depth = first_fn_event.get_stack_depth ();
-
-  const unsigned num = num_events ();
-  for (unsigned i = first_fn_event_idx + 1; i < num; i++)
-    {
-      if (!same_function_p (first_fn_event_idx, i))
-	return true;
-      if (get_event (i).get_stack_depth () != first_fn_stack_depth)
-	return true;
-    }
-  return false;
-}
-
 /* class logical_location.  */
 
 /* Return true iff this is a function or method.  */
@@ -2543,16 +2385,6 @@  set_text_art_charset (enum diagnostic_text_art_charset charset)
     }
 }
 
-/* Print PATH by emitting a dummy "note" associated with it.  */
-
-DEBUG_FUNCTION
-void debug (diagnostic_path *path)
-{
-  rich_location richloc (line_table, UNKNOWN_LOCATION);
-  richloc.set_path (path);
-  inform (&richloc, "debug path");
-}
-
 /* Really call the system 'abort'.  This has to go right at the end of
    this file, so that there are no functions after it that call abort
    and get the system abort instead of our macro.  */