mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-10 12:53:03 +00:00
Don't apply the default %destructor or %printer to the error token,
$undefined, or $accept. This change fits the general rule that the default %destructor and %printer are only for user-declared symbols, and it solves several difficulties that are described in the new test cases listed below. * src/symtab.c (symbol_destructor_get, symbol_printer_get): Implement. * tests/actions.at (Default %printer and %destructor are not for error or $undefined, Default %printer and %destructor are not for $accept): New test cases.
This commit is contained in:
20
src/symtab.c
20
src/symtab.c
@@ -163,12 +163,14 @@ symbol_destructor_set (symbol *sym, const char *destructor, location loc)
|
||||
const char *
|
||||
symbol_destructor_get (symbol *sym)
|
||||
{
|
||||
/* Token 0 cannot have a %destructor unless the user renames it. */
|
||||
if (UNIQSTR_EQ (sym->tag, uniqstr_new ("$end")))
|
||||
return NULL;
|
||||
|
||||
/* Per-symbol %destructor. */
|
||||
if (sym->destructor != NULL)
|
||||
return sym->destructor;
|
||||
|
||||
/* Apply the default %destructor only to user-defined symbols. */
|
||||
if (sym == errtoken || sym == undeftoken || sym == accept
|
||||
|| UNIQSTR_EQ (sym->tag, uniqstr_new ("$end")))
|
||||
return NULL;
|
||||
return default_destructor;
|
||||
}
|
||||
|
||||
@@ -207,12 +209,14 @@ symbol_printer_set (symbol *sym, const char *printer, location loc)
|
||||
const char *
|
||||
symbol_printer_get (symbol *sym)
|
||||
{
|
||||
/* Token 0 cannot have a %printer unless the user renames it. */
|
||||
if (UNIQSTR_EQ (sym->tag, uniqstr_new ("$end")))
|
||||
return NULL;
|
||||
|
||||
/* Per-symbol %printer. */
|
||||
if (sym->printer != NULL)
|
||||
return sym->printer;
|
||||
|
||||
/* Apply the default %printer only to user-defined symbols. */
|
||||
if (sym == errtoken || sym == undeftoken || sym == accept
|
||||
|| UNIQSTR_EQ (sym->tag, uniqstr_new ("$end")))
|
||||
return NULL;
|
||||
return default_printer;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user