diff options
author | Akim Demaille <akim@epita.fr> | 2002-07-30 11:09:59 +0000 |
---|---|---|
committer | Akim Demaille <akim@epita.fr> | 2002-07-30 11:09:59 +0000 |
commit | 52489d44456f33e4543cee350cc3eaea5a4426fe (patch) | |
tree | 6ec19f812edd1c22125340fe8f4a3f79d5298ab6 | |
parent | e8832397ea06de8049828011aff948b5302ffe66 (diff) | |
download | bison-52489d44456f33e4543cee350cc3eaea5a4426fe.tar.gz |
Normalize conflict related messages.
* src/complain.h, src/complain.c (warn, complain): New.
* src/conflicts.c (conflicts_print): Use them.
(conflict_report_yacc): New, extracted from...
(conflicts_print): here.
* tests/conflicts.at, tests/existing.at: Adjust.
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | src/complain.c | 62 | ||||
-rw-r--r-- | src/complain.h | 8 | ||||
-rw-r--r-- | src/conflicts.c | 57 | ||||
-rw-r--r-- | tests/conflicts.at | 12 | ||||
-rw-r--r-- | tests/existing.at | 2 |
6 files changed, 115 insertions, 36 deletions
@@ -1,5 +1,15 @@ 2002-07-30 Akim Demaille <akim@epita.fr> + Normalize conflict related messages. + + * src/complain.h, src/complain.c (warn, complain): New. + * src/conflicts.c (conflicts_print): Use them. + (conflict_report_yacc): New, extracted from... + (conflicts_print): here. + * tests/conflicts.at, tests/existing.at: Adjust. + +2002-07-30 Akim Demaille <akim@epita.fr> + Report rules which are never reduced by the parser: those hidden by conflicts. diff --git a/src/complain.c b/src/complain.c index 409bca5d..14ef2388 100644 --- a/src/complain.c +++ b/src/complain.c @@ -1,5 +1,5 @@ /* Declaration for error-reporting function for Bison. - Copyright 2000, 2001 Free Software Foundation, Inc. + Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the @@ -142,6 +142,35 @@ warn_at (location, message, va_alist) putc ('\n', stderr); fflush (stderr); } + +void +#if defined VA_START && defined __STDC__ +warn (const char *message, ...) +#else +warn (message, va_alist) + char *message; + va_dcl +#endif +{ +#ifdef VA_START + va_list args; +#endif + + fflush (stdout); + fprintf (stderr, "%s: %s", infile ? infile : program_name, _("warning: ")); + +#ifdef VA_START + VA_START (args, message); + vfprintf (stderr, message, args); + va_end (args); +#else + fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8); +#endif + + ++warn_message_count; + putc ('\n', stderr); + fflush (stderr); +} /*-----------------------------------------------------------. | An error has occurred, but we can proceed, and die later. | @@ -177,6 +206,35 @@ complain_at (location, message, va_alist) putc ('\n', stderr); fflush (stderr); } + +void +#if defined VA_START && defined __STDC__ +complain (const char *message, ...) +#else +complain (message, va_alist) + char *message; + va_dcl +#endif +{ +#ifdef VA_START + va_list args; +#endif + + fflush (stdout); + fprintf (stderr, "%s: ", infile ? infile : program_name); + +#ifdef VA_START + VA_START (args, message); + vfprintf (stderr, message, args); + va_end (args); +#else + fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8); +#endif + + ++complain_message_count; + putc ('\n', stderr); + fflush (stderr); +} /*-------------------------------------------------. | A severe error has occurred, we cannot proceed. | @@ -186,7 +244,7 @@ void #if defined VA_START && defined __STDC__ fatal_at (location_t location, const char *message, ...) #else -fatal (location, message, va_alist) +fatal_at (location, message, va_alist) location_t location; char *message; va_dcl diff --git a/src/complain.h b/src/complain.h index c2ae09dd..0541e299 100644 --- a/src/complain.h +++ b/src/complain.h @@ -29,11 +29,17 @@ extern "C" { /* Informative messages, but we proceed. */ +void warn (const char *format, ...) + __attribute__ ((__format__ (__printf__, 1, 2))); + void warn_at (location_t location, const char *format, ...) __attribute__ ((__format__ (__printf__, 2, 3))); /* Something bad happen, but let's continue and die later. */ +void complain (const char *format, ...) + __attribute__ ((__format__ (__printf__, 1, 2))); + void complain_at (location_t location, const char *format, ...) __attribute__ ((__format__ (__printf__, 2, 3))); @@ -46,7 +52,9 @@ void fatal_at (location_t location, const char *format, ...) __attribute__ ((__format__ (__printf__, 2, 3))); # else +void warn (); void warn_at (); +void complain (); void complain_at (); void fatal (); void fatal_at (); diff --git a/src/conflicts.c b/src/conflicts.c index 9dabd70b..cbf385ac 100644 --- a/src/conflicts.c +++ b/src/conflicts.c @@ -385,6 +385,7 @@ count_rr_conflicts (state_t *state, int one_per_token) return rrc_count; } + /*--------------------------------------------------------------. | Return a human readable string which reports shift/reduce and | | reduce/reduce conflict numbers (SRC_NUM, RRC_NUM). | @@ -416,14 +417,32 @@ conflict_report (int src_num, int rrc_num) cp += strlen (cp); } - *cp++ = '.'; - *cp++ = '\n'; *cp++ = '\0'; return res; } +/*----------------------------------------------------------------. +| Same as above, but report the number of conflicts a` la POSIX. | +`----------------------------------------------------------------*/ + +static void +conflict_report_yacc (int src_num, int rrc_num) +{ + /* If invoked with `--yacc', use the output format specified by + POSIX. */ + fprintf (stderr, _("conflicts: ")); + if (src_num > 0) + fprintf (stderr, _(" %d shift/reduce"), src_num); + if (src_num > 0 && rrc_num > 0) + fprintf (stderr, ","); + if (rrc_num > 0) + fprintf (stderr, _(" %d reduce/reduce"), rrc_num); + putc ('\n', stderr); +} + + /*-----------------------------------------------------------. | Output the detailed description of states with conflicts. | `-----------------------------------------------------------*/ @@ -443,8 +462,9 @@ conflicts_output (FILE *out) if (conflicts[i]) { fprintf (out, _("State %d contains "), i); - fputs (conflict_report (count_sr_conflicts (s), - count_rr_conflicts (s, TRUE)), out); + fprintf (out, "%s.\n", + conflict_report (count_sr_conflicts (s), + count_rr_conflicts (s, TRUE))); printed_sth = TRUE; } } @@ -530,32 +550,15 @@ conflicts_print (void) /* Report the total number of conflicts on STDERR. */ if (yacc_flag) - { - /* If invoked with `--yacc', use the output format specified by - POSIX. */ - fprintf (stderr, _("conflicts: ")); - if (src_total > 0) - fprintf (stderr, _(" %d shift/reduce"), src_total); - if (src_total > 0 && rrc_total > 0) - fprintf (stderr, ","); - if (rrc_total > 0) - fprintf (stderr, _(" %d reduce/reduce"), rrc_total); - putc ('\n', stderr); - } + conflict_report_yacc (src_total, rrc_total); else - { - fprintf (stderr, _("%s contains "), infile); - fputs (conflict_report (src_total, rrc_total), stderr); - } + warn ("%s", conflict_report (src_total, rrc_total)); if (expected_conflicts != -1 && !src_ok) - { - complain_message_count++; - fprintf (stderr, ngettext ("expected %d shift/reduce conflict\n", - "expected %d shift/reduce conflicts\n", - expected_conflicts), - expected_conflicts); - } + complain (ngettext ("expected %d shift/reduce conflict", + "expected %d shift/reduce conflicts", + expected_conflicts), + expected_conflicts); } diff --git a/tests/conflicts.at b/tests/conflicts.at index d0da937b..6a9ef9bd 100644 --- a/tests/conflicts.at +++ b/tests/conflicts.at @@ -142,7 +142,7 @@ exp: exp OP exp | NUM; ]]) AT_CHECK([bison input.y -o input.c --report=all], 0, [], -[input.y contains 1 shift/reduce conflict. +[input.y: warning: 1 shift/reduce conflict ]) # Check the contents of the report. @@ -371,7 +371,7 @@ id : '0'; ]]) AT_CHECK([bison input.y -o input.c --report=all], 0, [], -[[input.y contains 1 reduce/reduce conflict. +[[input.y: warning: 1 reduce/reduce conflict input.y:4.4-8: warning: rule never reduced because of conflicts: id: '0' ]]) @@ -483,8 +483,8 @@ exp: exp OP exp | NUM; ]]) AT_CHECK([bison input.y -o input.c], 1, [], -[input.y contains 1 shift/reduce conflict. -expected 0 shift/reduce conflicts +[input.y: warning: 1 shift/reduce conflict +input.y: expected 0 shift/reduce conflicts ]) AT_CLEANUP @@ -520,7 +520,7 @@ exp: exp OP exp | NUM; ]]) AT_CHECK([bison input.y -o input.c], 1, [], -[input.y contains 1 shift/reduce conflict. -expected 2 shift/reduce conflicts +[input.y: warning: 1 shift/reduce conflict +input.y: expected 2 shift/reduce conflicts ]) AT_CLEANUP diff --git a/tests/existing.at b/tests/existing.at index 6a1f7f39..bad9858e 100644 --- a/tests/existing.at +++ b/tests/existing.at @@ -1191,7 +1191,7 @@ ARGUMENT_LIST : EXPRESSION { mout(MENDSEP); # don't actually check the output. But SEGV is watching us, and # so might do dmalloc. AT_CHECK([[bison --verbose --defines input.y]], 0, [], -[[input.y contains 78 shift/reduce conflicts and 10 reduce/reduce conflicts. +[[input.y: warning: 78 shift/reduce conflicts and 10 reduce/reduce conflicts ]]) AT_CHECK([[grep '^State.*contains' input.output]], 0, |