comparison gcc/c-lex.c @ 55:77e2b8dfacca gcc-4.4.5

update it from 4.4.3 to 4.5.0
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Fri, 12 Feb 2010 23:39:51 +0900
parents a06113de4d67
children b7f97abdc517
comparison
equal deleted inserted replaced
52:c156f1bd5cd9 55:77e2b8dfacca
262 s = cpp_get_token (pfile); 262 s = cpp_get_token (pfile);
263 if (s->type == CPP_NAME) 263 if (s->type == CPP_NAME)
264 name = cpp_token_as_text (pfile, s); 264 name = cpp_token_as_text (pfile, s);
265 } 265 }
266 266
267 warning (OPT_Wunknown_pragmas, "%Hignoring #pragma %s %s", 267 warning_at (fe_loc, OPT_Wunknown_pragmas, "ignoring #pragma %s %s",
268 &fe_loc, space, name); 268 space, name);
269 } 269 }
270 } 270 }
271 271
272 /* #define callback for DWARF and DWARF2 debug info. */ 272 /* #define callback for DWARF and DWARF2 debug info. */
273 static void 273 static void
311 { 311 {
312 case CPP_PADDING: 312 case CPP_PADDING:
313 goto retry; 313 goto retry;
314 314
315 case CPP_NAME: 315 case CPP_NAME:
316 *value = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node)); 316 *value = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node.node));
317 break; 317 break;
318 318
319 case CPP_NUMBER: 319 case CPP_NUMBER:
320 { 320 {
321 unsigned int flags = cpp_classify_number (parse_in, tok); 321 unsigned int flags = cpp_classify_number (parse_in, tok);
363 363
364 case CPP_STRING: 364 case CPP_STRING:
365 case CPP_WSTRING: 365 case CPP_WSTRING:
366 case CPP_STRING16: 366 case CPP_STRING16:
367 case CPP_STRING32: 367 case CPP_STRING32:
368 case CPP_UTF8STRING:
368 type = lex_string (tok, value, true, true); 369 type = lex_string (tok, value, true, true);
369 break; 370 break;
370 371
371 case CPP_NAME: 372 case CPP_NAME:
372 *value = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node)); 373 *value = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node.node));
373 if (objc_is_reserved_word (*value)) 374 if (objc_is_reserved_word (*value))
374 { 375 {
375 type = CPP_AT_NAME; 376 type = CPP_AT_NAME;
376 break; 377 break;
377 } 378 }
378 /* FALLTHROUGH */ 379 /* FALLTHROUGH */
379 380
380 default: 381 default:
381 /* ... or not. */ 382 /* ... or not. */
382 error ("%Hstray %<@%> in program", &atloc); 383 error_at (atloc, "stray %<@%> in program");
383 *loc = newloc; 384 *loc = newloc;
384 goto retry_after_at; 385 goto retry_after_at;
385 } 386 }
386 break; 387 break;
387 } 388 }
388 389
389 /* FALLTHROUGH */ 390 /* FALLTHROUGH */
390 case CPP_HASH: 391 case CPP_HASH:
391 case CPP_PASTE: 392 case CPP_PASTE:
392 { 393 {
393 unsigned char name[4]; 394 unsigned char name[8];
394 395
395 *cpp_spell_token (parse_in, tok, name, true) = 0; 396 *cpp_spell_token (parse_in, tok, name, true) = 0;
396 397
397 error ("stray %qs in program", name); 398 error ("stray %qs in program", name);
398 } 399 }
421 422
422 case CPP_STRING: 423 case CPP_STRING:
423 case CPP_WSTRING: 424 case CPP_WSTRING:
424 case CPP_STRING16: 425 case CPP_STRING16:
425 case CPP_STRING32: 426 case CPP_STRING32:
426 if ((lex_flags & C_LEX_RAW_STRINGS) == 0) 427 case CPP_UTF8STRING:
428 if ((lex_flags & C_LEX_STRING_NO_JOIN) == 0)
427 { 429 {
428 type = lex_string (tok, value, false, 430 type = lex_string (tok, value, false,
429 (lex_flags & C_LEX_STRING_NO_TRANSLATE) == 0); 431 (lex_flags & C_LEX_STRING_NO_TRANSLATE) == 0);
430 break; 432 break;
431 } 433 }
432 *value = build_string (tok->val.str.len, (const char *) tok->val.str.text); 434 *value = build_string (tok->val.str.len, (const char *) tok->val.str.text);
433 break; 435 break;
434 436
435 case CPP_PRAGMA: 437 case CPP_PRAGMA:
436 *value = build_int_cst (NULL, tok->val.pragma); 438 *value = build_int_cst (NULL, tok->val.pragma);
437 break; 439 break;
438 440
439 /* These tokens should not be visible outside cpplib. */ 441 /* These tokens should not be visible outside cpplib. */
580 /* cpplib has already issued a warning for overflow. */ 582 /* cpplib has already issued a warning for overflow. */
581 type = ((flags & CPP_N_UNSIGNED) 583 type = ((flags & CPP_N_UNSIGNED)
582 ? widest_unsigned_literal_type_node 584 ? widest_unsigned_literal_type_node
583 : widest_integer_literal_type_node); 585 : widest_integer_literal_type_node);
584 else 586 else
585 type = integer_types[itk]; 587 {
586 588 type = integer_types[itk];
587 if (itk > itk_unsigned_long 589 if (itk > itk_unsigned_long
588 && (flags & CPP_N_WIDTH) != CPP_N_LARGE 590 && (flags & CPP_N_WIDTH) != CPP_N_LARGE)
589 && !in_system_header && !flag_isoc99) 591 emit_diagnostic
590 pedwarn (input_location, 0, "integer constant is too large for %qs type", 592 ((c_dialect_cxx () ? cxx_dialect == cxx98 : !flag_isoc99)
591 (flags & CPP_N_UNSIGNED) ? "unsigned long" : "long"); 593 ? DK_PEDWARN : DK_WARNING,
594 input_location, OPT_Wlong_long,
595 (flags & CPP_N_UNSIGNED)
596 ? "integer constant is too large for %<unsigned long%> type"
597 : "integer constant is too large for %<long%> type");
598 }
592 599
593 value = build_int_cst_wide (type, integer.low, integer.high); 600 value = build_int_cst_wide (type, integer.low, integer.high);
594 601
595 /* Convert imaginary to a complex type. */ 602 /* Convert imaginary to a complex type. */
596 if (flags & CPP_N_IMAGINARY) 603 if (flags & CPP_N_IMAGINARY)
603 by cpplib. */ 610 by cpplib. */
604 static tree 611 static tree
605 interpret_float (const cpp_token *token, unsigned int flags) 612 interpret_float (const cpp_token *token, unsigned int flags)
606 { 613 {
607 tree type; 614 tree type;
615 tree const_type;
608 tree value; 616 tree value;
609 REAL_VALUE_TYPE real; 617 REAL_VALUE_TYPE real;
618 REAL_VALUE_TYPE real_trunc;
610 char *copy; 619 char *copy;
611 size_t copylen; 620 size_t copylen;
621
622 /* Default (no suffix) depends on whether the FLOAT_CONST_DECIMAL64
623 pragma has been used and is either double or _Decimal64. Types
624 that are not allowed with decimal float default to double. */
625 if (flags & CPP_N_DEFAULT)
626 {
627 flags ^= CPP_N_DEFAULT;
628 flags |= CPP_N_MEDIUM;
629
630 if (((flags & CPP_N_HEX) == 0) && ((flags & CPP_N_IMAGINARY) == 0))
631 {
632 warning (OPT_Wunsuffixed_float_constants,
633 "unsuffixed float constant");
634 if (float_const_decimal64_p ())
635 flags |= CPP_N_DFLOAT;
636 }
637 }
612 638
613 /* Decode _Fract and _Accum. */ 639 /* Decode _Fract and _Accum. */
614 if (flags & CPP_N_FRACT || flags & CPP_N_ACCUM) 640 if (flags & CPP_N_FRACT || flags & CPP_N_ACCUM)
615 return interpret_fixed (token, flags); 641 return interpret_fixed (token, flags);
616 642
653 || flag_single_precision_constant) 679 || flag_single_precision_constant)
654 type = float_type_node; 680 type = float_type_node;
655 else 681 else
656 type = double_type_node; 682 type = double_type_node;
657 683
684 const_type = excess_precision_type (type);
685 if (!const_type)
686 const_type = type;
687
658 /* Copy the constant to a nul-terminated buffer. If the constant 688 /* Copy the constant to a nul-terminated buffer. If the constant
659 has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF 689 has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF
660 can't handle them. */ 690 can't handle them. */
661 copylen = token->val.str.len; 691 copylen = token->val.str.len;
662 if (flags & CPP_N_DFLOAT) 692 if (flags & CPP_N_DFLOAT)
663 copylen -= 2; 693 copylen -= 2;
664 else 694 else
665 { 695 {
666 if ((flags & CPP_N_WIDTH) != CPP_N_MEDIUM) 696 if ((flags & CPP_N_WIDTH) != CPP_N_MEDIUM)
667 /* Must be an F or L or machine defined suffix. */ 697 /* Must be an F or L or machine defined suffix. */
668 copylen--; 698 copylen--;
669 if (flags & CPP_N_IMAGINARY) 699 if (flags & CPP_N_IMAGINARY)
673 703
674 copy = (char *) alloca (copylen + 1); 704 copy = (char *) alloca (copylen + 1);
675 memcpy (copy, token->val.str.text, copylen); 705 memcpy (copy, token->val.str.text, copylen);
676 copy[copylen] = '\0'; 706 copy[copylen] = '\0';
677 707
678 real_from_string3 (&real, copy, TYPE_MODE (type)); 708 real_from_string3 (&real, copy, TYPE_MODE (const_type));
709 if (const_type != type)
710 /* Diagnosing if the result of converting the value with excess
711 precision to the semantic type would overflow (with associated
712 double rounding) is more appropriate than diagnosing if the
713 result of converting the string directly to the semantic type
714 would overflow. */
715 real_convert (&real_trunc, TYPE_MODE (type), &real);
679 716
680 /* Both C and C++ require a diagnostic for a floating constant 717 /* Both C and C++ require a diagnostic for a floating constant
681 outside the range of representable values of its type. Since we 718 outside the range of representable values of its type. Since we
682 have __builtin_inf* to produce an infinity, this is now a 719 have __builtin_inf* to produce an infinity, this is now a
683 mandatory pedwarn if the target does not support infinities. */ 720 mandatory pedwarn if the target does not support infinities. */
684 if (REAL_VALUE_ISINF (real)) 721 if (REAL_VALUE_ISINF (real)
722 || (const_type != type && REAL_VALUE_ISINF (real_trunc)))
685 { 723 {
686 if (!MODE_HAS_INFINITIES (TYPE_MODE (type))) 724 if (!MODE_HAS_INFINITIES (TYPE_MODE (type)))
687 pedwarn (input_location, 0, "floating constant exceeds range of %qT", type); 725 pedwarn (input_location, 0, "floating constant exceeds range of %qT", type);
688 else 726 else
689 warning (OPT_Woverflow, "floating constant exceeds range of %qT", type); 727 warning (OPT_Woverflow, "floating constant exceeds range of %qT", type);
690 } 728 }
691 /* We also give a warning if the value underflows. */ 729 /* We also give a warning if the value underflows. */
692 else if (REAL_VALUES_EQUAL (real, dconst0)) 730 else if (REAL_VALUES_EQUAL (real, dconst0)
731 || (const_type != type && REAL_VALUES_EQUAL (real_trunc, dconst0)))
693 { 732 {
694 REAL_VALUE_TYPE realvoidmode; 733 REAL_VALUE_TYPE realvoidmode;
695 int overflow = real_from_string (&realvoidmode, copy); 734 int overflow = real_from_string (&realvoidmode, copy);
696 if (overflow < 0 || !REAL_VALUES_EQUAL (realvoidmode, dconst0)) 735 if (overflow < 0 || !REAL_VALUES_EQUAL (realvoidmode, dconst0))
697 warning (OPT_Woverflow, "floating constant truncated to zero"); 736 warning (OPT_Woverflow, "floating constant truncated to zero");
698 } 737 }
699 738
700 /* Create a node with determined type and value. */ 739 /* Create a node with determined type and value. */
701 value = build_real (type, real); 740 value = build_real (const_type, real);
702 if (flags & CPP_N_IMAGINARY) 741 if (flags & CPP_N_IMAGINARY)
703 value = build_complex (NULL_TREE, convert (type, integer_zero_node), value); 742 value = build_complex (NULL_TREE, convert (const_type, integer_zero_node),
743 value);
744
745 if (type != const_type)
746 value = build1 (EXCESS_PRECISION_EXPR, type, value);
704 747
705 return value; 748 return value;
706 } 749 }
707 750
708 /* Interpret TOKEN, a fixed-point number with FLAGS as classified 751 /* Interpret TOKEN, a fixed-point number with FLAGS as classified
828 value = build_fixed (type, fixed); 871 value = build_fixed (type, fixed);
829 872
830 return value; 873 return value;
831 } 874 }
832 875
833 /* Convert a series of STRING, WSTRING, STRING16 and/or STRING32 tokens 876 /* Convert a series of STRING, WSTRING, STRING16, STRING32 and/or
834 into a tree, performing string constant concatenation. TOK is the 877 UTF8STRING tokens into a tree, performing string constant
835 first of these. VALP is the location to write the string into. 878 concatenation. TOK is the first of these. VALP is the location
836 OBJC_STRING indicates whether an '@' token preceded the incoming token. 879 to write the string into. OBJC_STRING indicates whether an '@' token
880 preceded the incoming token.
837 Returns the CPP token type of the result (CPP_STRING, CPP_WSTRING, 881 Returns the CPP token type of the result (CPP_STRING, CPP_WSTRING,
838 CPP_STRING32, CPP_STRING16, or CPP_OBJC_STRING). 882 CPP_STRING32, CPP_STRING16, CPP_UTF8STRING, or CPP_OBJC_STRING).
839 883
840 This is unfortunately more work than it should be. If any of the 884 This is unfortunately more work than it should be. If any of the
841 strings in the series has an L prefix, the result is a wide string 885 strings in the series has an L prefix, the result is a wide string
842 (6.4.5p4). Whether or not the result is a wide string affects the 886 (6.4.5p4). Whether or not the result is a wide string affects the
843 meaning of octal and hexadecimal escapes (6.4.4.4p6,9). But escape 887 meaning of octal and hexadecimal escapes (6.4.4.4p6,9). But escape
878 break; 922 break;
879 923
880 case CPP_WSTRING: 924 case CPP_WSTRING:
881 case CPP_STRING16: 925 case CPP_STRING16:
882 case CPP_STRING32: 926 case CPP_STRING32:
927 case CPP_UTF8STRING:
883 if (type != tok->type) 928 if (type != tok->type)
884 { 929 {
885 if (type == CPP_STRING) 930 if (type == CPP_STRING)
886 type = tok->type; 931 type = tok->type;
887 else 932 else
923 issued an error. */ 968 issued an error. */
924 switch (type) 969 switch (type)
925 { 970 {
926 default: 971 default:
927 case CPP_STRING: 972 case CPP_STRING:
973 case CPP_UTF8STRING:
928 value = build_string (1, ""); 974 value = build_string (1, "");
929 break; 975 break;
930 case CPP_STRING16: 976 case CPP_STRING16:
931 value = build_string (TYPE_PRECISION (char16_type_node) 977 value = build_string (TYPE_PRECISION (char16_type_node)
932 / TYPE_PRECISION (char_type_node), 978 / TYPE_PRECISION (char_type_node),
948 994
949 switch (type) 995 switch (type)
950 { 996 {
951 default: 997 default:
952 case CPP_STRING: 998 case CPP_STRING:
999 case CPP_UTF8STRING:
953 TREE_TYPE (value) = char_array_type_node; 1000 TREE_TYPE (value) = char_array_type_node;
954 break; 1001 break;
955 case CPP_STRING16: 1002 case CPP_STRING16:
956 TREE_TYPE (value) = char16_array_type_node; 1003 TREE_TYPE (value) = char16_array_type_node;
957 break; 1004 break;