]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/gcc/c-format.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / gcc / c-format.h
1 /* Check calls to formatted I/O functions (-Wformat).
2    Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3    2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301, USA.  */
21
22 #ifndef GCC_C_FORMAT_H
23 #define GCC_C_FORMAT_H
24
25 /* The meaningfully distinct length modifiers for format checking recognized
26    by GCC.  */
27 enum format_lengths
28 {
29   FMT_LEN_none,
30   FMT_LEN_hh,
31   FMT_LEN_h,
32   FMT_LEN_l,
33   FMT_LEN_ll,
34   FMT_LEN_L,
35   FMT_LEN_z,
36   FMT_LEN_t,
37   FMT_LEN_j,
38   FMT_LEN_H,
39   FMT_LEN_D,
40   FMT_LEN_DD,
41   FMT_LEN_MAX
42 };
43
44
45 /* The standard versions in which various format features appeared.  */
46 enum format_std_version
47 {
48   STD_C89,
49   STD_C94,
50   STD_C9L, /* C99, but treat as C89 if -Wno-long-long.  */
51   STD_C99,
52   STD_EXT
53 };
54
55 /* Flags that may apply to a particular kind of format checked by GCC.  */
56 enum
57 {
58   /* This format converts arguments of types determined by the
59      format string.  */
60   FMT_FLAG_ARG_CONVERT = 1,
61   /* The scanf allocation 'a' kludge applies to this format kind.  */
62   FMT_FLAG_SCANF_A_KLUDGE = 2,
63   /* A % during parsing a specifier is allowed to be a modified % rather
64      that indicating the format is broken and we are out-of-sync.  */
65   FMT_FLAG_FANCY_PERCENT_OK = 4,
66   /* With $ operand numbers, it is OK to reference the same argument more
67      than once.  */
68   FMT_FLAG_DOLLAR_MULTIPLE = 8,
69   /* This format type uses $ operand numbers (strfmon doesn't).  */
70   FMT_FLAG_USE_DOLLAR = 16,
71   /* Zero width is bad in this type of format (scanf).  */
72   FMT_FLAG_ZERO_WIDTH_BAD = 32,
73   /* Empty precision specification is OK in this type of format (printf).  */
74   FMT_FLAG_EMPTY_PREC_OK = 64,
75   /* Gaps are allowed in the arguments with $ operand numbers if all
76      arguments are pointers (scanf).  */
77   FMT_FLAG_DOLLAR_GAP_POINTER_OK = 128,
78   /* Not included here: details of whether width or precision may occur
79      (controlled by width_char and precision_char); details of whether
80      '*' can be used for these (width_type and precision_type); details
81      of whether length modifiers can occur (length_char_specs).  */
82   FMT_FLAG_NULL_FORMAT_OK = 256
83 };
84
85
86 /* Structure describing a length modifier supported in format checking, and
87    possibly a doubled version such as "hh".  */
88 typedef struct
89 {
90   /* Name of the single-character length modifier.  */
91   const char *name;
92   /* Index into a format_char_info.types array.  */
93   enum format_lengths index;
94   /* Standard version this length appears in.  */
95   enum format_std_version std;
96   /* Same, if the modifier can be repeated, or NULL if it can't.  */
97   const char *double_name;
98   enum format_lengths double_index;
99   enum format_std_version double_std;
100 } format_length_info;
101
102
103 /* Structure describing the combination of a conversion specifier
104    (or a set of specifiers which act identically) and a length modifier.  */
105 typedef struct
106 {
107   /* The standard version this combination of length and type appeared in.
108      This is only relevant if greater than those for length and type
109      individually; otherwise it is ignored.  */
110   enum format_std_version std;
111   /* The name to use for the type, if different from that generated internally
112      (e.g., "signed size_t").  */
113   const char *name;
114   /* The type itself.  */
115   tree *type;
116 } format_type_detail;
117
118
119 /* Macros to fill out tables of these.  */
120 #define NOARGUMENTS     { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }
121 #define BADLEN  { 0, NULL, NULL }
122 #define NOLENGTHS       { BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }
123
124
125 /* Structure describing a format conversion specifier (or a set of specifiers
126    which act identically), and the length modifiers used with it.  */
127 typedef struct format_char_info
128 {
129   const char *format_chars;
130   int pointer_count;
131   enum format_std_version std;
132   /* Types accepted for each length modifier.  */
133   format_type_detail types[FMT_LEN_MAX];
134   /* List of other modifier characters allowed with these specifiers.
135      This lists flags, and additionally "w" for width, "p" for precision
136      (right precision, for strfmon), "#" for left precision (strfmon),
137      "a" for scanf "a" allocation extension (not applicable in C99 mode),
138      "*" for scanf suppression, and "E" and "O" for those strftime
139      modifiers.  */
140   const char *flag_chars;
141   /* List of additional flags describing these conversion specifiers.
142      "c" for generic character pointers being allowed, "2" for strftime
143      two digit year formats, "3" for strftime formats giving two digit
144      years in some locales, "4" for "2" which becomes "3" with an "E" modifier,
145      "o" if use of strftime "O" is a GNU extension beyond C99,
146      "W" if the argument is a pointer which is dereferenced and written into,
147      "R" if the argument is a pointer which is dereferenced and read from,
148      "i" for printf integer formats where the '0' flag is ignored with
149      precision, and "[" for the starting character of a scanf scanset.  */
150   const char *flags2;
151   /* If this format conversion character consumes more than one argument,
152      CHAIN points to information about the next argument.  For later
153      arguments, only POINTER_COUNT, TYPES, and the "c", "R", and "W" flags
154      in FLAGS2 are used.  */
155   const struct format_char_info *chain;
156 } format_char_info;
157
158
159 /* Structure describing a flag accepted by some kind of format.  */
160 typedef struct
161 {
162   /* The flag character in question (0 for end of array).  */
163   int flag_char;
164   /* Zero if this entry describes the flag character in general, or a
165      nonzero character that may be found in flags2 if it describes the
166      flag when used with certain formats only.  If the latter, only
167      the first such entry found that applies to the current conversion
168      specifier is used; the values of 'name' and 'long_name' it supplies
169      will be used, if non-NULL and the standard version is higher than
170      the unpredicated one, for any pedantic warning.  For example, 'o'
171      for strftime formats (meaning 'O' is an extension over C99).  */
172   int predicate;
173   /* Nonzero if the next character after this flag in the format should
174      be skipped ('=' in strfmon), zero otherwise.  */
175   int skip_next_char;
176   /* The name to use for this flag in diagnostic messages.  For example,
177      N_("'0' flag"), N_("field width").  */
178   const char *name;
179   /* Long name for this flag in diagnostic messages; currently only used for
180      "ISO C does not support ...".  For example, N_("the 'I' printf flag").  */
181   const char *long_name;
182   /* The standard version in which it appeared.  */
183   enum format_std_version std;
184 } format_flag_spec;
185
186
187 /* Structure describing a combination of flags that is bad for some kind
188    of format.  */
189 typedef struct
190 {
191   /* The first flag character in question (0 for end of array).  */
192   int flag_char1;
193   /* The second flag character.  */
194   int flag_char2;
195   /* Nonzero if the message should say that the first flag is ignored with
196      the second, zero if the combination should simply be objected to.  */
197   int ignored;
198   /* Zero if this entry applies whenever this flag combination occurs,
199      a nonzero character from flags2 if it only applies in some
200      circumstances (e.g. 'i' for printf formats ignoring 0 with precision).  */
201   int predicate;
202 } format_flag_pair;
203
204
205 /* Structure describing a particular kind of format processed by GCC.  */
206 typedef struct
207 {
208   /* The name of this kind of format, for use in diagnostics.  Also
209      the name of the attribute (without preceding and following __).  */
210   const char *name;
211   /* Specifications of the length modifiers accepted; possibly NULL.  */
212   const format_length_info *length_char_specs;
213   /* Details of the conversion specification characters accepted.  */
214   const format_char_info *conversion_specs;
215   /* String listing the flag characters that are accepted.  */
216   const char *flag_chars;
217   /* String listing modifier characters (strftime) accepted.  May be NULL.  */
218   const char *modifier_chars;
219   /* Details of the flag characters, including pseudo-flags.  */
220   const format_flag_spec *flag_specs;
221   /* Details of bad combinations of flags.  */
222   const format_flag_pair *bad_flag_pairs;
223   /* Flags applicable to this kind of format.  */
224   int flags;
225   /* Flag character to treat a width as, or 0 if width not used.  */
226   int width_char;
227   /* Flag character to treat a left precision (strfmon) as,
228      or 0 if left precision not used.  */
229   int left_precision_char;
230   /* Flag character to treat a precision (for strfmon, right precision) as,
231      or 0 if precision not used.  */
232   int precision_char;
233   /* If a flag character has the effect of suppressing the conversion of
234      an argument ('*' in scanf), that flag character, otherwise 0.  */
235   int suppression_char;
236   /* Flag character to treat a length modifier as (ignored if length
237      modifiers not used).  Need not be placed in flag_chars for conversion
238      specifiers, but is used to check for bad combinations such as length
239      modifier with assignment suppression in scanf.  */
240   int length_code_char;
241   /* Pointer to type of argument expected if '*' is used for a width,
242      or NULL if '*' not used for widths.  */
243   tree *width_type;
244   /* Pointer to type of argument expected if '*' is used for a precision,
245      or NULL if '*' not used for precisions.  */
246   tree *precision_type;
247 } format_kind_info;
248
249 #define T_I     &integer_type_node
250 #define T89_I   { STD_C89, NULL, T_I }
251 #define T_L     &long_integer_type_node
252 #define T89_L   { STD_C89, NULL, T_L }
253 #define T_LL    &long_long_integer_type_node
254 #define T9L_LL  { STD_C9L, NULL, T_LL }
255 #define TEX_LL  { STD_EXT, NULL, T_LL }
256 #define T_S     &short_integer_type_node
257 #define T89_S   { STD_C89, NULL, T_S }
258 #define T_UI    &unsigned_type_node
259 #define T89_UI  { STD_C89, NULL, T_UI }
260 #define T_UL    &long_unsigned_type_node
261 #define T89_UL  { STD_C89, NULL, T_UL }
262 #define T_ULL   &long_long_unsigned_type_node
263 #define T9L_ULL { STD_C9L, NULL, T_ULL }
264 #define TEX_ULL { STD_EXT, NULL, T_ULL }
265 #define T_US    &short_unsigned_type_node
266 #define T89_US  { STD_C89, NULL, T_US }
267 #define T_F     &float_type_node
268 #define T89_F   { STD_C89, NULL, T_F }
269 #define T99_F   { STD_C99, NULL, T_F }
270 #define T_D     &double_type_node
271 #define T89_D   { STD_C89, NULL, T_D }
272 #define T99_D   { STD_C99, NULL, T_D }
273 #define T_LD    &long_double_type_node
274 #define T89_LD  { STD_C89, NULL, T_LD }
275 #define T99_LD  { STD_C99, NULL, T_LD }
276 #define T_C     &char_type_node
277 #define T89_C   { STD_C89, NULL, T_C }
278 #define T_SC    &signed_char_type_node
279 #define T99_SC  { STD_C99, NULL, T_SC }
280 #define T_UC    &unsigned_char_type_node
281 #define T99_UC  { STD_C99, NULL, T_UC }
282 #define T_V     &void_type_node
283 #define T89_V   { STD_C89, NULL, T_V }
284 #define T_W     &wchar_type_node
285 #define T94_W   { STD_C94, "wchar_t", T_W }
286 #define TEX_W   { STD_EXT, "wchar_t", T_W }
287 #define T_WI    &wint_type_node
288 #define T94_WI  { STD_C94, "wint_t", T_WI }
289 #define TEX_WI  { STD_EXT, "wint_t", T_WI }
290 #define T_ST    &size_type_node
291 #define T99_ST  { STD_C99, "size_t", T_ST }
292 #define T_SST   &signed_size_type_node
293 #define T99_SST { STD_C99, "signed size_t", T_SST }
294 #define T_PD    &ptrdiff_type_node
295 #define T99_PD  { STD_C99, "ptrdiff_t", T_PD }
296 #define T_UPD   &unsigned_ptrdiff_type_node
297 #define T99_UPD { STD_C99, "unsigned ptrdiff_t", T_UPD }
298 #define T_IM    &intmax_type_node
299 #define T99_IM  { STD_C99, "intmax_t", T_IM }
300 #define T_UIM   &uintmax_type_node
301 #define T99_UIM { STD_C99, "uintmax_t", T_UIM }
302 #define T_D32   &dfloat32_type_node
303 #define TEX_D32 { STD_EXT, "_Decimal32", T_D32 }
304 #define T_D64   &dfloat64_type_node
305 #define TEX_D64 { STD_EXT, "_Decimal64", T_D64 }
306 #define T_D128  &dfloat128_type_node
307 #define TEX_D128 { STD_EXT, "_Decimal128", T_D128 }
308
309 #endif /* GCC_C_FORMAT_H */