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