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, 2005, 2007 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
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
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/>. */
23 #include "coretypes.h"
30 #include "diagnostic.h"
31 #include "langhooks.h"
33 #include "alloc-pool.h"
35 /* Mingw specific format attributes ms_printf, ms_scanf, and ms_strftime. */
37 static const format_length_info ms_printf_length_specs
[] =
39 { "h", FMT_LEN_h
, STD_C89
, NULL
, 0, 0 },
40 { "l", FMT_LEN_l
, STD_C89
, NULL
, 0, 0 },
41 { "I32", FMT_LEN_l
, STD_EXT
, NULL
, 0, 0 },
42 { "I64", FMT_LEN_ll
, STD_EXT
, NULL
, 0, 0 },
43 { "I", FMT_LEN_L
, STD_EXT
, NULL
, 0, 0 },
44 { NULL
, 0, 0, NULL
, 0, 0 }
47 static const format_flag_spec ms_printf_flag_specs
[] =
49 { ' ', 0, 0, N_("' ' flag"), N_("the ' ' printf flag"), STD_C89
},
50 { '+', 0, 0, N_("'+' flag"), N_("the '+' printf flag"), STD_C89
},
51 { '#', 0, 0, N_("'#' flag"), N_("the '#' printf flag"), STD_C89
},
52 { '0', 0, 0, N_("'0' flag"), N_("the '0' printf flag"), STD_C89
},
53 { '-', 0, 0, N_("'-' flag"), N_("the '-' printf flag"), STD_C89
},
54 { '\'', 0, 0, N_("''' flag"), N_("the ''' printf flag"), STD_EXT
},
55 { 'w', 0, 0, N_("field width"), N_("field width in printf format"), STD_C89
},
56 { 'p', 0, 0, N_("precision"), N_("precision in printf format"), STD_C89
},
57 { 'L', 0, 0, N_("length modifier"), N_("length modifier in printf format"), STD_C89
},
58 { 0, 0, 0, NULL
, NULL
, 0 }
61 static const format_flag_pair ms_printf_flag_pairs
[] =
64 { '0', '-', 1, 0 }, { '0', 'p', 1, 'i' },
68 static const format_flag_spec ms_scanf_flag_specs
[] =
70 { '*', 0, 0, N_("assignment suppression"), N_("the assignment suppression scanf feature"), STD_C89
},
71 { 'a', 0, 0, N_("'a' flag"), N_("the 'a' scanf flag"), STD_EXT
},
72 { 'w', 0, 0, N_("field width"), N_("field width in scanf format"), STD_C89
},
73 { 'L', 0, 0, N_("length modifier"), N_("length modifier in scanf format"), STD_C89
},
74 { '\'', 0, 0, N_("''' flag"), N_("the ''' scanf flag"), STD_EXT
},
75 { 0, 0, 0, NULL
, NULL
, 0 }
78 static const format_flag_pair ms_scanf_flag_pairs
[] =
84 static const format_flag_spec ms_strftime_flag_specs
[] =
86 { '#', 0, 0, N_("'#' flag"), N_("the '#' strftime flag"), STD_EXT
},
87 { 0, 0, 0, NULL
, NULL
, 0 }
90 static const format_flag_pair ms_strftime_flag_pairs
[] =
95 static const format_char_info ms_print_char_table
[] =
97 /* C89 conversion specifiers. */
98 { "di", 0, STD_C89
, { T89_I
, BADLEN
, T89_S
, T89_L
, T9L_LL
, T99_SST
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-wp0 +'", "i", NULL
},
99 { "oxX", 0, STD_C89
, { T89_UI
, BADLEN
, T89_US
, T89_UL
, T9L_ULL
, T99_ST
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-wp0#", "i", NULL
},
100 { "u", 0, STD_C89
, { T89_UI
, BADLEN
, T89_US
, T89_UL
, T9L_ULL
, T99_ST
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-wp0'", "i", NULL
},
101 { "fgG", 0, STD_C89
, { T89_D
, BADLEN
, BADLEN
, T99_D
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-wp0 +#'", "", NULL
},
102 { "eE", 0, STD_C89
, { T89_D
, BADLEN
, BADLEN
, T99_D
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-wp0 +#", "", NULL
},
103 { "c", 0, STD_C89
, { T89_I
, BADLEN
, T89_S
, T94_WI
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-w", "", NULL
},
104 { "s", 1, STD_C89
, { T89_C
, BADLEN
, T89_S
, T94_W
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-wp", "cR", NULL
},
105 { "p", 1, STD_C89
, { T89_V
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-w", "c", NULL
},
106 { "n", 1, STD_C89
, { T89_I
, BADLEN
, T89_S
, T89_L
, T9L_LL
, BADLEN
, BADLEN
, BADLEN
, T99_IM
, BADLEN
, BADLEN
, BADLEN
}, "", "W", NULL
},
107 /* X/Open conversion specifiers. */
108 { "C", 0, STD_EXT
, { TEX_WI
, BADLEN
, T89_S
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-w", "", NULL
},
109 { "S", 1, STD_EXT
, { TEX_W
, BADLEN
, T89_S
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "-wp", "R", NULL
},
110 { NULL
, 0, 0, NOLENGTHS
, NULL
, NULL
, NULL
}
113 static const format_char_info ms_scan_char_table
[] =
115 /* C89 conversion specifiers. */
116 { "di", 1, STD_C89
, { T89_I
, BADLEN
, T89_S
, T89_L
, T9L_LL
, T99_SST
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "*w'", "W", NULL
},
117 { "u", 1, STD_C89
, { T89_UI
, BADLEN
, T89_US
, T89_UL
, T9L_ULL
, T99_ST
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "*w'", "W", NULL
},
118 { "oxX", 1, STD_C89
, { T89_UI
, BADLEN
, T89_US
, T89_UL
, T9L_ULL
, T99_ST
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "*w", "W", NULL
},
119 { "efgEG", 1, STD_C89
, { T89_F
, BADLEN
, BADLEN
, T89_D
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "*w'", "W", NULL
},
120 { "c", 1, STD_C89
, { T89_C
, BADLEN
, T89_S
, T94_W
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "*w", "cW", NULL
},
121 { "s", 1, STD_C89
, { T89_C
, BADLEN
, T89_S
, T94_W
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "*aw", "cW", NULL
},
122 { "[", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, T94_W
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "*aw", "cW[", NULL
},
123 { "p", 2, STD_C89
, { T89_V
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "*w", "W", NULL
},
124 { "n", 1, STD_C89
, { T89_I
, BADLEN
, T89_S
, T89_L
, T9L_LL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "", "W", NULL
},
125 /* X/Open conversion specifiers. */
126 { "C", 1, STD_EXT
, { TEX_W
, BADLEN
, T89_S
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "*w", "W", NULL
},
127 { "S", 1, STD_EXT
, { TEX_W
, BADLEN
, T89_S
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "*aw", "W", NULL
},
128 { NULL
, 0, 0, NOLENGTHS
, NULL
, NULL
, NULL
}
131 static const format_char_info ms_time_char_table
[] =
133 /* C89 conversion specifiers. */
134 { "ABZab", 0, STD_C89
, NOLENGTHS
, "#", "", NULL
},
135 { "cx", 0, STD_C89
, NOLENGTHS
, "#", "3", NULL
},
136 { "HIMSUWdmw", 0, STD_C89
, NOLENGTHS
, "#", "", NULL
},
137 { "j", 0, STD_C89
, NOLENGTHS
, "#", "", NULL
},
138 { "p", 0, STD_C89
, NOLENGTHS
, "#", "", NULL
},
139 { "X", 0, STD_C89
, NOLENGTHS
, "#", "", NULL
},
140 { "y", 0, STD_C89
, NOLENGTHS
, "#", "4", NULL
},
141 { "Y", 0, STD_C89
, NOLENGTHS
, "#", "", NULL
},
142 { "%", 0, STD_C89
, NOLENGTHS
, "", "", NULL
},
143 /* C99 conversion specifiers. */
144 { "z", 0, STD_C99
, NOLENGTHS
, "#", "", NULL
},
145 { NULL
, 0, 0, NOLENGTHS
, NULL
, NULL
, NULL
}
148 const format_kind_info mingw_format_attributes
[3] =
150 { "ms_printf", ms_printf_length_specs
, ms_print_char_table
, " +#0-'", NULL
,
151 ms_printf_flag_specs
, ms_printf_flag_pairs
,
152 FMT_FLAG_ARG_CONVERT
|FMT_FLAG_DOLLAR_MULTIPLE
|FMT_FLAG_USE_DOLLAR
|FMT_FLAG_EMPTY_PREC_OK
,
153 'w', 0, 'p', 0, 'L', 0,
154 &integer_type_node
, &integer_type_node
156 { "ms_scanf", ms_printf_length_specs
, ms_scan_char_table
, "*'", NULL
,
157 ms_scanf_flag_specs
, ms_scanf_flag_pairs
,
158 FMT_FLAG_ARG_CONVERT
|FMT_FLAG_SCANF_A_KLUDGE
|FMT_FLAG_USE_DOLLAR
|FMT_FLAG_ZERO_WIDTH_BAD
|FMT_FLAG_DOLLAR_GAP_POINTER_OK
,
159 'w', 0, 0, '*', 'L', 0,
162 { "ms_strftime", NULL
, ms_time_char_table
, "", "#",
163 ms_strftime_flag_specs
, ms_strftime_flag_pairs
,
164 FMT_FLAG_FANCY_PERCENT_OK
, 0, 0, 0, 0, 0, 0,
169 /* Default overrides for printf, scanf and strftime. */
170 const target_ovr_attr mingw_format_attribute_overrides
[4] =
172 { "ms_printf", "printf" },
173 { "ms_scanf", "scanf" },
174 { "ms_strftime", "strftime" }