]> git.saurik.com Git - bison.git/commitdiff
Warn about dubious constructions like "%token T T".
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 3 Jan 2006 21:31:57 +0000 (21:31 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 3 Jan 2006 21:31:57 +0000 (21:31 +0000)
* src/symtab.h (struct symbol.declared): New member.
* src/symtab.c (symbol_new): Initialize it to false.
(symbol_class_set): New arg DECLARING, specifying whether
this is a declaration that we want to warn about, if there
is more than one of them.  All uses changed.

ChangeLog
src/parse-gram.y
src/scan-gram.l
src/symtab.c
src/symtab.h

index 337397c13d02d71b79030d5dc801689493d20a77..f9907482af54a3fee973ed210e4fedd4e0430e47 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2006-01-03  Paul Eggert  <eggert@cs.ucla.edu>
 
 2006-01-03  Paul Eggert  <eggert@cs.ucla.edu>
 
+       Warn about dubious constructions like "%token T T".
+       Reported by twlevo.
+       * src/symtab.h (struct symbol.declared): New member.
+       * src/symtab.c (symbol_new): Initialize it to false.
+       (symbol_class_set): New arg DECLARING, specifying whether
+       this is a declaration that we want to warn about, if there
+       is more than one of them.  All uses changed.
+
        * data/glr.c, data/glr.cc, data/lalr1.cc, data/yacc.c:
        Allow multiple %union directives, whose contents concatenate.
        * src/parse-gram.y (grammar_declaration): Likewise.
        * data/glr.c, data/glr.cc, data/lalr1.cc, data/yacc.c:
        Allow multiple %union directives, whose contents concatenate.
        * src/parse-gram.y (grammar_declaration): Likewise.
index 1081f536adde340cfd3489073689f50bfcf00f70..71f4829e6c6c5cc6aca7248ce38131656555bde8 100644 (file)
@@ -1,6 +1,6 @@
 %{/* Bison Grammar Parser                             -*- C -*-
 
 %{/* Bison Grammar Parser                             -*- C -*-
 
-   Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -346,24 +346,24 @@ symbol_def:
      }
 | ID
      {
      }
 | ID
      {
-       symbol_class_set ($1, current_class, @1);
+       symbol_class_set ($1, current_class, @1, true);
        symbol_type_set ($1, current_type, @1);
      }
 | ID INT
     {
        symbol_type_set ($1, current_type, @1);
      }
 | ID INT
     {
-      symbol_class_set ($1, current_class, @1);
+      symbol_class_set ($1, current_class, @1, true);
       symbol_type_set ($1, current_type, @1);
       symbol_user_token_number_set ($1, $2, @2);
     }
 | ID string_as_id
     {
       symbol_type_set ($1, current_type, @1);
       symbol_user_token_number_set ($1, $2, @2);
     }
 | ID string_as_id
     {
-      symbol_class_set ($1, current_class, @1);
+      symbol_class_set ($1, current_class, @1, true);
       symbol_type_set ($1, current_type, @1);
       symbol_make_alias ($1, $2, @$);
     }
 | ID INT string_as_id
     {
       symbol_type_set ($1, current_type, @1);
       symbol_make_alias ($1, $2, @$);
     }
 | ID INT string_as_id
     {
-      symbol_class_set ($1, current_class, @1);
+      symbol_class_set ($1, current_class, @1, true);
       symbol_type_set ($1, current_type, @1);
       symbol_user_token_number_set ($1, $2, @2);
       symbol_make_alias ($1, $3, @$);
       symbol_type_set ($1, current_type, @1);
       symbol_user_token_number_set ($1, $2, @2);
       symbol_make_alias ($1, $3, @$);
@@ -441,7 +441,7 @@ string_as_id:
   STRING
     {
       $$ = symbol_get (quotearg_style (c_quoting_style, $1), @1);
   STRING
     {
       $$ = symbol_get (quotearg_style (c_quoting_style, $1), @1);
-      symbol_class_set ($$, token_sym, @1);
+      symbol_class_set ($$, token_sym, @1, false);
     }
 ;
 
     }
 ;
 
index cbb7b3de6d8b71e7e2a4f122af894e611c4c2bbf..718f297a3b97471bb971c003578defcd3d3059b4 100644 (file)
@@ -1,6 +1,6 @@
 /* Bison Grammar Scanner                             -*- C -*-
 
 /* Bison Grammar Scanner                             -*- C -*-
 
-   Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -420,7 +420,7 @@ splice       (\\[ \f\t\v]*\n)*
     val->symbol = symbol_get (quotearg_style (escape_quoting_style,
                                              last_string),
                              *loc);
     val->symbol = symbol_get (quotearg_style (escape_quoting_style,
                                              last_string),
                              *loc);
-    symbol_class_set (val->symbol, token_sym, *loc);
+    symbol_class_set (val->symbol, token_sym, *loc, false);
     last_string_1 = last_string[1];
     symbol_user_token_number_set (val->symbol, last_string_1, *loc);
     STRING_FREE;
     last_string_1 = last_string[1];
     symbol_user_token_number_set (val->symbol, last_string_1, *loc);
     STRING_FREE;
index bf231628a1da0f6bf603dae60a53699dca3d5062..1f2c17ee81ed7fc1a7dd4797568a6746cc523ecb 100644 (file)
@@ -1,7 +1,7 @@
 /* Symbol table manager for Bison.
 
 /* Symbol table manager for Bison.
 
-   Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004, 2005 Free Software
-   Foundation, Inc.
+   Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004, 2005, 2006 Free
+   Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -65,6 +65,7 @@ symbol_new (uniqstr tag, location loc)
 
   res->alias = NULL;
   res->class = unknown_sym;
 
   res->alias = NULL;
   res->class = unknown_sym;
+  res->declared = false;
 
   if (nsyms == SYMBOL_NUMBER_MAXIMUM)
     fatal (_("too many symbols in input grammar (limit is %d)"),
 
   if (nsyms == SYMBOL_NUMBER_MAXIMUM)
     fatal (_("too many symbols in input grammar (limit is %d)"),
@@ -182,7 +183,7 @@ symbol_precedence_set (symbol *sym, int prec, assoc a, location loc)
     }
 
   /* Only terminals have a precedence. */
     }
 
   /* Only terminals have a precedence. */
-  symbol_class_set (sym, token_sym, loc);
+  symbol_class_set (sym, token_sym, loc, false);
 }
 
 
 }
 
 
@@ -191,10 +192,13 @@ symbol_precedence_set (symbol *sym, int prec, assoc a, location loc)
 `------------------------------------*/
 
 void
 `------------------------------------*/
 
 void
-symbol_class_set (symbol *sym, symbol_class class, location loc)
+symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring)
 {
   if (sym->class != unknown_sym && sym->class != class)
 {
   if (sym->class != unknown_sym && sym->class != class)
-    complain_at (loc, _("symbol %s redefined"), sym->tag);
+    {
+      complain_at (loc, _("symbol %s redefined"), sym->tag);
+      sym->declared = false;
+    }
 
   if (class == nterm_sym && sym->class != nterm_sym)
     sym->number = nvars++;
 
   if (class == nterm_sym && sym->class != nterm_sym)
     sym->number = nvars++;
@@ -202,6 +206,13 @@ symbol_class_set (symbol *sym, symbol_class class, location loc)
     sym->number = ntokens++;
 
   sym->class = class;
     sym->number = ntokens++;
 
   sym->class = class;
+
+  if (declaring)
+    {
+      if (sym->declared)
+       warn_at (loc, _("symbol %s redeclared"), sym->tag);
+      sym->declared = true;
+    }
 }
 
 
 }
 
 
index 0f87c224fcb03144cf0bafda7aa6583482a5e730..0f852b7aa7dd9bb22d9aec905fa817c224de4d46 100644 (file)
@@ -1,6 +1,6 @@
 /* Definitions for symtab.c and callers, part of Bison.
 
 /* Definitions for symtab.c and callers, part of Bison.
 
-   Copyright (C) 1984, 1989, 1992, 2000, 2001, 2002, 2004, 2005
+   Copyright (C) 1984, 1989, 1992, 2000, 2001, 2002, 2004, 2005, 2006
    Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
    Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
@@ -79,6 +79,7 @@ struct symbol
      identifier-symbol pair for an alias.  */
   symbol *alias;
   symbol_class class;
      identifier-symbol pair for an alias.  */
   symbol *alias;
   symbol_class class;
+  bool declared;
 };
 
 /* Undefined user number.  */
 };
 
 /* Undefined user number.  */
@@ -121,7 +122,8 @@ void symbol_printer_set (symbol *sym, const char *printer, location loc);
 void symbol_precedence_set (symbol *sym, int prec, assoc a, location loc);
 
 /* Set the CLASS associated with SYM.  */
 void symbol_precedence_set (symbol *sym, int prec, assoc a, location loc);
 
 /* Set the CLASS associated with SYM.  */
-void symbol_class_set (symbol *sym, symbol_class class, location loc);
+void symbol_class_set (symbol *sym, symbol_class class, location loc,
+                      bool declaring);
 
 /* Set the USER_TOKEN_NUMBER associated with SYM.  */
 void symbol_user_token_number_set (symbol *sym, int user_number, location loc);
 
 /* Set the USER_TOKEN_NUMBER associated with SYM.  */
 void symbol_user_token_number_set (symbol *sym, int user_number, location loc);