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