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