c102f9c93792a308f60e420d051529c0ae987ddd
[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         .multichar                     = true,
17         .redundant_decls               = true,
18         .s_are_errors                  = false,
19         .shadow                        = false,
20         .sign_compare                  = false,
21         .strict_prototypes             = true,
22         .switch_default                = false,
23         .unknown_pragmas               = true,
24         .unused_function               = false,
25         .unused_label                  = false,
26         .unused_parameter              = false,
27         .unused_value                  = true,
28         .unused_variable               = false
29 };
30
31 void set_warning_opt(const char *const opt)
32 {
33         const char* s = opt;
34
35         bool state = true;
36
37         /* "no-" prefix */
38         if (s[0] == 'n' && s[1] == 'o' && s[2] == '-') {
39                 s += 3;
40                 state = false;
41         }
42
43         if (0) {}
44 #define OPTX(x)   else if (strcmp(s, x) == 0)
45 #define SET(y)    warning.y = state;
46 #define OPT(x, y) OPTX(x) SET(y)
47         OPTX("all") {
48                 /* Note: this switched on a lot of more warnings than gcc's -Wall */
49                 SET(char_subscripts)
50                 SET(check_format)
51                 SET(empty_statement)
52                 SET(implicit_function_declaration)
53                 SET(implicit_int)
54                 SET(main)
55                 SET(redundant_decls)
56                 SET(shadow)
57                 SET(sign_compare)
58                 SET(strict_prototypes)
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("multichar",                     multichar)
92         OPT("redundant-decls",               redundant_decls)
93         OPT("shadow",                        shadow)
94         OPT("sign-compare",                  sign_compare)
95         OPT("strict-prototypes",             strict_prototypes)
96         OPT("switch-default",                switch_default)
97         OPT("unknown-pragmas",               unknown_pragmas)
98         OPTX("unused") {
99                 SET(unused_function)
100                 SET(unused_label)
101                 SET(unused_parameter)
102                 SET(unused_value)
103                 SET(unused_variable)
104         }
105         OPT("unused-function",               unused_function)
106         OPT("unused-label",                  unused_label)
107         OPT("unused-parameter",              unused_parameter)
108         OPT("unused-value",                  unused_value)
109         OPT("unused-variable",               unused_variable)
110 #undef OPT
111 #undef SET
112 #undef OPT_X
113         else {
114                 fprintf(stderr, "warning: ignoring unknown option -W%s\n", opt);
115         }
116 }