mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-23 11:13:03 +00:00
style: isolate complain_symbol_undeclared
* src/symtab.c (complain_symbol_undeclared): New. Use it. Use quote on the guilty symbol (like GCC does, and we also do elsewhere). * tests/input.at: Adjust.
This commit is contained in:
21
src/symtab.c
21
src/symtab.c
@@ -27,7 +27,11 @@
|
|||||||
#include <hash.h>
|
#include <hash.h>
|
||||||
|
|
||||||
#include "complain.h"
|
#include "complain.h"
|
||||||
|
#include "getargs.h"
|
||||||
#include "gram.h"
|
#include "gram.h"
|
||||||
|
#include "quote.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------.
|
/*----------------------------------------------------------------.
|
||||||
| Symbols sorted by tag. Allocated by table_sort, after which no |
|
| Symbols sorted by tag. Allocated by table_sort, after which no |
|
||||||
@@ -317,6 +321,16 @@ complain_class_redeclared (symbol *sym, symbol_class class, location second)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
complain_symbol_undeclared (symbol *sym)
|
||||||
|
{
|
||||||
|
assert (sym->content->status != declared);
|
||||||
|
complain (&sym->location,
|
||||||
|
sym->content->status == needed ? complaint : Wother,
|
||||||
|
_("symbol %s is used, but is not defined as a token"
|
||||||
|
" and has no rules"),
|
||||||
|
quote (sym->tag));
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
symbol_location_as_lhs_set (symbol *sym, location loc)
|
symbol_location_as_lhs_set (symbol *sym, location loc)
|
||||||
@@ -520,12 +534,7 @@ symbol_check_defined (symbol *sym)
|
|||||||
sym_content *s = sym->content;
|
sym_content *s = sym->content;
|
||||||
if (s->class == unknown_sym)
|
if (s->class == unknown_sym)
|
||||||
{
|
{
|
||||||
assert (s->status != declared);
|
complain_symbol_undeclared (sym);
|
||||||
complain (&sym->location,
|
|
||||||
s->status == needed ? complaint : Wother,
|
|
||||||
_("symbol %s is used, but is not defined as a token"
|
|
||||||
" and has no rules"),
|
|
||||||
sym->tag);
|
|
||||||
s->class = nterm_sym;
|
s->class = nterm_sym;
|
||||||
s->number = nvars++;
|
s->number = nvars++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -822,16 +822,16 @@ exp: bar;
|
|||||||
]])
|
]])
|
||||||
|
|
||||||
AT_BISON_CHECK([-fcaret input.y], [1], [],
|
AT_BISON_CHECK([-fcaret input.y], [1], [],
|
||||||
[[input.y:2.16-18: error: symbol bar is used, but is not defined as a token and has no rules
|
[[input.y:2.16-18: error: symbol 'bar' is used, but is not defined as a token and has no rules
|
||||||
2 | %destructor {} bar
|
2 | %destructor {} bar
|
||||||
| ^~~
|
| ^~~
|
||||||
input.y:1.17-19: warning: symbol baz is used, but is not defined as a token and has no rules [-Wother]
|
input.y:1.17-19: warning: symbol 'baz' is used, but is not defined as a token and has no rules [-Wother]
|
||||||
1 | %printer {} foo baz
|
1 | %printer {} foo baz
|
||||||
| ^~~
|
| ^~~
|
||||||
input.y:1.13-15: warning: symbol foo is used, but is not defined as a token and has no rules [-Wother]
|
input.y:1.13-15: warning: symbol 'foo' is used, but is not defined as a token and has no rules [-Wother]
|
||||||
1 | %printer {} foo baz
|
1 | %printer {} foo baz
|
||||||
| ^~~
|
| ^~~
|
||||||
input.y:3.13-15: warning: symbol qux is used, but is not defined as a token and has no rules [-Wother]
|
input.y:3.13-15: warning: symbol 'qux' is used, but is not defined as a token and has no rules [-Wother]
|
||||||
3 | %type <foo> qux
|
3 | %type <foo> qux
|
||||||
| ^~~
|
| ^~~
|
||||||
]])
|
]])
|
||||||
|
|||||||
Reference in New Issue
Block a user