errors: introduce the -Werror=CATEGORY option

This new option is a lot more flexible than the previous one. Its
details will be discussed in the NEWS and info file, in a forthcoming
change.

If no category is specified (ie: used as simply "-Werror"), the
functionality is the same as before.

* src/complain.c (errors_flag): New variable.
(set_warning_issued): Accept warning categories as an argument.
* src/complain.h (Wall): Better definition.
* src/getargs.c (flags_argmatch): Support for the new format.
(usage): Update -Werror to -Werror[=CATEGORY] format.

* src/complain.c (errors_flag): New variable.
(set_warning_issued): Accept warning categories as an argument.
* src/complain.h (Wall): Better definition.
* src/getargs.c (flags_argmatch): Support for the new format.
(usage): Update -Werror to -Werror=[CATEGORY] format.

Signed-off-by: Akim Demaille <akim@lrde.epita.fr>
This commit is contained in:
Theophile Ranquet
2012-09-27 10:52:45 +00:00
committed by Akim Demaille
parent 11b192127c
commit 9503b0a4a8
4 changed files with 45 additions and 25 deletions

9
NEWS
View File

@@ -90,9 +90,8 @@ GNU Bison NEWS
foo.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] foo.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
foo.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr] foo.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
$ bison -Werror foo.y $ bison -Werror foo.y
bison: warnings being treated as errors foo.y: error: 1 shift/reduce conflict [-Werror=conflicts-sr]
foo.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] foo.y: error: 2 reduce/reduce conflicts [-Werror=conflicts-rr]
foo.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
When %expect or %expect-rr is used, such as with bar.y: When %expect or %expect-rr is used, such as with bar.y:
@@ -111,8 +110,8 @@ GNU Bison NEWS
New one: New one:
$ bison bar.y $ bison bar.y
bar.y: shift/reduce conflicts: 1 found, 0 expected bar.y: error: shift/reduce conflicts: 1 found, 0 expected
bar.y: reduce/reduce conflicts: 2 found, 0 expected bar.y: error: reduce/reduce conflicts: 2 found, 0 expected
** Additional yylex/yyparse arguments ** Additional yylex/yyparse arguments

View File

@@ -32,6 +32,8 @@
warnings warnings_flag = warnings warnings_flag =
Wconflicts_sr | Wconflicts_rr | Wdeprecated | Wother; Wconflicts_sr | Wconflicts_rr | Wdeprecated | Wother;
warnings errors_flag;
bool complaint_issued; bool complaint_issued;
static unsigned *indent_ptr = 0; static unsigned *indent_ptr = 0;
@@ -141,7 +143,7 @@ complains (const location *loc, warnings flags, const char *message,
} }
else if (warnings_flag & Wyacc) else if (warnings_flag & Wyacc)
{ {
set_warning_issued (); set_warning_issued (Wyacc);
error_message (loc, flags, error_message (loc, flags,
indent_ptr && *indent_ptr ? NULL : _("warning"), indent_ptr && *indent_ptr ? NULL : _("warning"),
message, args); message, args);
@@ -149,7 +151,7 @@ complains (const location *loc, warnings flags, const char *message,
} }
else if (warnings_flag & flags) else if (warnings_flag & flags)
{ {
set_warning_issued (); set_warning_issued (flags);
error_message (loc, flags, error_message (loc, flags,
indent_ptr && *indent_ptr ? NULL : _("warning"), indent_ptr && *indent_ptr ? NULL : _("warning"),
message, args); message, args);
@@ -191,10 +193,10 @@ void complain_at_indent (location loc, warnings flags, unsigned *indent,
`--------------------------------*/ `--------------------------------*/
void void
set_warning_issued (void) set_warning_issued (warnings warning)
{ {
static bool warning_issued = false; static bool warning_issued = false;
if (!warning_issued && (warnings_flag & Werror)) if (!warning_issued && (warning & warnings_flag & errors_flag))
{ {
fprintf (stderr, "%s: warnings being treated as errors\n", program_name); fprintf (stderr, "%s: warnings being treated as errors\n", program_name);
complaint_issued = true; complaint_issued = true;

View File

@@ -35,16 +35,22 @@ typedef enum
Wdeprecated = 1 << 4, /**< Obsolete constructs. */ Wdeprecated = 1 << 4, /**< Obsolete constructs. */
Wother = 1 << 5, /**< All other warnings. */ Wother = 1 << 5, /**< All other warnings. */
Werror = 1 << 10, /**< Warnings are treated as errors. */ Werror = 1 << 10, /** This bit is no longer used. */
complaint = 1 << 11, /**< All complaints. */ complaint = 1 << 11, /**< All complaints. */
fatal = 1 << 12, /**< All fatal errors. */ fatal = 1 << 12, /**< All fatal errors. */
silent = 1 << 13, /**< Do not display the warning type. */ silent = 1 << 13, /**< Do not display the warning type. */
Wall = ~Werror /**< All above warnings. */
/**< All above warnings. */
Wall = ~complaint & ~fatal & ~silent
} warnings; } warnings;
/** What warnings are issued. */ /** What warnings are issued. */
extern warnings warnings_flag; extern warnings warnings_flag;
/** What warnings are made errors. */
extern warnings errors_flag;
/** Display a "[-Wyacc]" like message on stderr. */ /** Display a "[-Wyacc]" like message on stderr. */
void warnings_print_categories (warnings warn_flags); void warnings_print_categories (warnings warn_flags);
@@ -56,7 +62,7 @@ void warnings_print_categories (warnings warn_flags);
only for the sake of Yacc-compatible conflict reports in conflicts.c. only for the sake of Yacc-compatible conflict reports in conflicts.c.
All other warnings should be implemented in complain.c and should use All other warnings should be implemented in complain.c and should use
the normal warning format. */ the normal warning format. */
void set_warning_issued (void); void set_warning_issued (warnings warning);
/** Make a complaint, but don't specify any location. */ /** Make a complaint, but don't specify any location. */
void complain (warnings flags, char const *message, ...) void complain (warnings flags, char const *message, ...)

View File

@@ -87,9 +87,17 @@ flags_argmatch (const char *option,
args = strtok (args, ","); args = strtok (args, ",");
while (args) while (args)
{ {
int value = all;
int *save_flags = flags;
int no = STRPREFIX_LIT ("no-", args) ? 3 : 0; int no = STRPREFIX_LIT ("no-", args) ? 3 : 0;
int value = XARGMATCH (option, args + no, keys, values); int err = STRPREFIX_LIT ("error", args + no) ? 5 : 0;
if (value == 0)
if (err)
flags = &errors_flag;
if (!err || args[no + err++] != '\0')
value = XARGMATCH (option, args + no + err, keys, values);
if (!value)
{ {
if (no) if (no)
*flags |= all; *flags |= all;
@@ -101,8 +109,13 @@ flags_argmatch (const char *option,
if (no) if (no)
*flags &= ~value; *flags &= ~value;
else else
*flags |= value; {
if (err)
warnings_flag |= value;
*flags |= value;
}
} }
flags = save_flags;
args = strtok (NULL, ","); args = strtok (NULL, ",");
} }
} }
@@ -322,16 +335,16 @@ Output:\n\
fputs (_("\ fputs (_("\
Warning categories include:\n\ Warning categories include:\n\
`midrule-values' unset or unused midrule values\n\ `midrule-values' unset or unused midrule values\n\
`yacc' incompatibilities with POSIX Yacc\n\ `yacc' incompatibilities with POSIX Yacc\n\
`conflicts-sr' S/R conflicts (enabled by default)\n\ `conflicts-sr' S/R conflicts (enabled by default)\n\
`conflicts-rr' R/R conflicts (enabled by default)\n\ `conflicts-rr' R/R conflicts (enabled by default)\n\
`deprecated' obsolete constructs\n\ `deprecated' obsolete constructs\n\
`other' all other warnings (enabled by default)\n\ `other' all other warnings (enabled by default)\n\
`all' all the warnings\n\ `all' all the warnings\n\
`no-CATEGORY' turn off warnings in CATEGORY\n\ `no-CATEGORY' turn off warnings in CATEGORY\n\
`none' turn off all the warnings\n\ `none' turn off all the warnings\n\
`error' treat warnings as errors\n\ `error[=CATEGORY]' treat warnings as errors\n\
"), stdout); "), stdout);
putc ('\n', stdout); putc ('\n', stdout);