* src/reader.c (parse_union_decl): Instead of handling two obstack

simultaneously, use one to define the `stype' muscle, and use the
value of the latter to fill defines_obstack.
(copy_comment): Remove.
(copy_comment2): Work for a single obstack.
Rename as...
(copy_comment): this.
This commit is contained in:
Akim Demaille
2001-12-15 15:25:15 +00:00
parent 428046f8d4
commit 2666f92821
2 changed files with 34 additions and 63 deletions

View File

@@ -1,3 +1,13 @@
2001-12-15 Akim Demaille <akim@epita.fr>
* src/reader.c (parse_union_decl): Instead of handling two obstack
simultaneously, use one to define the `stype' muscle, and use the
value of the latter to fill defines_obstack.
(copy_comment): Remove.
(copy_comment2): Work for a single obstack.
Rename as...
(copy_comment): this.
2001-12-15 Akim Demaille <akim@epita.fr> 2001-12-15 Akim Demaille <akim@epita.fr>
* src/lex.c, src/lex.h (xgetc): No longer static. * src/lex.c, src/lex.h (xgetc): No longer static.

View File

@@ -233,25 +233,22 @@ copy_identifier (FILE *fin, struct obstack *oout)
ungetc (c, fin); ungetc (c, fin);
} }
/*-----------------------------------------------------------------.
| Dump the wannabee comment from IN to OUT1 and OUT2 (which can be | /*------------------------------------------------------------------.
| NULL). In fact we just saw a `/', which might or might not be a | | Dump the wannabee comment from IN to OOUT. In fact we just saw a |
| comment. In any case, copy what we saw. | | `/', which might or might not be a comment. In any case, copy |
| | | what we saw. |
| OUT2 might be NULL. | `------------------------------------------------------------------*/
`-----------------------------------------------------------------*/
static inline void static inline void
copy_comment2 (FILE *fin, struct obstack *oout1, struct obstack *oout2) copy_comment (FILE *fin, struct obstack *oout)
{ {
int cplus_comment; int cplus_comment;
int ended; int ended;
int c; int c;
/* We read a `/', output it. */ /* We read a `/', output it. */
obstack_1grow (oout1, '/'); obstack_1grow (oout, '/');
if (oout2)
obstack_1grow (oout2, '/');
switch ((c = getc (fin))) switch ((c = getc (fin)))
{ {
@@ -266,9 +263,7 @@ copy_comment2 (FILE *fin, struct obstack *oout1, struct obstack *oout2)
return; return;
} }
obstack_1grow (oout1, c); obstack_1grow (oout, c);
if (oout2)
obstack_1grow (oout2, c);
c = getc (fin); c = getc (fin);
ended = 0; ended = 0;
@@ -278,26 +273,20 @@ copy_comment2 (FILE *fin, struct obstack *oout1, struct obstack *oout2)
{ {
while (c == '*') while (c == '*')
{ {
obstack_1grow (oout1, c); obstack_1grow (oout, c);
if (oout2)
obstack_1grow (oout2, c);
c = getc (fin); c = getc (fin);
} }
if (c == '/') if (c == '/')
{ {
obstack_1grow (oout1, c); obstack_1grow (oout, c);
if (oout2)
obstack_1grow (oout2, c);
ended = 1; ended = 1;
} }
} }
else if (c == '\n') else if (c == '\n')
{ {
lineno++; lineno++;
obstack_1grow (oout1, c); obstack_1grow (oout, c);
if (oout2)
obstack_1grow (oout2, c);
if (cplus_comment) if (cplus_comment)
ended = 1; ended = 1;
else else
@@ -307,27 +296,13 @@ copy_comment2 (FILE *fin, struct obstack *oout1, struct obstack *oout2)
fatal (_("unterminated comment")); fatal (_("unterminated comment"));
else else
{ {
obstack_1grow (oout1, c); obstack_1grow (oout, c);
if (oout2)
obstack_1grow (oout2, c);
c = getc (fin); c = getc (fin);
} }
} }
} }
/*-------------------------------------------------------------------.
| Dump the comment (actually the current string starting with a `/') |
| from FIN to OOUT. |
`-------------------------------------------------------------------*/
static inline void
copy_comment (FILE *fin, struct obstack *oout)
{
copy_comment2 (fin, oout, NULL);
}
/*-----------------------------------------------------------------. /*-----------------------------------------------------------------.
| FIN is pointing to a location (i.e., a `@'). Output to OOUT a | | FIN is pointing to a location (i.e., a `@'). Output to OOUT a |
| reference to this location. STACK_OFFSET is the number of values | | reference to this location. STACK_OFFSET is the number of values |
@@ -755,30 +730,13 @@ parse_union_decl (void)
int count = 0; int count = 0;
bool done = FALSE; bool done = FALSE;
struct obstack union_obstack; struct obstack union_obstack;
const char *prologue = "\
#ifndef YYSTYPE\n\
typedef union";
const char *epilogue = "\
yystype;\n\
# define YYSTYPE yystype\n\
#endif\n";
if (typed) if (typed)
complain (_("multiple %s declarations"), "%union"); complain (_("multiple %s declarations"), "%union");
typed = 1; typed = 1;
/* FIXME: I'm worried: are you sure attrs_obstack is properly
filled? */
/* I don't see any reasons to keep this line, because we should
create a special skeleton for this option. */
if (no_lines_flag)
obstack_1grow (&attrs_obstack, '\n');
obstack_init (&union_obstack); obstack_init (&union_obstack);
obstack_sgrow (&union_obstack, "union"); obstack_sgrow (&union_obstack, "union");
if (defines_flag)
obstack_sgrow (&defines_obstack, prologue);
while (!done) while (!done)
{ {
@@ -786,11 +744,7 @@ typedef union";
/* If C contains '/', it is output by copy_comment (). */ /* If C contains '/', it is output by copy_comment (). */
if (c != '/') if (c != '/')
{ obstack_1grow (&union_obstack, c);
obstack_1grow (&union_obstack, c);
if (defines_flag)
obstack_1grow (&defines_obstack, c);
}
switch (c) switch (c)
{ {
@@ -799,7 +753,7 @@ typedef union";
break; break;
case '/': case '/':
copy_comment2 (finput, &defines_obstack, &union_obstack); copy_comment (finput, &union_obstack);
break; break;
case '{': case '{':
@@ -817,14 +771,21 @@ typedef union";
} }
} }
if (defines_flag)
obstack_sgrow (&defines_obstack, epilogue);
/* JF don't choke on trailing semi */ /* JF don't choke on trailing semi */
c = skip_white_space (); c = skip_white_space ();
if (c != ';') if (c != ';')
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"));
} }