From 43168960182a2537605d6a1262a39e4e43c57d98 Mon Sep 17 00:00:00 2001
From: Akim Demaille <akim@epita.fr>
Date: Wed, 5 Dec 2001 09:41:15 +0000
Subject: [PATCH] New experimental feature: if --verbose --trace output all the
 items of a state, not only its kernel. * src/print.c (print_core): If
 `trace_flag', then invoke closure before outputting the items of the state
 (print_core is no longer a correct name them). (print_results): Invoke
 new_closure/free_closure if needed.

---
 ChangeLog   | 10 +++++++++
 src/print.c | 58 +++++++++++++++++++++++++++++++++++------------------
 2 files changed, 48 insertions(+), 20 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e70da665..752742b1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2001-12-05  Akim Demaille  <akim@epita.fr>
+
+	New experimental feature: if --verbose --trace output all the
+	items of a state, not only its kernel.
+
+	* src/print.c (print_core): If `trace_flag', then invoke closure
+	before outputting the items of the state (print_core is no longer
+	a correct name them).
+	(print_results): Invoke new_closure/free_closure if needed.
+
 2001-12-05  Akim Demaille  <akim@epita.fr>
 
 	* src/LR0.c (new_itemsets): Use nshifts only, not shiftcount.
diff --git a/src/print.c b/src/print.c
index 426ca9ae..025c179f 100644
--- a/src/print.c
+++ b/src/print.c
@@ -30,6 +30,7 @@
 #include "reader.h"
 #include "print.h"
 #include "reduce.h"
+#include "closure.h"
 
 #if 0
 static void
@@ -48,38 +49,48 @@ static void
 print_core (FILE *out, int state)
 {
   int i;
-  core *statep = state_table[state].state;
+  short *sitems = state_table[state].state->items;
+  int snitems   = state_table[state].state->nitems;
 
-  if (!statep->nitems)
-    return;
+  /* New experimental feature: if TRACE_FLAGS output all the items of
+     a state, not only its kernel.  */
+  if (trace_flag)
+    {
+      closure (sitems, snitems);
+      sitems = itemset;
+      snitems = nitemset;
+    }
 
-  for (i = 0; i < statep->nitems; i++)
+  if (snitems)
     {
-      short *sp;
-      short *sp1;
-      int rule;
+      for (i = 0; i < snitems; i++)
+	{
+	  short *sp;
+	  short *sp1;
+	  int rule;
 
-      sp1 = sp = ritem + statep->items[i];
+	  sp1 = sp = ritem + sitems[i];
 
-      while (*sp > 0)
-	sp++;
+	  while (*sp > 0)
+	    sp++;
 
-      rule = -(*sp);
-      fprintf (out, "    %s  ->  ", tags[rule_table[rule].lhs]);
+	  rule = -(*sp);
+	  fprintf (out, "    %s  ->  ", tags[rule_table[rule].lhs]);
 
-      for (sp = ritem + rule_table[rule].rhs; sp < sp1; sp++)
-	fprintf (out, "%s ", tags[*sp]);
+	  for (sp = ritem + rule_table[rule].rhs; sp < sp1; sp++)
+	    fprintf (out, "%s ", tags[*sp]);
 
-      fputc ('.', out);
+	  fputc ('.', out);
 
-      for (/* Nothing */; *sp > 0; ++sp)
-	fprintf (out, " %s", tags[*sp]);
+	  for (/* Nothing */; *sp > 0; ++sp)
+	    fprintf (out, " %s", tags[*sp]);
+
+	  fprintf (out, _("   (rule %d)"), rule);
+	  fputc ('\n', out);
+	}
 
-      fprintf (out, _("   (rule %d)"), rule);
       fputc ('\n', out);
     }
-
-  fputc ('\n', out);
 }
 
 static void
@@ -321,8 +332,15 @@ print_results (void)
 
       print_grammar (out);
 
+      /* New experimental feature: output all the items of a state,
+	 not only its kernel.  Requires to run closure, which need
+	 memory allocation/deallocation.  */
+      if (trace_flag)
+	new_closure (nitems);
       for (i = 0; i < nstates; i++)
 	print_state (out, i);
+      if (trace_flag)
+	free_closure ();
 
       xfclose (out);
     }
-- 
2.47.2