00001 /* Check calls to formatted I/O functions (-Wformat). 00002 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 00003 2001, 2002, 2003, 2004 Free Software Foundation, Inc. 00004 00005 This file is part of GCC. 00006 00007 GCC is free software; you can redistribute it and/or modify it under 00008 the terms of the GNU General Public License as published by the Free 00009 Software Foundation; either version 2, or (at your option) any later 00010 version. 00011 00012 GCC is distributed in the hope that it will be useful, but WITHOUT ANY 00013 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00015 for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with GCC; see the file COPYING. If not, write to the Free 00019 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 00020 02111-1307, USA. */ 00021 00022 #ifndef GCC_C_FORMAT_H 00023 #define GCC_C_FORMAT_H 00024 00025 /* The meaningfully distinct length modifiers for format checking recognized 00026 by GCC. */ 00027 enum format_lengths 00028 { 00029 FMT_LEN_none, 00030 FMT_LEN_hh, 00031 FMT_LEN_h, 00032 FMT_LEN_l, 00033 FMT_LEN_ll, 00034 FMT_LEN_L, 00035 FMT_LEN_z, 00036 FMT_LEN_t, 00037 FMT_LEN_j, 00038 FMT_LEN_MAX 00039 }; 00040 00041 00042 /* The standard versions in which various format features appeared. */ 00043 enum format_std_version 00044 { 00045 STD_C89, 00046 STD_C94, 00047 STD_C9L, /* C99, but treat as C89 if -Wno-long-long. */ 00048 STD_C99, 00049 STD_EXT 00050 }; 00051 00052 /* Flags that may apply to a particular kind of format checked by GCC. */ 00053 enum 00054 { 00055 /* This format converts arguments of types determined by the 00056 format string. */ 00057 FMT_FLAG_ARG_CONVERT = 1, 00058 /* The scanf allocation 'a' kludge applies to this format kind. */ 00059 FMT_FLAG_SCANF_A_KLUDGE = 2, 00060 /* A % during parsing a specifier is allowed to be a modified % rather 00061 that indicating the format is broken and we are out-of-sync. */ 00062 FMT_FLAG_FANCY_PERCENT_OK = 4, 00063 /* With $ operand numbers, it is OK to reference the same argument more 00064 than once. */ 00065 FMT_FLAG_DOLLAR_MULTIPLE = 8, 00066 /* This format type uses $ operand numbers (strfmon doesn't). */ 00067 FMT_FLAG_USE_DOLLAR = 16, 00068 /* Zero width is bad in this type of format (scanf). */ 00069 FMT_FLAG_ZERO_WIDTH_BAD = 32, 00070 /* Empty precision specification is OK in this type of format (printf). */ 00071 FMT_FLAG_EMPTY_PREC_OK = 64, 00072 /* Gaps are allowed in the arguments with $ operand numbers if all 00073 arguments are pointers (scanf). */ 00074 FMT_FLAG_DOLLAR_GAP_POINTER_OK = 128 00075 /* Not included here: details of whether width or precision may occur 00076 (controlled by width_char and precision_char); details of whether 00077 '*' can be used for these (width_type and precision_type); details 00078 of whether length modifiers can occur (length_char_specs). */ 00079 }; 00080 00081 00082 /* Structure describing a length modifier supported in format checking, and 00083 possibly a doubled version such as "hh". */ 00084 typedef struct 00085 { 00086 /* Name of the single-character length modifier. */ 00087 const char *name; 00088 /* Index into a format_char_info.types array. */ 00089 enum format_lengths index; 00090 /* Standard version this length appears in. */ 00091 enum format_std_version std; 00092 /* Same, if the modifier can be repeated, or NULL if it can't. */ 00093 const char *double_name; 00094 enum format_lengths double_index; 00095 enum format_std_version double_std; 00096 } format_length_info; 00097 00098 00099 /* Structure describing the combination of a conversion specifier 00100 (or a set of specifiers which act identically) and a length modifier. */ 00101 typedef struct 00102 { 00103 /* The standard version this combination of length and type appeared in. 00104 This is only relevant if greater than those for length and type 00105 individually; otherwise it is ignored. */ 00106 enum format_std_version std; 00107 /* The name to use for the type, if different from that generated internally 00108 (e.g., "signed size_t"). */ 00109 const char *name; 00110 /* The type itself. */ 00111 tree *type; 00112 } format_type_detail; 00113 00114 00115 /* Macros to fill out tables of these. */ 00116 #define NOARGUMENTS { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN } 00117 #define BADLEN { 0, NULL, NULL } 00118 #define NOLENGTHS { BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN } 00119 00120 00121 /* Structure describing a format conversion specifier (or a set of specifiers 00122 which act identically), and the length modifiers used with it. */ 00123 typedef struct format_char_info 00124 { 00125 const char *format_chars; 00126 int pointer_count; 00127 enum format_std_version std; 00128 /* Types accepted for each length modifier. */ 00129 format_type_detail types[FMT_LEN_MAX]; 00130 /* List of other modifier characters allowed with these specifiers. 00131 This lists flags, and additionally "w" for width, "p" for precision 00132 (right precision, for strfmon), "#" for left precision (strfmon), 00133 "a" for scanf "a" allocation extension (not applicable in C99 mode), 00134 "*" for scanf suppression, and "E" and "O" for those strftime 00135 modifiers. */ 00136 const char *flag_chars; 00137 /* List of additional flags describing these conversion specifiers. 00138 "c" for generic character pointers being allowed, "2" for strftime 00139 two digit year formats, "3" for strftime formats giving two digit 00140 years in some locales, "4" for "2" which becomes "3" with an "E" modifier, 00141 "o" if use of strftime "O" is a GNU extension beyond C99, 00142 "W" if the argument is a pointer which is dereferenced and written into, 00143 "R" if the argument is a pointer which is dereferenced and read from, 00144 "i" for printf integer formats where the '0' flag is ignored with 00145 precision, and "[" for the starting character of a scanf scanset. */ 00146 const char *flags2; 00147 /* If this format conversion character consumes more than one argument, 00148 CHAIN points to information about the next argument. For later 00149 arguments, only POINTER_COUNT, TYPES, and the "c", "R", and "W" flags 00150 in FLAGS2 are used. */ 00151 const struct format_char_info *chain; 00152 } format_char_info; 00153 00154 00155 /* Structure describing a flag accepted by some kind of format. */ 00156 typedef struct 00157 { 00158 /* The flag character in question (0 for end of array). */ 00159 int flag_char; 00160 /* Zero if this entry describes the flag character in general, or a 00161 nonzero character that may be found in flags2 if it describes the 00162 flag when used with certain formats only. If the latter, only 00163 the first such entry found that applies to the current conversion 00164 specifier is used; the values of 'name' and 'long_name' it supplies 00165 will be used, if non-NULL and the standard version is higher than 00166 the unpredicated one, for any pedantic warning. For example, 'o' 00167 for strftime formats (meaning 'O' is an extension over C99). */ 00168 int predicate; 00169 /* Nonzero if the next character after this flag in the format should 00170 be skipped ('=' in strfmon), zero otherwise. */ 00171 int skip_next_char; 00172 /* The name to use for this flag in diagnostic messages. For example, 00173 N_("'0' flag"), N_("field width"). */ 00174 const char *name; 00175 /* Long name for this flag in diagnostic messages; currently only used for 00176 "ISO C does not support ...". For example, N_("the 'I' printf flag"). */ 00177 const char *long_name; 00178 /* The standard version in which it appeared. */ 00179 enum format_std_version std; 00180 } format_flag_spec; 00181 00182 00183 /* Structure describing a combination of flags that is bad for some kind 00184 of format. */ 00185 typedef struct 00186 { 00187 /* The first flag character in question (0 for end of array). */ 00188 int flag_char1; 00189 /* The second flag character. */ 00190 int flag_char2; 00191 /* Nonzero if the message should say that the first flag is ignored with 00192 the second, zero if the combination should simply be objected to. */ 00193 int ignored; 00194 /* Zero if this entry applies whenever this flag combination occurs, 00195 a nonzero character from flags2 if it only applies in some 00196 circumstances (e.g. 'i' for printf formats ignoring 0 with precision). */ 00197 int predicate; 00198 } format_flag_pair; 00199 00200 00201 /* Structure describing a particular kind of format processed by GCC. */ 00202 typedef struct 00203 { 00204 /* The name of this kind of format, for use in diagnostics. Also 00205 the name of the attribute (without preceding and following __). */ 00206 const char *name; 00207 /* Specifications of the length modifiers accepted; possibly NULL. */ 00208 const format_length_info *length_char_specs; 00209 /* Details of the conversion specification characters accepted. */ 00210 const format_char_info *conversion_specs; 00211 /* String listing the flag characters that are accepted. */ 00212 const char *flag_chars; 00213 /* String listing modifier characters (strftime) accepted. May be NULL. */ 00214 const char *modifier_chars; 00215 /* Details of the flag characters, including pseudo-flags. */ 00216 const format_flag_spec *flag_specs; 00217 /* Details of bad combinations of flags. */ 00218 const format_flag_pair *bad_flag_pairs; 00219 /* Flags applicable to this kind of format. */ 00220 int flags; 00221 /* Flag character to treat a width as, or 0 if width not used. */ 00222 int width_char; 00223 /* Flag character to treat a left precision (strfmon) as, 00224 or 0 if left precision not used. */ 00225 int left_precision_char; 00226 /* Flag character to treat a precision (for strfmon, right precision) as, 00227 or 0 if precision not used. */ 00228 int precision_char; 00229 /* If a flag character has the effect of suppressing the conversion of 00230 an argument ('*' in scanf), that flag character, otherwise 0. */ 00231 int suppression_char; 00232 /* Flag character to treat a length modifier as (ignored if length 00233 modifiers not used). Need not be placed in flag_chars for conversion 00234 specifiers, but is used to check for bad combinations such as length 00235 modifier with assignment suppression in scanf. */ 00236 int length_code_char; 00237 /* Pointer to type of argument expected if '*' is used for a width, 00238 or NULL if '*' not used for widths. */ 00239 tree *width_type; 00240 /* Pointer to type of argument expected if '*' is used for a precision, 00241 or NULL if '*' not used for precisions. */ 00242 tree *precision_type; 00243 } format_kind_info; 00244 00245 #define T_I &integer_type_node 00246 #define T89_I { STD_C89, NULL, T_I } 00247 #define T_L &long_integer_type_node 00248 #define T89_L { STD_C89, NULL, T_L } 00249 #define T_LL &long_long_integer_type_node 00250 #define T9L_LL { STD_C9L, NULL, T_LL } 00251 #define TEX_LL { STD_EXT, NULL, T_LL } 00252 #define T_S &short_integer_type_node 00253 #define T89_S { STD_C89, NULL, T_S } 00254 #define T_UI &unsigned_type_node 00255 #define T89_UI { STD_C89, NULL, T_UI } 00256 #define T_UL &long_unsigned_type_node 00257 #define T89_UL { STD_C89, NULL, T_UL } 00258 #define T_ULL &long_long_unsigned_type_node 00259 #define T9L_ULL { STD_C9L, NULL, T_ULL } 00260 #define TEX_ULL { STD_EXT, NULL, T_ULL } 00261 #define T_US &short_unsigned_type_node 00262 #define T89_US { STD_C89, NULL, T_US } 00263 #define T_F &float_type_node 00264 #define T89_F { STD_C89, NULL, T_F } 00265 #define T99_F { STD_C99, NULL, T_F } 00266 #define T_D &double_type_node 00267 #define T89_D { STD_C89, NULL, T_D } 00268 #define T99_D { STD_C99, NULL, T_D } 00269 #define T_LD &long_double_type_node 00270 #define T89_LD { STD_C89, NULL, T_LD } 00271 #define T99_LD { STD_C99, NULL, T_LD } 00272 #define T_C &char_type_node 00273 #define T89_C { STD_C89, NULL, T_C } 00274 #define T_SC &signed_char_type_node 00275 #define T99_SC { STD_C99, NULL, T_SC } 00276 #define T_UC &unsigned_char_type_node 00277 #define T99_UC { STD_C99, NULL, T_UC } 00278 #define T_V &void_type_node 00279 #define T89_V { STD_C89, NULL, T_V } 00280 #define T_W &wchar_type_node 00281 #define T94_W { STD_C94, "wchar_t", T_W } 00282 #define TEX_W { STD_EXT, "wchar_t", T_W } 00283 #define T_WI &wint_type_node 00284 #define T94_WI { STD_C94, "wint_t", T_WI } 00285 #define TEX_WI { STD_EXT, "wint_t", T_WI } 00286 #define T_ST &size_type_node 00287 #define T99_ST { STD_C99, "size_t", T_ST } 00288 #define T_SST &signed_size_type_node 00289 #define T99_SST { STD_C99, "signed size_t", T_SST } 00290 #define T_PD &ptrdiff_type_node 00291 #define T99_PD { STD_C99, "ptrdiff_t", T_PD } 00292 #define T_UPD &unsigned_ptrdiff_type_node 00293 #define T99_UPD { STD_C99, "unsigned ptrdiff_t", T_UPD } 00294 #define T_IM &intmax_type_node 00295 #define T99_IM { STD_C99, "intmax_t", T_IM } 00296 #define T_UIM &uintmax_type_node 00297 #define T99_UIM { STD_C99, "uintmax_t", T_UIM } 00298 00299 #endif /* GCC_C_FORMAT_H */
1.5.6