From 052811bfc788cf8d4fee0836663c38eae1267f61 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Tue, 12 May 2020 10:50:24 -0400
Subject: [PATCH 113/179] FIXME: move binding_key2::kind to top level

---
 gcc/analyzer/store2.cc | 51 ++++++++++++++++++------------------------
 gcc/analyzer/store2.h  | 48 ++++++++++++++++++++++-----------------
 2 files changed, 49 insertions(+), 50 deletions(-)

diff --git a/gcc/analyzer/store2.cc b/gcc/analyzer/store2.cc
index 7a933fc2652..6c275777669 100644
--- a/gcc/analyzer/store2.cc
+++ b/gcc/analyzer/store2.cc
@@ -65,10 +65,18 @@ along with GCC; see the file COPYING3.  If not see
 
 namespace ana {
 
+/* FIXME.  */
+
+const char *binding_kind_to_string (enum binding_kind kind)
+{
+  return kind == BK_direct ? "direct" : "default";
+}
+
 /* class binding_key2.  */
 
 const binding_key2 *
-binding_key2::make (store2_manager *mgr, const region2 *r, enum kind kind)
+binding_key2::make (store2_manager *mgr, const region2 *r,
+		    enum binding_kind kind)
 {
   region_offset offset = r->get_offset ();
   if (offset.symbolic_p ())
@@ -86,7 +94,7 @@ binding_key2::dump_to_pp (pretty_printer *pp, bool simple) const
 {
   pp_string (pp, "region: ");
   m_region->dump_to_pp (pp, simple);
-  pp_printf (pp, ", kind: %s", kind_to_string (m_kind));
+  pp_printf (pp, ", kind: %s", binding_kind_to_string (m_kind));
 }
 
 /* FIXME.  */
@@ -121,8 +129,8 @@ binding_key2::cmp (const binding_key2 *k1, const binding_key2 *k2)
   if (int reg_cmp = region2::cmp_ids (k1->m_region, k2->m_region))
     return reg_cmp;
 
-  enum kind kind1 = k1->get_kind ();
-  enum kind kind2 = k2->get_kind ();
+  enum binding_kind kind1 = k1->get_kind ();
+  enum binding_kind kind2 = k2->get_kind ();
   if (kind1 != kind2)
     return (int)kind1 - (int)kind2;
 
@@ -235,7 +243,7 @@ binding_cluster2::dump_to_pp (pretty_printer *pp, bool simple,
 void
 binding_cluster2::bind (store2_manager *mgr,
 			const region2 *reg, const svalue2 *val,
-			binding_key2::kind kind)
+			binding_kind kind)
 {
   const binding_key2 *binding = binding_key2::make (mgr, reg, kind);
   m_map.put (binding, val);
@@ -257,7 +265,7 @@ binding_cluster2::purge_region (store2_manager *mgr, const region2 *reg)
   gcc_assert (reg->get_kind () == region2::RK_DECL);
   const binding_key2 *binding
     = binding_key2::make (mgr, const_cast<region2 *> (reg),
-			  binding_key2::BK_direct);
+			  BK_direct);
   m_map.remove (binding);
 }
 
@@ -275,7 +283,7 @@ binding_cluster2::zero_fill_region (store2_manager *mgr, const region2 *reg)
   const svalue2 *cast_sval
     = sval_mgr->get_or_create_unaryop (reg->get_type (), NOP_EXPR, cst_sval);
   // FIXME: will want this to fold redundant casts, I guess; it may do it already
-  bind (mgr, reg, cast_sval, binding_key2::BK_default);
+  bind (mgr, reg, cast_sval, BK_default);
 }
 
 /* FIXME.  */
@@ -283,7 +291,7 @@ binding_cluster2::zero_fill_region (store2_manager *mgr, const region2 *reg)
 const svalue2 *
 binding_cluster2::get_binding (store2_manager *mgr,
 			       const region2 *reg,
-			       binding_key2::kind kind) const
+			       binding_kind kind) const
 {
   const binding_key2 *binding = binding_key2::make (mgr, reg, kind);
   const svalue2 **slot = const_cast<map_t &> (m_map).get (binding);
@@ -299,7 +307,7 @@ binding_cluster2::get_default_binding_recursive (store2_manager *mgr,
 						 const region2 *reg) const
 {
   if (const svalue2 *default_sval
-      = get_binding (mgr, reg, binding_key2::BK_default))
+      = get_binding (mgr, reg, BK_default))
     return default_sval;
   if (const region2 *parent_reg = reg->get_parent_region ())
     if (const svalue2 *parent_default_sval
@@ -315,7 +323,7 @@ binding_cluster2::get_any_binding (store2_manager *mgr,
 				   const region2 *reg) const
 {
   if (const svalue2 *direct_sval
-      = get_binding (mgr, reg, binding_key2::BK_direct))
+      = get_binding (mgr, reg, BK_direct))
     return direct_sval;
   return get_default_binding_recursive (mgr, reg);
 }
@@ -331,7 +339,7 @@ binding_cluster2::get_overlapping_bindings (store2_manager *mgr,
   // TODO
 
   const binding_key2 *binding
-    = binding_key2::make (mgr, reg, binding_key2::BK_direct);
+    = binding_key2::make (mgr, reg, BK_direct);
   for (map_t::iterator iter = m_map.begin ();
        iter != m_map.end (); ++iter)
     {
@@ -443,7 +451,7 @@ binding_cluster2::get_representative_path_vars (const region2 *base_reg,
 
 const concrete_binding2 *
 store2_manager::get_concrete_binding (const region2 *reg,
-				      enum binding_key2::kind kind,
+				      enum binding_kind kind,
 				      concrete_binding2::bit_offset_t offset)
 {
   concrete_binding2 *b = new concrete_binding2 (reg, kind, offset);
@@ -452,7 +460,7 @@ store2_manager::get_concrete_binding (const region2 *reg,
 
 const symbolic_binding2 *
 store2_manager::get_symbolic_binding (const region2 *reg,
-				      enum binding_key2::kind kind,
+				      enum binding_kind kind,
 				      const region2 *concrete_offset_region)
 {
   symbolic_binding2 *b
@@ -597,23 +605,8 @@ store2::dump_to_pp (pretty_printer *pp, bool summarize, bool multiline) const
     }
 }
 
-#if 0
-const svalue2 *
-store2::get_direct_binding (store2_manager *mgr, const region2 *reg)
-{
-  return get_binding (mgr, reg, binding_key2::BK_direct);
-}
-
-const svalue2 *
-store2::get_default_binding (store2_manager *mgr, const region2 *reg)
-{
-  return get_binding (mgr, reg, binding_key2::BK_direct);
-}
-#endif
-
 const svalue2 *
 store2::get_any_binding (store2_manager *mgr, const region2 *reg)
-//binding_key2::kind kind)
 {
   const region2 *base_reg = reg->get_base_region ();
   binding_cluster2 **cluster_slot = m_cluster_map.get (base_reg);
@@ -630,7 +623,7 @@ store2::set_value (store2_manager *mgr, const region2 *lhs_reg,
 
   const region2 *base_reg = lhs_reg->get_base_region ();
   binding_cluster2 *cluster = get_or_create_cluster (base_reg);
-  cluster->bind (mgr, lhs_reg, rhs_sval, binding_key2::BK_direct);
+  cluster->bind (mgr, lhs_reg, rhs_sval, BK_direct);
   // TODO: various kinds of invalidation etc
 }
 
diff --git a/gcc/analyzer/store2.h b/gcc/analyzer/store2.h
index 3cf3e9bae31..c80f8e26e4b 100644
--- a/gcc/analyzer/store2.h
+++ b/gcc/analyzer/store2.h
@@ -34,6 +34,21 @@ namespace ana {
 
 class concrete_binding2;
 
+/* FIXME.  */
+
+enum binding_kind
+{
+  /* FIXME.  */
+  BK_direct,
+
+  /* FIXME.  */
+  BK_default
+};
+
+/* FIXME.  */
+
+extern const char *binding_kind_to_string (enum binding_kind kind);
+
 /* A binding within a store.  */
 
 class binding_key2
@@ -42,18 +57,8 @@ public:
   virtual ~binding_key2 () {}
   virtual bool concrete_p () const = 0;
 
-  enum kind
-  {
-   BK_direct,
-   BK_default
-  };
-  static const char *kind_to_string (enum kind kind)
-  {
-    return kind == BK_direct ? "direct" : "default";
-  }
-
   static const binding_key2 *make (store2_manager *mgr, const region2 *r,
-				   enum kind kind);
+				   enum binding_kind kind);
 
   virtual void dump_to_pp (pretty_printer *pp, bool simple) const;
   void dump (bool simple) const;
@@ -65,12 +70,12 @@ public:
   { return NULL; }
 
 protected:
-  binding_key2 (const region2 *region, enum kind kind)
+  binding_key2 (const region2 *region, enum binding_kind kind)
   : m_region (region), m_kind (kind) {}
 
   const region2 *get_region () const { return m_region; }
 
-  enum kind get_kind () const { return m_kind; }
+  enum binding_kind get_kind () const { return m_kind; }
 
   hashval_t impl_hash () const
   {
@@ -83,7 +88,7 @@ protected:
 
 private:
   const region2 *m_region;
-  enum kind m_kind;
+  enum binding_kind m_kind;
 };
 
 class concrete_binding2 : public binding_key2
@@ -91,7 +96,8 @@ class concrete_binding2 : public binding_key2
 public:
   typedef region_offset::bit_offset_t bit_offset_t;
 
-  concrete_binding2 (const region2 *region, enum kind kind, bit_offset_t offset)
+  concrete_binding2 (const region2 *region, enum binding_kind kind,
+		     bit_offset_t offset)
   : binding_key2 (region, kind), m_offset (offset)
   {}
   bool concrete_p () const FINAL OVERRIDE { return true; }
@@ -126,8 +132,8 @@ private:
 class symbolic_binding2 : public binding_key2
 {
 public:
-  symbolic_binding2 (const region2 *region, enum kind kind,
-		    const region2 *concrete_offset_region)
+  symbolic_binding2 (const region2 *region, enum binding_kind kind,
+		     const region2 *concrete_offset_region)
   : binding_key2 (region, kind),
     m_concrete_offset_region (concrete_offset_region)
   {}
@@ -168,7 +174,7 @@ public:
 
 #if 1
   void bind (store2_manager *mgr, const region2 *, const svalue2 *,
-	     binding_key2::kind kind);
+	     binding_kind kind);
 #else
   const binding_cluster2 *bind (const extrinsic_state &ext_state,
 			       const region2 *, const svalue2 *) const;
@@ -179,7 +185,7 @@ public:
   void zero_fill_region (store2_manager *mgr, const region2 *reg);
 
   const svalue2 *get_binding (store2_manager *mgr, const region2 *reg,
-			      binding_key2::kind kind) const;
+			      binding_kind kind) const;
   const svalue2 *get_default_binding_recursive (store2_manager *mgr,
 						const region2 *reg) const;
   const svalue2 *get_any_binding (store2_manager *mgr,
@@ -285,12 +291,12 @@ public:
   /* binding consolidation.  */
   const concrete_binding2 *
   get_concrete_binding (const region2 *region,
-			enum binding_key2::kind kind,
+			enum binding_kind kind,
 			concrete_binding2::bit_offset_t offset);
 
   const symbolic_binding2 *
   get_symbolic_binding (const region2 *region,
-			enum binding_key2::kind kind,
+			enum binding_kind kind,
 			const region2 *concrete_offset_region);
 
   region_model2_manager *get_svalue2_manager () const
-- 
2.21.0

