- implemented -Wsign-compare
[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(switch_default)
59                 SET(unknown_pragmas)
60                 SET(unused_function)
61                 SET(unused_label)
62                 SET(unused_parameter)
63                 SET(unused_value)
64                 SET(unused_variable)
65         }
66         OPT("char-subscripts",               char_subscripts)
67         OPT("empty-statement",               empty_statement)
68         OPT("error",                         s_are_errors)
69         OPTX("extra") {
70                 /* TODO */
71                 // TODO SET(function_end_without_return)
72                 SET(empty_statement)
73                 // TODO SET(incomplete_aggregate_init)
74                 // TODO SET(pointless_comparison)
75                 // TODO SET(sign_compare)
76                 SET(unused_parameter)
77                 SET(unused_value)
78         }
79         OPT("fatal-errors",                  fatal_errors)
80         OPT("float-equal",                   float_equal)
81         OPT("format",                        check_format)
82         OPTX("implicit") {
83                 SET(implicit_function_declaration)
84                 SET(implicit_int)
85         }
86         OPT("implicit-function-declaration", implicit_function_declaration)
87         OPT("implicit-int",                  implicit_int)
88         OPT("main",                          main)
89         OPT("missing-declarations",          missing_declarations)
90         OPT("missing-prototypes",            missing_prototypes)
91         OPT("redundant-decls",               redundant_decls)
92         OPT("shadow",                        shadow)
93         OPT("sign-compare",                  sign_compare)
94         OPT("strict-prototypes",             strict_prototypes)
95         OPT("switch-default",                switch_default)
96         OPT("unknown-pragmas",               unknown_pragmas)
97         OPTX("unused") {
98                 SET(unused_function)
99                 SET(unused_label)
100                 SET(unused_parameter)
101                 SET(unused_value)
102                 SET(unused_variable)
103         }
104         OPT("unused-function",               unused_function)
105         OPT("unused-label",                  unused_label)
106         OPT("unused-parameter",              unused_parameter)
107         OPT("unused-value",                  unused_value)
108         OPT("unused-variable",               unused_variable)
109 #undef OPT
110 #undef SET
111 #undef OPT_X
112         else {
113                 fprintf(stderr, "warning: ignoring unknown option -W%s\n", opt);
114         }
115 }