2 * This file is part of cparser.
3 * Copyright (C) 2007-2009 Matthias Braun <matze@braunis.de>
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.
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.
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
29 .aggregate_return = false,
32 .char_subscripts = true,
35 .declaration_after_statement = false,
36 .deprecated_declarations = true,
38 .empty_statement = false,
39 .error_implicit_function_declaration = false,
40 .fatal_errors = false,
43 .implicit_function_declaration = true,
48 .missing_declarations = false,
49 .missing_noreturn = false,
50 .missing_prototypes = false,
52 .nested_externs = false,
54 .old_style_definition = false,
58 .pointer_arith = true,
59 .redundant_decls = true,
61 .s_are_errors = false,
63 .shadow_local = false,
64 .sign_compare = false,
65 .strict_prototypes = true,
66 .switch_default = false,
69 .uninitialized = true,
70 .unknown_pragmas = true,
71 .unreachable_code = false,
72 .unused_function = false,
73 .unused_label = false,
74 .unused_parameter = false,
76 .unused_variable = false,
77 .write_strings = false
80 void print_warning_opt_help(void)
82 /* TODO: write explanations */
83 put_help("-Waddress", "");
84 put_help("-Wall", "");
85 put_help("-Waggregate-return", "");
86 put_help("-Wattribute", "");
87 put_help("-Wcast-qual", "");
88 put_help("-Wchar-subscripts", "");
89 put_help("-Wcomment", "");
90 put_help("-Wconversion", "");
91 put_help("-Wdeclaration-after-statement", "");
92 put_help("-Wdeprecated-declarations", "");
93 put_help("-Wdiv-by-zero", "");
94 put_help("-Wempty-statement", "");
95 put_help("-Werror", "warnings are errors");
96 put_help("-Werror-implicit-function-declaration", "");
97 put_help("-Wextra", "");
98 put_help("-Wfatal-errors", "");
99 put_help("-Wfloat-equal", "");
100 put_help("-Wformat", "");
101 put_help("-Wimplicit", "");
102 put_help("-Wimplicit-function-declaration", "");
103 put_help("-Wimplicit-int", "");
104 put_help("-Winit-self", "");
105 put_help("-Wlong-long", "");
106 put_help("-Wmain", "");
107 put_help("-Wmissing-declarations", "");
108 put_help("-Wmissing-noreturn", "");
109 put_help("-Wmissing-prototypes", "");
110 put_help("-Wmultichar", "");
111 put_help("-Wnested-externs", "");
112 put_help("-Wnonnull", "");
113 put_help("-Wold-style-definition", "");
114 put_help("-Wparentheses", "");
115 put_help("-Wpacked", "");
116 put_help("-Wpadded", "");
117 put_help("-Wparentheses", "");
118 put_help("-Wpointer-arith", "");
119 put_help("-Wredundant-decls", "");
120 put_help("-Wreturn-type", "");
121 put_help("-Wshadow", "");
122 put_help("-Wshadow-local", "");
123 put_help("-Wsign-compare", "");
124 put_help("-Wstrict-prototypes", "");
125 put_help("-Wswitch-default", "");
126 put_help("-Wswitch-enum", "");
127 put_help("-Wtraditional", "");
128 put_help("-Wuninitialized", "");
129 put_help("-Wunknown-pragmas", "");
130 put_help("-Wunreachable-code", "");
131 put_help("-Wunused", "");
132 put_help("-Wunused-function", "");
133 put_help("-Wunused-label", "");
134 put_help("-Wunused-parameter", "");
135 put_help("-Wunused-value", "");
136 put_help("-Wunused-variable", "");
137 put_help("-Wwrite-strings", "");
140 void set_warning_opt(const char *const opt)
147 if (s[0] == 'n' && s[1] == 'o' && s[2] == '-') {
152 if (s[0] == '\0') { // -W is an alias for -Wextra
155 #define OPTX(x) else if (strcmp(s, x) == 0)
156 #define SET(y) (void)(warning.y = state)
157 #define OPT(x, y) OPTX(x) SET(y)
159 /* Note: this switched on a lot more warnings than gcc's -Wall */
164 SET(char_subscripts);
166 SET(empty_statement);
168 SET(implicit_function_declaration);
172 SET(missing_declarations);
176 SET(redundant_decls);
180 SET(strict_prototypes);
183 SET(unknown_pragmas);
184 SET(unreachable_code);
185 SET(unused_function);
187 SET(unused_parameter);
189 SET(unused_variable);
191 OPT("address", address);
192 OPT("aggregate-return", aggregate_return);
193 OPT("attribute", attribute);
194 OPT("cast-qual", cast_qual);
195 OPT("char-subscripts", char_subscripts);
196 OPT("comment", comment);
197 OPT("conversion", conversion);
198 OPT("declaration-after-statement", declaration_after_statement);
199 OPT("deprecated-declarations", deprecated_declarations);
200 OPT("div-by-zero", div_by_zero);
201 OPT("empty-statement", empty_statement);
202 OPT("error", s_are_errors);
203 OPT("error-implicit-function-declaration", error_implicit_function_declaration);
207 // TODO SET(function_end_without_return);
208 SET(empty_statement);
209 // TODO SET(incomplete_aggregate_init);
210 // TODO SET(missing_field_initializers);
211 // TODO SET(pointless_comparison);
213 SET(unused_parameter);
216 OPT("fatal-errors", fatal_errors);
217 OPT("float-equal", float_equal);
223 SET(implicit_function_declaration);
226 OPT("implicit-function-declaration", implicit_function_declaration);
227 OPT("implicit-int", implicit_int);
228 OPT("init-self", init_self);
229 OPT("long-long", long_long);
231 OPT("missing-declarations", missing_declarations);
232 OPT("missing-noreturn", missing_noreturn);
233 OPT("missing-prototypes", missing_prototypes);
234 OPT("multichar", multichar);
235 OPT("nested-externs", nested_externs);
236 OPT("nonnull", nonnull);
237 OPT("old-style-definition", old_style_definition);
238 OPT("packed", packed);
239 OPT("padded", padded);
240 OPT("parentheses", parentheses);
241 OPT("pointer-arith", pointer_arith);
242 OPT("redundant-decls", redundant_decls);
243 OPT("return-type", return_type);
244 OPT("shadow", shadow);
245 OPT("shadow-local", shadow_local);
246 OPT("sign-compare", sign_compare);
247 OPT("strict-prototypes", strict_prototypes);
248 OPT("switch-default", switch_default);
249 OPT("switch-enum", switch_enum);
250 OPT("traditional", traditional);
251 OPT("uninitialized", uninitialized);
252 OPT("unknown-pragmas", unknown_pragmas);
253 OPT("unreachable-code", unreachable_code);
255 SET(unused_function);
257 SET(unused_parameter);
259 SET(unused_variable);
261 OPT("unused-function", unused_function);
262 OPT("unused-label", unused_label);
263 OPT("unused-parameter", unused_parameter);
264 OPT("unused-value", unused_value);
265 OPT("unused-variable", unused_variable);
266 OPT("write-strings", write_strings);
271 fprintf(stderr, "warning: ignoring unknown option -W%s\n", opt);