mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-10 12:53:03 +00:00
* src/files.c (guard_obstack): New.
(open_files): Initialize it. (output_files): Dump it... * src/files.h: Export it. * src/reader.c (copy_guard): Use it.
This commit is contained in:
17
src/files.c
17
src/files.c
@@ -28,19 +28,19 @@
|
||||
|
||||
FILE *finput = NULL;
|
||||
FILE *foutput = NULL;
|
||||
FILE *fguard = NULL;
|
||||
|
||||
struct obstack action_obstack;
|
||||
struct obstack attrs_obstack;
|
||||
struct obstack table_obstack;
|
||||
struct obstack defines_obstack;
|
||||
struct obstack guard_obstack;
|
||||
|
||||
/* File name specified with -o for the output file, or 0 if no -o. */
|
||||
char *spec_outfile;
|
||||
char *spec_outfile; /* for -o. */
|
||||
char *spec_file_prefix; /* for -b. */
|
||||
char *spec_name_prefix; /* for -p. */
|
||||
|
||||
char *infile;
|
||||
char *attrsfile;
|
||||
char *guardfile;
|
||||
|
||||
static char *base_name;
|
||||
static char *short_base_name;
|
||||
@@ -255,13 +255,13 @@ open_files (void)
|
||||
foutput = xfopen (stringappend (base_name, EXT_OUTPUT), "w");
|
||||
|
||||
attrsfile = stringappend (short_base_name, EXT_STYPE_H);
|
||||
guardfile = stringappend (short_base_name, EXT_GUARD_C);
|
||||
|
||||
/* Initialize the obstacks. */
|
||||
obstack_init (&action_obstack);
|
||||
obstack_init (&attrs_obstack);
|
||||
obstack_init (&table_obstack);
|
||||
obstack_init (&defines_obstack);
|
||||
obstack_init (&guard_obstack);
|
||||
}
|
||||
|
||||
|
||||
@@ -273,7 +273,6 @@ open_files (void)
|
||||
void
|
||||
output_files (void)
|
||||
{
|
||||
xfclose (fguard);
|
||||
xfclose (finput);
|
||||
xfclose (foutput);
|
||||
|
||||
@@ -294,5 +293,9 @@ output_files (void)
|
||||
/* If we produced a semantic parser ATTRS_OBSTACK must be dumped
|
||||
into its own file, ATTTRSFILE. */
|
||||
if (semantic_parser)
|
||||
obstack_save (&attrs_obstack, attrsfile);
|
||||
{
|
||||
obstack_save (&attrs_obstack, attrsfile);
|
||||
obstack_save (&guard_obstack,
|
||||
stringappend (short_base_name, EXT_GUARD_C));
|
||||
}
|
||||
}
|
||||
|
||||
15
src/files.h
15
src/files.h
@@ -27,7 +27,7 @@
|
||||
/* File name specified with -o for the output file, or 0 if no -o. */
|
||||
extern char *spec_outfile;
|
||||
|
||||
/* For -a, from getargs.c */
|
||||
/* For -a. */
|
||||
extern char *spec_name_prefix;
|
||||
|
||||
/* File name pfx specified with -b, or 0 if no -b. */
|
||||
@@ -40,16 +40,10 @@ extern FILE *finput;
|
||||
/* Optionally output messages describing the actions taken. */
|
||||
extern FILE *foutput;
|
||||
|
||||
/* If semantic parser, output yyguard, containing all the guard code. */
|
||||
extern FILE *fguard;
|
||||
|
||||
|
||||
/* Output all the action code; precise form depends on which parser. */
|
||||
extern struct obstack action_obstack;
|
||||
|
||||
/* If semantic parser, output a .h file that defines YYSTYPE */
|
||||
extern struct obstack attrs_obstack;
|
||||
|
||||
/* Output the tables and the parser and also contains all the %{
|
||||
... %} definitions. */
|
||||
extern struct obstack table_obstack;
|
||||
@@ -57,10 +51,15 @@ extern struct obstack table_obstack;
|
||||
/* optionally output #define's for token numbers. */
|
||||
extern struct obstack defines_obstack;
|
||||
|
||||
/* If semantic parser, output a .h file that defines YYSTYPE... */
|
||||
extern struct obstack attrs_obstack;
|
||||
|
||||
/* ... and output yyguard, containing all the guard code. */
|
||||
extern struct obstack guard_obstack;
|
||||
|
||||
|
||||
extern char *infile;
|
||||
extern char *attrsfile;
|
||||
extern char *guardfile;
|
||||
|
||||
void open_files PARAMS((void));
|
||||
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
#include "files.h"
|
||||
#include "getargs.h"
|
||||
|
||||
char *spec_file_prefix; /* for -b. */
|
||||
char *spec_name_prefix; /* for -p. */
|
||||
|
||||
int debug_flag = 0;
|
||||
int defines_flag = 0;
|
||||
int locations_flag = 0;
|
||||
|
||||
@@ -226,7 +226,7 @@ output_headers (void)
|
||||
char *attrsfile_quoted = quotearg_style (c_quoting_style, attrsfile);
|
||||
|
||||
if (semantic_parser)
|
||||
fprintf (fguard, GUARDSTR, attrsfile_quoted);
|
||||
obstack_fgrow1 (&guard_obstack, GUARDSTR, attrsfile_quoted);
|
||||
|
||||
if (no_parser_flag)
|
||||
return;
|
||||
@@ -236,11 +236,6 @@ output_headers (void)
|
||||
else
|
||||
obstack_grow_string (&action_obstack, ACTSTR_SIMPLE);
|
||||
|
||||
/* if (semantic_parser) JF moved this below
|
||||
fprintf(ftable, "#include \"%s\"\n", attrsfile);
|
||||
fprintf(ftable, "#include <stdio.h>\n\n");
|
||||
*/
|
||||
|
||||
/* Rename certain symbols if -p was specified. */
|
||||
if (spec_name_prefix)
|
||||
{
|
||||
@@ -270,7 +265,7 @@ void
|
||||
output_trailers (void)
|
||||
{
|
||||
if (semantic_parser)
|
||||
fprintf (fguard, "\n }\n}\n");
|
||||
obstack_grow_string (&guard_obstack, "\n }\n}\n");
|
||||
|
||||
obstack_1grow (&action_obstack, '\n');
|
||||
|
||||
|
||||
30
src/reader.c
30
src/reader.c
@@ -1002,8 +1002,6 @@ read_declarations (void)
|
||||
break;
|
||||
|
||||
case SEMANTIC_PARSER:
|
||||
if (!semantic_parser)
|
||||
fguard = xfopen (guardfile, "w");
|
||||
semantic_parser = 1;
|
||||
break;
|
||||
|
||||
@@ -1140,11 +1138,11 @@ copy_guard (symbol_list *rule, int stack_offset)
|
||||
if (semantic_parser)
|
||||
stack_offset = 0;
|
||||
|
||||
fprintf (fguard, "\ncase %d:\n", nrules);
|
||||
obstack_fgrow1 (&guard_obstack, "\ncase %d:\n", nrules);
|
||||
if (!no_lines_flag)
|
||||
fprintf (fguard, "#line %d %s\n",
|
||||
lineno, quotearg_style (c_quoting_style, infile));
|
||||
putc ('{', fguard);
|
||||
obstack_fgrow2 (&guard_obstack, "#line %d %s\n",
|
||||
lineno, quotearg_style (c_quoting_style, infile));
|
||||
obstack_1grow (&guard_obstack, '{');
|
||||
|
||||
count = 0;
|
||||
c = getc (finput);
|
||||
@@ -1154,18 +1152,18 @@ copy_guard (symbol_list *rule, int stack_offset)
|
||||
switch (c)
|
||||
{
|
||||
case '\n':
|
||||
putc (c, fguard);
|
||||
obstack_1grow (&guard_obstack, c);
|
||||
lineno++;
|
||||
break;
|
||||
|
||||
case '{':
|
||||
putc (c, fguard);
|
||||
obstack_1grow (&guard_obstack, c);
|
||||
brace_flag = 1;
|
||||
count++;
|
||||
break;
|
||||
|
||||
case '}':
|
||||
putc (c, fguard);
|
||||
obstack_1grow (&guard_obstack, c);
|
||||
if (count > 0)
|
||||
count--;
|
||||
else
|
||||
@@ -1177,26 +1175,26 @@ copy_guard (symbol_list *rule, int stack_offset)
|
||||
|
||||
case '\'':
|
||||
case '"':
|
||||
copy_string (finput, fguard, 0, c);
|
||||
copy_string (finput, 0, &guard_obstack, c);
|
||||
break;
|
||||
|
||||
case '/':
|
||||
copy_comment (finput, fguard, 0);
|
||||
copy_comment (finput, 0, &guard_obstack);
|
||||
break;
|
||||
|
||||
case '$':
|
||||
copy_dollar (finput, fguard, 0, rule, stack_offset);
|
||||
copy_dollar (finput, 0, &guard_obstack, rule, stack_offset);
|
||||
break;
|
||||
|
||||
case '@':
|
||||
copy_at (finput, fguard, 0, stack_offset);
|
||||
copy_at (finput, 0, &guard_obstack, stack_offset);
|
||||
break;
|
||||
|
||||
case EOF:
|
||||
fatal ("%s", _("unterminated %guard clause"));
|
||||
|
||||
default:
|
||||
putc (c, fguard);
|
||||
obstack_1grow (&guard_obstack, c);
|
||||
}
|
||||
|
||||
if (c != '}' || count != 0)
|
||||
@@ -1205,7 +1203,7 @@ copy_guard (symbol_list *rule, int stack_offset)
|
||||
|
||||
c = skip_white_space ();
|
||||
|
||||
fprintf (fguard, ";\n break;}");
|
||||
obstack_grow_string (&guard_obstack, ";\n break;}");
|
||||
if (c == '{')
|
||||
copy_action (rule, stack_offset);
|
||||
else if (c == '=')
|
||||
@@ -1898,7 +1896,7 @@ packgram (void)
|
||||
|
||||
/*-------------------------------------------------------------------.
|
||||
| Read in the grammar specification and record it in the format |
|
||||
| described in gram.h. All guards are copied into the FGUARD file |
|
||||
| described in gram.h. All guards are copied into the GUARD_OBSTACK |
|
||||
| and all actions into ACTION_OBSTACK, in each case forming the body |
|
||||
| of a C function (YYGUARD or YYACTION) which contains a switch |
|
||||
| statement to decide which guard or action to execute. |
|
||||
|
||||
Reference in New Issue
Block a user