mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
Change each use of fattrs' into a use of attrs_obstack'.
* src/reader.c (copy_at): Typo: s/yylloc/yyloc/. * src/files.c (fattrs): Remove. (attrs_obstack): New. Adjust all dependencies. (done): If SEMANTIC_PARSER, dump attrs_obstack into attrsfile.
This commit is contained in:
10
ChangeLog
10
ChangeLog
@@ -1,3 +1,13 @@
|
||||
2000-11-01 Akim Demaille <akim@epita.fr>
|
||||
|
||||
Change each use of `fattrs' into a use of `attrs_obstack'.
|
||||
|
||||
* src/reader.c (copy_at): Typo: s/yylloc/yyloc/.
|
||||
* src/files.c (fattrs): Remove.
|
||||
(attrs_obstack): New.
|
||||
Adjust all dependencies.
|
||||
(done): If SEMANTIC_PARSER, dump attrs_obstack into attrsfile.
|
||||
|
||||
2000-11-01 Akim Demaille <akim@epita.fr>
|
||||
|
||||
Introduce obstacks.
|
||||
|
||||
66
src/files.c
66
src/files.c
@@ -51,11 +51,11 @@ FILE *finput = NULL;
|
||||
FILE *foutput = NULL;
|
||||
FILE *fdefines = NULL;
|
||||
FILE *ftable = NULL;
|
||||
FILE *fattrs = NULL;
|
||||
FILE *fguard = NULL;
|
||||
FILE *fparser = NULL;
|
||||
|
||||
struct obstack action_obstack;
|
||||
struct obstack attrs_obstack;
|
||||
|
||||
/* File name specified with -o for the output file, or 0 if no -o. */
|
||||
char *spec_outfile;
|
||||
@@ -68,7 +68,6 @@ static char *defsfile;
|
||||
static char *tabfile;
|
||||
static char *guardfile;
|
||||
static char *actfile;
|
||||
static char *tmpattrsfile;
|
||||
static char *tmptabfile;
|
||||
static char *tmpdefsfile;
|
||||
|
||||
@@ -293,16 +292,13 @@ open_files (void)
|
||||
}
|
||||
|
||||
#ifdef MSDOS
|
||||
tmpattrsfile = mktemp (stringappend (tmp_base, tmp_len, "atXXXXXX"));
|
||||
tmptabfile = mktemp (stringappend (tmp_base, tmp_len, "taXXXXXX"));
|
||||
tmpdefsfile = mktemp (stringappend (tmp_base, tmp_len, "deXXXXXX"));
|
||||
#else
|
||||
tmpattrsfile = mktemp (stringappend (tmp_base, tmp_len, "attrs.XXXXXX"));
|
||||
tmptabfile = mktemp (stringappend (tmp_base, tmp_len, "tab.XXXXXX"));
|
||||
tmpdefsfile = mktemp (stringappend (tmp_base, tmp_len, "defs.XXXXXX"));
|
||||
#endif /* not MSDOS */
|
||||
|
||||
fattrs = xfopen (tmpattrsfile, "w+");
|
||||
ftable = xfopen (tmptabfile, "w+");
|
||||
|
||||
if (defines_flag)
|
||||
@@ -312,7 +308,6 @@ open_files (void)
|
||||
}
|
||||
|
||||
#if !(defined (MSDOS) || (defined(_WIN32) && !defined(__CYGWIN32__)))
|
||||
unlink (tmpattrsfile);
|
||||
unlink (tmptabfile);
|
||||
unlink (tmpdefsfile);
|
||||
#endif /* MSDOS || (_WIN32 && !__CYGWIN32__) */
|
||||
@@ -336,8 +331,9 @@ open_files (void)
|
||||
#endif /* not MSDOS */
|
||||
#endif /* not VMS */
|
||||
|
||||
/* Setup the action obstack. */
|
||||
/* Initialize the obstacks. */
|
||||
obstack_init (&action_obstack);
|
||||
obstack_init (&attrs_obstack);
|
||||
}
|
||||
|
||||
|
||||
@@ -350,12 +346,8 @@ open_files (void)
|
||||
void
|
||||
open_extra_files (void)
|
||||
{
|
||||
FILE *ftmp;
|
||||
int c;
|
||||
char *filename;
|
||||
#ifdef MSDOS
|
||||
char *cp;
|
||||
#endif
|
||||
|
||||
xfclose (fparser);
|
||||
|
||||
@@ -363,36 +355,29 @@ open_extra_files (void)
|
||||
{
|
||||
filename = (char *) getenv ("BISON_HAIRY");
|
||||
#ifdef MSDOS
|
||||
/* File doesn't exist in current directory; try in INIT directory. */
|
||||
cp = getenv ("INIT");
|
||||
if (filename == 0 && cp != NULL)
|
||||
{
|
||||
filename = XMALLOC (char, strlen (cp) + strlen (PFILE1) + 2);
|
||||
strcpy (filename, cp);
|
||||
cp = filename + strlen (filename);
|
||||
*cp++ = '/';
|
||||
strcpy (cp, PFILE1);
|
||||
}
|
||||
{
|
||||
/* File doesn't exist in current directory; try in INIT
|
||||
directory. */
|
||||
char *cp = getenv ("INIT");
|
||||
if (filename == 0 && cp != NULL)
|
||||
{
|
||||
filename = XMALLOC (char, strlen (cp) + strlen (PFILE1) + 2);
|
||||
strcpy (filename, cp);
|
||||
cp = filename + strlen (filename);
|
||||
*cp++ = '/';
|
||||
strcpy (cp, PFILE1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
fparser = xfopen (filename ? filename : PFILE1, "r");
|
||||
}
|
||||
|
||||
/* JF change from inline attrs file to separate one */
|
||||
ftmp = xfopen (attrsfile, "w");
|
||||
rewind (fattrs);
|
||||
while ((c = getc (fattrs)) != EOF) /* Thank god for buffering */
|
||||
putc (c, ftmp);
|
||||
xfclose (fattrs);
|
||||
fattrs = ftmp;
|
||||
|
||||
fguard = xfopen (guardfile, "w");
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
done (void)
|
||||
{
|
||||
xfclose (fattrs);
|
||||
xfclose (fguard);
|
||||
xfclose (finput);
|
||||
xfclose (fparser);
|
||||
@@ -423,16 +408,27 @@ done (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* If we output only the table, dump the actions in ACTION_OBSTACK.
|
||||
*/
|
||||
if (no_parser_flag)
|
||||
{
|
||||
FILE *faction = xfopen (actfile, "w");
|
||||
size_t size = obstack_object_size (&action_obstack);
|
||||
fwrite (obstack_finish (&action_obstack), 1, size, faction);
|
||||
fclose (faction);
|
||||
xfclose (faction);
|
||||
}
|
||||
|
||||
/* If we produced a semantic parser ATTRS_OBSTACK must be dumped
|
||||
into its own file, ATTTRSFILE. */
|
||||
if (semantic_parser)
|
||||
{
|
||||
FILE *fattrs = xfopen (attrsfile, "w");
|
||||
size_t size = obstack_object_size (&attrs_obstack);
|
||||
fwrite (obstack_finish (&attrs_obstack), 1, size, fattrs);
|
||||
xfclose (fattrs);
|
||||
}
|
||||
|
||||
#if defined (VMS) & !defined (__VMS_POSIX)
|
||||
if (fattrs)
|
||||
delete (tmpattrsfile);
|
||||
if (ftable)
|
||||
delete (tmptabfile);
|
||||
/* Don't call exit again, we're in atexit ().
|
||||
@@ -441,8 +437,6 @@ done (void)
|
||||
sys$exit(SS$_ABORT); */
|
||||
#else
|
||||
#if (defined (MSDOS) || (defined(_WIN32) && !defined(__CYGWIN32__)))
|
||||
if (tmpattrsfile)
|
||||
unlink (tmpattrsfile);
|
||||
if (tmptabfile)
|
||||
unlink (tmptabfile);
|
||||
if (tmpdefsfile)
|
||||
|
||||
@@ -31,7 +31,6 @@ extern FILE *finput; /* read grammar specifications */
|
||||
extern FILE *foutput; /* optionally output messages describing the actions taken */
|
||||
extern FILE *fdefines; /* optionally output #define's for token numbers. */
|
||||
extern FILE *ftable; /* output the tables and the parser */
|
||||
extern FILE *fattrs; /* if semantic parser, output a .h file that defines YYSTYPE */
|
||||
/* and also contains all the %{ ... %} definitions. */
|
||||
extern FILE *fguard; /* if semantic parser, output yyguard, containing all the guard code */
|
||||
extern FILE *fparser; /* read the parser to copy into ftable */
|
||||
@@ -47,6 +46,8 @@ extern char *spec_file_prefix;
|
||||
/* 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;
|
||||
|
||||
extern char *infile;
|
||||
extern int lineno;
|
||||
|
||||
10
src/output.c
10
src/output.c
@@ -1302,11 +1302,13 @@ output (void)
|
||||
int c;
|
||||
|
||||
/* output_token_defines(ftable); / * JF put out token defines FIRST */
|
||||
if (!semantic_parser) /* JF Put out other stuff */
|
||||
|
||||
/* If using a simple parser the definition of YYSTYPE are put into
|
||||
FTABLE. */
|
||||
if (!semantic_parser)
|
||||
{
|
||||
rewind (fattrs);
|
||||
while ((c = getc (fattrs)) != EOF)
|
||||
putc (c, ftable);
|
||||
size_t size = obstack_object_size (&attrs_obstack);
|
||||
fwrite (obstack_finish (&attrs_obstack), 1, size, ftable);
|
||||
}
|
||||
reader_output_yylsp (ftable);
|
||||
if (debug_flag)
|
||||
|
||||
43
src/reader.c
43
src/reader.c
@@ -341,7 +341,7 @@ copy_at (FILE *fin, FILE *fout, struct obstack *oout, int stack_offset)
|
||||
if (fout)
|
||||
fprintf (fout, "yyloc");
|
||||
if (oout)
|
||||
obstack_grow_literal_string (oout, "yylloc");
|
||||
obstack_grow_literal_string (oout, "yyloc");
|
||||
locations_flag = 1;
|
||||
}
|
||||
else if (isdigit (c) || c == '-')
|
||||
@@ -460,7 +460,7 @@ copy_definition (void)
|
||||
int after_percent;
|
||||
|
||||
if (!no_lines_flag)
|
||||
fprintf (fattrs, "#line %d \"%s\"\n", lineno, infile);
|
||||
obstack_fgrow2 (&attrs_obstack, "#line %d \"%s\"\n", lineno, infile);
|
||||
|
||||
after_percent = 0;
|
||||
|
||||
@@ -471,7 +471,7 @@ copy_definition (void)
|
||||
switch (c)
|
||||
{
|
||||
case '\n':
|
||||
putc (c, fattrs);
|
||||
obstack_1grow (&attrs_obstack, c);
|
||||
lineno++;
|
||||
break;
|
||||
|
||||
@@ -481,18 +481,18 @@ copy_definition (void)
|
||||
|
||||
case '\'':
|
||||
case '"':
|
||||
copy_string (finput, fattrs, 0, c);
|
||||
copy_string (finput, 0, &attrs_obstack, c);
|
||||
break;
|
||||
|
||||
case '/':
|
||||
copy_comment (finput, fattrs, 0);
|
||||
copy_comment (finput, 0, &attrs_obstack);
|
||||
break;
|
||||
|
||||
case EOF:
|
||||
fatal ("%s", _("unterminated `%{' definition"));
|
||||
|
||||
default:
|
||||
putc (c, fattrs);
|
||||
obstack_1grow (&attrs_obstack, c);
|
||||
}
|
||||
|
||||
c = getc (finput);
|
||||
@@ -501,12 +501,10 @@ copy_definition (void)
|
||||
{
|
||||
if (c == '}')
|
||||
return;
|
||||
putc ('%', fattrs);
|
||||
obstack_1grow (&attrs_obstack, '%');
|
||||
}
|
||||
after_percent = 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -762,11 +760,11 @@ token_buffer);
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------.
|
||||
| Copy the union declaration into fattrs (and fdefines), where it is |
|
||||
| made into the definition of YYSTYPE, the type of elements of the |
|
||||
| parser value stack. |
|
||||
`-------------------------------------------------------------------*/
|
||||
/*--------------------------------------------------------------.
|
||||
| Copy the union declaration into ATTRS_OBSTACK (and fdefines), |
|
||||
| where it is made into the definition of YYSTYPE, the type of |
|
||||
| elements of the parser value stack. |
|
||||
`--------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
parse_union_decl (void)
|
||||
@@ -780,11 +778,11 @@ parse_union_decl (void)
|
||||
typed = 1;
|
||||
|
||||
if (!no_lines_flag)
|
||||
fprintf (fattrs, "\n#line %d \"%s\"\n", lineno, infile);
|
||||
obstack_fgrow2 (&attrs_obstack, "\n#line %d \"%s\"\n", lineno, infile);
|
||||
else
|
||||
fprintf (fattrs, "\n");
|
||||
obstack_1grow (&attrs_obstack, '\n');
|
||||
|
||||
fprintf (fattrs, "typedef union");
|
||||
obstack_grow_literal_string (&attrs_obstack, "typedef union");
|
||||
if (fdefines)
|
||||
fprintf (fdefines, "typedef union");
|
||||
|
||||
@@ -792,7 +790,7 @@ parse_union_decl (void)
|
||||
|
||||
while (c != EOF)
|
||||
{
|
||||
putc (c, fattrs);
|
||||
obstack_1grow (&attrs_obstack, c);
|
||||
if (fdefines)
|
||||
putc (c, fdefines);
|
||||
|
||||
@@ -803,7 +801,7 @@ parse_union_decl (void)
|
||||
break;
|
||||
|
||||
case '/':
|
||||
copy_comment2 (finput, fattrs, fdefines, 0);
|
||||
copy_comment2 (finput, 0, fdefines, &attrs_obstack);
|
||||
break;
|
||||
|
||||
case '{':
|
||||
@@ -816,7 +814,7 @@ parse_union_decl (void)
|
||||
count--;
|
||||
if (count <= 0)
|
||||
{
|
||||
fprintf (fattrs, " YYSTYPE;\n");
|
||||
obstack_grow_literal_string (&attrs_obstack, " YYSTYPE;\n");
|
||||
if (fdefines)
|
||||
fprintf (fdefines, " YYSTYPE;\n");
|
||||
/* JF don't choke on trailing semi */
|
||||
@@ -934,7 +932,7 @@ parse_thong_decl (void)
|
||||
/*----------------------------------------------------------------.
|
||||
| Read from finput until `%%' is seen. Discard the `%%'. Handle |
|
||||
| any `%' declarations, and copy the contents of any `%{ ... %}' |
|
||||
| groups to fattrs. |
|
||||
| groups to ATTRS_OBSTACK. |
|
||||
`----------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
@@ -1595,7 +1593,8 @@ readgram (void)
|
||||
/* We used to use `unsigned long' as YYSTYPE on MSDOS,
|
||||
but it seems better to be consistent.
|
||||
Most programs should declare their own type anyway. */
|
||||
fprintf (fattrs, "#ifndef YYSTYPE\n#define YYSTYPE int\n#endif\n");
|
||||
obstack_grow_literal_string (&attrs_obstack,
|
||||
"#ifndef YYSTYPE\n#define YYSTYPE int\n#endif\n");
|
||||
if (fdefines)
|
||||
fprintf (fdefines, "#ifndef YYSTYPE\n#define YYSTYPE int\n#endif\n");
|
||||
}
|
||||
|
||||
@@ -180,3 +180,10 @@ do { \
|
||||
sprintf (buf, Format, Arg1); \
|
||||
obstack_grow (Obs, buf, strlen (buf)); \
|
||||
} while (0)
|
||||
|
||||
#define obstack_fgrow2(Obs, Format, Arg1, Arg2) \
|
||||
do { \
|
||||
char buf[4096]; \
|
||||
sprintf (buf, Format, Arg1, Arg2); \
|
||||
obstack_grow (Obs, buf, strlen (buf)); \
|
||||
} while (0)
|
||||
|
||||
Reference in New Issue
Block a user