]> git.saurik.com Git - bison.git/blobdiff - src/symtab.c
Undo previous change, then add comment as to why the
[bison.git] / src / symtab.c
index 3bc01871ca9b036b5508367b2ff91679e5a83aea..1e0ec1cce9c96a68ab06ffff8c5304b961804dd3 100644 (file)
@@ -1,6 +1,6 @@
 /* Symbol table manager for Bison.
 
 /* Symbol table manager for Bison.
 
-   Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004 Free Software
+   Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004, 2005 Free Software
    Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
    Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
@@ -17,8 +17,8 @@
 
    You should have received a copy of the GNU General Public License
    along with Bison; see the file COPYING.  If not, write to
 
    You should have received a copy of the GNU General Public License
    along with Bison; see the file COPYING.  If not, write to
-   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.  */
 
 
 #include "system.h"
 
 
 #include "system.h"
@@ -48,7 +48,7 @@ location startsymbol_location;
 static symbol *
 symbol_new (uniqstr tag, location loc)
 {
 static symbol *
 symbol_new (uniqstr tag, location loc)
 {
-  symbol *res = MALLOC (res, 1);
+  symbol *res = xmalloc (sizeof *res);
 
   uniqstr_assert (tag);
   res->tag = tag;
 
   uniqstr_assert (tag);
   res->tag = tag;
@@ -66,11 +66,33 @@ symbol_new (uniqstr tag, location loc)
   res->alias = NULL;
   res->class = unknown_sym;
 
   res->alias = NULL;
   res->class = unknown_sym;
 
+  if (nsyms == SYMBOL_NUMBER_MAXIMUM)
+    fatal (_("too many symbols in input grammar (limit is %d)"),
+          SYMBOL_NUMBER_MAXIMUM);
   nsyms++;
   return res;
 }
 
 
   nsyms++;
   return res;
 }
 
 
+/*-----------------.
+| Print a symbol.  |
+`-----------------*/
+
+#define SYMBOL_ATTR_PRINT(Attr)                                \
+  if (s->Attr)                                         \
+    fprintf (f, " %s { %s }", #Attr, s->Attr)
+
+void
+symbol_print (symbol *s, FILE *f)
+{
+  fprintf (f, "\"%s\"", s->tag);
+  SYMBOL_ATTR_PRINT (type_name);
+  SYMBOL_ATTR_PRINT (destructor);
+  SYMBOL_ATTR_PRINT (printer);
+}
+
+#undef SYMBOL_ATTR_PRINT
+
 /*------------------------------------------------------------------.
 | Complain that S's WHAT is redeclared at SECOND, and was first set |
 | at FIRST.                                                         |
 /*------------------------------------------------------------------.
 | Complain that S's WHAT is redeclared at SECOND, and was first set |
 | at FIRST.                                                         |
@@ -261,6 +283,7 @@ symbol_make_alias (symbol *sym, symbol *symval, location loc)
        abort ();
       sym->number = symval->number =
        (symval->number < sym->number) ? symval->number : sym->number;
        abort ();
       sym->number = symval->number =
        (symval->number < sym->number) ? symval->number : sym->number;
+      symbol_type_set (symval, sym->type_name, loc);
     }
 }
 
     }
 }
 
@@ -280,7 +303,7 @@ symbol_check_alias_consistency (symbol *this)
   if (!(this->alias && this->user_token_number == USER_NUMBER_ALIAS))
     return;
 
   if (!(this->alias && this->user_token_number == USER_NUMBER_ALIAS))
     return;
 
-  if (orig->type_name || alias->type_name)
+  if (orig->type_name != alias->type_name)
     {
       if (orig->type_name)
        symbol_type_set (alias, orig->type_name, orig->type_location);
     {
       if (orig->type_name)
        symbol_type_set (alias, orig->type_name, orig->type_location);
@@ -471,8 +494,7 @@ symbol_get (const char *key, location loc)
   symbol probe;
   symbol *entry;
 
   symbol probe;
   symbol *entry;
 
-  /* Keep the symbol in a printable form.  */
-  key = uniqstr_new (quotearg_style (escape_quoting_style, key));
+  key = uniqstr_new (key);
   probe.tag = key;
   entry = hash_lookup (symbol_table, &probe);
 
   probe.tag = key;
   entry = hash_lookup (symbol_table, &probe);
 
@@ -587,7 +609,8 @@ symbols_token_translations_init (void)
        max_user_token_number = this->user_token_number;
     }
 
        max_user_token_number = this->user_token_number;
     }
 
-  CALLOC (token_translations, max_user_token_number + 1);
+  token_translations = xnmalloc (max_user_token_number + 1,
+                                sizeof *token_translations);
 
   /* Initialize all entries for literal tokens to 2, the internal
      token number for $undefined, which represents all invalid inputs.
 
   /* Initialize all entries for literal tokens to 2, the internal
      token number for $undefined, which represents all invalid inputs.
@@ -606,7 +629,7 @@ symbols_token_translations_init (void)
 void
 symbols_pack (void)
 {
 void
 symbols_pack (void)
 {
-  CALLOC (symbols, nsyms);
+  symbols = xcalloc (nsyms, sizeof *symbols);
 
   symbols_do (symbol_check_alias_consistency_processor, NULL);
   symbols_do (symbol_pack_processor, NULL);
 
   symbols_do (symbol_check_alias_consistency_processor, NULL);
   symbols_do (symbol_pack_processor, NULL);