]> granicus.if.org Git - yasm/commitdiff
Enhance error/warning framework by allowing specific warnings to be disabled,
authorPeter Johnson <peter@tortall.net>
Sun, 13 Jan 2002 08:53:24 +0000 (08:53 -0000)
committerPeter Johnson <peter@tortall.net>
Sun, 13 Jan 2002 08:53:24 +0000 (08:53 -0000)
all warnings to be disabled, and warnings to be treated as errors, much in the
style of GNU tools such as gcc.

svn path=/trunk/yasm/; revision=463

frontends/yasm/yasm.c
libyasm/errwarn.c
libyasm/errwarn.h
modules/parsers/nasm/token.l.in
src/errwarn.c
src/errwarn.h
src/main.c
src/parsers/nasm/token.l.in

index 783d46005ed50247a03ca8d7e33b89df1ce31978..2d08aabf5b9ab7d3d5c4369d2aa9e8b9ae786bc0 100644 (file)
@@ -54,6 +54,7 @@ static int files_open = 0;
 static int opt_option_handler(char *cmd, /*@null@*/ char *param, int extra);
 static int opt_format_handler(char *cmd, /*@null@*/ char *param, int extra);
 static int opt_objfile_handler(char *cmd, /*@null@*/ char *param, int extra);
+static int opt_warning_handler(char *cmd, /*@null@*/ char *param, int extra);
 /* Fake handlers: remove them */
 static int boo_boo_handler(char *cmd, /*@null@*/ char *param, int extra);
 static int b_handler(char *cmd, /*@null@*/ char *param, int extra);
@@ -67,6 +68,8 @@ static opt_option options[] =
     { 'h', "help",    0, opt_option_handler, OPT_SHOW_HELP, "show help text", NULL },
     { 'f', "oformat", 1, opt_format_handler, 0, "select output format", "<format>" },
     { 'o', "objfile", 1, opt_objfile_handler, 0, "name of object-file output", "<filename>" },
+    { 'w', NULL,      0, opt_warning_handler, 1, "inhibits warning messages", NULL },
+    { 'W', NULL,      0, opt_warning_handler, 0, "enables/disables warning", NULL },
     /* Fake handlers: remove them */
     { 'b', NULL,      0, b_handler, 0, "says boom!", NULL },
     {  0,  "boo-boo", 0, boo_boo_handler, 0, "says boo-boo!", NULL },
@@ -298,6 +301,39 @@ opt_objfile_handler(/*@unused@*/ char *cmd, char *param,
     return 0;
 }
 
+static int
+opt_warning_handler(char *cmd, /*@unused@*/ char *param, int extra)
+{
+    int enable = 1;    /* is it disabling the warning instead of enabling? */
+
+    if (extra == 1) {
+       /* -w, disable warnings */
+       warnings_disabled = 1;
+       return 0;
+    }
+
+    /* skip past 'W' */
+    cmd++;
+
+    /* detect no- prefix to disable the warning */
+    if (cmd[0] == 'n' && cmd[1] == 'o' && cmd[2] == '-') {
+       enable = 0;
+       cmd += 3;   /* skip past it to get to the warning name */
+    }
+
+    if (cmd[0] == '\0')
+       /* just -W or -Wno-, so definitely not valid */
+       return 1;
+    else if (strcmp(cmd, "error") == 0) {
+       warning_error = enable;
+    } else if (strcmp(cmd, "unrecognized-char") == 0) {
+       WARN_ENABLE(WARN_UNRECOGNIZED_CHAR, enable);
+    } else
+       return 1;
+
+    return 0;
+}
+
 /* Fake handlers: remove them */
 static int
 boo_boo_handler(/*@unused@*/ char *cmd, /*@unused@*/ char *param,
index f64813b98c598834c450bc1becf0c40e692724c4..c00b0572c54862dd61f616b26d2d62b7ec22cad9 100644 (file)
 #include "errwarn.h"
 
 
+/* ALL warnings are disabled if this is nonzero. */
+int warnings_disabled = 0;
+
+/* Warnings are treated as errors if this is nonzero.
+ * =2 indicates that warnings are treated as errors, and the message to the
+ * user saying that has been output.
+ */
+int warning_error = 0;
+
+/* Default enabled warnings.  See errwarn.h for a list. */
+unsigned long warning_flags =
+    (1<<WARN_UNRECOGNIZED_CHAR);
+
 /* Total error count for entire assembler run.
  * Assembler should exit with EXIT_FAILURE if this is >= 0 on finish. */
 static unsigned int error_count = 0;
@@ -194,6 +207,9 @@ Warning(const char *fmt, ...)
     va_list ap;
     errwarn *we;
 
+    if (warnings_disabled)
+       return;
+
     if (previous_warning_line == line_index)
        return;
 
@@ -231,6 +247,9 @@ WarningNow(const char *fmt, ...)
 {
     va_list ap;
 
+    if (warnings_disabled)
+       return;
+
     fprintf(stderr, "%s ", _("warning:"));
     va_start(ap, fmt);
     vfprintf(stderr, fmt, ap);
@@ -262,6 +281,9 @@ WarningAt(unsigned long lindex, const char *fmt, ...)
     const char *filename;
     unsigned long line;
 
+    if (warnings_disabled)
+       return;
+
     line_lookup(lindex, &filename, &line);
     fprintf(stderr, "%s:%lu: %s ", filename?filename:"NULL", line,
            _("warning:"));
@@ -280,8 +302,18 @@ OutputAllErrorWarning(void)
     unsigned long line;
 
     /* If errwarns hasn't been initialized, there are no messages. */
-    if (!errwarns)
-       return error_count;
+    if (!errwarns) {
+       if (warning_error)
+           return error_count+warning_count;
+       else
+           return error_count;
+    }
+
+    /* If we're treating warnings as errors, tell the user about it. */
+    if (warning_error && warning_error != 2) {
+       fprintf(stderr, "%s\n", _("warnings being treated as errors"));
+       warning_error = 2;
+    }
 
     /* Output error and warning messages. */
     STAILQ_FOREACH(we, errwarns, link) {
@@ -301,6 +333,10 @@ OutputAllErrorWarning(void)
        we = we2;
     }
 
-    /* Return the total error count up to this point. */
+    /* Return the total error count up to this point.
+     * If we're treating warnings as errors, add that to the total as well.
+     */
+    if (warning_error)
+       return error_count+warning_count;
     return error_count;
 }
index d48c539a5f55ca1dd49719858c0c80e64127f5cb..e55ac18abda1e120104da43221495a54cb00f7d0 100644 (file)
 #ifndef YASM_ERRWARN_H
 #define YASM_ERRWARN_H
 
+/* ALL warnings disabled? */
+extern int warnings_disabled;
+
+/* Warnings treated as errors? */
+extern int warning_error;
+
+/* Warning flags.  Currently a maximum of 32 are allowed.  This can be
+ * increased by making this an array and modifying the WARN_ macros to use the
+ * proper array index based on the warning number.
+ *
+ * If a bit is 1, it means that particular warning is enabled.  The bit numbers
+ * are assigned according to the warn_flag_num enum.
+ *
+ * See errwarn.c for what warnings are enabled by default.
+ */
+extern unsigned long warning_flags;
+typedef enum {
+    WARN_UNRECOGNIZED_CHAR = 0
+} warn_flag_num;
+
+/* Tests the warning flags to see if warning "warn" is enabled */
+#define WARN_ENABLED(warn)     (warning_flags & (1<<(warn)))
+/* Sets warning "warn" to be enabled or disabled based on "s" (1=en, 0=dis). */
+#define WARN_ENABLE(warn, s)   do { \
+       warning_flags &= ~(1<<(warn)); \
+       warning_flags |= (s)<<(warn); \
+    } while(0)
+
 /* Fatal error constants.
  * See fatal_msgs in errwarn.c for strings that match up to these constants.
  * When adding a constant here, keep errwarn.c in sync! */
index b0b160c4380689c8e7f8a8ed66468fd1f5147c35..7f4585578504f306452a705548777c54775878bb 100644 (file)
@@ -188,8 +188,9 @@ WS       [ \t\r]
     return DIRECTIVE_NAME;
 }
 <DIRECTIVE>. {
-    Warning(_("ignoring unrecognized character `%s'"),
-           conv_unprint(yytext[0]));
+    if (WARN_ENABLED(WARN_UNRECOGNIZED_CHAR))
+       Warning(_("ignoring unrecognized character `%s'"),
+               conv_unprint(yytext[0]));
 }
 
     /* override local labels in directive state */
@@ -345,7 +346,8 @@ gs  { yylval.int_info = 5; return REG_GS; }
 \n     return '\n';
 
 .      {
-    Warning(_("ignoring unrecognized character `%s'"),
-           conv_unprint(yytext[0]));
+    if (WARN_ENABLED(WARN_UNRECOGNIZED_CHAR))
+       Warning(_("ignoring unrecognized character `%s'"),
+               conv_unprint(yytext[0]));
 }
 
index f64813b98c598834c450bc1becf0c40e692724c4..c00b0572c54862dd61f616b26d2d62b7ec22cad9 100644 (file)
 #include "errwarn.h"
 
 
+/* ALL warnings are disabled if this is nonzero. */
+int warnings_disabled = 0;
+
+/* Warnings are treated as errors if this is nonzero.
+ * =2 indicates that warnings are treated as errors, and the message to the
+ * user saying that has been output.
+ */
+int warning_error = 0;
+
+/* Default enabled warnings.  See errwarn.h for a list. */
+unsigned long warning_flags =
+    (1<<WARN_UNRECOGNIZED_CHAR);
+
 /* Total error count for entire assembler run.
  * Assembler should exit with EXIT_FAILURE if this is >= 0 on finish. */
 static unsigned int error_count = 0;
@@ -194,6 +207,9 @@ Warning(const char *fmt, ...)
     va_list ap;
     errwarn *we;
 
+    if (warnings_disabled)
+       return;
+
     if (previous_warning_line == line_index)
        return;
 
@@ -231,6 +247,9 @@ WarningNow(const char *fmt, ...)
 {
     va_list ap;
 
+    if (warnings_disabled)
+       return;
+
     fprintf(stderr, "%s ", _("warning:"));
     va_start(ap, fmt);
     vfprintf(stderr, fmt, ap);
@@ -262,6 +281,9 @@ WarningAt(unsigned long lindex, const char *fmt, ...)
     const char *filename;
     unsigned long line;
 
+    if (warnings_disabled)
+       return;
+
     line_lookup(lindex, &filename, &line);
     fprintf(stderr, "%s:%lu: %s ", filename?filename:"NULL", line,
            _("warning:"));
@@ -280,8 +302,18 @@ OutputAllErrorWarning(void)
     unsigned long line;
 
     /* If errwarns hasn't been initialized, there are no messages. */
-    if (!errwarns)
-       return error_count;
+    if (!errwarns) {
+       if (warning_error)
+           return error_count+warning_count;
+       else
+           return error_count;
+    }
+
+    /* If we're treating warnings as errors, tell the user about it. */
+    if (warning_error && warning_error != 2) {
+       fprintf(stderr, "%s\n", _("warnings being treated as errors"));
+       warning_error = 2;
+    }
 
     /* Output error and warning messages. */
     STAILQ_FOREACH(we, errwarns, link) {
@@ -301,6 +333,10 @@ OutputAllErrorWarning(void)
        we = we2;
     }
 
-    /* Return the total error count up to this point. */
+    /* Return the total error count up to this point.
+     * If we're treating warnings as errors, add that to the total as well.
+     */
+    if (warning_error)
+       return error_count+warning_count;
     return error_count;
 }
index d48c539a5f55ca1dd49719858c0c80e64127f5cb..e55ac18abda1e120104da43221495a54cb00f7d0 100644 (file)
 #ifndef YASM_ERRWARN_H
 #define YASM_ERRWARN_H
 
+/* ALL warnings disabled? */
+extern int warnings_disabled;
+
+/* Warnings treated as errors? */
+extern int warning_error;
+
+/* Warning flags.  Currently a maximum of 32 are allowed.  This can be
+ * increased by making this an array and modifying the WARN_ macros to use the
+ * proper array index based on the warning number.
+ *
+ * If a bit is 1, it means that particular warning is enabled.  The bit numbers
+ * are assigned according to the warn_flag_num enum.
+ *
+ * See errwarn.c for what warnings are enabled by default.
+ */
+extern unsigned long warning_flags;
+typedef enum {
+    WARN_UNRECOGNIZED_CHAR = 0
+} warn_flag_num;
+
+/* Tests the warning flags to see if warning "warn" is enabled */
+#define WARN_ENABLED(warn)     (warning_flags & (1<<(warn)))
+/* Sets warning "warn" to be enabled or disabled based on "s" (1=en, 0=dis). */
+#define WARN_ENABLE(warn, s)   do { \
+       warning_flags &= ~(1<<(warn)); \
+       warning_flags |= (s)<<(warn); \
+    } while(0)
+
 /* Fatal error constants.
  * See fatal_msgs in errwarn.c for strings that match up to these constants.
  * When adding a constant here, keep errwarn.c in sync! */
index 783d46005ed50247a03ca8d7e33b89df1ce31978..2d08aabf5b9ab7d3d5c4369d2aa9e8b9ae786bc0 100644 (file)
@@ -54,6 +54,7 @@ static int files_open = 0;
 static int opt_option_handler(char *cmd, /*@null@*/ char *param, int extra);
 static int opt_format_handler(char *cmd, /*@null@*/ char *param, int extra);
 static int opt_objfile_handler(char *cmd, /*@null@*/ char *param, int extra);
+static int opt_warning_handler(char *cmd, /*@null@*/ char *param, int extra);
 /* Fake handlers: remove them */
 static int boo_boo_handler(char *cmd, /*@null@*/ char *param, int extra);
 static int b_handler(char *cmd, /*@null@*/ char *param, int extra);
@@ -67,6 +68,8 @@ static opt_option options[] =
     { 'h', "help",    0, opt_option_handler, OPT_SHOW_HELP, "show help text", NULL },
     { 'f', "oformat", 1, opt_format_handler, 0, "select output format", "<format>" },
     { 'o', "objfile", 1, opt_objfile_handler, 0, "name of object-file output", "<filename>" },
+    { 'w', NULL,      0, opt_warning_handler, 1, "inhibits warning messages", NULL },
+    { 'W', NULL,      0, opt_warning_handler, 0, "enables/disables warning", NULL },
     /* Fake handlers: remove them */
     { 'b', NULL,      0, b_handler, 0, "says boom!", NULL },
     {  0,  "boo-boo", 0, boo_boo_handler, 0, "says boo-boo!", NULL },
@@ -298,6 +301,39 @@ opt_objfile_handler(/*@unused@*/ char *cmd, char *param,
     return 0;
 }
 
+static int
+opt_warning_handler(char *cmd, /*@unused@*/ char *param, int extra)
+{
+    int enable = 1;    /* is it disabling the warning instead of enabling? */
+
+    if (extra == 1) {
+       /* -w, disable warnings */
+       warnings_disabled = 1;
+       return 0;
+    }
+
+    /* skip past 'W' */
+    cmd++;
+
+    /* detect no- prefix to disable the warning */
+    if (cmd[0] == 'n' && cmd[1] == 'o' && cmd[2] == '-') {
+       enable = 0;
+       cmd += 3;   /* skip past it to get to the warning name */
+    }
+
+    if (cmd[0] == '\0')
+       /* just -W or -Wno-, so definitely not valid */
+       return 1;
+    else if (strcmp(cmd, "error") == 0) {
+       warning_error = enable;
+    } else if (strcmp(cmd, "unrecognized-char") == 0) {
+       WARN_ENABLE(WARN_UNRECOGNIZED_CHAR, enable);
+    } else
+       return 1;
+
+    return 0;
+}
+
 /* Fake handlers: remove them */
 static int
 boo_boo_handler(/*@unused@*/ char *cmd, /*@unused@*/ char *param,
index b0b160c4380689c8e7f8a8ed66468fd1f5147c35..7f4585578504f306452a705548777c54775878bb 100644 (file)
@@ -188,8 +188,9 @@ WS       [ \t\r]
     return DIRECTIVE_NAME;
 }
 <DIRECTIVE>. {
-    Warning(_("ignoring unrecognized character `%s'"),
-           conv_unprint(yytext[0]));
+    if (WARN_ENABLED(WARN_UNRECOGNIZED_CHAR))
+       Warning(_("ignoring unrecognized character `%s'"),
+               conv_unprint(yytext[0]));
 }
 
     /* override local labels in directive state */
@@ -345,7 +346,8 @@ gs  { yylval.int_info = 5; return REG_GS; }
 \n     return '\n';
 
 .      {
-    Warning(_("ignoring unrecognized character `%s'"),
-           conv_unprint(yytext[0]));
+    if (WARN_ENABLED(WARN_UNRECOGNIZED_CHAR))
+       Warning(_("ignoring unrecognized character `%s'"),
+               conv_unprint(yytext[0]));
 }