Mercurial > hg > CbC > CbC_gcc
comparison gcc/c-parser.c @ 70:b81903832de2
merge c-decl.c
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 21 Aug 2011 09:24:16 +0900 |
parents | 1b10fe6932e1 |
children | e334828451cb |
comparison
equal
deleted
inserted
replaced
69:1b10fe6932e1 | 70:b81903832de2 |
---|---|
54 #include "c-family/c-common.h" | 54 #include "c-family/c-common.h" |
55 #include "c-family/c-objc.h" | 55 #include "c-family/c-objc.h" |
56 #include "vec.h" | 56 #include "vec.h" |
57 #include "target.h" | 57 #include "target.h" |
58 #include "cgraph.h" | 58 #include "cgraph.h" |
59 #ifndef noCbC | |
60 #include "cbc-tree.h" | |
61 #endif | |
62 #include "plugin.h" | 59 #include "plugin.h" |
63 | 60 |
64 | 61 |
65 /* Initialization routine for this file. */ | 62 /* Initialization routine for this file. */ |
66 | 63 |
82 mask |= D_C99; | 79 mask |= D_C99; |
83 if (flag_no_asm) | 80 if (flag_no_asm) |
84 { | 81 { |
85 mask |= D_ASM | D_EXT; | 82 mask |= D_ASM | D_EXT; |
86 if (!flag_isoc99) | 83 if (!flag_isoc99) |
87 mask |= D_EXT89; | 84 mask |= D_EXT89; |
88 } | 85 } |
89 if (!c_dialect_objc ()) | 86 if (!c_dialect_objc ()) |
90 mask |= D_OBJC | D_CXX_OBJC; | 87 mask |= D_OBJC | D_CXX_OBJC; |
91 | 88 |
92 ridpointers = ggc_alloc_cleared_vec_tree ((int) RID_MAX); | 89 ridpointers = ggc_alloc_cleared_vec_tree ((int) RID_MAX); |
93 for (i = 0; i < num_c_common_reswords; i++) | 90 for (i = 0; i < num_c_common_reswords; i++) |
94 { | 91 { |
95 /* If a keyword is disabled, do not enter it into the table | 92 /* If a keyword is disabled, do not enter it into the table |
96 and so create a canonical spelling that isn't a keyword. */ | 93 and so create a canonical spelling that isn't a keyword. */ |
97 if (c_common_reswords[i].disable & mask) | 94 if (c_common_reswords[i].disable & mask) |
98 { | 95 { |
99 if (warn_cxx_compat | 96 if (warn_cxx_compat |
100 && (c_common_reswords[i].disable & D_CXXWARN)) | 97 && (c_common_reswords[i].disable & D_CXXWARN)) |
101 { | 98 { |
102 id = get_identifier (c_common_reswords[i].word); | 99 id = get_identifier (c_common_reswords[i].word); |
103 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN); | 100 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN); |
104 C_IS_RESERVED_WORD (id) = 1; | 101 C_IS_RESERVED_WORD (id) = 1; |
105 } | 102 } |
106 continue; | 103 continue; |
107 } | 104 } |
108 | 105 |
109 id = get_identifier (c_common_reswords[i].word); | 106 id = get_identifier (c_common_reswords[i].word); |
110 C_SET_RID_CODE (id, c_common_reswords[i].rid); | 107 C_SET_RID_CODE (id, c_common_reswords[i].rid); |
111 C_IS_RESERVED_WORD (id) = 1; | 108 C_IS_RESERVED_WORD (id) = 1; |
112 ridpointers [(int) c_common_reswords[i].rid] = id; | 109 ridpointers [(int) c_common_reswords[i].rid] = id; |
215 c_lex_one_token (c_parser *parser, c_token *token) | 212 c_lex_one_token (c_parser *parser, c_token *token) |
216 { | 213 { |
217 timevar_push (TV_LEX); | 214 timevar_push (TV_LEX); |
218 | 215 |
219 token->type = c_lex_with_flags (&token->value, &token->location, NULL, | 216 token->type = c_lex_with_flags (&token->value, &token->location, NULL, |
220 (parser->lex_untranslated_string | 217 (parser->lex_untranslated_string |
221 ? C_LEX_STRING_NO_TRANSLATE : 0)); | 218 ? C_LEX_STRING_NO_TRANSLATE : 0)); |
222 token->id_kind = C_ID_NONE; | 219 token->id_kind = C_ID_NONE; |
223 token->keyword = RID_MAX; | 220 token->keyword = RID_MAX; |
224 token->pragma_kind = PRAGMA_NONE; | 221 token->pragma_kind = PRAGMA_NONE; |
225 | 222 |
226 switch (token->type) | 223 switch (token->type) |
374 case CPP_COLON: | 371 case CPP_COLON: |
375 case CPP_COMMA: | 372 case CPP_COMMA: |
376 case CPP_CLOSE_PAREN: | 373 case CPP_CLOSE_PAREN: |
377 case CPP_SEMICOLON: | 374 case CPP_SEMICOLON: |
378 /* These tokens may affect the interpretation of any identifiers | 375 /* These tokens may affect the interpretation of any identifiers |
379 following, if doing Objective-C. */ | 376 following, if doing Objective-C. */ |
380 if (c_dialect_objc ()) | 377 if (c_dialect_objc ()) |
381 parser->objc_need_raw_identifier = false; | 378 parser->objc_need_raw_identifier = false; |
382 break; | 379 break; |
383 case CPP_PRAGMA: | 380 case CPP_PRAGMA: |
384 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */ | 381 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */ |
385 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value); | 382 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value); |
386 token->value = NULL; | 383 token->value = NULL; |
455 { | 452 { |
456 switch (token->type) | 453 switch (token->type) |
457 { | 454 { |
458 case CPP_NAME: | 455 case CPP_NAME: |
459 switch (token->id_kind) | 456 switch (token->id_kind) |
460 { | 457 { |
461 case C_ID_ID: | 458 case C_ID_ID: |
462 return false; | 459 return false; |
463 case C_ID_ADDRSPACE: | 460 case C_ID_ADDRSPACE: |
464 return true; | 461 return true; |
465 case C_ID_TYPENAME: | 462 case C_ID_TYPENAME: |
466 return true; | 463 return true; |
467 case C_ID_CLASSNAME: | 464 case C_ID_CLASSNAME: |
468 gcc_assert (c_dialect_objc ()); | 465 gcc_assert (c_dialect_objc ()); |
469 return true; | 466 return true; |
470 default: | 467 default: |
471 gcc_unreachable (); | 468 gcc_unreachable (); |
472 } | 469 } |
473 case CPP_KEYWORD: | 470 case CPP_KEYWORD: |
474 switch (token->keyword) | 471 switch (token->keyword) |
475 { | 472 { |
476 case RID_UNSIGNED: | 473 case RID_UNSIGNED: |
477 case RID_LONG: | 474 case RID_LONG: |
503 default: | 500 default: |
504 return false; | 501 return false; |
505 } | 502 } |
506 case CPP_LESS: | 503 case CPP_LESS: |
507 if (c_dialect_objc ()) | 504 if (c_dialect_objc ()) |
508 return true; | 505 return true; |
509 return false; | 506 return false; |
510 default: | 507 default: |
511 return false; | 508 return false; |
512 } | 509 } |
513 } | 510 } |
602 { | 599 { |
603 switch (token->type) | 600 switch (token->type) |
604 { | 601 { |
605 case CPP_NAME: | 602 case CPP_NAME: |
606 switch (token->id_kind) | 603 switch (token->id_kind) |
607 { | 604 { |
608 case C_ID_ID: | 605 case C_ID_ID: |
609 return false; | 606 return false; |
610 case C_ID_ADDRSPACE: | 607 case C_ID_ADDRSPACE: |
611 return true; | 608 return true; |
612 case C_ID_TYPENAME: | 609 case C_ID_TYPENAME: |
613 return true; | 610 return true; |
614 case C_ID_CLASSNAME: | 611 case C_ID_CLASSNAME: |
615 gcc_assert (c_dialect_objc ()); | 612 gcc_assert (c_dialect_objc ()); |
616 return true; | 613 return true; |
617 default: | 614 default: |
618 gcc_unreachable (); | 615 gcc_unreachable (); |
619 } | 616 } |
620 case CPP_KEYWORD: | 617 case CPP_KEYWORD: |
621 switch (token->keyword) | 618 switch (token->keyword) |
622 { | 619 { |
623 case RID_STATIC: | 620 case RID_STATIC: |
624 case RID_EXTERN: | 621 case RID_EXTERN: |
651 case RID_RESTRICT: | 648 case RID_RESTRICT: |
652 case RID_ATTRIBUTE: | 649 case RID_ATTRIBUTE: |
653 case RID_FRACT: | 650 case RID_FRACT: |
654 case RID_ACCUM: | 651 case RID_ACCUM: |
655 case RID_SAT: | 652 case RID_SAT: |
656 #ifndef noCbC | 653 return true; |
657 case RID_CbC_CODE: | |
658 #endif | |
659 return true; | |
660 default: | 654 default: |
661 return false; | 655 return false; |
662 } | 656 } |
663 case CPP_LESS: | 657 case CPP_LESS: |
664 if (c_dialect_objc ()) | 658 if (c_dialect_objc ()) |
665 return true; | 659 return true; |
666 return false; | 660 return false; |
667 default: | 661 default: |
668 return false; | 662 return false; |
669 } | 663 } |
670 } | 664 } |
795 return; | 789 return; |
796 /* This diagnostic makes more sense if it is tagged to the line of | 790 /* This diagnostic makes more sense if it is tagged to the line of |
797 the token we just peeked at. */ | 791 the token we just peeked at. */ |
798 c_parser_set_source_position_from_token (token); | 792 c_parser_set_source_position_from_token (token); |
799 c_parse_error (gmsgid, | 793 c_parse_error (gmsgid, |
800 /* Because c_parse_error does not understand | 794 /* Because c_parse_error does not understand |
801 CPP_KEYWORD, keywords are treated like | 795 CPP_KEYWORD, keywords are treated like |
802 identifiers. */ | 796 identifiers. */ |
803 (token->type == CPP_KEYWORD ? CPP_NAME : token->type), | 797 (token->type == CPP_KEYWORD ? CPP_NAME : token->type), |
804 /* ??? The C parser does not save the cpp flags of a | 798 /* ??? The C parser does not save the cpp flags of a |
805 token, we need to pass 0 here and we will not get | 799 token, we need to pass 0 here and we will not get |
806 the source spelling of some tokens but rather the | 800 the source spelling of some tokens but rather the |
807 canonical spelling. */ | 801 canonical spelling. */ |
808 token->value, /*flags=*/0); | 802 token->value, /*flags=*/0); |
809 } | 803 } |
810 | 804 |
811 /* If the next token is of the indicated TYPE, consume it. Otherwise, | 805 /* If the next token is of the indicated TYPE, consume it. Otherwise, |
812 issue the error MSGID. If MSGID is NULL then a message has already | 806 issue the error MSGID. If MSGID is NULL then a message has already |
813 been produced and no message will be produced this time. Returns | 807 been produced and no message will be produced this time. Returns |
814 true if found, false otherwise. */ | 808 true if found, false otherwise. */ |
815 | 809 |
816 static bool | 810 static bool |
817 c_parser_require (c_parser *parser, | 811 c_parser_require (c_parser *parser, |
818 enum cpp_ttype type, | 812 enum cpp_ttype type, |
819 const char *msgid) | 813 const char *msgid) |
820 { | 814 { |
821 if (c_parser_next_token_is (parser, type)) | 815 if (c_parser_next_token_is (parser, type)) |
822 { | 816 { |
823 c_parser_consume_token (parser); | 817 c_parser_consume_token (parser); |
824 return true; | 818 return true; |
833 /* If the next token is the indicated keyword, consume it. Otherwise, | 827 /* If the next token is the indicated keyword, consume it. Otherwise, |
834 issue the error MSGID. Returns true if found, false otherwise. */ | 828 issue the error MSGID. Returns true if found, false otherwise. */ |
835 | 829 |
836 static bool | 830 static bool |
837 c_parser_require_keyword (c_parser *parser, | 831 c_parser_require_keyword (c_parser *parser, |
838 enum rid keyword, | 832 enum rid keyword, |
839 const char *msgid) | 833 const char *msgid) |
840 { | 834 { |
841 if (c_parser_next_token_is_keyword (parser, keyword)) | 835 if (c_parser_next_token_is_keyword (parser, keyword)) |
842 { | 836 { |
843 c_parser_consume_token (parser); | 837 c_parser_consume_token (parser); |
844 return true; | 838 return true; |
856 already been produced and no message will be produced this | 850 already been produced and no message will be produced this |
857 time. */ | 851 time. */ |
858 | 852 |
859 static void | 853 static void |
860 c_parser_skip_until_found (c_parser *parser, | 854 c_parser_skip_until_found (c_parser *parser, |
861 enum cpp_ttype type, | 855 enum cpp_ttype type, |
862 const char *msgid) | 856 const char *msgid) |
863 { | 857 { |
864 unsigned nesting_depth = 0; | 858 unsigned nesting_depth = 0; |
865 | 859 |
866 if (c_parser_require (parser, type, msgid)) | 860 if (c_parser_require (parser, type, msgid)) |
867 return; | 861 return; |
871 { | 865 { |
872 /* Peek at the next token. */ | 866 /* Peek at the next token. */ |
873 c_token *token = c_parser_peek_token (parser); | 867 c_token *token = c_parser_peek_token (parser); |
874 /* If we've reached the token we want, consume it and stop. */ | 868 /* If we've reached the token we want, consume it and stop. */ |
875 if (token->type == type && !nesting_depth) | 869 if (token->type == type && !nesting_depth) |
876 { | 870 { |
877 c_parser_consume_token (parser); | 871 c_parser_consume_token (parser); |
878 break; | 872 break; |
879 } | 873 } |
880 | 874 |
881 /* If we've run out of tokens, stop. */ | 875 /* If we've run out of tokens, stop. */ |
882 if (token->type == CPP_EOF) | 876 if (token->type == CPP_EOF) |
883 return; | 877 return; |
884 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma) | 878 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma) |
885 return; | 879 return; |
886 if (token->type == CPP_OPEN_BRACE | 880 if (token->type == CPP_OPEN_BRACE |
887 || token->type == CPP_OPEN_PAREN | 881 || token->type == CPP_OPEN_PAREN |
888 || token->type == CPP_OPEN_SQUARE) | 882 || token->type == CPP_OPEN_SQUARE) |
889 ++nesting_depth; | 883 ++nesting_depth; |
890 else if (token->type == CPP_CLOSE_BRACE | 884 else if (token->type == CPP_CLOSE_BRACE |
891 || token->type == CPP_CLOSE_PAREN | 885 || token->type == CPP_CLOSE_PAREN |
892 || token->type == CPP_CLOSE_SQUARE) | 886 || token->type == CPP_CLOSE_SQUARE) |
893 { | 887 { |
894 if (nesting_depth-- == 0) | 888 if (nesting_depth-- == 0) |
895 break; | 889 break; |
896 } | 890 } |
897 /* Consume this token. */ | 891 /* Consume this token. */ |
898 c_parser_consume_token (parser); | 892 c_parser_consume_token (parser); |
899 } | 893 } |
900 parser->error = false; | 894 parser->error = false; |
901 } | 895 } |
910 | 904 |
911 while (true) | 905 while (true) |
912 { | 906 { |
913 c_token *token = c_parser_peek_token (parser); | 907 c_token *token = c_parser_peek_token (parser); |
914 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON) | 908 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON) |
915 && !nesting_depth) | 909 && !nesting_depth) |
916 break; | 910 break; |
917 /* If we've run out of tokens, stop. */ | 911 /* If we've run out of tokens, stop. */ |
918 if (token->type == CPP_EOF) | 912 if (token->type == CPP_EOF) |
919 return; | 913 return; |
920 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma) | 914 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma) |
921 return; | 915 return; |
922 if (token->type == CPP_OPEN_BRACE | 916 if (token->type == CPP_OPEN_BRACE |
923 || token->type == CPP_OPEN_PAREN | 917 || token->type == CPP_OPEN_PAREN |
924 || token->type == CPP_OPEN_SQUARE) | 918 || token->type == CPP_OPEN_SQUARE) |
925 ++nesting_depth; | 919 ++nesting_depth; |
926 else if (token->type == CPP_CLOSE_BRACE | 920 else if (token->type == CPP_CLOSE_BRACE |
927 || token->type == CPP_CLOSE_PAREN | 921 || token->type == CPP_CLOSE_PAREN |
928 || token->type == CPP_CLOSE_SQUARE) | 922 || token->type == CPP_CLOSE_SQUARE) |
929 { | 923 { |
930 if (nesting_depth-- == 0) | 924 if (nesting_depth-- == 0) |
931 break; | 925 break; |
932 } | 926 } |
933 /* Consume this token. */ | 927 /* Consume this token. */ |
934 c_parser_consume_token (parser); | 928 c_parser_consume_token (parser); |
935 } | 929 } |
936 parser->error = false; | 930 parser->error = false; |
937 } | 931 } |
946 parser->in_pragma = false; | 940 parser->in_pragma = false; |
947 | 941 |
948 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line")) | 942 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line")) |
949 while (true) | 943 while (true) |
950 { | 944 { |
951 c_token *token = c_parser_peek_token (parser); | 945 c_token *token = c_parser_peek_token (parser); |
952 if (token->type == CPP_EOF) | 946 if (token->type == CPP_EOF) |
953 break; | 947 break; |
954 if (token->type == CPP_PRAGMA_EOL) | 948 if (token->type == CPP_PRAGMA_EOL) |
955 { | 949 { |
956 c_parser_consume_token (parser); | 950 c_parser_consume_token (parser); |
957 break; | 951 break; |
958 } | 952 } |
959 c_parser_consume_token (parser); | 953 c_parser_consume_token (parser); |
960 } | 954 } |
961 | 955 |
962 parser->error = false; | 956 parser->error = false; |
963 } | 957 } |
964 | 958 |
977 | 971 |
978 /* Peek at the next token. */ | 972 /* Peek at the next token. */ |
979 token = c_parser_peek_token (parser); | 973 token = c_parser_peek_token (parser); |
980 | 974 |
981 switch (token->type) | 975 switch (token->type) |
982 { | 976 { |
983 case CPP_EOF: | 977 case CPP_EOF: |
984 return; | 978 return; |
985 | 979 |
986 case CPP_PRAGMA_EOL: | 980 case CPP_PRAGMA_EOL: |
987 if (parser->in_pragma) | 981 if (parser->in_pragma) |
988 return; | 982 return; |
989 break; | 983 break; |
990 | 984 |
991 case CPP_SEMICOLON: | 985 case CPP_SEMICOLON: |
992 /* If the next token is a ';', we have reached the | 986 /* If the next token is a ';', we have reached the |
993 end of the statement. */ | 987 end of the statement. */ |
994 if (!nesting_depth) | 988 if (!nesting_depth) |
995 { | 989 { |
996 /* Consume the ';'. */ | 990 /* Consume the ';'. */ |
997 c_parser_consume_token (parser); | 991 c_parser_consume_token (parser); |
998 goto finished; | 992 goto finished; |
999 } | 993 } |
1000 break; | 994 break; |
1001 | 995 |
1002 case CPP_CLOSE_BRACE: | 996 case CPP_CLOSE_BRACE: |
1003 /* If the next token is a non-nested '}', then we have | 997 /* If the next token is a non-nested '}', then we have |
1004 reached the end of the current block. */ | 998 reached the end of the current block. */ |
1005 if (nesting_depth == 0 || --nesting_depth == 0) | 999 if (nesting_depth == 0 || --nesting_depth == 0) |
1006 { | 1000 { |
1007 c_parser_consume_token (parser); | 1001 c_parser_consume_token (parser); |
1008 goto finished; | 1002 goto finished; |
1009 } | 1003 } |
1010 break; | 1004 break; |
1011 | 1005 |
1012 case CPP_OPEN_BRACE: | 1006 case CPP_OPEN_BRACE: |
1013 /* If it the next token is a '{', then we are entering a new | 1007 /* If it the next token is a '{', then we are entering a new |
1014 block. Consume the entire block. */ | 1008 block. Consume the entire block. */ |
1015 ++nesting_depth; | 1009 ++nesting_depth; |
1016 break; | 1010 break; |
1017 | 1011 |
1018 case CPP_PRAGMA: | 1012 case CPP_PRAGMA: |
1019 /* If we see a pragma, consume the whole thing at once. We | 1013 /* If we see a pragma, consume the whole thing at once. We |
1020 have some safeguards against consuming pragmas willy-nilly. | 1014 have some safeguards against consuming pragmas willy-nilly. |
1021 Normally, we'd expect to be here with parser->error set, | 1015 Normally, we'd expect to be here with parser->error set, |
1022 which disables these safeguards. But it's possible to get | 1016 which disables these safeguards. But it's possible to get |
1023 here for secondary error recovery, after parser->error has | 1017 here for secondary error recovery, after parser->error has |
1024 been cleared. */ | 1018 been cleared. */ |
1025 c_parser_consume_pragma (parser); | 1019 c_parser_consume_pragma (parser); |
1026 c_parser_skip_to_pragma_eol (parser); | 1020 c_parser_skip_to_pragma_eol (parser); |
1027 parser->error = save_error; | 1021 parser->error = save_error; |
1028 continue; | 1022 continue; |
1029 | 1023 |
1030 default: | 1024 default: |
1031 break; | 1025 break; |
1032 } | 1026 } |
1033 | 1027 |
1034 c_parser_consume_token (parser); | 1028 c_parser_consume_token (parser); |
1035 } | 1029 } |
1036 | 1030 |
1037 finished: | 1031 finished: |
1105 static struct c_typespec c_parser_enum_specifier (c_parser *); | 1099 static struct c_typespec c_parser_enum_specifier (c_parser *); |
1106 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *); | 1100 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *); |
1107 static tree c_parser_struct_declaration (c_parser *); | 1101 static tree c_parser_struct_declaration (c_parser *); |
1108 static struct c_typespec c_parser_typeof_specifier (c_parser *); | 1102 static struct c_typespec c_parser_typeof_specifier (c_parser *); |
1109 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn, | 1103 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn, |
1110 bool *); | 1104 bool *); |
1111 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool, | 1105 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool, |
1112 c_dtr_syn, bool *); | 1106 c_dtr_syn, bool *); |
1113 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *, | 1107 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *, |
1114 bool, | 1108 bool, |
1115 struct c_declarator *); | 1109 struct c_declarator *); |
1116 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree); | 1110 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree); |
1117 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree); | 1111 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree); |
1118 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree); | 1112 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree); |
1119 static tree c_parser_simple_asm_expr (c_parser *); | 1113 static tree c_parser_simple_asm_expr (c_parser *); |
1120 static tree c_parser_attributes (c_parser *); | 1114 static tree c_parser_attributes (c_parser *); |
1138 static tree c_parser_asm_operands (c_parser *, bool); | 1132 static tree c_parser_asm_operands (c_parser *, bool); |
1139 static tree c_parser_asm_goto_operands (c_parser *); | 1133 static tree c_parser_asm_goto_operands (c_parser *); |
1140 static tree c_parser_asm_clobbers (c_parser *); | 1134 static tree c_parser_asm_clobbers (c_parser *); |
1141 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *); | 1135 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *); |
1142 static struct c_expr c_parser_conditional_expression (c_parser *, | 1136 static struct c_expr c_parser_conditional_expression (c_parser *, |
1143 struct c_expr *); | 1137 struct c_expr *); |
1144 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *); | 1138 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *); |
1145 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *); | 1139 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *); |
1146 static struct c_expr c_parser_unary_expression (c_parser *); | 1140 static struct c_expr c_parser_unary_expression (c_parser *); |
1147 static struct c_expr c_parser_sizeof_expression (c_parser *); | 1141 static struct c_expr c_parser_sizeof_expression (c_parser *); |
1148 static struct c_expr c_parser_alignof_expression (c_parser *); | 1142 static struct c_expr c_parser_alignof_expression (c_parser *); |
1149 static struct c_expr c_parser_postfix_expression (c_parser *); | 1143 static struct c_expr c_parser_postfix_expression (c_parser *); |
1150 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *, | 1144 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *, |
1151 struct c_type_name *, | 1145 struct c_type_name *, |
1152 location_t); | 1146 location_t); |
1153 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *, | 1147 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *, |
1154 location_t loc, | 1148 location_t loc, |
1155 struct c_expr); | 1149 struct c_expr); |
1156 static struct c_expr c_parser_expression (c_parser *); | 1150 static struct c_expr c_parser_expression (c_parser *); |
1157 static struct c_expr c_parser_expression_conv (c_parser *); | 1151 static struct c_expr c_parser_expression_conv (c_parser *); |
1158 static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool, | 1152 static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool, |
1159 VEC(tree,gc) **); | 1153 VEC(tree,gc) **); |
1160 static void c_parser_omp_construct (c_parser *); | 1154 static void c_parser_omp_construct (c_parser *); |
1161 static void c_parser_omp_threadprivate (c_parser *); | 1155 static void c_parser_omp_threadprivate (c_parser *); |
1162 static void c_parser_omp_barrier (c_parser *); | 1156 static void c_parser_omp_barrier (c_parser *); |
1163 static void c_parser_omp_flush (c_parser *); | 1157 static void c_parser_omp_flush (c_parser *); |
1164 static void c_parser_omp_taskwait (c_parser *); | 1158 static void c_parser_omp_taskwait (c_parser *); |
1212 c_parser_translation_unit (c_parser *parser) | 1206 c_parser_translation_unit (c_parser *parser) |
1213 { | 1207 { |
1214 if (c_parser_next_token_is (parser, CPP_EOF)) | 1208 if (c_parser_next_token_is (parser, CPP_EOF)) |
1215 { | 1209 { |
1216 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic, | 1210 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic, |
1217 "ISO C forbids an empty translation unit"); | 1211 "ISO C forbids an empty translation unit"); |
1218 } | 1212 } |
1219 else | 1213 else |
1220 { | 1214 { |
1221 void *obstack_position = obstack_alloc (&parser_obstack, 0); | 1215 void *obstack_position = obstack_alloc (&parser_obstack, 0); |
1222 mark_valid_location_for_stdc_pragma (false); | 1216 mark_valid_location_for_stdc_pragma (false); |
1223 do | 1217 do |
1224 { | 1218 { |
1225 ggc_collect (); | 1219 ggc_collect (); |
1226 c_parser_external_declaration (parser); | 1220 c_parser_external_declaration (parser); |
1227 obstack_free (&parser_obstack, obstack_position); | 1221 obstack_free (&parser_obstack, obstack_position); |
1228 } | 1222 } |
1229 while (c_parser_next_token_is_not (parser, CPP_EOF)); | 1223 while (c_parser_next_token_is_not (parser, CPP_EOF)); |
1230 } | 1224 } |
1231 } | 1225 } |
1232 | 1226 |
1233 /* Parse an external declaration (C90 6.7, C99 6.9). | 1227 /* Parse an external declaration (C90 6.7, C99 6.9). |
1310 goto decl_or_fndef; | 1304 goto decl_or_fndef; |
1311 } | 1305 } |
1312 break; | 1306 break; |
1313 case CPP_SEMICOLON: | 1307 case CPP_SEMICOLON: |
1314 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic, | 1308 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic, |
1315 "ISO C does not allow extra %<;%> outside of a function"); | 1309 "ISO C does not allow extra %<;%> outside of a function"); |
1316 c_parser_consume_token (parser); | 1310 c_parser_consume_token (parser); |
1317 break; | 1311 break; |
1318 case CPP_PRAGMA: | 1312 case CPP_PRAGMA: |
1319 mark_valid_location_for_stdc_pragma (true); | 1313 mark_valid_location_for_stdc_pragma (true); |
1320 c_parser_pragma (parser, pragma_external); | 1314 c_parser_pragma (parser, pragma_external); |
1321 mark_valid_location_for_stdc_pragma (false); | 1315 mark_valid_location_for_stdc_pragma (false); |
1322 break; | 1316 break; |
1323 case CPP_PLUS: | 1317 case CPP_PLUS: |
1324 case CPP_MINUS: | 1318 case CPP_MINUS: |
1325 if (c_dialect_objc ()) | 1319 if (c_dialect_objc ()) |
1326 { | 1320 { |
1327 c_parser_objc_method_definition (parser); | 1321 c_parser_objc_method_definition (parser); |
1328 break; | 1322 break; |
1329 } | 1323 } |
1330 /* Else fall through, and yield a syntax error trying to parse | 1324 /* Else fall through, and yield a syntax error trying to parse |
1331 as a declaration or function definition. */ | 1325 as a declaration or function definition. */ |
1332 default: | 1326 default: |
1333 decl_or_fndef: | 1327 decl_or_fndef: |
1334 /* A declaration or a function definition (or, in Objective-C, | 1328 /* A declaration or a function definition (or, in Objective-C, |
1335 an @interface or @protocol with prefix attributes). We can | 1329 an @interface or @protocol with prefix attributes). We can |
1336 only tell which after parsing the declaration specifiers, if | 1330 only tell which after parsing the declaration specifiers, if |
1464 } | 1458 } |
1465 finish_declspecs (specs); | 1459 finish_declspecs (specs); |
1466 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | 1460 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
1467 { | 1461 { |
1468 if (empty_ok) | 1462 if (empty_ok) |
1469 shadow_tag (specs); | 1463 shadow_tag (specs); |
1470 else | 1464 else |
1471 { | 1465 { |
1472 shadow_tag_warned (specs, 1); | 1466 shadow_tag_warned (specs, 1); |
1473 pedwarn (here, 0, "empty declaration"); | 1467 pedwarn (here, 0, "empty declaration"); |
1474 } | 1468 } |
1475 c_parser_consume_token (parser); | 1469 c_parser_consume_token (parser); |
1476 return; | 1470 return; |
1477 } | 1471 } |
1478 | 1472 |
1479 /* Provide better error recovery. Note that a type name here is usually | 1473 /* Provide better error recovery. Note that a type name here is usually |
1581 implicit int suffices). */ | 1575 implicit int suffices). */ |
1582 declarator = c_parser_declarator (parser, | 1576 declarator = c_parser_declarator (parser, |
1583 specs->typespec_kind != ctsk_none, | 1577 specs->typespec_kind != ctsk_none, |
1584 C_DTR_NORMAL, &dummy); | 1578 C_DTR_NORMAL, &dummy); |
1585 if (declarator == NULL) | 1579 if (declarator == NULL) |
1586 { | 1580 { |
1587 c_parser_skip_to_end_of_block_or_statement (parser); | 1581 c_parser_skip_to_end_of_block_or_statement (parser); |
1588 return; | 1582 return; |
1589 } | 1583 } |
1590 if (c_parser_next_token_is (parser, CPP_EQ) | 1584 if (c_parser_next_token_is (parser, CPP_EQ) |
1591 || c_parser_next_token_is (parser, CPP_COMMA) | 1585 || c_parser_next_token_is (parser, CPP_COMMA) |
1592 || c_parser_next_token_is (parser, CPP_SEMICOLON) | 1586 || c_parser_next_token_is (parser, CPP_SEMICOLON) |
1593 || c_parser_next_token_is_keyword (parser, RID_ASM) | 1587 || c_parser_next_token_is_keyword (parser, RID_ASM) |
1594 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE) | 1588 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE) |
1678 c_parser_skip_to_end_of_block_or_statement (parser); | 1672 c_parser_skip_to_end_of_block_or_statement (parser); |
1679 return; | 1673 return; |
1680 } | 1674 } |
1681 } | 1675 } |
1682 else if (!fndef_ok) | 1676 else if (!fndef_ok) |
1683 { | 1677 { |
1684 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, " | 1678 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, " |
1685 "%<asm%> or %<__attribute__%>"); | 1679 "%<asm%> or %<__attribute__%>"); |
1686 c_parser_skip_to_end_of_block_or_statement (parser); | 1680 c_parser_skip_to_end_of_block_or_statement (parser); |
1687 return; | 1681 return; |
1688 } | 1682 } |
1689 /* Function definition (nested or otherwise). */ | 1683 /* Function definition (nested or otherwise). */ |
1690 if (nested) | 1684 if (nested) |
1691 { | 1685 { |
1692 pedwarn (here, OPT_pedantic, "ISO C forbids nested functions"); | 1686 pedwarn (here, OPT_pedantic, "ISO C forbids nested functions"); |
1693 c_push_function_context (); | 1687 c_push_function_context (); |
1694 } | 1688 } |
1695 if (!start_function (specs, declarator, all_prefix_attrs)) | 1689 if (!start_function (specs, declarator, all_prefix_attrs)) |
1696 { | 1690 { |
1697 /* This can appear in many cases looking nothing like a | 1691 /* This can appear in many cases looking nothing like a |
1698 function definition, so we don't give a more specific | 1692 function definition, so we don't give a more specific |
1699 error suggesting there was one. */ | 1693 error suggesting there was one. */ |
1700 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> " | 1694 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> " |
1701 "or %<__attribute__%>"); | 1695 "or %<__attribute__%>"); |
1702 if (nested) | 1696 if (nested) |
1703 c_pop_function_context (); | 1697 c_pop_function_context (); |
1704 break; | 1698 break; |
1705 } | 1699 } |
1706 /* Parse old-style parameter declarations. ??? Attributes are | 1700 /* Parse old-style parameter declarations. ??? Attributes are |
1707 not allowed to start declaration specifiers here because of a | 1701 not allowed to start declaration specifiers here because of a |
1708 syntax conflict between a function declaration with attribute | 1702 syntax conflict between a function declaration with attribute |
1709 suffix and a function definition with an attribute prefix on | 1703 suffix and a function definition with an attribute prefix on |
1710 first old-style parameter declaration. Following the old | 1704 first old-style parameter declaration. Following the old |
1711 parser, they are not accepted on subsequent old-style | 1705 parser, they are not accepted on subsequent old-style |
1712 parameter declarations either. However, there is no | 1706 parameter declarations either. However, there is no |
1713 ambiguity after the first declaration, nor indeed on the | 1707 ambiguity after the first declaration, nor indeed on the |
1714 first as long as we don't allow postfix attributes after a | 1708 first as long as we don't allow postfix attributes after a |
1715 declarator with a nonempty identifier list in a definition; | 1709 declarator with a nonempty identifier list in a definition; |
1716 and postfix attributes have never been accepted here in | 1710 and postfix attributes have never been accepted here in |
1717 function definitions either. */ | 1711 function definitions either. */ |
1718 while (c_parser_next_token_is_not (parser, CPP_EOF) | 1712 while (c_parser_next_token_is_not (parser, CPP_EOF) |
1719 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE)) | 1713 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE)) |
1720 c_parser_declaration_or_fndef (parser, false, false, false, | 1714 c_parser_declaration_or_fndef (parser, false, false, false, |
1721 true, false, NULL); | 1715 true, false, NULL); |
1722 store_parm_decls (); | 1716 store_parm_decls (); |
1723 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus | 1717 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus |
1724 = c_parser_peek_token (parser)->location; | 1718 = c_parser_peek_token (parser)->location; |
1725 fnbody = c_parser_compound_statement (parser); | 1719 fnbody = c_parser_compound_statement (parser); |
1726 if (nested) | 1720 if (nested) |
1727 { | 1721 { |
1728 tree decl = current_function_decl; | 1722 tree decl = current_function_decl; |
1729 /* Mark nested functions as needing static-chain initially. | 1723 /* Mark nested functions as needing static-chain initially. |
1730 lower_nested_functions will recompute it but the | 1724 lower_nested_functions will recompute it but the |
1731 DECL_STATIC_CHAIN flag is also used before that happens, | 1725 DECL_STATIC_CHAIN flag is also used before that happens, |
1732 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */ | 1726 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */ |
1733 DECL_STATIC_CHAIN (decl) = 1; | 1727 DECL_STATIC_CHAIN (decl) = 1; |
1734 add_stmt (fnbody); | 1728 add_stmt (fnbody); |
1735 finish_function (); | 1729 finish_function (); |
1736 c_pop_function_context (); | 1730 c_pop_function_context (); |
1737 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl)); | 1731 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl)); |
1738 } | 1732 } |
1739 else | 1733 else |
1740 { | 1734 { |
1741 add_stmt (fnbody); | 1735 add_stmt (fnbody); |
1742 finish_function (); | 1736 finish_function (); |
1743 } | 1737 } |
1744 break; | 1738 break; |
1745 } | 1739 } |
1746 } | 1740 } |
1747 | 1741 |
1748 /* Parse an asm-definition (asm() outside a function body). This is a | 1742 /* Parse an asm-definition (asm() outside a function body). This is a |
1954 | 1948 |
1955 if (!typespec_ok) | 1949 if (!typespec_ok) |
1956 gcc_assert (la == cla_prefer_id); | 1950 gcc_assert (la == cla_prefer_id); |
1957 | 1951 |
1958 while (c_parser_next_token_is (parser, CPP_NAME) | 1952 while (c_parser_next_token_is (parser, CPP_NAME) |
1959 || c_parser_next_token_is (parser, CPP_KEYWORD) | 1953 || c_parser_next_token_is (parser, CPP_KEYWORD) |
1960 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS))) | 1954 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS))) |
1961 { | 1955 { |
1962 struct c_typespec t; | 1956 struct c_typespec t; |
1963 tree attrs; | 1957 tree attrs; |
1964 location_t loc = c_parser_peek_token (parser)->location; | 1958 location_t loc = c_parser_peek_token (parser)->location; |
1965 | 1959 |
2029 t.expr_const_operands = true; | 2023 t.expr_const_operands = true; |
2030 declspecs_add_type (loc, specs, t); | 2024 declspecs_add_type (loc, specs, t); |
2031 continue; | 2025 continue; |
2032 } | 2026 } |
2033 if (c_parser_next_token_is (parser, CPP_LESS)) | 2027 if (c_parser_next_token_is (parser, CPP_LESS)) |
2034 { | 2028 { |
2035 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" - | 2029 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" - |
2036 nisse@lysator.liu.se. */ | 2030 nisse@lysator.liu.se. */ |
2037 tree proto; | 2031 tree proto; |
2038 gcc_assert (c_dialect_objc ()); | 2032 gcc_assert (c_dialect_objc ()); |
2039 if (!typespec_ok || seen_type) | 2033 if (!typespec_ok || seen_type) |
2040 break; | 2034 break; |
2041 proto = c_parser_objc_protocol_refs (parser); | 2035 proto = c_parser_objc_protocol_refs (parser); |
2042 t.kind = ctsk_objc; | 2036 t.kind = ctsk_objc; |
2043 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto); | 2037 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto); |
2044 t.expr = NULL_TREE; | 2038 t.expr = NULL_TREE; |
2045 t.expr_const_operands = true; | 2039 t.expr_const_operands = true; |
2046 declspecs_add_type (loc, specs, t); | 2040 declspecs_add_type (loc, specs, t); |
2047 continue; | 2041 continue; |
2048 } | 2042 } |
2049 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD)); | 2043 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD)); |
2050 switch (c_parser_peek_token (parser)->keyword) | 2044 switch (c_parser_peek_token (parser)->keyword) |
2051 { | 2045 { |
2052 case RID_STATIC: | 2046 case RID_STATIC: |
2053 case RID_EXTERN: | 2047 case RID_EXTERN: |
2094 t.expr = NULL_TREE; | 2088 t.expr = NULL_TREE; |
2095 t.expr_const_operands = true; | 2089 t.expr_const_operands = true; |
2096 declspecs_add_type (loc, specs, t); | 2090 declspecs_add_type (loc, specs, t); |
2097 c_parser_consume_token (parser); | 2091 c_parser_consume_token (parser); |
2098 break; | 2092 break; |
2099 #ifndef noCbC | |
2100 case RID_CbC_CODE: | |
2101 if (!typespec_ok) | |
2102 goto out; | |
2103 attrs_ok = true; | |
2104 seen_type = true; | |
2105 if (c_dialect_objc ()) | |
2106 parser->objc_need_raw_identifier = true; | |
2107 t.kind = ctsk_resword; | |
2108 t.spec = c_parser_peek_token (parser)->value; | |
2109 declspecs_add_type (loc, specs, t); | |
2110 | |
2111 /* | |
2112 attrs = get_identifier("fastcall"); | |
2113 attrs = build_tree_list(attrs, NULL_TREE); | |
2114 declspecs_add_attrs(specs, attrs); | |
2115 */ | |
2116 attrs = build_tree_list (get_identifier("fastcall"), NULL_TREE); | |
2117 /*attrs = build_tree_list (get_identifier("noreturn"), attrs);*/ | |
2118 declspecs_add_attrs(specs, attrs); | |
2119 | |
2120 c_parser_consume_token (parser); | |
2121 break; | |
2122 #endif | |
2123 case RID_ENUM: | 2093 case RID_ENUM: |
2124 if (!typespec_ok) | 2094 if (!typespec_ok) |
2125 goto out; | 2095 goto out; |
2126 attrs_ok = true; | 2096 attrs_ok = true; |
2127 seen_type = true; | 2097 seen_type = true; |
2134 goto out; | 2104 goto out; |
2135 attrs_ok = true; | 2105 attrs_ok = true; |
2136 seen_type = true; | 2106 seen_type = true; |
2137 t = c_parser_struct_or_union_specifier (parser); | 2107 t = c_parser_struct_or_union_specifier (parser); |
2138 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec); | 2108 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec); |
2139 declspecs_add_type (loc, specs, t); | 2109 declspecs_add_type (loc, specs, t); |
2140 break; | 2110 break; |
2141 case RID_TYPEOF: | 2111 case RID_TYPEOF: |
2142 /* ??? The old parser rejected typeof after other type | 2112 /* ??? The old parser rejected typeof after other type |
2143 specifiers, but is a syntax error the best way of | 2113 specifiers, but is a syntax error the best way of |
2144 handling this? */ | 2114 handling this? */ |
2145 if (!typespec_ok || seen_type) | 2115 if (!typespec_ok || seen_type) |
2146 goto out; | 2116 goto out; |
2147 attrs_ok = true; | 2117 attrs_ok = true; |
2148 seen_type = true; | 2118 seen_type = true; |
2149 t = c_parser_typeof_specifier (parser); | 2119 t = c_parser_typeof_specifier (parser); |
2150 declspecs_add_type (loc, specs, t); | 2120 declspecs_add_type (loc, specs, t); |
2151 break; | 2121 break; |
2152 case RID_CONST: | 2122 case RID_CONST: |
2153 case RID_VOLATILE: | 2123 case RID_VOLATILE: |
2154 case RID_RESTRICT: | 2124 case RID_RESTRICT: |
2155 attrs_ok = true; | 2125 attrs_ok = true; |
2156 declspecs_add_qual (specs, c_parser_peek_token (parser)->value); | 2126 declspecs_add_qual (specs, c_parser_peek_token (parser)->value); |
2157 c_parser_consume_token (parser); | 2127 c_parser_consume_token (parser); |
2158 break; | 2128 break; |
2159 case RID_ATTRIBUTE: | 2129 case RID_ATTRIBUTE: |
2160 if (!attrs_ok) | 2130 if (!attrs_ok) |
2161 goto out; | 2131 goto out; |
2162 attrs = c_parser_attributes (parser); | 2132 attrs = c_parser_attributes (parser); |
2163 declspecs_add_attrs (specs, attrs); | 2133 declspecs_add_attrs (specs, attrs); |
2164 break; | 2134 break; |
2165 default: | 2135 default: |
2166 goto out; | 2136 goto out; |
2167 } | 2137 } |
2168 } | 2138 } |
2169 out: ; | 2139 out: ; |
2170 } | 2140 } |
2171 | 2141 |
2172 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2). | 2142 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2). |
2218 /* Parse an enum definition. */ | 2188 /* Parse an enum definition. */ |
2219 struct c_enum_contents the_enum; | 2189 struct c_enum_contents the_enum; |
2220 tree type = start_enum (enum_loc, &the_enum, ident); | 2190 tree type = start_enum (enum_loc, &the_enum, ident); |
2221 tree postfix_attrs; | 2191 tree postfix_attrs; |
2222 /* We chain the enumerators in reverse order, then put them in | 2192 /* We chain the enumerators in reverse order, then put them in |
2223 forward order at the end. */ | 2193 forward order at the end. */ |
2224 tree values = NULL_TREE; | 2194 tree values = NULL_TREE; |
2225 c_parser_consume_token (parser); | 2195 c_parser_consume_token (parser); |
2226 while (true) | 2196 while (true) |
2227 { | 2197 { |
2228 tree enum_id; | 2198 tree enum_id; |
2279 break; | 2249 break; |
2280 } | 2250 } |
2281 } | 2251 } |
2282 postfix_attrs = c_parser_attributes (parser); | 2252 postfix_attrs = c_parser_attributes (parser); |
2283 ret.spec = finish_enum (type, nreverse (values), | 2253 ret.spec = finish_enum (type, nreverse (values), |
2284 chainon (attrs, postfix_attrs)); | 2254 chainon (attrs, postfix_attrs)); |
2285 ret.kind = ctsk_tagdef; | 2255 ret.kind = ctsk_tagdef; |
2286 ret.expr = NULL_TREE; | 2256 ret.expr = NULL_TREE; |
2287 ret.expr_const_operands = true; | 2257 ret.expr_const_operands = true; |
2288 return ret; | 2258 return ret; |
2289 } | 2259 } |
2301 defined. */ | 2271 defined. */ |
2302 if (pedantic && !COMPLETE_TYPE_P (ret.spec)) | 2272 if (pedantic && !COMPLETE_TYPE_P (ret.spec)) |
2303 { | 2273 { |
2304 gcc_assert (ident); | 2274 gcc_assert (ident); |
2305 pedwarn (enum_loc, OPT_pedantic, | 2275 pedwarn (enum_loc, OPT_pedantic, |
2306 "ISO C forbids forward references to %<enum%> types"); | 2276 "ISO C forbids forward references to %<enum%> types"); |
2307 } | 2277 } |
2308 return ret; | 2278 return ret; |
2309 } | 2279 } |
2310 | 2280 |
2311 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1). | 2281 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1). |
2382 c_parser_consume_token (parser); | 2352 c_parser_consume_token (parser); |
2383 } | 2353 } |
2384 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | 2354 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
2385 { | 2355 { |
2386 /* Parse a struct or union definition. Start the scope of the | 2356 /* Parse a struct or union definition. Start the scope of the |
2387 tag before parsing components. */ | 2357 tag before parsing components. */ |
2388 struct c_struct_parse_info *struct_info; | 2358 struct c_struct_parse_info *struct_info; |
2389 tree type = start_struct (struct_loc, code, ident, &struct_info); | 2359 tree type = start_struct (struct_loc, code, ident, &struct_info); |
2390 tree postfix_attrs; | 2360 tree postfix_attrs; |
2391 /* We chain the components in reverse order, then put them in | 2361 /* We chain the components in reverse order, then put them in |
2392 forward order at the end. Each struct-declaration may | 2362 forward order at the end. Each struct-declaration may |
2393 declare multiple components (comma-separated), so we must use | 2363 declare multiple components (comma-separated), so we must use |
2394 chainon to join them, although when parsing each | 2364 chainon to join them, although when parsing each |
2395 struct-declaration we can use TREE_CHAIN directly. | 2365 struct-declaration we can use TREE_CHAIN directly. |
2396 | 2366 |
2397 The theory behind all this is that there will be more | 2367 The theory behind all this is that there will be more |
2398 semicolon separated fields than comma separated fields, and | 2368 semicolon separated fields than comma separated fields, and |
2399 so we'll be minimizing the number of node traversals required | 2369 so we'll be minimizing the number of node traversals required |
2400 by chainon. */ | 2370 by chainon. */ |
2401 tree contents = NULL_TREE; | 2371 tree contents = NULL_TREE; |
2402 c_parser_consume_token (parser); | 2372 c_parser_consume_token (parser); |
2403 /* Handle the Objective-C @defs construct, | 2373 /* Handle the Objective-C @defs construct, |
2404 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */ | 2374 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */ |
2405 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS)) | 2375 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS)) |
2406 { | 2376 { |
2407 tree name; | 2377 tree name; |
2408 gcc_assert (c_dialect_objc ()); | 2378 gcc_assert (c_dialect_objc ()); |
2409 c_parser_consume_token (parser); | 2379 c_parser_consume_token (parser); |
2410 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | 2380 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
2411 goto end_at_defs; | 2381 goto end_at_defs; |
2412 if (c_parser_next_token_is (parser, CPP_NAME) | 2382 if (c_parser_next_token_is (parser, CPP_NAME) |
2413 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME) | 2383 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME) |
2414 { | 2384 { |
2415 name = c_parser_peek_token (parser)->value; | 2385 name = c_parser_peek_token (parser)->value; |
2416 c_parser_consume_token (parser); | 2386 c_parser_consume_token (parser); |
2417 } | 2387 } |
2418 else | 2388 else |
2419 { | 2389 { |
2420 c_parser_error (parser, "expected class name"); | 2390 c_parser_error (parser, "expected class name"); |
2421 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | 2391 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
2422 goto end_at_defs; | 2392 goto end_at_defs; |
2423 } | 2393 } |
2424 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | 2394 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
2425 "expected %<)%>"); | 2395 "expected %<)%>"); |
2426 contents = nreverse (objc_get_class_ivars (name)); | 2396 contents = nreverse (objc_get_class_ivars (name)); |
2427 } | 2397 } |
2428 end_at_defs: | 2398 end_at_defs: |
2429 /* Parse the struct-declarations and semicolons. Problems with | 2399 /* Parse the struct-declarations and semicolons. Problems with |
2430 semicolons are diagnosed here; empty structures are diagnosed | 2400 semicolons are diagnosed here; empty structures are diagnosed |
2431 elsewhere. */ | 2401 elsewhere. */ |
2432 while (true) | 2402 while (true) |
2433 { | 2403 { |
2434 tree decls; | 2404 tree decls; |
2435 /* Parse any stray semicolon. */ | 2405 /* Parse any stray semicolon. */ |
2436 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | 2406 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
2479 recovered already. Go on with the next field. */ | 2449 recovered already. Go on with the next field. */ |
2480 } | 2450 } |
2481 } | 2451 } |
2482 postfix_attrs = c_parser_attributes (parser); | 2452 postfix_attrs = c_parser_attributes (parser); |
2483 ret.spec = finish_struct (struct_loc, type, nreverse (contents), | 2453 ret.spec = finish_struct (struct_loc, type, nreverse (contents), |
2484 chainon (attrs, postfix_attrs), struct_info); | 2454 chainon (attrs, postfix_attrs), struct_info); |
2485 ret.kind = ctsk_tagdef; | 2455 ret.kind = ctsk_tagdef; |
2486 ret.expr = NULL_TREE; | 2456 ret.expr = NULL_TREE; |
2487 ret.expr_const_operands = true; | 2457 ret.expr_const_operands = true; |
2488 return ret; | 2458 return ret; |
2489 } | 2459 } |
2576 "ISO C forbids member declarations with no members"); | 2546 "ISO C forbids member declarations with no members"); |
2577 shadow_tag_warned (specs, pedantic); | 2547 shadow_tag_warned (specs, pedantic); |
2578 ret = NULL_TREE; | 2548 ret = NULL_TREE; |
2579 } | 2549 } |
2580 else | 2550 else |
2581 { | 2551 { |
2582 /* Support for unnamed structs or unions as members of | 2552 /* Support for unnamed structs or unions as members of |
2583 structs or unions (which is [a] useful and [b] supports | 2553 structs or unions (which is [a] useful and [b] supports |
2584 MS P-SDK). */ | 2554 MS P-SDK). */ |
2585 tree attrs = NULL; | 2555 tree attrs = NULL; |
2586 | 2556 |
2587 ret = grokfield (c_parser_peek_token (parser)->location, | 2557 ret = grokfield (c_parser_peek_token (parser)->location, |
2588 build_id_declarator (NULL_TREE), specs, | 2558 build_id_declarator (NULL_TREE), specs, |
2589 NULL_TREE, &attrs); | 2559 NULL_TREE, &attrs); |
2590 if (ret) | 2560 if (ret) |
2591 decl_attributes (&ret, attrs, 0); | 2561 decl_attributes (&ret, attrs, 0); |
2592 } | 2562 } |
2593 return ret; | 2563 return ret; |
2594 } | 2564 } |
2595 | 2565 |
2596 /* Provide better error recovery. Note that a type name here is valid, | 2566 /* Provide better error recovery. Note that a type name here is valid, |
2597 and will be treated as a field name. */ | 2567 and will be treated as a field name. */ |
2614 { | 2584 { |
2615 /* Declaring one or more declarators or un-named bit-fields. */ | 2585 /* Declaring one or more declarators or un-named bit-fields. */ |
2616 struct c_declarator *declarator; | 2586 struct c_declarator *declarator; |
2617 bool dummy = false; | 2587 bool dummy = false; |
2618 if (c_parser_next_token_is (parser, CPP_COLON)) | 2588 if (c_parser_next_token_is (parser, CPP_COLON)) |
2619 declarator = build_id_declarator (NULL_TREE); | 2589 declarator = build_id_declarator (NULL_TREE); |
2620 else | 2590 else |
2621 declarator = c_parser_declarator (parser, | 2591 declarator = c_parser_declarator (parser, |
2622 specs->typespec_kind != ctsk_none, | 2592 specs->typespec_kind != ctsk_none, |
2623 C_DTR_NORMAL, &dummy); | 2593 C_DTR_NORMAL, &dummy); |
2624 if (declarator == NULL) | 2594 if (declarator == NULL) |
2625 { | 2595 { |
2626 c_parser_skip_to_end_of_block_or_statement (parser); | 2596 c_parser_skip_to_end_of_block_or_statement (parser); |
2627 break; | 2597 break; |
2628 } | 2598 } |
2629 if (c_parser_next_token_is (parser, CPP_COLON) | 2599 if (c_parser_next_token_is (parser, CPP_COLON) |
2630 || c_parser_next_token_is (parser, CPP_COMMA) | 2600 || c_parser_next_token_is (parser, CPP_COMMA) |
2631 || c_parser_next_token_is (parser, CPP_SEMICOLON) | 2601 || c_parser_next_token_is (parser, CPP_SEMICOLON) |
2632 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE) | 2602 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE) |
2633 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | 2603 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
2666 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>"); | 2636 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>"); |
2667 break; | 2637 break; |
2668 } | 2638 } |
2669 } | 2639 } |
2670 else | 2640 else |
2671 all_prefix_attrs = prefix_attrs; | 2641 { |
2672 if (c_parser_next_token_is (parser, CPP_COMMA)) | 2642 c_parser_error (parser, |
2673 c_parser_consume_token (parser); | 2643 "expected %<:%>, %<,%>, %<;%>, %<}%> or " |
2674 else if (c_parser_next_token_is (parser, CPP_SEMICOLON) | 2644 "%<__attribute__%>"); |
2675 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | 2645 break; |
2676 { | 2646 } |
2677 /* Semicolon consumed in caller. */ | |
2678 break; | |
2679 } | |
2680 else | |
2681 { | |
2682 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>"); | |
2683 break; | |
2684 } | |
2685 } | |
2686 else | |
2687 { | |
2688 c_parser_error (parser, | |
2689 "expected %<:%>, %<,%>, %<;%>, %<}%> or " | |
2690 "%<__attribute__%>"); | |
2691 break; | |
2692 } | |
2693 } | 2647 } |
2694 return decls; | 2648 return decls; |
2695 } | 2649 } |
2696 | 2650 |
2697 /* Parse a typeof specifier (a GNU extension). | 2651 /* Parse a typeof specifier (a GNU extension). |
2723 { | 2677 { |
2724 struct c_type_name *type = c_parser_type_name (parser); | 2678 struct c_type_name *type = c_parser_type_name (parser); |
2725 c_inhibit_evaluation_warnings--; | 2679 c_inhibit_evaluation_warnings--; |
2726 in_typeof--; | 2680 in_typeof--; |
2727 if (type != NULL) | 2681 if (type != NULL) |
2728 { | 2682 { |
2729 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands); | 2683 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands); |
2730 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE)); | 2684 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE)); |
2731 } | 2685 } |
2732 } | 2686 } |
2733 else | 2687 else |
2734 { | 2688 { |
2735 bool was_vm; | 2689 bool was_vm; |
2736 location_t here = c_parser_peek_token (parser)->location; | 2690 location_t here = c_parser_peek_token (parser)->location; |
2742 error_at (here, "%<typeof%> applied to a bit-field"); | 2696 error_at (here, "%<typeof%> applied to a bit-field"); |
2743 mark_exp_read (expr.value); | 2697 mark_exp_read (expr.value); |
2744 ret.spec = TREE_TYPE (expr.value); | 2698 ret.spec = TREE_TYPE (expr.value); |
2745 was_vm = variably_modified_type_p (ret.spec, NULL_TREE); | 2699 was_vm = variably_modified_type_p (ret.spec, NULL_TREE); |
2746 /* This is returned with the type so that when the type is | 2700 /* This is returned with the type so that when the type is |
2747 evaluated, this can be evaluated. */ | 2701 evaluated, this can be evaluated. */ |
2748 if (was_vm) | 2702 if (was_vm) |
2749 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands); | 2703 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands); |
2750 pop_maybe_used (was_vm); | 2704 pop_maybe_used (was_vm); |
2751 } | 2705 } |
2752 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | 2706 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
2753 return ret; | 2707 return ret; |
2754 } | 2708 } |
2809 | 2763 |
2810 GNU extensions: | 2764 GNU extensions: |
2811 | 2765 |
2812 direct-declarator: | 2766 direct-declarator: |
2813 direct-declarator ( parameter-forward-declarations | 2767 direct-declarator ( parameter-forward-declarations |
2814 parameter-type-list[opt] ) | 2768 parameter-type-list[opt] ) |
2815 | 2769 |
2816 direct-abstract-declarator: | 2770 direct-abstract-declarator: |
2817 direct-abstract-declarator[opt] ( parameter-forward-declarations | 2771 direct-abstract-declarator[opt] ( parameter-forward-declarations |
2818 parameter-type-list[opt] ) | 2772 parameter-type-list[opt] ) |
2819 | 2773 |
2820 parameter-forward-declarations: | 2774 parameter-forward-declarations: |
2821 parameter-list ; | 2775 parameter-list ; |
2822 parameter-forward-declarations parameter-list ; | 2776 parameter-forward-declarations parameter-list ; |
2823 | 2777 |
2830 This function also accepts an omitted abstract declarator as being | 2784 This function also accepts an omitted abstract declarator as being |
2831 an abstract declarator, although not part of the formal syntax. */ | 2785 an abstract declarator, although not part of the formal syntax. */ |
2832 | 2786 |
2833 static struct c_declarator * | 2787 static struct c_declarator * |
2834 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind, | 2788 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind, |
2835 bool *seen_id) | 2789 bool *seen_id) |
2836 { | 2790 { |
2837 /* Parse any initial pointer part. */ | 2791 /* Parse any initial pointer part. */ |
2838 if (c_parser_next_token_is (parser, CPP_MULT)) | 2792 if (c_parser_next_token_is (parser, CPP_MULT)) |
2839 { | 2793 { |
2840 struct c_declspecs *quals_attrs = build_null_declspecs (); | 2794 struct c_declspecs *quals_attrs = build_null_declspecs (); |
2841 struct c_declarator *inner; | 2795 struct c_declarator *inner; |
2842 c_parser_consume_token (parser); | 2796 c_parser_consume_token (parser); |
2843 c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id); | 2797 c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id); |
2844 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id); | 2798 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id); |
2845 if (inner == NULL) | 2799 if (inner == NULL) |
2846 return NULL; | 2800 return NULL; |
2847 else | 2801 else |
2848 return make_pointer_declarator (quals_attrs, inner); | 2802 return make_pointer_declarator (quals_attrs, inner); |
2849 } | 2803 } |
2850 /* Now we have a direct declarator, direct abstract declarator or | 2804 /* Now we have a direct declarator, direct abstract declarator or |
2851 nothing (which counts as a direct abstract declarator here). */ | 2805 nothing (which counts as a direct abstract declarator here). */ |
2852 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id); | 2806 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id); |
2853 } | 2807 } |
2855 /* Parse a direct declarator or direct abstract declarator; arguments | 2809 /* Parse a direct declarator or direct abstract declarator; arguments |
2856 as c_parser_declarator. */ | 2810 as c_parser_declarator. */ |
2857 | 2811 |
2858 static struct c_declarator * | 2812 static struct c_declarator * |
2859 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind, | 2813 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind, |
2860 bool *seen_id) | 2814 bool *seen_id) |
2861 { | 2815 { |
2862 /* The direct declarator must start with an identifier (possibly | 2816 /* The direct declarator must start with an identifier (possibly |
2863 omitted) or a parenthesized declarator (possibly abstract). In | 2817 omitted) or a parenthesized declarator (possibly abstract). In |
2864 an ordinary declarator, initial parentheses must start a | 2818 an ordinary declarator, initial parentheses must start a |
2865 parenthesized declarator. In an abstract declarator or parameter | 2819 parenthesized declarator. In an abstract declarator or parameter |
2899 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME | 2853 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME |
2900 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)) | 2854 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)) |
2901 || c_parser_peek_token (parser)->id_kind == C_ID_ID)) | 2855 || c_parser_peek_token (parser)->id_kind == C_ID_ID)) |
2902 { | 2856 { |
2903 struct c_declarator *inner | 2857 struct c_declarator *inner |
2904 = build_id_declarator (c_parser_peek_token (parser)->value); | 2858 = build_id_declarator (c_parser_peek_token (parser)->value); |
2905 *seen_id = true; | 2859 *seen_id = true; |
2906 inner->id_loc = c_parser_peek_token (parser)->location; | 2860 inner->id_loc = c_parser_peek_token (parser)->location; |
2907 c_parser_consume_token (parser); | 2861 c_parser_consume_token (parser); |
2908 return c_parser_direct_declarator_inner (parser, *seen_id, inner); | 2862 return c_parser_direct_declarator_inner (parser, *seen_id, inner); |
2909 } | 2863 } |
2923 tree attrs; | 2877 tree attrs; |
2924 struct c_declarator *inner; | 2878 struct c_declarator *inner; |
2925 c_parser_consume_token (parser); | 2879 c_parser_consume_token (parser); |
2926 attrs = c_parser_attributes (parser); | 2880 attrs = c_parser_attributes (parser); |
2927 if (kind != C_DTR_NORMAL | 2881 if (kind != C_DTR_NORMAL |
2928 && (c_parser_next_token_starts_declspecs (parser) | 2882 && (c_parser_next_token_starts_declspecs (parser) |
2929 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))) | 2883 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))) |
2930 { | 2884 { |
2931 struct c_arg_info *args | 2885 struct c_arg_info *args |
2932 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL, | 2886 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL, |
2933 attrs); | 2887 attrs); |
2934 if (args == NULL) | 2888 if (args == NULL) |
2935 return NULL; | 2889 return NULL; |
2936 else | 2890 else |
2937 { | 2891 { |
2938 inner | 2892 inner |
2939 = build_function_declarator (args, | 2893 = build_function_declarator (args, |
2940 build_id_declarator (NULL_TREE)); | 2894 build_id_declarator (NULL_TREE)); |
2941 return c_parser_direct_declarator_inner (parser, *seen_id, | 2895 return c_parser_direct_declarator_inner (parser, *seen_id, |
2942 inner); | 2896 inner); |
2943 } | 2897 } |
2944 } | 2898 } |
2945 /* A parenthesized declarator. */ | 2899 /* A parenthesized declarator. */ |
2946 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id); | 2900 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id); |
2947 if (inner != NULL && attrs != NULL) | 2901 if (inner != NULL && attrs != NULL) |
2948 inner = build_attrs_declarator (attrs, inner); | 2902 inner = build_attrs_declarator (attrs, inner); |
2949 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | 2903 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
2950 { | 2904 { |
2951 c_parser_consume_token (parser); | 2905 c_parser_consume_token (parser); |
2952 if (inner == NULL) | 2906 if (inner == NULL) |
2953 return NULL; | 2907 return NULL; |
2908 else | |
2909 return c_parser_direct_declarator_inner (parser, *seen_id, inner); | |
2910 } | |
2954 else | 2911 else |
2955 return c_parser_direct_declarator_inner (parser, *seen_id, inner); | 2912 { |
2956 } | 2913 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
2914 "expected %<)%>"); | |
2915 return NULL; | |
2916 } | |
2917 } | |
2918 else | |
2919 { | |
2920 if (kind == C_DTR_NORMAL) | |
2921 { | |
2922 c_parser_error (parser, "expected identifier or %<(%>"); | |
2923 return NULL; | |
2924 } | |
2957 else | 2925 else |
2958 { | 2926 return build_id_declarator (NULL_TREE); |
2959 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
2960 "expected %<)%>"); | |
2961 return NULL; | |
2962 } | |
2963 } | |
2964 else | |
2965 { | |
2966 if (kind == C_DTR_NORMAL) | |
2967 { | |
2968 c_parser_error (parser, "expected identifier or %<(%>"); | |
2969 return NULL; | |
2970 } | |
2971 else | |
2972 return build_id_declarator (NULL_TREE); | |
2973 } | 2927 } |
2974 } | 2928 } |
2975 | 2929 |
2976 /* Parse part of a direct declarator or direct abstract declarator, | 2930 /* Parse part of a direct declarator or direct abstract declarator, |
2977 given that some (in INNER) has already been parsed; ID_PRESENT is | 2931 given that some (in INNER) has already been parsed; ID_PRESENT is |
2978 true if an identifier is present, false for an abstract | 2932 true if an identifier is present, false for an abstract |
2979 declarator. */ | 2933 declarator. */ |
2980 | 2934 |
2981 static struct c_declarator * | 2935 static struct c_declarator * |
2982 c_parser_direct_declarator_inner (c_parser *parser, bool id_present, | 2936 c_parser_direct_declarator_inner (c_parser *parser, bool id_present, |
2983 struct c_declarator *inner) | 2937 struct c_declarator *inner) |
2984 { | 2938 { |
2985 /* Parse a sequence of array declarators and parameter lists. */ | 2939 /* Parse a sequence of array declarators and parameter lists. */ |
2986 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) | 2940 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) |
2987 { | 2941 { |
2988 location_t brace_loc = c_parser_peek_token (parser)->location; | 2942 location_t brace_loc = c_parser_peek_token (parser)->location; |
2993 tree dimen; | 2947 tree dimen; |
2994 c_parser_consume_token (parser); | 2948 c_parser_consume_token (parser); |
2995 c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id); | 2949 c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id); |
2996 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC); | 2950 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC); |
2997 if (static_seen) | 2951 if (static_seen) |
2998 c_parser_consume_token (parser); | 2952 c_parser_consume_token (parser); |
2999 if (static_seen && !quals_attrs->declspecs_seen_p) | 2953 if (static_seen && !quals_attrs->declspecs_seen_p) |
3000 c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id); | 2954 c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id); |
3001 if (!quals_attrs->declspecs_seen_p) | 2955 if (!quals_attrs->declspecs_seen_p) |
3002 quals_attrs = NULL; | 2956 quals_attrs = NULL; |
3003 /* If "static" is present, there must be an array dimension. | 2957 /* If "static" is present, there must be an array dimension. |
3004 Otherwise, there may be a dimension, "*", or no | 2958 Otherwise, there may be a dimension, "*", or no |
3005 dimension. */ | 2959 dimension. */ |
3006 if (static_seen) | 2960 if (static_seen) |
3007 { | 2961 { |
3008 star_seen = false; | 2962 star_seen = false; |
3009 dimen = c_parser_expr_no_commas (parser, NULL).value; | 2963 dimen = c_parser_expr_no_commas (parser, NULL).value; |
3010 } | 2964 } |
3011 else | 2965 else |
3012 { | 2966 { |
2967 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) | |
2968 { | |
2969 dimen = NULL_TREE; | |
2970 star_seen = false; | |
2971 } | |
2972 else if (c_parser_next_token_is (parser, CPP_MULT)) | |
2973 { | |
2974 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE) | |
2975 { | |
2976 dimen = NULL_TREE; | |
2977 star_seen = true; | |
2978 c_parser_consume_token (parser); | |
2979 } | |
2980 else | |
2981 { | |
2982 star_seen = false; | |
2983 dimen = c_parser_expr_no_commas (parser, NULL).value; | |
2984 } | |
2985 } | |
2986 else | |
2987 { | |
2988 star_seen = false; | |
2989 dimen = c_parser_expr_no_commas (parser, NULL).value; | |
2990 } | |
2991 } | |
3013 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) | 2992 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) |
3014 { | 2993 c_parser_consume_token (parser); |
3015 dimen = NULL_TREE; | |
3016 star_seen = false; | |
3017 } | |
3018 else if (c_parser_next_token_is (parser, CPP_MULT)) | |
3019 { | |
3020 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE) | |
3021 { | |
3022 dimen = NULL_TREE; | |
3023 star_seen = true; | |
3024 c_parser_consume_token (parser); | |
3025 } | |
3026 else | |
3027 { | |
3028 star_seen = false; | |
3029 dimen = c_parser_expr_no_commas (parser, NULL).value; | |
3030 } | |
3031 } | |
3032 else | 2994 else |
3033 { | 2995 { |
3034 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | 2996 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, |
3035 "expected %<]%>"); | 2997 "expected %<]%>"); |
3036 return NULL; | 2998 return NULL; |
3037 } | 2999 } |
3038 if (dimen) | 3000 if (dimen) |
3039 mark_exp_read (dimen); | 3001 mark_exp_read (dimen); |
3040 declarator = build_array_declarator (brace_loc, dimen, quals_attrs, | 3002 declarator = build_array_declarator (brace_loc, dimen, quals_attrs, |
3041 static_seen, star_seen); | 3003 static_seen, star_seen); |
3042 if (declarator == NULL) | 3004 if (declarator == NULL) |
3043 return NULL; | 3005 return NULL; |
3044 inner = set_array_declarator_inner (declarator, inner); | 3006 inner = set_array_declarator_inner (declarator, inner); |
3045 return c_parser_direct_declarator_inner (parser, id_present, inner); | 3007 return c_parser_direct_declarator_inner (parser, id_present, inner); |
3046 } | 3008 } |
3047 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | 3009 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
3048 { | 3010 { |
3050 struct c_arg_info *args; | 3012 struct c_arg_info *args; |
3051 c_parser_consume_token (parser); | 3013 c_parser_consume_token (parser); |
3052 attrs = c_parser_attributes (parser); | 3014 attrs = c_parser_attributes (parser); |
3053 args = c_parser_parms_declarator (parser, id_present, attrs); | 3015 args = c_parser_parms_declarator (parser, id_present, attrs); |
3054 if (args == NULL) | 3016 if (args == NULL) |
3055 return NULL; | 3017 return NULL; |
3056 else | 3018 else |
3057 { | 3019 { |
3058 inner = build_function_declarator (args, inner); | 3020 inner = build_function_declarator (args, inner); |
3059 return c_parser_direct_declarator_inner (parser, id_present, inner); | 3021 return c_parser_direct_declarator_inner (parser, id_present, inner); |
3060 } | 3022 } |
3061 } | 3023 } |
3062 return inner; | 3024 return inner; |
3063 } | 3025 } |
3064 | 3026 |
3065 /* Parse a parameter list or identifier list, including the closing | 3027 /* Parse a parameter list or identifier list, including the closing |
3085 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN | 3047 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN |
3086 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE) | 3048 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE) |
3087 { | 3049 { |
3088 tree list = NULL_TREE, *nextp = &list; | 3050 tree list = NULL_TREE, *nextp = &list; |
3089 while (c_parser_next_token_is (parser, CPP_NAME) | 3051 while (c_parser_next_token_is (parser, CPP_NAME) |
3090 && c_parser_peek_token (parser)->id_kind == C_ID_ID) | 3052 && c_parser_peek_token (parser)->id_kind == C_ID_ID) |
3091 { | 3053 { |
3092 *nextp = build_tree_list (NULL_TREE, | 3054 *nextp = build_tree_list (NULL_TREE, |
3093 c_parser_peek_token (parser)->value); | 3055 c_parser_peek_token (parser)->value); |
3094 nextp = & TREE_CHAIN (*nextp); | 3056 nextp = & TREE_CHAIN (*nextp); |
3095 c_parser_consume_token (parser); | 3057 c_parser_consume_token (parser); |
3096 if (c_parser_next_token_is_not (parser, CPP_COMMA)) | 3058 if (c_parser_next_token_is_not (parser, CPP_COMMA)) |
3097 break; | 3059 break; |
3098 c_parser_consume_token (parser); | 3060 c_parser_consume_token (parser); |
3061 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3062 { | |
3063 c_parser_error (parser, "expected identifier"); | |
3064 break; | |
3065 } | |
3066 } | |
3099 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | 3067 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
3100 { | 3068 { |
3101 struct c_arg_info *ret = build_arg_info (); | 3069 struct c_arg_info *ret = build_arg_info (); |
3102 ret->types = list; | 3070 ret->types = list; |
3103 c_parser_consume_token (parser); | 3071 c_parser_consume_token (parser); |
3104 pop_scope (); | 3072 pop_scope (); |
3105 return ret; | 3073 return ret; |
3106 } | 3074 } |
3107 else | 3075 else |
3108 { | 3076 { |
3109 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | 3077 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
3110 "expected %<)%>"); | 3078 "expected %<)%>"); |
3111 pop_scope (); | 3079 pop_scope (); |
3112 return NULL; | 3080 return NULL; |
3113 } | 3081 } |
3114 } | 3082 } |
3115 else | 3083 else |
3116 { | 3084 { |
3117 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs); | 3085 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs); |
3118 pop_scope (); | 3086 pop_scope (); |
3144 { | 3112 { |
3145 struct c_arg_info *ret = build_arg_info (); | 3113 struct c_arg_info *ret = build_arg_info (); |
3146 /* Suppress -Wold-style-definition for this case. */ | 3114 /* Suppress -Wold-style-definition for this case. */ |
3147 ret->types = error_mark_node; | 3115 ret->types = error_mark_node; |
3148 error_at (c_parser_peek_token (parser)->location, | 3116 error_at (c_parser_peek_token (parser)->location, |
3149 "ISO C requires a named argument before %<...%>"); | 3117 "ISO C requires a named argument before %<...%>"); |
3150 c_parser_consume_token (parser); | 3118 c_parser_consume_token (parser); |
3151 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | 3119 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
3152 { | 3120 { |
3153 c_parser_consume_token (parser); | 3121 c_parser_consume_token (parser); |
3154 return ret; | 3122 return ret; |
3155 } | 3123 } |
3156 else | 3124 else |
3157 { | 3125 { |
3158 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | 3126 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
3159 "expected %<)%>"); | 3127 "expected %<)%>"); |
3160 return NULL; | 3128 return NULL; |
3161 } | 3129 } |
3162 } | 3130 } |
3163 /* Nonempty list of parameters, either terminated with semicolon | 3131 /* Nonempty list of parameters, either terminated with semicolon |
3164 (forward declarations; recurse) or with close parenthesis (normal | 3132 (forward declarations; recurse) or with close parenthesis (normal |
3165 function) or with ", ... )" (variadic function). */ | 3133 function) or with ", ... )" (variadic function). */ |
3166 while (true) | 3134 while (true) |
3171 if (parm == NULL) | 3139 if (parm == NULL) |
3172 bad_parm = true; | 3140 bad_parm = true; |
3173 else | 3141 else |
3174 push_parm_decl (parm); | 3142 push_parm_decl (parm); |
3175 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | 3143 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
3176 { | 3144 { |
3177 tree new_attrs; | 3145 tree new_attrs; |
3178 c_parser_consume_token (parser); | 3146 c_parser_consume_token (parser); |
3179 mark_forward_parm_decls (); | 3147 mark_forward_parm_decls (); |
3180 new_attrs = c_parser_attributes (parser); | 3148 new_attrs = c_parser_attributes (parser); |
3181 return c_parser_parms_list_declarator (parser, new_attrs); | 3149 return c_parser_parms_list_declarator (parser, new_attrs); |
3182 } | 3150 } |
3183 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | 3151 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
3184 { | 3152 { |
3185 c_parser_consume_token (parser); | 3153 c_parser_consume_token (parser); |
3186 if (bad_parm) | 3154 if (bad_parm) |
3187 { | 3155 { |
3190 } | 3158 } |
3191 else | 3159 else |
3192 return get_parm_info (false); | 3160 return get_parm_info (false); |
3193 } | 3161 } |
3194 if (!c_parser_require (parser, CPP_COMMA, | 3162 if (!c_parser_require (parser, CPP_COMMA, |
3195 "expected %<;%>, %<,%> or %<)%>")) | 3163 "expected %<;%>, %<,%> or %<)%>")) |
3196 { | 3164 { |
3197 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | 3165 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
3198 get_pending_sizes (); | 3166 get_pending_sizes (); |
3199 return NULL; | 3167 return NULL; |
3200 } | 3168 } |
3201 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) | 3169 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) |
3202 { | 3170 { |
3203 c_parser_consume_token (parser); | 3171 c_parser_consume_token (parser); |
3204 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | 3172 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
3205 { | 3173 { |
3273 return NULL; | 3241 return NULL; |
3274 } | 3242 } |
3275 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | 3243 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
3276 postfix_attrs = c_parser_attributes (parser); | 3244 postfix_attrs = c_parser_attributes (parser); |
3277 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs), | 3245 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs), |
3278 declarator); | 3246 declarator); |
3279 } | 3247 } |
3280 | 3248 |
3281 /* Parse a string literal in an asm expression. It should not be | 3249 /* Parse a string literal in an asm expression. It should not be |
3282 translated, and wide string literals are an error although | 3250 translated, and wide string literals are an error although |
3283 permitted by the syntax. This is a GNU extension. | 3251 permitted by the syntax. This is a GNU extension. |
3299 c_parser_consume_token (parser); | 3267 c_parser_consume_token (parser); |
3300 } | 3268 } |
3301 else if (c_parser_next_token_is (parser, CPP_WSTRING)) | 3269 else if (c_parser_next_token_is (parser, CPP_WSTRING)) |
3302 { | 3270 { |
3303 error_at (c_parser_peek_token (parser)->location, | 3271 error_at (c_parser_peek_token (parser)->location, |
3304 "wide string literal in %<asm%>"); | 3272 "wide string literal in %<asm%>"); |
3305 str = build_string (1, ""); | 3273 str = build_string (1, ""); |
3306 c_parser_consume_token (parser); | 3274 c_parser_consume_token (parser); |
3307 } | 3275 } |
3308 else | 3276 else |
3309 { | 3277 { |
3377 { | 3345 { |
3378 tree attrs = NULL_TREE; | 3346 tree attrs = NULL_TREE; |
3379 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | 3347 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
3380 { | 3348 { |
3381 /* ??? Follow the C++ parser rather than using the | 3349 /* ??? Follow the C++ parser rather than using the |
3382 lex_untranslated_string kludge. */ | 3350 lex_untranslated_string kludge. */ |
3383 parser->lex_untranslated_string = true; | 3351 parser->lex_untranslated_string = true; |
3384 c_parser_consume_token (parser); | 3352 c_parser_consume_token (parser); |
3385 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | 3353 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
3386 { | 3354 { |
3387 parser->lex_untranslated_string = false; | 3355 parser->lex_untranslated_string = false; |
3388 return attrs; | 3356 return attrs; |
3389 } | 3357 } |
3390 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | 3358 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
3391 { | 3359 { |
3392 parser->lex_untranslated_string = false; | 3360 parser->lex_untranslated_string = false; |
3393 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | 3361 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
3394 return attrs; | 3362 return attrs; |
3395 } | 3363 } |
3396 /* Parse the attribute list. */ | 3364 /* Parse the attribute list. */ |
3397 while (c_parser_next_token_is (parser, CPP_COMMA) | 3365 while (c_parser_next_token_is (parser, CPP_COMMA) |
3398 || c_parser_next_token_is (parser, CPP_NAME) | 3366 || c_parser_next_token_is (parser, CPP_NAME) |
3399 || c_parser_next_token_is (parser, CPP_KEYWORD)) | 3367 || c_parser_next_token_is (parser, CPP_KEYWORD)) |
3400 { | 3368 { |
3512 return attrs; | 3480 return attrs; |
3513 } | 3481 } |
3514 attrs = chainon (attrs, attr); | 3482 attrs = chainon (attrs, attr); |
3515 } | 3483 } |
3516 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | 3484 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
3517 c_parser_consume_token (parser); | 3485 c_parser_consume_token (parser); |
3518 else | 3486 else |
3519 { | 3487 { |
3520 parser->lex_untranslated_string = false; | 3488 parser->lex_untranslated_string = false; |
3521 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | 3489 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
3522 "expected %<)%>"); | 3490 "expected %<)%>"); |
3523 return attrs; | 3491 return attrs; |
3524 } | 3492 } |
3525 attrs = chainon (attrs, attr); | |
3526 } | |
3527 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | 3493 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
3528 c_parser_consume_token (parser); | 3494 c_parser_consume_token (parser); |
3529 else | 3495 else |
3530 { | 3496 { |
3531 parser->lex_untranslated_string = false; | 3497 parser->lex_untranslated_string = false; |
3532 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | 3498 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
3533 "expected %<)%>"); | 3499 "expected %<)%>"); |
3534 return attrs; | 3500 return attrs; |
3535 } | 3501 } |
3536 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3537 c_parser_consume_token (parser); | |
3538 else | |
3539 { | |
3540 parser->lex_untranslated_string = false; | |
3541 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
3542 "expected %<)%>"); | |
3543 return attrs; | |
3544 } | |
3545 parser->lex_untranslated_string = false; | 3502 parser->lex_untranslated_string = false; |
3546 } | 3503 } |
3547 return attrs; | 3504 return attrs; |
3548 } | 3505 } |
3549 | 3506 |
3666 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces"); | 3623 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces"); |
3667 } | 3624 } |
3668 else | 3625 else |
3669 { | 3626 { |
3670 /* Parse a non-empty initializer list, possibly with a trailing | 3627 /* Parse a non-empty initializer list, possibly with a trailing |
3671 comma. */ | 3628 comma. */ |
3672 while (true) | 3629 while (true) |
3673 { | 3630 { |
3674 c_parser_initelt (parser, &braced_init_obstack); | 3631 c_parser_initelt (parser, &braced_init_obstack); |
3675 if (parser->error) | 3632 if (parser->error) |
3676 break; | 3633 break; |
3712 /* Old-style structure member designator. */ | 3669 /* Old-style structure member designator. */ |
3713 set_init_label (c_parser_peek_token (parser)->value, | 3670 set_init_label (c_parser_peek_token (parser)->value, |
3714 braced_init_obstack); | 3671 braced_init_obstack); |
3715 /* Use the colon as the error location. */ | 3672 /* Use the colon as the error location. */ |
3716 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic, | 3673 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic, |
3717 "obsolete use of designated initializer with %<:%>"); | 3674 "obsolete use of designated initializer with %<:%>"); |
3718 c_parser_consume_token (parser); | 3675 c_parser_consume_token (parser); |
3719 c_parser_consume_token (parser); | 3676 c_parser_consume_token (parser); |
3720 } | 3677 } |
3721 else | 3678 else |
3722 { | 3679 { |
3723 /* des_seen is 0 if there have been no designators, 1 if there | 3680 /* des_seen is 0 if there have been no designators, 1 if there |
3724 has been a single array designator and 2 otherwise. */ | 3681 has been a single array designator and 2 otherwise. */ |
3725 int des_seen = 0; | 3682 int des_seen = 0; |
3726 /* Location of a designator. */ | 3683 /* Location of a designator. */ |
3727 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */ | 3684 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
3728 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE) | 3685 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE) |
3729 || c_parser_next_token_is (parser, CPP_DOT)) | 3686 || c_parser_next_token_is (parser, CPP_DOT)) |
3978 location_t brace_loc; | 3935 location_t brace_loc; |
3979 brace_loc = c_parser_peek_token (parser)->location; | 3936 brace_loc = c_parser_peek_token (parser)->location; |
3980 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) | 3937 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) |
3981 { | 3938 { |
3982 /* Ensure a scope is entered and left anyway to avoid confusion | 3939 /* Ensure a scope is entered and left anyway to avoid confusion |
3983 if we have just prepared to enter a function body. */ | 3940 if we have just prepared to enter a function body. */ |
3984 stmt = c_begin_compound_stmt (true); | 3941 stmt = c_begin_compound_stmt (true); |
3985 c_end_compound_stmt (brace_loc, stmt, true); | 3942 c_end_compound_stmt (brace_loc, stmt, true); |
3986 return error_mark_node; | 3943 return error_mark_node; |
3987 } | 3944 } |
3988 stmt = c_begin_compound_stmt (true); | 3945 stmt = c_begin_compound_stmt (true); |
4008 } | 3965 } |
4009 mark_valid_location_for_stdc_pragma (true); | 3966 mark_valid_location_for_stdc_pragma (true); |
4010 if (c_parser_next_token_is_keyword (parser, RID_LABEL)) | 3967 if (c_parser_next_token_is_keyword (parser, RID_LABEL)) |
4011 { | 3968 { |
4012 /* Read zero or more forward-declarations for labels that nested | 3969 /* Read zero or more forward-declarations for labels that nested |
4013 functions can jump to. */ | 3970 functions can jump to. */ |
4014 mark_valid_location_for_stdc_pragma (false); | 3971 mark_valid_location_for_stdc_pragma (false); |
4015 while (c_parser_next_token_is_keyword (parser, RID_LABEL)) | 3972 while (c_parser_next_token_is_keyword (parser, RID_LABEL)) |
4016 { | 3973 { |
4017 label_loc = c_parser_peek_token (parser)->location; | 3974 label_loc = c_parser_peek_token (parser)->location; |
4018 c_parser_consume_token (parser); | 3975 c_parser_consume_token (parser); |
4019 /* Any identifiers, including those declared as type names, | 3976 /* Any identifiers, including those declared as type names, |
4020 are OK here. */ | 3977 are OK here. */ |
4021 while (true) | 3978 while (true) |
4022 { | 3979 { |
4023 tree label; | 3980 tree label; |
4024 if (c_parser_next_token_is_not (parser, CPP_NAME)) | 3981 if (c_parser_next_token_is_not (parser, CPP_NAME)) |
4025 { | 3982 { |
4026 c_parser_error (parser, "expected identifier"); | 3983 c_parser_error (parser, "expected identifier"); |
4027 break; | 3984 break; |
4028 } | 3985 } |
4029 label | 3986 label |
4030 = declare_label (c_parser_peek_token (parser)->value); | 3987 = declare_label (c_parser_peek_token (parser)->value); |
4031 C_DECLARED_LABEL_FLAG (label) = 1; | 3988 C_DECLARED_LABEL_FLAG (label) = 1; |
4032 add_stmt (build_stmt (label_loc, DECL_EXPR, label)); | 3989 add_stmt (build_stmt (label_loc, DECL_EXPR, label)); |
4033 c_parser_consume_token (parser); | 3990 c_parser_consume_token (parser); |
4034 if (c_parser_next_token_is (parser, CPP_COMMA)) | 3991 if (c_parser_next_token_is (parser, CPP_COMMA)) |
4035 c_parser_consume_token (parser); | 3992 c_parser_consume_token (parser); |
4036 else | 3993 else |
4037 break; | 3994 break; |
4038 } | 3995 } |
4039 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | 3996 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
4040 } | 3997 } |
4041 pedwarn (label_loc, OPT_pedantic, "ISO C forbids label declarations"); | 3998 pedwarn (label_loc, OPT_pedantic, "ISO C forbids label declarations"); |
4042 } | 3999 } |
4043 /* We must now have at least one statement, label or declaration. */ | 4000 /* We must now have at least one statement, label or declaration. */ |
4044 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | 4001 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
4045 { | 4002 { |
4050 } | 4007 } |
4051 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE)) | 4008 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE)) |
4052 { | 4009 { |
4053 location_t loc = c_parser_peek_token (parser)->location; | 4010 location_t loc = c_parser_peek_token (parser)->location; |
4054 if (c_parser_next_token_is_keyword (parser, RID_CASE) | 4011 if (c_parser_next_token_is_keyword (parser, RID_CASE) |
4055 || c_parser_next_token_is_keyword (parser, RID_DEFAULT) | 4012 || c_parser_next_token_is_keyword (parser, RID_DEFAULT) |
4056 || (c_parser_next_token_is (parser, CPP_NAME) | 4013 || (c_parser_next_token_is (parser, CPP_NAME) |
4057 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) | 4014 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) |
4058 { | 4015 { |
4059 if (c_parser_next_token_is_keyword (parser, RID_CASE)) | 4016 if (c_parser_next_token_is_keyword (parser, RID_CASE)) |
4060 label_loc = c_parser_peek_2nd_token (parser)->location; | 4017 label_loc = c_parser_peek_2nd_token (parser)->location; |
4061 else | 4018 else |
4062 label_loc = c_parser_peek_token (parser)->location; | 4019 label_loc = c_parser_peek_token (parser)->location; |
4063 last_label = true; | 4020 last_label = true; |
4064 last_stmt = false; | 4021 last_stmt = false; |
4065 mark_valid_location_for_stdc_pragma (false); | 4022 mark_valid_location_for_stdc_pragma (false); |
4066 c_parser_label (parser); | 4023 c_parser_label (parser); |
4067 } | 4024 } |
4068 else if (!last_label | 4025 else if (!last_label |
4069 && c_parser_next_tokens_start_declaration (parser)) | 4026 && c_parser_next_tokens_start_declaration (parser)) |
4070 { | 4027 { |
4071 last_label = false; | 4028 last_label = false; |
4072 mark_valid_location_for_stdc_pragma (false); | 4029 mark_valid_location_for_stdc_pragma (false); |
4111 } | 4068 } |
4112 else | 4069 else |
4113 goto statement; | 4070 goto statement; |
4114 } | 4071 } |
4115 else if (c_parser_next_token_is (parser, CPP_PRAGMA)) | 4072 else if (c_parser_next_token_is (parser, CPP_PRAGMA)) |
4116 { | 4073 { |
4117 /* External pragmas, and some omp pragmas, are not associated | 4074 /* External pragmas, and some omp pragmas, are not associated |
4118 with regular c code, and so are not to be considered statements | 4075 with regular c code, and so are not to be considered statements |
4119 syntactically. This ensures that the user doesn't put them | 4076 syntactically. This ensures that the user doesn't put them |
4120 places that would turn into syntax errors if the directive | 4077 places that would turn into syntax errors if the directive |
4121 were ignored. */ | 4078 were ignored. */ |
4122 if (c_parser_pragma (parser, pragma_compound)) | 4079 if (c_parser_pragma (parser, pragma_compound)) |
4123 last_label = false, last_stmt = true; | 4080 last_label = false, last_stmt = true; |
4124 } | 4081 } |
4125 else if (c_parser_next_token_is (parser, CPP_EOF)) | 4082 else if (c_parser_next_token_is (parser, CPP_EOF)) |
4126 { | 4083 { |
4127 mark_valid_location_for_stdc_pragma (save_valid_for_pragma); | 4084 mark_valid_location_for_stdc_pragma (save_valid_for_pragma); |
4128 c_parser_error (parser, "expected declaration or statement"); | 4085 c_parser_error (parser, "expected declaration or statement"); |
4129 return; | 4086 return; |
4130 } | 4087 } |
4131 else if (c_parser_next_token_is_keyword (parser, RID_ELSE)) | 4088 else if (c_parser_next_token_is_keyword (parser, RID_ELSE)) |
4132 { | 4089 { |
4133 if (parser->in_if_block) | 4090 if (parser->in_if_block) |
4134 { | 4091 { |
4135 mark_valid_location_for_stdc_pragma (save_valid_for_pragma); | 4092 mark_valid_location_for_stdc_pragma (save_valid_for_pragma); |
4136 error_at (loc, """expected %<}%> before %<else%>"); | 4093 error_at (loc, """expected %<}%> before %<else%>"); |
4137 return; | 4094 return; |
4138 } | 4095 } |
4139 else | 4096 else |
4140 { | 4097 { |
4142 c_parser_consume_token (parser); | 4099 c_parser_consume_token (parser); |
4143 continue; | 4100 continue; |
4144 } | 4101 } |
4145 } | 4102 } |
4146 else | 4103 else |
4147 { | 4104 { |
4148 statement: | 4105 statement: |
4149 last_label = false; | 4106 last_label = false; |
4150 last_stmt = true; | 4107 last_stmt = true; |
4151 mark_valid_location_for_stdc_pragma (false); | 4108 mark_valid_location_for_stdc_pragma (false); |
4152 c_parser_statement_after_labels (parser); | 4109 c_parser_statement_after_labels (parser); |
4153 } | 4110 } |
4154 | 4111 |
4155 parser->error = false; | 4112 parser->error = false; |
4156 } | 4113 } |
4157 if (last_label) | 4114 if (last_label) |
4158 error_at (label_loc, "label at end of compound statement"); | 4115 error_at (label_loc, "label at end of compound statement"); |
4186 { | 4143 { |
4187 tree exp1, exp2; | 4144 tree exp1, exp2; |
4188 c_parser_consume_token (parser); | 4145 c_parser_consume_token (parser); |
4189 exp1 = c_parser_expr_no_commas (parser, NULL).value; | 4146 exp1 = c_parser_expr_no_commas (parser, NULL).value; |
4190 if (c_parser_next_token_is (parser, CPP_COLON)) | 4147 if (c_parser_next_token_is (parser, CPP_COLON)) |
4191 { | 4148 { |
4192 c_parser_consume_token (parser); | 4149 c_parser_consume_token (parser); |
4193 label = do_case (loc1, exp1, NULL_TREE); | 4150 label = do_case (loc1, exp1, NULL_TREE); |
4194 } | 4151 } |
4195 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) | 4152 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) |
4196 { | 4153 { |
4197 c_parser_consume_token (parser); | 4154 c_parser_consume_token (parser); |
4198 exp2 = c_parser_expr_no_commas (parser, NULL).value; | 4155 exp2 = c_parser_expr_no_commas (parser, NULL).value; |
4199 if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) | 4156 if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
4200 label = do_case (loc1, exp1, exp2); | 4157 label = do_case (loc1, exp1, exp2); |
4201 } | 4158 } |
4202 else | 4159 else |
4203 c_parser_error (parser, "expected %<:%> or %<...%>"); | 4160 c_parser_error (parser, "expected %<:%> or %<...%>"); |
4204 } | 4161 } |
4205 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT)) | 4162 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT)) |
4206 { | 4163 { |
4207 c_parser_consume_token (parser); | 4164 c_parser_consume_token (parser); |
4208 if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) | 4165 if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
4209 label = do_case (loc1, NULL_TREE, NULL_TREE); | 4166 label = do_case (loc1, NULL_TREE, NULL_TREE); |
4210 } | 4167 } |
4211 else | 4168 else |
4212 { | 4169 { |
4213 tree name = c_parser_peek_token (parser)->value; | 4170 tree name = c_parser_peek_token (parser)->value; |
4214 tree tlab; | 4171 tree tlab; |
4219 gcc_assert (c_parser_next_token_is (parser, CPP_COLON)); | 4176 gcc_assert (c_parser_next_token_is (parser, CPP_COLON)); |
4220 c_parser_consume_token (parser); | 4177 c_parser_consume_token (parser); |
4221 attrs = c_parser_attributes (parser); | 4178 attrs = c_parser_attributes (parser); |
4222 tlab = define_label (loc2, name); | 4179 tlab = define_label (loc2, name); |
4223 if (tlab) | 4180 if (tlab) |
4224 { | 4181 { |
4225 decl_attributes (&tlab, attrs, 0); | 4182 decl_attributes (&tlab, attrs, 0); |
4226 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab)); | 4183 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab)); |
4227 } | 4184 } |
4228 } | 4185 } |
4229 if (label) | 4186 if (label) |
4230 { | 4187 { |
4231 if (c_parser_next_tokens_start_declaration (parser)) | 4188 if (c_parser_next_tokens_start_declaration (parser)) |
4232 { | 4189 { |
4340 | 4297 |
4341 static void | 4298 static void |
4342 c_parser_statement (c_parser *parser) | 4299 c_parser_statement (c_parser *parser) |
4343 { | 4300 { |
4344 while (c_parser_next_token_is_keyword (parser, RID_CASE) | 4301 while (c_parser_next_token_is_keyword (parser, RID_CASE) |
4345 || c_parser_next_token_is_keyword (parser, RID_DEFAULT) | 4302 || c_parser_next_token_is_keyword (parser, RID_DEFAULT) |
4346 || (c_parser_next_token_is (parser, CPP_NAME) | 4303 || (c_parser_next_token_is (parser, CPP_NAME) |
4347 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) | 4304 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) |
4348 c_parser_label (parser); | 4305 c_parser_label (parser); |
4349 c_parser_statement_after_labels (parser); | 4306 c_parser_statement_after_labels (parser); |
4350 } | 4307 } |
4351 | 4308 |
4352 #if 0 | |
4353 static tree | |
4354 c_parser_cbc_make_env(c_parser *parser) | |
4355 { | |
4356 struct c_expr env; | |
4357 tree field, fields=NULL_TREE; | |
4358 tree env_struct, env_struct_type; | |
4359 tree ebp, argsp; | |
4360 tree tmp; | |
4361 | |
4362 c_parser_consume_token (parser); | |
4363 env = c_parser_expr_no_commas (parser, NULL); | |
4364 env = default_function_array_conversion (env); | |
4365 | |
4366 /* build type_node of environment structure */ | |
4367 env_struct_type = start_struct (RECORD_TYPE, NULL_TREE); | |
4368 field = build_decl (FIELD_DECL, get_identifier("sp"), ptr_type_node); | |
4369 fields = chainon (field, fields); | |
4370 field = build_decl (FIELD_DECL, get_identifier("argsp"), ptr_type_node); | |
4371 fields = chainon (field, fields); | |
4372 //field = build_decl (FIELD_DECL, get_identifier("retval"), intSI_type_node); | |
4373 //fields = chainon (field, fields); | |
4374 fields = nreverse(fields); | |
4375 finish_struct (env_struct_type, fields, NULL_TREE); | |
4376 | |
4377 env_struct = build_c_cast (build_pointer_type(env_struct_type), env.value); | |
4378 //build_component_ref (cbc_env, get_identifier("argsp")); | |
4379 ebp = build_component_ref (build_indirect_ref (loc,env_struct, "CbCenv->sp"), get_identifier("sp")); | |
4380 argsp = build_component_ref (build_indirect_ref (loc, env_struct, "CbCenv->sp"), get_identifier("argsp")); | |
4381 //ebp = chainon (ebp, argsp); | |
4382 tmp = build_tree_list (ebp, argsp); | |
4383 | |
4384 return tmp; | |
4385 } | |
4386 #endif | |
4387 | |
4388 static tree | |
4389 cbc_replace_arguments (location_t loc, tree call) | |
4390 { | |
4391 tree args; | |
4392 tree fn; | |
4393 tree tmp_decl; | |
4394 int i=0; | |
4395 | |
4396 fn = CALL_EXPR_FN (call); | |
4397 if ( TREE_CODE (fn)==PARM_DECL || !TREE_CONSTANT (fn) ) | |
4398 { | |
4399 tmp_decl = build_decl (loc, VAR_DECL, NULL_TREE, TREE_TYPE(fn)); | |
4400 pushdecl (tmp_decl); | |
4401 | |
4402 add_stmt (build_modify_expr (loc, tmp_decl, NULL_TREE, NOP_EXPR, loc, fn, NULL_TREE)); | |
4403 CALL_EXPR_FN (call) = tmp_decl; | |
4404 } | |
4405 | |
4406 args = CALL_EXPR_ARGS (call); | |
4407 for ( ;args; args = TREE_CHAIN (args), i++) | |
4408 { | |
4409 tree arg = TREE_VALUE (args); | |
4410 | |
4411 //if ( !CONSTANT_CLASS_P (arg) && !VAR_OR_FUNCTION_DECL_P (arg) ) | |
4412 if ( TREE_CODE (arg)==PARM_DECL || !TREE_CONSTANT (arg) ) | |
4413 { | |
4414 tmp_decl = build_decl (loc, VAR_DECL, NULL_TREE, TREE_TYPE(arg)); | |
4415 pushdecl (tmp_decl); | |
4416 | |
4417 add_stmt (build_modify_expr (loc, tmp_decl, NULL_TREE, NOP_EXPR, loc, arg, NULL_TREE)); | |
4418 CALL_EXPR_ARG (call, i) = tmp_decl; | |
4419 } | |
4420 } | |
4421 | |
4422 return call; | |
4423 } | |
4424 | |
4425 /* Parse a statement, other than a labeled statement. */ | 4309 /* Parse a statement, other than a labeled statement. */ |
4426 | 4310 |
4427 static void | 4311 static void |
4428 c_parser_statement_after_labels (c_parser *parser) | 4312 c_parser_statement_after_labels (c_parser *parser) |
4429 { | 4313 { |
4430 struct c_expr expr; | |
4431 location_t loc = c_parser_peek_token (parser)->location; | 4314 location_t loc = c_parser_peek_token (parser)->location; |
4432 tree stmt = NULL_TREE; | 4315 tree stmt = NULL_TREE; |
4433 bool in_if_block = parser->in_if_block; | 4316 bool in_if_block = parser->in_if_block; |
4434 parser->in_if_block = false; | 4317 parser->in_if_block = false; |
4435 switch (c_parser_peek_token (parser)->type) | 4318 switch (c_parser_peek_token (parser)->type) |
4455 case RID_FOR: | 4338 case RID_FOR: |
4456 c_parser_for_statement (parser); | 4339 c_parser_for_statement (parser); |
4457 break; | 4340 break; |
4458 case RID_GOTO: | 4341 case RID_GOTO: |
4459 c_parser_consume_token (parser); | 4342 c_parser_consume_token (parser); |
4460 #ifndef noCbC | |
4461 if ( c_parser_next_token_is (parser, CPP_NAME) | |
4462 && c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON ) | |
4463 { | |
4464 #else | |
4465 if (c_parser_next_token_is (parser, CPP_NAME)) | 4343 if (c_parser_next_token_is (parser, CPP_NAME)) |
4466 { | 4344 { |
4467 #endif | |
4468 stmt = c_finish_goto_label (loc, | 4345 stmt = c_finish_goto_label (loc, |
4469 c_parser_peek_token (parser)->value); | 4346 c_parser_peek_token (parser)->value); |
4470 c_parser_consume_token (parser); | 4347 c_parser_consume_token (parser); |
4471 } | 4348 } |
4472 else if (c_parser_next_token_is (parser, CPP_MULT)) | 4349 else if (c_parser_next_token_is (parser, CPP_MULT)) |
4473 { | 4350 { |
4474 tree val; | 4351 tree val; |
4352 | |
4475 c_parser_consume_token (parser); | 4353 c_parser_consume_token (parser); |
4476 val = c_parser_expression (parser).value; | 4354 val = c_parser_expression (parser).value; |
4477 mark_exp_read (val); | 4355 mark_exp_read (val); |
4478 stmt = c_finish_goto_ptr (loc, val); | 4356 stmt = c_finish_goto_ptr (loc, val); |
4479 } | 4357 } |
4480 else | 4358 else |
4481 #ifndef noCbC | |
4482 { | |
4483 if (c_parser_next_token_is (parser, CPP_NAME)) | |
4484 { | |
4485 tree id = c_parser_peek_token (parser)->value; | |
4486 location_t loc = c_parser_peek_token (parser)->location; | |
4487 /** build_external_ref (id,RID_CbC_CODE , loc); **/ | |
4488 build_external_ref (loc, id, RID_CbC_CODE, &expr.original_type); | |
4489 } | |
4490 expr = c_parser_expr_no_commas (parser, NULL); | |
4491 if (TREE_CODE(expr.value) == CALL_EXPR ) | |
4492 { | |
4493 location_t loc = c_parser_peek_token (parser)->location; | |
4494 cbc_replace_arguments (loc, expr.value); | |
4495 TREE_TYPE(expr.value) = void_type_node; | |
4496 /*tree env = NULL_TREE;**/ | |
4497 CbC_IS_CbC_GOTO (expr.value) = 1; | |
4498 CALL_EXPR_TAILCALL (expr.value) = 1; | |
4499 add_stmt(expr.value); | |
4500 stmt = c_finish_return(loc, NULL_TREE, NULL_TREE); /* stmt = c_finish_return (0); */ | |
4501 } | |
4502 else | |
4503 c_parser_error (parser, "expected code segment jump or %<*%>"); | |
4504 } | |
4505 #else | |
4506 c_parser_error (parser, "expected identifier or %<*%>"); | 4359 c_parser_error (parser, "expected identifier or %<*%>"); |
4507 #endif | 4360 goto expect_semicolon; |
4508 goto expect_semicolon; | |
4509 case RID_CONTINUE: | 4361 case RID_CONTINUE: |
4510 c_parser_consume_token (parser); | 4362 c_parser_consume_token (parser); |
4511 stmt = c_finish_bc_stmt (loc, &c_cont_label, false); | 4363 stmt = c_finish_bc_stmt (loc, &c_cont_label, false); |
4512 goto expect_semicolon; | 4364 goto expect_semicolon; |
4513 case RID_BREAK: | 4365 case RID_BREAK: |
4564 c_parser_consume_token (parser); | 4416 c_parser_consume_token (parser); |
4565 break; | 4417 break; |
4566 case CPP_CLOSE_PAREN: | 4418 case CPP_CLOSE_PAREN: |
4567 case CPP_CLOSE_SQUARE: | 4419 case CPP_CLOSE_SQUARE: |
4568 /* Avoid infinite loop in error recovery: | 4420 /* Avoid infinite loop in error recovery: |
4569 c_parser_skip_until_found stops at a closing nesting | 4421 c_parser_skip_until_found stops at a closing nesting |
4570 delimiter without consuming it, but here we need to consume | 4422 delimiter without consuming it, but here we need to consume |
4571 it to proceed further. */ | 4423 it to proceed further. */ |
4572 c_parser_error (parser, "expected statement"); | 4424 c_parser_error (parser, "expected statement"); |
4573 c_parser_consume_token (parser); | 4425 c_parser_consume_token (parser); |
4574 break; | 4426 break; |
4575 case CPP_PRAGMA: | 4427 case CPP_PRAGMA: |
4576 c_parser_pragma (parser, pragma_stmt); | 4428 c_parser_pragma (parser, pragma_stmt); |
4653 c_parser_if_body (c_parser *parser, bool *if_p) | 4505 c_parser_if_body (c_parser *parser, bool *if_p) |
4654 { | 4506 { |
4655 tree block = c_begin_compound_stmt (flag_isoc99); | 4507 tree block = c_begin_compound_stmt (flag_isoc99); |
4656 location_t body_loc = c_parser_peek_token (parser)->location; | 4508 location_t body_loc = c_parser_peek_token (parser)->location; |
4657 while (c_parser_next_token_is_keyword (parser, RID_CASE) | 4509 while (c_parser_next_token_is_keyword (parser, RID_CASE) |
4658 || c_parser_next_token_is_keyword (parser, RID_DEFAULT) | 4510 || c_parser_next_token_is_keyword (parser, RID_DEFAULT) |
4659 || (c_parser_next_token_is (parser, CPP_NAME) | 4511 || (c_parser_next_token_is (parser, CPP_NAME) |
4660 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) | 4512 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) |
4661 c_parser_label (parser); | 4513 c_parser_label (parser); |
4662 *if_p = c_parser_next_token_is_keyword (parser, RID_IF); | 4514 *if_p = c_parser_next_token_is_keyword (parser, RID_IF); |
4663 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | 4515 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
4664 { | 4516 { |
4665 location_t loc = c_parser_peek_token (parser)->location; | 4517 location_t loc = c_parser_peek_token (parser)->location; |
4666 add_stmt (build_empty_stmt (loc)); | 4518 add_stmt (build_empty_stmt (loc)); |
4667 c_parser_consume_token (parser); | 4519 c_parser_consume_token (parser); |
4668 if (!c_parser_next_token_is_keyword (parser, RID_ELSE)) | 4520 if (!c_parser_next_token_is_keyword (parser, RID_ELSE)) |
4669 warning_at (loc, OPT_Wempty_body, | 4521 warning_at (loc, OPT_Wempty_body, |
4670 "suggest braces around empty body in an %<if%> statement"); | 4522 "suggest braces around empty body in an %<if%> statement"); |
4671 } | 4523 } |
4672 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | 4524 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
4673 add_stmt (c_parser_compound_statement (parser)); | 4525 add_stmt (c_parser_compound_statement (parser)); |
4674 else | 4526 else |
4675 c_parser_statement_after_labels (parser); | 4527 c_parser_statement_after_labels (parser); |
4684 c_parser_else_body (c_parser *parser) | 4536 c_parser_else_body (c_parser *parser) |
4685 { | 4537 { |
4686 location_t else_loc = c_parser_peek_token (parser)->location; | 4538 location_t else_loc = c_parser_peek_token (parser)->location; |
4687 tree block = c_begin_compound_stmt (flag_isoc99); | 4539 tree block = c_begin_compound_stmt (flag_isoc99); |
4688 while (c_parser_next_token_is_keyword (parser, RID_CASE) | 4540 while (c_parser_next_token_is_keyword (parser, RID_CASE) |
4689 || c_parser_next_token_is_keyword (parser, RID_DEFAULT) | 4541 || c_parser_next_token_is_keyword (parser, RID_DEFAULT) |
4690 || (c_parser_next_token_is (parser, CPP_NAME) | 4542 || (c_parser_next_token_is (parser, CPP_NAME) |
4691 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) | 4543 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) |
4692 c_parser_label (parser); | 4544 c_parser_label (parser); |
4693 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | 4545 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
4694 { | 4546 { |
4695 location_t loc = c_parser_peek_token (parser)->location; | 4547 location_t loc = c_parser_peek_token (parser)->location; |
4696 warning_at (loc, | 4548 warning_at (loc, |
4697 OPT_Wempty_body, | 4549 OPT_Wempty_body, |
4698 "suggest braces around empty body in an %<else%> statement"); | 4550 "suggest braces around empty body in an %<else%> statement"); |
4699 add_stmt (build_empty_stmt (loc)); | 4551 add_stmt (build_empty_stmt (loc)); |
4700 c_parser_consume_token (parser); | 4552 c_parser_consume_token (parser); |
4701 } | 4553 } |
4702 else | 4554 else |
4703 c_parser_statement_after_labels (parser); | 4555 c_parser_statement_after_labels (parser); |
4823 location_t loc; | 4675 location_t loc; |
4824 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO)); | 4676 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO)); |
4825 c_parser_consume_token (parser); | 4677 c_parser_consume_token (parser); |
4826 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | 4678 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
4827 warning_at (c_parser_peek_token (parser)->location, | 4679 warning_at (c_parser_peek_token (parser)->location, |
4828 OPT_Wempty_body, | 4680 OPT_Wempty_body, |
4829 "suggest braces around empty body in %<do%> statement"); | 4681 "suggest braces around empty body in %<do%> statement"); |
4830 block = c_begin_compound_stmt (flag_isoc99); | 4682 block = c_begin_compound_stmt (flag_isoc99); |
4831 loc = c_parser_peek_token (parser)->location; | 4683 loc = c_parser_peek_token (parser)->location; |
4832 save_break = c_break_label; | 4684 save_break = c_break_label; |
4833 c_break_label = NULL_TREE; | 4685 c_break_label = NULL_TREE; |
4834 save_cont = c_cont_label; | 4686 save_cont = c_cont_label; |
5090 { | 4942 { |
5091 quals = c_parser_peek_token (parser)->value; | 4943 quals = c_parser_peek_token (parser)->value; |
5092 c_parser_consume_token (parser); | 4944 c_parser_consume_token (parser); |
5093 } | 4945 } |
5094 else if (c_parser_next_token_is_keyword (parser, RID_CONST) | 4946 else if (c_parser_next_token_is_keyword (parser, RID_CONST) |
5095 || c_parser_next_token_is_keyword (parser, RID_RESTRICT)) | 4947 || c_parser_next_token_is_keyword (parser, RID_RESTRICT)) |
5096 { | 4948 { |
5097 warning_at (c_parser_peek_token (parser)->location, | 4949 warning_at (c_parser_peek_token (parser)->location, |
5098 0, | 4950 0, |
5099 "%E qualifier ignored on asm", | 4951 "%E qualifier ignored on asm", |
5100 c_parser_peek_token (parser)->value); | 4952 c_parser_peek_token (parser)->value); |
5101 quals = NULL_TREE; | 4953 quals = NULL_TREE; |
5102 c_parser_consume_token (parser); | 4954 c_parser_consume_token (parser); |
5103 } | 4955 } |
5104 else | 4956 else |
5105 quals = NULL_TREE; | 4957 quals = NULL_TREE; |
5135 /* Parse each colon-delimited section of operands. */ | 4987 /* Parse each colon-delimited section of operands. */ |
5136 nsections = 3 + is_goto; | 4988 nsections = 3 + is_goto; |
5137 for (section = 0; section < nsections; ++section) | 4989 for (section = 0; section < nsections; ++section) |
5138 { | 4990 { |
5139 if (!c_parser_require (parser, CPP_COLON, | 4991 if (!c_parser_require (parser, CPP_COLON, |
5140 is_goto | 4992 is_goto |
5141 ? "expected %<:%>" | 4993 ? "expected %<:%>" |
5142 : "expected %<:%> or %<)%>")) | 4994 : "expected %<:%> or %<)%>")) |
5143 goto error_close_paren; | 4995 goto error_close_paren; |
5144 | 4996 |
5145 /* Once past any colon, we're no longer a simple asm. */ | 4997 /* Once past any colon, we're no longer a simple asm. */ |
5146 simple = false; | 4998 simple = false; |
5147 | 4999 |
5148 if ((!c_parser_next_token_is (parser, CPP_COLON) | 5000 if ((!c_parser_next_token_is (parser, CPP_COLON) |
5149 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | 5001 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
5150 || section == 3) | 5002 || section == 3) |
5151 switch (section) | 5003 switch (section) |
5152 { | 5004 { |
5153 case 0: | 5005 case 0: |
5154 /* For asm goto, we don't allow output operands, but reserve | 5006 /* For asm goto, we don't allow output operands, but reserve |
5155 the slot for a future extension that does allow them. */ | 5007 the slot for a future extension that does allow them. */ |
5156 if (!is_goto) | 5008 if (!is_goto) |
5157 outputs = c_parser_asm_operands (parser, false); | 5009 outputs = c_parser_asm_operands (parser, false); |
5158 break; | 5010 break; |
5159 case 1: | 5011 case 1: |
5160 inputs = c_parser_asm_operands (parser, true); | 5012 inputs = c_parser_asm_operands (parser, true); |
5161 break; | 5013 break; |
5162 case 2: | 5014 case 2: |
5163 clobbers = c_parser_asm_clobbers (parser); | 5015 clobbers = c_parser_asm_clobbers (parser); |
5164 break; | 5016 break; |
5165 case 3: | 5017 case 3: |
5166 labels = c_parser_asm_goto_operands (parser); | 5018 labels = c_parser_asm_goto_operands (parser); |
5167 break; | 5019 break; |
5168 default: | 5020 default: |
5169 gcc_unreachable (); | 5021 gcc_unreachable (); |
5170 } | 5022 } |
5171 | 5023 |
5172 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto) | 5024 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto) |
5173 goto done_asm; | 5025 goto done_asm; |
5174 } | 5026 } |
5175 | 5027 |
5176 done_asm: | 5028 done_asm: |
5177 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) | 5029 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
5178 { | 5030 { |
5182 | 5034 |
5183 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) | 5035 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) |
5184 c_parser_skip_to_end_of_block_or_statement (parser); | 5036 c_parser_skip_to_end_of_block_or_statement (parser); |
5185 | 5037 |
5186 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs, | 5038 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs, |
5187 clobbers, labels, simple)); | 5039 clobbers, labels, simple)); |
5188 | 5040 |
5189 error: | 5041 error: |
5190 parser->lex_untranslated_string = false; | 5042 parser->lex_untranslated_string = false; |
5191 return ret; | 5043 return ret; |
5192 | 5044 |
5216 while (true) | 5068 while (true) |
5217 { | 5069 { |
5218 tree name, str; | 5070 tree name, str; |
5219 struct c_expr expr; | 5071 struct c_expr expr; |
5220 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) | 5072 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) |
5221 { | 5073 { |
5222 c_parser_consume_token (parser); | 5074 c_parser_consume_token (parser); |
5223 if (c_parser_next_token_is (parser, CPP_NAME)) | 5075 if (c_parser_next_token_is (parser, CPP_NAME)) |
5224 { | 5076 { |
5225 tree id = c_parser_peek_token (parser)->value; | 5077 tree id = c_parser_peek_token (parser)->value; |
5226 c_parser_consume_token (parser); | 5078 c_parser_consume_token (parser); |
5227 name = build_string (IDENTIFIER_LENGTH (id), | 5079 name = build_string (IDENTIFIER_LENGTH (id), |
5228 IDENTIFIER_POINTER (id)); | 5080 IDENTIFIER_POINTER (id)); |
5229 } | 5081 } |
5082 else | |
5083 { | |
5084 c_parser_error (parser, "expected identifier"); | |
5085 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
5086 return NULL_TREE; | |
5087 } | |
5088 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | |
5089 "expected %<]%>"); | |
5090 } | |
5230 else | 5091 else |
5231 { | 5092 name = NULL_TREE; |
5232 c_parser_error (parser, "expected identifier"); | |
5233 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
5234 return NULL_TREE; | |
5235 } | |
5236 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | |
5237 "expected %<]%>"); | |
5238 } | |
5239 else | |
5240 name = NULL_TREE; | |
5241 str = c_parser_asm_string_literal (parser); | 5093 str = c_parser_asm_string_literal (parser); |
5242 if (str == NULL_TREE) | 5094 if (str == NULL_TREE) |
5243 return NULL_TREE; | 5095 return NULL_TREE; |
5244 parser->lex_untranslated_string = false; | 5096 parser->lex_untranslated_string = false; |
5245 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | 5097 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
5246 { | 5098 { |
5247 parser->lex_untranslated_string = true; | 5099 parser->lex_untranslated_string = true; |
5248 return NULL_TREE; | 5100 return NULL_TREE; |
5249 } | 5101 } |
5250 loc = c_parser_peek_token (parser)->location; | 5102 loc = c_parser_peek_token (parser)->location; |
5251 expr = c_parser_expression (parser); | 5103 expr = c_parser_expression (parser); |
5252 mark_exp_read (expr.value); | 5104 mark_exp_read (expr.value); |
5253 if (convert_p) | 5105 if (convert_p) |
5254 expr = default_function_array_conversion (loc, expr); | 5106 expr = default_function_array_conversion (loc, expr); |
5255 expr.value = c_fully_fold (expr.value, false, NULL); | 5107 expr.value = c_fully_fold (expr.value, false, NULL); |
5256 parser->lex_untranslated_string = true; | 5108 parser->lex_untranslated_string = true; |
5257 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) | 5109 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
5258 { | 5110 { |
5259 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | 5111 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
5260 return NULL_TREE; | 5112 return NULL_TREE; |
5261 } | 5113 } |
5262 list = chainon (list, build_tree_list (build_tree_list (name, str), | 5114 list = chainon (list, build_tree_list (build_tree_list (name, str), |
5263 expr.value)); | 5115 expr.value)); |
5264 if (c_parser_next_token_is (parser, CPP_COMMA)) | 5116 if (c_parser_next_token_is (parser, CPP_COMMA)) |
5265 c_parser_consume_token (parser); | 5117 c_parser_consume_token (parser); |
5266 else | 5118 else |
5267 break; | 5119 break; |
5268 } | 5120 } |
5269 return list; | 5121 return list; |
5270 } | 5122 } |
5271 | 5123 |
5272 /* Parse asm clobbers, a GNU extension. | 5124 /* Parse asm clobbers, a GNU extension. |
5282 tree list = NULL_TREE; | 5134 tree list = NULL_TREE; |
5283 while (true) | 5135 while (true) |
5284 { | 5136 { |
5285 tree str = c_parser_asm_string_literal (parser); | 5137 tree str = c_parser_asm_string_literal (parser); |
5286 if (str) | 5138 if (str) |
5287 list = tree_cons (NULL_TREE, str, list); | 5139 list = tree_cons (NULL_TREE, str, list); |
5288 else | 5140 else |
5289 return NULL_TREE; | 5141 return NULL_TREE; |
5290 if (c_parser_next_token_is (parser, CPP_COMMA)) | 5142 if (c_parser_next_token_is (parser, CPP_COMMA)) |
5291 c_parser_consume_token (parser); | 5143 c_parser_consume_token (parser); |
5292 else | 5144 else |
5293 break; | 5145 break; |
5294 } | 5146 } |
5295 return list; | 5147 return list; |
5296 } | 5148 } |
5297 | 5149 |
5298 /* Parse asm goto labels, a GNU extension. | 5150 /* Parse asm goto labels, a GNU extension. |
5309 while (true) | 5161 while (true) |
5310 { | 5162 { |
5311 tree name, label; | 5163 tree name, label; |
5312 | 5164 |
5313 if (c_parser_next_token_is (parser, CPP_NAME)) | 5165 if (c_parser_next_token_is (parser, CPP_NAME)) |
5314 { | 5166 { |
5315 c_token *tok = c_parser_peek_token (parser); | 5167 c_token *tok = c_parser_peek_token (parser); |
5316 name = tok->value; | 5168 name = tok->value; |
5317 label = lookup_label_for_goto (tok->location, name); | 5169 label = lookup_label_for_goto (tok->location, name); |
5318 c_parser_consume_token (parser); | 5170 c_parser_consume_token (parser); |
5319 TREE_USED (label) = 1; | 5171 TREE_USED (label) = 1; |
5320 } | 5172 } |
5321 else | 5173 else |
5322 { | 5174 { |
5323 c_parser_error (parser, "expected identifier"); | 5175 c_parser_error (parser, "expected identifier"); |
5324 return NULL_TREE; | 5176 return NULL_TREE; |
5325 } | 5177 } |
5326 | 5178 |
5327 name = build_string (IDENTIFIER_LENGTH (name), | 5179 name = build_string (IDENTIFIER_LENGTH (name), |
5328 IDENTIFIER_POINTER (name)); | 5180 IDENTIFIER_POINTER (name)); |
5329 list = tree_cons (name, label, list); | 5181 list = tree_cons (name, label, list); |
5330 if (c_parser_next_token_is (parser, CPP_COMMA)) | 5182 if (c_parser_next_token_is (parser, CPP_COMMA)) |
5331 c_parser_consume_token (parser); | 5183 c_parser_consume_token (parser); |
5332 else | 5184 else |
5333 return nreverse (list); | 5185 return nreverse (list); |
5334 } | 5186 } |
5335 } | 5187 } |
5336 | 5188 |
5337 /* Parse an expression other than a compound expression; that is, an | 5189 /* Parse an expression other than a compound expression; that is, an |
5338 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not | 5190 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not |
5400 c_parser_consume_token (parser); | 5252 c_parser_consume_token (parser); |
5401 exp_location = c_parser_peek_token (parser)->location; | 5253 exp_location = c_parser_peek_token (parser)->location; |
5402 rhs = c_parser_expr_no_commas (parser, NULL); | 5254 rhs = c_parser_expr_no_commas (parser, NULL); |
5403 rhs = default_function_array_read_conversion (exp_location, rhs); | 5255 rhs = default_function_array_read_conversion (exp_location, rhs); |
5404 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type, | 5256 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type, |
5405 code, exp_location, rhs.value, | 5257 code, exp_location, rhs.value, |
5406 rhs.original_type); | 5258 rhs.original_type); |
5407 if (code == NOP_EXPR) | 5259 if (code == NOP_EXPR) |
5408 ret.original_code = MODIFY_EXPR; | 5260 ret.original_code = MODIFY_EXPR; |
5409 else | 5261 else |
5410 { | 5262 { |
5411 TREE_NO_WARNING (ret.value) = 1; | 5263 TREE_NO_WARNING (ret.value) = 1; |
5445 cond = default_function_array_read_conversion (cond_loc, cond); | 5297 cond = default_function_array_read_conversion (cond_loc, cond); |
5446 c_parser_consume_token (parser); | 5298 c_parser_consume_token (parser); |
5447 if (c_parser_next_token_is (parser, CPP_COLON)) | 5299 if (c_parser_next_token_is (parser, CPP_COLON)) |
5448 { | 5300 { |
5449 tree eptype = NULL_TREE; | 5301 tree eptype = NULL_TREE; |
5302 | |
5450 middle_loc = c_parser_peek_token (parser)->location; | 5303 middle_loc = c_parser_peek_token (parser)->location; |
5451 pedwarn (middle_loc, OPT_pedantic, | 5304 pedwarn (middle_loc, OPT_pedantic, |
5452 "ISO C forbids omitting the middle term of a ?: expression"); | 5305 "ISO C forbids omitting the middle term of a ?: expression"); |
5453 warn_for_omitted_condop (middle_loc, cond.value); | 5306 warn_for_omitted_condop (middle_loc, cond.value); |
5454 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR) | 5307 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR) |
5455 { | 5308 { |
5456 eptype = TREE_TYPE (cond.value); | 5309 eptype = TREE_TYPE (cond.value); |
5457 cond.value = TREE_OPERAND (cond.value, 0); | 5310 cond.value = TREE_OPERAND (cond.value, 0); |
5458 } | 5311 } |
5459 /* Make sure first operand is calculated only once. */ | 5312 /* Make sure first operand is calculated only once. */ |
5460 exp1.value = c_save_expr (default_conversion (cond.value)); | 5313 exp1.value = c_save_expr (default_conversion (cond.value)); |
5461 if (eptype) | 5314 if (eptype) |
5462 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value); | 5315 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value); |
5463 exp1.original_type = NULL; | 5316 exp1.original_type = NULL; |
5464 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value); | 5317 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value); |
5465 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node; | 5318 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node; |
5466 } | 5319 } |
5467 else | 5320 else |
5468 { | 5321 { |
5469 cond.value | 5322 cond.value |
5470 = c_objc_common_truthvalue_conversion | 5323 = c_objc_common_truthvalue_conversion |
5471 (cond_loc, default_conversion (cond.value)); | 5324 (cond_loc, default_conversion (cond.value)); |
5472 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node; | 5325 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node; |
5473 exp1 = c_parser_expression_conv (parser); | 5326 exp1 = c_parser_expression_conv (parser); |
5474 mark_exp_read (exp1.value); | 5327 mark_exp_read (exp1.value); |
5475 c_inhibit_evaluation_warnings += | 5328 c_inhibit_evaluation_warnings += |
5476 ((cond.value == truthvalue_true_node) | 5329 ((cond.value == truthvalue_true_node) |
5477 - (cond.value == truthvalue_false_node)); | 5330 - (cond.value == truthvalue_false_node)); |
5478 } | 5331 } |
5479 | 5332 |
5480 colon_loc = c_parser_peek_token (parser)->location; | 5333 colon_loc = c_parser_peek_token (parser)->location; |
5481 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) | 5334 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
5482 { | 5335 { |
5491 exp2 = c_parser_conditional_expression (parser, NULL); | 5344 exp2 = c_parser_conditional_expression (parser, NULL); |
5492 exp2 = default_function_array_read_conversion (exp2_loc, exp2); | 5345 exp2 = default_function_array_read_conversion (exp2_loc, exp2); |
5493 } | 5346 } |
5494 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node; | 5347 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node; |
5495 ret.value = build_conditional_expr (colon_loc, cond.value, | 5348 ret.value = build_conditional_expr (colon_loc, cond.value, |
5496 cond.original_code == C_MAYBE_CONST_EXPR, | 5349 cond.original_code == C_MAYBE_CONST_EXPR, |
5497 exp1.value, exp1.original_type, | 5350 exp1.value, exp1.original_type, |
5498 exp2.value, exp2.original_type); | 5351 exp2.value, exp2.original_type); |
5499 ret.original_code = ERROR_MARK; | 5352 ret.original_code = ERROR_MARK; |
5500 if (exp1.value == error_mark_node || exp2.value == error_mark_node) | 5353 if (exp1.value == error_mark_node || exp2.value == error_mark_node) |
5501 ret.original_type = NULL; | 5354 ret.original_type = NULL; |
5502 else | 5355 else |
5503 { | 5356 { |
5504 tree t1, t2; | 5357 tree t1, t2; |
5505 | 5358 |
5506 /* If both sides are enum type, the default conversion will have | 5359 /* If both sides are enum type, the default conversion will have |
5507 made the type of the result be an integer type. We want to | 5360 made the type of the result be an integer type. We want to |
5508 remember the enum types we started with. */ | 5361 remember the enum types we started with. */ |
5509 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value); | 5362 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value); |
5510 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value); | 5363 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value); |
5511 ret.original_type = ((t1 != error_mark_node | 5364 ret.original_type = ((t1 != error_mark_node |
5512 && t2 != error_mark_node | 5365 && t2 != error_mark_node |
5513 && (TYPE_MAIN_VARIANT (t1) | 5366 && (TYPE_MAIN_VARIANT (t1) |
5514 == TYPE_MAIN_VARIANT (t2))) | 5367 == TYPE_MAIN_VARIANT (t2))) |
5515 ? t1 | 5368 ? t1 |
5516 : NULL); | 5369 : NULL); |
5517 } | 5370 } |
5518 return ret; | 5371 return ret; |
5519 } | 5372 } |
5520 | 5373 |
5521 /* Parse a binary expression; that is, a logical-OR-expression (C90 | 5374 /* Parse a binary expression; that is, a logical-OR-expression (C90 |
5661 while (true) | 5514 while (true) |
5662 { | 5515 { |
5663 enum prec oprec; | 5516 enum prec oprec; |
5664 enum tree_code ocode; | 5517 enum tree_code ocode; |
5665 if (parser->error) | 5518 if (parser->error) |
5666 goto out; | 5519 goto out; |
5667 switch (c_parser_peek_token (parser)->type) | 5520 switch (c_parser_peek_token (parser)->type) |
5668 { | 5521 { |
5669 case CPP_MULT: | 5522 case CPP_MULT: |
5670 oprec = PREC_MULT; | 5523 oprec = PREC_MULT; |
5671 ocode = MULT_EXPR; | 5524 ocode = MULT_EXPR; |
5672 break; | 5525 break; |
5673 case CPP_DIV: | 5526 case CPP_DIV: |
5674 oprec = PREC_MULT; | 5527 oprec = PREC_MULT; |
5675 ocode = TRUNC_DIV_EXPR; | 5528 ocode = TRUNC_DIV_EXPR; |
5676 break; | 5529 break; |
5677 case CPP_MOD: | 5530 case CPP_MOD: |
5678 oprec = PREC_MULT; | 5531 oprec = PREC_MULT; |
5679 ocode = TRUNC_MOD_EXPR; | 5532 ocode = TRUNC_MOD_EXPR; |
5680 break; | 5533 break; |
5681 case CPP_PLUS: | 5534 case CPP_PLUS: |
5682 oprec = PREC_ADD; | 5535 oprec = PREC_ADD; |
5683 ocode = PLUS_EXPR; | 5536 ocode = PLUS_EXPR; |
5684 break; | 5537 break; |
5685 case CPP_MINUS: | 5538 case CPP_MINUS: |
5686 oprec = PREC_ADD; | 5539 oprec = PREC_ADD; |
5687 ocode = MINUS_EXPR; | 5540 ocode = MINUS_EXPR; |
5688 break; | 5541 break; |
5689 case CPP_LSHIFT: | 5542 case CPP_LSHIFT: |
5690 oprec = PREC_SHIFT; | 5543 oprec = PREC_SHIFT; |
5691 ocode = LSHIFT_EXPR; | 5544 ocode = LSHIFT_EXPR; |
5692 break; | 5545 break; |
5693 case CPP_RSHIFT: | 5546 case CPP_RSHIFT: |
5694 oprec = PREC_SHIFT; | 5547 oprec = PREC_SHIFT; |
5695 ocode = RSHIFT_EXPR; | 5548 ocode = RSHIFT_EXPR; |
5696 break; | 5549 break; |
5697 case CPP_LESS: | 5550 case CPP_LESS: |
5698 oprec = PREC_REL; | 5551 oprec = PREC_REL; |
5699 ocode = LT_EXPR; | 5552 ocode = LT_EXPR; |
5700 break; | 5553 break; |
5701 case CPP_GREATER: | 5554 case CPP_GREATER: |
5702 oprec = PREC_REL; | 5555 oprec = PREC_REL; |
5703 ocode = GT_EXPR; | 5556 ocode = GT_EXPR; |
5704 break; | 5557 break; |
5705 case CPP_LESS_EQ: | 5558 case CPP_LESS_EQ: |
5706 oprec = PREC_REL; | 5559 oprec = PREC_REL; |
5707 ocode = LE_EXPR; | 5560 ocode = LE_EXPR; |
5708 break; | 5561 break; |
5709 case CPP_GREATER_EQ: | 5562 case CPP_GREATER_EQ: |
5710 oprec = PREC_REL; | 5563 oprec = PREC_REL; |
5711 ocode = GE_EXPR; | 5564 ocode = GE_EXPR; |
5712 break; | 5565 break; |
5713 case CPP_EQ_EQ: | 5566 case CPP_EQ_EQ: |
5714 oprec = PREC_EQ; | 5567 oprec = PREC_EQ; |
5715 ocode = EQ_EXPR; | 5568 ocode = EQ_EXPR; |
5716 break; | 5569 break; |
5717 case CPP_NOT_EQ: | 5570 case CPP_NOT_EQ: |
5718 oprec = PREC_EQ; | 5571 oprec = PREC_EQ; |
5719 ocode = NE_EXPR; | 5572 ocode = NE_EXPR; |
5720 break; | 5573 break; |
5721 case CPP_AND: | 5574 case CPP_AND: |
5722 oprec = PREC_BITAND; | 5575 oprec = PREC_BITAND; |
5723 ocode = BIT_AND_EXPR; | 5576 ocode = BIT_AND_EXPR; |
5724 break; | 5577 break; |
5725 case CPP_XOR: | 5578 case CPP_XOR: |
5726 oprec = PREC_BITXOR; | 5579 oprec = PREC_BITXOR; |
5727 ocode = BIT_XOR_EXPR; | 5580 ocode = BIT_XOR_EXPR; |
5728 break; | 5581 break; |
5729 case CPP_OR: | 5582 case CPP_OR: |
5730 oprec = PREC_BITOR; | 5583 oprec = PREC_BITOR; |
5731 ocode = BIT_IOR_EXPR; | 5584 ocode = BIT_IOR_EXPR; |
5732 break; | 5585 break; |
5733 case CPP_AND_AND: | 5586 case CPP_AND_AND: |
5734 oprec = PREC_LOGAND; | 5587 oprec = PREC_LOGAND; |
5735 ocode = TRUTH_ANDIF_EXPR; | 5588 ocode = TRUTH_ANDIF_EXPR; |
5736 break; | 5589 break; |
5737 case CPP_OR_OR: | 5590 case CPP_OR_OR: |
5738 oprec = PREC_LOGOR; | 5591 oprec = PREC_LOGOR; |
5739 ocode = TRUTH_ORIF_EXPR; | 5592 ocode = TRUTH_ORIF_EXPR; |
5740 break; | 5593 break; |
5741 default: | 5594 default: |
5742 /* Not a binary operator, so end of the binary | 5595 /* Not a binary operator, so end of the binary |
5743 expression. */ | 5596 expression. */ |
5744 goto out; | 5597 goto out; |
5745 } | 5598 } |
5746 binary_loc = c_parser_peek_token (parser)->location; | 5599 binary_loc = c_parser_peek_token (parser)->location; |
5747 c_parser_consume_token (parser); | 5600 c_parser_consume_token (parser); |
5748 while (oprec <= stack[sp].prec) | 5601 while (oprec <= stack[sp].prec) |
5749 POP; | 5602 POP; |
5750 switch (ocode) | 5603 switch (ocode) |
5751 { | 5604 { |
5752 case TRUTH_ANDIF_EXPR: | 5605 case TRUTH_ANDIF_EXPR: |
5753 stack[sp].expr | 5606 stack[sp].expr |
5754 = default_function_array_read_conversion (stack[sp].loc, | 5607 = default_function_array_read_conversion (stack[sp].loc, |
5798 { | 5651 { |
5799 location_t cast_loc = c_parser_peek_token (parser)->location; | 5652 location_t cast_loc = c_parser_peek_token (parser)->location; |
5800 gcc_assert (!after || c_dialect_objc ()); | 5653 gcc_assert (!after || c_dialect_objc ()); |
5801 if (after) | 5654 if (after) |
5802 return c_parser_postfix_expression_after_primary (parser, | 5655 return c_parser_postfix_expression_after_primary (parser, |
5803 cast_loc, *after); | 5656 cast_loc, *after); |
5804 /* If the expression begins with a parenthesized type name, it may | 5657 /* If the expression begins with a parenthesized type name, it may |
5805 be either a cast or a compound literal; we need to see whether | 5658 be either a cast or a compound literal; we need to see whether |
5806 the next character is '{' to tell the difference. If not, it is | 5659 the next character is '{' to tell the difference. If not, it is |
5807 an unary expression. Full detection of unknown typenames here | 5660 an unary expression. Full detection of unknown typenames here |
5808 would require a 3-token lookahead. */ | 5661 would require a 3-token lookahead. */ |
5814 struct c_expr expr; | 5667 struct c_expr expr; |
5815 c_parser_consume_token (parser); | 5668 c_parser_consume_token (parser); |
5816 type_name = c_parser_type_name (parser); | 5669 type_name = c_parser_type_name (parser); |
5817 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | 5670 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
5818 if (type_name == NULL) | 5671 if (type_name == NULL) |
5819 { | 5672 { |
5820 ret.value = error_mark_node; | 5673 ret.value = error_mark_node; |
5821 ret.original_code = ERROR_MARK; | 5674 ret.original_code = ERROR_MARK; |
5822 ret.original_type = NULL; | 5675 ret.original_type = NULL; |
5823 return ret; | 5676 return ret; |
5824 } | 5677 } |
5825 | 5678 |
5826 /* Save casted types in the function's used types hash table. */ | 5679 /* Save casted types in the function's used types hash table. */ |
5827 used_types_insert (type_name->specs->type); | 5680 used_types_insert (type_name->specs->type); |
5828 | 5681 |
5829 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | 5682 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
5830 return c_parser_postfix_expression_after_paren_type (parser, type_name, | 5683 return c_parser_postfix_expression_after_paren_type (parser, type_name, |
5831 cast_loc); | 5684 cast_loc); |
5832 { | 5685 { |
5833 location_t expr_loc = c_parser_peek_token (parser)->location; | 5686 location_t expr_loc = c_parser_peek_token (parser)->location; |
5834 expr = c_parser_cast_expression (parser, NULL); | 5687 expr = c_parser_cast_expression (parser, NULL); |
5835 expr = default_function_array_read_conversion (expr_loc, expr); | 5688 expr = default_function_array_read_conversion (expr_loc, expr); |
5836 } | 5689 } |
5905 op = default_function_array_read_conversion (exp_loc, op); | 5758 op = default_function_array_read_conversion (exp_loc, op); |
5906 ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR); | 5759 ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR); |
5907 return ret; | 5760 return ret; |
5908 case CPP_PLUS: | 5761 case CPP_PLUS: |
5909 if (!c_dialect_objc () && !in_system_header) | 5762 if (!c_dialect_objc () && !in_system_header) |
5910 warning_at (op_loc, | 5763 warning_at (op_loc, |
5911 OPT_Wtraditional, | 5764 OPT_Wtraditional, |
5912 "traditional C rejects the unary plus operator"); | 5765 "traditional C rejects the unary plus operator"); |
5913 c_parser_consume_token (parser); | 5766 c_parser_consume_token (parser); |
5914 exp_loc = c_parser_peek_token (parser)->location; | 5767 exp_loc = c_parser_peek_token (parser)->location; |
5915 op = c_parser_cast_expression (parser, NULL); | 5768 op = c_parser_cast_expression (parser, NULL); |
5916 op = default_function_array_read_conversion (exp_loc, op); | 5769 op = default_function_array_read_conversion (exp_loc, op); |
5917 return parser_build_unary_op (op_loc, CONVERT_EXPR, op); | 5770 return parser_build_unary_op (op_loc, CONVERT_EXPR, op); |
5935 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op); | 5788 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op); |
5936 case CPP_AND_AND: | 5789 case CPP_AND_AND: |
5937 /* Refer to the address of a label as a pointer. */ | 5790 /* Refer to the address of a label as a pointer. */ |
5938 c_parser_consume_token (parser); | 5791 c_parser_consume_token (parser); |
5939 if (c_parser_next_token_is (parser, CPP_NAME)) | 5792 if (c_parser_next_token_is (parser, CPP_NAME)) |
5940 { | 5793 { |
5941 ret.value = finish_label_address_expr | 5794 ret.value = finish_label_address_expr |
5942 (c_parser_peek_token (parser)->value, op_loc); | 5795 (c_parser_peek_token (parser)->value, op_loc); |
5943 c_parser_consume_token (parser); | 5796 c_parser_consume_token (parser); |
5944 } | 5797 } |
5945 else | 5798 else |
5946 { | 5799 { |
5947 c_parser_error (parser, "expected identifier"); | 5800 c_parser_error (parser, "expected identifier"); |
5948 ret.value = error_mark_node; | 5801 ret.value = error_mark_node; |
5949 } | 5802 } |
5950 return ret; | 5803 return ret; |
5951 case CPP_KEYWORD: | 5804 case CPP_KEYWORD: |
5952 switch (c_parser_peek_token (parser)->keyword) | 5805 switch (c_parser_peek_token (parser)->keyword) |
5953 { | 5806 { |
5954 case RID_SIZEOF: | 5807 case RID_SIZEOF: |
5955 return c_parser_sizeof_expression (parser); | 5808 return c_parser_sizeof_expression (parser); |
5956 case RID_ALIGNOF: | 5809 case RID_ALIGNOF: |
5957 return c_parser_alignof_expression (parser); | 5810 return c_parser_alignof_expression (parser); |
5958 case RID_EXTENSION: | 5811 case RID_EXTENSION: |
5959 c_parser_consume_token (parser); | 5812 c_parser_consume_token (parser); |
5960 ext = disable_extension_diagnostics (); | 5813 ext = disable_extension_diagnostics (); |
5961 ret = c_parser_cast_expression (parser, NULL); | 5814 ret = c_parser_cast_expression (parser, NULL); |
5962 restore_extension_diagnostics (ext); | 5815 restore_extension_diagnostics (ext); |
5963 return ret; | 5816 return ret; |
5964 case RID_REALPART: | 5817 case RID_REALPART: |
5965 c_parser_consume_token (parser); | 5818 c_parser_consume_token (parser); |
5966 exp_loc = c_parser_peek_token (parser)->location; | 5819 exp_loc = c_parser_peek_token (parser)->location; |
5967 op = c_parser_cast_expression (parser, NULL); | 5820 op = c_parser_cast_expression (parser, NULL); |
5968 op = default_function_array_conversion (exp_loc, op); | 5821 op = default_function_array_conversion (exp_loc, op); |
5969 return parser_build_unary_op (op_loc, REALPART_EXPR, op); | 5822 return parser_build_unary_op (op_loc, REALPART_EXPR, op); |
5970 case RID_IMAGPART: | 5823 case RID_IMAGPART: |
5971 c_parser_consume_token (parser); | 5824 c_parser_consume_token (parser); |
5972 exp_loc = c_parser_peek_token (parser)->location; | 5825 exp_loc = c_parser_peek_token (parser)->location; |
5973 op = c_parser_cast_expression (parser, NULL); | 5826 op = c_parser_cast_expression (parser, NULL); |
5974 op = default_function_array_conversion (exp_loc, op); | 5827 op = default_function_array_conversion (exp_loc, op); |
5975 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op); | 5828 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op); |
5976 default: | 5829 default: |
5977 return c_parser_postfix_expression (parser); | 5830 return c_parser_postfix_expression (parser); |
5978 } | 5831 } |
5979 default: | 5832 default: |
5980 return c_parser_postfix_expression (parser); | 5833 return c_parser_postfix_expression (parser); |
5981 } | 5834 } |
5982 } | 5835 } |
5983 | 5836 |
5994 in_sizeof++; | 5847 in_sizeof++; |
5995 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) | 5848 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) |
5996 && c_token_starts_typename (c_parser_peek_2nd_token (parser))) | 5849 && c_token_starts_typename (c_parser_peek_2nd_token (parser))) |
5997 { | 5850 { |
5998 /* Either sizeof ( type-name ) or sizeof unary-expression | 5851 /* Either sizeof ( type-name ) or sizeof unary-expression |
5999 starting with a compound literal. */ | 5852 starting with a compound literal. */ |
6000 struct c_type_name *type_name; | 5853 struct c_type_name *type_name; |
6001 c_parser_consume_token (parser); | 5854 c_parser_consume_token (parser); |
6002 expr_loc = c_parser_peek_token (parser)->location; | 5855 expr_loc = c_parser_peek_token (parser)->location; |
6003 type_name = c_parser_type_name (parser); | 5856 type_name = c_parser_type_name (parser); |
6004 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | 5857 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
6005 if (type_name == NULL) | 5858 if (type_name == NULL) |
6006 { | 5859 { |
6007 struct c_expr ret; | 5860 struct c_expr ret; |
6008 c_inhibit_evaluation_warnings--; | 5861 c_inhibit_evaluation_warnings--; |
6009 in_sizeof--; | 5862 in_sizeof--; |
6010 ret.value = error_mark_node; | 5863 ret.value = error_mark_node; |
6011 ret.original_code = ERROR_MARK; | 5864 ret.original_code = ERROR_MARK; |
6012 ret.original_type = NULL; | 5865 ret.original_type = NULL; |
6013 return ret; | 5866 return ret; |
6014 } | 5867 } |
6015 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | 5868 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
6016 { | 5869 { |
6017 expr = c_parser_postfix_expression_after_paren_type (parser, | 5870 expr = c_parser_postfix_expression_after_paren_type (parser, |
6018 type_name, | 5871 type_name, |
6019 expr_loc); | 5872 expr_loc); |
6020 goto sizeof_expr; | 5873 goto sizeof_expr; |
6021 } | 5874 } |
6022 /* sizeof ( type-name ). */ | 5875 /* sizeof ( type-name ). */ |
6023 c_inhibit_evaluation_warnings--; | 5876 c_inhibit_evaluation_warnings--; |
6024 in_sizeof--; | 5877 in_sizeof--; |
6025 return c_expr_sizeof_type (expr_loc, type_name); | 5878 return c_expr_sizeof_type (expr_loc, type_name); |
6026 } | 5879 } |
6031 sizeof_expr: | 5884 sizeof_expr: |
6032 c_inhibit_evaluation_warnings--; | 5885 c_inhibit_evaluation_warnings--; |
6033 in_sizeof--; | 5886 in_sizeof--; |
6034 mark_exp_read (expr.value); | 5887 mark_exp_read (expr.value); |
6035 if (TREE_CODE (expr.value) == COMPONENT_REF | 5888 if (TREE_CODE (expr.value) == COMPONENT_REF |
6036 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1))) | 5889 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1))) |
6037 error_at (expr_loc, "%<sizeof%> applied to a bit-field"); | 5890 error_at (expr_loc, "%<sizeof%> applied to a bit-field"); |
6038 return c_expr_sizeof_expr (expr_loc, expr); | 5891 return c_expr_sizeof_expr (expr_loc, expr); |
6039 } | 5892 } |
6040 } | 5893 } |
6041 | 5894 |
6042 /* Parse an alignof expression. */ | 5895 /* Parse an alignof expression. */ |
6052 in_alignof++; | 5905 in_alignof++; |
6053 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) | 5906 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) |
6054 && c_token_starts_typename (c_parser_peek_2nd_token (parser))) | 5907 && c_token_starts_typename (c_parser_peek_2nd_token (parser))) |
6055 { | 5908 { |
6056 /* Either __alignof__ ( type-name ) or __alignof__ | 5909 /* Either __alignof__ ( type-name ) or __alignof__ |
6057 unary-expression starting with a compound literal. */ | 5910 unary-expression starting with a compound literal. */ |
6058 location_t loc; | 5911 location_t loc; |
6059 struct c_type_name *type_name; | 5912 struct c_type_name *type_name; |
6060 struct c_expr ret; | 5913 struct c_expr ret; |
6061 c_parser_consume_token (parser); | 5914 c_parser_consume_token (parser); |
6062 loc = c_parser_peek_token (parser)->location; | 5915 loc = c_parser_peek_token (parser)->location; |
6063 type_name = c_parser_type_name (parser); | 5916 type_name = c_parser_type_name (parser); |
6064 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | 5917 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
6065 if (type_name == NULL) | 5918 if (type_name == NULL) |
6066 { | 5919 { |
6067 struct c_expr ret; | 5920 struct c_expr ret; |
6068 c_inhibit_evaluation_warnings--; | 5921 c_inhibit_evaluation_warnings--; |
6069 in_alignof--; | 5922 in_alignof--; |
6070 ret.value = error_mark_node; | 5923 ret.value = error_mark_node; |
6071 ret.original_code = ERROR_MARK; | 5924 ret.original_code = ERROR_MARK; |
6072 ret.original_type = NULL; | 5925 ret.original_type = NULL; |
6073 return ret; | 5926 return ret; |
6074 } | 5927 } |
6075 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | 5928 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
6076 { | 5929 { |
6077 expr = c_parser_postfix_expression_after_paren_type (parser, | 5930 expr = c_parser_postfix_expression_after_paren_type (parser, |
6078 type_name, | 5931 type_name, |
6079 loc); | 5932 loc); |
6080 goto alignof_expr; | 5933 goto alignof_expr; |
6081 } | 5934 } |
6082 /* alignof ( type-name ). */ | 5935 /* alignof ( type-name ). */ |
6083 c_inhibit_evaluation_warnings--; | 5936 c_inhibit_evaluation_warnings--; |
6084 in_alignof--; | 5937 in_alignof--; |
6085 ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL)); | 5938 ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL)); |
6086 ret.original_code = ERROR_MARK; | 5939 ret.original_code = ERROR_MARK; |
6134 __PRETTY_FUNCTION__ | 5987 __PRETTY_FUNCTION__ |
6135 ( compound-statement ) | 5988 ( compound-statement ) |
6136 __builtin_va_arg ( assignment-expression , type-name ) | 5989 __builtin_va_arg ( assignment-expression , type-name ) |
6137 __builtin_offsetof ( type-name , offsetof-member-designator ) | 5990 __builtin_offsetof ( type-name , offsetof-member-designator ) |
6138 __builtin_choose_expr ( assignment-expression , | 5991 __builtin_choose_expr ( assignment-expression , |
6139 assignment-expression , | 5992 assignment-expression , |
6140 assignment-expression ) | 5993 assignment-expression ) |
6141 __builtin_types_compatible_p ( type-name , type-name ) | 5994 __builtin_types_compatible_p ( type-name , type-name ) |
6142 | 5995 |
6143 offsetof-member-designator: | 5996 offsetof-member-designator: |
6144 identifier | 5997 identifier |
6145 offsetof-member-designator . identifier | 5998 offsetof-member-designator . identifier |
6154 @encode ( type-name ) | 6007 @encode ( type-name ) |
6155 objc-string-literal | 6008 objc-string-literal |
6156 Classname . identifier | 6009 Classname . identifier |
6157 */ | 6010 */ |
6158 | 6011 |
6159 static void | |
6160 cbc_finish_labeled_goto (location_t loc, tree label, tree retval) | |
6161 { | |
6162 /* add statement below. | |
6163 * | |
6164 * if (0) { | |
6165 * _cbc_exit0: | |
6166 * return retval; | |
6167 * } | |
6168 */ | |
6169 tree tlab; | |
6170 tree cond; | |
6171 | |
6172 tree cstmt = c_begin_compound_stmt (true); | |
6173 | |
6174 tlab = define_label (loc, label); | |
6175 gcc_assert (tlab); | |
6176 decl_attributes (&tlab, NULL_TREE, 0); | |
6177 add_stmt (build_stmt (loc, LABEL_EXPR, tlab)); | |
6178 | |
6179 tree ret = c_finish_return (loc, retval, retval); /*tree ret = c_finish_return (retval);*/ | |
6180 TREE_USED(ret) = 1; | |
6181 | |
6182 cond = integer_zero_node; | |
6183 tree if_body = c_end_compound_stmt (loc, cstmt, true); | |
6184 TREE_SIDE_EFFECTS (cstmt) = 1; | |
6185 c_finish_if_stmt (loc, cond, if_body, NULL_TREE, false); | |
6186 } | |
6187 | |
6188 static tree | |
6189 cbc_finish_nested_function (location_t loc, tree label, tree retval_decl) | |
6190 { | |
6191 | |
6192 /* add statement below. | |
6193 * void __return_func(int _retval, void *_envp){ | |
6194 * retval = _retval; | |
6195 * goto exit0; | |
6196 * } | |
6197 */ | |
6198 /* TODO: | |
6199 * retval(lhs)のTREE_DECLを引数から取得するように | |
6200 * int _retvalパラメータのタイプはretvalに合わせる | |
6201 */ | |
6202 | |
6203 tree fnbody; | |
6204 tree _retval_decl, _envp_decl; | |
6205 struct c_declarator *declarator; | |
6206 //tree ident; | |
6207 struct c_arg_info *args; | |
6208 struct c_declspecs *specs; | |
6209 struct c_typespec t; | |
6210 { | |
6211 push_scope (); | |
6212 declare_parm_level (); | |
6213 /*tree retval_type = TREE_TYPE(retval_decl);*/ | |
6214 | |
6215 _retval_decl = build_decl (loc, PARM_DECL, get_identifier ("_retval"), TREE_TYPE(retval_decl)); | |
6216 DECL_SOURCE_LOCATION (_retval_decl) = loc; | |
6217 DECL_ARTIFICIAL (_retval_decl) = 1; | |
6218 DECL_ARG_TYPE (_retval_decl) = TREE_TYPE(retval_decl); | |
6219 pushdecl (_retval_decl); | |
6220 finish_decl (_retval_decl, loc, NULL_TREE, NULL_TREE, NULL_TREE); | |
6221 | |
6222 _envp_decl = build_decl (loc, PARM_DECL, get_identifier ("_envp"), ptr_type_node); | |
6223 DECL_SOURCE_LOCATION (_envp_decl) = loc; | |
6224 DECL_ARTIFICIAL (_envp_decl) = 1; | |
6225 DECL_ARG_TYPE (_envp_decl) = ptr_type_node; | |
6226 pushdecl (_envp_decl); | |
6227 finish_decl (_envp_decl, loc, NULL_TREE, NULL_TREE, NULL_TREE); | |
6228 | |
6229 args = get_parm_info(false); | |
6230 pop_scope(); | |
6231 } | |
6232 | |
6233 t.kind = ctsk_resword; | |
6234 t.spec = get_identifier("void"); | |
6235 specs = build_null_declspecs(); | |
6236 declspecs_add_type (loc, specs, t); | |
6237 finish_declspecs (specs); | |
6238 | |
6239 /* make nested function. */ | |
6240 declarator = build_id_declarator (get_identifier ("_cbc_internal_return")); | |
6241 declarator = build_function_declarator (args, declarator); | |
6242 | |
6243 c_push_function_context (); | |
6244 | |
6245 if (!start_function (specs, declarator, NULL_TREE)) | |
6246 { | |
6247 c_pop_function_context(); | |
6248 gcc_assert (0); | |
6249 } | |
6250 store_parm_decls (); | |
6251 | |
6252 | |
6253 /* start compound statement. */ | |
6254 tree cstmt = c_begin_compound_stmt (true); | |
6255 | |
6256 add_stmt (build_modify_expr (loc, retval_decl, NULL_TREE, NOP_EXPR, loc, _retval_decl, NULL_TREE)); | |
6257 //tree stmt = c_finish_goto_label (loc, label); | |
6258 | |
6259 /* end compound statement. */ | |
6260 fnbody = c_end_compound_stmt (loc, cstmt, true); | |
6261 TREE_SIDE_EFFECTS (cstmt) = 1; | |
6262 | |
6263 /* finish declaration of nested function. */ | |
6264 tree decl = current_function_decl; | |
6265 add_stmt (fnbody); | |
6266 finish_function (); | |
6267 c_pop_function_context (); | |
6268 | |
6269 add_stmt (build_stmt (loc, DECL_EXPR, decl)); | |
6270 return decl; | |
6271 | |
6272 } | |
6273 | |
6274 static struct c_expr | 6012 static struct c_expr |
6275 c_parser_postfix_expression (c_parser *parser) | 6013 c_parser_postfix_expression (c_parser *parser) |
6276 { | 6014 { |
6277 struct c_expr expr, e1, e2, e3; | 6015 struct c_expr expr, e1, e2, e3; |
6278 struct c_type_name *t1, *t2; | 6016 struct c_type_name *t1, *t2; |
6279 //cbc? static tree return_label1; | |
6280 location_t loc = c_parser_peek_token (parser)->location;; | 6017 location_t loc = c_parser_peek_token (parser)->location;; |
6281 expr.original_code = ERROR_MARK; | 6018 expr.original_code = ERROR_MARK; |
6282 expr.original_type = NULL; | 6019 expr.original_type = NULL; |
6283 switch (c_parser_peek_token (parser)->type) | 6020 switch (c_parser_peek_token (parser)->type) |
6284 { | 6021 { |
6285 case CPP_NUMBER: | 6022 case CPP_NUMBER: |
6286 expr.value = c_parser_peek_token (parser)->value; | 6023 expr.value = c_parser_peek_token (parser)->value; |
6287 loc = c_parser_peek_token (parser)->location; | 6024 loc = c_parser_peek_token (parser)->location; |
6288 c_parser_consume_token (parser); | 6025 c_parser_consume_token (parser); |
6289 if (TREE_CODE (expr.value) == FIXED_CST | 6026 if (TREE_CODE (expr.value) == FIXED_CST |
6290 && !targetm.fixed_point_supported_p ()) | 6027 && !targetm.fixed_point_supported_p ()) |
6291 { | 6028 { |
6292 error_at (loc, "fixed-point types not supported for this target"); | 6029 error_at (loc, "fixed-point types not supported for this target"); |
6293 expr.value = error_mark_node; | 6030 expr.value = error_mark_node; |
6294 } | 6031 } |
6295 break; | 6032 break; |
6296 case CPP_CHAR: | 6033 case CPP_CHAR: |
6297 case CPP_CHAR16: | 6034 case CPP_CHAR16: |
6298 case CPP_CHAR32: | 6035 case CPP_CHAR32: |
6299 case CPP_WCHAR: | 6036 case CPP_WCHAR: |
6310 c_parser_consume_token (parser); | 6047 c_parser_consume_token (parser); |
6311 break; | 6048 break; |
6312 case CPP_OBJC_STRING: | 6049 case CPP_OBJC_STRING: |
6313 gcc_assert (c_dialect_objc ()); | 6050 gcc_assert (c_dialect_objc ()); |
6314 expr.value | 6051 expr.value |
6315 = objc_build_string_object (c_parser_peek_token (parser)->value); | 6052 = objc_build_string_object (c_parser_peek_token (parser)->value); |
6316 c_parser_consume_token (parser); | 6053 c_parser_consume_token (parser); |
6317 break; | 6054 break; |
6318 case CPP_NAME: | 6055 case CPP_NAME: |
6319 switch (c_parser_peek_token (parser)->id_kind) | 6056 switch (c_parser_peek_token (parser)->id_kind) |
6320 { | 6057 { |
6359 break; | 6096 break; |
6360 } | 6097 } |
6361 break; | 6098 break; |
6362 case CPP_OPEN_PAREN: | 6099 case CPP_OPEN_PAREN: |
6363 /* A parenthesized expression, statement expression or compound | 6100 /* A parenthesized expression, statement expression or compound |
6364 literal. */ | 6101 literal. */ |
6365 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE) | 6102 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE) |
6366 { | 6103 { |
6367 /* A statement expression. */ | 6104 /* A statement expression. */ |
6368 tree stmt; | 6105 tree stmt; |
6369 location_t brace_loc; | 6106 location_t brace_loc; |
6388 "ISO C forbids braced-groups within expressions"); | 6125 "ISO C forbids braced-groups within expressions"); |
6389 expr.value = c_finish_stmt_expr (brace_loc, stmt); | 6126 expr.value = c_finish_stmt_expr (brace_loc, stmt); |
6390 mark_exp_read (expr.value); | 6127 mark_exp_read (expr.value); |
6391 } | 6128 } |
6392 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser))) | 6129 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser))) |
6393 { | 6130 { |
6394 /* A compound literal. ??? Can we actually get here rather | 6131 /* A compound literal. ??? Can we actually get here rather |
6395 than going directly to | 6132 than going directly to |
6396 c_parser_postfix_expression_after_paren_type from | 6133 c_parser_postfix_expression_after_paren_type from |
6397 elsewhere? */ | 6134 elsewhere? */ |
6398 location_t loc; | 6135 location_t loc; |
6399 struct c_type_name *type_name; | 6136 struct c_type_name *type_name; |
6400 c_parser_consume_token (parser); | 6137 c_parser_consume_token (parser); |
6401 loc = c_parser_peek_token (parser)->location; | 6138 loc = c_parser_peek_token (parser)->location; |
6402 type_name = c_parser_type_name (parser); | 6139 type_name = c_parser_type_name (parser); |
6403 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | 6140 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
6404 "expected %<)%>"); | 6141 "expected %<)%>"); |
6405 if (type_name == NULL) | 6142 if (type_name == NULL) |
6406 { | 6143 { |
6407 expr.value = error_mark_node; | 6144 expr.value = error_mark_node; |
6408 } | 6145 } |
6146 else | |
6147 expr = c_parser_postfix_expression_after_paren_type (parser, | |
6148 type_name, | |
6149 loc); | |
6150 } | |
6409 else | 6151 else |
6410 expr = c_parser_postfix_expression_after_paren_type (parser, | 6152 { |
6411 type_name, | 6153 /* A parenthesized expression. */ |
6412 loc); | 6154 c_parser_consume_token (parser); |
6413 } | 6155 expr = c_parser_expression (parser); |
6414 else | 6156 if (TREE_CODE (expr.value) == MODIFY_EXPR) |
6415 { | 6157 TREE_NO_WARNING (expr.value) = 1; |
6416 /* A parenthesized expression. */ | 6158 if (expr.original_code != C_MAYBE_CONST_EXPR) |
6417 c_parser_consume_token (parser); | 6159 expr.original_code = ERROR_MARK; |
6418 expr = c_parser_expression (parser); | 6160 /* Don't change EXPR.ORIGINAL_TYPE. */ |
6419 if (TREE_CODE (expr.value) == MODIFY_EXPR) | 6161 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
6420 TREE_NO_WARNING (expr.value) = 1; | 6162 "expected %<)%>"); |
6421 if (expr.original_code != C_MAYBE_CONST_EXPR) | 6163 } |
6422 expr.original_code = ERROR_MARK; | |
6423 /* Don't change EXPR.ORIGINAL_TYPE. */ | |
6424 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
6425 "expected %<)%>"); | |
6426 } | |
6427 break; | 6164 break; |
6428 case CPP_KEYWORD: | 6165 case CPP_KEYWORD: |
6429 switch (c_parser_peek_token (parser)->keyword) | 6166 switch (c_parser_peek_token (parser)->keyword) |
6430 { | 6167 { |
6431 case RID_FUNCTION_NAME: | 6168 case RID_FUNCTION_NAME: |
6585 e3 = c_parser_expr_no_commas (parser, NULL); | 6322 e3 = c_parser_expr_no_commas (parser, NULL); |
6586 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | 6323 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
6587 "expected %<)%>"); | 6324 "expected %<)%>"); |
6588 { | 6325 { |
6589 tree c; | 6326 tree c; |
6327 | |
6590 c = e1.value; | 6328 c = e1.value; |
6591 mark_exp_read (e2.value); | 6329 mark_exp_read (e2.value); |
6592 mark_exp_read (e3.value); | 6330 mark_exp_read (e3.value); |
6593 if (TREE_CODE (c) != INTEGER_CST | 6331 if (TREE_CODE (c) != INTEGER_CST |
6594 || !INTEGRAL_TYPE_P (TREE_TYPE (c))) | 6332 || !INTEGRAL_TYPE_P (TREE_TYPE (c))) |
6626 } | 6364 } |
6627 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | 6365 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
6628 "expected %<)%>"); | 6366 "expected %<)%>"); |
6629 { | 6367 { |
6630 tree e1, e2; | 6368 tree e1, e2; |
6369 | |
6631 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL)); | 6370 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL)); |
6632 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL)); | 6371 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL)); |
6372 | |
6633 expr.value | 6373 expr.value |
6634 = comptypes (e1, e2) ? integer_one_node : integer_zero_node; | 6374 = comptypes (e1, e2) ? integer_one_node : integer_zero_node; |
6635 } | 6375 } |
6636 break; | 6376 break; |
6637 case RID_AT_SELECTOR: | 6377 case RID_AT_SELECTOR: |
6693 { | 6433 { |
6694 tree type = groktypename (t1, NULL, NULL); | 6434 tree type = groktypename (t1, NULL, NULL); |
6695 expr.value = objc_build_encode_expr (type); | 6435 expr.value = objc_build_encode_expr (type); |
6696 } | 6436 } |
6697 break; | 6437 break; |
6698 | |
6699 #ifndef noCbC | |
6700 case RID_CbC_ENV: | |
6701 { | |
6702 c_parser_consume_token (parser); | |
6703 /* get value of %ebp. */ | |
6704 /*tree env_tree = build_external_ref ( | |
6705 get_identifier ("__builtin_frame_address"), 0, | |
6706 c_parser_peek_token (parser)->location);*/ | |
6707 loc = c_parser_peek_token (parser)->location; | |
6708 tree env_tree = build_external_ref (loc, | |
6709 get_identifier ("__builtin_frame_address"), 0, &expr.original_type); | |
6710 expr.value = build_function_call(loc, env_tree, | |
6711 build_tree_list (NULL_TREE, build_int_cst (NULL_TREE,0))); | |
6712 expr.original_code = ERROR_MARK; | |
6713 } | |
6714 break; | |
6715 case RID_CbC_RET: | |
6716 case RID_RETURN: | |
6717 | |
6718 #if 0 | |
6719 if (cbc_return_f==0) | |
6720 { tree retval; | |
6721 | |
6722 /* | |
6723 Generates something like... | |
6724 | |
6725 int retval = 1; | |
6726 void (*ret)(int retval_,void *fp) ; | |
6727 | |
6728 ret = ({ | |
6729 __label__ exit0; | |
6730 volatile static flag = 0; | |
6731 void __return_func(int retval_,void *fp) { | |
6732 retval = retval_; | |
6733 goto exit0; | |
6734 } | |
6735 if (flag) { | |
6736 exit0: | |
6737 printf("f1: fp = 0x%x\n",__builtin_frame_address(0)); | |
6738 return retval; | |
6739 } | |
6740 __return_func; | |
6741 }); | |
6742 | |
6743 */ | |
6744 | |
6745 tree stmt = c_begin_stmt_expr (); | |
6746 cbc_return_f = c_parser_peek_token (parser)->value; | |
6747 cbc_return = c_parser_peek_token (parser)->location; | |
6748 c_parser_consume_token (parser); | |
6749 location_t next = c_parser_peek_token (parser)->location; | |
6750 | |
6751 // dummy variable for hidden condition | |
6752 struct c_expr cexpr; | |
6753 tree cond; | |
6754 location_t loc; | |
6755 loc = next; | |
6756 tree decl_cond = | |
6757 build_decl (VAR_DECL, get_identifier ("__return"), | |
6758 intHI_type_node); | |
6759 TREE_STATIC (decl_cond) = 1; | |
6760 cexpr.value = lang_hooks.decls.pushdecl(decl_cond); | |
6761 | |
6762 cexpr.original_code = ERROR_MARK; | |
6763 cond = c_objc_common_truthvalue_conversion(loc, cexpr.value); | |
6764 if (EXPR_P (cond)) | |
6765 SET_EXPR_LOCATION (cond, loc); | |
6766 | |
6767 | |
6768 | |
6769 | |
6770 tree fwlabel = create_artificial_label (); | |
6771 //TREE_USED(fwlabel) = 1; | |
6772 | |
6773 //add_stmt (build1 (GOTO_EXPR, void_type_node, fwlabel)); | |
6774 tree block = c_begin_compound_stmt (flag_isoc99); | |
6775 | |
6776 tree tlab = lookup_label(cbc_return_f); | |
6777 | |
6778 tree decl= build_stmt (LABEL_EXPR, tlab); | |
6779 //TREE_USED(decl) = 1; | |
6780 add_stmt(decl); | |
6781 | |
6782 //tree hoge = build_int_cst(NULL_TREE,55); | |
6783 retval = build_component_ref (cbc_env, get_identifier("retval")); | |
6784 tree ret = c_finish_return (retval); | |
6785 TREE_USED(ret) = 1; | |
6786 tree first_body = c_end_compound_stmt (block, flag_isoc99); | |
6787 | |
6788 c_finish_if_stmt (loc, cond, first_body, NULL_TREE, false); | |
6789 | |
6790 // define_label(EXPR_LOCATION(decl) ,cbc_return_f); | |
6791 return_label1 = | |
6792 define_label(cbc_return ,cbc_return_f); | |
6793 tree fwdef= build_stmt (LABEL_EXPR, fwlabel); | |
6794 | |
6795 //TREE_USED(fwdef) = 1; | |
6796 add_stmt(fwdef); | |
6797 TREE_SIDE_EFFECTS (block) = 1; | |
6798 | |
6799 // tree label = lookup_label(c_parser_peek_token (parser)->value); | |
6800 //TREE_USED(label) = 1; | |
6801 | |
6802 tree value = build1(ADDR_EXPR, ptr_type_node, return_label1); | |
6803 SET_EXPR_LOCATION (value, next); | |
6804 TREE_SIDE_EFFECTS (value) = 1; | |
6805 add_stmt(value); | |
6806 | |
6807 TREE_SIDE_EFFECTS (stmt) = 1; | |
6808 expr.value = c_finish_stmt_expr (stmt); | |
6809 expr.original_code = ERROR_MARK; | |
6810 | |
6811 | |
6812 } | |
6813 else | |
6814 { | |
6815 //tree label = lookup_label(c_parser_peek_token (parser)->value); | |
6816 //TREE_USED(label) = 1; | |
6817 //expr.value = build1(ADDR_EXPR, ptr_type_node, label); | |
6818 expr.value = build1(ADDR_EXPR, ptr_type_node, return_label1); | |
6819 c_parser_consume_token (parser); | |
6820 } | |
6821 #else //by KENT. | |
6822 { | |
6823 /* | |
6824 ({ | |
6825 __label__ _cbc_exit0; | |
6826 void __return_func(int retval_, void *_envp){ | |
6827 retval = retval_; | |
6828 goto exit0; | |
6829 } | |
6830 if (0) { | |
6831 _cbc_exit0: | |
6832 return retval; | |
6833 } | |
6834 __return_func; | |
6835 }); | |
6836 */ | |
6837 tree value, stmt, label, tlab, decl; | |
6838 c_parser_consume_token (parser); | |
6839 | |
6840 stmt = c_begin_stmt_expr (); | |
6841 cbc_return_f = c_parser_peek_token (parser)->value; | |
6842 location_t location = c_parser_peek_token (parser)->location; | |
6843 | |
6844 /* create label. (__label__ _cbc_exit0;) */ | |
6845 label = get_identifier ("_cbc_exit0"); | |
6846 tlab = declare_label (label); | |
6847 C_DECLARED_LABEL_FLAG (tlab) = 1; | |
6848 add_stmt (build_stmt (location, DECL_EXPR, tlab)); | |
6849 | |
6850 /* declare retval. (int retval;) */ | |
6851 tree decl_cond = | |
6852 build_decl (location, VAR_DECL, get_identifier ("retval"), | |
6853 TREE_TYPE (TREE_TYPE (current_function_decl))); | |
6854 TREE_STATIC (decl_cond) = 1; | |
6855 DECL_ARTIFICIAL (decl_cond) = 1; | |
6856 pushdecl (decl_cond); | |
6857 | |
6858 /* define nested function. */ | |
6859 decl = | |
6860 cbc_finish_nested_function (location, label, decl_cond); | |
6861 | |
6862 /* define if-ed goto label and return statement. */ | |
6863 cbc_finish_labeled_goto (location, label, decl_cond); | |
6864 | |
6865 /* get pointer to nested function. */ | |
6866 value = build_addr (decl , current_function_decl); | |
6867 SET_EXPR_LOCATION (value, location); | |
6868 add_stmt (value); | |
6869 /*value = build_external_ref (get_identifier("_cbc_internal_return"), false, location);*/ | |
6870 /*value = build_unary_op (location, ADDR_EXPR, value, 0);*/ | |
6871 /*add_stmt (value);*/ | |
6872 | |
6873 TREE_SIDE_EFFECTS (stmt) = 1; | |
6874 expr.value = c_finish_stmt_expr (location, stmt); | |
6875 expr.original_code = ERROR_MARK; | |
6876 } | |
6877 | |
6878 #endif //0 | |
6879 break; | |
6880 #endif //noCbC | |
6881 | |
6882 default: | 6438 default: |
6883 c_parser_error (parser, "expected expression"); | 6439 c_parser_error (parser, "expected expression"); |
6884 expr.value = error_mark_node; | 6440 expr.value = error_mark_node; |
6885 break; | 6441 break; |
6886 } | 6442 } |
6887 break; | 6443 break; |
6888 case CPP_OPEN_SQUARE: | 6444 case CPP_OPEN_SQUARE: |
6889 if (c_dialect_objc ()) | 6445 if (c_dialect_objc ()) |
6890 { | 6446 { |
6891 tree receiver, args; | 6447 tree receiver, args; |
6892 c_parser_consume_token (parser); | 6448 c_parser_consume_token (parser); |
6893 receiver = c_parser_objc_receiver (parser); | 6449 receiver = c_parser_objc_receiver (parser); |
6894 args = c_parser_objc_message_args (parser); | 6450 args = c_parser_objc_message_args (parser); |
6895 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | 6451 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, |
6896 "expected %<]%>"); | 6452 "expected %<]%>"); |
6897 expr.value = objc_build_message_expr (build_tree_list (receiver, | 6453 expr.value = objc_build_message_expr (build_tree_list (receiver, |
6898 args)); | 6454 args)); |
6899 break; | 6455 break; |
6900 } | 6456 } |
6901 /* Else fall through to report error. */ | 6457 /* Else fall through to report error. */ |
6902 default: | 6458 default: |
6903 c_parser_error (parser, "expected expression"); | 6459 c_parser_error (parser, "expected expression"); |
6904 expr.value = error_mark_node; | 6460 expr.value = error_mark_node; |
6905 break; | 6461 break; |
6917 location of the first token after the parentheses around the type | 6473 location of the first token after the parentheses around the type |
6918 name. */ | 6474 name. */ |
6919 | 6475 |
6920 static struct c_expr | 6476 static struct c_expr |
6921 c_parser_postfix_expression_after_paren_type (c_parser *parser, | 6477 c_parser_postfix_expression_after_paren_type (c_parser *parser, |
6922 struct c_type_name *type_name, | 6478 struct c_type_name *type_name, |
6923 location_t type_loc) | 6479 location_t type_loc) |
6924 { | 6480 { |
6925 tree type; | 6481 tree type; |
6926 struct c_expr init; | 6482 struct c_expr init; |
6927 bool non_const; | 6483 bool non_const; |
6928 struct c_expr expr; | 6484 struct c_expr expr; |
6951 } | 6507 } |
6952 | 6508 |
6953 if (!flag_isoc99) | 6509 if (!flag_isoc99) |
6954 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals"); | 6510 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals"); |
6955 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR) | 6511 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR) |
6956 ? CONSTRUCTOR_NON_CONST (init.value) | 6512 ? CONSTRUCTOR_NON_CONST (init.value) |
6957 : init.original_code == C_MAYBE_CONST_EXPR); | 6513 : init.original_code == C_MAYBE_CONST_EXPR); |
6958 non_const |= !type_expr_const; | 6514 non_const |= !type_expr_const; |
6959 expr.value = build_compound_literal (start_loc, type, init.value, non_const); | 6515 expr.value = build_compound_literal (start_loc, type, init.value, non_const); |
6960 expr.original_code = ERROR_MARK; | 6516 expr.original_code = ERROR_MARK; |
6961 expr.original_type = NULL; | 6517 expr.original_type = NULL; |
6962 if (type_expr) | 6518 if (type_expr) |
6963 { | 6519 { |
6964 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR) | 6520 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR) |
6965 { | 6521 { |
6966 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE); | 6522 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE); |
6967 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr; | 6523 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr; |
6968 } | 6524 } |
6969 else | 6525 else |
6970 { | 6526 { |
6971 gcc_assert (!non_const); | 6527 gcc_assert (!non_const); |
6972 expr.value = build2 (C_MAYBE_CONST_EXPR, type, | 6528 expr.value = build2 (C_MAYBE_CONST_EXPR, type, |
6973 type_expr, expr.value); | 6529 type_expr, expr.value); |
6974 } | 6530 } |
6975 } | 6531 } |
6976 return c_parser_postfix_expression_after_primary (parser, start_loc, expr); | 6532 return c_parser_postfix_expression_after_primary (parser, start_loc, expr); |
6977 } | 6533 } |
6978 | 6534 |
6979 /* Parse a postfix expression after the initial primary or compound | 6535 /* Parse a postfix expression after the initial primary or compound |
6981 | 6537 |
6982 EXPR_LOC is the location of the primary expression. */ | 6538 EXPR_LOC is the location of the primary expression. */ |
6983 | 6539 |
6984 static struct c_expr | 6540 static struct c_expr |
6985 c_parser_postfix_expression_after_primary (c_parser *parser, | 6541 c_parser_postfix_expression_after_primary (c_parser *parser, |
6986 location_t expr_loc, | 6542 location_t expr_loc, |
6987 struct c_expr expr) | 6543 struct c_expr expr) |
6988 { | 6544 { |
6989 struct c_expr orig_expr; | 6545 struct c_expr orig_expr; |
6990 tree ident, idx; | 6546 tree ident, idx; |
6991 VEC(tree,gc) *exprlist; | 6547 VEC(tree,gc) *exprlist; |
6992 VEC(tree,gc) *origtypes; | 6548 VEC(tree,gc) *origtypes; |
7174 nonempty-expr-list , assignment-expression | 6730 nonempty-expr-list , assignment-expression |
7175 */ | 6731 */ |
7176 | 6732 |
7177 static VEC(tree,gc) * | 6733 static VEC(tree,gc) * |
7178 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p, | 6734 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p, |
7179 VEC(tree,gc) **p_orig_types) | 6735 VEC(tree,gc) **p_orig_types) |
7180 { | 6736 { |
7181 VEC(tree,gc) *ret; | 6737 VEC(tree,gc) *ret; |
7182 VEC(tree,gc) *orig_types; | 6738 VEC(tree,gc) *orig_types; |
7183 struct c_expr expr; | 6739 struct c_expr expr; |
7184 location_t loc = c_parser_peek_token (parser)->location; | 6740 location_t loc = c_parser_peek_token (parser)->location; |
7203 loc = c_parser_peek_token (parser)->location; | 6759 loc = c_parser_peek_token (parser)->location; |
7204 expr = c_parser_expr_no_commas (parser, NULL); | 6760 expr = c_parser_expr_no_commas (parser, NULL); |
7205 if (convert_p) | 6761 if (convert_p) |
7206 expr = default_function_array_read_conversion (loc, expr); | 6762 expr = default_function_array_read_conversion (loc, expr); |
7207 if (fold_p) | 6763 if (fold_p) |
7208 expr.value = c_fully_fold (expr.value, false, NULL); | 6764 expr.value = c_fully_fold (expr.value, false, NULL); |
7209 VEC_safe_push (tree, gc, ret, expr.value); | 6765 VEC_safe_push (tree, gc, ret, expr.value); |
7210 if (orig_types != NULL) | 6766 if (orig_types != NULL) |
7211 VEC_safe_push (tree, gc, orig_types, expr.original_type); | 6767 VEC_safe_push (tree, gc, orig_types, expr.original_type); |
7212 } | 6768 } |
7213 if (orig_types != NULL) | 6769 if (orig_types != NULL) |
7214 *p_orig_types = orig_types; | 6770 *p_orig_types = orig_types; |
7215 return ret; | 6771 return ret; |
7216 } | 6772 } |
7285 id2 = c_parser_peek_token (parser)->value; | 6841 id2 = c_parser_peek_token (parser)->value; |
7286 c_parser_consume_token (parser); | 6842 c_parser_consume_token (parser); |
7287 } | 6843 } |
7288 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | 6844 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
7289 if (!iface_p) | 6845 if (!iface_p) |
7290 { | 6846 { |
7291 objc_start_category_implementation (id1, id2); | 6847 objc_start_category_implementation (id1, id2); |
7292 return; | 6848 return; |
7293 } | 6849 } |
7294 if (c_parser_next_token_is (parser, CPP_LESS)) | 6850 if (c_parser_next_token_is (parser, CPP_LESS)) |
7295 proto = c_parser_objc_protocol_refs (parser); | 6851 proto = c_parser_objc_protocol_refs (parser); |
7296 objc_start_category_interface (id1, id2, proto, attributes); | 6852 objc_start_category_interface (id1, id2, proto, attributes); |
7297 c_parser_objc_methodprotolist (parser); | 6853 c_parser_objc_methodprotolist (parser); |
7298 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); | 6854 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); |
7301 } | 6857 } |
7302 if (c_parser_next_token_is (parser, CPP_COLON)) | 6858 if (c_parser_next_token_is (parser, CPP_COLON)) |
7303 { | 6859 { |
7304 c_parser_consume_token (parser); | 6860 c_parser_consume_token (parser); |
7305 if (c_parser_next_token_is_not (parser, CPP_NAME)) | 6861 if (c_parser_next_token_is_not (parser, CPP_NAME)) |
7306 { | 6862 { |
7307 c_parser_error (parser, "expected identifier"); | 6863 c_parser_error (parser, "expected identifier"); |
7308 return; | 6864 return; |
7309 } | 6865 } |
7310 superclass = c_parser_peek_token (parser)->value; | 6866 superclass = c_parser_peek_token (parser)->value; |
7311 c_parser_consume_token (parser); | 6867 c_parser_consume_token (parser); |
7312 } | 6868 } |
7313 else | 6869 else |
7314 superclass = NULL_TREE; | 6870 superclass = NULL_TREE; |
7367 while (c_parser_next_token_is_not (parser, CPP_EOF)) | 6923 while (c_parser_next_token_is_not (parser, CPP_EOF)) |
7368 { | 6924 { |
7369 tree decls; | 6925 tree decls; |
7370 /* Parse any stray semicolon. */ | 6926 /* Parse any stray semicolon. */ |
7371 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | 6927 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
7372 { | 6928 { |
7373 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic, | 6929 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic, |
7374 "extra semicolon in struct or union specified"); | 6930 "extra semicolon in struct or union specified"); |
7375 c_parser_consume_token (parser); | 6931 c_parser_consume_token (parser); |
7376 continue; | 6932 continue; |
7377 } | 6933 } |
7378 /* Stop if at the end of the instance variables. */ | 6934 /* Stop if at the end of the instance variables. */ |
7379 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | 6935 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
7380 { | 6936 { |
7381 c_parser_consume_token (parser); | 6937 c_parser_consume_token (parser); |
7382 break; | 6938 break; |
7383 } | 6939 } |
7384 /* Parse any objc-visibility-spec. */ | 6940 /* Parse any objc-visibility-spec. */ |
7385 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE)) | 6941 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE)) |
7386 { | 6942 { |
7387 c_parser_consume_token (parser); | 6943 c_parser_consume_token (parser); |
7388 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE); | 6944 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE); |
7405 c_parser_consume_token (parser); | 6961 c_parser_consume_token (parser); |
7406 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE); | 6962 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE); |
7407 continue; | 6963 continue; |
7408 } | 6964 } |
7409 else if (c_parser_next_token_is (parser, CPP_PRAGMA)) | 6965 else if (c_parser_next_token_is (parser, CPP_PRAGMA)) |
7410 { | 6966 { |
7411 c_parser_pragma (parser, pragma_external); | 6967 c_parser_pragma (parser, pragma_external); |
7412 continue; | 6968 continue; |
7413 } | 6969 } |
6970 | |
7414 /* Parse some comma-separated declarations. */ | 6971 /* Parse some comma-separated declarations. */ |
7415 decls = c_parser_struct_declaration (parser); | 6972 decls = c_parser_struct_declaration (parser); |
7416 { | 6973 { |
7417 /* Comma-separated instance variables are chained together in | 6974 /* Comma-separated instance variables are chained together in |
7418 reverse order; add them one by one. */ | 6975 reverse order; add them one by one. */ |
7450 } | 7007 } |
7451 id = c_parser_peek_token (parser)->value; | 7008 id = c_parser_peek_token (parser)->value; |
7452 list = chainon (list, build_tree_list (NULL_TREE, id)); | 7009 list = chainon (list, build_tree_list (NULL_TREE, id)); |
7453 c_parser_consume_token (parser); | 7010 c_parser_consume_token (parser); |
7454 if (c_parser_next_token_is (parser, CPP_COMMA)) | 7011 if (c_parser_next_token_is (parser, CPP_COMMA)) |
7455 c_parser_consume_token (parser); | 7012 c_parser_consume_token (parser); |
7456 else | 7013 else |
7457 break; | 7014 break; |
7458 } | 7015 } |
7459 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | 7016 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
7460 objc_declare_class (list); | 7017 objc_declare_class (list); |
7461 } | 7018 } |
7462 | 7019 |
7517 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA | 7074 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA |
7518 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON) | 7075 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON) |
7519 { | 7076 { |
7520 tree list = NULL_TREE; | 7077 tree list = NULL_TREE; |
7521 /* Any identifiers, including those declared as type names, are | 7078 /* Any identifiers, including those declared as type names, are |
7522 OK here. */ | 7079 OK here. */ |
7523 while (true) | 7080 while (true) |
7524 { | 7081 { |
7525 tree id; | 7082 tree id; |
7526 if (c_parser_next_token_is_not (parser, CPP_NAME)) | 7083 if (c_parser_next_token_is_not (parser, CPP_NAME)) |
7527 { | 7084 { |
7528 c_parser_error (parser, "expected identifier"); | 7085 c_parser_error (parser, "expected identifier"); |
7529 break; | 7086 break; |
7530 } | 7087 } |
7531 id = c_parser_peek_token (parser)->value; | 7088 id = c_parser_peek_token (parser)->value; |
7532 list = chainon (list, build_tree_list (NULL_TREE, id)); | 7089 list = chainon (list, build_tree_list (NULL_TREE, id)); |
7533 c_parser_consume_token (parser); | 7090 c_parser_consume_token (parser); |
7534 if (c_parser_next_token_is (parser, CPP_COMMA)) | 7091 if (c_parser_next_token_is (parser, CPP_COMMA)) |
7535 c_parser_consume_token (parser); | 7092 c_parser_consume_token (parser); |
7536 else | 7093 else |
7537 break; | 7094 break; |
7538 } | 7095 } |
7539 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | 7096 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
7540 objc_declare_protocols (list, attributes); | 7097 objc_declare_protocols (list, attributes); |
7541 } | 7098 } |
7542 else | 7099 else |
7543 { | 7100 { |
7544 tree id = c_parser_peek_token (parser)->value; | 7101 tree id = c_parser_peek_token (parser)->value; |
7545 tree proto = NULL_TREE; | 7102 tree proto = NULL_TREE; |
7546 c_parser_consume_token (parser); | 7103 c_parser_consume_token (parser); |
7547 if (c_parser_next_token_is (parser, CPP_LESS)) | 7104 if (c_parser_next_token_is (parser, CPP_LESS)) |
7548 proto = c_parser_objc_protocol_refs (parser); | 7105 proto = c_parser_objc_protocol_refs (parser); |
7549 parser->objc_pq_context = true; | 7106 parser->objc_pq_context = true; |
7550 objc_start_protocol (id, proto, attributes); | 7107 objc_start_protocol (id, proto, attributes); |
7551 c_parser_objc_methodprotolist (parser); | 7108 c_parser_objc_methodprotolist (parser); |
7552 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); | 7109 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); |
7553 parser->objc_pq_context = false; | 7110 parser->objc_pq_context = false; |
7598 | 7155 |
7599 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | 7156 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
7600 { | 7157 { |
7601 c_parser_consume_token (parser); | 7158 c_parser_consume_token (parser); |
7602 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic, | 7159 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic, |
7603 "extra semicolon in method definition specified"); | 7160 "extra semicolon in method definition specified"); |
7604 } | 7161 } |
7605 | 7162 |
7606 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | 7163 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
7607 { | 7164 { |
7608 c_parser_error (parser, "expected %<{%>"); | 7165 c_parser_error (parser, "expected %<{%>"); |
7841 } | 7398 } |
7842 | 7399 |
7843 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ; | 7400 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ; |
7844 | 7401 |
7845 /* Parse the optional parameter list. Optional Objective-C | 7402 /* Parse the optional parameter list. Optional Objective-C |
7846 method parameters follow the C syntax, and may include '...' | 7403 method parameters follow the C syntax, and may include '...' |
7847 to denote a variable number of arguments. */ | 7404 to denote a variable number of arguments. */ |
7848 parms = make_node (TREE_LIST); | 7405 parms = make_node (TREE_LIST); |
7849 while (c_parser_next_token_is (parser, CPP_COMMA)) | 7406 while (c_parser_next_token_is (parser, CPP_COMMA)) |
7850 { | 7407 { |
7851 struct c_parm *parm; | 7408 struct c_parm *parm; |
7852 c_parser_consume_token (parser); | 7409 c_parser_consume_token (parser); |
7914 { | 7471 { |
7915 quals = chainon (build_tree_list (NULL_TREE, token->value), quals); | 7472 quals = chainon (build_tree_list (NULL_TREE, token->value), quals); |
7916 c_parser_consume_token (parser); | 7473 c_parser_consume_token (parser); |
7917 } | 7474 } |
7918 else | 7475 else |
7919 break; | 7476 break; |
7920 } | 7477 } |
7921 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type)) | 7478 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type)) |
7922 type_name = c_parser_type_name (parser); | 7479 type_name = c_parser_type_name (parser); |
7923 if (type_name) | 7480 if (type_name) |
7924 type = groktypename (type_name, NULL, NULL); | 7481 type = groktypename (type_name, NULL, NULL); |
7949 here. */ | 7506 here. */ |
7950 while (true) | 7507 while (true) |
7951 { | 7508 { |
7952 tree id; | 7509 tree id; |
7953 if (c_parser_next_token_is_not (parser, CPP_NAME)) | 7510 if (c_parser_next_token_is_not (parser, CPP_NAME)) |
7954 { | 7511 { |
7955 c_parser_error (parser, "expected identifier"); | 7512 c_parser_error (parser, "expected identifier"); |
7956 break; | 7513 break; |
7957 } | 7514 } |
7958 id = c_parser_peek_token (parser)->value; | 7515 id = c_parser_peek_token (parser)->value; |
7959 list = chainon (list, build_tree_list (NULL_TREE, id)); | 7516 list = chainon (list, build_tree_list (NULL_TREE, id)); |
7960 c_parser_consume_token (parser); | 7517 c_parser_consume_token (parser); |
7961 if (c_parser_next_token_is (parser, CPP_COMMA)) | 7518 if (c_parser_next_token_is (parser, CPP_COMMA)) |
7962 c_parser_consume_token (parser); | 7519 c_parser_consume_token (parser); |
7963 else | 7520 else |
7964 break; | 7521 break; |
7965 } | 7522 } |
7966 c_parser_require (parser, CPP_GREATER, "expected %<>%>"); | 7523 c_parser_require (parser, CPP_GREATER, "expected %<>%>"); |
7967 return list; | 7524 return list; |
7968 } | 7525 } |
7969 | 7526 |
8048 all (ie, they typed "@catch NSException *e"). So, just | 7605 all (ie, they typed "@catch NSException *e"). So, just |
8049 forget about the closing parenthesis and keep going. */ | 7606 forget about the closing parenthesis and keep going. */ |
8050 } | 7607 } |
8051 objc_begin_catch_clause (parameter_declaration); | 7608 objc_begin_catch_clause (parameter_declaration); |
8052 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) | 7609 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) |
8053 c_parser_compound_statement_nostart (parser); | 7610 c_parser_compound_statement_nostart (parser); |
8054 objc_finish_catch_clause (); | 7611 objc_finish_catch_clause (); |
8055 } | 7612 } |
8056 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY)) | 7613 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY)) |
8057 { | 7614 { |
8058 c_parser_consume_token (parser); | 7615 c_parser_consume_token (parser); |
8188 if (sel && c_parser_next_token_is_not (parser, CPP_COLON)) | 7745 if (sel && c_parser_next_token_is_not (parser, CPP_COLON)) |
8189 return sel; | 7746 return sel; |
8190 while (true) | 7747 while (true) |
8191 { | 7748 { |
8192 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) | 7749 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
8193 return list; | 7750 return list; |
8194 list = chainon (list, build_tree_list (sel, NULL_TREE)); | 7751 list = chainon (list, build_tree_list (sel, NULL_TREE)); |
8195 sel = c_parser_objc_selector (parser); | 7752 sel = c_parser_objc_selector (parser); |
8196 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON)) | 7753 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON)) |
8197 break; | 7754 break; |
8198 } | 7755 } |
8199 return list; | 7756 return list; |
8200 } | 7757 } |
8201 | 7758 |
8202 /* Parse an objc-receiver. | 7759 /* Parse an objc-receiver. |
8210 static tree | 7767 static tree |
8211 c_parser_objc_receiver (c_parser *parser) | 7768 c_parser_objc_receiver (c_parser *parser) |
8212 { | 7769 { |
8213 if (c_parser_peek_token (parser)->type == CPP_NAME | 7770 if (c_parser_peek_token (parser)->type == CPP_NAME |
8214 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME | 7771 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME |
8215 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)) | 7772 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)) |
8216 { | 7773 { |
8217 tree id = c_parser_peek_token (parser)->value; | 7774 tree id = c_parser_peek_token (parser)->value; |
8218 c_parser_consume_token (parser); | 7775 c_parser_consume_token (parser); |
8219 return objc_get_class_reference (id); | 7776 return objc_get_class_reference (id); |
8220 } | 7777 } |
8245 return sel; | 7802 return sel; |
8246 while (true) | 7803 while (true) |
8247 { | 7804 { |
8248 tree keywordexpr; | 7805 tree keywordexpr; |
8249 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) | 7806 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
8250 return error_mark_node; | 7807 return error_mark_node; |
8251 keywordexpr = c_parser_objc_keywordexpr (parser); | 7808 keywordexpr = c_parser_objc_keywordexpr (parser); |
8252 list = chainon (list, build_tree_list (sel, keywordexpr)); | 7809 list = chainon (list, build_tree_list (sel, keywordexpr)); |
8253 sel = c_parser_objc_selector (parser); | 7810 sel = c_parser_objc_selector (parser); |
8254 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON)) | 7811 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON)) |
8255 break; | 7812 break; |
8256 } | 7813 } |
8257 return list; | 7814 return list; |
8258 } | 7815 } |
8259 | 7816 |
8260 /* Parse an objc-keywordexpr. | 7817 /* Parse an objc-keywordexpr. |
8269 tree ret; | 7826 tree ret; |
8270 VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL); | 7827 VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL); |
8271 if (VEC_length (tree, expr_list) == 1) | 7828 if (VEC_length (tree, expr_list) == 1) |
8272 { | 7829 { |
8273 /* Just return the expression, remove a level of | 7830 /* Just return the expression, remove a level of |
8274 indirection. */ | 7831 indirection. */ |
8275 ret = VEC_index (tree, expr_list, 0); | 7832 ret = VEC_index (tree, expr_list, 0); |
8276 } | 7833 } |
8277 else | 7834 else |
8278 { | 7835 { |
8279 /* We have a comma expression, we will collapse later. */ | 7836 /* We have a comma expression, we will collapse later. */ |
8615 | 8172 |
8616 switch (id) | 8173 switch (id) |
8617 { | 8174 { |
8618 case PRAGMA_OMP_BARRIER: | 8175 case PRAGMA_OMP_BARRIER: |
8619 if (context != pragma_compound) | 8176 if (context != pragma_compound) |
8620 { | 8177 { |
8621 if (context == pragma_stmt) | 8178 if (context == pragma_stmt) |
8622 c_parser_error (parser, "%<#pragma omp barrier%> may only be " | 8179 c_parser_error (parser, "%<#pragma omp barrier%> may only be " |
8623 "used in compound statements"); | 8180 "used in compound statements"); |
8624 goto bad_stmt; | 8181 goto bad_stmt; |
8625 } | 8182 } |
8626 c_parser_omp_barrier (parser); | 8183 c_parser_omp_barrier (parser); |
8627 return false; | 8184 return false; |
8628 | 8185 |
8629 case PRAGMA_OMP_FLUSH: | 8186 case PRAGMA_OMP_FLUSH: |
8630 if (context != pragma_compound) | 8187 if (context != pragma_compound) |
8631 { | 8188 { |
8632 if (context == pragma_stmt) | 8189 if (context == pragma_stmt) |
8633 c_parser_error (parser, "%<#pragma omp flush%> may only be " | 8190 c_parser_error (parser, "%<#pragma omp flush%> may only be " |
8634 "used in compound statements"); | 8191 "used in compound statements"); |
8635 goto bad_stmt; | 8192 goto bad_stmt; |
8636 } | 8193 } |
8637 c_parser_omp_flush (parser); | 8194 c_parser_omp_flush (parser); |
8638 return false; | 8195 return false; |
8639 | 8196 |
8640 case PRAGMA_OMP_TASKWAIT: | 8197 case PRAGMA_OMP_TASKWAIT: |
8641 if (context != pragma_compound) | 8198 if (context != pragma_compound) |
8642 { | 8199 { |
8643 if (context == pragma_stmt) | 8200 if (context == pragma_stmt) |
8644 c_parser_error (parser, "%<#pragma omp taskwait%> may only be " | 8201 c_parser_error (parser, "%<#pragma omp taskwait%> may only be " |
8645 "used in compound statements"); | 8202 "used in compound statements"); |
8646 goto bad_stmt; | 8203 goto bad_stmt; |
8647 } | 8204 } |
8648 c_parser_omp_taskwait (parser); | 8205 c_parser_omp_taskwait (parser); |
8649 return false; | 8206 return false; |
8650 | 8207 |
8651 case PRAGMA_OMP_THREADPRIVATE: | 8208 case PRAGMA_OMP_THREADPRIVATE: |
8652 c_parser_omp_threadprivate (parser); | 8209 c_parser_omp_threadprivate (parser); |
8653 return false; | 8210 return false; |
8654 | 8211 |
8655 case PRAGMA_OMP_SECTION: | 8212 case PRAGMA_OMP_SECTION: |
8656 error_at (c_parser_peek_token (parser)->location, | 8213 error_at (c_parser_peek_token (parser)->location, |
8657 "%<#pragma omp section%> may only be used in " | 8214 "%<#pragma omp section%> may only be used in " |
8658 "%<#pragma omp sections%> construct"); | 8215 "%<#pragma omp sections%> construct"); |
8659 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); | 8216 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
8660 return false; | 8217 return false; |
8661 | 8218 |
8662 case PRAGMA_GCC_PCH_PREPROCESS: | 8219 case PRAGMA_GCC_PCH_PREPROCESS: |
8663 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first"); | 8220 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first"); |
8664 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); | 8221 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
8665 return false; | 8222 return false; |
8666 | 8223 |
8667 default: | 8224 default: |
8668 if (id < PRAGMA_FIRST_EXTERNAL) | 8225 if (id < PRAGMA_FIRST_EXTERNAL) |
8669 { | 8226 { |
8670 if (context == pragma_external) | 8227 if (context == pragma_external) |
8671 { | 8228 { |
8672 bad_stmt: | 8229 bad_stmt: |
8673 c_parser_error (parser, "expected declaration specifiers"); | 8230 c_parser_error (parser, "expected declaration specifiers"); |
8674 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); | 8231 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
8675 return false; | 8232 return false; |
8676 } | 8233 } |
8677 c_parser_omp_construct (parser); | 8234 c_parser_omp_construct (parser); |
8678 return true; | 8235 return true; |
8679 } | 8236 } |
8680 break; | 8237 break; |
8681 } | 8238 } |
8682 | 8239 |
8683 c_parser_consume_pragma (parser); | 8240 c_parser_consume_pragma (parser); |
8684 c_invoke_pragma_handler (id); | 8241 c_invoke_pragma_handler (id); |
8704 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF) | 8261 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF) |
8705 ret = CPP_EOF; | 8262 ret = CPP_EOF; |
8706 else | 8263 else |
8707 { | 8264 { |
8708 if (ret == CPP_KEYWORD) | 8265 if (ret == CPP_KEYWORD) |
8709 ret = CPP_NAME; | 8266 ret = CPP_NAME; |
8710 c_parser_consume_token (the_parser); | 8267 c_parser_consume_token (the_parser); |
8711 } | 8268 } |
8712 | 8269 |
8713 return ret; | 8270 return ret; |
8714 } | 8271 } |
8751 else if (c_parser_next_token_is (parser, CPP_NAME)) | 8308 else if (c_parser_next_token_is (parser, CPP_NAME)) |
8752 { | 8309 { |
8753 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | 8310 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
8754 | 8311 |
8755 switch (p[0]) | 8312 switch (p[0]) |
8756 { | 8313 { |
8757 case 'c': | 8314 case 'c': |
8758 if (!strcmp ("collapse", p)) | 8315 if (!strcmp ("collapse", p)) |
8759 result = PRAGMA_OMP_CLAUSE_COLLAPSE; | 8316 result = PRAGMA_OMP_CLAUSE_COLLAPSE; |
8760 else if (!strcmp ("copyin", p)) | 8317 else if (!strcmp ("copyin", p)) |
8761 result = PRAGMA_OMP_CLAUSE_COPYIN; | 8318 result = PRAGMA_OMP_CLAUSE_COPYIN; |
8762 else if (!strcmp ("copyprivate", p)) | 8319 else if (!strcmp ("copyprivate", p)) |
8763 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE; | 8320 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE; |
8764 break; | 8321 break; |
8765 case 'f': | 8322 case 'f': |
8766 if (!strcmp ("firstprivate", p)) | 8323 if (!strcmp ("firstprivate", p)) |
8767 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE; | 8324 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE; |
8768 break; | 8325 break; |
8769 case 'l': | 8326 case 'l': |
8770 if (!strcmp ("lastprivate", p)) | 8327 if (!strcmp ("lastprivate", p)) |
8771 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE; | 8328 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE; |
8772 break; | 8329 break; |
8773 case 'n': | 8330 case 'n': |
8774 if (!strcmp ("nowait", p)) | 8331 if (!strcmp ("nowait", p)) |
8775 result = PRAGMA_OMP_CLAUSE_NOWAIT; | 8332 result = PRAGMA_OMP_CLAUSE_NOWAIT; |
8776 else if (!strcmp ("num_threads", p)) | 8333 else if (!strcmp ("num_threads", p)) |
8777 result = PRAGMA_OMP_CLAUSE_NUM_THREADS; | 8334 result = PRAGMA_OMP_CLAUSE_NUM_THREADS; |
8778 break; | 8335 break; |
8779 case 'o': | 8336 case 'o': |
8780 if (!strcmp ("ordered", p)) | 8337 if (!strcmp ("ordered", p)) |
8781 result = PRAGMA_OMP_CLAUSE_ORDERED; | 8338 result = PRAGMA_OMP_CLAUSE_ORDERED; |
8782 break; | 8339 break; |
8783 case 'p': | 8340 case 'p': |
8784 if (!strcmp ("private", p)) | 8341 if (!strcmp ("private", p)) |
8785 result = PRAGMA_OMP_CLAUSE_PRIVATE; | 8342 result = PRAGMA_OMP_CLAUSE_PRIVATE; |
8786 break; | 8343 break; |
8787 case 'r': | 8344 case 'r': |
8788 if (!strcmp ("reduction", p)) | 8345 if (!strcmp ("reduction", p)) |
8789 result = PRAGMA_OMP_CLAUSE_REDUCTION; | 8346 result = PRAGMA_OMP_CLAUSE_REDUCTION; |
8790 break; | 8347 break; |
8791 case 's': | 8348 case 's': |
8792 if (!strcmp ("schedule", p)) | 8349 if (!strcmp ("schedule", p)) |
8793 result = PRAGMA_OMP_CLAUSE_SCHEDULE; | 8350 result = PRAGMA_OMP_CLAUSE_SCHEDULE; |
8794 else if (!strcmp ("shared", p)) | 8351 else if (!strcmp ("shared", p)) |
8795 result = PRAGMA_OMP_CLAUSE_SHARED; | 8352 result = PRAGMA_OMP_CLAUSE_SHARED; |
8796 break; | 8353 break; |
8797 case 'u': | 8354 case 'u': |
8798 if (!strcmp ("untied", p)) | 8355 if (!strcmp ("untied", p)) |
8799 result = PRAGMA_OMP_CLAUSE_UNTIED; | 8356 result = PRAGMA_OMP_CLAUSE_UNTIED; |
8800 break; | 8357 break; |
8801 } | 8358 } |
8802 } | 8359 } |
8803 | 8360 |
8804 if (result != PRAGMA_OMP_CLAUSE_NONE) | 8361 if (result != PRAGMA_OMP_CLAUSE_NONE) |
8805 c_parser_consume_token (parser); | 8362 c_parser_consume_token (parser); |
8806 | 8363 |
8809 | 8366 |
8810 /* Validate that a clause of the given type does not already exist. */ | 8367 /* Validate that a clause of the given type does not already exist. */ |
8811 | 8368 |
8812 static void | 8369 static void |
8813 check_no_duplicate_clause (tree clauses, enum omp_clause_code code, | 8370 check_no_duplicate_clause (tree clauses, enum omp_clause_code code, |
8814 const char *name) | 8371 const char *name) |
8815 { | 8372 { |
8816 tree c; | 8373 tree c; |
8817 | 8374 |
8818 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c)) | 8375 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c)) |
8819 if (OMP_CLAUSE_CODE (c) == code) | 8376 if (OMP_CLAUSE_CODE (c) == code) |
8820 { | 8377 { |
8821 location_t loc = OMP_CLAUSE_LOCATION (c); | 8378 location_t loc = OMP_CLAUSE_LOCATION (c); |
8822 error_at (loc, "too many %qs clauses", name); | 8379 error_at (loc, "too many %qs clauses", name); |
8823 break; | 8380 break; |
8824 } | 8381 } |
8825 } | 8382 } |
8826 | 8383 |
8827 /* OpenMP 2.5: | 8384 /* OpenMP 2.5: |
8828 variable-list: | 8385 variable-list: |
8836 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE; | 8393 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE; |
8837 return the list created. */ | 8394 return the list created. */ |
8838 | 8395 |
8839 static tree | 8396 static tree |
8840 c_parser_omp_variable_list (c_parser *parser, | 8397 c_parser_omp_variable_list (c_parser *parser, |
8841 location_t clause_loc, | 8398 location_t clause_loc, |
8842 enum omp_clause_code kind, | 8399 enum omp_clause_code kind, |
8843 tree list) | 8400 tree list) |
8844 { | 8401 { |
8845 if (c_parser_next_token_is_not (parser, CPP_NAME) | 8402 if (c_parser_next_token_is_not (parser, CPP_NAME) |
8846 || c_parser_peek_token (parser)->id_kind != C_ID_ID) | 8403 || c_parser_peek_token (parser)->id_kind != C_ID_ID) |
8847 c_parser_error (parser, "expected identifier"); | 8404 c_parser_error (parser, "expected identifier"); |
8848 | 8405 |
8849 while (c_parser_next_token_is (parser, CPP_NAME) | 8406 while (c_parser_next_token_is (parser, CPP_NAME) |
8850 && c_parser_peek_token (parser)->id_kind == C_ID_ID) | 8407 && c_parser_peek_token (parser)->id_kind == C_ID_ID) |
8851 { | 8408 { |
8852 tree t = lookup_name (c_parser_peek_token (parser)->value); | 8409 tree t = lookup_name (c_parser_peek_token (parser)->value); |
8853 | 8410 |
8854 if (t == NULL_TREE) | 8411 if (t == NULL_TREE) |
8855 undeclared_variable (c_parser_peek_token (parser)->location, | 8412 undeclared_variable (c_parser_peek_token (parser)->location, |
8856 c_parser_peek_token (parser)->value); | 8413 c_parser_peek_token (parser)->value); |
8857 else if (t == error_mark_node) | 8414 else if (t == error_mark_node) |
8858 ; | 8415 ; |
8859 else if (kind != 0) | 8416 else if (kind != 0) |
8860 { | 8417 { |
8861 tree u = build_omp_clause (clause_loc, kind); | 8418 tree u = build_omp_clause (clause_loc, kind); |
8862 OMP_CLAUSE_DECL (u) = t; | 8419 OMP_CLAUSE_DECL (u) = t; |
8863 OMP_CLAUSE_CHAIN (u) = list; | 8420 OMP_CLAUSE_CHAIN (u) = list; |
8864 list = u; | 8421 list = u; |
8865 } | 8422 } |
8866 else | 8423 else |
8867 list = tree_cons (t, NULL_TREE, list); | 8424 list = tree_cons (t, NULL_TREE, list); |
8868 | 8425 |
8869 c_parser_consume_token (parser); | 8426 c_parser_consume_token (parser); |
8870 | 8427 |
8871 if (c_parser_next_token_is_not (parser, CPP_COMMA)) | 8428 if (c_parser_next_token_is_not (parser, CPP_COMMA)) |
8872 break; | 8429 break; |
8873 | 8430 |
8874 c_parser_consume_token (parser); | 8431 c_parser_consume_token (parser); |
8875 } | 8432 } |
8876 | 8433 |
8877 return list; | 8434 return list; |
8880 /* Similarly, but expect leading and trailing parenthesis. This is a very | 8437 /* Similarly, but expect leading and trailing parenthesis. This is a very |
8881 common case for omp clauses. */ | 8438 common case for omp clauses. */ |
8882 | 8439 |
8883 static tree | 8440 static tree |
8884 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind, | 8441 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind, |
8885 tree list) | 8442 tree list) |
8886 { | 8443 { |
8887 /* The clauses location. */ | 8444 /* The clauses location. */ |
8888 location_t loc = c_parser_peek_token (parser)->location; | 8445 location_t loc = c_parser_peek_token (parser)->location; |
8889 | 8446 |
8890 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | 8447 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
8919 || !host_integerp (num, 0) | 8476 || !host_integerp (num, 0) |
8920 || (n = tree_low_cst (num, 0)) <= 0 | 8477 || (n = tree_low_cst (num, 0)) <= 0 |
8921 || (int) n != n) | 8478 || (int) n != n) |
8922 { | 8479 { |
8923 error_at (loc, | 8480 error_at (loc, |
8924 "collapse argument needs positive constant integer expression"); | 8481 "collapse argument needs positive constant integer expression"); |
8925 return list; | 8482 return list; |
8926 } | 8483 } |
8927 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE); | 8484 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE); |
8928 OMP_CLAUSE_COLLAPSE_EXPR (c) = num; | 8485 OMP_CLAUSE_COLLAPSE_EXPR (c) = num; |
8929 OMP_CLAUSE_CHAIN (c) = list; | 8486 OMP_CLAUSE_CHAIN (c) = list; |
8963 if (c_parser_next_token_is (parser, CPP_NAME)) | 8520 if (c_parser_next_token_is (parser, CPP_NAME)) |
8964 { | 8521 { |
8965 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | 8522 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
8966 | 8523 |
8967 switch (p[0]) | 8524 switch (p[0]) |
8968 { | 8525 { |
8969 case 'n': | 8526 case 'n': |
8970 if (strcmp ("none", p) != 0) | 8527 if (strcmp ("none", p) != 0) |
8971 goto invalid_kind; | 8528 goto invalid_kind; |
8972 kind = OMP_CLAUSE_DEFAULT_NONE; | 8529 kind = OMP_CLAUSE_DEFAULT_NONE; |
8973 break; | 8530 break; |
8974 | 8531 |
8975 case 's': | 8532 case 's': |
8976 if (strcmp ("shared", p) != 0) | 8533 if (strcmp ("shared", p) != 0) |
8977 goto invalid_kind; | 8534 goto invalid_kind; |
8978 kind = OMP_CLAUSE_DEFAULT_SHARED; | 8535 kind = OMP_CLAUSE_DEFAULT_SHARED; |
8979 break; | 8536 break; |
8980 | 8537 |
8981 default: | 8538 default: |
8982 goto invalid_kind; | 8539 goto invalid_kind; |
8983 } | 8540 } |
8984 | 8541 |
8985 c_parser_consume_token (parser); | 8542 c_parser_consume_token (parser); |
8986 } | 8543 } |
8987 else | 8544 else |
8988 { | 8545 { |
9075 t = c_fully_fold (t, false, NULL); | 8632 t = c_fully_fold (t, false, NULL); |
9076 | 8633 |
9077 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | 8634 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
9078 | 8635 |
9079 if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) | 8636 if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
9080 { | 8637 { |
9081 c_parser_error (parser, "expected integer expression"); | 8638 c_parser_error (parser, "expected integer expression"); |
9082 return list; | 8639 return list; |
9083 } | 8640 } |
9084 | 8641 |
9085 /* Attempt to statically determine when the number isn't positive. */ | 8642 /* Attempt to statically determine when the number isn't positive. */ |
9086 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, | 8643 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, |
9087 build_int_cst (TREE_TYPE (t), 0)); | 8644 build_int_cst (TREE_TYPE (t), 0)); |
9088 if (CAN_HAVE_LOCATION_P (c)) | 8645 if (CAN_HAVE_LOCATION_P (c)) |
9089 SET_EXPR_LOCATION (c, expr_loc); | 8646 SET_EXPR_LOCATION (c, expr_loc); |
9090 if (c == boolean_true_node) | 8647 if (c == boolean_true_node) |
9091 { | 8648 { |
9092 warning_at (expr_loc, 0, | 8649 warning_at (expr_loc, 0, |
9093 "%<num_threads%> value must be positive"); | 8650 "%<num_threads%> value must be positive"); |
9094 t = integer_one_node; | 8651 t = integer_one_node; |
9095 } | 8652 } |
9096 | 8653 |
9097 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads"); | 8654 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads"); |
9098 | 8655 |
9099 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS); | 8656 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS); |
9100 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t; | 8657 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t; |
9114 tree c; | 8671 tree c; |
9115 | 8672 |
9116 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered"); | 8673 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered"); |
9117 | 8674 |
9118 c = build_omp_clause (c_parser_peek_token (parser)->location, | 8675 c = build_omp_clause (c_parser_peek_token (parser)->location, |
9119 OMP_CLAUSE_ORDERED); | 8676 OMP_CLAUSE_ORDERED); |
9120 OMP_CLAUSE_CHAIN (c) = list; | 8677 OMP_CLAUSE_CHAIN (c) = list; |
9121 | 8678 |
9122 return c; | 8679 return c; |
9123 } | 8680 } |
9124 | 8681 |
9144 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | 8701 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
9145 { | 8702 { |
9146 enum tree_code code; | 8703 enum tree_code code; |
9147 | 8704 |
9148 switch (c_parser_peek_token (parser)->type) | 8705 switch (c_parser_peek_token (parser)->type) |
9149 { | 8706 { |
9150 case CPP_PLUS: | 8707 case CPP_PLUS: |
9151 code = PLUS_EXPR; | 8708 code = PLUS_EXPR; |
9152 break; | 8709 break; |
9153 case CPP_MULT: | 8710 case CPP_MULT: |
9154 code = MULT_EXPR; | 8711 code = MULT_EXPR; |
9155 break; | 8712 break; |
9156 case CPP_MINUS: | 8713 case CPP_MINUS: |
9157 code = MINUS_EXPR; | 8714 code = MINUS_EXPR; |
9158 break; | 8715 break; |
9159 case CPP_AND: | 8716 case CPP_AND: |
9160 code = BIT_AND_EXPR; | 8717 code = BIT_AND_EXPR; |
9161 break; | 8718 break; |
9162 case CPP_XOR: | 8719 case CPP_XOR: |
9163 code = BIT_XOR_EXPR; | 8720 code = BIT_XOR_EXPR; |
9164 break; | 8721 break; |
9165 case CPP_OR: | 8722 case CPP_OR: |
9166 code = BIT_IOR_EXPR; | 8723 code = BIT_IOR_EXPR; |
9167 break; | 8724 break; |
9168 case CPP_AND_AND: | 8725 case CPP_AND_AND: |
9169 code = TRUTH_ANDIF_EXPR; | 8726 code = TRUTH_ANDIF_EXPR; |
9170 break; | 8727 break; |
9171 case CPP_OR_OR: | 8728 case CPP_OR_OR: |
9172 code = TRUTH_ORIF_EXPR; | 8729 code = TRUTH_ORIF_EXPR; |
9173 break; | 8730 break; |
9174 default: | 8731 default: |
9175 c_parser_error (parser, | 8732 c_parser_error (parser, |
9176 "expected %<+%>, %<*%>, %<-%>, %<&%>, " | 8733 "expected %<+%>, %<*%>, %<-%>, %<&%>, " |
9177 "%<^%>, %<|%>, %<&&%>, or %<||%>"); | 8734 "%<^%>, %<|%>, %<&&%>, or %<||%>"); |
9178 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); | 8735 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); |
9179 return list; | 8736 return list; |
9180 } | 8737 } |
9181 c_parser_consume_token (parser); | 8738 c_parser_consume_token (parser); |
9182 if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) | 8739 if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
9183 { | 8740 { |
9184 tree nl, c; | 8741 tree nl, c; |
9185 | 8742 |
9186 nl = c_parser_omp_variable_list (parser, clause_loc, | 8743 nl = c_parser_omp_variable_list (parser, clause_loc, |
9187 OMP_CLAUSE_REDUCTION, list); | 8744 OMP_CLAUSE_REDUCTION, list); |
9188 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) | 8745 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
9189 OMP_CLAUSE_REDUCTION_CODE (c) = code; | 8746 OMP_CLAUSE_REDUCTION_CODE (c) = code; |
9190 | 8747 |
9191 list = nl; | 8748 list = nl; |
9192 } | 8749 } |
9193 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | 8750 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
9194 } | 8751 } |
9195 return list; | 8752 return list; |
9196 } | 8753 } |
9197 | 8754 |
9218 { | 8775 { |
9219 tree kind = c_parser_peek_token (parser)->value; | 8776 tree kind = c_parser_peek_token (parser)->value; |
9220 const char *p = IDENTIFIER_POINTER (kind); | 8777 const char *p = IDENTIFIER_POINTER (kind); |
9221 | 8778 |
9222 switch (p[0]) | 8779 switch (p[0]) |
9223 { | 8780 { |
9224 case 'd': | 8781 case 'd': |
9225 if (strcmp ("dynamic", p) != 0) | 8782 if (strcmp ("dynamic", p) != 0) |
9226 goto invalid_kind; | 8783 goto invalid_kind; |
9227 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC; | 8784 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC; |
9228 break; | 8785 break; |
9229 | 8786 |
9230 case 'g': | 8787 case 'g': |
9231 if (strcmp ("guided", p) != 0) | 8788 if (strcmp ("guided", p) != 0) |
9232 goto invalid_kind; | 8789 goto invalid_kind; |
9233 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED; | 8790 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED; |
9234 break; | 8791 break; |
9235 | 8792 |
9236 case 'r': | 8793 case 'r': |
9237 if (strcmp ("runtime", p) != 0) | 8794 if (strcmp ("runtime", p) != 0) |
9238 goto invalid_kind; | 8795 goto invalid_kind; |
9239 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME; | 8796 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME; |
9240 break; | 8797 break; |
9241 | 8798 |
9242 default: | 8799 default: |
9243 goto invalid_kind; | 8800 goto invalid_kind; |
9244 } | 8801 } |
9245 } | 8802 } |
9246 else if (c_parser_next_token_is_keyword (parser, RID_STATIC)) | 8803 else if (c_parser_next_token_is_keyword (parser, RID_STATIC)) |
9247 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC; | 8804 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC; |
9248 else if (c_parser_next_token_is_keyword (parser, RID_AUTO)) | 8805 else if (c_parser_next_token_is_keyword (parser, RID_AUTO)) |
9249 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO; | 8806 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO; |
9259 here = c_parser_peek_token (parser)->location; | 8816 here = c_parser_peek_token (parser)->location; |
9260 t = c_parser_expr_no_commas (parser, NULL).value; | 8817 t = c_parser_expr_no_commas (parser, NULL).value; |
9261 t = c_fully_fold (t, false, NULL); | 8818 t = c_fully_fold (t, false, NULL); |
9262 | 8819 |
9263 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME) | 8820 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME) |
9264 error_at (here, "schedule %<runtime%> does not take " | 8821 error_at (here, "schedule %<runtime%> does not take " |
9265 "a %<chunk_size%> parameter"); | 8822 "a %<chunk_size%> parameter"); |
9266 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO) | 8823 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO) |
9267 error_at (here, | 8824 error_at (here, |
9268 "schedule %<auto%> does not take " | 8825 "schedule %<auto%> does not take " |
9269 "a %<chunk_size%> parameter"); | 8826 "a %<chunk_size%> parameter"); |
9270 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE) | 8827 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE) |
9271 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t; | 8828 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t; |
9272 else | 8829 else |
9273 c_parser_error (parser, "expected integer expression"); | 8830 c_parser_error (parser, "expected integer expression"); |
9274 | 8831 |
9275 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | 8832 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
9276 } | 8833 } |
9277 else | 8834 else |
9278 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | 8835 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
9279 "expected %<,%> or %<)%>"); | 8836 "expected %<,%> or %<)%>"); |
9280 | 8837 |
9281 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule"); | 8838 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule"); |
9282 OMP_CLAUSE_CHAIN (c) = list; | 8839 OMP_CLAUSE_CHAIN (c) = list; |
9283 return c; | 8840 return c; |
9284 | 8841 |
9307 | 8864 |
9308 /* FIXME: Should we allow duplicates? */ | 8865 /* FIXME: Should we allow duplicates? */ |
9309 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied"); | 8866 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied"); |
9310 | 8867 |
9311 c = build_omp_clause (c_parser_peek_token (parser)->location, | 8868 c = build_omp_clause (c_parser_peek_token (parser)->location, |
9312 OMP_CLAUSE_UNTIED); | 8869 OMP_CLAUSE_UNTIED); |
9313 OMP_CLAUSE_CHAIN (c) = list; | 8870 OMP_CLAUSE_CHAIN (c) = list; |
9314 | 8871 |
9315 return c; | 8872 return c; |
9316 } | 8873 } |
9317 | 8874 |
9319 is a bitmask in MASK. Return the list of clauses found; the result | 8876 is a bitmask in MASK. Return the list of clauses found; the result |
9320 of clause default goes in *pdefault. */ | 8877 of clause default goes in *pdefault. */ |
9321 | 8878 |
9322 static tree | 8879 static tree |
9323 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask, | 8880 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask, |
9324 const char *where) | 8881 const char *where) |
9325 { | 8882 { |
9326 tree clauses = NULL; | 8883 tree clauses = NULL; |
9327 bool first = true; | 8884 bool first = true; |
9328 | 8885 |
9329 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | 8886 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
9332 pragma_omp_clause c_kind; | 8889 pragma_omp_clause c_kind; |
9333 const char *c_name; | 8890 const char *c_name; |
9334 tree prev = clauses; | 8891 tree prev = clauses; |
9335 | 8892 |
9336 if (!first && c_parser_next_token_is (parser, CPP_COMMA)) | 8893 if (!first && c_parser_next_token_is (parser, CPP_COMMA)) |
9337 c_parser_consume_token (parser); | 8894 c_parser_consume_token (parser); |
9338 | 8895 |
9339 first = false; | 8896 first = false; |
9340 here = c_parser_peek_token (parser)->location; | 8897 here = c_parser_peek_token (parser)->location; |
9341 c_kind = c_parser_omp_clause_name (parser); | 8898 c_kind = c_parser_omp_clause_name (parser); |
9342 | 8899 |
9343 switch (c_kind) | 8900 switch (c_kind) |
9344 { | 8901 { |
9345 case PRAGMA_OMP_CLAUSE_COLLAPSE: | 8902 case PRAGMA_OMP_CLAUSE_COLLAPSE: |
9346 clauses = c_parser_omp_clause_collapse (parser, clauses); | 8903 clauses = c_parser_omp_clause_collapse (parser, clauses); |
9347 c_name = "collapse"; | 8904 c_name = "collapse"; |
9348 break; | 8905 break; |
9349 case PRAGMA_OMP_CLAUSE_COPYIN: | 8906 case PRAGMA_OMP_CLAUSE_COPYIN: |
9350 clauses = c_parser_omp_clause_copyin (parser, clauses); | 8907 clauses = c_parser_omp_clause_copyin (parser, clauses); |
9351 c_name = "copyin"; | 8908 c_name = "copyin"; |
9352 break; | 8909 break; |
9353 case PRAGMA_OMP_CLAUSE_COPYPRIVATE: | 8910 case PRAGMA_OMP_CLAUSE_COPYPRIVATE: |
9354 clauses = c_parser_omp_clause_copyprivate (parser, clauses); | 8911 clauses = c_parser_omp_clause_copyprivate (parser, clauses); |
9355 c_name = "copyprivate"; | 8912 c_name = "copyprivate"; |
9356 break; | 8913 break; |
9357 case PRAGMA_OMP_CLAUSE_DEFAULT: | 8914 case PRAGMA_OMP_CLAUSE_DEFAULT: |
9358 clauses = c_parser_omp_clause_default (parser, clauses); | 8915 clauses = c_parser_omp_clause_default (parser, clauses); |
9359 c_name = "default"; | 8916 c_name = "default"; |
9360 break; | 8917 break; |
9361 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE: | 8918 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE: |
9362 clauses = c_parser_omp_clause_firstprivate (parser, clauses); | 8919 clauses = c_parser_omp_clause_firstprivate (parser, clauses); |
9363 c_name = "firstprivate"; | 8920 c_name = "firstprivate"; |
9364 break; | 8921 break; |
9365 case PRAGMA_OMP_CLAUSE_IF: | 8922 case PRAGMA_OMP_CLAUSE_IF: |
9366 clauses = c_parser_omp_clause_if (parser, clauses); | 8923 clauses = c_parser_omp_clause_if (parser, clauses); |
9367 c_name = "if"; | 8924 c_name = "if"; |
9368 break; | 8925 break; |
9369 case PRAGMA_OMP_CLAUSE_LASTPRIVATE: | 8926 case PRAGMA_OMP_CLAUSE_LASTPRIVATE: |
9370 clauses = c_parser_omp_clause_lastprivate (parser, clauses); | 8927 clauses = c_parser_omp_clause_lastprivate (parser, clauses); |
9371 c_name = "lastprivate"; | 8928 c_name = "lastprivate"; |
9372 break; | 8929 break; |
9373 case PRAGMA_OMP_CLAUSE_NOWAIT: | 8930 case PRAGMA_OMP_CLAUSE_NOWAIT: |
9374 clauses = c_parser_omp_clause_nowait (parser, clauses); | 8931 clauses = c_parser_omp_clause_nowait (parser, clauses); |
9375 c_name = "nowait"; | 8932 c_name = "nowait"; |
9376 break; | 8933 break; |
9377 case PRAGMA_OMP_CLAUSE_NUM_THREADS: | 8934 case PRAGMA_OMP_CLAUSE_NUM_THREADS: |
9378 clauses = c_parser_omp_clause_num_threads (parser, clauses); | 8935 clauses = c_parser_omp_clause_num_threads (parser, clauses); |
9379 c_name = "num_threads"; | 8936 c_name = "num_threads"; |
9380 break; | 8937 break; |
9381 case PRAGMA_OMP_CLAUSE_ORDERED: | 8938 case PRAGMA_OMP_CLAUSE_ORDERED: |
9382 clauses = c_parser_omp_clause_ordered (parser, clauses); | 8939 clauses = c_parser_omp_clause_ordered (parser, clauses); |
9383 c_name = "ordered"; | 8940 c_name = "ordered"; |
9384 break; | 8941 break; |
9385 case PRAGMA_OMP_CLAUSE_PRIVATE: | 8942 case PRAGMA_OMP_CLAUSE_PRIVATE: |
9386 clauses = c_parser_omp_clause_private (parser, clauses); | 8943 clauses = c_parser_omp_clause_private (parser, clauses); |
9387 c_name = "private"; | 8944 c_name = "private"; |
9388 break; | 8945 break; |
9389 case PRAGMA_OMP_CLAUSE_REDUCTION: | 8946 case PRAGMA_OMP_CLAUSE_REDUCTION: |
9390 clauses = c_parser_omp_clause_reduction (parser, clauses); | 8947 clauses = c_parser_omp_clause_reduction (parser, clauses); |
9391 c_name = "reduction"; | 8948 c_name = "reduction"; |
9392 break; | 8949 break; |
9393 case PRAGMA_OMP_CLAUSE_SCHEDULE: | 8950 case PRAGMA_OMP_CLAUSE_SCHEDULE: |
9394 clauses = c_parser_omp_clause_schedule (parser, clauses); | 8951 clauses = c_parser_omp_clause_schedule (parser, clauses); |
9395 c_name = "schedule"; | 8952 c_name = "schedule"; |
9396 break; | 8953 break; |
9397 case PRAGMA_OMP_CLAUSE_SHARED: | 8954 case PRAGMA_OMP_CLAUSE_SHARED: |
9398 clauses = c_parser_omp_clause_shared (parser, clauses); | 8955 clauses = c_parser_omp_clause_shared (parser, clauses); |
9399 c_name = "shared"; | 8956 c_name = "shared"; |
9400 break; | 8957 break; |
9401 case PRAGMA_OMP_CLAUSE_UNTIED: | 8958 case PRAGMA_OMP_CLAUSE_UNTIED: |
9402 clauses = c_parser_omp_clause_untied (parser, clauses); | 8959 clauses = c_parser_omp_clause_untied (parser, clauses); |
9403 c_name = "untied"; | 8960 c_name = "untied"; |
9404 break; | 8961 break; |
9405 default: | 8962 default: |
9406 c_parser_error (parser, "expected %<#pragma omp%> clause"); | 8963 c_parser_error (parser, "expected %<#pragma omp%> clause"); |
9407 goto saw_error; | 8964 goto saw_error; |
9408 } | 8965 } |
9409 | 8966 |
9410 if (((mask >> c_kind) & 1) == 0 && !parser->error) | 8967 if (((mask >> c_kind) & 1) == 0 && !parser->error) |
9411 { | 8968 { |
9412 /* Remove the invalid clause(s) from the list to avoid | 8969 /* Remove the invalid clause(s) from the list to avoid |
9413 confusing the rest of the compiler. */ | 8970 confusing the rest of the compiler. */ |
9414 clauses = prev; | 8971 clauses = prev; |
9415 error_at (here, "%qs is not valid for %qs", c_name, where); | 8972 error_at (here, "%qs is not valid for %qs", c_name, where); |
9416 } | 8973 } |
9417 } | 8974 } |
9418 | 8975 |
9419 saw_error: | 8976 saw_error: |
9420 c_parser_skip_to_pragma_eol (parser); | 8977 c_parser_skip_to_pragma_eol (parser); |
9421 | 8978 |
9520 } | 9077 } |
9521 } | 9078 } |
9522 /* FALLTHRU */ | 9079 /* FALLTHRU */ |
9523 default: | 9080 default: |
9524 switch (c_parser_peek_token (parser)->type) | 9081 switch (c_parser_peek_token (parser)->type) |
9525 { | 9082 { |
9526 case CPP_MULT_EQ: | 9083 case CPP_MULT_EQ: |
9527 code = MULT_EXPR; | 9084 code = MULT_EXPR; |
9528 break; | 9085 break; |
9529 case CPP_DIV_EQ: | 9086 case CPP_DIV_EQ: |
9530 code = TRUNC_DIV_EXPR; | 9087 code = TRUNC_DIV_EXPR; |
9531 break; | 9088 break; |
9532 case CPP_PLUS_EQ: | 9089 case CPP_PLUS_EQ: |
9533 code = PLUS_EXPR; | 9090 code = PLUS_EXPR; |
9534 break; | 9091 break; |
9535 case CPP_MINUS_EQ: | 9092 case CPP_MINUS_EQ: |
9536 code = MINUS_EXPR; | 9093 code = MINUS_EXPR; |
9537 break; | 9094 break; |
9538 case CPP_LSHIFT_EQ: | 9095 case CPP_LSHIFT_EQ: |
9539 code = LSHIFT_EXPR; | 9096 code = LSHIFT_EXPR; |
9540 break; | 9097 break; |
9541 case CPP_RSHIFT_EQ: | 9098 case CPP_RSHIFT_EQ: |
9542 code = RSHIFT_EXPR; | 9099 code = RSHIFT_EXPR; |
9543 break; | 9100 break; |
9544 case CPP_AND_EQ: | 9101 case CPP_AND_EQ: |
9545 code = BIT_AND_EXPR; | 9102 code = BIT_AND_EXPR; |
9546 break; | 9103 break; |
9547 case CPP_OR_EQ: | 9104 case CPP_OR_EQ: |
9548 code = BIT_IOR_EXPR; | 9105 code = BIT_IOR_EXPR; |
9549 break; | 9106 break; |
9550 case CPP_XOR_EQ: | 9107 case CPP_XOR_EQ: |
9551 code = BIT_XOR_EXPR; | 9108 code = BIT_XOR_EXPR; |
9552 break; | 9109 break; |
9553 default: | 9110 default: |
9554 c_parser_error (parser, | 9111 c_parser_error (parser, |
9555 "invalid operator for %<#pragma omp atomic%>"); | 9112 "invalid operator for %<#pragma omp atomic%>"); |
9556 goto saw_error; | 9113 goto saw_error; |
9557 } | 9114 } |
9558 | 9115 |
9559 /* Arrange to pass the location of the assignment operator to | 9116 /* Arrange to pass the location of the assignment operator to |
9560 c_finish_omp_atomic. */ | 9117 c_finish_omp_atomic. */ |
9561 loc = c_parser_peek_token (parser)->location; | 9118 loc = c_parser_peek_token (parser)->location; |
9562 c_parser_consume_token (parser); | 9119 c_parser_consume_token (parser); |
9603 | 9160 |
9604 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | 9161 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
9605 { | 9162 { |
9606 c_parser_consume_token (parser); | 9163 c_parser_consume_token (parser); |
9607 if (c_parser_next_token_is (parser, CPP_NAME)) | 9164 if (c_parser_next_token_is (parser, CPP_NAME)) |
9608 { | 9165 { |
9609 name = c_parser_peek_token (parser)->value; | 9166 name = c_parser_peek_token (parser)->value; |
9610 c_parser_consume_token (parser); | 9167 c_parser_consume_token (parser); |
9611 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | 9168 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
9612 } | 9169 } |
9613 else | 9170 else |
9614 c_parser_error (parser, "expected identifier"); | 9171 c_parser_error (parser, "expected identifier"); |
9615 } | 9172 } |
9616 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | 9173 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
9617 c_parser_error (parser, "expected %<(%> or end of line"); | 9174 c_parser_error (parser, "expected %<(%> or end of line"); |
9618 c_parser_skip_to_pragma_eol (parser); | 9175 c_parser_skip_to_pragma_eol (parser); |
9619 | 9176 |
9646 so that we can push a new decl if necessary to make it private. | 9203 so that we can push a new decl if necessary to make it private. |
9647 LOC is the location of the OMP in "#pragma omp". */ | 9204 LOC is the location of the OMP in "#pragma omp". */ |
9648 | 9205 |
9649 static tree | 9206 static tree |
9650 c_parser_omp_for_loop (location_t loc, | 9207 c_parser_omp_for_loop (location_t loc, |
9651 c_parser *parser, tree clauses, tree *par_clauses) | 9208 c_parser *parser, tree clauses, tree *par_clauses) |
9652 { | 9209 { |
9653 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl; | 9210 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl; |
9654 tree declv, condv, incrv, initv, ret = NULL; | 9211 tree declv, condv, incrv, initv, ret = NULL; |
9655 bool fail = false, open_brace_parsed = false; | 9212 bool fail = false, open_brace_parsed = false; |
9656 int i, collapse = 1, nbraces = 0; | 9213 int i, collapse = 1, nbraces = 0; |
9679 for (i = 0; i < collapse; i++) | 9236 for (i = 0; i < collapse; i++) |
9680 { | 9237 { |
9681 int bracecount = 0; | 9238 int bracecount = 0; |
9682 | 9239 |
9683 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | 9240 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
9684 goto pop_scopes; | 9241 goto pop_scopes; |
9685 | 9242 |
9686 /* Parse the initialization declaration or expression. */ | 9243 /* Parse the initialization declaration or expression. */ |
9687 if (c_parser_next_tokens_start_declaration (parser)) | 9244 if (c_parser_next_tokens_start_declaration (parser)) |
9688 { | 9245 { |
9689 if (i > 0) | 9246 if (i > 0) |
9718 init = c_process_expr_stmt (init_loc, init); | 9275 init = c_process_expr_stmt (init_loc, init); |
9719 | 9276 |
9720 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | 9277 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
9721 } | 9278 } |
9722 else | 9279 else |
9723 { | 9280 { |
9724 error_init: | 9281 error_init: |
9725 c_parser_error (parser, | 9282 c_parser_error (parser, |
9726 "expected iteration declaration or initialization"); | 9283 "expected iteration declaration or initialization"); |
9727 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | 9284 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
9728 "expected %<)%>"); | 9285 "expected %<)%>"); |
9729 fail = true; | 9286 fail = true; |
9730 goto parse_next; | 9287 goto parse_next; |
9731 } | 9288 } |
9732 | 9289 |
9733 /* Parse the loop condition. */ | 9290 /* Parse the loop condition. */ |
9734 cond = NULL_TREE; | 9291 cond = NULL_TREE; |
9735 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON)) | 9292 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON)) |
9736 { | 9293 { |
9737 location_t cond_loc = c_parser_peek_token (parser)->location; | 9294 location_t cond_loc = c_parser_peek_token (parser)->location; |
9738 struct c_expr cond_expr = c_parser_binary_expression (parser, NULL); | 9295 struct c_expr cond_expr = c_parser_binary_expression (parser, NULL); |
9739 | 9296 |
9740 cond = cond_expr.value; | 9297 cond = cond_expr.value; |
9741 cond = c_objc_common_truthvalue_conversion (cond_loc, cond); | 9298 cond = c_objc_common_truthvalue_conversion (cond_loc, cond); |
9742 cond = c_fully_fold (cond, false, NULL); | 9299 cond = c_fully_fold (cond, false, NULL); |
9743 switch (cond_expr.original_code) | 9300 switch (cond_expr.original_code) |
9744 { | 9301 { |
9745 case GT_EXPR: | 9302 case GT_EXPR: |
9746 case GE_EXPR: | 9303 case GE_EXPR: |
9747 case LT_EXPR: | 9304 case LT_EXPR: |
9748 case LE_EXPR: | 9305 case LE_EXPR: |
9749 break; | 9306 break; |
9750 default: | 9307 default: |
9751 /* Can't be cond = error_mark_node, because we want to preserve | 9308 /* Can't be cond = error_mark_node, because we want to preserve |
9752 the location until c_finish_omp_for. */ | 9309 the location until c_finish_omp_for. */ |
9753 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node); | 9310 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node); |
9754 break; | 9311 break; |
9755 } | 9312 } |
9756 protected_set_expr_location (cond, cond_loc); | 9313 protected_set_expr_location (cond, cond_loc); |
9757 } | 9314 } |
9758 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | 9315 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
9759 | 9316 |
9760 /* Parse the increment expression. */ | 9317 /* Parse the increment expression. */ |
9761 incr = NULL_TREE; | 9318 incr = NULL_TREE; |
9762 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)) | 9319 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)) |
9763 { | 9320 { |
9764 location_t incr_loc = c_parser_peek_token (parser)->location; | 9321 location_t incr_loc = c_parser_peek_token (parser)->location; |
9765 | 9322 |
9766 incr = c_process_expr_stmt (incr_loc, | 9323 incr = c_process_expr_stmt (incr_loc, |
9767 c_parser_expression (parser).value); | 9324 c_parser_expression (parser).value); |
9768 } | 9325 } |
9769 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | 9326 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
9770 | 9327 |
9771 if (decl == NULL || decl == error_mark_node || init == error_mark_node) | 9328 if (decl == NULL || decl == error_mark_node || init == error_mark_node) |
9772 fail = true; | 9329 fail = true; |
9773 else | 9330 else |
9774 { | 9331 { |
9775 TREE_VEC_ELT (declv, i) = decl; | 9332 TREE_VEC_ELT (declv, i) = decl; |
9776 TREE_VEC_ELT (initv, i) = init; | 9333 TREE_VEC_ELT (initv, i) = init; |
9777 TREE_VEC_ELT (condv, i) = cond; | 9334 TREE_VEC_ELT (condv, i) = cond; |
9778 TREE_VEC_ELT (incrv, i) = incr; | 9335 TREE_VEC_ELT (incrv, i) = incr; |
9779 } | 9336 } |
9780 | 9337 |
9781 parse_next: | 9338 parse_next: |
9782 if (i == collapse - 1) | 9339 if (i == collapse - 1) |
9783 break; | 9340 break; |
9784 | 9341 |
9785 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed | 9342 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed |
9786 in between the collapsed for loops to be still considered perfectly | 9343 in between the collapsed for loops to be still considered perfectly |
9787 nested. Hopefully the final version clarifies this. | 9344 nested. Hopefully the final version clarifies this. |
9788 For now handle (multiple) {'s and empty statements. */ | 9345 For now handle (multiple) {'s and empty statements. */ |
9789 do | 9346 do |
9790 { | 9347 { |
9791 if (c_parser_next_token_is_keyword (parser, RID_FOR)) | 9348 if (c_parser_next_token_is_keyword (parser, RID_FOR)) |
9792 { | 9349 { |
9793 c_parser_consume_token (parser); | 9350 c_parser_consume_token (parser); |
9794 break; | 9351 break; |
9795 } | 9352 } |
9796 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | 9353 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
9797 { | 9354 { |
9798 c_parser_consume_token (parser); | 9355 c_parser_consume_token (parser); |
9799 bracecount++; | 9356 bracecount++; |
9800 } | 9357 } |
9801 else if (bracecount | 9358 else if (bracecount |
9802 && c_parser_next_token_is (parser, CPP_SEMICOLON)) | 9359 && c_parser_next_token_is (parser, CPP_SEMICOLON)) |
9803 c_parser_consume_token (parser); | 9360 c_parser_consume_token (parser); |
9804 else | 9361 else |
9805 { | 9362 { |
9806 c_parser_error (parser, "not enough perfectly nested loops"); | 9363 c_parser_error (parser, "not enough perfectly nested loops"); |
9807 if (bracecount) | 9364 if (bracecount) |
9808 { | 9365 { |
9809 open_brace_parsed = true; | 9366 open_brace_parsed = true; |
9810 bracecount--; | 9367 bracecount--; |
9811 } | 9368 } |
9812 fail = true; | 9369 fail = true; |
9813 collapse = 0; | 9370 collapse = 0; |
9814 break; | 9371 break; |
9815 } | 9372 } |
9816 } | 9373 } |
9817 while (1); | 9374 while (1); |
9818 | 9375 |
9819 nbraces += bracecount; | 9376 nbraces += bracecount; |
9820 } | 9377 } |
9821 | 9378 |
9846 c_cont_label = save_cont; | 9403 c_cont_label = save_cont; |
9847 | 9404 |
9848 while (nbraces) | 9405 while (nbraces) |
9849 { | 9406 { |
9850 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | 9407 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
9851 { | 9408 { |
9852 c_parser_consume_token (parser); | 9409 c_parser_consume_token (parser); |
9853 nbraces--; | 9410 nbraces--; |
9854 } | 9411 } |
9855 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | 9412 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
9856 c_parser_consume_token (parser); | 9413 c_parser_consume_token (parser); |
9857 else | 9414 else |
9858 { | 9415 { |
9859 c_parser_error (parser, "collapsed loops not perfectly nested"); | 9416 c_parser_error (parser, "collapsed loops not perfectly nested"); |
9860 while (nbraces) | 9417 while (nbraces) |
9861 { | 9418 { |
9862 location_t here = c_parser_peek_token (parser)->location; | 9419 location_t here = c_parser_peek_token (parser)->location; |
9863 stmt = c_begin_compound_stmt (true); | 9420 stmt = c_begin_compound_stmt (true); |
9864 add_stmt (body); | 9421 add_stmt (body); |
9865 c_parser_compound_statement_nostart (parser); | 9422 c_parser_compound_statement_nostart (parser); |
9866 body = c_end_compound_stmt (here, stmt, true); | 9423 body = c_end_compound_stmt (here, stmt, true); |
9867 nbraces--; | 9424 nbraces--; |
9868 } | 9425 } |
9869 goto pop_scopes; | 9426 goto pop_scopes; |
9870 } | 9427 } |
9871 } | 9428 } |
9872 | 9429 |
9873 /* Only bother calling c_finish_omp_for if we haven't already generated | 9430 /* Only bother calling c_finish_omp_for if we haven't already generated |
9874 an error from the initialization parsing. */ | 9431 an error from the initialization parsing. */ |
9875 if (!fail) | 9432 if (!fail) |
9876 { | 9433 { |
9877 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL); | 9434 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL); |
9878 if (stmt) | 9435 if (stmt) |
9879 { | 9436 { |
9880 if (par_clauses != NULL) | 9437 if (par_clauses != NULL) |
9881 { | 9438 { |
9882 tree *c; | 9439 tree *c; |
9883 for (c = par_clauses; *c ; ) | 9440 for (c = par_clauses; *c ; ) |
9884 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE | 9441 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE |
9885 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE) | 9442 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE) |
9886 c = &OMP_CLAUSE_CHAIN (*c); | 9443 c = &OMP_CLAUSE_CHAIN (*c); |
9887 else | 9444 else |
9888 { | 9445 { |
9889 for (i = 0; i < collapse; i++) | 9446 for (i = 0; i < collapse; i++) |
9890 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c)) | 9447 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c)) |
9891 break; | 9448 break; |
9892 if (i == collapse) | 9449 if (i == collapse) |
9893 c = &OMP_CLAUSE_CHAIN (*c); | 9450 c = &OMP_CLAUSE_CHAIN (*c); |
9894 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE) | 9451 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE) |
9895 { | 9452 { |
9896 error_at (loc, | 9453 error_at (loc, |
9897 "iteration variable %qD should not be firstprivate", | 9454 "iteration variable %qD should not be firstprivate", |
9898 OMP_CLAUSE_DECL (*c)); | 9455 OMP_CLAUSE_DECL (*c)); |
9899 *c = OMP_CLAUSE_CHAIN (*c); | 9456 *c = OMP_CLAUSE_CHAIN (*c); |
9900 } | 9457 } |
9901 else | 9458 else |
9902 { | 9459 { |
9903 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES, | 9460 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES, |
9904 change it to shared (decl) in | 9461 change it to shared (decl) in |
9905 OMP_PARALLEL_CLAUSES. */ | 9462 OMP_PARALLEL_CLAUSES. */ |
9906 tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c), | 9463 tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c), |
9907 OMP_CLAUSE_LASTPRIVATE); | 9464 OMP_CLAUSE_LASTPRIVATE); |
9908 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c); | 9465 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c); |
9909 OMP_CLAUSE_CHAIN (l) = clauses; | 9466 OMP_CLAUSE_CHAIN (l) = clauses; |
9910 clauses = l; | 9467 clauses = l; |
9911 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED); | 9468 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED); |
9912 } | 9469 } |
9913 } | 9470 } |
9914 } | 9471 } |
9915 OMP_FOR_CLAUSES (stmt) = clauses; | 9472 OMP_FOR_CLAUSES (stmt) = clauses; |
9916 } | 9473 } |
9917 ret = stmt; | 9474 ret = stmt; |
9918 } | 9475 } |
9919 pop_scopes: | 9476 pop_scopes: |
9920 while (!VEC_empty (tree, for_block)) | 9477 while (!VEC_empty (tree, for_block)) |
9921 { | 9478 { |
9934 for-loop | 9491 for-loop |
9935 | 9492 |
9936 LOC is the location of the #pragma token. | 9493 LOC is the location of the #pragma token. |
9937 */ | 9494 */ |
9938 | 9495 |
9939 #define OMP_FOR_CLAUSE_MASK \ | 9496 #define OMP_FOR_CLAUSE_MASK \ |
9940 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \ | 9497 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
9941 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | 9498 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
9942 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ | 9499 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ |
9943 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \ | 9500 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \ |
9944 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \ | 9501 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \ |
9945 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \ | 9502 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \ |
9946 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \ | 9503 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \ |
9947 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT)) | 9504 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT)) |
9948 | 9505 |
9949 static tree | 9506 static tree |
9950 c_parser_omp_for (location_t loc, c_parser *parser) | 9507 c_parser_omp_for (location_t loc, c_parser *parser) |
9951 { | 9508 { |
9952 tree block, clauses, ret; | 9509 tree block, clauses, ret; |
9953 | 9510 |
9954 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK, | 9511 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK, |
9955 "#pragma omp for"); | 9512 "#pragma omp for"); |
9956 | 9513 |
9957 block = c_begin_compound_stmt (true); | 9514 block = c_begin_compound_stmt (true); |
9958 ret = c_parser_omp_for_loop (loc, parser, clauses, NULL); | 9515 ret = c_parser_omp_for_loop (loc, parser, clauses, NULL); |
9959 block = c_end_compound_stmt (loc, block, true); | 9516 block = c_end_compound_stmt (loc, block, true); |
9960 add_stmt (block); | 9517 add_stmt (block); |
10021 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION) | 9578 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION) |
10022 { | 9579 { |
10023 substmt = push_stmt_list (); | 9580 substmt = push_stmt_list (); |
10024 | 9581 |
10025 while (1) | 9582 while (1) |
10026 { | 9583 { |
10027 c_parser_statement (parser); | 9584 c_parser_statement (parser); |
10028 | 9585 |
10029 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION) | 9586 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION) |
10030 break; | 9587 break; |
10031 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | 9588 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
10032 break; | 9589 break; |
10033 if (c_parser_next_token_is (parser, CPP_EOF)) | 9590 if (c_parser_next_token_is (parser, CPP_EOF)) |
10034 break; | 9591 break; |
10035 } | 9592 } |
10036 | 9593 |
10037 substmt = pop_stmt_list (substmt); | 9594 substmt = pop_stmt_list (substmt); |
10038 substmt = build1 (OMP_SECTION, void_type_node, substmt); | 9595 substmt = build1 (OMP_SECTION, void_type_node, substmt); |
10039 SET_EXPR_LOCATION (substmt, loc); | 9596 SET_EXPR_LOCATION (substmt, loc); |
10040 add_stmt (substmt); | 9597 add_stmt (substmt); |
10041 } | 9598 } |
10042 | 9599 |
10043 while (1) | 9600 while (1) |
10044 { | 9601 { |
10045 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | 9602 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
10046 break; | 9603 break; |
10047 if (c_parser_next_token_is (parser, CPP_EOF)) | 9604 if (c_parser_next_token_is (parser, CPP_EOF)) |
10048 break; | 9605 break; |
10049 | 9606 |
10050 loc = c_parser_peek_token (parser)->location; | 9607 loc = c_parser_peek_token (parser)->location; |
10051 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION) | 9608 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION) |
10052 { | 9609 { |
10053 c_parser_consume_pragma (parser); | 9610 c_parser_consume_pragma (parser); |
10054 c_parser_skip_to_pragma_eol (parser); | 9611 c_parser_skip_to_pragma_eol (parser); |
10055 error_suppress = false; | 9612 error_suppress = false; |
10056 } | 9613 } |
10057 else if (!error_suppress) | 9614 else if (!error_suppress) |
10058 { | 9615 { |
10059 error_at (loc, "expected %<#pragma omp section%> or %<}%>"); | 9616 error_at (loc, "expected %<#pragma omp section%> or %<}%>"); |
10060 error_suppress = true; | 9617 error_suppress = true; |
10061 } | 9618 } |
10062 | 9619 |
10063 substmt = c_parser_omp_structured_block (parser); | 9620 substmt = c_parser_omp_structured_block (parser); |
10064 substmt = build1 (OMP_SECTION, void_type_node, substmt); | 9621 substmt = build1 (OMP_SECTION, void_type_node, substmt); |
10065 SET_EXPR_LOCATION (substmt, loc); | 9622 SET_EXPR_LOCATION (substmt, loc); |
10066 add_stmt (substmt); | 9623 add_stmt (substmt); |
10067 } | 9624 } |
10068 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, | 9625 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, |
10069 "expected %<#pragma omp section%> or %<}%>"); | 9626 "expected %<#pragma omp section%> or %<}%>"); |
10070 | 9627 |
10071 substmt = pop_stmt_list (stmt); | 9628 substmt = pop_stmt_list (stmt); |
10072 | 9629 |
10073 stmt = make_node (OMP_SECTIONS); | 9630 stmt = make_node (OMP_SECTIONS); |
10074 SET_EXPR_LOCATION (stmt, sections_loc); | 9631 SET_EXPR_LOCATION (stmt, sections_loc); |
10083 sections-scope | 9640 sections-scope |
10084 | 9641 |
10085 LOC is the location of the #pragma token. | 9642 LOC is the location of the #pragma token. |
10086 */ | 9643 */ |
10087 | 9644 |
10088 #define OMP_SECTIONS_CLAUSE_MASK \ | 9645 #define OMP_SECTIONS_CLAUSE_MASK \ |
10089 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \ | 9646 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
10090 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | 9647 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
10091 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ | 9648 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ |
10092 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \ | 9649 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \ |
10093 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT)) | 9650 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT)) |
10094 | 9651 |
10095 static tree | 9652 static tree |
10096 c_parser_omp_sections (location_t loc, c_parser *parser) | 9653 c_parser_omp_sections (location_t loc, c_parser *parser) |
10097 { | 9654 { |
10098 tree block, clauses, ret; | 9655 tree block, clauses, ret; |
10099 | 9656 |
10100 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK, | 9657 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK, |
10101 "#pragma omp sections"); | 9658 "#pragma omp sections"); |
10102 | 9659 |
10103 block = c_begin_compound_stmt (true); | 9660 block = c_begin_compound_stmt (true); |
10104 ret = c_parser_omp_sections_scope (loc, parser); | 9661 ret = c_parser_omp_sections_scope (loc, parser); |
10105 if (ret) | 9662 if (ret) |
10106 OMP_SECTIONS_CLAUSES (ret) = clauses; | 9663 OMP_SECTIONS_CLAUSES (ret) = clauses; |
10116 # pragma parallel sections parallel-sections-clause new-line | 9673 # pragma parallel sections parallel-sections-clause new-line |
10117 | 9674 |
10118 LOC is the location of the #pragma token. | 9675 LOC is the location of the #pragma token. |
10119 */ | 9676 */ |
10120 | 9677 |
10121 #define OMP_PARALLEL_CLAUSE_MASK \ | 9678 #define OMP_PARALLEL_CLAUSE_MASK \ |
10122 ( (1u << PRAGMA_OMP_CLAUSE_IF) \ | 9679 ( (1u << PRAGMA_OMP_CLAUSE_IF) \ |
10123 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \ | 9680 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
10124 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | 9681 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
10125 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \ | 9682 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \ |
10126 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \ | 9683 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \ |
10127 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \ | 9684 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \ |
10128 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \ | 9685 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \ |
10129 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS)) | 9686 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS)) |
10130 | 9687 |
10131 static tree | 9688 static tree |
10132 c_parser_omp_parallel (location_t loc, c_parser *parser) | 9689 c_parser_omp_parallel (location_t loc, c_parser *parser) |
10133 { | 9690 { |
10134 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL; | 9691 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL; |
10146 } | 9703 } |
10147 else if (c_parser_next_token_is (parser, CPP_NAME)) | 9704 else if (c_parser_next_token_is (parser, CPP_NAME)) |
10148 { | 9705 { |
10149 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | 9706 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
10150 if (strcmp (p, "sections") == 0) | 9707 if (strcmp (p, "sections") == 0) |
10151 { | 9708 { |
10152 c_parser_consume_token (parser); | 9709 c_parser_consume_token (parser); |
10153 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS; | 9710 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS; |
10154 p_name = "#pragma omp parallel sections"; | 9711 p_name = "#pragma omp parallel sections"; |
10155 mask |= OMP_SECTIONS_CLAUSE_MASK; | 9712 mask |= OMP_SECTIONS_CLAUSE_MASK; |
10156 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT); | 9713 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT); |
10157 } | 9714 } |
10158 } | 9715 } |
10159 | 9716 |
10160 clauses = c_parser_omp_all_clauses (parser, mask, p_name); | 9717 clauses = c_parser_omp_all_clauses (parser, mask, p_name); |
10161 | 9718 |
10162 switch (p_kind) | 9719 switch (p_kind) |
10178 case PRAGMA_OMP_PARALLEL_SECTIONS: | 9735 case PRAGMA_OMP_PARALLEL_SECTIONS: |
10179 block = c_begin_omp_parallel (); | 9736 block = c_begin_omp_parallel (); |
10180 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause); | 9737 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause); |
10181 stmt = c_parser_omp_sections_scope (loc, parser); | 9738 stmt = c_parser_omp_sections_scope (loc, parser); |
10182 if (stmt) | 9739 if (stmt) |
10183 OMP_SECTIONS_CLAUSES (stmt) = ws_clause; | 9740 OMP_SECTIONS_CLAUSES (stmt) = ws_clause; |
10184 stmt = c_finish_omp_parallel (loc, par_clause, block); | 9741 stmt = c_finish_omp_parallel (loc, par_clause, block); |
10185 OMP_PARALLEL_COMBINED (stmt) = 1; | 9742 OMP_PARALLEL_COMBINED (stmt) = 1; |
10186 break; | 9743 break; |
10187 | 9744 |
10188 default: | 9745 default: |
10197 structured-block | 9754 structured-block |
10198 | 9755 |
10199 LOC is the location of the #pragma. | 9756 LOC is the location of the #pragma. |
10200 */ | 9757 */ |
10201 | 9758 |
10202 #define OMP_SINGLE_CLAUSE_MASK \ | 9759 #define OMP_SINGLE_CLAUSE_MASK \ |
10203 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \ | 9760 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
10204 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | 9761 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
10205 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \ | 9762 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \ |
10206 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT)) | 9763 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT)) |
10207 | 9764 |
10208 static tree | 9765 static tree |
10209 c_parser_omp_single (location_t loc, c_parser *parser) | 9766 c_parser_omp_single (location_t loc, c_parser *parser) |
10210 { | 9767 { |
10211 tree stmt = make_node (OMP_SINGLE); | 9768 tree stmt = make_node (OMP_SINGLE); |
10212 SET_EXPR_LOCATION (stmt, loc); | 9769 SET_EXPR_LOCATION (stmt, loc); |
10213 TREE_TYPE (stmt) = void_type_node; | 9770 TREE_TYPE (stmt) = void_type_node; |
10214 | 9771 |
10215 OMP_SINGLE_CLAUSES (stmt) | 9772 OMP_SINGLE_CLAUSES (stmt) |
10216 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK, | 9773 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK, |
10217 "#pragma omp single"); | 9774 "#pragma omp single"); |
10218 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser); | 9775 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser); |
10219 | 9776 |
10220 return add_stmt (stmt); | 9777 return add_stmt (stmt); |
10221 } | 9778 } |
10222 | 9779 |
10224 # pragma omp task task-clause[optseq] new-line | 9781 # pragma omp task task-clause[optseq] new-line |
10225 | 9782 |
10226 LOC is the location of the #pragma. | 9783 LOC is the location of the #pragma. |
10227 */ | 9784 */ |
10228 | 9785 |
10229 #define OMP_TASK_CLAUSE_MASK \ | 9786 #define OMP_TASK_CLAUSE_MASK \ |
10230 ( (1u << PRAGMA_OMP_CLAUSE_IF) \ | 9787 ( (1u << PRAGMA_OMP_CLAUSE_IF) \ |
10231 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \ | 9788 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \ |
10232 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \ | 9789 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \ |
10233 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \ | 9790 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
10234 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | 9791 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
10235 | (1u << PRAGMA_OMP_CLAUSE_SHARED)) | 9792 | (1u << PRAGMA_OMP_CLAUSE_SHARED)) |
10236 | 9793 |
10237 static tree | 9794 static tree |
10238 c_parser_omp_task (location_t loc, c_parser *parser) | 9795 c_parser_omp_task (location_t loc, c_parser *parser) |
10239 { | 9796 { |
10240 tree clauses, block; | 9797 tree clauses, block; |
10241 | 9798 |
10242 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK, | 9799 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK, |
10243 "#pragma omp task"); | 9800 "#pragma omp task"); |
10244 | 9801 |
10245 block = c_begin_omp_task (); | 9802 block = c_begin_omp_task (); |
10246 c_parser_statement (parser); | 9803 c_parser_statement (parser); |
10247 return c_finish_omp_task (loc, clauses, block); | 9804 return c_finish_omp_task (loc, clauses, block); |
10248 } | 9805 } |
10329 for (t = vars; t; t = TREE_CHAIN (t)) | 9886 for (t = vars; t; t = TREE_CHAIN (t)) |
10330 { | 9887 { |
10331 tree v = TREE_PURPOSE (t); | 9888 tree v = TREE_PURPOSE (t); |
10332 | 9889 |
10333 /* FIXME diagnostics: Ideally we should keep individual | 9890 /* FIXME diagnostics: Ideally we should keep individual |
10334 locations for all the variables in the var list to make the | 9891 locations for all the variables in the var list to make the |
10335 following errors more precise. Perhaps | 9892 following errors more precise. Perhaps |
10336 c_parser_omp_var_list_parens() should construct a list of | 9893 c_parser_omp_var_list_parens() should construct a list of |
10337 locations to go along with the var list. */ | 9894 locations to go along with the var list. */ |
10338 | 9895 |
10339 /* If V had already been marked threadprivate, it doesn't matter | 9896 /* If V had already been marked threadprivate, it doesn't matter |
10340 whether it had been used prior to this point. */ | 9897 whether it had been used prior to this point. */ |
10341 if (TREE_CODE (v) != VAR_DECL) | 9898 if (TREE_CODE (v) != VAR_DECL) |
10342 error_at (loc, "%qD is not a variable", v); | 9899 error_at (loc, "%qD is not a variable", v); |
10343 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v)) | 9900 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v)) |
10344 error_at (loc, "%qE declared %<threadprivate%> after first use", v); | 9901 error_at (loc, "%qE declared %<threadprivate%> after first use", v); |
10345 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v)) | 9902 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v)) |
10346 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v); | 9903 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v); |
10347 else if (TREE_TYPE (v) == error_mark_node) | 9904 else if (TREE_TYPE (v) == error_mark_node) |
10348 ; | 9905 ; |
10349 else if (! COMPLETE_TYPE_P (TREE_TYPE (v))) | 9906 else if (! COMPLETE_TYPE_P (TREE_TYPE (v))) |
10350 error_at (loc, "%<threadprivate%> %qE has incomplete type", v); | 9907 error_at (loc, "%<threadprivate%> %qE has incomplete type", v); |
10351 else | 9908 else |
10352 { | 9909 { |
10353 if (! DECL_THREAD_LOCAL_P (v)) | 9910 if (! DECL_THREAD_LOCAL_P (v)) |
10354 { | 9911 { |
10355 DECL_TLS_MODEL (v) = decl_default_tls_model (v); | 9912 DECL_TLS_MODEL (v) = decl_default_tls_model (v); |
10356 /* If rtl has been already set for this var, call | 9913 /* If rtl has been already set for this var, call |
10357 make_decl_rtl once again, so that encode_section_info | 9914 make_decl_rtl once again, so that encode_section_info |
10358 has a chance to look at the new decl flags. */ | 9915 has a chance to look at the new decl flags. */ |
10359 if (DECL_RTL_SET_P (v)) | 9916 if (DECL_RTL_SET_P (v)) |
10360 make_decl_rtl (v); | 9917 make_decl_rtl (v); |
10361 } | 9918 } |
10362 C_DECL_THREADPRIVATE_P (v) = 1; | 9919 C_DECL_THREADPRIVATE_P (v) = 1; |
10363 } | 9920 } |
10364 } | 9921 } |
10365 | 9922 |
10366 c_parser_skip_to_pragma_eol (parser); | 9923 c_parser_skip_to_pragma_eol (parser); |
10367 } | 9924 } |
10368 | 9925 |