From 01d60051f084c99c4a5c019b1820ca10cd81282d Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 7 May 2020 06:56:09 -0400
Subject: [PATCH 106/237] FIXME: support single-line dumps

---
 gcc/analyzer/constraint-manager2.cc | 43 +++++++++++++++------
 gcc/analyzer/constraint-manager2.h  |  2 +-
 gcc/analyzer/engine.cc              | 22 +++++------
 gcc/analyzer/program-state.cc       | 59 ++++++++++++++++++++---------
 gcc/analyzer/program-state.h        | 10 ++---
 gcc/analyzer/region-model2.cc       | 57 +++++++++++++++++++---------
 gcc/analyzer/region-model2.h        |  6 +--
 gcc/analyzer/store2.cc              |  7 +++-
 8 files changed, 138 insertions(+), 68 deletions(-)

diff --git a/gcc/analyzer/constraint-manager2.cc b/gcc/analyzer/constraint-manager2.cc
index 03fe15ba286..e6a6c21653c 100644
--- a/gcc/analyzer/constraint-manager2.cc
+++ b/gcc/analyzer/constraint-manager2.cc
@@ -574,34 +574,55 @@ constraint_manager2::print (pretty_printer *pp) const
   pp_printf (pp, "}");
 }
 
-/* Dump a multiline representation of this constraint_manager2 to PP
+/* Dump a representation of this constraint_manager2 to PP
    (which must support %E for trees).  */
 
 void
-constraint_manager2::dump_to_pp (pretty_printer *pp) const
+constraint_manager2::dump_to_pp (pretty_printer *pp, bool multiline) const
 {
   // TODO
-  pp_string (pp, "  equiv classes:");
-  pp_newline (pp);
+  if (multiline)
+    pp_string (pp, "  ");
+  pp_string (pp, "equiv classes:");
+  if (multiline)
+    pp_newline (pp);
+  else
+    pp_string (pp, " {");
   int i;
   equiv_class2 *ec;
   FOR_EACH_VEC_ELT (m_equiv_class2es, i, ec)
     {
-      pp_string (pp, "    ");
+      if (multiline)
+	pp_string (pp, "    ");
+      else if (i > 0)
+	pp_string (pp, ", ");
       equiv_class2_id (i).print (pp);
       pp_string (pp, ": ");
       ec->print (pp);
-      pp_newline (pp);
+      if (multiline)
+	pp_newline (pp);
     }
-  pp_string (pp, "  constraints:");
-  pp_newline (pp);
+  if (multiline)
+    pp_string (pp, "  ");
+  else
+    pp_string (pp, "}");
+  pp_string (pp, "constraints:");
+  if (multiline)
+    pp_newline (pp);
+  else
+    pp_string (pp, "{");
   constraint2 *c;
   FOR_EACH_VEC_ELT (m_constraints, i, c)
     {
-      pp_printf (pp, "    %i: ", i);
+      if (multiline)
+	pp_string (pp, "    ");
+      pp_printf (pp, "%i: ", i);
       c->print (pp, *this);
-      pp_newline (pp);
+      if (multiline)
+	pp_newline (pp);
     }
+  if (!multiline)
+    pp_string (pp, "}");
 }
 
 /* Dump a multiline representation of this constraint_manager2 to FP.  */
@@ -613,7 +634,7 @@ constraint_manager2::dump (FILE *fp) const
   pp_format_decoder (&pp) = default_tree_printer;
   pp_show_color (&pp) = pp_show_color (global_dc->printer);
   pp.buffer->stream = fp;
-  dump_to_pp (&pp);
+  dump_to_pp (&pp, true);
   pp_flush (&pp);
 }
 
diff --git a/gcc/analyzer/constraint-manager2.h b/gcc/analyzer/constraint-manager2.h
index dc83d7c90e1..0e855dd3267 100644
--- a/gcc/analyzer/constraint-manager2.h
+++ b/gcc/analyzer/constraint-manager2.h
@@ -181,7 +181,7 @@ public:
   }
 
   void print (pretty_printer *pp) const;
-  void dump_to_pp (pretty_printer *pp) const;
+  void dump_to_pp (pretty_printer *pp, bool multiline) const;
   void dump (FILE *fp) const;
   void dump () const;
 
diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index e18f3dbb6f6..cec8dcf945b 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -1185,7 +1185,7 @@ exploded_node::dump_dot (graphviz_out *gv, const dump_args_t &args) const
 
   const extrinsic_state &ext_state = args.m_eg.get_ext_state ();
   const program_state &state = m_ps.get_state ();
-  state.dump_to_pp (ext_state, true, pp);
+  state.dump_to_pp (ext_state, true, false, pp);
   pp_newline (pp);
 
   {
@@ -1243,7 +1243,7 @@ exploded_node::dump_to_pp (pretty_printer *pp,
   m_ps.get_point ().print (pp, f);
   pp_newline (pp);
 
-  m_ps.get_state ().dump_to_pp (ext_state, false, pp);
+  m_ps.get_state ().dump_to_pp (ext_state, false, true, pp);
   pp_newline (pp);
 }
 
@@ -2385,7 +2385,7 @@ exploded_graph::get_or_create_node (const program_point &point,
       logger->end_log_line ();
       logger->start_log_line ();
       pp_string (pp, "state: ");
-      state.dump_to_pp (m_ext_state, true, pp);
+      state.dump_to_pp (m_ext_state, true, false, pp);
       logger->end_log_line ();
     }
 
@@ -2417,7 +2417,7 @@ exploded_graph::get_or_create_node (const program_point &point,
       pretty_printer *pp = logger->get_printer ();
       logger->start_log_line ();
       pp_string (pp, "pruned_state: ");
-      pruned_state.dump_to_pp (m_ext_state, true, pp);
+      pruned_state.dump_to_pp (m_ext_state, true, false, pp);
       logger->end_log_line ();
       if (pruned_state.m_region_model)
 	pruned_state.m_region_model->dump_to_pp (logger->get_printer (), true);
@@ -2535,7 +2535,7 @@ exploded_graph::get_or_create_node (const program_point &point,
       logger->end_log_line ();
       logger->start_log_line ();
       pp_string (pp, "pruned_state: ");
-      pruned_state.dump_to_pp (m_ext_state, true, pp);
+      pruned_state.dump_to_pp (m_ext_state, true, false, pp);
       logger->end_log_line ();
     }
 
@@ -2949,7 +2949,7 @@ exploded_graph::process_node (exploded_node *node)
       pp_string (pp, "point: ");
       point.print (pp, format (false));
       pp_string (pp, ", state: ");
-      state.dump_to_pp (m_ext_state, true, pp);
+      state.dump_to_pp (m_ext_state, true, false, pp);
       logger->end_log_line ();
     }
 
@@ -3084,7 +3084,7 @@ exploded_graph::process_node (exploded_node *node)
 		    logger->log_partial
 		      ("would create function summary for %qE; state: ",
 		       point.get_fndecl ());
-		    state.dump_to_pp (m_ext_state, true, pp);
+		    state.dump_to_pp (m_ext_state, true, false, pp);
 		    logger->end_log_line ();
 		  }
 		per_function_data *per_fn_data
@@ -3316,7 +3316,7 @@ exploded_graph::dump_states_for_supernode (FILE *out,
 	{
 	  pretty_printer pp;
 	  pp_format_decoder (&pp) = default_tree_printer;
-	  enode->get_state ().dump_to_pp (m_ext_state, true, &pp);
+	  enode->get_state ().dump_to_pp (m_ext_state, true, false, &pp);
 	  fprintf (out, "state %i: EN: %i\n  %s\n",
 		   state_idx++, enode->m_index,
 		   pp_formatted_text (&pp));
@@ -3773,7 +3773,7 @@ class enode_label : public range_label
   {
     pretty_printer pp;
     pp_format_decoder (&pp) = default_tree_printer;
-    m_enode->get_state ().dump_to_pp (m_ext_state, true, &pp);
+    m_enode->get_state ().dump_to_pp (m_ext_state, true, false, &pp);
     return make_label_text (false, "EN: %i: %s",
 			    m_enode->m_index, pp_formatted_text (&pp));
   }
@@ -3860,7 +3860,7 @@ exploded_graph::dump_exploded_nodes () const
 	  pretty_printer pp;
 	  enode->get_point ().print (&pp, format (true));
 	  fprintf (outf, "%s\n", pp_formatted_text (&pp));
-	  enode->get_state ().dump_to_file (m_ext_state, false, outf);
+	  enode->get_state ().dump_to_file (m_ext_state, false, true, outf);
 	}
 
       fclose (outf);
@@ -3887,7 +3887,7 @@ exploded_graph::dump_exploded_nodes () const
 	  pretty_printer pp;
 	  enode->get_point ().print (&pp, format (true));
 	  fprintf (outf, "%s\n", pp_formatted_text (&pp));
-	  enode->get_state ().dump_to_file (m_ext_state, false, outf);
+	  enode->get_state ().dump_to_file (m_ext_state, false, true, outf);
 
 	  fclose (outf);
 	}
diff --git a/gcc/analyzer/program-state.cc b/gcc/analyzer/program-state.cc
index c16bdcaab0a..a2e9e3b7063 100644
--- a/gcc/analyzer/program-state.cc
+++ b/gcc/analyzer/program-state.cc
@@ -632,6 +632,8 @@ sm_state_map2::print (const state_machine &sm, const region_model2 *model,
 	pp_string (pp, ", ");
       first = false;
       const svalue2 *sval = (*iter).first;
+      pp_pointer (pp, sval);
+      pp_string (pp, ": ");
       sval->dump_to_pp (pp, false);
 
       entry_t e = (*iter).second;
@@ -648,6 +650,8 @@ sm_state_map2::print (const state_machine &sm, const region_model2 *model,
       if (e.m_origin)
 	{
 	  pp_string (pp, " (origin: ");
+	  pp_pointer (pp, e.m_origin);
+	  pp_string (pp, ": ");
 	  e.m_origin->dump_to_pp (pp, false);
 #if 0
 	  if (model)
@@ -1250,24 +1254,39 @@ program_state::print (const extrinsic_state &ext_state,
     }
 }
 
+// FIXME:
 /* Dump a representation of this state to PP.
    If SUMMARIZE is true, print a one-line summary;
    if false, print a detailed multiline representation.  */
 
 void
 program_state::dump_to_pp (const extrinsic_state &ext_state,
-			   bool summarize,
+			   bool simple, bool multiline,
 			   pretty_printer *pp) const
 {
+  if (!multiline)
+    pp_string (pp, "{");
   if (m_region_model)
     {
-      pp_printf (pp, "rmodel: ");
-      m_region_model->dump_to_pp (pp, summarize);
+      pp_printf (pp, "rmodel:");
+      if (multiline)
+	pp_newline (pp);
+      else
+	pp_string (pp, " {");
+      m_region_model->dump_to_pp (pp, simple);
+      if (!multiline)
+	pp_string (pp, "}");
     }
   if (m_region_model2)
     {
-      pp_printf (pp, "rmodel2: ");
-      m_region_model2->dump_to_pp (pp, summarize);
+      pp_printf (pp, "rmodel2:");
+      if (multiline)
+	pp_newline (pp);
+      else
+	pp_string (pp, " {");
+      m_region_model2->dump_to_pp (pp, simple, multiline);
+      if (!multiline)
+	pp_string (pp, "}");
     }
 
   int i;
@@ -1276,11 +1295,11 @@ program_state::dump_to_pp (const extrinsic_state &ext_state,
     {
       if (!smap->is_empty_p ())
 	{
-	  if (summarize)
+	  if (!multiline)
 	    pp_space (pp);
 	  pp_printf (pp, "%s: ", ext_state.get_name (i));
 	  smap->print (ext_state.get_sm (i), m_region_model, pp);
-	  if (!summarize)
+	  if (multiline)
 	    pp_newline (pp);
 	}
     }
@@ -1289,30 +1308,34 @@ program_state::dump_to_pp (const extrinsic_state &ext_state,
     {
       if (!smap2->is_empty_p ())
 	{
-	  if (summarize)
-	    pp_space (pp);
+	  if (!multiline)
+	    pp_string (pp, " {");
 	  pp_printf (pp, "%s: ", ext_state.get_name (i));
 	  smap2->print (ext_state.get_sm (i), m_region_model2, pp);
-	  if (!summarize)
+	  if (multiline)
 	    pp_newline (pp);
+	  else
+	    pp_string (pp, "}");
 	}
     }
 
   if (!m_valid)
     {
-      if (summarize)
+      if (!multiline)
 	pp_space (pp);
       pp_printf (pp, "invalid state");
-      if (!summarize)
+      if (multiline)
 	pp_newline (pp);
     }
+  if (!multiline)
+    pp_string (pp, "}");
 }
 
-/* Dump a multiline representation of this state to OUTF.  */
+/* Dump a representation of this state to OUTF.  */
 
 void
 program_state::dump_to_file (const extrinsic_state &ext_state,
-			     bool summarize,
+			     bool simple, bool multiline,
 			     FILE *outf) const
 {
   pretty_printer pp;
@@ -1320,7 +1343,7 @@ program_state::dump_to_file (const extrinsic_state &ext_state,
   if (outf == stderr)
     pp_show_color (&pp) = pp_show_color (global_dc->printer);
   pp.buffer->stream = outf;
-  dump_to_pp (ext_state, summarize, &pp);
+  dump_to_pp (ext_state, simple, multiline, &pp);
   pp_flush (&pp);
 }
 
@@ -1328,9 +1351,9 @@ program_state::dump_to_file (const extrinsic_state &ext_state,
 
 DEBUG_FUNCTION void
 program_state::dump (const extrinsic_state &ext_state,
-		     bool summarize) const
+		     bool simple) const
 {
-  dump_to_file (ext_state, summarize, stderr);
+  dump_to_file (ext_state, simple, true, stderr);
 }
 
 /* FIXME.  */
@@ -2104,7 +2127,7 @@ assert_dump_eq (const location &loc,
   auto_fix_quotes sentinel;
   pretty_printer pp;
   pp_format_decoder (&pp) = default_tree_printer;
-  state.dump_to_pp (ext_state, summarize, &pp);
+  state.dump_to_pp (ext_state, summarize, !summarize, &pp);
   ASSERT_STREQ_AT (loc, pp_formatted_text (&pp), expected);
 }
 
diff --git a/gcc/analyzer/program-state.h b/gcc/analyzer/program-state.h
index 00023293a74..3338a24d680 100644
--- a/gcc/analyzer/program-state.h
+++ b/gcc/analyzer/program-state.h
@@ -361,11 +361,11 @@ public:
   void print (const extrinsic_state &ext_state,
 	      pretty_printer *pp) const;
 
-  void dump_to_pp (const extrinsic_state &ext_state, bool summarize,
-		   pretty_printer *pp) const;
-  void dump_to_file (const extrinsic_state &ext_state, bool summarize,
-		     FILE *outf) const;
-  void dump (const extrinsic_state &ext_state, bool summarize) const;
+  void dump_to_pp (const extrinsic_state &ext_state, bool simple,
+		   bool multiline, pretty_printer *pp) const;
+  void dump_to_file (const extrinsic_state &ext_state, bool simple,
+		     bool multiline, FILE *outf) const;
+  void dump (const extrinsic_state &ext_state, bool simple) const;
   json::value *to_json () const;
 
   void push_frame (const extrinsic_state &ext_state, function *fun);
diff --git a/gcc/analyzer/region-model2.cc b/gcc/analyzer/region-model2.cc
index 19856d4288b..8431c4a09be 100644
--- a/gcc/analyzer/region-model2.cc
+++ b/gcc/analyzer/region-model2.cc
@@ -3353,36 +3353,57 @@ region_model2::dump_dot (const char *path) const
 
 
 // FIXME:
-/* Dump a multiline representation of this model to PP, showing the
+/* Dump a representation of this model to PP, showing the
    region2 hierarchy, the svalue2s, and any constraints.
 
-   If SUMMARIZE is true, show only the most pertinent information,
+   If SIMPLE is true, show only the most pertinent information,
    in a form that attempts to be less verbose.
-   Otherwise, show all information.  */
+   Otherwise, show all information.
+
+   If MULTILINE... FIXME.  */
 
 void
-region_model2::dump_to_pp (pretty_printer *pp, bool summarize) const
+region_model2::dump_to_pp (pretty_printer *pp, bool simple,
+			   bool multiline) const
 {
 #if 1
   /* Dump stack.  */
   pp_printf (pp, "stack depth: %i", get_stack_depth ());
-  pp_newline (pp);
+  if (multiline)
+    pp_newline (pp);
+  else
+    pp_string (pp, " {");
   for (const frame_region2 *iter_frame = m_current_frame; iter_frame;
        iter_frame = iter_frame->get_calling_frame ())
     {
-      pp_printf (pp, "  frame (index %i): ", iter_frame->get_index ());
-      iter_frame->dump_to_pp (pp, summarize);
-      pp_newline (pp);
+      if (multiline)
+	pp_string (pp, "  ");
+      else if (iter_frame != m_current_frame)
+	pp_string (pp, ", ");
+      pp_printf (pp, "frame (index %i): ", iter_frame->get_index ());
+      iter_frame->dump_to_pp (pp, simple);
+      if (multiline)
+	pp_newline (pp);
     }
+  if (!multiline)
+    pp_string (pp, "}");
 
   /* Dump store.  */
-  m_store.dump_to_pp (pp, summarize, true); // FIXME
+  if (!multiline)
+    pp_string (pp, ", {");
+  m_store.dump_to_pp (pp, simple, multiline);
+  if (!multiline)
+    pp_string (pp, "}");
 
   /* Dump constraints.  */
   pp_string (pp, "constraint_manager2:");
-  pp_newline (pp);
-  m_constraints2->dump_to_pp (pp);
-
+  if (multiline)
+    pp_newline (pp);
+  else
+    pp_string (pp, " {");
+  m_constraints2->dump_to_pp (pp, multiline);
+  if (!multiline)
+    pp_string (pp, "}");
 #else
   for (store_map_t::iterator iter = m_store_map.begin ();
        iter != m_store_map.end (); ++iter)
@@ -3485,16 +3506,16 @@ region_model2::dump_to_pp (pretty_printer *pp, bool summarize) const
 #endif
 }
 
-/* Dump a multiline representation of this model to FILE.  */
+/* Dump a representation of this model to FILE.  */
 
 void
-region_model2::dump (FILE *fp, bool summarize) const
+region_model2::dump (FILE *fp, bool simple, bool multiline) const
 {
   pretty_printer pp;
   pp_format_decoder (&pp) = default_tree_printer;
   pp_show_color (&pp) = pp_show_color (global_dc->printer);
   pp.buffer->stream = fp;
-  dump_to_pp (&pp, summarize);
+  dump_to_pp (&pp, simple, multiline);
   pp_newline (&pp);
   pp_flush (&pp);
 }
@@ -3502,9 +3523,9 @@ region_model2::dump (FILE *fp, bool summarize) const
 /* Dump a multiline representation of this model to stderr.  */
 
 DEBUG_FUNCTION void
-region_model2::dump (bool summarize) const
+region_model2::dump (bool simple) const
 {
-  dump (stderr, summarize);
+  dump (stderr, simple, true);
 }
 
 /* Dump RMODEL fully to stderr (i.e. without summarization).  */
@@ -7371,7 +7392,7 @@ assert_dump_eq (const location &loc,
   pretty_printer pp;
   pp_format_decoder (&pp) = default_tree_printer;
 
-  model.dump_to_pp (&pp, summarize);
+  model.dump_to_pp (&pp, summarize, true);
   ASSERT_STREQ_AT (loc, pp_formatted_text (&pp), expected);
 }
 
diff --git a/gcc/analyzer/region-model2.h b/gcc/analyzer/region-model2.h
index 560ffa46d4f..b6f75090a10 100644
--- a/gcc/analyzer/region-model2.h
+++ b/gcc/analyzer/region-model2.h
@@ -1771,9 +1771,9 @@ class region_model2
   void dump_dot_to_file (FILE *fp) const;
   void dump_dot (const char *path) const;
 
-  void dump_to_pp (pretty_printer *pp, bool summarize) const;
-  void dump (FILE *fp, bool summarize) const;
-  void dump (bool summarize) const;
+  void dump_to_pp (pretty_printer *pp, bool simple, bool multiline) const;
+  void dump (FILE *fp, bool simple, bool multiline) const;
+  void dump (bool simple) const;
 
   void debug () const;
 
diff --git a/gcc/analyzer/store2.cc b/gcc/analyzer/store2.cc
index 7a9e7fdd136..80cae2935bb 100644
--- a/gcc/analyzer/store2.cc
+++ b/gcc/analyzer/store2.cc
@@ -508,7 +508,10 @@ store2::dump_to_pp (pretty_printer *pp, bool summarize, bool multiline) const
       gcc_assert (parent_reg);
       pp_string (pp, "clusters within ");
       parent_reg->dump_to_pp (pp, summarize);
-      pp_newline (pp);
+      if (multiline)
+	pp_newline (pp);
+      else
+	pp_string (pp, " {");
 
       const region2 *base_reg;
       unsigned j;
@@ -537,6 +540,8 @@ store2::dump_to_pp (pretty_printer *pp, bool summarize, bool multiline) const
 	      pp_string (pp, "}");
 	    }
 	}
+      if (!multiline)
+	pp_string (pp, "}");
     }
 }
 
-- 
2.26.2

