comparison gcc/c-parser.c @ 67:f6334be47118

update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Mar 2011 17:18:12 +0900
parents b7f97abdc517
children 1b10fe6932e1
comparison
equal deleted inserted replaced
65:65488c3d617d 67:f6334be47118
1 /* Parser for C and Objective-C. 1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010 3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc. 4 Free Software Foundation, Inc.
5 5
6 Parser actions based on the old Bison parser; structure somewhat 6 Parser actions based on the old Bison parser; structure somewhat
7 influenced by and fragments based on the C++ parser. 7 influenced by and fragments based on the C++ parser.
8 8
40 #include "config.h" 40 #include "config.h"
41 #include "system.h" 41 #include "system.h"
42 #include "coretypes.h" 42 #include "coretypes.h"
43 #include "tm.h" /* For rtl.h: needs enum reg_class. */ 43 #include "tm.h" /* For rtl.h: needs enum reg_class. */
44 #include "tree.h" 44 #include "tree.h"
45 #include "rtl.h" /* For decl_default_tls_model. */
46 #include "langhooks.h" 45 #include "langhooks.h"
47 #include "input.h" 46 #include "input.h"
48 #include "cpplib.h" 47 #include "cpplib.h"
49 #include "timevar.h" 48 #include "timevar.h"
50 #include "c-pragma.h" 49 #include "c-family/c-pragma.h"
51 #include "c-tree.h" 50 #include "c-tree.h"
52 #include "flags.h" 51 #include "flags.h"
53 #include "output.h" 52 #include "output.h"
54 #include "toplev.h"
55 #include "ggc.h" 53 #include "ggc.h"
56 #include "c-common.h" 54 #include "c-family/c-common.h"
55 #include "c-family/c-objc.h"
57 #include "vec.h" 56 #include "vec.h"
58 #include "target.h" 57 #include "target.h"
59 #include "cgraph.h" 58 #include "cgraph.h"
60 #include "plugin.h" 59 #include "plugin.h"
61 60
85 mask |= D_EXT89; 84 mask |= D_EXT89;
86 } 85 }
87 if (!c_dialect_objc ()) 86 if (!c_dialect_objc ())
88 mask |= D_OBJC | D_CXX_OBJC; 87 mask |= D_OBJC | D_CXX_OBJC;
89 88
90 ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX); 89 ridpointers = ggc_alloc_cleared_vec_tree ((int) RID_MAX);
91 for (i = 0; i < num_c_common_reswords; i++) 90 for (i = 0; i < num_c_common_reswords; i++)
92 { 91 {
93 /* 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
94 and so create a canonical spelling that isn't a keyword. */ 93 and so create a canonical spelling that isn't a keyword. */
95 if (c_common_reswords[i].disable & mask) 94 if (c_common_reswords[i].disable & mask)
178 BOOL_BITFIELD in_pragma : 1; 177 BOOL_BITFIELD in_pragma : 1;
179 /* True if we're parsing the outermost block of an if statement. */ 178 /* True if we're parsing the outermost block of an if statement. */
180 BOOL_BITFIELD in_if_block : 1; 179 BOOL_BITFIELD in_if_block : 1;
181 /* True if we want to lex an untranslated string. */ 180 /* True if we want to lex an untranslated string. */
182 BOOL_BITFIELD lex_untranslated_string : 1; 181 BOOL_BITFIELD lex_untranslated_string : 1;
182
183 /* Objective-C specific parser/lexer information. */ 183 /* Objective-C specific parser/lexer information. */
184
185 /* True if we are in a context where the Objective-C "PQ" keywords
186 are considered keywords. */
184 BOOL_BITFIELD objc_pq_context : 1; 187 BOOL_BITFIELD objc_pq_context : 1;
188 /* True if we are parsing a (potential) Objective-C foreach
189 statement. This is set to true after we parsed 'for (' and while
190 we wait for 'in' or ';' to decide if it's a standard C for loop or an
191 Objective-C foreach loop. */
192 BOOL_BITFIELD objc_could_be_foreach_context : 1;
185 /* The following flag is needed to contextualize Objective-C lexical 193 /* The following flag is needed to contextualize Objective-C lexical
186 analysis. In some cases (e.g., 'int NSObject;'), it is 194 analysis. In some cases (e.g., 'int NSObject;'), it is
187 undesirable to bind an identifier to an Objective-C class, even 195 undesirable to bind an identifier to an Objective-C class, even
188 if a class with that name exists. */ 196 if a class with that name exists. */
189 BOOL_BITFIELD objc_need_raw_identifier : 1; 197 BOOL_BITFIELD objc_need_raw_identifier : 1;
198 /* True if we are in a context where the Objective-C "Property attribute"
199 keywords are valid. */
200 BOOL_BITFIELD objc_property_attr_context : 1;
190 } c_parser; 201 } c_parser;
191 202
192 203
193 /* The actual parser and external interface. ??? Does this need to be 204 /* The actual parser and external interface. ??? Does this need to be
194 garbage-collected? */ 205 garbage-collected? */
195 206
196 static GTY (()) c_parser *the_parser; 207 static GTY (()) c_parser *the_parser;
197
198 208
199 /* Read in and lex a single token, storing it in *TOKEN. */ 209 /* Read in and lex a single token, storing it in *TOKEN. */
200 210
201 static void 211 static void
202 c_lex_one_token (c_parser *parser, c_token *token) 212 c_lex_one_token (c_parser *parser, c_token *token)
236 { 246 {
237 token->id_kind = C_ID_ADDRSPACE; 247 token->id_kind = C_ID_ADDRSPACE;
238 token->keyword = rid_code; 248 token->keyword = rid_code;
239 break; 249 break;
240 } 250 }
241 else if (c_dialect_objc ()) 251 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code))
242 { 252 {
243 if (!objc_is_reserved_word (token->value) 253 /* We found an Objective-C "pq" keyword (in, out,
244 && (!OBJC_IS_PQ_KEYWORD (rid_code) 254 inout, bycopy, byref, oneway). They need special
245 || parser->objc_pq_context)) 255 care because the interpretation depends on the
256 context. */
257 if (parser->objc_pq_context)
246 { 258 {
247 /* Return the canonical spelling for this keyword. */
248 token->value = ridpointers[(int) rid_code];
249 token->type = CPP_KEYWORD; 259 token->type = CPP_KEYWORD;
250 token->keyword = rid_code; 260 token->keyword = rid_code;
251 break; 261 break;
252 } 262 }
263 else if (parser->objc_could_be_foreach_context
264 && rid_code == RID_IN)
265 {
266 /* We are in Objective-C, inside a (potential)
267 foreach context (which means after having
268 parsed 'for (', but before having parsed ';'),
269 and we found 'in'. We consider it the keyword
270 which terminates the declaration at the
271 beginning of a foreach-statement. Note that
272 this means you can't use 'in' for anything else
273 in that context; in particular, in Objective-C
274 you can't use 'in' as the name of the running
275 variable in a C for loop. We could potentially
276 try to add code here to disambiguate, but it
277 seems a reasonable limitation. */
278 token->type = CPP_KEYWORD;
279 token->keyword = rid_code;
280 break;
281 }
282 /* Else, "pq" keywords outside of the "pq" context are
283 not keywords, and we fall through to the code for
284 normal tokens. */
285 }
286 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code))
287 {
288 /* We found an Objective-C "property attribute"
289 keyword (getter, setter, readonly, etc). These are
290 only valid in the property context. */
291 if (parser->objc_property_attr_context)
292 {
293 token->type = CPP_KEYWORD;
294 token->keyword = rid_code;
295 break;
296 }
297 /* Else they are not special keywords.
298 */
299 }
300 else if (c_dialect_objc ()
301 && (OBJC_IS_AT_KEYWORD (rid_code)
302 || OBJC_IS_CXX_KEYWORD (rid_code)))
303 {
304 /* We found one of the Objective-C "@" keywords (defs,
305 selector, synchronized, etc) or one of the
306 Objective-C "cxx" keywords (class, private,
307 protected, public, try, catch, throw) without a
308 preceding '@' sign. Do nothing and fall through to
309 the code for normal tokens (in C++ we would still
310 consider the CXX ones keywords, but not in C). */
311 ;
253 } 312 }
254 else 313 else
255 { 314 {
256 token->type = CPP_KEYWORD; 315 token->type = CPP_KEYWORD;
257 token->keyword = rid_code; 316 token->keyword = rid_code;
287 } 346 }
288 break; 347 break;
289 case CPP_AT_NAME: 348 case CPP_AT_NAME:
290 /* This only happens in Objective-C; it must be a keyword. */ 349 /* This only happens in Objective-C; it must be a keyword. */
291 token->type = CPP_KEYWORD; 350 token->type = CPP_KEYWORD;
292 token->keyword = C_RID_CODE (token->value); 351 switch (C_RID_CODE (token->value))
352 {
353 /* Replace 'class' with '@class', 'private' with '@private',
354 etc. This prevents confusion with the C++ keyword
355 'class', and makes the tokens consistent with other
356 Objective-C 'AT' keywords. For example '@class' is
357 reported as RID_AT_CLASS which is consistent with
358 '@synchronized', which is reported as
359 RID_AT_SYNCHRONIZED.
360 */
361 case RID_CLASS: token->keyword = RID_AT_CLASS; break;
362 case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break;
363 case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
364 case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break;
365 case RID_THROW: token->keyword = RID_AT_THROW; break;
366 case RID_TRY: token->keyword = RID_AT_TRY; break;
367 case RID_CATCH: token->keyword = RID_AT_CATCH; break;
368 default: token->keyword = C_RID_CODE (token->value);
369 }
293 break; 370 break;
294 case CPP_COLON: 371 case CPP_COLON:
295 case CPP_COMMA: 372 case CPP_COMMA:
296 case CPP_CLOSE_PAREN: 373 case CPP_CLOSE_PAREN:
297 case CPP_SEMICOLON: 374 case CPP_SEMICOLON:
350 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword) 427 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
351 { 428 {
352 return c_parser_peek_token (parser)->keyword == keyword; 429 return c_parser_peek_token (parser)->keyword == keyword;
353 } 430 }
354 431
432 /* Return a pointer to the next-but-one token from PARSER, reading it
433 in if necessary. The next token is already read in. */
434
435 static c_token *
436 c_parser_peek_2nd_token (c_parser *parser)
437 {
438 if (parser->tokens_avail >= 2)
439 return &parser->tokens[1];
440 gcc_assert (parser->tokens_avail == 1);
441 gcc_assert (parser->tokens[0].type != CPP_EOF);
442 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
443 c_lex_one_token (parser, &parser->tokens[1]);
444 parser->tokens_avail = 2;
445 return &parser->tokens[1];
446 }
447
355 /* Return true if TOKEN can start a type name, 448 /* Return true if TOKEN can start a type name,
356 false otherwise. */ 449 false otherwise. */
357 static bool 450 static bool
358 c_token_starts_typename (c_token *token) 451 c_token_starts_typename (c_token *token)
359 { 452 {
377 case CPP_KEYWORD: 470 case CPP_KEYWORD:
378 switch (token->keyword) 471 switch (token->keyword)
379 { 472 {
380 case RID_UNSIGNED: 473 case RID_UNSIGNED:
381 case RID_LONG: 474 case RID_LONG:
475 case RID_INT128:
382 case RID_SHORT: 476 case RID_SHORT:
383 case RID_SIGNED: 477 case RID_SIGNED:
384 case RID_COMPLEX: 478 case RID_COMPLEX:
385 case RID_INT: 479 case RID_INT:
386 case RID_CHAR: 480 case RID_CHAR:
413 default: 507 default:
414 return false; 508 return false;
415 } 509 }
416 } 510 }
417 511
512 enum c_lookahead_kind {
513 /* Always treat unknown identifiers as typenames. */
514 cla_prefer_type,
515
516 /* Could be parsing a nonabstract declarator. Only treat an identifier
517 as a typename if followed by another identifier or a star. */
518 cla_nonabstract_decl,
519
520 /* Never treat identifiers as typenames. */
521 cla_prefer_id
522 };
523
418 /* Return true if the next token from PARSER can start a type name, 524 /* Return true if the next token from PARSER can start a type name,
525 false otherwise. LA specifies how to do lookahead in order to
526 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
527
528 static inline bool
529 c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la)
530 {
531 c_token *token = c_parser_peek_token (parser);
532 if (c_token_starts_typename (token))
533 return true;
534
535 /* Try a bit harder to detect an unknown typename. */
536 if (la != cla_prefer_id
537 && token->type == CPP_NAME
538 && token->id_kind == C_ID_ID
539
540 /* Do not try too hard when we could have "object in array". */
541 && !parser->objc_could_be_foreach_context
542
543 && (la == cla_prefer_type
544 || c_parser_peek_2nd_token (parser)->type == CPP_NAME
545 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
546
547 /* Only unknown identifiers. */
548 && !lookup_name (token->value))
549 return true;
550
551 return false;
552 }
553
554 /* Return true if TOKEN is a type qualifier, false otherwise. */
555 static bool
556 c_token_is_qualifier (c_token *token)
557 {
558 switch (token->type)
559 {
560 case CPP_NAME:
561 switch (token->id_kind)
562 {
563 case C_ID_ADDRSPACE:
564 return true;
565 default:
566 return false;
567 }
568 case CPP_KEYWORD:
569 switch (token->keyword)
570 {
571 case RID_CONST:
572 case RID_VOLATILE:
573 case RID_RESTRICT:
574 case RID_ATTRIBUTE:
575 return true;
576 default:
577 return false;
578 }
579 case CPP_LESS:
580 return false;
581 default:
582 gcc_unreachable ();
583 }
584 }
585
586 /* Return true if the next token from PARSER is a type qualifier,
419 false otherwise. */ 587 false otherwise. */
420 static inline bool 588 static inline bool
421 c_parser_next_token_starts_typename (c_parser *parser) 589 c_parser_next_token_is_qualifier (c_parser *parser)
422 { 590 {
423 c_token *token = c_parser_peek_token (parser); 591 c_token *token = c_parser_peek_token (parser);
424 return c_token_starts_typename (token); 592 return c_token_is_qualifier (token);
425 } 593 }
426 594
427 /* Return true if TOKEN can start declaration specifiers, false 595 /* Return true if TOKEN can start declaration specifiers, false
428 otherwise. */ 596 otherwise. */
429 static bool 597 static bool
456 case RID_INLINE: 624 case RID_INLINE:
457 case RID_AUTO: 625 case RID_AUTO:
458 case RID_THREAD: 626 case RID_THREAD:
459 case RID_UNSIGNED: 627 case RID_UNSIGNED:
460 case RID_LONG: 628 case RID_LONG:
629 case RID_INT128:
461 case RID_SHORT: 630 case RID_SHORT:
462 case RID_SIGNED: 631 case RID_SIGNED:
463 case RID_COMPLEX: 632 case RID_COMPLEX:
464 case RID_INT: 633 case RID_INT:
465 case RID_CHAR: 634 case RID_CHAR:
511 specifiers, false otherwise. */ 680 specifiers, false otherwise. */
512 static inline bool 681 static inline bool
513 c_parser_next_token_starts_declspecs (c_parser *parser) 682 c_parser_next_token_starts_declspecs (c_parser *parser)
514 { 683 {
515 c_token *token = c_parser_peek_token (parser); 684 c_token *token = c_parser_peek_token (parser);
685
686 /* In Objective-C, a classname normally starts a declspecs unless it
687 is immediately followed by a dot. In that case, it is the
688 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
689 setter/getter on the class. c_token_starts_declspecs() can't
690 differentiate between the two cases because it only checks the
691 current token, so we have a special check here. */
692 if (c_dialect_objc ()
693 && token->type == CPP_NAME
694 && token->id_kind == C_ID_CLASSNAME
695 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
696 return false;
697
516 return c_token_starts_declspecs (token); 698 return c_token_starts_declspecs (token);
517 } 699 }
518 700
519 /* Return true if the next token from PARSER can start declaration 701 /* Return true if the next tokens from PARSER can start declaration
520 specifiers or a static assertion, false otherwise. */ 702 specifiers or a static assertion, false otherwise. */
521 static inline bool 703 static inline bool
522 c_parser_next_token_starts_declaration (c_parser *parser) 704 c_parser_next_tokens_start_declaration (c_parser *parser)
523 { 705 {
524 c_token *token = c_parser_peek_token (parser); 706 c_token *token = c_parser_peek_token (parser);
525 return c_token_starts_declaration (token); 707
526 } 708 /* Same as above. */
527 709 if (c_dialect_objc ()
528 /* Return a pointer to the next-but-one token from PARSER, reading it 710 && token->type == CPP_NAME
529 in if necessary. The next token is already read in. */ 711 && token->id_kind == C_ID_CLASSNAME
530 712 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
531 static c_token * 713 return false;
532 c_parser_peek_2nd_token (c_parser *parser) 714
533 { 715 /* Labels do not start declarations. */
534 if (parser->tokens_avail >= 2) 716 if (token->type == CPP_NAME
535 return &parser->tokens[1]; 717 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
536 gcc_assert (parser->tokens_avail == 1); 718 return false;
537 gcc_assert (parser->tokens[0].type != CPP_EOF); 719
538 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL); 720 if (c_token_starts_declaration (token))
539 c_lex_one_token (parser, &parser->tokens[1]); 721 return true;
540 parser->tokens_avail = 2; 722
541 return &parser->tokens[1]; 723 if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl))
724 return true;
725
726 return false;
542 } 727 }
543 728
544 /* Consume the next token from PARSER. */ 729 /* Consume the next token from PARSER. */
545 730
546 static void 731 static void
859 | (warn_pointer_arith << 1) 1044 | (warn_pointer_arith << 1)
860 | (warn_traditional << 2) 1045 | (warn_traditional << 2)
861 | (flag_iso << 3) 1046 | (flag_iso << 3)
862 | (warn_long_long << 4) 1047 | (warn_long_long << 4)
863 | (warn_cxx_compat << 5)); 1048 | (warn_cxx_compat << 5));
864 cpp_opts->pedantic = pedantic = 0; 1049 cpp_opts->cpp_pedantic = pedantic = 0;
865 warn_pointer_arith = 0; 1050 warn_pointer_arith = 0;
866 cpp_opts->warn_traditional = warn_traditional = 0; 1051 cpp_opts->cpp_warn_traditional = warn_traditional = 0;
867 flag_iso = 0; 1052 flag_iso = 0;
868 cpp_opts->warn_long_long = warn_long_long = 0; 1053 cpp_opts->cpp_warn_long_long = warn_long_long = 0;
869 warn_cxx_compat = 0; 1054 warn_cxx_compat = 0;
870 return ret; 1055 return ret;
871 } 1056 }
872 1057
873 /* Restore the warning flags which are controlled by __extension__. 1058 /* Restore the warning flags which are controlled by __extension__.
874 FLAGS is the return value from disable_extension_diagnostics. */ 1059 FLAGS is the return value from disable_extension_diagnostics. */
875 1060
876 static inline void 1061 static inline void
877 restore_extension_diagnostics (int flags) 1062 restore_extension_diagnostics (int flags)
878 { 1063 {
879 cpp_opts->pedantic = pedantic = flags & 1; 1064 cpp_opts->cpp_pedantic = pedantic = flags & 1;
880 warn_pointer_arith = (flags >> 1) & 1; 1065 warn_pointer_arith = (flags >> 1) & 1;
881 cpp_opts->warn_traditional = warn_traditional = (flags >> 2) & 1; 1066 cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
882 flag_iso = (flags >> 3) & 1; 1067 flag_iso = (flags >> 3) & 1;
883 cpp_opts->warn_long_long = warn_long_long = (flags >> 4) & 1; 1068 cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
884 warn_cxx_compat = (flags >> 5) & 1; 1069 warn_cxx_compat = (flags >> 5) & 1;
885 } 1070 }
886 1071
887 /* Possibly kinds of declarator to parse. */ 1072 /* Possibly kinds of declarator to parse. */
888 typedef enum c_dtr_syn { 1073 typedef enum c_dtr_syn {
904 } c_dtr_syn; 1089 } c_dtr_syn;
905 1090
906 static void c_parser_external_declaration (c_parser *); 1091 static void c_parser_external_declaration (c_parser *);
907 static void c_parser_asm_definition (c_parser *); 1092 static void c_parser_asm_definition (c_parser *);
908 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, 1093 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
909 bool, bool); 1094 bool, bool, tree *);
910 static void c_parser_static_assert_declaration_no_semi (c_parser *); 1095 static void c_parser_static_assert_declaration_no_semi (c_parser *);
911 static void c_parser_static_assert_declaration (c_parser *); 1096 static void c_parser_static_assert_declaration (c_parser *);
912 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool, 1097 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
913 bool); 1098 bool, enum c_lookahead_kind);
914 static struct c_typespec c_parser_enum_specifier (c_parser *); 1099 static struct c_typespec c_parser_enum_specifier (c_parser *);
915 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 *);
916 static tree c_parser_struct_declaration (c_parser *); 1101 static tree c_parser_struct_declaration (c_parser *);
917 static struct c_typespec c_parser_typeof_specifier (c_parser *); 1102 static struct c_typespec c_parser_typeof_specifier (c_parser *);
918 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,
975 enum pragma_context { pragma_external, pragma_stmt, pragma_compound }; 1160 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
976 static bool c_parser_pragma (c_parser *, enum pragma_context); 1161 static bool c_parser_pragma (c_parser *, enum pragma_context);
977 1162
978 /* These Objective-C parser functions are only ever called when 1163 /* These Objective-C parser functions are only ever called when
979 compiling Objective-C. */ 1164 compiling Objective-C. */
980 static void c_parser_objc_class_definition (c_parser *); 1165 static void c_parser_objc_class_definition (c_parser *, tree);
981 static void c_parser_objc_class_instance_variables (c_parser *); 1166 static void c_parser_objc_class_instance_variables (c_parser *);
982 static void c_parser_objc_class_declaration (c_parser *); 1167 static void c_parser_objc_class_declaration (c_parser *);
983 static void c_parser_objc_alias_declaration (c_parser *); 1168 static void c_parser_objc_alias_declaration (c_parser *);
984 static void c_parser_objc_protocol_definition (c_parser *); 1169 static void c_parser_objc_protocol_definition (c_parser *, tree);
985 static enum tree_code c_parser_objc_method_type (c_parser *); 1170 static bool c_parser_objc_method_type (c_parser *);
986 static void c_parser_objc_method_definition (c_parser *); 1171 static void c_parser_objc_method_definition (c_parser *);
987 static void c_parser_objc_methodprotolist (c_parser *); 1172 static void c_parser_objc_methodprotolist (c_parser *);
988 static void c_parser_objc_methodproto (c_parser *); 1173 static void c_parser_objc_methodproto (c_parser *);
989 static tree c_parser_objc_method_decl (c_parser *); 1174 static tree c_parser_objc_method_decl (c_parser *, bool, tree *);
990 static tree c_parser_objc_type_name (c_parser *); 1175 static tree c_parser_objc_type_name (c_parser *);
991 static tree c_parser_objc_protocol_refs (c_parser *); 1176 static tree c_parser_objc_protocol_refs (c_parser *);
992 static void c_parser_objc_try_catch_statement (c_parser *); 1177 static void c_parser_objc_try_catch_finally_statement (c_parser *);
993 static void c_parser_objc_synchronized_statement (c_parser *); 1178 static void c_parser_objc_synchronized_statement (c_parser *);
994 static tree c_parser_objc_selector (c_parser *); 1179 static tree c_parser_objc_selector (c_parser *);
995 static tree c_parser_objc_selector_arg (c_parser *); 1180 static tree c_parser_objc_selector_arg (c_parser *);
996 static tree c_parser_objc_receiver (c_parser *); 1181 static tree c_parser_objc_receiver (c_parser *);
997 static tree c_parser_objc_message_args (c_parser *); 1182 static tree c_parser_objc_message_args (c_parser *);
998 static tree c_parser_objc_keywordexpr (c_parser *); 1183 static tree c_parser_objc_keywordexpr (c_parser *);
1184 static void c_parser_objc_at_property_declaration (c_parser *);
1185 static void c_parser_objc_at_synthesize_declaration (c_parser *);
1186 static void c_parser_objc_at_dynamic_declaration (c_parser *);
1187 static bool c_parser_objc_diagnose_bad_element_prefix
1188 (c_parser *, struct c_declspecs *);
999 1189
1000 /* Parse a translation unit (C90 6.7, C99 6.9). 1190 /* Parse a translation unit (C90 6.7, C99 6.9).
1001 1191
1002 translation-unit: 1192 translation-unit:
1003 external-declarations 1193 external-declarations
1077 c_parser_asm_definition (parser); 1267 c_parser_asm_definition (parser);
1078 break; 1268 break;
1079 case RID_AT_INTERFACE: 1269 case RID_AT_INTERFACE:
1080 case RID_AT_IMPLEMENTATION: 1270 case RID_AT_IMPLEMENTATION:
1081 gcc_assert (c_dialect_objc ()); 1271 gcc_assert (c_dialect_objc ());
1082 c_parser_objc_class_definition (parser); 1272 c_parser_objc_class_definition (parser, NULL_TREE);
1083 break; 1273 break;
1084 case RID_CLASS: 1274 case RID_AT_CLASS:
1085 gcc_assert (c_dialect_objc ()); 1275 gcc_assert (c_dialect_objc ());
1086 c_parser_objc_class_declaration (parser); 1276 c_parser_objc_class_declaration (parser);
1087 break; 1277 break;
1088 case RID_AT_ALIAS: 1278 case RID_AT_ALIAS:
1089 gcc_assert (c_dialect_objc ()); 1279 gcc_assert (c_dialect_objc ());
1090 c_parser_objc_alias_declaration (parser); 1280 c_parser_objc_alias_declaration (parser);
1091 break; 1281 break;
1092 case RID_AT_PROTOCOL: 1282 case RID_AT_PROTOCOL:
1093 gcc_assert (c_dialect_objc ()); 1283 gcc_assert (c_dialect_objc ());
1094 c_parser_objc_protocol_definition (parser); 1284 c_parser_objc_protocol_definition (parser, NULL_TREE);
1285 break;
1286 case RID_AT_PROPERTY:
1287 gcc_assert (c_dialect_objc ());
1288 c_parser_objc_at_property_declaration (parser);
1289 break;
1290 case RID_AT_SYNTHESIZE:
1291 gcc_assert (c_dialect_objc ());
1292 c_parser_objc_at_synthesize_declaration (parser);
1293 break;
1294 case RID_AT_DYNAMIC:
1295 gcc_assert (c_dialect_objc ());
1296 c_parser_objc_at_dynamic_declaration (parser);
1095 break; 1297 break;
1096 case RID_AT_END: 1298 case RID_AT_END:
1097 gcc_assert (c_dialect_objc ()); 1299 gcc_assert (c_dialect_objc ());
1098 c_parser_consume_token (parser); 1300 c_parser_consume_token (parser);
1099 objc_finish_implementation (); 1301 objc_finish_implementation ();
1121 } 1323 }
1122 /* Else fall through, and yield a syntax error trying to parse 1324 /* Else fall through, and yield a syntax error trying to parse
1123 as a declaration or function definition. */ 1325 as a declaration or function definition. */
1124 default: 1326 default:
1125 decl_or_fndef: 1327 decl_or_fndef:
1126 /* A declaration or a function definition. We can only tell 1328 /* A declaration or a function definition (or, in Objective-C,
1127 which after parsing the declaration specifiers, if any, and 1329 an @interface or @protocol with prefix attributes). We can
1128 the first declarator. */ 1330 only tell which after parsing the declaration specifiers, if
1129 c_parser_declaration_or_fndef (parser, true, true, true, false, true); 1331 any, and the first declarator. */
1332 c_parser_declaration_or_fndef (parser, true, true, true, false, true, NULL);
1130 break; 1333 break;
1131 } 1334 }
1132 } 1335 }
1133
1134 1336
1135 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99 1337 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1136 6.7, 6.9.1). If FNDEF_OK is true, a function definition is 1338 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1137 accepted; otherwise (old-style parameter declarations) only other 1339 accepted; otherwise (old-style parameter declarations) only other
1138 declarations are accepted. If STATIC_ASSERT_OK is true, a static 1340 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1144 declaration specifiers may be optional. If EMPTY_OK is true, empty 1346 declaration specifiers may be optional. If EMPTY_OK is true, empty
1145 declarations are OK (subject to all other constraints); otherwise 1347 declarations are OK (subject to all other constraints); otherwise
1146 (old-style parameter declarations) they are diagnosed. If 1348 (old-style parameter declarations) they are diagnosed. If
1147 START_ATTR_OK is true, the declaration specifiers may start with 1349 START_ATTR_OK is true, the declaration specifiers may start with
1148 attributes; otherwise they may not. 1350 attributes; otherwise they may not.
1351 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1352 declaration when parsing an Objective-C foreach statement.
1149 1353
1150 declaration: 1354 declaration:
1151 declaration-specifiers init-declarator-list[opt] ; 1355 declaration-specifiers init-declarator-list[opt] ;
1152 static_assert-declaration 1356 static_assert-declaration
1153 1357
1170 GNU extensions: 1374 GNU extensions:
1171 1375
1172 nested-function-definition: 1376 nested-function-definition:
1173 declaration-specifiers declarator declaration-list[opt] 1377 declaration-specifiers declarator declaration-list[opt]
1174 compound-statement 1378 compound-statement
1379
1380 Objective-C:
1381 attributes objc-class-definition
1382 attributes objc-category-definition
1383 attributes objc-protocol-definition
1175 1384
1176 The simple-asm-expr and attributes are GNU extensions. 1385 The simple-asm-expr and attributes are GNU extensions.
1177 1386
1178 This function does not handle __extension__; that is handled in its 1387 This function does not handle __extension__; that is handled in its
1179 callers. ??? Following the old parser, __extension__ may start 1388 callers. ??? Following the old parser, __extension__ may start
1185 absence is diagnosed through the diagnosis of implicit int. In GNU 1394 absence is diagnosed through the diagnosis of implicit int. In GNU
1186 C we also allow but diagnose declarations without declaration 1395 C we also allow but diagnose declarations without declaration
1187 specifiers, but only at top level (elsewhere they conflict with 1396 specifiers, but only at top level (elsewhere they conflict with
1188 other syntax). 1397 other syntax).
1189 1398
1399 In Objective-C, declarations of the looping variable in a foreach
1400 statement are exceptionally terminated by 'in' (for example, 'for
1401 (NSObject *object in array) { ... }').
1402
1190 OpenMP: 1403 OpenMP:
1191 1404
1192 declaration: 1405 declaration:
1193 threadprivate-directive */ 1406 threadprivate-directive */
1194 1407
1195 static void 1408 static void
1196 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, 1409 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1197 bool static_assert_ok, bool empty_ok, 1410 bool static_assert_ok, bool empty_ok,
1198 bool nested, bool start_attr_ok) 1411 bool nested, bool start_attr_ok,
1412 tree *objc_foreach_object_declaration)
1199 { 1413 {
1200 struct c_declspecs *specs; 1414 struct c_declspecs *specs;
1201 tree prefix_attrs; 1415 tree prefix_attrs;
1202 tree all_prefix_attrs; 1416 tree all_prefix_attrs;
1203 bool diagnosed_no_specs = false; 1417 bool diagnosed_no_specs = false;
1208 { 1422 {
1209 c_parser_static_assert_declaration (parser); 1423 c_parser_static_assert_declaration (parser);
1210 return; 1424 return;
1211 } 1425 }
1212 specs = build_null_declspecs (); 1426 specs = build_null_declspecs ();
1213 c_parser_declspecs (parser, specs, true, true, start_attr_ok); 1427
1428 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1429 if (c_parser_peek_token (parser)->type == CPP_NAME
1430 && c_parser_peek_token (parser)->id_kind == C_ID_ID
1431 && (c_parser_peek_2nd_token (parser)->type == CPP_NAME
1432 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
1433 && (!nested || !lookup_name (c_parser_peek_token (parser)->value)))
1434 {
1435 error_at (here, "unknown type name %qE",
1436 c_parser_peek_token (parser)->value);
1437
1438 /* Parse declspecs normally to get a correct pointer type, but avoid
1439 a further "fails to be a type name" error. Refuse nested functions
1440 since it is not how the user likely wants us to recover. */
1441 c_parser_peek_token (parser)->type = CPP_KEYWORD;
1442 c_parser_peek_token (parser)->keyword = RID_VOID;
1443 c_parser_peek_token (parser)->value = error_mark_node;
1444 fndef_ok = !nested;
1445 }
1446
1447 c_parser_declspecs (parser, specs, true, true, start_attr_ok, cla_nonabstract_decl);
1214 if (parser->error) 1448 if (parser->error)
1215 { 1449 {
1216 c_parser_skip_to_end_of_block_or_statement (parser); 1450 c_parser_skip_to_end_of_block_or_statement (parser);
1217 return; 1451 return;
1218 } 1452 }
1233 pedwarn (here, 0, "empty declaration"); 1467 pedwarn (here, 0, "empty declaration");
1234 } 1468 }
1235 c_parser_consume_token (parser); 1469 c_parser_consume_token (parser);
1236 return; 1470 return;
1237 } 1471 }
1472
1473 /* Provide better error recovery. Note that a type name here is usually
1474 better diagnosed as a redeclaration. */
1475 if (empty_ok
1476 && specs->typespec_kind == ctsk_tagdef
1477 && c_parser_next_token_starts_declspecs (parser)
1478 && !c_parser_next_token_is (parser, CPP_NAME))
1479 {
1480 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
1481 parser->error = false;
1482 shadow_tag_warned (specs, 1);
1483 return;
1484 }
1485 else if (c_dialect_objc ())
1486 {
1487 /* Prefix attributes are an error on method decls. */
1488 switch (c_parser_peek_token (parser)->type)
1489 {
1490 case CPP_PLUS:
1491 case CPP_MINUS:
1492 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1493 return;
1494 if (specs->attrs)
1495 {
1496 warning_at (c_parser_peek_token (parser)->location,
1497 OPT_Wattributes,
1498 "prefix attributes are ignored for methods");
1499 specs->attrs = NULL_TREE;
1500 }
1501 if (fndef_ok)
1502 c_parser_objc_method_definition (parser);
1503 else
1504 c_parser_objc_methodproto (parser);
1505 return;
1506 break;
1507 default:
1508 break;
1509 }
1510 /* This is where we parse 'attributes @interface ...',
1511 'attributes @implementation ...', 'attributes @protocol ...'
1512 (where attributes could be, for example, __attribute__
1513 ((deprecated)).
1514 */
1515 switch (c_parser_peek_token (parser)->keyword)
1516 {
1517 case RID_AT_INTERFACE:
1518 {
1519 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1520 return;
1521 c_parser_objc_class_definition (parser, specs->attrs);
1522 return;
1523 }
1524 break;
1525 case RID_AT_IMPLEMENTATION:
1526 {
1527 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1528 return;
1529 if (specs->attrs)
1530 {
1531 warning_at (c_parser_peek_token (parser)->location,
1532 OPT_Wattributes,
1533 "prefix attributes are ignored for implementations");
1534 specs->attrs = NULL_TREE;
1535 }
1536 c_parser_objc_class_definition (parser, NULL_TREE);
1537 return;
1538 }
1539 break;
1540 case RID_AT_PROTOCOL:
1541 {
1542 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1543 return;
1544 c_parser_objc_protocol_definition (parser, specs->attrs);
1545 return;
1546 }
1547 break;
1548 case RID_AT_ALIAS:
1549 case RID_AT_CLASS:
1550 case RID_AT_END:
1551 case RID_AT_PROPERTY:
1552 if (specs->attrs)
1553 {
1554 c_parser_error (parser, "unexpected attribute");
1555 specs->attrs = NULL;
1556 }
1557 break;
1558 default:
1559 break;
1560 }
1561 }
1562
1238 pending_xref_error (); 1563 pending_xref_error ();
1239 prefix_attrs = specs->attrs; 1564 prefix_attrs = specs->attrs;
1240 all_prefix_attrs = prefix_attrs; 1565 all_prefix_attrs = prefix_attrs;
1241 specs->attrs = NULL_TREE; 1566 specs->attrs = NULL_TREE;
1242 while (true) 1567 while (true)
1246 tree fnbody; 1571 tree fnbody;
1247 /* Declaring either one or more declarators (in which case we 1572 /* Declaring either one or more declarators (in which case we
1248 should diagnose if there were no declaration specifiers) or a 1573 should diagnose if there were no declaration specifiers) or a
1249 function definition (in which case the diagnostic for 1574 function definition (in which case the diagnostic for
1250 implicit int suffices). */ 1575 implicit int suffices). */
1251 declarator = c_parser_declarator (parser, specs->type_seen_p, 1576 declarator = c_parser_declarator (parser,
1577 specs->typespec_kind != ctsk_none,
1252 C_DTR_NORMAL, &dummy); 1578 C_DTR_NORMAL, &dummy);
1253 if (declarator == NULL) 1579 if (declarator == NULL)
1254 { 1580 {
1255 c_parser_skip_to_end_of_block_or_statement (parser); 1581 c_parser_skip_to_end_of_block_or_statement (parser);
1256 return; 1582 return;
1257 } 1583 }
1258 if (c_parser_next_token_is (parser, CPP_EQ) 1584 if (c_parser_next_token_is (parser, CPP_EQ)
1259 || c_parser_next_token_is (parser, CPP_COMMA) 1585 || c_parser_next_token_is (parser, CPP_COMMA)
1260 || c_parser_next_token_is (parser, CPP_SEMICOLON) 1586 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1261 || c_parser_next_token_is_keyword (parser, RID_ASM) 1587 || c_parser_next_token_is_keyword (parser, RID_ASM)
1262 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) 1588 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
1589 || c_parser_next_token_is_keyword (parser, RID_IN))
1263 { 1590 {
1264 tree asm_name = NULL_TREE; 1591 tree asm_name = NULL_TREE;
1265 tree postfix_attrs = NULL_TREE; 1592 tree postfix_attrs = NULL_TREE;
1266 if (!diagnosed_no_specs && !specs->declspecs_seen_p) 1593 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1267 { 1594 {
1303 tree d = start_decl (declarator, specs, false, 1630 tree d = start_decl (declarator, specs, false,
1304 chainon (postfix_attrs, 1631 chainon (postfix_attrs,
1305 all_prefix_attrs)); 1632 all_prefix_attrs));
1306 if (d) 1633 if (d)
1307 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE, 1634 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1308 NULL_TREE, asm_name); 1635 NULL_TREE, asm_name);
1636
1637 if (c_parser_next_token_is_keyword (parser, RID_IN))
1638 {
1639 if (d)
1640 *objc_foreach_object_declaration = d;
1641 else
1642 *objc_foreach_object_declaration = error_mark_node;
1643 }
1309 } 1644 }
1310 if (c_parser_next_token_is (parser, CPP_COMMA)) 1645 if (c_parser_next_token_is (parser, CPP_COMMA))
1311 { 1646 {
1312 c_parser_consume_token (parser); 1647 c_parser_consume_token (parser);
1313 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) 1648 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1318 continue; 1653 continue;
1319 } 1654 }
1320 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 1655 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1321 { 1656 {
1322 c_parser_consume_token (parser); 1657 c_parser_consume_token (parser);
1658 return;
1659 }
1660 else if (c_parser_next_token_is_keyword (parser, RID_IN))
1661 {
1662 /* This can only happen in Objective-C: we found the
1663 'in' that terminates the declaration inside an
1664 Objective-C foreach statement. Do not consume the
1665 token, so that the caller can use it to determine
1666 that this indeed is a foreach context. */
1323 return; 1667 return;
1324 } 1668 }
1325 else 1669 else
1326 { 1670 {
1327 c_parser_error (parser, "expected %<,%> or %<;%>"); 1671 c_parser_error (parser, "expected %<,%> or %<;%>");
1366 and postfix attributes have never been accepted here in 1710 and postfix attributes have never been accepted here in
1367 function definitions either. */ 1711 function definitions either. */
1368 while (c_parser_next_token_is_not (parser, CPP_EOF) 1712 while (c_parser_next_token_is_not (parser, CPP_EOF)
1369 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE)) 1713 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1370 c_parser_declaration_or_fndef (parser, false, false, false, 1714 c_parser_declaration_or_fndef (parser, false, false, false,
1371 true, false); 1715 true, false, NULL);
1372 store_parm_decls (); 1716 store_parm_decls ();
1373 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus 1717 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1374 = c_parser_peek_token (parser)->location; 1718 = c_parser_peek_token (parser)->location;
1375 fnbody = c_parser_compound_statement (parser); 1719 fnbody = c_parser_compound_statement (parser);
1376 if (nested) 1720 if (nested)
1573 storage-class-specifier: 1917 storage-class-specifier:
1574 __thread 1918 __thread
1575 1919
1576 type-specifier: 1920 type-specifier:
1577 typeof-specifier 1921 typeof-specifier
1922 __int128
1578 _Decimal32 1923 _Decimal32
1579 _Decimal64 1924 _Decimal64
1580 _Decimal128 1925 _Decimal128
1581 _Fract 1926 _Fract
1582 _Accum 1927 _Accum
1593 objc-protocol-refs 1938 objc-protocol-refs
1594 */ 1939 */
1595 1940
1596 static void 1941 static void
1597 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs, 1942 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1598 bool scspec_ok, bool typespec_ok, bool start_attr_ok) 1943 bool scspec_ok, bool typespec_ok, bool start_attr_ok,
1944 enum c_lookahead_kind la)
1599 { 1945 {
1600 bool attrs_ok = start_attr_ok; 1946 bool attrs_ok = start_attr_ok;
1601 bool seen_type = specs->type_seen_p; 1947 bool seen_type = specs->typespec_kind != ctsk_none;
1948
1949 if (!typespec_ok)
1950 gcc_assert (la == cla_prefer_id);
1951
1602 while (c_parser_next_token_is (parser, CPP_NAME) 1952 while (c_parser_next_token_is (parser, CPP_NAME)
1603 || c_parser_next_token_is (parser, CPP_KEYWORD) 1953 || c_parser_next_token_is (parser, CPP_KEYWORD)
1604 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS))) 1954 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1605 { 1955 {
1606 struct c_typespec t; 1956 struct c_typespec t;
1607 tree attrs; 1957 tree attrs;
1608 location_t loc = c_parser_peek_token (parser)->location; 1958 location_t loc = c_parser_peek_token (parser)->location;
1959
1960 /* If we cannot accept a type, exit if the next token must start
1961 one. Also, if we already have seen a tagged definition,
1962 a typename would be an error anyway and likely the user
1963 has simply forgotten a semicolon, so we exit. */
1964 if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef)
1965 && c_parser_next_tokens_start_typename (parser, la)
1966 && !c_parser_next_token_is_qualifier (parser))
1967 break;
1968
1609 if (c_parser_next_token_is (parser, CPP_NAME)) 1969 if (c_parser_next_token_is (parser, CPP_NAME))
1610 { 1970 {
1611 tree value = c_parser_peek_token (parser)->value; 1971 tree value = c_parser_peek_token (parser)->value;
1612 c_id_kind kind = c_parser_peek_token (parser)->id_kind; 1972 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1613 1973
1619 c_parser_consume_token (parser); 1979 c_parser_consume_token (parser);
1620 attrs_ok = true; 1980 attrs_ok = true;
1621 continue; 1981 continue;
1622 } 1982 }
1623 1983
1624 /* This finishes the specifiers unless a type name is OK, it 1984 gcc_assert (!c_parser_next_token_is_qualifier (parser));
1625 is declared as a type name and a type name hasn't yet 1985
1626 been seen. */ 1986 /* If we cannot accept a type, and the next token must start one,
1627 if (!typespec_ok || seen_type 1987 exit. Do the same if we already have seen a tagged definition,
1628 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME)) 1988 since it would be an error anyway and likely the user has simply
1989 forgotten a semicolon. */
1990 if (seen_type || !c_parser_next_tokens_start_typename (parser, la))
1629 break; 1991 break;
1992
1993 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
1994 a C_ID_CLASSNAME. */
1630 c_parser_consume_token (parser); 1995 c_parser_consume_token (parser);
1631 seen_type = true; 1996 seen_type = true;
1632 attrs_ok = true; 1997 attrs_ok = true;
1633 if (kind == C_ID_TYPENAME 1998 if (kind == C_ID_ID)
1634 && (!c_dialect_objc () 1999 {
1635 || c_parser_next_token_is_not (parser, CPP_LESS))) 2000 error ("unknown type name %qE", value);
2001 t.kind = ctsk_typedef;
2002 t.spec = error_mark_node;
2003 }
2004 else if (kind == C_ID_TYPENAME
2005 && (!c_dialect_objc ()
2006 || c_parser_next_token_is_not (parser, CPP_LESS)))
1636 { 2007 {
1637 t.kind = ctsk_typedef; 2008 t.kind = ctsk_typedef;
1638 /* For a typedef name, record the meaning, not the name. 2009 /* For a typedef name, record the meaning, not the name.
1639 In case of 'foo foo, bar;'. */ 2010 In case of 'foo foo, bar;'. */
1640 t.spec = lookup_name (value); 2011 t.spec = lookup_name (value);
1641 t.expr = NULL_TREE;
1642 t.expr_const_operands = true;
1643 } 2012 }
1644 else 2013 else
1645 { 2014 {
1646 tree proto = NULL_TREE; 2015 tree proto = NULL_TREE;
1647 gcc_assert (c_dialect_objc ()); 2016 gcc_assert (c_dialect_objc ());
1648 t.kind = ctsk_objc; 2017 t.kind = ctsk_objc;
1649 if (c_parser_next_token_is (parser, CPP_LESS)) 2018 if (c_parser_next_token_is (parser, CPP_LESS))
1650 proto = c_parser_objc_protocol_refs (parser); 2019 proto = c_parser_objc_protocol_refs (parser);
1651 t.spec = objc_get_protocol_qualified_type (value, proto); 2020 t.spec = objc_get_protocol_qualified_type (value, proto);
1652 t.expr = NULL_TREE; 2021 }
1653 t.expr_const_operands = true; 2022 t.expr = NULL_TREE;
1654 } 2023 t.expr_const_operands = true;
1655 declspecs_add_type (loc, specs, t); 2024 declspecs_add_type (loc, specs, t);
1656 continue; 2025 continue;
1657 } 2026 }
1658 if (c_parser_next_token_is (parser, CPP_LESS)) 2027 if (c_parser_next_token_is (parser, CPP_LESS))
1659 { 2028 {
1690 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value); 2059 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1691 c_parser_consume_token (parser); 2060 c_parser_consume_token (parser);
1692 break; 2061 break;
1693 case RID_UNSIGNED: 2062 case RID_UNSIGNED:
1694 case RID_LONG: 2063 case RID_LONG:
2064 case RID_INT128:
1695 case RID_SHORT: 2065 case RID_SHORT:
1696 case RID_SIGNED: 2066 case RID_SIGNED:
1697 case RID_COMPLEX: 2067 case RID_COMPLEX:
1698 case RID_INT: 2068 case RID_INT:
1699 case RID_CHAR: 2069 case RID_CHAR:
1829 tree enum_value; 2199 tree enum_value;
1830 tree enum_decl; 2200 tree enum_decl;
1831 bool seen_comma; 2201 bool seen_comma;
1832 c_token *token; 2202 c_token *token;
1833 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */ 2203 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1834 location_t value_loc; 2204 location_t decl_loc, value_loc;
1835 if (c_parser_next_token_is_not (parser, CPP_NAME)) 2205 if (c_parser_next_token_is_not (parser, CPP_NAME))
1836 { 2206 {
1837 c_parser_error (parser, "expected identifier"); 2207 c_parser_error (parser, "expected identifier");
1838 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); 2208 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1839 values = error_mark_node; 2209 values = error_mark_node;
1841 } 2211 }
1842 token = c_parser_peek_token (parser); 2212 token = c_parser_peek_token (parser);
1843 enum_id = token->value; 2213 enum_id = token->value;
1844 /* Set the location in case we create a decl now. */ 2214 /* Set the location in case we create a decl now. */
1845 c_parser_set_source_position_from_token (token); 2215 c_parser_set_source_position_from_token (token);
1846 value_loc = token->location; 2216 decl_loc = value_loc = token->location;
1847 c_parser_consume_token (parser); 2217 c_parser_consume_token (parser);
1848 if (c_parser_next_token_is (parser, CPP_EQ)) 2218 if (c_parser_next_token_is (parser, CPP_EQ))
1849 { 2219 {
1850 c_parser_consume_token (parser); 2220 c_parser_consume_token (parser);
1851 value_loc = c_parser_peek_token (parser)->location; 2221 value_loc = c_parser_peek_token (parser)->location;
1852 enum_value = c_parser_expr_no_commas (parser, NULL).value; 2222 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1853 } 2223 }
1854 else 2224 else
1855 enum_value = NULL_TREE; 2225 enum_value = NULL_TREE;
1856 enum_decl = build_enumerator (value_loc, 2226 enum_decl = build_enumerator (decl_loc, value_loc,
1857 &the_enum, enum_id, enum_value); 2227 &the_enum, enum_id, enum_value);
1858 TREE_CHAIN (enum_decl) = values; 2228 TREE_CHAIN (enum_decl) = values;
1859 values = enum_decl; 2229 values = enum_decl;
1860 seen_comma = false; 2230 seen_comma = false;
1861 if (c_parser_next_token_is (parser, CPP_COMMA)) 2231 if (c_parser_next_token_is (parser, CPP_COMMA))
2064 else 2434 else
2065 { 2435 {
2066 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) 2436 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2067 pedwarn (c_parser_peek_token (parser)->location, 0, 2437 pedwarn (c_parser_peek_token (parser)->location, 0,
2068 "no semicolon at end of struct or union"); 2438 "no semicolon at end of struct or union");
2069 else 2439 else if (parser->error
2440 || !c_parser_next_token_starts_declspecs (parser))
2070 { 2441 {
2071 c_parser_error (parser, "expected %<;%>"); 2442 c_parser_error (parser, "expected %<;%>");
2072 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); 2443 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2073 break; 2444 break;
2074 } 2445 }
2446
2447 /* If we come here, we have already emitted an error
2448 for an expected `;', identifier or `(', and we also
2449 recovered already. Go on with the next field. */
2075 } 2450 }
2076 } 2451 }
2077 postfix_attrs = c_parser_attributes (parser); 2452 postfix_attrs = c_parser_attributes (parser);
2078 ret.spec = finish_struct (struct_loc, type, nreverse (contents), 2453 ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2079 chainon (attrs, postfix_attrs), struct_info); 2454 chainon (attrs, postfix_attrs), struct_info);
2150 c_parser_static_assert_declaration_no_semi (parser); 2525 c_parser_static_assert_declaration_no_semi (parser);
2151 return NULL_TREE; 2526 return NULL_TREE;
2152 } 2527 }
2153 specs = build_null_declspecs (); 2528 specs = build_null_declspecs ();
2154 decl_loc = c_parser_peek_token (parser)->location; 2529 decl_loc = c_parser_peek_token (parser)->location;
2155 c_parser_declspecs (parser, specs, false, true, true); 2530 c_parser_declspecs (parser, specs, false, true, true, cla_nonabstract_decl);
2156 if (parser->error) 2531 if (parser->error)
2157 return NULL_TREE; 2532 return NULL_TREE;
2158 if (!specs->declspecs_seen_p) 2533 if (!specs->declspecs_seen_p)
2159 { 2534 {
2160 c_parser_error (parser, "expected specifier-qualifier-list"); 2535 c_parser_error (parser, "expected specifier-qualifier-list");
2161 return NULL_TREE; 2536 return NULL_TREE;
2162 } 2537 }
2163 finish_declspecs (specs); 2538 finish_declspecs (specs);
2164 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 2539 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2540 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2165 { 2541 {
2166 tree ret; 2542 tree ret;
2167 if (!specs->type_seen_p) 2543 if (specs->typespec_kind == ctsk_none)
2168 { 2544 {
2169 pedwarn (decl_loc, OPT_pedantic, 2545 pedwarn (decl_loc, OPT_pedantic,
2170 "ISO C forbids member declarations with no members"); 2546 "ISO C forbids member declarations with no members");
2171 shadow_tag_warned (specs, pedantic); 2547 shadow_tag_warned (specs, pedantic);
2172 ret = NULL_TREE; 2548 ret = NULL_TREE;
2184 if (ret) 2560 if (ret)
2185 decl_attributes (&ret, attrs, 0); 2561 decl_attributes (&ret, attrs, 0);
2186 } 2562 }
2187 return ret; 2563 return ret;
2188 } 2564 }
2565
2566 /* Provide better error recovery. Note that a type name here is valid,
2567 and will be treated as a field name. */
2568 if (specs->typespec_kind == ctsk_tagdef
2569 && TREE_CODE (specs->type) != ENUMERAL_TYPE
2570 && c_parser_next_token_starts_declspecs (parser)
2571 && !c_parser_next_token_is (parser, CPP_NAME))
2572 {
2573 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
2574 parser->error = false;
2575 return NULL_TREE;
2576 }
2577
2189 pending_xref_error (); 2578 pending_xref_error ();
2190 prefix_attrs = specs->attrs; 2579 prefix_attrs = specs->attrs;
2191 all_prefix_attrs = prefix_attrs; 2580 all_prefix_attrs = prefix_attrs;
2192 specs->attrs = NULL_TREE; 2581 specs->attrs = NULL_TREE;
2193 decls = NULL_TREE; 2582 decls = NULL_TREE;
2197 struct c_declarator *declarator; 2586 struct c_declarator *declarator;
2198 bool dummy = false; 2587 bool dummy = false;
2199 if (c_parser_next_token_is (parser, CPP_COLON)) 2588 if (c_parser_next_token_is (parser, CPP_COLON))
2200 declarator = build_id_declarator (NULL_TREE); 2589 declarator = build_id_declarator (NULL_TREE);
2201 else 2590 else
2202 declarator = c_parser_declarator (parser, specs->type_seen_p, 2591 declarator = c_parser_declarator (parser,
2592 specs->typespec_kind != ctsk_none,
2203 C_DTR_NORMAL, &dummy); 2593 C_DTR_NORMAL, &dummy);
2204 if (declarator == NULL) 2594 if (declarator == NULL)
2205 { 2595 {
2206 c_parser_skip_to_end_of_block_or_statement (parser); 2596 c_parser_skip_to_end_of_block_or_statement (parser);
2207 break; 2597 break;
2224 postfix_attrs = c_parser_attributes (parser); 2614 postfix_attrs = c_parser_attributes (parser);
2225 d = grokfield (c_parser_peek_token (parser)->location, 2615 d = grokfield (c_parser_peek_token (parser)->location,
2226 declarator, specs, width, &all_prefix_attrs); 2616 declarator, specs, width, &all_prefix_attrs);
2227 decl_attributes (&d, chainon (postfix_attrs, 2617 decl_attributes (&d, chainon (postfix_attrs,
2228 all_prefix_attrs), 0); 2618 all_prefix_attrs), 0);
2229 TREE_CHAIN (d) = decls; 2619 DECL_CHAIN (d) = decls;
2230 decls = d; 2620 decls = d;
2231 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) 2621 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2232 all_prefix_attrs = chainon (c_parser_attributes (parser), 2622 all_prefix_attrs = chainon (c_parser_attributes (parser),
2233 prefix_attrs); 2623 prefix_attrs);
2234 else 2624 else
2281 { 2671 {
2282 c_inhibit_evaluation_warnings--; 2672 c_inhibit_evaluation_warnings--;
2283 in_typeof--; 2673 in_typeof--;
2284 return ret; 2674 return ret;
2285 } 2675 }
2286 if (c_parser_next_token_starts_typename (parser)) 2676 if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
2287 { 2677 {
2288 struct c_type_name *type = c_parser_type_name (parser); 2678 struct c_type_name *type = c_parser_type_name (parser);
2289 c_inhibit_evaluation_warnings--; 2679 c_inhibit_evaluation_warnings--;
2290 in_typeof--; 2680 in_typeof--;
2291 if (type != NULL) 2681 if (type != NULL)
2402 if (c_parser_next_token_is (parser, CPP_MULT)) 2792 if (c_parser_next_token_is (parser, CPP_MULT))
2403 { 2793 {
2404 struct c_declspecs *quals_attrs = build_null_declspecs (); 2794 struct c_declspecs *quals_attrs = build_null_declspecs ();
2405 struct c_declarator *inner; 2795 struct c_declarator *inner;
2406 c_parser_consume_token (parser); 2796 c_parser_consume_token (parser);
2407 c_parser_declspecs (parser, quals_attrs, false, false, true); 2797 c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
2408 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id); 2798 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2409 if (inner == NULL) 2799 if (inner == NULL)
2410 return NULL; 2800 return NULL;
2411 else 2801 else
2412 return make_pointer_declarator (quals_attrs, inner); 2802 return make_pointer_declarator (quals_attrs, inner);
2458 redeclared in declarators, but not Objective-C class names. */ 2848 redeclared in declarators, but not Objective-C class names. */
2459 2849
2460 if (kind != C_DTR_ABSTRACT 2850 if (kind != C_DTR_ABSTRACT
2461 && c_parser_next_token_is (parser, CPP_NAME) 2851 && c_parser_next_token_is (parser, CPP_NAME)
2462 && ((type_seen_p 2852 && ((type_seen_p
2463 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME) 2853 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
2854 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
2464 || c_parser_peek_token (parser)->id_kind == C_ID_ID)) 2855 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2465 { 2856 {
2466 struct c_declarator *inner 2857 struct c_declarator *inner
2467 = build_id_declarator (c_parser_peek_token (parser)->value); 2858 = build_id_declarator (c_parser_peek_token (parser)->value);
2468 *seen_id = true; 2859 *seen_id = true;
2553 struct c_declspecs *quals_attrs = build_null_declspecs (); 2944 struct c_declspecs *quals_attrs = build_null_declspecs ();
2554 bool static_seen; 2945 bool static_seen;
2555 bool star_seen; 2946 bool star_seen;
2556 tree dimen; 2947 tree dimen;
2557 c_parser_consume_token (parser); 2948 c_parser_consume_token (parser);
2558 c_parser_declspecs (parser, quals_attrs, false, false, true); 2949 c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
2559 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC); 2950 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2560 if (static_seen) 2951 if (static_seen)
2561 c_parser_consume_token (parser); 2952 c_parser_consume_token (parser);
2562 if (static_seen && !quals_attrs->declspecs_seen_p) 2953 if (static_seen && !quals_attrs->declspecs_seen_p)
2563 c_parser_declspecs (parser, quals_attrs, false, false, true); 2954 c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
2564 if (!quals_attrs->declspecs_seen_p) 2955 if (!quals_attrs->declspecs_seen_p)
2565 quals_attrs = NULL; 2956 quals_attrs = NULL;
2566 /* If "static" is present, there must be an array dimension. 2957 /* If "static" is present, there must be an array dimension.
2567 Otherwise, there may be a dimension, "*", or no 2958 Otherwise, there may be a dimension, "*", or no
2568 dimension. */ 2959 dimension. */
2646 /* If the list starts with an identifier, it is an identifier list. 3037 /* If the list starts with an identifier, it is an identifier list.
2647 Otherwise, it is either a prototype list or an empty list. */ 3038 Otherwise, it is either a prototype list or an empty list. */
2648 if (id_list_ok 3039 if (id_list_ok
2649 && !attrs 3040 && !attrs
2650 && c_parser_next_token_is (parser, CPP_NAME) 3041 && c_parser_next_token_is (parser, CPP_NAME)
2651 && c_parser_peek_token (parser)->id_kind == C_ID_ID) 3042 && c_parser_peek_token (parser)->id_kind == C_ID_ID
3043
3044 /* Look ahead to detect typos in type names. */
3045 && c_parser_peek_2nd_token (parser)->type != CPP_NAME
3046 && c_parser_peek_2nd_token (parser)->type != CPP_MULT
3047 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
3048 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE)
2652 { 3049 {
2653 tree list = NULL_TREE, *nextp = &list; 3050 tree list = NULL_TREE, *nextp = &list;
2654 while (c_parser_next_token_is (parser, CPP_NAME) 3051 while (c_parser_next_token_is (parser, CPP_NAME)
2655 && c_parser_peek_token (parser)->id_kind == C_ID_ID) 3052 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2656 { 3053 {
2667 break; 3064 break;
2668 } 3065 }
2669 } 3066 }
2670 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 3067 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2671 { 3068 {
2672 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info); 3069 struct c_arg_info *ret = build_arg_info ();
2673 ret->parms = 0;
2674 ret->tags = 0;
2675 ret->types = list; 3070 ret->types = list;
2676 ret->others = 0;
2677 ret->pending_sizes = 0;
2678 ret->had_vla_unspec = 0;
2679 c_parser_consume_token (parser); 3071 c_parser_consume_token (parser);
2680 pop_scope (); 3072 pop_scope ();
2681 return ret; 3073 return ret;
2682 } 3074 }
2683 else 3075 else
2701 the start of the list. */ 3093 the start of the list. */
2702 3094
2703 static struct c_arg_info * 3095 static struct c_arg_info *
2704 c_parser_parms_list_declarator (c_parser *parser, tree attrs) 3096 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2705 { 3097 {
2706 bool good_parm = false; 3098 bool bad_parm = false;
2707 /* ??? Following the old parser, forward parameter declarations may 3099 /* ??? Following the old parser, forward parameter declarations may
2708 use abstract declarators, and if no real parameter declarations 3100 use abstract declarators, and if no real parameter declarations
2709 follow the forward declarations then this is not diagnosed. Also 3101 follow the forward declarations then this is not diagnosed. Also
2710 note as above that attributes are ignored as the only contents of 3102 note as above that attributes are ignored as the only contents of
2711 the parentheses, or as the only contents after forward 3103 the parentheses, or as the only contents after forward
2712 declarations. */ 3104 declarations. */
2713 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 3105 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2714 { 3106 {
2715 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info); 3107 struct c_arg_info *ret = build_arg_info ();
2716 ret->parms = 0;
2717 ret->tags = 0;
2718 ret->types = 0;
2719 ret->others = 0;
2720 ret->pending_sizes = 0;
2721 ret->had_vla_unspec = 0;
2722 c_parser_consume_token (parser); 3108 c_parser_consume_token (parser);
2723 return ret; 3109 return ret;
2724 } 3110 }
2725 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) 3111 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2726 { 3112 {
2727 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info); 3113 struct c_arg_info *ret = build_arg_info ();
2728 ret->parms = 0;
2729 ret->tags = 0;
2730 ret->others = 0;
2731 ret->pending_sizes = 0;
2732 ret->had_vla_unspec = 0;
2733 /* Suppress -Wold-style-definition for this case. */ 3114 /* Suppress -Wold-style-definition for this case. */
2734 ret->types = error_mark_node; 3115 ret->types = error_mark_node;
2735 error_at (c_parser_peek_token (parser)->location, 3116 error_at (c_parser_peek_token (parser)->location,
2736 "ISO C requires a named argument before %<...%>"); 3117 "ISO C requires a named argument before %<...%>");
2737 c_parser_consume_token (parser); 3118 c_parser_consume_token (parser);
2753 while (true) 3134 while (true)
2754 { 3135 {
2755 /* Parse a parameter. */ 3136 /* Parse a parameter. */
2756 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs); 3137 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2757 attrs = NULL_TREE; 3138 attrs = NULL_TREE;
2758 if (parm != NULL) 3139 if (parm == NULL)
2759 { 3140 bad_parm = true;
2760 good_parm = true; 3141 else
2761 push_parm_decl (parm); 3142 push_parm_decl (parm);
2762 }
2763 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 3143 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2764 { 3144 {
2765 tree new_attrs; 3145 tree new_attrs;
2766 c_parser_consume_token (parser); 3146 c_parser_consume_token (parser);
2767 mark_forward_parm_decls (); 3147 mark_forward_parm_decls ();
2769 return c_parser_parms_list_declarator (parser, new_attrs); 3149 return c_parser_parms_list_declarator (parser, new_attrs);
2770 } 3150 }
2771 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 3151 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2772 { 3152 {
2773 c_parser_consume_token (parser); 3153 c_parser_consume_token (parser);
2774 if (good_parm) 3154 if (bad_parm)
3155 {
3156 get_pending_sizes ();
3157 return NULL;
3158 }
3159 else
2775 return get_parm_info (false); 3160 return get_parm_info (false);
2776 else
2777 {
2778 struct c_arg_info *ret
2779 = XOBNEW (&parser_obstack, struct c_arg_info);
2780 ret->parms = 0;
2781 ret->tags = 0;
2782 ret->types = 0;
2783 ret->others = 0;
2784 ret->pending_sizes = 0;
2785 ret->had_vla_unspec = 0;
2786 return ret;
2787 }
2788 } 3161 }
2789 if (!c_parser_require (parser, CPP_COMMA, 3162 if (!c_parser_require (parser, CPP_COMMA,
2790 "expected %<;%>, %<,%> or %<)%>")) 3163 "expected %<;%>, %<,%> or %<)%>"))
2791 { 3164 {
2792 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 3165 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2797 { 3170 {
2798 c_parser_consume_token (parser); 3171 c_parser_consume_token (parser);
2799 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 3172 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2800 { 3173 {
2801 c_parser_consume_token (parser); 3174 c_parser_consume_token (parser);
2802 if (good_parm) 3175 if (bad_parm)
3176 {
3177 get_pending_sizes ();
3178 return NULL;
3179 }
3180 else
2803 return get_parm_info (true); 3181 return get_parm_info (true);
2804 else
2805 {
2806 struct c_arg_info *ret
2807 = XOBNEW (&parser_obstack, struct c_arg_info);
2808 ret->parms = 0;
2809 ret->tags = 0;
2810 ret->types = 0;
2811 ret->others = 0;
2812 ret->pending_sizes = 0;
2813 ret->had_vla_unspec = 0;
2814 return ret;
2815 }
2816 } 3182 }
2817 else 3183 else
2818 { 3184 {
2819 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 3185 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2820 "expected %<)%>"); 3186 "expected %<)%>");
2836 tree prefix_attrs; 3202 tree prefix_attrs;
2837 tree postfix_attrs = NULL_TREE; 3203 tree postfix_attrs = NULL_TREE;
2838 bool dummy = false; 3204 bool dummy = false;
2839 if (!c_parser_next_token_starts_declspecs (parser)) 3205 if (!c_parser_next_token_starts_declspecs (parser))
2840 { 3206 {
3207 c_token *token = c_parser_peek_token (parser);
3208 if (parser->error)
3209 return NULL;
3210 c_parser_set_source_position_from_token (token);
3211 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
3212 {
3213 error ("unknown type name %qE", token->value);
3214 parser->error = true;
3215 }
2841 /* ??? In some Objective-C cases '...' isn't applicable so there 3216 /* ??? In some Objective-C cases '...' isn't applicable so there
2842 should be a different message. */ 3217 should be a different message. */
2843 c_parser_error (parser, 3218 else
2844 "expected declaration specifiers or %<...%>"); 3219 c_parser_error (parser,
3220 "expected declaration specifiers or %<...%>");
2845 c_parser_skip_to_end_of_parameter (parser); 3221 c_parser_skip_to_end_of_parameter (parser);
2846 return NULL; 3222 return NULL;
2847 } 3223 }
2848 specs = build_null_declspecs (); 3224 specs = build_null_declspecs ();
2849 if (attrs) 3225 if (attrs)
2850 { 3226 {
2851 declspecs_add_attrs (specs, attrs); 3227 declspecs_add_attrs (specs, attrs);
2852 attrs = NULL_TREE; 3228 attrs = NULL_TREE;
2853 } 3229 }
2854 c_parser_declspecs (parser, specs, true, true, true); 3230 c_parser_declspecs (parser, specs, true, true, true, cla_nonabstract_decl);
2855 finish_declspecs (specs); 3231 finish_declspecs (specs);
2856 pending_xref_error (); 3232 pending_xref_error ();
2857 prefix_attrs = specs->attrs; 3233 prefix_attrs = specs->attrs;
2858 specs->attrs = NULL_TREE; 3234 specs->attrs = NULL_TREE;
2859 declarator = c_parser_declarator (parser, specs->type_seen_p, 3235 declarator = c_parser_declarator (parser,
3236 specs->typespec_kind != ctsk_none,
2860 C_DTR_PARM, &dummy); 3237 C_DTR_PARM, &dummy);
2861 if (declarator == NULL) 3238 if (declarator == NULL)
2862 { 3239 {
2863 c_parser_skip_until_found (parser, CPP_COMMA, NULL); 3240 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2864 return NULL; 3241 return NULL;
3004 switch (c_parser_peek_token (parser)->keyword) 3381 switch (c_parser_peek_token (parser)->keyword)
3005 { 3382 {
3006 case RID_STATIC: 3383 case RID_STATIC:
3007 case RID_UNSIGNED: 3384 case RID_UNSIGNED:
3008 case RID_LONG: 3385 case RID_LONG:
3386 case RID_INT128:
3009 case RID_CONST: 3387 case RID_CONST:
3010 case RID_EXTERN: 3388 case RID_EXTERN:
3011 case RID_REGISTER: 3389 case RID_REGISTER:
3012 case RID_TYPEDEF: 3390 case RID_TYPEDEF:
3013 case RID_SHORT: 3391 case RID_SHORT:
3054 } 3432 }
3055 c_parser_consume_token (parser); 3433 c_parser_consume_token (parser);
3056 /* Parse the attribute contents. If they start with an 3434 /* Parse the attribute contents. If they start with an
3057 identifier which is followed by a comma or close 3435 identifier which is followed by a comma or close
3058 parenthesis, then the arguments start with that 3436 parenthesis, then the arguments start with that
3059 identifier; otherwise they are an expression list. */ 3437 identifier; otherwise they are an expression list.
3438 In objective-c the identifier may be a classname. */
3060 if (c_parser_next_token_is (parser, CPP_NAME) 3439 if (c_parser_next_token_is (parser, CPP_NAME)
3061 && c_parser_peek_token (parser)->id_kind == C_ID_ID 3440 && (c_parser_peek_token (parser)->id_kind == C_ID_ID
3441 || (c_dialect_objc ()
3442 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
3062 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA) 3443 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
3063 || (c_parser_peek_2nd_token (parser)->type 3444 || (c_parser_peek_2nd_token (parser)->type
3064 == CPP_CLOSE_PAREN))) 3445 == CPP_CLOSE_PAREN)))
3065 { 3446 {
3066 tree arg1 = c_parser_peek_token (parser)->value; 3447 tree arg1 = c_parser_peek_token (parser)->value;
3134 { 3515 {
3135 struct c_declspecs *specs = build_null_declspecs (); 3516 struct c_declspecs *specs = build_null_declspecs ();
3136 struct c_declarator *declarator; 3517 struct c_declarator *declarator;
3137 struct c_type_name *ret; 3518 struct c_type_name *ret;
3138 bool dummy = false; 3519 bool dummy = false;
3139 c_parser_declspecs (parser, specs, false, true, true); 3520 c_parser_declspecs (parser, specs, false, true, true, cla_prefer_type);
3140 if (!specs->declspecs_seen_p) 3521 if (!specs->declspecs_seen_p)
3141 { 3522 {
3142 c_parser_error (parser, "expected specifier-qualifier-list"); 3523 c_parser_error (parser, "expected specifier-qualifier-list");
3143 return NULL; 3524 return NULL;
3144 } 3525 }
3145 pending_xref_error (); 3526 if (specs->type != error_mark_node)
3146 finish_declspecs (specs); 3527 {
3147 declarator = c_parser_declarator (parser, specs->type_seen_p, 3528 pending_xref_error ();
3529 finish_declspecs (specs);
3530 }
3531 declarator = c_parser_declarator (parser,
3532 specs->typespec_kind != ctsk_none,
3148 C_DTR_ABSTRACT, &dummy); 3533 C_DTR_ABSTRACT, &dummy);
3149 if (declarator == NULL) 3534 if (declarator == NULL)
3150 return NULL; 3535 return NULL;
3151 ret = XOBNEW (&parser_obstack, struct c_type_name); 3536 ret = XOBNEW (&parser_obstack, struct c_type_name);
3152 ret->specs = specs; 3537 ret->specs = specs;
3636 last_stmt = false; 4021 last_stmt = false;
3637 mark_valid_location_for_stdc_pragma (false); 4022 mark_valid_location_for_stdc_pragma (false);
3638 c_parser_label (parser); 4023 c_parser_label (parser);
3639 } 4024 }
3640 else if (!last_label 4025 else if (!last_label
3641 && c_parser_next_token_starts_declaration (parser)) 4026 && c_parser_next_tokens_start_declaration (parser))
3642 { 4027 {
3643 last_label = false; 4028 last_label = false;
3644 mark_valid_location_for_stdc_pragma (false); 4029 mark_valid_location_for_stdc_pragma (false);
3645 c_parser_declaration_or_fndef (parser, true, true, true, true, true); 4030 c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
3646 if (last_stmt) 4031 if (last_stmt)
3647 pedwarn_c90 (loc, 4032 pedwarn_c90 (loc,
3648 (pedantic && !flag_isoc99) 4033 (pedantic && !flag_isoc99)
3649 ? OPT_pedantic 4034 ? OPT_pedantic
3650 : OPT_Wdeclaration_after_statement, 4035 : OPT_Wdeclaration_after_statement,
3668 ext = disable_extension_diagnostics (); 4053 ext = disable_extension_diagnostics ();
3669 c_parser_consume_token (parser); 4054 c_parser_consume_token (parser);
3670 last_label = false; 4055 last_label = false;
3671 mark_valid_location_for_stdc_pragma (false); 4056 mark_valid_location_for_stdc_pragma (false);
3672 c_parser_declaration_or_fndef (parser, true, true, true, true, 4057 c_parser_declaration_or_fndef (parser, true, true, true, true,
3673 true); 4058 true, NULL);
3674 /* Following the old parser, __extension__ does not 4059 /* Following the old parser, __extension__ does not
3675 disable this diagnostic. */ 4060 disable this diagnostic. */
3676 restore_extension_diagnostics (ext); 4061 restore_extension_diagnostics (ext);
3677 if (last_stmt) 4062 if (last_stmt)
3678 pedwarn_c90 (loc, (pedantic && !flag_isoc99) 4063 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
3798 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab)); 4183 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
3799 } 4184 }
3800 } 4185 }
3801 if (label) 4186 if (label)
3802 { 4187 {
3803 if (c_parser_next_token_starts_declaration (parser) 4188 if (c_parser_next_tokens_start_declaration (parser))
3804 && !(c_parser_next_token_is (parser, CPP_NAME)
3805 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3806 { 4189 {
3807 error_at (c_parser_peek_token (parser)->location, 4190 error_at (c_parser_peek_token (parser)->location,
3808 "a label can only be part of a statement and " 4191 "a label can only be part of a statement and "
3809 "a declaration is not a statement"); 4192 "a declaration is not a statement");
3810 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false, 4193 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
3811 /*static_assert_ok*/ true, 4194 /*static_assert_ok*/ true,
3812 /*nested*/ true, /*empty_ok*/ false, 4195 /*nested*/ true, /*empty_ok*/ false,
3813 /*start_attr_ok*/ true); 4196 /*start_attr_ok*/ true, NULL);
3814 } 4197 }
3815 } 4198 }
3816 } 4199 }
3817 4200
3818 /* Parse a statement (C90 6.6, C99 6.8). 4201 /* Parse a statement (C90 6.6, C99 6.8).
3963 c_parser_peek_token (parser)->value); 4346 c_parser_peek_token (parser)->value);
3964 c_parser_consume_token (parser); 4347 c_parser_consume_token (parser);
3965 } 4348 }
3966 else if (c_parser_next_token_is (parser, CPP_MULT)) 4349 else if (c_parser_next_token_is (parser, CPP_MULT))
3967 { 4350 {
4351 tree val;
4352
3968 c_parser_consume_token (parser); 4353 c_parser_consume_token (parser);
3969 stmt = c_finish_goto_ptr (loc, 4354 val = c_parser_expression (parser).value;
3970 c_parser_expression (parser).value); 4355 mark_exp_read (val);
4356 stmt = c_finish_goto_ptr (loc, val);
3971 } 4357 }
3972 else 4358 else
3973 c_parser_error (parser, "expected identifier or %<*%>"); 4359 c_parser_error (parser, "expected identifier or %<*%>");
3974 goto expect_semicolon; 4360 goto expect_semicolon;
3975 case RID_CONTINUE: 4361 case RID_CONTINUE:
3996 } 4382 }
3997 break; 4383 break;
3998 case RID_ASM: 4384 case RID_ASM:
3999 stmt = c_parser_asm_statement (parser); 4385 stmt = c_parser_asm_statement (parser);
4000 break; 4386 break;
4001 case RID_THROW: 4387 case RID_AT_THROW:
4002 gcc_assert (c_dialect_objc ()); 4388 gcc_assert (c_dialect_objc ());
4003 c_parser_consume_token (parser); 4389 c_parser_consume_token (parser);
4004 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 4390 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4005 { 4391 {
4006 stmt = objc_build_throw_stmt (loc, NULL_TREE); 4392 stmt = objc_build_throw_stmt (loc, NULL_TREE);
4012 expr = c_fully_fold (expr, false, NULL); 4398 expr = c_fully_fold (expr, false, NULL);
4013 stmt = objc_build_throw_stmt (loc, expr); 4399 stmt = objc_build_throw_stmt (loc, expr);
4014 goto expect_semicolon; 4400 goto expect_semicolon;
4015 } 4401 }
4016 break; 4402 break;
4017 case RID_TRY: 4403 case RID_AT_TRY:
4018 gcc_assert (c_dialect_objc ()); 4404 gcc_assert (c_dialect_objc ());
4019 c_parser_objc_try_catch_statement (parser); 4405 c_parser_objc_try_catch_finally_statement (parser);
4020 break; 4406 break;
4021 case RID_AT_SYNCHRONIZED: 4407 case RID_AT_SYNCHRONIZED:
4022 gcc_assert (c_dialect_objc ()); 4408 gcc_assert (c_dialect_objc ());
4023 c_parser_objc_synchronized_statement (parser); 4409 c_parser_objc_synchronized_statement (parser);
4024 break; 4410 break;
4324 nested function, which is then rejected in check_for_loop_decls, 4710 nested function, which is then rejected in check_for_loop_decls,
4325 but does it make any sense for this to be included in the grammar? 4711 but does it make any sense for this to be included in the grammar?
4326 Note in particular that the nested function does not include a 4712 Note in particular that the nested function does not include a
4327 trailing ';', whereas the "declaration" production includes one. 4713 trailing ';', whereas the "declaration" production includes one.
4328 Also, can we reject bad declarations earlier and cheaper than 4714 Also, can we reject bad declarations earlier and cheaper than
4329 check_for_loop_decls? */ 4715 check_for_loop_decls?
4716
4717 In Objective-C, there are two additional variants:
4718
4719 foreach-statement:
4720 for ( expression in expresssion ) statement
4721 for ( declaration in expression ) statement
4722
4723 This is inconsistent with C, because the second variant is allowed
4724 even if c99 is not enabled.
4725
4726 The rest of the comment documents these Objective-C foreach-statement.
4727
4728 Here is the canonical example of the first variant:
4729 for (object in array) { do something with object }
4730 we call the first expression ("object") the "object_expression" and
4731 the second expression ("array") the "collection_expression".
4732 object_expression must be an lvalue of type "id" (a generic Objective-C
4733 object) because the loop works by assigning to object_expression the
4734 various objects from the collection_expression. collection_expression
4735 must evaluate to something of type "id" which responds to the method
4736 countByEnumeratingWithState:objects:count:.
4737
4738 The canonical example of the second variant is:
4739 for (id object in array) { do something with object }
4740 which is completely equivalent to
4741 {
4742 id object;
4743 for (object in array) { do something with object }
4744 }
4745 Note that initizializing 'object' in some way (eg, "for ((object =
4746 xxx) in array) { do something with object }") is possibly
4747 technically valid, but completely pointless as 'object' will be
4748 assigned to something else as soon as the loop starts. We should
4749 most likely reject it (TODO).
4750
4751 The beginning of the Objective-C foreach-statement looks exactly
4752 like the beginning of the for-statement, and we can tell it is a
4753 foreach-statement only because the initial declaration or
4754 expression is terminated by 'in' instead of ';'.
4755 */
4330 4756
4331 static void 4757 static void
4332 c_parser_for_statement (c_parser *parser) 4758 c_parser_for_statement (c_parser *parser)
4333 { 4759 {
4334 tree block, cond, incr, save_break, save_cont, body; 4760 tree block, cond, incr, save_break, save_cont, body;
4761 /* The following are only used when parsing an ObjC foreach statement. */
4762 tree object_expression;
4763 /* Silence the bogus uninitialized warning. */
4764 tree collection_expression = NULL;
4335 location_t loc = c_parser_peek_token (parser)->location; 4765 location_t loc = c_parser_peek_token (parser)->location;
4336 location_t for_loc = c_parser_peek_token (parser)->location; 4766 location_t for_loc = c_parser_peek_token (parser)->location;
4767 bool is_foreach_statement = false;
4337 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR)); 4768 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4338 c_parser_consume_token (parser); 4769 c_parser_consume_token (parser);
4339 block = c_begin_compound_stmt (flag_isoc99); 4770 /* Open a compound statement in Objective-C as well, just in case this is
4771 as foreach expression. */
4772 block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
4773 cond = error_mark_node;
4774 incr = error_mark_node;
4340 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 4775 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4341 { 4776 {
4342 /* Parse the initialization declaration or expression. */ 4777 /* Parse the initialization declaration or expression. */
4778 object_expression = error_mark_node;
4779 parser->objc_could_be_foreach_context = c_dialect_objc ();
4343 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 4780 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4344 { 4781 {
4782 parser->objc_could_be_foreach_context = false;
4345 c_parser_consume_token (parser); 4783 c_parser_consume_token (parser);
4346 c_finish_expr_stmt (loc, NULL_TREE); 4784 c_finish_expr_stmt (loc, NULL_TREE);
4347 } 4785 }
4348 else if (c_parser_next_token_starts_declaration (parser)) 4786 else if (c_parser_next_tokens_start_declaration (parser))
4349 { 4787 {
4350 c_parser_declaration_or_fndef (parser, true, true, true, true, true); 4788 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
4351 check_for_loop_decls (for_loc); 4789 &object_expression);
4790 parser->objc_could_be_foreach_context = false;
4791
4792 if (c_parser_next_token_is_keyword (parser, RID_IN))
4793 {
4794 c_parser_consume_token (parser);
4795 is_foreach_statement = true;
4796 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4797 c_parser_error (parser, "multiple iterating variables in fast enumeration");
4798 }
4799 else
4800 check_for_loop_decls (for_loc, flag_isoc99);
4352 } 4801 }
4353 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION)) 4802 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4354 { 4803 {
4355 /* __extension__ can start a declaration, but is also an 4804 /* __extension__ can start a declaration, but is also an
4356 unary operator that can start an expression. Consume all 4805 unary operator that can start an expression. Consume all
4364 { 4813 {
4365 int ext; 4814 int ext;
4366 ext = disable_extension_diagnostics (); 4815 ext = disable_extension_diagnostics ();
4367 c_parser_consume_token (parser); 4816 c_parser_consume_token (parser);
4368 c_parser_declaration_or_fndef (parser, true, true, true, true, 4817 c_parser_declaration_or_fndef (parser, true, true, true, true,
4369 true); 4818 true, &object_expression);
4819 parser->objc_could_be_foreach_context = false;
4820
4370 restore_extension_diagnostics (ext); 4821 restore_extension_diagnostics (ext);
4371 check_for_loop_decls (for_loc); 4822 if (c_parser_next_token_is_keyword (parser, RID_IN))
4823 {
4824 c_parser_consume_token (parser);
4825 is_foreach_statement = true;
4826 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4827 c_parser_error (parser, "multiple iterating variables in fast enumeration");
4828 }
4829 else
4830 check_for_loop_decls (for_loc, flag_isoc99);
4372 } 4831 }
4373 else 4832 else
4374 goto init_expr; 4833 goto init_expr;
4375 } 4834 }
4376 else 4835 else
4377 { 4836 {
4378 init_expr: 4837 init_expr:
4379 c_finish_expr_stmt (loc, c_parser_expression (parser).value); 4838 {
4380 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 4839 tree init_expression;
4381 } 4840 init_expression = c_parser_expression (parser).value;
4382 /* Parse the loop condition. */ 4841 parser->objc_could_be_foreach_context = false;
4383 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 4842 if (c_parser_next_token_is_keyword (parser, RID_IN))
4384 { 4843 {
4385 c_parser_consume_token (parser); 4844 c_parser_consume_token (parser);
4386 cond = NULL_TREE; 4845 is_foreach_statement = true;
4846 if (! lvalue_p (init_expression))
4847 c_parser_error (parser, "invalid iterating variable in fast enumeration");
4848 object_expression = c_fully_fold (init_expression, false, NULL);
4849 }
4850 else
4851 {
4852 c_finish_expr_stmt (loc, init_expression);
4853 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4854 }
4855 }
4856 }
4857 /* Parse the loop condition. In the case of a foreach
4858 statement, there is no loop condition. */
4859 gcc_assert (!parser->objc_could_be_foreach_context);
4860 if (!is_foreach_statement)
4861 {
4862 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4863 {
4864 c_parser_consume_token (parser);
4865 cond = NULL_TREE;
4866 }
4867 else
4868 {
4869 cond = c_parser_condition (parser);
4870 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4871 }
4872 }
4873 /* Parse the increment expression (the third expression in a
4874 for-statement). In the case of a foreach-statement, this is
4875 the expression that follows the 'in'. */
4876 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4877 {
4878 if (is_foreach_statement)
4879 {
4880 c_parser_error (parser, "missing collection in fast enumeration");
4881 collection_expression = error_mark_node;
4882 }
4883 else
4884 incr = c_process_expr_stmt (loc, NULL_TREE);
4387 } 4885 }
4388 else 4886 else
4389 { 4887 {
4390 cond = c_parser_condition (parser); 4888 if (is_foreach_statement)
4391 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 4889 collection_expression = c_fully_fold (c_parser_expression (parser).value,
4392 } 4890 false, NULL);
4393 /* Parse the increment expression. */ 4891 else
4394 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 4892 incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4395 incr = c_process_expr_stmt (loc, NULL_TREE); 4893 }
4396 else
4397 incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4398 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 4894 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4399 }
4400 else
4401 {
4402 cond = error_mark_node;
4403 incr = error_mark_node;
4404 } 4895 }
4405 save_break = c_break_label; 4896 save_break = c_break_label;
4406 c_break_label = NULL_TREE; 4897 c_break_label = NULL_TREE;
4407 save_cont = c_cont_label; 4898 save_cont = c_cont_label;
4408 c_cont_label = NULL_TREE; 4899 c_cont_label = NULL_TREE;
4409 body = c_parser_c99_block_statement (parser); 4900 body = c_parser_c99_block_statement (parser);
4410 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true); 4901 if (is_foreach_statement)
4411 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99)); 4902 objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
4903 else
4904 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4905 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
4412 c_break_label = save_break; 4906 c_break_label = save_break;
4413 c_cont_label = save_cont; 4907 c_cont_label = save_cont;
4414 } 4908 }
4415 4909
4416 /* Parse an asm statement, a GNU extension. This is a full-blown asm 4910 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4789 5283
4790 static struct c_expr 5284 static struct c_expr
4791 c_parser_conditional_expression (c_parser *parser, struct c_expr *after) 5285 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4792 { 5286 {
4793 struct c_expr cond, exp1, exp2, ret; 5287 struct c_expr cond, exp1, exp2, ret;
4794 location_t cond_loc, colon_loc; 5288 location_t cond_loc, colon_loc, middle_loc;
4795 5289
4796 gcc_assert (!after || c_dialect_objc ()); 5290 gcc_assert (!after || c_dialect_objc ());
4797 5291
4798 cond = c_parser_binary_expression (parser, after); 5292 cond = c_parser_binary_expression (parser, after);
4799 5293
4803 cond = default_function_array_read_conversion (cond_loc, cond); 5297 cond = default_function_array_read_conversion (cond_loc, cond);
4804 c_parser_consume_token (parser); 5298 c_parser_consume_token (parser);
4805 if (c_parser_next_token_is (parser, CPP_COLON)) 5299 if (c_parser_next_token_is (parser, CPP_COLON))
4806 { 5300 {
4807 tree eptype = NULL_TREE; 5301 tree eptype = NULL_TREE;
4808 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic, 5302
5303 middle_loc = c_parser_peek_token (parser)->location;
5304 pedwarn (middle_loc, OPT_pedantic,
4809 "ISO C forbids omitting the middle term of a ?: expression"); 5305 "ISO C forbids omitting the middle term of a ?: expression");
5306 warn_for_omitted_condop (middle_loc, cond.value);
4810 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR) 5307 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
4811 { 5308 {
4812 eptype = TREE_TYPE (cond.value); 5309 eptype = TREE_TYPE (cond.value);
4813 cond.value = TREE_OPERAND (cond.value, 0); 5310 cond.value = TREE_OPERAND (cond.value, 0);
4814 } 5311 }
5158 return c_parser_postfix_expression_after_primary (parser, 5655 return c_parser_postfix_expression_after_primary (parser,
5159 cast_loc, *after); 5656 cast_loc, *after);
5160 /* If the expression begins with a parenthesized type name, it may 5657 /* If the expression begins with a parenthesized type name, it may
5161 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
5162 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
5163 an unary expression. */ 5660 an unary expression. Full detection of unknown typenames here
5661 would require a 3-token lookahead. */
5164 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) 5662 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5165 && c_token_starts_typename (c_parser_peek_2nd_token (parser))) 5663 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5166 { 5664 {
5167 struct c_type_name *type_name; 5665 struct c_type_name *type_name;
5168 struct c_expr ret; 5666 struct c_expr ret;
5506 [ objc-receiver objc-message-args ] 6004 [ objc-receiver objc-message-args ]
5507 @selector ( objc-selector-arg ) 6005 @selector ( objc-selector-arg )
5508 @protocol ( identifier ) 6006 @protocol ( identifier )
5509 @encode ( type-name ) 6007 @encode ( type-name )
5510 objc-string-literal 6008 objc-string-literal
6009 Classname . identifier
5511 */ 6010 */
5512 6011
5513 static struct c_expr 6012 static struct c_expr
5514 c_parser_postfix_expression (c_parser *parser) 6013 c_parser_postfix_expression (c_parser *parser)
5515 { 6014 {
5552 expr.value 6051 expr.value
5553 = objc_build_string_object (c_parser_peek_token (parser)->value); 6052 = objc_build_string_object (c_parser_peek_token (parser)->value);
5554 c_parser_consume_token (parser); 6053 c_parser_consume_token (parser);
5555 break; 6054 break;
5556 case CPP_NAME: 6055 case CPP_NAME:
5557 if (c_parser_peek_token (parser)->id_kind != C_ID_ID) 6056 switch (c_parser_peek_token (parser)->id_kind)
5558 { 6057 {
6058 case C_ID_ID:
6059 {
6060 tree id = c_parser_peek_token (parser)->value;
6061 c_parser_consume_token (parser);
6062 expr.value = build_external_ref (loc, id,
6063 (c_parser_peek_token (parser)->type
6064 == CPP_OPEN_PAREN),
6065 &expr.original_type);
6066 break;
6067 }
6068 case C_ID_CLASSNAME:
6069 {
6070 /* Here we parse the Objective-C 2.0 Class.name dot
6071 syntax. */
6072 tree class_name = c_parser_peek_token (parser)->value;
6073 tree component;
6074 c_parser_consume_token (parser);
6075 gcc_assert (c_dialect_objc ());
6076 if (!c_parser_require (parser, CPP_DOT, "expected %<.%>"))
6077 {
6078 expr.value = error_mark_node;
6079 break;
6080 }
6081 if (c_parser_next_token_is_not (parser, CPP_NAME))
6082 {
6083 c_parser_error (parser, "expected identifier");
6084 expr.value = error_mark_node;
6085 break;
6086 }
6087 component = c_parser_peek_token (parser)->value;
6088 c_parser_consume_token (parser);
6089 expr.value = objc_build_class_component_ref (class_name,
6090 component);
6091 break;
6092 }
6093 default:
5559 c_parser_error (parser, "expected expression"); 6094 c_parser_error (parser, "expected expression");
5560 expr.value = error_mark_node; 6095 expr.value = error_mark_node;
5561 break; 6096 break;
5562 } 6097 }
5563 {
5564 tree id = c_parser_peek_token (parser)->value;
5565 c_parser_consume_token (parser);
5566 expr.value = build_external_ref (loc, id,
5567 (c_parser_peek_token (parser)->type
5568 == CPP_OPEN_PAREN),
5569 &expr.original_type);
5570 }
5571 break; 6098 break;
5572 case CPP_OPEN_PAREN: 6099 case CPP_OPEN_PAREN:
5573 /* A parenthesized expression, statement expression or compound 6100 /* A parenthesized expression, statement expression or compound
5574 literal. */ 6101 literal. */
5575 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE) 6102 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5595 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 6122 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5596 "expected %<)%>"); 6123 "expected %<)%>");
5597 pedwarn (loc, OPT_pedantic, 6124 pedwarn (loc, OPT_pedantic,
5598 "ISO C forbids braced-groups within expressions"); 6125 "ISO C forbids braced-groups within expressions");
5599 expr.value = c_finish_stmt_expr (brace_loc, stmt); 6126 expr.value = c_finish_stmt_expr (brace_loc, stmt);
6127 mark_exp_read (expr.value);
5600 } 6128 }
5601 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)))
5602 { 6130 {
5603 /* A compound literal. ??? Can we actually get here rather 6131 /* A compound literal. ??? Can we actually get here rather
5604 than going directly to 6132 than going directly to
5690 expr.value = error_mark_node; 6218 expr.value = error_mark_node;
5691 break; 6219 break;
5692 } 6220 }
5693 t1 = c_parser_type_name (parser); 6221 t1 = c_parser_type_name (parser);
5694 if (t1 == NULL) 6222 if (t1 == NULL)
5695 { 6223 parser->error = true;
5696 expr.value = error_mark_node;
5697 break;
5698 }
5699 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) 6224 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6225 gcc_assert (parser->error);
6226 if (parser->error)
5700 { 6227 {
5701 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 6228 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5702 expr.value = error_mark_node; 6229 expr.value = error_mark_node;
5703 break; 6230 break;
5704 } 6231 }
6232
5705 { 6233 {
5706 tree type = groktypename (t1, NULL, NULL); 6234 tree type = groktypename (t1, NULL, NULL);
5707 tree offsetof_ref; 6235 tree offsetof_ref;
5708 if (type == error_mark_node) 6236 if (type == error_mark_node)
5709 offsetof_ref = error_mark_node; 6237 offsetof_ref = error_mark_node;
5840 tree e1, e2; 6368 tree e1, e2;
5841 6369
5842 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL)); 6370 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
5843 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL)); 6371 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
5844 6372
5845 expr.value = comptypes (e1, e2) 6373 expr.value
5846 ? build_int_cst (NULL_TREE, 1) 6374 = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
5847 : build_int_cst (NULL_TREE, 0);
5848 } 6375 }
5849 break; 6376 break;
5850 case RID_AT_SELECTOR: 6377 case RID_AT_SELECTOR:
5851 gcc_assert (c_dialect_objc ()); 6378 gcc_assert (c_dialect_objc ());
5852 c_parser_consume_token (parser); 6379 c_parser_consume_token (parser);
6253 objc-class-instance-variables[opt] objc-methodprotolist @end 6780 objc-class-instance-variables[opt] objc-methodprotolist @end
6254 @implementation identifier objc-superclass[opt] 6781 @implementation identifier objc-superclass[opt]
6255 objc-class-instance-variables[opt] 6782 objc-class-instance-variables[opt]
6256 @interface identifier ( identifier ) objc-protocol-refs[opt] 6783 @interface identifier ( identifier ) objc-protocol-refs[opt]
6257 objc-methodprotolist @end 6784 objc-methodprotolist @end
6785 @interface identifier ( ) objc-protocol-refs[opt]
6786 objc-methodprotolist @end
6258 @implementation identifier ( identifier ) 6787 @implementation identifier ( identifier )
6259 6788
6260 objc-superclass: 6789 objc-superclass:
6261 : identifier 6790 : identifier
6262 6791
6265 not start with a parenthesized identifier as a declarator of a data 6794 not start with a parenthesized identifier as a declarator of a data
6266 definition with no declaration specifiers if the objc-superclass, 6795 definition with no declaration specifiers if the objc-superclass,
6267 objc-protocol-refs and objc-class-instance-variables are omitted. */ 6796 objc-protocol-refs and objc-class-instance-variables are omitted. */
6268 6797
6269 static void 6798 static void
6270 c_parser_objc_class_definition (c_parser *parser) 6799 c_parser_objc_class_definition (c_parser *parser, tree attributes)
6271 { 6800 {
6272 bool iface_p; 6801 bool iface_p;
6273 tree id1; 6802 tree id1;
6274 tree superclass; 6803 tree superclass;
6275 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE)) 6804 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
6276 iface_p = true; 6805 iface_p = true;
6277 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION)) 6806 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
6278 iface_p = false; 6807 iface_p = false;
6279 else 6808 else
6280 gcc_unreachable (); 6809 gcc_unreachable ();
6810
6281 c_parser_consume_token (parser); 6811 c_parser_consume_token (parser);
6282 if (c_parser_next_token_is_not (parser, CPP_NAME)) 6812 if (c_parser_next_token_is_not (parser, CPP_NAME))
6283 { 6813 {
6284 c_parser_error (parser, "expected identifier"); 6814 c_parser_error (parser, "expected identifier");
6285 return; 6815 return;
6286 } 6816 }
6287 id1 = c_parser_peek_token (parser)->value; 6817 id1 = c_parser_peek_token (parser)->value;
6288 c_parser_consume_token (parser); 6818 c_parser_consume_token (parser);
6289 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) 6819 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6290 { 6820 {
6821 /* We have a category or class extension. */
6291 tree id2; 6822 tree id2;
6292 tree proto = NULL_TREE; 6823 tree proto = NULL_TREE;
6293 c_parser_consume_token (parser); 6824 c_parser_consume_token (parser);
6294 if (c_parser_next_token_is_not (parser, CPP_NAME)) 6825 if (c_parser_next_token_is_not (parser, CPP_NAME))
6295 { 6826 {
6296 c_parser_error (parser, "expected identifier"); 6827 if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6297 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 6828 {
6298 return; 6829 /* We have a class extension. */
6299 } 6830 id2 = NULL_TREE;
6300 id2 = c_parser_peek_token (parser)->value; 6831 }
6301 c_parser_consume_token (parser); 6832 else
6833 {
6834 c_parser_error (parser, "expected identifier or %<)%>");
6835 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6836 return;
6837 }
6838 }
6839 else
6840 {
6841 id2 = c_parser_peek_token (parser)->value;
6842 c_parser_consume_token (parser);
6843 }
6302 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 6844 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6303 if (!iface_p) 6845 if (!iface_p)
6304 { 6846 {
6305 objc_start_category_implementation (id1, id2); 6847 objc_start_category_implementation (id1, id2);
6306 return; 6848 return;
6307 } 6849 }
6308 if (c_parser_next_token_is (parser, CPP_LESS)) 6850 if (c_parser_next_token_is (parser, CPP_LESS))
6309 proto = c_parser_objc_protocol_refs (parser); 6851 proto = c_parser_objc_protocol_refs (parser);
6310 objc_start_category_interface (id1, id2, proto); 6852 objc_start_category_interface (id1, id2, proto, attributes);
6311 c_parser_objc_methodprotolist (parser); 6853 c_parser_objc_methodprotolist (parser);
6312 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); 6854 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6313 objc_finish_interface (); 6855 objc_finish_interface ();
6314 return; 6856 return;
6315 } 6857 }
6329 if (iface_p) 6871 if (iface_p)
6330 { 6872 {
6331 tree proto = NULL_TREE; 6873 tree proto = NULL_TREE;
6332 if (c_parser_next_token_is (parser, CPP_LESS)) 6874 if (c_parser_next_token_is (parser, CPP_LESS))
6333 proto = c_parser_objc_protocol_refs (parser); 6875 proto = c_parser_objc_protocol_refs (parser);
6334 objc_start_class_interface (id1, superclass, proto); 6876 objc_start_class_interface (id1, superclass, proto, attributes);
6335 } 6877 }
6336 else 6878 else
6337 objc_start_class_implementation (id1, superclass); 6879 objc_start_class_implementation (id1, superclass);
6338 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) 6880 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6339 c_parser_objc_class_instance_variables (parser); 6881 c_parser_objc_class_instance_variables (parser);
6394 { 6936 {
6395 c_parser_consume_token (parser); 6937 c_parser_consume_token (parser);
6396 break; 6938 break;
6397 } 6939 }
6398 /* Parse any objc-visibility-spec. */ 6940 /* Parse any objc-visibility-spec. */
6399 if (c_parser_next_token_is_keyword (parser, RID_PRIVATE)) 6941 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
6400 { 6942 {
6401 c_parser_consume_token (parser); 6943 c_parser_consume_token (parser);
6402 objc_set_visibility (2); 6944 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
6403 continue; 6945 continue;
6404 } 6946 }
6405 else if (c_parser_next_token_is_keyword (parser, RID_PROTECTED)) 6947 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
6406 { 6948 {
6407 c_parser_consume_token (parser); 6949 c_parser_consume_token (parser);
6408 objc_set_visibility (0); 6950 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
6409 continue; 6951 continue;
6410 } 6952 }
6411 else if (c_parser_next_token_is_keyword (parser, RID_PUBLIC)) 6953 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
6412 { 6954 {
6413 c_parser_consume_token (parser); 6955 c_parser_consume_token (parser);
6414 objc_set_visibility (1); 6956 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
6957 continue;
6958 }
6959 else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
6960 {
6961 c_parser_consume_token (parser);
6962 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
6415 continue; 6963 continue;
6416 } 6964 }
6417 else if (c_parser_next_token_is (parser, CPP_PRAGMA)) 6965 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
6418 { 6966 {
6419 c_parser_pragma (parser, pragma_external); 6967 c_parser_pragma (parser, pragma_external);
6424 decls = c_parser_struct_declaration (parser); 6972 decls = c_parser_struct_declaration (parser);
6425 { 6973 {
6426 /* Comma-separated instance variables are chained together in 6974 /* Comma-separated instance variables are chained together in
6427 reverse order; add them one by one. */ 6975 reverse order; add them one by one. */
6428 tree ivar = nreverse (decls); 6976 tree ivar = nreverse (decls);
6429 for (; ivar; ivar = TREE_CHAIN (ivar)) 6977 for (; ivar; ivar = DECL_CHAIN (ivar))
6430 objc_add_instance_variable (copy_node (ivar)); 6978 objc_add_instance_variable (copy_node (ivar));
6431 } 6979 }
6432 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 6980 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6433 } 6981 }
6434 } 6982 }
6441 6989
6442 static void 6990 static void
6443 c_parser_objc_class_declaration (c_parser *parser) 6991 c_parser_objc_class_declaration (c_parser *parser)
6444 { 6992 {
6445 tree list = NULL_TREE; 6993 tree list = NULL_TREE;
6446 gcc_assert (c_parser_next_token_is_keyword (parser, RID_CLASS)); 6994 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
6447 c_parser_consume_token (parser); 6995 c_parser_consume_token (parser);
6448 /* Any identifiers, including those declared as type names, are OK 6996 /* Any identifiers, including those declared as type names, are OK
6449 here. */ 6997 here. */
6450 while (true) 6998 while (true)
6451 { 6999 {
6452 tree id; 7000 tree id;
6453 if (c_parser_next_token_is_not (parser, CPP_NAME)) 7001 if (c_parser_next_token_is_not (parser, CPP_NAME))
6454 { 7002 {
6455 c_parser_error (parser, "expected identifier"); 7003 c_parser_error (parser, "expected identifier");
6456 break; 7004 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7005 parser->error = false;
7006 return;
6457 } 7007 }
6458 id = c_parser_peek_token (parser)->value; 7008 id = c_parser_peek_token (parser)->value;
6459 list = chainon (list, build_tree_list (NULL_TREE, id)); 7009 list = chainon (list, build_tree_list (NULL_TREE, id));
6460 c_parser_consume_token (parser); 7010 c_parser_consume_token (parser);
6461 if (c_parser_next_token_is (parser, CPP_COMMA)) 7011 if (c_parser_next_token_is (parser, CPP_COMMA))
6509 identifier-list ;": objc-methodprotolist may not start with a 7059 identifier-list ;": objc-methodprotolist may not start with a
6510 semicolon in the first alternative if objc-protocol-refs are 7060 semicolon in the first alternative if objc-protocol-refs are
6511 omitted. */ 7061 omitted. */
6512 7062
6513 static void 7063 static void
6514 c_parser_objc_protocol_definition (c_parser *parser) 7064 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
6515 { 7065 {
6516 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL)); 7066 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
7067
6517 c_parser_consume_token (parser); 7068 c_parser_consume_token (parser);
6518 if (c_parser_next_token_is_not (parser, CPP_NAME)) 7069 if (c_parser_next_token_is_not (parser, CPP_NAME))
6519 { 7070 {
6520 c_parser_error (parser, "expected identifier"); 7071 c_parser_error (parser, "expected identifier");
6521 return; 7072 return;
6541 c_parser_consume_token (parser); 7092 c_parser_consume_token (parser);
6542 else 7093 else
6543 break; 7094 break;
6544 } 7095 }
6545 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 7096 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6546 objc_declare_protocols (list); 7097 objc_declare_protocols (list, attributes);
6547 } 7098 }
6548 else 7099 else
6549 { 7100 {
6550 tree id = c_parser_peek_token (parser)->value; 7101 tree id = c_parser_peek_token (parser)->value;
6551 tree proto = NULL_TREE; 7102 tree proto = NULL_TREE;
6552 c_parser_consume_token (parser); 7103 c_parser_consume_token (parser);
6553 if (c_parser_next_token_is (parser, CPP_LESS)) 7104 if (c_parser_next_token_is (parser, CPP_LESS))
6554 proto = c_parser_objc_protocol_refs (parser); 7105 proto = c_parser_objc_protocol_refs (parser);
6555 parser->objc_pq_context = true; 7106 parser->objc_pq_context = true;
6556 objc_start_protocol (id, proto); 7107 objc_start_protocol (id, proto, attributes);
6557 c_parser_objc_methodprotolist (parser); 7108 c_parser_objc_methodprotolist (parser);
6558 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); 7109 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6559 parser->objc_pq_context = false; 7110 parser->objc_pq_context = false;
6560 objc_finish_interface (); 7111 objc_finish_interface ();
6561 } 7112 }
6564 /* Parse an objc-method-type. 7115 /* Parse an objc-method-type.
6565 7116
6566 objc-method-type: 7117 objc-method-type:
6567 + 7118 +
6568 - 7119 -
7120
7121 Return true if it is a class method (+) and false if it is
7122 an instance method (-).
6569 */ 7123 */
6570 7124 static inline bool
6571 static enum tree_code
6572 c_parser_objc_method_type (c_parser *parser) 7125 c_parser_objc_method_type (c_parser *parser)
6573 { 7126 {
6574 switch (c_parser_peek_token (parser)->type) 7127 switch (c_parser_peek_token (parser)->type)
6575 { 7128 {
6576 case CPP_PLUS: 7129 case CPP_PLUS:
6577 c_parser_consume_token (parser); 7130 c_parser_consume_token (parser);
6578 return PLUS_EXPR; 7131 return true;
6579 case CPP_MINUS: 7132 case CPP_MINUS:
6580 c_parser_consume_token (parser); 7133 c_parser_consume_token (parser);
6581 return MINUS_EXPR; 7134 return false;
6582 default: 7135 default:
6583 gcc_unreachable (); 7136 gcc_unreachable ();
6584 } 7137 }
6585 } 7138 }
6586 7139
6591 */ 7144 */
6592 7145
6593 static void 7146 static void
6594 c_parser_objc_method_definition (c_parser *parser) 7147 c_parser_objc_method_definition (c_parser *parser)
6595 { 7148 {
6596 enum tree_code type = c_parser_objc_method_type (parser); 7149 bool is_class_method = c_parser_objc_method_type (parser);
6597 tree decl; 7150 tree decl, attributes = NULL_TREE;
6598 objc_set_method_type (type);
6599 parser->objc_pq_context = true; 7151 parser->objc_pq_context = true;
6600 decl = c_parser_objc_method_decl (parser); 7152 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes);
7153 if (decl == error_mark_node)
7154 return; /* Bail here. */
7155
6601 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 7156 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6602 { 7157 {
6603 c_parser_consume_token (parser); 7158 c_parser_consume_token (parser);
6604 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic, 7159 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6605 "extra semicolon in method definition specified"); 7160 "extra semicolon in method definition specified");
6606 } 7161 }
7162
6607 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE)) 7163 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6608 { 7164 {
6609 c_parser_error (parser, "expected %<{%>"); 7165 c_parser_error (parser, "expected %<{%>");
6610 return; 7166 return;
6611 } 7167 }
7168
6612 parser->objc_pq_context = false; 7169 parser->objc_pq_context = false;
6613 objc_start_method_definition (decl); 7170 if (objc_start_method_definition (is_class_method, decl, attributes))
6614 add_stmt (c_parser_compound_statement (parser)); 7171 {
6615 objc_finish_method_definition (current_function_decl); 7172 add_stmt (c_parser_compound_statement (parser));
7173 objc_finish_method_definition (current_function_decl);
7174 }
7175 else
7176 {
7177 /* This code is executed when we find a method definition
7178 outside of an @implementation context (or invalid for other
7179 reasons). Parse the method (to keep going) but do not emit
7180 any code.
7181 */
7182 c_parser_compound_statement (parser);
7183 }
6616 } 7184 }
6617 7185
6618 /* Parse an objc-methodprotolist. 7186 /* Parse an objc-methodprotolist.
6619 7187
6620 objc-methodprotolist: 7188 objc-methodprotolist:
6621 empty 7189 empty
6622 objc-methodprotolist objc-methodproto 7190 objc-methodprotolist objc-methodproto
6623 objc-methodprotolist declaration 7191 objc-methodprotolist declaration
6624 objc-methodprotolist ; 7192 objc-methodprotolist ;
7193 @optional
7194 @required
6625 7195
6626 The declaration is a data definition, which may be missing 7196 The declaration is a data definition, which may be missing
6627 declaration specifiers under the same rules and diagnostics as 7197 declaration specifiers under the same rules and diagnostics as
6628 other data definitions outside functions, and the stray semicolon 7198 other data definitions outside functions, and the stray semicolon
6629 is diagnosed the same way as a stray semicolon outside a 7199 is diagnosed the same way as a stray semicolon outside a
6652 case CPP_EOF: 7222 case CPP_EOF:
6653 return; 7223 return;
6654 default: 7224 default:
6655 if (c_parser_next_token_is_keyword (parser, RID_AT_END)) 7225 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6656 return; 7226 return;
6657 c_parser_declaration_or_fndef (parser, false, false, true, 7227 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
6658 false, true); 7228 c_parser_objc_at_property_declaration (parser);
7229 else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
7230 {
7231 objc_set_method_opt (true);
7232 c_parser_consume_token (parser);
7233 }
7234 else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
7235 {
7236 objc_set_method_opt (false);
7237 c_parser_consume_token (parser);
7238 }
7239 else
7240 c_parser_declaration_or_fndef (parser, false, false, true,
7241 false, true, NULL);
6659 break; 7242 break;
6660 } 7243 }
6661 } 7244 }
6662 } 7245 }
6663 7246
6668 */ 7251 */
6669 7252
6670 static void 7253 static void
6671 c_parser_objc_methodproto (c_parser *parser) 7254 c_parser_objc_methodproto (c_parser *parser)
6672 { 7255 {
6673 enum tree_code type = c_parser_objc_method_type (parser); 7256 bool is_class_method = c_parser_objc_method_type (parser);
6674 tree decl; 7257 tree decl, attributes = NULL_TREE;
6675 objc_set_method_type (type); 7258
6676 /* Remember protocol qualifiers in prototypes. */ 7259 /* Remember protocol qualifiers in prototypes. */
6677 parser->objc_pq_context = true; 7260 parser->objc_pq_context = true;
6678 decl = c_parser_objc_method_decl (parser); 7261 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes);
6679 /* Forget protocol qualifiers here. */ 7262 /* Forget protocol qualifiers now. */
6680 parser->objc_pq_context = false; 7263 parser->objc_pq_context = false;
6681 objc_add_method_declaration (decl); 7264
7265 /* Do not allow the presence of attributes to hide an erroneous
7266 method implementation in the interface section. */
7267 if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
7268 {
7269 c_parser_error (parser, "expected %<;%>");
7270 return;
7271 }
7272
7273 if (decl != error_mark_node)
7274 objc_add_method_declaration (is_class_method, decl, attributes);
7275
6682 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 7276 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7277 }
7278
7279 /* If we are at a position that method attributes may be present, check that
7280 there are not any parsed already (a syntax error) and then collect any
7281 specified at the current location. Finally, if new attributes were present,
7282 check that the next token is legal ( ';' for decls and '{' for defs). */
7283
7284 static bool
7285 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
7286 {
7287 bool bad = false;
7288 if (*attributes)
7289 {
7290 c_parser_error (parser,
7291 "method attributes must be specified at the end only");
7292 *attributes = NULL_TREE;
7293 bad = true;
7294 }
7295
7296 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7297 *attributes = c_parser_attributes (parser);
7298
7299 /* If there were no attributes here, just report any earlier error. */
7300 if (*attributes == NULL_TREE || bad)
7301 return bad;
7302
7303 /* If the attributes are followed by a ; or {, then just report any earlier
7304 error. */
7305 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
7306 || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7307 return bad;
7308
7309 /* We've got attributes, but not at the end. */
7310 c_parser_error (parser,
7311 "expected %<;%> or %<{%> after method attribute definition");
7312 return true;
6683 } 7313 }
6684 7314
6685 /* Parse an objc-method-decl. 7315 /* Parse an objc-method-decl.
6686 7316
6687 objc-method-decl: 7317 objc-method-decl:
6688 ( objc-type-name ) objc-selector 7318 ( objc-type-name ) objc-selector
6689 objc-selector 7319 objc-selector
6690 ( objc-type-name ) objc-keyword-selector objc-optparmlist 7320 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6691 objc-keyword-selector objc-optparmlist 7321 objc-keyword-selector objc-optparmlist
7322 attributes
6692 7323
6693 objc-keyword-selector: 7324 objc-keyword-selector:
6694 objc-keyword-decl 7325 objc-keyword-decl
6695 objc-keyword-selector objc-keyword-decl 7326 objc-keyword-selector objc-keyword-decl
6696 7327
6711 empty 7342 empty
6712 , ... 7343 , ...
6713 */ 7344 */
6714 7345
6715 static tree 7346 static tree
6716 c_parser_objc_method_decl (c_parser *parser) 7347 c_parser_objc_method_decl (c_parser *parser, bool is_class_method, tree *attributes)
6717 { 7348 {
6718 tree type = NULL_TREE; 7349 tree type = NULL_TREE;
6719 tree sel; 7350 tree sel;
6720 tree parms = NULL_TREE; 7351 tree parms = NULL_TREE;
6721 bool ellipsis = false; 7352 bool ellipsis = false;
6722 7353 bool attr_err = false;
7354
7355 *attributes = NULL_TREE;
6723 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) 7356 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6724 { 7357 {
6725 c_parser_consume_token (parser); 7358 c_parser_consume_token (parser);
6726 type = c_parser_objc_type_name (parser); 7359 type = c_parser_objc_type_name (parser);
6727 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 7360 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6735 tree tsel = sel; 7368 tree tsel = sel;
6736 tree list = NULL_TREE; 7369 tree list = NULL_TREE;
6737 while (true) 7370 while (true)
6738 { 7371 {
6739 tree atype = NULL_TREE, id, keyworddecl; 7372 tree atype = NULL_TREE, id, keyworddecl;
7373 tree param_attr = NULL_TREE;
6740 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) 7374 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6741 break; 7375 break;
6742 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) 7376 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6743 { 7377 {
6744 c_parser_consume_token (parser); 7378 c_parser_consume_token (parser);
6745 atype = c_parser_objc_type_name (parser); 7379 atype = c_parser_objc_type_name (parser);
6746 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 7380 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6747 "expected %<)%>"); 7381 "expected %<)%>");
6748 } 7382 }
7383 /* New ObjC allows attributes on method parameters. */
7384 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7385 param_attr = c_parser_attributes (parser);
6749 if (c_parser_next_token_is_not (parser, CPP_NAME)) 7386 if (c_parser_next_token_is_not (parser, CPP_NAME))
6750 { 7387 {
6751 c_parser_error (parser, "expected identifier"); 7388 c_parser_error (parser, "expected identifier");
6752 return error_mark_node; 7389 return error_mark_node;
6753 } 7390 }
6754 id = c_parser_peek_token (parser)->value; 7391 id = c_parser_peek_token (parser)->value;
6755 c_parser_consume_token (parser); 7392 c_parser_consume_token (parser);
6756 keyworddecl = objc_build_keyword_decl (tsel, atype, id); 7393 keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
6757 list = chainon (list, keyworddecl); 7394 list = chainon (list, keyworddecl);
6758 tsel = c_parser_objc_selector (parser); 7395 tsel = c_parser_objc_selector (parser);
6759 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON)) 7396 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6760 break; 7397 break;
6761 } 7398 }
7399
7400 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7401
6762 /* Parse the optional parameter list. Optional Objective-C 7402 /* Parse the optional parameter list. Optional Objective-C
6763 method parameters follow the C syntax, and may include '...' 7403 method parameters follow the C syntax, and may include '...'
6764 to denote a variable number of arguments. */ 7404 to denote a variable number of arguments. */
6765 parms = make_node (TREE_LIST); 7405 parms = make_node (TREE_LIST);
6766 while (c_parser_next_token_is (parser, CPP_COMMA)) 7406 while (c_parser_next_token_is (parser, CPP_COMMA))
6769 c_parser_consume_token (parser); 7409 c_parser_consume_token (parser);
6770 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) 7410 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6771 { 7411 {
6772 ellipsis = true; 7412 ellipsis = true;
6773 c_parser_consume_token (parser); 7413 c_parser_consume_token (parser);
7414 attr_err |= c_parser_objc_maybe_method_attributes
7415 (parser, attributes) ;
6774 break; 7416 break;
6775 } 7417 }
6776 parm = c_parser_parameter_declaration (parser, NULL_TREE); 7418 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6777 if (parm == NULL) 7419 if (parm == NULL)
6778 break; 7420 break;
6779 parms = chainon (parms, 7421 parms = chainon (parms,
6780 build_tree_list (NULL_TREE, grokparm (parm))); 7422 build_tree_list (NULL_TREE, grokparm (parm)));
6781 } 7423 }
6782 sel = list; 7424 sel = list;
6783 } 7425 }
6784 return objc_build_method_signature (type, sel, parms, ellipsis); 7426 else
7427 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7428
7429 if (sel == NULL)
7430 {
7431 c_parser_error (parser, "objective-c method declaration is expected");
7432 return error_mark_node;
7433 }
7434
7435 if (attr_err)
7436 return error_mark_node;
7437
7438 return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis);
6785 } 7439 }
6786 7440
6787 /* Parse an objc-type-name. 7441 /* Parse an objc-type-name.
6788 7442
6789 objc-type-name: 7443 objc-type-name:
6813 || token->keyword == RID_INOUT 7467 || token->keyword == RID_INOUT
6814 || token->keyword == RID_BYCOPY 7468 || token->keyword == RID_BYCOPY
6815 || token->keyword == RID_BYREF 7469 || token->keyword == RID_BYREF
6816 || token->keyword == RID_ONEWAY)) 7470 || token->keyword == RID_ONEWAY))
6817 { 7471 {
6818 quals = chainon (quals, build_tree_list (NULL_TREE, token->value)); 7472 quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
6819 c_parser_consume_token (parser); 7473 c_parser_consume_token (parser);
6820 } 7474 }
6821 else 7475 else
6822 break; 7476 break;
6823 } 7477 }
6824 if (c_parser_next_token_starts_typename (parser)) 7478 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
6825 type_name = c_parser_type_name (parser); 7479 type_name = c_parser_type_name (parser);
6826 if (type_name) 7480 if (type_name)
6827 type = groktypename (type_name, NULL, NULL); 7481 type = groktypename (type_name, NULL, NULL);
7482
7483 /* If the type is unknown, and error has already been produced and
7484 we need to recover from the error. In that case, use NULL_TREE
7485 for the type, as if no type had been specified; this will use the
7486 default type ('id') which is good for error recovery. */
7487 if (type == error_mark_node)
7488 type = NULL_TREE;
7489
6828 return build_tree_list (quals, type); 7490 return build_tree_list (quals, type);
6829 } 7491 }
6830 7492
6831 /* Parse objc-protocol-refs. 7493 /* Parse objc-protocol-refs.
6832 7494
6860 } 7522 }
6861 c_parser_require (parser, CPP_GREATER, "expected %<>%>"); 7523 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6862 return list; 7524 return list;
6863 } 7525 }
6864 7526
6865 /* Parse an objc-try-catch-statement. 7527 /* Parse an objc-try-catch-finally-statement.
6866 7528
6867 objc-try-catch-statement: 7529 objc-try-catch-finally-statement:
6868 @try compound-statement objc-catch-list[opt] 7530 @try compound-statement objc-catch-list[opt]
6869 @try compound-statement objc-catch-list[opt] @finally compound-statement 7531 @try compound-statement objc-catch-list[opt] @finally compound-statement
6870 7532
6871 objc-catch-list: 7533 objc-catch-list:
6872 @catch ( parameter-declaration ) compound-statement 7534 @catch ( objc-catch-parameter-declaration ) compound-statement
6873 objc-catch-list @catch ( parameter-declaration ) compound-statement 7535 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
6874 */ 7536
7537 objc-catch-parameter-declaration:
7538 parameter-declaration
7539 '...'
7540
7541 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
7542
7543 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
7544 for C++. Keep them in sync. */
6875 7545
6876 static void 7546 static void
6877 c_parser_objc_try_catch_statement (c_parser *parser) 7547 c_parser_objc_try_catch_finally_statement (c_parser *parser)
6878 { 7548 {
6879 location_t loc; 7549 location_t location;
6880 tree stmt; 7550 tree stmt;
6881 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRY)); 7551
7552 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
6882 c_parser_consume_token (parser); 7553 c_parser_consume_token (parser);
6883 loc = c_parser_peek_token (parser)->location; 7554 location = c_parser_peek_token (parser)->location;
7555 objc_maybe_warn_exceptions (location);
6884 stmt = c_parser_compound_statement (parser); 7556 stmt = c_parser_compound_statement (parser);
6885 objc_begin_try_stmt (loc, stmt); 7557 objc_begin_try_stmt (location, stmt);
6886 while (c_parser_next_token_is_keyword (parser, RID_CATCH)) 7558
7559 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
6887 { 7560 {
6888 struct c_parm *parm; 7561 struct c_parm *parm;
7562 tree parameter_declaration = error_mark_node;
7563 bool seen_open_paren = false;
7564
6889 c_parser_consume_token (parser); 7565 c_parser_consume_token (parser);
6890 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 7566 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6891 break; 7567 seen_open_paren = true;
6892 parm = c_parser_parameter_declaration (parser, NULL_TREE); 7568 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6893 if (parm == NULL) 7569 {
6894 { 7570 /* We have "@catch (...)" (where the '...' are literally
6895 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 7571 what is in the code). Skip the '...'.
6896 break; 7572 parameter_declaration is set to NULL_TREE, and
6897 } 7573 objc_being_catch_clauses() knows that that means
6898 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 7574 '...'. */
6899 objc_begin_catch_clause (grokparm (parm)); 7575 c_parser_consume_token (parser);
7576 parameter_declaration = NULL_TREE;
7577 }
7578 else
7579 {
7580 /* We have "@catch (NSException *exception)" or something
7581 like that. Parse the parameter declaration. */
7582 parm = c_parser_parameter_declaration (parser, NULL_TREE);
7583 if (parm == NULL)
7584 parameter_declaration = error_mark_node;
7585 else
7586 parameter_declaration = grokparm (parm);
7587 }
7588 if (seen_open_paren)
7589 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7590 else
7591 {
7592 /* If there was no open parenthesis, we are recovering from
7593 an error, and we are trying to figure out what mistake
7594 the user has made. */
7595
7596 /* If there is an immediate closing parenthesis, the user
7597 probably forgot the opening one (ie, they typed "@catch
7598 NSException *e)". Parse the closing parenthesis and keep
7599 going. */
7600 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
7601 c_parser_consume_token (parser);
7602
7603 /* If these is no immediate closing parenthesis, the user
7604 probably doesn't know that parenthesis are required at
7605 all (ie, they typed "@catch NSException *e"). So, just
7606 forget about the closing parenthesis and keep going. */
7607 }
7608 objc_begin_catch_clause (parameter_declaration);
6900 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) 7609 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6901 c_parser_compound_statement_nostart (parser); 7610 c_parser_compound_statement_nostart (parser);
6902 objc_finish_catch_clause (); 7611 objc_finish_catch_clause ();
6903 } 7612 }
6904 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY)) 7613 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6905 { 7614 {
6906 location_t finloc;
6907 tree finstmt;
6908 c_parser_consume_token (parser); 7615 c_parser_consume_token (parser);
6909 finloc = c_parser_peek_token (parser)->location; 7616 location = c_parser_peek_token (parser)->location;
6910 finstmt = c_parser_compound_statement (parser); 7617 stmt = c_parser_compound_statement (parser);
6911 objc_build_finally_clause (finloc, finstmt); 7618 objc_build_finally_clause (location, stmt);
6912 } 7619 }
6913 objc_finish_try_stmt (); 7620 objc_finish_try_stmt ();
6914 } 7621 }
6915 7622
6916 /* Parse an objc-synchronized-statement. 7623 /* Parse an objc-synchronized-statement.
6925 location_t loc; 7632 location_t loc;
6926 tree expr, stmt; 7633 tree expr, stmt;
6927 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED)); 7634 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6928 c_parser_consume_token (parser); 7635 c_parser_consume_token (parser);
6929 loc = c_parser_peek_token (parser)->location; 7636 loc = c_parser_peek_token (parser)->location;
7637 objc_maybe_warn_exceptions (loc);
6930 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 7638 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6931 { 7639 {
6932 expr = c_parser_expression (parser).value; 7640 expr = c_parser_expression (parser).value;
6933 expr = c_fully_fold (expr, false, NULL); 7641 expr = c_fully_fold (expr, false, NULL);
6934 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 7642 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6986 case RID_SIZEOF: 7694 case RID_SIZEOF:
6987 case RID_TYPEOF: 7695 case RID_TYPEOF:
6988 case RID_ALIGNOF: 7696 case RID_ALIGNOF:
6989 case RID_UNSIGNED: 7697 case RID_UNSIGNED:
6990 case RID_LONG: 7698 case RID_LONG:
7699 case RID_INT128:
6991 case RID_CONST: 7700 case RID_CONST:
6992 case RID_SHORT: 7701 case RID_SHORT:
6993 case RID_VOLATILE: 7702 case RID_VOLATILE:
6994 case RID_SIGNED: 7703 case RID_SIGNED:
6995 case RID_RESTRICT: 7704 case RID_RESTRICT:
7129 } 7838 }
7130 release_tree_vector (expr_list); 7839 release_tree_vector (expr_list);
7131 return ret; 7840 return ret;
7132 } 7841 }
7133 7842
7843 /* A check, needed in several places, that ObjC interface, implementation or
7844 method definitions are not prefixed by incorrect items. */
7845 static bool
7846 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
7847 struct c_declspecs *specs)
7848 {
7849 if (!specs->declspecs_seen_p || specs->non_sc_seen_p
7850 || specs->typespec_kind != ctsk_none)
7851 {
7852 c_parser_error (parser,
7853 "no type or storage class may be specified here,");
7854 c_parser_skip_to_end_of_block_or_statement (parser);
7855 return true;
7856 }
7857 return false;
7858 }
7859
7860 /* Parse an Objective-C @property declaration. The syntax is:
7861
7862 objc-property-declaration:
7863 '@property' objc-property-attributes[opt] struct-declaration ;
7864
7865 objc-property-attributes:
7866 '(' objc-property-attribute-list ')'
7867
7868 objc-property-attribute-list:
7869 objc-property-attribute
7870 objc-property-attribute-list, objc-property-attribute
7871
7872 objc-property-attribute
7873 'getter' = identifier
7874 'setter' = identifier
7875 'readonly'
7876 'readwrite'
7877 'assign'
7878 'retain'
7879 'copy'
7880 'nonatomic'
7881
7882 For example:
7883 @property NSString *name;
7884 @property (readonly) id object;
7885 @property (retain, nonatomic, getter=getTheName) id name;
7886 @property int a, b, c;
7887
7888 PS: This function is identical to cp_parser_objc_at_propery_declaration
7889 for C++. Keep them in sync. */
7890 static void
7891 c_parser_objc_at_property_declaration (c_parser *parser)
7892 {
7893 /* The following variables hold the attributes of the properties as
7894 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
7895 seen. When we see an attribute, we set them to 'true' (if they
7896 are boolean properties) or to the identifier (if they have an
7897 argument, ie, for getter and setter). Note that here we only
7898 parse the list of attributes, check the syntax and accumulate the
7899 attributes that we find. objc_add_property_declaration() will
7900 then process the information. */
7901 bool property_assign = false;
7902 bool property_copy = false;
7903 tree property_getter_ident = NULL_TREE;
7904 bool property_nonatomic = false;
7905 bool property_readonly = false;
7906 bool property_readwrite = false;
7907 bool property_retain = false;
7908 tree property_setter_ident = NULL_TREE;
7909
7910 /* 'properties' is the list of properties that we read. Usually a
7911 single one, but maybe more (eg, in "@property int a, b, c;" there
7912 are three). */
7913 tree properties;
7914 location_t loc;
7915
7916 loc = c_parser_peek_token (parser)->location;
7917 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY));
7918
7919 c_parser_consume_token (parser); /* Eat '@property'. */
7920
7921 /* Parse the optional attribute list... */
7922 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7923 {
7924 /* Eat the '(' */
7925 c_parser_consume_token (parser);
7926
7927 /* Property attribute keywords are valid now. */
7928 parser->objc_property_attr_context = true;
7929
7930 while (true)
7931 {
7932 bool syntax_error = false;
7933 c_token *token = c_parser_peek_token (parser);
7934 enum rid keyword;
7935
7936 if (token->type != CPP_KEYWORD)
7937 {
7938 if (token->type == CPP_CLOSE_PAREN)
7939 c_parser_error (parser, "expected identifier");
7940 else
7941 {
7942 c_parser_consume_token (parser);
7943 c_parser_error (parser, "unknown property attribute");
7944 }
7945 break;
7946 }
7947 keyword = token->keyword;
7948 c_parser_consume_token (parser);
7949 switch (keyword)
7950 {
7951 case RID_ASSIGN: property_assign = true; break;
7952 case RID_COPY: property_copy = true; break;
7953 case RID_NONATOMIC: property_nonatomic = true; break;
7954 case RID_READONLY: property_readonly = true; break;
7955 case RID_READWRITE: property_readwrite = true; break;
7956 case RID_RETAIN: property_retain = true; break;
7957
7958 case RID_GETTER:
7959 case RID_SETTER:
7960 if (c_parser_next_token_is_not (parser, CPP_EQ))
7961 {
7962 if (keyword == RID_GETTER)
7963 c_parser_error (parser,
7964 "missing %<=%> (after %<getter%> attribute)");
7965 else
7966 c_parser_error (parser,
7967 "missing %<=%> (after %<setter%> attribute)");
7968 syntax_error = true;
7969 break;
7970 }
7971 c_parser_consume_token (parser); /* eat the = */
7972 if (c_parser_next_token_is_not (parser, CPP_NAME))
7973 {
7974 c_parser_error (parser, "expected identifier");
7975 syntax_error = true;
7976 break;
7977 }
7978 if (keyword == RID_SETTER)
7979 {
7980 if (property_setter_ident != NULL_TREE)
7981 c_parser_error (parser, "the %<setter%> attribute may only be specified once");
7982 else
7983 property_setter_ident = c_parser_peek_token (parser)->value;
7984 c_parser_consume_token (parser);
7985 if (c_parser_next_token_is_not (parser, CPP_COLON))
7986 c_parser_error (parser, "setter name must terminate with %<:%>");
7987 else
7988 c_parser_consume_token (parser);
7989 }
7990 else
7991 {
7992 if (property_getter_ident != NULL_TREE)
7993 c_parser_error (parser, "the %<getter%> attribute may only be specified once");
7994 else
7995 property_getter_ident = c_parser_peek_token (parser)->value;
7996 c_parser_consume_token (parser);
7997 }
7998 break;
7999 default:
8000 c_parser_error (parser, "unknown property attribute");
8001 syntax_error = true;
8002 break;
8003 }
8004
8005 if (syntax_error)
8006 break;
8007
8008 if (c_parser_next_token_is (parser, CPP_COMMA))
8009 c_parser_consume_token (parser);
8010 else
8011 break;
8012 }
8013 parser->objc_property_attr_context = false;
8014 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8015 }
8016 /* ... and the property declaration(s). */
8017 properties = c_parser_struct_declaration (parser);
8018
8019 if (properties == error_mark_node)
8020 {
8021 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8022 parser->error = false;
8023 return;
8024 }
8025
8026 if (properties == NULL_TREE)
8027 c_parser_error (parser, "expected identifier");
8028 else
8029 {
8030 /* Comma-separated properties are chained together in
8031 reverse order; add them one by one. */
8032 properties = nreverse (properties);
8033
8034 for (; properties; properties = TREE_CHAIN (properties))
8035 objc_add_property_declaration (loc, copy_node (properties),
8036 property_readonly, property_readwrite,
8037 property_assign, property_retain,
8038 property_copy, property_nonatomic,
8039 property_getter_ident, property_setter_ident);
8040 }
8041
8042 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8043 parser->error = false;
8044 }
8045
8046 /* Parse an Objective-C @synthesize declaration. The syntax is:
8047
8048 objc-synthesize-declaration:
8049 @synthesize objc-synthesize-identifier-list ;
8050
8051 objc-synthesize-identifier-list:
8052 objc-synthesize-identifier
8053 objc-synthesize-identifier-list, objc-synthesize-identifier
8054
8055 objc-synthesize-identifier
8056 identifier
8057 identifier = identifier
8058
8059 For example:
8060 @synthesize MyProperty;
8061 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8062
8063 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8064 for C++. Keep them in sync.
8065 */
8066 static void
8067 c_parser_objc_at_synthesize_declaration (c_parser *parser)
8068 {
8069 tree list = NULL_TREE;
8070 location_t loc;
8071 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE));
8072 loc = c_parser_peek_token (parser)->location;
8073
8074 c_parser_consume_token (parser);
8075 while (true)
8076 {
8077 tree property, ivar;
8078 if (c_parser_next_token_is_not (parser, CPP_NAME))
8079 {
8080 c_parser_error (parser, "expected identifier");
8081 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8082 /* Once we find the semicolon, we can resume normal parsing.
8083 We have to reset parser->error manually because
8084 c_parser_skip_until_found() won't reset it for us if the
8085 next token is precisely a semicolon. */
8086 parser->error = false;
8087 return;
8088 }
8089 property = c_parser_peek_token (parser)->value;
8090 c_parser_consume_token (parser);
8091 if (c_parser_next_token_is (parser, CPP_EQ))
8092 {
8093 c_parser_consume_token (parser);
8094 if (c_parser_next_token_is_not (parser, CPP_NAME))
8095 {
8096 c_parser_error (parser, "expected identifier");
8097 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8098 parser->error = false;
8099 return;
8100 }
8101 ivar = c_parser_peek_token (parser)->value;
8102 c_parser_consume_token (parser);
8103 }
8104 else
8105 ivar = NULL_TREE;
8106 list = chainon (list, build_tree_list (ivar, property));
8107 if (c_parser_next_token_is (parser, CPP_COMMA))
8108 c_parser_consume_token (parser);
8109 else
8110 break;
8111 }
8112 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8113 objc_add_synthesize_declaration (loc, list);
8114 }
8115
8116 /* Parse an Objective-C @dynamic declaration. The syntax is:
8117
8118 objc-dynamic-declaration:
8119 @dynamic identifier-list ;
8120
8121 For example:
8122 @dynamic MyProperty;
8123 @dynamic MyProperty, AnotherProperty;
8124
8125 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8126 for C++. Keep them in sync.
8127 */
8128 static void
8129 c_parser_objc_at_dynamic_declaration (c_parser *parser)
8130 {
8131 tree list = NULL_TREE;
8132 location_t loc;
8133 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC));
8134 loc = c_parser_peek_token (parser)->location;
8135
8136 c_parser_consume_token (parser);
8137 while (true)
8138 {
8139 tree property;
8140 if (c_parser_next_token_is_not (parser, CPP_NAME))
8141 {
8142 c_parser_error (parser, "expected identifier");
8143 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8144 parser->error = false;
8145 return;
8146 }
8147 property = c_parser_peek_token (parser)->value;
8148 list = chainon (list, build_tree_list (NULL_TREE, property));
8149 c_parser_consume_token (parser);
8150 if (c_parser_next_token_is (parser, CPP_COMMA))
8151 c_parser_consume_token (parser);
8152 else
8153 break;
8154 }
8155 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8156 objc_add_dynamic_declaration (loc, list);
8157 }
8158
7134 8159
7135 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore 8160 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
7136 should be considered, statements. ALLOW_STMT is true if we're within 8161 should be considered, statements. ALLOW_STMT is true if we're within
7137 the context of a function and such pragmas are to be allowed. Returns 8162 the context of a function and such pragmas are to be allowed. Returns
7138 true if we actually parsed such a pragma. */ 8163 true if we actually parsed such a pragma. */
8014 lhs = TREE_OPERAND (lhs, 0); 9039 lhs = TREE_OPERAND (lhs, 0);
8015 code = MINUS_EXPR; 9040 code = MINUS_EXPR;
8016 rhs = integer_one_node; 9041 rhs = integer_one_node;
8017 break; 9042 break;
8018 9043
9044 case COMPOUND_EXPR:
9045 if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
9046 && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
9047 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
9048 && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
9049 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
9050 (TREE_OPERAND (lhs, 1), 0), 0)))
9051 == BOOLEAN_TYPE)
9052 /* Undo effects of boolean_increment for post {in,de}crement. */
9053 lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
9054 /* FALLTHRU */
9055 case MODIFY_EXPR:
9056 if (TREE_CODE (lhs) == MODIFY_EXPR
9057 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
9058 {
9059 /* Undo effects of boolean_increment. */
9060 if (integer_onep (TREE_OPERAND (lhs, 1)))
9061 {
9062 /* This is pre or post increment. */
9063 rhs = TREE_OPERAND (lhs, 1);
9064 lhs = TREE_OPERAND (lhs, 0);
9065 code = NOP_EXPR;
9066 break;
9067 }
9068 if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
9069 && TREE_OPERAND (lhs, 0)
9070 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
9071 {
9072 /* This is pre or post decrement. */
9073 rhs = TREE_OPERAND (lhs, 1);
9074 lhs = TREE_OPERAND (lhs, 0);
9075 code = NOP_EXPR;
9076 break;
9077 }
9078 }
9079 /* FALLTHRU */
8019 default: 9080 default:
8020 switch (c_parser_peek_token (parser)->type) 9081 switch (c_parser_peek_token (parser)->type)
8021 { 9082 {
8022 case CPP_MULT_EQ: 9083 case CPP_MULT_EQ:
8023 code = MULT_EXPR; 9084 code = MULT_EXPR;
8050 c_parser_error (parser, 9111 c_parser_error (parser,
8051 "invalid operator for %<#pragma omp atomic%>"); 9112 "invalid operator for %<#pragma omp atomic%>");
8052 goto saw_error; 9113 goto saw_error;
8053 } 9114 }
8054 9115
9116 /* Arrange to pass the location of the assignment operator to
9117 c_finish_omp_atomic. */
9118 loc = c_parser_peek_token (parser)->location;
8055 c_parser_consume_token (parser); 9119 c_parser_consume_token (parser);
8056 { 9120 {
8057 location_t rhs_loc = c_parser_peek_token (parser)->location; 9121 location_t rhs_loc = c_parser_peek_token (parser)->location;
8058 rhs_expr = c_parser_expression (parser); 9122 rhs_expr = c_parser_expression (parser);
8059 rhs_expr = default_function_array_read_conversion (rhs_loc, rhs_expr); 9123 rhs_expr = default_function_array_read_conversion (rhs_loc, rhs_expr);
8142 static tree 9206 static tree
8143 c_parser_omp_for_loop (location_t loc, 9207 c_parser_omp_for_loop (location_t loc,
8144 c_parser *parser, tree clauses, tree *par_clauses) 9208 c_parser *parser, tree clauses, tree *par_clauses)
8145 { 9209 {
8146 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;
8147 tree declv, condv, incrv, initv, for_block = NULL, ret = NULL; 9211 tree declv, condv, incrv, initv, ret = NULL;
8148 bool fail = false, open_brace_parsed = false; 9212 bool fail = false, open_brace_parsed = false;
8149 int i, collapse = 1, nbraces = 0; 9213 int i, collapse = 1, nbraces = 0;
8150 location_t for_loc; 9214 location_t for_loc;
9215 VEC(tree,gc) *for_block = make_tree_vector ();
8151 9216
8152 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl)) 9217 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
8153 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE) 9218 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
8154 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0); 9219 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
8155 9220
8174 9239
8175 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 9240 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8176 goto pop_scopes; 9241 goto pop_scopes;
8177 9242
8178 /* Parse the initialization declaration or expression. */ 9243 /* Parse the initialization declaration or expression. */
8179 if (c_parser_next_token_starts_declaration (parser)) 9244 if (c_parser_next_tokens_start_declaration (parser))
8180 { 9245 {
8181 if (i > 0) 9246 if (i > 0)
8182 for_block 9247 VEC_safe_push (tree, gc, for_block, c_begin_compound_stmt (true));
8183 = tree_cons (NULL, c_begin_compound_stmt (true), for_block); 9248 c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
8184 c_parser_declaration_or_fndef (parser, true, true, true, true, true); 9249 decl = check_for_loop_decls (for_loc, flag_isoc99);
8185 decl = check_for_loop_decls (for_loc);
8186 if (decl == NULL) 9250 if (decl == NULL)
8187 goto error_init; 9251 goto error_init;
8188 if (DECL_INITIAL (decl) == error_mark_node) 9252 if (DECL_INITIAL (decl) == error_mark_node)
8189 decl = error_mark_node; 9253 decl = error_mark_node;
8190 init = decl; 9254 init = decl;
8408 OMP_FOR_CLAUSES (stmt) = clauses; 9472 OMP_FOR_CLAUSES (stmt) = clauses;
8409 } 9473 }
8410 ret = stmt; 9474 ret = stmt;
8411 } 9475 }
8412 pop_scopes: 9476 pop_scopes:
8413 while (for_block) 9477 while (!VEC_empty (tree, for_block))
8414 { 9478 {
8415 /* FIXME diagnostics: LOC below should be the actual location of 9479 /* FIXME diagnostics: LOC below should be the actual location of
8416 this particular for block. We need to build a list of 9480 this particular for block. We need to build a list of
8417 locations to go along with FOR_BLOCK. */ 9481 locations to go along with FOR_BLOCK. */
8418 stmt = c_end_compound_stmt (loc, TREE_VALUE (for_block), true); 9482 stmt = c_end_compound_stmt (loc, VEC_pop (tree, for_block), true);
8419 add_stmt (stmt); 9483 add_stmt (stmt);
8420 for_block = TREE_CHAIN (for_block); 9484 }
8421 } 9485 release_tree_vector (for_block);
8422 return ret; 9486 return ret;
8423 } 9487 }
8424 9488
8425 /* OpenMP 2.5: 9489 /* OpenMP 2.5:
8426 #pragma omp for for-clause[optseq] new-line 9490 #pragma omp for for-clause[optseq] new-line
8874 the_parser = &tparser; 9938 the_parser = &tparser;
8875 9939
8876 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS) 9940 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
8877 c_parser_pragma_pch_preprocess (&tparser); 9941 c_parser_pragma_pch_preprocess (&tparser);
8878 9942
8879 the_parser = GGC_NEW (c_parser); 9943 the_parser = ggc_alloc_c_parser ();
8880 *the_parser = tparser; 9944 *the_parser = tparser;
8881 9945
8882 /* Initialize EH, if we've been told to do so. */ 9946 /* Initialize EH, if we've been told to do so. */
8883 if (flag_exceptions) 9947 if (flag_exceptions)
8884 using_eh_for_cleanups (); 9948 using_eh_for_cleanups ();