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 .sign_compare = false,
64 .strict_prototypes = true,
65 .switch_default = false,
68 .uninitialized = true,
69 .unknown_pragmas = true,
70 .unreachable_code = false,
71 .unused_function = false,
72 .unused_label = false,
73 .unused_parameter = false,
75 .unused_variable = false,
76 .write_strings = false
79 void print_warning_opt_help(void)
81 /* TODO: write explanations */
82 put_help("-Waddress", "");
83 put_help("-Wall", "");
84 put_help("-Waggregate-return", "");
85 put_help("-Wattribute", "");
86 put_help("-Wcast-qual", "");
87 put_help("-Wchar-subscripts", "");
88 put_help("-Wcomment", "");
89 put_help("-Wconversion", "");
90 put_help("-Wdeclaration-after-statement", "");
91 put_help("-Wdeprecated-declarations", "");
92 put_help("-Wdiv-by-zero", "");
93 put_help("-Wempty-statement", "");
94 put_help("-Werror", "warnings are errors");
95 put_help("-Werror-implicit-function-declaration", "");
96 put_help("-Wextra", "");
97 put_help("-Wfatal-errors", "");
98 put_help("-Wfloat-equal", "");
99 put_help("-Wformat", "");
100 put_help("-Wimplicit", "");
101 put_help("-Wimplicit-function-declaration", "");
102 put_help("-Wimplicit-int", "");
103 put_help("-Winit-self", "");
104 put_help("-Wlong-long", "");
105 put_help("-Wmain", "");
106 put_help("-Wmissing-declarations", "");
107 put_help("-Wmissing-noreturn", "");
108 put_help("-Wmissing-prototypes", "");
109 put_help("-Wmultichar", "");
110 put_help("-Wnested-externs", "");
111 put_help("-Wnonnull", "");
112 put_help("-Wold-style-definition", "");
113 put_help("-Wparentheses", "");
114 put_help("-Wpacked", "");
115 put_help("-Wpadded", "");
116 put_help("-Wparentheses", "");
117 put_help("-Wpointer-arith", "");
118 put_help("-Wredundant-decls", "");
119 put_help("-Wreturn-type", "");
120 put_help("-Wshadow", "");
121 put_help("-Wsign-compare", "");
122 put_help("-Wstrict-prototypes", "");
123 put_help("-Wswitch-default", "");
124 put_help("-Wswitch-enum", "");
125 put_help("-Wtraditional", "");
126 put_help("-Wuninitialized", "");
127 put_help("-Wunknown-pragmas", "");
128 put_help("-Wunreachable-code", "");
129 put_help("-Wunused", "");
130 put_help("-Wunused-function", "");
131 put_help("-Wunused-label", "");
132 put_help("-Wunused-parameter", "");
133 put_help("-Wunused-value", "");
134 put_help("-Wunused-variable", "");
135 put_help("-Wwrite-strings", "");
138 void set_warning_opt(const char *const opt)
145 if (s[0] == 'n' && s[1] == 'o' && s[2] == '-') {
151 #define OPTX(x) else if (strcmp(s, x) == 0)
152 #define SET(y) (void)(warning.y = state)
153 #define OPT(x, y) OPTX(x) SET(y)
155 /* Note: this switched on a lot more warnings than gcc's -Wall */
160 SET(char_subscripts);
162 SET(empty_statement);
164 SET(implicit_function_declaration);
171 SET(redundant_decls);
175 SET(strict_prototypes);
178 SET(unknown_pragmas);
179 SET(unreachable_code);
180 SET(unused_function);
182 SET(unused_parameter);
184 SET(unused_variable);
186 OPT("address", address);
187 OPT("aggregate-return", aggregate_return);
188 OPT("attribute", attribute);
189 OPT("cast-qual", cast_qual);
190 OPT("char-subscripts", char_subscripts);
191 OPT("comment", comment);
192 OPT("conversion", conversion);
193 OPT("declaration-after-statement", declaration_after_statement);
194 OPT("deprecated-declarations", deprecated_declarations);
195 OPT("div-by-zero", div_by_zero);
196 OPT("empty-statement", empty_statement);
197 OPT("error", s_are_errors);
198 OPT("error-implicit-function-declaration", error_implicit_function_declaration);
201 // TODO SET(function_end_without_return);
202 SET(empty_statement);
203 // TODO SET(incomplete_aggregate_init);
204 // TODO SET(missing_field_initializers);
205 // TODO SET(pointless_comparison);
206 SET(unused_parameter);
209 OPT("fatal-errors", fatal_errors);
210 OPT("float-equal", float_equal);
216 SET(implicit_function_declaration);
219 OPT("implicit-function-declaration", implicit_function_declaration);
220 OPT("implicit-int", implicit_int);
221 OPT("init-self", init_self);
222 OPT("long-long", long_long);
224 OPT("missing-declarations", missing_declarations);
225 OPT("missing-noreturn", missing_noreturn);
226 OPT("missing-prototypes", missing_prototypes);
227 OPT("multichar", multichar);
228 OPT("nested-externs", nested_externs);
229 OPT("nonnull", nonnull);
230 OPT("old-style-definition", old_style_definition);
231 OPT("packed", packed);
232 OPT("padded", padded);
233 OPT("parentheses", parentheses);
234 OPT("pointer-arith", pointer_arith);
235 OPT("redundant-decls", redundant_decls);
236 OPT("return-type", return_type);
237 OPT("shadow", shadow);
238 OPT("sign-compare", sign_compare);
239 OPT("strict-prototypes", strict_prototypes);
240 OPT("switch-default", switch_default);
241 OPT("switch-enum", switch_enum);
242 OPT("traditional", traditional);
243 OPT("uninitialized", uninitialized);
244 OPT("unknown-pragmas", unknown_pragmas);
245 OPT("unreachable-code", unreachable_code);
247 SET(unused_function);
249 SET(unused_parameter);
251 SET(unused_variable);
253 OPT("unused-function", unused_function);
254 OPT("unused-label", unused_label);
255 OPT("unused-parameter", unused_parameter);
256 OPT("unused-value", unused_value);
257 OPT("unused-variable", unused_variable);
258 OPT("write-strings", write_strings);
263 fprintf(stderr, "warning: ignoring unknown option -W%s\n", opt);