bug-bison
[Top][All Lists]
Advanced

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

Re: %destructor feedback


From: Akim Demaille
Subject: Re: %destructor feedback
Date: Tue, 03 Jan 2006 17:10:25 +0100
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux)

>>> "Joel" == Joel E Denny <address@hidden> writes:

 > If I read that right, the effect of your algorithm is close to the 
 > following:

 > 1. $n for a RHS symbol is considered typed if declared so with, for 
 > example, %type.

 > 2. $n for the return of a mid-rule is considered typed if that mid-rule 
 > references $$.

 > 3. A warning is issued for any typed $n not referenced anywhere among the 
 > rules appearing to the right of it.

 > 4. $$ in the final rule is considered typed if the LHS symbol is declared 
 > so with, for example, %type.

 > 5. $$ in a mid-rule is considered typed if its corresponding $n is 
 > referenced anywhere among the rules appearing to the right of it.

 > 6. A warning is issued for any unreferenced typed $$.

 > This makes sense to me.  However, I'd be satisfied with just 1, 3, 4, and 
 > 6.

Same here: I would have liked the first algorithm, but the current
implementation (rules are in a linked list of symbols, not even of
rules) makes it hard to consult the previous (mid-)rules.  So I
installed the following which finishes to implementation the smaller
version.

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * src/reader.c (grammar_midrule_action): If $$ is set in a
        mid-rule, move the `used' bit to its lhs.
        * tests/input.at (Unused values): New.
        * tests/actions.at (Exotic Dollars): Adjust: exp is not typed.

Index: src/reader.c
===================================================================
RCS file: /cvsroot/bison/bison/src/reader.c,v
retrieving revision 1.244
diff -u -u -r1.244 reader.c
--- src/reader.c 28 Dec 2005 08:31:22 -0000 1.244
+++ src/reader.c 3 Jan 2006 16:08:14 -0000
@@ -1,7 +1,7 @@
 /* Input parser for Bison
 
    Copyright (C) 1984, 1986, 1989, 1992, 1998, 2000, 2001, 2002, 2003,
-   2005 Free Software Foundation, Inc.
+   2005, 2006 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -307,6 +307,10 @@
   midrule->action = current_rule->action;
   midrule->action_location = dummy_location;
   current_rule->action = NULL;
+  /* If $$ was used in the action, the LHS of the enclosing rule was
+     incorrectly flagged as used.  */
+  midrule->used = current_rule->used;
+  current_rule->used = false;
 
   if (previous_rule_end)
     previous_rule_end->next = midrule;
Index: src/symlist.c
===================================================================
RCS file: /cvsroot/bison/bison/src/symlist.c,v
retrieving revision 1.14
diff -u -u -r1.14 symlist.c
--- src/symlist.c 22 Dec 2005 11:40:05 -0000 1.14
+++ src/symlist.c 3 Jan 2006 16:08:14 -0000
@@ -56,11 +56,12 @@
 `------------------*/
 
 void
-symbol_list_print (symbol_list *l, FILE *f)
+symbol_list_print (const symbol_list *l, FILE *f)
 {
   for (/* Nothing. */; l && l->sym; l = l->next)
     {
       symbol_print (l->sym, f);
+      fprintf (stderr, l->used ? " used" : " unused");
       if (l && l->sym)
        fprintf (f, ", ");
     }
@@ -96,7 +97,7 @@
 `--------------------*/
 
 unsigned int
-symbol_list_length (symbol_list *l)
+symbol_list_length (const symbol_list *l)
 {
   int res = 0;
   for (/* Nothing. */; l; l = l->next)
Index: src/symlist.h
===================================================================
RCS file: /cvsroot/bison/bison/src/symlist.h,v
retrieving revision 1.11
diff -u -u -r1.11 symlist.h
--- src/symlist.h 22 Dec 2005 11:40:05 -0000 1.11
+++ src/symlist.h 3 Jan 2006 16:08:14 -0000
@@ -53,7 +53,7 @@
 symbol_list *symbol_list_new (symbol *sym, location loc);
 
 /* Print it.  */
-void symbol_list_print (symbol_list *l, FILE *f);
+void symbol_list_print (const symbol_list *l, FILE *f);
 
 /* Prepend SYM at LOC to the LIST.  */
 symbol_list *symbol_list_prepend (symbol_list *l,
@@ -64,7 +64,7 @@
 void symbol_list_free (symbol_list *l);
 
 /* Return its length. */
-unsigned int symbol_list_length (symbol_list *l);
+unsigned int symbol_list_length (const symbol_list *l);
 
 /* Get symbol N in symbol list L.  */
 symbol_list *symbol_list_n_get (symbol_list *l, int n);
Index: tests/actions.at
===================================================================
RCS file: /cvsroot/bison/bison/tests/actions.at,v
retrieving revision 1.56
diff -u -u -r1.56 actions.at
--- tests/actions.at 27 Dec 2005 17:50:00 -0000 1.56
+++ tests/actions.at 3 Jan 2006 16:08:14 -0000
@@ -1,5 +1,5 @@
 # Executing Actions.                               -*- Autotest -*-
-# Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, 
Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -107,7 +107,7 @@
 };
 
 %type <val> a_1 a_2 a_5
-            exp sum_of_the_five_previous_values
+            sum_of_the_five_previous_values
 
 %%
 exp: a_1 a_2 { $<val>$ = 3; } { $<val>$ = $<val>3 + 1; } a_5
@@ -146,7 +146,7 @@
 }
 ]])
 
-AT_CHECK([bison -d -v -o input.c input.y], 0, [], 
+AT_CHECK([bison -d -v -o input.c input.y], 0, [],
 [input.y:30.6-34.5: warning: unused value: $1
 input.y:30.6-34.5: warning: unused value: $2
 input.y:30.6-34.5: warning: unused value: $5
Index: tests/input.at
===================================================================
RCS file: /cvsroot/bison/bison/tests/input.at,v
retrieving revision 1.36
diff -u -u -r1.36 input.at
--- tests/input.at 12 Oct 2005 10:15:12 -0000 1.36
+++ tests/input.at 3 Jan 2006 16:08:14 -0000
@@ -1,5 +1,5 @@
 # Checking the Bison scanner.                    -*- Autotest -*-
-# Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+# Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -82,6 +82,57 @@
 AT_CLEANUP
 
 
+## --------------- ##
+## Unused values.  ##
+## --------------- ##
+
+AT_SETUP([Unused values])
+
+AT_DATA([input.y],
+[[%token <integer> INT
+%type <integer> exp
+%%
+exp:
+  INT { } INT { } INT { }
+/* Ideally we would like to complain also about $2 and $4 here, but
+   it's hard to implement.  */
+| INT { $$ } INT { $$ } INT { }
+| INT { $1 } INT { } INT { }
+| INT { } INT { $1 } INT { }
+| INT { } INT {  } INT { $1 }
+| INT { } INT {  } INT { $$ = $1 + $3 + $5; }
+;
+]])
+
+AT_CHECK([bison input.y], [], [],
+[[input.y:5.3-25: warning: unset value: $$
+input.y:5.3-25: warning: unused value: $1
+input.y:5.3-25: warning: unused value: $3
+input.y:5.3-25: warning: unused value: $5
+input.y:8.3-31: warning: unset value: $$
+input.y:8.3-31: warning: unused value: $1
+input.y:8.3-31: warning: unused value: $3
+input.y:8.3-31: warning: unused value: $5
+input.y:9.3-28: warning: unset value: $$
+input.y:9.3-28: warning: unused value: $3
+input.y:9.3-28: warning: unused value: $5
+input.y:10.3-28: warning: unset value: $$
+input.y:10.3-28: warning: unused value: $3
+input.y:10.3-28: warning: unused value: $5
+input.y:11.3-29: warning: unset value: $$
+input.y:11.3-29: warning: unused value: $3
+input.y:11.3-29: warning: unused value: $5
+input.y: conflicts: 1 reduce/reduce
+input.y:8.7-12: warning: rule never reduced because of conflicts: @3: /* empty 
*/
+input.y:9.7-12: warning: rule never reduced because of conflicts: @5: /* empty 
*/
+input.y:10.7-9: warning: rule never reduced because of conflicts: @7: /* empty 
*/
+input.y:11.7-9: warning: rule never reduced because of conflicts: @9: /* empty 
*/
+input.y:12.7-9: warning: rule never reduced because of conflicts: @11: /* 
empty */
+]])
+
+AT_CLEANUP
+
+
 ## ---------------------- ##
 ## Incompatible Aliases.  ##
 ## ---------------------- ##






reply via email to

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