Mercurial > hg > CbC > CbC_gcc
comparison gcc/c-family/c-lex.c @ 111:04ced10e8804
gcc 7
author | kono |
---|---|
date | Fri, 27 Oct 2017 22:46:09 +0900 |
parents | 561a7518be6b |
children | 84e7813d76e9 |
comparison
equal
deleted
inserted
replaced
68:561a7518be6b | 111:04ced10e8804 |
---|---|
1 /* Mainly the interface between cpplib and the C front ends. | 1 /* Mainly the interface between cpplib and the C front ends. |
2 Copyright (C) 1987, 1988, 1989, 1992, 1994, 1995, 1996, 1997 | 2 Copyright (C) 1987-2017 Free Software Foundation, Inc. |
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, | |
4 2011 Free Software Foundation, Inc. | |
5 | 3 |
6 This file is part of GCC. | 4 This file is part of GCC. |
7 | 5 |
8 GCC is free software; you can redistribute it and/or modify it under | 6 GCC is free software; you can redistribute it and/or modify it under |
9 the terms of the GNU General Public License as published by the Free | 7 the terms of the GNU General Public License as published by the Free |
20 <http://www.gnu.org/licenses/>. */ | 18 <http://www.gnu.org/licenses/>. */ |
21 | 19 |
22 #include "config.h" | 20 #include "config.h" |
23 #include "system.h" | 21 #include "system.h" |
24 #include "coretypes.h" | 22 #include "coretypes.h" |
25 #include "tm.h" | 23 #include "target.h" |
26 | |
27 #include "tree.h" | |
28 #include "input.h" | |
29 #include "output.h" | |
30 #include "c-common.h" | 24 #include "c-common.h" |
31 #include "flags.h" | |
32 #include "timevar.h" | 25 #include "timevar.h" |
33 #include "cpplib.h" | 26 #include "stringpool.h" |
27 #include "stor-layout.h" | |
34 #include "c-pragma.h" | 28 #include "c-pragma.h" |
35 #include "intl.h" | |
36 #include "splay-tree.h" | |
37 #include "debug.h" | 29 #include "debug.h" |
38 #include "target.h" | 30 |
31 #include "attribs.h" | |
39 | 32 |
40 /* We may keep statistics about how long which files took to compile. */ | 33 /* We may keep statistics about how long which files took to compile. */ |
41 static int header_time, body_time; | 34 static int header_time, body_time; |
42 static splay_tree file_info_tree; | 35 static splay_tree file_info_tree; |
43 | 36 |
44 int pending_lang_change; /* If we need to switch languages - C++ only */ | 37 int pending_lang_change; /* If we need to switch languages - C++ only */ |
45 int c_header_level; /* depth in C headers - C++ only */ | 38 int c_header_level; /* depth in C headers - C++ only */ |
46 | 39 |
47 static tree interpret_integer (const cpp_token *, unsigned int); | 40 static tree interpret_integer (const cpp_token *, unsigned int, |
48 static tree interpret_float (const cpp_token *, unsigned int); | 41 enum overflow_type *); |
42 static tree interpret_float (const cpp_token *, unsigned int, const char *, | |
43 enum overflow_type *); | |
49 static tree interpret_fixed (const cpp_token *, unsigned int); | 44 static tree interpret_fixed (const cpp_token *, unsigned int); |
50 static enum integer_type_kind narrowest_unsigned_type | 45 static enum integer_type_kind narrowest_unsigned_type |
51 (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int); | 46 (const widest_int &, unsigned int); |
52 static enum integer_type_kind narrowest_signed_type | 47 static enum integer_type_kind narrowest_signed_type |
53 (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int); | 48 (const widest_int &, unsigned int); |
54 static enum cpp_ttype lex_string (const cpp_token *, tree *, bool, bool); | 49 static enum cpp_ttype lex_string (const cpp_token *, tree *, bool, bool); |
55 static tree lex_charconst (const cpp_token *); | 50 static tree lex_charconst (const cpp_token *); |
56 static void update_header_times (const char *); | 51 static void update_header_times (const char *); |
57 static int dump_one_header (splay_tree_node, void *); | 52 static int dump_one_header (splay_tree_node, void *); |
58 static void cb_line_change (cpp_reader *, const cpp_token *, int); | 53 static void cb_line_change (cpp_reader *, const cpp_token *, int); |
82 cb->line_change = cb_line_change; | 77 cb->line_change = cb_line_change; |
83 cb->ident = cb_ident; | 78 cb->ident = cb_ident; |
84 cb->def_pragma = cb_def_pragma; | 79 cb->def_pragma = cb_def_pragma; |
85 cb->valid_pch = c_common_valid_pch; | 80 cb->valid_pch = c_common_valid_pch; |
86 cb->read_pch = c_common_read_pch; | 81 cb->read_pch = c_common_read_pch; |
82 cb->has_attribute = c_common_has_attribute; | |
83 cb->get_source_date_epoch = cb_get_source_date_epoch; | |
84 cb->get_suggestion = cb_get_suggestion; | |
87 | 85 |
88 /* Set the debug callbacks if we can use them. */ | 86 /* Set the debug callbacks if we can use them. */ |
89 if ((debug_info_level == DINFO_LEVEL_VERBOSE | 87 if ((debug_info_level == DINFO_LEVEL_VERBOSE |
90 && (write_symbols == DWARF2_DEBUG | 88 && (write_symbols == DWARF2_DEBUG |
91 || write_symbols == VMS_AND_DWARF2_DEBUG)) | 89 || write_symbols == VMS_AND_DWARF2_DEBUG)) |
144 } | 142 } |
145 | 143 |
146 void | 144 void |
147 dump_time_statistics (void) | 145 dump_time_statistics (void) |
148 { | 146 { |
149 struct c_fileinfo *file = get_fileinfo (input_filename); | 147 struct c_fileinfo *file = get_fileinfo (LOCATION_FILE (input_location)); |
150 int this_time = get_run_time (); | 148 int this_time = get_run_time (); |
151 file->time += this_time - body_time; | 149 file->time += this_time - body_time; |
152 | 150 |
153 fprintf (stderr, "\n******\n"); | 151 fprintf (stderr, "\n******\n"); |
154 print_time ("header files (total)", header_time); | 152 print_time ("header files (total)", header_time); |
163 static void | 161 static void |
164 cb_ident (cpp_reader * ARG_UNUSED (pfile), | 162 cb_ident (cpp_reader * ARG_UNUSED (pfile), |
165 unsigned int ARG_UNUSED (line), | 163 unsigned int ARG_UNUSED (line), |
166 const cpp_string * ARG_UNUSED (str)) | 164 const cpp_string * ARG_UNUSED (str)) |
167 { | 165 { |
168 #ifdef ASM_OUTPUT_IDENT | |
169 if (!flag_no_ident) | 166 if (!flag_no_ident) |
170 { | 167 { |
171 /* Convert escapes in the string. */ | 168 /* Convert escapes in the string. */ |
172 cpp_string cstr = { 0, 0 }; | 169 cpp_string cstr = { 0, 0 }; |
173 if (cpp_interpret_string (pfile, str, 1, &cstr, CPP_STRING)) | 170 if (cpp_interpret_string (pfile, str, 1, &cstr, CPP_STRING)) |
174 { | 171 { |
175 ASM_OUTPUT_IDENT (asm_out_file, (const char *) cstr.text); | 172 targetm.asm_out.output_ident ((const char *) cstr.text); |
176 free (CONST_CAST (unsigned char *, cstr.text)); | 173 free (CONST_CAST (unsigned char *, cstr.text)); |
177 } | 174 } |
178 } | 175 } |
179 #endif | |
180 } | 176 } |
181 | 177 |
182 /* Called at the start of every non-empty line. TOKEN is the first | 178 /* Called at the start of every non-empty line. TOKEN is the first |
183 lexed token on the line. Used for diagnostic line numbers. */ | 179 lexed token on the line. Used for diagnostic line numbers. */ |
184 static void | 180 static void |
188 if (token->type != CPP_EOF && !parsing_args) | 184 if (token->type != CPP_EOF && !parsing_args) |
189 input_location = token->src_loc; | 185 input_location = token->src_loc; |
190 } | 186 } |
191 | 187 |
192 void | 188 void |
193 fe_file_change (const struct line_map *new_map) | 189 fe_file_change (const line_map_ordinary *new_map) |
194 { | 190 { |
195 if (new_map == NULL) | 191 if (new_map == NULL) |
196 return; | 192 return; |
197 | 193 |
198 if (new_map->reason == LC_ENTER) | 194 if (new_map->reason == LC_ENTER) |
205 int line = 0; | 201 int line = 0; |
206 if (included_at > BUILTINS_LOCATION) | 202 if (included_at > BUILTINS_LOCATION) |
207 line = SOURCE_LINE (new_map - 1, included_at); | 203 line = SOURCE_LINE (new_map - 1, included_at); |
208 | 204 |
209 input_location = new_map->start_location; | 205 input_location = new_map->start_location; |
210 (*debug_hooks->start_source_file) (line, new_map->to_file); | 206 (*debug_hooks->start_source_file) (line, LINEMAP_FILE (new_map)); |
211 #ifndef NO_IMPLICIT_EXTERN_C | 207 #ifndef NO_IMPLICIT_EXTERN_C |
212 if (c_header_level) | 208 if (c_header_level) |
213 ++c_header_level; | 209 ++c_header_level; |
214 else if (new_map->sysp == 2) | 210 else if (LINEMAP_SYSP (new_map) == 2) |
215 { | 211 { |
216 c_header_level = 1; | 212 c_header_level = 1; |
217 ++pending_lang_change; | 213 ++pending_lang_change; |
218 } | 214 } |
219 #endif | 215 #endif |
222 else if (new_map->reason == LC_LEAVE) | 218 else if (new_map->reason == LC_LEAVE) |
223 { | 219 { |
224 #ifndef NO_IMPLICIT_EXTERN_C | 220 #ifndef NO_IMPLICIT_EXTERN_C |
225 if (c_header_level && --c_header_level == 0) | 221 if (c_header_level && --c_header_level == 0) |
226 { | 222 { |
227 if (new_map->sysp == 2) | 223 if (LINEMAP_SYSP (new_map) == 2) |
228 warning (0, "badly nested C headers from preprocessor"); | 224 warning (0, "badly nested C headers from preprocessor"); |
229 --pending_lang_change; | 225 --pending_lang_change; |
230 } | 226 } |
231 #endif | 227 #endif |
232 input_location = new_map->start_location; | 228 input_location = new_map->start_location; |
233 | 229 |
234 (*debug_hooks->end_source_file) (new_map->to_line); | 230 (*debug_hooks->end_source_file) (LINEMAP_LINE (new_map)); |
235 } | 231 } |
236 | 232 |
237 update_header_times (new_map->to_file); | 233 update_header_times (LINEMAP_FILE (new_map)); |
238 input_location = new_map->start_location; | 234 input_location = new_map->start_location; |
239 } | 235 } |
240 | 236 |
241 static void | 237 static void |
242 cb_def_pragma (cpp_reader *pfile, source_location loc) | 238 cb_def_pragma (cpp_reader *pfile, source_location loc) |
243 { | 239 { |
244 /* Issue a warning message if we have been asked to do so. Ignore | 240 /* Issue a warning message if we have been asked to do so. Ignore |
245 unknown pragmas in system headers unless an explicit | 241 unknown pragmas in system headers unless an explicit |
246 -Wunknown-pragmas has been given. */ | 242 -Wunknown-pragmas has been given. */ |
247 if (warn_unknown_pragmas > in_system_header) | 243 if (warn_unknown_pragmas > in_system_header_at (input_location)) |
248 { | 244 { |
249 const unsigned char *space, *name; | 245 const unsigned char *space, *name; |
250 const cpp_token *s; | 246 const cpp_token *s; |
251 location_t fe_loc = loc; | 247 location_t fe_loc = loc; |
252 | 248 |
268 /* #define callback for DWARF and DWARF2 debug info. */ | 264 /* #define callback for DWARF and DWARF2 debug info. */ |
269 static void | 265 static void |
270 cb_define (cpp_reader *pfile, source_location loc, cpp_hashnode *node) | 266 cb_define (cpp_reader *pfile, source_location loc, cpp_hashnode *node) |
271 { | 267 { |
272 const struct line_map *map = linemap_lookup (line_table, loc); | 268 const struct line_map *map = linemap_lookup (line_table, loc); |
273 (*debug_hooks->define) (SOURCE_LINE (map, loc), | 269 (*debug_hooks->define) (SOURCE_LINE (linemap_check_ordinary (map), loc), |
274 (const char *) cpp_macro_definition (pfile, node)); | 270 (const char *) cpp_macro_definition (pfile, node)); |
275 } | 271 } |
276 | 272 |
277 /* #undef callback for DWARF and DWARF2 debug info. */ | 273 /* #undef callback for DWARF and DWARF2 debug info. */ |
278 static void | 274 static void |
279 cb_undef (cpp_reader * ARG_UNUSED (pfile), source_location loc, | 275 cb_undef (cpp_reader * ARG_UNUSED (pfile), source_location loc, |
280 cpp_hashnode *node) | 276 cpp_hashnode *node) |
281 { | 277 { |
282 const struct line_map *map = linemap_lookup (line_table, loc); | 278 const struct line_map *map = linemap_lookup (line_table, loc); |
283 (*debug_hooks->undef) (SOURCE_LINE (map, loc), | 279 (*debug_hooks->undef) (SOURCE_LINE (linemap_check_ordinary (map), loc), |
284 (const char *) NODE_NAME (node)); | 280 (const char *) NODE_NAME (node)); |
281 } | |
282 | |
283 /* Wrapper around cpp_get_token to skip CPP_PADDING tokens | |
284 and not consume CPP_EOF. */ | |
285 static const cpp_token * | |
286 get_token_no_padding (cpp_reader *pfile) | |
287 { | |
288 for (;;) | |
289 { | |
290 const cpp_token *ret = cpp_peek_token (pfile, 0); | |
291 if (ret->type == CPP_EOF) | |
292 return ret; | |
293 ret = cpp_get_token (pfile); | |
294 if (ret->type != CPP_PADDING) | |
295 return ret; | |
296 } | |
297 } | |
298 | |
299 /* Callback for has_attribute. */ | |
300 int | |
301 c_common_has_attribute (cpp_reader *pfile) | |
302 { | |
303 int result = 0; | |
304 tree attr_name = NULL_TREE; | |
305 const cpp_token *token; | |
306 | |
307 token = get_token_no_padding (pfile); | |
308 if (token->type != CPP_OPEN_PAREN) | |
309 { | |
310 cpp_error (pfile, CPP_DL_ERROR, | |
311 "missing '(' after \"__has_attribute\""); | |
312 return 0; | |
313 } | |
314 token = get_token_no_padding (pfile); | |
315 if (token->type == CPP_NAME) | |
316 { | |
317 attr_name = get_identifier ((const char *) | |
318 cpp_token_as_text (pfile, token)); | |
319 attr_name = canonicalize_attr_name (attr_name); | |
320 if (c_dialect_cxx ()) | |
321 { | |
322 int idx = 0; | |
323 const cpp_token *nxt_token; | |
324 do | |
325 nxt_token = cpp_peek_token (pfile, idx++); | |
326 while (nxt_token->type == CPP_PADDING); | |
327 if (nxt_token->type == CPP_SCOPE) | |
328 { | |
329 get_token_no_padding (pfile); // Eat scope. | |
330 nxt_token = get_token_no_padding (pfile); | |
331 if (nxt_token->type == CPP_NAME) | |
332 { | |
333 tree attr_ns = attr_name; | |
334 tree attr_id | |
335 = get_identifier ((const char *) | |
336 cpp_token_as_text (pfile, nxt_token)); | |
337 attr_name = build_tree_list (attr_ns, attr_id); | |
338 } | |
339 else | |
340 { | |
341 cpp_error (pfile, CPP_DL_ERROR, | |
342 "attribute identifier required after scope"); | |
343 attr_name = NULL_TREE; | |
344 } | |
345 } | |
346 else | |
347 { | |
348 /* Some standard attributes need special handling. */ | |
349 if (is_attribute_p ("noreturn", attr_name)) | |
350 result = 200809; | |
351 else if (is_attribute_p ("deprecated", attr_name)) | |
352 result = 201309; | |
353 else if (is_attribute_p ("maybe_unused", attr_name) | |
354 || is_attribute_p ("nodiscard", attr_name) | |
355 || is_attribute_p ("fallthrough", attr_name)) | |
356 result = 201603; | |
357 if (result) | |
358 attr_name = NULL_TREE; | |
359 } | |
360 } | |
361 if (attr_name) | |
362 { | |
363 init_attributes (); | |
364 const struct attribute_spec *attr = lookup_attribute_spec (attr_name); | |
365 if (attr) | |
366 result = 1; | |
367 } | |
368 } | |
369 else | |
370 { | |
371 cpp_error (pfile, CPP_DL_ERROR, | |
372 "macro \"__has_attribute\" requires an identifier"); | |
373 return 0; | |
374 } | |
375 | |
376 if (get_token_no_padding (pfile)->type != CPP_CLOSE_PAREN) | |
377 cpp_error (pfile, CPP_DL_ERROR, | |
378 "missing ')' after \"__has_attribute\""); | |
379 | |
380 return result; | |
285 } | 381 } |
286 | 382 |
287 /* Read a token and return its type. Fill *VALUE with its value, if | 383 /* Read a token and return its type. Fill *VALUE with its value, if |
288 applicable. Fill *CPP_FLAGS with the token's flags, if it is | 384 applicable. Fill *CPP_FLAGS with the token's flags, if it is |
289 non-NULL. */ | 385 non-NULL. */ |
294 { | 390 { |
295 static bool no_more_pch; | 391 static bool no_more_pch; |
296 const cpp_token *tok; | 392 const cpp_token *tok; |
297 enum cpp_ttype type; | 393 enum cpp_ttype type; |
298 unsigned char add_flags = 0; | 394 unsigned char add_flags = 0; |
395 enum overflow_type overflow = OT_NONE; | |
299 | 396 |
300 timevar_push (TV_CPP); | 397 timevar_push (TV_CPP); |
301 retry: | 398 retry: |
302 tok = cpp_get_token_with_location (parse_in, loc); | 399 tok = cpp_get_token_with_location (parse_in, loc); |
303 type = tok->type; | 400 type = tok->type; |
312 *value = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node.node)); | 409 *value = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node.node)); |
313 break; | 410 break; |
314 | 411 |
315 case CPP_NUMBER: | 412 case CPP_NUMBER: |
316 { | 413 { |
317 unsigned int flags = cpp_classify_number (parse_in, tok); | 414 const char *suffix = NULL; |
415 unsigned int flags = cpp_classify_number (parse_in, tok, &suffix, *loc); | |
318 | 416 |
319 switch (flags & CPP_N_CATEGORY) | 417 switch (flags & CPP_N_CATEGORY) |
320 { | 418 { |
321 case CPP_N_INVALID: | 419 case CPP_N_INVALID: |
322 /* cpplib has issued an error. */ | 420 /* cpplib has issued an error. */ |
326 case CPP_N_INTEGER: | 424 case CPP_N_INTEGER: |
327 /* C++ uses '0' to mark virtual functions as pure. | 425 /* C++ uses '0' to mark virtual functions as pure. |
328 Set PURE_ZERO to pass this information to the C++ parser. */ | 426 Set PURE_ZERO to pass this information to the C++ parser. */ |
329 if (tok->val.str.len == 1 && *tok->val.str.text == '0') | 427 if (tok->val.str.len == 1 && *tok->val.str.text == '0') |
330 add_flags = PURE_ZERO; | 428 add_flags = PURE_ZERO; |
331 *value = interpret_integer (tok, flags); | 429 *value = interpret_integer (tok, flags, &overflow); |
332 break; | 430 break; |
333 | 431 |
334 case CPP_N_FLOATING: | 432 case CPP_N_FLOATING: |
335 *value = interpret_float (tok, flags); | 433 *value = interpret_float (tok, flags, suffix, &overflow); |
336 break; | 434 break; |
337 | 435 |
338 default: | 436 default: |
339 gcc_unreachable (); | 437 gcc_unreachable (); |
438 } | |
439 | |
440 if (flags & CPP_N_USERDEF) | |
441 { | |
442 char *str; | |
443 tree literal; | |
444 tree suffix_id = get_identifier (suffix); | |
445 int len = tok->val.str.len - strlen (suffix); | |
446 /* If this is going to be used as a C string to pass to a | |
447 raw literal operator, we need to add a trailing NUL. */ | |
448 tree num_string = build_string (len + 1, | |
449 (const char *) tok->val.str.text); | |
450 TREE_TYPE (num_string) = char_array_type_node; | |
451 num_string = fix_string_type (num_string); | |
452 str = CONST_CAST (char *, TREE_STRING_POINTER (num_string)); | |
453 str[len] = '\0'; | |
454 literal = build_userdef_literal (suffix_id, *value, overflow, | |
455 num_string); | |
456 *value = literal; | |
340 } | 457 } |
341 } | 458 } |
342 break; | 459 break; |
343 | 460 |
344 case CPP_ATSIGN: | 461 case CPP_ATSIGN: |
395 { | 512 { |
396 unsigned char name[8]; | 513 unsigned char name[8]; |
397 | 514 |
398 *cpp_spell_token (parse_in, tok, name, true) = 0; | 515 *cpp_spell_token (parse_in, tok, name, true) = 0; |
399 | 516 |
400 error ("stray %qs in program", name); | 517 error_at (*loc, "stray %qs in program", name); |
401 } | 518 } |
402 | 519 |
403 goto retry; | 520 goto retry; |
404 | 521 |
405 case CPP_OTHER: | 522 case CPP_OTHER: |
406 { | 523 { |
407 cppchar_t c = tok->val.str.text[0]; | 524 cppchar_t c = tok->val.str.text[0]; |
408 | 525 |
409 if (c == '"' || c == '\'') | 526 if (c == '"' || c == '\'') |
410 error ("missing terminating %c character", (int) c); | 527 error_at (*loc, "missing terminating %c character", (int) c); |
411 else if (ISGRAPH (c)) | 528 else if (ISGRAPH (c)) |
412 error ("stray %qc in program", (int) c); | 529 error_at (*loc, "stray %qc in program", (int) c); |
413 else | 530 else |
414 error ("stray %<\\%o%> in program", (int) c); | 531 error_at (*loc, "stray %<\\%o%> in program", (int) c); |
415 } | 532 } |
416 goto retry; | 533 goto retry; |
534 | |
535 case CPP_CHAR_USERDEF: | |
536 case CPP_WCHAR_USERDEF: | |
537 case CPP_CHAR16_USERDEF: | |
538 case CPP_CHAR32_USERDEF: | |
539 case CPP_UTF8CHAR_USERDEF: | |
540 { | |
541 tree literal; | |
542 cpp_token temp_tok = *tok; | |
543 const char *suffix = cpp_get_userdef_suffix (tok); | |
544 temp_tok.val.str.len -= strlen (suffix); | |
545 temp_tok.type = cpp_userdef_char_remove_type (type); | |
546 literal = build_userdef_literal (get_identifier (suffix), | |
547 lex_charconst (&temp_tok), | |
548 OT_NONE, NULL_TREE); | |
549 *value = literal; | |
550 } | |
551 break; | |
417 | 552 |
418 case CPP_CHAR: | 553 case CPP_CHAR: |
419 case CPP_WCHAR: | 554 case CPP_WCHAR: |
420 case CPP_CHAR16: | 555 case CPP_CHAR16: |
421 case CPP_CHAR32: | 556 case CPP_CHAR32: |
557 case CPP_UTF8CHAR: | |
422 *value = lex_charconst (tok); | 558 *value = lex_charconst (tok); |
559 break; | |
560 | |
561 case CPP_STRING_USERDEF: | |
562 case CPP_WSTRING_USERDEF: | |
563 case CPP_STRING16_USERDEF: | |
564 case CPP_STRING32_USERDEF: | |
565 case CPP_UTF8STRING_USERDEF: | |
566 { | |
567 tree literal, string; | |
568 const char *suffix = cpp_get_userdef_suffix (tok); | |
569 string = build_string (tok->val.str.len - strlen (suffix), | |
570 (const char *) tok->val.str.text); | |
571 literal = build_userdef_literal (get_identifier (suffix), | |
572 string, OT_NONE, NULL_TREE); | |
573 *value = literal; | |
574 } | |
423 break; | 575 break; |
424 | 576 |
425 case CPP_STRING: | 577 case CPP_STRING: |
426 case CPP_WSTRING: | 578 case CPP_WSTRING: |
427 case CPP_STRING16: | 579 case CPP_STRING16: |
435 } | 587 } |
436 *value = build_string (tok->val.str.len, (const char *) tok->val.str.text); | 588 *value = build_string (tok->val.str.len, (const char *) tok->val.str.text); |
437 break; | 589 break; |
438 | 590 |
439 case CPP_PRAGMA: | 591 case CPP_PRAGMA: |
440 *value = build_int_cst (NULL, tok->val.pragma); | 592 *value = build_int_cst (integer_type_node, tok->val.pragma); |
441 break; | 593 break; |
442 | 594 |
443 /* These tokens should not be visible outside cpplib. */ | 595 /* These tokens should not be visible outside cpplib. */ |
444 case CPP_HEADER_NAME: | 596 case CPP_HEADER_NAME: |
445 case CPP_MACRO_ARG: | 597 case CPP_MACRO_ARG: |
446 gcc_unreachable (); | 598 gcc_unreachable (); |
447 | 599 |
448 /* CPP_COMMENT will appear when compiling with -C and should be | 600 /* CPP_COMMENT will appear when compiling with -C. Ignore, except |
449 ignored. */ | 601 when it is a FALLTHROUGH comment, in that case set |
450 case CPP_COMMENT: | 602 PREV_FALLTHROUGH flag on the next non-comment token. */ |
603 case CPP_COMMENT: | |
604 if (tok->flags & PREV_FALLTHROUGH) | |
605 { | |
606 do | |
607 { | |
608 tok = cpp_get_token_with_location (parse_in, loc); | |
609 type = tok->type; | |
610 } | |
611 while (type == CPP_PADDING || type == CPP_COMMENT); | |
612 add_flags |= PREV_FALLTHROUGH; | |
613 goto retry_after_at; | |
614 } | |
451 goto retry; | 615 goto retry; |
452 | 616 |
453 default: | 617 default: |
454 *value = NULL_TREE; | 618 *value = NULL_TREE; |
455 break; | 619 break; |
472 /* Returns the narrowest C-visible unsigned type, starting with the | 636 /* Returns the narrowest C-visible unsigned type, starting with the |
473 minimum specified by FLAGS, that can fit HIGH:LOW, or itk_none if | 637 minimum specified by FLAGS, that can fit HIGH:LOW, or itk_none if |
474 there isn't one. */ | 638 there isn't one. */ |
475 | 639 |
476 static enum integer_type_kind | 640 static enum integer_type_kind |
477 narrowest_unsigned_type (unsigned HOST_WIDE_INT low, | 641 narrowest_unsigned_type (const widest_int &val, unsigned int flags) |
478 unsigned HOST_WIDE_INT high, | |
479 unsigned int flags) | |
480 { | 642 { |
481 int itk; | 643 int itk; |
482 | 644 |
483 if ((flags & CPP_N_WIDTH) == CPP_N_SMALL) | 645 if ((flags & CPP_N_WIDTH) == CPP_N_SMALL) |
484 itk = itk_unsigned_int; | 646 itk = itk_unsigned_int; |
493 | 655 |
494 if (integer_types[itk] == NULL_TREE) | 656 if (integer_types[itk] == NULL_TREE) |
495 continue; | 657 continue; |
496 upper = TYPE_MAX_VALUE (integer_types[itk]); | 658 upper = TYPE_MAX_VALUE (integer_types[itk]); |
497 | 659 |
498 if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (upper) > high | 660 if (wi::geu_p (wi::to_widest (upper), val)) |
499 || ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (upper) == high | |
500 && TREE_INT_CST_LOW (upper) >= low)) | |
501 return (enum integer_type_kind) itk; | 661 return (enum integer_type_kind) itk; |
502 } | 662 } |
503 | 663 |
504 return itk_none; | 664 return itk_none; |
505 } | 665 } |
506 | 666 |
507 /* Ditto, but narrowest signed type. */ | 667 /* Ditto, but narrowest signed type. */ |
508 static enum integer_type_kind | 668 static enum integer_type_kind |
509 narrowest_signed_type (unsigned HOST_WIDE_INT low, | 669 narrowest_signed_type (const widest_int &val, unsigned int flags) |
510 unsigned HOST_WIDE_INT high, unsigned int flags) | |
511 { | 670 { |
512 int itk; | 671 int itk; |
513 | 672 |
514 if ((flags & CPP_N_WIDTH) == CPP_N_SMALL) | 673 if ((flags & CPP_N_WIDTH) == CPP_N_SMALL) |
515 itk = itk_int; | 674 itk = itk_int; |
516 else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM) | 675 else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM) |
517 itk = itk_long; | 676 itk = itk_long; |
518 else | 677 else |
519 itk = itk_long_long; | 678 itk = itk_long_long; |
520 | 679 |
521 | |
522 for (; itk < itk_none; itk += 2 /* skip signed types */) | 680 for (; itk < itk_none; itk += 2 /* skip signed types */) |
523 { | 681 { |
524 tree upper; | 682 tree upper; |
525 | 683 |
526 if (integer_types[itk] == NULL_TREE) | 684 if (integer_types[itk] == NULL_TREE) |
527 continue; | 685 continue; |
528 upper = TYPE_MAX_VALUE (integer_types[itk]); | 686 upper = TYPE_MAX_VALUE (integer_types[itk]); |
529 | 687 |
530 if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (upper) > high | 688 if (wi::geu_p (wi::to_widest (upper), val)) |
531 || ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (upper) == high | |
532 && TREE_INT_CST_LOW (upper) >= low)) | |
533 return (enum integer_type_kind) itk; | 689 return (enum integer_type_kind) itk; |
534 } | 690 } |
535 | 691 |
536 return itk_none; | 692 return itk_none; |
537 } | 693 } |
538 | 694 |
539 /* Interpret TOKEN, an integer with FLAGS as classified by cpplib. */ | 695 /* Interpret TOKEN, an integer with FLAGS as classified by cpplib. */ |
540 static tree | 696 static tree |
541 interpret_integer (const cpp_token *token, unsigned int flags) | 697 interpret_integer (const cpp_token *token, unsigned int flags, |
698 enum overflow_type *overflow) | |
542 { | 699 { |
543 tree value, type; | 700 tree value, type; |
544 enum integer_type_kind itk; | 701 enum integer_type_kind itk; |
545 cpp_num integer; | 702 cpp_num integer; |
546 cpp_options *options = cpp_get_options (parse_in); | 703 HOST_WIDE_INT ival[3]; |
704 | |
705 *overflow = OT_NONE; | |
547 | 706 |
548 integer = cpp_interpret_integer (parse_in, token, flags); | 707 integer = cpp_interpret_integer (parse_in, token, flags); |
549 integer = cpp_num_sign_extend (integer, options->precision); | 708 if (integer.overflow) |
709 *overflow = OT_OVERFLOW; | |
710 | |
711 ival[0] = integer.low; | |
712 ival[1] = integer.high; | |
713 ival[2] = 0; | |
714 widest_int wval = widest_int::from_array (ival, 3); | |
550 | 715 |
551 /* The type of a constant with a U suffix is straightforward. */ | 716 /* The type of a constant with a U suffix is straightforward. */ |
552 if (flags & CPP_N_UNSIGNED) | 717 if (flags & CPP_N_UNSIGNED) |
553 itk = narrowest_unsigned_type (integer.low, integer.high, flags); | 718 itk = narrowest_unsigned_type (wval, flags); |
554 else | 719 else |
555 { | 720 { |
556 /* The type of a potentially-signed integer constant varies | 721 /* The type of a potentially-signed integer constant varies |
557 depending on the base it's in, the standard in use, and the | 722 depending on the base it's in, the standard in use, and the |
558 length suffixes. */ | 723 length suffixes. */ |
559 enum integer_type_kind itk_u | 724 enum integer_type_kind itk_u |
560 = narrowest_unsigned_type (integer.low, integer.high, flags); | 725 = narrowest_unsigned_type (wval, flags); |
561 enum integer_type_kind itk_s | 726 enum integer_type_kind itk_s |
562 = narrowest_signed_type (integer.low, integer.high, flags); | 727 = narrowest_signed_type (wval, flags); |
563 | 728 |
564 /* In both C89 and C99, octal and hex constants may be signed or | 729 /* In both C89 and C99, octal and hex constants may be signed or |
565 unsigned, whichever fits tighter. We do not warn about this | 730 unsigned, whichever fits tighter. We do not warn about this |
566 choice differing from the traditional choice, as the constant | 731 choice differing from the traditional choice, as the constant |
567 is probably a bit pattern and either way will work. */ | 732 is probably a bit pattern and either way will work. */ |
609 (flags & CPP_N_UNSIGNED) | 774 (flags & CPP_N_UNSIGNED) |
610 ? "integer constant is too large for %<unsigned long%> type" | 775 ? "integer constant is too large for %<unsigned long%> type" |
611 : "integer constant is too large for %<long%> type"); | 776 : "integer constant is too large for %<long%> type"); |
612 } | 777 } |
613 | 778 |
614 value = build_int_cst_wide (type, integer.low, integer.high); | 779 value = wide_int_to_tree (type, wval); |
615 | 780 |
616 /* Convert imaginary to a complex type. */ | 781 /* Convert imaginary to a complex type. */ |
617 if (flags & CPP_N_IMAGINARY) | 782 if (flags & CPP_N_IMAGINARY) |
618 value = build_complex (NULL_TREE, build_int_cst (type, 0), value); | 783 value = build_complex (NULL_TREE, build_int_cst (type, 0), value); |
619 | 784 |
620 return value; | 785 return value; |
621 } | 786 } |
622 | 787 |
623 /* Interpret TOKEN, a floating point number with FLAGS as classified | 788 /* Interpret TOKEN, a floating point number with FLAGS as classified |
624 by cpplib. */ | 789 by cpplib. For C++11 SUFFIX may contain a user-defined literal suffix. */ |
625 static tree | 790 static tree |
626 interpret_float (const cpp_token *token, unsigned int flags) | 791 interpret_float (const cpp_token *token, unsigned int flags, |
792 const char *suffix, enum overflow_type *overflow) | |
627 { | 793 { |
628 tree type; | 794 tree type; |
629 tree const_type; | 795 tree const_type; |
630 tree value; | 796 tree value; |
631 REAL_VALUE_TYPE real; | 797 REAL_VALUE_TYPE real; |
632 REAL_VALUE_TYPE real_trunc; | 798 REAL_VALUE_TYPE real_trunc; |
633 char *copy; | 799 char *copy; |
634 size_t copylen; | 800 size_t copylen; |
801 | |
802 *overflow = OT_NONE; | |
635 | 803 |
636 /* Default (no suffix) depends on whether the FLOAT_CONST_DECIMAL64 | 804 /* Default (no suffix) depends on whether the FLOAT_CONST_DECIMAL64 |
637 pragma has been used and is either double or _Decimal64. Types | 805 pragma has been used and is either double or _Decimal64. Types |
638 that are not allowed with decimal float default to double. */ | 806 that are not allowed with decimal float default to double. */ |
639 if (flags & CPP_N_DEFAULT) | 807 if (flags & CPP_N_DEFAULT) |
664 type = dfloat64_type_node; | 832 type = dfloat64_type_node; |
665 else | 833 else |
666 if (flags & CPP_N_WIDTH_MD) | 834 if (flags & CPP_N_WIDTH_MD) |
667 { | 835 { |
668 char suffix; | 836 char suffix; |
669 enum machine_mode mode; | 837 machine_mode mode; |
670 | 838 |
671 if ((flags & CPP_N_WIDTH_MD) == CPP_N_MD_W) | 839 if ((flags & CPP_N_WIDTH_MD) == CPP_N_MD_W) |
672 suffix = 'w'; | 840 suffix = 'w'; |
673 else | 841 else |
674 suffix = 'q'; | 842 suffix = 'q'; |
679 error ("unsupported non-standard suffix on floating constant"); | 847 error ("unsupported non-standard suffix on floating constant"); |
680 | 848 |
681 return error_mark_node; | 849 return error_mark_node; |
682 } | 850 } |
683 else | 851 else |
684 pedwarn (input_location, OPT_pedantic, "non-standard suffix on floating constant"); | 852 pedwarn (input_location, OPT_Wpedantic, "non-standard suffix on floating constant"); |
685 | 853 |
686 type = c_common_type_for_mode (mode, 0); | 854 type = c_common_type_for_mode (mode, 0); |
687 gcc_assert (type); | 855 gcc_assert (type); |
856 } | |
857 else if ((flags & (CPP_N_FLOATN | CPP_N_FLOATNX)) != 0) | |
858 { | |
859 unsigned int n = (flags & CPP_N_WIDTH_FLOATN_NX) >> CPP_FLOATN_SHIFT; | |
860 bool extended = (flags & CPP_N_FLOATNX) != 0; | |
861 type = NULL_TREE; | |
862 for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++) | |
863 if (floatn_nx_types[i].n == (int) n | |
864 && floatn_nx_types[i].extended == extended) | |
865 { | |
866 type = FLOATN_NX_TYPE_NODE (i); | |
867 break; | |
868 } | |
869 if (type == NULL_TREE) | |
870 { | |
871 error ("unsupported non-standard suffix on floating constant"); | |
872 return error_mark_node; | |
873 } | |
874 else | |
875 pedwarn (input_location, OPT_Wpedantic, "non-standard suffix on floating constant"); | |
688 } | 876 } |
689 else if ((flags & CPP_N_WIDTH) == CPP_N_LARGE) | 877 else if ((flags & CPP_N_WIDTH) == CPP_N_LARGE) |
690 type = long_double_type_node; | 878 type = long_double_type_node; |
691 else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL | 879 else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL |
692 || flag_single_precision_constant) | 880 || flag_single_precision_constant) |
700 | 888 |
701 /* Copy the constant to a nul-terminated buffer. If the constant | 889 /* Copy the constant to a nul-terminated buffer. If the constant |
702 has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF | 890 has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF |
703 can't handle them. */ | 891 can't handle them. */ |
704 copylen = token->val.str.len; | 892 copylen = token->val.str.len; |
705 if (flags & CPP_N_DFLOAT) | 893 if (flags & CPP_N_USERDEF) |
894 copylen -= strlen (suffix); | |
895 else if (flags & CPP_N_DFLOAT) | |
706 copylen -= 2; | 896 copylen -= 2; |
707 else | 897 else |
708 { | 898 { |
709 if ((flags & CPP_N_WIDTH) != CPP_N_MEDIUM) | 899 if ((flags & CPP_N_WIDTH) != CPP_N_MEDIUM) |
710 /* Must be an F or L or machine defined suffix. */ | 900 /* Must be an F or L or machine defined suffix. */ |
711 copylen--; | 901 copylen--; |
712 if (flags & CPP_N_IMAGINARY) | 902 if (flags & CPP_N_IMAGINARY) |
713 /* I or J suffix. */ | 903 /* I or J suffix. */ |
714 copylen--; | 904 copylen--; |
905 if (flags & CPP_N_FLOATNX) | |
906 copylen--; | |
907 if (flags & (CPP_N_FLOATN | CPP_N_FLOATNX)) | |
908 { | |
909 unsigned int n = (flags & CPP_N_WIDTH_FLOATN_NX) >> CPP_FLOATN_SHIFT; | |
910 while (n > 0) | |
911 { | |
912 copylen--; | |
913 n /= 10; | |
914 } | |
915 } | |
715 } | 916 } |
716 | 917 |
717 copy = (char *) alloca (copylen + 1); | 918 copy = (char *) alloca (copylen + 1); |
718 memcpy (copy, token->val.str.text, copylen); | 919 if (cxx_dialect > cxx11) |
719 copy[copylen] = '\0'; | 920 { |
921 size_t maxlen = 0; | |
922 for (size_t i = 0; i < copylen; ++i) | |
923 if (token->val.str.text[i] != '\'') | |
924 copy[maxlen++] = token->val.str.text[i]; | |
925 copy[maxlen] = '\0'; | |
926 } | |
927 else | |
928 { | |
929 memcpy (copy, token->val.str.text, copylen); | |
930 copy[copylen] = '\0'; | |
931 } | |
720 | 932 |
721 real_from_string3 (&real, copy, TYPE_MODE (const_type)); | 933 real_from_string3 (&real, copy, TYPE_MODE (const_type)); |
722 if (const_type != type) | 934 if (const_type != type) |
723 /* Diagnosing if the result of converting the value with excess | 935 /* Diagnosing if the result of converting the value with excess |
724 precision to the semantic type would overflow (with associated | 936 precision to the semantic type would overflow (with associated |
732 have __builtin_inf* to produce an infinity, this is now a | 944 have __builtin_inf* to produce an infinity, this is now a |
733 mandatory pedwarn if the target does not support infinities. */ | 945 mandatory pedwarn if the target does not support infinities. */ |
734 if (REAL_VALUE_ISINF (real) | 946 if (REAL_VALUE_ISINF (real) |
735 || (const_type != type && REAL_VALUE_ISINF (real_trunc))) | 947 || (const_type != type && REAL_VALUE_ISINF (real_trunc))) |
736 { | 948 { |
737 if (!MODE_HAS_INFINITIES (TYPE_MODE (type))) | 949 *overflow = OT_OVERFLOW; |
738 pedwarn (input_location, 0, "floating constant exceeds range of %qT", type); | 950 if (!(flags & CPP_N_USERDEF)) |
739 else | 951 { |
740 warning (OPT_Woverflow, "floating constant exceeds range of %qT", type); | 952 if (!MODE_HAS_INFINITIES (TYPE_MODE (type))) |
953 pedwarn (input_location, 0, | |
954 "floating constant exceeds range of %qT", type); | |
955 else | |
956 warning (OPT_Woverflow, | |
957 "floating constant exceeds range of %qT", type); | |
958 } | |
741 } | 959 } |
742 /* We also give a warning if the value underflows. */ | 960 /* We also give a warning if the value underflows. */ |
743 else if (REAL_VALUES_EQUAL (real, dconst0) | 961 else if (real_equal (&real, &dconst0) |
744 || (const_type != type && REAL_VALUES_EQUAL (real_trunc, dconst0))) | 962 || (const_type != type |
963 && real_equal (&real_trunc, &dconst0))) | |
745 { | 964 { |
746 REAL_VALUE_TYPE realvoidmode; | 965 REAL_VALUE_TYPE realvoidmode; |
747 int overflow = real_from_string (&realvoidmode, copy); | 966 int oflow = real_from_string (&realvoidmode, copy); |
748 if (overflow < 0 || !REAL_VALUES_EQUAL (realvoidmode, dconst0)) | 967 *overflow = (oflow == 0 ? OT_NONE |
749 warning (OPT_Woverflow, "floating constant truncated to zero"); | 968 : (oflow < 0 ? OT_UNDERFLOW : OT_OVERFLOW)); |
969 if (!(flags & CPP_N_USERDEF)) | |
970 { | |
971 if (oflow < 0 || !real_equal (&realvoidmode, &dconst0)) | |
972 warning (OPT_Woverflow, "floating constant truncated to zero"); | |
973 } | |
750 } | 974 } |
751 | 975 |
752 /* Create a node with determined type and value. */ | 976 /* Create a node with determined type and value. */ |
753 value = build_real (const_type, real); | 977 value = build_real (const_type, real); |
754 if (flags & CPP_N_IMAGINARY) | 978 if (flags & CPP_N_IMAGINARY) |
755 { | 979 { |
756 value = build_complex (NULL_TREE, convert (const_type, | 980 value = build_complex (NULL_TREE, |
757 integer_zero_node), value); | 981 fold_convert (const_type, |
982 integer_zero_node), value); | |
758 if (type != const_type) | 983 if (type != const_type) |
759 { | 984 { |
760 const_type = TREE_TYPE (value); | 985 const_type = TREE_TYPE (value); |
761 type = build_complex_type (type); | 986 type = build_complex_type (type); |
762 } | 987 } |
763 } | 988 } |
764 | 989 |
765 if (type != const_type) | 990 if (type != const_type) |
766 value = build1 (EXCESS_PRECISION_EXPR, type, value); | 991 value = build1_loc (token->src_loc, EXCESS_PRECISION_EXPR, type, value); |
767 | 992 |
768 return value; | 993 return value; |
769 } | 994 } |
770 | 995 |
771 /* Interpret TOKEN, a fixed-point number with FLAGS as classified | 996 /* Interpret TOKEN, a fixed-point number with FLAGS as classified |
883 | 1108 |
884 copy = (char *) alloca (copylen + 1); | 1109 copy = (char *) alloca (copylen + 1); |
885 memcpy (copy, token->val.str.text, copylen); | 1110 memcpy (copy, token->val.str.text, copylen); |
886 copy[copylen] = '\0'; | 1111 copy[copylen] = '\0'; |
887 | 1112 |
888 fixed_from_string (&fixed, copy, TYPE_MODE (type)); | 1113 fixed_from_string (&fixed, copy, SCALAR_TYPE_MODE (type)); |
889 | 1114 |
890 /* Create a node with determined type and value. */ | 1115 /* Create a node with determined type and value. */ |
891 value = build_fixed (type, fixed); | 1116 value = build_fixed (type, fixed); |
892 | 1117 |
893 return value; | 1118 return value; |
916 lex_string (const cpp_token *tok, tree *valp, bool objc_string, bool translate) | 1141 lex_string (const cpp_token *tok, tree *valp, bool objc_string, bool translate) |
917 { | 1142 { |
918 tree value; | 1143 tree value; |
919 size_t concats = 0; | 1144 size_t concats = 0; |
920 struct obstack str_ob; | 1145 struct obstack str_ob; |
1146 struct obstack loc_ob; | |
921 cpp_string istr; | 1147 cpp_string istr; |
922 enum cpp_ttype type = tok->type; | 1148 enum cpp_ttype type = tok->type; |
923 | 1149 |
924 /* Try to avoid the overhead of creating and destroying an obstack | 1150 /* Try to avoid the overhead of creating and destroying an obstack |
925 for the common case of just one string. */ | 1151 for the common case of just one string. */ |
926 cpp_string str = tok->val.str; | 1152 cpp_string str = tok->val.str; |
1153 location_t init_loc = tok->src_loc; | |
927 cpp_string *strs = &str; | 1154 cpp_string *strs = &str; |
1155 location_t *locs = NULL; | |
928 | 1156 |
929 /* objc_at_sign_was_seen is only used when doing Objective-C string | 1157 /* objc_at_sign_was_seen is only used when doing Objective-C string |
930 concatenation. It is 'true' if we have seen an '@' before the | 1158 concatenation. It is 'true' if we have seen an '@' before the |
931 current string, and 'false' if not. We must see exactly one or | 1159 current string, and 'false' if not. We must see exactly one or |
932 zero '@' before each string. */ | 1160 zero '@' before each string. */ |
961 if (type == CPP_STRING) | 1189 if (type == CPP_STRING) |
962 type = tok->type; | 1190 type = tok->type; |
963 else | 1191 else |
964 error ("unsupported non-standard concatenation of string literals"); | 1192 error ("unsupported non-standard concatenation of string literals"); |
965 } | 1193 } |
1194 /* FALLTHROUGH */ | |
966 | 1195 |
967 case CPP_STRING: | 1196 case CPP_STRING: |
968 if (!concats) | 1197 if (!concats) |
969 { | 1198 { |
970 gcc_obstack_init (&str_ob); | 1199 gcc_obstack_init (&str_ob); |
1200 gcc_obstack_init (&loc_ob); | |
971 obstack_grow (&str_ob, &str, sizeof (cpp_string)); | 1201 obstack_grow (&str_ob, &str, sizeof (cpp_string)); |
1202 obstack_grow (&loc_ob, &init_loc, sizeof (location_t)); | |
972 } | 1203 } |
973 | 1204 |
974 concats++; | 1205 concats++; |
975 obstack_grow (&str_ob, &tok->val.str, sizeof (cpp_string)); | 1206 obstack_grow (&str_ob, &tok->val.str, sizeof (cpp_string)); |
1207 obstack_grow (&loc_ob, &tok->src_loc, sizeof (location_t)); | |
1208 | |
976 if (objc_string) | 1209 if (objc_string) |
977 objc_at_sign_was_seen = false; | 1210 objc_at_sign_was_seen = false; |
978 goto retry; | 1211 goto retry; |
979 } | 1212 } |
980 | 1213 |
983 error ("stray %<@%> in program"); | 1216 error ("stray %<@%> in program"); |
984 | 1217 |
985 /* We have read one more token than we want. */ | 1218 /* We have read one more token than we want. */ |
986 _cpp_backup_tokens (parse_in, 1); | 1219 _cpp_backup_tokens (parse_in, 1); |
987 if (concats) | 1220 if (concats) |
988 strs = XOBFINISH (&str_ob, cpp_string *); | 1221 { |
989 | 1222 strs = XOBFINISH (&str_ob, cpp_string *); |
990 if (concats && !objc_string && !in_system_header) | 1223 locs = XOBFINISH (&loc_ob, location_t *); |
1224 } | |
1225 | |
1226 if (concats && !objc_string && !in_system_header_at (input_location)) | |
991 warning (OPT_Wtraditional, | 1227 warning (OPT_Wtraditional, |
992 "traditional C rejects string constant concatenation"); | 1228 "traditional C rejects string constant concatenation"); |
993 | 1229 |
994 if ((translate | 1230 if ((translate |
995 ? cpp_interpret_string : cpp_interpret_string_notranslate) | 1231 ? cpp_interpret_string : cpp_interpret_string_notranslate) |
996 (parse_in, strs, concats + 1, &istr, type)) | 1232 (parse_in, strs, concats + 1, &istr, type)) |
997 { | 1233 { |
998 value = build_string (istr.len, (const char *) istr.text); | 1234 value = build_string (istr.len, (const char *) istr.text); |
999 free (CONST_CAST (unsigned char *, istr.text)); | 1235 free (CONST_CAST (unsigned char *, istr.text)); |
1236 if (concats) | |
1237 { | |
1238 gcc_assert (locs); | |
1239 gcc_assert (g_string_concat_db); | |
1240 g_string_concat_db->record_string_concatenation (concats + 1, locs); | |
1241 } | |
1000 } | 1242 } |
1001 else | 1243 else |
1002 { | 1244 { |
1003 /* Callers cannot generally handle error_mark_node in this context, | 1245 /* Callers cannot generally handle error_mark_node in this context, |
1004 so return the empty string instead. cpp_interpret_string has | 1246 so return the empty string instead. cpp_interpret_string has |
1046 TREE_TYPE (value) = wchar_array_type_node; | 1288 TREE_TYPE (value) = wchar_array_type_node; |
1047 } | 1289 } |
1048 *valp = fix_string_type (value); | 1290 *valp = fix_string_type (value); |
1049 | 1291 |
1050 if (concats) | 1292 if (concats) |
1051 obstack_free (&str_ob, 0); | 1293 { |
1294 obstack_free (&str_ob, 0); | |
1295 obstack_free (&loc_ob, 0); | |
1296 } | |
1052 | 1297 |
1053 return objc_string ? CPP_OBJC_STRING : type; | 1298 return objc_string ? CPP_OBJC_STRING : type; |
1054 } | 1299 } |
1055 | 1300 |
1056 /* Converts a (possibly wide) character constant token into a tree. */ | 1301 /* Converts a (possibly wide) character constant token into a tree. */ |
1069 type = wchar_type_node; | 1314 type = wchar_type_node; |
1070 else if (token->type == CPP_CHAR32) | 1315 else if (token->type == CPP_CHAR32) |
1071 type = char32_type_node; | 1316 type = char32_type_node; |
1072 else if (token->type == CPP_CHAR16) | 1317 else if (token->type == CPP_CHAR16) |
1073 type = char16_type_node; | 1318 type = char16_type_node; |
1319 else if (token->type == CPP_UTF8CHAR) | |
1320 type = char_type_node; | |
1074 /* In C, a character constant has type 'int'. | 1321 /* In C, a character constant has type 'int'. |
1075 In C++ 'char', but multi-char charconsts have type 'int'. */ | 1322 In C++ 'char', but multi-char charconsts have type 'int'. */ |
1076 else if (!c_dialect_cxx () || chars_seen > 1) | 1323 else if (!c_dialect_cxx () || chars_seen > 1) |
1077 type = integer_type_node; | 1324 type = integer_type_node; |
1078 else | 1325 else |
1079 type = char_type_node; | 1326 type = char_type_node; |
1080 | 1327 |
1081 /* Cast to cppchar_signed_t to get correct sign-extension of RESULT | 1328 /* Cast to cppchar_signed_t to get correct sign-extension of RESULT |
1082 before possibly widening to HOST_WIDE_INT for build_int_cst. */ | 1329 before possibly widening to HOST_WIDE_INT for build_int_cst. */ |
1083 if (unsignedp || (cppchar_signed_t) result >= 0) | 1330 if (unsignedp || (cppchar_signed_t) result >= 0) |
1084 value = build_int_cst_wide (type, result, 0); | 1331 value = build_int_cst (type, result); |
1085 else | 1332 else |
1086 value = build_int_cst_wide (type, (cppchar_signed_t) result, -1); | 1333 value = build_int_cst (type, (cppchar_signed_t) result); |
1087 | 1334 |
1088 return value; | 1335 return value; |
1089 } | 1336 } |
1337 | |
1338 /* Helper function for c_parser_peek_conflict_marker | |
1339 and cp_lexer_peek_conflict_marker. | |
1340 Given a possible conflict marker token of kind TOK1_KIND | |
1341 consisting of a pair of characters, get the token kind for the | |
1342 standalone final character. */ | |
1343 | |
1344 enum cpp_ttype | |
1345 conflict_marker_get_final_tok_kind (enum cpp_ttype tok1_kind) | |
1346 { | |
1347 switch (tok1_kind) | |
1348 { | |
1349 default: gcc_unreachable (); | |
1350 case CPP_LSHIFT: | |
1351 /* "<<" and '<' */ | |
1352 return CPP_LESS; | |
1353 | |
1354 case CPP_EQ_EQ: | |
1355 /* "==" and '=' */ | |
1356 return CPP_EQ; | |
1357 | |
1358 case CPP_RSHIFT: | |
1359 /* ">>" and '>' */ | |
1360 return CPP_GREATER; | |
1361 } | |
1362 } |