mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-18 08:43:03 +00:00
The header can also be produced directly, without any obstack!
Yahoo! * src/files.c, src/files.h (defines_obstack): Remove. (compute_header_macro): Global. (defines_obstack_save): Remove. * src/reader.c (parse_union_decl): No longer output to defines_obstack: its content can be found in the `stype' muscle anyway. (output_token_translations): Merge into... (symbols_output): this. Rename as... (symbols_save): this. (reader): Adjust. * src/output.c (header_output): New. (output): Call it.
This commit is contained in:
19
ChangeLog
19
ChangeLog
@@ -1,3 +1,22 @@
|
|||||||
|
2001-12-15 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
The header can also be produced directly, without any obstack!
|
||||||
|
Yahoo!
|
||||||
|
|
||||||
|
* src/files.c, src/files.h (defines_obstack): Remove.
|
||||||
|
(compute_header_macro): Global.
|
||||||
|
(defines_obstack_save): Remove.
|
||||||
|
* src/reader.c (parse_union_decl): No longer output to
|
||||||
|
defines_obstack: its content can be found in the `stype' muscle
|
||||||
|
anyway.
|
||||||
|
(output_token_translations): Merge into...
|
||||||
|
(symbols_output): this.
|
||||||
|
Rename as...
|
||||||
|
(symbols_save): this.
|
||||||
|
(reader): Adjust.
|
||||||
|
* src/output.c (header_output): New.
|
||||||
|
(output): Call it.
|
||||||
|
|
||||||
2001-12-15 Akim Demaille <akim@epita.fr>
|
2001-12-15 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* src/reader.c (parse_union_decl): Instead of handling two obstack
|
* src/reader.c (parse_union_decl): Instead of handling two obstack
|
||||||
|
|||||||
29
src/files.c
29
src/files.c
@@ -30,7 +30,6 @@ FILE *finput = NULL;
|
|||||||
|
|
||||||
struct obstack action_obstack;
|
struct obstack action_obstack;
|
||||||
struct obstack attrs_obstack;
|
struct obstack attrs_obstack;
|
||||||
struct obstack defines_obstack;
|
|
||||||
struct obstack guard_obstack;
|
struct obstack guard_obstack;
|
||||||
struct obstack output_obstack;
|
struct obstack output_obstack;
|
||||||
|
|
||||||
@@ -94,7 +93,7 @@ stringappend (const char *string1, const char *string2)
|
|||||||
| alphanumerical + underscore). |
|
| alphanumerical + underscore). |
|
||||||
`-----------------------------------------------------------------*/
|
`-----------------------------------------------------------------*/
|
||||||
|
|
||||||
static char *
|
char *
|
||||||
compute_header_macro (void)
|
compute_header_macro (void)
|
||||||
{
|
{
|
||||||
const char *prefix = "BISON_";
|
const char *prefix = "BISON_";
|
||||||
@@ -178,26 +177,6 @@ obstack_save (struct obstack *obs, const char *filename)
|
|||||||
xfclose (out);
|
xfclose (out);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------.
|
|
||||||
| Output double inclusion protection macros and saves defines_obstack |
|
|
||||||
`---------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
static void
|
|
||||||
defines_obstack_save (const char *filename)
|
|
||||||
{
|
|
||||||
FILE *out = xfopen (filename, "w");
|
|
||||||
size_t size = obstack_object_size (&defines_obstack);
|
|
||||||
char *macro_name = compute_header_macro ();
|
|
||||||
|
|
||||||
fprintf (out, "#ifndef %s\n", macro_name);
|
|
||||||
fprintf (out, "# define %s\n\n", macro_name);
|
|
||||||
fwrite (obstack_finish (&defines_obstack), 1, size, out);
|
|
||||||
fprintf (out, "\n#endif /* not %s */\n", macro_name);
|
|
||||||
|
|
||||||
free (macro_name);
|
|
||||||
xfclose (out);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------.
|
/*------------------------------------------------------------------.
|
||||||
| Return the path to the skeleton which locaction might be given in |
|
| Return the path to the skeleton which locaction might be given in |
|
||||||
| ENVVAR, otherwise return SKELETON_NAME. |
|
| ENVVAR, otherwise return SKELETON_NAME. |
|
||||||
@@ -471,7 +450,6 @@ open_files (void)
|
|||||||
/* Initialize the obstacks. */
|
/* Initialize the obstacks. */
|
||||||
obstack_init (&action_obstack);
|
obstack_init (&action_obstack);
|
||||||
obstack_init (&attrs_obstack);
|
obstack_init (&attrs_obstack);
|
||||||
obstack_init (&defines_obstack);
|
|
||||||
obstack_init (&guard_obstack);
|
obstack_init (&guard_obstack);
|
||||||
obstack_init (&output_obstack);
|
obstack_init (&output_obstack);
|
||||||
}
|
}
|
||||||
@@ -495,11 +473,6 @@ close_files (void)
|
|||||||
void
|
void
|
||||||
output_files (void)
|
output_files (void)
|
||||||
{
|
{
|
||||||
/* Output the header file if wanted. */
|
|
||||||
if (defines_flag)
|
|
||||||
defines_obstack_save (spec_defines_file);
|
|
||||||
obstack_free (&defines_obstack, NULL);
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* Seems to be invalid now --akim. */
|
/* Seems to be invalid now --akim. */
|
||||||
|
|
||||||
|
|||||||
@@ -49,9 +49,6 @@ extern FILE *finput;
|
|||||||
/* Output all the action code; precise form depends on which parser. */
|
/* Output all the action code; precise form depends on which parser. */
|
||||||
extern struct obstack action_obstack;
|
extern struct obstack action_obstack;
|
||||||
|
|
||||||
/* optionally output #define's for token numbers. */
|
|
||||||
extern struct obstack defines_obstack;
|
|
||||||
|
|
||||||
/* If semantic parser, output a .h file that defines YYSTYPE... */
|
/* If semantic parser, output a .h file that defines YYSTYPE... */
|
||||||
extern struct obstack attrs_obstack;
|
extern struct obstack attrs_obstack;
|
||||||
|
|
||||||
@@ -73,6 +70,9 @@ void output_files PARAMS((void));
|
|||||||
FILE *xfopen PARAMS ((const char *name, const char *mode));
|
FILE *xfopen PARAMS ((const char *name, const char *mode));
|
||||||
int xfclose PARAMS ((FILE *ptr));
|
int xfclose PARAMS ((FILE *ptr));
|
||||||
|
|
||||||
|
/* Compute the double inclusion guard's name. */
|
||||||
|
char * compute_header_macro PARAMS ((void));
|
||||||
|
|
||||||
const char *skeleton_find PARAMS ((const char *envvar,
|
const char *skeleton_find PARAMS ((const char *envvar,
|
||||||
const char *skeleton_name));
|
const char *skeleton_name));
|
||||||
#endif /* !FILES_H_ */
|
#endif /* !FILES_H_ */
|
||||||
|
|||||||
47
src/output.c
47
src/output.c
@@ -91,7 +91,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "obstack.h"
|
|
||||||
#include "quotearg.h"
|
#include "quotearg.h"
|
||||||
#include "getargs.h"
|
#include "getargs.h"
|
||||||
#include "files.h"
|
#include "files.h"
|
||||||
@@ -1044,6 +1043,48 @@ prepare (void)
|
|||||||
MUSCLE_INSERT_INT ("locations-flag", locations_flag);
|
MUSCLE_INSERT_INT ("locations-flag", locations_flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------.
|
||||||
|
| Output the header file. |
|
||||||
|
`-------------------------*/
|
||||||
|
|
||||||
|
static void
|
||||||
|
header_output (void)
|
||||||
|
{
|
||||||
|
FILE *out = xfopen (spec_defines_file, "w");
|
||||||
|
char *macro_name = compute_header_macro ();
|
||||||
|
|
||||||
|
fprintf (out, "#ifndef %s\n", macro_name);
|
||||||
|
fprintf (out, "# define %s\n\n", macro_name);
|
||||||
|
|
||||||
|
fputs (muscle_find ("tokendef"), out);
|
||||||
|
fprintf (out, "\
|
||||||
|
#ifndef YYSTYPE\n\
|
||||||
|
typedef %s
|
||||||
|
yystype;\n\
|
||||||
|
# define YYSTYPE yystype\n\
|
||||||
|
#endif\n",
|
||||||
|
muscle_find ("stype"));
|
||||||
|
|
||||||
|
if (!pure_parser)
|
||||||
|
fprintf (out, "\nextern YYSTYPE %slval;\n",
|
||||||
|
spec_name_prefix);
|
||||||
|
if (semantic_parser)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = ntokens; i < nsyms; i++)
|
||||||
|
/* don't make these for dummy nonterminals made by gensym. */
|
||||||
|
if (*tags[i] != '@')
|
||||||
|
fprintf (out, "# define\tNT%s\t%d\n", tags[i], i);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf (out, "\n#endif /* not %s */\n", macro_name);
|
||||||
|
free (macro_name);
|
||||||
|
xfclose (out);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------.
|
/*----------------------------------------------------------.
|
||||||
| Output the parsing tables and the parser code to ftable. |
|
| Output the parsing tables and the parser code to ftable. |
|
||||||
`----------------------------------------------------------*/
|
`----------------------------------------------------------*/
|
||||||
@@ -1068,7 +1109,11 @@ output (void)
|
|||||||
obstack_1grow (&attrs_obstack, 0);
|
obstack_1grow (&attrs_obstack, 0);
|
||||||
muscle_insert ("prologue", obstack_finish (&attrs_obstack));
|
muscle_insert ("prologue", obstack_finish (&attrs_obstack));
|
||||||
|
|
||||||
|
/* Output the parser. */
|
||||||
output_master_parser ();
|
output_master_parser ();
|
||||||
|
/* Output the header if needed. */
|
||||||
|
if (defines_flag)
|
||||||
|
header_output ();
|
||||||
|
|
||||||
free (rule_table + 1);
|
free (rule_table + 1);
|
||||||
obstack_free (&muscle_obstack, 0);
|
obstack_free (&muscle_obstack, 0);
|
||||||
|
|||||||
143
src/reader.c
143
src/reader.c
@@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "obstack.h"
|
|
||||||
#include "quotearg.h"
|
#include "quotearg.h"
|
||||||
#include "quote.h"
|
#include "quote.h"
|
||||||
#include "getargs.h"
|
#include "getargs.h"
|
||||||
@@ -777,15 +776,6 @@ parse_union_decl (void)
|
|||||||
ungetc (c, finput);
|
ungetc (c, finput);
|
||||||
obstack_1grow (&union_obstack, 0);
|
obstack_1grow (&union_obstack, 0);
|
||||||
muscle_insert ("stype", obstack_finish (&union_obstack));
|
muscle_insert ("stype", obstack_finish (&union_obstack));
|
||||||
|
|
||||||
if (defines_flag)
|
|
||||||
obstack_fgrow1 (&defines_obstack, "\
|
|
||||||
#ifndef YYSTYPE\n\
|
|
||||||
typedef %s
|
|
||||||
yystype;\n\
|
|
||||||
# define YYSTYPE yystype\n\
|
|
||||||
#endif\n",
|
|
||||||
muscle_find ("stype"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1567,55 +1557,6 @@ read_additionnal_code (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------.
|
|
||||||
| For named tokens, but not literal ones, define the name. The |
|
|
||||||
| value is the user token number. |
|
|
||||||
`--------------------------------------------------------------*/
|
|
||||||
|
|
||||||
static void
|
|
||||||
output_token_defines (struct obstack *oout)
|
|
||||||
{
|
|
||||||
bucket *bp;
|
|
||||||
char *cp, *symbol;
|
|
||||||
char c;
|
|
||||||
|
|
||||||
for (bp = firstsymbol; bp; bp = bp->next)
|
|
||||||
{
|
|
||||||
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. */
|
|
||||||
cp = symbol;
|
|
||||||
while ((c = *cp++) && c != '.');
|
|
||||||
if (c != '\0')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
obstack_fgrow2 (oout, "# define\t%s\t%d\n",
|
|
||||||
symbol, bp->user_token_number);
|
|
||||||
if (semantic_parser)
|
|
||||||
/* FIXME: This is certainly dead wrong, and should be just as
|
|
||||||
above. --akim. */
|
|
||||||
obstack_fgrow2 (oout, "# define\tT%s\t%d\n", symbol, bp->value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------.
|
/*------------------------------------------------------------------.
|
||||||
| Set TOKEN_TRANSLATIONS. Check that no two symbols share the same |
|
| Set TOKEN_TRANSLATIONS. Check that no two symbols share the same |
|
||||||
| number. |
|
| number. |
|
||||||
@@ -1757,48 +1698,57 @@ packsymbols (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------.
|
/*---------------------------------------------------------------.
|
||||||
| Output definition of token names. |
|
| Save the definition of token names in the `TOKENDEFS' muscle. |
|
||||||
`-----------------------------------*/
|
`---------------------------------------------------------------*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
symbols_output (void)
|
symbols_save (void)
|
||||||
{
|
{
|
||||||
{
|
struct obstack tokendefs;
|
||||||
struct obstack tokendefs;
|
bucket *bp;
|
||||||
obstack_init (&tokendefs);
|
char *cp, *symbol;
|
||||||
output_token_defines (&tokendefs);
|
char c;
|
||||||
obstack_1grow (&tokendefs, 0);
|
obstack_init (&tokendefs);
|
||||||
muscle_insert ("tokendef", xstrdup (obstack_finish (&tokendefs)));
|
|
||||||
obstack_free (&tokendefs, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (defines_flag)
|
for (bp = firstsymbol; bp; bp = bp->next)
|
||||||
{
|
{
|
||||||
output_token_defines (&defines_obstack);
|
symbol = bp->tag; /* get symbol */
|
||||||
|
|
||||||
if (!pure_parser)
|
if (bp->value >= ntokens)
|
||||||
obstack_fgrow1 (&defines_obstack, "\nextern YYSTYPE %slval;\n",
|
continue;
|
||||||
spec_name_prefix);
|
if (bp->user_token_number == SALIAS)
|
||||||
if (semantic_parser)
|
continue;
|
||||||
|
if ('\'' == *symbol)
|
||||||
|
continue; /* skip literal character */
|
||||||
|
if (bp == errtoken)
|
||||||
|
continue; /* skip error token */
|
||||||
|
if ('\"' == *symbol)
|
||||||
{
|
{
|
||||||
int i;
|
/* use literal string only if given a symbol with an alias */
|
||||||
|
if (bp->alias)
|
||||||
for (i = ntokens; i < nsyms; i++)
|
symbol = bp->alias->tag;
|
||||||
{
|
else
|
||||||
/* don't make these for dummy nonterminals made by gensym. */
|
continue;
|
||||||
if (*tags[i] != '@')
|
|
||||||
obstack_fgrow2 (&defines_obstack,
|
|
||||||
"# define\tNT%s\t%d\n", tags[i], i);
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
/* `fdefines' is now a temporary file, so we need to copy its
|
|
||||||
contents in `done', so we can't close it here. */
|
|
||||||
fclose (fdefines);
|
|
||||||
fdefines = NULL;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Don't #define nonliteral tokens whose names contain periods. */
|
||||||
|
cp = symbol;
|
||||||
|
while ((c = *cp++) && c != '.');
|
||||||
|
if (c != '\0')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
obstack_fgrow2 (&tokendefs, "# define\t%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\tT%s\t%d\n", symbol, bp->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
obstack_1grow (&tokendefs, 0);
|
||||||
|
muscle_insert ("tokendef", xstrdup (obstack_finish (&tokendefs)));
|
||||||
|
obstack_free (&tokendefs, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1925,15 +1875,12 @@ reader (void)
|
|||||||
/* Some C code is given at the end of the grammar file. */
|
/* Some C code is given at the end of the grammar file. */
|
||||||
read_additionnal_code ();
|
read_additionnal_code ();
|
||||||
|
|
||||||
/* Now we know whether we need the line-number stack. If we do,
|
|
||||||
write its type into the .tab.h file.
|
|
||||||
This is no longer need with header skeleton. */
|
|
||||||
|
|
||||||
/* 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 ();
|
||||||
/* Output the headers. */
|
|
||||||
symbols_output ();
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user