mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-12 22:03:02 +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:
@@ -105,6 +105,7 @@ symbol_new (uniqstr tag, location loc)
|
||||
|
||||
res->tag = tag;
|
||||
res->location = loc;
|
||||
res->location_of_lhs = false;
|
||||
res->alias = NULL;
|
||||
res->content = sym_content_new (res);
|
||||
res->is_alias = false;
|
||||
@@ -189,6 +190,7 @@ code_props_type_string (code_props_type kind)
|
||||
assert (0);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------.
|
||||
| Create a new semantic type, named TAG. |
|
||||
`----------------------------------------*/
|
||||
@@ -307,6 +309,13 @@ semantic_type_redeclaration (semantic_type *s, const char *what, location first,
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
symbol_location_as_lhs_set (symbol *sym, location loc)
|
||||
{
|
||||
if (!sym->location_of_lhs)
|
||||
sym->location = loc;
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------.
|
||||
| Set the TYPE_NAME associated with SYM. Does nothing if passed 0 |
|
||||
|
||||
Reference in New Issue
Block a user