1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 Parser actions based on the old Bison parser; structure somewhat
6 influenced by and fragments based on the C++ parser.
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
31 Add testcases covering every input symbol in every state in old and
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
42 #include "coretypes.h"
46 #include "langhooks.h"
62 /* Miscellaneous data and functions needed for the parser. */
66 /* Objective-C specific parser/lexer information. */
68 static int objc_pq_context = 0;
70 /* The following flag is needed to contextualize Objective-C lexical
71 analysis. In some cases (e.g., 'int NSObject;'), it is undesirable
72 to bind an identifier to an Objective-C class, even if a class with
74 static int objc_need_raw_identifier = 0;
75 #define OBJC_NEED_RAW_IDENTIFIER(VAL) \
77 if (c_dialect_objc ()) \
78 objc_need_raw_identifier = VAL; \
81 /* APPLE LOCAL begin C* property (Radar 4436866) (in 4.2 d) */
82 /* For checking property attribute keywords */
83 static int objc_property_attr_context;
84 /* APPLE LOCAL end C* property (Radar 4436866) (in 4.2 d) */
85 /* APPLE LOCAL radar 3803157 - objc attribute (in 4.2 e) */
86 static tree objc_method_attributes;
87 /* APPLE LOCAL begin C* language (in 4.2 f) */
88 /* For checking for 'foreach' context. */
89 static int objc_foreach_context;
90 /* APPLE LOCAL end C* language (in 4.2 f) */
92 /* The reserved keyword table. */
96 ENUM_BITFIELD(rid) rid : 16;
97 unsigned int disable : 16;
100 /* Disable mask. Keywords are disabled if (reswords[i].disable &
102 #define D_C89 0x01 /* not in C89 */
103 #define D_EXT 0x02 /* GCC extension */
104 #define D_EXT89 0x04 /* GCC extension incorporated in C99 */
105 #define D_OBJC 0x08 /* Objective C only */
107 static const struct resword reswords[] =
109 { "_Bool", RID_BOOL, 0 },
110 { "_Complex", RID_COMPLEX, 0 },
111 { "_Decimal32", RID_DFLOAT32, D_EXT },
112 { "_Decimal64", RID_DFLOAT64, D_EXT },
113 { "_Decimal128", RID_DFLOAT128, D_EXT },
114 { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
115 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
116 { "__alignof", RID_ALIGNOF, 0 },
117 { "__alignof__", RID_ALIGNOF, 0 },
118 { "__asm", RID_ASM, 0 },
119 { "__asm__", RID_ASM, 0 },
120 { "__attribute", RID_ATTRIBUTE, 0 },
121 { "__attribute__", RID_ATTRIBUTE, 0 },
122 { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
123 { "__builtin_offsetof", RID_OFFSETOF, 0 },
124 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
125 { "__builtin_va_arg", RID_VA_ARG, 0 },
126 { "__complex", RID_COMPLEX, 0 },
127 { "__complex__", RID_COMPLEX, 0 },
128 { "__const", RID_CONST, 0 },
129 { "__const__", RID_CONST, 0 },
130 { "__extension__", RID_EXTENSION, 0 },
131 { "__func__", RID_C99_FUNCTION_NAME, 0 },
132 { "__imag", RID_IMAGPART, 0 },
133 { "__imag__", RID_IMAGPART, 0 },
134 { "__inline", RID_INLINE, 0 },
135 { "__inline__", RID_INLINE, 0 },
136 { "__label__", RID_LABEL, 0 },
137 { "__real", RID_REALPART, 0 },
138 { "__real__", RID_REALPART, 0 },
139 { "__restrict", RID_RESTRICT, 0 },
140 { "__restrict__", RID_RESTRICT, 0 },
141 { "__signed", RID_SIGNED, 0 },
142 { "__signed__", RID_SIGNED, 0 },
143 { "__thread", RID_THREAD, 0 },
144 { "__typeof", RID_TYPEOF, 0 },
145 { "__typeof__", RID_TYPEOF, 0 },
146 { "__volatile", RID_VOLATILE, 0 },
147 { "__volatile__", RID_VOLATILE, 0 },
148 { "asm", RID_ASM, D_EXT },
149 { "auto", RID_AUTO, 0 },
150 { "break", RID_BREAK, 0 },
151 { "case", RID_CASE, 0 },
152 { "char", RID_CHAR, 0 },
153 { "const", RID_CONST, 0 },
154 { "continue", RID_CONTINUE, 0 },
155 { "default", RID_DEFAULT, 0 },
157 { "double", RID_DOUBLE, 0 },
158 { "else", RID_ELSE, 0 },
159 { "enum", RID_ENUM, 0 },
160 { "extern", RID_EXTERN, 0 },
161 { "float", RID_FLOAT, 0 },
162 { "for", RID_FOR, 0 },
163 { "goto", RID_GOTO, 0 },
165 { "inline", RID_INLINE, D_EXT89 },
166 { "int", RID_INT, 0 },
167 { "long", RID_LONG, 0 },
168 { "register", RID_REGISTER, 0 },
169 { "restrict", RID_RESTRICT, D_C89 },
170 { "return", RID_RETURN, 0 },
171 { "short", RID_SHORT, 0 },
172 { "signed", RID_SIGNED, 0 },
173 { "sizeof", RID_SIZEOF, 0 },
174 { "static", RID_STATIC, 0 },
175 { "struct", RID_STRUCT, 0 },
176 { "switch", RID_SWITCH, 0 },
177 { "typedef", RID_TYPEDEF, 0 },
178 { "typeof", RID_TYPEOF, D_EXT },
179 { "union", RID_UNION, 0 },
180 { "unsigned", RID_UNSIGNED, 0 },
181 { "void", RID_VOID, 0 },
182 { "volatile", RID_VOLATILE, 0 },
183 { "while", RID_WHILE, 0 },
184 /* These Objective-C keywords are recognized only immediately after
186 { "class", RID_AT_CLASS, D_OBJC },
187 { "compatibility_alias", RID_AT_ALIAS, D_OBJC },
188 { "defs", RID_AT_DEFS, D_OBJC },
189 { "encode", RID_AT_ENCODE, D_OBJC },
190 { "end", RID_AT_END, D_OBJC },
191 { "implementation", RID_AT_IMPLEMENTATION, D_OBJC },
192 { "interface", RID_AT_INTERFACE, D_OBJC },
193 /* APPLE LOCAL begin C* language (in 4.2 j) */
194 { "optional", RID_AT_OPTIONAL, D_OBJC },
195 { "required", RID_AT_REQUIRED, D_OBJC },
196 /* APPLE LOCAL end C* language (in 4.2 j) */
197 /* APPLE LOCAL C* property (Radar 4436866) (in 4.2 k) */
198 { "property", RID_AT_PROPERTY, D_OBJC },
199 /* APPLE LOCAL radar 4564694 */
200 { "package", RID_AT_PACKAGE, D_OBJC },
201 { "private", RID_AT_PRIVATE, D_OBJC },
202 { "protected", RID_AT_PROTECTED, D_OBJC },
203 { "protocol", RID_AT_PROTOCOL, D_OBJC },
204 { "public", RID_AT_PUBLIC, D_OBJC },
205 { "selector", RID_AT_SELECTOR, D_OBJC },
206 { "throw", RID_AT_THROW, D_OBJC },
207 { "try", RID_AT_TRY, D_OBJC },
208 { "catch", RID_AT_CATCH, D_OBJC },
209 { "finally", RID_AT_FINALLY, D_OBJC },
210 { "synchronized", RID_AT_SYNCHRONIZED, D_OBJC },
211 /* These are recognized only in protocol-qualifier context
213 { "bycopy", RID_BYCOPY, D_OBJC },
214 { "byref", RID_BYREF, D_OBJC },
215 { "in", RID_IN, D_OBJC },
216 { "inout", RID_INOUT, D_OBJC },
217 { "oneway", RID_ONEWAY, D_OBJC },
218 { "out", RID_OUT, D_OBJC },
219 /* APPLE LOCAL begin C* property (Radar 4436866) (in 4.2 l) */
220 /* These are recognized inside a property attribute list */
221 { "readonly", RID_READONLY, D_OBJC },
222 { "getter", RID_GETTER, D_OBJC },
223 { "setter", RID_SETTER, D_OBJC },
224 /* APPLE LOCAL end C* property (Radar 4436866) (in 4.2 l) */
225 /* APPLE LOCAL radar 4947014 - objc atomic property */
226 { "nonatomic", RID_NONATOMIC, D_OBJC },
228 #define N_reswords (sizeof reswords / sizeof (struct resword))
230 /* All OpenMP clauses. OpenMP 2.5. */
231 typedef enum pragma_omp_clause {
232 PRAGMA_OMP_CLAUSE_NONE = 0,
234 PRAGMA_OMP_CLAUSE_COPYIN,
235 PRAGMA_OMP_CLAUSE_COPYPRIVATE,
236 PRAGMA_OMP_CLAUSE_DEFAULT,
237 PRAGMA_OMP_CLAUSE_FIRSTPRIVATE,
238 PRAGMA_OMP_CLAUSE_IF,
239 PRAGMA_OMP_CLAUSE_LASTPRIVATE,
240 PRAGMA_OMP_CLAUSE_NOWAIT,
241 PRAGMA_OMP_CLAUSE_NUM_THREADS,
242 PRAGMA_OMP_CLAUSE_ORDERED,
243 PRAGMA_OMP_CLAUSE_PRIVATE,
244 PRAGMA_OMP_CLAUSE_REDUCTION,
245 PRAGMA_OMP_CLAUSE_SCHEDULE,
246 PRAGMA_OMP_CLAUSE_SHARED
250 /* Initialization routine for this file. */
255 /* The only initialization required is of the reserved word
259 int mask = (flag_isoc99 ? 0 : D_C89)
260 | (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0);
262 if (!c_dialect_objc ())
265 ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
266 for (i = 0; i < N_reswords; i++)
268 /* If a keyword is disabled, do not enter it into the table
269 and so create a canonical spelling that isn't a keyword. */
270 if (reswords[i].disable & mask)
273 id = get_identifier (reswords[i].word);
274 C_RID_CODE (id) = reswords[i].rid;
275 C_IS_RESERVED_WORD (id) = 1;
276 ridpointers [(int) reswords[i].rid] = id;
280 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
281 and the C parser. Unlike the C++ lexer, the parser structure
282 stores the lexer information instead of using a separate structure.
283 Identifiers are separated into ordinary identifiers, type names,
284 keywords and some other Objective-C types of identifiers, and some
285 look-ahead is maintained.
287 ??? It might be a good idea to lex the whole file up front (as for
288 C++). It would then be possible to share more of the C and C++
289 lexer code, if desired. */
291 /* The following local token type is used. */
294 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
296 /* More information about the type of a CPP_NAME token. */
297 typedef enum c_id_kind {
298 /* An ordinary identifier. */
300 /* An identifier declared as a typedef name. */
302 /* An identifier declared as an Objective-C class name. */
304 /* Not an identifier. */
308 /* A single C token after string literal concatenation and conversion
309 of preprocessing tokens to tokens. */
310 typedef struct c_token GTY (())
312 /* The kind of token. */
313 ENUM_BITFIELD (cpp_ttype) type : 8;
314 /* If this token is a CPP_NAME, this value indicates whether also
315 declared as some kind of type. Otherwise, it is C_ID_NONE. */
316 ENUM_BITFIELD (c_id_kind) id_kind : 8;
317 /* If this token is a keyword, this value indicates which keyword.
318 Otherwise, this value is RID_MAX. */
319 ENUM_BITFIELD (rid) keyword : 8;
320 /* If this token is a CPP_PRAGMA, this indicates the pragma that
321 was seen. Otherwise it is PRAGMA_NONE. */
322 ENUM_BITFIELD (pragma_kind) pragma_kind : 7;
323 /* True if this token is from a system header. */
324 BOOL_BITFIELD in_system_header : 1;
325 /* The value associated with this token, if any. */
327 /* The location at which this token was found. */
331 /* A parser structure recording information about the state and
332 context of parsing. Includes lexer information with up to two
333 tokens of look-ahead; more are not needed for C. */
334 typedef struct c_parser GTY(())
336 /* The look-ahead tokens. */
338 /* How many look-ahead tokens are available (0, 1 or 2). */
340 /* True if a syntax error is being recovered from; false otherwise.
341 c_parser_error sets this flag. It should clear this flag when
342 enough tokens have been consumed to recover from the error. */
343 BOOL_BITFIELD error : 1;
344 /* True if we're processing a pragma, and shouldn't automatically
345 consume CPP_PRAGMA_EOL. */
346 BOOL_BITFIELD in_pragma : 1;
350 /* The actual parser and external interface. ??? Does this need to be
351 garbage-collected? */
353 static GTY (()) c_parser *the_parser;
355 /* APPLE LOCAL C* language (in 4.2 ae) */
356 static c_token * c_parser_peek_2nd_token (c_parser *);
358 /* Read in and lex a single token, storing it in *TOKEN. */
361 c_lex_one_token (c_token *token, c_parser *parser)
363 timevar_push (TV_LEX);
365 token->type = c_lex_with_flags (&token->value, &token->location, NULL);
366 token->id_kind = C_ID_NONE;
367 token->keyword = RID_MAX;
368 token->pragma_kind = PRAGMA_NONE;
369 token->in_system_header = in_system_header;
377 int objc_force_identifier = objc_need_raw_identifier;
378 OBJC_NEED_RAW_IDENTIFIER (0);
380 if (C_IS_RESERVED_WORD (token->value))
382 enum rid rid_code = C_RID_CODE (token->value);
384 if (c_dialect_objc ())
386 if (!OBJC_IS_AT_KEYWORD (rid_code)
387 && (!OBJC_IS_PQ_KEYWORD (rid_code) || objc_pq_context))
389 /* Return the canonical spelling for this keyword. */
390 token->value = ridpointers[(int) rid_code];
391 token->type = CPP_KEYWORD;
392 token->keyword = rid_code;
395 /* APPLE LOCAL begin radar 4708210 (for_objc_collection in 4.2) */
396 else if (objc_foreach_context && rid_code == RID_IN)
398 /* This is dangerous, we assume we don't need 3 input tokens look ahead. */
399 c_token *tk = c_parser_peek_2nd_token (parser);
400 if (tk->type == CPP_NAME
401 || tk->type == CPP_OPEN_PAREN
402 || tk->type == CPP_MULT
403 || tk->type == CPP_PLUS
404 || tk->type == CPP_PLUS_PLUS
405 || tk->type == CPP_MINUS
406 || tk->type == CPP_MINUS_MINUS
407 /* APPLE LOCAL radar 4529200 (in 4.2 af) */
408 || tk->type == CPP_OPEN_SQUARE)
410 token->type = CPP_KEYWORD;
411 token->keyword = rid_code;
415 /* APPLE LOCAL end radar 4708210 (for_objc_collection in 4.2) */
419 /* Return the canonical spelling for this keyword. */
420 token->value = ridpointers[(int) rid_code];
421 token->type = CPP_KEYWORD;
422 token->keyword = rid_code;
427 decl = lookup_name (token->value);
430 if (TREE_CODE (decl) == TYPE_DECL)
432 token->id_kind = C_ID_TYPENAME;
436 else if (c_dialect_objc ())
438 tree objc_interface_decl = objc_is_class_name (token->value);
439 /* Objective-C class names are in the same namespace as
440 variables and typedefs, and hence are shadowed by local
442 if (objc_interface_decl
443 && (global_bindings_p ()
444 || (!objc_force_identifier && !decl)))
446 token->value = objc_interface_decl;
447 token->id_kind = C_ID_CLASSNAME;
451 token->id_kind = C_ID_ID;
455 /* This only happens in Objective-C; it must be a keyword. */
456 token->type = CPP_KEYWORD;
457 token->keyword = C_RID_CODE (token->value);
461 case CPP_CLOSE_PAREN:
463 /* These tokens may affect the interpretation of any identifiers
464 following, if doing Objective-C. */
465 OBJC_NEED_RAW_IDENTIFIER (0);
468 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
469 token->pragma_kind = TREE_INT_CST_LOW (token->value);
475 timevar_pop (TV_LEX);
478 /* Return a pointer to the next token from PARSER, reading it in if
481 static inline c_token *
482 c_parser_peek_token (c_parser *parser)
484 if (parser->tokens_avail == 0)
486 /* APPLE LOCAL begin switch these two */
487 parser->tokens_avail = 1;
488 /* APPLE LOCAL C* language (in 4.2 ae) */
489 c_lex_one_token (&parser->tokens[0], parser);
490 /* APPLE LOCAL end switch these two */
492 return &parser->tokens[0];
495 /* Return true if the next token from PARSER has the indicated
499 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
501 return c_parser_peek_token (parser)->type == type;
504 /* Return true if the next token from PARSER does not have the
508 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
510 return !c_parser_next_token_is (parser, type);
513 /* Return true if the next token from PARSER is the indicated
517 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
521 /* Peek at the next token. */
522 token = c_parser_peek_token (parser);
523 /* Check to see if it is the indicated keyword. */
524 return token->keyword == keyword;
527 /* Return true if TOKEN can start a type name,
530 c_token_starts_typename (c_token *token)
535 switch (token->id_kind)
542 gcc_assert (c_dialect_objc ());
548 switch (token->keyword)
577 if (c_dialect_objc ())
585 /* Return true if the next token from PARSER can start a type name,
588 c_parser_next_token_starts_typename (c_parser *parser)
590 c_token *token = c_parser_peek_token (parser);
591 return c_token_starts_typename (token);
594 /* Return true if TOKEN can start declaration specifiers, false
597 c_token_starts_declspecs (c_token *token)
602 switch (token->id_kind)
609 gcc_assert (c_dialect_objc ());
615 switch (token->keyword)
651 if (c_dialect_objc ())
659 /* Return true if the next token from PARSER can start declaration
660 specifiers, false otherwise. */
662 c_parser_next_token_starts_declspecs (c_parser *parser)
664 c_token *token = c_parser_peek_token (parser);
665 /* APPLE LOCAL begin radar 5277239 */
666 /* Yes, we can have CLASS.method to mean property-style dot-syntax
667 notation to call a class method (equiv to [CLASS meth]). */
668 return c_token_starts_declspecs (token)
669 && (token->id_kind != C_ID_CLASSNAME
670 || c_parser_peek_2nd_token (parser)->type != CPP_DOT);
671 /* APPLE LOCAL end radar 5277239 */
674 /* Return a pointer to the next-but-one token from PARSER, reading it
675 in if necessary. The next token is already read in. */
678 c_parser_peek_2nd_token (c_parser *parser)
680 if (parser->tokens_avail >= 2)
681 return &parser->tokens[1];
682 gcc_assert (parser->tokens_avail == 1);
683 gcc_assert (parser->tokens[0].type != CPP_EOF);
684 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
685 /* APPLE LOCAL begin switch these two */
686 parser->tokens_avail = 2;
687 /* APPLE LOCAL C* language (in 4.2 ae) */
688 c_lex_one_token (&parser->tokens[1], parser);
689 /* APPLE LOCAL end switch these two */
690 return &parser->tokens[1];
693 /* Consume the next token from PARSER. */
696 c_parser_consume_token (c_parser *parser)
698 gcc_assert (parser->tokens_avail >= 1);
699 gcc_assert (parser->tokens[0].type != CPP_EOF);
700 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
701 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
702 if (parser->tokens_avail == 2)
703 parser->tokens[0] = parser->tokens[1];
704 parser->tokens_avail--;
707 /* Expect the current token to be a #pragma. Consume it and remember
708 that we've begun parsing a pragma. */
711 c_parser_consume_pragma (c_parser *parser)
713 gcc_assert (!parser->in_pragma);
714 gcc_assert (parser->tokens_avail >= 1);
715 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
716 if (parser->tokens_avail == 2)
717 parser->tokens[0] = parser->tokens[1];
718 parser->tokens_avail--;
719 parser->in_pragma = true;
722 /* Update the globals input_location and in_system_header from
725 c_parser_set_source_position_from_token (c_token *token)
727 if (token->type != CPP_EOF)
729 input_location = token->location;
730 in_system_header = token->in_system_header;
734 /* Issue a diagnostic of the form
735 FILE:LINE: MESSAGE before TOKEN
736 where TOKEN is the next token in the input stream of PARSER.
737 MESSAGE (specified by the caller) is usually of the form "expected
740 Do not issue a diagnostic if still recovering from an error.
742 ??? This is taken from the C++ parser, but building up messages in
743 this way is not i18n-friendly and some other approach should be
747 c_parser_error (c_parser *parser, const char *gmsgid)
749 c_token *token = c_parser_peek_token (parser);
752 parser->error = true;
755 /* This diagnostic makes more sense if it is tagged to the line of
756 the token we just peeked at. */
757 c_parser_set_source_position_from_token (token);
758 c_parse_error (gmsgid,
759 /* Because c_parse_error does not understand
760 CPP_KEYWORD, keywords are treated like
762 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
766 /* If the next token is of the indicated TYPE, consume it. Otherwise,
767 issue the error MSGID. If MSGID is NULL then a message has already
768 been produced and no message will be produced this time. Returns
769 true if found, false otherwise. */
772 c_parser_require (c_parser *parser,
776 if (c_parser_next_token_is (parser, type))
778 c_parser_consume_token (parser);
783 c_parser_error (parser, msgid);
788 /* If the next token is the indicated keyword, consume it. Otherwise,
789 issue the error MSGID. Returns true if found, false otherwise. */
792 c_parser_require_keyword (c_parser *parser,
796 if (c_parser_next_token_is_keyword (parser, keyword))
798 c_parser_consume_token (parser);
803 c_parser_error (parser, msgid);
808 /* Like c_parser_require, except that tokens will be skipped until the
809 desired token is found. An error message is still produced if the
810 next token is not as expected. If MSGID is NULL then a message has
811 already been produced and no message will be produced this
815 c_parser_skip_until_found (c_parser *parser,
819 unsigned nesting_depth = 0;
821 if (c_parser_require (parser, type, msgid))
824 /* Skip tokens until the desired token is found. */
827 /* Peek at the next token. */
828 c_token *token = c_parser_peek_token (parser);
829 /* If we've reached the token we want, consume it and stop. */
830 if (token->type == type && !nesting_depth)
832 c_parser_consume_token (parser);
836 /* If we've run out of tokens, stop. */
837 if (token->type == CPP_EOF)
839 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
841 if (token->type == CPP_OPEN_BRACE
842 || token->type == CPP_OPEN_PAREN
843 || token->type == CPP_OPEN_SQUARE)
845 else if (token->type == CPP_CLOSE_BRACE
846 || token->type == CPP_CLOSE_PAREN
847 || token->type == CPP_CLOSE_SQUARE)
849 if (nesting_depth-- == 0)
852 /* Consume this token. */
853 c_parser_consume_token (parser);
855 parser->error = false;
858 /* Skip tokens until the end of a parameter is found, but do not
859 consume the comma, semicolon or closing delimiter. */
862 c_parser_skip_to_end_of_parameter (c_parser *parser)
864 unsigned nesting_depth = 0;
868 c_token *token = c_parser_peek_token (parser);
869 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
872 /* If we've run out of tokens, stop. */
873 if (token->type == CPP_EOF)
875 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
877 if (token->type == CPP_OPEN_BRACE
878 || token->type == CPP_OPEN_PAREN
879 || token->type == CPP_OPEN_SQUARE)
881 else if (token->type == CPP_CLOSE_BRACE
882 || token->type == CPP_CLOSE_PAREN
883 || token->type == CPP_CLOSE_SQUARE)
885 if (nesting_depth-- == 0)
888 /* Consume this token. */
889 c_parser_consume_token (parser);
891 parser->error = false;
894 /* Expect to be at the end of the pragma directive and consume an
895 end of line marker. */
898 c_parser_skip_to_pragma_eol (c_parser *parser)
900 gcc_assert (parser->in_pragma);
901 parser->in_pragma = false;
903 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
906 c_token *token = c_parser_peek_token (parser);
907 if (token->type == CPP_EOF)
909 if (token->type == CPP_PRAGMA_EOL)
911 c_parser_consume_token (parser);
914 c_parser_consume_token (parser);
917 parser->error = false;
920 /* Skip tokens until we have consumed an entire block, or until we
921 have consumed a non-nested ';'. */
924 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
926 unsigned nesting_depth = 0;
927 bool save_error = parser->error;
933 /* Peek at the next token. */
934 token = c_parser_peek_token (parser);
942 if (parser->in_pragma)
947 /* If the next token is a ';', we have reached the
948 end of the statement. */
951 /* Consume the ';'. */
952 c_parser_consume_token (parser);
957 case CPP_CLOSE_BRACE:
958 /* If the next token is a non-nested '}', then we have
959 reached the end of the current block. */
960 if (nesting_depth == 0 || --nesting_depth == 0)
962 c_parser_consume_token (parser);
968 /* If it the next token is a '{', then we are entering a new
969 block. Consume the entire block. */
974 /* If we see a pragma, consume the whole thing at once. We
975 have some safeguards against consuming pragmas willy-nilly.
976 Normally, we'd expect to be here with parser->error set,
977 which disables these safeguards. But it's possible to get
978 here for secondary error recovery, after parser->error has
980 c_parser_consume_pragma (parser);
981 c_parser_skip_to_pragma_eol (parser);
982 parser->error = save_error;
989 c_parser_consume_token (parser);
993 parser->error = false;
996 /* Save the warning flags which are controlled by __extension__. */
999 disable_extension_diagnostics (void)
1002 | (warn_pointer_arith << 1)
1003 | (warn_traditional << 2)
1006 warn_pointer_arith = 0;
1007 warn_traditional = 0;
1012 /* Restore the warning flags which are controlled by __extension__.
1013 FLAGS is the return value from disable_extension_diagnostics. */
1016 restore_extension_diagnostics (int flags)
1018 pedantic = flags & 1;
1019 warn_pointer_arith = (flags >> 1) & 1;
1020 warn_traditional = (flags >> 2) & 1;
1021 flag_iso = (flags >> 3) & 1;
1024 /* Possibly kinds of declarator to parse. */
1025 typedef enum c_dtr_syn {
1026 /* A normal declarator with an identifier. */
1028 /* An abstract declarator (maybe empty). */
1030 /* APPLE LOCAL begin blocks 6339747 */
1031 /* A block declarator (maybe empty). */
1033 /* APPLE LOCAL end blocks 6339747 */
1034 /* A parameter declarator: may be either, but after a type name does
1035 not redeclare a typedef name as an identifier if it can
1036 alternatively be interpreted as a typedef name; see DR#009,
1037 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1038 following DR#249. For example, given a typedef T, "int T" and
1039 "int *T" are valid parameter declarations redeclaring T, while
1040 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1041 abstract declarators rather than involving redundant parentheses;
1042 the same applies with attributes inside the parentheses before
1047 static void c_parser_external_declaration (c_parser *);
1048 static void c_parser_asm_definition (c_parser *);
1049 /* APPLE LOCAL radar 4708210 (for_objc_collection in 4.2) */
1050 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, bool, tree*);
1051 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
1053 static struct c_typespec c_parser_enum_specifier (c_parser *);
1054 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1055 static tree c_parser_struct_declaration (c_parser *);
1056 static struct c_typespec c_parser_typeof_specifier (c_parser *);
1057 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
1059 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1061 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1063 struct c_declarator *);
1064 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1065 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
1066 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1067 static tree c_parser_simple_asm_expr (c_parser *);
1068 static tree c_parser_attributes (c_parser *);
1069 static struct c_type_name *c_parser_type_name (c_parser *);
1070 static struct c_expr c_parser_initializer (c_parser *);
1071 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
1072 static void c_parser_initelt (c_parser *);
1073 static void c_parser_initval (c_parser *, struct c_expr *);
1074 static tree c_parser_compound_statement (c_parser *);
1075 static void c_parser_compound_statement_nostart (c_parser *);
1076 static void c_parser_label (c_parser *);
1077 static void c_parser_statement (c_parser *);
1078 static void c_parser_statement_after_labels (c_parser *);
1079 static void c_parser_if_statement (c_parser *);
1080 static void c_parser_switch_statement (c_parser *);
1081 static void c_parser_while_statement (c_parser *);
1082 static void c_parser_do_statement (c_parser *);
1083 static void c_parser_for_statement (c_parser *);
1084 static tree c_parser_asm_statement (c_parser *);
1085 /* APPLE LOCAL begin radar 5732232 - blocks (C++ ca) */
1086 static tree c_parser_block_literal_expr (c_parser *);
1087 /* APPLE LOCAL end radar 5732232 - blocks (C++ ca) */
1088 static tree c_parser_asm_operands (c_parser *, bool);
1089 static tree c_parser_asm_clobbers (c_parser *);
1090 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
1091 static struct c_expr c_parser_conditional_expression (c_parser *,
1093 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
1094 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1095 static struct c_expr c_parser_unary_expression (c_parser *);
1096 static struct c_expr c_parser_sizeof_expression (c_parser *);
1097 static struct c_expr c_parser_alignof_expression (c_parser *);
1098 static struct c_expr c_parser_postfix_expression (c_parser *);
1099 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1100 struct c_type_name *);
1101 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1103 static struct c_expr c_parser_expression (c_parser *);
1104 static struct c_expr c_parser_expression_conv (c_parser *);
1105 static tree c_parser_expr_list (c_parser *, bool);
1106 static void c_parser_omp_construct (c_parser *);
1107 static void c_parser_omp_threadprivate (c_parser *);
1108 static void c_parser_omp_barrier (c_parser *);
1109 static void c_parser_omp_flush (c_parser *);
1111 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
1112 static bool c_parser_pragma (c_parser *, enum pragma_context);
1114 /* These Objective-C parser functions are only ever called when
1115 compiling Objective-C. */
1116 /* APPLE LOCAL radar 4548636 - class attributes. */
1117 static void c_parser_objc_class_definition (c_parser *, tree);
1118 static void c_parser_objc_class_instance_variables (c_parser *);
1119 static void c_parser_objc_class_declaration (c_parser *);
1120 static void c_parser_objc_alias_declaration (c_parser *);
1121 /* APPLE LOCAL radar 4947311 - protocol attributes */
1122 static void c_parser_objc_protocol_definition (c_parser *, tree);
1123 static enum tree_code c_parser_objc_method_type (c_parser *);
1124 static void c_parser_objc_method_definition (c_parser *);
1125 /* APPLE LOCAL C* property (Radar 4436866) (in 4.2 b) */
1126 static void c_parser_objc_interfacedecllist (c_parser *);
1127 /* APPLE LOCAL C* property (Radar 4436866) (in 4.2 x) */
1128 static void c_parser_objc_property_declaration (c_parser *);
1129 static void c_parser_objc_methodproto (c_parser *);
1130 static tree c_parser_objc_method_decl (c_parser *);
1131 static tree c_parser_objc_type_name (c_parser *);
1132 static tree c_parser_objc_protocol_refs (c_parser *);
1133 static void c_parser_objc_try_catch_statement (c_parser *);
1134 static void c_parser_objc_synchronized_statement (c_parser *);
1135 static tree c_parser_objc_selector (c_parser *);
1136 static tree c_parser_objc_selector_arg (c_parser *);
1137 static tree c_parser_objc_receiver (c_parser *);
1138 static tree c_parser_objc_message_args (c_parser *);
1139 static tree c_parser_objc_keywordexpr (c_parser *);
1141 /* Parse a translation unit (C90 6.7, C99 6.9).
1144 external-declarations
1146 external-declarations:
1147 external-declaration
1148 external-declarations external-declaration
1157 c_parser_translation_unit (c_parser *parser)
1159 if (c_parser_next_token_is (parser, CPP_EOF))
1162 pedwarn ("ISO C forbids an empty source file");
1166 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1170 c_parser_external_declaration (parser);
1171 obstack_free (&parser_obstack, obstack_position);
1173 while (c_parser_next_token_is_not (parser, CPP_EOF));
1177 /* Parse an external declaration (C90 6.7, C99 6.9).
1179 external-declaration:
1185 external-declaration:
1188 __extension__ external-declaration
1192 external-declaration:
1193 objc-class-definition
1194 objc-class-declaration
1195 objc-alias-declaration
1196 objc-protocol-definition
1197 objc-method-definition
1202 c_parser_external_declaration (c_parser *parser)
1205 switch (c_parser_peek_token (parser)->type)
1208 switch (c_parser_peek_token (parser)->keyword)
1211 ext = disable_extension_diagnostics ();
1212 c_parser_consume_token (parser);
1213 c_parser_external_declaration (parser);
1214 restore_extension_diagnostics (ext);
1217 c_parser_asm_definition (parser);
1219 case RID_AT_INTERFACE:
1220 case RID_AT_IMPLEMENTATION:
1221 gcc_assert (c_dialect_objc ());
1222 /* APPLE LOCAL radar 4548636 - class attributes. */
1223 c_parser_objc_class_definition (parser, NULL_TREE);
1226 gcc_assert (c_dialect_objc ());
1227 c_parser_objc_class_declaration (parser);
1230 gcc_assert (c_dialect_objc ());
1231 c_parser_objc_alias_declaration (parser);
1233 case RID_AT_PROTOCOL:
1234 gcc_assert (c_dialect_objc ());
1235 /* APPLE LOCAL begin radar 4947311 - protocol attributes */
1236 c_parser_objc_protocol_definition (parser, NULL_TREE);
1238 /* APPLE LOCAL end radar 4947311 - protocol attributes */
1239 /* APPLE LOCAL begin C* property (Radar 4436866) (in 4.2 x) */
1240 case RID_AT_PROPERTY:
1241 c_parser_objc_property_declaration (parser);
1243 /* APPLE LOCAL end C* property (Radar 4436866) (in 4.2 x) */
1245 gcc_assert (c_dialect_objc ());
1246 c_parser_consume_token (parser);
1247 objc_finish_implementation ();
1255 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
1256 c_parser_consume_token (parser);
1259 c_parser_pragma (parser, pragma_external);
1263 if (c_dialect_objc ())
1265 c_parser_objc_method_definition (parser);
1268 /* Else fall through, and yield a syntax error trying to parse
1269 as a declaration or function definition. */
1272 /* A declaration or a function definition. We can only tell
1273 which after parsing the declaration specifiers, if any, and
1274 the first declarator. */
1275 /* APPLE LOCAL radar 4708210 (for_objc_collection in 4.2) */
1276 c_parser_declaration_or_fndef (parser, true, true, false, true, NULL);
1282 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1283 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1284 accepted; otherwise (old-style parameter declarations) only other
1285 declarations are accepted. If NESTED is true, we are inside a
1286 function or parsing old-style parameter declarations; any functions
1287 encountered are nested functions and declaration specifiers are
1288 required; otherwise we are at top level and functions are normal
1289 functions and declaration specifiers may be optional. If EMPTY_OK
1290 is true, empty declarations are OK (subject to all other
1291 constraints); otherwise (old-style parameter declarations) they are
1292 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1293 may start with attributes; otherwise they may not.
1296 declaration-specifiers init-declarator-list[opt] ;
1298 function-definition:
1299 declaration-specifiers[opt] declarator declaration-list[opt]
1304 declaration-list declaration
1306 init-declarator-list:
1308 init-declarator-list , init-declarator
1311 declarator simple-asm-expr[opt] attributes[opt]
1312 declarator simple-asm-expr[opt] attributes[opt] = initializer
1316 nested-function-definition:
1317 declaration-specifiers declarator declaration-list[opt]
1320 The simple-asm-expr and attributes are GNU extensions.
1322 This function does not handle __extension__; that is handled in its
1323 callers. ??? Following the old parser, __extension__ may start
1324 external declarations, declarations in functions and declarations
1325 at the start of "for" loops, but not old-style parameter
1328 C99 requires declaration specifiers in a function definition; the
1329 absence is diagnosed through the diagnosis of implicit int. In GNU
1330 C we also allow but diagnose declarations without declaration
1331 specifiers, but only at top level (elsewhere they conflict with
1337 threadprivate-directive */
1340 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
1341 /* APPLE LOCAL radar 4708210 (for_objc_collection in 4.2) */
1342 bool nested, bool start_attr_ok, tree *foreach_elem)
1344 struct c_declspecs *specs;
1346 tree all_prefix_attrs;
1347 bool diagnosed_no_specs = false;
1349 specs = build_null_declspecs ();
1350 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1353 c_parser_skip_to_end_of_block_or_statement (parser);
1356 if (nested && !specs->declspecs_seen_p)
1358 c_parser_error (parser, "expected declaration specifiers");
1359 c_parser_skip_to_end_of_block_or_statement (parser);
1362 finish_declspecs (specs);
1363 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1369 shadow_tag_warned (specs, 1);
1370 pedwarn ("empty declaration");
1372 c_parser_consume_token (parser);
1375 /* APPLE LOCAL begin radar 4548636 - class attributes. */
1376 else if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE)
1377 || c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
1379 gcc_assert (c_dialect_objc ());
1380 if (!specs->declspecs_seen_p || specs->attrs == NULL_TREE
1381 || specs->type_seen_p || specs->non_sc_seen_p)
1382 c_parser_error (parser, "no type or storage class may be specified here");
1383 c_parser_objc_class_definition (parser, specs->attrs);
1386 /* APPLE LOCAL end radar 4548636 - class attributes. */
1387 /* APPLE LOCAL begin radar 4947311 - protocol attributes */
1388 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL))
1390 gcc_assert (c_dialect_objc ());
1391 if (!specs->declspecs_seen_p || specs->attrs == NULL_TREE
1392 || specs->type_seen_p || specs->non_sc_seen_p)
1393 c_parser_error (parser, "no type or storage class may be specified here");
1394 c_parser_objc_protocol_definition (parser, specs->attrs);
1397 /* APPLE LOCAL end radar 4947311 - protocol attributes */
1398 pending_xref_error ();
1399 prefix_attrs = specs->attrs;
1400 all_prefix_attrs = prefix_attrs;
1401 specs->attrs = NULL_TREE;
1404 struct c_declarator *declarator;
1407 /* Declaring either one or more declarators (in which case we
1408 should diagnose if there were no declaration specifiers) or a
1409 function definition (in which case the diagnostic for
1410 implicit int suffices). */
1411 declarator = c_parser_declarator (parser, specs->type_seen_p,
1412 C_DTR_NORMAL, &dummy);
1413 if (declarator == NULL)
1415 c_parser_skip_to_end_of_block_or_statement (parser);
1418 if (c_parser_next_token_is (parser, CPP_EQ)
1419 || c_parser_next_token_is (parser, CPP_COMMA)
1420 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1421 || c_parser_next_token_is_keyword (parser, RID_ASM)
1422 /* APPLE LOCAL radar 4708210 (for_objc_collection in 4.2) */
1423 || c_parser_next_token_is_keyword (parser, RID_IN)
1424 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1426 tree asm_name = NULL_TREE;
1427 tree postfix_attrs = NULL_TREE;
1428 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1430 diagnosed_no_specs = true;
1431 pedwarn ("data definition has no type or storage class");
1433 /* Having seen a data definition, there cannot now be a
1434 function definition. */
1436 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1437 asm_name = c_parser_simple_asm_expr (parser);
1438 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1439 postfix_attrs = c_parser_attributes (parser);
1440 /* APPLE LOCAL begin radar 4708210 (for_objc_collection in 4.2) */
1441 if (c_parser_next_token_is_keyword (parser, RID_IN))
1443 gcc_assert (foreach_elem);
1444 *foreach_elem = start_decl (declarator, specs, true,
1445 chainon (postfix_attrs, all_prefix_attrs));
1447 *foreach_elem = error_mark_node;
1448 start_init (*foreach_elem, asm_name, global_bindings_p ());
1451 /* APPLE LOCAL end radar 4708210 (for_objc_collection in 4.2) */
1452 if (c_parser_next_token_is (parser, CPP_EQ))
1456 c_parser_consume_token (parser);
1457 /* The declaration of the variable is in effect while
1458 its initializer is parsed. */
1459 d = start_decl (declarator, specs, true,
1460 chainon (postfix_attrs, all_prefix_attrs));
1462 d = error_mark_node;
1463 start_init (d, asm_name, global_bindings_p ());
1464 init = c_parser_initializer (parser);
1466 if (d != error_mark_node)
1468 maybe_warn_string_init (TREE_TYPE (d), init);
1469 finish_decl (d, init.value, asm_name);
1474 tree d = start_decl (declarator, specs, false,
1475 chainon (postfix_attrs,
1478 finish_decl (d, NULL_TREE, asm_name);
1480 if (c_parser_next_token_is (parser, CPP_COMMA))
1482 c_parser_consume_token (parser);
1483 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1484 all_prefix_attrs = chainon (c_parser_attributes (parser),
1487 all_prefix_attrs = prefix_attrs;
1490 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1492 c_parser_consume_token (parser);
1497 c_parser_error (parser, "expected %<,%> or %<;%>");
1498 c_parser_skip_to_end_of_block_or_statement (parser);
1504 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1505 "%<asm%> or %<__attribute__%>");
1506 c_parser_skip_to_end_of_block_or_statement (parser);
1509 /* Function definition (nested or otherwise). */
1512 /* APPLE LOCAL begin radar 5985368 */
1513 if (declarator->declarator && declarator->declarator->kind == cdk_block_pointer)
1514 error ("bad definition of a block");
1516 /* APPLE LOCAL end radar 5985368 */
1517 pedwarn ("ISO C forbids nested functions");
1518 /* APPLE LOCAL begin nested functions 4258406 4357979 (in 4.2 m) */
1519 else if (flag_nested_functions == 0)
1520 error ("nested functions are disabled, use -fnested-functions to re-enable");
1521 /* APPLE LOCAL end nested functions 4258406 4357979 (in 4.2 m) */
1523 push_function_context ();
1525 if (!start_function (specs, declarator, all_prefix_attrs))
1527 /* This can appear in many cases looking nothing like a
1528 function definition, so we don't give a more specific
1529 error suggesting there was one. */
1530 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1531 "or %<__attribute__%>");
1533 pop_function_context ();
1536 /* Parse old-style parameter declarations. ??? Attributes are
1537 not allowed to start declaration specifiers here because of a
1538 syntax conflict between a function declaration with attribute
1539 suffix and a function definition with an attribute prefix on
1540 first old-style parameter declaration. Following the old
1541 parser, they are not accepted on subsequent old-style
1542 parameter declarations either. However, there is no
1543 ambiguity after the first declaration, nor indeed on the
1544 first as long as we don't allow postfix attributes after a
1545 declarator with a nonempty identifier list in a definition;
1546 and postfix attributes have never been accepted here in
1547 function definitions either. */
1548 while (c_parser_next_token_is_not (parser, CPP_EOF)
1549 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1550 /* APPLE LOCAL radar 4708210 (for_objc_collection in 4.2) */
1551 c_parser_declaration_or_fndef (parser, false, false, true, false, NULL);
1552 DECL_SOURCE_LOCATION (current_function_decl)
1553 = c_parser_peek_token (parser)->location;
1554 store_parm_decls ();
1555 fnbody = c_parser_compound_statement (parser);
1558 tree decl = current_function_decl;
1561 pop_function_context ();
1562 add_stmt (build_stmt (DECL_EXPR, decl));
1574 finish_parse_foreach_header (c_parser *parser, tree foreach_elem_selector)
1577 int save_flag_isoc99 = flag_isoc99;
1578 gcc_assert (foreach_elem_selector);
1579 /* Consume 'in' keyword */
1580 c_parser_consume_token (parser);
1581 res = build_tree_list (foreach_elem_selector, c_parser_initializer (parser).value);
1584 check_for_loop_decls ();
1585 flag_isoc99 = save_flag_isoc99;
1588 /* APPLE LOCAL end radar 4708210 (for_objc_collection in 4.2) */
1590 /* Parse an asm-definition (asm() outside a function body). This is a
1598 c_parser_asm_definition (c_parser *parser)
1600 tree asm_str = c_parser_simple_asm_expr (parser);
1602 cgraph_add_asm_node (asm_str);
1603 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1606 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1607 6.7), adding them to SPECS (which may already include some).
1608 Storage class specifiers are accepted iff SCSPEC_OK; type
1609 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1610 the start iff START_ATTR_OK.
1612 declaration-specifiers:
1613 storage-class-specifier declaration-specifiers[opt]
1614 type-specifier declaration-specifiers[opt]
1615 type-qualifier declaration-specifiers[opt]
1616 function-specifier declaration-specifiers[opt]
1618 Function specifiers (inline) are from C99, and are currently
1619 handled as storage class specifiers, as is __thread.
1621 C90 6.5.1, C99 6.7.1:
1622 storage-class-specifier:
1633 C90 6.5.2, C99 6.7.2:
1646 [_Imaginary removed in C99 TC2]
1647 struct-or-union-specifier
1651 (_Bool and _Complex are new in C99.)
1653 C90 6.5.3, C99 6.7.3:
1660 (restrict is new in C99.)
1664 declaration-specifiers:
1665 attributes declaration-specifiers[opt]
1667 storage-class-specifier:
1679 class-name objc-protocol-refs[opt]
1680 typedef-name objc-protocol-refs
1685 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1686 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1688 bool attrs_ok = start_attr_ok;
1689 bool seen_type = specs->type_seen_p;
1690 while (c_parser_next_token_is (parser, CPP_NAME)
1691 || c_parser_next_token_is (parser, CPP_KEYWORD)
1692 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1694 struct c_typespec t;
1696 if (c_parser_next_token_is (parser, CPP_NAME))
1698 tree value = c_parser_peek_token (parser)->value;
1699 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1700 /* This finishes the specifiers unless a type name is OK, it
1701 is declared as a type name and a type name hasn't yet
1703 if (!typespec_ok || seen_type
1704 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1706 c_parser_consume_token (parser);
1709 if (kind == C_ID_TYPENAME
1710 && (!c_dialect_objc ()
1711 || c_parser_next_token_is_not (parser, CPP_LESS)))
1713 t.kind = ctsk_typedef;
1714 /* For a typedef name, record the meaning, not the name.
1715 In case of 'foo foo, bar;'. */
1716 t.spec = lookup_name (value);
1720 tree proto = NULL_TREE;
1721 gcc_assert (c_dialect_objc ());
1723 if (c_parser_next_token_is (parser, CPP_LESS))
1724 proto = c_parser_objc_protocol_refs (parser);
1725 t.spec = objc_get_protocol_qualified_type (value, proto);
1727 declspecs_add_type (specs, t);
1730 if (c_parser_next_token_is (parser, CPP_LESS))
1732 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1733 nisse@lysator.liu.se. */
1735 gcc_assert (c_dialect_objc ());
1736 if (!typespec_ok || seen_type)
1738 proto = c_parser_objc_protocol_refs (parser);
1740 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1741 declspecs_add_type (specs, t);
1744 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1745 switch (c_parser_peek_token (parser)->keyword)
1757 /* TODO: Distinguish between function specifiers (inline)
1758 and storage class specifiers, either here or in
1759 declspecs_add_scspec. */
1760 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1761 c_parser_consume_token (parser);
1781 OBJC_NEED_RAW_IDENTIFIER (1);
1782 t.kind = ctsk_resword;
1783 t.spec = c_parser_peek_token (parser)->value;
1784 declspecs_add_type (specs, t);
1785 c_parser_consume_token (parser);
1792 t = c_parser_enum_specifier (parser);
1793 declspecs_add_type (specs, t);
1801 t = c_parser_struct_or_union_specifier (parser);
1802 declspecs_add_type (specs, t);
1805 /* ??? The old parser rejected typeof after other type
1806 specifiers, but is a syntax error the best way of
1808 if (!typespec_ok || seen_type)
1812 t = c_parser_typeof_specifier (parser);
1813 declspecs_add_type (specs, t);
1819 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1820 c_parser_consume_token (parser);
1825 attrs = c_parser_attributes (parser);
1826 declspecs_add_attrs (specs, attrs);
1835 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1838 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1839 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1840 enum attributes[opt] identifier
1842 The form with trailing comma is new in C99. The forms with
1843 attributes are GNU extensions. In GNU C, we accept any expression
1844 without commas in the syntax (assignment expressions, not just
1845 conditional expressions); assignment expressions will be diagnosed
1850 enumerator-list , enumerator
1853 enumeration-constant
1854 enumeration-constant = constant-expression
1857 static struct c_typespec
1858 c_parser_enum_specifier (c_parser *parser)
1860 struct c_typespec ret;
1862 tree ident = NULL_TREE;
1863 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1864 c_parser_consume_token (parser);
1865 attrs = c_parser_attributes (parser);
1866 if (c_parser_next_token_is (parser, CPP_NAME))
1868 ident = c_parser_peek_token (parser)->value;
1869 c_parser_consume_token (parser);
1871 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1873 /* Parse an enum definition. */
1874 tree type = start_enum (ident);
1876 /* We chain the enumerators in reverse order, then put them in
1877 forward order at the end. */
1878 tree values = NULL_TREE;
1879 c_parser_consume_token (parser);
1886 if (c_parser_next_token_is_not (parser, CPP_NAME))
1888 c_parser_error (parser, "expected identifier");
1889 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1890 values = error_mark_node;
1893 enum_id = c_parser_peek_token (parser)->value;
1894 c_parser_consume_token (parser);
1895 if (c_parser_next_token_is (parser, CPP_EQ))
1897 c_parser_consume_token (parser);
1898 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1901 enum_value = NULL_TREE;
1902 enum_decl = build_enumerator (enum_id, enum_value);
1903 TREE_CHAIN (enum_decl) = values;
1906 if (c_parser_next_token_is (parser, CPP_COMMA))
1909 c_parser_consume_token (parser);
1911 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1913 if (seen_comma && pedantic && !flag_isoc99)
1914 pedwarn ("comma at end of enumerator list");
1915 c_parser_consume_token (parser);
1920 c_parser_error (parser, "expected %<,%> or %<}%>");
1921 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1922 values = error_mark_node;
1926 postfix_attrs = c_parser_attributes (parser);
1927 ret.spec = finish_enum (type, nreverse (values),
1928 chainon (attrs, postfix_attrs));
1929 ret.kind = ctsk_tagdef;
1934 c_parser_error (parser, "expected %<{%>");
1935 ret.spec = error_mark_node;
1936 ret.kind = ctsk_tagref;
1939 ret = parser_xref_tag (ENUMERAL_TYPE, ident);
1940 /* In ISO C, enumerated types can be referred to only if already
1942 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1943 pedwarn ("ISO C forbids forward references to %<enum%> types");
1947 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1949 struct-or-union-specifier:
1950 struct-or-union attributes[opt] identifier[opt]
1951 { struct-contents } attributes[opt]
1952 struct-or-union attributes[opt] identifier
1955 struct-declaration-list
1957 struct-declaration-list:
1958 struct-declaration ;
1959 struct-declaration-list struct-declaration ;
1966 struct-declaration-list struct-declaration
1968 struct-declaration-list:
1969 struct-declaration-list ;
1972 (Note that in the syntax here, unlike that in ISO C, the semicolons
1973 are included here rather than in struct-declaration, in order to
1974 describe the syntax with extra semicolons and missing semicolon at
1979 struct-declaration-list:
1980 @defs ( class-name )
1982 (Note this does not include a trailing semicolon, but can be
1983 followed by further declarations, and gets a pedwarn-if-pedantic
1984 when followed by a semicolon.) */
1986 static struct c_typespec
1987 c_parser_struct_or_union_specifier (c_parser *parser)
1989 struct c_typespec ret;
1991 tree ident = NULL_TREE;
1992 enum tree_code code;
1993 switch (c_parser_peek_token (parser)->keyword)
2004 c_parser_consume_token (parser);
2005 attrs = c_parser_attributes (parser);
2006 if (c_parser_next_token_is (parser, CPP_NAME))
2008 ident = c_parser_peek_token (parser)->value;
2009 c_parser_consume_token (parser);
2011 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2013 /* Parse a struct or union definition. Start the scope of the
2014 tag before parsing components. */
2015 tree type = start_struct (code, ident);
2017 /* We chain the components in reverse order, then put them in
2018 forward order at the end. Each struct-declaration may
2019 declare multiple components (comma-separated), so we must use
2020 chainon to join them, although when parsing each
2021 struct-declaration we can use TREE_CHAIN directly.
2023 The theory behind all this is that there will be more
2024 semicolon separated fields than comma separated fields, and
2025 so we'll be minimizing the number of node traversals required
2027 tree contents = NULL_TREE;
2028 c_parser_consume_token (parser);
2029 /* Handle the Objective-C @defs construct,
2030 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2031 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2034 gcc_assert (c_dialect_objc ());
2035 c_parser_consume_token (parser);
2036 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2038 if (c_parser_next_token_is (parser, CPP_NAME)
2039 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2041 name = c_parser_peek_token (parser)->value;
2042 c_parser_consume_token (parser);
2046 c_parser_error (parser, "expected class name");
2047 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2050 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2052 contents = nreverse (objc_get_class_ivars (name));
2055 /* Parse the struct-declarations and semicolons. Problems with
2056 semicolons are diagnosed here; empty structures are diagnosed
2061 /* Parse any stray semicolon. */
2062 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2065 pedwarn ("extra semicolon in struct or union specified");
2066 c_parser_consume_token (parser);
2069 /* Stop if at the end of the struct or union contents. */
2070 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2072 c_parser_consume_token (parser);
2075 /* Accept #pragmas at struct scope. */
2076 if (c_parser_next_token_is (parser, CPP_PRAGMA))
2078 c_parser_pragma (parser, pragma_external);
2081 /* Parse some comma-separated declarations, but not the
2082 trailing semicolon if any. */
2083 decls = c_parser_struct_declaration (parser);
2084 contents = chainon (decls, contents);
2085 /* If no semicolon follows, either we have a parse error or
2086 are at the end of the struct or union and should
2088 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2089 c_parser_consume_token (parser);
2092 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2093 pedwarn ("no semicolon at end of struct or union");
2096 c_parser_error (parser, "expected %<;%>");
2097 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2102 postfix_attrs = c_parser_attributes (parser);
2103 ret.spec = finish_struct (type, nreverse (contents),
2104 chainon (attrs, postfix_attrs));
2105 ret.kind = ctsk_tagdef;
2110 c_parser_error (parser, "expected %<{%>");
2111 ret.spec = error_mark_node;
2112 ret.kind = ctsk_tagref;
2115 ret = parser_xref_tag (code, ident);
2119 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2120 the trailing semicolon.
2123 specifier-qualifier-list struct-declarator-list
2125 specifier-qualifier-list:
2126 type-specifier specifier-qualifier-list[opt]
2127 type-qualifier specifier-qualifier-list[opt]
2128 attributes specifier-qualifier-list[opt]
2130 struct-declarator-list:
2132 struct-declarator-list , attributes[opt] struct-declarator
2135 declarator attributes[opt]
2136 declarator[opt] : constant-expression attributes[opt]
2141 __extension__ struct-declaration
2142 specifier-qualifier-list
2144 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2145 of attributes where shown is a GNU extension. In GNU C, we accept
2146 any expression without commas in the syntax (assignment
2147 expressions, not just conditional expressions); assignment
2148 expressions will be diagnosed as non-constant. */
2151 c_parser_struct_declaration (c_parser *parser)
2153 struct c_declspecs *specs;
2155 tree all_prefix_attrs;
2157 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2161 ext = disable_extension_diagnostics ();
2162 c_parser_consume_token (parser);
2163 decl = c_parser_struct_declaration (parser);
2164 restore_extension_diagnostics (ext);
2167 specs = build_null_declspecs ();
2168 c_parser_declspecs (parser, specs, false, true, true);
2171 if (!specs->declspecs_seen_p)
2173 c_parser_error (parser, "expected specifier-qualifier-list");
2176 finish_declspecs (specs);
2177 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2180 if (!specs->type_seen_p)
2183 pedwarn ("ISO C forbids member declarations with no members");
2184 shadow_tag_warned (specs, pedantic);
2189 /* Support for unnamed structs or unions as members of
2190 structs or unions (which is [a] useful and [b] supports
2192 ret = grokfield (build_id_declarator (NULL_TREE), specs, NULL_TREE);
2196 pending_xref_error ();
2197 prefix_attrs = specs->attrs;
2198 all_prefix_attrs = prefix_attrs;
2199 specs->attrs = NULL_TREE;
2203 /* Declaring one or more declarators or un-named bit-fields. */
2204 struct c_declarator *declarator;
2206 if (c_parser_next_token_is (parser, CPP_COLON))
2207 declarator = build_id_declarator (NULL_TREE);
2209 declarator = c_parser_declarator (parser, specs->type_seen_p,
2210 C_DTR_NORMAL, &dummy);
2211 if (declarator == NULL)
2213 c_parser_skip_to_end_of_block_or_statement (parser);
2216 if (c_parser_next_token_is (parser, CPP_COLON)
2217 || c_parser_next_token_is (parser, CPP_COMMA)
2218 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2219 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2220 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2222 tree postfix_attrs = NULL_TREE;
2223 tree width = NULL_TREE;
2225 if (c_parser_next_token_is (parser, CPP_COLON))
2227 c_parser_consume_token (parser);
2228 width = c_parser_expr_no_commas (parser, NULL).value;
2230 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2231 postfix_attrs = c_parser_attributes (parser);
2232 d = grokfield (declarator, specs, width);
2233 decl_attributes (&d, chainon (postfix_attrs,
2234 all_prefix_attrs), 0);
2235 TREE_CHAIN (d) = decls;
2237 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2238 all_prefix_attrs = chainon (c_parser_attributes (parser),
2241 all_prefix_attrs = prefix_attrs;
2242 if (c_parser_next_token_is (parser, CPP_COMMA))
2243 c_parser_consume_token (parser);
2244 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2245 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2247 /* Semicolon consumed in caller. */
2252 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2258 c_parser_error (parser,
2259 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2260 "%<__attribute__%>");
2267 /* Parse a typeof specifier (a GNU extension).
2270 typeof ( expression )
2271 typeof ( type-name )
2274 static struct c_typespec
2275 c_parser_typeof_specifier (c_parser *parser)
2277 struct c_typespec ret;
2278 ret.kind = ctsk_typeof;
2279 ret.spec = error_mark_node;
2280 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2281 c_parser_consume_token (parser);
2284 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2290 if (c_parser_next_token_starts_typename (parser))
2292 struct c_type_name *type = c_parser_type_name (parser);
2297 ret.spec = groktypename (type);
2298 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2304 struct c_expr expr = c_parser_expression (parser);
2307 if (TREE_CODE (expr.value) == COMPONENT_REF
2308 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2309 error ("%<typeof%> applied to a bit-field");
2310 ret.spec = TREE_TYPE (expr.value);
2311 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2312 /* This should be returned with the type so that when the type
2313 is evaluated, this can be evaluated. For now, we avoid
2314 evaluation when the context might. */
2315 if (!skip_evaluation && was_vm)
2317 tree e = expr.value;
2319 /* If the expression is not of a type to which we cannot assign a line
2320 number, wrap the thing in a no-op NOP_EXPR. */
2321 if (DECL_P (e) || CONSTANT_CLASS_P (e))
2322 e = build1 (NOP_EXPR, void_type_node, e);
2325 SET_EXPR_LOCATION (e, input_location);
2329 pop_maybe_used (was_vm);
2331 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2335 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2336 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2337 be redeclared; otherwise it may not. KIND indicates which kind of
2338 declarator is wanted. Returns a valid declarator except in the
2339 case of a syntax error in which case NULL is returned. *SEEN_ID is
2340 set to true if an identifier being declared is seen; this is used
2341 to diagnose bad forms of abstract array declarators and to
2342 determine whether an identifier list is syntactically permitted.
2345 pointer[opt] direct-declarator
2349 ( attributes[opt] declarator )
2350 direct-declarator array-declarator
2351 direct-declarator ( parameter-type-list )
2352 direct-declarator ( identifier-list[opt] )
2355 * type-qualifier-list[opt]
2356 * type-qualifier-list[opt] pointer
2358 type-qualifier-list:
2361 type-qualifier-list type-qualifier
2362 type-qualifier-list attributes
2364 parameter-type-list:
2366 parameter-list , ...
2369 parameter-declaration
2370 parameter-list , parameter-declaration
2372 parameter-declaration:
2373 declaration-specifiers declarator attributes[opt]
2374 declaration-specifiers abstract-declarator[opt] attributes[opt]
2378 identifier-list , identifier
2380 abstract-declarator:
2382 pointer[opt] direct-abstract-declarator
2384 direct-abstract-declarator:
2385 ( attributes[opt] abstract-declarator )
2386 direct-abstract-declarator[opt] array-declarator
2387 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2392 direct-declarator ( parameter-forward-declarations
2393 parameter-type-list[opt] )
2395 direct-abstract-declarator:
2396 direct-abstract-declarator[opt] ( parameter-forward-declarations
2397 parameter-type-list[opt] )
2399 parameter-forward-declarations:
2401 parameter-forward-declarations parameter-list ;
2403 APPLE LOCAL begin blocks 6339747
2406 pointer[opt] direct-block-declarator
2408 direct-block-declarator:
2409 ( attributes[opt] block-declarator )
2410 direct-block-declarator[opt] array-declarator
2411 direct-block-declarator[opt]
2412 ( parameter-type-list[opt] ) [opt]
2413 APPLE LOCAL end blocks 6339747
2415 The uses of attributes shown above are GNU extensions.
2417 Some forms of array declarator are not included in C99 in the
2418 syntax for abstract declarators; these are disallowed elsewhere.
2419 This may be a defect (DR#289).
2421 This function also accepts an omitted abstract declarator as being
2422 an abstract declarator, although not part of the formal syntax. */
2424 static struct c_declarator *
2425 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2428 /* Parse any initial pointer part. */
2429 if (c_parser_next_token_is (parser, CPP_MULT))
2431 struct c_declspecs *quals_attrs = build_null_declspecs ();
2432 struct c_declarator *inner;
2433 c_parser_consume_token (parser);
2434 c_parser_declspecs (parser, quals_attrs, false, false, true);
2435 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2439 return make_pointer_declarator (quals_attrs, inner);
2441 /* APPLE LOCAL begin radar 5732232 - blocks (C++ cc) */
2442 else if (flag_blocks && c_parser_next_token_is (parser, CPP_XOR)) {
2443 struct c_declspecs *quals_attrs = build_null_declspecs ();
2444 struct c_declarator *inner;
2445 c_parser_consume_token (parser);
2446 c_parser_declspecs (parser, quals_attrs, false, false, true);
2447 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2451 /* APPLE LOCAL radar 5814025 (C++ cc) */
2452 return make_block_pointer_declarator (quals_attrs, inner);
2454 /* APPLE LOCAL end radar 5732232 - blocks (C++ cc) */
2455 /* Now we have a direct declarator, direct abstract declarator or
2456 nothing (which counts as a direct abstract declarator here). */
2457 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2460 /* Parse a direct declarator or direct abstract declarator; arguments
2461 as c_parser_declarator. */
2463 static struct c_declarator *
2464 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2467 /* The direct declarator must start with an identifier (possibly
2468 omitted) or a parenthesized declarator (possibly abstract). In
2469 an ordinary declarator, initial parentheses must start a
2470 parenthesized declarator. In an abstract declarator or parameter
2471 declarator, they could start a parenthesized declarator or a
2472 parameter list. To tell which, the open parenthesis and any
2473 following attributes must be read. If a declaration specifier
2474 follows, then it is a parameter list; if the specifier is a
2475 typedef name, there might be an ambiguity about redeclaring it,
2476 which is resolved in the direction of treating it as a typedef
2477 name. If a close parenthesis follows, it is also an empty
2478 parameter list, as the syntax does not permit empty abstract
2479 declarators. Otherwise, it is a parenthesized declarator (in
2480 which case the analysis may be repeated inside it, recursively).
2482 ??? There is an ambiguity in a parameter declaration "int
2483 (__attribute__((foo)) x)", where x is not a typedef name: it
2484 could be an abstract declarator for a function, or declare x with
2485 parentheses. The proper resolution of this ambiguity needs
2486 documenting. At present we follow an accident of the old
2487 parser's implementation, whereby the first parameter must have
2488 some declaration specifiers other than just attributes. Thus as
2489 a parameter declaration it is treated as a parenthesized
2490 parameter named x, and as an abstract declarator it is
2493 ??? Also following the old parser, attributes inside an empty
2494 parameter list are ignored, making it a list not yielding a
2495 prototype, rather than giving an error or making it have one
2496 parameter with implicit type int.
2498 ??? Also following the old parser, typedef names may be
2499 redeclared in declarators, but not Objective-C class names. */
2501 /* APPLE LOCAL blocks 6339747 */
2502 if ((kind != C_DTR_ABSTRACT && kind != C_DTR_BLOCK)
2503 && c_parser_next_token_is (parser, CPP_NAME)
2505 /* APPLE LOCAL begin radar 4281748 */
2506 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
2507 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
2508 /* APPLE LOCAL end radar 4281748 */
2509 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2511 struct c_declarator *inner
2512 = build_id_declarator (c_parser_peek_token (parser)->value);
2514 inner->id_loc = c_parser_peek_token (parser)->location;
2515 c_parser_consume_token (parser);
2516 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2519 if (kind != C_DTR_NORMAL
2520 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2522 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2523 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2526 /* Either we are at the end of an abstract declarator, or we have
2529 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2532 struct c_declarator *inner;
2533 c_parser_consume_token (parser);
2534 attrs = c_parser_attributes (parser);
2535 if (kind != C_DTR_NORMAL
2536 && (c_parser_next_token_starts_declspecs (parser)
2537 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2539 struct c_arg_info *args
2540 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2547 = build_function_declarator (args,
2548 build_id_declarator (NULL_TREE));
2549 return c_parser_direct_declarator_inner (parser, *seen_id,
2553 /* A parenthesized declarator. */
2554 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2555 if (inner != NULL && attrs != NULL)
2556 inner = build_attrs_declarator (attrs, inner);
2557 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2559 c_parser_consume_token (parser);
2563 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2567 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2574 if (kind == C_DTR_NORMAL)
2576 c_parser_error (parser, "expected identifier or %<(%>");
2580 return build_id_declarator (NULL_TREE);
2584 /* Parse part of a direct declarator or direct abstract declarator,
2585 given that some (in INNER) has already been parsed; ID_PRESENT is
2586 true if an identifier is present, false for an abstract
2589 static struct c_declarator *
2590 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2591 struct c_declarator *inner)
2593 /* Parse a sequence of array declarators and parameter lists. */
2594 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2596 struct c_declarator *declarator;
2597 struct c_declspecs *quals_attrs = build_null_declspecs ();
2601 c_parser_consume_token (parser);
2602 c_parser_declspecs (parser, quals_attrs, false, false, true);
2603 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2605 c_parser_consume_token (parser);
2606 if (static_seen && !quals_attrs->declspecs_seen_p)
2607 c_parser_declspecs (parser, quals_attrs, false, false, true);
2608 if (!quals_attrs->declspecs_seen_p)
2610 /* If "static" is present, there must be an array dimension.
2611 Otherwise, there may be a dimension, "*", or no
2616 dimen = c_parser_expr_no_commas (parser, NULL).value;
2620 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2625 else if (c_parser_next_token_is (parser, CPP_MULT))
2627 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2631 c_parser_consume_token (parser);
2636 dimen = c_parser_expr_no_commas (parser, NULL).value;
2642 dimen = c_parser_expr_no_commas (parser, NULL).value;
2645 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2646 c_parser_consume_token (parser);
2649 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2653 declarator = build_array_declarator (dimen, quals_attrs, static_seen,
2655 if (declarator == NULL)
2657 inner = set_array_declarator_inner (declarator, inner, !id_present);
2658 return c_parser_direct_declarator_inner (parser, id_present, inner);
2660 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2663 struct c_arg_info *args;
2664 c_parser_consume_token (parser);
2665 attrs = c_parser_attributes (parser);
2666 args = c_parser_parms_declarator (parser, id_present, attrs);
2671 inner = build_function_declarator (args, inner);
2672 return c_parser_direct_declarator_inner (parser, id_present, inner);
2678 /* Parse a parameter list or identifier list, including the closing
2679 parenthesis but not the opening one. ATTRS are the attributes at
2680 the start of the list. ID_LIST_OK is true if an identifier list is
2681 acceptable; such a list must not have attributes at the start. */
2683 static struct c_arg_info *
2684 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2687 declare_parm_level ();
2688 /* If the list starts with an identifier, it is an identifier list.
2689 Otherwise, it is either a prototype list or an empty list. */
2692 && c_parser_next_token_is (parser, CPP_NAME)
2693 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2695 tree list = NULL_TREE, *nextp = &list;
2696 while (c_parser_next_token_is (parser, CPP_NAME)
2697 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2699 *nextp = build_tree_list (NULL_TREE,
2700 c_parser_peek_token (parser)->value);
2701 nextp = & TREE_CHAIN (*nextp);
2702 c_parser_consume_token (parser);
2703 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2705 c_parser_consume_token (parser);
2706 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2708 c_parser_error (parser, "expected identifier");
2712 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2714 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2719 ret->pending_sizes = 0;
2720 ret->had_vla_unspec = 0;
2721 c_parser_consume_token (parser);
2727 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2735 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2741 /* Parse a parameter list (possibly empty), including the closing
2742 parenthesis but not the opening one. ATTRS are the attributes at
2743 the start of the list. */
2745 static struct c_arg_info *
2746 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2748 bool good_parm = false;
2749 /* ??? Following the old parser, forward parameter declarations may
2750 use abstract declarators, and if no real parameter declarations
2751 follow the forward declarations then this is not diagnosed. Also
2752 note as above that attributes are ignored as the only contents of
2753 the parentheses, or as the only contents after forward
2755 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2757 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2762 ret->pending_sizes = 0;
2763 ret->had_vla_unspec = 0;
2764 c_parser_consume_token (parser);
2767 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2769 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2773 ret->pending_sizes = 0;
2774 ret->had_vla_unspec = 0;
2775 /* Suppress -Wold-style-definition for this case. */
2776 ret->types = error_mark_node;
2777 error ("ISO C requires a named argument before %<...%>");
2778 c_parser_consume_token (parser);
2779 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2781 c_parser_consume_token (parser);
2786 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2791 /* Nonempty list of parameters, either terminated with semicolon
2792 (forward declarations; recurse) or with close parenthesis (normal
2793 function) or with ", ... )" (variadic function). */
2796 /* Parse a parameter. */
2797 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2802 push_parm_decl (parm);
2804 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2807 c_parser_consume_token (parser);
2808 mark_forward_parm_decls ();
2809 new_attrs = c_parser_attributes (parser);
2810 return c_parser_parms_list_declarator (parser, new_attrs);
2812 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2814 c_parser_consume_token (parser);
2816 return get_parm_info (false);
2819 struct c_arg_info *ret
2820 = XOBNEW (&parser_obstack, struct c_arg_info);
2825 ret->pending_sizes = 0;
2826 ret->had_vla_unspec = 0;
2830 if (!c_parser_require (parser, CPP_COMMA,
2831 "expected %<;%>, %<,%> or %<)%>"))
2833 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2836 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2838 c_parser_consume_token (parser);
2839 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2841 c_parser_consume_token (parser);
2843 return get_parm_info (true);
2846 struct c_arg_info *ret
2847 = XOBNEW (&parser_obstack, struct c_arg_info);
2852 ret->pending_sizes = 0;
2853 ret->had_vla_unspec = 0;
2859 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2867 /* Parse a parameter declaration. ATTRS are the attributes at the
2868 start of the declaration if it is the first parameter. */
2870 static struct c_parm *
2871 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2873 struct c_declspecs *specs;
2874 struct c_declarator *declarator;
2876 tree postfix_attrs = NULL_TREE;
2878 if (!c_parser_next_token_starts_declspecs (parser))
2880 /* ??? In some Objective-C cases '...' isn't applicable so there
2881 should be a different message. */
2882 c_parser_error (parser,
2883 "expected declaration specifiers or %<...%>");
2884 c_parser_skip_to_end_of_parameter (parser);
2887 specs = build_null_declspecs ();
2890 declspecs_add_attrs (specs, attrs);
2893 c_parser_declspecs (parser, specs, true, true, true);
2894 finish_declspecs (specs);
2895 pending_xref_error ();
2896 prefix_attrs = specs->attrs;
2897 specs->attrs = NULL_TREE;
2898 declarator = c_parser_declarator (parser, specs->type_seen_p,
2899 C_DTR_PARM, &dummy);
2900 if (declarator == NULL)
2902 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2905 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2906 postfix_attrs = c_parser_attributes (parser);
2907 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2911 /* Parse a string literal in an asm expression. It should not be
2912 translated, and wide string literals are an error although
2913 permitted by the syntax. This is a GNU extension.
2918 ??? At present, following the old parser, the caller needs to have
2919 set c_lex_string_translate to 0. It would be better to follow the
2920 C++ parser rather than using the c_lex_string_translate kludge. */
2923 c_parser_asm_string_literal (c_parser *parser)
2926 if (c_parser_next_token_is (parser, CPP_STRING))
2928 str = c_parser_peek_token (parser)->value;
2929 c_parser_consume_token (parser);
2931 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2933 error ("wide string literal in %<asm%>");
2934 str = build_string (1, "");
2935 c_parser_consume_token (parser);
2939 c_parser_error (parser, "expected string literal");
2945 /* Parse a simple asm expression. This is used in restricted
2946 contexts, where a full expression with inputs and outputs does not
2947 make sense. This is a GNU extension.
2950 asm ( asm-string-literal )
2954 c_parser_simple_asm_expr (c_parser *parser)
2957 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2958 /* ??? Follow the C++ parser rather than using the
2959 c_lex_string_translate kludge. */
2960 c_lex_string_translate = 0;
2961 c_parser_consume_token (parser);
2962 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2964 c_lex_string_translate = 1;
2967 str = c_parser_asm_string_literal (parser);
2968 c_lex_string_translate = 1;
2969 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2971 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2977 /* Parse (possibly empty) attributes. This is a GNU extension.
2981 attributes attribute
2984 __attribute__ ( ( attribute-list ) )
2988 attribute_list , attrib
2993 any-word ( identifier )
2994 any-word ( identifier , nonempty-expr-list )
2995 any-word ( expr-list )
2997 where the "identifier" must not be declared as a type, and
2998 "any-word" may be any identifier (including one declared as a
2999 type), a reserved word storage class specifier, type specifier or
3000 type qualifier. ??? This still leaves out most reserved keywords
3001 (following the old parser), shouldn't we include them, and why not
3002 allow identifiers declared as types to start the arguments? */
3005 c_parser_attributes (c_parser *parser)
3007 tree attrs = NULL_TREE;
3008 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3010 /* ??? Follow the C++ parser rather than using the
3011 c_lex_string_translate kludge. */
3012 c_lex_string_translate = 0;
3013 c_parser_consume_token (parser);
3014 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3016 c_lex_string_translate = 1;
3019 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3021 c_lex_string_translate = 1;
3022 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3025 /* Parse the attribute list. */
3026 while (c_parser_next_token_is (parser, CPP_COMMA)
3027 || c_parser_next_token_is (parser, CPP_NAME)
3028 || c_parser_next_token_is (parser, CPP_KEYWORD))
3030 tree attr, attr_name, attr_args;
3031 if (c_parser_next_token_is (parser, CPP_COMMA))
3033 c_parser_consume_token (parser);
3036 if (c_parser_next_token_is (parser, CPP_KEYWORD))
3038 /* ??? See comment above about what keywords are
3041 switch (c_parser_peek_token (parser)->keyword)
3076 attr_name = c_parser_peek_token (parser)->value;
3077 c_parser_consume_token (parser);
3078 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
3080 attr = build_tree_list (attr_name, NULL_TREE);
3081 attrs = chainon (attrs, attr);
3084 c_parser_consume_token (parser);
3085 /* Parse the attribute contents. If they start with an
3086 identifier which is followed by a comma or close
3087 parenthesis, then the arguments start with that
3088 identifier; otherwise they are an expression list. */
3089 if (c_parser_next_token_is (parser, CPP_NAME)
3090 && c_parser_peek_token (parser)->id_kind == C_ID_ID
3091 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
3092 || (c_parser_peek_2nd_token (parser)->type
3093 == CPP_CLOSE_PAREN)))
3095 tree arg1 = c_parser_peek_token (parser)->value;
3096 c_parser_consume_token (parser);
3097 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3098 attr_args = build_tree_list (NULL_TREE, arg1);
3101 c_parser_consume_token (parser);
3102 attr_args = tree_cons (NULL_TREE, arg1,
3103 c_parser_expr_list (parser, false));
3108 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3109 attr_args = NULL_TREE;
3111 attr_args = c_parser_expr_list (parser, false);
3113 attr = build_tree_list (attr_name, attr_args);
3114 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3115 c_parser_consume_token (parser);
3118 c_lex_string_translate = 1;
3119 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3123 attrs = chainon (attrs, attr);
3125 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3126 c_parser_consume_token (parser);
3129 c_lex_string_translate = 1;
3130 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3134 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3135 c_parser_consume_token (parser);
3138 c_lex_string_translate = 1;
3139 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3143 c_lex_string_translate = 1;
3148 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3151 specifier-qualifier-list abstract-declarator[opt]
3154 static struct c_type_name *
3155 c_parser_type_name (c_parser *parser)
3157 struct c_declspecs *specs = build_null_declspecs ();
3158 struct c_declarator *declarator;
3159 struct c_type_name *ret;
3161 c_parser_declspecs (parser, specs, false, true, true);
3162 if (!specs->declspecs_seen_p)
3164 c_parser_error (parser, "expected specifier-qualifier-list");
3167 pending_xref_error ();
3168 finish_declspecs (specs);
3169 declarator = c_parser_declarator (parser, specs->type_seen_p,
3170 C_DTR_ABSTRACT, &dummy);
3171 if (declarator == NULL)
3173 ret = XOBNEW (&parser_obstack, struct c_type_name);
3175 ret->declarator = declarator;
3179 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3182 assignment-expression
3183 { initializer-list }
3184 { initializer-list , }
3187 designation[opt] initializer
3188 initializer-list , designation[opt] initializer
3195 designator-list designator
3202 [ constant-expression ]
3214 [ constant-expression ... constant-expression ]
3216 Any expression without commas is accepted in the syntax for the
3217 constant-expressions, with non-constant expressions rejected later.
3219 This function is only used for top-level initializers; for nested
3220 ones, see c_parser_initval. */
3222 static struct c_expr
3223 c_parser_initializer (c_parser *parser)
3225 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3226 return c_parser_braced_init (parser, NULL_TREE, false);
3230 ret = c_parser_expr_no_commas (parser, NULL);
3231 if (TREE_CODE (ret.value) != STRING_CST
3232 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3233 ret = default_function_array_conversion (ret);
3238 /* Parse a braced initializer list. TYPE is the type specified for a
3239 compound literal, and NULL_TREE for other initializers and for
3240 nested braced lists. NESTED_P is true for nested braced lists,
3241 false for the list of a compound literal or the list that is the
3242 top-level initializer in a declaration. */
3244 static struct c_expr
3245 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3247 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3248 c_parser_consume_token (parser);
3250 push_init_level (0);
3252 really_start_incremental_init (type);
3253 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3256 pedwarn ("ISO C forbids empty initializer braces");
3260 /* Parse a non-empty initializer list, possibly with a trailing
3264 c_parser_initelt (parser);
3267 if (c_parser_next_token_is (parser, CPP_COMMA))
3268 c_parser_consume_token (parser);
3271 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3275 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3278 ret.value = error_mark_node;
3279 ret.original_code = ERROR_MARK;
3280 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3283 c_parser_consume_token (parser);
3284 return pop_init_level (0);
3287 /* Parse a nested initializer, including designators. */
3290 c_parser_initelt (c_parser *parser)
3292 /* Parse any designator or designator list. A single array
3293 designator may have the subsequent "=" omitted in GNU C, but a
3294 longer list or a structure member designator may not. */
3295 if (c_parser_next_token_is (parser, CPP_NAME)
3296 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3298 /* Old-style structure member designator. */
3299 set_init_label (c_parser_peek_token (parser)->value);
3301 pedwarn ("obsolete use of designated initializer with %<:%>");
3302 c_parser_consume_token (parser);
3303 c_parser_consume_token (parser);
3307 /* des_seen is 0 if there have been no designators, 1 if there
3308 has been a single array designator and 2 otherwise. */
3310 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3311 || c_parser_next_token_is (parser, CPP_DOT))
3313 int des_prev = des_seen;
3316 if (c_parser_next_token_is (parser, CPP_DOT))
3319 c_parser_consume_token (parser);
3320 if (c_parser_next_token_is (parser, CPP_NAME))
3322 set_init_label (c_parser_peek_token (parser)->value);
3323 c_parser_consume_token (parser);
3328 init.value = error_mark_node;
3329 init.original_code = ERROR_MARK;
3330 c_parser_error (parser, "expected identifier");
3331 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3332 process_init_element (init);
3339 /* ??? Following the old parser, [ objc-receiver
3340 objc-message-args ] is accepted as an initializer,
3341 being distinguished from a designator by what follows
3342 the first assignment expression inside the square
3343 brackets, but after a first array designator a
3344 subsequent square bracket is for Objective-C taken to
3345 start an expression, using the obsolete form of
3346 designated initializer without '=', rather than
3347 possibly being a second level of designation: in LALR
3348 terms, the '[' is shifted rather than reducing
3349 designator to designator-list. */
3350 if (des_prev == 1 && c_dialect_objc ())
3352 des_seen = des_prev;
3355 if (des_prev == 0 && c_dialect_objc ())
3357 /* This might be an array designator or an
3358 Objective-C message expression. If the former,
3359 continue parsing here; if the latter, parse the
3360 remainder of the initializer given the starting
3361 primary-expression. ??? It might make sense to
3362 distinguish when des_prev == 1 as well; see
3363 previous comment. */
3365 struct c_expr mexpr;
3366 c_parser_consume_token (parser);
3367 if (c_parser_peek_token (parser)->type == CPP_NAME
3368 && ((c_parser_peek_token (parser)->id_kind
3370 || (c_parser_peek_token (parser)->id_kind
3371 == C_ID_CLASSNAME)))
3373 /* Type name receiver. */
3374 tree id = c_parser_peek_token (parser)->value;
3375 c_parser_consume_token (parser);
3376 rec = objc_get_class_reference (id);
3377 goto parse_message_args;
3379 first = c_parser_expr_no_commas (parser, NULL).value;
3380 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3381 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3382 goto array_desig_after_first;
3383 /* Expression receiver. So far only one part
3384 without commas has been parsed; there might be
3385 more of the expression. */
3387 while (c_parser_next_token_is (parser, CPP_COMMA))
3390 c_parser_consume_token (parser);
3391 next = c_parser_expr_no_commas (parser, NULL);
3392 next = default_function_array_conversion (next);
3393 rec = build_compound_expr (rec, next.value);
3396 /* Now parse the objc-message-args. */
3397 args = c_parser_objc_message_args (parser);
3398 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3401 = objc_build_message_expr (build_tree_list (rec, args));
3402 mexpr.original_code = ERROR_MARK;
3403 /* Now parse and process the remainder of the
3404 initializer, starting with this message
3405 expression as a primary-expression. */
3406 c_parser_initval (parser, &mexpr);
3409 c_parser_consume_token (parser);
3410 first = c_parser_expr_no_commas (parser, NULL).value;
3411 array_desig_after_first:
3412 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3414 c_parser_consume_token (parser);
3415 second = c_parser_expr_no_commas (parser, NULL).value;
3419 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3421 c_parser_consume_token (parser);
3422 set_init_index (first, second);
3423 if (pedantic && second)
3424 pedwarn ("ISO C forbids specifying range of "
3425 "elements to initialize");
3428 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3434 if (c_parser_next_token_is (parser, CPP_EQ))
3436 if (pedantic && !flag_isoc99)
3437 pedwarn ("ISO C90 forbids specifying subobject to initialize");
3438 c_parser_consume_token (parser);
3445 pedwarn ("obsolete use of designated initializer "
3451 init.value = error_mark_node;
3452 init.original_code = ERROR_MARK;
3453 c_parser_error (parser, "expected %<=%>");
3454 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3455 process_init_element (init);
3461 c_parser_initval (parser, NULL);
3464 /* Parse a nested initializer; as c_parser_initializer but parses
3465 initializers within braced lists, after any designators have been
3466 applied. If AFTER is not NULL then it is an Objective-C message
3467 expression which is the primary-expression starting the
3471 c_parser_initval (c_parser *parser, struct c_expr *after)
3474 gcc_assert (!after || c_dialect_objc ());
3475 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3476 init = c_parser_braced_init (parser, NULL_TREE, true);
3479 init = c_parser_expr_no_commas (parser, after);
3480 if (init.value != NULL_TREE
3481 && TREE_CODE (init.value) != STRING_CST
3482 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3483 init = default_function_array_conversion (init);
3485 process_init_element (init);
3488 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3492 { block-item-list[opt] }
3493 { label-declarations block-item-list }
3497 block-item-list block-item
3509 { label-declarations block-item-list }
3512 __extension__ nested-declaration
3513 nested-function-definition
3517 label-declarations label-declaration
3520 __label__ identifier-list ;
3522 Allowing the mixing of declarations and code is new in C99. The
3523 GNU syntax also permits (not shown above) labels at the end of
3524 compound statements, which yield an error. We don't allow labels
3525 on declarations; this might seem like a natural extension, but
3526 there would be a conflict between attributes on the label and
3527 prefix attributes on the declaration. ??? The syntax follows the
3528 old parser in requiring something after label declarations.
3529 Although they are erroneous if the labels declared aren't defined,
3530 is it useful for the syntax to be this way?
3542 c_parser_compound_statement (c_parser *parser)
3545 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3546 return error_mark_node;
3547 stmt = c_begin_compound_stmt (true);
3548 c_parser_compound_statement_nostart (parser);
3549 return c_end_compound_stmt (stmt, true);
3552 /* Parse a compound statement except for the opening brace. This is
3553 used for parsing both compound statements and statement expressions
3554 (which follow different paths to handling the opening). */
3557 c_parser_compound_statement_nostart (c_parser *parser)
3559 bool last_stmt = false;
3560 bool last_label = false;
3561 /* APPLE LOCAL radar 5732232 - blocks (not in C++) */
3562 bool first_stmt = true;
3563 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3565 c_parser_consume_token (parser);
3568 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3570 /* Read zero or more forward-declarations for labels that nested
3571 functions can jump to. */
3572 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3574 c_parser_consume_token (parser);
3575 /* Any identifiers, including those declared as type names,
3580 if (c_parser_next_token_is_not (parser, CPP_NAME))
3582 c_parser_error (parser, "expected identifier");
3586 = declare_label (c_parser_peek_token (parser)->value);
3587 C_DECLARED_LABEL_FLAG (label) = 1;
3588 add_stmt (build_stmt (DECL_EXPR, label));
3589 c_parser_consume_token (parser);
3590 if (c_parser_next_token_is (parser, CPP_COMMA))
3591 c_parser_consume_token (parser);
3595 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3597 /* ??? Locating this diagnostic on the token after the
3598 declarations end follows the old parser, but it might be
3599 better to locate it where the declarations start instead. */
3601 pedwarn ("ISO C forbids label declarations");
3603 /* We must now have at least one statement, label or declaration. */
3604 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3606 c_parser_error (parser, "expected declaration or statement");
3607 c_parser_consume_token (parser);
3610 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3612 location_t loc = c_parser_peek_token (parser)->location;
3613 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3614 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3615 || (c_parser_next_token_is (parser, CPP_NAME)
3616 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3620 c_parser_label (parser);
3622 else if (!last_label
3623 && c_parser_next_token_starts_declspecs (parser))
3626 /* APPLE LOCAL radar 4708210 (for_objc_collection in 4.2) */
3627 c_parser_declaration_or_fndef (parser, true, true, true, true, NULL);
3629 && ((pedantic && !flag_isoc99)
3630 || warn_declaration_after_statement))
3631 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3635 else if (!last_label
3636 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3638 /* __extension__ can start a declaration, but is also an
3639 unary operator that can start an expression. Consume all
3640 but the last of a possible series of __extension__ to
3642 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3643 && (c_parser_peek_2nd_token (parser)->keyword
3645 c_parser_consume_token (parser);
3646 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3649 ext = disable_extension_diagnostics ();
3650 c_parser_consume_token (parser);
3652 /* APPLE LOCAL radar 4708210 (for_objc_collection in 4.2) */
3653 c_parser_declaration_or_fndef (parser, true, true, true, true, NULL);
3654 /* Following the old parser, __extension__ does not
3655 disable this diagnostic. */
3656 restore_extension_diagnostics (ext);
3658 && ((pedantic && !flag_isoc99)
3659 || warn_declaration_after_statement))
3660 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3667 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3669 /* External pragmas, and some omp pragmas, are not associated
3670 with regular c code, and so are not to be considered statements
3671 syntactically. This ensures that the user doesn't put them
3672 places that would turn into syntax errors if the directive
3674 if (c_parser_pragma (parser, pragma_compound))
3675 last_label = false, last_stmt = true;
3677 else if (c_parser_next_token_is (parser, CPP_EOF))
3679 c_parser_error (parser, "expected declaration or statement");
3687 c_parser_statement_after_labels (parser);
3690 parser->error = false;
3691 /* APPLE LOCAL radar 5732232 - blocks (not in C++) */
3695 error ("label at end of compound statement");
3696 c_parser_consume_token (parser);
3699 /* Parse a label (C90 6.6.1, C99 6.8.1).
3702 identifier : attributes[opt]
3703 case constant-expression :
3709 case constant-expression ... constant-expression :
3711 The use of attributes on labels is a GNU extension. The syntax in
3712 GNU C accepts any expressions without commas, non-constant
3713 expressions being rejected later. */
3716 c_parser_label (c_parser *parser)
3718 location_t loc1 = c_parser_peek_token (parser)->location;
3719 tree label = NULL_TREE;
3720 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3723 c_parser_consume_token (parser);
3724 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3725 if (c_parser_next_token_is (parser, CPP_COLON))
3727 c_parser_consume_token (parser);
3728 label = do_case (exp1, NULL_TREE);
3730 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3732 c_parser_consume_token (parser);
3733 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3734 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3735 label = do_case (exp1, exp2);
3738 c_parser_error (parser, "expected %<:%> or %<...%>");
3740 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3742 c_parser_consume_token (parser);
3743 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3744 label = do_case (NULL_TREE, NULL_TREE);
3748 tree name = c_parser_peek_token (parser)->value;
3752 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3753 c_parser_consume_token (parser);
3754 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3755 loc2 = c_parser_peek_token (parser)->location;
3756 c_parser_consume_token (parser);
3757 attrs = c_parser_attributes (parser);
3758 tlab = define_label (loc2, name);
3761 decl_attributes (&tlab, attrs, 0);
3762 label = add_stmt (build_stmt (LABEL_EXPR, tlab));
3766 SET_EXPR_LOCATION (label, loc1);
3769 /* Parse a statement (C90 6.6, C99 6.8).
3774 expression-statement
3782 expression-statement:
3785 selection-statement:
3789 iteration-statement:
3798 return expression[opt] ;
3811 objc-throw-statement
3812 objc-try-catch-statement
3813 objc-synchronized-statement
3815 objc-throw-statement:
3829 parallel-for-construct
3830 parallel-sections-construct
3837 parallel-directive structured-block
3840 for-directive iteration-statement
3843 sections-directive section-scope
3846 single-directive structured-block
3848 parallel-for-construct:
3849 parallel-for-directive iteration-statement
3851 parallel-sections-construct:
3852 parallel-sections-directive section-scope
3855 master-directive structured-block
3858 critical-directive structured-block
3861 atomic-directive expression-statement
3864 ordered-directive structured-block */
3867 c_parser_statement (c_parser *parser)
3869 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3870 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3871 || (c_parser_next_token_is (parser, CPP_NAME)
3872 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3873 c_parser_label (parser);
3874 c_parser_statement_after_labels (parser);
3877 /* Parse a statement, other than a labeled statement. */
3880 c_parser_statement_after_labels (c_parser *parser)
3882 location_t loc = c_parser_peek_token (parser)->location;
3883 tree stmt = NULL_TREE;
3884 switch (c_parser_peek_token (parser)->type)
3886 case CPP_OPEN_BRACE:
3887 add_stmt (c_parser_compound_statement (parser));
3890 switch (c_parser_peek_token (parser)->keyword)
3893 c_parser_if_statement (parser);
3896 c_parser_switch_statement (parser);
3899 c_parser_while_statement (parser);
3902 c_parser_do_statement (parser);
3905 c_parser_for_statement (parser);
3908 /* APPLE LOCAL begin radar 5732232 - blocks (C++ cb) */
3910 error ("goto not allowed in block literal");
3911 /* APPLE LOCAL end radar 5732232 - blocks (C++ cb) */
3912 c_parser_consume_token (parser);
3913 if (c_parser_next_token_is (parser, CPP_NAME))
3915 stmt = c_finish_goto_label (c_parser_peek_token (parser)->value);
3916 c_parser_consume_token (parser);
3918 else if (c_parser_next_token_is (parser, CPP_MULT))
3920 c_parser_consume_token (parser);
3921 stmt = c_finish_goto_ptr (c_parser_expression (parser).value);
3924 c_parser_error (parser, "expected identifier or %<*%>");
3925 goto expect_semicolon;
3927 c_parser_consume_token (parser);
3928 stmt = c_finish_bc_stmt (&c_cont_label, false);
3929 goto expect_semicolon;
3931 c_parser_consume_token (parser);
3932 stmt = c_finish_bc_stmt (&c_break_label, true);
3933 goto expect_semicolon;
3935 c_parser_consume_token (parser);
3936 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3938 stmt = c_finish_return (NULL_TREE);
3939 c_parser_consume_token (parser);
3943 stmt = c_finish_return (c_parser_expression_conv (parser).value);
3944 goto expect_semicolon;
3948 stmt = c_parser_asm_statement (parser);
3951 gcc_assert (c_dialect_objc ());
3952 c_parser_consume_token (parser);
3953 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3955 stmt = objc_build_throw_stmt (NULL_TREE);
3956 c_parser_consume_token (parser);
3961 = objc_build_throw_stmt (c_parser_expression (parser).value);
3962 goto expect_semicolon;
3966 gcc_assert (c_dialect_objc ());
3967 c_parser_objc_try_catch_statement (parser);
3969 case RID_AT_SYNCHRONIZED:
3970 gcc_assert (c_dialect_objc ());
3971 c_parser_objc_synchronized_statement (parser);
3978 c_parser_consume_token (parser);
3980 case CPP_CLOSE_PAREN:
3981 case CPP_CLOSE_SQUARE:
3982 /* Avoid infinite loop in error recovery:
3983 c_parser_skip_until_found stops at a closing nesting
3984 delimiter without consuming it, but here we need to consume
3985 it to proceed further. */
3986 c_parser_error (parser, "expected statement");
3987 c_parser_consume_token (parser);
3990 c_parser_pragma (parser, pragma_stmt);
3994 stmt = c_finish_expr_stmt (c_parser_expression_conv (parser).value);
3996 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3999 /* Two cases cannot and do not have line numbers associated: If stmt
4000 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4001 cannot hold line numbers. But that's OK because the statement
4002 will either be changed to a MODIFY_EXPR during gimplification of
4003 the statement expr, or discarded. If stmt was compound, but
4004 without new variables, we will have skipped the creation of a
4005 BIND and will have a bare STATEMENT_LIST. But that's OK because
4006 (recursively) all of the component statements should already have
4007 line numbers assigned. ??? Can we discard no-op statements
4009 /* APPLE LOCAL begin Radar 6144634 */
4010 /* Normal expr stmts, including modify exprs, get the location where
4011 the statement began, i.e. 'loc'. Assignments of Blocks to Block
4012 pointer variables get the location of the end of the Block definition,
4013 i.e. 'input_location', which should already be set by this point. */
4014 if (stmt && EXPR_P (stmt))
4016 if (TREE_CODE (stmt) == MODIFY_EXPR
4017 && TREE_CODE (TREE_TYPE (TREE_OPERAND (stmt, 0))) == BLOCK_POINTER_TYPE)
4018 SET_EXPR_LOCATION (stmt, input_location);
4020 SET_EXPR_LOCATION (stmt, loc);
4022 /* APPLE LOCAL end Radar 6144634 */
4025 /* Parse a parenthesized condition from an if, do or while statement.
4031 c_parser_paren_condition (c_parser *parser)
4035 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4036 return error_mark_node;
4037 loc = c_parser_peek_token (parser)->location;
4038 cond = c_objc_common_truthvalue_conversion
4039 (c_parser_expression_conv (parser).value);
4041 SET_EXPR_LOCATION (cond, loc);
4042 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4046 /* Parse a statement which is a block in C99. */
4049 c_parser_c99_block_statement (c_parser *parser)
4051 tree block = c_begin_compound_stmt (flag_isoc99);
4052 c_parser_statement (parser);
4053 return c_end_compound_stmt (block, flag_isoc99);
4056 /* Parse the body of an if statement or the else half thereof. This
4057 is just parsing a statement but (a) it is a block in C99, (b) we
4058 track whether the body is an if statement for the sake of
4059 -Wparentheses warnings, (c) we handle an empty body specially for
4060 the sake of -Wextra warnings. */
4063 c_parser_if_body (c_parser *parser, bool *if_p)
4065 tree block = c_begin_compound_stmt (flag_isoc99);
4066 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4067 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4068 || (c_parser_next_token_is (parser, CPP_NAME)
4069 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4070 c_parser_label (parser);
4071 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
4072 if (extra_warnings && c_parser_next_token_is (parser, CPP_SEMICOLON))
4073 add_stmt (build_empty_stmt ());
4074 c_parser_statement_after_labels (parser);
4075 return c_end_compound_stmt (block, flag_isoc99);
4078 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4081 if ( expression ) statement
4082 if ( expression ) statement else statement
4086 c_parser_if_statement (c_parser *parser)
4091 bool first_if = false, second_if = false;
4092 tree first_body, second_body;
4093 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
4094 c_parser_consume_token (parser);
4095 block = c_begin_compound_stmt (flag_isoc99);
4096 loc = c_parser_peek_token (parser)->location;
4097 cond = c_parser_paren_condition (parser);
4098 first_body = c_parser_if_body (parser, &first_if);
4099 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4101 c_parser_consume_token (parser);
4102 second_body = c_parser_if_body (parser, &second_if);
4105 second_body = NULL_TREE;
4106 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
4107 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4110 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4113 switch (expression) statement
4117 c_parser_switch_statement (c_parser *parser)
4119 tree block, expr, body, save_break;
4120 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
4121 c_parser_consume_token (parser);
4122 block = c_begin_compound_stmt (flag_isoc99);
4123 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4125 expr = c_parser_expression (parser).value;
4126 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4129 expr = error_mark_node;
4130 c_start_case (expr);
4131 save_break = c_break_label;
4132 c_break_label = NULL_TREE;
4133 body = c_parser_c99_block_statement (parser);
4134 c_finish_case (body);
4136 add_stmt (build1 (LABEL_EXPR, void_type_node, c_break_label));
4137 c_break_label = save_break;
4138 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4141 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4144 APPLE LOCAL begin for-fsf-4_4 3274130 5295549
4145 while attributes (expression) statement
4147 The use of attributes is a GNU extension.
4148 APPLE LOCAL end for-fsf-4_4 3274130 5295549
4152 c_parser_while_statement (c_parser *parser)
4154 /* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
4155 tree block, cond, body, save_break, save_cont, attrs;
4156 /* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
4158 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4159 c_parser_consume_token (parser);
4160 /* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
4161 attrs = c_parser_attributes (parser);
4162 /* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
4163 block = c_begin_compound_stmt (flag_isoc99);
4164 loc = c_parser_peek_token (parser)->location;
4165 cond = c_parser_paren_condition (parser);
4166 save_break = c_break_label;
4167 c_break_label = NULL_TREE;
4168 save_cont = c_cont_label;
4169 c_cont_label = NULL_TREE;
4170 body = c_parser_c99_block_statement (parser);
4171 /* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
4172 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, attrs,
4174 /* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
4175 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4176 c_break_label = save_break;
4177 c_cont_label = save_cont;
4180 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4183 APPLE LOCAL begin for-fsf-4_4 3274130 5295549
4184 do attributes statement while ( expression ) ;
4186 The use of attributes is a GNU extension.
4187 APPLE LOCAL end for-fsf-4_4 3274130 5295549
4191 c_parser_do_statement (c_parser *parser)
4193 /* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
4194 tree block, cond, body, save_break, save_cont, new_break, new_cont, attrs;
4195 /* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
4197 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4198 c_parser_consume_token (parser);
4199 /* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
4200 attrs = c_parser_attributes (parser);
4201 /* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
4202 block = c_begin_compound_stmt (flag_isoc99);
4203 loc = c_parser_peek_token (parser)->location;
4204 save_break = c_break_label;
4205 c_break_label = NULL_TREE;
4206 save_cont = c_cont_label;
4207 c_cont_label = NULL_TREE;
4208 body = c_parser_c99_block_statement (parser);
4209 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4210 new_break = c_break_label;
4211 c_break_label = save_break;
4212 new_cont = c_cont_label;
4213 c_cont_label = save_cont;
4214 cond = c_parser_paren_condition (parser);
4215 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4216 c_parser_skip_to_end_of_block_or_statement (parser);
4217 /* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
4218 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, attrs, false);
4219 /* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
4220 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4223 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4226 APPLE LOCAL begin for-fsf-4_4 3274130 5295549
4227 for attributes ( expression[opt] ; expression[opt] ; expression[opt] ) \
4229 for attributes ( nested-declaration expression[opt] ; expression[opt] ) \
4232 The form with a declaration is new in C99.
4234 The use of attributes is a GNU extension.
4236 APPLE LOCAL end for-fsf-4_4 3274130 5295549
4237 ??? In accordance with the old parser, the declaration may be a
4238 nested function, which is then rejected in check_for_loop_decls,
4239 but does it make any sense for this to be included in the grammar?
4240 Note in particular that the nested function does not include a
4241 trailing ';', whereas the "declaration" production includes one.
4242 Also, can we reject bad declarations earlier and cheaper than
4243 check_for_loop_decls? */
4246 c_parser_for_statement (c_parser *parser)
4248 /* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
4249 tree block, cond, incr, save_break, save_cont, body, attrs;
4250 /* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
4252 /* APPLE LOCAL radar 4708210 (for_objc_collection in 4.2) */
4253 bool foreach_p = false;
4254 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4255 loc = c_parser_peek_token (parser)->location;
4256 c_parser_consume_token (parser);
4257 /* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
4258 attrs = c_parser_attributes (parser);
4259 /* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
4260 block = c_begin_compound_stmt (flag_isoc99);
4261 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4263 /* Parse the initialization declaration or expression. */
4264 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4266 c_parser_consume_token (parser);
4267 c_finish_expr_stmt (NULL_TREE);
4269 else if (c_parser_next_token_starts_declspecs (parser))
4271 /* APPLE LOCAL begin radar 4708210 (for_objc_collection in 4.2) */
4273 c_parser_declaration_or_fndef (parser, true, true, true, true, &cond);
4274 /* APPLE LOCAL radar 5925639 */
4275 if (c_parser_next_token_is_keyword (parser, RID_IN) && cond)
4277 cond = finish_parse_foreach_header (parser, cond);
4281 check_for_loop_decls ();
4282 /* APPLE LOCAL end radar 4708210 (for_objc_collection in 4.2) */
4284 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4286 /* __extension__ can start a declaration, but is also an
4287 unary operator that can start an expression. Consume all
4288 but the last of a possible series of __extension__ to
4290 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4291 && (c_parser_peek_2nd_token (parser)->keyword
4293 c_parser_consume_token (parser);
4294 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
4297 ext = disable_extension_diagnostics ();
4298 c_parser_consume_token (parser);
4299 /* APPLE LOCAL begin radar 4708210 (for_objc_collection in 4.2) */
4301 c_parser_declaration_or_fndef (parser, true, true, true, true, &cond);
4302 restore_extension_diagnostics (ext);
4303 /* APPLE LOCAL radar 5925639 */
4304 if (c_parser_next_token_is_keyword (parser, RID_IN) && cond)
4306 cond = finish_parse_foreach_header (parser, cond);
4310 check_for_loop_decls ();
4311 /* APPLE LOCAL end radar 4708210 (for_objc_collection in 4.2) */
4319 /* APPLE LOCAL begin radar 4708210 (for_objc_collection in 4.2) */
4320 cond = c_parser_expression (parser).value;
4321 if (c_parser_next_token_is_keyword (parser, RID_IN))
4323 c_parser_consume_token (parser); /* IN */
4324 cond = build_tree_list (cond, c_parser_initializer (parser).value);
4329 c_finish_expr_stmt (cond);
4330 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4333 objc_foreach_context = 0;
4334 /* APPLE LOCAL end radar 4708210 (for_objc_collection in 4.2) */
4335 /* Parse the loop condition. */
4336 loc = c_parser_peek_token (parser)->location;
4337 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4339 c_parser_consume_token (parser);
4342 /* APPLE LOCAL begin radar 4708210 (for_objc_collection in 4.2) */
4345 /* APPLE LOCAL end radar 4708210 (for_objc_collection in 4.2) */
4348 tree ocond = c_parser_expression_conv (parser).value;
4349 cond = c_objc_common_truthvalue_conversion (ocond);
4351 SET_EXPR_LOCATION (cond, loc);
4352 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4354 /* Parse the increment expression. */
4355 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4356 incr = c_process_expr_stmt (NULL_TREE);
4358 incr = c_process_expr_stmt (c_parser_expression (parser).value);
4359 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4363 cond = error_mark_node;
4364 incr = error_mark_node;
4366 save_break = c_break_label;
4367 c_break_label = NULL_TREE;
4368 save_cont = c_cont_label;
4369 c_cont_label = NULL_TREE;
4370 body = c_parser_c99_block_statement (parser);
4371 /* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
4372 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, attrs,
4374 /* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
4375 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4376 c_break_label = save_break;
4377 c_cont_label = save_cont;
4380 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4381 statement with inputs, outputs, clobbers, and volatile tag
4385 asm type-qualifier[opt] ( asm-argument ) ;
4389 asm-string-literal : asm-operands[opt]
4390 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4391 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4393 Qualifiers other than volatile are accepted in the syntax but
4397 c_parser_asm_statement (c_parser *parser)
4399 tree quals, str, outputs, inputs, clobbers, ret;
4401 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4402 c_parser_consume_token (parser);
4403 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4405 quals = c_parser_peek_token (parser)->value;
4406 c_parser_consume_token (parser);
4408 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4409 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4411 warning (0, "%E qualifier ignored on asm",
4412 c_parser_peek_token (parser)->value);
4414 c_parser_consume_token (parser);
4418 /* ??? Follow the C++ parser rather than using the
4419 c_lex_string_translate kludge. */
4420 c_lex_string_translate = 0;
4421 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4423 c_lex_string_translate = 1;
4426 str = c_parser_asm_string_literal (parser);
4427 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4430 outputs = NULL_TREE;
4432 clobbers = NULL_TREE;
4435 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4437 c_lex_string_translate = 1;
4438 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4442 /* Parse outputs. */
4443 if (c_parser_next_token_is (parser, CPP_COLON)
4444 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4445 outputs = NULL_TREE;
4447 outputs = c_parser_asm_operands (parser, false);
4448 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4451 clobbers = NULL_TREE;
4454 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4456 c_lex_string_translate = 1;
4457 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4461 if (c_parser_next_token_is (parser, CPP_COLON)
4462 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4465 inputs = c_parser_asm_operands (parser, true);
4466 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4468 clobbers = NULL_TREE;
4471 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4473 c_lex_string_translate = 1;
4474 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4477 /* Parse clobbers. */
4478 clobbers = c_parser_asm_clobbers (parser);
4480 c_lex_string_translate = 1;
4481 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4483 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4486 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4487 c_parser_skip_to_end_of_block_or_statement (parser);
4488 ret = build_asm_stmt (quals, build_asm_expr (str, outputs, inputs,
4493 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4494 not outputs), apply the default conversion of functions and arrays
4499 asm-operands , asm-operand
4502 asm-string-literal ( expression )
4503 [ identifier ] asm-string-literal ( expression )
4507 c_parser_asm_operands (c_parser *parser, bool convert_p)
4509 tree list = NULL_TREE;
4514 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4516 c_parser_consume_token (parser);
4517 if (c_parser_next_token_is (parser, CPP_NAME))
4519 tree id = c_parser_peek_token (parser)->value;
4520 c_parser_consume_token (parser);
4521 name = build_string (IDENTIFIER_LENGTH (id),
4522 IDENTIFIER_POINTER (id));
4526 c_parser_error (parser, "expected identifier");
4527 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4530 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4535 str = c_parser_asm_string_literal (parser);
4536 if (str == NULL_TREE)
4538 c_lex_string_translate = 1;
4539 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4541 c_lex_string_translate = 0;
4544 expr = c_parser_expression (parser);
4546 expr = default_function_array_conversion (expr);
4547 c_lex_string_translate = 0;
4548 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4550 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4553 list = chainon (list, build_tree_list (build_tree_list (name, str),
4555 if (c_parser_next_token_is (parser, CPP_COMMA))
4556 c_parser_consume_token (parser);
4563 /* Parse asm clobbers, a GNU extension.
4567 asm-clobbers , asm-string-literal
4571 c_parser_asm_clobbers (c_parser *parser)
4573 tree list = NULL_TREE;
4576 tree str = c_parser_asm_string_literal (parser);
4578 list = tree_cons (NULL_TREE, str, list);
4581 if (c_parser_next_token_is (parser, CPP_COMMA))
4582 c_parser_consume_token (parser);
4589 /* Parse an expression other than a compound expression; that is, an
4590 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4591 NULL then it is an Objective-C message expression which is the
4592 primary-expression starting the expression as an initializer.
4594 assignment-expression:
4595 conditional-expression
4596 unary-expression assignment-operator assignment-expression
4598 assignment-operator: one of
4599 = *= /= %= += -= <<= >>= &= ^= |=
4601 In GNU C we accept any conditional expression on the LHS and
4602 diagnose the invalid lvalue rather than producing a syntax
4605 static struct c_expr
4606 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4608 struct c_expr lhs, rhs, ret;
4609 enum tree_code code;
4610 gcc_assert (!after || c_dialect_objc ());
4611 lhs = c_parser_conditional_expression (parser, after);
4612 switch (c_parser_peek_token (parser)->type)
4621 code = TRUNC_DIV_EXPR;
4624 code = TRUNC_MOD_EXPR;
4639 code = BIT_AND_EXPR;
4642 code = BIT_XOR_EXPR;
4645 code = BIT_IOR_EXPR;
4650 c_parser_consume_token (parser);
4651 rhs = c_parser_expr_no_commas (parser, NULL);
4652 rhs = default_function_array_conversion (rhs);
4653 ret.value = build_modify_expr (lhs.value, code, rhs.value);
4654 if (code == NOP_EXPR)
4655 ret.original_code = MODIFY_EXPR;
4658 TREE_NO_WARNING (ret.value) = 1;
4659 ret.original_code = ERROR_MARK;
4664 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4665 is not NULL then it is an Objective-C message expression which is
4666 the primary-expression starting the expression as an initializer.
4668 conditional-expression:
4669 logical-OR-expression
4670 logical-OR-expression ? expression : conditional-expression
4674 conditional-expression:
4675 logical-OR-expression ? : conditional-expression
4678 static struct c_expr
4679 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4681 struct c_expr cond, exp1, exp2, ret;
4682 gcc_assert (!after || c_dialect_objc ());
4683 cond = c_parser_binary_expression (parser, after);
4684 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4686 cond = default_function_array_conversion (cond);
4687 c_parser_consume_token (parser);
4688 if (c_parser_next_token_is (parser, CPP_COLON))
4691 pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
4692 /* Make sure first operand is calculated only once. */
4693 exp1.value = save_expr (default_conversion (cond.value));
4694 cond.value = c_objc_common_truthvalue_conversion (exp1.value);
4695 skip_evaluation += cond.value == truthvalue_true_node;
4700 = c_objc_common_truthvalue_conversion
4701 (default_conversion (cond.value));
4702 skip_evaluation += cond.value == truthvalue_false_node;
4703 exp1 = c_parser_expression_conv (parser);
4704 skip_evaluation += ((cond.value == truthvalue_true_node)
4705 - (cond.value == truthvalue_false_node));
4707 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4709 skip_evaluation -= cond.value == truthvalue_true_node;
4710 ret.value = error_mark_node;
4711 ret.original_code = ERROR_MARK;
4714 exp2 = c_parser_conditional_expression (parser, NULL);
4715 exp2 = default_function_array_conversion (exp2);
4716 skip_evaluation -= cond.value == truthvalue_true_node;
4717 ret.value = build_conditional_expr (cond.value, exp1.value, exp2.value);
4718 ret.original_code = ERROR_MARK;
4722 /* Parse a binary expression; that is, a logical-OR-expression (C90
4723 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4724 an Objective-C message expression which is the primary-expression
4725 starting the expression as an initializer.
4727 multiplicative-expression:
4729 multiplicative-expression * cast-expression
4730 multiplicative-expression / cast-expression
4731 multiplicative-expression % cast-expression
4733 additive-expression:
4734 multiplicative-expression
4735 additive-expression + multiplicative-expression
4736 additive-expression - multiplicative-expression
4740 shift-expression << additive-expression
4741 shift-expression >> additive-expression
4743 relational-expression:
4745 relational-expression < shift-expression
4746 relational-expression > shift-expression
4747 relational-expression <= shift-expression
4748 relational-expression >= shift-expression
4750 equality-expression:
4751 relational-expression
4752 equality-expression == relational-expression
4753 equality-expression != relational-expression
4757 AND-expression & equality-expression
4759 exclusive-OR-expression:
4761 exclusive-OR-expression ^ AND-expression
4763 inclusive-OR-expression:
4764 exclusive-OR-expression
4765 inclusive-OR-expression | exclusive-OR-expression
4767 logical-AND-expression:
4768 inclusive-OR-expression
4769 logical-AND-expression && inclusive-OR-expression
4771 logical-OR-expression:
4772 logical-AND-expression
4773 logical-OR-expression || logical-AND-expression
4776 static struct c_expr
4777 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4779 /* A binary expression is parsed using operator-precedence parsing,
4780 with the operands being cast expressions. All the binary
4781 operators are left-associative. Thus a binary expression is of
4784 E0 op1 E1 op2 E2 ...
4786 which we represent on a stack. On the stack, the precedence
4787 levels are strictly increasing. When a new operator is
4788 encountered of higher precedence than that at the top of the
4789 stack, it is pushed; its LHS is the top expression, and its RHS
4790 is everything parsed until it is popped. When a new operator is
4791 encountered with precedence less than or equal to that at the top
4792 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4793 by the result of the operation until the operator at the top of
4794 the stack has lower precedence than the new operator or there is
4795 only one element on the stack; then the top expression is the LHS
4796 of the new operator. In the case of logical AND and OR
4797 expressions, we also need to adjust skip_evaluation as
4798 appropriate when the operators are pushed and popped. */
4800 /* The precedence levels, where 0 is a dummy lowest level used for
4801 the bottom of the stack. */
4817 /* The expression at this stack level. */
4819 /* The precedence of the operator on its left, PREC_NONE at the
4820 bottom of the stack. */
4822 /* The operation on its left. */
4828 switch (stack[sp].op) \
4830 case TRUTH_ANDIF_EXPR: \
4831 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4833 case TRUTH_ORIF_EXPR: \
4834 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4839 stack[sp - 1].expr \
4840 = default_function_array_conversion (stack[sp - 1].expr); \
4842 = default_function_array_conversion (stack[sp].expr); \
4843 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4844 stack[sp - 1].expr, \
4848 gcc_assert (!after || c_dialect_objc ());
4849 stack[0].expr = c_parser_cast_expression (parser, after);
4850 /* APPLE LOCAL begin radar 4426814 */
4851 if (c_dialect_objc() && flag_objc_gc)
4852 /* APPLE LOCAL radar 5276085 */
4853 stack[0].expr.value = objc_build_weak_reference_tree (stack[0].expr.value);
4854 /* APPLE LOCAL end radar 4426814 */
4855 stack[0].prec = PREC_NONE;
4860 enum tree_code ocode;
4863 switch (c_parser_peek_token (parser)->type)
4871 ocode = TRUNC_DIV_EXPR;
4875 ocode = TRUNC_MOD_EXPR;
4887 ocode = LSHIFT_EXPR;
4891 ocode = RSHIFT_EXPR;
4905 case CPP_GREATER_EQ:
4918 oprec = PREC_BITAND;
4919 ocode = BIT_AND_EXPR;
4922 oprec = PREC_BITXOR;
4923 ocode = BIT_XOR_EXPR;
4927 ocode = BIT_IOR_EXPR;
4930 oprec = PREC_LOGAND;
4931 ocode = TRUTH_ANDIF_EXPR;
4935 ocode = TRUTH_ORIF_EXPR;
4938 /* Not a binary operator, so end of the binary
4942 c_parser_consume_token (parser);
4943 while (oprec <= stack[sp].prec)
4947 case TRUTH_ANDIF_EXPR:
4949 = default_function_array_conversion (stack[sp].expr);
4950 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4951 (default_conversion (stack[sp].expr.value));
4952 skip_evaluation += stack[sp].expr.value == truthvalue_false_node;
4954 case TRUTH_ORIF_EXPR:
4956 = default_function_array_conversion (stack[sp].expr);
4957 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4958 (default_conversion (stack[sp].expr.value));
4959 skip_evaluation += stack[sp].expr.value == truthvalue_true_node;
4965 stack[sp].expr = c_parser_cast_expression (parser, NULL);
4966 /* APPLE LOCAL begin radar 4426814 */
4967 if (c_dialect_objc() && flag_objc_gc)
4968 /* APPLE LOCAL radar 5276085 */
4969 stack[sp].expr.value = objc_build_weak_reference_tree (stack[sp].expr.value);
4970 /* APPLE LOCAL end radar 4426814 */
4971 stack[sp].prec = oprec;
4972 stack[sp].op = ocode;
4977 return stack[0].expr;
4981 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4982 NULL then it is an Objective-C message expression which is the
4983 primary-expression starting the expression as an initializer.
4987 ( type-name ) unary-expression
4990 static struct c_expr
4991 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
4993 gcc_assert (!after || c_dialect_objc ());
4995 return c_parser_postfix_expression_after_primary (parser, *after);
4996 /* If the expression begins with a parenthesized type name, it may
4997 be either a cast or a compound literal; we need to see whether
4998 the next character is '{' to tell the difference. If not, it is
4999 an unary expression. */
5000 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5001 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5003 struct c_type_name *type_name;
5006 c_parser_consume_token (parser);
5007 type_name = c_parser_type_name (parser);
5008 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5009 if (type_name == NULL)
5011 ret.value = error_mark_node;
5012 ret.original_code = ERROR_MARK;
5016 /* Save casted types in the function's used types hash table. */
5017 used_types_insert (type_name->specs->type);
5019 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5020 return c_parser_postfix_expression_after_paren_type (parser,
5022 expr = c_parser_cast_expression (parser, NULL);
5023 expr = default_function_array_conversion (expr);
5024 ret.value = c_cast_expr (type_name, expr.value);
5025 ret.original_code = ERROR_MARK;
5029 return c_parser_unary_expression (parser);
5032 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5038 unary-operator cast-expression
5039 sizeof unary-expression
5040 sizeof ( type-name )
5042 unary-operator: one of
5048 __alignof__ unary-expression
5049 __alignof__ ( type-name )
5052 unary-operator: one of
5053 __extension__ __real__ __imag__
5055 In addition, the GNU syntax treats ++ and -- as unary operators, so
5056 they may be applied to cast expressions with errors for non-lvalues
5059 static struct c_expr
5060 c_parser_unary_expression (c_parser *parser)
5063 struct c_expr ret, op;
5064 switch (c_parser_peek_token (parser)->type)
5067 c_parser_consume_token (parser);
5068 op = c_parser_cast_expression (parser, NULL);
5069 op = default_function_array_conversion (op);
5070 return parser_build_unary_op (PREINCREMENT_EXPR, op);
5071 case CPP_MINUS_MINUS:
5072 c_parser_consume_token (parser);
5073 op = c_parser_cast_expression (parser, NULL);
5074 op = default_function_array_conversion (op);
5075 return parser_build_unary_op (PREDECREMENT_EXPR, op);
5077 c_parser_consume_token (parser);
5078 return parser_build_unary_op (ADDR_EXPR,
5079 c_parser_cast_expression (parser, NULL));
5081 c_parser_consume_token (parser);
5082 op = c_parser_cast_expression (parser, NULL);
5083 op = default_function_array_conversion (op);
5084 ret.value = build_indirect_ref (op.value, "unary *");
5085 ret.original_code = ERROR_MARK;
5088 c_parser_consume_token (parser);
5089 if (!c_dialect_objc () && !in_system_header)
5090 warning (OPT_Wtraditional,
5091 "traditional C rejects the unary plus operator");
5092 op = c_parser_cast_expression (parser, NULL);
5093 op = default_function_array_conversion (op);
5094 return parser_build_unary_op (CONVERT_EXPR, op);
5096 c_parser_consume_token (parser);
5097 op = c_parser_cast_expression (parser, NULL);
5098 op = default_function_array_conversion (op);
5099 return parser_build_unary_op (NEGATE_EXPR, op);
5101 c_parser_consume_token (parser);
5102 op = c_parser_cast_expression (parser, NULL);
5103 op = default_function_array_conversion (op);
5104 return parser_build_unary_op (BIT_NOT_EXPR, op);
5106 c_parser_consume_token (parser);
5107 op = c_parser_cast_expression (parser, NULL);
5108 op = default_function_array_conversion (op);
5109 return parser_build_unary_op (TRUTH_NOT_EXPR, op);
5111 /* Refer to the address of a label as a pointer. */
5112 c_parser_consume_token (parser);
5113 if (c_parser_next_token_is (parser, CPP_NAME))
5115 ret.value = finish_label_address_expr
5116 (c_parser_peek_token (parser)->value);
5117 c_parser_consume_token (parser);
5121 c_parser_error (parser, "expected identifier");
5122 ret.value = error_mark_node;
5124 ret.original_code = ERROR_MARK;
5127 switch (c_parser_peek_token (parser)->keyword)
5130 return c_parser_sizeof_expression (parser);
5132 return c_parser_alignof_expression (parser);
5134 c_parser_consume_token (parser);
5135 ext = disable_extension_diagnostics ();
5136 ret = c_parser_cast_expression (parser, NULL);
5137 restore_extension_diagnostics (ext);
5140 c_parser_consume_token (parser);
5141 op = c_parser_cast_expression (parser, NULL);
5142 op = default_function_array_conversion (op);
5143 return parser_build_unary_op (REALPART_EXPR, op);
5145 c_parser_consume_token (parser);
5146 op = c_parser_cast_expression (parser, NULL);
5147 op = default_function_array_conversion (op);
5148 return parser_build_unary_op (IMAGPART_EXPR, op);
5150 return c_parser_postfix_expression (parser);
5153 return c_parser_postfix_expression (parser);
5157 /* Parse a sizeof expression. */
5159 static struct c_expr
5160 c_parser_sizeof_expression (c_parser *parser)
5163 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
5164 c_parser_consume_token (parser);
5167 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5168 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5170 /* Either sizeof ( type-name ) or sizeof unary-expression
5171 starting with a compound literal. */
5172 struct c_type_name *type_name;
5173 c_parser_consume_token (parser);
5174 type_name = c_parser_type_name (parser);
5175 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5176 if (type_name == NULL)
5181 ret.value = error_mark_node;
5182 ret.original_code = ERROR_MARK;
5185 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5187 expr = c_parser_postfix_expression_after_paren_type (parser,
5191 /* sizeof ( type-name ). */
5194 if (type_name->declarator->kind == cdk_array
5195 && type_name->declarator->u.array.vla_unspec_p)
5198 error ("%<[*]%> not allowed in other than a declaration");
5200 return c_expr_sizeof_type (type_name);
5204 expr = c_parser_unary_expression (parser);
5208 if (TREE_CODE (expr.value) == COMPONENT_REF
5209 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
5210 error ("%<sizeof%> applied to a bit-field");
5211 return c_expr_sizeof_expr (expr);
5215 /* Parse an alignof expression. */
5217 static struct c_expr
5218 c_parser_alignof_expression (c_parser *parser)
5221 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5222 c_parser_consume_token (parser);
5225 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5226 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5228 /* Either __alignof__ ( type-name ) or __alignof__
5229 unary-expression starting with a compound literal. */
5230 struct c_type_name *type_name;
5232 c_parser_consume_token (parser);
5233 type_name = c_parser_type_name (parser);
5234 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5235 if (type_name == NULL)
5240 ret.value = error_mark_node;
5241 ret.original_code = ERROR_MARK;
5244 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5246 expr = c_parser_postfix_expression_after_paren_type (parser,
5250 /* alignof ( type-name ). */
5253 ret.value = c_alignof (groktypename (type_name));
5254 ret.original_code = ERROR_MARK;
5260 expr = c_parser_unary_expression (parser);
5264 ret.value = c_alignof_expr (expr.value);
5265 ret.original_code = ERROR_MARK;
5270 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5274 postfix-expression [ expression ]
5275 postfix-expression ( argument-expression-list[opt] )
5276 postfix-expression . identifier
5277 postfix-expression -> identifier
5278 postfix-expression ++
5279 postfix-expression --
5280 ( type-name ) { initializer-list }
5281 ( type-name ) { initializer-list , }
5283 argument-expression-list:
5285 argument-expression-list , argument-expression
5297 (treated as a keyword in GNU C)
5300 ( compound-statement )
5301 __builtin_va_arg ( assignment-expression , type-name )
5302 __builtin_offsetof ( type-name , offsetof-member-designator )
5303 __builtin_choose_expr ( assignment-expression ,
5304 assignment-expression ,
5305 assignment-expression )
5306 __builtin_types_compatible_p ( type-name , type-name )
5307 APPLE LOCAL blocks (C++ cf)
5310 offsetof-member-designator:
5312 offsetof-member-designator . identifier
5313 offsetof-member-designator [ expression ]
5318 [ objc-receiver objc-message-args ]
5319 @selector ( objc-selector-arg )
5320 @protocol ( identifier )
5321 @encode ( type-name )
5325 static struct c_expr
5326 c_parser_postfix_expression (c_parser *parser)
5328 struct c_expr expr, e1, e2, e3;
5329 struct c_type_name *t1, *t2;
5330 switch (c_parser_peek_token (parser)->type)
5335 expr.value = c_parser_peek_token (parser)->value;
5336 expr.original_code = ERROR_MARK;
5337 c_parser_consume_token (parser);
5341 expr.value = c_parser_peek_token (parser)->value;
5342 expr.original_code = STRING_CST;
5343 c_parser_consume_token (parser);
5345 case CPP_OBJC_STRING:
5346 gcc_assert (c_dialect_objc ());
5348 = objc_build_string_object (c_parser_peek_token (parser)->value);
5349 expr.original_code = ERROR_MARK;
5350 c_parser_consume_token (parser);
5353 /* APPLE LOCAL begin radar 5277239 */
5354 if (c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME
5355 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
5357 /* CLASS.class_method expression. */
5358 tree receiver, component;
5359 receiver = c_parser_objc_receiver (parser);
5360 /* consume '.' operator */
5361 c_parser_consume_token (parser);
5362 component = c_parser_objc_message_args (parser);
5363 expr.value = objc_build_property_reference_expr (receiver, component);
5364 expr.original_code = ERROR_MARK;
5367 /* APPLE LOCAL end radar 5277239 */
5368 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5370 c_parser_error (parser, "expected expression");
5371 expr.value = error_mark_node;
5372 expr.original_code = ERROR_MARK;
5376 tree id = c_parser_peek_token (parser)->value;
5377 location_t loc = c_parser_peek_token (parser)->location;
5378 c_parser_consume_token (parser);
5379 expr.value = build_external_ref (id,
5380 (c_parser_peek_token (parser)->type
5381 == CPP_OPEN_PAREN), loc);
5382 /* APPLE LOCAL begin radar 5732232 - blocks (C++ cd) */
5383 /* If a variabled declared as referenced variable, using |...| syntax,
5384 is used in the block, it has to be derefrenced because this
5385 variable holds address of the outside variable referenced in. */
5387 /* APPLE LOCAL begin radar 5932809 - copyable byref blocks (C++ cd) */
5388 if (TREE_CODE (expr.value) == VAR_DECL)
5390 if (BLOCK_DECL_BYREF (expr.value))
5392 tree orig_decl = expr.value;
5393 expr.value = build_indirect_ref (expr.value, "unary *");
5394 if (COPYABLE_BYREF_LOCAL_VAR (orig_decl)) {
5395 /* What we have is an expression which is of type
5396 struct __Block_byref_X. Must get to the value of the variable
5397 embedded in this structure. It is at:
5398 __Block_byref_X.__forwarding->x */
5399 expr.value = build_byref_local_var_access (expr.value,
5400 DECL_NAME (orig_decl));
5403 else if (COPYABLE_BYREF_LOCAL_VAR (expr.value))
5404 expr.value = build_byref_local_var_access (expr.value,
5405 DECL_NAME (expr.value));
5407 /* APPLE LOCAL end radar 5932809 - copyable byref blocks */
5409 /* APPLE LOCAL end radar 5732232 - blocks (C++ cd) */
5410 expr.original_code = ERROR_MARK;
5413 case CPP_OPEN_PAREN:
5414 /* A parenthesized expression, statement expression or compound
5416 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5418 /* A statement expression. */
5420 c_parser_consume_token (parser);
5421 c_parser_consume_token (parser);
5422 if (cur_stmt_list == NULL)
5424 error ("braced-group within expression allowed "
5425 "only inside a function");
5426 parser->error = true;
5427 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5428 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5429 expr.value = error_mark_node;
5430 expr.original_code = ERROR_MARK;
5433 stmt = c_begin_stmt_expr ();
5434 c_parser_compound_statement_nostart (parser);
5435 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5438 pedwarn ("ISO C forbids braced-groups within expressions");
5439 expr.value = c_finish_stmt_expr (stmt);
5440 expr.original_code = ERROR_MARK;
5442 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5444 /* A compound literal. ??? Can we actually get here rather
5445 than going directly to
5446 c_parser_postfix_expression_after_paren_type from
5448 struct c_type_name *type_name;
5449 c_parser_consume_token (parser);
5450 type_name = c_parser_type_name (parser);
5451 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5453 if (type_name == NULL)
5455 expr.value = error_mark_node;
5456 expr.original_code = ERROR_MARK;
5459 expr = c_parser_postfix_expression_after_paren_type (parser,
5464 /* A parenthesized expression. */
5465 c_parser_consume_token (parser);
5466 expr = c_parser_expression (parser);
5467 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5468 TREE_NO_WARNING (expr.value) = 1;
5469 expr.original_code = ERROR_MARK;
5470 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5475 switch (c_parser_peek_token (parser)->keyword)
5477 case RID_FUNCTION_NAME:
5478 case RID_PRETTY_FUNCTION_NAME:
5479 case RID_C99_FUNCTION_NAME:
5480 expr.value = fname_decl (c_parser_peek_token (parser)->keyword,
5481 c_parser_peek_token (parser)->value);
5482 expr.original_code = ERROR_MARK;
5483 c_parser_consume_token (parser);
5486 c_parser_consume_token (parser);
5487 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5489 expr.value = error_mark_node;
5490 expr.original_code = ERROR_MARK;
5493 e1 = c_parser_expr_no_commas (parser, NULL);
5494 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5496 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5497 expr.value = error_mark_node;
5498 expr.original_code = ERROR_MARK;
5501 t1 = c_parser_type_name (parser);
5502 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5506 expr.value = error_mark_node;
5507 expr.original_code = ERROR_MARK;
5511 expr.value = build_va_arg (e1.value, groktypename (t1));
5512 expr.original_code = ERROR_MARK;
5516 c_parser_consume_token (parser);
5517 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5519 expr.value = error_mark_node;
5520 expr.original_code = ERROR_MARK;
5523 t1 = c_parser_type_name (parser);
5526 expr.value = error_mark_node;
5527 expr.original_code = ERROR_MARK;
5530 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5532 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5533 expr.value = error_mark_node;
5534 expr.original_code = ERROR_MARK;
5538 tree type = groktypename (t1);
5540 if (type == error_mark_node)
5541 offsetof_ref = error_mark_node;
5543 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5544 /* Parse the second argument to __builtin_offsetof. We
5545 must have one identifier, and beyond that we want to
5546 accept sub structure and sub array references. */
5547 if (c_parser_next_token_is (parser, CPP_NAME))
5549 offsetof_ref = build_component_ref
5550 (offsetof_ref, c_parser_peek_token (parser)->value);
5551 c_parser_consume_token (parser);
5552 while (c_parser_next_token_is (parser, CPP_DOT)
5553 || c_parser_next_token_is (parser,
5556 if (c_parser_next_token_is (parser, CPP_DOT))
5558 c_parser_consume_token (parser);
5559 if (c_parser_next_token_is_not (parser,
5562 c_parser_error (parser, "expected identifier");
5565 offsetof_ref = build_component_ref
5567 c_parser_peek_token (parser)->value);
5568 c_parser_consume_token (parser);
5573 c_parser_consume_token (parser);
5574 idx = c_parser_expression (parser).value;
5575 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5577 offsetof_ref = build_array_ref (offsetof_ref, idx);
5582 c_parser_error (parser, "expected identifier");
5583 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5585 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5586 expr.original_code = ERROR_MARK;
5589 case RID_CHOOSE_EXPR:
5590 c_parser_consume_token (parser);
5591 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5593 expr.value = error_mark_node;
5594 expr.original_code = ERROR_MARK;
5597 e1 = c_parser_expr_no_commas (parser, NULL);
5598 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5600 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5601 expr.value = error_mark_node;
5602 expr.original_code = ERROR_MARK;
5605 e2 = c_parser_expr_no_commas (parser, NULL);
5606 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5608 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5609 expr.value = error_mark_node;
5610 expr.original_code = ERROR_MARK;
5613 e3 = c_parser_expr_no_commas (parser, NULL);
5614 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5619 c = fold (e1.value);
5620 if (TREE_CODE (c) != INTEGER_CST)
5621 error ("first argument to %<__builtin_choose_expr%> not"
5623 expr = integer_zerop (c) ? e3 : e2;
5626 case RID_TYPES_COMPATIBLE_P:
5627 c_parser_consume_token (parser);
5628 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5630 expr.value = error_mark_node;
5631 expr.original_code = ERROR_MARK;
5634 t1 = c_parser_type_name (parser);
5637 expr.value = error_mark_node;
5638 expr.original_code = ERROR_MARK;
5641 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5643 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5644 expr.value = error_mark_node;
5645 expr.original_code = ERROR_MARK;
5648 t2 = c_parser_type_name (parser);
5651 expr.value = error_mark_node;
5652 expr.original_code = ERROR_MARK;
5655 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5660 e1 = TYPE_MAIN_VARIANT (groktypename (t1));
5661 e2 = TYPE_MAIN_VARIANT (groktypename (t2));
5663 expr.value = comptypes (e1, e2)
5664 ? build_int_cst (NULL_TREE, 1)
5665 : build_int_cst (NULL_TREE, 0);
5666 expr.original_code = ERROR_MARK;
5669 case RID_AT_SELECTOR:
5670 gcc_assert (c_dialect_objc ());
5671 c_parser_consume_token (parser);
5672 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5674 expr.value = error_mark_node;
5675 expr.original_code = ERROR_MARK;
5679 tree sel = c_parser_objc_selector_arg (parser);
5680 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5682 expr.value = objc_build_selector_expr (sel);
5683 expr.original_code = ERROR_MARK;
5686 case RID_AT_PROTOCOL:
5687 gcc_assert (c_dialect_objc ());
5688 c_parser_consume_token (parser);
5689 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5691 expr.value = error_mark_node;
5692 expr.original_code = ERROR_MARK;
5695 if (c_parser_next_token_is_not (parser, CPP_NAME))
5697 c_parser_error (parser, "expected identifier");
5698 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5699 expr.value = error_mark_node;
5700 expr.original_code = ERROR_MARK;
5704 tree id = c_parser_peek_token (parser)->value;
5705 c_parser_consume_token (parser);
5706 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5708 expr.value = objc_build_protocol_expr (id);
5709 expr.original_code = ERROR_MARK;
5713 /* Extension to support C-structures in the archiver. */
5714 gcc_assert (c_dialect_objc ());
5715 c_parser_consume_token (parser);
5716 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5718 expr.value = error_mark_node;
5719 expr.original_code = ERROR_MARK;
5722 t1 = c_parser_type_name (parser);
5725 expr.value = error_mark_node;
5726 expr.original_code = ERROR_MARK;
5727 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5730 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5733 tree type = groktypename (t1);
5734 expr.value = objc_build_encode_expr (type);
5735 expr.original_code = ERROR_MARK;
5739 c_parser_error (parser, "expected expression");
5740 expr.value = error_mark_node;
5741 expr.original_code = ERROR_MARK;
5745 /* APPLE LOCAL begin radar 5732232 - blocks (C++ cf) */
5748 expr.value = c_parser_block_literal_expr (parser);
5749 expr.original_code = ERROR_MARK;
5752 c_parser_error (parser, "expected expression");
5753 expr.value = error_mark_node;
5754 expr.original_code = ERROR_MARK;
5756 /* APPLE LOCAL end radar 5732232 - blocks (C++ cf) */
5757 case CPP_OPEN_SQUARE:
5758 if (c_dialect_objc ())
5760 tree receiver, args;
5761 c_parser_consume_token (parser);
5762 receiver = c_parser_objc_receiver (parser);
5763 args = c_parser_objc_message_args (parser);
5764 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5766 expr.value = objc_build_message_expr (build_tree_list (receiver,
5768 expr.original_code = ERROR_MARK;
5771 /* Else fall through to report error. */
5773 c_parser_error (parser, "expected expression");
5774 expr.value = error_mark_node;
5775 expr.original_code = ERROR_MARK;
5778 return c_parser_postfix_expression_after_primary (parser, expr);
5781 /* Parse a postfix expression after a parenthesized type name: the
5782 brace-enclosed initializer of a compound literal, possibly followed
5783 by some postfix operators. This is separate because it is not
5784 possible to tell until after the type name whether a cast
5785 expression has a cast or a compound literal, or whether the operand
5786 of sizeof is a parenthesized type name or starts with a compound
5789 static struct c_expr
5790 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5791 struct c_type_name *type_name)
5796 start_init (NULL_TREE, NULL, 0);
5797 type = groktypename (type_name);
5798 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
5800 error ("compound literal has variable size");
5801 type = error_mark_node;
5803 init = c_parser_braced_init (parser, type, false);
5805 maybe_warn_string_init (type, init);
5807 if (pedantic && !flag_isoc99)
5808 pedwarn ("ISO C90 forbids compound literals");
5809 expr.value = build_compound_literal (type, init.value);
5810 expr.original_code = ERROR_MARK;
5811 return c_parser_postfix_expression_after_primary (parser, expr);
5814 /* Parse a postfix expression after the initial primary or compound
5815 literal; that is, parse a series of postfix operators. */
5817 static struct c_expr
5818 c_parser_postfix_expression_after_primary (c_parser *parser,
5821 tree ident, idx, exprlist;
5824 switch (c_parser_peek_token (parser)->type)
5826 case CPP_OPEN_SQUARE:
5827 /* Array reference. */
5828 c_parser_consume_token (parser);
5829 idx = c_parser_expression (parser).value;
5830 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5832 expr.value = build_array_ref (expr.value, idx);
5833 expr.original_code = ERROR_MARK;
5835 case CPP_OPEN_PAREN:
5836 /* Function call. */
5837 c_parser_consume_token (parser);
5838 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5839 exprlist = NULL_TREE;
5841 exprlist = c_parser_expr_list (parser, true);
5842 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5844 expr.value = build_function_call (expr.value, exprlist);
5845 expr.original_code = ERROR_MARK;
5848 /* Structure element reference. */
5849 c_parser_consume_token (parser);
5850 expr = default_function_array_conversion (expr);
5851 if (c_parser_next_token_is (parser, CPP_NAME))
5852 ident = c_parser_peek_token (parser)->value;
5855 c_parser_error (parser, "expected identifier");
5856 expr.value = error_mark_node;
5857 expr.original_code = ERROR_MARK;
5860 c_parser_consume_token (parser);
5861 expr.value = build_component_ref (expr.value, ident);
5862 expr.original_code = ERROR_MARK;
5865 /* Structure element reference. */
5866 c_parser_consume_token (parser);
5867 expr = default_function_array_conversion (expr);
5868 if (c_parser_next_token_is (parser, CPP_NAME))
5869 ident = c_parser_peek_token (parser)->value;
5872 c_parser_error (parser, "expected identifier");
5873 expr.value = error_mark_node;
5874 expr.original_code = ERROR_MARK;
5877 c_parser_consume_token (parser);
5878 expr.value = build_component_ref (build_indirect_ref (expr.value,
5880 expr.original_code = ERROR_MARK;
5883 /* Postincrement. */
5884 c_parser_consume_token (parser);
5885 expr = default_function_array_conversion (expr);
5886 expr.value = build_unary_op (POSTINCREMENT_EXPR, expr.value, 0);
5887 expr.original_code = ERROR_MARK;
5889 case CPP_MINUS_MINUS:
5890 /* Postdecrement. */
5891 c_parser_consume_token (parser);
5892 expr = default_function_array_conversion (expr);
5893 expr.value = build_unary_op (POSTDECREMENT_EXPR, expr.value, 0);
5894 expr.original_code = ERROR_MARK;
5902 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5905 assignment-expression
5906 expression , assignment-expression
5909 static struct c_expr
5910 c_parser_expression (c_parser *parser)
5913 expr = c_parser_expr_no_commas (parser, NULL);
5914 while (c_parser_next_token_is (parser, CPP_COMMA))
5917 c_parser_consume_token (parser);
5918 next = c_parser_expr_no_commas (parser, NULL);
5919 next = default_function_array_conversion (next);
5920 expr.value = build_compound_expr (expr.value, next.value);
5921 expr.original_code = COMPOUND_EXPR;
5926 /* Parse an expression and convert functions or arrays to
5929 static struct c_expr
5930 c_parser_expression_conv (c_parser *parser)
5933 expr = c_parser_expression (parser);
5934 expr = default_function_array_conversion (expr);
5938 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5939 functions and arrays to pointers.
5942 assignment-expression
5943 nonempty-expr-list , assignment-expression
5947 c_parser_expr_list (c_parser *parser, bool convert_p)
5951 expr = c_parser_expr_no_commas (parser, NULL);
5953 expr = default_function_array_conversion (expr);
5954 ret = cur = build_tree_list (NULL_TREE, expr.value);
5955 while (c_parser_next_token_is (parser, CPP_COMMA))
5957 c_parser_consume_token (parser);
5958 expr = c_parser_expr_no_commas (parser, NULL);
5960 expr = default_function_array_conversion (expr);
5961 cur = TREE_CHAIN (cur) = build_tree_list (NULL_TREE, expr.value);
5967 /* Parse Objective-C-specific constructs. */
5969 /* Parse an objc-class-definition.
5971 objc-class-definition:
5972 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5973 objc-class-instance-variables[opt] objc-methodprotolist @end
5974 @implementation identifier objc-superclass[opt]
5975 objc-class-instance-variables[opt]
5976 @interface identifier ( identifier ) objc-protocol-refs[opt]
5977 objc-methodprotolist @end
5978 @implementation identifier ( identifier )
5983 "@interface identifier (" must start "@interface identifier (
5984 identifier ) ...": objc-methodprotolist in the first production may
5985 not start with a parenthesized identifier as a declarator of a data
5986 definition with no declaration specifiers if the objc-superclass,
5987 objc-protocol-refs and objc-class-instance-variables are omitted. */
5990 /* APPLE LOCAL radar 4548636 - class attributes. */
5991 c_parser_objc_class_definition (c_parser *parser, tree prefix_attrs)
5996 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
5998 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
5999 /* APPLE LOCAL begin radar 4548636 - class attributes. */
6003 error ("attributes may not be specified on an implementation");
6004 prefix_attrs = NULL_TREE;
6008 /* APPLE LOCAL end radar 4548636 - class attributes. */
6011 c_parser_consume_token (parser);
6012 if (c_parser_next_token_is_not (parser, CPP_NAME))
6014 /* APPLE LOCAL radar 4965989 */
6015 tree id2 = NULL_TREE;
6016 tree proto = NULL_TREE;
6017 c_parser_consume_token (parser);
6018 /* APPLE LOCAL begin radar 4965989 */
6019 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
6021 if (c_parser_next_token_is_not (parser, CPP_NAME))
6023 c_parser_error (parser, "expected identifier");
6024 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6027 id2 = c_parser_peek_token (parser)->value;
6028 c_parser_consume_token (parser);
6030 /* APPLE LOCAL end radar 4965989 */
6031 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6034 /* APPLE LOCAL begin radar 4965989 */
6035 if (id2 == NULL_TREE)
6037 error ("cannot implement anonymous category");
6040 /* APPLE LOCAL end radar 4965989 */
6041 objc_start_category_implementation (id1, id2);
6044 if (c_parser_next_token_is (parser, CPP_LESS))
6045 proto = c_parser_objc_protocol_refs (parser);
6046 /* APPLE LOCAL begin radar 4548636 - class attributes. */
6048 error ("attributes may not be specified on a category");
6049 /* APPLE LOCAL end radar 4548636 - class attributes. */
6050 objc_start_category_interface (id1, id2, proto);
6051 /* APPLE LOCAL C* property (Radar 4436866) (in 4.2 q) */
6052 c_parser_objc_interfacedecllist (parser);
6053 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6054 objc_finish_interface ();
6057 if (c_parser_next_token_is (parser, CPP_COLON))
6059 c_parser_consume_token (parser);
6060 if (c_parser_next_token_is_not (parser, CPP_NAME))
6062 c_parser_error (parser, "expected identifier");
6065 superclass = c_parser_peek_token (parser)->value;
6066 c_parser_consume_token (parser);
6069 superclass = NULL_TREE;
6072 tree proto = NULL_TREE;
6073 if (c_parser_next_token_is (parser, CPP_LESS))
6074 proto = c_parser_objc_protocol_refs (parser);
6075 /* APPLE LOCAL radar 4548636 - class attributes. */
6076 objc_start_class_interface (id1, superclass, proto, prefix_attrs);
6079 objc_start_class_implementation (id1, superclass);
6080 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6081 c_parser_objc_class_instance_variables (parser);
6084 objc_continue_interface ();
6085 /* APPLE LOCAL C* property (Radar 4436866) (in 4.2 q) */
6086 c_parser_objc_interfacedecllist (parser);
6087 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6088 objc_finish_interface ();
6092 objc_continue_implementation ();
6097 /* APPLE LOCAL begin C* property (Radar 4436866) (in 4.2 s) */
6099 c_parser_objc_eq_identifier (c_parser *parser)
6102 if (c_parser_next_token_is_not (parser, CPP_EQ))
6104 c_parser_error (parser, "expected %<=%>");
6108 c_parser_consume_token (parser);
6109 if (c_parser_next_token_is_not (parser, CPP_NAME))
6111 c_parser_error (parser, "expected identifier");
6114 id = c_parser_peek_token (parser)->value;
6115 c_parser_consume_token (parser);
6119 /* Parse obj-property-attribute.
6122 c_parser_objc_property_attribute (c_parser *parser)
6125 if (c_parser_peek_token (parser)->type != CPP_KEYWORD)
6127 c_parser_error (parser, "expected a property attribute");
6128 c_parser_consume_token (parser);
6131 switch (c_parser_peek_token (parser)->keyword)
6134 c_parser_consume_token (parser);
6135 objc_set_property_attr (1, NULL_TREE);
6138 c_parser_consume_token (parser);
6139 id = c_parser_objc_eq_identifier (parser);
6141 objc_set_property_attr (2, id);
6144 c_parser_consume_token (parser);
6145 id = c_parser_objc_eq_identifier (parser);
6147 objc_set_property_attr (3, id);
6148 /* Consume the ':' which must always follow the setter name. */
6149 if (c_parser_next_token_is (parser, CPP_COLON))
6150 c_parser_consume_token (parser);
6152 /* APPLE LOCAL begin radar 4947014 - objc atomic property */
6154 c_parser_consume_token (parser);
6155 objc_set_property_attr (13, NULL_TREE);
6157 /* APPLE LOCAL end radar 4947014 - objc atomic property */
6159 c_parser_error (parser, "expected a property attribute");
6160 c_parser_consume_token (parser);
6165 c_parser_objc_property_attrlist (c_parser *parser)
6167 while (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)
6168 && c_parser_next_token_is_not (parser, CPP_EOF))
6170 c_parser_objc_property_attribute (parser);
6171 /* APPLE LOCAL begin radar 6302949 */
6172 if (c_parser_next_token_is_not (parser, CPP_COMMA)
6173 && c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)
6174 && c_parser_next_token_is_not (parser, CPP_EOF))
6175 warning (0, "property attributes must be separated by a comma");
6176 /* APPLE LOCAL end radar 6302949 */
6177 if (c_parser_next_token_is (parser, CPP_COMMA)
6178 || c_parser_next_token_is (parser, CPP_NAME) /* error */)
6179 c_parser_consume_token (parser);
6184 c_parser_objc_property_attr_decl (c_parser *parser)
6186 if (!c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6188 c_parser_consume_token (parser);
6189 c_parser_objc_property_attrlist (parser);
6190 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6194 c_parser_component_decl (c_parser *parser)
6196 tree decl = c_parser_struct_declaration (parser);
6201 c_parser_objc_property_declaration (c_parser *parser)
6204 c_parser_require_keyword (parser, RID_AT_PROPERTY, "expected %<@property%>");
6205 objc_property_attr_context = 1;
6206 objc_set_property_attr (0, NULL_TREE);
6207 c_parser_objc_property_attr_decl (parser);
6208 objc_property_attr_context = 0;
6209 prop = c_parser_component_decl (parser);
6210 /* Comma-separated properties are chained together in
6211 reverse order; add them one by one. */
6212 prop = nreverse (prop);
6214 for (; prop; prop = TREE_CHAIN (prop))
6215 objc_add_property_variable (copy_node (prop));
6216 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6218 /* APPLE LOCAL end C* property (Radar 4436866) (in 4.2 s) */
6220 /* Parse objc-class-instance-variables.
6222 objc-class-instance-variables:
6223 { objc-instance-variable-decl-list[opt] }
6225 objc-instance-variable-decl-list:
6226 objc-visibility-spec
6227 objc-instance-variable-decl ;
6229 objc-instance-variable-decl-list objc-visibility-spec
6230 objc-instance-variable-decl-list objc-instance-variable-decl ;
6231 objc-instance-variable-decl-list ;
6233 objc-visibility-spec:
6238 objc-instance-variable-decl:
6243 c_parser_objc_class_instance_variables (c_parser *parser)
6245 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
6246 c_parser_consume_token (parser);
6247 while (c_parser_next_token_is_not (parser, CPP_EOF))
6250 /* Parse any stray semicolon. */
6251 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6254 pedwarn ("extra semicolon in struct or union specified");
6255 c_parser_consume_token (parser);
6258 /* Stop if at the end of the instance variables. */
6259 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
6261 c_parser_consume_token (parser);
6264 /* Parse any objc-visibility-spec. */
6265 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
6267 c_parser_consume_token (parser);
6268 objc_set_visibility (2);
6271 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
6273 c_parser_consume_token (parser);
6274 objc_set_visibility (0);
6277 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
6279 c_parser_consume_token (parser);
6280 objc_set_visibility (1);
6283 /* APPLE LOCAL begin radar 4564694 */
6284 else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
6286 c_parser_consume_token (parser);
6287 objc_set_visibility (3);
6290 /* APPLE LOCAL end radar 4564694 */
6291 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
6293 c_parser_pragma (parser, pragma_external);
6297 /* Parse some comma-separated declarations. */
6298 decls = c_parser_struct_declaration (parser);
6300 /* Comma-separated instance variables are chained together in
6301 reverse order; add them one by one. */
6302 tree ivar = nreverse (decls);
6303 for (; ivar; ivar = TREE_CHAIN (ivar))
6304 objc_add_instance_variable (copy_node (ivar));
6306 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6310 /* Parse an objc-class-declaration.
6312 objc-class-declaration:
6313 @class identifier-list ;
6317 c_parser_objc_class_declaration (c_parser *parser)
6319 tree list = NULL_TREE;
6320 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
6321 c_parser_consume_token (parser);
6322 /* Any identifiers, including those declared as type names, are OK
6327 if (c_parser_next_token_is_not (parser, CPP_NAME))
6329 c_parser_error (parser, "expected identifier");
6332 id = c_parser_peek_token (parser)->value;
6333 list = chainon (list, build_tree_list (NULL_TREE, id));
6334 c_parser_consume_token (parser);
6335 if (c_parser_next_token_is (parser, CPP_COMMA))
6336 c_parser_consume_token (parser);
6340 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6341 objc_declare_class (list);
6344 /* Parse an objc-alias-declaration.
6346 objc-alias-declaration:
6347 @compatibility_alias identifier identifier ;
6351 c_parser_objc_alias_declaration (c_parser *parser)
6354 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
6355 c_parser_consume_token (parser);
6356 if (c_parser_next_token_is_not (parser, CPP_NAME))
6358 c_parser_error (parser, "expected identifier");
6359 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6362 id1 = c_parser_peek_token (parser)->value;
6363 c_parser_consume_token (parser);
6364 if (c_parser_next_token_is_not (parser, CPP_NAME))
6366 c_parser_error (parser, "expected identifier");
6367 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6370 id2 = c_parser_peek_token (parser)->value;
6371 c_parser_consume_token (parser);
6372 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6373 objc_declare_alias (id1, id2);
6376 /* Parse an objc-protocol-definition.
6378 objc-protocol-definition:
6379 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6380 @protocol identifier-list ;
6382 "@protocol identifier ;" should be resolved as "@protocol
6383 identifier-list ;": objc-methodprotolist may not start with a
6384 semicolon in the first alternative if objc-protocol-refs are
6388 /* APPLE LOCAL radar 4947311 - protocol attributes */
6389 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
6391 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
6392 c_parser_consume_token (parser);
6393 if (c_parser_next_token_is_not (parser, CPP_NAME))
6395 c_parser_error (parser, "expected identifier");
6398 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
6399 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
6401 tree list = NULL_TREE;
6402 /* Any identifiers, including those declared as type names, are
6407 if (c_parser_next_token_is_not (parser, CPP_NAME))
6409 c_parser_error (parser, "expected identifier");
6412 id = c_parser_peek_token (parser)->value;
6413 list = chainon (list, build_tree_list (NULL_TREE, id));
6414 c_parser_consume_token (parser);
6415 if (c_parser_next_token_is (parser, CPP_COMMA))
6416 c_parser_consume_token (parser);
6420 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6421 /* APPLE LOCAL radar 4947311 - protocol attributes */
6422 objc_declare_protocols (list, attributes);
6426 tree id = c_parser_peek_token (parser)->value;
6427 tree proto = NULL_TREE;
6428 c_parser_consume_token (parser);
6429 if (c_parser_next_token_is (parser, CPP_LESS))
6430 proto = c_parser_objc_protocol_refs (parser);
6431 objc_pq_context = 1;
6432 /* APPLE LOCAL radar 4947311 - protocol attributes */
6433 objc_start_protocol (id, proto, attributes);
6434 /* APPLE LOCAL C* property (Radar 4436866) (in 4.2 r) */
6435 c_parser_objc_interfacedecllist (parser);
6436 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6437 objc_pq_context = 0;
6438 objc_finish_interface ();
6442 /* Parse an objc-method-type.
6449 static enum tree_code
6450 c_parser_objc_method_type (c_parser *parser)
6452 switch (c_parser_peek_token (parser)->type)
6455 c_parser_consume_token (parser);
6458 c_parser_consume_token (parser);
6465 /* Parse an objc-method-definition.
6467 objc-method-definition:
6468 objc-method-type objc-method-decl ;[opt] compound-statement
6472 c_parser_objc_method_definition (c_parser *parser)
6474 enum tree_code type = c_parser_objc_method_type (parser);
6476 objc_set_method_type (type);
6477 objc_pq_context = 1;
6478 decl = c_parser_objc_method_decl (parser);
6479 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6481 c_parser_consume_token (parser);
6483 pedwarn ("extra semicolon in method definition specified");
6485 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6487 c_parser_error (parser, "expected %<{%>");
6490 objc_pq_context = 0;
6491 /* APPLE LOCAL begin radar 3803157 - objc attribute (in 4.2 a) */
6492 objc_start_method_definition (decl, objc_method_attributes);
6493 objc_method_attributes = NULL_TREE;
6494 /* APPLE LOCAL end radar 3803157 - objc attribute (in 4.2 a) */
6495 add_stmt (c_parser_compound_statement (parser));
6496 objc_finish_method_definition (current_function_decl);
6499 /* APPLE LOCAL begin C* language (in 4.2 w) */
6500 /* True iff the gioven TOKEN starts a methodproto. */
6503 c_token_starts_methodproto (c_token *token)
6505 return token->type == CPP_PLUS
6506 || token->type == CPP_MINUS
6507 || (token->type == CPP_KEYWORD
6508 && (token->keyword == RID_AT_REQUIRED
6509 || token->keyword == RID_AT_OPTIONAL));
6511 /* APPLE LOCAL end C* language (in 4.2 w) */
6513 /* Parse an objc-methodprotolist.
6515 objc-methodprotolist:
6517 objc-methodprotolist objc-methodproto
6518 objc-methodprotolist declaration
6519 objc-methodprotolist ;
6521 The declaration is a data definition, which may be missing
6522 declaration specifiers under the same rules and diagnostics as
6523 other data definitions outside functions, and the stray semicolon
6524 is diagnosed the same way as a stray semicolon outside a
6528 /* APPLE LOCAL C* property (Radar 4436866) (in 4.2 b) */
6529 c_parser_objc_interfacedecllist (c_parser *parser)
6533 /* APPLE LOCAL begin C* property (Radar 4436866) (in 4.2 b) */
6535 token = c_parser_peek_token (parser);
6536 if (token->type == CPP_KEYWORD
6537 && token->keyword == RID_AT_PROPERTY)
6539 c_parser_objc_property_declaration (parser);
6542 /* APPLE LOCAL end C* property (Radar 4436866) (in 4.2 b) */
6543 /* APPLE LOCAL begin C* language (in 4.2 w) */
6544 if (c_token_starts_methodproto (token))
6546 c_parser_objc_methodproto (parser);
6549 /* APPLE LOCAL end C* language (in 4.2 w) */
6551 /* The list is terminated by @end. */
6552 switch (c_parser_peek_token (parser)->type)
6556 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
6557 c_parser_consume_token (parser);
6559 /* APPLE LOCAL begin C* language (in 4.2 w) */
6560 /* CPP_PLUS and CPP_MINUS deleted */
6561 /* APPLE LOCAL end C* language (in 4.2 w) */
6563 c_parser_pragma (parser, pragma_external);
6568 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6570 /* APPLE LOCAL radar 4708210 (for_objc_collection in 4.2) */
6571 c_parser_declaration_or_fndef (parser, false, true, false, true, NULL);
6577 /* Parse an objc-methodproto.
6580 objc-method-type objc-method-decl ;
6584 c_parser_objc_methodproto (c_parser *parser)
6586 /* APPLE LOCAL C* language */
6587 enum tree_code type;
6589 /* APPLE LOCAL begin C* language */
6590 if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
6592 objc_set_method_opt (0);
6593 c_parser_consume_token (parser);
6596 if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
6598 objc_set_method_opt (1);
6599 c_parser_consume_token (parser);
6602 /* APPLE LOCAL begin C* language */
6603 /* APPLE LOCAL C* language */
6604 type = c_parser_objc_method_type (parser);
6605 objc_set_method_type (type);
6606 /* Remember protocol qualifiers in prototypes. */
6607 objc_pq_context = 1;
6608 decl = c_parser_objc_method_decl (parser);
6609 /* Forget protocol qualifiers here. */
6610 objc_pq_context = 0;
6611 /* APPLE LOCAL begin radar 3803157 - objc attribute (in 4.2 c) */
6612 objc_add_method_declaration (decl, objc_method_attributes);
6613 objc_method_attributes = NULL_TREE;
6614 /* APPLE LOCAL end radar 3803157 - objc attribute (in 4.2 c) */
6615 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6618 /* Parse an objc-method-decl.
6621 ( objc-type-name ) objc-selector
6623 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6624 objc-keyword-selector objc-optparmlist
6626 objc-keyword-selector:
6628 objc-keyword-selector objc-keyword-decl
6631 objc-selector : ( objc-type-name ) identifier
6632 objc-selector : identifier
6633 : ( objc-type-name ) identifier
6637 objc-optparms objc-optellipsis
6641 objc-opt-parms , parameter-declaration
6649 c_parser_objc_method_decl (c_parser *parser)
6651 tree type = NULL_TREE;
6653 tree parms = NULL_TREE;
6654 bool ellipsis = false;
6656 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6658 c_parser_consume_token (parser);
6659 type = c_parser_objc_type_name (parser);
6660 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6662 sel = c_parser_objc_selector (parser);
6663 /* If there is no selector, or a colon follows, we have an
6664 objc-keyword-selector. If there is a selector, and a colon does
6665 not follow, that selector ends the objc-method-decl. */
6666 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6669 tree list = NULL_TREE;
6672 /* APPLE LOCAL radar 4157812 */
6673 tree attr = NULL_TREE;
6674 tree atype = NULL_TREE, id, keyworddecl;
6675 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6677 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6679 c_parser_consume_token (parser);
6680 atype = c_parser_objc_type_name (parser);
6681 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6684 /* APPLE LOCAL begin radar 4157812 */
6685 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
6686 attr = c_parser_attributes (parser);
6687 /* APPLE LOCAL end radar 4157812 */
6688 if (c_parser_next_token_is_not (parser, CPP_NAME))
6690 c_parser_error (parser, "expected identifier");
6691 return error_mark_node;
6693 id = c_parser_peek_token (parser)->value;
6694 c_parser_consume_token (parser);
6695 /* APPLE LOCAL radar 4157812 */
6696 keyworddecl = objc_build_keyword_decl (tsel, atype, id, attr);
6697 list = chainon (list, keyworddecl);
6698 tsel = c_parser_objc_selector (parser);
6699 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6702 /* APPLE LOCAL begin radar 3803157 - objc attribute (in 4.2 y) */
6703 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
6704 objc_method_attributes = c_parser_attributes (parser);
6705 /* APPLE LOCAL end radar 3803157 - objc attribute (in 4.2 y) */
6706 /* Parse the optional parameter list. Optional Objective-C
6707 method parameters follow the C syntax, and may include '...'
6708 to denote a variable number of arguments. */
6709 parms = make_node (TREE_LIST);
6710 while (c_parser_next_token_is (parser, CPP_COMMA))
6712 struct c_parm *parm;
6713 c_parser_consume_token (parser);
6714 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6717 c_parser_consume_token (parser);
6718 /* APPLE LOCAL end radar 3803157 - objc attribute (in 4.2 y) */
6719 if (objc_method_attributes)
6720 error ("method attributes must be specified at the end only");
6721 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
6722 objc_method_attributes = c_parser_attributes (parser);
6723 /* APPLE LOCAL end radar 3803157 - objc attribute (in 4.2 y) */
6726 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6729 parms = chainon (parms,
6730 build_tree_list (NULL_TREE, grokparm (parm)));
6734 /* APPLE LOCAL begin radar 3803157 - objc attribute (in 4.2 y) */
6737 gcc_assert (objc_method_attributes == NULL_TREE);
6738 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
6739 objc_method_attributes = c_parser_attributes (parser);
6741 /* APPLE LOCAL end radar 3803157 - objc attribute (in 4.2 y) */
6742 /* APPLE LOCAL begin radar 4157812 */
6745 c_parser_error (parser, "objective-c method declaration is expected");
6746 return error_mark_node;
6748 /* APPLE LOCAL end radar 4157812 */
6749 return objc_build_method_signature (type, sel, parms, ellipsis);
6752 /* Parse an objc-type-name.
6755 objc-type-qualifiers[opt] type-name
6756 objc-type-qualifiers[opt]
6758 objc-type-qualifiers:
6760 objc-type-qualifiers objc-type-qualifier
6762 objc-type-qualifier: one of
6763 in out inout bycopy byref oneway
6767 c_parser_objc_type_name (c_parser *parser)
6769 tree quals = NULL_TREE;
6770 struct c_type_name *typename = NULL;
6771 tree type = NULL_TREE;
6774 c_token *token = c_parser_peek_token (parser);
6775 if (token->type == CPP_KEYWORD
6776 && (token->keyword == RID_IN
6777 || token->keyword == RID_OUT
6778 || token->keyword == RID_INOUT
6779 || token->keyword == RID_BYCOPY
6780 || token->keyword == RID_BYREF
6781 || token->keyword == RID_ONEWAY))
6783 /* APPLE LOCAL radar 4301047 (in 4.2 z) */
6784 quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
6785 c_parser_consume_token (parser);
6790 if (c_parser_next_token_starts_typename (parser))
6791 typename = c_parser_type_name (parser);
6793 type = groktypename (typename);
6794 return build_tree_list (quals, type);
6797 /* Parse objc-protocol-refs.
6804 c_parser_objc_protocol_refs (c_parser *parser)
6806 tree list = NULL_TREE;
6807 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6808 c_parser_consume_token (parser);
6809 /* Any identifiers, including those declared as type names, are OK
6814 if (c_parser_next_token_is_not (parser, CPP_NAME))
6816 c_parser_error (parser, "expected identifier");
6819 id = c_parser_peek_token (parser)->value;
6820 list = chainon (list, build_tree_list (NULL_TREE, id));
6821 c_parser_consume_token (parser);
6822 if (c_parser_next_token_is (parser, CPP_COMMA))
6823 c_parser_consume_token (parser);
6827 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6831 /* Parse an objc-try-catch-statement.
6833 objc-try-catch-statement:
6834 @try compound-statement objc-catch-list[opt]
6835 @try compound-statement objc-catch-list[opt] @finally compound-statement
6838 @catch ( parameter-declaration ) compound-statement
6839 objc-catch-list @catch ( parameter-declaration ) compound-statement
6843 c_parser_objc_try_catch_statement (c_parser *parser)
6847 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
6848 c_parser_consume_token (parser);
6849 loc = c_parser_peek_token (parser)->location;
6850 stmt = c_parser_compound_statement (parser);
6851 objc_begin_try_stmt (loc, stmt);
6852 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
6854 struct c_parm *parm;
6855 c_parser_consume_token (parser);
6856 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6858 /* APPLE LOCAL begin radar 2848255 */
6859 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6862 c_parser_consume_token (parser);
6863 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6864 objc_begin_catch_clause (NULL_TREE);
6868 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6871 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6874 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6875 objc_begin_catch_clause (grokparm (parm));
6877 /* APPLE LOCAL end radar 2848255 */
6878 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6879 c_parser_compound_statement_nostart (parser);
6880 objc_finish_catch_clause ();
6882 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6886 c_parser_consume_token (parser);
6887 finloc = c_parser_peek_token (parser)->location;
6888 finstmt = c_parser_compound_statement (parser);
6889 objc_build_finally_clause (finloc, finstmt);
6891 objc_finish_try_stmt ();
6894 /* APPLE LOCAL begin radar 5982990 */
6895 /* This routine is called from c_parser_objc_synchronized_statement
6896 and is identical to c_parser_compound_statement with
6897 the addition of volatizing local variables seen in the scope
6898 of @synchroniz block.
6901 c_parser_objc_synch_compound_statement (c_parser *parser)
6904 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6905 return error_mark_node;
6906 stmt = c_begin_compound_stmt (true);
6907 c_parser_compound_statement_nostart (parser);
6908 if (flag_objc_sjlj_exceptions)
6909 objc_mark_locals_volatile (NULL);
6910 return c_end_compound_stmt (stmt, true);
6912 /* APPLE LOCAL end radar 5982990 */
6914 /* Parse an objc-synchronized-statement.
6916 objc-synchronized-statement:
6917 @synchronized ( expression ) compound-statement
6921 c_parser_objc_synchronized_statement (c_parser *parser)
6925 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6926 c_parser_consume_token (parser);
6927 loc = c_parser_peek_token (parser)->location;
6928 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6930 expr = c_parser_expression (parser).value;
6931 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6934 expr = error_mark_node;
6935 /* APPLE LOCAL radar 5982990 */
6936 stmt = c_parser_objc_synch_compound_statement (parser);
6937 objc_build_synchronized (loc, expr, stmt);
6940 /* Parse an objc-selector; return NULL_TREE without an error if the
6941 next token is not an objc-selector.
6946 enum struct union if else while do for switch case default
6947 break continue return goto asm sizeof typeof __alignof
6948 unsigned long const short volatile signed restrict _Complex
6949 in out inout bycopy byref oneway int char float double void _Bool
6951 ??? Why this selection of keywords but not, for example, storage
6952 class specifiers? */
6955 c_parser_objc_selector (c_parser *parser)
6957 c_token *token = c_parser_peek_token (parser);
6958 tree value = token->value;
6959 if (token->type == CPP_NAME)
6961 c_parser_consume_token (parser);
6964 if (token->type != CPP_KEYWORD)
6966 switch (token->keyword)
7007 c_parser_consume_token (parser);
7014 /* Parse an objc-selector-arg.
7018 objc-keywordname-list
7020 objc-keywordname-list:
7022 objc-keywordname-list objc-keywordname
7030 c_parser_objc_selector_arg (c_parser *parser)
7032 tree sel = c_parser_objc_selector (parser);
7033 tree list = NULL_TREE;
7034 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7038 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7040 list = chainon (list, build_tree_list (sel, NULL_TREE));
7041 sel = c_parser_objc_selector (parser);
7042 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7048 /* Parse an objc-receiver.
7057 c_parser_objc_receiver (c_parser *parser)
7059 if (c_parser_peek_token (parser)->type == CPP_NAME
7060 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
7061 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
7063 tree id = c_parser_peek_token (parser)->value;
7064 c_parser_consume_token (parser);
7065 return objc_get_class_reference (id);
7067 return c_parser_expression (parser).value;
7070 /* Parse objc-message-args.
7074 objc-keywordarg-list
7076 objc-keywordarg-list:
7078 objc-keywordarg-list objc-keywordarg
7081 objc-selector : objc-keywordexpr
7086 c_parser_objc_message_args (c_parser *parser)
7088 tree sel = c_parser_objc_selector (parser);
7089 tree list = NULL_TREE;
7090 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7095 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7097 keywordexpr = c_parser_objc_keywordexpr (parser);
7098 list = chainon (list, build_tree_list (sel, keywordexpr));
7099 sel = c_parser_objc_selector (parser);
7100 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7106 /* Parse an objc-keywordexpr.
7113 c_parser_objc_keywordexpr (c_parser *parser)
7115 tree list = c_parser_expr_list (parser, true);
7116 if (TREE_CHAIN (list) == NULL_TREE)
7118 /* Just return the expression, remove a level of
7120 return TREE_VALUE (list);
7124 /* We have a comma expression, we will collapse later. */
7130 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
7131 should be considered, statements. ALLOW_STMT is true if we're within
7132 the context of a function and such pragmas are to be allowed. Returns
7133 true if we actually parsed such a pragma. */
7136 c_parser_pragma (c_parser *parser, enum pragma_context context)
7140 id = c_parser_peek_token (parser)->pragma_kind;
7141 gcc_assert (id != PRAGMA_NONE);
7145 case PRAGMA_OMP_BARRIER:
7146 if (context != pragma_compound)
7148 if (context == pragma_stmt)
7149 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
7150 "used in compound statements");
7153 c_parser_omp_barrier (parser);
7156 case PRAGMA_OMP_FLUSH:
7157 if (context != pragma_compound)
7159 if (context == pragma_stmt)
7160 c_parser_error (parser, "%<#pragma omp flush%> may only be "
7161 "used in compound statements");
7164 c_parser_omp_flush (parser);
7167 case PRAGMA_OMP_THREADPRIVATE:
7168 c_parser_omp_threadprivate (parser);
7171 case PRAGMA_OMP_SECTION:
7172 error ("%<#pragma omp section%> may only be used in "
7173 "%<#pragma omp sections%> construct");
7174 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7177 case PRAGMA_GCC_PCH_PREPROCESS:
7178 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
7179 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7183 if (id < PRAGMA_FIRST_EXTERNAL)
7185 if (context == pragma_external)
7188 c_parser_error (parser, "expected declaration specifiers");
7189 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7192 c_parser_omp_construct (parser);
7198 c_parser_consume_pragma (parser);
7199 c_invoke_pragma_handler (id);
7201 /* Skip to EOL, but suppress any error message. Those will have been
7202 generated by the handler routine through calling error, as opposed
7203 to calling c_parser_error. */
7204 parser->error = true;
7205 c_parser_skip_to_pragma_eol (parser);
7210 /* The interface the pragma parsers have to the lexer. */
7213 pragma_lex (tree *value)
7215 c_token *tok = c_parser_peek_token (the_parser);
7216 enum cpp_ttype ret = tok->type;
7218 *value = tok->value;
7219 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
7223 if (ret == CPP_KEYWORD)
7225 c_parser_consume_token (the_parser);
7232 c_parser_pragma_pch_preprocess (c_parser *parser)
7236 c_parser_consume_pragma (parser);
7237 if (c_parser_next_token_is (parser, CPP_STRING))
7239 name = c_parser_peek_token (parser)->value;
7240 c_parser_consume_token (parser);
7243 c_parser_error (parser, "expected string literal");
7244 c_parser_skip_to_pragma_eol (parser);
7247 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
7250 /* OpenMP 2.5 parsing routines. */
7252 /* Returns name of the next clause.
7253 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
7254 the token is not consumed. Otherwise appropriate pragma_omp_clause is
7255 returned and the token is consumed. */
7257 static pragma_omp_clause
7258 c_parser_omp_clause_name (c_parser *parser)
7260 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
7262 if (c_parser_next_token_is_keyword (parser, RID_IF))
7263 result = PRAGMA_OMP_CLAUSE_IF;
7264 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
7265 result = PRAGMA_OMP_CLAUSE_DEFAULT;
7266 else if (c_parser_next_token_is (parser, CPP_NAME))
7268 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7273 if (!strcmp ("copyin", p))
7274 result = PRAGMA_OMP_CLAUSE_COPYIN;
7275 else if (!strcmp ("copyprivate", p))
7276 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
7279 if (!strcmp ("firstprivate", p))
7280 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
7283 if (!strcmp ("lastprivate", p))
7284 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
7287 if (!strcmp ("nowait", p))
7288 result = PRAGMA_OMP_CLAUSE_NOWAIT;
7289 else if (!strcmp ("num_threads", p))
7290 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
7293 if (!strcmp ("ordered", p))
7294 result = PRAGMA_OMP_CLAUSE_ORDERED;
7297 if (!strcmp ("private", p))
7298 result = PRAGMA_OMP_CLAUSE_PRIVATE;
7301 if (!strcmp ("reduction", p))
7302 result = PRAGMA_OMP_CLAUSE_REDUCTION;
7305 if (!strcmp ("schedule", p))
7306 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
7307 else if (!strcmp ("shared", p))
7308 result = PRAGMA_OMP_CLAUSE_SHARED;
7313 if (result != PRAGMA_OMP_CLAUSE_NONE)
7314 c_parser_consume_token (parser);
7319 /* Validate that a clause of the given type does not already exist. */
7322 check_no_duplicate_clause (tree clauses, enum tree_code code, const char *name)
7326 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
7327 if (OMP_CLAUSE_CODE (c) == code)
7329 error ("too many %qs clauses", name);
7337 variable-list , identifier
7339 If KIND is nonzero, create the appropriate node and install the decl
7340 in OMP_CLAUSE_DECL and add the node to the head of the list.
7342 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
7343 return the list created. */
7346 c_parser_omp_variable_list (c_parser *parser, enum omp_clause_code kind,
7349 if (c_parser_next_token_is_not (parser, CPP_NAME)
7350 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
7351 c_parser_error (parser, "expected identifier");
7353 while (c_parser_next_token_is (parser, CPP_NAME)
7354 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
7356 tree t = lookup_name (c_parser_peek_token (parser)->value);
7359 undeclared_variable (c_parser_peek_token (parser)->value,
7360 c_parser_peek_token (parser)->location);
7361 else if (t == error_mark_node)
7365 tree u = build_omp_clause (kind);
7366 OMP_CLAUSE_DECL (u) = t;
7367 OMP_CLAUSE_CHAIN (u) = list;
7371 list = tree_cons (t, NULL_TREE, list);
7373 c_parser_consume_token (parser);
7375 if (c_parser_next_token_is_not (parser, CPP_COMMA))
7378 c_parser_consume_token (parser);
7384 /* Similarly, but expect leading and trailing parenthesis. This is a very
7385 common case for omp clauses. */
7388 c_parser_omp_var_list_parens (c_parser *parser, enum tree_code kind, tree list)
7390 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7392 list = c_parser_omp_variable_list (parser, kind, list);
7393 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7399 copyin ( variable-list ) */
7402 c_parser_omp_clause_copyin (c_parser *parser, tree list)
7404 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
7408 copyprivate ( variable-list ) */
7411 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
7413 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
7417 default ( shared | none ) */
7420 c_parser_omp_clause_default (c_parser *parser, tree list)
7422 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
7425 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7427 if (c_parser_next_token_is (parser, CPP_NAME))
7429 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7434 if (strcmp ("none", p) != 0)
7436 kind = OMP_CLAUSE_DEFAULT_NONE;
7440 if (strcmp ("shared", p) != 0)
7442 kind = OMP_CLAUSE_DEFAULT_SHARED;
7449 c_parser_consume_token (parser);
7454 c_parser_error (parser, "expected %<none%> or %<shared%>");
7456 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7458 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
7461 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
7462 c = build_omp_clause (OMP_CLAUSE_DEFAULT);
7463 OMP_CLAUSE_CHAIN (c) = list;
7464 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
7470 firstprivate ( variable-list ) */
7473 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
7475 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
7479 if ( expression ) */
7482 c_parser_omp_clause_if (c_parser *parser, tree list)
7484 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7486 tree t = c_parser_paren_condition (parser);
7489 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
7491 c = build_omp_clause (OMP_CLAUSE_IF);
7492 OMP_CLAUSE_IF_EXPR (c) = t;
7493 OMP_CLAUSE_CHAIN (c) = list;
7497 c_parser_error (parser, "expected %<(%>");
7503 lastprivate ( variable-list ) */
7506 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
7508 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
7515 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7519 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
7521 c = build_omp_clause (OMP_CLAUSE_NOWAIT);
7522 OMP_CLAUSE_CHAIN (c) = list;
7527 num_threads ( expression ) */
7530 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
7532 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7534 tree c, t = c_parser_expression (parser).value;
7536 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7538 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
7540 c_parser_error (parser, "expected integer expression");
7544 /* Attempt to statically determine when the number isn't positive. */
7545 c = fold_build2 (LE_EXPR, boolean_type_node, t,
7546 build_int_cst (TREE_TYPE (t), 0));
7547 if (c == boolean_true_node)
7549 warning (0, "%<num_threads%> value must be positive");
7550 t = integer_one_node;
7553 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
7555 c = build_omp_clause (OMP_CLAUSE_NUM_THREADS);
7556 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
7557 OMP_CLAUSE_CHAIN (c) = list;
7568 c_parser_omp_clause_ordered (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7572 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
7574 c = build_omp_clause (OMP_CLAUSE_ORDERED);
7575 OMP_CLAUSE_CHAIN (c) = list;
7580 private ( variable-list ) */
7583 c_parser_omp_clause_private (c_parser *parser, tree list)
7585 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
7589 reduction ( reduction-operator : variable-list )
7592 One of: + * - & ^ | && || */
7595 c_parser_omp_clause_reduction (c_parser *parser, tree list)
7597 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7599 enum tree_code code;
7601 switch (c_parser_peek_token (parser)->type)
7613 code = BIT_AND_EXPR;
7616 code = BIT_XOR_EXPR;
7619 code = BIT_IOR_EXPR;
7622 code = TRUTH_ANDIF_EXPR;
7625 code = TRUTH_ORIF_EXPR;
7628 c_parser_error (parser,
7629 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7630 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7631 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7634 c_parser_consume_token (parser);
7635 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7639 nl = c_parser_omp_variable_list (parser, OMP_CLAUSE_REDUCTION, list);
7640 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
7641 OMP_CLAUSE_REDUCTION_CODE (c) = code;
7645 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7651 schedule ( schedule-kind )
7652 schedule ( schedule-kind , expression )
7655 static | dynamic | guided | runtime
7659 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7663 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7666 c = build_omp_clause (OMP_CLAUSE_SCHEDULE);
7668 if (c_parser_next_token_is (parser, CPP_NAME))
7670 tree kind = c_parser_peek_token (parser)->value;
7671 const char *p = IDENTIFIER_POINTER (kind);
7676 if (strcmp ("dynamic", p) != 0)
7678 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7682 if (strcmp ("guided", p) != 0)
7684 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7688 if (strcmp ("runtime", p) != 0)
7690 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7697 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7698 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7702 c_parser_consume_token (parser);
7703 if (c_parser_next_token_is (parser, CPP_COMMA))
7705 c_parser_consume_token (parser);
7707 t = c_parser_expr_no_commas (parser, NULL).value;
7709 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7710 error ("schedule %<runtime%> does not take "
7711 "a %<chunk_size%> parameter");
7712 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7713 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7715 c_parser_error (parser, "expected integer expression");
7717 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7720 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7721 "expected %<,%> or %<)%>");
7723 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7724 OMP_CLAUSE_CHAIN (c) = list;
7728 c_parser_error (parser, "invalid schedule kind");
7729 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7734 shared ( variable-list ) */
7737 c_parser_omp_clause_shared (c_parser *parser, tree list)
7739 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7742 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7743 is a bitmask in MASK. Return the list of clauses found; the result
7744 of clause default goes in *pdefault. */
7747 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7750 tree clauses = NULL;
7752 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7754 const pragma_omp_clause c_kind = c_parser_omp_clause_name (parser);
7756 tree prev = clauses;
7760 case PRAGMA_OMP_CLAUSE_COPYIN:
7761 clauses = c_parser_omp_clause_copyin (parser, clauses);
7764 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7765 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7766 c_name = "copyprivate";
7768 case PRAGMA_OMP_CLAUSE_DEFAULT:
7769 clauses = c_parser_omp_clause_default (parser, clauses);
7772 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7773 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7774 c_name = "firstprivate";
7776 case PRAGMA_OMP_CLAUSE_IF:
7777 clauses = c_parser_omp_clause_if (parser, clauses);
7780 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7781 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7782 c_name = "lastprivate";
7784 case PRAGMA_OMP_CLAUSE_NOWAIT:
7785 clauses = c_parser_omp_clause_nowait (parser, clauses);
7788 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7789 clauses = c_parser_omp_clause_num_threads (parser, clauses);
7790 c_name = "num_threads";
7792 case PRAGMA_OMP_CLAUSE_ORDERED:
7793 clauses = c_parser_omp_clause_ordered (parser, clauses);
7796 case PRAGMA_OMP_CLAUSE_PRIVATE:
7797 clauses = c_parser_omp_clause_private (parser, clauses);
7800 case PRAGMA_OMP_CLAUSE_REDUCTION:
7801 clauses = c_parser_omp_clause_reduction (parser, clauses);
7802 c_name = "reduction";
7804 case PRAGMA_OMP_CLAUSE_SCHEDULE:
7805 clauses = c_parser_omp_clause_schedule (parser, clauses);
7806 c_name = "schedule";
7808 case PRAGMA_OMP_CLAUSE_SHARED:
7809 clauses = c_parser_omp_clause_shared (parser, clauses);
7813 c_parser_error (parser, "expected %<#pragma omp%> clause");
7817 if (((mask >> c_kind) & 1) == 0 && !parser->error)
7819 /* Remove the invalid clause(s) from the list to avoid
7820 confusing the rest of the compiler. */
7822 error ("%qs is not valid for %qs", c_name, where);
7827 c_parser_skip_to_pragma_eol (parser);
7829 return c_finish_omp_clauses (clauses);
7836 In practice, we're also interested in adding the statement to an
7837 outer node. So it is convenient if we work around the fact that
7838 c_parser_statement calls add_stmt. */
7841 c_parser_omp_structured_block (c_parser *parser)
7843 tree stmt = push_stmt_list ();
7844 c_parser_statement (parser);
7845 return pop_stmt_list (stmt);
7849 # pragma omp atomic new-line
7853 x binop= expr | x++ | ++x | x-- | --x
7855 +, *, -, /, &, ^, |, <<, >>
7857 where x is an lvalue expression with scalar type. */
7860 c_parser_omp_atomic (c_parser *parser)
7864 enum tree_code code;
7866 c_parser_skip_to_pragma_eol (parser);
7868 lhs = c_parser_unary_expression (parser).value;
7869 switch (TREE_CODE (lhs))
7873 c_parser_skip_to_end_of_block_or_statement (parser);
7876 case PREINCREMENT_EXPR:
7877 case POSTINCREMENT_EXPR:
7878 lhs = TREE_OPERAND (lhs, 0);
7880 rhs = integer_one_node;
7883 case PREDECREMENT_EXPR:
7884 case POSTDECREMENT_EXPR:
7885 lhs = TREE_OPERAND (lhs, 0);
7887 rhs = integer_one_node;
7891 switch (c_parser_peek_token (parser)->type)
7897 code = TRUNC_DIV_EXPR;
7912 code = BIT_AND_EXPR;
7915 code = BIT_IOR_EXPR;
7918 code = BIT_XOR_EXPR;
7921 c_parser_error (parser,
7922 "invalid operator for %<#pragma omp atomic%>");
7926 c_parser_consume_token (parser);
7927 rhs = c_parser_expression (parser).value;
7930 stmt = c_finish_omp_atomic (code, lhs, rhs);
7931 if (stmt != error_mark_node)
7933 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7938 # pragma omp barrier new-line
7942 c_parser_omp_barrier (c_parser *parser)
7944 c_parser_consume_pragma (parser);
7945 c_parser_skip_to_pragma_eol (parser);
7947 c_finish_omp_barrier ();
7951 # pragma omp critical [(name)] new-line
7956 c_parser_omp_critical (c_parser *parser)
7958 tree stmt, name = NULL;
7960 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7962 c_parser_consume_token (parser);
7963 if (c_parser_next_token_is (parser, CPP_NAME))
7965 name = c_parser_peek_token (parser)->value;
7966 c_parser_consume_token (parser);
7967 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7970 c_parser_error (parser, "expected identifier");
7972 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7973 c_parser_error (parser, "expected %<(%> or end of line");
7974 c_parser_skip_to_pragma_eol (parser);
7976 stmt = c_parser_omp_structured_block (parser);
7977 return c_finish_omp_critical (stmt, name);
7981 # pragma omp flush flush-vars[opt] new-line
7984 ( variable-list ) */
7987 c_parser_omp_flush (c_parser *parser)
7989 c_parser_consume_pragma (parser);
7990 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7991 c_parser_omp_var_list_parens (parser, 0, NULL);
7992 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7993 c_parser_error (parser, "expected %<(%> or end of line");
7994 c_parser_skip_to_pragma_eol (parser);
7996 c_finish_omp_flush ();
7999 /* Parse the restricted form of the for statment allowed by OpenMP.
8000 The real trick here is to determine the loop control variable early
8001 so that we can push a new decl if necessary to make it private. */
8004 c_parser_omp_for_loop (c_parser *parser)
8006 tree decl, cond, incr, save_break, save_cont, body, init;
8009 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
8011 c_parser_error (parser, "for statement expected");
8014 loc = c_parser_peek_token (parser)->location;
8015 c_parser_consume_token (parser);
8017 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8020 /* Parse the initialization declaration or expression. */
8021 if (c_parser_next_token_starts_declspecs (parser))
8023 /* APPLE LOCAL radar 4708210 (for_objc_collection in 4.2) */
8024 c_parser_declaration_or_fndef (parser, true, true, true, true, NULL);
8025 decl = check_for_loop_decls ();
8030 else if (c_parser_next_token_is (parser, CPP_NAME)
8031 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
8033 decl = c_parser_postfix_expression (parser).value;
8035 c_parser_require (parser, CPP_EQ, "expected %<=%>");
8037 init = c_parser_expr_no_commas (parser, NULL).value;
8038 init = build_modify_expr (decl, NOP_EXPR, init);
8039 init = c_process_expr_stmt (init);
8041 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8046 /* Parse the loop condition. */
8048 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
8050 cond = c_parser_expression_conv (parser).value;
8051 cond = c_objc_common_truthvalue_conversion (cond);
8053 SET_EXPR_LOCATION (cond, input_location);
8055 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8057 /* Parse the increment expression. */
8059 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
8060 incr = c_process_expr_stmt (c_parser_expression (parser).value);
8061 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8064 save_break = c_break_label;
8065 c_break_label = size_one_node;
8066 save_cont = c_cont_label;
8067 c_cont_label = NULL_TREE;
8068 body = push_stmt_list ();
8070 add_stmt (c_parser_c99_block_statement (parser));
8072 add_stmt (build1 (LABEL_EXPR, void_type_node, c_cont_label));
8074 body = pop_stmt_list (body);
8075 c_break_label = save_break;
8076 c_cont_label = save_cont;
8078 /* Only bother calling c_finish_omp_for if we havn't already generated
8079 an error from the initialization parsing. */
8080 if (decl != NULL && decl != error_mark_node && init != error_mark_node)
8081 return c_finish_omp_for (loc, decl, init, cond, incr, body, NULL);
8085 c_parser_error (parser, "expected iteration declaration or initialization");
8086 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8087 decl = init = cond = incr = NULL_TREE;
8092 #pragma omp for for-clause[optseq] new-line
8096 #define OMP_FOR_CLAUSE_MASK \
8097 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8098 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8099 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8100 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8101 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
8102 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
8103 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8106 c_parser_omp_for (c_parser *parser)
8108 tree block, clauses, ret;
8110 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
8113 block = c_begin_compound_stmt (true);
8114 ret = c_parser_omp_for_loop (parser);
8116 OMP_FOR_CLAUSES (ret) = clauses;
8117 block = c_end_compound_stmt (block, true);
8124 # pragma omp master new-line
8129 c_parser_omp_master (c_parser *parser)
8131 c_parser_skip_to_pragma_eol (parser);
8132 return c_finish_omp_master (c_parser_omp_structured_block (parser));
8136 # pragma omp ordered new-line
8141 c_parser_omp_ordered (c_parser *parser)
8143 c_parser_skip_to_pragma_eol (parser);
8144 return c_finish_omp_ordered (c_parser_omp_structured_block (parser));
8150 { section-sequence }
8153 section-directive[opt] structured-block
8154 section-sequence section-directive structured-block */
8157 c_parser_omp_sections_scope (c_parser *parser)
8160 bool error_suppress = false;
8163 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
8165 /* Avoid skipping until the end of the block. */
8166 parser->error = false;
8170 stmt = push_stmt_list ();
8172 loc = c_parser_peek_token (parser)->location;
8173 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
8175 substmt = push_stmt_list ();
8179 c_parser_statement (parser);
8181 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
8183 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8185 if (c_parser_next_token_is (parser, CPP_EOF))
8189 substmt = pop_stmt_list (substmt);
8190 substmt = build1 (OMP_SECTION, void_type_node, substmt);
8191 SET_EXPR_LOCATION (substmt, loc);
8197 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8199 if (c_parser_next_token_is (parser, CPP_EOF))
8202 loc = c_parser_peek_token (parser)->location;
8203 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
8205 c_parser_consume_pragma (parser);
8206 c_parser_skip_to_pragma_eol (parser);
8207 error_suppress = false;
8209 else if (!error_suppress)
8211 error ("expected %<#pragma omp section%> or %<}%>");
8212 error_suppress = true;
8215 substmt = c_parser_omp_structured_block (parser);
8216 substmt = build1 (OMP_SECTION, void_type_node, substmt);
8217 SET_EXPR_LOCATION (substmt, loc);
8220 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
8221 "expected %<#pragma omp section%> or %<}%>");
8223 substmt = pop_stmt_list (stmt);
8225 stmt = make_node (OMP_SECTIONS);
8226 TREE_TYPE (stmt) = void_type_node;
8227 OMP_SECTIONS_BODY (stmt) = substmt;
8229 return add_stmt (stmt);
8233 # pragma omp sections sections-clause[optseq] newline
8237 #define OMP_SECTIONS_CLAUSE_MASK \
8238 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8239 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8240 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8241 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8242 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8245 c_parser_omp_sections (c_parser *parser)
8247 tree block, clauses, ret;
8249 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
8250 "#pragma omp sections");
8252 block = c_begin_compound_stmt (true);
8253 ret = c_parser_omp_sections_scope (parser);
8255 OMP_SECTIONS_CLAUSES (ret) = clauses;
8256 block = c_end_compound_stmt (block, true);
8263 # pragma parallel parallel-clause new-line
8264 # pragma parallel for parallel-for-clause new-line
8265 # pragma parallel sections parallel-sections-clause new-line
8268 #define OMP_PARALLEL_CLAUSE_MASK \
8269 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8270 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8271 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8272 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8273 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8274 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8275 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8276 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8279 c_parser_omp_parallel (c_parser *parser)
8281 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
8282 const char *p_name = "#pragma omp parallel";
8283 tree stmt, clauses, par_clause, ws_clause, block;
8284 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
8286 if (c_parser_next_token_is_keyword (parser, RID_FOR))
8288 c_parser_consume_token (parser);
8289 p_kind = PRAGMA_OMP_PARALLEL_FOR;
8290 p_name = "#pragma omp parallel for";
8291 mask |= OMP_FOR_CLAUSE_MASK;
8292 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8294 else if (c_parser_next_token_is (parser, CPP_NAME))
8296 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8297 if (strcmp (p, "sections") == 0)
8299 c_parser_consume_token (parser);
8300 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
8301 p_name = "#pragma omp parallel sections";
8302 mask |= OMP_SECTIONS_CLAUSE_MASK;
8303 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8307 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
8311 case PRAGMA_OMP_PARALLEL:
8312 block = c_begin_omp_parallel ();
8313 c_parser_statement (parser);
8314 stmt = c_finish_omp_parallel (clauses, block);
8317 case PRAGMA_OMP_PARALLEL_FOR:
8318 block = c_begin_omp_parallel ();
8319 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
8320 stmt = c_parser_omp_for_loop (parser);
8322 OMP_FOR_CLAUSES (stmt) = ws_clause;
8323 stmt = c_finish_omp_parallel (par_clause, block);
8324 OMP_PARALLEL_COMBINED (stmt) = 1;
8327 case PRAGMA_OMP_PARALLEL_SECTIONS:
8328 block = c_begin_omp_parallel ();
8329 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
8330 stmt = c_parser_omp_sections_scope (parser);
8332 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
8333 stmt = c_finish_omp_parallel (par_clause, block);
8334 OMP_PARALLEL_COMBINED (stmt) = 1;
8345 # pragma omp single single-clause[optseq] new-line
8349 #define OMP_SINGLE_CLAUSE_MASK \
8350 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8351 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8352 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8353 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8356 c_parser_omp_single (c_parser *parser)
8358 tree stmt = make_node (OMP_SINGLE);
8359 TREE_TYPE (stmt) = void_type_node;
8361 OMP_SINGLE_CLAUSES (stmt)
8362 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
8363 "#pragma omp single");
8364 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
8366 return add_stmt (stmt);
8370 /* Main entry point to parsing most OpenMP pragmas. */
8373 c_parser_omp_construct (c_parser *parser)
8375 enum pragma_kind p_kind;
8379 loc = c_parser_peek_token (parser)->location;
8380 p_kind = c_parser_peek_token (parser)->pragma_kind;
8381 c_parser_consume_pragma (parser);
8383 /* For all constructs below except #pragma omp atomic
8384 MUST_NOT_THROW catch handlers are needed when exceptions
8386 if (p_kind != PRAGMA_OMP_ATOMIC)
8387 c_maybe_initialize_eh ();
8391 case PRAGMA_OMP_ATOMIC:
8392 c_parser_omp_atomic (parser);
8394 case PRAGMA_OMP_CRITICAL:
8395 stmt = c_parser_omp_critical (parser);
8397 case PRAGMA_OMP_FOR:
8398 stmt = c_parser_omp_for (parser);
8400 case PRAGMA_OMP_MASTER:
8401 stmt = c_parser_omp_master (parser);
8403 case PRAGMA_OMP_ORDERED:
8404 stmt = c_parser_omp_ordered (parser);
8406 case PRAGMA_OMP_PARALLEL:
8407 stmt = c_parser_omp_parallel (parser);
8409 case PRAGMA_OMP_SECTIONS:
8410 stmt = c_parser_omp_sections (parser);
8412 case PRAGMA_OMP_SINGLE:
8413 stmt = c_parser_omp_single (parser);
8420 SET_EXPR_LOCATION (stmt, loc);
8425 # pragma omp threadprivate (variable-list) */
8428 c_parser_omp_threadprivate (c_parser *parser)
8432 c_parser_consume_pragma (parser);
8433 vars = c_parser_omp_var_list_parens (parser, 0, NULL);
8435 if (!targetm.have_tls)
8436 sorry ("threadprivate variables not supported in this target");
8438 /* Mark every variable in VARS to be assigned thread local storage. */
8439 for (t = vars; t; t = TREE_CHAIN (t))
8441 tree v = TREE_PURPOSE (t);
8443 /* If V had already been marked threadprivate, it doesn't matter
8444 whether it had been used prior to this point. */
8445 if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
8446 error ("%qE declared %<threadprivate%> after first use", v);
8447 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
8448 error ("automatic variable %qE cannot be %<threadprivate%>", v);
8449 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
8450 error ("%<threadprivate%> %qE has incomplete type", v);
8453 if (! DECL_THREAD_LOCAL_P (v))
8455 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
8456 /* If rtl has been already set for this var, call
8457 make_decl_rtl once again, so that encode_section_info
8458 has a chance to look at the new decl flags. */
8459 if (DECL_RTL_SET_P (v))
8462 C_DECL_THREADPRIVATE_P (v) = 1;
8466 c_parser_skip_to_pragma_eol (parser);
8470 /* Parse a single source file. */
8475 /* Use local storage to begin. If the first token is a pragma, parse it.
8476 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8477 which will cause garbage collection. */
8480 memset (&tparser, 0, sizeof tparser);
8481 the_parser = &tparser;
8483 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
8484 c_parser_pragma_pch_preprocess (&tparser);
8486 the_parser = GGC_NEW (c_parser);
8487 *the_parser = tparser;
8489 c_parser_translation_unit (the_parser);
8493 /* APPLE LOCAL begin radar 5732232 - blocks (C++ ce) */
8495 /* APPLE LOCAL begin radar 6300081 */
8497 /* This function builds a "generic" block struct type, to be passed
8498 into the debug information for blocks pointers, to allow gdb to
8499 find the actual function pointer for the block. Any time the Blocks
8500 structure layout changes, this may also need to change.
8502 Currently a block pointer is a pointer to a __block_literal_n struct,
8503 the third field of which is a pointer to a __block_descriptor struct,
8504 whose third field is the function pointer. There are other fields as
8505 well, but these are the ones gdb needs to know about to find the
8506 function pointer. Therefore a generic block struct currently looks
8509 struct __block_literal_generic
8514 void (*__FuncPtr)(void *);
8515 struct __block_descriptor
8517 unsigned long int reserved;
8518 unsigned long int Size;
8522 IF AT ANY TIME THE STRUCTURE OF A __BLOCK_LITERAL_N CHANGES, THIS
8523 MUST BE CHANGED ALSO!!
8528 /* APPLE LOCAL radar 6353006 */
8529 c_build_generic_block_struct_type (void)
8531 tree field_decl_chain;
8533 tree block_struct_type;
8535 push_to_top_level ();
8536 block_struct_type = start_struct (RECORD_TYPE,
8537 get_identifier ("__block_literal_generic"));
8539 field_decl = build_decl (FIELD_DECL, get_identifier ("__isa"), ptr_type_node);
8540 field_decl_chain = field_decl;
8542 field_decl = build_decl (FIELD_DECL, get_identifier ("__flags"),
8544 chainon (field_decl_chain, field_decl);
8546 field_decl = build_decl (FIELD_DECL, get_identifier ("__reserved"),
8548 chainon (field_decl_chain, field_decl);
8550 /* void *__FuncPtr; */
8551 field_decl = build_decl (FIELD_DECL, get_identifier ("__FuncPtr"), ptr_type_node);
8552 chainon (field_decl_chain, field_decl);
8554 field_decl = build_decl (FIELD_DECL, get_identifier ("__descriptor"),
8555 build_block_descriptor_type (false));
8556 chainon (field_decl_chain, field_decl);
8558 TYPE_BLOCK_IMPL_STRUCT (block_struct_type) = 1;
8559 finish_struct (block_struct_type, field_decl_chain, NULL_TREE);
8560 pop_from_top_level ();
8561 return block_struct_type;
8563 /* APPLE LOCAL end radar 6300081 */
8565 /* APPLE LOCAL begin radar 5847213 - radar 6329245 */
8566 /** build_block_struct_type -
8567 struct __block_literal_n {
8568 void *__isa; // initialized to &_NSConcreteStackBlock or &_NSConcreteGlobalBlock
8572 struct __block_descriptor {
8573 unsigned long int reserved; // NULL
8574 unsigned long int Size; // sizeof(struct __block_literal_n)
8576 // optional helper functions
8577 void *CopyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE
8578 void *DestroyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE
8581 // imported variables
8582 int x; // ref variable list ...
8583 int *y; // byref variable list
8587 build_block_struct_type (struct block_sema_info * block_impl)
8589 tree field_decl_chain, field_decl, chain;
8591 static int unique_count;
8592 tree block_struct_type;
8594 /* Check and see if this block is required to have a Copy/Dispose
8595 helper function. If yes, set BlockHasCopyDispose to TRUE. */
8596 for (chain = block_impl->block_ref_decl_list; chain;
8597 chain = TREE_CHAIN (chain))
8598 if (block_requires_copying (TREE_VALUE (chain)))
8600 block_impl->BlockHasCopyDispose = TRUE;
8604 /* Further check to see that we have __block variables which require
8605 Copy/Dispose helpers. */
8606 for (chain = block_impl->block_byref_decl_list; chain;
8607 chain = TREE_CHAIN (chain))
8608 if (COPYABLE_BYREF_LOCAL_VAR (TREE_VALUE (chain)))
8610 block_impl->BlockHasCopyDispose = TRUE;
8614 sprintf(buffer, "__block_literal_%d", ++unique_count);
8615 push_to_top_level ();
8616 block_struct_type = start_struct (RECORD_TYPE, get_identifier (buffer));
8619 field_decl = build_decl (FIELD_DECL, get_identifier ("__isa"), ptr_type_node);
8620 field_decl_chain = field_decl;
8623 field_decl = build_decl (FIELD_DECL, get_identifier ("__flags"),
8625 chainon (field_decl_chain, field_decl);
8627 /* int __reserved */
8628 field_decl = build_decl (FIELD_DECL, get_identifier ("__reserved"),
8630 chainon (field_decl_chain, field_decl);
8632 /* void *__FuncPtr; */
8633 field_decl = build_decl (FIELD_DECL, get_identifier ("__FuncPtr"), ptr_type_node);
8634 chainon (field_decl_chain, field_decl);
8636 /* struct __block_descriptor *__descriptor */
8637 field_decl = build_decl (FIELD_DECL, get_identifier ("__descriptor"),
8638 build_block_descriptor_type (block_impl->BlockHasCopyDispose));
8639 chainon (field_decl_chain, field_decl);
8641 if (block_impl->BlockHasCopyDispose)
8643 /* If inner block of a nested block has BlockHasCopyDispose, so
8644 does its outer block. */
8645 if (block_impl->prev_block_info)
8646 block_impl->prev_block_info->BlockHasCopyDispose = TRUE;
8649 /* int x; // ref variable list ... */
8650 for (chain = block_impl->block_ref_decl_list; chain; chain = TREE_CHAIN (chain))
8652 tree p = TREE_VALUE (chain);
8653 /* Note! const-ness of copied in variable must not be carried over to the
8654 type of the synthesized struct field. It prevents to assign to this
8655 field when copy constructor is synthesized. */
8656 field_decl = build_decl (FIELD_DECL, DECL_NAME (p),
8657 c_build_qualified_type (TREE_TYPE (p),
8659 chainon (field_decl_chain, field_decl);
8662 /* int *y; // byref variable list */
8663 for (chain = block_impl->block_byref_decl_list; chain; chain = TREE_CHAIN (chain))
8665 tree p = TREE_VALUE (chain);
8666 field_decl = build_decl (FIELD_DECL, DECL_NAME (p),
8668 chainon (field_decl_chain, field_decl);
8670 pop_from_top_level ();
8671 finish_struct (block_struct_type, field_decl_chain, NULL_TREE);
8672 return block_struct_type;
8675 /** build_descriptor_block_decl -
8676 This routine builds a static block_descriptior variable of type:
8677 struct __block_descriptor; and initializes it to:
8678 {0, sizeof(struct literal_block_n),
8679 copy_helper_block_1, // only if block BLOCK_HAS_COPY_DISPOSE
8680 destroy_helper_block_1, // only if block BLOCK_HAS_COPY_DISPOSE
8684 build_descriptor_block_decl (tree block_struct_type, struct block_sema_info *block_impl)
8686 extern tree create_tmp_var_raw (tree, const char *);
8687 static int desc_unique_count;
8689 tree helper_addr, fields;
8690 tree decl, constructor, initlist;
8693 tree descriptor_type =
8694 TREE_TYPE (build_block_descriptor_type (block_impl->BlockHasCopyDispose));
8696 sprintf (name, "__block_descriptor_tmp_%d", ++desc_unique_count);
8697 decl = create_tmp_var_raw (descriptor_type, name);
8698 DECL_CONTEXT (decl) = NULL_TREE;
8699 DECL_ARTIFICIAL (decl) = 1;
8701 /* Initialize "reserved" field to 0 for now. */
8702 fields = TYPE_FIELDS (descriptor_type);
8703 initlist = build_tree_list (fields, build_int_cst (long_unsigned_type_node, 0));
8704 fields = TREE_CHAIN (fields);
8706 /* Initialize "Size" field. */
8707 size = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (block_struct_type));
8708 initlist = tree_cons (fields,
8709 build_int_cst (long_unsigned_type_node, size),
8712 if (block_impl->BlockHasCopyDispose)
8714 /* Initialize "CopyFuncPtr" and "DestroyFuncPtr" fields. */
8715 /* Helpers were previously generated completeley as a nested
8716 function (and context was required for code gen.) But they are not,
8717 so context must be set to NULL so initialization logic does not complain. */
8718 DECL_CONTEXT (block_impl->copy_helper_func_decl) = NULL_TREE;
8719 fields = TREE_CHAIN (fields);
8720 helper_addr = build_fold_addr_expr (block_impl->copy_helper_func_decl);
8721 helper_addr = convert (ptr_type_node, helper_addr);
8722 initlist = tree_cons (fields, helper_addr, initlist);
8723 DECL_CONTEXT (block_impl->destroy_helper_func_decl) = NULL_TREE;
8724 fields = TREE_CHAIN (fields);
8725 helper_addr = build_fold_addr_expr (block_impl->destroy_helper_func_decl);
8726 helper_addr = convert (ptr_type_node, helper_addr);
8727 initlist = tree_cons (fields, helper_addr, initlist);
8729 constructor = build_constructor_from_list (descriptor_type,
8730 nreverse (initlist));
8731 TREE_CONSTANT (constructor) = 1;
8732 TREE_STATIC (constructor) = 1;
8733 TREE_READONLY (constructor) = 1;
8734 DECL_INITIAL (decl) = constructor;
8735 exp = build_stmt (DECL_EXPR, decl);
8736 bind = build3 (BIND_EXPR, void_type_node, decl, exp, NULL);
8737 TREE_SIDE_EFFECTS (bind) = 1;
8739 TREE_PUBLIC (decl) = 0;
8740 TREE_STATIC (decl) = 1;
8741 finish_decl (decl, constructor, NULL_TREE);
8746 build_block_struct_initlist - builds the initializer list:
8747 { &_NSConcreteStackBlock or &_NSConcreteGlobalBlock // __isa,
8748 BLOCK_USE_STRET | BLOCK_HAS_COPY_DISPOSE | BLOCK_IS_GLOBAL // __flags,
8750 &helper_1, // __FuncPtr,
8751 &static_descriptor_variable // __descriptor,
8752 x, // user variables.
8758 build_block_struct_initlist (tree block_struct_type,
8759 struct block_sema_info *block_impl)
8761 tree initlist, helper_addr;
8763 /* APPLE LOCAL radar 7735196 */
8764 unsigned int flags = 0;
8765 static tree NSConcreteStackBlock_decl = NULL_TREE;
8766 static tree NSConcreteGlobalBlock_decl = NULL_TREE;
8767 tree descriptor_block_decl = build_descriptor_block_decl (block_struct_type, block_impl);
8769 if (block_impl->BlockHasCopyDispose)
8770 /* Note! setting of this flag merely indicates to the runtime that
8771 we have destroy_helper_block/copy_helper_block helper
8773 flags |= BLOCK_HAS_COPY_DISPOSE;
8774 /* APPLE LOCAL begin radar 7735196 */
8775 if (block_impl->return_type && aggregate_value_p(block_impl->return_type, 0))
8776 flags |= BLOCK_USE_STRET;
8777 /* APPLE LOCAL end 7735196 */
8779 fields = TYPE_FIELDS (block_struct_type);
8780 /* APPLE LOCAL begin radar 6230297 */
8781 if (!current_function_decl ||
8782 (block_impl->block_ref_decl_list == NULL_TREE &&
8783 block_impl->block_byref_decl_list == NULL_TREE))
8784 /* APPLE LOCAL end radar 6230297 */
8786 /* This is a global block. */
8787 /* Find an existing declaration for _NSConcreteGlobalBlock or declare
8788 extern void *_NSConcreteGlobalBlock; */
8789 if (NSConcreteGlobalBlock_decl == NULL_TREE)
8791 tree name_id = get_identifier("_NSConcreteGlobalBlock");
8792 NSConcreteGlobalBlock_decl = lookup_name (name_id);
8793 if (!NSConcreteGlobalBlock_decl)
8795 NSConcreteGlobalBlock_decl = build_decl (VAR_DECL, name_id, ptr_type_node);
8796 DECL_EXTERNAL (NSConcreteGlobalBlock_decl) = 1;
8797 TREE_PUBLIC (NSConcreteGlobalBlock_decl) = 1;
8798 pushdecl_top_level (NSConcreteGlobalBlock_decl);
8799 rest_of_decl_compilation (NSConcreteGlobalBlock_decl, 0, 0);
8802 /* APPLE LOCAL begin radar 6457359 */
8803 initlist = build_tree_list (fields,
8804 convert (ptr_type_node,
8805 build_fold_addr_expr (NSConcreteGlobalBlock_decl)));
8806 /* APPLE LOCAL end radar 6457359 */
8807 flags |= BLOCK_IS_GLOBAL;
8811 /* Find an existing declaration for _NSConcreteStackBlock or declare
8812 extern void *_NSConcreteStackBlock; */
8813 if (NSConcreteStackBlock_decl == NULL_TREE)
8815 tree name_id = get_identifier("_NSConcreteStackBlock");
8816 NSConcreteStackBlock_decl = lookup_name (name_id);
8817 if (!NSConcreteStackBlock_decl)
8819 NSConcreteStackBlock_decl = build_decl (VAR_DECL, name_id, ptr_type_node);
8820 DECL_EXTERNAL (NSConcreteStackBlock_decl) = 1;
8821 TREE_PUBLIC (NSConcreteStackBlock_decl) = 1;
8822 pushdecl_top_level (NSConcreteStackBlock_decl);
8823 rest_of_decl_compilation (NSConcreteStackBlock_decl, 0, 0);
8826 /* APPLE LOCAL begin radar 6457359 */
8827 initlist = build_tree_list (fields,
8828 convert (ptr_type_node,
8829 build_fold_addr_expr (NSConcreteStackBlock_decl)));
8830 /* APPLE LOCAL end radar 6457359 */
8832 fields = TREE_CHAIN (fields);
8835 initlist = tree_cons (fields,
8836 build_int_cst (integer_type_node, flags),
8838 fields = TREE_CHAIN (fields);
8841 initlist = tree_cons (fields,
8842 build_int_cst (integer_type_node, 0),
8844 fields = TREE_CHAIN (fields);
8847 helper_addr = build_fold_addr_expr (block_impl->helper_func_decl);
8848 helper_addr = convert (ptr_type_node, helper_addr);
8849 initlist = tree_cons (fields, helper_addr, initlist);
8850 fields = TREE_CHAIN (fields);
8853 /* APPLE LOCAL begin radar 6457359 */
8854 initlist = tree_cons (fields,
8855 build_fold_addr_expr (descriptor_block_decl),
8857 /* APPLE LOCAL end radar 6457359 */
8858 for (chain = block_impl->block_original_ref_decl_list; chain;
8859 chain = TREE_CHAIN (chain))
8861 tree y = TREE_VALUE (chain);
8863 fields = TREE_CHAIN (fields);
8864 initlist = tree_cons (fields, y, initlist);
8866 for (chain = block_impl->block_byref_decl_list; chain;
8867 chain = TREE_CHAIN (chain))
8869 tree y = lookup_name (DECL_NAME (TREE_VALUE (chain)));
8870 tree forwarding_expr;
8873 if (COPYABLE_BYREF_LOCAL_VAR (y))
8875 /* For variables declared __block, either the original one
8876 at the point of declaration or the imported version (which is
8877 initialized in the helper function's prologue) is used to
8878 initilize the byref variable field in the temporary. */
8879 if (TREE_CODE (TREE_TYPE (y)) != RECORD_TYPE)
8880 y = build_indirect_ref (y, "unary *");
8881 /* We will be using the __block_struct_variable.__forwarding as the
8883 forwarding_expr = build_component_ref (y, get_identifier ("__forwarding"));
8886 /* Global variable is always assumed passed by its address. */
8887 forwarding_expr = build_fold_addr_expr (y);
8888 fields = TREE_CHAIN (fields);
8889 initlist = tree_cons (fields, forwarding_expr, initlist);
8895 build_block_literal_tmp - This routine:
8897 1) builds block type:
8898 struct __block_literal_n {
8899 void *__isa; // initialized to &_NSConcreteStackBlock or &_NSConcreteGlobalBlock
8903 struct __block_descriptor {
8904 unsigned long int reserved; // NULL
8905 unsigned long int Size; // sizeof(struct Block_literal_1)
8907 // optional helper functions
8908 void *CopyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE
8909 void *DestroyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE
8912 // imported variables
8913 int x; // ref variable list ...
8914 int *y; // byref variable list
8917 2) build function prototype:
8918 double helper_1(struct __block_literal_n *ii, int z);
8920 3) build the temporary initialization:
8921 struct __block_literal_n I = {
8922 &_NSConcreteStackBlock or &_NSConcreteGlobalBlock // __isa,
8923 BLOCK_USE_STRET | BLOCK_HAS_COPY_DISPOSE | BLOCK_IS_GLOBAL // __flags,
8925 &helper_1, // __FuncPtr
8926 &static_descriptor_variable // __descriptor,
8927 x, // user variables.
8931 It return the temporary.
8935 build_block_literal_tmp (const char *name,
8936 struct block_sema_info * block_impl)
8938 extern tree create_tmp_var_raw (tree, const char *);
8939 tree block_holder_tmp_decl;
8940 tree constructor, initlist;
8942 tree block_struct_type = TREE_TYPE (block_impl->block_arg_ptr_type);
8943 /* APPLE LOCAL begin radar 6230297 */
8944 bool staticBlockTmp = (block_impl->block_ref_decl_list == NULL_TREE &&
8945 block_impl->block_byref_decl_list == NULL_TREE);
8948 block_holder_tmp_decl = create_tmp_var_raw (block_struct_type, name);
8949 /* Context will not be known until when the literal is synthesized.
8950 This is more so in the case of nested block literal blocks. */
8951 DECL_CONTEXT (block_holder_tmp_decl) = staticBlockTmp ? NULL_TREE
8952 : current_function_decl;
8953 /* In the new ABI, helper function decl. is the initializer for the
8954 descriptor variable which is always declared static. So, it must
8955 have no context; otherwise, gcc thinks that it requires trampoline! when
8956 address of this function is used as initializer. */
8957 DECL_CONTEXT (block_impl->helper_func_decl) = NULL_TREE;
8958 /* APPLE LOCAL end radar 6230297 */
8959 DECL_ARTIFICIAL (block_holder_tmp_decl) = 1;
8961 initlist = build_block_struct_initlist (block_struct_type,
8963 initlist = nreverse (initlist);
8964 constructor = build_constructor_from_list (block_struct_type,
8966 TREE_CONSTANT (constructor) = 1;
8967 TREE_STATIC (constructor) = 1;
8968 TREE_READONLY (constructor) = 1;
8969 DECL_INITIAL (block_holder_tmp_decl) = constructor;
8970 exp = build_stmt (DECL_EXPR, block_holder_tmp_decl);
8971 bind = build3 (BIND_EXPR, void_type_node, block_holder_tmp_decl, exp, NULL);
8972 TREE_SIDE_EFFECTS (bind) = 1;
8974 /* Temporary representing a global block is made global static. */
8975 /* APPLE LOCAL radar 6230297 */
8976 if (staticBlockTmp || global_bindings_p ()) {
8977 TREE_PUBLIC (block_holder_tmp_decl) = 0;
8978 TREE_STATIC (block_holder_tmp_decl) = 1;
8979 finish_decl (block_holder_tmp_decl, constructor, NULL_TREE);
8981 return block_holder_tmp_decl;
8983 /* APPLE LOCAL end radar 5847213 - radar 6329245 */
8986 clean_and_exit (tree block)
8988 pop_function_context ();
8989 free (finish_block (block));
8990 return error_mark_node;
8993 /** synth_copy_helper_block_func - This function synthesizes
8994 void copy_helper_block (struct block* _dest, struct block *_src) function.
8998 synth_copy_helper_block_func (struct block_sema_info * block_impl)
9000 tree stmt, chain, fnbody;
9001 tree dst_arg, src_arg;
9002 struct c_arg_info * arg_info;
9003 /* Set up: (struct block* _dest, struct block *_src) parameters. */
9004 dst_arg = build_decl (PARM_DECL, get_identifier ("_dst"),
9005 block_impl->block_arg_ptr_type);
9006 DECL_CONTEXT (dst_arg) = cur_block->copy_helper_func_decl;
9007 TREE_USED (dst_arg) = 1;
9008 DECL_ARG_TYPE (dst_arg) = block_impl->block_arg_ptr_type;
9009 src_arg = build_decl (PARM_DECL, get_identifier ("_src"),
9010 block_impl->block_arg_ptr_type);
9011 /* APPLE LOCAL radar 5847213 */
9012 DECL_CONTEXT (src_arg) = cur_block->copy_helper_func_decl;
9013 TREE_USED (src_arg) = 1;
9014 DECL_ARG_TYPE (src_arg) = block_impl->block_arg_ptr_type;
9015 arg_info = xcalloc (1, sizeof (struct c_arg_info));
9016 TREE_CHAIN (dst_arg) = src_arg;
9017 arg_info->parms = dst_arg;
9018 arg_info->types = tree_cons (NULL_TREE, block_impl->block_arg_ptr_type,
9019 tree_cons (NULL_TREE,
9020 block_impl->block_arg_ptr_type,
9022 /* function header synthesis. */
9023 push_function_context ();
9024 start_block_helper_function (cur_block->copy_helper_func_decl);
9025 store_parm_decls_from (arg_info);
9027 /* Body of the function. */
9028 stmt = c_begin_compound_stmt (true);
9029 for (chain = block_impl->block_ref_decl_list; chain;
9030 chain = TREE_CHAIN (chain))
9031 if (block_requires_copying (TREE_VALUE (chain)))
9033 /* APPLE LOCAL begin radar 6175959 */
9036 tree p = TREE_VALUE (chain);
9037 tree dst_block_component, src_block_component;
9038 dst_block_component = build_component_ref (build_indirect_ref (dst_arg, "->"),
9040 src_block_component = build_component_ref (build_indirect_ref (src_arg, "->"),
9043 if (TREE_CODE (TREE_TYPE (p)) == BLOCK_POINTER_TYPE)
9044 /* _Block_object_assign(&_dest->myImportedBlock, _src->myImportedClosure, BLOCK_FIELD_IS_BLOCK) */
9045 flag = BLOCK_FIELD_IS_BLOCK;
9047 /* _Block_object_assign(&_dest->myImportedBlock, _src->myImportedClosure, BLOCK_FIELD_IS_OBJECT) */
9048 flag = BLOCK_FIELD_IS_OBJECT;
9049 dst_block_component = build_fold_addr_expr (dst_block_component);
9050 call_exp = build_block_object_assign_call_exp (dst_block_component, src_block_component, flag);
9051 add_stmt (call_exp);
9052 /* APPLE LOCAL end radar 6175959 */
9055 /* For each __block declared variable must generate call to:
9056 _Block_object_assign(&_dest->myImportedBlock, _src->myImportedBlock, BLOCK_FIELD_IS_BYREF [|BLOCK_FIELD_IS_WEAK])
9058 for (chain = block_impl->block_byref_decl_list; chain;
9059 chain = TREE_CHAIN (chain))
9060 if (COPYABLE_BYREF_LOCAL_VAR (TREE_VALUE (chain)))
9062 int flag = BLOCK_FIELD_IS_BYREF;
9064 tree p = TREE_VALUE (chain);
9065 tree dst_block_component, src_block_component;
9066 dst_block_component = build_component_ref (build_indirect_ref (dst_arg, "->"),
9068 src_block_component = build_component_ref (build_indirect_ref (src_arg, "->"),
9071 /* _Block_object_assign(&_dest->myImportedClosure, _src->myImportedClosure, BLOCK_FIELD_IS_BYREF [|BLOCK_FIELD_IS_WEAK]) */
9072 if (COPYABLE_WEAK_BLOCK (p))
9073 flag |= BLOCK_FIELD_IS_WEAK;
9075 dst_block_component = build_fold_addr_expr (dst_block_component);
9076 call_exp = build_block_object_assign_call_exp (dst_block_component, src_block_component, flag);
9077 add_stmt (call_exp);
9080 fnbody = c_end_compound_stmt (stmt, true);
9083 pop_function_context ();
9088 synth_destroy_helper_block_func (struct block_sema_info * block_impl)
9090 tree stmt, chain, fnbody;
9092 struct c_arg_info * arg_info;
9093 /* Set up: (struct block *_src) parameter. */
9094 src_arg = build_decl (PARM_DECL, get_identifier ("_src"),
9095 block_impl->block_arg_ptr_type);
9096 TREE_USED (src_arg) = 1;
9097 DECL_ARG_TYPE (src_arg) = block_impl->block_arg_ptr_type;
9098 arg_info = xcalloc (1, sizeof (struct c_arg_info));
9099 arg_info->parms = src_arg;
9100 arg_info->types = tree_cons (NULL_TREE, block_impl->block_arg_ptr_type,
9103 /* function header synthesis. */
9104 push_function_context ();
9105 start_block_helper_function (cur_block->destroy_helper_func_decl);
9106 store_parm_decls_from (arg_info);
9108 /* Body of the function. */
9109 stmt = c_begin_compound_stmt (true);
9110 for (chain = block_impl->block_ref_decl_list; chain;
9111 chain = TREE_CHAIN (chain))
9112 if (block_requires_copying (TREE_VALUE (chain)))
9116 tree p = TREE_VALUE (chain);
9117 tree src_block_component;
9118 src_block_component = build_component_ref (build_indirect_ref (src_arg, "->"),
9121 if (TREE_CODE (TREE_TYPE (p)) == BLOCK_POINTER_TYPE)
9122 /* _Block_object_dispose(_src->imported_object_0, BLOCK_FIELD_IS_BLOCK); */
9123 flag = BLOCK_FIELD_IS_BLOCK;
9125 /* _Block_object_dispose(_src->imported_object_0, BLOCK_FIELD_IS_OBJECT); */
9126 flag = BLOCK_FIELD_IS_OBJECT;
9127 rel_exp = build_block_object_dispose_call_exp (src_block_component, flag);
9131 /* For each __block declared variable must generate call to:
9132 _Block_object_dispose(_src->myImportedClosure, BLOCK_FIELD_IS_BYREF[|BLOCK_FIELD_IS_WEAK])
9134 for (chain = block_impl->block_byref_decl_list; chain;
9135 chain = TREE_CHAIN (chain))
9136 if (COPYABLE_BYREF_LOCAL_VAR (TREE_VALUE (chain)))
9139 int flag = BLOCK_FIELD_IS_BYREF;
9140 tree p = TREE_VALUE (chain);
9141 tree src_block_component;
9143 src_block_component = build_component_ref (build_indirect_ref (src_arg, "->"),
9145 if (COPYABLE_WEAK_BLOCK (p))
9146 flag |= BLOCK_FIELD_IS_WEAK;
9147 /* _Block_object_dispose(_src->myImportedClosure, BLOCK_FIELD_IS_BYREF[|BLOCK_FIELD_IS_WEAK]) */
9148 call_exp = build_block_object_dispose_call_exp (src_block_component, flag);
9149 add_stmt (call_exp);
9152 fnbody = c_end_compound_stmt (stmt, true);
9155 pop_function_context ();
9159 /* Parse a block-id.
9164 specifier-qualifier-list block-declarator
9166 Returns the DECL specified or implied. */
9169 c_parser_block_id (c_parser* parser)
9171 struct c_declspecs *specs = build_null_declspecs ();
9172 struct c_declarator *declarator;
9175 c_parser_declspecs (parser, specs, false, true, true);
9176 if (!specs->declspecs_seen_p)
9178 c_parser_error (parser, "expected specifier-qualifier-list");
9181 pending_xref_error ();
9182 finish_declspecs (specs);
9183 declarator = c_parser_declarator (parser, specs->type_seen_p,
9184 C_DTR_BLOCK, &dummy);
9185 if (declarator == NULL)
9188 return grokblockdecl (specs, declarator);
9191 /* Parse a block-literal-expr.
9196 ^ parameter-declation-clause exception-specification [opt] compound-statement
9197 ^ block-id compound-statement
9199 It synthesizes the helper function for later generation and builds
9200 the necessary data to represent the block literal where it is
9203 c_parser_block_literal_expr (c_parser* parser)
9206 static int global_unique_count;
9207 int unique_count = ++global_unique_count;
9208 tree block_helper_function_decl;
9209 tree expr, body, type, arglist = void_list_node, ftype;
9210 tree self_arg, stmt;
9211 struct c_arg_info *args = NULL;
9212 tree arg_type = void_list_node;
9213 struct block_sema_info *block_impl;
9215 bool open_paren_seen = false;
9217 tree fnbody, typelist;
9218 tree helper_function_type;
9220 /* APPLE LOCAL radar 6185344 */
9221 tree declared_block_return_type = NULL_TREE;
9222 /* APPLE LOCAL radar 6237713 */
9223 tree attributes = NULL_TREE;
9225 c_parser_consume_token (parser); /* eat '^' */
9227 /* APPLE LOCAL begin radar 6237713 */
9228 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
9229 attributes = c_parser_attributes (parser);
9230 /* APPLE LOCAL end radar 6237713 */
9232 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9234 /* Parse the optional argument list */
9235 c_parser_consume_token (parser);
9236 /* Open the scope to collect parameter decls */
9238 args = c_parser_parms_declarator (parser, true, NULL_TREE);
9239 /* Check for args as it might be NULL due to error. */
9242 arglist = args->parms;
9243 arg_type = args->types;
9248 return error_mark_node;
9250 open_paren_seen = true;
9253 else if (c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
9255 /* Parse user declared return type. */
9258 /* APPLE LOCAL begin radar 6237713 */
9261 warning (0, "attributes before block type are ignored");
9262 attributes = NULL_TREE;
9264 /* APPLE LOCAL end radar 6237713 */
9266 decl = c_parser_block_id (parser);
9268 if (decl && decl != error_mark_node)
9270 arg_type = TYPE_ARG_TYPES (TREE_TYPE (decl));
9271 arglist = DECL_ARGUMENTS (decl);
9272 declared_block_return_type = TREE_TYPE (TREE_TYPE (decl));
9276 block = begin_block ();
9278 cur_block->arg_info = NULL;
9279 if (declared_block_return_type)
9281 cur_block->return_type = TYPE_MAIN_VARIANT (declared_block_return_type);
9282 cur_block->block_has_return_type = true;
9285 cur_block->return_type = NULL_TREE;
9288 cur_block->arg_info = args;
9290 cur_block->arg_info = xcalloc (1, sizeof (struct c_arg_info));
9292 if (declared_block_return_type)
9294 cur_block->arg_info->parms = arglist;
9295 cur_block->arg_info->types = arg_type;
9298 /* Must also build hidden parameter .block_descriptor added to the helper
9299 function, even though we do not know its type yet. */
9300 /* APPLE LOCAL radar 6404979 */
9301 self_arg = build_decl (PARM_DECL, get_identifier (".block_descriptor"),
9303 TREE_USED (self_arg) = 1; /* Prevent unused parameter '.block_descriptor' warning. */
9304 TREE_CHAIN (self_arg) = cur_block->arg_info->parms;
9305 cur_block->arg_info->types = tree_cons (NULL_TREE, ptr_type_node, arg_type);
9306 cur_block->arg_info->parms = self_arg;
9308 /* APPLE LOCAL begin radar 6185344 */
9309 /* Build the declaration of the helper function (if we do not know its result
9310 type yet, assume it is 'void'. If user provided it, use it).
9311 Treat this as a nested function and use nested function infrastructure for
9314 ftype = build_function_type ((!cur_block->block_has_return_type
9315 ? void_type_node : cur_block->return_type),
9316 cur_block->arg_info->types);
9317 /* APPLE LOCAL end radar 6185344 */
9318 /* APPLE LOCAL radar 6160536 - radar 6411649 */
9319 block_helper_function_decl = build_helper_func_decl (build_block_helper_name (0),
9321 DECL_CONTEXT (block_helper_function_decl) = current_function_decl;
9322 cur_block->helper_func_decl = block_helper_function_decl;
9324 push_function_context ();
9325 start_block_helper_function (cur_block->helper_func_decl);
9326 /* Set block's scope to the scope of the helper function's main body.
9327 This is primarily used when nested blocks are declared. */
9328 /* FIXME: Name of objc_get_current_scope needs to get changed. */
9329 cur_block->the_scope = (struct c_scope*)objc_get_current_scope ();
9331 /* Enter parameter list to the scope of the helper function. */
9332 store_parm_decls_from (cur_block->arg_info);
9334 /* APPLE LOCAL begin radar 6237713 */
9335 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
9336 attributes = c_parser_attributes (parser);
9337 /* APPLE LOCAL radar 6246527 */
9338 any_recognized_block_attribute (attributes);
9339 decl_attributes (&cur_block->helper_func_decl, attributes, 0);
9340 /* APPLE LOCAL end radar 6237713 */
9342 /* Start parsing body or expression part of the block literal. */
9343 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) {
9344 tree save_c_break_label = c_break_label;
9345 tree save_c_cont_label = c_cont_label;
9346 /* Indicate no valid break/continue context by setting these variables
9347 to some non-null, non-label value. We'll notice and emit the proper
9348 error message in c_finish_bc_stmt. */
9349 c_break_label = c_cont_label = size_zero_node;
9350 c_parser_consume_token (parser); /* Consure '{'. */
9351 stmt = c_begin_compound_stmt (true);
9352 c_parser_compound_statement_nostart (parser);
9353 c_cont_label = save_c_cont_label;
9354 c_break_label = save_c_break_label;
9359 stmt = c_begin_compound_stmt (true);
9360 error ("blocks require { }");
9361 expr = c_parser_cast_expression (parser, NULL);
9363 if (body == error_mark_node)
9364 return clean_and_exit (block);
9366 if (cur_block->return_type)
9368 error ("return not allowed in block expression literal");
9369 return clean_and_exit (block);
9371 else if (!open_paren_seen)
9373 error ("argument list is required for block expression literals");
9374 return clean_and_exit (block);
9378 tree restype = TYPE_MAIN_VARIANT (TREE_TYPE (body));
9381 TREE_TYPE (current_function_decl)
9382 = build_function_type (restype,
9383 TYPE_ARG_TYPES (TREE_TYPE (current_function_decl)));
9384 TREE_TYPE (DECL_RESULT (current_function_decl)) = restype;
9385 relayout_decl (DECL_RESULT (current_function_decl));
9386 cur_block->return_type = restype;
9390 cur_block->block_arg_ptr_type =
9391 build_pointer_type (build_block_struct_type (cur_block));
9393 restype = !cur_block->return_type ? void_type_node
9394 : cur_block->return_type;
9395 if (restype == error_mark_node)
9396 return clean_and_exit (block);
9398 /* Now that we know type of the hidden .block_descriptor argument, fix its type. */
9399 TREE_TYPE (self_arg) = cur_block->block_arg_ptr_type;
9400 DECL_ARG_TYPE (self_arg) = cur_block->block_arg_ptr_type;
9402 /* The DECL_RESULT should already have the correct type by now. */
9403 gcc_assert (TREE_TYPE (DECL_RESULT (current_function_decl))
9406 cur_block->block_body = stmt;
9407 block_build_prologue (cur_block);
9409 fnbody = c_end_compound_stmt (stmt, true);
9412 /* We are done parsing of the block body. Return type of block is now known.
9413 We also know all we need to know about the helper function. So, fix its
9415 /* We moved this here because for global blocks, helper function body is
9416 not nested and is gimplified in call to finish_function() and return type
9417 of the function must be correct. */
9418 ftype = build_function_type (restype, arg_type);
9419 /* Declare helper function; as in:
9420 double helper_1(struct block_1 *ii, int z); */
9421 typelist = TYPE_ARG_TYPES (ftype);
9422 /* (struct block_1 *ii, int z, ...) */
9423 typelist = tree_cons (NULL_TREE, cur_block->block_arg_ptr_type,
9425 helper_function_type = build_function_type (TREE_TYPE (ftype), typelist);
9426 TREE_TYPE (cur_block->helper_func_decl) = helper_function_type;
9428 pop_function_context ();
9430 /* Build the declaration for copy_helper_block and destroy_helper_block
9431 helper functions for later use. */
9433 if (cur_block->BlockHasCopyDispose)
9435 /* void copy_helper_block (struct block*, struct block *); */
9436 tree s_ftype = build_function_type (void_type_node,
9437 tree_cons (NULL_TREE, cur_block->block_arg_ptr_type,
9438 tree_cons (NULL_TREE,
9439 cur_block->block_arg_ptr_type,
9441 sprintf (name, "__copy_helper_block_%d", unique_count);
9442 cur_block->copy_helper_func_decl =
9443 build_helper_func_decl (get_identifier (name), s_ftype);
9444 synth_copy_helper_block_func (cur_block);
9446 /* void destroy_helper_block (struct block*); */
9447 s_ftype = build_function_type (void_type_node,
9448 tree_cons (NULL_TREE,
9449 cur_block->block_arg_ptr_type, void_list_node));
9450 sprintf (name, "__destroy_helper_block_%d", unique_count);
9451 cur_block->destroy_helper_func_decl =
9452 build_helper_func_decl (get_identifier (name), s_ftype);
9453 synth_destroy_helper_block_func (cur_block);
9456 block_impl = finish_block (block);
9458 /* Build unqiue name of the temporary used in code gen. */
9459 sprintf (name, "__block_holder_tmp_%d", unique_count);
9460 tmp = build_block_literal_tmp (name, block_impl);
9461 tmp = build_fold_addr_expr (tmp);
9462 type = build_block_pointer_type (ftype);
9463 expr = convert (type, convert (ptr_type_node, tmp));
9467 /* APPLE LOCAL end radar 5732232 - blocks (C++ ce) */
9469 #include "gt-c-parser.h"