mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
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:
committed by
Akim Demaille
parent
11b192127c
commit
9503b0a4a8
9
NEWS
9
NEWS
@@ -90,9 +90,8 @@ GNU Bison NEWS
|
||||
foo.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
foo.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
$ bison -Werror foo.y
|
||||
bison: warnings being treated as errors
|
||||
foo.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
foo.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
foo.y: error: 1 shift/reduce conflict [-Werror=conflicts-sr]
|
||||
foo.y: error: 2 reduce/reduce conflicts [-Werror=conflicts-rr]
|
||||
|
||||
When %expect or %expect-rr is used, such as with bar.y:
|
||||
|
||||
@@ -111,8 +110,8 @@ GNU Bison NEWS
|
||||
New one:
|
||||
|
||||
$ bison bar.y
|
||||
bar.y: shift/reduce conflicts: 1 found, 0 expected
|
||||
bar.y: reduce/reduce conflicts: 2 found, 0 expected
|
||||
bar.y: error: shift/reduce conflicts: 1 found, 0 expected
|
||||
bar.y: error: reduce/reduce conflicts: 2 found, 0 expected
|
||||
|
||||
** Additional yylex/yyparse arguments
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
warnings warnings_flag =
|
||||
Wconflicts_sr | Wconflicts_rr | Wdeprecated | Wother;
|
||||
|
||||
warnings errors_flag;
|
||||
|
||||
bool complaint_issued;
|
||||
static unsigned *indent_ptr = 0;
|
||||
|
||||
@@ -141,7 +143,7 @@ complains (const location *loc, warnings flags, const char *message,
|
||||
}
|
||||
else if (warnings_flag & Wyacc)
|
||||
{
|
||||
set_warning_issued ();
|
||||
set_warning_issued (Wyacc);
|
||||
error_message (loc, flags,
|
||||
indent_ptr && *indent_ptr ? NULL : _("warning"),
|
||||
message, args);
|
||||
@@ -149,7 +151,7 @@ complains (const location *loc, warnings flags, const char *message,
|
||||
}
|
||||
else if (warnings_flag & flags)
|
||||
{
|
||||
set_warning_issued ();
|
||||
set_warning_issued (flags);
|
||||
error_message (loc, flags,
|
||||
indent_ptr && *indent_ptr ? NULL : _("warning"),
|
||||
message, args);
|
||||
@@ -191,10 +193,10 @@ void complain_at_indent (location loc, warnings flags, unsigned *indent,
|
||||
`--------------------------------*/
|
||||
|
||||
void
|
||||
set_warning_issued (void)
|
||||
set_warning_issued (warnings warning)
|
||||
{
|
||||
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);
|
||||
complaint_issued = true;
|
||||
|
||||
@@ -35,16 +35,22 @@ typedef enum
|
||||
Wdeprecated = 1 << 4, /**< Obsolete constructs. */
|
||||
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. */
|
||||
fatal = 1 << 12, /**< All fatal errors. */
|
||||
silent = 1 << 13, /**< Do not display the warning type. */
|
||||
Wall = ~Werror /**< All above warnings. */
|
||||
|
||||
/**< All above warnings. */
|
||||
Wall = ~complaint & ~fatal & ~silent
|
||||
} warnings;
|
||||
|
||||
/** What warnings are issued. */
|
||||
extern warnings warnings_flag;
|
||||
|
||||
/** What warnings are made errors. */
|
||||
extern warnings errors_flag;
|
||||
|
||||
/** Display a "[-Wyacc]" like message on stderr. */
|
||||
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.
|
||||
All other warnings should be implemented in complain.c and should use
|
||||
the normal warning format. */
|
||||
void set_warning_issued (void);
|
||||
void set_warning_issued (warnings warning);
|
||||
|
||||
/** Make a complaint, but don't specify any location. */
|
||||
void complain (warnings flags, char const *message, ...)
|
||||
|
||||
@@ -87,9 +87,17 @@ flags_argmatch (const char *option,
|
||||
args = strtok (args, ",");
|
||||
while (args)
|
||||
{
|
||||
int value = all;
|
||||
int *save_flags = flags;
|
||||
int no = STRPREFIX_LIT ("no-", args) ? 3 : 0;
|
||||
int value = XARGMATCH (option, args + no, keys, values);
|
||||
if (value == 0)
|
||||
int err = STRPREFIX_LIT ("error", args + no) ? 5 : 0;
|
||||
|
||||
if (err)
|
||||
flags = &errors_flag;
|
||||
if (!err || args[no + err++] != '\0')
|
||||
value = XARGMATCH (option, args + no + err, keys, values);
|
||||
|
||||
if (!value)
|
||||
{
|
||||
if (no)
|
||||
*flags |= all;
|
||||
@@ -101,8 +109,13 @@ flags_argmatch (const char *option,
|
||||
if (no)
|
||||
*flags &= ~value;
|
||||
else
|
||||
*flags |= value;
|
||||
{
|
||||
if (err)
|
||||
warnings_flag |= value;
|
||||
*flags |= value;
|
||||
}
|
||||
}
|
||||
flags = save_flags;
|
||||
args = strtok (NULL, ",");
|
||||
}
|
||||
}
|
||||
@@ -322,16 +335,16 @@ Output:\n\
|
||||
|
||||
fputs (_("\
|
||||
Warning categories include:\n\
|
||||
`midrule-values' unset or unused midrule values\n\
|
||||
`yacc' incompatibilities with POSIX Yacc\n\
|
||||
`conflicts-sr' S/R conflicts (enabled by default)\n\
|
||||
`conflicts-rr' R/R conflicts (enabled by default)\n\
|
||||
`deprecated' obsolete constructs\n\
|
||||
`other' all other warnings (enabled by default)\n\
|
||||
`all' all the warnings\n\
|
||||
`no-CATEGORY' turn off warnings in CATEGORY\n\
|
||||
`none' turn off all the warnings\n\
|
||||
`error' treat warnings as errors\n\
|
||||
`midrule-values' unset or unused midrule values\n\
|
||||
`yacc' incompatibilities with POSIX Yacc\n\
|
||||
`conflicts-sr' S/R conflicts (enabled by default)\n\
|
||||
`conflicts-rr' R/R conflicts (enabled by default)\n\
|
||||
`deprecated' obsolete constructs\n\
|
||||
`other' all other warnings (enabled by default)\n\
|
||||
`all' all the warnings\n\
|
||||
`no-CATEGORY' turn off warnings in CATEGORY\n\
|
||||
`none' turn off all the warnings\n\
|
||||
`error[=CATEGORY]' treat warnings as errors\n\
|
||||
"), stdout);
|
||||
putc ('\n', stdout);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user