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