re PR inline-asm/39059 (ICE with fixed-point type in inline-asm)
[gcc.git] / gcc / c-parser.c
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, 2007, 2008, 2009
4 Free Software Foundation, Inc.
5
6 Parser actions based on the old Bison parser; structure somewhat
7 influenced by and fragments based on the C++ parser.
8
9 This file is part of GCC.
10
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
14 version.
15
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
24
25 /* TODO:
26
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
29 of syntax accepted.
30
31 Add testcases covering every input symbol in every state in old and
32 new parsers.
33
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
36
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
39
40 #include "config.h"
41 #include "system.h"
42 #include "coretypes.h"
43 #include "tm.h"
44 #include "tree.h"
45 #include "rtl.h"
46 #include "langhooks.h"
47 #include "input.h"
48 #include "cpplib.h"
49 #include "timevar.h"
50 #include "c-pragma.h"
51 #include "c-tree.h"
52 #include "flags.h"
53 #include "output.h"
54 #include "toplev.h"
55 #include "ggc.h"
56 #include "c-common.h"
57 #include "vec.h"
58 #include "target.h"
59 #include "cgraph.h"
60
61 \f
62 /* Initialization routine for this file. */
63
64 void
65 c_parse_init (void)
66 {
67 /* The only initialization required is of the reserved word
68 identifiers. */
69 unsigned int i;
70 tree id;
71 int mask = 0;
72
73 mask |= D_CXXONLY;
74 if (!flag_isoc99)
75 mask |= D_C99;
76 if (flag_no_asm)
77 {
78 mask |= D_ASM | D_EXT;
79 if (!flag_isoc99)
80 mask |= D_EXT89;
81 }
82 if (!c_dialect_objc ())
83 mask |= D_OBJC | D_CXX_OBJC;
84
85 ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
86 for (i = 0; i < num_c_common_reswords; i++)
87 {
88 /* If a keyword is disabled, do not enter it into the table
89 and so create a canonical spelling that isn't a keyword. */
90 if (c_common_reswords[i].disable & mask)
91 {
92 if (warn_cxx_compat
93 && (c_common_reswords[i].disable & D_CXXWARN))
94 {
95 id = get_identifier (c_common_reswords[i].word);
96 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
97 C_IS_RESERVED_WORD (id) = 1;
98 }
99 continue;
100 }
101
102 id = get_identifier (c_common_reswords[i].word);
103 C_SET_RID_CODE (id, c_common_reswords[i].rid);
104 C_IS_RESERVED_WORD (id) = 1;
105 ridpointers [(int) c_common_reswords[i].rid] = id;
106 }
107 }
108 \f
109 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
110 and the C parser. Unlike the C++ lexer, the parser structure
111 stores the lexer information instead of using a separate structure.
112 Identifiers are separated into ordinary identifiers, type names,
113 keywords and some other Objective-C types of identifiers, and some
114 look-ahead is maintained.
115
116 ??? It might be a good idea to lex the whole file up front (as for
117 C++). It would then be possible to share more of the C and C++
118 lexer code, if desired. */
119
120 /* The following local token type is used. */
121
122 /* A keyword. */
123 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
124
125 /* More information about the type of a CPP_NAME token. */
126 typedef enum c_id_kind {
127 /* An ordinary identifier. */
128 C_ID_ID,
129 /* An identifier declared as a typedef name. */
130 C_ID_TYPENAME,
131 /* An identifier declared as an Objective-C class name. */
132 C_ID_CLASSNAME,
133 /* Not an identifier. */
134 C_ID_NONE
135 } c_id_kind;
136
137 /* A single C token after string literal concatenation and conversion
138 of preprocessing tokens to tokens. */
139 typedef struct c_token GTY (())
140 {
141 /* The kind of token. */
142 ENUM_BITFIELD (cpp_ttype) type : 8;
143 /* If this token is a CPP_NAME, this value indicates whether also
144 declared as some kind of type. Otherwise, it is C_ID_NONE. */
145 ENUM_BITFIELD (c_id_kind) id_kind : 8;
146 /* If this token is a keyword, this value indicates which keyword.
147 Otherwise, this value is RID_MAX. */
148 ENUM_BITFIELD (rid) keyword : 8;
149 /* If this token is a CPP_PRAGMA, this indicates the pragma that
150 was seen. Otherwise it is PRAGMA_NONE. */
151 ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
152 /* The value associated with this token, if any. */
153 tree value;
154 /* The location at which this token was found. */
155 location_t location;
156 } c_token;
157
158 /* A parser structure recording information about the state and
159 context of parsing. Includes lexer information with up to two
160 tokens of look-ahead; more are not needed for C. */
161 typedef struct c_parser GTY(())
162 {
163 /* The look-ahead tokens. */
164 c_token tokens[2];
165 /* How many look-ahead tokens are available (0, 1 or 2). */
166 short tokens_avail;
167 /* True if a syntax error is being recovered from; false otherwise.
168 c_parser_error sets this flag. It should clear this flag when
169 enough tokens have been consumed to recover from the error. */
170 BOOL_BITFIELD error : 1;
171 /* True if we're processing a pragma, and shouldn't automatically
172 consume CPP_PRAGMA_EOL. */
173 BOOL_BITFIELD in_pragma : 1;
174 /* True if we're parsing the outermost block of an if statement. */
175 BOOL_BITFIELD in_if_block : 1;
176 /* True if we want to lex an untranslated string. */
177 BOOL_BITFIELD lex_untranslated_string : 1;
178 /* Objective-C specific parser/lexer information. */
179 BOOL_BITFIELD objc_pq_context : 1;
180 /* The following flag is needed to contextualize Objective-C lexical
181 analysis. In some cases (e.g., 'int NSObject;'), it is
182 undesirable to bind an identifier to an Objective-C class, even
183 if a class with that name exists. */
184 BOOL_BITFIELD objc_need_raw_identifier : 1;
185 } c_parser;
186
187
188 /* The actual parser and external interface. ??? Does this need to be
189 garbage-collected? */
190
191 static GTY (()) c_parser *the_parser;
192
193
194 /* Read in and lex a single token, storing it in *TOKEN. */
195
196 static void
197 c_lex_one_token (c_parser *parser, c_token *token)
198 {
199 timevar_push (TV_LEX);
200
201 token->type = c_lex_with_flags (&token->value, &token->location, NULL,
202 (parser->lex_untranslated_string
203 ? C_LEX_STRING_NO_TRANSLATE : 0));
204 token->id_kind = C_ID_NONE;
205 token->keyword = RID_MAX;
206 token->pragma_kind = PRAGMA_NONE;
207
208 switch (token->type)
209 {
210 case CPP_NAME:
211 {
212 tree decl;
213
214 bool objc_force_identifier = parser->objc_need_raw_identifier;
215 if (c_dialect_objc ())
216 parser->objc_need_raw_identifier = false;
217
218 if (C_IS_RESERVED_WORD (token->value))
219 {
220 enum rid rid_code = C_RID_CODE (token->value);
221
222 if (rid_code == RID_CXX_COMPAT_WARN)
223 {
224 warning_at (token->location,
225 OPT_Wc___compat,
226 "identifier %qs conflicts with C++ keyword",
227 IDENTIFIER_POINTER (token->value));
228 }
229 else if (c_dialect_objc ())
230 {
231 if (!objc_is_reserved_word (token->value)
232 && (!OBJC_IS_PQ_KEYWORD (rid_code)
233 || parser->objc_pq_context))
234 {
235 /* Return the canonical spelling for this keyword. */
236 token->value = ridpointers[(int) rid_code];
237 token->type = CPP_KEYWORD;
238 token->keyword = rid_code;
239 break;
240 }
241 }
242 else
243 {
244 token->type = CPP_KEYWORD;
245 token->keyword = rid_code;
246 break;
247 }
248 }
249
250 decl = lookup_name (token->value);
251 if (decl)
252 {
253 if (TREE_CODE (decl) == TYPE_DECL)
254 {
255 token->id_kind = C_ID_TYPENAME;
256 break;
257 }
258 }
259 else if (c_dialect_objc ())
260 {
261 tree objc_interface_decl = objc_is_class_name (token->value);
262 /* Objective-C class names are in the same namespace as
263 variables and typedefs, and hence are shadowed by local
264 declarations. */
265 if (objc_interface_decl
266 && (global_bindings_p ()
267 || (!objc_force_identifier && !decl)))
268 {
269 token->value = objc_interface_decl;
270 token->id_kind = C_ID_CLASSNAME;
271 break;
272 }
273 }
274 token->id_kind = C_ID_ID;
275 }
276 break;
277 case CPP_AT_NAME:
278 /* This only happens in Objective-C; it must be a keyword. */
279 token->type = CPP_KEYWORD;
280 token->keyword = C_RID_CODE (token->value);
281 break;
282 case CPP_COLON:
283 case CPP_COMMA:
284 case CPP_CLOSE_PAREN:
285 case CPP_SEMICOLON:
286 /* These tokens may affect the interpretation of any identifiers
287 following, if doing Objective-C. */
288 if (c_dialect_objc ())
289 parser->objc_need_raw_identifier = false;
290 break;
291 case CPP_PRAGMA:
292 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
293 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
294 token->value = NULL;
295 break;
296 default:
297 break;
298 }
299 timevar_pop (TV_LEX);
300 }
301
302 /* Return a pointer to the next token from PARSER, reading it in if
303 necessary. */
304
305 static inline c_token *
306 c_parser_peek_token (c_parser *parser)
307 {
308 if (parser->tokens_avail == 0)
309 {
310 c_lex_one_token (parser, &parser->tokens[0]);
311 parser->tokens_avail = 1;
312 }
313 return &parser->tokens[0];
314 }
315
316 /* Return true if the next token from PARSER has the indicated
317 TYPE. */
318
319 static inline bool
320 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
321 {
322 return c_parser_peek_token (parser)->type == type;
323 }
324
325 /* Return true if the next token from PARSER does not have the
326 indicated TYPE. */
327
328 static inline bool
329 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
330 {
331 return !c_parser_next_token_is (parser, type);
332 }
333
334 /* Return true if the next token from PARSER is the indicated
335 KEYWORD. */
336
337 static inline bool
338 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
339 {
340 return c_parser_peek_token (parser)->keyword == keyword;
341 }
342
343 /* Return true if TOKEN can start a type name,
344 false otherwise. */
345 static bool
346 c_token_starts_typename (c_token *token)
347 {
348 switch (token->type)
349 {
350 case CPP_NAME:
351 switch (token->id_kind)
352 {
353 case C_ID_ID:
354 return false;
355 case C_ID_TYPENAME:
356 return true;
357 case C_ID_CLASSNAME:
358 gcc_assert (c_dialect_objc ());
359 return true;
360 default:
361 gcc_unreachable ();
362 }
363 case CPP_KEYWORD:
364 switch (token->keyword)
365 {
366 case RID_UNSIGNED:
367 case RID_LONG:
368 case RID_SHORT:
369 case RID_SIGNED:
370 case RID_COMPLEX:
371 case RID_INT:
372 case RID_CHAR:
373 case RID_FLOAT:
374 case RID_DOUBLE:
375 case RID_VOID:
376 case RID_DFLOAT32:
377 case RID_DFLOAT64:
378 case RID_DFLOAT128:
379 case RID_BOOL:
380 case RID_ENUM:
381 case RID_STRUCT:
382 case RID_UNION:
383 case RID_TYPEOF:
384 case RID_CONST:
385 case RID_VOLATILE:
386 case RID_RESTRICT:
387 case RID_ATTRIBUTE:
388 case RID_FRACT:
389 case RID_ACCUM:
390 case RID_SAT:
391 return true;
392 default:
393 return false;
394 }
395 case CPP_LESS:
396 if (c_dialect_objc ())
397 return true;
398 return false;
399 default:
400 return false;
401 }
402 }
403
404 /* Return true if the next token from PARSER can start a type name,
405 false otherwise. */
406 static inline bool
407 c_parser_next_token_starts_typename (c_parser *parser)
408 {
409 c_token *token = c_parser_peek_token (parser);
410 return c_token_starts_typename (token);
411 }
412
413 /* Return true if TOKEN can start declaration specifiers, false
414 otherwise. */
415 static bool
416 c_token_starts_declspecs (c_token *token)
417 {
418 switch (token->type)
419 {
420 case CPP_NAME:
421 switch (token->id_kind)
422 {
423 case C_ID_ID:
424 return false;
425 case C_ID_TYPENAME:
426 return true;
427 case C_ID_CLASSNAME:
428 gcc_assert (c_dialect_objc ());
429 return true;
430 default:
431 gcc_unreachable ();
432 }
433 case CPP_KEYWORD:
434 switch (token->keyword)
435 {
436 case RID_STATIC:
437 case RID_EXTERN:
438 case RID_REGISTER:
439 case RID_TYPEDEF:
440 case RID_INLINE:
441 case RID_AUTO:
442 case RID_THREAD:
443 case RID_UNSIGNED:
444 case RID_LONG:
445 case RID_SHORT:
446 case RID_SIGNED:
447 case RID_COMPLEX:
448 case RID_INT:
449 case RID_CHAR:
450 case RID_FLOAT:
451 case RID_DOUBLE:
452 case RID_VOID:
453 case RID_DFLOAT32:
454 case RID_DFLOAT64:
455 case RID_DFLOAT128:
456 case RID_BOOL:
457 case RID_ENUM:
458 case RID_STRUCT:
459 case RID_UNION:
460 case RID_TYPEOF:
461 case RID_CONST:
462 case RID_VOLATILE:
463 case RID_RESTRICT:
464 case RID_ATTRIBUTE:
465 case RID_FRACT:
466 case RID_ACCUM:
467 case RID_SAT:
468 return true;
469 default:
470 return false;
471 }
472 case CPP_LESS:
473 if (c_dialect_objc ())
474 return true;
475 return false;
476 default:
477 return false;
478 }
479 }
480
481 /* Return true if the next token from PARSER can start declaration
482 specifiers, false otherwise. */
483 static inline bool
484 c_parser_next_token_starts_declspecs (c_parser *parser)
485 {
486 c_token *token = c_parser_peek_token (parser);
487 return c_token_starts_declspecs (token);
488 }
489
490 /* Return a pointer to the next-but-one token from PARSER, reading it
491 in if necessary. The next token is already read in. */
492
493 static c_token *
494 c_parser_peek_2nd_token (c_parser *parser)
495 {
496 if (parser->tokens_avail >= 2)
497 return &parser->tokens[1];
498 gcc_assert (parser->tokens_avail == 1);
499 gcc_assert (parser->tokens[0].type != CPP_EOF);
500 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
501 c_lex_one_token (parser, &parser->tokens[1]);
502 parser->tokens_avail = 2;
503 return &parser->tokens[1];
504 }
505
506 /* Consume the next token from PARSER. */
507
508 static void
509 c_parser_consume_token (c_parser *parser)
510 {
511 gcc_assert (parser->tokens_avail >= 1);
512 gcc_assert (parser->tokens[0].type != CPP_EOF);
513 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
514 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
515 if (parser->tokens_avail == 2)
516 parser->tokens[0] = parser->tokens[1];
517 parser->tokens_avail--;
518 }
519
520 /* Expect the current token to be a #pragma. Consume it and remember
521 that we've begun parsing a pragma. */
522
523 static void
524 c_parser_consume_pragma (c_parser *parser)
525 {
526 gcc_assert (!parser->in_pragma);
527 gcc_assert (parser->tokens_avail >= 1);
528 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
529 if (parser->tokens_avail == 2)
530 parser->tokens[0] = parser->tokens[1];
531 parser->tokens_avail--;
532 parser->in_pragma = true;
533 }
534
535 /* Update the globals input_location and in_system_header from
536 TOKEN. */
537 static inline void
538 c_parser_set_source_position_from_token (c_token *token)
539 {
540 if (token->type != CPP_EOF)
541 {
542 input_location = token->location;
543 }
544 }
545
546 /* Issue a diagnostic of the form
547 FILE:LINE: MESSAGE before TOKEN
548 where TOKEN is the next token in the input stream of PARSER.
549 MESSAGE (specified by the caller) is usually of the form "expected
550 OTHER-TOKEN".
551
552 Do not issue a diagnostic if still recovering from an error.
553
554 ??? This is taken from the C++ parser, but building up messages in
555 this way is not i18n-friendly and some other approach should be
556 used. */
557
558 static void
559 c_parser_error (c_parser *parser, const char *gmsgid)
560 {
561 c_token *token = c_parser_peek_token (parser);
562 if (parser->error)
563 return;
564 parser->error = true;
565 if (!gmsgid)
566 return;
567 /* This diagnostic makes more sense if it is tagged to the line of
568 the token we just peeked at. */
569 c_parser_set_source_position_from_token (token);
570 c_parse_error (gmsgid,
571 /* Because c_parse_error does not understand
572 CPP_KEYWORD, keywords are treated like
573 identifiers. */
574 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
575 token->value);
576 }
577
578 /* If the next token is of the indicated TYPE, consume it. Otherwise,
579 issue the error MSGID. If MSGID is NULL then a message has already
580 been produced and no message will be produced this time. Returns
581 true if found, false otherwise. */
582
583 static bool
584 c_parser_require (c_parser *parser,
585 enum cpp_ttype type,
586 const char *msgid)
587 {
588 if (c_parser_next_token_is (parser, type))
589 {
590 c_parser_consume_token (parser);
591 return true;
592 }
593 else
594 {
595 c_parser_error (parser, msgid);
596 return false;
597 }
598 }
599
600 /* If the next token is the indicated keyword, consume it. Otherwise,
601 issue the error MSGID. Returns true if found, false otherwise. */
602
603 static bool
604 c_parser_require_keyword (c_parser *parser,
605 enum rid keyword,
606 const char *msgid)
607 {
608 if (c_parser_next_token_is_keyword (parser, keyword))
609 {
610 c_parser_consume_token (parser);
611 return true;
612 }
613 else
614 {
615 c_parser_error (parser, msgid);
616 return false;
617 }
618 }
619
620 /* Like c_parser_require, except that tokens will be skipped until the
621 desired token is found. An error message is still produced if the
622 next token is not as expected. If MSGID is NULL then a message has
623 already been produced and no message will be produced this
624 time. */
625
626 static void
627 c_parser_skip_until_found (c_parser *parser,
628 enum cpp_ttype type,
629 const char *msgid)
630 {
631 unsigned nesting_depth = 0;
632
633 if (c_parser_require (parser, type, msgid))
634 return;
635
636 /* Skip tokens until the desired token is found. */
637 while (true)
638 {
639 /* Peek at the next token. */
640 c_token *token = c_parser_peek_token (parser);
641 /* If we've reached the token we want, consume it and stop. */
642 if (token->type == type && !nesting_depth)
643 {
644 c_parser_consume_token (parser);
645 break;
646 }
647
648 /* If we've run out of tokens, stop. */
649 if (token->type == CPP_EOF)
650 return;
651 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
652 return;
653 if (token->type == CPP_OPEN_BRACE
654 || token->type == CPP_OPEN_PAREN
655 || token->type == CPP_OPEN_SQUARE)
656 ++nesting_depth;
657 else if (token->type == CPP_CLOSE_BRACE
658 || token->type == CPP_CLOSE_PAREN
659 || token->type == CPP_CLOSE_SQUARE)
660 {
661 if (nesting_depth-- == 0)
662 break;
663 }
664 /* Consume this token. */
665 c_parser_consume_token (parser);
666 }
667 parser->error = false;
668 }
669
670 /* Skip tokens until the end of a parameter is found, but do not
671 consume the comma, semicolon or closing delimiter. */
672
673 static void
674 c_parser_skip_to_end_of_parameter (c_parser *parser)
675 {
676 unsigned nesting_depth = 0;
677
678 while (true)
679 {
680 c_token *token = c_parser_peek_token (parser);
681 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
682 && !nesting_depth)
683 break;
684 /* If we've run out of tokens, stop. */
685 if (token->type == CPP_EOF)
686 return;
687 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
688 return;
689 if (token->type == CPP_OPEN_BRACE
690 || token->type == CPP_OPEN_PAREN
691 || token->type == CPP_OPEN_SQUARE)
692 ++nesting_depth;
693 else if (token->type == CPP_CLOSE_BRACE
694 || token->type == CPP_CLOSE_PAREN
695 || token->type == CPP_CLOSE_SQUARE)
696 {
697 if (nesting_depth-- == 0)
698 break;
699 }
700 /* Consume this token. */
701 c_parser_consume_token (parser);
702 }
703 parser->error = false;
704 }
705
706 /* Expect to be at the end of the pragma directive and consume an
707 end of line marker. */
708
709 static void
710 c_parser_skip_to_pragma_eol (c_parser *parser)
711 {
712 gcc_assert (parser->in_pragma);
713 parser->in_pragma = false;
714
715 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
716 while (true)
717 {
718 c_token *token = c_parser_peek_token (parser);
719 if (token->type == CPP_EOF)
720 break;
721 if (token->type == CPP_PRAGMA_EOL)
722 {
723 c_parser_consume_token (parser);
724 break;
725 }
726 c_parser_consume_token (parser);
727 }
728
729 parser->error = false;
730 }
731
732 /* Skip tokens until we have consumed an entire block, or until we
733 have consumed a non-nested ';'. */
734
735 static void
736 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
737 {
738 unsigned nesting_depth = 0;
739 bool save_error = parser->error;
740
741 while (true)
742 {
743 c_token *token;
744
745 /* Peek at the next token. */
746 token = c_parser_peek_token (parser);
747
748 switch (token->type)
749 {
750 case CPP_EOF:
751 return;
752
753 case CPP_PRAGMA_EOL:
754 if (parser->in_pragma)
755 return;
756 break;
757
758 case CPP_SEMICOLON:
759 /* If the next token is a ';', we have reached the
760 end of the statement. */
761 if (!nesting_depth)
762 {
763 /* Consume the ';'. */
764 c_parser_consume_token (parser);
765 goto finished;
766 }
767 break;
768
769 case CPP_CLOSE_BRACE:
770 /* If the next token is a non-nested '}', then we have
771 reached the end of the current block. */
772 if (nesting_depth == 0 || --nesting_depth == 0)
773 {
774 c_parser_consume_token (parser);
775 goto finished;
776 }
777 break;
778
779 case CPP_OPEN_BRACE:
780 /* If it the next token is a '{', then we are entering a new
781 block. Consume the entire block. */
782 ++nesting_depth;
783 break;
784
785 case CPP_PRAGMA:
786 /* If we see a pragma, consume the whole thing at once. We
787 have some safeguards against consuming pragmas willy-nilly.
788 Normally, we'd expect to be here with parser->error set,
789 which disables these safeguards. But it's possible to get
790 here for secondary error recovery, after parser->error has
791 been cleared. */
792 c_parser_consume_pragma (parser);
793 c_parser_skip_to_pragma_eol (parser);
794 parser->error = save_error;
795 continue;
796
797 default:
798 break;
799 }
800
801 c_parser_consume_token (parser);
802 }
803
804 finished:
805 parser->error = false;
806 }
807
808 /* CPP's options (initialized by c-opts.c). */
809 extern cpp_options *cpp_opts;
810
811 /* Save the warning flags which are controlled by __extension__. */
812
813 static inline int
814 disable_extension_diagnostics (void)
815 {
816 int ret = (pedantic
817 | (warn_pointer_arith << 1)
818 | (warn_traditional << 2)
819 | (flag_iso << 3)
820 | (warn_long_long << 4)
821 | (cpp_opts->warn_long_long << 5));
822 cpp_opts->pedantic = pedantic = 0;
823 warn_pointer_arith = 0;
824 cpp_opts->warn_traditional = warn_traditional = 0;
825 flag_iso = 0;
826 warn_long_long = 0;
827 cpp_opts->warn_long_long = 0;
828 return ret;
829 }
830
831 /* Restore the warning flags which are controlled by __extension__.
832 FLAGS is the return value from disable_extension_diagnostics. */
833
834 static inline void
835 restore_extension_diagnostics (int flags)
836 {
837 cpp_opts->pedantic = pedantic = flags & 1;
838 warn_pointer_arith = (flags >> 1) & 1;
839 cpp_opts->warn_traditional = warn_traditional = (flags >> 2) & 1;
840 flag_iso = (flags >> 3) & 1;
841 warn_long_long = (flags >> 4) & 1;
842 cpp_opts->warn_long_long = (flags >> 5) & 1;
843 }
844
845 /* Possibly kinds of declarator to parse. */
846 typedef enum c_dtr_syn {
847 /* A normal declarator with an identifier. */
848 C_DTR_NORMAL,
849 /* An abstract declarator (maybe empty). */
850 C_DTR_ABSTRACT,
851 /* A parameter declarator: may be either, but after a type name does
852 not redeclare a typedef name as an identifier if it can
853 alternatively be interpreted as a typedef name; see DR#009,
854 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
855 following DR#249. For example, given a typedef T, "int T" and
856 "int *T" are valid parameter declarations redeclaring T, while
857 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
858 abstract declarators rather than involving redundant parentheses;
859 the same applies with attributes inside the parentheses before
860 "T". */
861 C_DTR_PARM
862 } c_dtr_syn;
863
864 static void c_parser_external_declaration (c_parser *);
865 static void c_parser_asm_definition (c_parser *);
866 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, bool);
867 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
868 bool);
869 static struct c_typespec c_parser_enum_specifier (c_parser *);
870 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
871 static tree c_parser_struct_declaration (c_parser *);
872 static struct c_typespec c_parser_typeof_specifier (c_parser *);
873 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
874 bool *);
875 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
876 c_dtr_syn, bool *);
877 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
878 bool,
879 struct c_declarator *);
880 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
881 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
882 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
883 static tree c_parser_simple_asm_expr (c_parser *);
884 static tree c_parser_attributes (c_parser *);
885 static struct c_type_name *c_parser_type_name (c_parser *);
886 static struct c_expr c_parser_initializer (c_parser *);
887 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
888 static void c_parser_initelt (c_parser *);
889 static void c_parser_initval (c_parser *, struct c_expr *);
890 static tree c_parser_compound_statement (c_parser *);
891 static void c_parser_compound_statement_nostart (c_parser *);
892 static void c_parser_label (c_parser *);
893 static void c_parser_statement (c_parser *);
894 static void c_parser_statement_after_labels (c_parser *);
895 static void c_parser_if_statement (c_parser *);
896 static void c_parser_switch_statement (c_parser *);
897 static void c_parser_while_statement (c_parser *);
898 static void c_parser_do_statement (c_parser *);
899 static void c_parser_for_statement (c_parser *);
900 static tree c_parser_asm_statement (c_parser *);
901 static tree c_parser_asm_operands (c_parser *, bool);
902 static tree c_parser_asm_clobbers (c_parser *);
903 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
904 static struct c_expr c_parser_conditional_expression (c_parser *,
905 struct c_expr *);
906 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
907 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
908 static struct c_expr c_parser_unary_expression (c_parser *);
909 static struct c_expr c_parser_sizeof_expression (c_parser *);
910 static struct c_expr c_parser_alignof_expression (c_parser *);
911 static struct c_expr c_parser_postfix_expression (c_parser *);
912 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
913 struct c_type_name *);
914 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
915 struct c_expr);
916 static struct c_expr c_parser_expression (c_parser *);
917 static struct c_expr c_parser_expression_conv (c_parser *);
918 static tree c_parser_expr_list (c_parser *, bool);
919 static void c_parser_omp_construct (c_parser *);
920 static void c_parser_omp_threadprivate (c_parser *);
921 static void c_parser_omp_barrier (c_parser *);
922 static void c_parser_omp_flush (c_parser *);
923 static void c_parser_omp_taskwait (c_parser *);
924
925 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
926 static bool c_parser_pragma (c_parser *, enum pragma_context);
927
928 /* These Objective-C parser functions are only ever called when
929 compiling Objective-C. */
930 static void c_parser_objc_class_definition (c_parser *);
931 static void c_parser_objc_class_instance_variables (c_parser *);
932 static void c_parser_objc_class_declaration (c_parser *);
933 static void c_parser_objc_alias_declaration (c_parser *);
934 static void c_parser_objc_protocol_definition (c_parser *);
935 static enum tree_code c_parser_objc_method_type (c_parser *);
936 static void c_parser_objc_method_definition (c_parser *);
937 static void c_parser_objc_methodprotolist (c_parser *);
938 static void c_parser_objc_methodproto (c_parser *);
939 static tree c_parser_objc_method_decl (c_parser *);
940 static tree c_parser_objc_type_name (c_parser *);
941 static tree c_parser_objc_protocol_refs (c_parser *);
942 static void c_parser_objc_try_catch_statement (c_parser *);
943 static void c_parser_objc_synchronized_statement (c_parser *);
944 static tree c_parser_objc_selector (c_parser *);
945 static tree c_parser_objc_selector_arg (c_parser *);
946 static tree c_parser_objc_receiver (c_parser *);
947 static tree c_parser_objc_message_args (c_parser *);
948 static tree c_parser_objc_keywordexpr (c_parser *);
949
950 /* Parse a translation unit (C90 6.7, C99 6.9).
951
952 translation-unit:
953 external-declarations
954
955 external-declarations:
956 external-declaration
957 external-declarations external-declaration
958
959 GNU extensions:
960
961 translation-unit:
962 empty
963 */
964
965 static void
966 c_parser_translation_unit (c_parser *parser)
967 {
968 if (c_parser_next_token_is (parser, CPP_EOF))
969 {
970 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
971 "ISO C forbids an empty translation unit");
972 }
973 else
974 {
975 void *obstack_position = obstack_alloc (&parser_obstack, 0);
976 do
977 {
978 ggc_collect ();
979 c_parser_external_declaration (parser);
980 obstack_free (&parser_obstack, obstack_position);
981 }
982 while (c_parser_next_token_is_not (parser, CPP_EOF));
983 }
984 }
985
986 /* Parse an external declaration (C90 6.7, C99 6.9).
987
988 external-declaration:
989 function-definition
990 declaration
991
992 GNU extensions:
993
994 external-declaration:
995 asm-definition
996 ;
997 __extension__ external-declaration
998
999 Objective-C:
1000
1001 external-declaration:
1002 objc-class-definition
1003 objc-class-declaration
1004 objc-alias-declaration
1005 objc-protocol-definition
1006 objc-method-definition
1007 @end
1008 */
1009
1010 static void
1011 c_parser_external_declaration (c_parser *parser)
1012 {
1013 int ext;
1014 switch (c_parser_peek_token (parser)->type)
1015 {
1016 case CPP_KEYWORD:
1017 switch (c_parser_peek_token (parser)->keyword)
1018 {
1019 case RID_EXTENSION:
1020 ext = disable_extension_diagnostics ();
1021 c_parser_consume_token (parser);
1022 c_parser_external_declaration (parser);
1023 restore_extension_diagnostics (ext);
1024 break;
1025 case RID_ASM:
1026 c_parser_asm_definition (parser);
1027 break;
1028 case RID_AT_INTERFACE:
1029 case RID_AT_IMPLEMENTATION:
1030 gcc_assert (c_dialect_objc ());
1031 c_parser_objc_class_definition (parser);
1032 break;
1033 case RID_CLASS:
1034 gcc_assert (c_dialect_objc ());
1035 c_parser_objc_class_declaration (parser);
1036 break;
1037 case RID_AT_ALIAS:
1038 gcc_assert (c_dialect_objc ());
1039 c_parser_objc_alias_declaration (parser);
1040 break;
1041 case RID_AT_PROTOCOL:
1042 gcc_assert (c_dialect_objc ());
1043 c_parser_objc_protocol_definition (parser);
1044 break;
1045 case RID_AT_END:
1046 gcc_assert (c_dialect_objc ());
1047 c_parser_consume_token (parser);
1048 objc_finish_implementation ();
1049 break;
1050 default:
1051 goto decl_or_fndef;
1052 }
1053 break;
1054 case CPP_SEMICOLON:
1055 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1056 "ISO C does not allow extra %<;%> outside of a function");
1057 c_parser_consume_token (parser);
1058 break;
1059 case CPP_PRAGMA:
1060 c_parser_pragma (parser, pragma_external);
1061 break;
1062 case CPP_PLUS:
1063 case CPP_MINUS:
1064 if (c_dialect_objc ())
1065 {
1066 c_parser_objc_method_definition (parser);
1067 break;
1068 }
1069 /* Else fall through, and yield a syntax error trying to parse
1070 as a declaration or function definition. */
1071 default:
1072 decl_or_fndef:
1073 /* A declaration or a function definition. We can only tell
1074 which after parsing the declaration specifiers, if any, and
1075 the first declarator. */
1076 c_parser_declaration_or_fndef (parser, true, true, false, true);
1077 break;
1078 }
1079 }
1080
1081
1082 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1083 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1084 accepted; otherwise (old-style parameter declarations) only other
1085 declarations are accepted. If NESTED is true, we are inside a
1086 function or parsing old-style parameter declarations; any functions
1087 encountered are nested functions and declaration specifiers are
1088 required; otherwise we are at top level and functions are normal
1089 functions and declaration specifiers may be optional. If EMPTY_OK
1090 is true, empty declarations are OK (subject to all other
1091 constraints); otherwise (old-style parameter declarations) they are
1092 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1093 may start with attributes; otherwise they may not.
1094
1095 declaration:
1096 declaration-specifiers init-declarator-list[opt] ;
1097
1098 function-definition:
1099 declaration-specifiers[opt] declarator declaration-list[opt]
1100 compound-statement
1101
1102 declaration-list:
1103 declaration
1104 declaration-list declaration
1105
1106 init-declarator-list:
1107 init-declarator
1108 init-declarator-list , init-declarator
1109
1110 init-declarator:
1111 declarator simple-asm-expr[opt] attributes[opt]
1112 declarator simple-asm-expr[opt] attributes[opt] = initializer
1113
1114 GNU extensions:
1115
1116 nested-function-definition:
1117 declaration-specifiers declarator declaration-list[opt]
1118 compound-statement
1119
1120 The simple-asm-expr and attributes are GNU extensions.
1121
1122 This function does not handle __extension__; that is handled in its
1123 callers. ??? Following the old parser, __extension__ may start
1124 external declarations, declarations in functions and declarations
1125 at the start of "for" loops, but not old-style parameter
1126 declarations.
1127
1128 C99 requires declaration specifiers in a function definition; the
1129 absence is diagnosed through the diagnosis of implicit int. In GNU
1130 C we also allow but diagnose declarations without declaration
1131 specifiers, but only at top level (elsewhere they conflict with
1132 other syntax).
1133
1134 OpenMP:
1135
1136 declaration:
1137 threadprivate-directive */
1138
1139 static void
1140 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
1141 bool nested, bool start_attr_ok)
1142 {
1143 struct c_declspecs *specs;
1144 tree prefix_attrs;
1145 tree all_prefix_attrs;
1146 bool diagnosed_no_specs = false;
1147 location_t here = c_parser_peek_token (parser)->location;
1148
1149 specs = build_null_declspecs ();
1150 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1151 if (parser->error)
1152 {
1153 c_parser_skip_to_end_of_block_or_statement (parser);
1154 return;
1155 }
1156 if (nested && !specs->declspecs_seen_p)
1157 {
1158 c_parser_error (parser, "expected declaration specifiers");
1159 c_parser_skip_to_end_of_block_or_statement (parser);
1160 return;
1161 }
1162 finish_declspecs (specs);
1163 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1164 {
1165 if (empty_ok)
1166 shadow_tag (specs);
1167 else
1168 {
1169 shadow_tag_warned (specs, 1);
1170 pedwarn (here, 0, "empty declaration");
1171 }
1172 c_parser_consume_token (parser);
1173 return;
1174 }
1175 pending_xref_error ();
1176 prefix_attrs = specs->attrs;
1177 all_prefix_attrs = prefix_attrs;
1178 specs->attrs = NULL_TREE;
1179 while (true)
1180 {
1181 struct c_declarator *declarator;
1182 bool dummy = false;
1183 tree fnbody;
1184 /* Declaring either one or more declarators (in which case we
1185 should diagnose if there were no declaration specifiers) or a
1186 function definition (in which case the diagnostic for
1187 implicit int suffices). */
1188 declarator = c_parser_declarator (parser, specs->type_seen_p,
1189 C_DTR_NORMAL, &dummy);
1190 if (declarator == NULL)
1191 {
1192 c_parser_skip_to_end_of_block_or_statement (parser);
1193 return;
1194 }
1195 if (c_parser_next_token_is (parser, CPP_EQ)
1196 || c_parser_next_token_is (parser, CPP_COMMA)
1197 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1198 || c_parser_next_token_is_keyword (parser, RID_ASM)
1199 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1200 {
1201 tree asm_name = NULL_TREE;
1202 tree postfix_attrs = NULL_TREE;
1203 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1204 {
1205 diagnosed_no_specs = true;
1206 pedwarn (here, 0, "data definition has no type or storage class");
1207 }
1208 /* Having seen a data definition, there cannot now be a
1209 function definition. */
1210 fndef_ok = false;
1211 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1212 asm_name = c_parser_simple_asm_expr (parser);
1213 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1214 postfix_attrs = c_parser_attributes (parser);
1215 if (c_parser_next_token_is (parser, CPP_EQ))
1216 {
1217 tree d;
1218 struct c_expr init;
1219 c_parser_consume_token (parser);
1220 /* The declaration of the variable is in effect while
1221 its initializer is parsed. */
1222 d = start_decl (declarator, specs, true,
1223 chainon (postfix_attrs, all_prefix_attrs));
1224 if (!d)
1225 d = error_mark_node;
1226 start_init (d, asm_name, global_bindings_p ());
1227 init = c_parser_initializer (parser);
1228 finish_init ();
1229 if (d != error_mark_node)
1230 {
1231 maybe_warn_string_init (TREE_TYPE (d), init);
1232 finish_decl (d, init.value, asm_name);
1233 }
1234 }
1235 else
1236 {
1237 tree d = start_decl (declarator, specs, false,
1238 chainon (postfix_attrs,
1239 all_prefix_attrs));
1240 if (d)
1241 finish_decl (d, NULL_TREE, asm_name);
1242 }
1243 if (c_parser_next_token_is (parser, CPP_COMMA))
1244 {
1245 c_parser_consume_token (parser);
1246 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1247 all_prefix_attrs = chainon (c_parser_attributes (parser),
1248 prefix_attrs);
1249 else
1250 all_prefix_attrs = prefix_attrs;
1251 continue;
1252 }
1253 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1254 {
1255 c_parser_consume_token (parser);
1256 return;
1257 }
1258 else
1259 {
1260 c_parser_error (parser, "expected %<,%> or %<;%>");
1261 c_parser_skip_to_end_of_block_or_statement (parser);
1262 return;
1263 }
1264 }
1265 else if (!fndef_ok)
1266 {
1267 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1268 "%<asm%> or %<__attribute__%>");
1269 c_parser_skip_to_end_of_block_or_statement (parser);
1270 return;
1271 }
1272 /* Function definition (nested or otherwise). */
1273 if (nested)
1274 {
1275 pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
1276 c_push_function_context ();
1277 }
1278 if (!start_function (specs, declarator, all_prefix_attrs))
1279 {
1280 /* This can appear in many cases looking nothing like a
1281 function definition, so we don't give a more specific
1282 error suggesting there was one. */
1283 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1284 "or %<__attribute__%>");
1285 if (nested)
1286 c_pop_function_context ();
1287 break;
1288 }
1289 /* Parse old-style parameter declarations. ??? Attributes are
1290 not allowed to start declaration specifiers here because of a
1291 syntax conflict between a function declaration with attribute
1292 suffix and a function definition with an attribute prefix on
1293 first old-style parameter declaration. Following the old
1294 parser, they are not accepted on subsequent old-style
1295 parameter declarations either. However, there is no
1296 ambiguity after the first declaration, nor indeed on the
1297 first as long as we don't allow postfix attributes after a
1298 declarator with a nonempty identifier list in a definition;
1299 and postfix attributes have never been accepted here in
1300 function definitions either. */
1301 while (c_parser_next_token_is_not (parser, CPP_EOF)
1302 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1303 c_parser_declaration_or_fndef (parser, false, false, true, false);
1304 store_parm_decls ();
1305 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1306 = c_parser_peek_token (parser)->location;
1307 fnbody = c_parser_compound_statement (parser);
1308 if (nested)
1309 {
1310 tree decl = current_function_decl;
1311 add_stmt (fnbody);
1312 finish_function ();
1313 c_pop_function_context ();
1314 add_stmt (build_stmt (DECL_EXPR, decl));
1315 }
1316 else
1317 {
1318 add_stmt (fnbody);
1319 finish_function ();
1320 }
1321 break;
1322 }
1323 }
1324
1325 /* Parse an asm-definition (asm() outside a function body). This is a
1326 GNU extension.
1327
1328 asm-definition:
1329 simple-asm-expr ;
1330 */
1331
1332 static void
1333 c_parser_asm_definition (c_parser *parser)
1334 {
1335 tree asm_str = c_parser_simple_asm_expr (parser);
1336 if (asm_str)
1337 cgraph_add_asm_node (asm_str);
1338 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1339 }
1340
1341 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1342 6.7), adding them to SPECS (which may already include some).
1343 Storage class specifiers are accepted iff SCSPEC_OK; type
1344 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1345 the start iff START_ATTR_OK.
1346
1347 declaration-specifiers:
1348 storage-class-specifier declaration-specifiers[opt]
1349 type-specifier declaration-specifiers[opt]
1350 type-qualifier declaration-specifiers[opt]
1351 function-specifier declaration-specifiers[opt]
1352
1353 Function specifiers (inline) are from C99, and are currently
1354 handled as storage class specifiers, as is __thread.
1355
1356 C90 6.5.1, C99 6.7.1:
1357 storage-class-specifier:
1358 typedef
1359 extern
1360 static
1361 auto
1362 register
1363
1364 C99 6.7.4:
1365 function-specifier:
1366 inline
1367
1368 C90 6.5.2, C99 6.7.2:
1369 type-specifier:
1370 void
1371 char
1372 short
1373 int
1374 long
1375 float
1376 double
1377 signed
1378 unsigned
1379 _Bool
1380 _Complex
1381 [_Imaginary removed in C99 TC2]
1382 struct-or-union-specifier
1383 enum-specifier
1384 typedef-name
1385
1386 (_Bool and _Complex are new in C99.)
1387
1388 C90 6.5.3, C99 6.7.3:
1389
1390 type-qualifier:
1391 const
1392 restrict
1393 volatile
1394
1395 (restrict is new in C99.)
1396
1397 GNU extensions:
1398
1399 declaration-specifiers:
1400 attributes declaration-specifiers[opt]
1401
1402 storage-class-specifier:
1403 __thread
1404
1405 type-specifier:
1406 typeof-specifier
1407 _Decimal32
1408 _Decimal64
1409 _Decimal128
1410 _Fract
1411 _Accum
1412 _Sat
1413
1414 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1415 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1416
1417 Objective-C:
1418
1419 type-specifier:
1420 class-name objc-protocol-refs[opt]
1421 typedef-name objc-protocol-refs
1422 objc-protocol-refs
1423 */
1424
1425 static void
1426 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1427 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1428 {
1429 bool attrs_ok = start_attr_ok;
1430 bool seen_type = specs->type_seen_p;
1431 while (c_parser_next_token_is (parser, CPP_NAME)
1432 || c_parser_next_token_is (parser, CPP_KEYWORD)
1433 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1434 {
1435 struct c_typespec t;
1436 tree attrs;
1437 if (c_parser_next_token_is (parser, CPP_NAME))
1438 {
1439 tree value = c_parser_peek_token (parser)->value;
1440 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1441 /* This finishes the specifiers unless a type name is OK, it
1442 is declared as a type name and a type name hasn't yet
1443 been seen. */
1444 if (!typespec_ok || seen_type
1445 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1446 break;
1447 c_parser_consume_token (parser);
1448 seen_type = true;
1449 attrs_ok = true;
1450 if (kind == C_ID_TYPENAME
1451 && (!c_dialect_objc ()
1452 || c_parser_next_token_is_not (parser, CPP_LESS)))
1453 {
1454 t.kind = ctsk_typedef;
1455 /* For a typedef name, record the meaning, not the name.
1456 In case of 'foo foo, bar;'. */
1457 t.spec = lookup_name (value);
1458 }
1459 else
1460 {
1461 tree proto = NULL_TREE;
1462 gcc_assert (c_dialect_objc ());
1463 t.kind = ctsk_objc;
1464 if (c_parser_next_token_is (parser, CPP_LESS))
1465 proto = c_parser_objc_protocol_refs (parser);
1466 t.spec = objc_get_protocol_qualified_type (value, proto);
1467 }
1468 declspecs_add_type (specs, t);
1469 continue;
1470 }
1471 if (c_parser_next_token_is (parser, CPP_LESS))
1472 {
1473 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1474 nisse@lysator.liu.se. */
1475 tree proto;
1476 gcc_assert (c_dialect_objc ());
1477 if (!typespec_ok || seen_type)
1478 break;
1479 proto = c_parser_objc_protocol_refs (parser);
1480 t.kind = ctsk_objc;
1481 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1482 declspecs_add_type (specs, t);
1483 continue;
1484 }
1485 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1486 switch (c_parser_peek_token (parser)->keyword)
1487 {
1488 case RID_STATIC:
1489 case RID_EXTERN:
1490 case RID_REGISTER:
1491 case RID_TYPEDEF:
1492 case RID_INLINE:
1493 case RID_AUTO:
1494 case RID_THREAD:
1495 if (!scspec_ok)
1496 goto out;
1497 attrs_ok = true;
1498 /* TODO: Distinguish between function specifiers (inline)
1499 and storage class specifiers, either here or in
1500 declspecs_add_scspec. */
1501 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1502 c_parser_consume_token (parser);
1503 break;
1504 case RID_UNSIGNED:
1505 case RID_LONG:
1506 case RID_SHORT:
1507 case RID_SIGNED:
1508 case RID_COMPLEX:
1509 case RID_INT:
1510 case RID_CHAR:
1511 case RID_FLOAT:
1512 case RID_DOUBLE:
1513 case RID_VOID:
1514 case RID_DFLOAT32:
1515 case RID_DFLOAT64:
1516 case RID_DFLOAT128:
1517 case RID_BOOL:
1518 case RID_FRACT:
1519 case RID_ACCUM:
1520 case RID_SAT:
1521 if (!typespec_ok)
1522 goto out;
1523 attrs_ok = true;
1524 seen_type = true;
1525 if (c_dialect_objc ())
1526 parser->objc_need_raw_identifier = true;
1527 t.kind = ctsk_resword;
1528 t.spec = c_parser_peek_token (parser)->value;
1529 declspecs_add_type (specs, t);
1530 c_parser_consume_token (parser);
1531 break;
1532 case RID_ENUM:
1533 if (!typespec_ok)
1534 goto out;
1535 attrs_ok = true;
1536 seen_type = true;
1537 t = c_parser_enum_specifier (parser);
1538 declspecs_add_type (specs, t);
1539 break;
1540 case RID_STRUCT:
1541 case RID_UNION:
1542 if (!typespec_ok)
1543 goto out;
1544 attrs_ok = true;
1545 seen_type = true;
1546 t = c_parser_struct_or_union_specifier (parser);
1547 declspecs_add_type (specs, t);
1548 break;
1549 case RID_TYPEOF:
1550 /* ??? The old parser rejected typeof after other type
1551 specifiers, but is a syntax error the best way of
1552 handling this? */
1553 if (!typespec_ok || seen_type)
1554 goto out;
1555 attrs_ok = true;
1556 seen_type = true;
1557 t = c_parser_typeof_specifier (parser);
1558 declspecs_add_type (specs, t);
1559 break;
1560 case RID_CONST:
1561 case RID_VOLATILE:
1562 case RID_RESTRICT:
1563 attrs_ok = true;
1564 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1565 c_parser_consume_token (parser);
1566 break;
1567 case RID_ATTRIBUTE:
1568 if (!attrs_ok)
1569 goto out;
1570 attrs = c_parser_attributes (parser);
1571 declspecs_add_attrs (specs, attrs);
1572 break;
1573 default:
1574 goto out;
1575 }
1576 }
1577 out: ;
1578 }
1579
1580 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1581
1582 enum-specifier:
1583 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1584 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1585 enum attributes[opt] identifier
1586
1587 The form with trailing comma is new in C99. The forms with
1588 attributes are GNU extensions. In GNU C, we accept any expression
1589 without commas in the syntax (assignment expressions, not just
1590 conditional expressions); assignment expressions will be diagnosed
1591 as non-constant.
1592
1593 enumerator-list:
1594 enumerator
1595 enumerator-list , enumerator
1596
1597 enumerator:
1598 enumeration-constant
1599 enumeration-constant = constant-expression
1600 */
1601
1602 static struct c_typespec
1603 c_parser_enum_specifier (c_parser *parser)
1604 {
1605 struct c_typespec ret;
1606 tree attrs;
1607 tree ident = NULL_TREE;
1608 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1609 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1610 c_parser_consume_token (parser);
1611 attrs = c_parser_attributes (parser);
1612 /* Set the location in case we create a decl now. */
1613 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1614 if (c_parser_next_token_is (parser, CPP_NAME))
1615 {
1616 ident = c_parser_peek_token (parser)->value;
1617 ident_loc = c_parser_peek_token (parser)->location;
1618 c_parser_consume_token (parser);
1619 }
1620 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1621 {
1622 /* Parse an enum definition. */
1623 struct c_enum_contents the_enum;
1624 tree type = start_enum (&the_enum, ident);
1625 tree postfix_attrs;
1626 /* We chain the enumerators in reverse order, then put them in
1627 forward order at the end. */
1628 tree values = NULL_TREE;
1629 c_parser_consume_token (parser);
1630 while (true)
1631 {
1632 tree enum_id;
1633 tree enum_value;
1634 tree enum_decl;
1635 bool seen_comma;
1636 c_token *token;
1637 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1638 location_t value_loc;
1639 if (c_parser_next_token_is_not (parser, CPP_NAME))
1640 {
1641 c_parser_error (parser, "expected identifier");
1642 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1643 values = error_mark_node;
1644 break;
1645 }
1646 token = c_parser_peek_token (parser);
1647 enum_id = token->value;
1648 /* Set the location in case we create a decl now. */
1649 c_parser_set_source_position_from_token (token);
1650 value_loc = token->location;
1651 c_parser_consume_token (parser);
1652 if (c_parser_next_token_is (parser, CPP_EQ))
1653 {
1654 c_parser_consume_token (parser);
1655 value_loc = c_parser_peek_token (parser)->location;
1656 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1657 }
1658 else
1659 enum_value = NULL_TREE;
1660 enum_decl = build_enumerator (&the_enum, enum_id, enum_value,
1661 value_loc);
1662 TREE_CHAIN (enum_decl) = values;
1663 values = enum_decl;
1664 seen_comma = false;
1665 if (c_parser_next_token_is (parser, CPP_COMMA))
1666 {
1667 comma_loc = c_parser_peek_token (parser)->location;
1668 seen_comma = true;
1669 c_parser_consume_token (parser);
1670 }
1671 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1672 {
1673 if (seen_comma && !flag_isoc99)
1674 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
1675 c_parser_consume_token (parser);
1676 break;
1677 }
1678 if (!seen_comma)
1679 {
1680 c_parser_error (parser, "expected %<,%> or %<}%>");
1681 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1682 values = error_mark_node;
1683 break;
1684 }
1685 }
1686 postfix_attrs = c_parser_attributes (parser);
1687 ret.spec = finish_enum (type, nreverse (values),
1688 chainon (attrs, postfix_attrs));
1689 ret.kind = ctsk_tagdef;
1690 return ret;
1691 }
1692 else if (!ident)
1693 {
1694 c_parser_error (parser, "expected %<{%>");
1695 ret.spec = error_mark_node;
1696 ret.kind = ctsk_tagref;
1697 return ret;
1698 }
1699 ret = parser_xref_tag (ENUMERAL_TYPE, ident);
1700 /* In ISO C, enumerated types can be referred to only if already
1701 defined. */
1702 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1703 {
1704 gcc_assert (ident);
1705 pedwarn (ident_loc, OPT_pedantic,
1706 "ISO C forbids forward references to %<enum%> types");
1707 }
1708 return ret;
1709 }
1710
1711 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1712
1713 struct-or-union-specifier:
1714 struct-or-union attributes[opt] identifier[opt]
1715 { struct-contents } attributes[opt]
1716 struct-or-union attributes[opt] identifier
1717
1718 struct-contents:
1719 struct-declaration-list
1720
1721 struct-declaration-list:
1722 struct-declaration ;
1723 struct-declaration-list struct-declaration ;
1724
1725 GNU extensions:
1726
1727 struct-contents:
1728 empty
1729 struct-declaration
1730 struct-declaration-list struct-declaration
1731
1732 struct-declaration-list:
1733 struct-declaration-list ;
1734 ;
1735
1736 (Note that in the syntax here, unlike that in ISO C, the semicolons
1737 are included here rather than in struct-declaration, in order to
1738 describe the syntax with extra semicolons and missing semicolon at
1739 end.)
1740
1741 Objective-C:
1742
1743 struct-declaration-list:
1744 @defs ( class-name )
1745
1746 (Note this does not include a trailing semicolon, but can be
1747 followed by further declarations, and gets a pedwarn-if-pedantic
1748 when followed by a semicolon.) */
1749
1750 static struct c_typespec
1751 c_parser_struct_or_union_specifier (c_parser *parser)
1752 {
1753 struct c_typespec ret;
1754 tree attrs;
1755 tree ident = NULL_TREE;
1756 enum tree_code code;
1757 switch (c_parser_peek_token (parser)->keyword)
1758 {
1759 case RID_STRUCT:
1760 code = RECORD_TYPE;
1761 break;
1762 case RID_UNION:
1763 code = UNION_TYPE;
1764 break;
1765 default:
1766 gcc_unreachable ();
1767 }
1768 c_parser_consume_token (parser);
1769 attrs = c_parser_attributes (parser);
1770 /* Set the location in case we create a decl now. */
1771 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1772 if (c_parser_next_token_is (parser, CPP_NAME))
1773 {
1774 ident = c_parser_peek_token (parser)->value;
1775 c_parser_consume_token (parser);
1776 }
1777 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1778 {
1779 /* Parse a struct or union definition. Start the scope of the
1780 tag before parsing components. */
1781 tree type = start_struct (code, ident);
1782 tree postfix_attrs;
1783 /* We chain the components in reverse order, then put them in
1784 forward order at the end. Each struct-declaration may
1785 declare multiple components (comma-separated), so we must use
1786 chainon to join them, although when parsing each
1787 struct-declaration we can use TREE_CHAIN directly.
1788
1789 The theory behind all this is that there will be more
1790 semicolon separated fields than comma separated fields, and
1791 so we'll be minimizing the number of node traversals required
1792 by chainon. */
1793 tree contents = NULL_TREE;
1794 c_parser_consume_token (parser);
1795 /* Handle the Objective-C @defs construct,
1796 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1797 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
1798 {
1799 tree name;
1800 gcc_assert (c_dialect_objc ());
1801 c_parser_consume_token (parser);
1802 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1803 goto end_at_defs;
1804 if (c_parser_next_token_is (parser, CPP_NAME)
1805 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
1806 {
1807 name = c_parser_peek_token (parser)->value;
1808 c_parser_consume_token (parser);
1809 }
1810 else
1811 {
1812 c_parser_error (parser, "expected class name");
1813 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
1814 goto end_at_defs;
1815 }
1816 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
1817 "expected %<)%>");
1818 contents = nreverse (objc_get_class_ivars (name));
1819 }
1820 end_at_defs:
1821 /* Parse the struct-declarations and semicolons. Problems with
1822 semicolons are diagnosed here; empty structures are diagnosed
1823 elsewhere. */
1824 while (true)
1825 {
1826 tree decls;
1827 /* Parse any stray semicolon. */
1828 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1829 {
1830 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1831 "extra semicolon in struct or union specified");
1832 c_parser_consume_token (parser);
1833 continue;
1834 }
1835 /* Stop if at the end of the struct or union contents. */
1836 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1837 {
1838 c_parser_consume_token (parser);
1839 break;
1840 }
1841 /* Accept #pragmas at struct scope. */
1842 if (c_parser_next_token_is (parser, CPP_PRAGMA))
1843 {
1844 c_parser_pragma (parser, pragma_external);
1845 continue;
1846 }
1847 /* Parse some comma-separated declarations, but not the
1848 trailing semicolon if any. */
1849 decls = c_parser_struct_declaration (parser);
1850 contents = chainon (decls, contents);
1851 /* If no semicolon follows, either we have a parse error or
1852 are at the end of the struct or union and should
1853 pedwarn. */
1854 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1855 c_parser_consume_token (parser);
1856 else
1857 {
1858 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1859 pedwarn (c_parser_peek_token (parser)->location, 0,
1860 "no semicolon at end of struct or union");
1861 else
1862 {
1863 c_parser_error (parser, "expected %<;%>");
1864 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1865 break;
1866 }
1867 }
1868 }
1869 postfix_attrs = c_parser_attributes (parser);
1870 ret.spec = finish_struct (type, nreverse (contents),
1871 chainon (attrs, postfix_attrs));
1872 ret.kind = ctsk_tagdef;
1873 return ret;
1874 }
1875 else if (!ident)
1876 {
1877 c_parser_error (parser, "expected %<{%>");
1878 ret.spec = error_mark_node;
1879 ret.kind = ctsk_tagref;
1880 return ret;
1881 }
1882 ret = parser_xref_tag (code, ident);
1883 return ret;
1884 }
1885
1886 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1887 the trailing semicolon.
1888
1889 struct-declaration:
1890 specifier-qualifier-list struct-declarator-list
1891
1892 specifier-qualifier-list:
1893 type-specifier specifier-qualifier-list[opt]
1894 type-qualifier specifier-qualifier-list[opt]
1895 attributes specifier-qualifier-list[opt]
1896
1897 struct-declarator-list:
1898 struct-declarator
1899 struct-declarator-list , attributes[opt] struct-declarator
1900
1901 struct-declarator:
1902 declarator attributes[opt]
1903 declarator[opt] : constant-expression attributes[opt]
1904
1905 GNU extensions:
1906
1907 struct-declaration:
1908 __extension__ struct-declaration
1909 specifier-qualifier-list
1910
1911 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1912 of attributes where shown is a GNU extension. In GNU C, we accept
1913 any expression without commas in the syntax (assignment
1914 expressions, not just conditional expressions); assignment
1915 expressions will be diagnosed as non-constant. */
1916
1917 static tree
1918 c_parser_struct_declaration (c_parser *parser)
1919 {
1920 struct c_declspecs *specs;
1921 tree prefix_attrs;
1922 tree all_prefix_attrs;
1923 tree decls;
1924 location_t decl_loc;
1925 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
1926 {
1927 int ext;
1928 tree decl;
1929 ext = disable_extension_diagnostics ();
1930 c_parser_consume_token (parser);
1931 decl = c_parser_struct_declaration (parser);
1932 restore_extension_diagnostics (ext);
1933 return decl;
1934 }
1935 specs = build_null_declspecs ();
1936 decl_loc = c_parser_peek_token (parser)->location;
1937 c_parser_declspecs (parser, specs, false, true, true);
1938 if (parser->error)
1939 return NULL_TREE;
1940 if (!specs->declspecs_seen_p)
1941 {
1942 c_parser_error (parser, "expected specifier-qualifier-list");
1943 return NULL_TREE;
1944 }
1945 finish_declspecs (specs);
1946 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1947 {
1948 tree ret;
1949 if (!specs->type_seen_p)
1950 {
1951 pedwarn (decl_loc, OPT_pedantic,
1952 "ISO C forbids member declarations with no members");
1953 shadow_tag_warned (specs, pedantic);
1954 ret = NULL_TREE;
1955 }
1956 else
1957 {
1958 /* Support for unnamed structs or unions as members of
1959 structs or unions (which is [a] useful and [b] supports
1960 MS P-SDK). */
1961 tree attrs = NULL;
1962
1963 ret = grokfield (c_parser_peek_token (parser)->location,
1964 build_id_declarator (NULL_TREE), specs,
1965 NULL_TREE, &attrs);
1966 if (ret)
1967 decl_attributes (&ret, attrs, 0);
1968 }
1969 return ret;
1970 }
1971 pending_xref_error ();
1972 prefix_attrs = specs->attrs;
1973 all_prefix_attrs = prefix_attrs;
1974 specs->attrs = NULL_TREE;
1975 decls = NULL_TREE;
1976 while (true)
1977 {
1978 /* Declaring one or more declarators or un-named bit-fields. */
1979 struct c_declarator *declarator;
1980 bool dummy = false;
1981 if (c_parser_next_token_is (parser, CPP_COLON))
1982 declarator = build_id_declarator (NULL_TREE);
1983 else
1984 declarator = c_parser_declarator (parser, specs->type_seen_p,
1985 C_DTR_NORMAL, &dummy);
1986 if (declarator == NULL)
1987 {
1988 c_parser_skip_to_end_of_block_or_statement (parser);
1989 break;
1990 }
1991 if (c_parser_next_token_is (parser, CPP_COLON)
1992 || c_parser_next_token_is (parser, CPP_COMMA)
1993 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1994 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
1995 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1996 {
1997 tree postfix_attrs = NULL_TREE;
1998 tree width = NULL_TREE;
1999 tree d;
2000 if (c_parser_next_token_is (parser, CPP_COLON))
2001 {
2002 c_parser_consume_token (parser);
2003 width = c_parser_expr_no_commas (parser, NULL).value;
2004 }
2005 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2006 postfix_attrs = c_parser_attributes (parser);
2007 d = grokfield (c_parser_peek_token (parser)->location,
2008 declarator, specs, width, &all_prefix_attrs);
2009 decl_attributes (&d, chainon (postfix_attrs,
2010 all_prefix_attrs), 0);
2011 TREE_CHAIN (d) = decls;
2012 decls = d;
2013 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2014 all_prefix_attrs = chainon (c_parser_attributes (parser),
2015 prefix_attrs);
2016 else
2017 all_prefix_attrs = prefix_attrs;
2018 if (c_parser_next_token_is (parser, CPP_COMMA))
2019 c_parser_consume_token (parser);
2020 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2021 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2022 {
2023 /* Semicolon consumed in caller. */
2024 break;
2025 }
2026 else
2027 {
2028 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2029 break;
2030 }
2031 }
2032 else
2033 {
2034 c_parser_error (parser,
2035 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2036 "%<__attribute__%>");
2037 break;
2038 }
2039 }
2040 return decls;
2041 }
2042
2043 /* Parse a typeof specifier (a GNU extension).
2044
2045 typeof-specifier:
2046 typeof ( expression )
2047 typeof ( type-name )
2048 */
2049
2050 static struct c_typespec
2051 c_parser_typeof_specifier (c_parser *parser)
2052 {
2053 struct c_typespec ret;
2054 ret.kind = ctsk_typeof;
2055 ret.spec = error_mark_node;
2056 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2057 c_parser_consume_token (parser);
2058 skip_evaluation++;
2059 in_typeof++;
2060 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2061 {
2062 skip_evaluation--;
2063 in_typeof--;
2064 return ret;
2065 }
2066 if (c_parser_next_token_starts_typename (parser))
2067 {
2068 struct c_type_name *type = c_parser_type_name (parser);
2069 skip_evaluation--;
2070 in_typeof--;
2071 if (type != NULL)
2072 {
2073 ret.spec = groktypename (type);
2074 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2075 }
2076 }
2077 else
2078 {
2079 bool was_vm;
2080 location_t here = c_parser_peek_token (parser)->location;
2081 struct c_expr expr = c_parser_expression (parser);
2082 skip_evaluation--;
2083 in_typeof--;
2084 if (TREE_CODE (expr.value) == COMPONENT_REF
2085 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2086 error_at (here, "%<typeof%> applied to a bit-field");
2087 ret.spec = TREE_TYPE (expr.value);
2088 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2089 /* This should be returned with the type so that when the type
2090 is evaluated, this can be evaluated. For now, we avoid
2091 evaluation when the context might. */
2092 if (!skip_evaluation && was_vm)
2093 {
2094 tree e = expr.value;
2095
2096 /* If the expression is not of a type to which we cannot assign a line
2097 number, wrap the thing in a no-op NOP_EXPR. */
2098 if (DECL_P (e) || CONSTANT_CLASS_P (e))
2099 e = build1 (NOP_EXPR, void_type_node, e);
2100
2101 protected_set_expr_location (e, here);
2102
2103 add_stmt (e);
2104 }
2105 pop_maybe_used (was_vm);
2106 }
2107 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2108 return ret;
2109 }
2110
2111 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2112 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2113 be redeclared; otherwise it may not. KIND indicates which kind of
2114 declarator is wanted. Returns a valid declarator except in the
2115 case of a syntax error in which case NULL is returned. *SEEN_ID is
2116 set to true if an identifier being declared is seen; this is used
2117 to diagnose bad forms of abstract array declarators and to
2118 determine whether an identifier list is syntactically permitted.
2119
2120 declarator:
2121 pointer[opt] direct-declarator
2122
2123 direct-declarator:
2124 identifier
2125 ( attributes[opt] declarator )
2126 direct-declarator array-declarator
2127 direct-declarator ( parameter-type-list )
2128 direct-declarator ( identifier-list[opt] )
2129
2130 pointer:
2131 * type-qualifier-list[opt]
2132 * type-qualifier-list[opt] pointer
2133
2134 type-qualifier-list:
2135 type-qualifier
2136 attributes
2137 type-qualifier-list type-qualifier
2138 type-qualifier-list attributes
2139
2140 parameter-type-list:
2141 parameter-list
2142 parameter-list , ...
2143
2144 parameter-list:
2145 parameter-declaration
2146 parameter-list , parameter-declaration
2147
2148 parameter-declaration:
2149 declaration-specifiers declarator attributes[opt]
2150 declaration-specifiers abstract-declarator[opt] attributes[opt]
2151
2152 identifier-list:
2153 identifier
2154 identifier-list , identifier
2155
2156 abstract-declarator:
2157 pointer
2158 pointer[opt] direct-abstract-declarator
2159
2160 direct-abstract-declarator:
2161 ( attributes[opt] abstract-declarator )
2162 direct-abstract-declarator[opt] array-declarator
2163 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2164
2165 GNU extensions:
2166
2167 direct-declarator:
2168 direct-declarator ( parameter-forward-declarations
2169 parameter-type-list[opt] )
2170
2171 direct-abstract-declarator:
2172 direct-abstract-declarator[opt] ( parameter-forward-declarations
2173 parameter-type-list[opt] )
2174
2175 parameter-forward-declarations:
2176 parameter-list ;
2177 parameter-forward-declarations parameter-list ;
2178
2179 The uses of attributes shown above are GNU extensions.
2180
2181 Some forms of array declarator are not included in C99 in the
2182 syntax for abstract declarators; these are disallowed elsewhere.
2183 This may be a defect (DR#289).
2184
2185 This function also accepts an omitted abstract declarator as being
2186 an abstract declarator, although not part of the formal syntax. */
2187
2188 static struct c_declarator *
2189 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2190 bool *seen_id)
2191 {
2192 /* Parse any initial pointer part. */
2193 if (c_parser_next_token_is (parser, CPP_MULT))
2194 {
2195 struct c_declspecs *quals_attrs = build_null_declspecs ();
2196 struct c_declarator *inner;
2197 c_parser_consume_token (parser);
2198 c_parser_declspecs (parser, quals_attrs, false, false, true);
2199 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2200 if (inner == NULL)
2201 return NULL;
2202 else
2203 return make_pointer_declarator (quals_attrs, inner);
2204 }
2205 /* Now we have a direct declarator, direct abstract declarator or
2206 nothing (which counts as a direct abstract declarator here). */
2207 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2208 }
2209
2210 /* Parse a direct declarator or direct abstract declarator; arguments
2211 as c_parser_declarator. */
2212
2213 static struct c_declarator *
2214 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2215 bool *seen_id)
2216 {
2217 /* The direct declarator must start with an identifier (possibly
2218 omitted) or a parenthesized declarator (possibly abstract). In
2219 an ordinary declarator, initial parentheses must start a
2220 parenthesized declarator. In an abstract declarator or parameter
2221 declarator, they could start a parenthesized declarator or a
2222 parameter list. To tell which, the open parenthesis and any
2223 following attributes must be read. If a declaration specifier
2224 follows, then it is a parameter list; if the specifier is a
2225 typedef name, there might be an ambiguity about redeclaring it,
2226 which is resolved in the direction of treating it as a typedef
2227 name. If a close parenthesis follows, it is also an empty
2228 parameter list, as the syntax does not permit empty abstract
2229 declarators. Otherwise, it is a parenthesized declarator (in
2230 which case the analysis may be repeated inside it, recursively).
2231
2232 ??? There is an ambiguity in a parameter declaration "int
2233 (__attribute__((foo)) x)", where x is not a typedef name: it
2234 could be an abstract declarator for a function, or declare x with
2235 parentheses. The proper resolution of this ambiguity needs
2236 documenting. At present we follow an accident of the old
2237 parser's implementation, whereby the first parameter must have
2238 some declaration specifiers other than just attributes. Thus as
2239 a parameter declaration it is treated as a parenthesized
2240 parameter named x, and as an abstract declarator it is
2241 rejected.
2242
2243 ??? Also following the old parser, attributes inside an empty
2244 parameter list are ignored, making it a list not yielding a
2245 prototype, rather than giving an error or making it have one
2246 parameter with implicit type int.
2247
2248 ??? Also following the old parser, typedef names may be
2249 redeclared in declarators, but not Objective-C class names. */
2250
2251 if (kind != C_DTR_ABSTRACT
2252 && c_parser_next_token_is (parser, CPP_NAME)
2253 && ((type_seen_p
2254 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2255 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2256 {
2257 struct c_declarator *inner
2258 = build_id_declarator (c_parser_peek_token (parser)->value);
2259 *seen_id = true;
2260 inner->id_loc = c_parser_peek_token (parser)->location;
2261 c_parser_consume_token (parser);
2262 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2263 }
2264
2265 if (kind != C_DTR_NORMAL
2266 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2267 {
2268 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2269 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2270 }
2271
2272 /* Either we are at the end of an abstract declarator, or we have
2273 parentheses. */
2274
2275 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2276 {
2277 tree attrs;
2278 struct c_declarator *inner;
2279 c_parser_consume_token (parser);
2280 attrs = c_parser_attributes (parser);
2281 if (kind != C_DTR_NORMAL
2282 && (c_parser_next_token_starts_declspecs (parser)
2283 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2284 {
2285 struct c_arg_info *args
2286 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2287 attrs);
2288 if (args == NULL)
2289 return NULL;
2290 else
2291 {
2292 inner
2293 = build_function_declarator (args,
2294 build_id_declarator (NULL_TREE));
2295 return c_parser_direct_declarator_inner (parser, *seen_id,
2296 inner);
2297 }
2298 }
2299 /* A parenthesized declarator. */
2300 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2301 if (inner != NULL && attrs != NULL)
2302 inner = build_attrs_declarator (attrs, inner);
2303 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2304 {
2305 c_parser_consume_token (parser);
2306 if (inner == NULL)
2307 return NULL;
2308 else
2309 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2310 }
2311 else
2312 {
2313 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2314 "expected %<)%>");
2315 return NULL;
2316 }
2317 }
2318 else
2319 {
2320 if (kind == C_DTR_NORMAL)
2321 {
2322 c_parser_error (parser, "expected identifier or %<(%>");
2323 return NULL;
2324 }
2325 else
2326 return build_id_declarator (NULL_TREE);
2327 }
2328 }
2329
2330 /* Parse part of a direct declarator or direct abstract declarator,
2331 given that some (in INNER) has already been parsed; ID_PRESENT is
2332 true if an identifier is present, false for an abstract
2333 declarator. */
2334
2335 static struct c_declarator *
2336 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2337 struct c_declarator *inner)
2338 {
2339 /* Parse a sequence of array declarators and parameter lists. */
2340 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2341 {
2342 struct c_declarator *declarator;
2343 struct c_declspecs *quals_attrs = build_null_declspecs ();
2344 bool static_seen;
2345 bool star_seen;
2346 tree dimen;
2347 c_parser_consume_token (parser);
2348 c_parser_declspecs (parser, quals_attrs, false, false, true);
2349 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2350 if (static_seen)
2351 c_parser_consume_token (parser);
2352 if (static_seen && !quals_attrs->declspecs_seen_p)
2353 c_parser_declspecs (parser, quals_attrs, false, false, true);
2354 if (!quals_attrs->declspecs_seen_p)
2355 quals_attrs = NULL;
2356 /* If "static" is present, there must be an array dimension.
2357 Otherwise, there may be a dimension, "*", or no
2358 dimension. */
2359 if (static_seen)
2360 {
2361 star_seen = false;
2362 dimen = c_parser_expr_no_commas (parser, NULL).value;
2363 }
2364 else
2365 {
2366 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2367 {
2368 dimen = NULL_TREE;
2369 star_seen = false;
2370 }
2371 else if (c_parser_next_token_is (parser, CPP_MULT))
2372 {
2373 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2374 {
2375 dimen = NULL_TREE;
2376 star_seen = true;
2377 c_parser_consume_token (parser);
2378 }
2379 else
2380 {
2381 star_seen = false;
2382 dimen = c_parser_expr_no_commas (parser, NULL).value;
2383 }
2384 }
2385 else
2386 {
2387 star_seen = false;
2388 dimen = c_parser_expr_no_commas (parser, NULL).value;
2389 }
2390 }
2391 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2392 c_parser_consume_token (parser);
2393 else
2394 {
2395 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2396 "expected %<]%>");
2397 return NULL;
2398 }
2399 declarator = build_array_declarator (dimen, quals_attrs, static_seen,
2400 star_seen);
2401 if (declarator == NULL)
2402 return NULL;
2403 inner = set_array_declarator_inner (declarator, inner);
2404 return c_parser_direct_declarator_inner (parser, id_present, inner);
2405 }
2406 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2407 {
2408 tree attrs;
2409 struct c_arg_info *args;
2410 c_parser_consume_token (parser);
2411 attrs = c_parser_attributes (parser);
2412 args = c_parser_parms_declarator (parser, id_present, attrs);
2413 if (args == NULL)
2414 return NULL;
2415 else
2416 {
2417 inner = build_function_declarator (args, inner);
2418 return c_parser_direct_declarator_inner (parser, id_present, inner);
2419 }
2420 }
2421 return inner;
2422 }
2423
2424 /* Parse a parameter list or identifier list, including the closing
2425 parenthesis but not the opening one. ATTRS are the attributes at
2426 the start of the list. ID_LIST_OK is true if an identifier list is
2427 acceptable; such a list must not have attributes at the start. */
2428
2429 static struct c_arg_info *
2430 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2431 {
2432 push_scope ();
2433 declare_parm_level ();
2434 /* If the list starts with an identifier, it is an identifier list.
2435 Otherwise, it is either a prototype list or an empty list. */
2436 if (id_list_ok
2437 && !attrs
2438 && c_parser_next_token_is (parser, CPP_NAME)
2439 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2440 {
2441 tree list = NULL_TREE, *nextp = &list;
2442 while (c_parser_next_token_is (parser, CPP_NAME)
2443 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2444 {
2445 *nextp = build_tree_list (NULL_TREE,
2446 c_parser_peek_token (parser)->value);
2447 nextp = & TREE_CHAIN (*nextp);
2448 c_parser_consume_token (parser);
2449 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2450 break;
2451 c_parser_consume_token (parser);
2452 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2453 {
2454 c_parser_error (parser, "expected identifier");
2455 break;
2456 }
2457 }
2458 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2459 {
2460 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2461 ret->parms = 0;
2462 ret->tags = 0;
2463 ret->types = list;
2464 ret->others = 0;
2465 ret->pending_sizes = 0;
2466 ret->had_vla_unspec = 0;
2467 c_parser_consume_token (parser);
2468 pop_scope ();
2469 return ret;
2470 }
2471 else
2472 {
2473 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2474 "expected %<)%>");
2475 pop_scope ();
2476 return NULL;
2477 }
2478 }
2479 else
2480 {
2481 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2482 pop_scope ();
2483 return ret;
2484 }
2485 }
2486
2487 /* Parse a parameter list (possibly empty), including the closing
2488 parenthesis but not the opening one. ATTRS are the attributes at
2489 the start of the list. */
2490
2491 static struct c_arg_info *
2492 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2493 {
2494 bool good_parm = false;
2495 /* ??? Following the old parser, forward parameter declarations may
2496 use abstract declarators, and if no real parameter declarations
2497 follow the forward declarations then this is not diagnosed. Also
2498 note as above that attributes are ignored as the only contents of
2499 the parentheses, or as the only contents after forward
2500 declarations. */
2501 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2502 {
2503 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2504 ret->parms = 0;
2505 ret->tags = 0;
2506 ret->types = 0;
2507 ret->others = 0;
2508 ret->pending_sizes = 0;
2509 ret->had_vla_unspec = 0;
2510 c_parser_consume_token (parser);
2511 return ret;
2512 }
2513 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2514 {
2515 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2516 ret->parms = 0;
2517 ret->tags = 0;
2518 ret->others = 0;
2519 ret->pending_sizes = 0;
2520 ret->had_vla_unspec = 0;
2521 /* Suppress -Wold-style-definition for this case. */
2522 ret->types = error_mark_node;
2523 error_at (c_parser_peek_token (parser)->location,
2524 "ISO C requires a named argument before %<...%>");
2525 c_parser_consume_token (parser);
2526 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2527 {
2528 c_parser_consume_token (parser);
2529 return ret;
2530 }
2531 else
2532 {
2533 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2534 "expected %<)%>");
2535 return NULL;
2536 }
2537 }
2538 /* Nonempty list of parameters, either terminated with semicolon
2539 (forward declarations; recurse) or with close parenthesis (normal
2540 function) or with ", ... )" (variadic function). */
2541 while (true)
2542 {
2543 /* Parse a parameter. */
2544 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2545 attrs = NULL_TREE;
2546 if (parm != NULL)
2547 {
2548 good_parm = true;
2549 push_parm_decl (parm);
2550 }
2551 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2552 {
2553 tree new_attrs;
2554 c_parser_consume_token (parser);
2555 mark_forward_parm_decls ();
2556 new_attrs = c_parser_attributes (parser);
2557 return c_parser_parms_list_declarator (parser, new_attrs);
2558 }
2559 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2560 {
2561 c_parser_consume_token (parser);
2562 if (good_parm)
2563 return get_parm_info (false);
2564 else
2565 {
2566 struct c_arg_info *ret
2567 = XOBNEW (&parser_obstack, struct c_arg_info);
2568 ret->parms = 0;
2569 ret->tags = 0;
2570 ret->types = 0;
2571 ret->others = 0;
2572 ret->pending_sizes = 0;
2573 ret->had_vla_unspec = 0;
2574 return ret;
2575 }
2576 }
2577 if (!c_parser_require (parser, CPP_COMMA,
2578 "expected %<;%>, %<,%> or %<)%>"))
2579 {
2580 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2581 return NULL;
2582 }
2583 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2584 {
2585 c_parser_consume_token (parser);
2586 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2587 {
2588 c_parser_consume_token (parser);
2589 if (good_parm)
2590 return get_parm_info (true);
2591 else
2592 {
2593 struct c_arg_info *ret
2594 = XOBNEW (&parser_obstack, struct c_arg_info);
2595 ret->parms = 0;
2596 ret->tags = 0;
2597 ret->types = 0;
2598 ret->others = 0;
2599 ret->pending_sizes = 0;
2600 ret->had_vla_unspec = 0;
2601 return ret;
2602 }
2603 }
2604 else
2605 {
2606 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2607 "expected %<)%>");
2608 return NULL;
2609 }
2610 }
2611 }
2612 }
2613
2614 /* Parse a parameter declaration. ATTRS are the attributes at the
2615 start of the declaration if it is the first parameter. */
2616
2617 static struct c_parm *
2618 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2619 {
2620 struct c_declspecs *specs;
2621 struct c_declarator *declarator;
2622 tree prefix_attrs;
2623 tree postfix_attrs = NULL_TREE;
2624 bool dummy = false;
2625 if (!c_parser_next_token_starts_declspecs (parser))
2626 {
2627 /* ??? In some Objective-C cases '...' isn't applicable so there
2628 should be a different message. */
2629 c_parser_error (parser,
2630 "expected declaration specifiers or %<...%>");
2631 c_parser_skip_to_end_of_parameter (parser);
2632 return NULL;
2633 }
2634 specs = build_null_declspecs ();
2635 if (attrs)
2636 {
2637 declspecs_add_attrs (specs, attrs);
2638 attrs = NULL_TREE;
2639 }
2640 c_parser_declspecs (parser, specs, true, true, true);
2641 finish_declspecs (specs);
2642 pending_xref_error ();
2643 prefix_attrs = specs->attrs;
2644 specs->attrs = NULL_TREE;
2645 declarator = c_parser_declarator (parser, specs->type_seen_p,
2646 C_DTR_PARM, &dummy);
2647 if (declarator == NULL)
2648 {
2649 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2650 return NULL;
2651 }
2652 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2653 postfix_attrs = c_parser_attributes (parser);
2654 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2655 declarator);
2656 }
2657
2658 /* Parse a string literal in an asm expression. It should not be
2659 translated, and wide string literals are an error although
2660 permitted by the syntax. This is a GNU extension.
2661
2662 asm-string-literal:
2663 string-literal
2664
2665 ??? At present, following the old parser, the caller needs to have
2666 set lex_untranslated_string to 1. It would be better to follow the
2667 C++ parser rather than using this kludge. */
2668
2669 static tree
2670 c_parser_asm_string_literal (c_parser *parser)
2671 {
2672 tree str;
2673 if (c_parser_next_token_is (parser, CPP_STRING))
2674 {
2675 str = c_parser_peek_token (parser)->value;
2676 c_parser_consume_token (parser);
2677 }
2678 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2679 {
2680 error_at (c_parser_peek_token (parser)->location,
2681 "wide string literal in %<asm%>");
2682 str = build_string (1, "");
2683 c_parser_consume_token (parser);
2684 }
2685 else
2686 {
2687 c_parser_error (parser, "expected string literal");
2688 str = NULL_TREE;
2689 }
2690 return str;
2691 }
2692
2693 /* Parse a simple asm expression. This is used in restricted
2694 contexts, where a full expression with inputs and outputs does not
2695 make sense. This is a GNU extension.
2696
2697 simple-asm-expr:
2698 asm ( asm-string-literal )
2699 */
2700
2701 static tree
2702 c_parser_simple_asm_expr (c_parser *parser)
2703 {
2704 tree str;
2705 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2706 /* ??? Follow the C++ parser rather than using the
2707 lex_untranslated_string kludge. */
2708 parser->lex_untranslated_string = true;
2709 c_parser_consume_token (parser);
2710 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2711 {
2712 parser->lex_untranslated_string = false;
2713 return NULL_TREE;
2714 }
2715 str = c_parser_asm_string_literal (parser);
2716 parser->lex_untranslated_string = false;
2717 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2718 {
2719 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2720 return NULL_TREE;
2721 }
2722 return str;
2723 }
2724
2725 /* Parse (possibly empty) attributes. This is a GNU extension.
2726
2727 attributes:
2728 empty
2729 attributes attribute
2730
2731 attribute:
2732 __attribute__ ( ( attribute-list ) )
2733
2734 attribute-list:
2735 attrib
2736 attribute_list , attrib
2737
2738 attrib:
2739 empty
2740 any-word
2741 any-word ( identifier )
2742 any-word ( identifier , nonempty-expr-list )
2743 any-word ( expr-list )
2744
2745 where the "identifier" must not be declared as a type, and
2746 "any-word" may be any identifier (including one declared as a
2747 type), a reserved word storage class specifier, type specifier or
2748 type qualifier. ??? This still leaves out most reserved keywords
2749 (following the old parser), shouldn't we include them, and why not
2750 allow identifiers declared as types to start the arguments? */
2751
2752 static tree
2753 c_parser_attributes (c_parser *parser)
2754 {
2755 tree attrs = NULL_TREE;
2756 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2757 {
2758 /* ??? Follow the C++ parser rather than using the
2759 lex_untranslated_string kludge. */
2760 parser->lex_untranslated_string = true;
2761 c_parser_consume_token (parser);
2762 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2763 {
2764 parser->lex_untranslated_string = false;
2765 return attrs;
2766 }
2767 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2768 {
2769 parser->lex_untranslated_string = false;
2770 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2771 return attrs;
2772 }
2773 /* Parse the attribute list. */
2774 while (c_parser_next_token_is (parser, CPP_COMMA)
2775 || c_parser_next_token_is (parser, CPP_NAME)
2776 || c_parser_next_token_is (parser, CPP_KEYWORD))
2777 {
2778 tree attr, attr_name, attr_args;
2779 if (c_parser_next_token_is (parser, CPP_COMMA))
2780 {
2781 c_parser_consume_token (parser);
2782 continue;
2783 }
2784 if (c_parser_next_token_is (parser, CPP_KEYWORD))
2785 {
2786 /* ??? See comment above about what keywords are
2787 accepted here. */
2788 bool ok;
2789 switch (c_parser_peek_token (parser)->keyword)
2790 {
2791 case RID_STATIC:
2792 case RID_UNSIGNED:
2793 case RID_LONG:
2794 case RID_CONST:
2795 case RID_EXTERN:
2796 case RID_REGISTER:
2797 case RID_TYPEDEF:
2798 case RID_SHORT:
2799 case RID_INLINE:
2800 case RID_VOLATILE:
2801 case RID_SIGNED:
2802 case RID_AUTO:
2803 case RID_RESTRICT:
2804 case RID_COMPLEX:
2805 case RID_THREAD:
2806 case RID_INT:
2807 case RID_CHAR:
2808 case RID_FLOAT:
2809 case RID_DOUBLE:
2810 case RID_VOID:
2811 case RID_DFLOAT32:
2812 case RID_DFLOAT64:
2813 case RID_DFLOAT128:
2814 case RID_BOOL:
2815 case RID_FRACT:
2816 case RID_ACCUM:
2817 case RID_SAT:
2818 ok = true;
2819 break;
2820 default:
2821 ok = false;
2822 break;
2823 }
2824 if (!ok)
2825 break;
2826 /* Accept __attribute__((__const)) as __attribute__((const))
2827 etc. */
2828 attr_name
2829 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
2830 }
2831 else
2832 attr_name = c_parser_peek_token (parser)->value;
2833 c_parser_consume_token (parser);
2834 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
2835 {
2836 attr = build_tree_list (attr_name, NULL_TREE);
2837 attrs = chainon (attrs, attr);
2838 continue;
2839 }
2840 c_parser_consume_token (parser);
2841 /* Parse the attribute contents. If they start with an
2842 identifier which is followed by a comma or close
2843 parenthesis, then the arguments start with that
2844 identifier; otherwise they are an expression list. */
2845 if (c_parser_next_token_is (parser, CPP_NAME)
2846 && c_parser_peek_token (parser)->id_kind == C_ID_ID
2847 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
2848 || (c_parser_peek_2nd_token (parser)->type
2849 == CPP_CLOSE_PAREN)))
2850 {
2851 tree arg1 = c_parser_peek_token (parser)->value;
2852 c_parser_consume_token (parser);
2853 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2854 attr_args = build_tree_list (NULL_TREE, arg1);
2855 else
2856 {
2857 c_parser_consume_token (parser);
2858 attr_args = tree_cons (NULL_TREE, arg1,
2859 c_parser_expr_list (parser, false));
2860 }
2861 }
2862 else
2863 {
2864 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2865 attr_args = NULL_TREE;
2866 else
2867 attr_args = c_parser_expr_list (parser, false);
2868 }
2869 attr = build_tree_list (attr_name, attr_args);
2870 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2871 c_parser_consume_token (parser);
2872 else
2873 {
2874 parser->lex_untranslated_string = false;
2875 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2876 "expected %<)%>");
2877 return attrs;
2878 }
2879 attrs = chainon (attrs, attr);
2880 }
2881 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2882 c_parser_consume_token (parser);
2883 else
2884 {
2885 parser->lex_untranslated_string = false;
2886 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2887 "expected %<)%>");
2888 return attrs;
2889 }
2890 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2891 c_parser_consume_token (parser);
2892 else
2893 {
2894 parser->lex_untranslated_string = false;
2895 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2896 "expected %<)%>");
2897 return attrs;
2898 }
2899 parser->lex_untranslated_string = false;
2900 }
2901 return attrs;
2902 }
2903
2904 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2905
2906 type-name:
2907 specifier-qualifier-list abstract-declarator[opt]
2908 */
2909
2910 static struct c_type_name *
2911 c_parser_type_name (c_parser *parser)
2912 {
2913 struct c_declspecs *specs = build_null_declspecs ();
2914 struct c_declarator *declarator;
2915 struct c_type_name *ret;
2916 bool dummy = false;
2917 c_parser_declspecs (parser, specs, false, true, true);
2918 if (!specs->declspecs_seen_p)
2919 {
2920 c_parser_error (parser, "expected specifier-qualifier-list");
2921 return NULL;
2922 }
2923 pending_xref_error ();
2924 finish_declspecs (specs);
2925 declarator = c_parser_declarator (parser, specs->type_seen_p,
2926 C_DTR_ABSTRACT, &dummy);
2927 if (declarator == NULL)
2928 return NULL;
2929 ret = XOBNEW (&parser_obstack, struct c_type_name);
2930 ret->specs = specs;
2931 ret->declarator = declarator;
2932 return ret;
2933 }
2934
2935 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2936
2937 initializer:
2938 assignment-expression
2939 { initializer-list }
2940 { initializer-list , }
2941
2942 initializer-list:
2943 designation[opt] initializer
2944 initializer-list , designation[opt] initializer
2945
2946 designation:
2947 designator-list =
2948
2949 designator-list:
2950 designator
2951 designator-list designator
2952
2953 designator:
2954 array-designator
2955 . identifier
2956
2957 array-designator:
2958 [ constant-expression ]
2959
2960 GNU extensions:
2961
2962 initializer:
2963 { }
2964
2965 designation:
2966 array-designator
2967 identifier :
2968
2969 array-designator:
2970 [ constant-expression ... constant-expression ]
2971
2972 Any expression without commas is accepted in the syntax for the
2973 constant-expressions, with non-constant expressions rejected later.
2974
2975 This function is only used for top-level initializers; for nested
2976 ones, see c_parser_initval. */
2977
2978 static struct c_expr
2979 c_parser_initializer (c_parser *parser)
2980 {
2981 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2982 return c_parser_braced_init (parser, NULL_TREE, false);
2983 else
2984 {
2985 struct c_expr ret;
2986 ret = c_parser_expr_no_commas (parser, NULL);
2987 if (TREE_CODE (ret.value) != STRING_CST
2988 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
2989 ret = default_function_array_conversion (ret);
2990 return ret;
2991 }
2992 }
2993
2994 /* Parse a braced initializer list. TYPE is the type specified for a
2995 compound literal, and NULL_TREE for other initializers and for
2996 nested braced lists. NESTED_P is true for nested braced lists,
2997 false for the list of a compound literal or the list that is the
2998 top-level initializer in a declaration. */
2999
3000 static struct c_expr
3001 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3002 {
3003 location_t brace_loc = c_parser_peek_token (parser)->location;
3004 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3005 c_parser_consume_token (parser);
3006 if (nested_p)
3007 push_init_level (0);
3008 else
3009 really_start_incremental_init (type);
3010 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3011 {
3012 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3013 }
3014 else
3015 {
3016 /* Parse a non-empty initializer list, possibly with a trailing
3017 comma. */
3018 while (true)
3019 {
3020 c_parser_initelt (parser);
3021 if (parser->error)
3022 break;
3023 if (c_parser_next_token_is (parser, CPP_COMMA))
3024 c_parser_consume_token (parser);
3025 else
3026 break;
3027 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3028 break;
3029 }
3030 }
3031 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3032 {
3033 struct c_expr ret;
3034 ret.value = error_mark_node;
3035 ret.original_code = ERROR_MARK;
3036 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3037 return ret;
3038 }
3039 c_parser_consume_token (parser);
3040 return pop_init_level (0);
3041 }
3042
3043 /* Parse a nested initializer, including designators. */
3044
3045 static void
3046 c_parser_initelt (c_parser *parser)
3047 {
3048 /* Parse any designator or designator list. A single array
3049 designator may have the subsequent "=" omitted in GNU C, but a
3050 longer list or a structure member designator may not. */
3051 if (c_parser_next_token_is (parser, CPP_NAME)
3052 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3053 {
3054 /* Old-style structure member designator. */
3055 set_init_label (c_parser_peek_token (parser)->value);
3056 /* Use the colon as the error location. */
3057 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3058 "obsolete use of designated initializer with %<:%>");
3059 c_parser_consume_token (parser);
3060 c_parser_consume_token (parser);
3061 }
3062 else
3063 {
3064 /* des_seen is 0 if there have been no designators, 1 if there
3065 has been a single array designator and 2 otherwise. */
3066 int des_seen = 0;
3067 /* Location of a designator. */
3068 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3069 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3070 || c_parser_next_token_is (parser, CPP_DOT))
3071 {
3072 int des_prev = des_seen;
3073 if (!des_seen)
3074 des_loc = c_parser_peek_token (parser)->location;
3075 if (des_seen < 2)
3076 des_seen++;
3077 if (c_parser_next_token_is (parser, CPP_DOT))
3078 {
3079 des_seen = 2;
3080 c_parser_consume_token (parser);
3081 if (c_parser_next_token_is (parser, CPP_NAME))
3082 {
3083 set_init_label (c_parser_peek_token (parser)->value);
3084 c_parser_consume_token (parser);
3085 }
3086 else
3087 {
3088 struct c_expr init;
3089 init.value = error_mark_node;
3090 init.original_code = ERROR_MARK;
3091 c_parser_error (parser, "expected identifier");
3092 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3093 process_init_element (init, false);
3094 return;
3095 }
3096 }
3097 else
3098 {
3099 tree first, second;
3100 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3101 /* ??? Following the old parser, [ objc-receiver
3102 objc-message-args ] is accepted as an initializer,
3103 being distinguished from a designator by what follows
3104 the first assignment expression inside the square
3105 brackets, but after a first array designator a
3106 subsequent square bracket is for Objective-C taken to
3107 start an expression, using the obsolete form of
3108 designated initializer without '=', rather than
3109 possibly being a second level of designation: in LALR
3110 terms, the '[' is shifted rather than reducing
3111 designator to designator-list. */
3112 if (des_prev == 1 && c_dialect_objc ())
3113 {
3114 des_seen = des_prev;
3115 break;
3116 }
3117 if (des_prev == 0 && c_dialect_objc ())
3118 {
3119 /* This might be an array designator or an
3120 Objective-C message expression. If the former,
3121 continue parsing here; if the latter, parse the
3122 remainder of the initializer given the starting
3123 primary-expression. ??? It might make sense to
3124 distinguish when des_prev == 1 as well; see
3125 previous comment. */
3126 tree rec, args;
3127 struct c_expr mexpr;
3128 c_parser_consume_token (parser);
3129 if (c_parser_peek_token (parser)->type == CPP_NAME
3130 && ((c_parser_peek_token (parser)->id_kind
3131 == C_ID_TYPENAME)
3132 || (c_parser_peek_token (parser)->id_kind
3133 == C_ID_CLASSNAME)))
3134 {
3135 /* Type name receiver. */
3136 tree id = c_parser_peek_token (parser)->value;
3137 c_parser_consume_token (parser);
3138 rec = objc_get_class_reference (id);
3139 goto parse_message_args;
3140 }
3141 first = c_parser_expr_no_commas (parser, NULL).value;
3142 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3143 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3144 goto array_desig_after_first;
3145 /* Expression receiver. So far only one part
3146 without commas has been parsed; there might be
3147 more of the expression. */
3148 rec = first;
3149 while (c_parser_next_token_is (parser, CPP_COMMA))
3150 {
3151 struct c_expr next;
3152 c_parser_consume_token (parser);
3153 next = c_parser_expr_no_commas (parser, NULL);
3154 next = default_function_array_conversion (next);
3155 rec = build_compound_expr (rec, next.value);
3156 }
3157 parse_message_args:
3158 /* Now parse the objc-message-args. */
3159 args = c_parser_objc_message_args (parser);
3160 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3161 "expected %<]%>");
3162 mexpr.value
3163 = objc_build_message_expr (build_tree_list (rec, args));
3164 mexpr.original_code = ERROR_MARK;
3165 /* Now parse and process the remainder of the
3166 initializer, starting with this message
3167 expression as a primary-expression. */
3168 c_parser_initval (parser, &mexpr);
3169 return;
3170 }
3171 c_parser_consume_token (parser);
3172 first = c_parser_expr_no_commas (parser, NULL).value;
3173 array_desig_after_first:
3174 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3175 {
3176 ellipsis_loc = c_parser_peek_token (parser)->location;
3177 c_parser_consume_token (parser);
3178 second = c_parser_expr_no_commas (parser, NULL).value;
3179 }
3180 else
3181 second = NULL_TREE;
3182 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3183 {
3184 c_parser_consume_token (parser);
3185 set_init_index (first, second);
3186 if (second)
3187 pedwarn (ellipsis_loc, OPT_pedantic,
3188 "ISO C forbids specifying range of elements to initialize");
3189 }
3190 else
3191 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3192 "expected %<]%>");
3193 }
3194 }
3195 if (des_seen >= 1)
3196 {
3197 if (c_parser_next_token_is (parser, CPP_EQ))
3198 {
3199 if (!flag_isoc99)
3200 pedwarn (des_loc, OPT_pedantic,
3201 "ISO C90 forbids specifying subobject to initialize");
3202 c_parser_consume_token (parser);
3203 }
3204 else
3205 {
3206 if (des_seen == 1)
3207 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3208 "obsolete use of designated initializer without %<=%>");
3209 else
3210 {
3211 struct c_expr init;
3212 init.value = error_mark_node;
3213 init.original_code = ERROR_MARK;
3214 c_parser_error (parser, "expected %<=%>");
3215 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3216 process_init_element (init, false);
3217 return;
3218 }
3219 }
3220 }
3221 }
3222 c_parser_initval (parser, NULL);
3223 }
3224
3225 /* Parse a nested initializer; as c_parser_initializer but parses
3226 initializers within braced lists, after any designators have been
3227 applied. If AFTER is not NULL then it is an Objective-C message
3228 expression which is the primary-expression starting the
3229 initializer. */
3230
3231 static void
3232 c_parser_initval (c_parser *parser, struct c_expr *after)
3233 {
3234 struct c_expr init;
3235 gcc_assert (!after || c_dialect_objc ());
3236 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3237 init = c_parser_braced_init (parser, NULL_TREE, true);
3238 else
3239 {
3240 init = c_parser_expr_no_commas (parser, after);
3241 if (init.value != NULL_TREE
3242 && TREE_CODE (init.value) != STRING_CST
3243 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3244 init = default_function_array_conversion (init);
3245 }
3246 process_init_element (init, false);
3247 }
3248
3249 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3250 C99 6.8.2).
3251
3252 compound-statement:
3253 { block-item-list[opt] }
3254 { label-declarations block-item-list }
3255
3256 block-item-list:
3257 block-item
3258 block-item-list block-item
3259
3260 block-item:
3261 nested-declaration
3262 statement
3263
3264 nested-declaration:
3265 declaration
3266
3267 GNU extensions:
3268
3269 compound-statement:
3270 { label-declarations block-item-list }
3271
3272 nested-declaration:
3273 __extension__ nested-declaration
3274 nested-function-definition
3275
3276 label-declarations:
3277 label-declaration
3278 label-declarations label-declaration
3279
3280 label-declaration:
3281 __label__ identifier-list ;
3282
3283 Allowing the mixing of declarations and code is new in C99. The
3284 GNU syntax also permits (not shown above) labels at the end of
3285 compound statements, which yield an error. We don't allow labels
3286 on declarations; this might seem like a natural extension, but
3287 there would be a conflict between attributes on the label and
3288 prefix attributes on the declaration. ??? The syntax follows the
3289 old parser in requiring something after label declarations.
3290 Although they are erroneous if the labels declared aren't defined,
3291 is it useful for the syntax to be this way?
3292
3293 OpenMP:
3294
3295 block-item:
3296 openmp-directive
3297
3298 openmp-directive:
3299 barrier-directive
3300 flush-directive */
3301
3302 static tree
3303 c_parser_compound_statement (c_parser *parser)
3304 {
3305 tree stmt;
3306 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3307 return error_mark_node;
3308 stmt = c_begin_compound_stmt (true);
3309 c_parser_compound_statement_nostart (parser);
3310 return c_end_compound_stmt (stmt, true);
3311 }
3312
3313 /* Parse a compound statement except for the opening brace. This is
3314 used for parsing both compound statements and statement expressions
3315 (which follow different paths to handling the opening). */
3316
3317 static void
3318 c_parser_compound_statement_nostart (c_parser *parser)
3319 {
3320 bool last_stmt = false;
3321 bool last_label = false;
3322 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3323 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3324 {
3325 c_parser_consume_token (parser);
3326 return;
3327 }
3328 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3329 {
3330 location_t err_loc = c_parser_peek_token (parser)->location;
3331 /* Read zero or more forward-declarations for labels that nested
3332 functions can jump to. */
3333 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3334 {
3335 c_parser_consume_token (parser);
3336 /* Any identifiers, including those declared as type names,
3337 are OK here. */
3338 while (true)
3339 {
3340 tree label;
3341 if (c_parser_next_token_is_not (parser, CPP_NAME))
3342 {
3343 c_parser_error (parser, "expected identifier");
3344 break;
3345 }
3346 label
3347 = declare_label (c_parser_peek_token (parser)->value);
3348 C_DECLARED_LABEL_FLAG (label) = 1;
3349 add_stmt (build_stmt (DECL_EXPR, label));
3350 c_parser_consume_token (parser);
3351 if (c_parser_next_token_is (parser, CPP_COMMA))
3352 c_parser_consume_token (parser);
3353 else
3354 break;
3355 }
3356 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3357 }
3358 pedwarn (err_loc, OPT_pedantic, "ISO C forbids label declarations");
3359 }
3360 /* We must now have at least one statement, label or declaration. */
3361 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3362 {
3363 c_parser_error (parser, "expected declaration or statement");
3364 c_parser_consume_token (parser);
3365 return;
3366 }
3367 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3368 {
3369 location_t loc = c_parser_peek_token (parser)->location;
3370 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3371 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3372 || (c_parser_next_token_is (parser, CPP_NAME)
3373 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3374 {
3375 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3376 label_loc = c_parser_peek_2nd_token (parser)->location;
3377 else
3378 label_loc = c_parser_peek_token (parser)->location;
3379 last_label = true;
3380 last_stmt = false;
3381 c_parser_label (parser);
3382 }
3383 else if (!last_label
3384 && c_parser_next_token_starts_declspecs (parser))
3385 {
3386 last_label = false;
3387 c_parser_declaration_or_fndef (parser, true, true, true, true);
3388 if (last_stmt)
3389 pedwarn_c90 (loc,
3390 (pedantic && !flag_isoc99)
3391 ? OPT_pedantic
3392 : OPT_Wdeclaration_after_statement,
3393 "ISO C90 forbids mixed declarations and code");
3394 last_stmt = false;
3395 }
3396 else if (!last_label
3397 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3398 {
3399 /* __extension__ can start a declaration, but is also an
3400 unary operator that can start an expression. Consume all
3401 but the last of a possible series of __extension__ to
3402 determine which. */
3403 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3404 && (c_parser_peek_2nd_token (parser)->keyword
3405 == RID_EXTENSION))
3406 c_parser_consume_token (parser);
3407 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3408 {
3409 int ext;
3410 ext = disable_extension_diagnostics ();
3411 c_parser_consume_token (parser);
3412 last_label = false;
3413 c_parser_declaration_or_fndef (parser, true, true, true, true);
3414 /* Following the old parser, __extension__ does not
3415 disable this diagnostic. */
3416 restore_extension_diagnostics (ext);
3417 if (last_stmt)
3418 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
3419 ? OPT_pedantic
3420 : OPT_Wdeclaration_after_statement,
3421 "ISO C90 forbids mixed declarations and code");
3422 last_stmt = false;
3423 }
3424 else
3425 goto statement;
3426 }
3427 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3428 {
3429 /* External pragmas, and some omp pragmas, are not associated
3430 with regular c code, and so are not to be considered statements
3431 syntactically. This ensures that the user doesn't put them
3432 places that would turn into syntax errors if the directive
3433 were ignored. */
3434 if (c_parser_pragma (parser, pragma_compound))
3435 last_label = false, last_stmt = true;
3436 }
3437 else if (c_parser_next_token_is (parser, CPP_EOF))
3438 {
3439 c_parser_error (parser, "expected declaration or statement");
3440 return;
3441 }
3442 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3443 {
3444 if (parser->in_if_block)
3445 {
3446 error_at (loc, """expected %<}%> before %<else%>");
3447 return;
3448 }
3449 else
3450 {
3451 error_at (loc, "%<else%> without a previous %<if%>");
3452 c_parser_consume_token (parser);
3453 continue;
3454 }
3455 }
3456 else
3457 {
3458 statement:
3459 last_label = false;
3460 last_stmt = true;
3461 c_parser_statement_after_labels (parser);
3462 }
3463
3464 parser->error = false;
3465 }
3466 if (last_label)
3467 error_at (label_loc, "label at end of compound statement");
3468 c_parser_consume_token (parser);
3469 }
3470
3471 /* Parse a label (C90 6.6.1, C99 6.8.1).
3472
3473 label:
3474 identifier : attributes[opt]
3475 case constant-expression :
3476 default :
3477
3478 GNU extensions:
3479
3480 label:
3481 case constant-expression ... constant-expression :
3482
3483 The use of attributes on labels is a GNU extension. The syntax in
3484 GNU C accepts any expressions without commas, non-constant
3485 expressions being rejected later. */
3486
3487 static void
3488 c_parser_label (c_parser *parser)
3489 {
3490 location_t loc1 = c_parser_peek_token (parser)->location;
3491 tree label = NULL_TREE;
3492 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3493 {
3494 tree exp1, exp2;
3495 c_parser_consume_token (parser);
3496 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3497 if (c_parser_next_token_is (parser, CPP_COLON))
3498 {
3499 c_parser_consume_token (parser);
3500 label = do_case (exp1, NULL_TREE);
3501 }
3502 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3503 {
3504 c_parser_consume_token (parser);
3505 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3506 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3507 label = do_case (exp1, exp2);
3508 }
3509 else
3510 c_parser_error (parser, "expected %<:%> or %<...%>");
3511 }
3512 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3513 {
3514 c_parser_consume_token (parser);
3515 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3516 label = do_case (NULL_TREE, NULL_TREE);
3517 }
3518 else
3519 {
3520 tree name = c_parser_peek_token (parser)->value;
3521 tree tlab;
3522 tree attrs;
3523 location_t loc2 = c_parser_peek_token (parser)->location;
3524 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3525 c_parser_consume_token (parser);
3526 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3527 c_parser_consume_token (parser);
3528 attrs = c_parser_attributes (parser);
3529 tlab = define_label (loc2, name);
3530 if (tlab)
3531 {
3532 decl_attributes (&tlab, attrs, 0);
3533 label = add_stmt (build_stmt (LABEL_EXPR, tlab));
3534 }
3535 }
3536 if (label)
3537 {
3538 SET_EXPR_LOCATION (label, loc1);
3539 if (c_parser_next_token_starts_declspecs (parser)
3540 && !(c_parser_next_token_is (parser, CPP_NAME)
3541 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3542 {
3543 error_at (c_parser_peek_token (parser)->location,
3544 "a label can only be part of a statement and "
3545 "a declaration is not a statement");
3546 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
3547 /*nested*/ true, /*empty_ok*/ false,
3548 /*start_attr_ok*/ true);
3549 }
3550 }
3551 }
3552
3553 /* Parse a statement (C90 6.6, C99 6.8).
3554
3555 statement:
3556 labeled-statement
3557 compound-statement
3558 expression-statement
3559 selection-statement
3560 iteration-statement
3561 jump-statement
3562
3563 labeled-statement:
3564 label statement
3565
3566 expression-statement:
3567 expression[opt] ;
3568
3569 selection-statement:
3570 if-statement
3571 switch-statement
3572
3573 iteration-statement:
3574 while-statement
3575 do-statement
3576 for-statement
3577
3578 jump-statement:
3579 goto identifier ;
3580 continue ;
3581 break ;
3582 return expression[opt] ;
3583
3584 GNU extensions:
3585
3586 statement:
3587 asm-statement
3588
3589 jump-statement:
3590 goto * expression ;
3591
3592 Objective-C:
3593
3594 statement:
3595 objc-throw-statement
3596 objc-try-catch-statement
3597 objc-synchronized-statement
3598
3599 objc-throw-statement:
3600 @throw expression ;
3601 @throw ;
3602
3603 OpenMP:
3604
3605 statement:
3606 openmp-construct
3607
3608 openmp-construct:
3609 parallel-construct
3610 for-construct
3611 sections-construct
3612 single-construct
3613 parallel-for-construct
3614 parallel-sections-construct
3615 master-construct
3616 critical-construct
3617 atomic-construct
3618 ordered-construct
3619
3620 parallel-construct:
3621 parallel-directive structured-block
3622
3623 for-construct:
3624 for-directive iteration-statement
3625
3626 sections-construct:
3627 sections-directive section-scope
3628
3629 single-construct:
3630 single-directive structured-block
3631
3632 parallel-for-construct:
3633 parallel-for-directive iteration-statement
3634
3635 parallel-sections-construct:
3636 parallel-sections-directive section-scope
3637
3638 master-construct:
3639 master-directive structured-block
3640
3641 critical-construct:
3642 critical-directive structured-block
3643
3644 atomic-construct:
3645 atomic-directive expression-statement
3646
3647 ordered-construct:
3648 ordered-directive structured-block */
3649
3650 static void
3651 c_parser_statement (c_parser *parser)
3652 {
3653 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3654 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3655 || (c_parser_next_token_is (parser, CPP_NAME)
3656 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3657 c_parser_label (parser);
3658 c_parser_statement_after_labels (parser);
3659 }
3660
3661 /* Parse a statement, other than a labeled statement. */
3662
3663 static void
3664 c_parser_statement_after_labels (c_parser *parser)
3665 {
3666 location_t loc = c_parser_peek_token (parser)->location;
3667 tree stmt = NULL_TREE;
3668 bool in_if_block = parser->in_if_block;
3669 parser->in_if_block = false;
3670 switch (c_parser_peek_token (parser)->type)
3671 {
3672 case CPP_OPEN_BRACE:
3673 add_stmt (c_parser_compound_statement (parser));
3674 break;
3675 case CPP_KEYWORD:
3676 switch (c_parser_peek_token (parser)->keyword)
3677 {
3678 case RID_IF:
3679 c_parser_if_statement (parser);
3680 break;
3681 case RID_SWITCH:
3682 c_parser_switch_statement (parser);
3683 break;
3684 case RID_WHILE:
3685 c_parser_while_statement (parser);
3686 break;
3687 case RID_DO:
3688 c_parser_do_statement (parser);
3689 break;
3690 case RID_FOR:
3691 c_parser_for_statement (parser);
3692 break;
3693 case RID_GOTO:
3694 c_parser_consume_token (parser);
3695 if (c_parser_next_token_is (parser, CPP_NAME))
3696 {
3697 stmt = c_finish_goto_label (c_parser_peek_token (parser)->value);
3698 c_parser_consume_token (parser);
3699 }
3700 else if (c_parser_next_token_is (parser, CPP_MULT))
3701 {
3702 c_parser_consume_token (parser);
3703 stmt = c_finish_goto_ptr (c_parser_expression (parser).value);
3704 }
3705 else
3706 c_parser_error (parser, "expected identifier or %<*%>");
3707 goto expect_semicolon;
3708 case RID_CONTINUE:
3709 c_parser_consume_token (parser);
3710 stmt = c_finish_bc_stmt (&c_cont_label, false);
3711 goto expect_semicolon;
3712 case RID_BREAK:
3713 c_parser_consume_token (parser);
3714 stmt = c_finish_bc_stmt (&c_break_label, true);
3715 goto expect_semicolon;
3716 case RID_RETURN:
3717 c_parser_consume_token (parser);
3718 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3719 {
3720 stmt = c_finish_return (NULL_TREE);
3721 c_parser_consume_token (parser);
3722 }
3723 else
3724 {
3725 stmt = c_finish_return (c_parser_expression_conv (parser).value);
3726 goto expect_semicolon;
3727 }
3728 break;
3729 case RID_ASM:
3730 stmt = c_parser_asm_statement (parser);
3731 break;
3732 case RID_THROW:
3733 gcc_assert (c_dialect_objc ());
3734 c_parser_consume_token (parser);
3735 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3736 {
3737 stmt = objc_build_throw_stmt (NULL_TREE);
3738 c_parser_consume_token (parser);
3739 }
3740 else
3741 {
3742 stmt
3743 = objc_build_throw_stmt (c_parser_expression (parser).value);
3744 goto expect_semicolon;
3745 }
3746 break;
3747 case RID_TRY:
3748 gcc_assert (c_dialect_objc ());
3749 c_parser_objc_try_catch_statement (parser);
3750 break;
3751 case RID_AT_SYNCHRONIZED:
3752 gcc_assert (c_dialect_objc ());
3753 c_parser_objc_synchronized_statement (parser);
3754 break;
3755 default:
3756 goto expr_stmt;
3757 }
3758 break;
3759 case CPP_SEMICOLON:
3760 c_parser_consume_token (parser);
3761 break;
3762 case CPP_CLOSE_PAREN:
3763 case CPP_CLOSE_SQUARE:
3764 /* Avoid infinite loop in error recovery:
3765 c_parser_skip_until_found stops at a closing nesting
3766 delimiter without consuming it, but here we need to consume
3767 it to proceed further. */
3768 c_parser_error (parser, "expected statement");
3769 c_parser_consume_token (parser);
3770 break;
3771 case CPP_PRAGMA:
3772 c_parser_pragma (parser, pragma_stmt);
3773 break;
3774 default:
3775 expr_stmt:
3776 stmt = c_finish_expr_stmt (c_parser_expression_conv (parser).value);
3777 expect_semicolon:
3778 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3779 break;
3780 }
3781 /* Two cases cannot and do not have line numbers associated: If stmt
3782 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3783 cannot hold line numbers. But that's OK because the statement
3784 will either be changed to a MODIFY_EXPR during gimplification of
3785 the statement expr, or discarded. If stmt was compound, but
3786 without new variables, we will have skipped the creation of a
3787 BIND and will have a bare STATEMENT_LIST. But that's OK because
3788 (recursively) all of the component statements should already have
3789 line numbers assigned. ??? Can we discard no-op statements
3790 earlier? */
3791 protected_set_expr_location (stmt, loc);
3792
3793 parser->in_if_block = in_if_block;
3794 }
3795
3796 /* Parse the condition from an if, do, while or for statements. */
3797
3798 static tree
3799 c_parser_condition (c_parser *parser)
3800 {
3801 location_t loc;
3802 tree cond;
3803 loc = c_parser_peek_token (parser)->location;
3804 cond = c_objc_common_truthvalue_conversion
3805 (loc, c_parser_expression_conv (parser).value);
3806 protected_set_expr_location (cond, loc);
3807 if (warn_sequence_point)
3808 verify_sequence_points (cond);
3809 return cond;
3810 }
3811
3812 /* Parse a parenthesized condition from an if, do or while statement.
3813
3814 condition:
3815 ( expression )
3816 */
3817 static tree
3818 c_parser_paren_condition (c_parser *parser)
3819 {
3820 tree cond;
3821 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3822 return error_mark_node;
3823 cond = c_parser_condition (parser);
3824 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3825 return cond;
3826 }
3827
3828 /* Parse a statement which is a block in C99. */
3829
3830 static tree
3831 c_parser_c99_block_statement (c_parser *parser)
3832 {
3833 tree block = c_begin_compound_stmt (flag_isoc99);
3834 c_parser_statement (parser);
3835 return c_end_compound_stmt (block, flag_isoc99);
3836 }
3837
3838 /* Parse the body of an if statement. This is just parsing a
3839 statement but (a) it is a block in C99, (b) we track whether the
3840 body is an if statement for the sake of -Wparentheses warnings, (c)
3841 we handle an empty body specially for the sake of -Wempty-body
3842 warnings, and (d) we call parser_compound_statement directly
3843 because c_parser_statement_after_labels resets
3844 parser->in_if_block. */
3845
3846 static tree
3847 c_parser_if_body (c_parser *parser, bool *if_p)
3848 {
3849 tree block = c_begin_compound_stmt (flag_isoc99);
3850 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3851 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3852 || (c_parser_next_token_is (parser, CPP_NAME)
3853 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3854 c_parser_label (parser);
3855 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
3856 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3857 {
3858 location_t loc = c_parser_peek_token (parser)->location;
3859 add_stmt (build_empty_stmt ());
3860 c_parser_consume_token (parser);
3861 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
3862 warning_at (loc, OPT_Wempty_body,
3863 "suggest braces around empty body in an %<if%> statement");
3864 }
3865 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3866 add_stmt (c_parser_compound_statement (parser));
3867 else
3868 c_parser_statement_after_labels (parser);
3869 return c_end_compound_stmt (block, flag_isoc99);
3870 }
3871
3872 /* Parse the else body of an if statement. This is just parsing a
3873 statement but (a) it is a block in C99, (b) we handle an empty body
3874 specially for the sake of -Wempty-body warnings. */
3875
3876 static tree
3877 c_parser_else_body (c_parser *parser)
3878 {
3879 tree block = c_begin_compound_stmt (flag_isoc99);
3880 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3881 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3882 || (c_parser_next_token_is (parser, CPP_NAME)
3883 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3884 c_parser_label (parser);
3885 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3886 {
3887 warning_at (c_parser_peek_token (parser)->location,
3888 OPT_Wempty_body,
3889 "suggest braces around empty body in an %<else%> statement");
3890 add_stmt (build_empty_stmt ());
3891 c_parser_consume_token (parser);
3892 }
3893 else
3894 c_parser_statement_after_labels (parser);
3895 return c_end_compound_stmt (block, flag_isoc99);
3896 }
3897
3898 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3899
3900 if-statement:
3901 if ( expression ) statement
3902 if ( expression ) statement else statement
3903 */
3904
3905 static void
3906 c_parser_if_statement (c_parser *parser)
3907 {
3908 tree block;
3909 location_t loc;
3910 tree cond;
3911 bool first_if = false;
3912 tree first_body, second_body;
3913 bool in_if_block;
3914
3915 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
3916 c_parser_consume_token (parser);
3917 block = c_begin_compound_stmt (flag_isoc99);
3918 loc = c_parser_peek_token (parser)->location;
3919 cond = c_parser_paren_condition (parser);
3920 in_if_block = parser->in_if_block;
3921 parser->in_if_block = true;
3922 first_body = c_parser_if_body (parser, &first_if);
3923 parser->in_if_block = in_if_block;
3924 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3925 {
3926 c_parser_consume_token (parser);
3927 second_body = c_parser_else_body (parser);
3928 }
3929 else
3930 second_body = NULL_TREE;
3931 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
3932 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3933 }
3934
3935 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3936
3937 switch-statement:
3938 switch (expression) statement
3939 */
3940
3941 static void
3942 c_parser_switch_statement (c_parser *parser)
3943 {
3944 tree block, expr, body, save_break;
3945 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
3946 c_parser_consume_token (parser);
3947 block = c_begin_compound_stmt (flag_isoc99);
3948 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3949 {
3950 expr = c_parser_expression (parser).value;
3951 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3952 }
3953 else
3954 expr = error_mark_node;
3955 c_start_case (expr);
3956 save_break = c_break_label;
3957 c_break_label = NULL_TREE;
3958 body = c_parser_c99_block_statement (parser);
3959 c_finish_case (body);
3960 if (c_break_label)
3961 add_stmt (build1 (LABEL_EXPR, void_type_node, c_break_label));
3962 c_break_label = save_break;
3963 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3964 }
3965
3966 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3967
3968 while-statement:
3969 while (expression) statement
3970 */
3971
3972 static void
3973 c_parser_while_statement (c_parser *parser)
3974 {
3975 tree block, cond, body, save_break, save_cont;
3976 location_t loc;
3977 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
3978 c_parser_consume_token (parser);
3979 block = c_begin_compound_stmt (flag_isoc99);
3980 loc = c_parser_peek_token (parser)->location;
3981 cond = c_parser_paren_condition (parser);
3982 save_break = c_break_label;
3983 c_break_label = NULL_TREE;
3984 save_cont = c_cont_label;
3985 c_cont_label = NULL_TREE;
3986 body = c_parser_c99_block_statement (parser);
3987 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
3988 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3989 c_break_label = save_break;
3990 c_cont_label = save_cont;
3991 }
3992
3993 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3994
3995 do-statement:
3996 do statement while ( expression ) ;
3997 */
3998
3999 static void
4000 c_parser_do_statement (c_parser *parser)
4001 {
4002 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4003 location_t loc;
4004 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4005 c_parser_consume_token (parser);
4006 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4007 warning_at (c_parser_peek_token (parser)->location,
4008 OPT_Wempty_body,
4009 "suggest braces around empty body in %<do%> statement");
4010 block = c_begin_compound_stmt (flag_isoc99);
4011 loc = c_parser_peek_token (parser)->location;
4012 save_break = c_break_label;
4013 c_break_label = NULL_TREE;
4014 save_cont = c_cont_label;
4015 c_cont_label = NULL_TREE;
4016 body = c_parser_c99_block_statement (parser);
4017 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4018 new_break = c_break_label;
4019 c_break_label = save_break;
4020 new_cont = c_cont_label;
4021 c_cont_label = save_cont;
4022 cond = c_parser_paren_condition (parser);
4023 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4024 c_parser_skip_to_end_of_block_or_statement (parser);
4025 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4026 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4027 }
4028
4029 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4030
4031 for-statement:
4032 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4033 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4034
4035 The form with a declaration is new in C99.
4036
4037 ??? In accordance with the old parser, the declaration may be a
4038 nested function, which is then rejected in check_for_loop_decls,
4039 but does it make any sense for this to be included in the grammar?
4040 Note in particular that the nested function does not include a
4041 trailing ';', whereas the "declaration" production includes one.
4042 Also, can we reject bad declarations earlier and cheaper than
4043 check_for_loop_decls? */
4044
4045 static void
4046 c_parser_for_statement (c_parser *parser)
4047 {
4048 tree block, cond, incr, save_break, save_cont, body;
4049 location_t loc;
4050 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4051 loc = c_parser_peek_token (parser)->location;
4052 c_parser_consume_token (parser);
4053 block = c_begin_compound_stmt (flag_isoc99);
4054 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4055 {
4056 /* Parse the initialization declaration or expression. */
4057 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4058 {
4059 c_parser_consume_token (parser);
4060 c_finish_expr_stmt (NULL_TREE);
4061 }
4062 else if (c_parser_next_token_starts_declspecs (parser))
4063 {
4064 c_parser_declaration_or_fndef (parser, true, true, true, true);
4065 check_for_loop_decls ();
4066 }
4067 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4068 {
4069 /* __extension__ can start a declaration, but is also an
4070 unary operator that can start an expression. Consume all
4071 but the last of a possible series of __extension__ to
4072 determine which. */
4073 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4074 && (c_parser_peek_2nd_token (parser)->keyword
4075 == RID_EXTENSION))
4076 c_parser_consume_token (parser);
4077 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
4078 {
4079 int ext;
4080 ext = disable_extension_diagnostics ();
4081 c_parser_consume_token (parser);
4082 c_parser_declaration_or_fndef (parser, true, true, true, true);
4083 restore_extension_diagnostics (ext);
4084 check_for_loop_decls ();
4085 }
4086 else
4087 goto init_expr;
4088 }
4089 else
4090 {
4091 init_expr:
4092 c_finish_expr_stmt (c_parser_expression (parser).value);
4093 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4094 }
4095 /* Parse the loop condition. */
4096 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4097 {
4098 c_parser_consume_token (parser);
4099 cond = NULL_TREE;
4100 }
4101 else
4102 {
4103 cond = c_parser_condition (parser);
4104 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4105 }
4106 /* Parse the increment expression. */
4107 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4108 incr = c_process_expr_stmt (NULL_TREE);
4109 else
4110 incr = c_process_expr_stmt (c_parser_expression (parser).value);
4111 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4112 }
4113 else
4114 {
4115 cond = error_mark_node;
4116 incr = error_mark_node;
4117 }
4118 save_break = c_break_label;
4119 c_break_label = NULL_TREE;
4120 save_cont = c_cont_label;
4121 c_cont_label = NULL_TREE;
4122 body = c_parser_c99_block_statement (parser);
4123 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4124 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4125 c_break_label = save_break;
4126 c_cont_label = save_cont;
4127 }
4128
4129 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4130 statement with inputs, outputs, clobbers, and volatile tag
4131 allowed.
4132
4133 asm-statement:
4134 asm type-qualifier[opt] ( asm-argument ) ;
4135
4136 asm-argument:
4137 asm-string-literal
4138 asm-string-literal : asm-operands[opt]
4139 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4140 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4141
4142 Qualifiers other than volatile are accepted in the syntax but
4143 warned for. */
4144
4145 static tree
4146 c_parser_asm_statement (c_parser *parser)
4147 {
4148 tree quals, str, outputs, inputs, clobbers, ret;
4149 bool simple;
4150 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4151 c_parser_consume_token (parser);
4152 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4153 {
4154 quals = c_parser_peek_token (parser)->value;
4155 c_parser_consume_token (parser);
4156 }
4157 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4158 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4159 {
4160 warning_at (c_parser_peek_token (parser)->location,
4161 0,
4162 "%E qualifier ignored on asm",
4163 c_parser_peek_token (parser)->value);
4164 quals = NULL_TREE;
4165 c_parser_consume_token (parser);
4166 }
4167 else
4168 quals = NULL_TREE;
4169 /* ??? Follow the C++ parser rather than using the
4170 lex_untranslated_string kludge. */
4171 parser->lex_untranslated_string = true;
4172 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4173 {
4174 parser->lex_untranslated_string = false;
4175 return NULL_TREE;
4176 }
4177 str = c_parser_asm_string_literal (parser);
4178 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4179 {
4180 simple = true;
4181 outputs = NULL_TREE;
4182 inputs = NULL_TREE;
4183 clobbers = NULL_TREE;
4184 goto done_asm;
4185 }
4186 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4187 {
4188 parser->lex_untranslated_string = false;
4189 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4190 return NULL_TREE;
4191 }
4192 simple = false;
4193 /* Parse outputs. */
4194 if (c_parser_next_token_is (parser, CPP_COLON)
4195 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4196 outputs = NULL_TREE;
4197 else
4198 outputs = c_parser_asm_operands (parser, false);
4199 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4200 {
4201 inputs = NULL_TREE;
4202 clobbers = NULL_TREE;
4203 goto done_asm;
4204 }
4205 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4206 {
4207 parser->lex_untranslated_string = false;
4208 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4209 return NULL_TREE;
4210 }
4211 /* Parse inputs. */
4212 if (c_parser_next_token_is (parser, CPP_COLON)
4213 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4214 inputs = NULL_TREE;
4215 else
4216 inputs = c_parser_asm_operands (parser, true);
4217 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4218 {
4219 clobbers = NULL_TREE;
4220 goto done_asm;
4221 }
4222 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4223 {
4224 parser->lex_untranslated_string = false;
4225 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4226 return NULL_TREE;
4227 }
4228 /* Parse clobbers. */
4229 clobbers = c_parser_asm_clobbers (parser);
4230 done_asm:
4231 parser->lex_untranslated_string = false;
4232 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4233 {
4234 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4235 return NULL_TREE;
4236 }
4237 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4238 c_parser_skip_to_end_of_block_or_statement (parser);
4239 ret = build_asm_stmt (quals, build_asm_expr (str, outputs, inputs,
4240 clobbers, simple));
4241 return ret;
4242 }
4243
4244 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4245 not outputs), apply the default conversion of functions and arrays
4246 to pointers.
4247
4248 asm-operands:
4249 asm-operand
4250 asm-operands , asm-operand
4251
4252 asm-operand:
4253 asm-string-literal ( expression )
4254 [ identifier ] asm-string-literal ( expression )
4255 */
4256
4257 static tree
4258 c_parser_asm_operands (c_parser *parser, bool convert_p)
4259 {
4260 tree list = NULL_TREE;
4261 while (true)
4262 {
4263 tree name, str;
4264 struct c_expr expr;
4265 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4266 {
4267 c_parser_consume_token (parser);
4268 if (c_parser_next_token_is (parser, CPP_NAME))
4269 {
4270 tree id = c_parser_peek_token (parser)->value;
4271 c_parser_consume_token (parser);
4272 name = build_string (IDENTIFIER_LENGTH (id),
4273 IDENTIFIER_POINTER (id));
4274 }
4275 else
4276 {
4277 c_parser_error (parser, "expected identifier");
4278 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4279 return NULL_TREE;
4280 }
4281 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4282 "expected %<]%>");
4283 }
4284 else
4285 name = NULL_TREE;
4286 str = c_parser_asm_string_literal (parser);
4287 if (str == NULL_TREE)
4288 return NULL_TREE;
4289 parser->lex_untranslated_string = false;
4290 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4291 {
4292 parser->lex_untranslated_string = true;
4293 return NULL_TREE;
4294 }
4295 expr = c_parser_expression (parser);
4296 if (convert_p)
4297 expr = default_function_array_conversion (expr);
4298 parser->lex_untranslated_string = true;
4299 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4300 {
4301 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4302 return NULL_TREE;
4303 }
4304 list = chainon (list, build_tree_list (build_tree_list (name, str),
4305 expr.value));
4306 if (c_parser_next_token_is (parser, CPP_COMMA))
4307 c_parser_consume_token (parser);
4308 else
4309 break;
4310 }
4311 return list;
4312 }
4313
4314 /* Parse asm clobbers, a GNU extension.
4315
4316 asm-clobbers:
4317 asm-string-literal
4318 asm-clobbers , asm-string-literal
4319 */
4320
4321 static tree
4322 c_parser_asm_clobbers (c_parser *parser)
4323 {
4324 tree list = NULL_TREE;
4325 while (true)
4326 {
4327 tree str = c_parser_asm_string_literal (parser);
4328 if (str)
4329 list = tree_cons (NULL_TREE, str, list);
4330 else
4331 return NULL_TREE;
4332 if (c_parser_next_token_is (parser, CPP_COMMA))
4333 c_parser_consume_token (parser);
4334 else
4335 break;
4336 }
4337 return list;
4338 }
4339
4340 /* Parse an expression other than a compound expression; that is, an
4341 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4342 NULL then it is an Objective-C message expression which is the
4343 primary-expression starting the expression as an initializer.
4344
4345 assignment-expression:
4346 conditional-expression
4347 unary-expression assignment-operator assignment-expression
4348
4349 assignment-operator: one of
4350 = *= /= %= += -= <<= >>= &= ^= |=
4351
4352 In GNU C we accept any conditional expression on the LHS and
4353 diagnose the invalid lvalue rather than producing a syntax
4354 error. */
4355
4356 static struct c_expr
4357 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4358 {
4359 struct c_expr lhs, rhs, ret;
4360 enum tree_code code;
4361 location_t op_location;
4362 gcc_assert (!after || c_dialect_objc ());
4363 lhs = c_parser_conditional_expression (parser, after);
4364 op_location = c_parser_peek_token (parser)->location;
4365 switch (c_parser_peek_token (parser)->type)
4366 {
4367 case CPP_EQ:
4368 code = NOP_EXPR;
4369 break;
4370 case CPP_MULT_EQ:
4371 code = MULT_EXPR;
4372 break;
4373 case CPP_DIV_EQ:
4374 code = TRUNC_DIV_EXPR;
4375 break;
4376 case CPP_MOD_EQ:
4377 code = TRUNC_MOD_EXPR;
4378 break;
4379 case CPP_PLUS_EQ:
4380 code = PLUS_EXPR;
4381 break;
4382 case CPP_MINUS_EQ:
4383 code = MINUS_EXPR;
4384 break;
4385 case CPP_LSHIFT_EQ:
4386 code = LSHIFT_EXPR;
4387 break;
4388 case CPP_RSHIFT_EQ:
4389 code = RSHIFT_EXPR;
4390 break;
4391 case CPP_AND_EQ:
4392 code = BIT_AND_EXPR;
4393 break;
4394 case CPP_XOR_EQ:
4395 code = BIT_XOR_EXPR;
4396 break;
4397 case CPP_OR_EQ:
4398 code = BIT_IOR_EXPR;
4399 break;
4400 default:
4401 return lhs;
4402 }
4403 c_parser_consume_token (parser);
4404 rhs = c_parser_expr_no_commas (parser, NULL);
4405 rhs = default_function_array_conversion (rhs);
4406 ret.value = build_modify_expr (op_location, lhs.value, code, rhs.value);
4407 if (code == NOP_EXPR)
4408 ret.original_code = MODIFY_EXPR;
4409 else
4410 {
4411 TREE_NO_WARNING (ret.value) = 1;
4412 ret.original_code = ERROR_MARK;
4413 }
4414 return ret;
4415 }
4416
4417 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4418 is not NULL then it is an Objective-C message expression which is
4419 the primary-expression starting the expression as an initializer.
4420
4421 conditional-expression:
4422 logical-OR-expression
4423 logical-OR-expression ? expression : conditional-expression
4424
4425 GNU extensions:
4426
4427 conditional-expression:
4428 logical-OR-expression ? : conditional-expression
4429 */
4430
4431 static struct c_expr
4432 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4433 {
4434 struct c_expr cond, exp1, exp2, ret;
4435 location_t cond_loc;
4436
4437 gcc_assert (!after || c_dialect_objc ());
4438
4439 cond_loc = c_parser_peek_token (parser)->location;
4440 cond = c_parser_binary_expression (parser, after);
4441 protected_set_expr_location (cond.value, cond_loc);
4442
4443 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4444 return cond;
4445 cond = default_function_array_conversion (cond);
4446 c_parser_consume_token (parser);
4447 if (c_parser_next_token_is (parser, CPP_COLON))
4448 {
4449 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
4450 "ISO C forbids omitting the middle term of a ?: expression");
4451 /* Make sure first operand is calculated only once. */
4452 exp1.value = save_expr (default_conversion (cond.value));
4453 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
4454 skip_evaluation += cond.value == truthvalue_true_node;
4455 }
4456 else
4457 {
4458 cond.value
4459 = c_objc_common_truthvalue_conversion
4460 (cond_loc, default_conversion (cond.value));
4461 skip_evaluation += cond.value == truthvalue_false_node;
4462 exp1 = c_parser_expression_conv (parser);
4463 skip_evaluation += ((cond.value == truthvalue_true_node)
4464 - (cond.value == truthvalue_false_node));
4465 }
4466 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4467 {
4468 skip_evaluation -= cond.value == truthvalue_true_node;
4469 ret.value = error_mark_node;
4470 ret.original_code = ERROR_MARK;
4471 return ret;
4472 }
4473 exp2 = c_parser_conditional_expression (parser, NULL);
4474 exp2 = default_function_array_conversion (exp2);
4475 skip_evaluation -= cond.value == truthvalue_true_node;
4476 ret.value = build_conditional_expr (cond.value, exp1.value, exp2.value);
4477 ret.original_code = ERROR_MARK;
4478 return ret;
4479 }
4480
4481 /* Parse a binary expression; that is, a logical-OR-expression (C90
4482 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4483 an Objective-C message expression which is the primary-expression
4484 starting the expression as an initializer.
4485
4486 multiplicative-expression:
4487 cast-expression
4488 multiplicative-expression * cast-expression
4489 multiplicative-expression / cast-expression
4490 multiplicative-expression % cast-expression
4491
4492 additive-expression:
4493 multiplicative-expression
4494 additive-expression + multiplicative-expression
4495 additive-expression - multiplicative-expression
4496
4497 shift-expression:
4498 additive-expression
4499 shift-expression << additive-expression
4500 shift-expression >> additive-expression
4501
4502 relational-expression:
4503 shift-expression
4504 relational-expression < shift-expression
4505 relational-expression > shift-expression
4506 relational-expression <= shift-expression
4507 relational-expression >= shift-expression
4508
4509 equality-expression:
4510 relational-expression
4511 equality-expression == relational-expression
4512 equality-expression != relational-expression
4513
4514 AND-expression:
4515 equality-expression
4516 AND-expression & equality-expression
4517
4518 exclusive-OR-expression:
4519 AND-expression
4520 exclusive-OR-expression ^ AND-expression
4521
4522 inclusive-OR-expression:
4523 exclusive-OR-expression
4524 inclusive-OR-expression | exclusive-OR-expression
4525
4526 logical-AND-expression:
4527 inclusive-OR-expression
4528 logical-AND-expression && inclusive-OR-expression
4529
4530 logical-OR-expression:
4531 logical-AND-expression
4532 logical-OR-expression || logical-AND-expression
4533 */
4534
4535 static struct c_expr
4536 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4537 {
4538 /* A binary expression is parsed using operator-precedence parsing,
4539 with the operands being cast expressions. All the binary
4540 operators are left-associative. Thus a binary expression is of
4541 form:
4542
4543 E0 op1 E1 op2 E2 ...
4544
4545 which we represent on a stack. On the stack, the precedence
4546 levels are strictly increasing. When a new operator is
4547 encountered of higher precedence than that at the top of the
4548 stack, it is pushed; its LHS is the top expression, and its RHS
4549 is everything parsed until it is popped. When a new operator is
4550 encountered with precedence less than or equal to that at the top
4551 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4552 by the result of the operation until the operator at the top of
4553 the stack has lower precedence than the new operator or there is
4554 only one element on the stack; then the top expression is the LHS
4555 of the new operator. In the case of logical AND and OR
4556 expressions, we also need to adjust skip_evaluation as
4557 appropriate when the operators are pushed and popped. */
4558
4559 /* The precedence levels, where 0 is a dummy lowest level used for
4560 the bottom of the stack. */
4561 enum prec {
4562 PREC_NONE,
4563 PREC_LOGOR,
4564 PREC_LOGAND,
4565 PREC_BITOR,
4566 PREC_BITXOR,
4567 PREC_BITAND,
4568 PREC_EQ,
4569 PREC_REL,
4570 PREC_SHIFT,
4571 PREC_ADD,
4572 PREC_MULT,
4573 NUM_PRECS
4574 };
4575 struct {
4576 /* The expression at this stack level. */
4577 struct c_expr expr;
4578 /* The precedence of the operator on its left, PREC_NONE at the
4579 bottom of the stack. */
4580 enum prec prec;
4581 /* The operation on its left. */
4582 enum tree_code op;
4583 } stack[NUM_PRECS];
4584 int sp;
4585 /* Location of the binary operator. */
4586 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4587 #define POP \
4588 do { \
4589 switch (stack[sp].op) \
4590 { \
4591 case TRUTH_ANDIF_EXPR: \
4592 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4593 break; \
4594 case TRUTH_ORIF_EXPR: \
4595 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4596 break; \
4597 default: \
4598 break; \
4599 } \
4600 stack[sp - 1].expr \
4601 = default_function_array_conversion (stack[sp - 1].expr); \
4602 stack[sp].expr \
4603 = default_function_array_conversion (stack[sp].expr); \
4604 stack[sp - 1].expr = parser_build_binary_op (binary_loc, \
4605 stack[sp].op, \
4606 stack[sp - 1].expr, \
4607 stack[sp].expr); \
4608 sp--; \
4609 } while (0)
4610 gcc_assert (!after || c_dialect_objc ());
4611 stack[0].expr = c_parser_cast_expression (parser, after);
4612 stack[0].prec = PREC_NONE;
4613 sp = 0;
4614 while (true)
4615 {
4616 enum prec oprec;
4617 enum tree_code ocode;
4618 if (parser->error)
4619 goto out;
4620 switch (c_parser_peek_token (parser)->type)
4621 {
4622 case CPP_MULT:
4623 oprec = PREC_MULT;
4624 ocode = MULT_EXPR;
4625 break;
4626 case CPP_DIV:
4627 oprec = PREC_MULT;
4628 ocode = TRUNC_DIV_EXPR;
4629 break;
4630 case CPP_MOD:
4631 oprec = PREC_MULT;
4632 ocode = TRUNC_MOD_EXPR;
4633 break;
4634 case CPP_PLUS:
4635 oprec = PREC_ADD;
4636 ocode = PLUS_EXPR;
4637 break;
4638 case CPP_MINUS:
4639 oprec = PREC_ADD;
4640 ocode = MINUS_EXPR;
4641 break;
4642 case CPP_LSHIFT:
4643 oprec = PREC_SHIFT;
4644 ocode = LSHIFT_EXPR;
4645 break;
4646 case CPP_RSHIFT:
4647 oprec = PREC_SHIFT;
4648 ocode = RSHIFT_EXPR;
4649 break;
4650 case CPP_LESS:
4651 oprec = PREC_REL;
4652 ocode = LT_EXPR;
4653 break;
4654 case CPP_GREATER:
4655 oprec = PREC_REL;
4656 ocode = GT_EXPR;
4657 break;
4658 case CPP_LESS_EQ:
4659 oprec = PREC_REL;
4660 ocode = LE_EXPR;
4661 break;
4662 case CPP_GREATER_EQ:
4663 oprec = PREC_REL;
4664 ocode = GE_EXPR;
4665 break;
4666 case CPP_EQ_EQ:
4667 oprec = PREC_EQ;
4668 ocode = EQ_EXPR;
4669 break;
4670 case CPP_NOT_EQ:
4671 oprec = PREC_EQ;
4672 ocode = NE_EXPR;
4673 break;
4674 case CPP_AND:
4675 oprec = PREC_BITAND;
4676 ocode = BIT_AND_EXPR;
4677 break;
4678 case CPP_XOR:
4679 oprec = PREC_BITXOR;
4680 ocode = BIT_XOR_EXPR;
4681 break;
4682 case CPP_OR:
4683 oprec = PREC_BITOR;
4684 ocode = BIT_IOR_EXPR;
4685 break;
4686 case CPP_AND_AND:
4687 oprec = PREC_LOGAND;
4688 ocode = TRUTH_ANDIF_EXPR;
4689 break;
4690 case CPP_OR_OR:
4691 oprec = PREC_LOGOR;
4692 ocode = TRUTH_ORIF_EXPR;
4693 break;
4694 default:
4695 /* Not a binary operator, so end of the binary
4696 expression. */
4697 goto out;
4698 }
4699 binary_loc = c_parser_peek_token (parser)->location;
4700 c_parser_consume_token (parser);
4701 while (oprec <= stack[sp].prec)
4702 POP;
4703 switch (ocode)
4704 {
4705 case TRUTH_ANDIF_EXPR:
4706 stack[sp].expr
4707 = default_function_array_conversion (stack[sp].expr);
4708 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4709 (binary_loc, default_conversion (stack[sp].expr.value));
4710 skip_evaluation += stack[sp].expr.value == truthvalue_false_node;
4711 break;
4712 case TRUTH_ORIF_EXPR:
4713 stack[sp].expr
4714 = default_function_array_conversion (stack[sp].expr);
4715 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4716 (binary_loc, default_conversion (stack[sp].expr.value));
4717 skip_evaluation += stack[sp].expr.value == truthvalue_true_node;
4718 break;
4719 default:
4720 break;
4721 }
4722 sp++;
4723 stack[sp].expr = c_parser_cast_expression (parser, NULL);
4724 stack[sp].prec = oprec;
4725 stack[sp].op = ocode;
4726 }
4727 out:
4728 while (sp > 0)
4729 POP;
4730 return stack[0].expr;
4731 #undef POP
4732 }
4733
4734 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4735 NULL then it is an Objective-C message expression which is the
4736 primary-expression starting the expression as an initializer.
4737
4738 cast-expression:
4739 unary-expression
4740 ( type-name ) unary-expression
4741 */
4742
4743 static struct c_expr
4744 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
4745 {
4746 gcc_assert (!after || c_dialect_objc ());
4747 if (after)
4748 return c_parser_postfix_expression_after_primary (parser, *after);
4749 /* If the expression begins with a parenthesized type name, it may
4750 be either a cast or a compound literal; we need to see whether
4751 the next character is '{' to tell the difference. If not, it is
4752 an unary expression. */
4753 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4754 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4755 {
4756 struct c_type_name *type_name;
4757 struct c_expr ret;
4758 struct c_expr expr;
4759 c_parser_consume_token (parser);
4760 type_name = c_parser_type_name (parser);
4761 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4762 if (type_name == NULL)
4763 {
4764 ret.value = error_mark_node;
4765 ret.original_code = ERROR_MARK;
4766 return ret;
4767 }
4768
4769 /* Save casted types in the function's used types hash table. */
4770 used_types_insert (type_name->specs->type);
4771
4772 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4773 return c_parser_postfix_expression_after_paren_type (parser,
4774 type_name);
4775 expr = c_parser_cast_expression (parser, NULL);
4776 expr = default_function_array_conversion (expr);
4777 ret.value = c_cast_expr (type_name, expr.value);
4778 ret.original_code = ERROR_MARK;
4779 return ret;
4780 }
4781 else
4782 return c_parser_unary_expression (parser);
4783 }
4784
4785 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4786
4787 unary-expression:
4788 postfix-expression
4789 ++ unary-expression
4790 -- unary-expression
4791 unary-operator cast-expression
4792 sizeof unary-expression
4793 sizeof ( type-name )
4794
4795 unary-operator: one of
4796 & * + - ~ !
4797
4798 GNU extensions:
4799
4800 unary-expression:
4801 __alignof__ unary-expression
4802 __alignof__ ( type-name )
4803 && identifier
4804
4805 unary-operator: one of
4806 __extension__ __real__ __imag__
4807
4808 In addition, the GNU syntax treats ++ and -- as unary operators, so
4809 they may be applied to cast expressions with errors for non-lvalues
4810 given later. */
4811
4812 static struct c_expr
4813 c_parser_unary_expression (c_parser *parser)
4814 {
4815 int ext;
4816 struct c_expr ret, op;
4817 location_t loc = c_parser_peek_token (parser)->location;
4818 switch (c_parser_peek_token (parser)->type)
4819 {
4820 case CPP_PLUS_PLUS:
4821 c_parser_consume_token (parser);
4822 op = c_parser_cast_expression (parser, NULL);
4823 op = default_function_array_conversion (op);
4824 return parser_build_unary_op (PREINCREMENT_EXPR, op, loc);
4825 case CPP_MINUS_MINUS:
4826 c_parser_consume_token (parser);
4827 op = c_parser_cast_expression (parser, NULL);
4828 op = default_function_array_conversion (op);
4829 return parser_build_unary_op (PREDECREMENT_EXPR, op, loc);
4830 case CPP_AND:
4831 c_parser_consume_token (parser);
4832 return parser_build_unary_op (ADDR_EXPR,
4833 c_parser_cast_expression (parser, NULL),
4834 loc);
4835 case CPP_MULT:
4836 c_parser_consume_token (parser);
4837 op = c_parser_cast_expression (parser, NULL);
4838 op = default_function_array_conversion (op);
4839 ret.value = build_indirect_ref (loc, op.value, "unary *");
4840 ret.original_code = ERROR_MARK;
4841 return ret;
4842 case CPP_PLUS:
4843 if (!c_dialect_objc () && !in_system_header)
4844 warning_at (c_parser_peek_token (parser)->location,
4845 OPT_Wtraditional,
4846 "traditional C rejects the unary plus operator");
4847 c_parser_consume_token (parser);
4848 op = c_parser_cast_expression (parser, NULL);
4849 op = default_function_array_conversion (op);
4850 return parser_build_unary_op (CONVERT_EXPR, op, loc);
4851 case CPP_MINUS:
4852 c_parser_consume_token (parser);
4853 op = c_parser_cast_expression (parser, NULL);
4854 op = default_function_array_conversion (op);
4855 return parser_build_unary_op (NEGATE_EXPR, op, loc);
4856 case CPP_COMPL:
4857 c_parser_consume_token (parser);
4858 op = c_parser_cast_expression (parser, NULL);
4859 op = default_function_array_conversion (op);
4860 return parser_build_unary_op (BIT_NOT_EXPR, op, loc);
4861 case CPP_NOT:
4862 c_parser_consume_token (parser);
4863 op = c_parser_cast_expression (parser, NULL);
4864 op = default_function_array_conversion (op);
4865 return parser_build_unary_op (TRUTH_NOT_EXPR, op, loc);
4866 case CPP_AND_AND:
4867 /* Refer to the address of a label as a pointer. */
4868 c_parser_consume_token (parser);
4869 if (c_parser_next_token_is (parser, CPP_NAME))
4870 {
4871 ret.value = finish_label_address_expr
4872 (c_parser_peek_token (parser)->value, loc);
4873 c_parser_consume_token (parser);
4874 }
4875 else
4876 {
4877 c_parser_error (parser, "expected identifier");
4878 ret.value = error_mark_node;
4879 }
4880 ret.original_code = ERROR_MARK;
4881 return ret;
4882 case CPP_KEYWORD:
4883 switch (c_parser_peek_token (parser)->keyword)
4884 {
4885 case RID_SIZEOF:
4886 return c_parser_sizeof_expression (parser);
4887 case RID_ALIGNOF:
4888 return c_parser_alignof_expression (parser);
4889 case RID_EXTENSION:
4890 c_parser_consume_token (parser);
4891 ext = disable_extension_diagnostics ();
4892 ret = c_parser_cast_expression (parser, NULL);
4893 restore_extension_diagnostics (ext);
4894 return ret;
4895 case RID_REALPART:
4896 c_parser_consume_token (parser);
4897 op = c_parser_cast_expression (parser, NULL);
4898 op = default_function_array_conversion (op);
4899 return parser_build_unary_op (REALPART_EXPR, op, loc);
4900 case RID_IMAGPART:
4901 c_parser_consume_token (parser);
4902 op = c_parser_cast_expression (parser, NULL);
4903 op = default_function_array_conversion (op);
4904 return parser_build_unary_op (IMAGPART_EXPR, op, loc);
4905 default:
4906 return c_parser_postfix_expression (parser);
4907 }
4908 default:
4909 return c_parser_postfix_expression (parser);
4910 }
4911 }
4912
4913 /* Parse a sizeof expression. */
4914
4915 static struct c_expr
4916 c_parser_sizeof_expression (c_parser *parser)
4917 {
4918 struct c_expr expr;
4919 location_t expr_loc;
4920 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
4921 c_parser_consume_token (parser);
4922 skip_evaluation++;
4923 in_sizeof++;
4924 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4925 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4926 {
4927 /* Either sizeof ( type-name ) or sizeof unary-expression
4928 starting with a compound literal. */
4929 struct c_type_name *type_name;
4930 c_parser_consume_token (parser);
4931 expr_loc = c_parser_peek_token (parser)->location;
4932 type_name = c_parser_type_name (parser);
4933 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4934 if (type_name == NULL)
4935 {
4936 struct c_expr ret;
4937 skip_evaluation--;
4938 in_sizeof--;
4939 ret.value = error_mark_node;
4940 ret.original_code = ERROR_MARK;
4941 return ret;
4942 }
4943 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4944 {
4945 expr = c_parser_postfix_expression_after_paren_type (parser,
4946 type_name);
4947 goto sizeof_expr;
4948 }
4949 /* sizeof ( type-name ). */
4950 skip_evaluation--;
4951 in_sizeof--;
4952 if (type_name->declarator->kind == cdk_array
4953 && type_name->declarator->u.array.vla_unspec_p)
4954 {
4955 /* C99 6.7.5.2p4 */
4956 error_at (expr_loc,
4957 "%<[*]%> not allowed in other than a declaration");
4958 }
4959 return c_expr_sizeof_type (type_name);
4960 }
4961 else
4962 {
4963 expr_loc = c_parser_peek_token (parser)->location;
4964 expr = c_parser_unary_expression (parser);
4965 sizeof_expr:
4966 skip_evaluation--;
4967 in_sizeof--;
4968 if (TREE_CODE (expr.value) == COMPONENT_REF
4969 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
4970 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
4971 return c_expr_sizeof_expr (expr);
4972 }
4973 }
4974
4975 /* Parse an alignof expression. */
4976
4977 static struct c_expr
4978 c_parser_alignof_expression (c_parser *parser)
4979 {
4980 struct c_expr expr;
4981 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
4982 c_parser_consume_token (parser);
4983 skip_evaluation++;
4984 in_alignof++;
4985 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4986 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4987 {
4988 /* Either __alignof__ ( type-name ) or __alignof__
4989 unary-expression starting with a compound literal. */
4990 struct c_type_name *type_name;
4991 struct c_expr ret;
4992 c_parser_consume_token (parser);
4993 type_name = c_parser_type_name (parser);
4994 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4995 if (type_name == NULL)
4996 {
4997 struct c_expr ret;
4998 skip_evaluation--;
4999 in_alignof--;
5000 ret.value = error_mark_node;
5001 ret.original_code = ERROR_MARK;
5002 return ret;
5003 }
5004 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5005 {
5006 expr = c_parser_postfix_expression_after_paren_type (parser,
5007 type_name);
5008 goto alignof_expr;
5009 }
5010 /* alignof ( type-name ). */
5011 skip_evaluation--;
5012 in_alignof--;
5013 ret.value = c_alignof (groktypename (type_name));
5014 ret.original_code = ERROR_MARK;
5015 return ret;
5016 }
5017 else
5018 {
5019 struct c_expr ret;
5020 expr = c_parser_unary_expression (parser);
5021 alignof_expr:
5022 skip_evaluation--;
5023 in_alignof--;
5024 ret.value = c_alignof_expr (expr.value);
5025 ret.original_code = ERROR_MARK;
5026 return ret;
5027 }
5028 }
5029
5030 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5031
5032 postfix-expression:
5033 primary-expression
5034 postfix-expression [ expression ]
5035 postfix-expression ( argument-expression-list[opt] )
5036 postfix-expression . identifier
5037 postfix-expression -> identifier
5038 postfix-expression ++
5039 postfix-expression --
5040 ( type-name ) { initializer-list }
5041 ( type-name ) { initializer-list , }
5042
5043 argument-expression-list:
5044 argument-expression
5045 argument-expression-list , argument-expression
5046
5047 primary-expression:
5048 identifier
5049 constant
5050 string-literal
5051 ( expression )
5052
5053 GNU extensions:
5054
5055 primary-expression:
5056 __func__
5057 (treated as a keyword in GNU C)
5058 __FUNCTION__
5059 __PRETTY_FUNCTION__
5060 ( compound-statement )
5061 __builtin_va_arg ( assignment-expression , type-name )
5062 __builtin_offsetof ( type-name , offsetof-member-designator )
5063 __builtin_choose_expr ( assignment-expression ,
5064 assignment-expression ,
5065 assignment-expression )
5066 __builtin_types_compatible_p ( type-name , type-name )
5067
5068 offsetof-member-designator:
5069 identifier
5070 offsetof-member-designator . identifier
5071 offsetof-member-designator [ expression ]
5072
5073 Objective-C:
5074
5075 primary-expression:
5076 [ objc-receiver objc-message-args ]
5077 @selector ( objc-selector-arg )
5078 @protocol ( identifier )
5079 @encode ( type-name )
5080 objc-string-literal
5081 */
5082
5083 static struct c_expr
5084 c_parser_postfix_expression (c_parser *parser)
5085 {
5086 struct c_expr expr, e1, e2, e3;
5087 struct c_type_name *t1, *t2;
5088 location_t loc;
5089 switch (c_parser_peek_token (parser)->type)
5090 {
5091 case CPP_NUMBER:
5092 expr.value = c_parser_peek_token (parser)->value;
5093 expr.original_code = ERROR_MARK;
5094 loc = c_parser_peek_token (parser)->location;
5095 c_parser_consume_token (parser);
5096 if (TREE_CODE (expr.value) == FIXED_CST
5097 && !targetm.fixed_point_supported_p ())
5098 {
5099 error_at (loc, "fixed-point types not supported for this target");
5100 expr.value = error_mark_node;
5101 }
5102 break;
5103 case CPP_CHAR:
5104 case CPP_CHAR16:
5105 case CPP_CHAR32:
5106 case CPP_WCHAR:
5107 expr.value = c_parser_peek_token (parser)->value;
5108 expr.original_code = ERROR_MARK;
5109 c_parser_consume_token (parser);
5110 break;
5111 case CPP_STRING:
5112 case CPP_STRING16:
5113 case CPP_STRING32:
5114 case CPP_WSTRING:
5115 expr.value = c_parser_peek_token (parser)->value;
5116 expr.original_code = STRING_CST;
5117 c_parser_consume_token (parser);
5118 break;
5119 case CPP_OBJC_STRING:
5120 gcc_assert (c_dialect_objc ());
5121 expr.value
5122 = objc_build_string_object (c_parser_peek_token (parser)->value);
5123 expr.original_code = ERROR_MARK;
5124 c_parser_consume_token (parser);
5125 break;
5126 case CPP_NAME:
5127 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5128 {
5129 c_parser_error (parser, "expected expression");
5130 expr.value = error_mark_node;
5131 expr.original_code = ERROR_MARK;
5132 break;
5133 }
5134 {
5135 tree id = c_parser_peek_token (parser)->value;
5136 location_t loc = c_parser_peek_token (parser)->location;
5137 c_parser_consume_token (parser);
5138 expr.value = build_external_ref (id,
5139 (c_parser_peek_token (parser)->type
5140 == CPP_OPEN_PAREN), loc);
5141 expr.original_code = ERROR_MARK;
5142 }
5143 break;
5144 case CPP_OPEN_PAREN:
5145 /* A parenthesized expression, statement expression or compound
5146 literal. */
5147 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5148 {
5149 /* A statement expression. */
5150 tree stmt;
5151 location_t here = c_parser_peek_token (parser)->location;
5152 c_parser_consume_token (parser);
5153 c_parser_consume_token (parser);
5154 if (cur_stmt_list == NULL)
5155 {
5156 error_at (here, "braced-group within expression allowed "
5157 "only inside a function");
5158 parser->error = true;
5159 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5160 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5161 expr.value = error_mark_node;
5162 expr.original_code = ERROR_MARK;
5163 break;
5164 }
5165 stmt = c_begin_stmt_expr ();
5166 c_parser_compound_statement_nostart (parser);
5167 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5168 "expected %<)%>");
5169 pedwarn (here, OPT_pedantic,
5170 "ISO C forbids braced-groups within expressions");
5171 expr.value = c_finish_stmt_expr (stmt);
5172 expr.original_code = ERROR_MARK;
5173 }
5174 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5175 {
5176 /* A compound literal. ??? Can we actually get here rather
5177 than going directly to
5178 c_parser_postfix_expression_after_paren_type from
5179 elsewhere? */
5180 struct c_type_name *type_name;
5181 c_parser_consume_token (parser);
5182 type_name = c_parser_type_name (parser);
5183 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5184 "expected %<)%>");
5185 if (type_name == NULL)
5186 {
5187 expr.value = error_mark_node;
5188 expr.original_code = ERROR_MARK;
5189 }
5190 else
5191 expr = c_parser_postfix_expression_after_paren_type (parser,
5192 type_name);
5193 }
5194 else
5195 {
5196 /* A parenthesized expression. */
5197 c_parser_consume_token (parser);
5198 expr = c_parser_expression (parser);
5199 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5200 TREE_NO_WARNING (expr.value) = 1;
5201 expr.original_code = ERROR_MARK;
5202 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5203 "expected %<)%>");
5204 }
5205 break;
5206 case CPP_KEYWORD:
5207 switch (c_parser_peek_token (parser)->keyword)
5208 {
5209 case RID_FUNCTION_NAME:
5210 case RID_PRETTY_FUNCTION_NAME:
5211 case RID_C99_FUNCTION_NAME:
5212 expr.value = fname_decl (c_parser_peek_token (parser)->location,
5213 c_parser_peek_token (parser)->keyword,
5214 c_parser_peek_token (parser)->value);
5215 expr.original_code = ERROR_MARK;
5216 c_parser_consume_token (parser);
5217 break;
5218 case RID_VA_ARG:
5219 c_parser_consume_token (parser);
5220 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5221 {
5222 expr.value = error_mark_node;
5223 expr.original_code = ERROR_MARK;
5224 break;
5225 }
5226 e1 = c_parser_expr_no_commas (parser, NULL);
5227 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5228 {
5229 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5230 expr.value = error_mark_node;
5231 expr.original_code = ERROR_MARK;
5232 break;
5233 }
5234 t1 = c_parser_type_name (parser);
5235 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5236 "expected %<)%>");
5237 if (t1 == NULL)
5238 {
5239 expr.value = error_mark_node;
5240 expr.original_code = ERROR_MARK;
5241 }
5242 else
5243 {
5244 expr.value = build_va_arg (e1.value, groktypename (t1));
5245 expr.original_code = ERROR_MARK;
5246 }
5247 break;
5248 case RID_OFFSETOF:
5249 c_parser_consume_token (parser);
5250 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5251 {
5252 expr.value = error_mark_node;
5253 expr.original_code = ERROR_MARK;
5254 break;
5255 }
5256 t1 = c_parser_type_name (parser);
5257 if (t1 == NULL)
5258 {
5259 expr.value = error_mark_node;
5260 expr.original_code = ERROR_MARK;
5261 break;
5262 }
5263 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5264 {
5265 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5266 expr.value = error_mark_node;
5267 expr.original_code = ERROR_MARK;
5268 break;
5269 }
5270 {
5271 tree type = groktypename (t1);
5272 tree offsetof_ref;
5273 if (type == error_mark_node)
5274 offsetof_ref = error_mark_node;
5275 else
5276 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5277 /* Parse the second argument to __builtin_offsetof. We
5278 must have one identifier, and beyond that we want to
5279 accept sub structure and sub array references. */
5280 if (c_parser_next_token_is (parser, CPP_NAME))
5281 {
5282 offsetof_ref = build_component_ref
5283 (offsetof_ref, c_parser_peek_token (parser)->value);
5284 c_parser_consume_token (parser);
5285 while (c_parser_next_token_is (parser, CPP_DOT)
5286 || c_parser_next_token_is (parser,
5287 CPP_OPEN_SQUARE)
5288 || c_parser_next_token_is (parser,
5289 CPP_DEREF))
5290 {
5291 if (c_parser_next_token_is (parser, CPP_DEREF))
5292 {
5293 loc = c_parser_peek_token (parser)->location;
5294 offsetof_ref = build_array_ref (offsetof_ref,
5295 integer_zero_node,
5296 loc);
5297 goto do_dot;
5298 }
5299 else if (c_parser_next_token_is (parser, CPP_DOT))
5300 {
5301 do_dot:
5302 c_parser_consume_token (parser);
5303 if (c_parser_next_token_is_not (parser,
5304 CPP_NAME))
5305 {
5306 c_parser_error (parser, "expected identifier");
5307 break;
5308 }
5309 offsetof_ref = build_component_ref
5310 (offsetof_ref,
5311 c_parser_peek_token (parser)->value);
5312 c_parser_consume_token (parser);
5313 }
5314 else
5315 {
5316 tree idx;
5317 loc = c_parser_peek_token (parser)->location;
5318 c_parser_consume_token (parser);
5319 idx = c_parser_expression (parser).value;
5320 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5321 "expected %<]%>");
5322 offsetof_ref = build_array_ref (offsetof_ref, idx, loc);
5323 }
5324 }
5325 }
5326 else
5327 c_parser_error (parser, "expected identifier");
5328 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5329 "expected %<)%>");
5330 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5331 expr.original_code = ERROR_MARK;
5332 }
5333 break;
5334 case RID_CHOOSE_EXPR:
5335 c_parser_consume_token (parser);
5336 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5337 {
5338 expr.value = error_mark_node;
5339 expr.original_code = ERROR_MARK;
5340 break;
5341 }
5342 loc = c_parser_peek_token (parser)->location;
5343 e1 = c_parser_expr_no_commas (parser, NULL);
5344 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5345 {
5346 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5347 expr.value = error_mark_node;
5348 expr.original_code = ERROR_MARK;
5349 break;
5350 }
5351 e2 = c_parser_expr_no_commas (parser, NULL);
5352 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5353 {
5354 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5355 expr.value = error_mark_node;
5356 expr.original_code = ERROR_MARK;
5357 break;
5358 }
5359 e3 = c_parser_expr_no_commas (parser, NULL);
5360 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5361 "expected %<)%>");
5362 {
5363 tree c;
5364
5365 c = fold (e1.value);
5366 if (TREE_CODE (c) != INTEGER_CST)
5367 error_at (loc,
5368 "first argument to %<__builtin_choose_expr%> not"
5369 " a constant");
5370 expr = integer_zerop (c) ? e3 : e2;
5371 }
5372 break;
5373 case RID_TYPES_COMPATIBLE_P:
5374 c_parser_consume_token (parser);
5375 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5376 {
5377 expr.value = error_mark_node;
5378 expr.original_code = ERROR_MARK;
5379 break;
5380 }
5381 t1 = c_parser_type_name (parser);
5382 if (t1 == NULL)
5383 {
5384 expr.value = error_mark_node;
5385 expr.original_code = ERROR_MARK;
5386 break;
5387 }
5388 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5389 {
5390 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5391 expr.value = error_mark_node;
5392 expr.original_code = ERROR_MARK;
5393 break;
5394 }
5395 t2 = c_parser_type_name (parser);
5396 if (t2 == NULL)
5397 {
5398 expr.value = error_mark_node;
5399 expr.original_code = ERROR_MARK;
5400 break;
5401 }
5402 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5403 "expected %<)%>");
5404 {
5405 tree e1, e2;
5406
5407 e1 = TYPE_MAIN_VARIANT (groktypename (t1));
5408 e2 = TYPE_MAIN_VARIANT (groktypename (t2));
5409
5410 expr.value = comptypes (e1, e2)
5411 ? build_int_cst (NULL_TREE, 1)
5412 : build_int_cst (NULL_TREE, 0);
5413 expr.original_code = ERROR_MARK;
5414 }
5415 break;
5416 case RID_AT_SELECTOR:
5417 gcc_assert (c_dialect_objc ());
5418 c_parser_consume_token (parser);
5419 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5420 {
5421 expr.value = error_mark_node;
5422 expr.original_code = ERROR_MARK;
5423 break;
5424 }
5425 {
5426 tree sel = c_parser_objc_selector_arg (parser);
5427 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5428 "expected %<)%>");
5429 expr.value = objc_build_selector_expr (sel);
5430 expr.original_code = ERROR_MARK;
5431 }
5432 break;
5433 case RID_AT_PROTOCOL:
5434 gcc_assert (c_dialect_objc ());
5435 c_parser_consume_token (parser);
5436 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5437 {
5438 expr.value = error_mark_node;
5439 expr.original_code = ERROR_MARK;
5440 break;
5441 }
5442 if (c_parser_next_token_is_not (parser, CPP_NAME))
5443 {
5444 c_parser_error (parser, "expected identifier");
5445 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5446 expr.value = error_mark_node;
5447 expr.original_code = ERROR_MARK;
5448 break;
5449 }
5450 {
5451 tree id = c_parser_peek_token (parser)->value;
5452 c_parser_consume_token (parser);
5453 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5454 "expected %<)%>");
5455 expr.value = objc_build_protocol_expr (id);
5456 expr.original_code = ERROR_MARK;
5457 }
5458 break;
5459 case RID_AT_ENCODE:
5460 /* Extension to support C-structures in the archiver. */
5461 gcc_assert (c_dialect_objc ());
5462 c_parser_consume_token (parser);
5463 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5464 {
5465 expr.value = error_mark_node;
5466 expr.original_code = ERROR_MARK;
5467 break;
5468 }
5469 t1 = c_parser_type_name (parser);
5470 if (t1 == NULL)
5471 {
5472 expr.value = error_mark_node;
5473 expr.original_code = ERROR_MARK;
5474 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5475 break;
5476 }
5477 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5478 "expected %<)%>");
5479 {
5480 tree type = groktypename (t1);
5481 expr.value = objc_build_encode_expr (type);
5482 expr.original_code = ERROR_MARK;
5483 }
5484 break;
5485 default:
5486 c_parser_error (parser, "expected expression");
5487 expr.value = error_mark_node;
5488 expr.original_code = ERROR_MARK;
5489 break;
5490 }
5491 break;
5492 case CPP_OPEN_SQUARE:
5493 if (c_dialect_objc ())
5494 {
5495 tree receiver, args;
5496 c_parser_consume_token (parser);
5497 receiver = c_parser_objc_receiver (parser);
5498 args = c_parser_objc_message_args (parser);
5499 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5500 "expected %<]%>");
5501 expr.value = objc_build_message_expr (build_tree_list (receiver,
5502 args));
5503 expr.original_code = ERROR_MARK;
5504 break;
5505 }
5506 /* Else fall through to report error. */
5507 default:
5508 c_parser_error (parser, "expected expression");
5509 expr.value = error_mark_node;
5510 expr.original_code = ERROR_MARK;
5511 break;
5512 }
5513 return c_parser_postfix_expression_after_primary (parser, expr);
5514 }
5515
5516 /* Parse a postfix expression after a parenthesized type name: the
5517 brace-enclosed initializer of a compound literal, possibly followed
5518 by some postfix operators. This is separate because it is not
5519 possible to tell until after the type name whether a cast
5520 expression has a cast or a compound literal, or whether the operand
5521 of sizeof is a parenthesized type name or starts with a compound
5522 literal. */
5523
5524 static struct c_expr
5525 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5526 struct c_type_name *type_name)
5527 {
5528 tree type;
5529 struct c_expr init;
5530 struct c_expr expr;
5531 location_t start_loc;
5532 start_init (NULL_TREE, NULL, 0);
5533 type = groktypename (type_name);
5534 start_loc = c_parser_peek_token (parser)->location;
5535 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
5536 {
5537 error_at (start_loc, "compound literal has variable size");
5538 type = error_mark_node;
5539 }
5540 init = c_parser_braced_init (parser, type, false);
5541 finish_init ();
5542 maybe_warn_string_init (type, init);
5543
5544 if (!flag_isoc99)
5545 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
5546 expr.value = build_compound_literal (type, init.value);
5547 expr.original_code = ERROR_MARK;
5548 return c_parser_postfix_expression_after_primary (parser, expr);
5549 }
5550
5551 /* Parse a postfix expression after the initial primary or compound
5552 literal; that is, parse a series of postfix operators. */
5553
5554 static struct c_expr
5555 c_parser_postfix_expression_after_primary (c_parser *parser,
5556 struct c_expr expr)
5557 {
5558 tree ident, idx, exprlist;
5559 location_t loc = c_parser_peek_token (parser)->location;
5560 while (true)
5561 {
5562 switch (c_parser_peek_token (parser)->type)
5563 {
5564 case CPP_OPEN_SQUARE:
5565 /* Array reference. */
5566 loc = c_parser_peek_token (parser)->location;
5567 c_parser_consume_token (parser);
5568 idx = c_parser_expression (parser).value;
5569 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5570 "expected %<]%>");
5571 expr.value = build_array_ref (expr.value, idx, loc);
5572 expr.original_code = ERROR_MARK;
5573 break;
5574 case CPP_OPEN_PAREN:
5575 /* Function call. */
5576 c_parser_consume_token (parser);
5577 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5578 exprlist = NULL_TREE;
5579 else
5580 exprlist = c_parser_expr_list (parser, true);
5581 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5582 "expected %<)%>");
5583 expr.value = build_function_call (expr.value, exprlist);
5584 expr.original_code = ERROR_MARK;
5585 if (warn_disallowed_functions)
5586 warn_if_disallowed_function_p (expr.value);
5587 break;
5588 case CPP_DOT:
5589 /* Structure element reference. */
5590 c_parser_consume_token (parser);
5591 expr = default_function_array_conversion (expr);
5592 if (c_parser_next_token_is (parser, CPP_NAME))
5593 ident = c_parser_peek_token (parser)->value;
5594 else
5595 {
5596 c_parser_error (parser, "expected identifier");
5597 expr.value = error_mark_node;
5598 expr.original_code = ERROR_MARK;
5599 return expr;
5600 }
5601 c_parser_consume_token (parser);
5602 expr.value = build_component_ref (expr.value, ident);
5603 expr.original_code = ERROR_MARK;
5604 break;
5605 case CPP_DEREF:
5606 /* Structure element reference. */
5607 c_parser_consume_token (parser);
5608 expr = default_function_array_conversion (expr);
5609 if (c_parser_next_token_is (parser, CPP_NAME))
5610 ident = c_parser_peek_token (parser)->value;
5611 else
5612 {
5613 c_parser_error (parser, "expected identifier");
5614 expr.value = error_mark_node;
5615 expr.original_code = ERROR_MARK;
5616 return expr;
5617 }
5618 c_parser_consume_token (parser);
5619 expr.value = build_component_ref (build_indirect_ref (loc,
5620 expr.value,
5621 "->"),
5622 ident);
5623 expr.original_code = ERROR_MARK;
5624 break;
5625 case CPP_PLUS_PLUS:
5626 /* Postincrement. */
5627 c_parser_consume_token (parser);
5628 expr = default_function_array_conversion (expr);
5629 expr.value = build_unary_op (loc,
5630 POSTINCREMENT_EXPR, expr.value, 0);
5631 expr.original_code = ERROR_MARK;
5632 break;
5633 case CPP_MINUS_MINUS:
5634 /* Postdecrement. */
5635 c_parser_consume_token (parser);
5636 expr = default_function_array_conversion (expr);
5637 expr.value = build_unary_op (loc,
5638 POSTDECREMENT_EXPR, expr.value, 0);
5639 expr.original_code = ERROR_MARK;
5640 break;
5641 default:
5642 return expr;
5643 }
5644 }
5645 }
5646
5647 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5648
5649 expression:
5650 assignment-expression
5651 expression , assignment-expression
5652 */
5653
5654 static struct c_expr
5655 c_parser_expression (c_parser *parser)
5656 {
5657 struct c_expr expr;
5658 expr = c_parser_expr_no_commas (parser, NULL);
5659 while (c_parser_next_token_is (parser, CPP_COMMA))
5660 {
5661 struct c_expr next;
5662 c_parser_consume_token (parser);
5663 next = c_parser_expr_no_commas (parser, NULL);
5664 next = default_function_array_conversion (next);
5665 expr.value = build_compound_expr (expr.value, next.value);
5666 expr.original_code = COMPOUND_EXPR;
5667 }
5668 return expr;
5669 }
5670
5671 /* Parse an expression and convert functions or arrays to
5672 pointers. */
5673
5674 static struct c_expr
5675 c_parser_expression_conv (c_parser *parser)
5676 {
5677 struct c_expr expr;
5678 expr = c_parser_expression (parser);
5679 expr = default_function_array_conversion (expr);
5680 return expr;
5681 }
5682
5683 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5684 functions and arrays to pointers.
5685
5686 nonempty-expr-list:
5687 assignment-expression
5688 nonempty-expr-list , assignment-expression
5689 */
5690
5691 static tree
5692 c_parser_expr_list (c_parser *parser, bool convert_p)
5693 {
5694 struct c_expr expr;
5695 tree ret, cur;
5696 expr = c_parser_expr_no_commas (parser, NULL);
5697 if (convert_p)
5698 expr = default_function_array_conversion (expr);
5699 ret = cur = build_tree_list (NULL_TREE, expr.value);
5700 while (c_parser_next_token_is (parser, CPP_COMMA))
5701 {
5702 c_parser_consume_token (parser);
5703 expr = c_parser_expr_no_commas (parser, NULL);
5704 if (convert_p)
5705 expr = default_function_array_conversion (expr);
5706 cur = TREE_CHAIN (cur) = build_tree_list (NULL_TREE, expr.value);
5707 }
5708 return ret;
5709 }
5710
5711 \f
5712 /* Parse Objective-C-specific constructs. */
5713
5714 /* Parse an objc-class-definition.
5715
5716 objc-class-definition:
5717 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5718 objc-class-instance-variables[opt] objc-methodprotolist @end
5719 @implementation identifier objc-superclass[opt]
5720 objc-class-instance-variables[opt]
5721 @interface identifier ( identifier ) objc-protocol-refs[opt]
5722 objc-methodprotolist @end
5723 @implementation identifier ( identifier )
5724
5725 objc-superclass:
5726 : identifier
5727
5728 "@interface identifier (" must start "@interface identifier (
5729 identifier ) ...": objc-methodprotolist in the first production may
5730 not start with a parenthesized identifier as a declarator of a data
5731 definition with no declaration specifiers if the objc-superclass,
5732 objc-protocol-refs and objc-class-instance-variables are omitted. */
5733
5734 static void
5735 c_parser_objc_class_definition (c_parser *parser)
5736 {
5737 bool iface_p;
5738 tree id1;
5739 tree superclass;
5740 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
5741 iface_p = true;
5742 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
5743 iface_p = false;
5744 else
5745 gcc_unreachable ();
5746 c_parser_consume_token (parser);
5747 if (c_parser_next_token_is_not (parser, CPP_NAME))
5748 {
5749 c_parser_error (parser, "expected identifier");
5750 return;
5751 }
5752 id1 = c_parser_peek_token (parser)->value;
5753 c_parser_consume_token (parser);
5754 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
5755 {
5756 tree id2;
5757 tree proto = NULL_TREE;
5758 c_parser_consume_token (parser);
5759 if (c_parser_next_token_is_not (parser, CPP_NAME))
5760 {
5761 c_parser_error (parser, "expected identifier");
5762 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5763 return;
5764 }
5765 id2 = c_parser_peek_token (parser)->value;
5766 c_parser_consume_token (parser);
5767 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5768 if (!iface_p)
5769 {
5770 objc_start_category_implementation (id1, id2);
5771 return;
5772 }
5773 if (c_parser_next_token_is (parser, CPP_LESS))
5774 proto = c_parser_objc_protocol_refs (parser);
5775 objc_start_category_interface (id1, id2, proto);
5776 c_parser_objc_methodprotolist (parser);
5777 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5778 objc_finish_interface ();
5779 return;
5780 }
5781 if (c_parser_next_token_is (parser, CPP_COLON))
5782 {
5783 c_parser_consume_token (parser);
5784 if (c_parser_next_token_is_not (parser, CPP_NAME))
5785 {
5786 c_parser_error (parser, "expected identifier");
5787 return;
5788 }
5789 superclass = c_parser_peek_token (parser)->value;
5790 c_parser_consume_token (parser);
5791 }
5792 else
5793 superclass = NULL_TREE;
5794 if (iface_p)
5795 {
5796 tree proto = NULL_TREE;
5797 if (c_parser_next_token_is (parser, CPP_LESS))
5798 proto = c_parser_objc_protocol_refs (parser);
5799 objc_start_class_interface (id1, superclass, proto);
5800 }
5801 else
5802 objc_start_class_implementation (id1, superclass);
5803 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5804 c_parser_objc_class_instance_variables (parser);
5805 if (iface_p)
5806 {
5807 objc_continue_interface ();
5808 c_parser_objc_methodprotolist (parser);
5809 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5810 objc_finish_interface ();
5811 }
5812 else
5813 {
5814 objc_continue_implementation ();
5815 return;
5816 }
5817 }
5818
5819 /* Parse objc-class-instance-variables.
5820
5821 objc-class-instance-variables:
5822 { objc-instance-variable-decl-list[opt] }
5823
5824 objc-instance-variable-decl-list:
5825 objc-visibility-spec
5826 objc-instance-variable-decl ;
5827 ;
5828 objc-instance-variable-decl-list objc-visibility-spec
5829 objc-instance-variable-decl-list objc-instance-variable-decl ;
5830 objc-instance-variable-decl-list ;
5831
5832 objc-visibility-spec:
5833 @private
5834 @protected
5835 @public
5836
5837 objc-instance-variable-decl:
5838 struct-declaration
5839 */
5840
5841 static void
5842 c_parser_objc_class_instance_variables (c_parser *parser)
5843 {
5844 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
5845 c_parser_consume_token (parser);
5846 while (c_parser_next_token_is_not (parser, CPP_EOF))
5847 {
5848 tree decls;
5849 /* Parse any stray semicolon. */
5850 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5851 {
5852 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
5853 "extra semicolon in struct or union specified");
5854 c_parser_consume_token (parser);
5855 continue;
5856 }
5857 /* Stop if at the end of the instance variables. */
5858 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
5859 {
5860 c_parser_consume_token (parser);
5861 break;
5862 }
5863 /* Parse any objc-visibility-spec. */
5864 if (c_parser_next_token_is_keyword (parser, RID_PRIVATE))
5865 {
5866 c_parser_consume_token (parser);
5867 objc_set_visibility (2);
5868 continue;
5869 }
5870 else if (c_parser_next_token_is_keyword (parser, RID_PROTECTED))
5871 {
5872 c_parser_consume_token (parser);
5873 objc_set_visibility (0);
5874 continue;
5875 }
5876 else if (c_parser_next_token_is_keyword (parser, RID_PUBLIC))
5877 {
5878 c_parser_consume_token (parser);
5879 objc_set_visibility (1);
5880 continue;
5881 }
5882 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
5883 {
5884 c_parser_pragma (parser, pragma_external);
5885 continue;
5886 }
5887
5888 /* Parse some comma-separated declarations. */
5889 decls = c_parser_struct_declaration (parser);
5890 {
5891 /* Comma-separated instance variables are chained together in
5892 reverse order; add them one by one. */
5893 tree ivar = nreverse (decls);
5894 for (; ivar; ivar = TREE_CHAIN (ivar))
5895 objc_add_instance_variable (copy_node (ivar));
5896 }
5897 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5898 }
5899 }
5900
5901 /* Parse an objc-class-declaration.
5902
5903 objc-class-declaration:
5904 @class identifier-list ;
5905 */
5906
5907 static void
5908 c_parser_objc_class_declaration (c_parser *parser)
5909 {
5910 tree list = NULL_TREE;
5911 gcc_assert (c_parser_next_token_is_keyword (parser, RID_CLASS));
5912 c_parser_consume_token (parser);
5913 /* Any identifiers, including those declared as type names, are OK
5914 here. */
5915 while (true)
5916 {
5917 tree id;
5918 if (c_parser_next_token_is_not (parser, CPP_NAME))
5919 {
5920 c_parser_error (parser, "expected identifier");
5921 break;
5922 }
5923 id = c_parser_peek_token (parser)->value;
5924 list = chainon (list, build_tree_list (NULL_TREE, id));
5925 c_parser_consume_token (parser);
5926 if (c_parser_next_token_is (parser, CPP_COMMA))
5927 c_parser_consume_token (parser);
5928 else
5929 break;
5930 }
5931 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5932 objc_declare_class (list);
5933 }
5934
5935 /* Parse an objc-alias-declaration.
5936
5937 objc-alias-declaration:
5938 @compatibility_alias identifier identifier ;
5939 */
5940
5941 static void
5942 c_parser_objc_alias_declaration (c_parser *parser)
5943 {
5944 tree id1, id2;
5945 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
5946 c_parser_consume_token (parser);
5947 if (c_parser_next_token_is_not (parser, CPP_NAME))
5948 {
5949 c_parser_error (parser, "expected identifier");
5950 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5951 return;
5952 }
5953 id1 = c_parser_peek_token (parser)->value;
5954 c_parser_consume_token (parser);
5955 if (c_parser_next_token_is_not (parser, CPP_NAME))
5956 {
5957 c_parser_error (parser, "expected identifier");
5958 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5959 return;
5960 }
5961 id2 = c_parser_peek_token (parser)->value;
5962 c_parser_consume_token (parser);
5963 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5964 objc_declare_alias (id1, id2);
5965 }
5966
5967 /* Parse an objc-protocol-definition.
5968
5969 objc-protocol-definition:
5970 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5971 @protocol identifier-list ;
5972
5973 "@protocol identifier ;" should be resolved as "@protocol
5974 identifier-list ;": objc-methodprotolist may not start with a
5975 semicolon in the first alternative if objc-protocol-refs are
5976 omitted. */
5977
5978 static void
5979 c_parser_objc_protocol_definition (c_parser *parser)
5980 {
5981 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
5982 c_parser_consume_token (parser);
5983 if (c_parser_next_token_is_not (parser, CPP_NAME))
5984 {
5985 c_parser_error (parser, "expected identifier");
5986 return;
5987 }
5988 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
5989 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
5990 {
5991 tree list = NULL_TREE;
5992 /* Any identifiers, including those declared as type names, are
5993 OK here. */
5994 while (true)
5995 {
5996 tree id;
5997 if (c_parser_next_token_is_not (parser, CPP_NAME))
5998 {
5999 c_parser_error (parser, "expected identifier");
6000 break;
6001 }
6002 id = c_parser_peek_token (parser)->value;
6003 list = chainon (list, build_tree_list (NULL_TREE, id));
6004 c_parser_consume_token (parser);
6005 if (c_parser_next_token_is (parser, CPP_COMMA))
6006 c_parser_consume_token (parser);
6007 else
6008 break;
6009 }
6010 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6011 objc_declare_protocols (list);
6012 }
6013 else
6014 {
6015 tree id = c_parser_peek_token (parser)->value;
6016 tree proto = NULL_TREE;
6017 c_parser_consume_token (parser);
6018 if (c_parser_next_token_is (parser, CPP_LESS))
6019 proto = c_parser_objc_protocol_refs (parser);
6020 parser->objc_pq_context = true;
6021 objc_start_protocol (id, proto);
6022 c_parser_objc_methodprotolist (parser);
6023 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6024 parser->objc_pq_context = false;
6025 objc_finish_interface ();
6026 }
6027 }
6028
6029 /* Parse an objc-method-type.
6030
6031 objc-method-type:
6032 +
6033 -
6034 */
6035
6036 static enum tree_code
6037 c_parser_objc_method_type (c_parser *parser)
6038 {
6039 switch (c_parser_peek_token (parser)->type)
6040 {
6041 case CPP_PLUS:
6042 c_parser_consume_token (parser);
6043 return PLUS_EXPR;
6044 case CPP_MINUS:
6045 c_parser_consume_token (parser);
6046 return MINUS_EXPR;
6047 default:
6048 gcc_unreachable ();
6049 }
6050 }
6051
6052 /* Parse an objc-method-definition.
6053
6054 objc-method-definition:
6055 objc-method-type objc-method-decl ;[opt] compound-statement
6056 */
6057
6058 static void
6059 c_parser_objc_method_definition (c_parser *parser)
6060 {
6061 enum tree_code type = c_parser_objc_method_type (parser);
6062 tree decl;
6063 objc_set_method_type (type);
6064 parser->objc_pq_context = true;
6065 decl = c_parser_objc_method_decl (parser);
6066 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6067 {
6068 c_parser_consume_token (parser);
6069 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6070 "extra semicolon in method definition specified");
6071 }
6072 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6073 {
6074 c_parser_error (parser, "expected %<{%>");
6075 return;
6076 }
6077 parser->objc_pq_context = false;
6078 objc_start_method_definition (decl);
6079 add_stmt (c_parser_compound_statement (parser));
6080 objc_finish_method_definition (current_function_decl);
6081 }
6082
6083 /* Parse an objc-methodprotolist.
6084
6085 objc-methodprotolist:
6086 empty
6087 objc-methodprotolist objc-methodproto
6088 objc-methodprotolist declaration
6089 objc-methodprotolist ;
6090
6091 The declaration is a data definition, which may be missing
6092 declaration specifiers under the same rules and diagnostics as
6093 other data definitions outside functions, and the stray semicolon
6094 is diagnosed the same way as a stray semicolon outside a
6095 function. */
6096
6097 static void
6098 c_parser_objc_methodprotolist (c_parser *parser)
6099 {
6100 while (true)
6101 {
6102 /* The list is terminated by @end. */
6103 switch (c_parser_peek_token (parser)->type)
6104 {
6105 case CPP_SEMICOLON:
6106 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6107 "ISO C does not allow extra %<;%> outside of a function");
6108 c_parser_consume_token (parser);
6109 break;
6110 case CPP_PLUS:
6111 case CPP_MINUS:
6112 c_parser_objc_methodproto (parser);
6113 break;
6114 case CPP_PRAGMA:
6115 c_parser_pragma (parser, pragma_external);
6116 break;
6117 case CPP_EOF:
6118 return;
6119 default:
6120 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6121 return;
6122 c_parser_declaration_or_fndef (parser, false, true, false, true);
6123 break;
6124 }
6125 }
6126 }
6127
6128 /* Parse an objc-methodproto.
6129
6130 objc-methodproto:
6131 objc-method-type objc-method-decl ;
6132 */
6133
6134 static void
6135 c_parser_objc_methodproto (c_parser *parser)
6136 {
6137 enum tree_code type = c_parser_objc_method_type (parser);
6138 tree decl;
6139 objc_set_method_type (type);
6140 /* Remember protocol qualifiers in prototypes. */
6141 parser->objc_pq_context = true;
6142 decl = c_parser_objc_method_decl (parser);
6143 /* Forget protocol qualifiers here. */
6144 parser->objc_pq_context = false;
6145 objc_add_method_declaration (decl);
6146 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6147 }
6148
6149 /* Parse an objc-method-decl.
6150
6151 objc-method-decl:
6152 ( objc-type-name ) objc-selector
6153 objc-selector
6154 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6155 objc-keyword-selector objc-optparmlist
6156
6157 objc-keyword-selector:
6158 objc-keyword-decl
6159 objc-keyword-selector objc-keyword-decl
6160
6161 objc-keyword-decl:
6162 objc-selector : ( objc-type-name ) identifier
6163 objc-selector : identifier
6164 : ( objc-type-name ) identifier
6165 : identifier
6166
6167 objc-optparmlist:
6168 objc-optparms objc-optellipsis
6169
6170 objc-optparms:
6171 empty
6172 objc-opt-parms , parameter-declaration
6173
6174 objc-optellipsis:
6175 empty
6176 , ...
6177 */
6178
6179 static tree
6180 c_parser_objc_method_decl (c_parser *parser)
6181 {
6182 tree type = NULL_TREE;
6183 tree sel;
6184 tree parms = NULL_TREE;
6185 bool ellipsis = false;
6186
6187 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6188 {
6189 c_parser_consume_token (parser);
6190 type = c_parser_objc_type_name (parser);
6191 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6192 }
6193 sel = c_parser_objc_selector (parser);
6194 /* If there is no selector, or a colon follows, we have an
6195 objc-keyword-selector. If there is a selector, and a colon does
6196 not follow, that selector ends the objc-method-decl. */
6197 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6198 {
6199 tree tsel = sel;
6200 tree list = NULL_TREE;
6201 while (true)
6202 {
6203 tree atype = NULL_TREE, id, keyworddecl;
6204 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6205 break;
6206 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6207 {
6208 c_parser_consume_token (parser);
6209 atype = c_parser_objc_type_name (parser);
6210 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6211 "expected %<)%>");
6212 }
6213 if (c_parser_next_token_is_not (parser, CPP_NAME))
6214 {
6215 c_parser_error (parser, "expected identifier");
6216 return error_mark_node;
6217 }
6218 id = c_parser_peek_token (parser)->value;
6219 c_parser_consume_token (parser);
6220 keyworddecl = objc_build_keyword_decl (tsel, atype, id);
6221 list = chainon (list, keyworddecl);
6222 tsel = c_parser_objc_selector (parser);
6223 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6224 break;
6225 }
6226 /* Parse the optional parameter list. Optional Objective-C
6227 method parameters follow the C syntax, and may include '...'
6228 to denote a variable number of arguments. */
6229 parms = make_node (TREE_LIST);
6230 while (c_parser_next_token_is (parser, CPP_COMMA))
6231 {
6232 struct c_parm *parm;
6233 c_parser_consume_token (parser);
6234 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6235 {
6236 ellipsis = true;
6237 c_parser_consume_token (parser);
6238 break;
6239 }
6240 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6241 if (parm == NULL)
6242 break;
6243 parms = chainon (parms,
6244 build_tree_list (NULL_TREE, grokparm (parm)));
6245 }
6246 sel = list;
6247 }
6248 return objc_build_method_signature (type, sel, parms, ellipsis);
6249 }
6250
6251 /* Parse an objc-type-name.
6252
6253 objc-type-name:
6254 objc-type-qualifiers[opt] type-name
6255 objc-type-qualifiers[opt]
6256
6257 objc-type-qualifiers:
6258 objc-type-qualifier
6259 objc-type-qualifiers objc-type-qualifier
6260
6261 objc-type-qualifier: one of
6262 in out inout bycopy byref oneway
6263 */
6264
6265 static tree
6266 c_parser_objc_type_name (c_parser *parser)
6267 {
6268 tree quals = NULL_TREE;
6269 struct c_type_name *type_name = NULL;
6270 tree type = NULL_TREE;
6271 while (true)
6272 {
6273 c_token *token = c_parser_peek_token (parser);
6274 if (token->type == CPP_KEYWORD
6275 && (token->keyword == RID_IN
6276 || token->keyword == RID_OUT
6277 || token->keyword == RID_INOUT
6278 || token->keyword == RID_BYCOPY
6279 || token->keyword == RID_BYREF
6280 || token->keyword == RID_ONEWAY))
6281 {
6282 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6283 c_parser_consume_token (parser);
6284 }
6285 else
6286 break;
6287 }
6288 if (c_parser_next_token_starts_typename (parser))
6289 type_name = c_parser_type_name (parser);
6290 if (type_name)
6291 type = groktypename (type_name);
6292 return build_tree_list (quals, type);
6293 }
6294
6295 /* Parse objc-protocol-refs.
6296
6297 objc-protocol-refs:
6298 < identifier-list >
6299 */
6300
6301 static tree
6302 c_parser_objc_protocol_refs (c_parser *parser)
6303 {
6304 tree list = NULL_TREE;
6305 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6306 c_parser_consume_token (parser);
6307 /* Any identifiers, including those declared as type names, are OK
6308 here. */
6309 while (true)
6310 {
6311 tree id;
6312 if (c_parser_next_token_is_not (parser, CPP_NAME))
6313 {
6314 c_parser_error (parser, "expected identifier");
6315 break;
6316 }
6317 id = c_parser_peek_token (parser)->value;
6318 list = chainon (list, build_tree_list (NULL_TREE, id));
6319 c_parser_consume_token (parser);
6320 if (c_parser_next_token_is (parser, CPP_COMMA))
6321 c_parser_consume_token (parser);
6322 else
6323 break;
6324 }
6325 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6326 return list;
6327 }
6328
6329 /* Parse an objc-try-catch-statement.
6330
6331 objc-try-catch-statement:
6332 @try compound-statement objc-catch-list[opt]
6333 @try compound-statement objc-catch-list[opt] @finally compound-statement
6334
6335 objc-catch-list:
6336 @catch ( parameter-declaration ) compound-statement
6337 objc-catch-list @catch ( parameter-declaration ) compound-statement
6338 */
6339
6340 static void
6341 c_parser_objc_try_catch_statement (c_parser *parser)
6342 {
6343 location_t loc;
6344 tree stmt;
6345 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRY));
6346 c_parser_consume_token (parser);
6347 loc = c_parser_peek_token (parser)->location;
6348 stmt = c_parser_compound_statement (parser);
6349 objc_begin_try_stmt (loc, stmt);
6350 while (c_parser_next_token_is_keyword (parser, RID_CATCH))
6351 {
6352 struct c_parm *parm;
6353 c_parser_consume_token (parser);
6354 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6355 break;
6356 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6357 if (parm == NULL)
6358 {
6359 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6360 break;
6361 }
6362 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6363 objc_begin_catch_clause (grokparm (parm));
6364 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6365 c_parser_compound_statement_nostart (parser);
6366 objc_finish_catch_clause ();
6367 }
6368 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6369 {
6370 location_t finloc;
6371 tree finstmt;
6372 c_parser_consume_token (parser);
6373 finloc = c_parser_peek_token (parser)->location;
6374 finstmt = c_parser_compound_statement (parser);
6375 objc_build_finally_clause (finloc, finstmt);
6376 }
6377 objc_finish_try_stmt ();
6378 }
6379
6380 /* Parse an objc-synchronized-statement.
6381
6382 objc-synchronized-statement:
6383 @synchronized ( expression ) compound-statement
6384 */
6385
6386 static void
6387 c_parser_objc_synchronized_statement (c_parser *parser)
6388 {
6389 location_t loc;
6390 tree expr, stmt;
6391 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6392 c_parser_consume_token (parser);
6393 loc = c_parser_peek_token (parser)->location;
6394 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6395 {
6396 expr = c_parser_expression (parser).value;
6397 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6398 }
6399 else
6400 expr = error_mark_node;
6401 stmt = c_parser_compound_statement (parser);
6402 objc_build_synchronized (loc, expr, stmt);
6403 }
6404
6405 /* Parse an objc-selector; return NULL_TREE without an error if the
6406 next token is not an objc-selector.
6407
6408 objc-selector:
6409 identifier
6410 one of
6411 enum struct union if else while do for switch case default
6412 break continue return goto asm sizeof typeof __alignof
6413 unsigned long const short volatile signed restrict _Complex
6414 in out inout bycopy byref oneway int char float double void _Bool
6415
6416 ??? Why this selection of keywords but not, for example, storage
6417 class specifiers? */
6418
6419 static tree
6420 c_parser_objc_selector (c_parser *parser)
6421 {
6422 c_token *token = c_parser_peek_token (parser);
6423 tree value = token->value;
6424 if (token->type == CPP_NAME)
6425 {
6426 c_parser_consume_token (parser);
6427 return value;
6428 }
6429 if (token->type != CPP_KEYWORD)
6430 return NULL_TREE;
6431 switch (token->keyword)
6432 {
6433 case RID_ENUM:
6434 case RID_STRUCT:
6435 case RID_UNION:
6436 case RID_IF:
6437 case RID_ELSE:
6438 case RID_WHILE:
6439 case RID_DO:
6440 case RID_FOR:
6441 case RID_SWITCH:
6442 case RID_CASE:
6443 case RID_DEFAULT:
6444 case RID_BREAK:
6445 case RID_CONTINUE:
6446 case RID_RETURN:
6447 case RID_GOTO:
6448 case RID_ASM:
6449 case RID_SIZEOF:
6450 case RID_TYPEOF:
6451 case RID_ALIGNOF:
6452 case RID_UNSIGNED:
6453 case RID_LONG:
6454 case RID_CONST:
6455 case RID_SHORT:
6456 case RID_VOLATILE:
6457 case RID_SIGNED:
6458 case RID_RESTRICT:
6459 case RID_COMPLEX:
6460 case RID_IN:
6461 case RID_OUT:
6462 case RID_INOUT:
6463 case RID_BYCOPY:
6464 case RID_BYREF:
6465 case RID_ONEWAY:
6466 case RID_INT:
6467 case RID_CHAR:
6468 case RID_FLOAT:
6469 case RID_DOUBLE:
6470 case RID_VOID:
6471 case RID_BOOL:
6472 c_parser_consume_token (parser);
6473 return value;
6474 default:
6475 return NULL_TREE;
6476 }
6477 }
6478
6479 /* Parse an objc-selector-arg.
6480
6481 objc-selector-arg:
6482 objc-selector
6483 objc-keywordname-list
6484
6485 objc-keywordname-list:
6486 objc-keywordname
6487 objc-keywordname-list objc-keywordname
6488
6489 objc-keywordname:
6490 objc-selector :
6491 :
6492 */
6493
6494 static tree
6495 c_parser_objc_selector_arg (c_parser *parser)
6496 {
6497 tree sel = c_parser_objc_selector (parser);
6498 tree list = NULL_TREE;
6499 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6500 return sel;
6501 while (true)
6502 {
6503 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6504 return list;
6505 list = chainon (list, build_tree_list (sel, NULL_TREE));
6506 sel = c_parser_objc_selector (parser);
6507 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6508 break;
6509 }
6510 return list;
6511 }
6512
6513 /* Parse an objc-receiver.
6514
6515 objc-receiver:
6516 expression
6517 class-name
6518 type-name
6519 */
6520
6521 static tree
6522 c_parser_objc_receiver (c_parser *parser)
6523 {
6524 if (c_parser_peek_token (parser)->type == CPP_NAME
6525 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
6526 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
6527 {
6528 tree id = c_parser_peek_token (parser)->value;
6529 c_parser_consume_token (parser);
6530 return objc_get_class_reference (id);
6531 }
6532 return c_parser_expression (parser).value;
6533 }
6534
6535 /* Parse objc-message-args.
6536
6537 objc-message-args:
6538 objc-selector
6539 objc-keywordarg-list
6540
6541 objc-keywordarg-list:
6542 objc-keywordarg
6543 objc-keywordarg-list objc-keywordarg
6544
6545 objc-keywordarg:
6546 objc-selector : objc-keywordexpr
6547 : objc-keywordexpr
6548 */
6549
6550 static tree
6551 c_parser_objc_message_args (c_parser *parser)
6552 {
6553 tree sel = c_parser_objc_selector (parser);
6554 tree list = NULL_TREE;
6555 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6556 return sel;
6557 while (true)
6558 {
6559 tree keywordexpr;
6560 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6561 return list;
6562 keywordexpr = c_parser_objc_keywordexpr (parser);
6563 list = chainon (list, build_tree_list (sel, keywordexpr));
6564 sel = c_parser_objc_selector (parser);
6565 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6566 break;
6567 }
6568 return list;
6569 }
6570
6571 /* Parse an objc-keywordexpr.
6572
6573 objc-keywordexpr:
6574 nonempty-expr-list
6575 */
6576
6577 static tree
6578 c_parser_objc_keywordexpr (c_parser *parser)
6579 {
6580 tree list = c_parser_expr_list (parser, true);
6581 if (TREE_CHAIN (list) == NULL_TREE)
6582 {
6583 /* Just return the expression, remove a level of
6584 indirection. */
6585 return TREE_VALUE (list);
6586 }
6587 else
6588 {
6589 /* We have a comma expression, we will collapse later. */
6590 return list;
6591 }
6592 }
6593
6594 \f
6595 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6596 should be considered, statements. ALLOW_STMT is true if we're within
6597 the context of a function and such pragmas are to be allowed. Returns
6598 true if we actually parsed such a pragma. */
6599
6600 static bool
6601 c_parser_pragma (c_parser *parser, enum pragma_context context)
6602 {
6603 unsigned int id;
6604
6605 id = c_parser_peek_token (parser)->pragma_kind;
6606 gcc_assert (id != PRAGMA_NONE);
6607
6608 switch (id)
6609 {
6610 case PRAGMA_OMP_BARRIER:
6611 if (context != pragma_compound)
6612 {
6613 if (context == pragma_stmt)
6614 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
6615 "used in compound statements");
6616 goto bad_stmt;
6617 }
6618 c_parser_omp_barrier (parser);
6619 return false;
6620
6621 case PRAGMA_OMP_FLUSH:
6622 if (context != pragma_compound)
6623 {
6624 if (context == pragma_stmt)
6625 c_parser_error (parser, "%<#pragma omp flush%> may only be "
6626 "used in compound statements");
6627 goto bad_stmt;
6628 }
6629 c_parser_omp_flush (parser);
6630 return false;
6631
6632 case PRAGMA_OMP_TASKWAIT:
6633 if (context != pragma_compound)
6634 {
6635 if (context == pragma_stmt)
6636 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
6637 "used in compound statements");
6638 goto bad_stmt;
6639 }
6640 c_parser_omp_taskwait (parser);
6641 return false;
6642
6643 case PRAGMA_OMP_THREADPRIVATE:
6644 c_parser_omp_threadprivate (parser);
6645 return false;
6646
6647 case PRAGMA_OMP_SECTION:
6648 error_at (c_parser_peek_token (parser)->location,
6649 "%<#pragma omp section%> may only be used in "
6650 "%<#pragma omp sections%> construct");
6651 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6652 return false;
6653
6654 case PRAGMA_GCC_PCH_PREPROCESS:
6655 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
6656 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6657 return false;
6658
6659 default:
6660 if (id < PRAGMA_FIRST_EXTERNAL)
6661 {
6662 if (context == pragma_external)
6663 {
6664 bad_stmt:
6665 c_parser_error (parser, "expected declaration specifiers");
6666 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6667 return false;
6668 }
6669 c_parser_omp_construct (parser);
6670 return true;
6671 }
6672 break;
6673 }
6674
6675 c_parser_consume_pragma (parser);
6676 c_invoke_pragma_handler (id);
6677
6678 /* Skip to EOL, but suppress any error message. Those will have been
6679 generated by the handler routine through calling error, as opposed
6680 to calling c_parser_error. */
6681 parser->error = true;
6682 c_parser_skip_to_pragma_eol (parser);
6683
6684 return false;
6685 }
6686
6687 /* The interface the pragma parsers have to the lexer. */
6688
6689 enum cpp_ttype
6690 pragma_lex (tree *value)
6691 {
6692 c_token *tok = c_parser_peek_token (the_parser);
6693 enum cpp_ttype ret = tok->type;
6694
6695 *value = tok->value;
6696 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
6697 ret = CPP_EOF;
6698 else
6699 {
6700 if (ret == CPP_KEYWORD)
6701 ret = CPP_NAME;
6702 c_parser_consume_token (the_parser);
6703 }
6704
6705 return ret;
6706 }
6707
6708 static void
6709 c_parser_pragma_pch_preprocess (c_parser *parser)
6710 {
6711 tree name = NULL;
6712
6713 c_parser_consume_pragma (parser);
6714 if (c_parser_next_token_is (parser, CPP_STRING))
6715 {
6716 name = c_parser_peek_token (parser)->value;
6717 c_parser_consume_token (parser);
6718 }
6719 else
6720 c_parser_error (parser, "expected string literal");
6721 c_parser_skip_to_pragma_eol (parser);
6722
6723 if (name)
6724 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
6725 }
6726 \f
6727 /* OpenMP 2.5 parsing routines. */
6728
6729 /* Returns name of the next clause.
6730 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6731 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6732 returned and the token is consumed. */
6733
6734 static pragma_omp_clause
6735 c_parser_omp_clause_name (c_parser *parser)
6736 {
6737 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
6738
6739 if (c_parser_next_token_is_keyword (parser, RID_IF))
6740 result = PRAGMA_OMP_CLAUSE_IF;
6741 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
6742 result = PRAGMA_OMP_CLAUSE_DEFAULT;
6743 else if (c_parser_next_token_is (parser, CPP_NAME))
6744 {
6745 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6746
6747 switch (p[0])
6748 {
6749 case 'c':
6750 if (!strcmp ("collapse", p))
6751 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
6752 else if (!strcmp ("copyin", p))
6753 result = PRAGMA_OMP_CLAUSE_COPYIN;
6754 else if (!strcmp ("copyprivate", p))
6755 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
6756 break;
6757 case 'f':
6758 if (!strcmp ("firstprivate", p))
6759 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
6760 break;
6761 case 'l':
6762 if (!strcmp ("lastprivate", p))
6763 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
6764 break;
6765 case 'n':
6766 if (!strcmp ("nowait", p))
6767 result = PRAGMA_OMP_CLAUSE_NOWAIT;
6768 else if (!strcmp ("num_threads", p))
6769 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
6770 break;
6771 case 'o':
6772 if (!strcmp ("ordered", p))
6773 result = PRAGMA_OMP_CLAUSE_ORDERED;
6774 break;
6775 case 'p':
6776 if (!strcmp ("private", p))
6777 result = PRAGMA_OMP_CLAUSE_PRIVATE;
6778 break;
6779 case 'r':
6780 if (!strcmp ("reduction", p))
6781 result = PRAGMA_OMP_CLAUSE_REDUCTION;
6782 break;
6783 case 's':
6784 if (!strcmp ("schedule", p))
6785 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
6786 else if (!strcmp ("shared", p))
6787 result = PRAGMA_OMP_CLAUSE_SHARED;
6788 break;
6789 case 'u':
6790 if (!strcmp ("untied", p))
6791 result = PRAGMA_OMP_CLAUSE_UNTIED;
6792 break;
6793 }
6794 }
6795
6796 if (result != PRAGMA_OMP_CLAUSE_NONE)
6797 c_parser_consume_token (parser);
6798
6799 return result;
6800 }
6801
6802 /* Validate that a clause of the given type does not already exist. */
6803
6804 static void
6805 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
6806 const char *name)
6807 {
6808 tree c;
6809
6810 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
6811 if (OMP_CLAUSE_CODE (c) == code)
6812 {
6813 error ("too many %qs clauses", name);
6814 break;
6815 }
6816 }
6817
6818 /* OpenMP 2.5:
6819 variable-list:
6820 identifier
6821 variable-list , identifier
6822
6823 If KIND is nonzero, create the appropriate node and install the decl
6824 in OMP_CLAUSE_DECL and add the node to the head of the list.
6825
6826 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6827 return the list created. */
6828
6829 static tree
6830 c_parser_omp_variable_list (c_parser *parser, enum omp_clause_code kind,
6831 tree list)
6832 {
6833 if (c_parser_next_token_is_not (parser, CPP_NAME)
6834 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
6835 c_parser_error (parser, "expected identifier");
6836
6837 while (c_parser_next_token_is (parser, CPP_NAME)
6838 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
6839 {
6840 tree t = lookup_name (c_parser_peek_token (parser)->value);
6841
6842 if (t == NULL_TREE)
6843 undeclared_variable (c_parser_peek_token (parser)->value,
6844 c_parser_peek_token (parser)->location);
6845 else if (t == error_mark_node)
6846 ;
6847 else if (kind != 0)
6848 {
6849 tree u = build_omp_clause (kind);
6850 OMP_CLAUSE_DECL (u) = t;
6851 OMP_CLAUSE_CHAIN (u) = list;
6852 list = u;
6853 }
6854 else
6855 list = tree_cons (t, NULL_TREE, list);
6856
6857 c_parser_consume_token (parser);
6858
6859 if (c_parser_next_token_is_not (parser, CPP_COMMA))
6860 break;
6861
6862 c_parser_consume_token (parser);
6863 }
6864
6865 return list;
6866 }
6867
6868 /* Similarly, but expect leading and trailing parenthesis. This is a very
6869 common case for omp clauses. */
6870
6871 static tree
6872 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
6873 tree list)
6874 {
6875 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6876 {
6877 list = c_parser_omp_variable_list (parser, kind, list);
6878 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6879 }
6880 return list;
6881 }
6882
6883 /* OpenMP 3.0:
6884 collapse ( constant-expression ) */
6885
6886 static tree
6887 c_parser_omp_clause_collapse (c_parser *parser, tree list)
6888 {
6889 tree c, num = error_mark_node;
6890 HOST_WIDE_INT n;
6891 location_t loc;
6892
6893 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
6894
6895 loc = c_parser_peek_token (parser)->location;
6896 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6897 {
6898 num = c_parser_expr_no_commas (parser, NULL).value;
6899 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6900 }
6901 if (num == error_mark_node)
6902 return list;
6903 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
6904 || !host_integerp (num, 0)
6905 || (n = tree_low_cst (num, 0)) <= 0
6906 || (int) n != n)
6907 {
6908 error_at (loc,
6909 "collapse argument needs positive constant integer expression");
6910 return list;
6911 }
6912 c = build_omp_clause (OMP_CLAUSE_COLLAPSE);
6913 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
6914 OMP_CLAUSE_CHAIN (c) = list;
6915 return c;
6916 }
6917
6918 /* OpenMP 2.5:
6919 copyin ( variable-list ) */
6920
6921 static tree
6922 c_parser_omp_clause_copyin (c_parser *parser, tree list)
6923 {
6924 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
6925 }
6926
6927 /* OpenMP 2.5:
6928 copyprivate ( variable-list ) */
6929
6930 static tree
6931 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
6932 {
6933 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
6934 }
6935
6936 /* OpenMP 2.5:
6937 default ( shared | none ) */
6938
6939 static tree
6940 c_parser_omp_clause_default (c_parser *parser, tree list)
6941 {
6942 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
6943 tree c;
6944
6945 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6946 return list;
6947 if (c_parser_next_token_is (parser, CPP_NAME))
6948 {
6949 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6950
6951 switch (p[0])
6952 {
6953 case 'n':
6954 if (strcmp ("none", p) != 0)
6955 goto invalid_kind;
6956 kind = OMP_CLAUSE_DEFAULT_NONE;
6957 break;
6958
6959 case 's':
6960 if (strcmp ("shared", p) != 0)
6961 goto invalid_kind;
6962 kind = OMP_CLAUSE_DEFAULT_SHARED;
6963 break;
6964
6965 default:
6966 goto invalid_kind;
6967 }
6968
6969 c_parser_consume_token (parser);
6970 }
6971 else
6972 {
6973 invalid_kind:
6974 c_parser_error (parser, "expected %<none%> or %<shared%>");
6975 }
6976 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6977
6978 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
6979 return list;
6980
6981 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
6982 c = build_omp_clause (OMP_CLAUSE_DEFAULT);
6983 OMP_CLAUSE_CHAIN (c) = list;
6984 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
6985
6986 return c;
6987 }
6988
6989 /* OpenMP 2.5:
6990 firstprivate ( variable-list ) */
6991
6992 static tree
6993 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
6994 {
6995 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
6996 }
6997
6998 /* OpenMP 2.5:
6999 if ( expression ) */
7000
7001 static tree
7002 c_parser_omp_clause_if (c_parser *parser, tree list)
7003 {
7004 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7005 {
7006 tree t = c_parser_paren_condition (parser);
7007 tree c;
7008
7009 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
7010
7011 c = build_omp_clause (OMP_CLAUSE_IF);
7012 OMP_CLAUSE_IF_EXPR (c) = t;
7013 OMP_CLAUSE_CHAIN (c) = list;
7014 list = c;
7015 }
7016 else
7017 c_parser_error (parser, "expected %<(%>");
7018
7019 return list;
7020 }
7021
7022 /* OpenMP 2.5:
7023 lastprivate ( variable-list ) */
7024
7025 static tree
7026 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
7027 {
7028 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
7029 }
7030
7031 /* OpenMP 2.5:
7032 nowait */
7033
7034 static tree
7035 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7036 {
7037 tree c;
7038
7039 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
7040
7041 c = build_omp_clause (OMP_CLAUSE_NOWAIT);
7042 OMP_CLAUSE_CHAIN (c) = list;
7043 return c;
7044 }
7045
7046 /* OpenMP 2.5:
7047 num_threads ( expression ) */
7048
7049 static tree
7050 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
7051 {
7052 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7053 {
7054 location_t expr_loc = c_parser_peek_token (parser)->location;
7055 tree c, t = c_parser_expression (parser).value;
7056
7057 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7058
7059 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
7060 {
7061 c_parser_error (parser, "expected integer expression");
7062 return list;
7063 }
7064
7065 /* Attempt to statically determine when the number isn't positive. */
7066 c = fold_build2 (LE_EXPR, boolean_type_node, t,
7067 build_int_cst (TREE_TYPE (t), 0));
7068 if (c == boolean_true_node)
7069 {
7070 warning_at (expr_loc, 0,
7071 "%<num_threads%> value must be positive");
7072 t = integer_one_node;
7073 }
7074
7075 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
7076
7077 c = build_omp_clause (OMP_CLAUSE_NUM_THREADS);
7078 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
7079 OMP_CLAUSE_CHAIN (c) = list;
7080 list = c;
7081 }
7082
7083 return list;
7084 }
7085
7086 /* OpenMP 2.5:
7087 ordered */
7088
7089 static tree
7090 c_parser_omp_clause_ordered (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7091 {
7092 tree c;
7093
7094 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
7095
7096 c = build_omp_clause (OMP_CLAUSE_ORDERED);
7097 OMP_CLAUSE_CHAIN (c) = list;
7098 return c;
7099 }
7100
7101 /* OpenMP 2.5:
7102 private ( variable-list ) */
7103
7104 static tree
7105 c_parser_omp_clause_private (c_parser *parser, tree list)
7106 {
7107 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
7108 }
7109
7110 /* OpenMP 2.5:
7111 reduction ( reduction-operator : variable-list )
7112
7113 reduction-operator:
7114 One of: + * - & ^ | && || */
7115
7116 static tree
7117 c_parser_omp_clause_reduction (c_parser *parser, tree list)
7118 {
7119 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7120 {
7121 enum tree_code code;
7122
7123 switch (c_parser_peek_token (parser)->type)
7124 {
7125 case CPP_PLUS:
7126 code = PLUS_EXPR;
7127 break;
7128 case CPP_MULT:
7129 code = MULT_EXPR;
7130 break;
7131 case CPP_MINUS:
7132 code = MINUS_EXPR;
7133 break;
7134 case CPP_AND:
7135 code = BIT_AND_EXPR;
7136 break;
7137 case CPP_XOR:
7138 code = BIT_XOR_EXPR;
7139 break;
7140 case CPP_OR:
7141 code = BIT_IOR_EXPR;
7142 break;
7143 case CPP_AND_AND:
7144 code = TRUTH_ANDIF_EXPR;
7145 break;
7146 case CPP_OR_OR:
7147 code = TRUTH_ORIF_EXPR;
7148 break;
7149 default:
7150 c_parser_error (parser,
7151 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7152 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7153 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7154 return list;
7155 }
7156 c_parser_consume_token (parser);
7157 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7158 {
7159 tree nl, c;
7160
7161 nl = c_parser_omp_variable_list (parser, OMP_CLAUSE_REDUCTION, list);
7162 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
7163 OMP_CLAUSE_REDUCTION_CODE (c) = code;
7164
7165 list = nl;
7166 }
7167 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7168 }
7169 return list;
7170 }
7171
7172 /* OpenMP 2.5:
7173 schedule ( schedule-kind )
7174 schedule ( schedule-kind , expression )
7175
7176 schedule-kind:
7177 static | dynamic | guided | runtime | auto
7178 */
7179
7180 static tree
7181 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7182 {
7183 tree c, t;
7184
7185 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7186 return list;
7187
7188 c = build_omp_clause (OMP_CLAUSE_SCHEDULE);
7189
7190 if (c_parser_next_token_is (parser, CPP_NAME))
7191 {
7192 tree kind = c_parser_peek_token (parser)->value;
7193 const char *p = IDENTIFIER_POINTER (kind);
7194
7195 switch (p[0])
7196 {
7197 case 'd':
7198 if (strcmp ("dynamic", p) != 0)
7199 goto invalid_kind;
7200 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7201 break;
7202
7203 case 'g':
7204 if (strcmp ("guided", p) != 0)
7205 goto invalid_kind;
7206 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7207 break;
7208
7209 case 'r':
7210 if (strcmp ("runtime", p) != 0)
7211 goto invalid_kind;
7212 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7213 break;
7214
7215 default:
7216 goto invalid_kind;
7217 }
7218 }
7219 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7220 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7221 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
7222 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
7223 else
7224 goto invalid_kind;
7225
7226 c_parser_consume_token (parser);
7227 if (c_parser_next_token_is (parser, CPP_COMMA))
7228 {
7229 location_t here;
7230 c_parser_consume_token (parser);
7231
7232 here = c_parser_peek_token (parser)->location;
7233 t = c_parser_expr_no_commas (parser, NULL).value;
7234
7235 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7236 error_at (here, "schedule %<runtime%> does not take "
7237 "a %<chunk_size%> parameter");
7238 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
7239 error_at (here,
7240 "schedule %<auto%> does not take "
7241 "a %<chunk_size%> parameter");
7242 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7243 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7244 else
7245 c_parser_error (parser, "expected integer expression");
7246
7247 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7248 }
7249 else
7250 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7251 "expected %<,%> or %<)%>");
7252
7253 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7254 OMP_CLAUSE_CHAIN (c) = list;
7255 return c;
7256
7257 invalid_kind:
7258 c_parser_error (parser, "invalid schedule kind");
7259 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7260 return list;
7261 }
7262
7263 /* OpenMP 2.5:
7264 shared ( variable-list ) */
7265
7266 static tree
7267 c_parser_omp_clause_shared (c_parser *parser, tree list)
7268 {
7269 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7270 }
7271
7272 /* OpenMP 3.0:
7273 untied */
7274
7275 static tree
7276 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7277 {
7278 tree c;
7279
7280 /* FIXME: Should we allow duplicates? */
7281 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
7282
7283 c = build_omp_clause (OMP_CLAUSE_UNTIED);
7284 OMP_CLAUSE_CHAIN (c) = list;
7285 return c;
7286 }
7287
7288 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7289 is a bitmask in MASK. Return the list of clauses found; the result
7290 of clause default goes in *pdefault. */
7291
7292 static tree
7293 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7294 const char *where)
7295 {
7296 tree clauses = NULL;
7297 bool first = true;
7298
7299 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7300 {
7301 location_t here;
7302 pragma_omp_clause c_kind;
7303 const char *c_name;
7304 tree prev = clauses;
7305
7306 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
7307 c_parser_consume_token (parser);
7308
7309 first = false;
7310 here = c_parser_peek_token (parser)->location;
7311 c_kind = c_parser_omp_clause_name (parser);
7312
7313 switch (c_kind)
7314 {
7315 case PRAGMA_OMP_CLAUSE_COLLAPSE:
7316 clauses = c_parser_omp_clause_collapse (parser, clauses);
7317 c_name = "collapse";
7318 break;
7319 case PRAGMA_OMP_CLAUSE_COPYIN:
7320 clauses = c_parser_omp_clause_copyin (parser, clauses);
7321 c_name = "copyin";
7322 break;
7323 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7324 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7325 c_name = "copyprivate";
7326 break;
7327 case PRAGMA_OMP_CLAUSE_DEFAULT:
7328 clauses = c_parser_omp_clause_default (parser, clauses);
7329 c_name = "default";
7330 break;
7331 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7332 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7333 c_name = "firstprivate";
7334 break;
7335 case PRAGMA_OMP_CLAUSE_IF:
7336 clauses = c_parser_omp_clause_if (parser, clauses);
7337 c_name = "if";
7338 break;
7339 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7340 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7341 c_name = "lastprivate";
7342 break;
7343 case PRAGMA_OMP_CLAUSE_NOWAIT:
7344 clauses = c_parser_omp_clause_nowait (parser, clauses);
7345 c_name = "nowait";
7346 break;
7347 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7348 clauses = c_parser_omp_clause_num_threads (parser, clauses);
7349 c_name = "num_threads";
7350 break;
7351 case PRAGMA_OMP_CLAUSE_ORDERED:
7352 clauses = c_parser_omp_clause_ordered (parser, clauses);
7353 c_name = "ordered";
7354 break;
7355 case PRAGMA_OMP_CLAUSE_PRIVATE:
7356 clauses = c_parser_omp_clause_private (parser, clauses);
7357 c_name = "private";
7358 break;
7359 case PRAGMA_OMP_CLAUSE_REDUCTION:
7360 clauses = c_parser_omp_clause_reduction (parser, clauses);
7361 c_name = "reduction";
7362 break;
7363 case PRAGMA_OMP_CLAUSE_SCHEDULE:
7364 clauses = c_parser_omp_clause_schedule (parser, clauses);
7365 c_name = "schedule";
7366 break;
7367 case PRAGMA_OMP_CLAUSE_SHARED:
7368 clauses = c_parser_omp_clause_shared (parser, clauses);
7369 c_name = "shared";
7370 break;
7371 case PRAGMA_OMP_CLAUSE_UNTIED:
7372 clauses = c_parser_omp_clause_untied (parser, clauses);
7373 c_name = "untied";
7374 break;
7375 default:
7376 c_parser_error (parser, "expected %<#pragma omp%> clause");
7377 goto saw_error;
7378 }
7379
7380 if (((mask >> c_kind) & 1) == 0 && !parser->error)
7381 {
7382 /* Remove the invalid clause(s) from the list to avoid
7383 confusing the rest of the compiler. */
7384 clauses = prev;
7385 error_at (here, "%qs is not valid for %qs", c_name, where);
7386 }
7387 }
7388
7389 saw_error:
7390 c_parser_skip_to_pragma_eol (parser);
7391
7392 return c_finish_omp_clauses (clauses);
7393 }
7394
7395 /* OpenMP 2.5:
7396 structured-block:
7397 statement
7398
7399 In practice, we're also interested in adding the statement to an
7400 outer node. So it is convenient if we work around the fact that
7401 c_parser_statement calls add_stmt. */
7402
7403 static tree
7404 c_parser_omp_structured_block (c_parser *parser)
7405 {
7406 tree stmt = push_stmt_list ();
7407 c_parser_statement (parser);
7408 return pop_stmt_list (stmt);
7409 }
7410
7411 /* OpenMP 2.5:
7412 # pragma omp atomic new-line
7413 expression-stmt
7414
7415 expression-stmt:
7416 x binop= expr | x++ | ++x | x-- | --x
7417 binop:
7418 +, *, -, /, &, ^, |, <<, >>
7419
7420 where x is an lvalue expression with scalar type. */
7421
7422 static void
7423 c_parser_omp_atomic (c_parser *parser)
7424 {
7425 tree lhs, rhs;
7426 tree stmt;
7427 enum tree_code code;
7428 struct c_expr rhs_expr;
7429
7430 c_parser_skip_to_pragma_eol (parser);
7431
7432 lhs = c_parser_unary_expression (parser).value;
7433 switch (TREE_CODE (lhs))
7434 {
7435 case ERROR_MARK:
7436 saw_error:
7437 c_parser_skip_to_end_of_block_or_statement (parser);
7438 return;
7439
7440 case PREINCREMENT_EXPR:
7441 case POSTINCREMENT_EXPR:
7442 lhs = TREE_OPERAND (lhs, 0);
7443 code = PLUS_EXPR;
7444 rhs = integer_one_node;
7445 break;
7446
7447 case PREDECREMENT_EXPR:
7448 case POSTDECREMENT_EXPR:
7449 lhs = TREE_OPERAND (lhs, 0);
7450 code = MINUS_EXPR;
7451 rhs = integer_one_node;
7452 break;
7453
7454 default:
7455 switch (c_parser_peek_token (parser)->type)
7456 {
7457 case CPP_MULT_EQ:
7458 code = MULT_EXPR;
7459 break;
7460 case CPP_DIV_EQ:
7461 code = TRUNC_DIV_EXPR;
7462 break;
7463 case CPP_PLUS_EQ:
7464 code = PLUS_EXPR;
7465 break;
7466 case CPP_MINUS_EQ:
7467 code = MINUS_EXPR;
7468 break;
7469 case CPP_LSHIFT_EQ:
7470 code = LSHIFT_EXPR;
7471 break;
7472 case CPP_RSHIFT_EQ:
7473 code = RSHIFT_EXPR;
7474 break;
7475 case CPP_AND_EQ:
7476 code = BIT_AND_EXPR;
7477 break;
7478 case CPP_OR_EQ:
7479 code = BIT_IOR_EXPR;
7480 break;
7481 case CPP_XOR_EQ:
7482 code = BIT_XOR_EXPR;
7483 break;
7484 default:
7485 c_parser_error (parser,
7486 "invalid operator for %<#pragma omp atomic%>");
7487 goto saw_error;
7488 }
7489
7490 c_parser_consume_token (parser);
7491 rhs_expr = c_parser_expression (parser);
7492 rhs_expr = default_function_array_conversion (rhs_expr);
7493 rhs = rhs_expr.value;
7494 break;
7495 }
7496 stmt = c_finish_omp_atomic (code, lhs, rhs);
7497 if (stmt != error_mark_node)
7498 add_stmt (stmt);
7499 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7500 }
7501
7502
7503 /* OpenMP 2.5:
7504 # pragma omp barrier new-line
7505 */
7506
7507 static void
7508 c_parser_omp_barrier (c_parser *parser)
7509 {
7510 c_parser_consume_pragma (parser);
7511 c_parser_skip_to_pragma_eol (parser);
7512
7513 c_finish_omp_barrier ();
7514 }
7515
7516 /* OpenMP 2.5:
7517 # pragma omp critical [(name)] new-line
7518 structured-block
7519 */
7520
7521 static tree
7522 c_parser_omp_critical (c_parser *parser)
7523 {
7524 tree stmt, name = NULL;
7525
7526 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7527 {
7528 c_parser_consume_token (parser);
7529 if (c_parser_next_token_is (parser, CPP_NAME))
7530 {
7531 name = c_parser_peek_token (parser)->value;
7532 c_parser_consume_token (parser);
7533 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7534 }
7535 else
7536 c_parser_error (parser, "expected identifier");
7537 }
7538 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7539 c_parser_error (parser, "expected %<(%> or end of line");
7540 c_parser_skip_to_pragma_eol (parser);
7541
7542 stmt = c_parser_omp_structured_block (parser);
7543 return c_finish_omp_critical (stmt, name);
7544 }
7545
7546 /* OpenMP 2.5:
7547 # pragma omp flush flush-vars[opt] new-line
7548
7549 flush-vars:
7550 ( variable-list ) */
7551
7552 static void
7553 c_parser_omp_flush (c_parser *parser)
7554 {
7555 c_parser_consume_pragma (parser);
7556 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7557 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
7558 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7559 c_parser_error (parser, "expected %<(%> or end of line");
7560 c_parser_skip_to_pragma_eol (parser);
7561
7562 c_finish_omp_flush ();
7563 }
7564
7565 /* Parse the restricted form of the for statement allowed by OpenMP.
7566 The real trick here is to determine the loop control variable early
7567 so that we can push a new decl if necessary to make it private. */
7568
7569 static tree
7570 c_parser_omp_for_loop (c_parser *parser, tree clauses, tree *par_clauses)
7571 {
7572 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
7573 tree declv, condv, incrv, initv, for_block = NULL, ret = NULL;
7574 location_t loc;
7575 bool fail = false, open_brace_parsed = false;
7576 int i, collapse = 1, nbraces = 0;
7577
7578 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
7579 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
7580 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
7581
7582 gcc_assert (collapse >= 1);
7583
7584 declv = make_tree_vec (collapse);
7585 initv = make_tree_vec (collapse);
7586 condv = make_tree_vec (collapse);
7587 incrv = make_tree_vec (collapse);
7588
7589 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
7590 {
7591 c_parser_error (parser, "for statement expected");
7592 return NULL;
7593 }
7594 loc = c_parser_peek_token (parser)->location;
7595 c_parser_consume_token (parser);
7596
7597 for (i = 0; i < collapse; i++)
7598 {
7599 int bracecount = 0;
7600
7601 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7602 goto pop_scopes;
7603
7604 /* Parse the initialization declaration or expression. */
7605 if (c_parser_next_token_starts_declspecs (parser))
7606 {
7607 if (i > 0)
7608 for_block
7609 = tree_cons (NULL, c_begin_compound_stmt (true), for_block);
7610 c_parser_declaration_or_fndef (parser, true, true, true, true);
7611 decl = check_for_loop_decls ();
7612 if (decl == NULL)
7613 goto error_init;
7614 if (DECL_INITIAL (decl) == error_mark_node)
7615 decl = error_mark_node;
7616 init = decl;
7617 }
7618 else if (c_parser_next_token_is (parser, CPP_NAME)
7619 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
7620 {
7621 struct c_expr init_exp;
7622 location_t init_loc;
7623
7624 decl = c_parser_postfix_expression (parser).value;
7625
7626 c_parser_require (parser, CPP_EQ, "expected %<=%>");
7627 init_loc = c_parser_peek_token (parser)->location;
7628
7629 init_exp = c_parser_expr_no_commas (parser, NULL);
7630 init_exp = default_function_array_conversion (init_exp);
7631 init = build_modify_expr (init_loc,
7632 decl, NOP_EXPR, init_exp.value);
7633 init = c_process_expr_stmt (init);
7634
7635 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7636 }
7637 else
7638 {
7639 error_init:
7640 c_parser_error (parser,
7641 "expected iteration declaration or initialization");
7642 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7643 "expected %<)%>");
7644 fail = true;
7645 goto parse_next;
7646 }
7647
7648 /* Parse the loop condition. */
7649 cond = NULL_TREE;
7650 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
7651 {
7652 location_t cond_loc = c_parser_peek_token (parser)->location;
7653
7654 cond = c_parser_expression_conv (parser).value;
7655 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
7656 protected_set_expr_location (cond, cond_loc);
7657 }
7658 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7659
7660 /* Parse the increment expression. */
7661 incr = NULL_TREE;
7662 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
7663 {
7664 location_t incr_loc = c_parser_peek_token (parser)->location;
7665
7666 incr = c_process_expr_stmt (c_parser_expression (parser).value);
7667 protected_set_expr_location (incr, incr_loc);
7668 }
7669 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7670
7671 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
7672 fail = true;
7673 else
7674 {
7675 TREE_VEC_ELT (declv, i) = decl;
7676 TREE_VEC_ELT (initv, i) = init;
7677 TREE_VEC_ELT (condv, i) = cond;
7678 TREE_VEC_ELT (incrv, i) = incr;
7679 }
7680
7681 parse_next:
7682 if (i == collapse - 1)
7683 break;
7684
7685 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
7686 in between the collapsed for loops to be still considered perfectly
7687 nested. Hopefully the final version clarifies this.
7688 For now handle (multiple) {'s and empty statements. */
7689 do
7690 {
7691 if (c_parser_next_token_is_keyword (parser, RID_FOR))
7692 {
7693 c_parser_consume_token (parser);
7694 break;
7695 }
7696 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7697 {
7698 c_parser_consume_token (parser);
7699 bracecount++;
7700 }
7701 else if (bracecount
7702 && c_parser_next_token_is (parser, CPP_SEMICOLON))
7703 c_parser_consume_token (parser);
7704 else
7705 {
7706 c_parser_error (parser, "not enough perfectly nested loops");
7707 if (bracecount)
7708 {
7709 open_brace_parsed = true;
7710 bracecount--;
7711 }
7712 fail = true;
7713 collapse = 0;
7714 break;
7715 }
7716 }
7717 while (1);
7718
7719 nbraces += bracecount;
7720 }
7721
7722 save_break = c_break_label;
7723 c_break_label = size_one_node;
7724 save_cont = c_cont_label;
7725 c_cont_label = NULL_TREE;
7726 body = push_stmt_list ();
7727
7728 if (open_brace_parsed)
7729 {
7730 stmt = c_begin_compound_stmt (true);
7731 c_parser_compound_statement_nostart (parser);
7732 add_stmt (c_end_compound_stmt (stmt, true));
7733 }
7734 else
7735 add_stmt (c_parser_c99_block_statement (parser));
7736 if (c_cont_label)
7737 add_stmt (build1 (LABEL_EXPR, void_type_node, c_cont_label));
7738
7739 body = pop_stmt_list (body);
7740 c_break_label = save_break;
7741 c_cont_label = save_cont;
7742
7743 while (nbraces)
7744 {
7745 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7746 {
7747 c_parser_consume_token (parser);
7748 nbraces--;
7749 }
7750 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
7751 c_parser_consume_token (parser);
7752 else
7753 {
7754 c_parser_error (parser, "collapsed loops not perfectly nested");
7755 while (nbraces)
7756 {
7757 stmt = c_begin_compound_stmt (true);
7758 add_stmt (body);
7759 c_parser_compound_statement_nostart (parser);
7760 body = c_end_compound_stmt (stmt, true);
7761 nbraces--;
7762 }
7763 goto pop_scopes;
7764 }
7765 }
7766
7767 /* Only bother calling c_finish_omp_for if we haven't already generated
7768 an error from the initialization parsing. */
7769 if (!fail)
7770 {
7771 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
7772 if (stmt)
7773 {
7774 if (par_clauses != NULL)
7775 {
7776 tree *c;
7777 for (c = par_clauses; *c ; )
7778 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
7779 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
7780 c = &OMP_CLAUSE_CHAIN (*c);
7781 else
7782 {
7783 for (i = 0; i < collapse; i++)
7784 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
7785 break;
7786 if (i == collapse)
7787 c = &OMP_CLAUSE_CHAIN (*c);
7788 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
7789 {
7790 error_at (loc,
7791 "iteration variable %qD should not be firstprivate",
7792 OMP_CLAUSE_DECL (*c));
7793 *c = OMP_CLAUSE_CHAIN (*c);
7794 }
7795 else
7796 {
7797 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
7798 change it to shared (decl) in
7799 OMP_PARALLEL_CLAUSES. */
7800 tree l = build_omp_clause (OMP_CLAUSE_LASTPRIVATE);
7801 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
7802 OMP_CLAUSE_CHAIN (l) = clauses;
7803 clauses = l;
7804 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
7805 }
7806 }
7807 }
7808 OMP_FOR_CLAUSES (stmt) = clauses;
7809 }
7810 ret = stmt;
7811 }
7812 pop_scopes:
7813 while (for_block)
7814 {
7815 stmt = c_end_compound_stmt (TREE_VALUE (for_block), true);
7816 add_stmt (stmt);
7817 for_block = TREE_CHAIN (for_block);
7818 }
7819 return ret;
7820 }
7821
7822 /* OpenMP 2.5:
7823 #pragma omp for for-clause[optseq] new-line
7824 for-loop
7825 */
7826
7827 #define OMP_FOR_CLAUSE_MASK \
7828 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7829 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7830 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7831 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7832 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7833 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7834 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
7835 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7836
7837 static tree
7838 c_parser_omp_for (c_parser *parser)
7839 {
7840 tree block, clauses, ret;
7841
7842 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
7843 "#pragma omp for");
7844
7845 block = c_begin_compound_stmt (true);
7846 ret = c_parser_omp_for_loop (parser, clauses, NULL);
7847 block = c_end_compound_stmt (block, true);
7848 add_stmt (block);
7849
7850 return ret;
7851 }
7852
7853 /* OpenMP 2.5:
7854 # pragma omp master new-line
7855 structured-block
7856 */
7857
7858 static tree
7859 c_parser_omp_master (c_parser *parser)
7860 {
7861 c_parser_skip_to_pragma_eol (parser);
7862 return c_finish_omp_master (c_parser_omp_structured_block (parser));
7863 }
7864
7865 /* OpenMP 2.5:
7866 # pragma omp ordered new-line
7867 structured-block
7868 */
7869
7870 static tree
7871 c_parser_omp_ordered (c_parser *parser)
7872 {
7873 c_parser_skip_to_pragma_eol (parser);
7874 return c_finish_omp_ordered (c_parser_omp_structured_block (parser));
7875 }
7876
7877 /* OpenMP 2.5:
7878
7879 section-scope:
7880 { section-sequence }
7881
7882 section-sequence:
7883 section-directive[opt] structured-block
7884 section-sequence section-directive structured-block */
7885
7886 static tree
7887 c_parser_omp_sections_scope (c_parser *parser)
7888 {
7889 tree stmt, substmt;
7890 bool error_suppress = false;
7891 location_t loc;
7892
7893 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7894 {
7895 /* Avoid skipping until the end of the block. */
7896 parser->error = false;
7897 return NULL_TREE;
7898 }
7899
7900 stmt = push_stmt_list ();
7901
7902 loc = c_parser_peek_token (parser)->location;
7903 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
7904 {
7905 substmt = push_stmt_list ();
7906
7907 while (1)
7908 {
7909 c_parser_statement (parser);
7910
7911 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7912 break;
7913 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7914 break;
7915 if (c_parser_next_token_is (parser, CPP_EOF))
7916 break;
7917 }
7918
7919 substmt = pop_stmt_list (substmt);
7920 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7921 SET_EXPR_LOCATION (substmt, loc);
7922 add_stmt (substmt);
7923 }
7924
7925 while (1)
7926 {
7927 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7928 break;
7929 if (c_parser_next_token_is (parser, CPP_EOF))
7930 break;
7931
7932 loc = c_parser_peek_token (parser)->location;
7933 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7934 {
7935 c_parser_consume_pragma (parser);
7936 c_parser_skip_to_pragma_eol (parser);
7937 error_suppress = false;
7938 }
7939 else if (!error_suppress)
7940 {
7941 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
7942 error_suppress = true;
7943 }
7944
7945 substmt = c_parser_omp_structured_block (parser);
7946 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7947 SET_EXPR_LOCATION (substmt, loc);
7948 add_stmt (substmt);
7949 }
7950 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
7951 "expected %<#pragma omp section%> or %<}%>");
7952
7953 substmt = pop_stmt_list (stmt);
7954
7955 stmt = make_node (OMP_SECTIONS);
7956 TREE_TYPE (stmt) = void_type_node;
7957 OMP_SECTIONS_BODY (stmt) = substmt;
7958
7959 return add_stmt (stmt);
7960 }
7961
7962 /* OpenMP 2.5:
7963 # pragma omp sections sections-clause[optseq] newline
7964 sections-scope
7965 */
7966
7967 #define OMP_SECTIONS_CLAUSE_MASK \
7968 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7969 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7970 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7971 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7972 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7973
7974 static tree
7975 c_parser_omp_sections (c_parser *parser)
7976 {
7977 tree block, clauses, ret;
7978
7979 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
7980 "#pragma omp sections");
7981
7982 block = c_begin_compound_stmt (true);
7983 ret = c_parser_omp_sections_scope (parser);
7984 if (ret)
7985 OMP_SECTIONS_CLAUSES (ret) = clauses;
7986 block = c_end_compound_stmt (block, true);
7987 add_stmt (block);
7988
7989 return ret;
7990 }
7991
7992 /* OpenMP 2.5:
7993 # pragma parallel parallel-clause new-line
7994 # pragma parallel for parallel-for-clause new-line
7995 # pragma parallel sections parallel-sections-clause new-line
7996 */
7997
7998 #define OMP_PARALLEL_CLAUSE_MASK \
7999 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8000 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8001 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8002 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8003 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8004 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8005 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8006 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8007
8008 static tree
8009 c_parser_omp_parallel (c_parser *parser)
8010 {
8011 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
8012 const char *p_name = "#pragma omp parallel";
8013 tree stmt, clauses, par_clause, ws_clause, block;
8014 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
8015
8016 if (c_parser_next_token_is_keyword (parser, RID_FOR))
8017 {
8018 c_parser_consume_token (parser);
8019 p_kind = PRAGMA_OMP_PARALLEL_FOR;
8020 p_name = "#pragma omp parallel for";
8021 mask |= OMP_FOR_CLAUSE_MASK;
8022 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8023 }
8024 else if (c_parser_next_token_is (parser, CPP_NAME))
8025 {
8026 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8027 if (strcmp (p, "sections") == 0)
8028 {
8029 c_parser_consume_token (parser);
8030 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
8031 p_name = "#pragma omp parallel sections";
8032 mask |= OMP_SECTIONS_CLAUSE_MASK;
8033 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8034 }
8035 }
8036
8037 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
8038
8039 switch (p_kind)
8040 {
8041 case PRAGMA_OMP_PARALLEL:
8042 block = c_begin_omp_parallel ();
8043 c_parser_statement (parser);
8044 stmt = c_finish_omp_parallel (clauses, block);
8045 break;
8046
8047 case PRAGMA_OMP_PARALLEL_FOR:
8048 block = c_begin_omp_parallel ();
8049 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
8050 c_parser_omp_for_loop (parser, ws_clause, &par_clause);
8051 stmt = c_finish_omp_parallel (par_clause, block);
8052 OMP_PARALLEL_COMBINED (stmt) = 1;
8053 break;
8054
8055 case PRAGMA_OMP_PARALLEL_SECTIONS:
8056 block = c_begin_omp_parallel ();
8057 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
8058 stmt = c_parser_omp_sections_scope (parser);
8059 if (stmt)
8060 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
8061 stmt = c_finish_omp_parallel (par_clause, block);
8062 OMP_PARALLEL_COMBINED (stmt) = 1;
8063 break;
8064
8065 default:
8066 gcc_unreachable ();
8067 }
8068
8069 return stmt;
8070 }
8071
8072 /* OpenMP 2.5:
8073 # pragma omp single single-clause[optseq] new-line
8074 structured-block
8075 */
8076
8077 #define OMP_SINGLE_CLAUSE_MASK \
8078 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8079 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8080 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8081 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8082
8083 static tree
8084 c_parser_omp_single (c_parser *parser)
8085 {
8086 tree stmt = make_node (OMP_SINGLE);
8087 TREE_TYPE (stmt) = void_type_node;
8088
8089 OMP_SINGLE_CLAUSES (stmt)
8090 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
8091 "#pragma omp single");
8092 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
8093
8094 return add_stmt (stmt);
8095 }
8096
8097 /* OpenMP 3.0:
8098 # pragma omp task task-clause[optseq] new-line
8099 */
8100
8101 #define OMP_TASK_CLAUSE_MASK \
8102 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8103 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8104 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8105 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8106 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8107 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8108
8109 static tree
8110 c_parser_omp_task (c_parser *parser)
8111 {
8112 tree clauses, block;
8113
8114 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
8115 "#pragma omp task");
8116
8117 block = c_begin_omp_task ();
8118 c_parser_statement (parser);
8119 return c_finish_omp_task (clauses, block);
8120 }
8121
8122 /* OpenMP 3.0:
8123 # pragma omp taskwait new-line
8124 */
8125
8126 static void
8127 c_parser_omp_taskwait (c_parser *parser)
8128 {
8129 c_parser_consume_pragma (parser);
8130 c_parser_skip_to_pragma_eol (parser);
8131
8132 c_finish_omp_taskwait ();
8133 }
8134
8135 /* Main entry point to parsing most OpenMP pragmas. */
8136
8137 static void
8138 c_parser_omp_construct (c_parser *parser)
8139 {
8140 enum pragma_kind p_kind;
8141 location_t loc;
8142 tree stmt;
8143
8144 loc = c_parser_peek_token (parser)->location;
8145 p_kind = c_parser_peek_token (parser)->pragma_kind;
8146 c_parser_consume_pragma (parser);
8147
8148 /* For all constructs below except #pragma omp atomic
8149 MUST_NOT_THROW catch handlers are needed when exceptions
8150 are enabled. */
8151 if (p_kind != PRAGMA_OMP_ATOMIC)
8152 c_maybe_initialize_eh ();
8153
8154 switch (p_kind)
8155 {
8156 case PRAGMA_OMP_ATOMIC:
8157 c_parser_omp_atomic (parser);
8158 return;
8159 case PRAGMA_OMP_CRITICAL:
8160 stmt = c_parser_omp_critical (parser);
8161 break;
8162 case PRAGMA_OMP_FOR:
8163 stmt = c_parser_omp_for (parser);
8164 break;
8165 case PRAGMA_OMP_MASTER:
8166 stmt = c_parser_omp_master (parser);
8167 break;
8168 case PRAGMA_OMP_ORDERED:
8169 stmt = c_parser_omp_ordered (parser);
8170 break;
8171 case PRAGMA_OMP_PARALLEL:
8172 stmt = c_parser_omp_parallel (parser);
8173 break;
8174 case PRAGMA_OMP_SECTIONS:
8175 stmt = c_parser_omp_sections (parser);
8176 break;
8177 case PRAGMA_OMP_SINGLE:
8178 stmt = c_parser_omp_single (parser);
8179 break;
8180 case PRAGMA_OMP_TASK:
8181 stmt = c_parser_omp_task (parser);
8182 break;
8183 default:
8184 gcc_unreachable ();
8185 }
8186
8187 if (stmt)
8188 SET_EXPR_LOCATION (stmt, loc);
8189 }
8190
8191
8192 /* OpenMP 2.5:
8193 # pragma omp threadprivate (variable-list) */
8194
8195 static void
8196 c_parser_omp_threadprivate (c_parser *parser)
8197 {
8198 tree vars, t;
8199
8200 c_parser_consume_pragma (parser);
8201 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
8202
8203 /* Mark every variable in VARS to be assigned thread local storage. */
8204 for (t = vars; t; t = TREE_CHAIN (t))
8205 {
8206 tree v = TREE_PURPOSE (t);
8207
8208 /* If V had already been marked threadprivate, it doesn't matter
8209 whether it had been used prior to this point. */
8210 if (TREE_CODE (v) != VAR_DECL)
8211 error ("%qD is not a variable", v);
8212 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
8213 error ("%qE declared %<threadprivate%> after first use", v);
8214 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
8215 error ("automatic variable %qE cannot be %<threadprivate%>", v);
8216 else if (TREE_TYPE (v) == error_mark_node)
8217 ;
8218 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
8219 error ("%<threadprivate%> %qE has incomplete type", v);
8220 else
8221 {
8222 if (! DECL_THREAD_LOCAL_P (v))
8223 {
8224 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
8225 /* If rtl has been already set for this var, call
8226 make_decl_rtl once again, so that encode_section_info
8227 has a chance to look at the new decl flags. */
8228 if (DECL_RTL_SET_P (v))
8229 make_decl_rtl (v);
8230 }
8231 C_DECL_THREADPRIVATE_P (v) = 1;
8232 }
8233 }
8234
8235 c_parser_skip_to_pragma_eol (parser);
8236 }
8237
8238 \f
8239 /* Parse a single source file. */
8240
8241 void
8242 c_parse_file (void)
8243 {
8244 /* Use local storage to begin. If the first token is a pragma, parse it.
8245 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8246 which will cause garbage collection. */
8247 c_parser tparser;
8248
8249 memset (&tparser, 0, sizeof tparser);
8250 the_parser = &tparser;
8251
8252 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
8253 c_parser_pragma_pch_preprocess (&tparser);
8254
8255 the_parser = GGC_NEW (c_parser);
8256 *the_parser = tparser;
8257
8258 c_parser_translation_unit (the_parser);
8259 the_parser = NULL;
8260 }
8261
8262 #include "gt-c-parser.h"