fix typo
[cparser] / warning.c
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2007-2008 Matthias Braun <matze@braunis.de>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18  * 02111-1307, USA.
19  */
20 #include <stdio.h>
21 #include <string.h>
22 #include "warning.h"
23
24 warning_t warning = {
25         .other                         = true,
26
27         .address                       = true,
28         .aggregate_return              = false,
29         .attribute                     = true,
30         .cast_qual                     = false,
31         .char_subscripts               = true,
32         .comment                       = false,
33         .conversion                    = false,
34         .declaration_after_statement   = false,
35         .deprecated_declarations       = true,
36         .div_by_zero                   = true,
37         .empty_statement               = false,
38         .fatal_errors                  = false,
39         .float_equal                   = false,
40         .format                        = true,
41         .implicit_function_declaration = true,
42         .implicit_int                  = true,
43         .init_self                     = true,
44         .long_long                     = false,
45         .main                          = true,
46         .missing_declarations          = false,
47         .missing_noreturn              = false,
48         .missing_prototypes            = false,
49         .multichar                     = true,
50         .nested_externs                = false,
51         .nonnull                       = true,
52         .old_style_definition          = false,
53         .packed                        = false,
54         .padded                        = false,
55         .pointer_arith                 = true,
56         .redundant_decls               = true,
57         .return_type                   = true,
58         .s_are_errors                  = false,
59         .shadow                        = false,
60         .sign_compare                  = false,
61         .strict_prototypes             = true,
62         .switch_default                = false,
63         .switch_enum                   = false,
64         .traditional                   = false,
65         .unknown_pragmas               = true,
66         .unreachable_code              = false,
67         .unused_function               = false,
68         .unused_label                  = false,
69         .unused_parameter              = false,
70         .unused_value                  = true,
71         .unused_variable               = false,
72         .write_strings                 = false
73 };
74
75 void set_warning_opt(const char *const opt)
76 {
77         const char* s = opt;
78
79         bool state = true;
80
81         /* "no-" prefix */
82         if (s[0] == 'n' && s[1] == 'o' && s[2] == '-') {
83                 s += 3;
84                 state = false;
85         }
86
87         if (0) {}
88 #define OPTX(x)   else if (strcmp(s, x) == 0)
89 #define SET(y)    (void)(warning.y = state)
90 #define OPT(x, y) OPTX(x) SET(y)
91         OPTX("all") {
92                 /* Note: this switched on a lot more warnings than gcc's -Wall */
93                 SET(other);
94
95                 SET(address);
96                 SET(attribute);
97                 SET(char_subscripts);
98                 SET(comment);
99                 SET(empty_statement);
100                 SET(format);
101                 SET(implicit_function_declaration);
102                 SET(implicit_int);
103                 SET(init_self);
104                 SET(main);
105                 SET(nonnull);
106                 SET(pointer_arith);
107                 SET(redundant_decls);
108                 SET(return_type);
109                 SET(shadow);
110                 SET(sign_compare);
111                 SET(strict_prototypes);
112                 SET(switch_enum);
113                 SET(unknown_pragmas);
114                 SET(unreachable_code);
115                 SET(unused_function);
116                 SET(unused_label);
117                 SET(unused_parameter);
118                 SET(unused_value);
119                 SET(unused_variable);
120         }
121         OPT("address",                       address);
122         OPT("aggregate-return",              aggregate_return);
123         OPT("attribute",                     attribute);
124         OPT("cast-qual",                     cast_qual);
125         OPT("char-subscripts",               char_subscripts);
126         OPT("comment",                       comment);
127         OPT("conversion",                    conversion);
128         OPT("declaration-after-statement",   declaration_after_statement);
129         OPT("deprecated-declarations",       deprecated_declarations);
130         OPT("div-by-zero",                   div_by_zero);
131         OPT("empty-statement",               empty_statement);
132         OPT("error",                         s_are_errors);
133         OPTX("extra") {
134                 /* TODO */
135                 // TODO SET(function_end_without_return);
136                 SET(empty_statement);
137                 // TODO SET(incomplete_aggregate_init);
138                 // TODO SET(missing_field_initializers);
139                 // TODO SET(pointless_comparison);
140                 SET(unused_parameter);
141                 SET(unused_value);
142         }
143         OPT("fatal-errors",                  fatal_errors);
144         OPT("float-equal",                   float_equal);
145         OPTX("format") {
146                 SET(format);
147                 SET(nonnull);
148         }
149         OPTX("implicit") {
150                 SET(implicit_function_declaration);
151                 SET(implicit_int);
152         }
153         OPT("implicit-function-declaration", implicit_function_declaration);
154         OPT("implicit-int",                  implicit_int);
155         OPT("init-self",                     init_self);
156         OPT("long-long",                     long_long);
157         OPT("main",                          main);
158         OPT("missing-declarations",          missing_declarations);
159         OPT("missing-noreturn",              missing_noreturn);
160         OPT("missing-prototypes",            missing_prototypes);
161         OPT("multichar",                     multichar);
162         OPT("nested-externs",                nested_externs);
163         OPT("nonnull",                       nonnull);
164         OPT("old-style-definition",          old_style_definition);
165         OPT("packed",                        packed);
166         OPT("padded",                        padded);
167         OPT("pointer-arith",                 pointer_arith);
168         OPT("redundant-decls",               redundant_decls);
169         OPT("return-type",                   return_type);
170         OPT("shadow",                        shadow);
171         OPT("sign-compare",                  sign_compare);
172         OPT("strict-prototypes",             strict_prototypes);
173         OPT("switch-default",                switch_default);
174         OPT("switch-enum",                   switch_enum);
175         OPT("traditional",                   traditional);
176         OPT("unknown-pragmas",               unknown_pragmas);
177         OPT("unreachable-code",              unreachable_code);
178         OPTX("unused") {
179                 SET(unused_function);
180                 SET(unused_label);
181                 SET(unused_parameter);
182                 SET(unused_value);
183                 SET(unused_variable);
184         }
185         OPT("unused-function",               unused_function);
186         OPT("unused-label",                  unused_label);
187         OPT("unused-parameter",              unused_parameter);
188         OPT("unused-value",                  unused_value);
189         OPT("unused-variable",               unused_variable);
190         OPT("write-strings",                 write_strings);
191 #undef OPT
192 #undef SET
193 #undef OPT_X
194         else {
195                 fprintf(stderr, "warning: ignoring unknown option -W%s\n", opt);
196         }
197 }