Mercurial > hg > CbC > CbC_gcc
comparison libcpp/errors.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
1 /* Default error handlers for CPP Library. | 1 /* Default error handlers for CPP Library. |
2 Copyright (C) 1986-2017 Free Software Foundation, Inc. | 2 Copyright (C) 1986-2018 Free Software Foundation, Inc. |
3 Written by Per Bothner, 1994. | 3 Written by Per Bothner, 1994. |
4 Based on CCCP program by Paul Rubin, June 1986 | 4 Based on CCCP program by Paul Rubin, June 1986 |
5 Adapted to ANSI C, Richard Stallman, Jan 1987 | 5 Adapted to ANSI C, Richard Stallman, Jan 1987 |
6 | 6 |
7 This program is free software; you can redistribute it and/or modify it | 7 This program is free software; you can redistribute it and/or modify it |
29 | 29 |
30 /* Print a diagnostic at the given location. */ | 30 /* Print a diagnostic at the given location. */ |
31 | 31 |
32 ATTRIBUTE_FPTR_PRINTF(5,0) | 32 ATTRIBUTE_FPTR_PRINTF(5,0) |
33 static bool | 33 static bool |
34 cpp_diagnostic_at_richloc (cpp_reader * pfile, int level, int reason, | 34 cpp_diagnostic_at (cpp_reader * pfile, enum cpp_diagnostic_level level, |
35 rich_location *richloc, | 35 enum cpp_warning_reason reason, rich_location *richloc, |
36 const char *msgid, va_list *ap) | 36 const char *msgid, va_list *ap) |
37 { | 37 { |
38 bool ret; | 38 bool ret; |
39 | 39 |
40 if (!pfile->cb.error) | 40 if (!pfile->cb.diagnostic) |
41 abort (); | 41 abort (); |
42 ret = pfile->cb.error (pfile, level, reason, richloc, _(msgid), ap); | 42 ret = pfile->cb.diagnostic (pfile, level, reason, richloc, _(msgid), ap); |
43 | |
44 return ret; | |
45 } | |
46 | |
47 /* Print a diagnostic at the given location. */ | |
48 | |
49 ATTRIBUTE_FPTR_PRINTF(5,0) | |
50 static bool | |
51 cpp_diagnostic_at (cpp_reader * pfile, int level, int reason, | |
52 source_location src_loc, | |
53 const char *msgid, va_list *ap) | |
54 { | |
55 bool ret; | |
56 | |
57 if (!pfile->cb.error) | |
58 abort (); | |
59 rich_location richloc (pfile->line_table, src_loc); | |
60 ret = pfile->cb.error (pfile, level, reason, &richloc, _(msgid), ap); | |
61 | 43 |
62 return ret; | 44 return ret; |
63 } | 45 } |
64 | 46 |
65 /* Print a diagnostic at the location of the previously lexed token. */ | 47 /* Print a diagnostic at the location of the previously lexed token. */ |
66 | 48 |
67 ATTRIBUTE_FPTR_PRINTF(4,0) | 49 ATTRIBUTE_FPTR_PRINTF(4,0) |
68 static bool | 50 static bool |
69 cpp_diagnostic (cpp_reader * pfile, int level, int reason, | 51 cpp_diagnostic (cpp_reader * pfile, enum cpp_diagnostic_level level, |
70 const char *msgid, va_list *ap) | 52 enum cpp_warning_reason reason, |
53 const char *msgid, va_list *ap) | |
71 { | 54 { |
72 source_location src_loc; | 55 source_location src_loc; |
73 | 56 |
74 if (CPP_OPTION (pfile, traditional)) | 57 if (CPP_OPTION (pfile, traditional)) |
75 { | 58 { |
86 } | 69 } |
87 else | 70 else |
88 { | 71 { |
89 src_loc = pfile->cur_token[-1].src_loc; | 72 src_loc = pfile->cur_token[-1].src_loc; |
90 } | 73 } |
91 return cpp_diagnostic_at (pfile, level, reason, src_loc, msgid, ap); | 74 rich_location richloc (pfile->line_table, src_loc); |
75 return cpp_diagnostic_at (pfile, level, reason, &richloc, msgid, ap); | |
92 } | 76 } |
93 | 77 |
94 /* Print a warning or error, depending on the value of LEVEL. */ | 78 /* Print a warning or error, depending on the value of LEVEL. */ |
95 | 79 |
96 bool | 80 bool |
97 cpp_error (cpp_reader * pfile, int level, const char *msgid, ...) | 81 cpp_error (cpp_reader * pfile, enum cpp_diagnostic_level level, |
82 const char *msgid, ...) | |
98 { | 83 { |
99 va_list ap; | 84 va_list ap; |
100 bool ret; | 85 bool ret; |
101 | 86 |
102 va_start (ap, msgid); | 87 va_start (ap, msgid); |
108 } | 93 } |
109 | 94 |
110 /* Print a warning. The warning reason may be given in REASON. */ | 95 /* Print a warning. The warning reason may be given in REASON. */ |
111 | 96 |
112 bool | 97 bool |
113 cpp_warning (cpp_reader * pfile, int reason, const char *msgid, ...) | 98 cpp_warning (cpp_reader * pfile, enum cpp_warning_reason reason, |
99 const char *msgid, ...) | |
114 { | 100 { |
115 va_list ap; | 101 va_list ap; |
116 bool ret; | 102 bool ret; |
117 | 103 |
118 va_start (ap, msgid); | 104 va_start (ap, msgid); |
124 } | 110 } |
125 | 111 |
126 /* Print a pedantic warning. The warning reason may be given in REASON. */ | 112 /* Print a pedantic warning. The warning reason may be given in REASON. */ |
127 | 113 |
128 bool | 114 bool |
129 cpp_pedwarning (cpp_reader * pfile, int reason, const char *msgid, ...) | 115 cpp_pedwarning (cpp_reader * pfile, enum cpp_warning_reason reason, |
116 const char *msgid, ...) | |
130 { | 117 { |
131 va_list ap; | 118 va_list ap; |
132 bool ret; | 119 bool ret; |
133 | 120 |
134 va_start (ap, msgid); | 121 va_start (ap, msgid); |
141 | 128 |
142 /* Print a warning, including system headers. The warning reason may be | 129 /* Print a warning, including system headers. The warning reason may be |
143 given in REASON. */ | 130 given in REASON. */ |
144 | 131 |
145 bool | 132 bool |
146 cpp_warning_syshdr (cpp_reader * pfile, int reason, const char *msgid, ...) | 133 cpp_warning_syshdr (cpp_reader * pfile, enum cpp_warning_reason reason, |
134 const char *msgid, ...) | |
147 { | 135 { |
148 va_list ap; | 136 va_list ap; |
149 bool ret; | 137 bool ret; |
150 | 138 |
151 va_start (ap, msgid); | 139 va_start (ap, msgid); |
158 | 146 |
159 /* Print a diagnostic at a specific location. */ | 147 /* Print a diagnostic at a specific location. */ |
160 | 148 |
161 ATTRIBUTE_FPTR_PRINTF(6,0) | 149 ATTRIBUTE_FPTR_PRINTF(6,0) |
162 static bool | 150 static bool |
163 cpp_diagnostic_with_line (cpp_reader * pfile, int level, int reason, | 151 cpp_diagnostic_with_line (cpp_reader * pfile, enum cpp_diagnostic_level level, |
164 source_location src_loc, unsigned int column, | 152 enum cpp_warning_reason reason, |
165 const char *msgid, va_list *ap) | 153 source_location src_loc, unsigned int column, |
154 const char *msgid, va_list *ap) | |
166 { | 155 { |
167 bool ret; | 156 bool ret; |
168 | 157 |
169 if (!pfile->cb.error) | 158 if (!pfile->cb.diagnostic) |
170 abort (); | 159 abort (); |
171 rich_location richloc (pfile->line_table, src_loc); | 160 rich_location richloc (pfile->line_table, src_loc); |
172 if (column) | 161 if (column) |
173 richloc.override_column (column); | 162 richloc.override_column (column); |
174 ret = pfile->cb.error (pfile, level, reason, &richloc, _(msgid), ap); | 163 ret = pfile->cb.diagnostic (pfile, level, reason, &richloc, _(msgid), ap); |
175 | 164 |
176 return ret; | 165 return ret; |
177 } | 166 } |
178 | 167 |
179 /* Print a warning or error, depending on the value of LEVEL. */ | 168 /* Print a warning or error, depending on the value of LEVEL. */ |
180 | 169 |
181 bool | 170 bool |
182 cpp_error_with_line (cpp_reader *pfile, int level, | 171 cpp_error_with_line (cpp_reader *pfile, enum cpp_diagnostic_level level, |
183 source_location src_loc, unsigned int column, | 172 source_location src_loc, unsigned int column, |
184 const char *msgid, ...) | 173 const char *msgid, ...) |
185 { | 174 { |
186 va_list ap; | 175 va_list ap; |
187 bool ret; | 176 bool ret; |
196 } | 185 } |
197 | 186 |
198 /* Print a warning. The warning reason may be given in REASON. */ | 187 /* Print a warning. The warning reason may be given in REASON. */ |
199 | 188 |
200 bool | 189 bool |
201 cpp_warning_with_line (cpp_reader *pfile, int reason, | 190 cpp_warning_with_line (cpp_reader *pfile, enum cpp_warning_reason reason, |
202 source_location src_loc, unsigned int column, | 191 source_location src_loc, unsigned int column, |
203 const char *msgid, ...) | 192 const char *msgid, ...) |
204 { | 193 { |
205 va_list ap; | 194 va_list ap; |
206 bool ret; | 195 bool ret; |
215 } | 204 } |
216 | 205 |
217 /* Print a pedantic warning. The warning reason may be given in REASON. */ | 206 /* Print a pedantic warning. The warning reason may be given in REASON. */ |
218 | 207 |
219 bool | 208 bool |
220 cpp_pedwarning_with_line (cpp_reader *pfile, int reason, | 209 cpp_pedwarning_with_line (cpp_reader *pfile, enum cpp_warning_reason reason, |
221 source_location src_loc, unsigned int column, | 210 source_location src_loc, unsigned int column, |
222 const char *msgid, ...) | 211 const char *msgid, ...) |
223 { | 212 { |
224 va_list ap; | 213 va_list ap; |
225 bool ret; | 214 bool ret; |
226 | 215 |
227 va_start (ap, msgid); | 216 va_start (ap, msgid); |
235 | 224 |
236 /* Print a warning, including system headers. The warning reason may be | 225 /* Print a warning, including system headers. The warning reason may be |
237 given in REASON. */ | 226 given in REASON. */ |
238 | 227 |
239 bool | 228 bool |
240 cpp_warning_with_line_syshdr (cpp_reader *pfile, int reason, | 229 cpp_warning_with_line_syshdr (cpp_reader *pfile, enum cpp_warning_reason reason, |
241 source_location src_loc, unsigned int column, | 230 source_location src_loc, unsigned int column, |
242 const char *msgid, ...) | 231 const char *msgid, ...) |
243 { | 232 { |
244 va_list ap; | 233 va_list ap; |
245 bool ret; | 234 bool ret; |
246 | 235 |
247 va_start (ap, msgid); | 236 va_start (ap, msgid); |
255 | 244 |
256 /* As cpp_error, but use SRC_LOC as the location of the error, without | 245 /* As cpp_error, but use SRC_LOC as the location of the error, without |
257 a column override. */ | 246 a column override. */ |
258 | 247 |
259 bool | 248 bool |
260 cpp_error_at (cpp_reader * pfile, int level, source_location src_loc, | 249 cpp_error_at (cpp_reader * pfile, enum cpp_diagnostic_level level, |
261 const char *msgid, ...) | 250 source_location src_loc, const char *msgid, ...) |
262 { | 251 { |
263 va_list ap; | 252 va_list ap; |
264 bool ret; | 253 bool ret; |
265 | 254 |
266 va_start (ap, msgid); | 255 va_start (ap, msgid); |
267 | 256 |
268 ret = cpp_diagnostic_at (pfile, level, CPP_W_NONE, src_loc, | 257 rich_location richloc (pfile->line_table, src_loc); |
258 ret = cpp_diagnostic_at (pfile, level, CPP_W_NONE, &richloc, | |
269 msgid, &ap); | 259 msgid, &ap); |
270 | 260 |
271 va_end (ap); | 261 va_end (ap); |
272 return ret; | 262 return ret; |
273 } | 263 } |
274 | 264 |
275 /* As cpp_error, but use RICHLOC as the location of the error, without | 265 /* As cpp_error, but use RICHLOC as the location of the error, without |
276 a column override. */ | 266 a column override. */ |
277 | 267 |
278 bool | 268 bool |
279 cpp_error_at_richloc (cpp_reader * pfile, int level, rich_location *richloc, | 269 cpp_error_at (cpp_reader * pfile, enum cpp_diagnostic_level level, |
280 const char *msgid, ...) | 270 rich_location *richloc, const char *msgid, ...) |
281 { | 271 { |
282 va_list ap; | 272 va_list ap; |
283 bool ret; | 273 bool ret; |
284 | 274 |
285 va_start (ap, msgid); | 275 va_start (ap, msgid); |
286 | 276 |
287 ret = cpp_diagnostic_at_richloc (pfile, level, CPP_W_NONE, richloc, | 277 ret = cpp_diagnostic_at (pfile, level, CPP_W_NONE, richloc, |
288 msgid, &ap); | 278 msgid, &ap); |
289 | 279 |
290 va_end (ap); | 280 va_end (ap); |
291 return ret; | 281 return ret; |
292 } | 282 } |
293 | 283 |
294 /* Print a warning or error, depending on the value of LEVEL. Include | 284 /* Print a warning or error, depending on the value of LEVEL. Include |
295 information from errno. */ | 285 information from errno. */ |
296 | 286 |
297 bool | 287 bool |
298 cpp_errno (cpp_reader *pfile, int level, const char *msgid) | 288 cpp_errno (cpp_reader *pfile, enum cpp_diagnostic_level level, |
289 const char *msgid) | |
299 { | 290 { |
300 return cpp_error (pfile, level, "%s: %s", _(msgid), xstrerror (errno)); | 291 return cpp_error (pfile, level, "%s: %s", _(msgid), xstrerror (errno)); |
301 } | 292 } |
302 | 293 |
303 /* Print a warning or error, depending on the value of LEVEL. Include | 294 /* Print a warning or error, depending on the value of LEVEL. Include |
304 information from errno. Unlike cpp_errno, the argument is a filename | 295 information from errno. Unlike cpp_errno, the argument is a filename |
305 that is not localized, but "" is replaced with localized "stdout". */ | 296 that is not localized, but "" is replaced with localized "stdout". */ |
306 | 297 |
307 bool | 298 bool |
308 cpp_errno_filename (cpp_reader *pfile, int level, const char *filename, | 299 cpp_errno_filename (cpp_reader *pfile, enum cpp_diagnostic_level level, |
300 const char *filename, | |
309 source_location loc) | 301 source_location loc) |
310 { | 302 { |
311 if (filename[0] == '\0') | 303 if (filename[0] == '\0') |
312 filename = _("stdout"); | 304 filename = _("stdout"); |
313 | 305 |