Enable declaration of default %printer/%destructor. Make the parser

use these for all user-declared grammar symbols for which the user does
not declare a specific %printer/%destructor.  Thus, the parser uses it
for token 0 if the user declares it but not if Bison generates it as
$end.  Discussed starting at
<http://lists.gnu.org/archive/html/bison-patches/2006-02/msg00064.html>,
<http://lists.gnu.org/archive/html/bison-patches/2006-06/msg00091.html>,
and
<http://lists.gnu.org/archive/html/bison-patches/2006-07/msg00019.html>.
* NEWS (2.3+): Mention.
* doc/bison.texinfo (Actions in Mid-Rule): It's no longer impossible to
declare a %destructor for a mid-rule's semantic value.  It's just
impossible to declare one specific to it.
(Freeing Discarded Symbols): Mention that @$ can be used in %destructor
code.  Describe default %destructor form.
* src/parse-gram.y (grammar_declaration): Parse default
%printer/%destructor declarations.
* src/output.c (symbol_destructors_output): Use symbol_destructor_get
and symbol_destructor_location_get rather than accessing the destructor
and destructor_location members of struct symbol.
(symbol_printers_output): Likewise but for %printer's.
* src/reader.c (symbol_should_be_used): Likewise but for %destructor's
again.
* src/symtab.c (default_destructor, default_destructor_location,
default_printer, default_printer_location): New static global
variables to record the default %destructor and %printer.
(symbol_destructor_get, symbol_destructor_location_get,
symbol_printer_get, symbol_printer_location_get): New functions to
compute the appropriate %destructor and %printer for a symbol.
(default_destructor_set, default_printer_set): New functions to set the
default %destructor and %printer.
* src/symtab.h: Prototype all those new functions.
* tests/actions.at (Default %printer and %destructor): New test to
check that the right %printer and %destructor are called, that they're
not called for $end, and that $$ and @$ work correctly.
(Default %printer and %destructor for user-declared end token): New
test to check that the default %printer and %destructor are called for
a user-declared end token.
* tests/input.at (Default %printer and %destructor redeclared, Unused
values with default %destructor): New tests to check related grammar
warnings and errors.
This commit is contained in:
Joel E. Denny
2006-07-29 05:53:42 +00:00
parent 868d2d9638
commit ec5479ce35
12 changed files with 771 additions and 276 deletions

View File

@@ -390,7 +390,7 @@ symbol_destructors_output (FILE *out)
fputs ("m4_define([b4_symbol_destructors], \n[", out);
for (i = 0; i < nsyms; ++i)
if (symbols[i]->destructor)
if (symbol_destructor_get (symbols[i]))
{
symbol *sym = symbols[i];
@@ -399,10 +399,12 @@ symbol_destructors_output (FILE *out)
destructor, optional typename. */
fprintf (out, "%s[", sep);
sep = ",\n";
escaped_output (out, sym->destructor_location.start.file);
fprintf (out, ", %d, ", sym->destructor_location.start.line);
escaped_output (out, symbol_destructor_location_get (sym).start.file);
fprintf (out, ", %d, ",
symbol_destructor_location_get (sym).start.line);
escaped_output (out, sym->tag);
fprintf (out, ", %d, [[%s]]", sym->number, sym->destructor);
fprintf (out, ", %d, [[%s]]", sym->number,
symbol_destructor_get (sym));
if (sym->type_name)
fprintf (out, ", [[%s]]", sym->type_name);
fputc (']', out);
@@ -423,7 +425,7 @@ symbol_printers_output (FILE *out)
fputs ("m4_define([b4_symbol_printers], \n[", out);
for (i = 0; i < nsyms; ++i)
if (symbols[i]->printer)
if (symbol_printer_get (symbols[i]))
{
symbol *sym = symbols[i];
@@ -432,10 +434,10 @@ symbol_printers_output (FILE *out)
printer, optional typename. */
fprintf (out, "%s[", sep);
sep = ",\n";
escaped_output (out, sym->printer_location.start.file);
fprintf (out, ", %d, ", sym->printer_location.start.line);
escaped_output (out, symbol_printer_location_get (sym).start.file);
fprintf (out, ", %d, ", symbol_printer_location_get (sym).start.line);
escaped_output (out, sym->tag);
fprintf (out, ", %d, [[%s]]", sym->number, sym->printer);
fprintf (out, ", %d, [[%s]]", sym->number, symbol_printer_get (sym));
if (sym->type_name)
fprintf (out, ", [[%s]]", sym->type_name);
fputc (']', out);