parser: improve location of string alias errors

* src/parse-gram.y (symbol_def): Pass the right location for symbol_make_alias.
* tests/regression.at (Duplicate string): Move to...
* tests/input.at: here.
(Token collisions): New.
This commit is contained in:
Akim Demaille
2018-11-27 21:07:21 +01:00
parent d92ed9d9f7
commit 2c5e933672
4 changed files with 63 additions and 37 deletions

View File

@@ -530,7 +530,7 @@ symbol_def:
}
symbol_class_set ($1, current_class, @1, true);
symbol_type_set ($1, current_type, @1);
symbol_make_alias ($1, $2, @$);
symbol_make_alias ($1, $2, @2);
}
| id INT string_as_id
{
@@ -545,7 +545,7 @@ symbol_def:
symbol_class_set ($1, current_class, @1, true);
symbol_type_set ($1, current_type, @1);
symbol_user_token_number_set ($1, $2, @2);
symbol_make_alias ($1, $3, @$);
symbol_make_alias ($1, $3, @3);
}
;

View File

@@ -462,9 +462,7 @@ symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring)
void
symbol_user_token_number_set (symbol *sym, int user_token_number, location loc)
{
int *user_token_numberp;
user_token_numberp = &sym->content->user_token_number;
int *user_token_numberp = &sym->content->user_token_number;
if (*user_token_numberp != USER_NUMBER_UNDEFINED
&& *user_token_numberp != user_token_number)
complain (&loc, complaint, _("redefining user token number of %s"),

View File

@@ -801,6 +801,63 @@ input.y:7.6-8: warning: unset value: $$ [-Wother]
AT_CLEANUP
## ------------------ ##
## Duplicate string. ##
## ------------------ ##
AT_SETUP([Duplicate string])
AT_BISON_OPTION_PUSHDEFS
AT_DATA([input.y],
[[/* 'Bison -v' used to dump core when two tokens are defined with the same
string, as LE and GE below. */
%token NUM
%token LE "<="
%token GE "<="
%%
exp: '(' exp ')' | NUM ;
%%
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-v -o input.c input.y], 0, [],
[[input.y:6.11-14: warning: symbol "<=" used more than once as a literal string [-Wother]
]])
AT_CLEANUP
## ------------------ ##
## Token collisions. ##
## ------------------ ##
AT_SETUP([Token collisions])
AT_DATA([[input.y]],
[[%token FOO 42 "foo"
BAR 42 "foo"
%%
exp: FOO BAR;
]])
AT_BISON_CHECK([-fcaret input.y], [1], [],
[[input.y:2.17-21: warning: symbol "foo" used more than once as a literal string [-Wother]
BAR 42 "foo"
^^^^^
input.y:2.10-12: error: user token number 42 redeclaration for BAR
BAR 42 "foo"
^^^
input.y:1.8-10: previous declaration for FOO
%token FOO 42 "foo"
^^^
]])
AT_CLEANUP
## ---------------------- ##
## Incompatible Aliases. ##
## ---------------------- ##

View File

@@ -188,35 +188,6 @@ AT_CHECK([grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
AT_CLEANUP
## ------------------ ##
## Duplicate string. ##
## ------------------ ##
AT_SETUP([Duplicate string])
AT_BISON_OPTION_PUSHDEFS
AT_DATA([input.y],
[[/* 'Bison -v' used to dump core when two tokens are defined with the same
string, as LE and GE below. */
%token NUM
%token LE "<="
%token GE "<="
%%
exp: '(' exp ')' | NUM ;
%%
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-v -o input.c input.y], 0, [],
[[input.y:6.8-14: warning: symbol "<=" used more than once as a literal string [-Wother]
]])
AT_CLEANUP
## ------------------- ##
## Rule Line Numbers. ##
## ------------------- ##
@@ -477,15 +448,15 @@ AT_BISON_OPTION_POPDEFS
# the user specification is eliminated.
AT_BISON_CHECK([-o input.c input.y], [[0]], [[]],
[[input.y:22.8-14: warning: symbol SPECIAL redeclared [-Wother]
input.y:22.8-63: warning: symbol "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!" used more than once as a literal string [-Wother]
input.y:22.16-63: warning: symbol "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!" used more than once as a literal string [-Wother]
]])
AT_BISON_CHECK([-fcaret -o input.c input.y], [[0]], [[]],
[[input.y:22.8-14: warning: symbol SPECIAL redeclared [-Wother]
%token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
^^^^^^^
input.y:22.8-63: warning: symbol "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!" used more than once as a literal string [-Wother]
input.y:22.16-63: warning: symbol "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!" used more than once as a literal string [-Wother]
%token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
]])
AT_COMPILE([input])