* tests/calc.at: Exercise prologue splitting.

* data/bison.simple, data/bison.c++: Use `b4_pre_prologue' and
`b4_post_prologue' instead of `b4_prologue'.
* src/output.c (prepare): Add the `pre_prologue' and `post_prologue'
muscles.
(output): Free pre_prologue_obstack and post_prologue_obstack.
* src/files.h, src/files.c (attrs_obstack): Remove.
(pre_prologue_obstack, post_prologue_obstack): New.
* src/reader.c (copy_definition): Add a parameter to specify the
obstack to fill, instead of using attrs_obstack unconditionally.
(read_declarations): Pass pre_prologue_obstack to copy_definition if
`%union' has not yet been seen, pass post_prologue_obstack otherwise.
This commit is contained in:
Robert Anisko
2002-04-24 16:22:57 +00:00
parent b98ec53ee4
commit 0dd1580afc
8 changed files with 66 additions and 19 deletions

View File

@@ -33,8 +33,9 @@ const char *base_name PARAMS ((char const *name));
FILE *finput = NULL;
struct obstack action_obstack;
struct obstack attrs_obstack;
struct obstack output_obstack;
struct obstack pre_prologue_obstack;
struct obstack post_prologue_obstack;
/* Initializing some values below (such SPEC_NAME_PREFIX to `yy') is
tempting, but don't do that: for the time being our handling of the

View File

@@ -50,7 +50,8 @@ extern FILE *finput;
extern struct obstack action_obstack;
/* If semantic parser, output a .h file that defines YYSTYPE... */
extern struct obstack attrs_obstack;
extern struct obstack pre_prologue_obstack;
extern struct obstack post_prologue_obstack;
/* The verbose output. */
extern struct obstack output_obstack;

View File

@@ -1092,8 +1092,10 @@ prepare (void)
MUSCLE_INSERT_INT ("defines_flag", defines_flag);
/* Copy definitions in directive. */
obstack_1grow (&attrs_obstack, 0);
muscle_insert ("prologue", obstack_finish (&attrs_obstack));
obstack_1grow (&pre_prologue_obstack, 0);
obstack_1grow (&post_prologue_obstack, 0);
muscle_insert ("pre_prologue", obstack_finish (&pre_prologue_obstack));
muscle_insert ("post_prologue", obstack_finish (&post_prologue_obstack));
/* Find the right skeleton file. */
if (!skeleton)
@@ -1131,5 +1133,6 @@ output (void)
obstack_free (&muscle_obstack, NULL);
obstack_free (&format_obstack, NULL);
obstack_free (&action_obstack, NULL);
obstack_free (&attrs_obstack, NULL);
obstack_free (&pre_prologue_obstack, NULL);
obstack_free (&post_prologue_obstack, NULL);
}

View File

@@ -591,7 +591,7 @@ copy_dollar (FILE *fin, struct obstack *oout,
`-------------------------------------------------------------------*/
static void
copy_definition (void)
copy_definition (struct obstack *oout)
{
int c;
/* -1 while reading a character if prev char was %. */
@@ -599,7 +599,7 @@ copy_definition (void)
if (!no_lines_flag)
{
obstack_fgrow2 (&attrs_obstack, muscle_find ("linef"),
obstack_fgrow2 (oout, muscle_find ("linef"),
lineno, quotearg_style (c_quoting_style,
muscle_find ("filename")));
}
@@ -613,7 +613,7 @@ copy_definition (void)
switch (c)
{
case '\n':
obstack_1grow (&attrs_obstack, c);
obstack_1grow (oout, c);
++lineno;
break;
@@ -623,18 +623,18 @@ copy_definition (void)
case '\'':
case '"':
copy_string (finput, &attrs_obstack, c);
copy_string (finput, oout, c);
break;
case '/':
copy_comment (finput, &attrs_obstack);
copy_comment (finput, oout);
break;
case EOF:
fatal ("%s", _("unterminated `%{' definition"));
default:
obstack_1grow (&attrs_obstack, c);
obstack_1grow (oout, c);
}
c = getc (finput);
@@ -643,7 +643,7 @@ copy_definition (void)
{
if (c == '}')
return;
obstack_1grow (&attrs_obstack, '%');
obstack_1grow (oout, '%');
}
after_percent = 0;
}
@@ -1154,7 +1154,7 @@ parse_skel_decl (void)
/*----------------------------------------------------------------.
| Read from finput until `%%' is seen. Discard the `%%'. Handle |
| any `%' declarations, and copy the contents of any `%{ ... %}' |
| groups to ATTRS_OBSTACK. |
| groups to PRE_PROLOGUE_OBSTACK or POST_PROLOGUE_OBSTACK. |
`----------------------------------------------------------------*/
static void
@@ -1174,7 +1174,10 @@ read_declarations (void)
return;
case tok_percent_left_curly:
copy_definition ();
if (!typed)
copy_definition (&pre_prologue_obstack);
else
copy_definition (&post_prologue_obstack);
break;
case tok_token:
@@ -1854,8 +1857,9 @@ reader (void)
/* Initialize the obstacks. */
obstack_init (&action_obstack);
obstack_init (&attrs_obstack);
obstack_init (&output_obstack);
obstack_init (&pre_prologue_obstack);
obstack_init (&post_prologue_obstack);
finput = xfopen (infile, "r");