[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
parser: improve location of string alias errors
From: |
Akim Demaille |
Subject: |
parser: improve location of string alias errors |
Date: |
Thu, 29 Nov 2018 06:08:44 +0100 |
commit d3b2277254f223f12bff0c9da64dbfdf538fede0
Author: Akim Demaille <address@hidden>
Date: Tue Nov 27 21:07:21 2018 +0100
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.
diff --git a/src/parse-gram.y b/src/parse-gram.y
index 52c85c8e..a9f38abf 100644
--- a/src/parse-gram.y
+++ b/src/parse-gram.y
@@ -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);
}
;
diff --git a/src/symtab.c b/src/symtab.c
index a91ac3f8..9a062aaf 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -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"),
diff --git a/tests/input.at b/tests/input.at
index 0ada606e..5e3cbe3d 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -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. ##
## ---------------------- ##
diff --git a/tests/regression.at b/tests/regression.at
index d0cb5107..1a7d777c 100644
--- a/tests/regression.at
+++ b/tests/regression.at
@@ -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])
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- parser: improve location of string alias errors,
Akim Demaille <=