mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-11 21:33:04 +00:00
Don't apply the default %destructor/%printer to an unreferenced midrule
value. Mentioned at <http://lists.gnu.org/archive/html/bison-patches/2006-09/msg00104.html>. * src/symtab.c (dummy_symbol_get): Name all dummy symbols initially like $@n instead of just @n so that the default %destructor/%printer logic doesn't see them as user-defined symbols. (symbol_is_dummy): Check for both forms of the name. * src/reader.c (packgram): Remove the `$' from each midrule symbol name for which the midrule value is referenced in any action. * tests/actions.at (Default %printer and %destructor for mid-rule values): New test. * tests/regression.at (Rule Line Numbers, Web2c Report): Update output for change to dummy symbol names.
This commit is contained in:
20
src/reader.c
20
src/reader.c
@@ -459,11 +459,12 @@ packgram (void)
|
||||
|
||||
rules = xnmalloc (nrules, sizeof *rules);
|
||||
|
||||
/* Before invoking grammar_rule_check on any rule, make sure
|
||||
all actions have already been scanned in order to set `used' flags.
|
||||
Otherwise, checking that a midrule's $$ is set will not always work
|
||||
properly because the midrule check must forward-reference the midrule's
|
||||
parent rule. */
|
||||
/* Before invoking grammar_rule_check on any rule, make sure all actions have
|
||||
already been scanned in order to set `used' flags. Otherwise, checking
|
||||
that a midrule's $$ should be set will not always work properly because
|
||||
the check must forward-reference the midrule's parent rule. For the same
|
||||
reason, all the `used' flags must be set before checking whether to remove
|
||||
`$' from any midrule symbol name. */
|
||||
while (p)
|
||||
{
|
||||
if (p->action)
|
||||
@@ -492,6 +493,15 @@ packgram (void)
|
||||
rules[ruleno].action = p->action;
|
||||
rules[ruleno].action_location = p->action_location;
|
||||
|
||||
/* If the midrule's $$ is set or its $n is used, remove the `$' from the
|
||||
symbol name so that it's a user-defined symbol so that the default
|
||||
%destructor and %printer apply. */
|
||||
if (p->midrule_parent_rule
|
||||
&& (p->used
|
||||
|| symbol_list_n_get (p->midrule_parent_rule,
|
||||
p->midrule_parent_rhs_index)->used))
|
||||
p->content.sym->tag += 1;
|
||||
|
||||
/* Don't check the generated rule 0. It has no action, so some rhs
|
||||
symbols may appear unused, but the parsing algorithm ensures that
|
||||
%destructor's are invoked appropriately. */
|
||||
|
||||
@@ -769,7 +769,7 @@ dummy_symbol_get (location loc)
|
||||
|
||||
symbol *sym;
|
||||
|
||||
sprintf (buf, "@%d", ++dummy_count);
|
||||
sprintf (buf, "$@%d", ++dummy_count);
|
||||
sym = symbol_get (buf, loc);
|
||||
sym->class = nterm_sym;
|
||||
sym->number = nvars++;
|
||||
@@ -779,7 +779,7 @@ dummy_symbol_get (location loc)
|
||||
bool
|
||||
symbol_is_dummy (const symbol *sym)
|
||||
{
|
||||
return sym->tag[0] == '@';
|
||||
return sym->tag[0] == '@' || (sym->tag[0] == '$' && sym->tag[1] == '@');
|
||||
}
|
||||
|
||||
/*-------------------.
|
||||
|
||||
Reference in New Issue
Block a user