From f3ffe968900d6d4986b311df874ca666ce68f123 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Tue, 30 Apr 2019 09:46:12 -0400
Subject: [PATCH 211/217] FIXME: impl-4: minor cleanups

---
 gcc/analyzer/digraph.h | 42 ++++++++++++++++++++++++++++++++++--------
 gcc/analyzer/impl-4.cc | 24 ++++++++++++++++--------
 2 files changed, 50 insertions(+), 16 deletions(-)

diff --git a/gcc/analyzer/digraph.h b/gcc/analyzer/digraph.h
index 2d9cb6a..54275d3 100644
--- a/gcc/analyzer/digraph.h
+++ b/gcc/analyzer/digraph.h
@@ -24,6 +24,9 @@ along with GCC; see the file COPYING3.  If not see
 /* Forwards decls.  */
 class dnode;
 class dedge;
+class cluster;
+
+/* Abstract base class for a node in a directed graph.  */
 
 class dnode
 {
@@ -33,6 +36,8 @@ class dnode
   virtual void dump_dot (graphviz_out *gv) const = 0;
 };
 
+/* Abstract base class for an edge in a directed graph.  */
+
 class dedge
 {
  public:
@@ -41,14 +46,7 @@ class dedge
   virtual void dump_dot (graphviz_out *gv) const = 0;
 };
 
-class cluster
-{
- public:
-  virtual void add_node (dnode *node) = 0;
-
-  /* Recursively dump the cluster, all nodes, and child clusters.  */
-  virtual void dump_dot (graphviz_out *gv) const = 0;
-};
+/* Abstract base class for a directed graph.  */
 
 class digraph
 {
@@ -68,4 +66,32 @@ class digraph
   auto_delete_vec<dedge> m_edges;
 };
 
+/* Abstract base class for splitting dnodes into hierarchical clusters
+   in the generated .dot file.
+
+   See "Subgraphs and Clusters" within
+     https://www.graphviz.org/doc/info/lang.html
+   and e.g.
+     https://graphviz.gitlab.io/_pages/Gallery/directed/cluster.html
+
+   If a root_cluster is passed to dump_dot*, then all nodes will be
+   added to it at the start of dumping, via calls to add_node.
+
+   The root cluster can organize the nodes into a hierarchy of
+   child clusters.
+
+   After all nodes are added to the root cluster, dump_dot will then
+   be called on it (and not on the nodes themselves).  */
+
+class cluster
+{
+ public:
+  virtual ~cluster () {}
+
+  virtual void add_node (dnode *node) = 0;
+
+  /* Recursively dump the cluster, all nodes, and child clusters.  */
+  virtual void dump_dot (graphviz_out *gv) const = 0;
+};
+
 #endif /* GCC_ANALYZER_DIGRAPH_H */
diff --git a/gcc/analyzer/impl-4.cc b/gcc/analyzer/impl-4.cc
index 9d91553..f907f57 100644
--- a/gcc/analyzer/impl-4.cc
+++ b/gcc/analyzer/impl-4.cc
@@ -328,9 +328,8 @@ public:
     return ec_id.get_obj (m_path_state);
   }
 
-#if 1
+  //private:
   path_state m_path_state;
-#endif
 
   auto_vec<sm_state_map *> m_checker_states;
 
@@ -1299,6 +1298,8 @@ program_state::operator= (const program_state &other)
   sm_state_map *smap;
   FOR_EACH_VEC_ELT (other.m_checker_states, i, smap)
     m_checker_states.safe_push (smap->clone ());
+
+  return *this;
 }
 
 void
@@ -1338,9 +1339,6 @@ exploded_node::dump_dot (graphviz_out *gv) const
 {
   pretty_printer *pp = gv->m_pp;
 
-  // TODO: we'll probably want to add clusters for functions and for supernodes
-  // TODO: maybe have an explicit hierarchy of cluster objects?
-
   dump_dot_id (pp);
   pp_printf (pp, " [shape=%s,style=filled,fillcolor=%s,label=\"",
 	     "record", "lightgrey");
@@ -2394,6 +2392,8 @@ checker4_path::to_str () const
 
 ////////////////////////////////////////////////////////////////////////////
 
+/* Subclass of cluster which casts the dnode instances to exploded_node.  */
+
 class en_cluster : public cluster
 {
 public:
@@ -2405,6 +2405,8 @@ public:
   virtual void add_exploded_node (exploded_node *en) = 0;
 };
 
+/* Cluster containing all exploded_node instances for one supernode.  */
+
 class supernode_cluster : public en_cluster
 {
 public:
@@ -2440,6 +2442,8 @@ private:
   auto_vec <exploded_node *> m_enodes;
 };
 
+/* Cluster containing all supernode_cluster instances for one function.  */
+
 class function_cluster : public en_cluster
 {
 public:
@@ -2486,6 +2490,9 @@ private:
   map_t m_map;
 };
 
+/* Top-level cluster for printing exploded graphs, grouping the nodes
+   by function.  */
+
 class root_cluster : public en_cluster
 {
 public:
@@ -2498,7 +2505,7 @@ public:
   {
     int i;
     exploded_node *enode;
-    FOR_EACH_VEC_ELT (m_enodes, i, enode)
+    FOR_EACH_VEC_ELT (m_functionless_enodes, i, enode)
       enode->dump_dot (gv);
 
     for (map_t::iterator iter = m_map.begin ();
@@ -2512,7 +2519,7 @@ public:
     function *fun = en->get_function ();
     if (!fun)
       {
-	m_enodes.safe_push (en);
+	m_functionless_enodes.safe_push (en);
 	return;
       }
 
@@ -2531,7 +2538,8 @@ private:
   typedef hash_map<function *, function_cluster *> map_t;
   map_t m_map;
 
-  auto_vec <exploded_node *> m_enodes;
+  /* This should just be the origin exploded_node.  */
+  auto_vec <exploded_node *> m_functionless_enodes;
 };
 
 ////////////////////////////////////////////////////////////////////////////
-- 
1.8.5.3

