Do no include -Wswitch-default in -Wall.
[cparser] / warning.c
1 #include <stdio.h>
2 #include <string.h>
3 #include "warning.h"
4
5 warning_t warning = {
6         .char_subscripts               = true,
7         .check_format                  = true,
8         .empty_statement               = false,
9         .fatal_errors                  = false,
10         .float_equal                   = false,
11         .implicit_function_declaration = true,
12         .implicit_int                  = true,
13         .main                          = true,
14         .missing_declarations          = false,
15         .missing_prototypes            = false,
16         .redundant_decls               = true,
17         .s_are_errors                  = false,
18         .shadow                        = false,
19         .sign_compare                  = false,
20         .strict_prototypes             = true,
21         .switch_default                = false,
22         .unknown_pragmas               = true,
23         .unused_function               = false,
24         .unused_label                  = false,
25         .unused_parameter              = false,
26         .unused_value                  = true,
27         .unused_variable               = false
28 };
29
30 void set_warning_opt(const char *const opt)
31 {
32         const char* s = opt;
33
34         bool state = true;
35
36         /* "no-" prefix */
37         if (s[0] == 'n' && s[1] == 'o' && s[2] == '-') {
38                 s += 3;
39                 state = false;
40         }
41
42         if (0) {}
43 #define OPTX(x)   else if (strcmp(s, x) == 0)
44 #define SET(y)    warning.y = state;
45 #define OPT(x, y) OPTX(x) SET(y)
46         OPTX("all") {
47                 /* Note: this switched on a lot of more warnings than gcc's -Wall */
48                 SET(char_subscripts)
49                 SET(check_format)
50                 SET(empty_statement)
51                 SET(implicit_function_declaration)
52                 SET(implicit_int)
53                 SET(main)
54                 SET(redundant_decls)
55                 SET(shadow)
56                 SET(sign_compare)
57                 SET(strict_prototypes)
58                 SET(unknown_pragmas)
59                 SET(unused_function)
60                 SET(unused_label)
61                 SET(unused_parameter)
62                 SET(unused_value)
63                 SET(unused_variable)
64         }
65         OPT("char-subscripts",               char_subscripts)
66         OPT("empty-statement",               empty_statement)
67         OPT("error",                         s_are_errors)
68         OPTX("extra") {
69                 /* TODO */
70                 // TODO SET(function_end_without_return)
71                 SET(empty_statement)
72                 // TODO SET(incomplete_aggregate_init)
73                 // TODO SET(pointless_comparison)
74                 // TODO SET(sign_compare)
75                 SET(unused_parameter)
76                 SET(unused_value)
77         }
78         OPT("fatal-errors",                  fatal_errors)
79         OPT("float-equal",                   float_equal)
80         OPT("format",                        check_format)
81         OPTX("implicit") {
82                 SET(implicit_function_declaration)
83                 SET(implicit_int)
84         }
85         OPT("implicit-function-declaration", implicit_function_declaration)
86         OPT("implicit-int",                  implicit_int)
87         OPT("main",                          main)
88         OPT("missing-declarations",          missing_declarations)
89         OPT("missing-prototypes",            missing_prototypes)
90         OPT("redundant-decls",               redundant_decls)
91         OPT("shadow",                        shadow)
92         OPT("sign-compare",                  sign_compare)
93         OPT("strict-prototypes",             strict_prototypes)
94         OPT("switch-default",                switch_default)
95         OPT("unknown-pragmas",               unknown_pragmas)
96         OPTX("unused") {
97                 SET(unused_function)
98                 SET(unused_label)
99                 SET(unused_parameter)
100                 SET(unused_value)
101                 SET(unused_variable)
102         }
103         OPT("unused-function",               unused_function)
104         OPT("unused-label",                  unused_label)
105         OPT("unused-parameter",              unused_parameter)
106         OPT("unused-value",                  unused_value)
107         OPT("unused-variable",               unused_variable)
108 #undef OPT
109 #undef SET
110 #undef OPT_X
111         else {
112                 fprintf(stderr, "warning: ignoring unknown option -W%s\n", opt);
113         }
114 }