mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-12 05:43:03 +00:00
symbol: use the first occurrence as an LHS as defining location
Currently on the following grammar:
%type <foo> foo
%%
start: foo | bar | "baz"
foo: foo
bar: bar
bison reports:
warning: 2 nonterminals useless in grammar [-Wother]
warning: 4 rules useless in grammar [-Wother]
1.13-15: warning: nonterminal useless in grammar: foo [-Wother]
%type <foo> foo
^^^
3.14-16: warning: nonterminal useless in grammar: bar [-Wother]
start: foo | bar | "baz"
^^^
[...]
i.e., the location of the first occurrence of a symbol is taken as its
definition point. In the case of nonterminals, the first occurrence
as a left-hand side of a rule makes more sense:
warning: 2 nonterminals useless in grammar [-Wother]
warning: 4 rules useless in grammar [-Wother]
4.1-3: warning: nonterminal useless in grammar: foo [-Wother]
foo: foo
^^^
5.1-3: warning: nonterminal useless in grammar: bar [-Wother]
bar: bar
^^^
[...]
* src/symtab.h, src/symtab.c (symbol::location_of_lhs): New.
(symbol_location_as_lhs_set): New.
* src/parse-gram.y (current_lhs): Use it.
* tests/reduce.at: Update locations.
This commit is contained in:
@@ -254,9 +254,9 @@ not-reduced.y: warning: 3 rules useless in grammar [-Wother]
|
||||
not-reduced.y:14.1-13: warning: nonterminal useless in grammar: not_reachable [-Wother]
|
||||
not_reachable: useful { /* A not reachable action. */ }
|
||||
^^^^^^^^^^^^^
|
||||
not-reduced.y:11.6-19: warning: nonterminal useless in grammar: non_productive [-Wother]
|
||||
| non_productive { /* A non productive action. */ }
|
||||
^^^^^^^^^^^^^^
|
||||
not-reduced.y:17.1-14: warning: nonterminal useless in grammar: non_productive [-Wother]
|
||||
non_productive: non_productive useless_token
|
||||
^^^^^^^^^^^^^^
|
||||
not-reduced.y:11.6-57: warning: rule useless in grammar [-Wother]
|
||||
| non_productive { /* A non productive action. */ }
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@@ -330,12 +330,12 @@ indirection: underivable;
|
||||
AT_BISON_CHECK([[-fcaret input.y]], 0, [],
|
||||
[[input.y: warning: 2 nonterminals useless in grammar [-Wother]
|
||||
input.y: warning: 3 rules useless in grammar [-Wother]
|
||||
input.y:5.15-25: warning: nonterminal useless in grammar: underivable [-Wother]
|
||||
exp: useful | underivable;
|
||||
^^^^^^^^^^^
|
||||
input.y:6.14-24: warning: nonterminal useless in grammar: indirection [-Wother]
|
||||
input.y:6.1-11: warning: nonterminal useless in grammar: underivable [-Wother]
|
||||
underivable: indirection;
|
||||
^^^^^^^^^^^
|
||||
^^^^^^^^^^^
|
||||
input.y:7.1-11: warning: nonterminal useless in grammar: indirection [-Wother]
|
||||
indirection: underivable;
|
||||
^^^^^^^^^^^
|
||||
input.y:5.15-25: warning: rule useless in grammar [-Wother]
|
||||
exp: useful | underivable;
|
||||
^^^^^^^^^^^
|
||||
|
||||
Reference in New Issue
Block a user