analyzer: add program_point::get_next
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 15 Sep 2020 18:25:52 +0000 (14:25 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Wed, 16 Sep 2020 23:00:41 +0000 (19:00 -0400)
Avoid some future copy-and-paste by introducing a function.

gcc/analyzer/ChangeLog:
* engine.cc
(exploded_graph::process_node) <case PK_BEFORE_SUPERNODE>:
Simplify by using program_point::get_next.
* program-point.cc (program_point::get_next): New.
* program-point.h (program_point::get_next): New decl.

gcc/analyzer/engine.cc
gcc/analyzer/program-point.cc
gcc/analyzer/program-point.h

index 8f5c5143ca57af634e2852ac9b9de9fcee427908..5903b19b7744a5c26962bd97ef19cfc5440bd069 100644 (file)
@@ -2458,26 +2458,10 @@ exploded_graph::process_node (exploded_node *node)
                 &ctxt);
          }
 
-       if (point.get_supernode ()->m_stmts.length () > 0)
-         {
-           program_point next_point
-             = program_point::before_stmt (point.get_supernode (), 0,
-                                           point.get_call_string ());
-           exploded_node *next
-             = get_or_create_node (next_point, next_state, node);
-           if (next)
-             add_edge (node, next, NULL);
-         }
-       else
-         {
-           program_point next_point
-             = program_point::after_supernode (point.get_supernode (),
-                                               point.get_call_string ());
-           exploded_node *next = get_or_create_node (next_point, next_state,
-                                                     node);
-           if (next)
-             add_edge (node, next, NULL);
-         }
+       program_point next_point (point.get_next ());
+       exploded_node *next = get_or_create_node (next_point, next_state, node);
+       if (next)
+         add_edge (node, next, NULL);
       }
       break;
     case PK_BEFORE_STMT:
index 2c0a4c42bf513a3d4744523ae08e8bbc3eb70cc2..ef19e6e38e576f71d121b1c347d2f72c6a339c1b 100644 (file)
@@ -529,6 +529,35 @@ function_point::next_stmt ()
     }
 }
 
+/* For those program points for which there is a uniquely-defined
+   successor, return it.  */
+
+program_point
+program_point::get_next () const
+{
+  switch (m_function_point.get_kind ())
+    {
+    default:
+      gcc_unreachable ();
+    case PK_ORIGIN:
+    case PK_AFTER_SUPERNODE:
+      gcc_unreachable (); /* Not uniquely defined.  */
+    case PK_BEFORE_SUPERNODE:
+      if (get_supernode ()->m_stmts.length () > 0)
+       return before_stmt (get_supernode (), 0, get_call_string ());
+      else
+       return after_supernode (get_supernode (), get_call_string ());
+    case PK_BEFORE_STMT:
+      {
+       unsigned next_idx = get_stmt_idx ();
+       if (next_idx < get_supernode ()->m_stmts.length ())
+         return before_stmt (get_supernode (), next_idx, get_call_string ());
+       else
+         return after_supernode (get_supernode (), get_call_string ());
+      }
+    }
+}
+
 #if CHECKING_P
 
 namespace selftest {
index cb11478468d2cc48fdee27d7a3f6d277f168ab6e..97fd0a5e9deea7a4b2a18da63f81a111f9a24c8d 100644 (file)
@@ -294,6 +294,8 @@ public:
   /* For before_stmt, go to next stmt.  */
   void next_stmt () { m_function_point.next_stmt (); }
 
+  program_point get_next () const;
+
  private:
   function_point m_function_point;
   call_string m_call_string;