X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/aea10ef46f726371c21e99d2bfb78c1ab891f73d..44bb9084856ec2c421c91e1e1bd0f20437ce83b8:/src/symtab.c diff --git a/src/symtab.c b/src/symtab.c index b65bdd48..727ac2c7 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -1,6 +1,7 @@ /* Symbol table manager for Bison. - Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008 + Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004, 2005, 2006, 2007, + 2008, 2009 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -58,6 +59,13 @@ symbol_new (uniqstr tag, location loc) symbol *res = xmalloc (sizeof *res); uniqstr_assert (tag); + + /* If the tag is not a string (starts with a double quote), check + that it is valid for Yacc. */ + if (tag[0] != '\"' && tag[0] != '\'' && strchr (tag, '-')) + yacc_at (loc, _("POSIX Yacc forbids dashes in symbol names: %s"), + tag); + res->tag = tag; res->location = loc; @@ -185,6 +193,7 @@ semantic_type_redeclaration (semantic_type *s, const char *what, location first, } + /*-----------------------------------------------------------------. | Set the TYPE_NAME associated with SYM. Does nothing if passed 0 | | as TYPE_NAME. | @@ -574,7 +583,26 @@ symbol_pack_processor (void *this, void *null ATTRIBUTE_UNUSED) } +static void +user_token_number_redeclaration (int num, symbol *first, symbol *second) +{ + /* User token numbers are not assigned during the parsing, but in a + second step, via a (nondeterministic) traversal of the symbol + hash table. + Make errors deterministic: keep the first declaration first. */ + if (location_cmp (first->location, second->location) > 0) + { + symbol* tmp = first; + first = second; + second = tmp; + } + complain_at (second->location, + _("user token number %d redeclaration for %s"), + num, second->tag); + complain_at (first->location, _("previous declaration for %s"), + first->tag); +} /*--------------------------------------------------. | Put THIS in TOKEN_TRANSLATIONS if it is a token. | @@ -589,10 +617,10 @@ symbol_translation (symbol *this) { /* A token which translation has already been set? */ if (token_translations[this->user_token_number] != undeftoken->number) - complain_at (this->location, - _("tokens %s and %s both assigned number %d"), - symbols[token_translations[this->user_token_number]]->tag, - this->tag, this->user_token_number); + user_token_number_redeclaration + (this->user_token_number, + symbols[token_translations[this->user_token_number]], + this); token_translations[this->user_token_number] = this->number; } @@ -707,7 +735,8 @@ symbol_from_uniqstr (const uniqstr key, location loc) { /* First insertion in the hash. */ entry = symbol_new (key, loc); - hash_insert (symbol_table, entry); + if (!hash_insert (symbol_table, entry)) + xalloc_die (); } return entry; } @@ -731,7 +760,8 @@ semantic_type_from_uniqstr (const uniqstr key) { /* First insertion in the hash. */ entry = semantic_type_new (key); - hash_insert (semantic_type_table, entry); + if (!hash_insert (semantic_type_table, entry)) + xalloc_die (); } return entry; }