implemented -Wall, -Wextra, -Wunused, -Wunused-function with limited
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Sat, 15 Dec 2007 04:03:40 +0000 (04:03 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Sat, 15 Dec 2007 04:03:40 +0000 (04:03 +0000)
functionality

[r18764]

warning.c
warning.h

index 5cc88af..212a337 100644 (file)
--- a/warning.c
+++ b/warning.c
@@ -2,11 +2,88 @@
 #include <string.h>
 #include "warning.h"
 
+warning_t warning = {
+       .char_subscripts               = true,
+       .check_format                  = true,
+       .empty_statement               = false,
+       .fatal_errors                  = false,
+       .float_equal                   = false,
+       .implicit_function_declaration = true,
+       .implicit_int                  = true,
+       .main                          = true,
+       .missing_declarations          = false,
+       .missing_prototypes            = false,
+       .redundant_decls               = true,
+       .s_are_errors                  = false,
+       .strict_prototypes             = true,
+       .switch_default                = false,
+       .unknown_pragmas               = true,
+       .unused_function               = false,
+       .unused_label                  = false,
+       .unused_parameter              = false,
+       .unused_variable               = false,
+       .unused_value                  = true
+};
+
+/**
+ * Switch on options for -Wall.
+ */
+static void set_all_options(void) {
+       warning.char_subscripts               = true;
+       warning.check_format                  = true;
+       warning.empty_statement               = true;
+       /* warning.fatal_errors */
+       /* warning.float_equal */
+       warning.implicit_function_declaration = true;
+       warning.implicit_int                  = true;
+       warning.main                          = true;
+       /* warning.missing_declarations */
+       /* warning.missing_prototypes */
+       warning.redundant_decls               = true;
+       /* warning.s_are_errors */
+       warning.strict_prototypes             = true;
+       warning.switch_default                = true;
+       warning.unknown_pragmas               = true;
+       warning.unused_function               = true;
+       warning.unused_label                  = true;
+       warning.unused_parameter              = true;
+       warning.unused_variable               = true;
+       warning.unused_value                  = true;
+}
+
+/**
+ * Switch on options for -Wunused.
+ */
+static void set_unused_options(void) {
+       warning.unused_function               = true;
+       warning.unused_label                  = true;
+       warning.unused_parameter              = true;
+       warning.unused_variable               = true;
+       warning.unused_value                  = true;
+}
+
+/**
+ * Switch on options for -Wextra.
+ */
+static void set_extra_options(void) {
+}
+
 void set_warning_opt(const char *const opt)
 {
        const char* s = opt;
 
        bool state = true;
+       if (strcmp(s, "all") == 0) {
+               set_all_options();
+               return;
+       } else if (strcmp(s, "extra") == 0) {
+               set_extra_options();
+               return;
+       } else if (strcmp(s, "unused") == 0) {
+               set_unused_options();
+               return;
+       }
+
        /* no- modifier */
        if (s[0] == 'n' && s[1] == 'o' && s[2] == '-') {
                s += 3;
@@ -36,6 +113,7 @@ void set_warning_opt(const char *const opt)
        OPT("strict-prototypes",             strict_prototypes)
        OPT("switch-default",                switch_default)
        OPT("unknown-pragmas",               unknown_pragmas)
+       OPT("unused-function",               unused_function)
        OPT("unused-label",                  unused_label)
        OPT("unused-parameter",              unused_parameter)
        OPT("unused-variable",               unused_variable)
@@ -56,25 +134,3 @@ void set_warning_opt(const char *const opt)
                fprintf(stderr, "warning: ignoring unknown option -W%s\n", opt);
        }
 }
-
-warning_t warning = {
-       .char_subscripts               = true,
-       .check_format                  = true,
-       .empty_statement               = false,
-       .fatal_errors                  = false,
-       .float_equal                   = false,
-       .implicit_function_declaration = true,
-       .implicit_int                  = true,
-       .main                          = true,
-       .missing_declarations          = false,
-       .missing_prototypes            = false,
-       .redundant_decls               = true,
-       .s_are_errors                  = false,
-       .strict_prototypes             = true,
-       .switch_default                = false,
-       .unknown_pragmas               = true,
-       .unused_label                  = false,
-       .unused_parameter              = false,
-       .unused_variable               = false,
-       .unused_value                  = true
-};
index 87fc35a..fb82953 100644 (file)
--- a/warning.h
+++ b/warning.h
@@ -72,8 +72,8 @@ typedef struct warning_t {
        bool unknown_pragmas:1;               /**< Warn when a #pragma directive is encountered which is not understood */
 #if 0 // TODO
        bool unreachable_code:1;              /**< Warn if the compiler detects that code will never be executed */
-       bool unused_function:1;               /**< Warn whenever a static function is declared but not defined or a non-inline static function is unused */
 #endif
+       bool unused_function:1;               /**< Warn whenever a static function is declared but not defined or a non-inline static function is unused */
        bool unused_label:1;                  /**< Warn whenever a label is declared but not used */
        bool unused_parameter:1;              /**< Warn whenever a function parameter is unused aside from its declaration */
        bool unused_variable:1;               /**< Warn whenever a local variable or non-constant static variable is unused aside from its declaration */