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.
&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:
}
}
+/* 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 {
/* 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;