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