Fix a longstanding bug uncovered by bro-0.9a9/src/parse.y, which I

got from <http://bro-ids.org/download.html>.  The bug is that
when two actions appeared in succession, the second one was
scanned before the first one was added to the grammar rule
as a midrule action.  Bison then output the incorrect warning
"parse.y:905.17-906.36: warning: unused value: $3".
* src/parse-gram.y (BRACED_CODE, action): These are no longer
associated with a value.
(rhs): Don't invoke grammar_current_rule_action_append.
(action): Invoke it here instead.
* src/reader.c (grammar_midrule_action): Now extern.
(grammar_current_rule_action_append): Don't invoke
grammar_midrule_action; that is now the scanner's job.
* src/reader.h (last_string, last_braced_code_loc):
(grammar_midrule_action): New decls.
* src/scan-gram.l (last_string): Now extern, sigh.
(last_braced_code_loc): New extern variable.
(<INITIAL>"{"): Invoke grammar_midrule_action if the current
rule already has an action.
(<SC_BRACED_CODE>"}"): Set last_braced_code_loc before returning.
* tests/input.at (AT_CHECK_UNUSED_VALUES):
Add some tests to check that the above changes fixed the bug.
This commit is contained in:
Paul Eggert
2006-01-30 07:26:00 +00:00
parent d40ba6c272
commit 6b7022680e
6 changed files with 68 additions and 19 deletions

View File

@@ -87,8 +87,11 @@ static size_t no_cr_read (FILE *, char *, size_t);
static struct obstack obstack_for_string;
/* A string representing the most recently saved token. */
static char *last_string;
char *last_string;
/* The location of the most recently saved token, if it was a
BRACED_CODE token; otherwise, this has an unspecified value. */
location last_braced_code_loc;
#define STRING_GROW \
obstack_grow (&obstack_for_string, yytext, yyleng)
@@ -289,6 +292,8 @@ splice (\\[ \f\t\v]*\n)*
/* Code in between braces. */
"{" {
if (current_rule->action)
grammar_midrule_action ();
STRING_GROW;
token_type = BRACED_CODE;
braces_level = 0;
@@ -618,6 +623,7 @@ splice (\\[ \f\t\v]*\n)*
loc->start = code_start;
val->chars = last_string;
increment_rule_length (*loc);
last_braced_code_loc = *loc;
BEGIN INITIAL;
return token_type;
}