mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
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:
25
ChangeLog
25
ChangeLog
@@ -1,3 +1,28 @@
|
||||
2006-01-29 Paul Eggert <eggert@cs.ucla.edu>
|
||||
|
||||
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.
|
||||
|
||||
2006-01-27 Paul Eggert <eggert@cs.ucla.edu>
|
||||
|
||||
* src/reader.c (symbol_should_be_used): Renamed from symbol_typed_p.
|
||||
|
||||
@@ -176,7 +176,6 @@ static int current_prec = 0;
|
||||
"%parse-param {...}"
|
||||
"%printer {...}"
|
||||
"%union {...}"
|
||||
BRACED_CODE action
|
||||
PROLOGUE EPILOGUE
|
||||
%printer { fprintf (stderr, "\"%s\"", $$); }
|
||||
STRING string_content
|
||||
@@ -187,7 +186,6 @@ static int current_prec = 0;
|
||||
"%parse-param {...}"
|
||||
"%printer {...}"
|
||||
"%union {...}"
|
||||
BRACED_CODE action
|
||||
PROLOGUE EPILOGUE
|
||||
%type <uniqstr> TYPE
|
||||
%printer { fprintf (stderr, "<%s>", $$); } TYPE
|
||||
@@ -430,7 +428,6 @@ rhs:
|
||||
| rhs symbol
|
||||
{ grammar_current_rule_symbol_append ($2, @2); }
|
||||
| rhs action
|
||||
{ grammar_current_rule_action_append ($2, @2); }
|
||||
| rhs "%prec" symbol
|
||||
{ grammar_current_rule_prec_set ($3, @3); }
|
||||
| rhs "%dprec" INT
|
||||
@@ -444,9 +441,21 @@ symbol:
|
||||
| string_as_id { $$ = $1; }
|
||||
;
|
||||
|
||||
/* Handle the semantics of an action specially, with a mid-rule
|
||||
action, so that grammar_current_rule_action_append is invoked
|
||||
immediately after the braced code is read by the scanner.
|
||||
|
||||
This implementation relies on the LALR(1) parsing algorithm.
|
||||
If grammar_current_rule_action_append were executed in a normal
|
||||
action for this rule, then when the input grammar contains two
|
||||
successive actions, the scanner would have to read both actions
|
||||
before reducing this rule. That wouldn't work, since the scanner
|
||||
relies on all preceding input actions being processed by
|
||||
grammar_current_rule_action_append before it scans the next
|
||||
action. */
|
||||
action:
|
||||
{ grammar_current_rule_action_append (last_string, last_braced_code_loc); }
|
||||
BRACED_CODE
|
||||
{ $$ = $1; }
|
||||
;
|
||||
|
||||
/* A string used as an ID: quote it. */
|
||||
|
||||
@@ -300,7 +300,7 @@ grammar_current_rule_end (location loc)
|
||||
| rule. |
|
||||
`-------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
void
|
||||
grammar_midrule_action (void)
|
||||
{
|
||||
/* Since the action was written out with this rule's number, we must
|
||||
@@ -394,14 +394,13 @@ grammar_current_rule_symbol_append (symbol *sym, location loc)
|
||||
grammar_symbol_append (sym, loc);
|
||||
}
|
||||
|
||||
/* Attach an ACTION to the current rule. If needed, move the previous
|
||||
action as a mid-rule action. */
|
||||
/* Attach an ACTION to the current rule. */
|
||||
|
||||
void
|
||||
grammar_current_rule_action_append (const char *action, location loc)
|
||||
{
|
||||
if (current_rule->action)
|
||||
grammar_midrule_action ();
|
||||
/* There's no need to invoke grammar_midrule_action here, since the
|
||||
scanner already did it if necessary. */
|
||||
current_rule->action = action;
|
||||
current_rule->action_location = loc;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* Input parser for Bison
|
||||
|
||||
Copyright (C) 2000, 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of Bison, the GNU Compiler Compiler.
|
||||
|
||||
@@ -38,6 +39,8 @@ typedef struct merger_list
|
||||
extern FILE *gram_in;
|
||||
extern int gram__flex_debug;
|
||||
extern boundary scanner_cursor;
|
||||
extern char *last_string;
|
||||
extern location last_braced_code_loc;
|
||||
extern int max_left_semantic_context;
|
||||
void scanner_initialize (void);
|
||||
void scanner_free (void);
|
||||
@@ -63,6 +66,7 @@ void grammar_start_symbol_set (symbol *sym, location loc);
|
||||
void prologue_augment (const char *prologue, location loc);
|
||||
void grammar_current_rule_begin (symbol *lhs, location loc);
|
||||
void grammar_current_rule_end (location loc);
|
||||
void grammar_midrule_action (void);
|
||||
void grammar_current_rule_prec_set (symbol *precsym, location loc);
|
||||
void grammar_current_rule_dprec_set (int dprec, location loc);
|
||||
void grammar_current_rule_merge_set (uniqstr name, location loc);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -151,15 +151,21 @@ input.y:6.3-36: warning: unused value: $4
|
||||
input.y:6.3-36: warning: unused value: $5
|
||||
])
|
||||
|
||||
# AT_CHECK_UNUSED_VALUES([INT { $$ } { $$ = $2 } { }],
|
||||
# [input.y:6.3-36: warning: unset value: $$
|
||||
# input.y:6.3-36: warning: unused value: $1
|
||||
# input.y:6.3-36: warning: unused value: $3
|
||||
# input.y:6.3-36: warning: unused value: $4
|
||||
# input.y:6.3-36: warning: unused value: $5
|
||||
# ])
|
||||
AT_CHECK_UNUSED_VALUES([INT INT { } { $$ = $1 + $2; }])
|
||||
|
||||
AT_CHECK_UNUSED_VALUES([INT { $$ = $1 } INT { $$ = $2 + $3 } INT { $$ = $4 + $5 }])
|
||||
AT_CHECK_UNUSED_VALUES([INT INT { $<integer>$ = 1; } { $$ = $1 + $2; }],
|
||||
[input.y:6.3-48: warning: unused value: $3
|
||||
])
|
||||
|
||||
AT_CHECK_UNUSED_VALUES([INT INT { $$; } { $$ = $3; } { }],
|
||||
[input.y:6.3-34: warning: unset value: $$
|
||||
input.y:6.3-34: warning: unused value: $1
|
||||
input.y:6.3-34: warning: unused value: $2
|
||||
input.y:6.3-34: warning: unused value: $4
|
||||
])
|
||||
|
||||
AT_CHECK_UNUSED_VALUES(
|
||||
[INT { $$ = $1; } INT { $$ = $2 + $3; } INT { $$ = $4 + $5; }])
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user