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