From 0f244fceb5038bd310514fda796ec8b39dd15c2a Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Mon, 20 May 2019 12:38:41 -0400
Subject: [PATCH 58/66] FIXME: put old constraint impl in a namespace

---
 gcc/analyzer/engine.cc     | 14 ++++++-------
 gcc/analyzer/impl-3.cc     | 14 +++++++------
 gcc/analyzer/impl-4.cc     | 19 +++++++++---------
 gcc/analyzer/path-state.cc |  4 +++-
 gcc/analyzer/path-state.h  | 50 +++++++++++++++++++++++++++++-----------------
 5 files changed, 60 insertions(+), 41 deletions(-)

diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index 715d9c6..873c990 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -1412,8 +1412,8 @@ public:
 
     // FIXME: do it for everything in the equivalence class
     // FIXME: stack depth:
-    equiv_class_id ec_id = m_ps->get_or_add_equiv_class (path_var (var, 0));
-    equiv_class &ec = ec_id.get_obj (*m_ps);
+    psn::equiv_class_id ec_id = m_ps->get_or_add_equiv_class (path_var (var, 0));
+    psn::equiv_class &ec = ec_id.get_obj (*m_ps);
 
     if (m_engine->get_logger ())
       m_engine->log ("considering equivalence class: %s",
@@ -1865,8 +1865,8 @@ engine::on_stmt (const supernode *node, const gimple *stmt,
 	       this path, and record the result, if known.  */
 	    tree rhs2 = gimple_assign_rhs2 (assign);
 	    // FIXME: stack depths:
-	    equiv_class_id rhs1_ec_id = ps->get_or_add_equiv_class (path_var (rhs1, 0));
-	    equiv_class_id rhs2_ec_id = ps->get_or_add_equiv_class (path_var (rhs2, 0));
+	    psn::equiv_class_id rhs1_ec_id = ps->get_or_add_equiv_class (path_var (rhs1, 0));
+	    psn::equiv_class_id rhs2_ec_id = ps->get_or_add_equiv_class (path_var (rhs2, 0));
 	    tristate t = ps->eval_condition (rhs1_ec_id, op, rhs2_ec_id);
 	    if (get_logger ())
 	      log ("eval condition: %s", t.as_string ());
@@ -2604,7 +2604,7 @@ engine::detect_leaks (const supernode *node, const sm_instance &sm_inst,
       {
 	log ("new_ps before escapes: %s", new_ps.to_str ().c_str ());
 	// FIXME: stack depth:
-	equiv_class_id ec_id
+	psn::equiv_class_id ec_id
 	  = new_ps.get_or_add_equiv_class (path_var (result, 0));
 	new_ps.recursively_mark_as_escaping (ec_id);
 	log ("new_ps after escapes: %s", new_ps.to_str ().c_str ());
@@ -2641,9 +2641,9 @@ engine::detect_leaks (const supernode *node, const sm_instance &sm_inst,
        /* Did this var's equivalence class escape?  If so, don't complain
 	 about it leaking.  */
       // FIXME: stack depth:
-      equiv_class_id ec_id
+      psn::equiv_class_id ec_id
 	= new_ps.get_or_add_equiv_class (path_var (vs->m_var, 0));
-      equiv_class &ec = ec_id.get_obj (new_ps);
+      psn::equiv_class &ec = ec_id.get_obj (new_ps);
       if (get_logger ())
 	log ("within %s", ec.to_str ().c_str ());
       if (ec.m_escaped)
diff --git a/gcc/analyzer/impl-3.cc b/gcc/analyzer/impl-3.cc
index 35bda74..1bfaca4 100644
--- a/gcc/analyzer/impl-3.cc
+++ b/gcc/analyzer/impl-3.cc
@@ -43,6 +43,8 @@
 #include "selftest.h"
 #include "path-state.h"
 
+using namespace psn;
+
 namespace impl_3 {
 
 ////////////////////////////////////////////////////////////////////////////
@@ -87,7 +89,7 @@ class engine;
 
 /* FIXME.  */
 
-class ec3_state : public extra_ec_state
+class ec3_state : public psn::extra_ec_state
 {
  public:
   ec3_state (const state_machine &sm,
@@ -645,10 +647,10 @@ public:
 		  state_machine::state_t baseline_state,
 		  state_machine::state_t new_state);
 
-  equiv_class &get_ec (tree expr)
+  psn::equiv_class &get_ec (tree expr)
   {
     path_var pv (expr, get_stack_depth ());
-    equiv_class_id ec_id = m_ps.get_or_add_equiv_class (pv);
+    psn::equiv_class_id ec_id = m_ps.get_or_add_equiv_class (pv);
     return ec_id.get_obj (m_ps);
   }
 
@@ -781,7 +783,7 @@ public:
   void reset_baseline_states ()
   {
     int i;
-    equiv_class *ec;
+    psn::equiv_class *ec;
     FOR_EACH_VEC_ELT (m_path->m_ps.m_equiv_classes, i, ec)
       {
 	ec3_state *extra_state = (ec3_state *)ec->m_extra_state;
@@ -1079,7 +1081,7 @@ checker3_path::add_link (const superedge *edge, const supernode *node)
 state_machine::state_t
 checker3_path::get_baseline_state (tree expr)
 {
-  equiv_class &ec = get_ec (expr);
+  psn::equiv_class &ec = get_ec (expr);
   ec3_state *extra_state = (ec3_state *)ec.m_extra_state;
   if (extra_state)
     return extra_state->m_baseline_state;
@@ -1092,7 +1094,7 @@ checker3_path::set_state (tree expr,
 			  state_machine::state_t baseline_state,
 			  state_machine::state_t new_state)
 {
-  equiv_class &ec = get_ec (expr);
+  psn::equiv_class &ec = get_ec (expr);
   delete ec.m_extra_state;
   ec.m_extra_state = new ec3_state (get_sm (), baseline_state, new_state);
   if (m_engine->get_logger ())
diff --git a/gcc/analyzer/impl-4.cc b/gcc/analyzer/impl-4.cc
index ab59bd2..24102bc 100644
--- a/gcc/analyzer/impl-4.cc
+++ b/gcc/analyzer/impl-4.cc
@@ -630,7 +630,7 @@ public:
 
   void set_state (path_state *ps, path_var pv, state_machine::state_t state,
 		  path_var origin);
-  void set_state (const equiv_class &ec,
+  void set_state (const psn::equiv_class &ec,
 		  state_machine::state_t state,
 		  path_var origin);
   void impl_set_state (path_var pv,
@@ -678,9 +678,9 @@ public:
 	      pretty_printer *pp) const;
   std::string to_str (const extrinsic_state &ext_state) const;
 
-  equiv_class &get_ec (path_var pv)
+  psn::equiv_class &get_ec (path_var pv)
   {
-    equiv_class_id ec_id = m_path_state.get_or_add_equiv_class (pv);
+    psn::equiv_class_id ec_id = m_path_state.get_or_add_equiv_class (pv);
     return ec_id.get_obj (m_path_state);
   }
 
@@ -1998,14 +1998,15 @@ sm_state_map::set_state (path_state *ps,
 			 state_machine::state_t state,
 			 path_var origin)
 {
-  equiv_class &ec = ps->get_equiv_class (pv);
+  psn::equiv_class &ec = ps->get_equiv_class (pv);
   set_state (ec, state, origin);
 }
 
 /* FIXME.  */
 
 void
-sm_state_map::set_state (const equiv_class &ec, state_machine::state_t state,
+sm_state_map::set_state (const psn::equiv_class &ec,
+			 state_machine::state_t state,
 			 path_var origin)
 {
   int i;
@@ -2679,9 +2680,9 @@ exploded_node::on_stmt (exploded_graph &eg) const
 	    /* If we see a comparison, evaluate it based on what we know along
 	       this path, and record the result, if known.  */
 	    tree rhs2 = gimple_assign_rhs2 (assign);
-	    equiv_class_id rhs1_ec_id
+	    psn::equiv_class_id rhs1_ec_id
 	      = new_ps->get_or_add_equiv_class (path_var (rhs1, stack_depth));
-	    equiv_class_id rhs2_ec_id
+	    psn::equiv_class_id rhs2_ec_id
 	      = new_ps->get_or_add_equiv_class (path_var (rhs2, stack_depth));
 	    tristate t = new_ps->eval_condition (rhs1_ec_id, op, rhs2_ec_id);
 	    if (eg.get_logger ())
@@ -3055,7 +3056,7 @@ exploded_node::detect_leaks (exploded_graph &eg) const
       {
 	if (eg.get_logger ())
 	  eg.log ("new_ps before escapes: %s", new_ps->to_str ().c_str ());
-	equiv_class_id ec_id
+	psn::equiv_class_id ec_id
 	  = new_ps->get_or_add_equiv_class (path_var (result, stack_depth));
 	new_ps->recursively_mark_as_escaping (ec_id);
 	if (eg.get_logger ())
@@ -3064,7 +3065,7 @@ exploded_node::detect_leaks (exploded_graph &eg) const
   }
 
   int i;
-  equiv_class *ec;
+  psn::equiv_class *ec;
   FOR_EACH_VEC_ELT (new_ps->m_equiv_classes, i, ec)
     {
       if (eg.get_logger ())
diff --git a/gcc/analyzer/path-state.cc b/gcc/analyzer/path-state.cc
index ec39dc6..3dcb237 100644
--- a/gcc/analyzer/path-state.cc
+++ b/gcc/analyzer/path-state.cc
@@ -41,6 +41,8 @@
 #include "path-state.h"
 #include "supergraph.h"
 
+using namespace psn;
+
 /* A subclass of purge_criteria: purge a specific path_var.  */
 
 class purge_one_path_var : public purge_criteria
@@ -257,7 +259,7 @@ equiv_class::get_representative () const
 /* FIXME.  */
 
 const char *
-constraint_op_code (enum constraint_op c_op)
+psn::constraint_op_code (enum constraint_op c_op)
 {
   switch (c_op)
     {
diff --git a/gcc/analyzer/path-state.h b/gcc/analyzer/path-state.h
index 5dbc8a0..ac82356 100644
--- a/gcc/analyzer/path-state.h
+++ b/gcc/analyzer/path-state.h
@@ -25,6 +25,11 @@ class superedge;
 class call_superedge;
 class return_superedge;
 
+/* FIXME: put everything to do with path_state in its own namespace
+   while building up the alternative impl.  */
+
+namespace psn {
+
 /* One of the end-points of a range.  */
 
 struct bound
@@ -55,6 +60,8 @@ struct range
   bound m_upper_bound;
 };
 
+} // namespace psn
+
 /* A tree, extended with stack frame information for locals, so that
    we can distinguish between different values of locals within a potentially
    recursive callstack.  */
@@ -89,6 +96,13 @@ public:
   virtual bool should_purge_p (path_var pv) const = 0;
 };
 
+class path_state;
+
+/* FIXME: put everything to do with path_state in its own namespace
+   while building up the alternative impl.  */
+
+namespace psn {
+
 /* Optional per-engine extra state (to avoid making path_state a
    template).  */
 
@@ -147,8 +161,6 @@ enum constraint_op
 
 const char *constraint_op_code (enum constraint_op c_op);
 
-class path_state;
-
 class equiv_class_id
 {
 public:
@@ -199,6 +211,8 @@ class constraint {
   equiv_class_id m_rhs;
 };
 
+} // namespace psn
+
 /* The state of a particular point at one point in the traversal (not including
    state-machine information).  */
 
@@ -220,18 +234,18 @@ public:
 
   std::string to_str () const;
 
-  const equiv_class &get_equiv_class_by_index (unsigned idx) const
+  const psn::equiv_class &get_equiv_class_by_index (unsigned idx) const
   {
     return *m_equiv_classes[idx];
   }
-  equiv_class &get_equiv_class_by_index (unsigned idx)
+  psn::equiv_class &get_equiv_class_by_index (unsigned idx)
   {
     return *m_equiv_classes[idx];
   }
 
-  equiv_class &get_equiv_class (path_var pv)
+  psn::equiv_class &get_equiv_class (path_var pv)
   {
-    equiv_class_id ec_id = get_or_add_equiv_class (pv);
+    psn::equiv_class_id ec_id = get_or_add_equiv_class (pv);
     return ec_id.get_obj (*this);
   }
 
@@ -247,9 +261,9 @@ public:
 
   bool add_constraint (path_var lhs, enum tree_code op, path_var rhs);
 
-  bool add_constraint (equiv_class_id lhs_ec_id,
+  bool add_constraint (psn::equiv_class_id lhs_ec_id,
 		       enum tree_code op,
-		       equiv_class_id rhs_ec_id);
+		       psn::equiv_class_id rhs_ec_id);
 
   //private:
   bool apply_constraints_for_call (const call_superedge& edge);
@@ -262,30 +276,30 @@ public:
 				    const gcond *cond_stmt);
   bool apply_constraints_for_gswitch (const superedge &edge,
 				      const gswitch *switch_stmt);
-  bool get_equiv_class (path_var pv, equiv_class_id *out) const;
-  equiv_class_id get_or_add_equiv_class (path_var vr);
-  tristate eval_condition (equiv_class_id lhs,
+  bool get_equiv_class (path_var pv, psn::equiv_class_id *out) const;
+  psn::equiv_class_id get_or_add_equiv_class (path_var vr);
+  tristate eval_condition (psn::equiv_class_id lhs,
 			   enum tree_code op,
-			   equiv_class_id rhs);
+			   psn::equiv_class_id rhs);
 
   /* For implementing "__analyzer_eval".  */
   tristate dump_condition (tree lhs, enum tree_code op, tree rhs);
 
-  void recursively_mark_as_escaping (equiv_class_id ec_id);
+  void recursively_mark_as_escaping (psn::equiv_class_id ec_id);
   bool calc_escaped_p (path_var pv);
 
   int purge (const purge_criteria &p);
 
   void validate () const;
 
-  auto_vec<equiv_class *> m_equiv_classes;
-  auto_vec<constraint> m_constraints;
+  auto_vec<psn::equiv_class *> m_equiv_classes;
+  auto_vec<psn::constraint> m_constraints;
   int m_stack_depth;
 
  private:
-  void add_constraint_internal (equiv_class_id lhs_id,
-				enum constraint_op c_op,
-				equiv_class_id rhs_id);
+  void add_constraint_internal (psn::equiv_class_id lhs_id,
+				enum psn::constraint_op c_op,
+				psn::equiv_class_id rhs_id);
 };
 
 namespace inchash
-- 
1.8.5.3

