bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

warn about unset midrule $$


From: Joel E. Denny
Subject: warn about unset midrule $$
Date: Fri, 20 Oct 2006 22:32:00 -0400 (EDT)

Bison warns about unused midrule $n:

  start: { $$ = 1; } {}

but not unset midrule $$:

  start: {} { $$ = $1; }

I recall that we did propose both warnings back when we discussed all 
this.  I don't recall why the second was never implemented.  I'm thinking 
it may have been too difficult giving the state of Bison at the time.  
That no longer seems to be the case, and I committed the following.

Index: ChangeLog
===================================================================
RCS file: /sources/bison/bison/ChangeLog,v
retrieving revision 1.1591
diff -p -u -r1.1591 ChangeLog
--- ChangeLog   20 Oct 2006 22:10:50 -0000      1.1591
+++ ChangeLog   21 Oct 2006 02:23:39 -0000
@@ -1,5 +1,18 @@
 2006-10-20  Joel E. Denny  <address@hidden>
 
+       Warn about unset midrule $$ if the corresponding $n is used.
+       * src/reader.c (symbol_should_be_used): Check midrule parent rule for
+       $n usage.
+       (packgram): Before invoking grammar_rule_check on any rule, make sure
+       all actions have already been scanned in order to set `used' flags.
+       Otherwise, checking that a midrule's $$ is set will not always work
+       properly because the midrule check must forward-reference the midrule's
+       parent rule.
+       * tests/input.at (AT_CHECK_UNUSED_VALUES): Extend to check the new
+       warning.
+
+2006-10-20  Joel E. Denny  <address@hidden>
+
        More improvements to the documentation of the prologue alternatives:
        * NEWS (2.3a+): Mention the new `Prologue Alternatives' section in the
        Bison manual.
Index: src/reader.c
===================================================================
RCS file: /sources/bison/bison/src/reader.c,v
retrieving revision 1.273
diff -p -u -r1.273 reader.c
--- src/reader.c        16 Oct 2006 05:25:36 -0000      1.273
+++ src/reader.c        21 Oct 2006 02:23:39 -0000
@@ -252,7 +252,10 @@ static bool
 symbol_should_be_used (symbol_list const *s)
 {
   return (symbol_destructor_get (s->content.sym)
-         || (s->midrule && s->midrule->used));
+         || (s->midrule && s->midrule->used)
+         || (s->midrule_parent_rule
+             && symbol_list_n_get (s->midrule_parent_rule,
+                                    s->midrule_parent_rhs_index)->used));
 }
 
 /*----------------------------------------------------------------.
@@ -456,6 +459,20 @@ packgram (void)
 
   rules = xnmalloc (nrules, sizeof *rules);
 
+  /* Before invoking grammar_rule_check on any rule, make sure
+     all actions have already been scanned in order to set `used' flags.
+     Otherwise, checking that a midrule's $$ is set will not always work
+     properly because the midrule check must forward-reference the midrule's
+     parent rule.  */
+  while (p)
+    {
+      if (p->action)
+        p->action = translate_rule_action (p);
+      if (p)
+       p = p->next;
+    }
+
+  p = grammar;
   while (p)
     {
       int rule_length = 0;
@@ -472,14 +489,9 @@ packgram (void)
       rules[ruleno].precsym = NULL;
       rules[ruleno].location = p->location;
       rules[ruleno].useful = true;
-      rules[ruleno].action = p->action ? translate_rule_action (p) : NULL;
+      rules[ruleno].action = p->action;
       rules[ruleno].action_location = p->action_location;
 
-      /* If this rule contains midrules, rest assured that
-        grammar_midrule_action inserted the midrules into grammar before this
-        rule.  Thus, the midrule actions have already been scanned in order to
-        set `used' flags for this rule's rhs, so grammar_rule_check will work
-        properly.  */
       /* Don't check the generated rule 0.  It has no action, so some rhs
         symbols may appear unused, but the parsing algorithm ensures that
         %destructor's are invoked appropriately.  */
Index: tests/input.at
===================================================================
RCS file: /sources/bison/bison/tests/input.at,v
retrieving revision 1.58
diff -p -u -r1.58 input.at
--- tests/input.at      15 Oct 2006 00:02:21 -0000      1.58
+++ tests/input.at      21 Oct 2006 02:23:39 -0000
@@ -103,8 +103,8 @@ start:
 
 a: INT | INT { } INT { } INT { };
 b: INT | /* empty */;
-c: INT | INT { $]1[ } INT { } INT { };
-d: INT | INT { } INT { $]1[ } INT { };
+c: INT | INT { $]1[ } INT { $<integer>2 } INT { $<integer>4 };
+d: INT | INT { } INT { $]1[ } INT { $<integer>2 };
 e: INT | INT { } INT {  } INT { $]1[ };
 f: INT | INT { } INT {  } INT { $]$[ = $]1[ + $]3[ + $]5[; };
 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
@@ -122,12 +122,15 @@ input.y:11.10-32: warning: unused value:
 input.y:11.10-32: warning: unused value: $]3[
 input.y:11.10-32: warning: unused value: $]5[
 input.y:12.9: warning: empty rule for typed nonterminal, and no action
-input.y:13.10-35: warning: unset value: $]$[
-input.y:13.10-35: warning: unused value: $]3[
-input.y:13.10-35: warning: unused value: $]5[
-input.y:14.10-35: warning: unset value: $]$[
-input.y:14.10-35: warning: unused value: $]3[
-input.y:14.10-35: warning: unused value: $]5[
+input.y:13.14-19: warning: unset value: $$
+input.y:13.25-39: warning: unset value: $$
+input.y:13.10-59: warning: unset value: $]$[
+input.y:13.10-59: warning: unused value: $]3[
+input.y:13.10-59: warning: unused value: $]5[
+input.y:14.14-16: warning: unset value: $$
+input.y:14.10-47: warning: unset value: $]$[
+input.y:14.10-47: warning: unused value: $]3[
+input.y:14.10-47: warning: unused value: $]5[
 input.y:15.10-36: warning: unset value: $]$[
 input.y:15.10-36: warning: unused value: $]3[
 input.y:15.10-36: warning: unused value: $]5[




reply via email to

[Prev in Thread] Current Thread [Next in Thread]