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