skip_typeref().
[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         .address                       = true,
26         .aggregate_return              = false,
27         .attribute                     = true,
28         .cast_qual                     = false,
29         .char_subscripts               = true,
30         .comment                       = false,
31         .conversion                    = false,
32         .declaration_after_statement   = false,
33         .deprecated_declarations       = true,
34         .div_by_zero                   = true,
35         .empty_statement               = false,
36         .fatal_errors                  = false,
37         .float_equal                   = false,
38         .format                        = true,
39         .implicit_function_declaration = true,
40         .implicit_int                  = true,
41         .init_self                     = true,
42         .long_long                     = false,
43         .main                          = true,
44         .missing_declarations          = false,
45         .missing_noreturn              = false,
46         .missing_prototypes            = false,
47         .multichar                     = true,
48         .nested_externs                = false,
49         .nonnull                       = true,
50         .old_style_definition          = false,
51         .packed                        = false,
52         .padded                        = false,
53         .pointer_arith                 = true,
54         .redundant_decls               = true,
55         .return_type                   = true,
56         .s_are_errors                  = false,
57         .shadow                        = false,
58         .sign_compare                  = false,
59         .strict_prototypes             = true,
60         .switch_default                = false,
61         .switch_enum                   = false,
62         .traditional                   = false,
63         .unknown_pragmas               = true,
64         .unreachable_code              = false,
65         .unused_function               = false,
66         .unused_label                  = false,
67         .unused_parameter              = false,
68         .unused_value                  = true,
69         .unused_variable               = false,
70         .write_strings                 = false
71 };
72
73 void set_warning_opt(const char *const opt)
74 {
75         const char* s = opt;
76
77         bool state = true;
78
79         /* "no-" prefix */
80         if (s[0] == 'n' && s[1] == 'o' && s[2] == '-') {
81                 s += 3;
82                 state = false;
83         }
84
85         if (0) {}
86 #define OPTX(x)   else if (strcmp(s, x) == 0)
87 #define SET(y)    (void)(warning.y = state)
88 #define OPT(x, y) OPTX(x) SET(y)
89         OPTX("all") {
90                 /* Note: this switched on a lot of more warnings than gcc's -Wall */
91                 SET(address);
92                 SET(attribute);
93                 SET(char_subscripts);
94                 SET(comment);
95                 SET(empty_statement);
96                 SET(format);
97                 SET(implicit_function_declaration);
98                 SET(implicit_int);
99                 SET(init_self);
100                 SET(main);
101                 SET(nonnull);
102                 SET(pointer_arith);
103                 SET(redundant_decls);
104                 SET(return_type);
105                 SET(shadow);
106                 SET(sign_compare);
107                 SET(strict_prototypes);
108                 SET(switch_enum);
109                 SET(unknown_pragmas);
110                 SET(unreachable_code);
111                 SET(unused_function);
112                 SET(unused_label);
113                 SET(unused_parameter);
114                 SET(unused_value);
115                 SET(unused_variable);
116         }
117         OPT("address",                       address);
118         OPT("aggregate-return",              aggregate_return);
119         OPT("attribute",                     attribute);
120         OPT("cast-qual",                     cast_qual);
121         OPT("char-subscripts",               char_subscripts);
122         OPT("comment",                       comment);
123         OPT("conversion",                    conversion);
124         OPT("declaration-after-statement",   declaration_after_statement);
125         OPT("deprecated-declarations",       deprecated_declarations);
126         OPT("div-by-zero",                   div_by_zero);
127         OPT("empty-statement",               empty_statement);
128         OPT("error",                         s_are_errors);
129         OPTX("extra") {
130                 /* TODO */
131                 // TODO SET(function_end_without_return);
132                 SET(empty_statement);
133                 // TODO SET(incomplete_aggregate_init);
134                 // TODO SET(missing_field_initializers);
135                 // TODO SET(pointless_comparison);
136                 SET(unused_parameter);
137                 SET(unused_value);
138         }
139         OPT("fatal-errors",                  fatal_errors);
140         OPT("float-equal",                   float_equal);
141         OPTX("format") {
142                 SET(format);
143                 SET(nonnull);
144         }
145         OPTX("implicit") {
146                 SET(implicit_function_declaration);
147                 SET(implicit_int);
148         }
149         OPT("implicit-function-declaration", implicit_function_declaration);
150         OPT("implicit-int",                  implicit_int);
151         OPT("init-self",                     init_self);
152         OPT("long-long",                     long_long);
153         OPT("main",                          main);
154         OPT("missing-declarations",          missing_declarations);
155         OPT("missing-noreturn",              missing_noreturn);
156         OPT("missing-prototypes",            missing_prototypes);
157         OPT("multichar",                     multichar);
158         OPT("nested-externs",                nested_externs);
159         OPT("nonnull",                       nonnull);
160         OPT("old-style-definition",          old_style_definition);
161         OPT("packed",                        packed);
162         OPT("padded",                        padded);
163         OPT("pointer-arith",                 pointer_arith);
164         OPT("redundant-decls",               redundant_decls);
165         OPT("return-type",                   return_type);
166         OPT("shadow",                        shadow);
167         OPT("sign-compare",                  sign_compare);
168         OPT("strict-prototypes",             strict_prototypes);
169         OPT("switch-default",                switch_default);
170         OPT("switch-enum",                   switch_enum);
171         OPT("traditional",                   traditional);
172         OPT("unknown-pragmas",               unknown_pragmas);
173         OPT("unreachable-code",              unreachable_code);
174         OPTX("unused") {
175                 SET(unused_function);
176                 SET(unused_label);
177                 SET(unused_parameter);
178                 SET(unused_value);
179                 SET(unused_variable);
180         }
181         OPT("unused-function",               unused_function);
182         OPT("unused-label",                  unused_label);
183         OPT("unused-parameter",              unused_parameter);
184         OPT("unused-value",                  unused_value);
185         OPT("unused-variable",               unused_variable);
186         OPT("write-strings",                 write_strings);
187 #undef OPT
188 #undef SET
189 #undef OPT_X
190         else {
191                 fprintf(stderr, "warning: ignoring unknown option -W%s\n", opt);
192         }
193 }