mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-10 12:53:03 +00:00
warnings: use the regular interface for s/r and r/r conflicts
The current routines used to display s/r and r/r conflicts are both
inconvenient from the programmer point of view (they do not use the
warning infrastructure) and for the user (the messages are rather
terse, not necessarily pleasant to read, and because they don't use
the same routines, they look different).
It was due to the belief (dating back to the initial checked-in
version of Bison) that, at some point, POSIX Yacc mandated the format
for these messages. Today, the Open Group's manual page for Yacc,
<http://pubs.opengroup.org/onlinepubs/009695399/utilities/yacc.html>,
explicitly states that the format of these messages is unspecified.
See commit be7280480c and
<http://lists.gnu.org/archive/html/bison-patches/2002-12/msg00027.html>.
For a discussion on the chosen warning format, see
http://lists.gnu.org/archive/html/bison-patches/2012-09/msg00039.html
In an effort to factor the handling of errors and warnings, use the
Bison warning routines to report these messages.
* src/conflicts.c (conflicts_print): Rewrite with clearer sections
about S/R and then R/R conflicts.
(conflict_report): Remove, inlined in its sole
caller...
(conflicts_output): here.
* tests/conflicts.at, tests/existing.at, tests/glr-regression.at,
* tests/reduce.at, tests/regression.at: Adjust the expected results.
* NEWS: Update.
This commit is contained in:
124
src/conflicts.c
124
src/conflicts.c
@@ -505,22 +505,6 @@ count_rr_conflicts (bool one_per_token)
|
||||
return res;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------.
|
||||
| Report the number of conflicts, using the Yacc format. |
|
||||
`--------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
conflict_report (FILE *out, size_t src_num, size_t rrc_num)
|
||||
{
|
||||
if (src_num && rrc_num)
|
||||
fprintf (out, _("conflicts: %zd shift/reduce, %zd reduce/reduce\n"),
|
||||
src_num, rrc_num);
|
||||
else if (src_num)
|
||||
fprintf (out, _("conflicts: %zd shift/reduce\n"), src_num);
|
||||
else if (rrc_num)
|
||||
fprintf (out, _("conflicts: %zd reduce/reduce\n"), rrc_num);
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------------------------.
|
||||
| Output the detailed description of states with conflicts. |
|
||||
@@ -536,10 +520,17 @@ conflicts_output (FILE *out)
|
||||
state *s = states[i];
|
||||
if (conflicts[i])
|
||||
{
|
||||
int src = count_state_sr_conflicts (s);
|
||||
int rrc = count_state_rr_conflicts (s, true);
|
||||
fprintf (out, _("State %d "), i);
|
||||
conflict_report (out,
|
||||
count_state_sr_conflicts (s),
|
||||
count_state_rr_conflicts (s, true));
|
||||
if (src && rrc)
|
||||
fprintf (out,
|
||||
_("conflicts: %d shift/reduce, %d reduce/reduce\n"),
|
||||
src, rrc);
|
||||
else if (src)
|
||||
fprintf (out, _("conflicts: %d shift/reduce\n"), src);
|
||||
else if (rrc)
|
||||
fprintf (out, _("conflicts: %d reduce/reduce\n"), rrc);
|
||||
printed_sth = true;
|
||||
}
|
||||
}
|
||||
@@ -568,64 +559,57 @@ conflicts_total_count (void)
|
||||
void
|
||||
conflicts_print (void)
|
||||
{
|
||||
/* Is the number of SR conflicts OK? Either EXPECTED_CONFLICTS is
|
||||
not set, and then we want 0 SR, or else it is specified, in which
|
||||
case we want equality. */
|
||||
bool src_ok;
|
||||
bool rrc_ok;
|
||||
|
||||
int src_expected;
|
||||
int rrc_expected;
|
||||
|
||||
int src_total = count_sr_conflicts ();
|
||||
int rrc_total = count_rr_conflicts (true);
|
||||
|
||||
if (! glr_parser && expected_rr_conflicts != -1)
|
||||
{
|
||||
complain (Wother, _("%%expect-rr applies only to GLR parsers"));
|
||||
expected_rr_conflicts = -1;
|
||||
}
|
||||
|
||||
src_expected = expected_sr_conflicts == -1 ? 0 : expected_sr_conflicts;
|
||||
rrc_expected = expected_rr_conflicts == -1 ? 0 : expected_rr_conflicts;
|
||||
src_ok = src_total == src_expected;
|
||||
rrc_ok = rrc_total == rrc_expected;
|
||||
/* Screams for factoring, but almost useless because of the
|
||||
different strings to translate. */
|
||||
{
|
||||
int total = count_sr_conflicts ();
|
||||
// If %expect is not used, but %expect-rr is, then expect 0 sr.
|
||||
int expected =
|
||||
(expected_sr_conflicts == -1 && expected_rr_conflicts != -1)
|
||||
? 0
|
||||
: expected_sr_conflicts;
|
||||
if (expected != -1)
|
||||
{
|
||||
if (expected != total)
|
||||
complain (complaint,
|
||||
_("shift/reduce conflicts: %d found, %d expected"),
|
||||
total, expected);
|
||||
}
|
||||
else if (total)
|
||||
complain (Wconflicts_sr,
|
||||
ngettext ("%d shift/reduce conflict",
|
||||
"%d shift/reduce conflicts",
|
||||
total),
|
||||
total);
|
||||
}
|
||||
|
||||
/* If there are as many RR conflicts and SR conflicts as
|
||||
expected, then there is nothing to report. */
|
||||
if (rrc_ok & src_ok)
|
||||
return;
|
||||
|
||||
/* Report the total number of conflicts on STDERR. */
|
||||
if (expected_sr_conflicts == -1 && expected_rr_conflicts == -1)
|
||||
{
|
||||
if (!(warnings_flag & Wconflicts_sr))
|
||||
src_total = 0;
|
||||
if (!(warnings_flag & Wconflicts_rr))
|
||||
rrc_total = 0;
|
||||
}
|
||||
if (src_total | rrc_total)
|
||||
{
|
||||
if (expected_sr_conflicts == -1 && expected_rr_conflicts == -1)
|
||||
set_warning_issued ();
|
||||
if (! yacc_flag)
|
||||
fprintf (stderr, "%s: ", current_file);
|
||||
conflict_report (stderr, src_total, rrc_total);
|
||||
}
|
||||
|
||||
if (expected_sr_conflicts != -1 || expected_rr_conflicts != -1)
|
||||
{
|
||||
if (! src_ok)
|
||||
complain (complaint, ngettext ("expected %d shift/reduce conflict",
|
||||
"expected %d shift/reduce conflicts",
|
||||
src_expected),
|
||||
src_expected);
|
||||
if (! rrc_ok)
|
||||
complain (complaint, ngettext ("expected %d reduce/reduce conflict",
|
||||
"expected %d reduce/reduce conflicts",
|
||||
rrc_expected),
|
||||
rrc_expected);
|
||||
}
|
||||
{
|
||||
int total = count_rr_conflicts (true);
|
||||
// If %expect-rr is not used, but %expect is, then expect 0 rr.
|
||||
int expected =
|
||||
(expected_rr_conflicts == -1 && expected_sr_conflicts != -1)
|
||||
? 0
|
||||
: expected_rr_conflicts;
|
||||
if (expected != -1)
|
||||
{
|
||||
if (expected != total)
|
||||
complain (complaint,
|
||||
_("reduce/reduce conflicts: %d found, %d expected"),
|
||||
total, expected);
|
||||
}
|
||||
else if (total)
|
||||
complain (Wconflicts_rr,
|
||||
ngettext ("%d reduce/reduce conflict",
|
||||
"%d reduce/reduce conflicts",
|
||||
total),
|
||||
total);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user