[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/3] warnings: fix early exit
From: |
Theophile Ranquet |
Subject: |
[PATCH 2/3] warnings: fix early exit |
Date: |
Fri, 26 Oct 2012 17:37:28 +0000 |
Treating warnings as errors caused Bison to exit earlier than needed, making it
hide warnings that would have been printed had -Werror not been set.
Also, fix a bug that caused some context information of errors to not be
shown.
* src/complain.c (complaint_issued): Rename as...
(complaint_status): This, and change its type from boolean to
* src/complain.h (err_status): This, new enumeration.
* src/main.c (main): Adjust (only finish early if an actual complaint was
risen, not a mere warning treated an error).
* src/reader.c: Adjust.
* src/scan-code.l (show_sub_message, show_sub_messages): Take a new warnings
argument.
* src/scan-skel.l (flag): Bug fix.
---
src/complain.c | 9 ++++++---
src/complain.h | 13 ++++++++++++-
src/main.c | 6 +++---
src/reader.c | 2 +-
src/scan-code.l | 24 +++++++++++++++---------
src/scan-skel.l | 2 +-
6 files changed, 38 insertions(+), 18 deletions(-)
diff --git a/src/complain.c b/src/complain.c
index 0fa812a..2e4e71a 100644
--- a/src/complain.c
+++ b/src/complain.c
@@ -34,7 +34,7 @@ warnings warnings_flag =
warnings errors_flag;
-bool complaint_issued;
+err_status complaint_status = status_none;
static unsigned *indent_ptr = 0;
void
@@ -129,8 +129,11 @@ complains (const location *loc, warnings flags, const char
*message,
: flags & (errors_flag | complaint) ? _("error")
: _("warning");
- complaint_issued |= flags & (complaint | errors_flag);
- if (flags & (warnings_flag | silent | fatal | complaint))
+ if ((flags & complaint) && complaint_status < status_complaint)
+ complaint_status = status_complaint;
+ else if ((flags & (warnings_flag & errors_flag)) && ! complaint_status)
+ complaint_status = status_warning_as_error;
+ if (flags & (warnings_flag | fatal | complaint))
error_message (loc, flags, prefix, message, args);
if (flags & fatal)
exit (EXIT_FAILURE);
diff --git a/src/complain.h b/src/complain.h
index 6a871d8..56ddfa0 100644
--- a/src/complain.h
+++ b/src/complain.h
@@ -70,7 +70,18 @@ void complain_indent (location const *loc, warnings flags,
unsigned *indent,
char const *message, ...)
__attribute__ ((__format__ (__printf__, 4, 5)));
+
+/** Warnings treated as errors shouldn't stop the execution as regular errors
+ should (because due to their nature, it is safe to go on). Thus, there are
+ three possible execution statuses. */
+typedef enum
+ {
+ status_none,
+ status_warning_as_error,
+ status_complaint
+ } err_status;
+
/** Whether an error was reported. */
-extern bool complaint_issued;
+extern err_status complaint_status;
#endif /* !COMPLAIN_H_ */
diff --git a/src/main.c b/src/main.c
index 9a03630..39b39c7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -94,7 +94,7 @@ main (int argc, char *argv[])
reader ();
timevar_pop (TV_READER);
- if (complaint_issued)
+ if (complaint_status == status_complaint)
goto finish;
/* Find useless nonterminals and productions and reduce the grammar. */
@@ -173,7 +173,7 @@ main (int argc, char *argv[])
/* Stop if there were errors, to avoid trashing previous output
files. */
- if (complaint_issued)
+ if (complaint_status == status_complaint)
goto finish;
/* Lookahead tokens are no longer needed. */
@@ -215,5 +215,5 @@ main (int argc, char *argv[])
timevar_stop (TV_TOTAL);
timevar_print (stderr);
- return complaint_issued ? EXIT_FAILURE : EXIT_SUCCESS;
+ return complaint_status ? EXIT_FAILURE : EXIT_SUCCESS;
}
diff --git a/src/reader.c b/src/reader.c
index f18b5b8..fb17b01 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -631,7 +631,7 @@ reader (void)
gram_parse ();
prepare_percent_define_front_end_variables ();
- if (! complaint_issued)
+ if (complaint_status < status_complaint)
check_and_convert_grammar ();
xfclose (gram_in);
diff --git a/src/scan-code.l b/src/scan-code.l
index 138d2d9..f6e5a14 100644
--- a/src/scan-code.l
+++ b/src/scan-code.l
@@ -398,14 +398,15 @@ get_at_spec(unsigned symbol_index)
}
static void
-show_sub_message (const char* cp, bool explicit_bracketing,
+show_sub_message (warnings warning,
+ const char* cp, bool explicit_bracketing,
int midrule_rhs_index, char dollar_or_at,
unsigned indent, const variant *var)
{
const char *at_spec = get_at_spec (var->symbol_index);
if (var->err == 0)
- complain_indent (&var->loc, silent, &indent,
+ complain_indent (&var->loc, warning, &indent,
_("refers to: %c%s at %s"), dollar_or_at,
var->id, at_spec);
else
@@ -442,21 +443,23 @@ show_sub_message (const char* cp, bool
explicit_bracketing,
_(", cannot be accessed from mid-rule action at $%d"),
midrule_rhs_index);
- complain_indent (&id_loc, silent, &indent, "%s",
- obstack_finish0 (&msg_buf));
+ complain_indent (&id_loc, warning, &indent, "%s",
+ obstack_finish0 (&msg_buf));
obstack_free (&msg_buf, 0);
}
}
static void
-show_sub_messages (const char* cp, bool explicit_bracketing,
+show_sub_messages (warnings warning,
+ const char* cp, bool explicit_bracketing,
int midrule_rhs_index, char dollar_or_at,
unsigned indent)
{
unsigned i;
for (i = 0; i < variant_count; ++i)
- show_sub_message (cp, explicit_bracketing,
+ show_sub_message (Wother | silent,
+ cp, explicit_bracketing,
midrule_rhs_index, dollar_or_at,
indent, &variant_table[i]);
}
@@ -610,7 +613,8 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
len, cp);
if (variant_count > 0)
- show_sub_messages (cp, explicit_bracketing, midrule_rhs_index,
+ show_sub_messages (complaint,
+ cp, explicit_bracketing, midrule_rhs_index,
dollar_or_at, indent);
return INVALID_REF;
}
@@ -621,7 +625,8 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
{
complain_indent (&text_loc, Wother, &indent,
_("misleading reference: %s"), quote (text));
- show_sub_messages (cp, explicit_bracketing, midrule_rhs_index,
+ show_sub_messages (Wother,
+ cp, explicit_bracketing, midrule_rhs_index,
dollar_or_at, indent + SUB_INDENT);
}
{
@@ -636,7 +641,8 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
unsigned indent = 0;
complain_indent (&text_loc, complaint, &indent,
_("ambiguous reference: %s"), quote (text));
- show_sub_messages (cp, explicit_bracketing, midrule_rhs_index,
+ show_sub_messages (complaint,
+ cp, explicit_bracketing, midrule_rhs_index,
dollar_or_at, indent + SUB_INDENT);
return INVALID_REF;
}
diff --git a/src/scan-skel.l b/src/scan-skel.l
index c1e7b65..a0d9c9e 100644
--- a/src/scan-skel.l
+++ b/src/scan-skel.l
@@ -186,7 +186,7 @@ flag (const char *arg)
else if (STREQ (arg, "fatal"))
return fatal;
else if (STREQ (arg, "note"))
- return silent;
+ return silent | complaint;
else if (STREQ (arg, "warn"))
return Wother;
else
--
1.7.11.4