options -w and -Wfatal-errors implemented
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Tue, 11 Dec 2007 23:48:16 +0000 (23:48 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Tue, 11 Dec 2007 23:48:16 +0000 (23:48 +0000)
[r18687]

diagnostic.c
diagnostic.h
main.c

index 9af6491..c1a4ad8 100644 (file)
@@ -7,16 +7,18 @@
 #include "token_t.h"
 #include "type.h"
 
-//#define ABORT_ON_ERROR
-
 /** Number of occurred diagnostics. */
 unsigned diagnostic_count = 0;
 /** Number of occurred errors. */
 unsigned error_count      = 0;
 /** Number of occurred warnings. */
 unsigned warning_count    = 0;
-/* true if warnings should be treated as errors */
+/** true if warnings should be inhibited */
+bool inhibit_all_warnings = false;
+/** true if warnings should be treated as errors */
 bool warnings_are_errors  = false;
+/** true if the first error should stop the compilation */
+bool fatal_errors = false;
 
 /**
  * Issue a diagnostic message.
@@ -137,33 +139,48 @@ void diagnosticf(const char *const fmt, ...)
        va_end(ap);
 }
 
-void errorf(const source_position_t pos, const char *const fmt, ...)
+static void errorvf(const source_position_t pos,
+                    const char *const fmt, va_list ap)
 {
-       va_list ap;
-       va_start(ap, fmt);
        fprintf(stderr, "%s:%u: error: ", pos.input_name, pos.linenr);
        ++error_count;
        diagnosticvf(fmt, ap);
-       va_end(ap);
        fputc('\n', stderr);
 
-#ifdef ABORT_ON_ERROR
-       abort();
-#endif
+       if (fatal_errors)
+               abort();
+}
+void errorf(const source_position_t pos, const char *const fmt, ...)
+{
+       va_list ap;
+       va_start(ap, fmt);
+       errorvf(pos, fmt, ap);
+       va_end(ap);
+
+       if (fatal_errors)
+               exit(1);
+}
+
+static void warningvf(const source_position_t pos,
+                      const char *const fmt, va_list ap)
+{
+       fprintf(stderr, "%s:%u: warning: ", pos.input_name, pos.linenr);
+       ++warning_count;
+       diagnosticvf(fmt, ap);
+       fputc('\n', stderr);
 }
 
 void warningf(const source_position_t pos, const char *const fmt, ...)
 {
+       if (inhibit_all_warnings)
+               return;
+
        va_list ap;
        va_start(ap, fmt);
        if (warnings_are_errors) {
-               fprintf(stderr, "%s:%u: error: ", pos.input_name, pos.linenr);
-               ++error_count;
+               errorvf(pos, fmt, ap);
        } else {
-               fprintf(stderr, "%s:%u: warning: ", pos.input_name, pos.linenr);
-               ++warning_count;
+               warningvf(pos, fmt, ap);
        }
-       diagnosticvf(fmt, ap);
        va_end(ap);
-       fputc('\n', stderr);
 }
index 27a1821..cd75562 100644 (file)
@@ -11,7 +11,13 @@ extern unsigned diagnostic_count;
 extern unsigned error_count;
 extern unsigned warning_count;
 
+/* true if warnings should be inhibited */
+extern bool inhibit_all_warnings;
+
 /* true if warnings should be treated as errors */
 extern bool warnings_are_errors;
 
+/* true if the first error should stop the compilation */
+extern bool fatal_errors;
+
 #endif
diff --git a/main.c b/main.c
index abf0fbf..2790e01 100644 (file)
--- a/main.c
+++ b/main.c
@@ -421,6 +421,8 @@ int main(int argc, char **argv)
                        mode         = CompileDump;
                } else if(strcmp(arg, "-v") == 0) {
                        verbose = 1;
+               } else if(strcmp(arg, "-w") == 0) {
+                       inhibit_all_warnings = true;
                } else if(arg[0] == '-' && arg[1] == 'f') {
                        const char *opt;
                        GET_ARG_AFTER(opt, "-f");
@@ -456,6 +458,8 @@ int main(int argc, char **argv)
                        GET_ARG_AFTER(opt, "-W");
                        if (strcmp(opt, "error") == 0) {
                                warnings_are_errors = true;
+                       } else if (strcmp(opt, "fatal-errors") == 0) {
+                               fatal_errors = true;
                        } else {
                                fprintf(stderr, "warning: ignoring gcc option -W%s\n", opt);
                        }