From 981c53e257f1974854edc4f6ad0e88c7f18e2bea Mon Sep 17 00:00:00 2001 From: Theophile Ranquet Date: Thu, 20 Sep 2012 12:21:28 +0200 Subject: [PATCH] introduced a GCC-like -Werror=type * src/complain.h : errors_flag variable * src/complain.c : actual stuff happens here * src/conflits.c : differentiated SR and RR conflicts * src/getargs.c : flags_argmatch recognizes the new -Werror format --- src/complain.c | 19 ++++++++----- src/complain.h | 11 ++++++-- src/conflicts.c | 6 +++-- src/getargs.c | 72 +++++++++++++++++++++++++++++++++++-------------- 4 files changed, 77 insertions(+), 31 deletions(-) diff --git a/src/complain.c b/src/complain.c index d79a2502..8ebd1fb8 100644 --- a/src/complain.c +++ b/src/complain.c @@ -31,6 +31,7 @@ warnings warnings_flag = Wconflicts_sr | Wconflicts_rr | Wdeprecated | Wother; +warnings errors_flag; bool complaint_issued; static unsigned *indent_ptr = 0; @@ -55,7 +56,9 @@ warnings_print_categories (warnings warn_flags) for (i = 0; i < ARRAY_CARDINALITY (warn_names); ++i) if (warn_flags & 1 << i) { - fprintf (stderr, "%s-W%s", any ? ", " : " [", warn_names[i]); + bool err = warn_flags & errors_flag; + fprintf (stderr, "%s-W", any ? ", " : " ["); + fprintf (stderr, "%s%s", err ? "error=" : "" , warn_names[i]); any = true; } if (any) @@ -139,14 +142,16 @@ complains (const location *loc, warnings flags, const char *message, } else if (warnings_flag & Wyacc) { - set_warning_issued (); - error_message (loc, flags, _("warning"), message, args); + char* severity = Wyacc & errors_flag ? _("error") : _("warning"); + set_warning_issued (Wyacc); + error_message (loc, flags, severity, message, args); } } else if (warnings_flag & flags) { - set_warning_issued (); - error_message (loc, flags, _("warning"), message, args); + char* severity = flags & errors_flag ? _("error") : _("warning"); + set_warning_issued (flags); + error_message (loc, flags, severity, message, args); } } @@ -184,10 +189,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; diff --git a/src/complain.h b/src/complain.h index 44be293d..bdf6bfcd 100644 --- a/src/complain.h +++ b/src/complain.h @@ -35,16 +35,23 @@ typedef enum Wdeprecated = 1 << 4, /**< Obsolete constructs. */ Wother = 1 << 5, /**< All other warnings. */ + /* Deprecated, this option now uses a second instance of this enum */ Werror = 1 << 10, /**< Warnings are treated as errors. */ + 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); @@ -53,7 +60,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, ...) diff --git a/src/conflicts.c b/src/conflicts.c index 989dfc25..105c5ceb 100644 --- a/src/conflicts.c +++ b/src/conflicts.c @@ -602,8 +602,10 @@ conflicts_print (void) } if (src_total | rrc_total) { - if (expected_sr_conflicts == -1 && expected_rr_conflicts == -1) - set_warning_issued (); + if (expected_sr_conflicts == -1 && src_total) + set_warning_issued (Wconflicts_sr); + if (expected_rr_conflicts == -1 && rrc_total) + set_warning_issued (Wconflicts_rr); if (! yacc_flag) fprintf (stderr, "%s: ", current_file); conflict_report (stderr, src_total, rrc_total); diff --git a/src/getargs.c b/src/getargs.c index 74be4101..b0a6601a 100644 --- a/src/getargs.c +++ b/src/getargs.c @@ -83,31 +83,63 @@ flags_argmatch (const char *option, int all, int *flags, char *args) { if (args) + { + args = strtok (args, ","); + + /* Not sure whether we should keep this : -Werror=no-bar */ + int no = STRPREFIX_LIT ("no-", args) ? 3 : 0; + args += no; + int value = 0; + + while (args) { - args = strtok (args, ","); - while (args) + int err = STRPREFIX_LIT ("error", args); + if (err) + args += (args[5] == '=') ? 6 : 5; + + if (!err || args[-1] == '=') + value = XARGMATCH (option, args, keys, values); + if (value == 0) + { + if (no) + { + if (err) + /* Using &= ~all activates complaint, silent and fatal */ + errors_flag = Wnone; + else + *flags |= all; + } + else + { + if (err) + errors_flag |= all; + else + *flags &= ~all; + } + } + else + { + if (no) { - int no = STRPREFIX_LIT ("no-", args) ? 3 : 0; - int value = XARGMATCH (option, args + no, keys, values); - if (value == 0) - { - if (no) - *flags |= all; - else - *flags &= ~all; - } + if (err) + errors_flag &= ~value; else - { - if (no) - *flags &= ~value; - else - *flags |= value; - } - args = strtok (NULL, ","); + *flags &= ~value; } + else + { + if (err) + { + errors_flag |= value; + warnings_flag |= value; + } + else + *flags |= value; + } + } + args = strtok (NULL, ","); } - else - *flags |= all; + } } /** Decode a set of sub arguments. -- 2.45.2