mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-20 01:33:03 +00:00
Don't store the token defs in a muscle, just be ready to output it
on command. Now possible via `symbols'. Fixes a memory leak. * src/output.c (token_definitions_output): New. (output_parser, header_output): Use it. * src/reader.c (symbols_save): Remove.
This commit is contained in:
10
ChangeLog
10
ChangeLog
@@ -1,3 +1,13 @@
|
|||||||
|
2001-12-29 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
Don't store the token defs in a muscle, just be ready to output it
|
||||||
|
on command. Now possible via `symbols'. Fixes a memory leak.
|
||||||
|
|
||||||
|
* src/output.c (token_definitions_output): New.
|
||||||
|
(output_parser, header_output): Use it.
|
||||||
|
* src/reader.c (symbols_save): Remove.
|
||||||
|
|
||||||
|
|
||||||
2001-12-29 Akim Demaille <akim@epita.fr>
|
2001-12-29 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* src/bison.simple: Do not provide a default for YYSTYPE and
|
* src/bison.simple: Do not provide a default for YYSTYPE and
|
||||||
|
|||||||
@@ -58,9 +58,6 @@ muscle_init (void)
|
|||||||
muscle_insert ("stype", "int");
|
muscle_insert ("stype", "int");
|
||||||
muscle_insert ("ltype", "yyltype");
|
muscle_insert ("ltype", "yyltype");
|
||||||
|
|
||||||
/* Tokens. */
|
|
||||||
muscle_insert ("tokendef", NULL);
|
|
||||||
|
|
||||||
/* Tables. */
|
/* Tables. */
|
||||||
muscle_insert ("rhs", NULL);
|
muscle_insert ("rhs", NULL);
|
||||||
muscle_insert ("pact", NULL);
|
muscle_insert ("pact", NULL);
|
||||||
|
|||||||
53
src/output.c
53
src/output.c
@@ -567,6 +567,54 @@ guards_output (FILE *out, size_t *line)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------.
|
||||||
|
| Output the tokens definition to OOUT. |
|
||||||
|
`---------------------------------------*/
|
||||||
|
|
||||||
|
static void
|
||||||
|
token_definitions_output (FILE *out, size_t *line)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < ntokens; ++i)
|
||||||
|
{
|
||||||
|
bucket *symbol = symbols[i];
|
||||||
|
int number = symbol->user_token_number;
|
||||||
|
|
||||||
|
if (number == SALIAS)
|
||||||
|
continue;
|
||||||
|
/* Skip error token. */
|
||||||
|
if (symbol->value == error_token_number)
|
||||||
|
continue;
|
||||||
|
if (symbol->tag[0] == '\'')
|
||||||
|
continue; /* skip literal character */
|
||||||
|
if (symbol->tag[0] == '\"')
|
||||||
|
{
|
||||||
|
/* use literal string only if given a symbol with an alias */
|
||||||
|
if (symbol->alias)
|
||||||
|
symbol = symbol->alias;
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Don't #define nonliteral tokens whose names contain periods
|
||||||
|
or '$' (as does the default value of the EOF token). */
|
||||||
|
if (strchr (symbol->tag, '.') || strchr (symbol->tag, '$'))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
fprintf (out, "# define %s\t%d\n",
|
||||||
|
symbol->tag, number);
|
||||||
|
++*line;
|
||||||
|
if (semantic_parser)
|
||||||
|
{
|
||||||
|
/* FIXME: This is probably wrong, and should be just as
|
||||||
|
above. --akim. */
|
||||||
|
fprintf (out, "# define T%s\t%d\n", symbol->tag, symbol->value);
|
||||||
|
++*line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
save_column (int symbol, int default_state)
|
save_column (int symbol, int default_state)
|
||||||
{
|
{
|
||||||
@@ -963,6 +1011,8 @@ output_parser (const char *skel_filename, FILE *out)
|
|||||||
guards_output (out, &output_line);
|
guards_output (out, &output_line);
|
||||||
else if (!strcmp (muscle_key, "line"))
|
else if (!strcmp (muscle_key, "line"))
|
||||||
fprintf (out, "%d", output_line);
|
fprintf (out, "%d", output_line);
|
||||||
|
else if (!strcmp (muscle_key, "tokendef"))
|
||||||
|
token_definitions_output (out, &output_line);
|
||||||
else if (!strcmp (muscle_key, "skeleton-line"))
|
else if (!strcmp (muscle_key, "skeleton-line"))
|
||||||
fprintf (out, "%d", skeleton_line);
|
fprintf (out, "%d", skeleton_line);
|
||||||
else if (muscle_value)
|
else if (muscle_value)
|
||||||
@@ -1059,13 +1109,14 @@ prepare (void)
|
|||||||
static void
|
static void
|
||||||
header_output (void)
|
header_output (void)
|
||||||
{
|
{
|
||||||
|
size_t dummy_line;
|
||||||
FILE *out = xfopen (spec_defines_file, "w");
|
FILE *out = xfopen (spec_defines_file, "w");
|
||||||
char *macro_name = compute_header_macro ();
|
char *macro_name = compute_header_macro ();
|
||||||
|
|
||||||
fprintf (out, "#ifndef %s\n", macro_name);
|
fprintf (out, "#ifndef %s\n", macro_name);
|
||||||
fprintf (out, "# define %s\n\n", macro_name);
|
fprintf (out, "# define %s\n\n", macro_name);
|
||||||
|
|
||||||
fputs (muscle_find ("tokendef"), out);
|
token_definitions_output (out, &dummy_line);
|
||||||
fprintf (out, "\
|
fprintf (out, "\
|
||||||
#ifndef YYSTYPE\n\
|
#ifndef YYSTYPE\n\
|
||||||
typedef %s
|
typedef %s
|
||||||
|
|||||||
52
src/reader.c
52
src/reader.c
@@ -1658,56 +1658,6 @@ packsymbols (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------.
|
|
||||||
| Save the definition of token names in the `TOKENDEFS' muscle. |
|
|
||||||
`---------------------------------------------------------------*/
|
|
||||||
|
|
||||||
static void
|
|
||||||
symbols_save (void)
|
|
||||||
{
|
|
||||||
struct obstack tokendefs;
|
|
||||||
bucket *bp;
|
|
||||||
obstack_init (&tokendefs);
|
|
||||||
|
|
||||||
for (bp = firstsymbol; bp; bp = bp->next)
|
|
||||||
{
|
|
||||||
char *symbol = bp->tag; /* get symbol */
|
|
||||||
|
|
||||||
if (bp->value >= ntokens)
|
|
||||||
continue;
|
|
||||||
if (bp->user_token_number == SALIAS)
|
|
||||||
continue;
|
|
||||||
if ('\'' == *symbol)
|
|
||||||
continue; /* skip literal character */
|
|
||||||
if (bp == errtoken)
|
|
||||||
continue; /* skip error token */
|
|
||||||
if ('\"' == *symbol)
|
|
||||||
{
|
|
||||||
/* use literal string only if given a symbol with an alias */
|
|
||||||
if (bp->alias)
|
|
||||||
symbol = bp->alias->tag;
|
|
||||||
else
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Don't #define nonliteral tokens whose names contain periods. */
|
|
||||||
if (strchr (symbol, '.'))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
obstack_fgrow2 (&tokendefs, "# define %s\t%d\n",
|
|
||||||
symbol, bp->user_token_number);
|
|
||||||
if (semantic_parser)
|
|
||||||
/* FIXME: This is probably wrong, and should be just as
|
|
||||||
above. --akim. */
|
|
||||||
obstack_fgrow2 (&tokendefs, "# define T%s\t%d\n", symbol, bp->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
obstack_1grow (&tokendefs, 0);
|
|
||||||
muscle_insert ("tokendef", xstrdup (obstack_finish (&tokendefs)));
|
|
||||||
obstack_free (&tokendefs, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------.
|
/*---------------------------------------------------------------.
|
||||||
| Convert the rules into the representation using RRHS, RLHS and |
|
| Convert the rules into the representation using RRHS, RLHS and |
|
||||||
| RITEMS. |
|
| RITEMS. |
|
||||||
@@ -1867,8 +1817,6 @@ reader (void)
|
|||||||
/* Assign the symbols their symbol numbers. Write #defines for the
|
/* Assign the symbols their symbol numbers. Write #defines for the
|
||||||
token symbols into FDEFINES if requested. */
|
token symbols into FDEFINES if requested. */
|
||||||
packsymbols ();
|
packsymbols ();
|
||||||
/* Save them. */
|
|
||||||
symbols_save ();
|
|
||||||
|
|
||||||
/* Convert the grammar into the format described in gram.h. */
|
/* Convert the grammar into the format described in gram.h. */
|
||||||
packgram ();
|
packgram ();
|
||||||
|
|||||||
Reference in New Issue
Block a user