+2002-04-24 Robert Anisko <robert@lrde.epita.fr>
+
+ * 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.
+
2002-04-23 Paul Eggert <eggert@twinsun.com>
* data/bison.simple: Remove unnecessary commentary and white
/* Using locations. */
#define YYLSP_NEEDED b4_locations_flag
-b4_prologue
+/* Copy the first part of user declarations. */
+b4_pre_prologue
/* Tokens. */
b4_token_defines(b4_tokens)
# define YYSTYPE yystype
#endif
+/* Copy the second part of user declarations. */
+b4_post_prologue
+
#line __oline__ "__ofile__"
#ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N) \
#endif
])
-/* Copy the user declarations. */
-b4_prologue
+/* Copy the first part of user declarations. */
+b4_pre_prologue
/* Enabling traces. */
#ifndef YYDEBUG
# define YYLTYPE b4_ltype
#endif
+/* Copy the second part of user declarations. */
+b4_post_prologue
+
/* Line __line__ of __file__. */
#line __oline__ "__ofile__"
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
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;
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)
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);
}
`-------------------------------------------------------------------*/
static void
-copy_definition (void)
+copy_definition (struct obstack *oout)
{
int c;
/* -1 while reading a character if prev char was %. */
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")));
}
switch (c)
{
case '\n':
- obstack_1grow (&attrs_obstack, c);
+ obstack_1grow (oout, c);
++lineno;
break;
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);
{
if (c == '}')
return;
- obstack_1grow (&attrs_obstack, '%');
+ obstack_1grow (oout, '%');
}
after_percent = 0;
}
/*----------------------------------------------------------------.
| 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
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:
/* 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");
static void yyungetc (int c);
extern void perror (const char *s);
+
+/* Exercise pre-prologue dependency to %union. */
+typedef int value_t;
+
%}
/* Also exercise %union. */
%union
{
- int ival; /* A comment to exercise an old bug. */
+ value_t ival; /* A comment to exercise an old bug. */
};
+/* Exercise post-prologue dependency to %union. */
+%{
+static void id (YYSTYPE *lval);
+%}
+
/* Bison Declarations */
%token CALC_EOF 0 "end of file"
%token <ival> NUM "number"
return res;
}
+void
+id (YYSTYPE* lval)
+{
+}
+
int
main (int argc, const char **argv)
{