mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-13 14:23:04 +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:
19
src/symtab.h
19
src/symtab.h
@@ -87,10 +87,19 @@ struct symbol
|
||||
{
|
||||
/** The key, name of the symbol. */
|
||||
uniqstr tag;
|
||||
/** The location of its first occurrence. */
|
||||
|
||||
/** The "defining" location. */
|
||||
location location;
|
||||
|
||||
/* Points to the other in the symbol-string pair for an alias. */
|
||||
/** Whether \a location is about the first uses as left-hand side
|
||||
symbol of a rule (true), or simply the first occurrence (e.g.,
|
||||
in a %type, or as a rhs symbol of a rule). The former type of
|
||||
location is more natural in error messages. This Boolean helps
|
||||
moving from location of the first occurrence to first use as
|
||||
lhs. */
|
||||
bool location_of_lhs;
|
||||
|
||||
/** Points to the other in the symbol-string pair for an alias. */
|
||||
symbol *alias;
|
||||
|
||||
/** Whether this symbol is the alias of another or not. */
|
||||
@@ -177,6 +186,12 @@ uniqstr symbol_id_get (symbol const *sym);
|
||||
*/
|
||||
void symbol_make_alias (symbol *sym, symbol *str, location loc);
|
||||
|
||||
/**
|
||||
* This symbol is used as the lhs of a rule. Record this location
|
||||
* as definition point, if not already done.
|
||||
*/
|
||||
void symbol_location_as_lhs_set (symbol *sym, location loc);
|
||||
|
||||
/** Set the \c type_name associated with \c sym.
|
||||
|
||||
Do nothing if passed 0 as \c type_name. */
|
||||
|
||||
Reference in New Issue
Block a user