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