mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-13 22:33:03 +00:00
deterministic user-token-number redeclaration errors.
Address nondeterminism reported by Joel E. Denny. http://lists.gnu.org/archive/html/bison-patches/2009-05/msg00023.html * src/uniqstr.h: Comment changes. * src/location.h (boundary_cmp, location_cmp): New. * src/symtab.c (user_token_number_redeclaration): New. (symbol_translation): Use it. * tests/input.at (Numbered tokens): Adjust the expected output.
This commit is contained in:
28
src/symtab.c
28
src/symtab.c
@@ -193,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. |
|
||||
@@ -582,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. |
|
||||
@@ -597,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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user