[PATCH 3/8] cex: make sure traces go to stderr

Akim Demaille <[email protected]>
Newsgroups gmane.comp.parsers.bison.patches
Message-ID <[email protected]>
* src/parse-simulation.h, src/parse-simulation.c (print_parse_state):
here.
---
 src/counterexample.c   |  1 +
 src/parse-simulation.c | 17 +++++++++--------
 src/parse-simulation.h |  1 +
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/counterexample.c b/src/counterexample.c
index 47ff53e5..2668e621 100644
--- a/src/counterexample.c
+++ b/src/counterexample.c
@@ -561,6 +561,7 @@ search_state_free (search_state *ss)
   free (ss);
 }
 
+/* For debugging traces.  */
 static void
 search_state_print (search_state *ss)
 {
diff --git a/src/parse-simulation.c b/src/parse-simulation.c
index e439360d..098e4e70 100644
--- a/src/parse-simulation.c
+++ b/src/parse-simulation.c
@@ -572,7 +572,7 @@ simulate_reduction (parse_state *ps, int rule_len, bitset symbol_set)
 gl_list_t
 parser_prepend (parse_state *ps)
 {
-  gl_list_t result = parse_state_list_new ();
+  gl_list_t res = parse_state_list_new ();
   const state_item *head = ps->state_items.head_elt;
   symbol_number prepend_sym =
     item_number_as_symbol_number (*(head->item - 1));
@@ -584,19 +584,20 @@ parser_prepend (parse_state *ps)
     ps_si_prepend (copy, state_items + sin);
     if (SI_TRANSITION (head))
       ps_derivs_prepend (copy, derivation_new_leaf (prepend_sym));
-    parse_state_list_append (result, copy);
+    parse_state_list_append (res, copy);
   }
-  return result;
+  return res;
 }
 
 void
 print_parse_state (parse_state *ps)
 {
-  printf ("(size %zu depth %d rc %d)\n",
+  FILE *out = stderr;
+  fprintf (out, "(size %zu depth %d rc %d)\n",
           ps->state_items.total_size, ps->depth, ps->reference_count);
-  print_state_item (ps->state_items.head_elt, stdout);
-  print_state_item (ps->state_items.tail_elt, stdout);
+  print_state_item (ps->state_items.head_elt, out);
+  print_state_item (ps->state_items.tail_elt, out);
   if (ps->derivs.total_size > 0)
-    derivation_print (ps->derivs.head_elt, stdout);
-  putc ('\n', stdout);
+    derivation_print (ps->derivs.head_elt, out);
+  putc ('\n', out);
 }
diff --git a/src/parse-simulation.h b/src/parse-simulation.h
index 2e49d769..ff759e37 100644
--- a/src/parse-simulation.h
+++ b/src/parse-simulation.h
@@ -140,6 +140,7 @@ parse_state_list simulate_reduction (parse_state *ps, int rule_len,
  * transition or production step to ps's head. */
 parse_state_list parser_prepend (parse_state *ps);
 
+/* For debugging traces.  */
 void print_parse_state (parse_state *ps);
 
 #endif /* PARSE_SIMULATION_H */
-- 
2.27.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.