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