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