[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 19/22] %merge: associate it to its first definition, not the late
From: |
Akim Demaille |
Subject: |
[PATCH 19/22] %merge: associate it to its first definition, not the latest |
Date: |
Sat, 23 Jan 2021 15:55:58 +0100 |
Currently each time we meet %merge we record this location as the
defining location (and symbol). Instead, record the first definition.
In the generated code we go from
yy0->A = merge (*yy0, *yy1);
to
yy0->S = merge (*yy0, *yy1);
where S was indeed the first symbol, and in the diagnostics we go from
glr-regr18.y:30.18-24: error: result type clash on merge function 'merge':
<type2> != <type1>
30 | sym2: sym3 %merge<merge> { $$ = $1; } ;
| ^~~~~~~
glr-regr18.y:29.18-24: note: previous declaration
29 | sym1: sym2 %merge<merge> { $$ = $1; } ;
| ^~~~~~~
glr-regr18.y:31.13-19: error: result type clash on merge function 'merge':
<type3> != <type2>
31 | sym3: %merge<merge> { $$ = 0; } ;
| ^~~~~~~
glr-regr18.y:30.18-24: note: previous declaration
30 | sym2: sym3 %merge<merge> { $$ = $1; } ;
| ^~~~~~~
to
glr-regr18.y:30.18-24: error: result type clash on merge function 'merge':
<type2> != <type1>
30 | sym2: sym3 %merge<merge> { $$ = $1; } ;
| ^~~~~~~
glr-regr18.y:29.18-24: note: previous declaration
29 | sym1: sym2 %merge<merge> { $$ = $1; } ;
| ^~~~~~~
glr-regr18.y:31.13-19: error: result type clash on merge function 'merge':
<type3> != <type1>
31 | sym3: %merge<merge> { $$ = 0; } ;
| ^~~~~~~
glr-regr18.y:29.18-24: note: previous declaration
29 | sym1: sym2 %merge<merge> { $$ = $1; } ;
| ^~~~~~~
where both duplicates are reported against definition 1, rather than
using definition 1 as a reference when diagnosing about definition 2,
and then 2 as a reference for 3.
* src/reader.c (record_merge_function_type): Keep the first definition.
* tests/glr-regression.at: Adjust.
---
src/reader.c | 27 ++++++++++++++++-----------
tests/glr-regression.at | 6 +++---
2 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/src/reader.c b/src/reader.c
index b71dd916a..a43c5e41d 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -122,19 +122,24 @@ record_merge_function_type (int merger, symbol *sym,
location declaration_loc)
merge_function = merge_function->next)
merger_find += 1;
aver (merge_function != NULL && merger_find == merger);
- if (merge_function->sym && merge_function->sym->content->type_name
- && !UNIQSTR_EQ (merge_function->sym->content->type_name, type))
+ if (merge_function->sym && merge_function->sym->content->type_name)
{
- complain (&declaration_loc, complaint,
- _("result type clash on merge function %s: "
- "<%s> != <%s>"),
- quote (merge_function->name), type,
- merge_function->sym->content->type_name);
- subcomplain (&merge_function->type_declaration_loc, complaint,
- _("previous declaration"));
+ if (!UNIQSTR_EQ (merge_function->sym->content->type_name, type))
+ {
+ complain (&declaration_loc, complaint,
+ _("result type clash on merge function %s: "
+ "<%s> != <%s>"),
+ quote (merge_function->name), type,
+ merge_function->sym->content->type_name);
+ subcomplain (&merge_function->type_declaration_loc, complaint,
+ _("previous declaration"));
+ }
+ }
+ else
+ {
+ merge_function->sym = sym;
+ merge_function->type_declaration_loc = declaration_loc;
}
- merge_function->sym = sym;
- merge_function->type_declaration_loc = declaration_loc;
}
/*--------------------------------------.
diff --git a/tests/glr-regression.at b/tests/glr-regression.at
index a6deb9c90..51c6ee5e0 100644
--- a/tests/glr-regression.at
+++ b/tests/glr-regression.at
@@ -1682,11 +1682,11 @@ AT_BISON_CHECK([[-o glr-regr18.c -rall -fcaret
glr-regr18.y]], 1, [],
glr-regr18.y:27.18-24: note: previous declaration
27 | sym1: sym2 %merge<merge> { $$ = $][1; } ;
| ^~~~~~~
-glr-regr18.y:29.13-19: error: result type clash on merge function 'merge':
<type3> != <type2>
+glr-regr18.y:29.13-19: error: result type clash on merge function 'merge':
<type3> != <type1>
29 | sym3: %merge<merge> { $$ = 0; } ;
| ^~~~~~~
-glr-regr18.y:28.18-24: note: previous declaration
- 28 | sym2: sym3 %merge<merge> { $$ = $][1; } ;
+glr-regr18.y:27.18-24: note: previous declaration
+ 27 | sym1: sym2 %merge<merge> { $$ = $][1; } ;
| ^~~~~~~
]])
--
2.30.0
- [PATCH 09/22] cex: add support for $TIME_LIMIT, (continued)
- [PATCH 09/22] cex: add support for $TIME_LIMIT, Akim Demaille, 2021/01/23
- [PATCH 10/22] cex: fix traces: add missing end-of-lines, Akim Demaille, 2021/01/23
- [PATCH 11/22] cex: fix traces: fix display of disabled items, Akim Demaille, 2021/01/23
- [PATCH 12/22] package: codespell, Akim Demaille, 2021/01/23
- [PATCH 13/22] style: YYUSE is private, make it YY_USE, Akim Demaille, 2021/01/23
- [PATCH 14/22] skeletons: introduce "slot"s for symbols, Akim Demaille, 2021/01/23
- [PATCH 15/22] %merge: clearer tests on diagnostics, Akim Demaille, 2021/01/23
- [PATCH 16/22] %merge: let mergers record a typing-symbol, rather than a type, Akim Demaille, 2021/01/23
- [PATCH 17/22] %merge: delegate the generation of calls to mergers to m4, Akim Demaille, 2021/01/23
- [PATCH 18/22] %merge: fix compatibility with api.value.type=union, Akim Demaille, 2021/01/23
- [PATCH 19/22] %merge: associate it to its first definition, not the latest,
Akim Demaille <=
- [PATCH 20/22] package: bump copyrights to 2021, Akim Demaille, 2021/01/23
- [PATCH 21/22] news: update, Akim Demaille, 2021/01/23
- [PATCH 22/22] package: pacify syntax-check, Akim Demaille, 2021/01/23