c-parser.c revision 260014
155682Smarkm/* Parser for C and Objective-C.
290929Snectar   Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
355682Smarkm   1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
455682Smarkm
555682Smarkm   Parser actions based on the old Bison parser; structure somewhat
655682Smarkm   influenced by and fragments based on the C++ parser.
755682Smarkm
855682SmarkmThis file is part of GCC.
955682Smarkm
1055682SmarkmGCC is free software; you can redistribute it and/or modify it under
1155682Smarkmthe terms of the GNU General Public License as published by the Free
1255682SmarkmSoftware Foundation; either version 2, or (at your option) any later
1355682Smarkmversion.
1455682Smarkm
1555682SmarkmGCC is distributed in the hope that it will be useful, but WITHOUT ANY
1655682SmarkmWARRANTY; without even the implied warranty of MERCHANTABILITY or
1755682SmarkmFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1855682Smarkmfor more details.
1955682Smarkm
2055682SmarkmYou should have received a copy of the GNU General Public License
2155682Smarkmalong with GCC; see the file COPYING.  If not, write to the Free
2255682SmarkmSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
2355682Smarkm02110-1301, USA.  */
2455682Smarkm
2555682Smarkm/* TODO:
2655682Smarkm
2755682Smarkm   Make sure all relevant comments, and all relevant code from all
2855682Smarkm   actions, brought over from old parser.  Verify exact correspondence
2955682Smarkm   of syntax accepted.
3055682Smarkm
3155682Smarkm   Add testcases covering every input symbol in every state in old and
3255682Smarkm   new parsers.
3355682Smarkm
3455682Smarkm   Include full syntax for GNU C, including erroneous cases accepted
35103426Snectar   with error messages, in syntax productions in comments.
3657428Smarkm
3755682Smarkm   Make more diagnostics in the front end generally take an explicit
3855682Smarkm   location rather than implicitly using input_location.  */
3955682Smarkm
4055682Smarkm#include "config.h"
4155682Smarkm#include "system.h"
4255682Smarkm#include "coretypes.h"
4355682Smarkm#include "tm.h"
4455682Smarkm#include "tree.h"
4555682Smarkm#include "rtl.h"
4655682Smarkm#include "langhooks.h"
4755682Smarkm#include "input.h"
4855682Smarkm#include "cpplib.h"
4955682Smarkm#include "timevar.h"
5055682Smarkm#include "c-pragma.h"
5155682Smarkm#include "c-tree.h"
5255682Smarkm#include "flags.h"
5355682Smarkm#include "output.h"
5455682Smarkm#include "toplev.h"
5555682Smarkm#include "ggc.h"
5655682Smarkm#include "c-common.h"
5755682Smarkm#include "vec.h"
5855682Smarkm#include "target.h"
5955682Smarkm#include "cgraph.h"
6055682Smarkm
6155682Smarkm
6255682Smarkm/* Miscellaneous data and functions needed for the parser.  */
6355682Smarkm
6455682Smarkmint yydebug;
6555682Smarkm
6655682Smarkm/* Objective-C specific parser/lexer information.  */
6755682Smarkm
6855682Smarkmstatic int objc_pq_context = 0;
6972448Sassar
7055682Smarkm/* The following flag is needed to contextualize Objective-C lexical
7155682Smarkm   analysis.  In some cases (e.g., 'int NSObject;'), it is undesirable
7255682Smarkm   to bind an identifier to an Objective-C class, even if a class with
7355682Smarkm   that name exists.  */
7455682Smarkmstatic int objc_need_raw_identifier = 0;
7555682Smarkm#define OBJC_NEED_RAW_IDENTIFIER(VAL)		\
7655682Smarkm  do {						\
7755682Smarkm    if (c_dialect_objc ())			\
7855682Smarkm      objc_need_raw_identifier = VAL;		\
7955682Smarkm  } while (0)
8055682Smarkm
8155682Smarkm/* The reserved keyword table.  */
8255682Smarkmstruct resword
8355682Smarkm{
8455682Smarkm  const char *word;
8555682Smarkm  ENUM_BITFIELD(rid) rid : 16;
8655682Smarkm  unsigned int disable   : 16;
8755682Smarkm};
8855682Smarkm
8955682Smarkm/* Disable mask.  Keywords are disabled if (reswords[i].disable &
9055682Smarkm   mask) is _true_.  */
9155682Smarkm#define D_C89	0x01	/* not in C89 */
9255682Smarkm#define D_EXT	0x02	/* GCC extension */
9355682Smarkm#define D_EXT89	0x04	/* GCC extension incorporated in C99 */
9455682Smarkm#define D_OBJC	0x08	/* Objective C only */
9555682Smarkm
9655682Smarkmstatic const struct resword reswords[] =
9755682Smarkm{
9872448Sassar  { "_Bool",		RID_BOOL,	0 },
9972448Sassar  { "_Complex",		RID_COMPLEX,	0 },
10072448Sassar  { "_Decimal32",       RID_DFLOAT32,  D_EXT },
10172448Sassar  { "_Decimal64",       RID_DFLOAT64,  D_EXT },
10272448Sassar  { "_Decimal128",      RID_DFLOAT128, D_EXT },
10372448Sassar  { "__FUNCTION__",	RID_FUNCTION_NAME, 0 },
10472448Sassar  { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
10572448Sassar  { "__alignof",	RID_ALIGNOF,	0 },
10672448Sassar  { "__alignof__",	RID_ALIGNOF,	0 },
10772448Sassar  { "__asm",		RID_ASM,	0 },
10855682Smarkm  { "__asm__",		RID_ASM,	0 },
10955682Smarkm  { "__attribute",	RID_ATTRIBUTE,	0 },
11055682Smarkm  { "__attribute__",	RID_ATTRIBUTE,	0 },
11155682Smarkm  { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
11255682Smarkm  { "__builtin_offsetof", RID_OFFSETOF, 0 },
11355682Smarkm  { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
11455682Smarkm  { "__builtin_va_arg",	RID_VA_ARG,	0 },
11555682Smarkm  { "__complex",	RID_COMPLEX,	0 },
11678536Sassar  { "__complex__",	RID_COMPLEX,	0 },
11755682Smarkm  { "__const",		RID_CONST,	0 },
11855682Smarkm  { "__const__",	RID_CONST,	0 },
11978536Sassar  { "__extension__",	RID_EXTENSION,	0 },
12078536Sassar  { "__func__",		RID_C99_FUNCTION_NAME, 0 },
12172448Sassar  { "__imag",		RID_IMAGPART,	0 },
12272448Sassar  { "__imag__",		RID_IMAGPART,	0 },
12372448Sassar  { "__inline",		RID_INLINE,	0 },
12472448Sassar  { "__inline__",	RID_INLINE,	0 },
12555682Smarkm  { "__label__",	RID_LABEL,	0 },
12655682Smarkm  { "__real",		RID_REALPART,	0 },
12755682Smarkm  { "__real__",		RID_REALPART,	0 },
12855682Smarkm  { "__restrict",	RID_RESTRICT,	0 },
12955682Smarkm  { "__restrict__",	RID_RESTRICT,	0 },
13055682Smarkm  { "__signed",		RID_SIGNED,	0 },
13155682Smarkm  { "__signed__",	RID_SIGNED,	0 },
13255682Smarkm  { "__thread",		RID_THREAD,	0 },
13355682Smarkm  { "__typeof",		RID_TYPEOF,	0 },
13455682Smarkm  { "__typeof__",	RID_TYPEOF,	0 },
13555682Smarkm  { "__volatile",	RID_VOLATILE,	0 },
13655682Smarkm  { "__volatile__",	RID_VOLATILE,	0 },
13755682Smarkm  { "asm",		RID_ASM,	D_EXT },
13855682Smarkm  { "auto",		RID_AUTO,	0 },
13955682Smarkm  { "break",		RID_BREAK,	0 },
14055682Smarkm  { "case",		RID_CASE,	0 },
14155682Smarkm  { "char",		RID_CHAR,	0 },
14255682Smarkm  { "const",		RID_CONST,	0 },
143102647Snectar  { "continue",		RID_CONTINUE,	0 },
14455682Smarkm  { "default",		RID_DEFAULT,	0 },
14555682Smarkm  { "do",		RID_DO,		0 },
14655682Smarkm  { "double",		RID_DOUBLE,	0 },
14755682Smarkm  { "else",		RID_ELSE,	0 },
14855682Smarkm  { "enum",		RID_ENUM,	0 },
14955682Smarkm  { "extern",		RID_EXTERN,	0 },
15055682Smarkm  { "float",		RID_FLOAT,	0 },
15155682Smarkm  { "for",		RID_FOR,	0 },
15255682Smarkm  { "goto",		RID_GOTO,	0 },
15355682Smarkm  { "if",		RID_IF,		0 },
154102647Snectar  { "inline",		RID_INLINE,	D_EXT89 },
15555682Smarkm  { "int",		RID_INT,	0 },
15655682Smarkm  { "long",		RID_LONG,	0 },
15755682Smarkm  { "register",		RID_REGISTER,	0 },
15855682Smarkm  { "restrict",		RID_RESTRICT,	D_C89 },
15955682Smarkm  { "return",		RID_RETURN,	0 },
16090929Snectar  { "short",		RID_SHORT,	0 },
16190929Snectar  { "signed",		RID_SIGNED,	0 },
16290929Snectar  { "sizeof",		RID_SIZEOF,	0 },
16390929Snectar  { "static",		RID_STATIC,	0 },
16490929Snectar  { "struct",		RID_STRUCT,	0 },
16590929Snectar  { "switch",		RID_SWITCH,	0 },
16690929Snectar  { "typedef",		RID_TYPEDEF,	0 },
16790929Snectar  { "typeof",		RID_TYPEOF,	D_EXT },
16890929Snectar  { "union",		RID_UNION,	0 },
16990929Snectar  { "unsigned",		RID_UNSIGNED,	0 },
17090929Snectar  { "void",		RID_VOID,	0 },
17190929Snectar  { "volatile",		RID_VOLATILE,	0 },
17290929Snectar  { "while",		RID_WHILE,	0 },
17390929Snectar  /* These Objective-C keywords are recognized only immediately after
17490929Snectar     an '@'.  */
17590929Snectar  { "class",		RID_AT_CLASS,		D_OBJC },
17690929Snectar  { "compatibility_alias", RID_AT_ALIAS,	D_OBJC },
17790929Snectar  { "defs",		RID_AT_DEFS,		D_OBJC },
17890929Snectar  { "encode",		RID_AT_ENCODE,		D_OBJC },
17990929Snectar  { "end",		RID_AT_END,		D_OBJC },
18090929Snectar  { "implementation",	RID_AT_IMPLEMENTATION,	D_OBJC },
18190929Snectar  { "interface",	RID_AT_INTERFACE,	D_OBJC },
18290929Snectar  { "private",		RID_AT_PRIVATE,		D_OBJC },
18390929Snectar  { "protected",	RID_AT_PROTECTED,	D_OBJC },
18490929Snectar  { "protocol",		RID_AT_PROTOCOL,	D_OBJC },
18590929Snectar  { "public",		RID_AT_PUBLIC,		D_OBJC },
18690929Snectar  { "selector",		RID_AT_SELECTOR,	D_OBJC },
18790929Snectar  { "throw",		RID_AT_THROW,		D_OBJC },
18890929Snectar  { "try",		RID_AT_TRY,		D_OBJC },
18990929Snectar  { "catch",		RID_AT_CATCH,		D_OBJC },
19090929Snectar  { "finally",		RID_AT_FINALLY,		D_OBJC },
19155682Smarkm  { "synchronized",	RID_AT_SYNCHRONIZED,	D_OBJC },
192102647Snectar  /* These are recognized only in protocol-qualifier context
19355682Smarkm     (see above) */
19455682Smarkm  { "bycopy",		RID_BYCOPY,		D_OBJC },
19555682Smarkm  { "byref",		RID_BYREF,		D_OBJC },
19655682Smarkm  { "in",		RID_IN,			D_OBJC },
19755682Smarkm  { "inout",		RID_INOUT,		D_OBJC },
19890929Snectar  { "oneway",		RID_ONEWAY,		D_OBJC },
19955682Smarkm  { "out",		RID_OUT,		D_OBJC },
20055682Smarkm};
20155682Smarkm#define N_reswords (sizeof reswords / sizeof (struct resword))
20290929Snectar
20355682Smarkm/* All OpenMP clauses.  OpenMP 2.5.  */
20490929Snectartypedef enum pragma_omp_clause {
20578536Sassar  PRAGMA_OMP_CLAUSE_NONE = 0,
20655682Smarkm
20778536Sassar  PRAGMA_OMP_CLAUSE_COPYIN,
20855682Smarkm  PRAGMA_OMP_CLAUSE_COPYPRIVATE,
20955682Smarkm  PRAGMA_OMP_CLAUSE_DEFAULT,
21090929Snectar  PRAGMA_OMP_CLAUSE_FIRSTPRIVATE,
21155682Smarkm  PRAGMA_OMP_CLAUSE_IF,
21255682Smarkm  PRAGMA_OMP_CLAUSE_LASTPRIVATE,
21355682Smarkm  PRAGMA_OMP_CLAUSE_NOWAIT,
21455682Smarkm  PRAGMA_OMP_CLAUSE_NUM_THREADS,
21555682Smarkm  PRAGMA_OMP_CLAUSE_ORDERED,
21655682Smarkm  PRAGMA_OMP_CLAUSE_PRIVATE,
21755682Smarkm  PRAGMA_OMP_CLAUSE_REDUCTION,
21855682Smarkm  PRAGMA_OMP_CLAUSE_SCHEDULE,
21955682Smarkm  PRAGMA_OMP_CLAUSE_SHARED
22055682Smarkm} pragma_omp_clause;
22155682Smarkm
22255682Smarkm
22355682Smarkm/* Initialization routine for this file.  */
22455682Smarkm
22555682Smarkmvoid
22655682Smarkmc_parse_init (void)
22755682Smarkm{
22855682Smarkm  /* The only initialization required is of the reserved word
229102647Snectar     identifiers.  */
23055682Smarkm  unsigned int i;
23155682Smarkm  tree id;
23255682Smarkm  int mask = (flag_isoc99 ? 0 : D_C89)
23355682Smarkm	      | (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0);
23455682Smarkm
23555682Smarkm  if (!c_dialect_objc ())
23655682Smarkm     mask |= D_OBJC;
23755682Smarkm
23872448Sassar  ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
23972448Sassar  for (i = 0; i < N_reswords; i++)
24055682Smarkm    {
24155682Smarkm      /* If a keyword is disabled, do not enter it into the table
24255682Smarkm	 and so create a canonical spelling that isn't a keyword.  */
24355682Smarkm      if (reswords[i].disable & mask)
24455682Smarkm	continue;
24555682Smarkm
24655682Smarkm      id = get_identifier (reswords[i].word);
24755682Smarkm      C_RID_CODE (id) = reswords[i].rid;
24855682Smarkm      C_IS_RESERVED_WORD (id) = 1;
24955682Smarkm      ridpointers [(int) reswords[i].rid] = id;
25055682Smarkm    }
25155682Smarkm}
25255682Smarkm
25355682Smarkm/* The C lexer intermediates between the lexer in cpplib and c-lex.c
25455682Smarkm   and the C parser.  Unlike the C++ lexer, the parser structure
25555682Smarkm   stores the lexer information instead of using a separate structure.
25655682Smarkm   Identifiers are separated into ordinary identifiers, type names,
25755682Smarkm   keywords and some other Objective-C types of identifiers, and some
258102647Snectar   look-ahead is maintained.
25955682Smarkm
26055682Smarkm   ??? It might be a good idea to lex the whole file up front (as for
26155682Smarkm   C++).  It would then be possible to share more of the C and C++
26255682Smarkm   lexer code, if desired.  */
26355682Smarkm
26455682Smarkm/* The following local token type is used.  */
26555682Smarkm
26655682Smarkm/* A keyword.  */
26755682Smarkm#define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
26855682Smarkm
26972448Sassar/* More information about the type of a CPP_NAME token.  */
27072448Sassartypedef enum c_id_kind {
27172448Sassar  /* An ordinary identifier.  */
27272448Sassar  C_ID_ID,
27372448Sassar  /* An identifier declared as a typedef name.  */
27472448Sassar  C_ID_TYPENAME,
27572448Sassar  /* An identifier declared as an Objective-C class name.  */
27672448Sassar  C_ID_CLASSNAME,
27755682Smarkm  /* Not an identifier.  */
27855682Smarkm  C_ID_NONE
27955682Smarkm} c_id_kind;
28055682Smarkm
28155682Smarkm/* A single C token after string literal concatenation and conversion
28290929Snectar   of preprocessing tokens to tokens.  */
28355682Smarkmtypedef struct c_token GTY (())
28455682Smarkm{
28555682Smarkm  /* The kind of token.  */
28655682Smarkm  ENUM_BITFIELD (cpp_ttype) type : 8;
28790929Snectar  /* If this token is a CPP_NAME, this value indicates whether also
28855682Smarkm     declared as some kind of type.  Otherwise, it is C_ID_NONE.  */
28955682Smarkm  ENUM_BITFIELD (c_id_kind) id_kind : 8;
29055682Smarkm  /* If this token is a keyword, this value indicates which keyword.
29155682Smarkm     Otherwise, this value is RID_MAX.  */
29255682Smarkm  ENUM_BITFIELD (rid) keyword : 8;
29355682Smarkm  /* If this token is a CPP_PRAGMA, this indicates the pragma that
29455682Smarkm     was seen.  Otherwise it is PRAGMA_NONE.  */
29555682Smarkm  ENUM_BITFIELD (pragma_kind) pragma_kind : 7;
29655682Smarkm  /* True if this token is from a system header.  */
29755682Smarkm  BOOL_BITFIELD in_system_header : 1;
29855682Smarkm  /* The value associated with this token, if any.  */
29955682Smarkm  tree value;
30055682Smarkm  /* The location at which this token was found.  */
30155682Smarkm  location_t location;
30255682Smarkm} c_token;
30355682Smarkm
30455682Smarkm/* A parser structure recording information about the state and
305102647Snectar   context of parsing.  Includes lexer information with up to two
30655682Smarkm   tokens of look-ahead; more are not needed for C.  */
307102647Snectartypedef struct c_parser GTY(())
30855682Smarkm{
30955682Smarkm  /* The look-ahead tokens.  */
31055682Smarkm  c_token tokens[2];
31155682Smarkm  /* How many look-ahead tokens are available (0, 1 or 2).  */
31255682Smarkm  short tokens_avail;
31355682Smarkm  /* True if a syntax error is being recovered from; false otherwise.
31455682Smarkm     c_parser_error sets this flag.  It should clear this flag when
31555682Smarkm     enough tokens have been consumed to recover from the error.  */
31655682Smarkm  BOOL_BITFIELD error : 1;
31755682Smarkm  /* True if we're processing a pragma, and shouldn't automatically
31855682Smarkm     consume CPP_PRAGMA_EOL.  */
31955682Smarkm  BOOL_BITFIELD in_pragma : 1;
32055682Smarkm} c_parser;
32155682Smarkm
32255682Smarkm
32355682Smarkm/* The actual parser and external interface.  ??? Does this need to be
32455682Smarkm   garbage-collected?  */
32555682Smarkm
32655682Smarkmstatic GTY (()) c_parser *the_parser;
32755682Smarkm
32855682Smarkm
32955682Smarkm/* Read in and lex a single token, storing it in *TOKEN.  */
33055682Smarkm
33155682Smarkmstatic void
33255682Smarkmc_lex_one_token (c_token *token)
33355682Smarkm{
33455682Smarkm  timevar_push (TV_LEX);
33555682Smarkm
33655682Smarkm  token->type = c_lex_with_flags (&token->value, &token->location, NULL);
33755682Smarkm  token->id_kind = C_ID_NONE;
33855682Smarkm  token->keyword = RID_MAX;
33955682Smarkm  token->pragma_kind = PRAGMA_NONE;
34055682Smarkm  token->in_system_header = in_system_header;
34155682Smarkm
34255682Smarkm  switch (token->type)
34355682Smarkm    {
34455682Smarkm    case CPP_NAME:
34555682Smarkm      {
34655682Smarkm	tree decl;
34755682Smarkm
34855682Smarkm	int objc_force_identifier = objc_need_raw_identifier;
34955682Smarkm	OBJC_NEED_RAW_IDENTIFIER (0);
35055682Smarkm
35155682Smarkm	if (C_IS_RESERVED_WORD (token->value))
35255682Smarkm	  {
35355682Smarkm	    enum rid rid_code = C_RID_CODE (token->value);
35455682Smarkm
35555682Smarkm	    if (c_dialect_objc ())
35655682Smarkm	      {
35755682Smarkm		if (!OBJC_IS_AT_KEYWORD (rid_code)
35855682Smarkm		    && (!OBJC_IS_PQ_KEYWORD (rid_code) || objc_pq_context))
35955682Smarkm		  {
36055682Smarkm		    /* Return the canonical spelling for this keyword.  */
36155682Smarkm		    token->value = ridpointers[(int) rid_code];
36255682Smarkm		    token->type = CPP_KEYWORD;
36355682Smarkm		    token->keyword = rid_code;
36455682Smarkm		    break;
36555682Smarkm		  }
36655682Smarkm	      }
36755682Smarkm	    else
36855682Smarkm	      {
36955682Smarkm		/* Return the canonical spelling for this keyword.  */
37055682Smarkm		token->value = ridpointers[(int) rid_code];
37155682Smarkm		token->type = CPP_KEYWORD;
37278536Sassar		token->keyword = rid_code;
37378536Sassar		break;
37455682Smarkm	      }
37578536Sassar	  }
37655682Smarkm
37755682Smarkm	decl = lookup_name (token->value);
37855682Smarkm	if (decl)
37955682Smarkm	  {
38055682Smarkm	    if (TREE_CODE (decl) == TYPE_DECL)
38155682Smarkm	      {
38255682Smarkm		token->id_kind = C_ID_TYPENAME;
38355682Smarkm		break;
38455682Smarkm	      }
38555682Smarkm	  }
38655682Smarkm	else if (c_dialect_objc ())
38755682Smarkm	  {
38855682Smarkm	    tree objc_interface_decl = objc_is_class_name (token->value);
389102647Snectar	    /* Objective-C class names are in the same namespace as
39055682Smarkm	       variables and typedefs, and hence are shadowed by local
39155682Smarkm	       declarations.  */
39255682Smarkm	    if (objc_interface_decl
39390929Snectar		&& (global_bindings_p ()
39490929Snectar		    || (!objc_force_identifier && !decl)))
39555682Smarkm	      {
39655682Smarkm		token->value = objc_interface_decl;
39755682Smarkm		token->id_kind = C_ID_CLASSNAME;
39855682Smarkm		break;
39955682Smarkm	      }
40055682Smarkm	  }
40155682Smarkm        token->id_kind = C_ID_ID;
402102647Snectar      }
40355682Smarkm      break;
40455682Smarkm    case CPP_AT_NAME:
40555682Smarkm      /* This only happens in Objective-C; it must be a keyword.  */
40655682Smarkm      token->type = CPP_KEYWORD;
40755682Smarkm      token->keyword = C_RID_CODE (token->value);
40855682Smarkm      break;
40955682Smarkm    case CPP_COLON:
41055682Smarkm    case CPP_COMMA:
41155682Smarkm    case CPP_CLOSE_PAREN:
41255682Smarkm    case CPP_SEMICOLON:
41355682Smarkm      /* These tokens may affect the interpretation of any identifiers
41455682Smarkm	 following, if doing Objective-C.  */
41555682Smarkm      OBJC_NEED_RAW_IDENTIFIER (0);
41655682Smarkm      break;
41755682Smarkm    case CPP_PRAGMA:
41855682Smarkm      /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST.  */
41955682Smarkm      token->pragma_kind = TREE_INT_CST_LOW (token->value);
42055682Smarkm      token->value = NULL;
42155682Smarkm      break;
42255682Smarkm    default:
42355682Smarkm      break;
42455682Smarkm    }
42555682Smarkm  timevar_pop (TV_LEX);
42678536Sassar}
42778536Sassar
42855682Smarkm/* Return a pointer to the next token from PARSER, reading it in if
42978536Sassar   necessary.  */
43055682Smarkm
43155682Smarkmstatic inline c_token *
43255682Smarkmc_parser_peek_token (c_parser *parser)
43355682Smarkm{
43455682Smarkm  if (parser->tokens_avail == 0)
43555682Smarkm    {
43655682Smarkm      c_lex_one_token (&parser->tokens[0]);
43755682Smarkm      parser->tokens_avail = 1;
43855682Smarkm    }
43955682Smarkm  return &parser->tokens[0];
44055682Smarkm}
44155682Smarkm
44255682Smarkm/* Return true if the next token from PARSER has the indicated
44355682Smarkm   TYPE.  */
44455682Smarkm
44555682Smarkmstatic inline bool
44655682Smarkmc_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
44755682Smarkm{
44855682Smarkm  return c_parser_peek_token (parser)->type == type;
44955682Smarkm}
45055682Smarkm
45155682Smarkm/* Return true if the next token from PARSER does not have the
45255682Smarkm   indicated TYPE.  */
45355682Smarkm
45455682Smarkmstatic inline bool
45555682Smarkmc_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
45655682Smarkm{
45755682Smarkm  return !c_parser_next_token_is (parser, type);
45855682Smarkm}
45955682Smarkm
46055682Smarkm/* Return true if the next token from PARSER is the indicated
46155682Smarkm   KEYWORD.  */
46255682Smarkm
46355682Smarkmstatic inline bool
46455682Smarkmc_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
46555682Smarkm{
46655682Smarkm  c_token *token;
46755682Smarkm
46855682Smarkm  /* Peek at the next token.  */
46955682Smarkm  token = c_parser_peek_token (parser);
47057416Smarkm  /* Check to see if it is the indicated keyword.  */
47155682Smarkm  return token->keyword == keyword;
47272448Sassar}
47355682Smarkm
47478536Sassar/* Return true if TOKEN can start a type name,
47578536Sassar   false otherwise.  */
47655682Smarkmstatic bool
47778536Sassarc_token_starts_typename (c_token *token)
47855682Smarkm{
47955682Smarkm  switch (token->type)
48055682Smarkm    {
48155682Smarkm    case CPP_NAME:
48272448Sassar      switch (token->id_kind)
48372448Sassar	{
48455682Smarkm	case C_ID_ID:
48555682Smarkm	  return false;
48672448Sassar	case C_ID_TYPENAME:
48755682Smarkm	  return true;
48855682Smarkm	case C_ID_CLASSNAME:
48955682Smarkm	  gcc_assert (c_dialect_objc ());
49055682Smarkm	  return true;
49155682Smarkm	default:
49255682Smarkm	  gcc_unreachable ();
49355682Smarkm	}
49455682Smarkm    case CPP_KEYWORD:
49555682Smarkm      switch (token->keyword)
49655682Smarkm	{
49755682Smarkm	case RID_UNSIGNED:
49855682Smarkm	case RID_LONG:
49955682Smarkm	case RID_SHORT:
50055682Smarkm	case RID_SIGNED:
50155682Smarkm	case RID_COMPLEX:
50255682Smarkm	case RID_INT:
50355682Smarkm	case RID_CHAR:
50455682Smarkm	case RID_FLOAT:
50555682Smarkm	case RID_DOUBLE:
50655682Smarkm	case RID_VOID:
50755682Smarkm	case RID_DFLOAT32:
50855682Smarkm	case RID_DFLOAT64:
50955682Smarkm	case RID_DFLOAT128:
51055682Smarkm	case RID_BOOL:
51155682Smarkm	case RID_ENUM:
512102647Snectar	case RID_STRUCT:
513102647Snectar	case RID_UNION:
51455682Smarkm	case RID_TYPEOF:
51555682Smarkm	case RID_CONST:
51655682Smarkm	case RID_VOLATILE:
51755682Smarkm	case RID_RESTRICT:
51855682Smarkm	case RID_ATTRIBUTE:
51955682Smarkm	  return true;
52055682Smarkm	default:
52155682Smarkm	  return false;
52255682Smarkm	}
52355682Smarkm    case CPP_LESS:
52455682Smarkm      if (c_dialect_objc ())
52555682Smarkm	return true;
52655682Smarkm      return false;
52755682Smarkm    default:
52855682Smarkm      return false;
52955682Smarkm    }
53055682Smarkm}
53155682Smarkm
53255682Smarkm/* Return true if the next token from PARSER can start a type name,
53355682Smarkm   false otherwise.  */
53455682Smarkmstatic inline bool
53555682Smarkmc_parser_next_token_starts_typename (c_parser *parser)
53655682Smarkm{
53755682Smarkm  c_token *token = c_parser_peek_token (parser);
53855682Smarkm  return c_token_starts_typename (token);
53955682Smarkm}
54055682Smarkm
54155682Smarkm/* Return true if TOKEN can start declaration specifiers, false
54255682Smarkm   otherwise.  */
54355682Smarkmstatic bool
54455682Smarkmc_token_starts_declspecs (c_token *token)
54555682Smarkm{
54655682Smarkm  switch (token->type)
54755682Smarkm    {
54855682Smarkm    case CPP_NAME:
54955682Smarkm      switch (token->id_kind)
55055682Smarkm	{
55155682Smarkm	case C_ID_ID:
55255682Smarkm	  return false;
55355682Smarkm	case C_ID_TYPENAME:
55455682Smarkm	  return true;
55555682Smarkm	case C_ID_CLASSNAME:
55655682Smarkm	  gcc_assert (c_dialect_objc ());
55755682Smarkm	  return true;
55855682Smarkm	default:
55955682Smarkm	  gcc_unreachable ();
56055682Smarkm	}
56155682Smarkm    case CPP_KEYWORD:
56255682Smarkm      switch (token->keyword)
56355682Smarkm	{
56455682Smarkm	case RID_STATIC:
56555682Smarkm	case RID_EXTERN:
56655682Smarkm	case RID_REGISTER:
56755682Smarkm	case RID_TYPEDEF:
56855682Smarkm	case RID_INLINE:
56955682Smarkm	case RID_AUTO:
57055682Smarkm	case RID_THREAD:
57155682Smarkm	case RID_UNSIGNED:
57255682Smarkm	case RID_LONG:
57355682Smarkm	case RID_SHORT:
57455682Smarkm	case RID_SIGNED:
575102647Snectar	case RID_COMPLEX:
57655682Smarkm	case RID_INT:
57755682Smarkm	case RID_CHAR:
57855682Smarkm	case RID_FLOAT:
57955682Smarkm	case RID_DOUBLE:
58055682Smarkm	case RID_VOID:
58155682Smarkm	case RID_DFLOAT32:
58255682Smarkm	case RID_DFLOAT64:
58355682Smarkm	case RID_DFLOAT128:
58455682Smarkm	case RID_BOOL:
58555682Smarkm	case RID_ENUM:
58655682Smarkm	case RID_STRUCT:
58755682Smarkm	case RID_UNION:
58855682Smarkm	case RID_TYPEOF:
58955682Smarkm	case RID_CONST:
59055682Smarkm	case RID_VOLATILE:
59155682Smarkm	case RID_RESTRICT:
59255682Smarkm	case RID_ATTRIBUTE:
59355682Smarkm	  return true;
59455682Smarkm	default:
59555682Smarkm	  return false;
59655682Smarkm	}
59755682Smarkm    case CPP_LESS:
59855682Smarkm      if (c_dialect_objc ())
59955682Smarkm	return true;
60055682Smarkm      return false;
60155682Smarkm    default:
60255682Smarkm      return false;
60355682Smarkm    }
60455682Smarkm}
60555682Smarkm
60655682Smarkm/* Return true if the next token from PARSER can start declaration
60755682Smarkm   specifiers, false otherwise.  */
60855682Smarkmstatic inline bool
60955682Smarkmc_parser_next_token_starts_declspecs (c_parser *parser)
61055682Smarkm{
61155682Smarkm  c_token *token = c_parser_peek_token (parser);
61255682Smarkm  return c_token_starts_declspecs (token);
61355682Smarkm}
61455682Smarkm
61555682Smarkm/* Return a pointer to the next-but-one token from PARSER, reading it
61655682Smarkm   in if necessary.  The next token is already read in.  */
61755682Smarkm
61855682Smarkmstatic c_token *
61955682Smarkmc_parser_peek_2nd_token (c_parser *parser)
62055682Smarkm{
62155682Smarkm  if (parser->tokens_avail >= 2)
62278536Sassar    return &parser->tokens[1];
62378536Sassar  gcc_assert (parser->tokens_avail == 1);
62478536Sassar  gcc_assert (parser->tokens[0].type != CPP_EOF);
62555682Smarkm  gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
62678536Sassar  c_lex_one_token (&parser->tokens[1]);
62755682Smarkm  parser->tokens_avail = 2;
62855682Smarkm  return &parser->tokens[1];
62955682Smarkm}
63078536Sassar
63178536Sassar/* Consume the next token from PARSER.  */
63255682Smarkm
63378536Sassarstatic void
63455682Smarkmc_parser_consume_token (c_parser *parser)
63555682Smarkm{
63655682Smarkm  gcc_assert (parser->tokens_avail >= 1);
63778536Sassar  gcc_assert (parser->tokens[0].type != CPP_EOF);
63855682Smarkm  gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
63955682Smarkm  gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
64055682Smarkm  if (parser->tokens_avail == 2)
64155682Smarkm    parser->tokens[0] = parser->tokens[1];
64255682Smarkm  parser->tokens_avail--;
64355682Smarkm}
64455682Smarkm
64555682Smarkm/* Expect the current token to be a #pragma.  Consume it and remember
64655682Smarkm   that we've begun parsing a pragma.  */
64755682Smarkm
64855682Smarkmstatic void
64955682Smarkmc_parser_consume_pragma (c_parser *parser)
65055682Smarkm{
65178536Sassar  gcc_assert (!parser->in_pragma);
65278536Sassar  gcc_assert (parser->tokens_avail >= 1);
65378536Sassar  gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
65455682Smarkm  if (parser->tokens_avail == 2)
65578536Sassar    parser->tokens[0] = parser->tokens[1];
65655682Smarkm  parser->tokens_avail--;
65755682Smarkm  parser->in_pragma = true;
65855682Smarkm}
65955682Smarkm
66055682Smarkm/* Update the globals input_location and in_system_header from
66155682Smarkm   TOKEN.  */
66278536Sassarstatic inline void
66355682Smarkmc_parser_set_source_position_from_token (c_token *token)
66455682Smarkm{
66555682Smarkm  if (token->type != CPP_EOF)
66655682Smarkm    {
66755682Smarkm      input_location = token->location;
66855682Smarkm      in_system_header = token->in_system_header;
66955682Smarkm    }
67055682Smarkm}
67155682Smarkm
67255682Smarkm/* Issue a diagnostic of the form
67355682Smarkm      FILE:LINE: MESSAGE before TOKEN
67455682Smarkm   where TOKEN is the next token in the input stream of PARSER.
67555682Smarkm   MESSAGE (specified by the caller) is usually of the form "expected
67655682Smarkm   OTHER-TOKEN".
67755682Smarkm
67855682Smarkm   Do not issue a diagnostic if still recovering from an error.
67955682Smarkm
68055682Smarkm   ??? This is taken from the C++ parser, but building up messages in
68155682Smarkm   this way is not i18n-friendly and some other approach should be
68255682Smarkm   used.  */
68355682Smarkm
68455682Smarkmstatic void
68555682Smarkmc_parser_error (c_parser *parser, const char *gmsgid)
68655682Smarkm{
68755682Smarkm  c_token *token = c_parser_peek_token (parser);
68855682Smarkm  if (parser->error)
68955682Smarkm    return;
69055682Smarkm  parser->error = true;
69155682Smarkm  if (!gmsgid)
69255682Smarkm    return;
69355682Smarkm  /* This diagnostic makes more sense if it is tagged to the line of
69455682Smarkm     the token we just peeked at.  */
69555682Smarkm  c_parser_set_source_position_from_token (token);
69655682Smarkm  c_parse_error (gmsgid,
69755682Smarkm		 /* Because c_parse_error does not understand
69855682Smarkm		    CPP_KEYWORD, keywords are treated like
69955682Smarkm		    identifiers.  */
70055682Smarkm		 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
70155682Smarkm		 token->value);
70255682Smarkm}
70355682Smarkm
70455682Smarkm/* If the next token is of the indicated TYPE, consume it.  Otherwise,
70555682Smarkm   issue the error MSGID.  If MSGID is NULL then a message has already
70655682Smarkm   been produced and no message will be produced this time.  Returns
70755682Smarkm   true if found, false otherwise.  */
70855682Smarkm
70955682Smarkmstatic bool
71055682Smarkmc_parser_require (c_parser *parser,
71155682Smarkm		  enum cpp_ttype type,
71255682Smarkm		  const char *msgid)
71355682Smarkm{
71455682Smarkm  if (c_parser_next_token_is (parser, type))
71555682Smarkm    {
71655682Smarkm      c_parser_consume_token (parser);
71755682Smarkm      return true;
71855682Smarkm    }
71955682Smarkm  else
72055682Smarkm    {
72155682Smarkm      c_parser_error (parser, msgid);
72255682Smarkm      return false;
72355682Smarkm    }
72455682Smarkm}
72555682Smarkm
72655682Smarkm/* If the next token is the indicated keyword, consume it.  Otherwise,
72755682Smarkm   issue the error MSGID.  Returns true if found, false otherwise.  */
72855682Smarkm
72955682Smarkmstatic bool
73055682Smarkmc_parser_require_keyword (c_parser *parser,
73155682Smarkm			  enum rid keyword,
73255682Smarkm			  const char *msgid)
73355682Smarkm{
73472448Sassar  if (c_parser_next_token_is_keyword (parser, keyword))
73572448Sassar    {
73672448Sassar      c_parser_consume_token (parser);
73772448Sassar      return true;
73872448Sassar    }
73955682Smarkm  else
74055682Smarkm    {
74155682Smarkm      c_parser_error (parser, msgid);
74255682Smarkm      return false;
74355682Smarkm    }
74455682Smarkm}
74555682Smarkm
74655682Smarkm/* Like c_parser_require, except that tokens will be skipped until the
74755682Smarkm   desired token is found.  An error message is still produced if the
74878536Sassar   next token is not as expected.  If MSGID is NULL then a message has
74978536Sassar   already been produced and no message will be produced this
75078536Sassar   time.  */
75155682Smarkm
75278536Sassarstatic void
75355682Smarkmc_parser_skip_until_found (c_parser *parser,
75455682Smarkm			   enum cpp_ttype type,
75555682Smarkm			   const char *msgid)
75678536Sassar{
75778536Sassar  unsigned nesting_depth = 0;
75855682Smarkm
75955682Smarkm  if (c_parser_require (parser, type, msgid))
76055682Smarkm    return;
76172448Sassar
76272448Sassar  /* Skip tokens until the desired token is found.  */
76372448Sassar  while (true)
76472448Sassar    {
76572448Sassar      /* Peek at the next token.  */
76672448Sassar      c_token *token = c_parser_peek_token (parser);
76755682Smarkm      /* If we've reached the token we want, consume it and stop.  */
76855682Smarkm      if (token->type == type && !nesting_depth)
76955682Smarkm	{
77055682Smarkm	  c_parser_consume_token (parser);
77155682Smarkm	  break;
77255682Smarkm	}
77355682Smarkm
77455682Smarkm      /* If we've run out of tokens, stop.  */
77555682Smarkm      if (token->type == CPP_EOF)
77655682Smarkm	return;
77755682Smarkm      if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
77855682Smarkm	return;
77955682Smarkm      if (token->type == CPP_OPEN_BRACE
78055682Smarkm	  || token->type == CPP_OPEN_PAREN
78155682Smarkm	  || token->type == CPP_OPEN_SQUARE)
78255682Smarkm	++nesting_depth;
78355682Smarkm      else if (token->type == CPP_CLOSE_BRACE
78455682Smarkm	       || token->type == CPP_CLOSE_PAREN
78555682Smarkm	       || token->type == CPP_CLOSE_SQUARE)
78678536Sassar	{
78778536Sassar	  if (nesting_depth-- == 0)
78855682Smarkm	    break;
78978536Sassar	}
79055682Smarkm      /* Consume this token.  */
79178536Sassar      c_parser_consume_token (parser);
79278536Sassar    }
79355682Smarkm  parser->error = false;
79478536Sassar}
79555682Smarkm
79655682Smarkm/* Skip tokens until the end of a parameter is found, but do not
79755682Smarkm   consume the comma, semicolon or closing delimiter.  */
79855682Smarkm
79955682Smarkmstatic void
80055682Smarkmc_parser_skip_to_end_of_parameter (c_parser *parser)
80155682Smarkm{
80255682Smarkm  unsigned nesting_depth = 0;
80355682Smarkm
80455682Smarkm  while (true)
80555682Smarkm    {
80655682Smarkm      c_token *token = c_parser_peek_token (parser);
80755682Smarkm      if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
80855682Smarkm	  && !nesting_depth)
80978536Sassar	break;
81055682Smarkm      /* If we've run out of tokens, stop.  */
81155682Smarkm      if (token->type == CPP_EOF)
81255682Smarkm	return;
81355682Smarkm      if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
81455682Smarkm	return;
81555682Smarkm      if (token->type == CPP_OPEN_BRACE
81655682Smarkm	  || token->type == CPP_OPEN_PAREN
81755682Smarkm	  || token->type == CPP_OPEN_SQUARE)
81855682Smarkm	++nesting_depth;
81955682Smarkm      else if (token->type == CPP_CLOSE_BRACE
82078536Sassar	       || token->type == CPP_CLOSE_PAREN
82178536Sassar	       || token->type == CPP_CLOSE_SQUARE)
82278536Sassar	{
82355682Smarkm	  if (nesting_depth-- == 0)
82478536Sassar	    break;
82555682Smarkm	}
82655682Smarkm      /* Consume this token.  */
82755682Smarkm      c_parser_consume_token (parser);
82855682Smarkm    }
82955682Smarkm  parser->error = false;
83055682Smarkm}
83155682Smarkm
83255682Smarkm/* Expect to be at the end of the pragma directive and consume an
83355682Smarkm   end of line marker.  */
83455682Smarkm
83555682Smarkmstatic void
83655682Smarkmc_parser_skip_to_pragma_eol (c_parser *parser)
83755682Smarkm{
83855682Smarkm  gcc_assert (parser->in_pragma);
83955682Smarkm  parser->in_pragma = false;
84055682Smarkm
84155682Smarkm  if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
84255682Smarkm    while (true)
84355682Smarkm      {
84455682Smarkm	c_token *token = c_parser_peek_token (parser);
84555682Smarkm	if (token->type == CPP_EOF)
84655682Smarkm	  break;
84772448Sassar	if (token->type == CPP_PRAGMA_EOL)
84872448Sassar	  {
84955682Smarkm	    c_parser_consume_token (parser);
85078536Sassar	    break;
85178536Sassar	  }
85255682Smarkm	c_parser_consume_token (parser);
85378536Sassar      }
85455682Smarkm
85555682Smarkm  parser->error = false;
85655682Smarkm}
85755682Smarkm
85855682Smarkm/* Skip tokens until we have consumed an entire block, or until we
85955682Smarkm   have consumed a non-nested ';'.  */
86055682Smarkm
86155682Smarkmstatic void
86255682Smarkmc_parser_skip_to_end_of_block_or_statement (c_parser *parser)
86355682Smarkm{
86455682Smarkm  unsigned nesting_depth = 0;
86555682Smarkm  bool save_error = parser->error;
86655682Smarkm
86755682Smarkm  while (true)
86855682Smarkm    {
86955682Smarkm      c_token *token;
87055682Smarkm
87172448Sassar      /* Peek at the next token.  */
87255682Smarkm      token = c_parser_peek_token (parser);
87372448Sassar
87455682Smarkm      switch (token->type)
87555682Smarkm	{
87655682Smarkm	case CPP_EOF:
87755682Smarkm	  return;
87855682Smarkm
87955682Smarkm	case CPP_PRAGMA_EOL:
88055682Smarkm	  if (parser->in_pragma)
88172448Sassar	    return;
88255682Smarkm	  break;
88372448Sassar
88455682Smarkm	case CPP_SEMICOLON:
88555682Smarkm	  /* If the next token is a ';', we have reached the
88655682Smarkm	     end of the statement.  */
88755682Smarkm	  if (!nesting_depth)
88855682Smarkm	    {
88955682Smarkm	      /* Consume the ';'.  */
89055682Smarkm	      c_parser_consume_token (parser);
89155682Smarkm	      goto finished;
89255682Smarkm	    }
89355682Smarkm	  break;
89455682Smarkm
89555682Smarkm	case CPP_CLOSE_BRACE:
89655682Smarkm	  /* If the next token is a non-nested '}', then we have
89755682Smarkm	     reached the end of the current block.  */
89855682Smarkm	  if (nesting_depth == 0 || --nesting_depth == 0)
89972448Sassar	    {
90055682Smarkm	      c_parser_consume_token (parser);
90172448Sassar	      goto finished;
90255682Smarkm	    }
90355682Smarkm	  break;
90457416Smarkm
90557416Smarkm	case CPP_OPEN_BRACE:
90672448Sassar	  /* If it the next token is a '{', then we are entering a new
90772448Sassar	     block.  Consume the entire block.  */
90872448Sassar	  ++nesting_depth;
90955682Smarkm	  break;
91055682Smarkm
91155682Smarkm	case CPP_PRAGMA:
91255682Smarkm	  /* If we see a pragma, consume the whole thing at once.  We
91355682Smarkm	     have some safeguards against consuming pragmas willy-nilly.
91472448Sassar	     Normally, we'd expect to be here with parser->error set,
91555682Smarkm	     which disables these safeguards.  But it's possible to get
91672448Sassar	     here for secondary error recovery, after parser->error has
91755682Smarkm	     been cleared.  */
91855682Smarkm	  c_parser_consume_pragma (parser);
91957416Smarkm	  c_parser_skip_to_pragma_eol (parser);
92055682Smarkm	  parser->error = save_error;
92155682Smarkm	  continue;
92255682Smarkm
92355682Smarkm	default:
92472448Sassar	  break;
92572448Sassar	}
92672448Sassar
92772448Sassar      c_parser_consume_token (parser);
92855682Smarkm    }
92990929Snectar
93090929Snectar finished:
93155682Smarkm  parser->error = false;
93255682Smarkm}
93355682Smarkm
93455682Smarkm/* Save the warning flags which are controlled by __extension__.  */
93555682Smarkm
93655682Smarkmstatic inline int
93755682Smarkmdisable_extension_diagnostics (void)
93855682Smarkm{
93955682Smarkm  int ret = (pedantic
94072448Sassar	     | (warn_pointer_arith << 1)
94155682Smarkm	     | (warn_traditional << 2)
94272448Sassar	     | (flag_iso << 3));
94355682Smarkm  pedantic = 0;
94455682Smarkm  warn_pointer_arith = 0;
94557416Smarkm  warn_traditional = 0;
94655682Smarkm  flag_iso = 0;
94755682Smarkm  return ret;
94855682Smarkm}
94955682Smarkm
95055682Smarkm/* Restore the warning flags which are controlled by __extension__.
95155682Smarkm   FLAGS is the return value from disable_extension_diagnostics.  */
95257416Smarkm
95355682Smarkmstatic inline void
95455682Smarkmrestore_extension_diagnostics (int flags)
95555682Smarkm{
95655682Smarkm  pedantic = flags & 1;
95755682Smarkm  warn_pointer_arith = (flags >> 1) & 1;
95872448Sassar  warn_traditional = (flags >> 2) & 1;
95972448Sassar  flag_iso = (flags >> 3) & 1;
96072448Sassar}
96172448Sassar
96278536Sassar/* Possibly kinds of declarator to parse.  */
96378536Sassartypedef enum c_dtr_syn {
96455682Smarkm  /* A normal declarator with an identifier.  */
96578536Sassar  C_DTR_NORMAL,
96655682Smarkm  /* An abstract declarator (maybe empty).  */
96755682Smarkm  C_DTR_ABSTRACT,
96855682Smarkm  /* A parameter declarator: may be either, but after a type name does
96955682Smarkm     not redeclare a typedef name as an identifier if it can
97055682Smarkm     alternatively be interpreted as a typedef name; see DR#009,
97155682Smarkm     applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
97255682Smarkm     following DR#249.  For example, given a typedef T, "int T" and
97355682Smarkm     "int *T" are valid parameter declarations redeclaring T, while
97472448Sassar     "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
97555682Smarkm     abstract declarators rather than involving redundant parentheses;
97672448Sassar     the same applies with attributes inside the parentheses before
97755682Smarkm     "T".  */
97855682Smarkm  C_DTR_PARM
97957416Smarkm} c_dtr_syn;
98057416Smarkm
98172448Sassarstatic void c_parser_external_declaration (c_parser *);
98272448Sassarstatic void c_parser_asm_definition (c_parser *);
98372448Sassarstatic void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, bool);
98455682Smarkmstatic void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
98555682Smarkm				bool);
98655682Smarkmstatic struct c_typespec c_parser_enum_specifier (c_parser *);
98755682Smarkmstatic struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
98855682Smarkmstatic tree c_parser_struct_declaration (c_parser *);
98972448Sassarstatic struct c_typespec c_parser_typeof_specifier (c_parser *);
99055682Smarkmstatic struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
99172448Sassar						 bool *);
99255682Smarkmstatic struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
99355682Smarkm							c_dtr_syn, bool *);
99457416Smarkmstatic struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
99555682Smarkm							      bool,
99655682Smarkm							      struct c_declarator *);
99755682Smarkmstatic struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
99855682Smarkmstatic struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
99972448Sassarstatic struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
100072448Sassarstatic tree c_parser_simple_asm_expr (c_parser *);
100172448Sassarstatic tree c_parser_attributes (c_parser *);
100272448Sassarstatic struct c_type_name *c_parser_type_name (c_parser *);
100355682Smarkmstatic struct c_expr c_parser_initializer (c_parser *);
100490929Snectarstatic struct c_expr c_parser_braced_init (c_parser *, tree, bool);
100590929Snectarstatic void c_parser_initelt (c_parser *);
100655682Smarkmstatic void c_parser_initval (c_parser *, struct c_expr *);
100755682Smarkmstatic tree c_parser_compound_statement (c_parser *);
100855682Smarkmstatic void c_parser_compound_statement_nostart (c_parser *);
100955682Smarkmstatic void c_parser_label (c_parser *);
101055682Smarkmstatic void c_parser_statement (c_parser *);
101155682Smarkmstatic void c_parser_statement_after_labels (c_parser *);
101255682Smarkmstatic void c_parser_if_statement (c_parser *);
101355682Smarkmstatic void c_parser_switch_statement (c_parser *);
101455682Smarkmstatic void c_parser_while_statement (c_parser *);
101572448Sassarstatic void c_parser_do_statement (c_parser *);
101655682Smarkmstatic void c_parser_for_statement (c_parser *);
101772448Sassarstatic tree c_parser_asm_statement (c_parser *);
101855682Smarkmstatic tree c_parser_asm_operands (c_parser *, bool);
101955682Smarkmstatic tree c_parser_asm_clobbers (c_parser *);
102057416Smarkmstatic struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
102155682Smarkmstatic struct c_expr c_parser_conditional_expression (c_parser *,
102255682Smarkm						      struct c_expr *);
102355682Smarkmstatic struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
102455682Smarkmstatic struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
102555682Smarkmstatic struct c_expr c_parser_unary_expression (c_parser *);
102655682Smarkmstatic struct c_expr c_parser_sizeof_expression (c_parser *);
102755682Smarkmstatic struct c_expr c_parser_alignof_expression (c_parser *);
102855682Smarkmstatic struct c_expr c_parser_postfix_expression (c_parser *);
102955682Smarkmstatic struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
103055682Smarkm								   struct c_type_name *);
103155682Smarkmstatic struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
103255682Smarkm								struct c_expr);
103355682Smarkmstatic struct c_expr c_parser_expression (c_parser *);
103472448Sassarstatic struct c_expr c_parser_expression_conv (c_parser *);
103572448Sassarstatic tree c_parser_expr_list (c_parser *, bool);
103672448Sassarstatic void c_parser_omp_construct (c_parser *);
103772448Sassarstatic void c_parser_omp_threadprivate (c_parser *);
103878536Sassarstatic void c_parser_omp_barrier (c_parser *);
103978536Sassarstatic void c_parser_omp_flush (c_parser *);
104055682Smarkm
104178536Sassarenum pragma_context { pragma_external, pragma_stmt, pragma_compound };
104255682Smarkmstatic bool c_parser_pragma (c_parser *, enum pragma_context);
104355682Smarkm
104455682Smarkm/* These Objective-C parser functions are only ever called when
104555682Smarkm   compiling Objective-C.  */
104655682Smarkmstatic void c_parser_objc_class_definition (c_parser *);
104755682Smarkmstatic void c_parser_objc_class_instance_variables (c_parser *);
104855682Smarkmstatic void c_parser_objc_class_declaration (c_parser *);
104955682Smarkmstatic void c_parser_objc_alias_declaration (c_parser *);
105072448Sassarstatic void c_parser_objc_protocol_definition (c_parser *);
105155682Smarkmstatic enum tree_code c_parser_objc_method_type (c_parser *);
105272448Sassarstatic void c_parser_objc_method_definition (c_parser *);
105355682Smarkmstatic void c_parser_objc_methodprotolist (c_parser *);
105455682Smarkmstatic void c_parser_objc_methodproto (c_parser *);
105557416Smarkmstatic tree c_parser_objc_method_decl (c_parser *);
105655682Smarkmstatic tree c_parser_objc_type_name (c_parser *);
105755682Smarkmstatic tree c_parser_objc_protocol_refs (c_parser *);
105855682Smarkmstatic void c_parser_objc_try_catch_statement (c_parser *);
105955682Smarkmstatic void c_parser_objc_synchronized_statement (c_parser *);
106055682Smarkmstatic tree c_parser_objc_selector (c_parser *);
106172448Sassarstatic tree c_parser_objc_selector_arg (c_parser *);
106272448Sassarstatic tree c_parser_objc_receiver (c_parser *);
106372448Sassarstatic tree c_parser_objc_message_args (c_parser *);
106472448Sassarstatic tree c_parser_objc_keywordexpr (c_parser *);
106555682Smarkm
106690929Snectar/* Parse a translation unit (C90 6.7, C99 6.9).
106790929Snectar
106855682Smarkm   translation-unit:
106955682Smarkm     external-declarations
107055682Smarkm
107155682Smarkm   external-declarations:
107255682Smarkm     external-declaration
107355682Smarkm     external-declarations external-declaration
107455682Smarkm
107555682Smarkm   GNU extensions:
107655682Smarkm
107772448Sassar   translation-unit:
107855682Smarkm     empty
107972448Sassar*/
108055682Smarkm
108155682Smarkmstatic void
108257416Smarkmc_parser_translation_unit (c_parser *parser)
108355682Smarkm{
108455682Smarkm  if (c_parser_next_token_is (parser, CPP_EOF))
108555682Smarkm    {
108655682Smarkm      if (pedantic)
108755682Smarkm	pedwarn ("ISO C forbids an empty source file");
108855682Smarkm    }
108955682Smarkm  else
109055682Smarkm    {
109155682Smarkm      void *obstack_position = obstack_alloc (&parser_obstack, 0);
109255682Smarkm      do
109355682Smarkm	{
109455682Smarkm	  ggc_collect ();
109555682Smarkm	  c_parser_external_declaration (parser);
109672448Sassar	  obstack_free (&parser_obstack, obstack_position);
109772448Sassar	}
109872448Sassar      while (c_parser_next_token_is_not (parser, CPP_EOF));
109972448Sassar    }
110078536Sassar}
110178536Sassar
110255682Smarkm/* Parse an external declaration (C90 6.7, C99 6.9).
110378536Sassar
110455682Smarkm   external-declaration:
110555682Smarkm     function-definition
110655682Smarkm     declaration
110755682Smarkm
110855682Smarkm   GNU extensions:
110955682Smarkm
111055682Smarkm   external-declaration:
111155682Smarkm     asm-definition
111272448Sassar     ;
111355682Smarkm     __extension__ external-declaration
111472448Sassar
111555682Smarkm   Objective-C:
111655682Smarkm
111772448Sassar   external-declaration:
111857416Smarkm     objc-class-definition
111972448Sassar     objc-class-declaration
112072448Sassar     objc-alias-declaration
112172448Sassar     objc-protocol-definition
112255682Smarkm     objc-method-definition
112355682Smarkm     @end
112455682Smarkm*/
112555682Smarkm
112655682Smarkmstatic void
112755682Smarkmc_parser_external_declaration (c_parser *parser)
112872448Sassar{
112955682Smarkm  int ext;
113072448Sassar  switch (c_parser_peek_token (parser)->type)
113155682Smarkm    {
113255682Smarkm    case CPP_KEYWORD:
113355682Smarkm      switch (c_parser_peek_token (parser)->keyword)
113455682Smarkm	{
113555682Smarkm	case RID_EXTENSION:
113655682Smarkm	  ext = disable_extension_diagnostics ();
113755682Smarkm	  c_parser_consume_token (parser);
113855682Smarkm	  c_parser_external_declaration (parser);
113955682Smarkm	  restore_extension_diagnostics (ext);
114055682Smarkm	  break;
114155682Smarkm	case RID_ASM:
114255682Smarkm	  c_parser_asm_definition (parser);
114355682Smarkm	  break;
114472448Sassar	case RID_AT_INTERFACE:
114555682Smarkm	case RID_AT_IMPLEMENTATION:
114655682Smarkm	  gcc_assert (c_dialect_objc ());
114755682Smarkm	  c_parser_objc_class_definition (parser);
114855682Smarkm	  break;
114955682Smarkm	case RID_AT_CLASS:
115055682Smarkm	  gcc_assert (c_dialect_objc ());
115155682Smarkm	  c_parser_objc_class_declaration (parser);
115255682Smarkm	  break;
115355682Smarkm	case RID_AT_ALIAS:
115455682Smarkm	  gcc_assert (c_dialect_objc ());
115555682Smarkm	  c_parser_objc_alias_declaration (parser);
115655682Smarkm	  break;
115755682Smarkm	case RID_AT_PROTOCOL:
115855682Smarkm	  gcc_assert (c_dialect_objc ());
115955682Smarkm	  c_parser_objc_protocol_definition (parser);
116055682Smarkm	  break;
116172448Sassar	case RID_AT_END:
116272448Sassar	  gcc_assert (c_dialect_objc ());
116355682Smarkm	  c_parser_consume_token (parser);
116455682Smarkm	  objc_finish_implementation ();
116555682Smarkm	  break;
116672448Sassar	default:
116755682Smarkm	  goto decl_or_fndef;
116855682Smarkm	}
116955682Smarkm      break;
117055682Smarkm    case CPP_SEMICOLON:
117155682Smarkm      if (pedantic)
117255682Smarkm	pedwarn ("ISO C does not allow extra %<;%> outside of a function");
117355682Smarkm      c_parser_consume_token (parser);
117455682Smarkm      break;
117555682Smarkm    case CPP_PRAGMA:
117672448Sassar      c_parser_pragma (parser, pragma_external);
117755682Smarkm      break;
117872448Sassar    case CPP_PLUS:
117955682Smarkm    case CPP_MINUS:
118055682Smarkm      if (c_dialect_objc ())
118155682Smarkm	{
118255682Smarkm	  c_parser_objc_method_definition (parser);
118372448Sassar	  break;
118455682Smarkm	}
118555682Smarkm      /* Else fall through, and yield a syntax error trying to parse
118672448Sassar	 as a declaration or function definition.  */
118772448Sassar    default:
118872448Sassar    decl_or_fndef:
118972448Sassar      /* A declaration or a function definition.  We can only tell
119072448Sassar	 which after parsing the declaration specifiers, if any, and
119172448Sassar	 the first declarator.  */
119272448Sassar      c_parser_declaration_or_fndef (parser, true, true, false, true);
119372448Sassar      break;
119472448Sassar    }
119572448Sassar}
119672448Sassar
119772448Sassar
119872448Sassar/* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
119972448Sassar   6.7, 6.9.1).  If FNDEF_OK is true, a function definition is
120072448Sassar   accepted; otherwise (old-style parameter declarations) only other
120172448Sassar   declarations are accepted.  If NESTED is true, we are inside a
120272448Sassar   function or parsing old-style parameter declarations; any functions
120372448Sassar   encountered are nested functions and declaration specifiers are
120472448Sassar   required; otherwise we are at top level and functions are normal
120572448Sassar   functions and declaration specifiers may be optional.  If EMPTY_OK
120672448Sassar   is true, empty declarations are OK (subject to all other
120772448Sassar   constraints); otherwise (old-style parameter declarations) they are
120872448Sassar   diagnosed.  If START_ATTR_OK is true, the declaration specifiers
120972448Sassar   may start with attributes; otherwise they may not.
121072448Sassar
121172448Sassar   declaration:
121272448Sassar     declaration-specifiers init-declarator-list[opt] ;
121372448Sassar
121472448Sassar   function-definition:
121572448Sassar     declaration-specifiers[opt] declarator declaration-list[opt]
121672448Sassar       compound-statement
121772448Sassar
121872448Sassar   declaration-list:
121972448Sassar     declaration
122072448Sassar     declaration-list declaration
122172448Sassar
122272448Sassar   init-declarator-list:
122372448Sassar     init-declarator
122472448Sassar     init-declarator-list , init-declarator
122572448Sassar
122672448Sassar   init-declarator:
122772448Sassar     declarator simple-asm-expr[opt] attributes[opt]
122872448Sassar     declarator simple-asm-expr[opt] attributes[opt] = initializer
122972448Sassar
123072448Sassar   GNU extensions:
123172448Sassar
123272448Sassar   nested-function-definition:
123372448Sassar     declaration-specifiers declarator declaration-list[opt]
123472448Sassar       compound-statement
123572448Sassar
123672448Sassar   The simple-asm-expr and attributes are GNU extensions.
123772448Sassar
123872448Sassar   This function does not handle __extension__; that is handled in its
123972448Sassar   callers.  ??? Following the old parser, __extension__ may start
124072448Sassar   external declarations, declarations in functions and declarations
124172448Sassar   at the start of "for" loops, but not old-style parameter
124272448Sassar   declarations.
124372448Sassar
124472448Sassar   C99 requires declaration specifiers in a function definition; the
124572448Sassar   absence is diagnosed through the diagnosis of implicit int.  In GNU
124672448Sassar   C we also allow but diagnose declarations without declaration
124772448Sassar   specifiers, but only at top level (elsewhere they conflict with
124872448Sassar   other syntax).
124972448Sassar
125072448Sassar   OpenMP:
125172448Sassar
125272448Sassar   declaration:
125372448Sassar     threadprivate-directive  */
125472448Sassar
125572448Sassarstatic void
125655682Smarkmc_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
125755682Smarkm			       bool nested, bool start_attr_ok)
125855682Smarkm{
125955682Smarkm  struct c_declspecs *specs;
126055682Smarkm  tree prefix_attrs;
126155682Smarkm  tree all_prefix_attrs;
126255682Smarkm  bool diagnosed_no_specs = false;
126355682Smarkm
126455682Smarkm  specs = build_null_declspecs ();
126555682Smarkm  c_parser_declspecs (parser, specs, true, true, start_attr_ok);
126655682Smarkm  if (parser->error)
126755682Smarkm    {
126855682Smarkm      c_parser_skip_to_end_of_block_or_statement (parser);
126955682Smarkm      return;
127055682Smarkm    }
127155682Smarkm  if (nested && !specs->declspecs_seen_p)
127255682Smarkm    {
127355682Smarkm      c_parser_error (parser, "expected declaration specifiers");
127455682Smarkm      c_parser_skip_to_end_of_block_or_statement (parser);
127555682Smarkm      return;
127655682Smarkm    }
127755682Smarkm  finish_declspecs (specs);
127855682Smarkm  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
127955682Smarkm    {
128055682Smarkm      if (empty_ok)
128155682Smarkm	shadow_tag (specs);
128255682Smarkm      else
128355682Smarkm	{
128455682Smarkm	  shadow_tag_warned (specs, 1);
128555682Smarkm	  pedwarn ("empty declaration");
128655682Smarkm	}
128755682Smarkm      c_parser_consume_token (parser);
128855682Smarkm      return;
128955682Smarkm    }
129055682Smarkm  pending_xref_error ();
129155682Smarkm  prefix_attrs = specs->attrs;
129255682Smarkm  all_prefix_attrs = prefix_attrs;
129355682Smarkm  specs->attrs = NULL_TREE;
129455682Smarkm  while (true)
129555682Smarkm    {
129655682Smarkm      struct c_declarator *declarator;
129755682Smarkm      bool dummy = false;
129855682Smarkm      tree fnbody;
129972448Sassar      /* Declaring either one or more declarators (in which case we
130055682Smarkm	 should diagnose if there were no declaration specifiers) or a
130155682Smarkm	 function definition (in which case the diagnostic for
130255682Smarkm	 implicit int suffices).  */
130355682Smarkm      declarator = c_parser_declarator (parser, specs->type_seen_p,
130455682Smarkm					C_DTR_NORMAL, &dummy);
130555682Smarkm      if (declarator == NULL)
130655682Smarkm	{
130772448Sassar	  c_parser_skip_to_end_of_block_or_statement (parser);
130855682Smarkm	  return;
130955682Smarkm	}
131055682Smarkm      if (c_parser_next_token_is (parser, CPP_EQ)
131155682Smarkm	  || c_parser_next_token_is (parser, CPP_COMMA)
131255682Smarkm	  || c_parser_next_token_is (parser, CPP_SEMICOLON)
131355682Smarkm	  || c_parser_next_token_is_keyword (parser, RID_ASM)
131455682Smarkm	  || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
131572448Sassar	{
131672448Sassar	  tree asm_name = NULL_TREE;
131755682Smarkm	  tree postfix_attrs = NULL_TREE;
131855682Smarkm	  if (!diagnosed_no_specs && !specs->declspecs_seen_p)
131955682Smarkm	    {
132055682Smarkm	      diagnosed_no_specs = true;
132155682Smarkm	      pedwarn ("data definition has no type or storage class");
132255682Smarkm	    }
132355682Smarkm	  /* Having seen a data definition, there cannot now be a
132455682Smarkm	     function definition.  */
132555682Smarkm	  fndef_ok = false;
132655682Smarkm	  if (c_parser_next_token_is_keyword (parser, RID_ASM))
132755682Smarkm	    asm_name = c_parser_simple_asm_expr (parser);
132855682Smarkm	  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
132955682Smarkm	    postfix_attrs = c_parser_attributes (parser);
133055682Smarkm	  if (c_parser_next_token_is (parser, CPP_EQ))
133155682Smarkm	    {
133255682Smarkm	      tree d;
133355682Smarkm	      struct c_expr init;
133455682Smarkm	      c_parser_consume_token (parser);
133572448Sassar	      /* The declaration of the variable is in effect while
133655682Smarkm		 its initializer is parsed.  */
133755682Smarkm	      d = start_decl (declarator, specs, true,
133855682Smarkm			      chainon (postfix_attrs, all_prefix_attrs));
133955682Smarkm	      if (!d)
134055682Smarkm		d = error_mark_node;
134155682Smarkm	      start_init (d, asm_name, global_bindings_p ());
134255682Smarkm	      init = c_parser_initializer (parser);
134355682Smarkm	      finish_init ();
134472448Sassar	      if (d != error_mark_node)
134555682Smarkm		{
134655682Smarkm		  maybe_warn_string_init (TREE_TYPE (d), init);
134755682Smarkm		  finish_decl (d, init.value, asm_name);
134855682Smarkm		}
134955682Smarkm	    }
135055682Smarkm	  else
135155682Smarkm	    {
135255682Smarkm	      tree d = start_decl (declarator, specs, false,
135355682Smarkm				   chainon (postfix_attrs,
135455682Smarkm					    all_prefix_attrs));
135555682Smarkm	      if (d)
135655682Smarkm		finish_decl (d, NULL_TREE, asm_name);
135755682Smarkm	    }
135855682Smarkm	  if (c_parser_next_token_is (parser, CPP_COMMA))
135955682Smarkm	    {
136055682Smarkm	      c_parser_consume_token (parser);
136155682Smarkm	      if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
136255682Smarkm		all_prefix_attrs = chainon (c_parser_attributes (parser),
136355682Smarkm					    prefix_attrs);
136455682Smarkm	      else
136572448Sassar		all_prefix_attrs = prefix_attrs;
136672448Sassar	      continue;
136772448Sassar	    }
136872448Sassar	  else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
136972448Sassar	    {
137072448Sassar	      c_parser_consume_token (parser);
137172448Sassar	      return;
137272448Sassar	    }
137372448Sassar	  else
137472448Sassar	    {
137572448Sassar	      c_parser_error (parser, "expected %<,%> or %<;%>");
137672448Sassar	      c_parser_skip_to_end_of_block_or_statement (parser);
137772448Sassar	      return;
137872448Sassar	    }
137972448Sassar	}
138072448Sassar      else if (!fndef_ok)
138172448Sassar	{
138272448Sassar	  c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
138372448Sassar			  "%<asm%> or %<__attribute__%>");
138472448Sassar	  c_parser_skip_to_end_of_block_or_statement (parser);
138555682Smarkm	  return;
138655682Smarkm	}
138755682Smarkm      /* Function definition (nested or otherwise).  */
138855682Smarkm      if (nested)
138955682Smarkm	{
139055682Smarkm	  if (pedantic)
139155682Smarkm	    pedwarn ("ISO C forbids nested functions");
139255682Smarkm	  push_function_context ();
139355682Smarkm	}
139455682Smarkm      if (!start_function (specs, declarator, all_prefix_attrs))
139555682Smarkm	{
139655682Smarkm	  /* This can appear in many cases looking nothing like a
139755682Smarkm	     function definition, so we don't give a more specific
139855682Smarkm	     error suggesting there was one.  */
139972448Sassar	  c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
140072448Sassar			  "or %<__attribute__%>");
140172448Sassar	  if (nested)
140255682Smarkm	    pop_function_context ();
140355682Smarkm	  break;
140455682Smarkm	}
140555682Smarkm      /* Parse old-style parameter declarations.  ??? Attributes are
140655682Smarkm	 not allowed to start declaration specifiers here because of a
140755682Smarkm	 syntax conflict between a function declaration with attribute
140855682Smarkm	 suffix and a function definition with an attribute prefix on
140955682Smarkm	 first old-style parameter declaration.  Following the old
141055682Smarkm	 parser, they are not accepted on subsequent old-style
141155682Smarkm	 parameter declarations either.  However, there is no
141255682Smarkm	 ambiguity after the first declaration, nor indeed on the
141355682Smarkm	 first as long as we don't allow postfix attributes after a
141455682Smarkm	 declarator with a nonempty identifier list in a definition;
141555682Smarkm	 and postfix attributes have never been accepted here in
141655682Smarkm	 function definitions either.  */
141755682Smarkm      while (c_parser_next_token_is_not (parser, CPP_EOF)
141855682Smarkm	     && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
141955682Smarkm	c_parser_declaration_or_fndef (parser, false, false, true, false);
142055682Smarkm      DECL_SOURCE_LOCATION (current_function_decl)
142155682Smarkm	= c_parser_peek_token (parser)->location;
142255682Smarkm      store_parm_decls ();
142355682Smarkm      fnbody = c_parser_compound_statement (parser);
142455682Smarkm      if (nested)
142555682Smarkm	{
142655682Smarkm	  tree decl = current_function_decl;
142755682Smarkm	  add_stmt (fnbody);
142855682Smarkm	  finish_function ();
142955682Smarkm	  pop_function_context ();
143055682Smarkm	  add_stmt (build_stmt (DECL_EXPR, decl));
143178536Sassar	}
143278536Sassar      else
143355682Smarkm	{
143478536Sassar	  add_stmt (fnbody);
143555682Smarkm	  finish_function ();
143655682Smarkm	}
143755682Smarkm      break;
143855682Smarkm    }
143955682Smarkm}
144055682Smarkm
144155682Smarkm/* Parse an asm-definition (asm() outside a function body).  This is a
144255682Smarkm   GNU extension.
144355682Smarkm
144455682Smarkm   asm-definition:
144555682Smarkm     simple-asm-expr ;
144655682Smarkm*/
144755682Smarkm
144855682Smarkmstatic void
144955682Smarkmc_parser_asm_definition (c_parser *parser)
145055682Smarkm{
145155682Smarkm  tree asm_str = c_parser_simple_asm_expr (parser);
145255682Smarkm  if (asm_str)
145355682Smarkm    cgraph_add_asm_node (asm_str);
145455682Smarkm  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
145555682Smarkm}
145655682Smarkm
145755682Smarkm/* Parse some declaration specifiers (possibly none) (C90 6.5, C99
145855682Smarkm   6.7), adding them to SPECS (which may already include some).
145955682Smarkm   Storage class specifiers are accepted iff SCSPEC_OK; type
146055682Smarkm   specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
146155682Smarkm   the start iff START_ATTR_OK.
146278536Sassar
146378536Sassar   declaration-specifiers:
146455682Smarkm     storage-class-specifier declaration-specifiers[opt]
146578536Sassar     type-specifier declaration-specifiers[opt]
146672448Sassar     type-qualifier declaration-specifiers[opt]
146755682Smarkm     function-specifier declaration-specifiers[opt]
146872448Sassar
146972448Sassar   Function specifiers (inline) are from C99, and are currently
147072448Sassar   handled as storage class specifiers, as is __thread.
147155682Smarkm
147255682Smarkm   C90 6.5.1, C99 6.7.1:
147355682Smarkm   storage-class-specifier:
147472448Sassar     typedef
147555682Smarkm     extern
147655682Smarkm     static
147755682Smarkm     auto
147855682Smarkm     register
147955682Smarkm
148055682Smarkm   C99 6.7.4:
148190929Snectar   function-specifier:
148278536Sassar     inline
148355682Smarkm
148455682Smarkm   C90 6.5.2, C99 6.7.2:
148555682Smarkm   type-specifier:
148655682Smarkm     void
148778536Sassar     char
148855682Smarkm     short
148978536Sassar     int
149078536Sassar     long
149178536Sassar     float
149255682Smarkm     double
149378536Sassar     signed
149478536Sassar     unsigned
149578536Sassar     _Bool
149678536Sassar     _Complex
149778536Sassar     [_Imaginary removed in C99 TC2]
149878536Sassar     struct-or-union-specifier
149978536Sassar     enum-specifier
150055682Smarkm     typedef-name
150178536Sassar
150255682Smarkm   (_Bool and _Complex are new in C99.)
150355682Smarkm
150455682Smarkm   C90 6.5.3, C99 6.7.3:
150555682Smarkm
150655682Smarkm   type-qualifier:
150755682Smarkm     const
150878536Sassar     restrict
150978536Sassar     volatile
151055682Smarkm
151155682Smarkm   (restrict is new in C99.)
151255682Smarkm
151355682Smarkm   GNU extensions:
151455682Smarkm
151578536Sassar   declaration-specifiers:
151678536Sassar     attributes declaration-specifiers[opt]
151755682Smarkm
151855682Smarkm   storage-class-specifier:
151955682Smarkm     __thread
152055682Smarkm
152155682Smarkm   type-specifier:
152255682Smarkm     typeof-specifier
152355682Smarkm     _Decimal32
152455682Smarkm     _Decimal64
152555682Smarkm     _Decimal128
152655682Smarkm
152755682Smarkm   Objective-C:
152855682Smarkm
152955682Smarkm   type-specifier:
153055682Smarkm     class-name objc-protocol-refs[opt]
153155682Smarkm     typedef-name objc-protocol-refs
153255682Smarkm     objc-protocol-refs
153355682Smarkm*/
153478536Sassar
153578536Sassarstatic void
153678536Sassarc_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
153755682Smarkm		    bool scspec_ok, bool typespec_ok, bool start_attr_ok)
153878536Sassar{
153978536Sassar  bool attrs_ok = start_attr_ok;
154078536Sassar  bool seen_type = specs->type_seen_p;
154155682Smarkm  while (c_parser_next_token_is (parser, CPP_NAME)
154278536Sassar	 || c_parser_next_token_is (parser, CPP_KEYWORD)
154355682Smarkm	 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
154478536Sassar    {
154578536Sassar      struct c_typespec t;
154655682Smarkm      tree attrs;
154778536Sassar      if (c_parser_next_token_is (parser, CPP_NAME))
154855682Smarkm	{
154955682Smarkm	  tree value = c_parser_peek_token (parser)->value;
155055682Smarkm	  c_id_kind kind = c_parser_peek_token (parser)->id_kind;
155155682Smarkm	  /* This finishes the specifiers unless a type name is OK, it
155255682Smarkm	     is declared as a type name and a type name hasn't yet
155372448Sassar	     been seen.  */
155455682Smarkm	  if (!typespec_ok || seen_type
155555682Smarkm	      || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
155655682Smarkm	    break;
155755682Smarkm	  c_parser_consume_token (parser);
155855682Smarkm	  seen_type = true;
155972448Sassar	  attrs_ok = true;
156055682Smarkm	  if (kind == C_ID_TYPENAME
156155682Smarkm	      && (!c_dialect_objc ()
156278536Sassar		  || c_parser_next_token_is_not (parser, CPP_LESS)))
156378536Sassar	    {
156455682Smarkm	      t.kind = ctsk_typedef;
156578536Sassar	      /* For a typedef name, record the meaning, not the name.
156655682Smarkm		 In case of 'foo foo, bar;'.  */
156778536Sassar	      t.spec = lookup_name (value);
156855682Smarkm	    }
156955682Smarkm	  else
157055682Smarkm	    {
157155682Smarkm	      tree proto = NULL_TREE;
157255682Smarkm	      gcc_assert (c_dialect_objc ());
157355682Smarkm	      t.kind = ctsk_objc;
157455682Smarkm	      if (c_parser_next_token_is (parser, CPP_LESS))
157555682Smarkm		proto = c_parser_objc_protocol_refs (parser);
157655682Smarkm	      t.spec = objc_get_protocol_qualified_type (value, proto);
157755682Smarkm	    }
157855682Smarkm	  declspecs_add_type (specs, t);
157955682Smarkm	  continue;
158055682Smarkm	}
158155682Smarkm      if (c_parser_next_token_is (parser, CPP_LESS))
158255682Smarkm	{
158355682Smarkm	  /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
158455682Smarkm	     nisse@lysator.liu.se.  */
158555682Smarkm	  tree proto;
158655682Smarkm	  gcc_assert (c_dialect_objc ());
158755682Smarkm	  if (!typespec_ok || seen_type)
158855682Smarkm	    break;
158955682Smarkm	  proto = c_parser_objc_protocol_refs (parser);
159078536Sassar	  t.kind = ctsk_objc;
159178536Sassar	  t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
159278536Sassar	  declspecs_add_type (specs, t);
159355682Smarkm	  continue;
159478536Sassar	}
159555682Smarkm      gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
159655682Smarkm      switch (c_parser_peek_token (parser)->keyword)
159755682Smarkm	{
159855682Smarkm	case RID_STATIC:
159955682Smarkm	case RID_EXTERN:
160055682Smarkm	case RID_REGISTER:
160155682Smarkm	case RID_TYPEDEF:
160255682Smarkm	case RID_INLINE:
160355682Smarkm	case RID_AUTO:
160478536Sassar	case RID_THREAD:
160578536Sassar	  if (!scspec_ok)
160678536Sassar	    goto out;
160755682Smarkm	  attrs_ok = true;
160878536Sassar	  /* TODO: Distinguish between function specifiers (inline)
160955682Smarkm	     and storage class specifiers, either here or in
161055682Smarkm	     declspecs_add_scspec.  */
161155682Smarkm	  declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
161255682Smarkm	  c_parser_consume_token (parser);
161355682Smarkm	  break;
161455682Smarkm	case RID_UNSIGNED:
161555682Smarkm	case RID_LONG:
161655682Smarkm	case RID_SHORT:
161778536Sassar	case RID_SIGNED:
161878536Sassar	case RID_COMPLEX:
161978536Sassar	case RID_INT:
162055682Smarkm	case RID_CHAR:
162178536Sassar	case RID_FLOAT:
162255682Smarkm	case RID_DOUBLE:
162355682Smarkm	case RID_VOID:
162455682Smarkm	case RID_DFLOAT32:
162555682Smarkm	case RID_DFLOAT64:
162655682Smarkm	case RID_DFLOAT128:
162755682Smarkm	case RID_BOOL:
162855682Smarkm	  if (!typespec_ok)
162972448Sassar	    goto out;
163078536Sassar	  attrs_ok = true;
163178536Sassar	  seen_type = true;
163255682Smarkm	  OBJC_NEED_RAW_IDENTIFIER (1);
163355682Smarkm	  t.kind = ctsk_resword;
163472448Sassar	  t.spec = c_parser_peek_token (parser)->value;
163572448Sassar	  declspecs_add_type (specs, t);
163672448Sassar	  c_parser_consume_token (parser);
163755682Smarkm	  break;
163872448Sassar	case RID_ENUM:
163955682Smarkm	  if (!typespec_ok)
164055682Smarkm	    goto out;
164172448Sassar	  attrs_ok = true;
164278536Sassar	  seen_type = true;
164378536Sassar	  t = c_parser_enum_specifier (parser);
164455682Smarkm	  declspecs_add_type (specs, t);
164555682Smarkm	  break;
164672448Sassar	case RID_STRUCT:
164772448Sassar	case RID_UNION:
164872448Sassar	  if (!typespec_ok)
164955682Smarkm	    goto out;
165055682Smarkm	  attrs_ok = true;
165155682Smarkm	  seen_type = true;
165255682Smarkm	  t = c_parser_struct_or_union_specifier (parser);
165355682Smarkm	  declspecs_add_type (specs, t);
165472448Sassar	  break;
165555682Smarkm	case RID_TYPEOF:
165655682Smarkm	  /* ??? The old parser rejected typeof after other type
165772448Sassar	     specifiers, but is a syntax error the best way of
165878536Sassar	     handling this?  */
165978536Sassar	  if (!typespec_ok || seen_type)
166055682Smarkm	    goto out;
166155682Smarkm	  attrs_ok = true;
166272448Sassar	  seen_type = true;
166372448Sassar	  t = c_parser_typeof_specifier (parser);
166472448Sassar	  declspecs_add_type (specs, t);
166555682Smarkm	  break;
166655682Smarkm	case RID_CONST:
166755682Smarkm	case RID_VOLATILE:
166855682Smarkm	case RID_RESTRICT:
166955682Smarkm	  attrs_ok = true;
167072448Sassar	  declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
167155682Smarkm	  c_parser_consume_token (parser);
167255682Smarkm	  break;
167372448Sassar	case RID_ATTRIBUTE:
167478536Sassar	  if (!attrs_ok)
167578536Sassar	    goto out;
167655682Smarkm	  attrs = c_parser_attributes (parser);
167755682Smarkm	  declspecs_add_attrs (specs, attrs);
167872448Sassar	  break;
167972448Sassar	default:
1680103426Snectar	  goto out;
168155682Smarkm	}
1682103426Snectar    }
168355682Smarkm out: ;
1684103426Snectar}
1685103426Snectar
1686103426Snectar/* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1687103426Snectar
168872448Sassar   enum-specifier:
168972448Sassar     enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
169072448Sassar     enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
169172448Sassar     enum attributes[opt] identifier
169272448Sassar
169378536Sassar   The form with trailing comma is new in C99.  The forms with
169478536Sassar   attributes are GNU extensions.  In GNU C, we accept any expression
169572448Sassar   without commas in the syntax (assignment expressions, not just
169672448Sassar   conditional expressions); assignment expressions will be diagnosed
169772448Sassar   as non-constant.
169872448Sassar
169972448Sassar   enumerator-list:
170072448Sassar     enumerator
170172448Sassar     enumerator-list , enumerator
170272448Sassar
170372448Sassar   enumerator:
170472448Sassar     enumeration-constant
170572448Sassar     enumeration-constant = constant-expression
170672448Sassar*/
170772448Sassar
170872448Sassarstatic struct c_typespec
170972448Sassarc_parser_enum_specifier (c_parser *parser)
171072448Sassar{
171178536Sassar  struct c_typespec ret;
171278536Sassar  tree attrs;
171372448Sassar  tree ident = NULL_TREE;
171472448Sassar  gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
171572448Sassar  c_parser_consume_token (parser);
171672448Sassar  attrs = c_parser_attributes (parser);
171772448Sassar  if (c_parser_next_token_is (parser, CPP_NAME))
171872448Sassar    {
171972448Sassar      ident = c_parser_peek_token (parser)->value;
172072448Sassar      c_parser_consume_token (parser);
172172448Sassar    }
172272448Sassar  if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
172372448Sassar    {
172472448Sassar      /* Parse an enum definition.  */
172572448Sassar      tree type = start_enum (ident);
172672448Sassar      tree postfix_attrs;
172772448Sassar      /* We chain the enumerators in reverse order, then put them in
172872448Sassar	 forward order at the end.  */
172972448Sassar      tree values = NULL_TREE;
173072448Sassar      c_parser_consume_token (parser);
173172448Sassar      while (true)
173272448Sassar	{
173372448Sassar	  tree enum_id;
173478536Sassar	  tree enum_value;
173578536Sassar	  tree enum_decl;
173672448Sassar	  bool seen_comma;
173772448Sassar	  if (c_parser_next_token_is_not (parser, CPP_NAME))
173872448Sassar	    {
173972448Sassar	      c_parser_error (parser, "expected identifier");
174072448Sassar	      c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
174172448Sassar	      values = error_mark_node;
174272448Sassar	      break;
174372448Sassar	    }
174472448Sassar	  enum_id = c_parser_peek_token (parser)->value;
174572448Sassar	  c_parser_consume_token (parser);
174672448Sassar	  if (c_parser_next_token_is (parser, CPP_EQ))
174790929Snectar	    {
174872448Sassar	      c_parser_consume_token (parser);
174972448Sassar	      enum_value = c_parser_expr_no_commas (parser, NULL).value;
175072448Sassar	    }
175172448Sassar	  else
175272448Sassar	    enum_value = NULL_TREE;
175372448Sassar	  enum_decl = build_enumerator (enum_id, enum_value);
175472448Sassar	  TREE_CHAIN (enum_decl) = values;
175572448Sassar	  values = enum_decl;
175672448Sassar	  seen_comma = false;
175772448Sassar	  if (c_parser_next_token_is (parser, CPP_COMMA))
175872448Sassar	    {
175972448Sassar	      seen_comma = true;
176072448Sassar	      c_parser_consume_token (parser);
176172448Sassar	    }
176272448Sassar	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
176372448Sassar	    {
176472448Sassar	      if (seen_comma && pedantic && !flag_isoc99)
176572448Sassar		pedwarn ("comma at end of enumerator list");
176672448Sassar	      c_parser_consume_token (parser);
176772448Sassar	      break;
176872448Sassar	    }
176972448Sassar	  if (!seen_comma)
177072448Sassar	    {
177172448Sassar	      c_parser_error (parser, "expected %<,%> or %<}%>");
177272448Sassar	      c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
177372448Sassar	      values = error_mark_node;
177472448Sassar	      break;
177572448Sassar	    }
177672448Sassar	}
177772448Sassar      postfix_attrs = c_parser_attributes (parser);
177872448Sassar      ret.spec = finish_enum (type, nreverse (values),
177972448Sassar			      chainon (attrs, postfix_attrs));
178072448Sassar      ret.kind = ctsk_tagdef;
178172448Sassar      return ret;
178272448Sassar    }
178372448Sassar  else if (!ident)
178472448Sassar    {
178572448Sassar      c_parser_error (parser, "expected %<{%>");
178672448Sassar      ret.spec = error_mark_node;
178772448Sassar      ret.kind = ctsk_tagref;
178872448Sassar      return ret;
178972448Sassar    }
179078536Sassar  ret = parser_xref_tag (ENUMERAL_TYPE, ident);
179178536Sassar  /* In ISO C, enumerated types can be referred to only if already
179272448Sassar     defined.  */
179372448Sassar  if (pedantic && !COMPLETE_TYPE_P (ret.spec))
179472448Sassar    pedwarn ("ISO C forbids forward references to %<enum%> types");
179572448Sassar  return ret;
179672448Sassar}
179772448Sassar
179872448Sassar/* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
179972448Sassar
180072448Sassar   struct-or-union-specifier:
180172448Sassar     struct-or-union attributes[opt] identifier[opt]
180272448Sassar       { struct-contents } attributes[opt]
180390929Snectar     struct-or-union attributes[opt] identifier
180472448Sassar
180572448Sassar   struct-contents:
180672448Sassar     struct-declaration-list
180772448Sassar
180872448Sassar   struct-declaration-list:
180972448Sassar     struct-declaration ;
181072448Sassar     struct-declaration-list struct-declaration ;
181172448Sassar
181272448Sassar   GNU extensions:
181372448Sassar
181472448Sassar   struct-contents:
181572448Sassar     empty
181672448Sassar     struct-declaration
181772448Sassar     struct-declaration-list struct-declaration
181872448Sassar
181972448Sassar   struct-declaration-list:
182072448Sassar     struct-declaration-list ;
182172448Sassar     ;
182272448Sassar
182372448Sassar   (Note that in the syntax here, unlike that in ISO C, the semicolons
182472448Sassar   are included here rather than in struct-declaration, in order to
182572448Sassar   describe the syntax with extra semicolons and missing semicolon at
182672448Sassar   end.)
182772448Sassar
182872448Sassar   Objective-C:
182972448Sassar
183072448Sassar   struct-declaration-list:
183172448Sassar     @defs ( class-name )
183272448Sassar
183372448Sassar   (Note this does not include a trailing semicolon, but can be
183472448Sassar   followed by further declarations, and gets a pedwarn-if-pedantic
183572448Sassar   when followed by a semicolon.)  */
183672448Sassar
183772448Sassarstatic struct c_typespec
183872448Sassarc_parser_struct_or_union_specifier (c_parser *parser)
183972448Sassar{
184072448Sassar  struct c_typespec ret;
184172448Sassar  tree attrs;
184272448Sassar  tree ident = NULL_TREE;
184372448Sassar  enum tree_code code;
184472448Sassar  switch (c_parser_peek_token (parser)->keyword)
184578536Sassar    {
184678536Sassar    case RID_STRUCT:
184772448Sassar      code = RECORD_TYPE;
184878536Sassar      break;
184972448Sassar    case RID_UNION:
185078536Sassar      code = UNION_TYPE;
185172448Sassar      break;
185272448Sassar    default:
185372448Sassar      gcc_unreachable ();
185472448Sassar    }
185572448Sassar  c_parser_consume_token (parser);
185672448Sassar  attrs = c_parser_attributes (parser);
185772448Sassar  if (c_parser_next_token_is (parser, CPP_NAME))
185872448Sassar    {
1859102647Snectar      ident = c_parser_peek_token (parser)->value;
1860102647Snectar      c_parser_consume_token (parser);
186172448Sassar    }
1862102647Snectar  if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
186372448Sassar    {
1864102647Snectar      /* Parse a struct or union definition.  Start the scope of the
1865102647Snectar	 tag before parsing components.  */
186672448Sassar      tree type = start_struct (code, ident);
1867102647Snectar      tree postfix_attrs;
186872448Sassar      /* We chain the components in reverse order, then put them in
1869102647Snectar	 forward order at the end.  Each struct-declaration may
1870102647Snectar	 declare multiple components (comma-separated), so we must use
187172448Sassar	 chainon to join them, although when parsing each
187272448Sassar	 struct-declaration we can use TREE_CHAIN directly.
187372448Sassar
187472448Sassar	 The theory behind all this is that there will be more
1875102647Snectar	 semicolon separated fields than comma separated fields, and
1876102647Snectar	 so we'll be minimizing the number of node traversals required
187772448Sassar	 by chainon.  */
187872448Sassar      tree contents = NULL_TREE;
1879102647Snectar      c_parser_consume_token (parser);
1880102647Snectar      /* Handle the Objective-C @defs construct,
188172448Sassar	 e.g. foo(sizeof(struct{ @defs(ClassName) }));.  */
188272448Sassar      if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
188372448Sassar	{
1884102647Snectar	  tree name;
1885102647Snectar	  gcc_assert (c_dialect_objc ());
188672448Sassar	  c_parser_consume_token (parser);
1887102647Snectar	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
188872448Sassar	    goto end_at_defs;
188972448Sassar	  if (c_parser_next_token_is (parser, CPP_NAME)
189072448Sassar	      && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
189172448Sassar	    {
189272448Sassar	      name = c_parser_peek_token (parser)->value;
189372448Sassar	      c_parser_consume_token (parser);
189472448Sassar	    }
189572448Sassar	  else
189672448Sassar	    {
189772448Sassar	      c_parser_error (parser, "expected class name");
189872448Sassar	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
189972448Sassar	      goto end_at_defs;
190072448Sassar	    }
1901102647Snectar	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
1902102647Snectar				     "expected %<)%>");
190372448Sassar	  contents = nreverse (objc_get_class_ivars (name));
190472448Sassar	}
190572448Sassar    end_at_defs:
190672448Sassar      /* Parse the struct-declarations and semicolons.  Problems with
190778536Sassar	 semicolons are diagnosed here; empty structures are diagnosed
190878536Sassar	 elsewhere.  */
190955682Smarkm      while (true)
191055682Smarkm	{
191172448Sassar	  tree decls;
191272448Sassar	  /* Parse any stray semicolon.  */
191372448Sassar	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
191455682Smarkm	    {
1915102647Snectar	      if (pedantic)
1916102647Snectar		pedwarn ("extra semicolon in struct or union specified");
1917102647Snectar	      c_parser_consume_token (parser);
191855682Smarkm	      continue;
191972448Sassar	    }
192078536Sassar	  /* Stop if at the end of the struct or union contents.  */
192172448Sassar	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
192278536Sassar	    {
192355682Smarkm	      c_parser_consume_token (parser);
192455682Smarkm	      break;
192572448Sassar	    }
192655682Smarkm	  /* Accept #pragmas at struct scope.  */
192755682Smarkm	  if (c_parser_next_token_is (parser, CPP_PRAGMA))
192872448Sassar	    {
192955682Smarkm	      c_parser_pragma (parser, pragma_external);
193078536Sassar	      continue;
193178536Sassar	    }
193278536Sassar	  /* Parse some comma-separated declarations, but not the
193378536Sassar	     trailing semicolon if any.  */
193478536Sassar	  decls = c_parser_struct_declaration (parser);
193578536Sassar	  contents = chainon (decls, contents);
193678536Sassar	  /* If no semicolon follows, either we have a parse error or
193778536Sassar	     are at the end of the struct or union and should
193878536Sassar	     pedwarn.  */
193978536Sassar	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
194055682Smarkm	    c_parser_consume_token (parser);
194178536Sassar	  else
194278536Sassar	    {
194378536Sassar	      if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
194478536Sassar		pedwarn ("no semicolon at end of struct or union");
194578536Sassar	      else
194678536Sassar		{
194778536Sassar		  c_parser_error (parser, "expected %<;%>");
194878536Sassar		  c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
194978536Sassar		  break;
195078536Sassar		}
195178536Sassar	    }
195278536Sassar	}
195378536Sassar      postfix_attrs = c_parser_attributes (parser);
195478536Sassar      ret.spec = finish_struct (type, nreverse (contents),
195578536Sassar				chainon (attrs, postfix_attrs));
195678536Sassar      ret.kind = ctsk_tagdef;
195778536Sassar      return ret;
195878536Sassar    }
195978536Sassar  else if (!ident)
196078536Sassar    {
196178536Sassar      c_parser_error (parser, "expected %<{%>");
196278536Sassar      ret.spec = error_mark_node;
196378536Sassar      ret.kind = ctsk_tagref;
196478536Sassar      return ret;
196578536Sassar    }
196678536Sassar  ret = parser_xref_tag (code, ident);
196778536Sassar  return ret;
196878536Sassar}
196978536Sassar
197078536Sassar/* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
197178536Sassar   the trailing semicolon.
197278536Sassar
197378536Sassar   struct-declaration:
197478536Sassar     specifier-qualifier-list struct-declarator-list
197578536Sassar
197678536Sassar   specifier-qualifier-list:
197778536Sassar     type-specifier specifier-qualifier-list[opt]
197878536Sassar     type-qualifier specifier-qualifier-list[opt]
197978536Sassar     attributes specifier-qualifier-list[opt]
198090929Snectar
198178536Sassar   struct-declarator-list:
198278536Sassar     struct-declarator
198378536Sassar     struct-declarator-list , attributes[opt] struct-declarator
198478536Sassar
198578536Sassar   struct-declarator:
198678536Sassar     declarator attributes[opt]
198778536Sassar     declarator[opt] : constant-expression attributes[opt]
198878536Sassar
198978536Sassar   GNU extensions:
199078536Sassar
199178536Sassar   struct-declaration:
199278536Sassar     __extension__ struct-declaration
199378536Sassar     specifier-qualifier-list
199478536Sassar
199578536Sassar   Unlike the ISO C syntax, semicolons are handled elsewhere.  The use
199678536Sassar   of attributes where shown is a GNU extension.  In GNU C, we accept
199778536Sassar   any expression without commas in the syntax (assignment
199878536Sassar   expressions, not just conditional expressions); assignment
199978536Sassar   expressions will be diagnosed as non-constant.  */
200078536Sassar
200178536Sassarstatic tree
200278536Sassarc_parser_struct_declaration (c_parser *parser)
200378536Sassar{
200478536Sassar  struct c_declspecs *specs;
200578536Sassar  tree prefix_attrs;
200678536Sassar  tree all_prefix_attrs;
200778536Sassar  tree decls;
200878536Sassar  if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
200978536Sassar    {
201078536Sassar      int ext;
201178536Sassar      tree decl;
201278536Sassar      ext = disable_extension_diagnostics ();
201378536Sassar      c_parser_consume_token (parser);
201478536Sassar      decl = c_parser_struct_declaration (parser);
201578536Sassar      restore_extension_diagnostics (ext);
201678536Sassar      return decl;
201778536Sassar    }
201878536Sassar  specs = build_null_declspecs ();
201978536Sassar  c_parser_declspecs (parser, specs, false, true, true);
202078536Sassar  if (parser->error)
202178536Sassar    return NULL_TREE;
202278536Sassar  if (!specs->declspecs_seen_p)
202378536Sassar    {
202478536Sassar      c_parser_error (parser, "expected specifier-qualifier-list");
202578536Sassar      return NULL_TREE;
202678536Sassar    }
202778536Sassar  finish_declspecs (specs);
202878536Sassar  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
202978536Sassar    {
203078536Sassar      tree ret;
203178536Sassar      if (!specs->type_seen_p)
203278536Sassar	{
203378536Sassar	  if (pedantic)
203478536Sassar	    pedwarn ("ISO C forbids member declarations with no members");
203578536Sassar	  shadow_tag_warned (specs, pedantic);
203678536Sassar	  ret = NULL_TREE;
203778536Sassar	}
203878536Sassar      else
203978536Sassar	{
204078536Sassar	  /* Support for unnamed structs or unions as members of
204178536Sassar	     structs or unions (which is [a] useful and [b] supports
204278536Sassar	     MS P-SDK).  */
204378536Sassar	  ret = grokfield (build_id_declarator (NULL_TREE), specs, NULL_TREE);
204478536Sassar	}
204578536Sassar      return ret;
204678536Sassar    }
204778536Sassar  pending_xref_error ();
204878536Sassar  prefix_attrs = specs->attrs;
204978536Sassar  all_prefix_attrs = prefix_attrs;
205078536Sassar  specs->attrs = NULL_TREE;
205178536Sassar  decls = NULL_TREE;
205278536Sassar  while (true)
205378536Sassar    {
205478536Sassar      /* Declaring one or more declarators or un-named bit-fields.  */
205578536Sassar      struct c_declarator *declarator;
205678536Sassar      bool dummy = false;
205778536Sassar      if (c_parser_next_token_is (parser, CPP_COLON))
205878536Sassar	declarator = build_id_declarator (NULL_TREE);
205978536Sassar      else
206078536Sassar	declarator = c_parser_declarator (parser, specs->type_seen_p,
206178536Sassar					  C_DTR_NORMAL, &dummy);
206255682Smarkm      if (declarator == NULL)
206378536Sassar	{
206478536Sassar	  c_parser_skip_to_end_of_block_or_statement (parser);
206578536Sassar	  break;
206678536Sassar	}
206778536Sassar      if (c_parser_next_token_is (parser, CPP_COLON)
206878536Sassar	  || c_parser_next_token_is (parser, CPP_COMMA)
206978536Sassar	  || c_parser_next_token_is (parser, CPP_SEMICOLON)
207078536Sassar	  || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
207178536Sassar	  || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
207278536Sassar	{
207378536Sassar	  tree postfix_attrs = NULL_TREE;
207478536Sassar	  tree width = NULL_TREE;
2075103426Snectar	  tree d;
207678536Sassar	  if (c_parser_next_token_is (parser, CPP_COLON))
207778536Sassar	    {
207855682Smarkm	      c_parser_consume_token (parser);
207955682Smarkm	      width = c_parser_expr_no_commas (parser, NULL).value;
208055682Smarkm	    }
208155682Smarkm	  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
208255682Smarkm	    postfix_attrs = c_parser_attributes (parser);
208355682Smarkm	  d = grokfield (declarator, specs, width);
208455682Smarkm	  decl_attributes (&d, chainon (postfix_attrs,
208555682Smarkm					all_prefix_attrs), 0);
208678536Sassar	  TREE_CHAIN (d) = decls;
208778536Sassar	  decls = d;
208855682Smarkm	  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
208955682Smarkm	    all_prefix_attrs = chainon (c_parser_attributes (parser),
209055682Smarkm					prefix_attrs);
209155682Smarkm	  else
209255682Smarkm	    all_prefix_attrs = prefix_attrs;
209355682Smarkm	  if (c_parser_next_token_is (parser, CPP_COMMA))
209455682Smarkm	    c_parser_consume_token (parser);
209555682Smarkm	  else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
209655682Smarkm		   || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
209755682Smarkm	    {
209855682Smarkm	      /* Semicolon consumed in caller.  */
209978536Sassar	      break;
210078536Sassar	    }
210178536Sassar	  else
210255682Smarkm	    {
210378536Sassar	      c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
210455682Smarkm	      break;
210578536Sassar	    }
210678536Sassar	}
210755682Smarkm      else
210878536Sassar	{
210955682Smarkm	  c_parser_error (parser,
211055682Smarkm			  "expected %<:%>, %<,%>, %<;%>, %<}%> or "
211155682Smarkm			  "%<__attribute__%>");
211255682Smarkm	  break;
211355682Smarkm	}
211455682Smarkm    }
211555682Smarkm  return decls;
211655682Smarkm}
211755682Smarkm
211855682Smarkm/* Parse a typeof specifier (a GNU extension).
211978536Sassar
212078536Sassar   typeof-specifier:
212155682Smarkm     typeof ( expression )
212255682Smarkm     typeof ( type-name )
212378536Sassar*/
212478536Sassar
212555682Smarkmstatic struct c_typespec
212655682Smarkmc_parser_typeof_specifier (c_parser *parser)
212755682Smarkm{
212855682Smarkm  struct c_typespec ret;
212955682Smarkm  ret.kind = ctsk_typeof;
213055682Smarkm  ret.spec = error_mark_node;
213155682Smarkm  gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
213255682Smarkm  c_parser_consume_token (parser);
213355682Smarkm  skip_evaluation++;
213478536Sassar  in_typeof++;
213578536Sassar  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
213678536Sassar    {
213755682Smarkm      skip_evaluation--;
213878536Sassar      in_typeof--;
213955682Smarkm      return ret;
214055682Smarkm    }
214155682Smarkm  if (c_parser_next_token_starts_typename (parser))
214255682Smarkm    {
214355682Smarkm      struct c_type_name *type = c_parser_type_name (parser);
214455682Smarkm      skip_evaluation--;
214555682Smarkm      in_typeof--;
214655682Smarkm      if (type != NULL)
214755682Smarkm	{
214855682Smarkm	  ret.spec = groktypename (type);
214955682Smarkm	  pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
215055682Smarkm	}
215155682Smarkm    }
215255682Smarkm  else
215355682Smarkm    {
215455682Smarkm      bool was_vm;
215555682Smarkm      struct c_expr expr = c_parser_expression (parser);
215655682Smarkm      skip_evaluation--;
215755682Smarkm      in_typeof--;
215855682Smarkm      if (TREE_CODE (expr.value) == COMPONENT_REF
215955682Smarkm	  && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
216055682Smarkm	error ("%<typeof%> applied to a bit-field");
216155682Smarkm      ret.spec = TREE_TYPE (expr.value);
216290929Snectar      was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
216355682Smarkm      /* This should be returned with the type so that when the type
216455682Smarkm	 is evaluated, this can be evaluated.  For now, we avoid
216555682Smarkm	 evaluation when the context might.  */
216690929Snectar      if (!skip_evaluation && was_vm)
216755682Smarkm	{
216855682Smarkm	  tree e = expr.value;
216978536Sassar
217078536Sassar	  /* If the expression is not of a type to which we cannot assign a line
217155682Smarkm	     number, wrap the thing in a no-op NOP_EXPR.  */
217255682Smarkm	  if (DECL_P (e) || CONSTANT_CLASS_P (e))
217390929Snectar	    e = build1 (NOP_EXPR, void_type_node, e);
217478536Sassar
217578536Sassar	  if (EXPR_P (e))
217655682Smarkm	    SET_EXPR_LOCATION (e, input_location);
217778536Sassar
217855682Smarkm	  add_stmt (e);
217955682Smarkm	}
218078536Sassar      pop_maybe_used (was_vm);
218178536Sassar    }
218278536Sassar  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
218355682Smarkm  return ret;
218455682Smarkm}
218555682Smarkm
218655682Smarkm/* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
218755682Smarkm   6.5.5, C99 6.7.5, 6.7.6).  If TYPE_SEEN_P then a typedef name may
218855682Smarkm   be redeclared; otherwise it may not.  KIND indicates which kind of
218955682Smarkm   declarator is wanted.  Returns a valid declarator except in the
219055682Smarkm   case of a syntax error in which case NULL is returned.  *SEEN_ID is
219155682Smarkm   set to true if an identifier being declared is seen; this is used
219255682Smarkm   to diagnose bad forms of abstract array declarators and to
219355682Smarkm   determine whether an identifier list is syntactically permitted.
219455682Smarkm
219555682Smarkm   declarator:
219655682Smarkm     pointer[opt] direct-declarator
219755682Smarkm
219890929Snectar   direct-declarator:
219955682Smarkm     identifier
220055682Smarkm     ( attributes[opt] declarator )
220190929Snectar     direct-declarator array-declarator
220255682Smarkm     direct-declarator ( parameter-type-list )
220355682Smarkm     direct-declarator ( identifier-list[opt] )
220455682Smarkm
220555682Smarkm   pointer:
220655682Smarkm     * type-qualifier-list[opt]
220755682Smarkm     * type-qualifier-list[opt] pointer
220855682Smarkm
220978536Sassar   type-qualifier-list:
221078536Sassar     type-qualifier
221155682Smarkm     attributes
221278536Sassar     type-qualifier-list type-qualifier
221355682Smarkm     type-qualifier-list attributes
221455682Smarkm
221555682Smarkm   parameter-type-list:
221655682Smarkm     parameter-list
221755682Smarkm     parameter-list , ...
221855682Smarkm
221955682Smarkm   parameter-list:
222055682Smarkm     parameter-declaration
222155682Smarkm     parameter-list , parameter-declaration
222255682Smarkm
222355682Smarkm   parameter-declaration:
222455682Smarkm     declaration-specifiers declarator attributes[opt]
222555682Smarkm     declaration-specifiers abstract-declarator[opt] attributes[opt]
222655682Smarkm
222755682Smarkm   identifier-list:
222855682Smarkm     identifier
222955682Smarkm     identifier-list , identifier
223055682Smarkm
223155682Smarkm   abstract-declarator:
223255682Smarkm     pointer
223355682Smarkm     pointer[opt] direct-abstract-declarator
223455682Smarkm
223555682Smarkm   direct-abstract-declarator:
223655682Smarkm     ( attributes[opt] abstract-declarator )
223755682Smarkm     direct-abstract-declarator[opt] array-declarator
223855682Smarkm     direct-abstract-declarator[opt] ( parameter-type-list[opt] )
223955682Smarkm
224055682Smarkm   GNU extensions:
224155682Smarkm
224255682Smarkm   direct-declarator:
224355682Smarkm     direct-declarator ( parameter-forward-declarations
224455682Smarkm			 parameter-type-list[opt] )
224572448Sassar
224672448Sassar   direct-abstract-declarator:
224772448Sassar     direct-abstract-declarator[opt] ( parameter-forward-declarations
224872448Sassar				       parameter-type-list[opt] )
224972448Sassar
225072448Sassar   parameter-forward-declarations:
225155682Smarkm     parameter-list ;
225255682Smarkm     parameter-forward-declarations parameter-list ;
225355682Smarkm
225455682Smarkm   The uses of attributes shown above are GNU extensions.
225555682Smarkm
225655682Smarkm   Some forms of array declarator are not included in C99 in the
225755682Smarkm   syntax for abstract declarators; these are disallowed elsewhere.
225855682Smarkm   This may be a defect (DR#289).
225955682Smarkm
226055682Smarkm   This function also accepts an omitted abstract declarator as being
226172448Sassar   an abstract declarator, although not part of the formal syntax.  */
226272448Sassar
226355682Smarkmstatic struct c_declarator *
226490929Snectarc_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
226555682Smarkm		     bool *seen_id)
226655682Smarkm{
226755682Smarkm  /* Parse any initial pointer part.  */
226855682Smarkm  if (c_parser_next_token_is (parser, CPP_MULT))
226990929Snectar    {
227055682Smarkm      struct c_declspecs *quals_attrs = build_null_declspecs ();
227155682Smarkm      struct c_declarator *inner;
227255682Smarkm      c_parser_consume_token (parser);
227390929Snectar      c_parser_declspecs (parser, quals_attrs, false, false, true);
227455682Smarkm      inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
227590929Snectar      if (inner == NULL)
227690929Snectar	return NULL;
227790929Snectar      else
227890929Snectar	return make_pointer_declarator (quals_attrs, inner);
227955682Smarkm    }
228090929Snectar  /* Now we have a direct declarator, direct abstract declarator or
228155682Smarkm     nothing (which counts as a direct abstract declarator here).  */
228255682Smarkm  return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
228355682Smarkm}
228455682Smarkm
228555682Smarkm/* Parse a direct declarator or direct abstract declarator; arguments
228655682Smarkm   as c_parser_declarator.  */
228755682Smarkm
228855682Smarkmstatic struct c_declarator *
228955682Smarkmc_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
229078536Sassar			    bool *seen_id)
229155682Smarkm{
229255682Smarkm  /* The direct declarator must start with an identifier (possibly
229355682Smarkm     omitted) or a parenthesized declarator (possibly abstract).  In
229472448Sassar     an ordinary declarator, initial parentheses must start a
229572448Sassar     parenthesized declarator.  In an abstract declarator or parameter
229678536Sassar     declarator, they could start a parenthesized declarator or a
229772448Sassar     parameter list.  To tell which, the open parenthesis and any
229872448Sassar     following attributes must be read.  If a declaration specifier
229990929Snectar     follows, then it is a parameter list; if the specifier is a
230090929Snectar     typedef name, there might be an ambiguity about redeclaring it,
230155682Smarkm     which is resolved in the direction of treating it as a typedef
230272448Sassar     name.  If a close parenthesis follows, it is also an empty
230355682Smarkm     parameter list, as the syntax does not permit empty abstract
230490929Snectar     declarators.  Otherwise, it is a parenthesized declarator (in
230590929Snectar     which case the analysis may be repeated inside it, recursively).
230655682Smarkm
230790929Snectar     ??? There is an ambiguity in a parameter declaration "int
230890929Snectar     (__attribute__((foo)) x)", where x is not a typedef name: it
230955682Smarkm     could be an abstract declarator for a function, or declare x with
231055682Smarkm     parentheses.  The proper resolution of this ambiguity needs
231155682Smarkm     documenting.  At present we follow an accident of the old
231290929Snectar     parser's implementation, whereby the first parameter must have
231390929Snectar     some declaration specifiers other than just attributes.  Thus as
231490929Snectar     a parameter declaration it is treated as a parenthesized
231555682Smarkm     parameter named x, and as an abstract declarator it is
231690929Snectar     rejected.
231755682Smarkm
231890929Snectar     ??? Also following the old parser, attributes inside an empty
231990929Snectar     parameter list are ignored, making it a list not yielding a
232090929Snectar     prototype, rather than giving an error or making it have one
232190929Snectar     parameter with implicit type int.
232255682Smarkm
232355682Smarkm     ??? Also following the old parser, typedef names may be
232490929Snectar     redeclared in declarators, but not Objective-C class names.  */
232555682Smarkm
232655682Smarkm  if (kind != C_DTR_ABSTRACT
232755682Smarkm      && c_parser_next_token_is (parser, CPP_NAME)
232855682Smarkm      && ((type_seen_p
232955682Smarkm	   && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
233072448Sassar	  || c_parser_peek_token (parser)->id_kind == C_ID_ID))
233172448Sassar    {
233255682Smarkm      struct c_declarator *inner
233355682Smarkm	= build_id_declarator (c_parser_peek_token (parser)->value);
233455682Smarkm      *seen_id = true;
233555682Smarkm      inner->id_loc = c_parser_peek_token (parser)->location;
233655682Smarkm      c_parser_consume_token (parser);
233790929Snectar      return c_parser_direct_declarator_inner (parser, *seen_id, inner);
233855682Smarkm    }
233978536Sassar
234055682Smarkm  if (kind != C_DTR_NORMAL
234155682Smarkm      && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
234255682Smarkm    {
234355682Smarkm      struct c_declarator *inner = build_id_declarator (NULL_TREE);
234478536Sassar      return c_parser_direct_declarator_inner (parser, *seen_id, inner);
234578536Sassar    }
234655682Smarkm
234778536Sassar  /* Either we are at the end of an abstract declarator, or we have
234855682Smarkm     parentheses.  */
234955682Smarkm
235055682Smarkm  if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
235155682Smarkm    {
235255682Smarkm      tree attrs;
235355682Smarkm      struct c_declarator *inner;
235455682Smarkm      c_parser_consume_token (parser);
235555682Smarkm      attrs = c_parser_attributes (parser);
235655682Smarkm      if (kind != C_DTR_NORMAL
235778536Sassar	  && (c_parser_next_token_starts_declspecs (parser)
235855682Smarkm	      || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
235978536Sassar	{
236055682Smarkm	  struct c_arg_info *args
236155682Smarkm	    = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
236255682Smarkm					 attrs);
236355682Smarkm	  if (args == NULL)
236478536Sassar	    return NULL;
236590929Snectar	  else
236655682Smarkm	    {
236755682Smarkm	      inner
236890929Snectar		= build_function_declarator (args,
236990929Snectar					     build_id_declarator (NULL_TREE));
237055682Smarkm	      return c_parser_direct_declarator_inner (parser, *seen_id,
237155682Smarkm						       inner);
237255682Smarkm	    }
237390929Snectar	}
237490929Snectar      /* A parenthesized declarator.  */
237590929Snectar      inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
237690929Snectar      if (inner != NULL && attrs != NULL)
237790929Snectar	inner = build_attrs_declarator (attrs, inner);
237890929Snectar      if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
237990929Snectar	{
238055682Smarkm	  c_parser_consume_token (parser);
238155682Smarkm	  if (inner == NULL)
238255682Smarkm	    return NULL;
238355682Smarkm	  else
238455682Smarkm	    return c_parser_direct_declarator_inner (parser, *seen_id, inner);
238555682Smarkm	}
238655682Smarkm      else
238790929Snectar	{
238890929Snectar	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
238990929Snectar				     "expected %<)%>");
239090929Snectar	  return NULL;
239155682Smarkm	}
239255682Smarkm    }
239355682Smarkm  else
239472448Sassar    {
239572448Sassar      if (kind == C_DTR_NORMAL)
239672448Sassar	{
239772448Sassar	  c_parser_error (parser, "expected identifier or %<(%>");
239872448Sassar	  return NULL;
239972448Sassar	}
240072448Sassar      else
240172448Sassar	return build_id_declarator (NULL_TREE);
240272448Sassar    }
240378536Sassar}
240472448Sassar
240572448Sassar/* Parse part of a direct declarator or direct abstract declarator,
240690929Snectar   given that some (in INNER) has already been parsed; ID_PRESENT is
240772448Sassar   true if an identifier is present, false for an abstract
240872448Sassar   declarator.  */
240978536Sassar
241078536Sassarstatic struct c_declarator *
241172448Sassarc_parser_direct_declarator_inner (c_parser *parser, bool id_present,
241278536Sassar				  struct c_declarator *inner)
241372448Sassar{
241472448Sassar  /* Parse a sequence of array declarators and parameter lists.  */
241572448Sassar  if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
241672448Sassar    {
241772448Sassar      struct c_declarator *declarator;
241872448Sassar      struct c_declspecs *quals_attrs = build_null_declspecs ();
241990929Snectar      bool static_seen;
242090929Snectar      bool star_seen;
242190929Snectar      tree dimen;
242290929Snectar      c_parser_consume_token (parser);
242390929Snectar      c_parser_declspecs (parser, quals_attrs, false, false, true);
242490929Snectar      static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
242572448Sassar      if (static_seen)
242672448Sassar	c_parser_consume_token (parser);
242772448Sassar      if (static_seen && !quals_attrs->declspecs_seen_p)
242872448Sassar	c_parser_declspecs (parser, quals_attrs, false, false, true);
242972448Sassar      if (!quals_attrs->declspecs_seen_p)
243072448Sassar	quals_attrs = NULL;
243155682Smarkm      /* If "static" is present, there must be an array dimension.
243255682Smarkm	 Otherwise, there may be a dimension, "*", or no
243355682Smarkm	 dimension.  */
243455682Smarkm      if (static_seen)
243555682Smarkm	{
243672448Sassar	  star_seen = false;
243772448Sassar	  dimen = c_parser_expr_no_commas (parser, NULL).value;
243855682Smarkm	}
243955682Smarkm      else
244055682Smarkm	{
244155682Smarkm	  if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
244255682Smarkm	    {
244355682Smarkm	      dimen = NULL_TREE;
244455682Smarkm	      star_seen = false;
244555682Smarkm	    }
244655682Smarkm	  else if (c_parser_next_token_is (parser, CPP_MULT))
244772448Sassar	    {
244878536Sassar	      if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
244978536Sassar		{
245078536Sassar		  dimen = NULL_TREE;
245178536Sassar		  star_seen = true;
245272448Sassar		  c_parser_consume_token (parser);
245355682Smarkm		}
245478536Sassar	      else
245578536Sassar		{
245655682Smarkm		  star_seen = false;
245778536Sassar		  dimen = c_parser_expr_no_commas (parser, NULL).value;
245855682Smarkm		}
245955682Smarkm	    }
246055682Smarkm	  else
246155682Smarkm	    {
246255682Smarkm	      star_seen = false;
246355682Smarkm	      dimen = c_parser_expr_no_commas (parser, NULL).value;
246455682Smarkm	    }
246555682Smarkm	}
246655682Smarkm      if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
246755682Smarkm	c_parser_consume_token (parser);
246855682Smarkm      else
246955682Smarkm	{
247055682Smarkm	  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
247155682Smarkm				     "expected %<]%>");
247255682Smarkm	  return NULL;
247355682Smarkm	}
247455682Smarkm      declarator = build_array_declarator (dimen, quals_attrs, static_seen,
247590929Snectar					   star_seen);
247690929Snectar      if (declarator == NULL)
247790929Snectar	return NULL;
247890929Snectar      inner = set_array_declarator_inner (declarator, inner, !id_present);
247990929Snectar      return c_parser_direct_declarator_inner (parser, id_present, inner);
248055682Smarkm    }
248155682Smarkm  else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
248255682Smarkm    {
248355682Smarkm      tree attrs;
248455682Smarkm      struct c_arg_info *args;
248555682Smarkm      c_parser_consume_token (parser);
248655682Smarkm      attrs = c_parser_attributes (parser);
248755682Smarkm      args = c_parser_parms_declarator (parser, id_present, attrs);
248855682Smarkm      if (args == NULL)
248955682Smarkm	return NULL;
249055682Smarkm      else
249155682Smarkm	{
249255682Smarkm	  inner = build_function_declarator (args, inner);
249355682Smarkm	  return c_parser_direct_declarator_inner (parser, id_present, inner);
249455682Smarkm	}
249555682Smarkm    }
249655682Smarkm  return inner;
249755682Smarkm}
249878536Sassar
249955682Smarkm/* Parse a parameter list or identifier list, including the closing
250078536Sassar   parenthesis but not the opening one.  ATTRS are the attributes at
250155682Smarkm   the start of the list.  ID_LIST_OK is true if an identifier list is
250255682Smarkm   acceptable; such a list must not have attributes at the start.  */
250355682Smarkm
250455682Smarkmstatic struct c_arg_info *
250555682Smarkmc_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
250655682Smarkm{
250755682Smarkm  push_scope ();
250855682Smarkm  declare_parm_level ();
250955682Smarkm  /* If the list starts with an identifier, it is an identifier list.
251055682Smarkm     Otherwise, it is either a prototype list or an empty list.  */
251155682Smarkm  if (id_list_ok
251272448Sassar      && !attrs
251372448Sassar      && c_parser_next_token_is (parser, CPP_NAME)
251455682Smarkm      && c_parser_peek_token (parser)->id_kind == C_ID_ID)
251555682Smarkm    {
251655682Smarkm      tree list = NULL_TREE, *nextp = &list;
251755682Smarkm      while (c_parser_next_token_is (parser, CPP_NAME)
251855682Smarkm	     && c_parser_peek_token (parser)->id_kind == C_ID_ID)
251955682Smarkm	{
252055682Smarkm	  *nextp = build_tree_list (NULL_TREE,
252178536Sassar				    c_parser_peek_token (parser)->value);
252255682Smarkm	  nextp = & TREE_CHAIN (*nextp);
252378536Sassar	  c_parser_consume_token (parser);
252478536Sassar	  if (c_parser_next_token_is_not (parser, CPP_COMMA))
252555682Smarkm	    break;
252678536Sassar	  c_parser_consume_token (parser);
252755682Smarkm	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
252855682Smarkm	    {
252955682Smarkm	      c_parser_error (parser, "expected identifier");
253055682Smarkm	      break;
253155682Smarkm	    }
253255682Smarkm	}
253355682Smarkm      if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
253455682Smarkm	{
253555682Smarkm	  struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
253655682Smarkm	  ret->parms = 0;
253790929Snectar	  ret->tags = 0;
253890929Snectar	  ret->types = list;
253990929Snectar	  ret->others = 0;
254090929Snectar	  ret->pending_sizes = 0;
254190929Snectar	  ret->had_vla_unspec = 0;
254255682Smarkm	  c_parser_consume_token (parser);
254355682Smarkm	  pop_scope ();
254472448Sassar	  return ret;
254572448Sassar	}
254655682Smarkm      else
254755682Smarkm	{
254878536Sassar	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
254955682Smarkm				     "expected %<)%>");
255055682Smarkm	  pop_scope ();
255155682Smarkm	  return NULL;
255255682Smarkm	}
255355682Smarkm    }
255455682Smarkm  else
255555682Smarkm    {
255655682Smarkm      struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
255755682Smarkm      pop_scope ();
255855682Smarkm      return ret;
255955682Smarkm    }
256078536Sassar}
256155682Smarkm
256255682Smarkm/* Parse a parameter list (possibly empty), including the closing
256355682Smarkm   parenthesis but not the opening one.  ATTRS are the attributes at
256455682Smarkm   the start of the list.  */
256555682Smarkm
256655682Smarkmstatic struct c_arg_info *
256772448Sassarc_parser_parms_list_declarator (c_parser *parser, tree attrs)
256872448Sassar{
256972448Sassar  bool good_parm = false;
257072448Sassar  /* ??? Following the old parser, forward parameter declarations may
257172448Sassar     use abstract declarators, and if no real parameter declarations
257272448Sassar     follow the forward declarations then this is not diagnosed.  Also
257372448Sassar     note as above that attributes are ignored as the only contents of
257472448Sassar     the parentheses, or as the only contents after forward
257572448Sassar     declarations.  */
257672448Sassar  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
257778536Sassar    {
257872448Sassar      struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
257972448Sassar      ret->parms = 0;
258072448Sassar      ret->tags = 0;
258190929Snectar      ret->types = 0;
258272448Sassar      ret->others = 0;
258372448Sassar      ret->pending_sizes = 0;
258478536Sassar      ret->had_vla_unspec = 0;
258578536Sassar      c_parser_consume_token (parser);
258672448Sassar      return ret;
258778536Sassar    }
258872448Sassar  if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
258990929Snectar    {
259090929Snectar      struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
259190929Snectar      ret->parms = 0;
259290929Snectar      ret->tags = 0;
259390929Snectar      ret->others = 0;
259472448Sassar      ret->pending_sizes = 0;
259572448Sassar      ret->had_vla_unspec = 0;
259672448Sassar      /* Suppress -Wold-style-definition for this case.  */
259772448Sassar      ret->types = error_mark_node;
259872448Sassar      error ("ISO C requires a named argument before %<...%>");
259972448Sassar      c_parser_consume_token (parser);
260072448Sassar      if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
260172448Sassar	{
260272448Sassar	  c_parser_consume_token (parser);
260355682Smarkm	  return ret;
260472448Sassar	}
260572448Sassar      else
260672448Sassar	{
260772448Sassar	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
260872448Sassar				     "expected %<)%>");
260972448Sassar	  return NULL;
261072448Sassar	}
261172448Sassar    }
261272448Sassar  /* Nonempty list of parameters, either terminated with semicolon
261372448Sassar     (forward declarations; recurse) or with close parenthesis (normal
261472448Sassar     function) or with ", ... )" (variadic function).  */
261572448Sassar  while (true)
261672448Sassar    {
261772448Sassar      /* Parse a parameter.  */
261872448Sassar      struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
261972448Sassar      attrs = NULL_TREE;
262072448Sassar      if (parm != NULL)
262172448Sassar	{
262272448Sassar	  good_parm = true;
262355682Smarkm	  push_parm_decl (parm);
262455682Smarkm	}
262555682Smarkm      if (c_parser_next_token_is (parser, CPP_SEMICOLON))
262655682Smarkm	{
262755682Smarkm	  tree new_attrs;
262855682Smarkm	  c_parser_consume_token (parser);
262955682Smarkm	  mark_forward_parm_decls ();
263072448Sassar	  new_attrs = c_parser_attributes (parser);
263155682Smarkm	  return c_parser_parms_list_declarator (parser, new_attrs);
263255682Smarkm	}
263355682Smarkm      if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
263455682Smarkm	{
263555682Smarkm	  c_parser_consume_token (parser);
263655682Smarkm	  if (good_parm)
263755682Smarkm	    return get_parm_info (false);
263855682Smarkm	  else
263955682Smarkm	    {
264055682Smarkm	      struct c_arg_info *ret
264155682Smarkm		= XOBNEW (&parser_obstack, struct c_arg_info);
264255682Smarkm	      ret->parms = 0;
264355682Smarkm	      ret->tags = 0;
264455682Smarkm	      ret->types = 0;
264555682Smarkm	      ret->others = 0;
264655682Smarkm	      ret->pending_sizes = 0;
264755682Smarkm	      ret->had_vla_unspec = 0;
264855682Smarkm	      return ret;
264955682Smarkm	    }
265055682Smarkm	}
265155682Smarkm      if (!c_parser_require (parser, CPP_COMMA,
265272448Sassar			     "expected %<;%>, %<,%> or %<)%>"))
265372448Sassar	{
265472448Sassar	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
265572448Sassar	  return NULL;
265672448Sassar	}
265772448Sassar      if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
265872448Sassar	{
265972448Sassar	  c_parser_consume_token (parser);
266072448Sassar	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
266172448Sassar	    {
266272448Sassar	      c_parser_consume_token (parser);
266372448Sassar	      if (good_parm)
266472448Sassar		return get_parm_info (true);
266572448Sassar	      else
266672448Sassar		{
266772448Sassar		  struct c_arg_info *ret
266872448Sassar		    = XOBNEW (&parser_obstack, struct c_arg_info);
266972448Sassar		  ret->parms = 0;
267072448Sassar		  ret->tags = 0;
267155682Smarkm		  ret->types = 0;
267255682Smarkm		  ret->others = 0;
267355682Smarkm		  ret->pending_sizes = 0;
267455682Smarkm		  ret->had_vla_unspec = 0;
267555682Smarkm		  return ret;
267655682Smarkm		}
267755682Smarkm	    }
267872448Sassar	  else
267972448Sassar	    {
268055682Smarkm	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
268155682Smarkm					 "expected %<)%>");
268255682Smarkm	      return NULL;
268355682Smarkm	    }
268455682Smarkm	}
268555682Smarkm    }
268672448Sassar}
268755682Smarkm
268855682Smarkm/* Parse a parameter declaration.  ATTRS are the attributes at the
268955682Smarkm   start of the declaration if it is the first parameter.  */
269055682Smarkm
269155682Smarkmstatic struct c_parm *
269255682Smarkmc_parser_parameter_declaration (c_parser *parser, tree attrs)
269355682Smarkm{
269455682Smarkm  struct c_declspecs *specs;
269555682Smarkm  struct c_declarator *declarator;
269655682Smarkm  tree prefix_attrs;
269790929Snectar  tree postfix_attrs = NULL_TREE;
269878536Sassar  bool dummy = false;
269978536Sassar  if (!c_parser_next_token_starts_declspecs (parser))
270078536Sassar    {
270178536Sassar      /* ??? In some Objective-C cases '...' isn't applicable so there
270278536Sassar	 should be a different message.  */
270378536Sassar      c_parser_error (parser,
270478536Sassar		      "expected declaration specifiers or %<...%>");
270578536Sassar      c_parser_skip_to_end_of_parameter (parser);
270678536Sassar      return NULL;
270778536Sassar    }
270878536Sassar  specs = build_null_declspecs ();
270978536Sassar  if (attrs)
271078536Sassar    {
271178536Sassar      declspecs_add_attrs (specs, attrs);
271278536Sassar      attrs = NULL_TREE;
271378536Sassar    }
271478536Sassar  c_parser_declspecs (parser, specs, true, true, true);
271578536Sassar  finish_declspecs (specs);
271678536Sassar  pending_xref_error ();
271778536Sassar  prefix_attrs = specs->attrs;
271878536Sassar  specs->attrs = NULL_TREE;
271978536Sassar  declarator = c_parser_declarator (parser, specs->type_seen_p,
272078536Sassar				    C_DTR_PARM, &dummy);
272178536Sassar  if (declarator == NULL)
272278536Sassar    {
272378536Sassar      c_parser_skip_until_found (parser, CPP_COMMA, NULL);
272478536Sassar      return NULL;
272590929Snectar    }
272678536Sassar  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
272778536Sassar    postfix_attrs = c_parser_attributes (parser);
272878536Sassar  return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
272978536Sassar		       declarator);
273078536Sassar}
273178536Sassar
273278536Sassar/* Parse a string literal in an asm expression.  It should not be
273378536Sassar   translated, and wide string literals are an error although
273478536Sassar   permitted by the syntax.  This is a GNU extension.
273578536Sassar
273678536Sassar   asm-string-literal:
273778536Sassar     string-literal
273878536Sassar
273978536Sassar   ??? At present, following the old parser, the caller needs to have
274078536Sassar   set c_lex_string_translate to 0.  It would be better to follow the
274178536Sassar   C++ parser rather than using the c_lex_string_translate kludge.  */
274278536Sassar
274378536Sassarstatic tree
274478536Sassarc_parser_asm_string_literal (c_parser *parser)
274578536Sassar{
274678536Sassar  tree str;
274755682Smarkm  if (c_parser_next_token_is (parser, CPP_STRING))
274855682Smarkm    {
274955682Smarkm      str = c_parser_peek_token (parser)->value;
275078536Sassar      c_parser_consume_token (parser);
275178536Sassar    }
275278536Sassar  else if (c_parser_next_token_is (parser, CPP_WSTRING))
275378536Sassar    {
275478536Sassar      error ("wide string literal in %<asm%>");
275578536Sassar      str = build_string (1, "");
275678536Sassar      c_parser_consume_token (parser);
275778536Sassar    }
275878536Sassar  else
275978536Sassar    {
276078536Sassar      c_parser_error (parser, "expected string literal");
276178536Sassar      str = NULL_TREE;
276278536Sassar    }
276378536Sassar  return str;
276478536Sassar}
276578536Sassar
276655682Smarkm/* Parse a simple asm expression.  This is used in restricted
276755682Smarkm   contexts, where a full expression with inputs and outputs does not
276855682Smarkm   make sense.  This is a GNU extension.
276955682Smarkm
277055682Smarkm   simple-asm-expr:
277155682Smarkm     asm ( asm-string-literal )
277255682Smarkm*/
277355682Smarkm
277455682Smarkmstatic tree
277555682Smarkmc_parser_simple_asm_expr (c_parser *parser)
277655682Smarkm{
277755682Smarkm  tree str;
277855682Smarkm  gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
277955682Smarkm  /* ??? Follow the C++ parser rather than using the
278055682Smarkm     c_lex_string_translate kludge.  */
278155682Smarkm  c_lex_string_translate = 0;
278255682Smarkm  c_parser_consume_token (parser);
278355682Smarkm  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
278455682Smarkm    {
278555682Smarkm      c_lex_string_translate = 1;
278655682Smarkm      return NULL_TREE;
278755682Smarkm    }
278878536Sassar  str = c_parser_asm_string_literal (parser);
278955682Smarkm  c_lex_string_translate = 1;
279055682Smarkm  if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
279155682Smarkm    {
279255682Smarkm      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
279355682Smarkm      return NULL_TREE;
279455682Smarkm    }
279555682Smarkm  return str;
279655682Smarkm}
279755682Smarkm
279855682Smarkm/* Parse (possibly empty) attributes.  This is a GNU extension.
279955682Smarkm
280055682Smarkm   attributes:
280155682Smarkm     empty
280255682Smarkm     attributes attribute
280355682Smarkm
280455682Smarkm   attribute:
280555682Smarkm     __attribute__ ( ( attribute-list ) )
280655682Smarkm
280755682Smarkm   attribute-list:
280855682Smarkm     attrib
280955682Smarkm     attribute_list , attrib
281055682Smarkm
281155682Smarkm   attrib:
281255682Smarkm     empty
281355682Smarkm     any-word
281455682Smarkm     any-word ( identifier )
281555682Smarkm     any-word ( identifier , nonempty-expr-list )
281655682Smarkm     any-word ( expr-list )
281755682Smarkm
281855682Smarkm   where the "identifier" must not be declared as a type, and
281955682Smarkm   "any-word" may be any identifier (including one declared as a
282055682Smarkm   type), a reserved word storage class specifier, type specifier or
282155682Smarkm   type qualifier.  ??? This still leaves out most reserved keywords
282255682Smarkm   (following the old parser), shouldn't we include them, and why not
282355682Smarkm   allow identifiers declared as types to start the arguments?  */
282455682Smarkm
282555682Smarkmstatic tree
282655682Smarkmc_parser_attributes (c_parser *parser)
282755682Smarkm{
282855682Smarkm  tree attrs = NULL_TREE;
282978536Sassar  while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
283055682Smarkm    {
283155682Smarkm      /* ??? Follow the C++ parser rather than using the
283255682Smarkm	 c_lex_string_translate kludge.  */
283355682Smarkm      c_lex_string_translate = 0;
283455682Smarkm      c_parser_consume_token (parser);
283555682Smarkm      if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
283655682Smarkm	{
283755682Smarkm	  c_lex_string_translate = 1;
283855682Smarkm	  return attrs;
283955682Smarkm	}
284072448Sassar      if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
284155682Smarkm	{
284255682Smarkm	  c_lex_string_translate = 1;
284355682Smarkm	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
284478536Sassar	  return attrs;
284578536Sassar	}
284655682Smarkm      /* Parse the attribute list.  */
284778536Sassar      while (c_parser_next_token_is (parser, CPP_COMMA)
284855682Smarkm	     || c_parser_next_token_is (parser, CPP_NAME)
284955682Smarkm	     || c_parser_next_token_is (parser, CPP_KEYWORD))
285055682Smarkm	{
285155682Smarkm	  tree attr, attr_name, attr_args;
285255682Smarkm	  if (c_parser_next_token_is (parser, CPP_COMMA))
285355682Smarkm	    {
285478536Sassar	      c_parser_consume_token (parser);
285578536Sassar	      continue;
285655682Smarkm	    }
285755682Smarkm	  if (c_parser_next_token_is (parser, CPP_KEYWORD))
285872448Sassar	    {
285955682Smarkm	      /* ??? See comment above about what keywords are
286055682Smarkm		 accepted here.  */
286155682Smarkm	      bool ok;
286278536Sassar	      switch (c_parser_peek_token (parser)->keyword)
286378536Sassar		{
286455682Smarkm		case RID_STATIC:
286578536Sassar		case RID_UNSIGNED:
286655682Smarkm		case RID_LONG:
286778536Sassar		case RID_CONST:
286855682Smarkm		case RID_EXTERN:
286978536Sassar		case RID_REGISTER:
287078536Sassar		case RID_TYPEDEF:
287178536Sassar		case RID_SHORT:
287255682Smarkm		case RID_INLINE:
287378536Sassar		case RID_VOLATILE:
287455682Smarkm		case RID_SIGNED:
287555682Smarkm		case RID_AUTO:
287655682Smarkm		case RID_RESTRICT:
287755682Smarkm		case RID_COMPLEX:
287855682Smarkm		case RID_THREAD:
287955682Smarkm		case RID_INT:
288055682Smarkm		case RID_CHAR:
288155682Smarkm		case RID_FLOAT:
288255682Smarkm		case RID_DOUBLE:
288355682Smarkm		case RID_VOID:
288478536Sassar		case RID_DFLOAT32:
288578536Sassar		case RID_DFLOAT64:
288678536Sassar		case RID_DFLOAT128:
288755682Smarkm		case RID_BOOL:
288855682Smarkm		  ok = true;
288955682Smarkm		  break;
289055682Smarkm		default:
289155682Smarkm		  ok = false;
289255682Smarkm		  break;
289355682Smarkm		}
289455682Smarkm	      if (!ok)
289555682Smarkm		break;
289655682Smarkm	    }
289755682Smarkm	  attr_name = c_parser_peek_token (parser)->value;
289855682Smarkm	  c_parser_consume_token (parser);
289955682Smarkm	  if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
290055682Smarkm	    {
290155682Smarkm	      attr = build_tree_list (attr_name, NULL_TREE);
290255682Smarkm	      attrs = chainon (attrs, attr);
290355682Smarkm	      continue;
290455682Smarkm	    }
290555682Smarkm	  c_parser_consume_token (parser);
290655682Smarkm	  /* Parse the attribute contents.  If they start with an
290755682Smarkm	     identifier which is followed by a comma or close
290855682Smarkm	     parenthesis, then the arguments start with that
290978536Sassar	     identifier; otherwise they are an expression list.  */
291078536Sassar	  if (c_parser_next_token_is (parser, CPP_NAME)
291178536Sassar	      && c_parser_peek_token (parser)->id_kind == C_ID_ID
291278536Sassar	      && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
291378536Sassar		  || (c_parser_peek_2nd_token (parser)->type
291478536Sassar		      == CPP_CLOSE_PAREN)))
291578536Sassar	    {
291678536Sassar	      tree arg1 = c_parser_peek_token (parser)->value;
291778536Sassar	      c_parser_consume_token (parser);
291878536Sassar	      if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
291978536Sassar		attr_args = build_tree_list (NULL_TREE, arg1);
292078536Sassar	      else
292178536Sassar		{
292278536Sassar		  c_parser_consume_token (parser);
292378536Sassar		  attr_args = tree_cons (NULL_TREE, arg1,
292478536Sassar					 c_parser_expr_list (parser, false));
292578536Sassar		}
292678536Sassar	    }
292778536Sassar	  else
292878536Sassar	    {
292978536Sassar	      if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
293078536Sassar		attr_args = NULL_TREE;
293178536Sassar	      else
293278536Sassar		attr_args = c_parser_expr_list (parser, false);
293378536Sassar	    }
293478536Sassar	  attr = build_tree_list (attr_name, attr_args);
293578536Sassar	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
293678536Sassar	    c_parser_consume_token (parser);
293778536Sassar	  else
293878536Sassar	    {
293978536Sassar	      c_lex_string_translate = 1;
294078536Sassar	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
294155682Smarkm					 "expected %<)%>");
294255682Smarkm	      return attrs;
294355682Smarkm	    }
294455682Smarkm	  attrs = chainon (attrs, attr);
294555682Smarkm	}
294655682Smarkm      if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
294755682Smarkm	c_parser_consume_token (parser);
294855682Smarkm      else
294955682Smarkm	{
295055682Smarkm	  c_lex_string_translate = 1;
295155682Smarkm	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
295255682Smarkm				     "expected %<)%>");
295355682Smarkm	  return attrs;
295455682Smarkm	}
295555682Smarkm      if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
295655682Smarkm	c_parser_consume_token (parser);
295778536Sassar      else
295878536Sassar	{
295955682Smarkm	  c_lex_string_translate = 1;
296078536Sassar	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
296155682Smarkm				     "expected %<)%>");
296255682Smarkm	  return attrs;
296355682Smarkm	}
296455682Smarkm      c_lex_string_translate = 1;
296555682Smarkm    }
296655682Smarkm  return attrs;
296755682Smarkm}
296855682Smarkm
296955682Smarkm/* Parse a type name (C90 6.5.5, C99 6.7.6).
297055682Smarkm
297178536Sassar   type-name:
297255682Smarkm     specifier-qualifier-list abstract-declarator[opt]
297355682Smarkm*/
297455682Smarkm
297555682Smarkmstatic struct c_type_name *
297655682Smarkmc_parser_type_name (c_parser *parser)
297778536Sassar{
297878536Sassar  struct c_declspecs *specs = build_null_declspecs ();
297955682Smarkm  struct c_declarator *declarator;
298078536Sassar  struct c_type_name *ret;
298155682Smarkm  bool dummy = false;
298255682Smarkm  c_parser_declspecs (parser, specs, false, true, true);
298355682Smarkm  if (!specs->declspecs_seen_p)
298455682Smarkm    {
298555682Smarkm      c_parser_error (parser, "expected specifier-qualifier-list");
298678536Sassar      return NULL;
298778536Sassar    }
298855682Smarkm  pending_xref_error ();
298955682Smarkm  finish_declspecs (specs);
2990102647Snectar  declarator = c_parser_declarator (parser, specs->type_seen_p,
2991102647Snectar				    C_DTR_ABSTRACT, &dummy);
2992102647Snectar  if (declarator == NULL)
2993102647Snectar    return NULL;
2994102647Snectar  ret = XOBNEW (&parser_obstack, struct c_type_name);
299555682Smarkm  ret->specs = specs;
299655682Smarkm  ret->declarator = declarator;
299755682Smarkm  return ret;
299855682Smarkm}
299955682Smarkm
300055682Smarkm/* Parse an initializer (C90 6.5.7, C99 6.7.8).
300155682Smarkm
300255682Smarkm   initializer:
300355682Smarkm     assignment-expression
300455682Smarkm     { initializer-list }
300555682Smarkm     { initializer-list , }
300655682Smarkm
300755682Smarkm   initializer-list:
300855682Smarkm     designation[opt] initializer
300955682Smarkm     initializer-list , designation[opt] initializer
301055682Smarkm
301155682Smarkm   designation:
301255682Smarkm     designator-list =
301355682Smarkm
301455682Smarkm   designator-list:
301555682Smarkm     designator
301655682Smarkm     designator-list designator
301755682Smarkm
301855682Smarkm   designator:
301955682Smarkm     array-designator
302055682Smarkm     . identifier
302155682Smarkm
302255682Smarkm   array-designator:
302355682Smarkm     [ constant-expression ]
302455682Smarkm
302555682Smarkm   GNU extensions:
302655682Smarkm
302755682Smarkm   initializer:
302855682Smarkm     { }
302955682Smarkm
303055682Smarkm   designation:
303155682Smarkm     array-designator
303255682Smarkm     identifier :
303355682Smarkm
303455682Smarkm   array-designator:
303555682Smarkm     [ constant-expression ... constant-expression ]
303655682Smarkm
3037103426Snectar   Any expression without commas is accepted in the syntax for the
3038103426Snectar   constant-expressions, with non-constant expressions rejected later.
3039103426Snectar
3040103426Snectar   This function is only used for top-level initializers; for nested
3041103426Snectar   ones, see c_parser_initval.  */
3042103426Snectar
3043103426Snectarstatic struct c_expr
3044103426Snectarc_parser_initializer (c_parser *parser)
3045103426Snectar{
304655682Smarkm  if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
304755682Smarkm    return c_parser_braced_init (parser, NULL_TREE, false);
304855682Smarkm  else
304955682Smarkm    {
305055682Smarkm      struct c_expr ret;
305155682Smarkm      ret = c_parser_expr_no_commas (parser, NULL);
305255682Smarkm      if (TREE_CODE (ret.value) != STRING_CST
305355682Smarkm	  && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
305455682Smarkm	ret = default_function_array_conversion (ret);
305590929Snectar      return ret;
305655682Smarkm    }
305755682Smarkm}
305878536Sassar
305978536Sassar/* Parse a braced initializer list.  TYPE is the type specified for a
306078536Sassar   compound literal, and NULL_TREE for other initializers and for
306155682Smarkm   nested braced lists.  NESTED_P is true for nested braced lists,
306278536Sassar   false for the list of a compound literal or the list that is the
306355682Smarkm   top-level initializer in a declaration.  */
306490929Snectar
306590929Snectarstatic struct c_expr
306690929Snectarc_parser_braced_init (c_parser *parser, tree type, bool nested_p)
306790929Snectar{
306890929Snectar  gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
306990929Snectar  c_parser_consume_token (parser);
307090929Snectar  if (nested_p)
307190929Snectar    push_init_level (0);
307290929Snectar  else
307355682Smarkm    really_start_incremental_init (type);
307490929Snectar  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
307590929Snectar    {
307690929Snectar      if (pedantic)
307790929Snectar	pedwarn ("ISO C forbids empty initializer braces");
307890929Snectar    }
307990929Snectar  else
308090929Snectar    {
308155682Smarkm      /* Parse a non-empty initializer list, possibly with a trailing
308290929Snectar	 comma.  */
308390929Snectar      while (true)
308490929Snectar	{
308590929Snectar	  c_parser_initelt (parser);
308655682Smarkm	  if (parser->error)
308755682Smarkm	    break;
308855682Smarkm	  if (c_parser_next_token_is (parser, CPP_COMMA))
308955682Smarkm	    c_parser_consume_token (parser);
309055682Smarkm	  else
309155682Smarkm	    break;
309255682Smarkm	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
309355682Smarkm	    break;
309455682Smarkm	}
309572448Sassar    }
309672448Sassar  if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
309772448Sassar    {
309872448Sassar      struct c_expr ret;
309972448Sassar      ret.value = error_mark_node;
310072448Sassar      ret.original_code = ERROR_MARK;
310172448Sassar      c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
310272448Sassar      return ret;
310372448Sassar    }
310478536Sassar  c_parser_consume_token (parser);
310572448Sassar  return pop_init_level (0);
310672448Sassar}
310772448Sassar
310872448Sassar/* Parse a nested initializer, including designators.  */
310972448Sassar
311072448Sassarstatic void
311172448Sassarc_parser_initelt (c_parser *parser)
311272448Sassar{
311372448Sassar  /* Parse any designator or designator list.  A single array
311472448Sassar     designator may have the subsequent "=" omitted in GNU C, but a
311572448Sassar     longer list or a structure member designator may not.  */
311672448Sassar  if (c_parser_next_token_is (parser, CPP_NAME)
311772448Sassar      && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
311872448Sassar    {
311972448Sassar      /* Old-style structure member designator.  */
312078536Sassar      set_init_label (c_parser_peek_token (parser)->value);
312172448Sassar      if (pedantic)
312272448Sassar	pedwarn ("obsolete use of designated initializer with %<:%>");
312372448Sassar      c_parser_consume_token (parser);
312455682Smarkm      c_parser_consume_token (parser);
312555682Smarkm    }
312655682Smarkm  else
312755682Smarkm    {
312855682Smarkm      /* des_seen is 0 if there have been no designators, 1 if there
312955682Smarkm	 has been a single array designator and 2 otherwise.  */
313055682Smarkm      int des_seen = 0;
313155682Smarkm      while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
313255682Smarkm	     || c_parser_next_token_is (parser, CPP_DOT))
313372448Sassar	{
313472448Sassar	  int des_prev = des_seen;
313572448Sassar	  if (des_seen < 2)
313672448Sassar	    des_seen++;
313755682Smarkm	  if (c_parser_next_token_is (parser, CPP_DOT))
313855682Smarkm	    {
313955682Smarkm	      des_seen = 2;
314055682Smarkm	      c_parser_consume_token (parser);
314155682Smarkm	      if (c_parser_next_token_is (parser, CPP_NAME))
314255682Smarkm		{
314355682Smarkm		  set_init_label (c_parser_peek_token (parser)->value);
314455682Smarkm		  c_parser_consume_token (parser);
314555682Smarkm		}
314657416Smarkm	      else
314755682Smarkm		{
314857416Smarkm		  struct c_expr init;
314972448Sassar		  init.value = error_mark_node;
315072448Sassar		  init.original_code = ERROR_MARK;
315172448Sassar		  c_parser_error (parser, "expected identifier");
315255682Smarkm		  c_parser_skip_until_found (parser, CPP_COMMA, NULL);
315355682Smarkm		  process_init_element (init);
315455682Smarkm		  return;
315555682Smarkm		}
315655682Smarkm	    }
315755682Smarkm	  else
315855682Smarkm	    {
315955682Smarkm	      tree first, second;
316055682Smarkm	      /* ??? Following the old parser, [ objc-receiver
316155682Smarkm		 objc-message-args ] is accepted as an initializer,
316255682Smarkm		 being distinguished from a designator by what follows
316355682Smarkm		 the first assignment expression inside the square
316455682Smarkm		 brackets, but after a first array designator a
316555682Smarkm		 subsequent square bracket is for Objective-C taken to
316655682Smarkm		 start an expression, using the obsolete form of
316755682Smarkm		 designated initializer without '=', rather than
316855682Smarkm		 possibly being a second level of designation: in LALR
316955682Smarkm		 terms, the '[' is shifted rather than reducing
317055682Smarkm		 designator to designator-list.  */
317155682Smarkm	      if (des_prev == 1 && c_dialect_objc ())
317255682Smarkm		{
317355682Smarkm		  des_seen = des_prev;
317455682Smarkm		  break;
317572448Sassar		}
317672448Sassar	      if (des_prev == 0 && c_dialect_objc ())
317772448Sassar		{
317872448Sassar		  /* This might be an array designator or an
317972448Sassar		     Objective-C message expression.  If the former,
318072448Sassar		     continue parsing here; if the latter, parse the
318172448Sassar		     remainder of the initializer given the starting
318272448Sassar		     primary-expression.  ??? It might make sense to
318372448Sassar		     distinguish when des_prev == 1 as well; see
318472448Sassar		     previous comment.  */
318572448Sassar		  tree rec, args;
318672448Sassar		  struct c_expr mexpr;
318772448Sassar		  c_parser_consume_token (parser);
318872448Sassar		  if (c_parser_peek_token (parser)->type == CPP_NAME
318972448Sassar		      && ((c_parser_peek_token (parser)->id_kind
319072448Sassar			   == C_ID_TYPENAME)
319172448Sassar			  || (c_parser_peek_token (parser)->id_kind
319272448Sassar			      == C_ID_CLASSNAME)))
319372448Sassar		    {
319472448Sassar		      /* Type name receiver.  */
319572448Sassar		      tree id = c_parser_peek_token (parser)->value;
319672448Sassar		      c_parser_consume_token (parser);
319772448Sassar		      rec = objc_get_class_reference (id);
319872448Sassar		      goto parse_message_args;
319972448Sassar		    }
320072448Sassar		  first = c_parser_expr_no_commas (parser, NULL).value;
320172448Sassar		  if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
320272448Sassar		      || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
320372448Sassar		    goto array_desig_after_first;
320472448Sassar		  /* Expression receiver.  So far only one part
320572448Sassar		     without commas has been parsed; there might be
320672448Sassar		     more of the expression.  */
320772448Sassar		  rec = first;
320872448Sassar		  while (c_parser_next_token_is (parser, CPP_COMMA))
320972448Sassar		    {
321072448Sassar		      struct c_expr next;
321172448Sassar		      c_parser_consume_token (parser);
321272448Sassar		      next = c_parser_expr_no_commas (parser, NULL);
321372448Sassar		      next = default_function_array_conversion (next);
321472448Sassar		      rec = build_compound_expr (rec, next.value);
321572448Sassar		    }
321672448Sassar		parse_message_args:
321772448Sassar		  /* Now parse the objc-message-args.  */
321872448Sassar		  args = c_parser_objc_message_args (parser);
321972448Sassar		  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
322072448Sassar					     "expected %<]%>");
322172448Sassar		  mexpr.value
322272448Sassar		    = objc_build_message_expr (build_tree_list (rec, args));
322372448Sassar		  mexpr.original_code = ERROR_MARK;
322472448Sassar		  /* Now parse and process the remainder of the
322572448Sassar		     initializer, starting with this message
322672448Sassar		     expression as a primary-expression.  */
322772448Sassar		  c_parser_initval (parser, &mexpr);
322872448Sassar		  return;
322972448Sassar		}
323072448Sassar	      c_parser_consume_token (parser);
323172448Sassar	      first = c_parser_expr_no_commas (parser, NULL).value;
323272448Sassar	    array_desig_after_first:
323372448Sassar	      if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
323472448Sassar		{
323572448Sassar		  c_parser_consume_token (parser);
323672448Sassar		  second = c_parser_expr_no_commas (parser, NULL).value;
323772448Sassar		}
323872448Sassar	      else
323972448Sassar		second = NULL_TREE;
324072448Sassar	      if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3241		{
3242		  c_parser_consume_token (parser);
3243		  set_init_index (first, second);
3244		  if (pedantic && second)
3245		    pedwarn ("ISO C forbids specifying range of "
3246			     "elements to initialize");
3247		}
3248	      else
3249		c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3250					   "expected %<]%>");
3251	    }
3252	}
3253      if (des_seen >= 1)
3254	{
3255	  if (c_parser_next_token_is (parser, CPP_EQ))
3256	    {
3257	      if (pedantic && !flag_isoc99)
3258		pedwarn ("ISO C90 forbids specifying subobject to initialize");
3259	      c_parser_consume_token (parser);
3260	    }
3261	  else
3262	    {
3263	      if (des_seen == 1)
3264		{
3265		  if (pedantic)
3266		    pedwarn ("obsolete use of designated initializer "
3267			     "without %<=%>");
3268		}
3269	      else
3270		{
3271		  struct c_expr init;
3272		  init.value = error_mark_node;
3273		  init.original_code = ERROR_MARK;
3274		  c_parser_error (parser, "expected %<=%>");
3275		  c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3276		  process_init_element (init);
3277		  return;
3278		}
3279	    }
3280	}
3281    }
3282  c_parser_initval (parser, NULL);
3283}
3284
3285/* Parse a nested initializer; as c_parser_initializer but parses
3286   initializers within braced lists, after any designators have been
3287   applied.  If AFTER is not NULL then it is an Objective-C message
3288   expression which is the primary-expression starting the
3289   initializer.  */
3290
3291static void
3292c_parser_initval (c_parser *parser, struct c_expr *after)
3293{
3294  struct c_expr init;
3295  gcc_assert (!after || c_dialect_objc ());
3296  if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3297    init = c_parser_braced_init (parser, NULL_TREE, true);
3298  else
3299    {
3300      init = c_parser_expr_no_commas (parser, after);
3301      if (init.value != NULL_TREE
3302	  && TREE_CODE (init.value) != STRING_CST
3303	  && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3304	init = default_function_array_conversion (init);
3305    }
3306  process_init_element (init);
3307}
3308
3309/* Parse a compound statement (possibly a function body) (C90 6.6.2,
3310   C99 6.8.2).
3311
3312   compound-statement:
3313     { block-item-list[opt] }
3314     { label-declarations block-item-list }
3315
3316   block-item-list:
3317     block-item
3318     block-item-list block-item
3319
3320   block-item:
3321     nested-declaration
3322     statement
3323
3324   nested-declaration:
3325     declaration
3326
3327   GNU extensions:
3328
3329   compound-statement:
3330     { label-declarations block-item-list }
3331
3332   nested-declaration:
3333     __extension__ nested-declaration
3334     nested-function-definition
3335
3336   label-declarations:
3337     label-declaration
3338     label-declarations label-declaration
3339
3340   label-declaration:
3341     __label__ identifier-list ;
3342
3343   Allowing the mixing of declarations and code is new in C99.  The
3344   GNU syntax also permits (not shown above) labels at the end of
3345   compound statements, which yield an error.  We don't allow labels
3346   on declarations; this might seem like a natural extension, but
3347   there would be a conflict between attributes on the label and
3348   prefix attributes on the declaration.  ??? The syntax follows the
3349   old parser in requiring something after label declarations.
3350   Although they are erroneous if the labels declared aren't defined,
3351   is it useful for the syntax to be this way?
3352
3353   OpenMP:
3354
3355   block-item:
3356     openmp-directive
3357
3358   openmp-directive:
3359     barrier-directive
3360     flush-directive  */
3361
3362static tree
3363c_parser_compound_statement (c_parser *parser)
3364{
3365  tree stmt;
3366  if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3367    return error_mark_node;
3368  stmt = c_begin_compound_stmt (true);
3369  c_parser_compound_statement_nostart (parser);
3370  return c_end_compound_stmt (stmt, true);
3371}
3372
3373/* Parse a compound statement except for the opening brace.  This is
3374   used for parsing both compound statements and statement expressions
3375   (which follow different paths to handling the opening).  */
3376
3377static void
3378c_parser_compound_statement_nostart (c_parser *parser)
3379{
3380  bool last_stmt = false;
3381  bool last_label = false;
3382  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3383    {
3384      c_parser_consume_token (parser);
3385      return;
3386    }
3387  if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3388    {
3389      /* Read zero or more forward-declarations for labels that nested
3390	 functions can jump to.  */
3391      while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3392	{
3393	  c_parser_consume_token (parser);
3394	  /* Any identifiers, including those declared as type names,
3395	     are OK here.  */
3396	  while (true)
3397	    {
3398	      tree label;
3399	      if (c_parser_next_token_is_not (parser, CPP_NAME))
3400		{
3401		  c_parser_error (parser, "expected identifier");
3402		  break;
3403		}
3404	      label
3405		= declare_label (c_parser_peek_token (parser)->value);
3406	      C_DECLARED_LABEL_FLAG (label) = 1;
3407	      add_stmt (build_stmt (DECL_EXPR, label));
3408	      c_parser_consume_token (parser);
3409	      if (c_parser_next_token_is (parser, CPP_COMMA))
3410		c_parser_consume_token (parser);
3411	      else
3412		break;
3413	    }
3414	  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3415	}
3416      /* ??? Locating this diagnostic on the token after the
3417	 declarations end follows the old parser, but it might be
3418	 better to locate it where the declarations start instead.  */
3419      if (pedantic)
3420	pedwarn ("ISO C forbids label declarations");
3421    }
3422  /* We must now have at least one statement, label or declaration.  */
3423  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3424    {
3425      c_parser_error (parser, "expected declaration or statement");
3426      c_parser_consume_token (parser);
3427      return;
3428    }
3429  while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3430    {
3431      location_t loc = c_parser_peek_token (parser)->location;
3432      if (c_parser_next_token_is_keyword (parser, RID_CASE)
3433	  || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3434	  || (c_parser_next_token_is (parser, CPP_NAME)
3435	      && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3436	{
3437	  last_label = true;
3438	  last_stmt = false;
3439	  c_parser_label (parser);
3440	}
3441      else if (!last_label
3442	       && c_parser_next_token_starts_declspecs (parser))
3443	{
3444	  last_label = false;
3445	  c_parser_declaration_or_fndef (parser, true, true, true, true);
3446	  if (last_stmt
3447	      && ((pedantic && !flag_isoc99)
3448		  || warn_declaration_after_statement))
3449	    pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3450			 &loc);
3451	  last_stmt = false;
3452	}
3453      else if (!last_label
3454	       && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3455	{
3456	  /* __extension__ can start a declaration, but is also an
3457	     unary operator that can start an expression.  Consume all
3458	     but the last of a possible series of __extension__ to
3459	     determine which.  */
3460	  while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3461		 && (c_parser_peek_2nd_token (parser)->keyword
3462		     == RID_EXTENSION))
3463	    c_parser_consume_token (parser);
3464	  if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3465	    {
3466	      int ext;
3467	      ext = disable_extension_diagnostics ();
3468	      c_parser_consume_token (parser);
3469	      last_label = false;
3470	      c_parser_declaration_or_fndef (parser, true, true, true, true);
3471	      /* Following the old parser, __extension__ does not
3472		 disable this diagnostic.  */
3473	      restore_extension_diagnostics (ext);
3474	      if (last_stmt
3475		  && ((pedantic && !flag_isoc99)
3476		      || warn_declaration_after_statement))
3477		pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3478			     &loc);
3479	      last_stmt = false;
3480	    }
3481	  else
3482	    goto statement;
3483	}
3484      else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3485	{
3486	  /* External pragmas, and some omp pragmas, are not associated
3487	     with regular c code, and so are not to be considered statements
3488	     syntactically.  This ensures that the user doesn't put them
3489	     places that would turn into syntax errors if the directive
3490	     were ignored.  */
3491	  if (c_parser_pragma (parser, pragma_compound))
3492	    last_label = false, last_stmt = true;
3493	}
3494      else if (c_parser_next_token_is (parser, CPP_EOF))
3495	{
3496	  c_parser_error (parser, "expected declaration or statement");
3497	  return;
3498	}
3499      else
3500	{
3501	statement:
3502	  last_label = false;
3503	  last_stmt = true;
3504	  c_parser_statement_after_labels (parser);
3505	}
3506
3507      parser->error = false;
3508    }
3509  if (last_label)
3510    error ("label at end of compound statement");
3511  c_parser_consume_token (parser);
3512}
3513
3514/* Parse a label (C90 6.6.1, C99 6.8.1).
3515
3516   label:
3517     identifier : attributes[opt]
3518     case constant-expression :
3519     default :
3520
3521   GNU extensions:
3522
3523   label:
3524     case constant-expression ... constant-expression :
3525
3526   The use of attributes on labels is a GNU extension.  The syntax in
3527   GNU C accepts any expressions without commas, non-constant
3528   expressions being rejected later.  */
3529
3530static void
3531c_parser_label (c_parser *parser)
3532{
3533  location_t loc1 = c_parser_peek_token (parser)->location;
3534  tree label = NULL_TREE;
3535  if (c_parser_next_token_is_keyword (parser, RID_CASE))
3536    {
3537      tree exp1, exp2;
3538      c_parser_consume_token (parser);
3539      exp1 = c_parser_expr_no_commas (parser, NULL).value;
3540      if (c_parser_next_token_is (parser, CPP_COLON))
3541	{
3542	  c_parser_consume_token (parser);
3543	  label = do_case (exp1, NULL_TREE);
3544	}
3545      else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3546	{
3547	  c_parser_consume_token (parser);
3548	  exp2 = c_parser_expr_no_commas (parser, NULL).value;
3549	  if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3550	    label = do_case (exp1, exp2);
3551	}
3552      else
3553	c_parser_error (parser, "expected %<:%> or %<...%>");
3554    }
3555  else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3556    {
3557      c_parser_consume_token (parser);
3558      if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3559	label = do_case (NULL_TREE, NULL_TREE);
3560    }
3561  else
3562    {
3563      tree name = c_parser_peek_token (parser)->value;
3564      tree tlab;
3565      location_t loc2;
3566      tree attrs;
3567      gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3568      c_parser_consume_token (parser);
3569      gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3570      loc2 = c_parser_peek_token (parser)->location;
3571      c_parser_consume_token (parser);
3572      attrs = c_parser_attributes (parser);
3573      tlab = define_label (loc2, name);
3574      if (tlab)
3575	{
3576	  decl_attributes (&tlab, attrs, 0);
3577	  label = add_stmt (build_stmt (LABEL_EXPR, tlab));
3578	}
3579    }
3580  if (label)
3581    SET_EXPR_LOCATION (label, loc1);
3582}
3583
3584/* Parse a statement (C90 6.6, C99 6.8).
3585
3586   statement:
3587     labeled-statement
3588     compound-statement
3589     expression-statement
3590     selection-statement
3591     iteration-statement
3592     jump-statement
3593
3594   labeled-statement:
3595     label statement
3596
3597   expression-statement:
3598     expression[opt] ;
3599
3600   selection-statement:
3601     if-statement
3602     switch-statement
3603
3604   iteration-statement:
3605     while-statement
3606     do-statement
3607     for-statement
3608
3609   jump-statement:
3610     goto identifier ;
3611     continue ;
3612     break ;
3613     return expression[opt] ;
3614
3615   GNU extensions:
3616
3617   statement:
3618     asm-statement
3619
3620   jump-statement:
3621     goto * expression ;
3622
3623   Objective-C:
3624
3625   statement:
3626     objc-throw-statement
3627     objc-try-catch-statement
3628     objc-synchronized-statement
3629
3630   objc-throw-statement:
3631     @throw expression ;
3632     @throw ;
3633
3634   OpenMP:
3635
3636   statement:
3637     openmp-construct
3638
3639   openmp-construct:
3640     parallel-construct
3641     for-construct
3642     sections-construct
3643     single-construct
3644     parallel-for-construct
3645     parallel-sections-construct
3646     master-construct
3647     critical-construct
3648     atomic-construct
3649     ordered-construct
3650
3651   parallel-construct:
3652     parallel-directive structured-block
3653
3654   for-construct:
3655     for-directive iteration-statement
3656
3657   sections-construct:
3658     sections-directive section-scope
3659
3660   single-construct:
3661     single-directive structured-block
3662
3663   parallel-for-construct:
3664     parallel-for-directive iteration-statement
3665
3666   parallel-sections-construct:
3667     parallel-sections-directive section-scope
3668
3669   master-construct:
3670     master-directive structured-block
3671
3672   critical-construct:
3673     critical-directive structured-block
3674
3675   atomic-construct:
3676     atomic-directive expression-statement
3677
3678   ordered-construct:
3679     ordered-directive structured-block  */
3680
3681static void
3682c_parser_statement (c_parser *parser)
3683{
3684  while (c_parser_next_token_is_keyword (parser, RID_CASE)
3685	 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3686	 || (c_parser_next_token_is (parser, CPP_NAME)
3687	     && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3688    c_parser_label (parser);
3689  c_parser_statement_after_labels (parser);
3690}
3691
3692/* Parse a statement, other than a labeled statement.  */
3693
3694static void
3695c_parser_statement_after_labels (c_parser *parser)
3696{
3697  location_t loc = c_parser_peek_token (parser)->location;
3698  tree stmt = NULL_TREE;
3699  switch (c_parser_peek_token (parser)->type)
3700    {
3701    case CPP_OPEN_BRACE:
3702      add_stmt (c_parser_compound_statement (parser));
3703      break;
3704    case CPP_KEYWORD:
3705      switch (c_parser_peek_token (parser)->keyword)
3706	{
3707	case RID_IF:
3708	  c_parser_if_statement (parser);
3709	  break;
3710	case RID_SWITCH:
3711	  c_parser_switch_statement (parser);
3712	  break;
3713	case RID_WHILE:
3714	  c_parser_while_statement (parser);
3715	  break;
3716	case RID_DO:
3717	  c_parser_do_statement (parser);
3718	  break;
3719	case RID_FOR:
3720	  c_parser_for_statement (parser);
3721	  break;
3722	case RID_GOTO:
3723	  c_parser_consume_token (parser);
3724	  if (c_parser_next_token_is (parser, CPP_NAME))
3725	    {
3726	      stmt = c_finish_goto_label (c_parser_peek_token (parser)->value);
3727	      c_parser_consume_token (parser);
3728	    }
3729	  else if (c_parser_next_token_is (parser, CPP_MULT))
3730	    {
3731	      c_parser_consume_token (parser);
3732	      stmt = c_finish_goto_ptr (c_parser_expression (parser).value);
3733	    }
3734	  else
3735	    c_parser_error (parser, "expected identifier or %<*%>");
3736	  goto expect_semicolon;
3737	case RID_CONTINUE:
3738	  c_parser_consume_token (parser);
3739	  stmt = c_finish_bc_stmt (&c_cont_label, false);
3740	  goto expect_semicolon;
3741	case RID_BREAK:
3742	  c_parser_consume_token (parser);
3743	  stmt = c_finish_bc_stmt (&c_break_label, true);
3744	  goto expect_semicolon;
3745	case RID_RETURN:
3746	  c_parser_consume_token (parser);
3747	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3748	    {
3749	      stmt = c_finish_return (NULL_TREE);
3750	      c_parser_consume_token (parser);
3751	    }
3752	  else
3753	    {
3754	      stmt = c_finish_return (c_parser_expression_conv (parser).value);
3755	      goto expect_semicolon;
3756	    }
3757	  break;
3758	case RID_ASM:
3759	  stmt = c_parser_asm_statement (parser);
3760	  break;
3761	case RID_AT_THROW:
3762	  gcc_assert (c_dialect_objc ());
3763	  c_parser_consume_token (parser);
3764	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3765	    {
3766	      stmt = objc_build_throw_stmt (NULL_TREE);
3767	      c_parser_consume_token (parser);
3768	    }
3769	  else
3770	    {
3771	      stmt
3772		= objc_build_throw_stmt (c_parser_expression (parser).value);
3773	      goto expect_semicolon;
3774	    }
3775	  break;
3776	case RID_AT_TRY:
3777	  gcc_assert (c_dialect_objc ());
3778	  c_parser_objc_try_catch_statement (parser);
3779	  break;
3780	case RID_AT_SYNCHRONIZED:
3781	  gcc_assert (c_dialect_objc ());
3782	  c_parser_objc_synchronized_statement (parser);
3783	  break;
3784	default:
3785	  goto expr_stmt;
3786	}
3787      break;
3788    case CPP_SEMICOLON:
3789      c_parser_consume_token (parser);
3790      break;
3791    case CPP_CLOSE_PAREN:
3792    case CPP_CLOSE_SQUARE:
3793      /* Avoid infinite loop in error recovery:
3794	 c_parser_skip_until_found stops at a closing nesting
3795	 delimiter without consuming it, but here we need to consume
3796	 it to proceed further.  */
3797      c_parser_error (parser, "expected statement");
3798      c_parser_consume_token (parser);
3799      break;
3800    case CPP_PRAGMA:
3801      c_parser_pragma (parser, pragma_stmt);
3802      break;
3803    default:
3804    expr_stmt:
3805      stmt = c_finish_expr_stmt (c_parser_expression_conv (parser).value);
3806    expect_semicolon:
3807      c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3808      break;
3809    }
3810  /* Two cases cannot and do not have line numbers associated: If stmt
3811     is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3812     cannot hold line numbers.  But that's OK because the statement
3813     will either be changed to a MODIFY_EXPR during gimplification of
3814     the statement expr, or discarded.  If stmt was compound, but
3815     without new variables, we will have skipped the creation of a
3816     BIND and will have a bare STATEMENT_LIST.  But that's OK because
3817     (recursively) all of the component statements should already have
3818     line numbers assigned.  ??? Can we discard no-op statements
3819     earlier?  */
3820  if (stmt && EXPR_P (stmt))
3821    SET_EXPR_LOCATION (stmt, loc);
3822}
3823
3824/* Parse a parenthesized condition from an if, do or while statement.
3825
3826   condition:
3827     ( expression )
3828*/
3829static tree
3830c_parser_paren_condition (c_parser *parser)
3831{
3832  location_t loc;
3833  tree cond;
3834  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3835    return error_mark_node;
3836  loc = c_parser_peek_token (parser)->location;
3837  cond = c_objc_common_truthvalue_conversion
3838    (c_parser_expression_conv (parser).value);
3839  if (EXPR_P (cond))
3840    SET_EXPR_LOCATION (cond, loc);
3841  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3842  return cond;
3843}
3844
3845/* Parse a statement which is a block in C99.  */
3846
3847static tree
3848c_parser_c99_block_statement (c_parser *parser)
3849{
3850  tree block = c_begin_compound_stmt (flag_isoc99);
3851  c_parser_statement (parser);
3852  return c_end_compound_stmt (block, flag_isoc99);
3853}
3854
3855/* Parse the body of an if statement or the else half thereof.  This
3856   is just parsing a statement but (a) it is a block in C99, (b) we
3857   track whether the body is an if statement for the sake of
3858   -Wparentheses warnings, (c) we handle an empty body specially for
3859   the sake of -Wextra warnings.  */
3860
3861static tree
3862c_parser_if_body (c_parser *parser, bool *if_p)
3863{
3864  tree block = c_begin_compound_stmt (flag_isoc99);
3865  while (c_parser_next_token_is_keyword (parser, RID_CASE)
3866	 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3867	 || (c_parser_next_token_is (parser, CPP_NAME)
3868	     && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3869    c_parser_label (parser);
3870  *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
3871  if (extra_warnings && c_parser_next_token_is (parser, CPP_SEMICOLON))
3872    add_stmt (build_empty_stmt ());
3873  c_parser_statement_after_labels (parser);
3874  return c_end_compound_stmt (block, flag_isoc99);
3875}
3876
3877/* Parse an if statement (C90 6.6.4, C99 6.8.4).
3878
3879   if-statement:
3880     if ( expression ) statement
3881     if ( expression ) statement else statement
3882*/
3883
3884static void
3885c_parser_if_statement (c_parser *parser)
3886{
3887  tree block;
3888  location_t loc;
3889  tree cond;
3890  bool first_if = false, second_if = false;
3891  tree first_body, second_body;
3892  gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
3893  c_parser_consume_token (parser);
3894  block = c_begin_compound_stmt (flag_isoc99);
3895  loc = c_parser_peek_token (parser)->location;
3896  cond = c_parser_paren_condition (parser);
3897  first_body = c_parser_if_body (parser, &first_if);
3898  if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3899    {
3900      c_parser_consume_token (parser);
3901      second_body = c_parser_if_body (parser, &second_if);
3902    }
3903  else
3904    second_body = NULL_TREE;
3905  c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
3906  add_stmt (c_end_compound_stmt (block, flag_isoc99));
3907}
3908
3909/* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3910
3911   switch-statement:
3912     switch (expression) statement
3913*/
3914
3915static void
3916c_parser_switch_statement (c_parser *parser)
3917{
3918  tree block, expr, body, save_break;
3919  gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
3920  c_parser_consume_token (parser);
3921  block = c_begin_compound_stmt (flag_isoc99);
3922  if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3923    {
3924      expr = c_parser_expression (parser).value;
3925      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3926    }
3927  else
3928    expr = error_mark_node;
3929  c_start_case (expr);
3930  save_break = c_break_label;
3931  c_break_label = NULL_TREE;
3932  body = c_parser_c99_block_statement (parser);
3933  c_finish_case (body);
3934  if (c_break_label)
3935    add_stmt (build1 (LABEL_EXPR, void_type_node, c_break_label));
3936  c_break_label = save_break;
3937  add_stmt (c_end_compound_stmt (block, flag_isoc99));
3938}
3939
3940/* Parse a while statement (C90 6.6.5, C99 6.8.5).
3941
3942   while-statement:
3943   APPLE LOCAL begin for-fsf-4_4 3274130 5295549
3944      while attributes (expression) statement
3945
3946   The use of attributes is a GNU extension.
3947   APPLE LOCAL end for-fsf-4_4 3274130 5295549
3948*/
3949
3950static void
3951c_parser_while_statement (c_parser *parser)
3952{
3953/* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
3954  tree block, cond, body, save_break, save_cont, attrs;
3955/* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
3956  location_t loc;
3957  gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
3958  c_parser_consume_token (parser);
3959/* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
3960  attrs = c_parser_attributes (parser);
3961/* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
3962  block = c_begin_compound_stmt (flag_isoc99);
3963  loc = c_parser_peek_token (parser)->location;
3964  cond = c_parser_paren_condition (parser);
3965  save_break = c_break_label;
3966  c_break_label = NULL_TREE;
3967  save_cont = c_cont_label;
3968  c_cont_label = NULL_TREE;
3969  body = c_parser_c99_block_statement (parser);
3970/* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
3971  c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, attrs,
3972		 true);
3973/* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
3974  add_stmt (c_end_compound_stmt (block, flag_isoc99));
3975  c_break_label = save_break;
3976  c_cont_label = save_cont;
3977}
3978
3979/* Parse a do statement (C90 6.6.5, C99 6.8.5).
3980
3981   do-statement:
3982   APPLE LOCAL begin for-fsf-4_4 3274130 5295549
3983     do attributes statement while ( expression ) ;
3984
3985   The use of attributes is a GNU extension.
3986   APPLE LOCAL end for-fsf-4_4 3274130 5295549
3987*/
3988
3989static void
3990c_parser_do_statement (c_parser *parser)
3991{
3992/* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
3993  tree block, cond, body, save_break, save_cont, new_break, new_cont, attrs;
3994/* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
3995  location_t loc;
3996  gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
3997  c_parser_consume_token (parser);
3998/* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
3999  attrs = c_parser_attributes (parser);
4000/* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
4001  block = c_begin_compound_stmt (flag_isoc99);
4002  loc = c_parser_peek_token (parser)->location;
4003  save_break = c_break_label;
4004  c_break_label = NULL_TREE;
4005  save_cont = c_cont_label;
4006  c_cont_label = NULL_TREE;
4007  body = c_parser_c99_block_statement (parser);
4008  c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4009  new_break = c_break_label;
4010  c_break_label = save_break;
4011  new_cont = c_cont_label;
4012  c_cont_label = save_cont;
4013  cond = c_parser_paren_condition (parser);
4014  if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4015    c_parser_skip_to_end_of_block_or_statement (parser);
4016/* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
4017  c_finish_loop (loc, cond, NULL, body, new_break, new_cont, attrs, false);
4018/* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
4019  add_stmt (c_end_compound_stmt (block, flag_isoc99));
4020}
4021
4022/* Parse a for statement (C90 6.6.5, C99 6.8.5).
4023
4024   for-statement:
4025   APPLE LOCAL begin for-fsf-4_4 3274130 5295549
4026     for attributes ( expression[opt] ; expression[opt] ; expression[opt] ) \
4027         statement
4028     for attributes ( nested-declaration expression[opt] ; expression[opt] ) \
4029         statement
4030
4031   The form with a declaration is new in C99.
4032
4033   The use of attributes is a GNU extension.
4034
4035   APPLE LOCAL end for-fsf-4_4 3274130 5295549
4036   ??? In accordance with the old parser, the declaration may be a
4037   nested function, which is then rejected in check_for_loop_decls,
4038   but does it make any sense for this to be included in the grammar?
4039   Note in particular that the nested function does not include a
4040   trailing ';', whereas the "declaration" production includes one.
4041   Also, can we reject bad declarations earlier and cheaper than
4042   check_for_loop_decls?  */
4043
4044static void
4045c_parser_for_statement (c_parser *parser)
4046{
4047/* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
4048  tree block, cond, incr, save_break, save_cont, body, attrs;
4049/* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
4050  location_t loc;
4051  gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4052  loc = c_parser_peek_token (parser)->location;
4053  c_parser_consume_token (parser);
4054/* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
4055  attrs = c_parser_attributes (parser);
4056/* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
4057  block = c_begin_compound_stmt (flag_isoc99);
4058  if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4059    {
4060      /* Parse the initialization declaration or expression.  */
4061      if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4062	{
4063	  c_parser_consume_token (parser);
4064	  c_finish_expr_stmt (NULL_TREE);
4065	}
4066      else if (c_parser_next_token_starts_declspecs (parser))
4067	{
4068	  c_parser_declaration_or_fndef (parser, true, true, true, true);
4069	  check_for_loop_decls ();
4070	}
4071      else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4072	{
4073	  /* __extension__ can start a declaration, but is also an
4074	     unary operator that can start an expression.  Consume all
4075	     but the last of a possible series of __extension__ to
4076	     determine which.  */
4077	  while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4078		 && (c_parser_peek_2nd_token (parser)->keyword
4079		     == RID_EXTENSION))
4080	    c_parser_consume_token (parser);
4081	  if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
4082	    {
4083	      int ext;
4084	      ext = disable_extension_diagnostics ();
4085	      c_parser_consume_token (parser);
4086	      c_parser_declaration_or_fndef (parser, true, true, true, true);
4087	      restore_extension_diagnostics (ext);
4088	      check_for_loop_decls ();
4089	    }
4090	  else
4091	    goto init_expr;
4092	}
4093      else
4094	{
4095	init_expr:
4096	  c_finish_expr_stmt (c_parser_expression (parser).value);
4097	  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4098	}
4099      /* Parse the loop condition.  */
4100      loc = c_parser_peek_token (parser)->location;
4101      if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4102	{
4103	  c_parser_consume_token (parser);
4104	  cond = NULL_TREE;
4105	}
4106      else
4107	{
4108	  tree ocond = c_parser_expression_conv (parser).value;
4109	  cond = c_objc_common_truthvalue_conversion (ocond);
4110	  if (EXPR_P (cond))
4111	    SET_EXPR_LOCATION (cond, loc);
4112	  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4113	}
4114      /* Parse the increment expression.  */
4115      if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4116	incr = c_process_expr_stmt (NULL_TREE);
4117      else
4118	incr = c_process_expr_stmt (c_parser_expression (parser).value);
4119      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4120    }
4121  else
4122    {
4123      cond = error_mark_node;
4124      incr = error_mark_node;
4125    }
4126  save_break = c_break_label;
4127  c_break_label = NULL_TREE;
4128  save_cont = c_cont_label;
4129  c_cont_label = NULL_TREE;
4130  body = c_parser_c99_block_statement (parser);
4131/* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
4132    c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, attrs,
4133		   true);
4134/* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
4135  add_stmt (c_end_compound_stmt (block, flag_isoc99));
4136  c_break_label = save_break;
4137  c_cont_label = save_cont;
4138}
4139
4140/* Parse an asm statement, a GNU extension.  This is a full-blown asm
4141   statement with inputs, outputs, clobbers, and volatile tag
4142   allowed.
4143
4144   asm-statement:
4145     asm type-qualifier[opt] ( asm-argument ) ;
4146
4147   asm-argument:
4148     asm-string-literal
4149     asm-string-literal : asm-operands[opt]
4150     asm-string-literal : asm-operands[opt] : asm-operands[opt]
4151     asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4152
4153   Qualifiers other than volatile are accepted in the syntax but
4154   warned for.  */
4155
4156static tree
4157c_parser_asm_statement (c_parser *parser)
4158{
4159  tree quals, str, outputs, inputs, clobbers, ret;
4160  bool simple;
4161  gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4162  c_parser_consume_token (parser);
4163  if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4164    {
4165      quals = c_parser_peek_token (parser)->value;
4166      c_parser_consume_token (parser);
4167    }
4168  else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4169	   || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4170    {
4171      warning (0, "%E qualifier ignored on asm",
4172	       c_parser_peek_token (parser)->value);
4173      quals = NULL_TREE;
4174      c_parser_consume_token (parser);
4175    }
4176  else
4177    quals = NULL_TREE;
4178  /* ??? Follow the C++ parser rather than using the
4179     c_lex_string_translate kludge.  */
4180  c_lex_string_translate = 0;
4181  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4182    {
4183      c_lex_string_translate = 1;
4184      return NULL_TREE;
4185    }
4186  str = c_parser_asm_string_literal (parser);
4187  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4188    {
4189      simple = true;
4190      outputs = NULL_TREE;
4191      inputs = NULL_TREE;
4192      clobbers = NULL_TREE;
4193      goto done_asm;
4194    }
4195  if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4196    {
4197      c_lex_string_translate = 1;
4198      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4199      return NULL_TREE;
4200    }
4201  simple = false;
4202  /* Parse outputs.  */
4203  if (c_parser_next_token_is (parser, CPP_COLON)
4204      || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4205    outputs = NULL_TREE;
4206  else
4207    outputs = c_parser_asm_operands (parser, false);
4208  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4209    {
4210      inputs = NULL_TREE;
4211      clobbers = NULL_TREE;
4212      goto done_asm;
4213    }
4214  if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4215    {
4216      c_lex_string_translate = 1;
4217      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4218      return NULL_TREE;
4219    }
4220  /* Parse inputs.  */
4221  if (c_parser_next_token_is (parser, CPP_COLON)
4222      || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4223    inputs = NULL_TREE;
4224  else
4225    inputs = c_parser_asm_operands (parser, true);
4226  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4227    {
4228      clobbers = NULL_TREE;
4229      goto done_asm;
4230    }
4231  if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4232    {
4233      c_lex_string_translate = 1;
4234      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4235      return NULL_TREE;
4236    }
4237  /* Parse clobbers.  */
4238  clobbers = c_parser_asm_clobbers (parser);
4239 done_asm:
4240  c_lex_string_translate = 1;
4241  if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4242    {
4243      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4244      return NULL_TREE;
4245    }
4246  if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4247    c_parser_skip_to_end_of_block_or_statement (parser);
4248  ret = build_asm_stmt (quals, build_asm_expr (str, outputs, inputs,
4249					       clobbers, simple));
4250  return ret;
4251}
4252
4253/* Parse asm operands, a GNU extension.  If CONVERT_P (for inputs but
4254   not outputs), apply the default conversion of functions and arrays
4255   to pointers.
4256
4257   asm-operands:
4258     asm-operand
4259     asm-operands , asm-operand
4260
4261   asm-operand:
4262     asm-string-literal ( expression )
4263     [ identifier ] asm-string-literal ( expression )
4264*/
4265
4266static tree
4267c_parser_asm_operands (c_parser *parser, bool convert_p)
4268{
4269  tree list = NULL_TREE;
4270  while (true)
4271    {
4272      tree name, str;
4273      struct c_expr expr;
4274      if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4275	{
4276	  c_parser_consume_token (parser);
4277	  if (c_parser_next_token_is (parser, CPP_NAME))
4278	    {
4279	      tree id = c_parser_peek_token (parser)->value;
4280	      c_parser_consume_token (parser);
4281	      name = build_string (IDENTIFIER_LENGTH (id),
4282				   IDENTIFIER_POINTER (id));
4283	    }
4284	  else
4285	    {
4286	      c_parser_error (parser, "expected identifier");
4287	      c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4288	      return NULL_TREE;
4289	    }
4290	  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4291				     "expected %<]%>");
4292	}
4293      else
4294	name = NULL_TREE;
4295      str = c_parser_asm_string_literal (parser);
4296      if (str == NULL_TREE)
4297	return NULL_TREE;
4298      c_lex_string_translate = 1;
4299      if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4300	{
4301	  c_lex_string_translate = 0;
4302	  return NULL_TREE;
4303	}
4304      expr = c_parser_expression (parser);
4305      if (convert_p)
4306	expr = default_function_array_conversion (expr);
4307      c_lex_string_translate = 0;
4308      if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4309	{
4310	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4311	  return NULL_TREE;
4312	}
4313      list = chainon (list, build_tree_list (build_tree_list (name, str),
4314					     expr.value));
4315      if (c_parser_next_token_is (parser, CPP_COMMA))
4316	c_parser_consume_token (parser);
4317      else
4318	break;
4319    }
4320  return list;
4321}
4322
4323/* Parse asm clobbers, a GNU extension.
4324
4325   asm-clobbers:
4326     asm-string-literal
4327     asm-clobbers , asm-string-literal
4328*/
4329
4330static tree
4331c_parser_asm_clobbers (c_parser *parser)
4332{
4333  tree list = NULL_TREE;
4334  while (true)
4335    {
4336      tree str = c_parser_asm_string_literal (parser);
4337      if (str)
4338	list = tree_cons (NULL_TREE, str, list);
4339      else
4340	return NULL_TREE;
4341      if (c_parser_next_token_is (parser, CPP_COMMA))
4342	c_parser_consume_token (parser);
4343      else
4344	break;
4345    }
4346  return list;
4347}
4348
4349/* Parse an expression other than a compound expression; that is, an
4350   assignment expression (C90 6.3.16, C99 6.5.16).  If AFTER is not
4351   NULL then it is an Objective-C message expression which is the
4352   primary-expression starting the expression as an initializer.
4353
4354   assignment-expression:
4355     conditional-expression
4356     unary-expression assignment-operator assignment-expression
4357
4358   assignment-operator: one of
4359     = *= /= %= += -= <<= >>= &= ^= |=
4360
4361   In GNU C we accept any conditional expression on the LHS and
4362   diagnose the invalid lvalue rather than producing a syntax
4363   error.  */
4364
4365static struct c_expr
4366c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4367{
4368  struct c_expr lhs, rhs, ret;
4369  enum tree_code code;
4370  gcc_assert (!after || c_dialect_objc ());
4371  lhs = c_parser_conditional_expression (parser, after);
4372  switch (c_parser_peek_token (parser)->type)
4373    {
4374    case CPP_EQ:
4375      code = NOP_EXPR;
4376      break;
4377    case CPP_MULT_EQ:
4378      code = MULT_EXPR;
4379      break;
4380    case CPP_DIV_EQ:
4381      code = TRUNC_DIV_EXPR;
4382      break;
4383    case CPP_MOD_EQ:
4384      code = TRUNC_MOD_EXPR;
4385      break;
4386    case CPP_PLUS_EQ:
4387      code = PLUS_EXPR;
4388      break;
4389    case CPP_MINUS_EQ:
4390      code = MINUS_EXPR;
4391      break;
4392    case CPP_LSHIFT_EQ:
4393      code = LSHIFT_EXPR;
4394      break;
4395    case CPP_RSHIFT_EQ:
4396      code = RSHIFT_EXPR;
4397      break;
4398    case CPP_AND_EQ:
4399      code = BIT_AND_EXPR;
4400      break;
4401    case CPP_XOR_EQ:
4402      code = BIT_XOR_EXPR;
4403      break;
4404    case CPP_OR_EQ:
4405      code = BIT_IOR_EXPR;
4406      break;
4407    default:
4408      return lhs;
4409    }
4410  c_parser_consume_token (parser);
4411  rhs = c_parser_expr_no_commas (parser, NULL);
4412  rhs = default_function_array_conversion (rhs);
4413  ret.value = build_modify_expr (lhs.value, code, rhs.value);
4414  if (code == NOP_EXPR)
4415    ret.original_code = MODIFY_EXPR;
4416  else
4417    {
4418      TREE_NO_WARNING (ret.value) = 1;
4419      ret.original_code = ERROR_MARK;
4420    }
4421  return ret;
4422}
4423
4424/* Parse a conditional expression (C90 6.3.15, C99 6.5.15).  If AFTER
4425   is not NULL then it is an Objective-C message expression which is
4426   the primary-expression starting the expression as an initializer.
4427
4428   conditional-expression:
4429     logical-OR-expression
4430     logical-OR-expression ? expression : conditional-expression
4431
4432   GNU extensions:
4433
4434   conditional-expression:
4435     logical-OR-expression ? : conditional-expression
4436*/
4437
4438static struct c_expr
4439c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4440{
4441  struct c_expr cond, exp1, exp2, ret;
4442  gcc_assert (!after || c_dialect_objc ());
4443  cond = c_parser_binary_expression (parser, after);
4444  if (c_parser_next_token_is_not (parser, CPP_QUERY))
4445    return cond;
4446  cond = default_function_array_conversion (cond);
4447  c_parser_consume_token (parser);
4448  if (c_parser_next_token_is (parser, CPP_COLON))
4449    {
4450      if (pedantic)
4451	pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
4452      /* Make sure first operand is calculated only once.  */
4453      exp1.value = save_expr (default_conversion (cond.value));
4454      cond.value = c_objc_common_truthvalue_conversion (exp1.value);
4455      skip_evaluation += cond.value == truthvalue_true_node;
4456    }
4457  else
4458    {
4459      cond.value
4460	= c_objc_common_truthvalue_conversion
4461	(default_conversion (cond.value));
4462      skip_evaluation += cond.value == truthvalue_false_node;
4463      exp1 = c_parser_expression_conv (parser);
4464      skip_evaluation += ((cond.value == truthvalue_true_node)
4465			  - (cond.value == truthvalue_false_node));
4466    }
4467  if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4468    {
4469      skip_evaluation -= cond.value == truthvalue_true_node;
4470      ret.value = error_mark_node;
4471      ret.original_code = ERROR_MARK;
4472      return ret;
4473    }
4474  exp2 = c_parser_conditional_expression (parser, NULL);
4475  exp2 = default_function_array_conversion (exp2);
4476  skip_evaluation -= cond.value == truthvalue_true_node;
4477  ret.value = build_conditional_expr (cond.value, exp1.value, exp2.value);
4478  ret.original_code = ERROR_MARK;
4479  return ret;
4480}
4481
4482/* Parse a binary expression; that is, a logical-OR-expression (C90
4483   6.3.5-6.3.14, C99 6.5.5-6.5.14).  If AFTER is not NULL then it is
4484   an Objective-C message expression which is the primary-expression
4485   starting the expression as an initializer.
4486
4487   multiplicative-expression:
4488     cast-expression
4489     multiplicative-expression * cast-expression
4490     multiplicative-expression / cast-expression
4491     multiplicative-expression % cast-expression
4492
4493   additive-expression:
4494     multiplicative-expression
4495     additive-expression + multiplicative-expression
4496     additive-expression - multiplicative-expression
4497
4498   shift-expression:
4499     additive-expression
4500     shift-expression << additive-expression
4501     shift-expression >> additive-expression
4502
4503   relational-expression:
4504     shift-expression
4505     relational-expression < shift-expression
4506     relational-expression > shift-expression
4507     relational-expression <= shift-expression
4508     relational-expression >= shift-expression
4509
4510   equality-expression:
4511     relational-expression
4512     equality-expression == relational-expression
4513     equality-expression != relational-expression
4514
4515   AND-expression:
4516     equality-expression
4517     AND-expression & equality-expression
4518
4519   exclusive-OR-expression:
4520     AND-expression
4521     exclusive-OR-expression ^ AND-expression
4522
4523   inclusive-OR-expression:
4524     exclusive-OR-expression
4525     inclusive-OR-expression | exclusive-OR-expression
4526
4527   logical-AND-expression:
4528     inclusive-OR-expression
4529     logical-AND-expression && inclusive-OR-expression
4530
4531   logical-OR-expression:
4532     logical-AND-expression
4533     logical-OR-expression || logical-AND-expression
4534*/
4535
4536static struct c_expr
4537c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4538{
4539  /* A binary expression is parsed using operator-precedence parsing,
4540     with the operands being cast expressions.  All the binary
4541     operators are left-associative.  Thus a binary expression is of
4542     form:
4543
4544     E0 op1 E1 op2 E2 ...
4545
4546     which we represent on a stack.  On the stack, the precedence
4547     levels are strictly increasing.  When a new operator is
4548     encountered of higher precedence than that at the top of the
4549     stack, it is pushed; its LHS is the top expression, and its RHS
4550     is everything parsed until it is popped.  When a new operator is
4551     encountered with precedence less than or equal to that at the top
4552     of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4553     by the result of the operation until the operator at the top of
4554     the stack has lower precedence than the new operator or there is
4555     only one element on the stack; then the top expression is the LHS
4556     of the new operator.  In the case of logical AND and OR
4557     expressions, we also need to adjust skip_evaluation as
4558     appropriate when the operators are pushed and popped.  */
4559
4560  /* The precedence levels, where 0 is a dummy lowest level used for
4561     the bottom of the stack.  */
4562  enum prec {
4563    PREC_NONE,
4564    PREC_LOGOR,
4565    PREC_LOGAND,
4566    PREC_BITOR,
4567    PREC_BITXOR,
4568    PREC_BITAND,
4569    PREC_EQ,
4570    PREC_REL,
4571    PREC_SHIFT,
4572    PREC_ADD,
4573    PREC_MULT,
4574    NUM_PRECS
4575  };
4576  struct {
4577    /* The expression at this stack level.  */
4578    struct c_expr expr;
4579    /* The precedence of the operator on its left, PREC_NONE at the
4580       bottom of the stack.  */
4581    enum prec prec;
4582    /* The operation on its left.  */
4583    enum tree_code op;
4584  } stack[NUM_PRECS];
4585  int sp;
4586#define POP								      \
4587  do {									      \
4588    switch (stack[sp].op)						      \
4589      {									      \
4590      case TRUTH_ANDIF_EXPR:						      \
4591	skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4592	break;								      \
4593      case TRUTH_ORIF_EXPR:						      \
4594	skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node;  \
4595	break;								      \
4596      default:								      \
4597	break;								      \
4598      }									      \
4599    stack[sp - 1].expr							      \
4600      = default_function_array_conversion (stack[sp - 1].expr);		      \
4601    stack[sp].expr							      \
4602      = default_function_array_conversion (stack[sp].expr);		      \
4603    stack[sp - 1].expr = parser_build_binary_op (stack[sp].op,		      \
4604						 stack[sp - 1].expr,	      \
4605						 stack[sp].expr);	      \
4606    sp--;								      \
4607  } while (0)
4608  gcc_assert (!after || c_dialect_objc ());
4609  stack[0].expr = c_parser_cast_expression (parser, after);
4610  stack[0].prec = PREC_NONE;
4611  sp = 0;
4612  while (true)
4613    {
4614      enum prec oprec;
4615      enum tree_code ocode;
4616      if (parser->error)
4617	goto out;
4618      switch (c_parser_peek_token (parser)->type)
4619	{
4620	case CPP_MULT:
4621	  oprec = PREC_MULT;
4622	  ocode = MULT_EXPR;
4623	  break;
4624	case CPP_DIV:
4625	  oprec = PREC_MULT;
4626	  ocode = TRUNC_DIV_EXPR;
4627	  break;
4628	case CPP_MOD:
4629	  oprec = PREC_MULT;
4630	  ocode = TRUNC_MOD_EXPR;
4631	  break;
4632	case CPP_PLUS:
4633	  oprec = PREC_ADD;
4634	  ocode = PLUS_EXPR;
4635	  break;
4636	case CPP_MINUS:
4637	  oprec = PREC_ADD;
4638	  ocode = MINUS_EXPR;
4639	  break;
4640	case CPP_LSHIFT:
4641	  oprec = PREC_SHIFT;
4642	  ocode = LSHIFT_EXPR;
4643	  break;
4644	case CPP_RSHIFT:
4645	  oprec = PREC_SHIFT;
4646	  ocode = RSHIFT_EXPR;
4647	  break;
4648	case CPP_LESS:
4649	  oprec = PREC_REL;
4650	  ocode = LT_EXPR;
4651	  break;
4652	case CPP_GREATER:
4653	  oprec = PREC_REL;
4654	  ocode = GT_EXPR;
4655	  break;
4656	case CPP_LESS_EQ:
4657	  oprec = PREC_REL;
4658	  ocode = LE_EXPR;
4659	  break;
4660	case CPP_GREATER_EQ:
4661	  oprec = PREC_REL;
4662	  ocode = GE_EXPR;
4663	  break;
4664	case CPP_EQ_EQ:
4665	  oprec = PREC_EQ;
4666	  ocode = EQ_EXPR;
4667	  break;
4668	case CPP_NOT_EQ:
4669	  oprec = PREC_EQ;
4670	  ocode = NE_EXPR;
4671	  break;
4672	case CPP_AND:
4673	  oprec = PREC_BITAND;
4674	  ocode = BIT_AND_EXPR;
4675	  break;
4676	case CPP_XOR:
4677	  oprec = PREC_BITXOR;
4678	  ocode = BIT_XOR_EXPR;
4679	  break;
4680	case CPP_OR:
4681	  oprec = PREC_BITOR;
4682	  ocode = BIT_IOR_EXPR;
4683	  break;
4684	case CPP_AND_AND:
4685	  oprec = PREC_LOGAND;
4686	  ocode = TRUTH_ANDIF_EXPR;
4687	  break;
4688	case CPP_OR_OR:
4689	  oprec = PREC_LOGOR;
4690	  ocode = TRUTH_ORIF_EXPR;
4691	  break;
4692	default:
4693	  /* Not a binary operator, so end of the binary
4694	     expression.  */
4695	  goto out;
4696	}
4697      c_parser_consume_token (parser);
4698      while (oprec <= stack[sp].prec)
4699	POP;
4700      switch (ocode)
4701	{
4702	case TRUTH_ANDIF_EXPR:
4703	  stack[sp].expr
4704	    = default_function_array_conversion (stack[sp].expr);
4705	  stack[sp].expr.value = c_objc_common_truthvalue_conversion
4706	    (default_conversion (stack[sp].expr.value));
4707	  skip_evaluation += stack[sp].expr.value == truthvalue_false_node;
4708	  break;
4709	case TRUTH_ORIF_EXPR:
4710	  stack[sp].expr
4711	    = default_function_array_conversion (stack[sp].expr);
4712	  stack[sp].expr.value = c_objc_common_truthvalue_conversion
4713	    (default_conversion (stack[sp].expr.value));
4714	  skip_evaluation += stack[sp].expr.value == truthvalue_true_node;
4715	  break;
4716	default:
4717	  break;
4718	}
4719      sp++;
4720      stack[sp].expr = c_parser_cast_expression (parser, NULL);
4721      stack[sp].prec = oprec;
4722      stack[sp].op = ocode;
4723    }
4724 out:
4725  while (sp > 0)
4726    POP;
4727  return stack[0].expr;
4728#undef POP
4729}
4730
4731/* Parse a cast expression (C90 6.3.4, C99 6.5.4).  If AFTER is not
4732   NULL then it is an Objective-C message expression which is the
4733   primary-expression starting the expression as an initializer.
4734
4735   cast-expression:
4736     unary-expression
4737     ( type-name ) unary-expression
4738*/
4739
4740static struct c_expr
4741c_parser_cast_expression (c_parser *parser, struct c_expr *after)
4742{
4743  gcc_assert (!after || c_dialect_objc ());
4744  if (after)
4745    return c_parser_postfix_expression_after_primary (parser, *after);
4746  /* If the expression begins with a parenthesized type name, it may
4747     be either a cast or a compound literal; we need to see whether
4748     the next character is '{' to tell the difference.  If not, it is
4749     an unary expression.  */
4750  if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4751      && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4752    {
4753      struct c_type_name *type_name;
4754      struct c_expr ret;
4755      struct c_expr expr;
4756      c_parser_consume_token (parser);
4757      type_name = c_parser_type_name (parser);
4758      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4759      if (type_name == NULL)
4760	{
4761	  ret.value = error_mark_node;
4762	  ret.original_code = ERROR_MARK;
4763	  return ret;
4764	}
4765
4766      /* Save casted types in the function's used types hash table.  */
4767      used_types_insert (type_name->specs->type);
4768
4769      if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4770	return c_parser_postfix_expression_after_paren_type (parser,
4771							     type_name);
4772      expr = c_parser_cast_expression (parser, NULL);
4773      expr = default_function_array_conversion (expr);
4774      ret.value = c_cast_expr (type_name, expr.value);
4775      ret.original_code = ERROR_MARK;
4776      return ret;
4777    }
4778  else
4779    return c_parser_unary_expression (parser);
4780}
4781
4782/* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4783
4784   unary-expression:
4785     postfix-expression
4786     ++ unary-expression
4787     -- unary-expression
4788     unary-operator cast-expression
4789     sizeof unary-expression
4790     sizeof ( type-name )
4791
4792   unary-operator: one of
4793     & * + - ~ !
4794
4795   GNU extensions:
4796
4797   unary-expression:
4798     __alignof__ unary-expression
4799     __alignof__ ( type-name )
4800     && identifier
4801
4802   unary-operator: one of
4803     __extension__ __real__ __imag__
4804
4805   In addition, the GNU syntax treats ++ and -- as unary operators, so
4806   they may be applied to cast expressions with errors for non-lvalues
4807   given later.  */
4808
4809static struct c_expr
4810c_parser_unary_expression (c_parser *parser)
4811{
4812  int ext;
4813  struct c_expr ret, op;
4814  switch (c_parser_peek_token (parser)->type)
4815    {
4816    case CPP_PLUS_PLUS:
4817      c_parser_consume_token (parser);
4818      op = c_parser_cast_expression (parser, NULL);
4819      op = default_function_array_conversion (op);
4820      return parser_build_unary_op (PREINCREMENT_EXPR, op);
4821    case CPP_MINUS_MINUS:
4822      c_parser_consume_token (parser);
4823      op = c_parser_cast_expression (parser, NULL);
4824      op = default_function_array_conversion (op);
4825      return parser_build_unary_op (PREDECREMENT_EXPR, op);
4826    case CPP_AND:
4827      c_parser_consume_token (parser);
4828      return parser_build_unary_op (ADDR_EXPR,
4829				    c_parser_cast_expression (parser, NULL));
4830    case CPP_MULT:
4831      c_parser_consume_token (parser);
4832      op = c_parser_cast_expression (parser, NULL);
4833      op = default_function_array_conversion (op);
4834      ret.value = build_indirect_ref (op.value, "unary *");
4835      ret.original_code = ERROR_MARK;
4836      return ret;
4837    case CPP_PLUS:
4838      c_parser_consume_token (parser);
4839      if (!c_dialect_objc () && !in_system_header)
4840	warning (OPT_Wtraditional,
4841		 "traditional C rejects the unary plus operator");
4842      op = c_parser_cast_expression (parser, NULL);
4843      op = default_function_array_conversion (op);
4844      return parser_build_unary_op (CONVERT_EXPR, op);
4845    case CPP_MINUS:
4846      c_parser_consume_token (parser);
4847      op = c_parser_cast_expression (parser, NULL);
4848      op = default_function_array_conversion (op);
4849      return parser_build_unary_op (NEGATE_EXPR, op);
4850    case CPP_COMPL:
4851      c_parser_consume_token (parser);
4852      op = c_parser_cast_expression (parser, NULL);
4853      op = default_function_array_conversion (op);
4854      return parser_build_unary_op (BIT_NOT_EXPR, op);
4855    case CPP_NOT:
4856      c_parser_consume_token (parser);
4857      op = c_parser_cast_expression (parser, NULL);
4858      op = default_function_array_conversion (op);
4859      return parser_build_unary_op (TRUTH_NOT_EXPR, op);
4860    case CPP_AND_AND:
4861      /* Refer to the address of a label as a pointer.  */
4862      c_parser_consume_token (parser);
4863      if (c_parser_next_token_is (parser, CPP_NAME))
4864	{
4865	  ret.value = finish_label_address_expr
4866	    (c_parser_peek_token (parser)->value);
4867	  c_parser_consume_token (parser);
4868	}
4869      else
4870	{
4871	  c_parser_error (parser, "expected identifier");
4872	  ret.value = error_mark_node;
4873	}
4874	ret.original_code = ERROR_MARK;
4875	return ret;
4876    case CPP_KEYWORD:
4877      switch (c_parser_peek_token (parser)->keyword)
4878	{
4879	case RID_SIZEOF:
4880	  return c_parser_sizeof_expression (parser);
4881	case RID_ALIGNOF:
4882	  return c_parser_alignof_expression (parser);
4883	case RID_EXTENSION:
4884	  c_parser_consume_token (parser);
4885	  ext = disable_extension_diagnostics ();
4886	  ret = c_parser_cast_expression (parser, NULL);
4887	  restore_extension_diagnostics (ext);
4888	  return ret;
4889	case RID_REALPART:
4890	  c_parser_consume_token (parser);
4891	  op = c_parser_cast_expression (parser, NULL);
4892	  op = default_function_array_conversion (op);
4893	  return parser_build_unary_op (REALPART_EXPR, op);
4894	case RID_IMAGPART:
4895	  c_parser_consume_token (parser);
4896	  op = c_parser_cast_expression (parser, NULL);
4897	  op = default_function_array_conversion (op);
4898	  return parser_build_unary_op (IMAGPART_EXPR, op);
4899	default:
4900	  return c_parser_postfix_expression (parser);
4901	}
4902    default:
4903      return c_parser_postfix_expression (parser);
4904    }
4905}
4906
4907/* Parse a sizeof expression.  */
4908
4909static struct c_expr
4910c_parser_sizeof_expression (c_parser *parser)
4911{
4912  struct c_expr expr;
4913  gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
4914  c_parser_consume_token (parser);
4915  skip_evaluation++;
4916  in_sizeof++;
4917  if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4918      && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4919    {
4920      /* Either sizeof ( type-name ) or sizeof unary-expression
4921	 starting with a compound literal.  */
4922      struct c_type_name *type_name;
4923      c_parser_consume_token (parser);
4924      type_name = c_parser_type_name (parser);
4925      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4926      if (type_name == NULL)
4927	{
4928	  struct c_expr ret;
4929	  skip_evaluation--;
4930	  in_sizeof--;
4931	  ret.value = error_mark_node;
4932	  ret.original_code = ERROR_MARK;
4933	  return ret;
4934	}
4935      if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4936	{
4937	  expr = c_parser_postfix_expression_after_paren_type (parser,
4938							       type_name);
4939	  goto sizeof_expr;
4940	}
4941      /* sizeof ( type-name ).  */
4942      skip_evaluation--;
4943      in_sizeof--;
4944      if (type_name->declarator->kind == cdk_array
4945	  && type_name->declarator->u.array.vla_unspec_p)
4946	{
4947	  /* C99 6.7.5.2p4 */
4948	  error ("%<[*]%> not allowed in other than a declaration");
4949	}
4950      return c_expr_sizeof_type (type_name);
4951    }
4952  else
4953    {
4954      expr = c_parser_unary_expression (parser);
4955    sizeof_expr:
4956      skip_evaluation--;
4957      in_sizeof--;
4958      if (TREE_CODE (expr.value) == COMPONENT_REF
4959	  && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
4960	error ("%<sizeof%> applied to a bit-field");
4961      return c_expr_sizeof_expr (expr);
4962    }
4963}
4964
4965/* Parse an alignof expression.  */
4966
4967static struct c_expr
4968c_parser_alignof_expression (c_parser *parser)
4969{
4970  struct c_expr expr;
4971  gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
4972  c_parser_consume_token (parser);
4973  skip_evaluation++;
4974  in_alignof++;
4975  if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4976      && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4977    {
4978      /* Either __alignof__ ( type-name ) or __alignof__
4979	 unary-expression starting with a compound literal.  */
4980      struct c_type_name *type_name;
4981      struct c_expr ret;
4982      c_parser_consume_token (parser);
4983      type_name = c_parser_type_name (parser);
4984      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4985      if (type_name == NULL)
4986	{
4987	  struct c_expr ret;
4988	  skip_evaluation--;
4989	  in_alignof--;
4990	  ret.value = error_mark_node;
4991	  ret.original_code = ERROR_MARK;
4992	  return ret;
4993	}
4994      if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4995	{
4996	  expr = c_parser_postfix_expression_after_paren_type (parser,
4997							       type_name);
4998	  goto alignof_expr;
4999	}
5000      /* alignof ( type-name ).  */
5001      skip_evaluation--;
5002      in_alignof--;
5003      ret.value = c_alignof (groktypename (type_name));
5004      ret.original_code = ERROR_MARK;
5005      return ret;
5006    }
5007  else
5008    {
5009      struct c_expr ret;
5010      expr = c_parser_unary_expression (parser);
5011    alignof_expr:
5012      skip_evaluation--;
5013      in_alignof--;
5014      ret.value = c_alignof_expr (expr.value);
5015      ret.original_code = ERROR_MARK;
5016      return ret;
5017    }
5018}
5019
5020/* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5021
5022   postfix-expression:
5023     primary-expression
5024     postfix-expression [ expression ]
5025     postfix-expression ( argument-expression-list[opt] )
5026     postfix-expression . identifier
5027     postfix-expression -> identifier
5028     postfix-expression ++
5029     postfix-expression --
5030     ( type-name ) { initializer-list }
5031     ( type-name ) { initializer-list , }
5032
5033   argument-expression-list:
5034     argument-expression
5035     argument-expression-list , argument-expression
5036
5037   primary-expression:
5038     identifier
5039     constant
5040     string-literal
5041     ( expression )
5042
5043   GNU extensions:
5044
5045   primary-expression:
5046     __func__
5047       (treated as a keyword in GNU C)
5048     __FUNCTION__
5049     __PRETTY_FUNCTION__
5050     ( compound-statement )
5051     __builtin_va_arg ( assignment-expression , type-name )
5052     __builtin_offsetof ( type-name , offsetof-member-designator )
5053     __builtin_choose_expr ( assignment-expression ,
5054			     assignment-expression ,
5055			     assignment-expression )
5056     __builtin_types_compatible_p ( type-name , type-name )
5057
5058   offsetof-member-designator:
5059     identifier
5060     offsetof-member-designator . identifier
5061     offsetof-member-designator [ expression ]
5062
5063   Objective-C:
5064
5065   primary-expression:
5066     [ objc-receiver objc-message-args ]
5067     @selector ( objc-selector-arg )
5068     @protocol ( identifier )
5069     @encode ( type-name )
5070     objc-string-literal
5071*/
5072
5073static struct c_expr
5074c_parser_postfix_expression (c_parser *parser)
5075{
5076  struct c_expr expr, e1, e2, e3;
5077  struct c_type_name *t1, *t2;
5078  switch (c_parser_peek_token (parser)->type)
5079    {
5080    case CPP_NUMBER:
5081    case CPP_CHAR:
5082    case CPP_WCHAR:
5083      expr.value = c_parser_peek_token (parser)->value;
5084      expr.original_code = ERROR_MARK;
5085      c_parser_consume_token (parser);
5086      break;
5087    case CPP_STRING:
5088    case CPP_WSTRING:
5089      expr.value = c_parser_peek_token (parser)->value;
5090      expr.original_code = STRING_CST;
5091      c_parser_consume_token (parser);
5092      break;
5093    case CPP_OBJC_STRING:
5094      gcc_assert (c_dialect_objc ());
5095      expr.value
5096	= objc_build_string_object (c_parser_peek_token (parser)->value);
5097      expr.original_code = ERROR_MARK;
5098      c_parser_consume_token (parser);
5099      break;
5100    case CPP_NAME:
5101      if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5102	{
5103	  c_parser_error (parser, "expected expression");
5104	  expr.value = error_mark_node;
5105	  expr.original_code = ERROR_MARK;
5106	  break;
5107	}
5108      {
5109	tree id = c_parser_peek_token (parser)->value;
5110	location_t loc = c_parser_peek_token (parser)->location;
5111	c_parser_consume_token (parser);
5112	expr.value = build_external_ref (id,
5113					 (c_parser_peek_token (parser)->type
5114					  == CPP_OPEN_PAREN), loc);
5115	expr.original_code = ERROR_MARK;
5116      }
5117      break;
5118    case CPP_OPEN_PAREN:
5119      /* A parenthesized expression, statement expression or compound
5120	 literal.  */
5121      if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5122	{
5123	  /* A statement expression.  */
5124	  tree stmt;
5125	  c_parser_consume_token (parser);
5126	  c_parser_consume_token (parser);
5127	  if (cur_stmt_list == NULL)
5128	    {
5129	      error ("braced-group within expression allowed "
5130		     "only inside a function");
5131	      parser->error = true;
5132	      c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5133	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5134	      expr.value = error_mark_node;
5135	      expr.original_code = ERROR_MARK;
5136	      break;
5137	    }
5138	  stmt = c_begin_stmt_expr ();
5139	  c_parser_compound_statement_nostart (parser);
5140	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5141				     "expected %<)%>");
5142	  if (pedantic)
5143	    pedwarn ("ISO C forbids braced-groups within expressions");
5144	  expr.value = c_finish_stmt_expr (stmt);
5145	  expr.original_code = ERROR_MARK;
5146	}
5147      else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5148	{
5149	  /* A compound literal.  ??? Can we actually get here rather
5150	     than going directly to
5151	     c_parser_postfix_expression_after_paren_type from
5152	     elsewhere?  */
5153	  struct c_type_name *type_name;
5154	  c_parser_consume_token (parser);
5155	  type_name = c_parser_type_name (parser);
5156	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5157				     "expected %<)%>");
5158	  if (type_name == NULL)
5159	    {
5160	      expr.value = error_mark_node;
5161	      expr.original_code = ERROR_MARK;
5162	    }
5163	  else
5164	    expr = c_parser_postfix_expression_after_paren_type (parser,
5165								 type_name);
5166	}
5167      else
5168	{
5169	  /* A parenthesized expression.  */
5170	  c_parser_consume_token (parser);
5171	  expr = c_parser_expression (parser);
5172	  if (TREE_CODE (expr.value) == MODIFY_EXPR)
5173	    TREE_NO_WARNING (expr.value) = 1;
5174	  expr.original_code = ERROR_MARK;
5175	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5176				     "expected %<)%>");
5177	}
5178      break;
5179    case CPP_KEYWORD:
5180      switch (c_parser_peek_token (parser)->keyword)
5181	{
5182	case RID_FUNCTION_NAME:
5183	case RID_PRETTY_FUNCTION_NAME:
5184	case RID_C99_FUNCTION_NAME:
5185	  expr.value = fname_decl (c_parser_peek_token (parser)->keyword,
5186				   c_parser_peek_token (parser)->value);
5187	  expr.original_code = ERROR_MARK;
5188	  c_parser_consume_token (parser);
5189	  break;
5190	case RID_VA_ARG:
5191	  c_parser_consume_token (parser);
5192	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5193	    {
5194	      expr.value = error_mark_node;
5195	      expr.original_code = ERROR_MARK;
5196	      break;
5197	    }
5198	  e1 = c_parser_expr_no_commas (parser, NULL);
5199	  if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5200	    {
5201	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5202	      expr.value = error_mark_node;
5203	      expr.original_code = ERROR_MARK;
5204	      break;
5205	    }
5206	  t1 = c_parser_type_name (parser);
5207	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5208				     "expected %<)%>");
5209	  if (t1 == NULL)
5210	    {
5211	      expr.value = error_mark_node;
5212	      expr.original_code = ERROR_MARK;
5213	    }
5214	  else
5215	    {
5216	      expr.value = build_va_arg (e1.value, groktypename (t1));
5217	      expr.original_code = ERROR_MARK;
5218	    }
5219	  break;
5220	case RID_OFFSETOF:
5221	  c_parser_consume_token (parser);
5222	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5223	    {
5224	      expr.value = error_mark_node;
5225	      expr.original_code = ERROR_MARK;
5226	      break;
5227	    }
5228	  t1 = c_parser_type_name (parser);
5229	  if (t1 == NULL)
5230	    {
5231	      expr.value = error_mark_node;
5232	      expr.original_code = ERROR_MARK;
5233	      break;
5234	    }
5235	  if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5236	    {
5237	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5238	      expr.value = error_mark_node;
5239	      expr.original_code = ERROR_MARK;
5240	      break;
5241	    }
5242	  {
5243	    tree type = groktypename (t1);
5244	    tree offsetof_ref;
5245	    if (type == error_mark_node)
5246	      offsetof_ref = error_mark_node;
5247	    else
5248	      offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5249	    /* Parse the second argument to __builtin_offsetof.  We
5250	       must have one identifier, and beyond that we want to
5251	       accept sub structure and sub array references.  */
5252	    if (c_parser_next_token_is (parser, CPP_NAME))
5253	      {
5254		offsetof_ref = build_component_ref
5255		  (offsetof_ref, c_parser_peek_token (parser)->value);
5256		c_parser_consume_token (parser);
5257		while (c_parser_next_token_is (parser, CPP_DOT)
5258		       || c_parser_next_token_is (parser,
5259						  CPP_OPEN_SQUARE))
5260		  {
5261		    if (c_parser_next_token_is (parser, CPP_DOT))
5262		      {
5263			c_parser_consume_token (parser);
5264			if (c_parser_next_token_is_not (parser,
5265							CPP_NAME))
5266			  {
5267			    c_parser_error (parser, "expected identifier");
5268			    break;
5269			  }
5270			offsetof_ref = build_component_ref
5271			  (offsetof_ref,
5272			   c_parser_peek_token (parser)->value);
5273			c_parser_consume_token (parser);
5274		      }
5275		    else
5276		      {
5277			tree idx;
5278			c_parser_consume_token (parser);
5279			idx = c_parser_expression (parser).value;
5280			c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5281						   "expected %<]%>");
5282			offsetof_ref = build_array_ref (offsetof_ref, idx);
5283		      }
5284		  }
5285	      }
5286	    else
5287	      c_parser_error (parser, "expected identifier");
5288	    c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5289				       "expected %<)%>");
5290	    expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5291	    expr.original_code = ERROR_MARK;
5292	  }
5293	  break;
5294	case RID_CHOOSE_EXPR:
5295	  c_parser_consume_token (parser);
5296	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5297	    {
5298	      expr.value = error_mark_node;
5299	      expr.original_code = ERROR_MARK;
5300	      break;
5301	    }
5302	  e1 = c_parser_expr_no_commas (parser, NULL);
5303	  if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5304	    {
5305	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5306	      expr.value = error_mark_node;
5307	      expr.original_code = ERROR_MARK;
5308	      break;
5309	    }
5310	  e2 = c_parser_expr_no_commas (parser, NULL);
5311	  if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5312	    {
5313	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5314	      expr.value = error_mark_node;
5315	      expr.original_code = ERROR_MARK;
5316	      break;
5317	    }
5318	  e3 = c_parser_expr_no_commas (parser, NULL);
5319	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5320				     "expected %<)%>");
5321	  {
5322	    tree c;
5323
5324	    c = fold (e1.value);
5325	    if (TREE_CODE (c) != INTEGER_CST)
5326	      error ("first argument to %<__builtin_choose_expr%> not"
5327		     " a constant");
5328	    expr = integer_zerop (c) ? e3 : e2;
5329	  }
5330	  break;
5331	case RID_TYPES_COMPATIBLE_P:
5332	  c_parser_consume_token (parser);
5333	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5334	    {
5335	      expr.value = error_mark_node;
5336	      expr.original_code = ERROR_MARK;
5337	      break;
5338	    }
5339	  t1 = c_parser_type_name (parser);
5340	  if (t1 == NULL)
5341	    {
5342	      expr.value = error_mark_node;
5343	      expr.original_code = ERROR_MARK;
5344	      break;
5345	    }
5346	  if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5347	    {
5348	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5349	      expr.value = error_mark_node;
5350	      expr.original_code = ERROR_MARK;
5351	      break;
5352	    }
5353	  t2 = c_parser_type_name (parser);
5354	  if (t2 == NULL)
5355	    {
5356	      expr.value = error_mark_node;
5357	      expr.original_code = ERROR_MARK;
5358	      break;
5359	    }
5360	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5361				     "expected %<)%>");
5362	  {
5363	    tree e1, e2;
5364
5365	    e1 = TYPE_MAIN_VARIANT (groktypename (t1));
5366	    e2 = TYPE_MAIN_VARIANT (groktypename (t2));
5367
5368	    expr.value = comptypes (e1, e2)
5369	      ? build_int_cst (NULL_TREE, 1)
5370	      : build_int_cst (NULL_TREE, 0);
5371	    expr.original_code = ERROR_MARK;
5372	  }
5373	  break;
5374	case RID_AT_SELECTOR:
5375	  gcc_assert (c_dialect_objc ());
5376	  c_parser_consume_token (parser);
5377	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5378	    {
5379	      expr.value = error_mark_node;
5380	      expr.original_code = ERROR_MARK;
5381	      break;
5382	    }
5383	  {
5384	    tree sel = c_parser_objc_selector_arg (parser);
5385	    c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5386				       "expected %<)%>");
5387	    expr.value = objc_build_selector_expr (sel);
5388	    expr.original_code = ERROR_MARK;
5389	  }
5390	  break;
5391	case RID_AT_PROTOCOL:
5392	  gcc_assert (c_dialect_objc ());
5393	  c_parser_consume_token (parser);
5394	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5395	    {
5396	      expr.value = error_mark_node;
5397	      expr.original_code = ERROR_MARK;
5398	      break;
5399	    }
5400	  if (c_parser_next_token_is_not (parser, CPP_NAME))
5401	    {
5402	      c_parser_error (parser, "expected identifier");
5403	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5404	      expr.value = error_mark_node;
5405	      expr.original_code = ERROR_MARK;
5406	      break;
5407	    }
5408	  {
5409	    tree id = c_parser_peek_token (parser)->value;
5410	    c_parser_consume_token (parser);
5411	    c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5412				       "expected %<)%>");
5413	    expr.value = objc_build_protocol_expr (id);
5414	    expr.original_code = ERROR_MARK;
5415	  }
5416	  break;
5417	case RID_AT_ENCODE:
5418	  /* Extension to support C-structures in the archiver.  */
5419	  gcc_assert (c_dialect_objc ());
5420	  c_parser_consume_token (parser);
5421	  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5422	    {
5423	      expr.value = error_mark_node;
5424	      expr.original_code = ERROR_MARK;
5425	      break;
5426	    }
5427	  t1 = c_parser_type_name (parser);
5428	  if (t1 == NULL)
5429	    {
5430	      expr.value = error_mark_node;
5431	      expr.original_code = ERROR_MARK;
5432	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5433	      break;
5434	    }
5435	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5436				     "expected %<)%>");
5437	  {
5438	    tree type = groktypename (t1);
5439	    expr.value = objc_build_encode_expr (type);
5440	    expr.original_code = ERROR_MARK;
5441	  }
5442	  break;
5443	default:
5444	  c_parser_error (parser, "expected expression");
5445	  expr.value = error_mark_node;
5446	  expr.original_code = ERROR_MARK;
5447	  break;
5448	}
5449      break;
5450    case CPP_OPEN_SQUARE:
5451      if (c_dialect_objc ())
5452	{
5453	  tree receiver, args;
5454	  c_parser_consume_token (parser);
5455	  receiver = c_parser_objc_receiver (parser);
5456	  args = c_parser_objc_message_args (parser);
5457	  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5458				     "expected %<]%>");
5459	  expr.value = objc_build_message_expr (build_tree_list (receiver,
5460								 args));
5461	  expr.original_code = ERROR_MARK;
5462	  break;
5463	}
5464      /* Else fall through to report error.  */
5465    default:
5466      c_parser_error (parser, "expected expression");
5467      expr.value = error_mark_node;
5468      expr.original_code = ERROR_MARK;
5469      break;
5470    }
5471  return c_parser_postfix_expression_after_primary (parser, expr);
5472}
5473
5474/* Parse a postfix expression after a parenthesized type name: the
5475   brace-enclosed initializer of a compound literal, possibly followed
5476   by some postfix operators.  This is separate because it is not
5477   possible to tell until after the type name whether a cast
5478   expression has a cast or a compound literal, or whether the operand
5479   of sizeof is a parenthesized type name or starts with a compound
5480   literal.  */
5481
5482static struct c_expr
5483c_parser_postfix_expression_after_paren_type (c_parser *parser,
5484					      struct c_type_name *type_name)
5485{
5486  tree type;
5487  struct c_expr init;
5488  struct c_expr expr;
5489  start_init (NULL_TREE, NULL, 0);
5490  type = groktypename (type_name);
5491  if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
5492    {
5493      error ("compound literal has variable size");
5494      type = error_mark_node;
5495    }
5496  init = c_parser_braced_init (parser, type, false);
5497  finish_init ();
5498  maybe_warn_string_init (type, init);
5499
5500  if (pedantic && !flag_isoc99)
5501    pedwarn ("ISO C90 forbids compound literals");
5502  expr.value = build_compound_literal (type, init.value);
5503  expr.original_code = ERROR_MARK;
5504  return c_parser_postfix_expression_after_primary (parser, expr);
5505}
5506
5507/* Parse a postfix expression after the initial primary or compound
5508   literal; that is, parse a series of postfix operators.  */
5509
5510static struct c_expr
5511c_parser_postfix_expression_after_primary (c_parser *parser,
5512					   struct c_expr expr)
5513{
5514  tree ident, idx, exprlist;
5515  while (true)
5516    {
5517      switch (c_parser_peek_token (parser)->type)
5518	{
5519	case CPP_OPEN_SQUARE:
5520	  /* Array reference.  */
5521	  c_parser_consume_token (parser);
5522	  idx = c_parser_expression (parser).value;
5523	  c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5524				     "expected %<]%>");
5525	  expr.value = build_array_ref (expr.value, idx);
5526	  expr.original_code = ERROR_MARK;
5527	  break;
5528	case CPP_OPEN_PAREN:
5529	  /* Function call.  */
5530	  c_parser_consume_token (parser);
5531	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5532	    exprlist = NULL_TREE;
5533	  else
5534	    exprlist = c_parser_expr_list (parser, true);
5535	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5536				     "expected %<)%>");
5537	  expr.value = build_function_call (expr.value, exprlist);
5538	  expr.original_code = ERROR_MARK;
5539	  break;
5540	case CPP_DOT:
5541	  /* Structure element reference.  */
5542	  c_parser_consume_token (parser);
5543	  expr = default_function_array_conversion (expr);
5544	  if (c_parser_next_token_is (parser, CPP_NAME))
5545	    ident = c_parser_peek_token (parser)->value;
5546	  else
5547	    {
5548	      c_parser_error (parser, "expected identifier");
5549	      expr.value = error_mark_node;
5550	      expr.original_code = ERROR_MARK;
5551	      return expr;
5552	    }
5553	  c_parser_consume_token (parser);
5554	  expr.value = build_component_ref (expr.value, ident);
5555	  expr.original_code = ERROR_MARK;
5556	  break;
5557	case CPP_DEREF:
5558	  /* Structure element reference.  */
5559	  c_parser_consume_token (parser);
5560	  expr = default_function_array_conversion (expr);
5561	  if (c_parser_next_token_is (parser, CPP_NAME))
5562	    ident = c_parser_peek_token (parser)->value;
5563	  else
5564	    {
5565	      c_parser_error (parser, "expected identifier");
5566	      expr.value = error_mark_node;
5567	      expr.original_code = ERROR_MARK;
5568	      return expr;
5569	    }
5570	  c_parser_consume_token (parser);
5571	  expr.value = build_component_ref (build_indirect_ref (expr.value,
5572								"->"), ident);
5573	  expr.original_code = ERROR_MARK;
5574	  break;
5575	case CPP_PLUS_PLUS:
5576	  /* Postincrement.  */
5577	  c_parser_consume_token (parser);
5578	  expr = default_function_array_conversion (expr);
5579	  expr.value = build_unary_op (POSTINCREMENT_EXPR, expr.value, 0);
5580	  expr.original_code = ERROR_MARK;
5581	  break;
5582	case CPP_MINUS_MINUS:
5583	  /* Postdecrement.  */
5584	  c_parser_consume_token (parser);
5585	  expr = default_function_array_conversion (expr);
5586	  expr.value = build_unary_op (POSTDECREMENT_EXPR, expr.value, 0);
5587	  expr.original_code = ERROR_MARK;
5588	  break;
5589	default:
5590	  return expr;
5591	}
5592    }
5593}
5594
5595/* Parse an expression (C90 6.3.17, C99 6.5.17).
5596
5597   expression:
5598     assignment-expression
5599     expression , assignment-expression
5600*/
5601
5602static struct c_expr
5603c_parser_expression (c_parser *parser)
5604{
5605  struct c_expr expr;
5606  expr = c_parser_expr_no_commas (parser, NULL);
5607  while (c_parser_next_token_is (parser, CPP_COMMA))
5608    {
5609      struct c_expr next;
5610      c_parser_consume_token (parser);
5611      next = c_parser_expr_no_commas (parser, NULL);
5612      next = default_function_array_conversion (next);
5613      expr.value = build_compound_expr (expr.value, next.value);
5614      expr.original_code = COMPOUND_EXPR;
5615    }
5616  return expr;
5617}
5618
5619/* Parse an expression and convert functions or arrays to
5620   pointers.  */
5621
5622static struct c_expr
5623c_parser_expression_conv (c_parser *parser)
5624{
5625  struct c_expr expr;
5626  expr = c_parser_expression (parser);
5627  expr = default_function_array_conversion (expr);
5628  return expr;
5629}
5630
5631/* Parse a non-empty list of expressions.  If CONVERT_P, convert
5632   functions and arrays to pointers.
5633
5634   nonempty-expr-list:
5635     assignment-expression
5636     nonempty-expr-list , assignment-expression
5637*/
5638
5639static tree
5640c_parser_expr_list (c_parser *parser, bool convert_p)
5641{
5642  struct c_expr expr;
5643  tree ret, cur;
5644  expr = c_parser_expr_no_commas (parser, NULL);
5645  if (convert_p)
5646    expr = default_function_array_conversion (expr);
5647  ret = cur = build_tree_list (NULL_TREE, expr.value);
5648  while (c_parser_next_token_is (parser, CPP_COMMA))
5649    {
5650      c_parser_consume_token (parser);
5651      expr = c_parser_expr_no_commas (parser, NULL);
5652      if (convert_p)
5653	expr = default_function_array_conversion (expr);
5654      cur = TREE_CHAIN (cur) = build_tree_list (NULL_TREE, expr.value);
5655    }
5656  return ret;
5657}
5658
5659
5660/* Parse Objective-C-specific constructs.  */
5661
5662/* Parse an objc-class-definition.
5663
5664   objc-class-definition:
5665     @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5666       objc-class-instance-variables[opt] objc-methodprotolist @end
5667     @implementation identifier objc-superclass[opt]
5668       objc-class-instance-variables[opt]
5669     @interface identifier ( identifier ) objc-protocol-refs[opt]
5670       objc-methodprotolist @end
5671     @implementation identifier ( identifier )
5672
5673   objc-superclass:
5674     : identifier
5675
5676   "@interface identifier (" must start "@interface identifier (
5677   identifier ) ...": objc-methodprotolist in the first production may
5678   not start with a parenthesized identifier as a declarator of a data
5679   definition with no declaration specifiers if the objc-superclass,
5680   objc-protocol-refs and objc-class-instance-variables are omitted.  */
5681
5682static void
5683c_parser_objc_class_definition (c_parser *parser)
5684{
5685  bool iface_p;
5686  tree id1;
5687  tree superclass;
5688  if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
5689    iface_p = true;
5690  else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
5691    iface_p = false;
5692  else
5693    gcc_unreachable ();
5694  c_parser_consume_token (parser);
5695  if (c_parser_next_token_is_not (parser, CPP_NAME))
5696    {
5697      c_parser_error (parser, "expected identifier");
5698      return;
5699    }
5700  id1 = c_parser_peek_token (parser)->value;
5701  c_parser_consume_token (parser);
5702  if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
5703    {
5704      tree id2;
5705      tree proto = NULL_TREE;
5706      c_parser_consume_token (parser);
5707      if (c_parser_next_token_is_not (parser, CPP_NAME))
5708	{
5709	  c_parser_error (parser, "expected identifier");
5710	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5711	  return;
5712	}
5713      id2 = c_parser_peek_token (parser)->value;
5714      c_parser_consume_token (parser);
5715      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5716      if (!iface_p)
5717	{
5718	  objc_start_category_implementation (id1, id2);
5719	  return;
5720	}
5721      if (c_parser_next_token_is (parser, CPP_LESS))
5722	proto = c_parser_objc_protocol_refs (parser);
5723      objc_start_category_interface (id1, id2, proto);
5724      c_parser_objc_methodprotolist (parser);
5725      c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5726      objc_finish_interface ();
5727      return;
5728    }
5729  if (c_parser_next_token_is (parser, CPP_COLON))
5730    {
5731      c_parser_consume_token (parser);
5732      if (c_parser_next_token_is_not (parser, CPP_NAME))
5733	{
5734	  c_parser_error (parser, "expected identifier");
5735	  return;
5736	}
5737      superclass = c_parser_peek_token (parser)->value;
5738      c_parser_consume_token (parser);
5739    }
5740  else
5741    superclass = NULL_TREE;
5742  if (iface_p)
5743    {
5744      tree proto = NULL_TREE;
5745      if (c_parser_next_token_is (parser, CPP_LESS))
5746	proto = c_parser_objc_protocol_refs (parser);
5747      objc_start_class_interface (id1, superclass, proto);
5748    }
5749  else
5750    objc_start_class_implementation (id1, superclass);
5751  if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5752    c_parser_objc_class_instance_variables (parser);
5753  if (iface_p)
5754    {
5755      objc_continue_interface ();
5756      c_parser_objc_methodprotolist (parser);
5757      c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5758      objc_finish_interface ();
5759    }
5760  else
5761    {
5762      objc_continue_implementation ();
5763      return;
5764    }
5765}
5766
5767/* Parse objc-class-instance-variables.
5768
5769   objc-class-instance-variables:
5770     { objc-instance-variable-decl-list[opt] }
5771
5772   objc-instance-variable-decl-list:
5773     objc-visibility-spec
5774     objc-instance-variable-decl ;
5775     ;
5776     objc-instance-variable-decl-list objc-visibility-spec
5777     objc-instance-variable-decl-list objc-instance-variable-decl ;
5778     objc-instance-variable-decl-list ;
5779
5780   objc-visibility-spec:
5781     @private
5782     @protected
5783     @public
5784
5785   objc-instance-variable-decl:
5786     struct-declaration
5787*/
5788
5789static void
5790c_parser_objc_class_instance_variables (c_parser *parser)
5791{
5792  gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
5793  c_parser_consume_token (parser);
5794  while (c_parser_next_token_is_not (parser, CPP_EOF))
5795    {
5796      tree decls;
5797      /* Parse any stray semicolon.  */
5798      if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5799	{
5800	  if (pedantic)
5801	    pedwarn ("extra semicolon in struct or union specified");
5802	  c_parser_consume_token (parser);
5803	  continue;
5804	}
5805      /* Stop if at the end of the instance variables.  */
5806      if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
5807	{
5808	  c_parser_consume_token (parser);
5809	  break;
5810	}
5811      /* Parse any objc-visibility-spec.  */
5812      if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
5813	{
5814	  c_parser_consume_token (parser);
5815	  objc_set_visibility (2);
5816	  continue;
5817	}
5818      else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
5819	{
5820	  c_parser_consume_token (parser);
5821	  objc_set_visibility (0);
5822	  continue;
5823	}
5824      else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
5825	{
5826	  c_parser_consume_token (parser);
5827	  objc_set_visibility (1);
5828	  continue;
5829	}
5830      else if (c_parser_next_token_is (parser, CPP_PRAGMA))
5831	{
5832	  c_parser_pragma (parser, pragma_external);
5833	  continue;
5834	}
5835
5836      /* Parse some comma-separated declarations.  */
5837      decls = c_parser_struct_declaration (parser);
5838      {
5839	/* Comma-separated instance variables are chained together in
5840	   reverse order; add them one by one.  */
5841	tree ivar = nreverse (decls);
5842	for (; ivar; ivar = TREE_CHAIN (ivar))
5843	  objc_add_instance_variable (copy_node (ivar));
5844      }
5845      c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5846    }
5847}
5848
5849/* Parse an objc-class-declaration.
5850
5851   objc-class-declaration:
5852     @class identifier-list ;
5853*/
5854
5855static void
5856c_parser_objc_class_declaration (c_parser *parser)
5857{
5858  tree list = NULL_TREE;
5859  gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
5860  c_parser_consume_token (parser);
5861  /* Any identifiers, including those declared as type names, are OK
5862     here.  */
5863  while (true)
5864    {
5865      tree id;
5866      if (c_parser_next_token_is_not (parser, CPP_NAME))
5867	{
5868	  c_parser_error (parser, "expected identifier");
5869	  break;
5870	}
5871      id = c_parser_peek_token (parser)->value;
5872      list = chainon (list, build_tree_list (NULL_TREE, id));
5873      c_parser_consume_token (parser);
5874      if (c_parser_next_token_is (parser, CPP_COMMA))
5875	c_parser_consume_token (parser);
5876      else
5877	break;
5878    }
5879  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5880  objc_declare_class (list);
5881}
5882
5883/* Parse an objc-alias-declaration.
5884
5885   objc-alias-declaration:
5886     @compatibility_alias identifier identifier ;
5887*/
5888
5889static void
5890c_parser_objc_alias_declaration (c_parser *parser)
5891{
5892  tree id1, id2;
5893  gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
5894  c_parser_consume_token (parser);
5895  if (c_parser_next_token_is_not (parser, CPP_NAME))
5896    {
5897      c_parser_error (parser, "expected identifier");
5898      c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5899      return;
5900    }
5901  id1 = c_parser_peek_token (parser)->value;
5902  c_parser_consume_token (parser);
5903  if (c_parser_next_token_is_not (parser, CPP_NAME))
5904    {
5905      c_parser_error (parser, "expected identifier");
5906      c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5907      return;
5908    }
5909  id2 = c_parser_peek_token (parser)->value;
5910  c_parser_consume_token (parser);
5911  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5912  objc_declare_alias (id1, id2);
5913}
5914
5915/* Parse an objc-protocol-definition.
5916
5917   objc-protocol-definition:
5918     @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5919     @protocol identifier-list ;
5920
5921   "@protocol identifier ;" should be resolved as "@protocol
5922   identifier-list ;": objc-methodprotolist may not start with a
5923   semicolon in the first alternative if objc-protocol-refs are
5924   omitted.  */
5925
5926static void
5927c_parser_objc_protocol_definition (c_parser *parser)
5928{
5929  gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
5930  c_parser_consume_token (parser);
5931  if (c_parser_next_token_is_not (parser, CPP_NAME))
5932    {
5933      c_parser_error (parser, "expected identifier");
5934      return;
5935    }
5936  if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
5937      || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
5938    {
5939      tree list = NULL_TREE;
5940      /* Any identifiers, including those declared as type names, are
5941	 OK here.  */
5942      while (true)
5943	{
5944	  tree id;
5945	  if (c_parser_next_token_is_not (parser, CPP_NAME))
5946	    {
5947	      c_parser_error (parser, "expected identifier");
5948	      break;
5949	    }
5950	  id = c_parser_peek_token (parser)->value;
5951	  list = chainon (list, build_tree_list (NULL_TREE, id));
5952	  c_parser_consume_token (parser);
5953	  if (c_parser_next_token_is (parser, CPP_COMMA))
5954	    c_parser_consume_token (parser);
5955	  else
5956	    break;
5957	}
5958      c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5959      objc_declare_protocols (list);
5960    }
5961  else
5962    {
5963      tree id = c_parser_peek_token (parser)->value;
5964      tree proto = NULL_TREE;
5965      c_parser_consume_token (parser);
5966      if (c_parser_next_token_is (parser, CPP_LESS))
5967	proto = c_parser_objc_protocol_refs (parser);
5968      objc_pq_context = 1;
5969      objc_start_protocol (id, proto);
5970      c_parser_objc_methodprotolist (parser);
5971      c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5972      objc_pq_context = 0;
5973      objc_finish_interface ();
5974    }
5975}
5976
5977/* Parse an objc-method-type.
5978
5979   objc-method-type:
5980     +
5981     -
5982*/
5983
5984static enum tree_code
5985c_parser_objc_method_type (c_parser *parser)
5986{
5987  switch (c_parser_peek_token (parser)->type)
5988    {
5989    case CPP_PLUS:
5990      c_parser_consume_token (parser);
5991      return PLUS_EXPR;
5992    case CPP_MINUS:
5993      c_parser_consume_token (parser);
5994      return MINUS_EXPR;
5995    default:
5996      gcc_unreachable ();
5997    }
5998}
5999
6000/* Parse an objc-method-definition.
6001
6002   objc-method-definition:
6003     objc-method-type objc-method-decl ;[opt] compound-statement
6004*/
6005
6006static void
6007c_parser_objc_method_definition (c_parser *parser)
6008{
6009  enum tree_code type = c_parser_objc_method_type (parser);
6010  tree decl;
6011  objc_set_method_type (type);
6012  objc_pq_context = 1;
6013  decl = c_parser_objc_method_decl (parser);
6014  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6015    {
6016      c_parser_consume_token (parser);
6017      if (pedantic)
6018	pedwarn ("extra semicolon in method definition specified");
6019    }
6020  if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6021    {
6022      c_parser_error (parser, "expected %<{%>");
6023      return;
6024    }
6025  objc_pq_context = 0;
6026  objc_start_method_definition (decl);
6027  add_stmt (c_parser_compound_statement (parser));
6028  objc_finish_method_definition (current_function_decl);
6029}
6030
6031/* Parse an objc-methodprotolist.
6032
6033   objc-methodprotolist:
6034     empty
6035     objc-methodprotolist objc-methodproto
6036     objc-methodprotolist declaration
6037     objc-methodprotolist ;
6038
6039   The declaration is a data definition, which may be missing
6040   declaration specifiers under the same rules and diagnostics as
6041   other data definitions outside functions, and the stray semicolon
6042   is diagnosed the same way as a stray semicolon outside a
6043   function.  */
6044
6045static void
6046c_parser_objc_methodprotolist (c_parser *parser)
6047{
6048  while (true)
6049    {
6050      /* The list is terminated by @end.  */
6051      switch (c_parser_peek_token (parser)->type)
6052	{
6053	case CPP_SEMICOLON:
6054	  if (pedantic)
6055	    pedwarn ("ISO C does not allow extra %<;%> outside of a function");
6056	  c_parser_consume_token (parser);
6057	  break;
6058	case CPP_PLUS:
6059	case CPP_MINUS:
6060	  c_parser_objc_methodproto (parser);
6061	  break;
6062	case CPP_PRAGMA:
6063	  c_parser_pragma (parser, pragma_external);
6064	  break;
6065	case CPP_EOF:
6066	  return;
6067	default:
6068	  if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6069	    return;
6070	  c_parser_declaration_or_fndef (parser, false, true, false, true);
6071	  break;
6072	}
6073    }
6074}
6075
6076/* Parse an objc-methodproto.
6077
6078   objc-methodproto:
6079     objc-method-type objc-method-decl ;
6080*/
6081
6082static void
6083c_parser_objc_methodproto (c_parser *parser)
6084{
6085  enum tree_code type = c_parser_objc_method_type (parser);
6086  tree decl;
6087  objc_set_method_type (type);
6088  /* Remember protocol qualifiers in prototypes.  */
6089  objc_pq_context = 1;
6090  decl = c_parser_objc_method_decl (parser);
6091  /* Forget protocol qualifiers here.  */
6092  objc_pq_context = 0;
6093  objc_add_method_declaration (decl);
6094  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6095}
6096
6097/* Parse an objc-method-decl.
6098
6099   objc-method-decl:
6100     ( objc-type-name ) objc-selector
6101     objc-selector
6102     ( objc-type-name ) objc-keyword-selector objc-optparmlist
6103     objc-keyword-selector objc-optparmlist
6104
6105   objc-keyword-selector:
6106     objc-keyword-decl
6107     objc-keyword-selector objc-keyword-decl
6108
6109   objc-keyword-decl:
6110     objc-selector : ( objc-type-name ) identifier
6111     objc-selector : identifier
6112     : ( objc-type-name ) identifier
6113     : identifier
6114
6115   objc-optparmlist:
6116     objc-optparms objc-optellipsis
6117
6118   objc-optparms:
6119     empty
6120     objc-opt-parms , parameter-declaration
6121
6122   objc-optellipsis:
6123     empty
6124     , ...
6125*/
6126
6127static tree
6128c_parser_objc_method_decl (c_parser *parser)
6129{
6130  tree type = NULL_TREE;
6131  tree sel;
6132  tree parms = NULL_TREE;
6133  bool ellipsis = false;
6134
6135  if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6136    {
6137      c_parser_consume_token (parser);
6138      type = c_parser_objc_type_name (parser);
6139      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6140    }
6141  sel = c_parser_objc_selector (parser);
6142  /* If there is no selector, or a colon follows, we have an
6143     objc-keyword-selector.  If there is a selector, and a colon does
6144     not follow, that selector ends the objc-method-decl.  */
6145  if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6146    {
6147      tree tsel = sel;
6148      tree list = NULL_TREE;
6149      while (true)
6150	{
6151	  tree atype = NULL_TREE, id, keyworddecl;
6152	  if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6153	    break;
6154	  if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6155	    {
6156	      c_parser_consume_token (parser);
6157	      atype = c_parser_objc_type_name (parser);
6158	      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6159					 "expected %<)%>");
6160	    }
6161	  if (c_parser_next_token_is_not (parser, CPP_NAME))
6162	    {
6163	      c_parser_error (parser, "expected identifier");
6164	      return error_mark_node;
6165	    }
6166	  id = c_parser_peek_token (parser)->value;
6167	  c_parser_consume_token (parser);
6168	  keyworddecl = objc_build_keyword_decl (tsel, atype, id);
6169	  list = chainon (list, keyworddecl);
6170	  tsel = c_parser_objc_selector (parser);
6171	  if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6172	    break;
6173	}
6174      /* Parse the optional parameter list.  Optional Objective-C
6175	 method parameters follow the C syntax, and may include '...'
6176	 to denote a variable number of arguments.  */
6177      parms = make_node (TREE_LIST);
6178      while (c_parser_next_token_is (parser, CPP_COMMA))
6179	{
6180	  struct c_parm *parm;
6181	  c_parser_consume_token (parser);
6182	  if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6183	    {
6184	      ellipsis = true;
6185	      c_parser_consume_token (parser);
6186	      break;
6187	    }
6188	  parm = c_parser_parameter_declaration (parser, NULL_TREE);
6189	  if (parm == NULL)
6190	    break;
6191	  parms = chainon (parms,
6192			   build_tree_list (NULL_TREE, grokparm (parm)));
6193	}
6194      sel = list;
6195    }
6196  return objc_build_method_signature (type, sel, parms, ellipsis);
6197}
6198
6199/* Parse an objc-type-name.
6200
6201   objc-type-name:
6202     objc-type-qualifiers[opt] type-name
6203     objc-type-qualifiers[opt]
6204
6205   objc-type-qualifiers:
6206     objc-type-qualifier
6207     objc-type-qualifiers objc-type-qualifier
6208
6209   objc-type-qualifier: one of
6210     in out inout bycopy byref oneway
6211*/
6212
6213static tree
6214c_parser_objc_type_name (c_parser *parser)
6215{
6216  tree quals = NULL_TREE;
6217  struct c_type_name *typename = NULL;
6218  tree type = NULL_TREE;
6219  while (true)
6220    {
6221      c_token *token = c_parser_peek_token (parser);
6222      if (token->type == CPP_KEYWORD
6223	  && (token->keyword == RID_IN
6224	      || token->keyword == RID_OUT
6225	      || token->keyword == RID_INOUT
6226	      || token->keyword == RID_BYCOPY
6227	      || token->keyword == RID_BYREF
6228	      || token->keyword == RID_ONEWAY))
6229	{
6230	  quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6231	  c_parser_consume_token (parser);
6232	}
6233      else
6234	break;
6235    }
6236  if (c_parser_next_token_starts_typename (parser))
6237    typename = c_parser_type_name (parser);
6238  if (typename)
6239    type = groktypename (typename);
6240  return build_tree_list (quals, type);
6241}
6242
6243/* Parse objc-protocol-refs.
6244
6245   objc-protocol-refs:
6246     < identifier-list >
6247*/
6248
6249static tree
6250c_parser_objc_protocol_refs (c_parser *parser)
6251{
6252  tree list = NULL_TREE;
6253  gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6254  c_parser_consume_token (parser);
6255  /* Any identifiers, including those declared as type names, are OK
6256     here.  */
6257  while (true)
6258    {
6259      tree id;
6260      if (c_parser_next_token_is_not (parser, CPP_NAME))
6261	{
6262	  c_parser_error (parser, "expected identifier");
6263	  break;
6264	}
6265      id = c_parser_peek_token (parser)->value;
6266      list = chainon (list, build_tree_list (NULL_TREE, id));
6267      c_parser_consume_token (parser);
6268      if (c_parser_next_token_is (parser, CPP_COMMA))
6269	c_parser_consume_token (parser);
6270      else
6271	break;
6272    }
6273  c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6274  return list;
6275}
6276
6277/* Parse an objc-try-catch-statement.
6278
6279   objc-try-catch-statement:
6280     @try compound-statement objc-catch-list[opt]
6281     @try compound-statement objc-catch-list[opt] @finally compound-statement
6282
6283   objc-catch-list:
6284     @catch ( parameter-declaration ) compound-statement
6285     objc-catch-list @catch ( parameter-declaration ) compound-statement
6286*/
6287
6288static void
6289c_parser_objc_try_catch_statement (c_parser *parser)
6290{
6291  location_t loc;
6292  tree stmt;
6293  gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
6294  c_parser_consume_token (parser);
6295  loc = c_parser_peek_token (parser)->location;
6296  stmt = c_parser_compound_statement (parser);
6297  objc_begin_try_stmt (loc, stmt);
6298  while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
6299    {
6300      struct c_parm *parm;
6301      c_parser_consume_token (parser);
6302      if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6303	break;
6304      parm = c_parser_parameter_declaration (parser, NULL_TREE);
6305      if (parm == NULL)
6306	{
6307	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6308	  break;
6309	}
6310      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6311      objc_begin_catch_clause (grokparm (parm));
6312      if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6313	c_parser_compound_statement_nostart (parser);
6314      objc_finish_catch_clause ();
6315    }
6316  if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6317    {
6318      location_t finloc;
6319      tree finstmt;
6320      c_parser_consume_token (parser);
6321      finloc = c_parser_peek_token (parser)->location;
6322      finstmt = c_parser_compound_statement (parser);
6323      objc_build_finally_clause (finloc, finstmt);
6324    }
6325  objc_finish_try_stmt ();
6326}
6327
6328/* Parse an objc-synchronized-statement.
6329
6330   objc-synchronized-statement:
6331     @synchronized ( expression ) compound-statement
6332*/
6333
6334static void
6335c_parser_objc_synchronized_statement (c_parser *parser)
6336{
6337  location_t loc;
6338  tree expr, stmt;
6339  gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6340  c_parser_consume_token (parser);
6341  loc = c_parser_peek_token (parser)->location;
6342  if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6343    {
6344      expr = c_parser_expression (parser).value;
6345      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6346    }
6347  else
6348    expr = error_mark_node;
6349  stmt = c_parser_compound_statement (parser);
6350  objc_build_synchronized (loc, expr, stmt);
6351}
6352
6353/* Parse an objc-selector; return NULL_TREE without an error if the
6354   next token is not an objc-selector.
6355
6356   objc-selector:
6357     identifier
6358     one of
6359       enum struct union if else while do for switch case default
6360       break continue return goto asm sizeof typeof __alignof
6361       unsigned long const short volatile signed restrict _Complex
6362       in out inout bycopy byref oneway int char float double void _Bool
6363
6364   ??? Why this selection of keywords but not, for example, storage
6365   class specifiers?  */
6366
6367static tree
6368c_parser_objc_selector (c_parser *parser)
6369{
6370  c_token *token = c_parser_peek_token (parser);
6371  tree value = token->value;
6372  if (token->type == CPP_NAME)
6373    {
6374      c_parser_consume_token (parser);
6375      return value;
6376    }
6377  if (token->type != CPP_KEYWORD)
6378    return NULL_TREE;
6379  switch (token->keyword)
6380    {
6381    case RID_ENUM:
6382    case RID_STRUCT:
6383    case RID_UNION:
6384    case RID_IF:
6385    case RID_ELSE:
6386    case RID_WHILE:
6387    case RID_DO:
6388    case RID_FOR:
6389    case RID_SWITCH:
6390    case RID_CASE:
6391    case RID_DEFAULT:
6392    case RID_BREAK:
6393    case RID_CONTINUE:
6394    case RID_RETURN:
6395    case RID_GOTO:
6396    case RID_ASM:
6397    case RID_SIZEOF:
6398    case RID_TYPEOF:
6399    case RID_ALIGNOF:
6400    case RID_UNSIGNED:
6401    case RID_LONG:
6402    case RID_CONST:
6403    case RID_SHORT:
6404    case RID_VOLATILE:
6405    case RID_SIGNED:
6406    case RID_RESTRICT:
6407    case RID_COMPLEX:
6408    case RID_IN:
6409    case RID_OUT:
6410    case RID_INOUT:
6411    case RID_BYCOPY:
6412    case RID_BYREF:
6413    case RID_ONEWAY:
6414    case RID_INT:
6415    case RID_CHAR:
6416    case RID_FLOAT:
6417    case RID_DOUBLE:
6418    case RID_VOID:
6419    case RID_BOOL:
6420      c_parser_consume_token (parser);
6421      return value;
6422    default:
6423      return NULL_TREE;
6424    }
6425}
6426
6427/* Parse an objc-selector-arg.
6428
6429   objc-selector-arg:
6430     objc-selector
6431     objc-keywordname-list
6432
6433   objc-keywordname-list:
6434     objc-keywordname
6435     objc-keywordname-list objc-keywordname
6436
6437   objc-keywordname:
6438     objc-selector :
6439     :
6440*/
6441
6442static tree
6443c_parser_objc_selector_arg (c_parser *parser)
6444{
6445  tree sel = c_parser_objc_selector (parser);
6446  tree list = NULL_TREE;
6447  if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6448    return sel;
6449  while (true)
6450    {
6451      if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6452	return list;
6453      list = chainon (list, build_tree_list (sel, NULL_TREE));
6454      sel = c_parser_objc_selector (parser);
6455      if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6456	break;
6457    }
6458  return list;
6459}
6460
6461/* Parse an objc-receiver.
6462
6463   objc-receiver:
6464     expression
6465     class-name
6466     type-name
6467*/
6468
6469static tree
6470c_parser_objc_receiver (c_parser *parser)
6471{
6472  if (c_parser_peek_token (parser)->type == CPP_NAME
6473      && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
6474	  || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
6475    {
6476      tree id = c_parser_peek_token (parser)->value;
6477      c_parser_consume_token (parser);
6478      return objc_get_class_reference (id);
6479    }
6480  return c_parser_expression (parser).value;
6481}
6482
6483/* Parse objc-message-args.
6484
6485   objc-message-args:
6486     objc-selector
6487     objc-keywordarg-list
6488
6489   objc-keywordarg-list:
6490     objc-keywordarg
6491     objc-keywordarg-list objc-keywordarg
6492
6493   objc-keywordarg:
6494     objc-selector : objc-keywordexpr
6495     : objc-keywordexpr
6496*/
6497
6498static tree
6499c_parser_objc_message_args (c_parser *parser)
6500{
6501  tree sel = c_parser_objc_selector (parser);
6502  tree list = NULL_TREE;
6503  if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6504    return sel;
6505  while (true)
6506    {
6507      tree keywordexpr;
6508      if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6509	return list;
6510      keywordexpr = c_parser_objc_keywordexpr (parser);
6511      list = chainon (list, build_tree_list (sel, keywordexpr));
6512      sel = c_parser_objc_selector (parser);
6513      if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6514	break;
6515    }
6516  return list;
6517}
6518
6519/* Parse an objc-keywordexpr.
6520
6521   objc-keywordexpr:
6522     nonempty-expr-list
6523*/
6524
6525static tree
6526c_parser_objc_keywordexpr (c_parser *parser)
6527{
6528  tree list = c_parser_expr_list (parser, true);
6529  if (TREE_CHAIN (list) == NULL_TREE)
6530    {
6531      /* Just return the expression, remove a level of
6532	 indirection.  */
6533      return TREE_VALUE (list);
6534    }
6535  else
6536    {
6537      /* We have a comma expression, we will collapse later.  */
6538      return list;
6539    }
6540}
6541
6542
6543/* Handle pragmas.  Some OpenMP pragmas are associated with, and therefore
6544   should be considered, statements.  ALLOW_STMT is true if we're within
6545   the context of a function and such pragmas are to be allowed.  Returns
6546   true if we actually parsed such a pragma.  */
6547
6548static bool
6549c_parser_pragma (c_parser *parser, enum pragma_context context)
6550{
6551  unsigned int id;
6552
6553  id = c_parser_peek_token (parser)->pragma_kind;
6554  gcc_assert (id != PRAGMA_NONE);
6555
6556  switch (id)
6557    {
6558    case PRAGMA_OMP_BARRIER:
6559      if (context != pragma_compound)
6560	{
6561	  if (context == pragma_stmt)
6562	    c_parser_error (parser, "%<#pragma omp barrier%> may only be "
6563			    "used in compound statements");
6564	  goto bad_stmt;
6565	}
6566      c_parser_omp_barrier (parser);
6567      return false;
6568
6569    case PRAGMA_OMP_FLUSH:
6570      if (context != pragma_compound)
6571	{
6572	  if (context == pragma_stmt)
6573	    c_parser_error (parser, "%<#pragma omp flush%> may only be "
6574			    "used in compound statements");
6575	  goto bad_stmt;
6576	}
6577      c_parser_omp_flush (parser);
6578      return false;
6579
6580    case PRAGMA_OMP_THREADPRIVATE:
6581      c_parser_omp_threadprivate (parser);
6582      return false;
6583
6584    case PRAGMA_OMP_SECTION:
6585      error ("%<#pragma omp section%> may only be used in "
6586	     "%<#pragma omp sections%> construct");
6587      c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6588      return false;
6589
6590    case PRAGMA_GCC_PCH_PREPROCESS:
6591      c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
6592      c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6593      return false;
6594
6595    default:
6596      if (id < PRAGMA_FIRST_EXTERNAL)
6597	{
6598	  if (context == pragma_external)
6599	    {
6600	    bad_stmt:
6601	      c_parser_error (parser, "expected declaration specifiers");
6602	      c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6603	      return false;
6604	    }
6605	  c_parser_omp_construct (parser);
6606	  return true;
6607	}
6608      break;
6609    }
6610
6611  c_parser_consume_pragma (parser);
6612  c_invoke_pragma_handler (id);
6613
6614  /* Skip to EOL, but suppress any error message.  Those will have been
6615     generated by the handler routine through calling error, as opposed
6616     to calling c_parser_error.  */
6617  parser->error = true;
6618  c_parser_skip_to_pragma_eol (parser);
6619
6620  return false;
6621}
6622
6623/* The interface the pragma parsers have to the lexer.  */
6624
6625enum cpp_ttype
6626pragma_lex (tree *value)
6627{
6628  c_token *tok = c_parser_peek_token (the_parser);
6629  enum cpp_ttype ret = tok->type;
6630
6631  *value = tok->value;
6632  if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
6633    ret = CPP_EOF;
6634  else
6635    {
6636      if (ret == CPP_KEYWORD)
6637	ret = CPP_NAME;
6638      c_parser_consume_token (the_parser);
6639    }
6640
6641  return ret;
6642}
6643
6644static void
6645c_parser_pragma_pch_preprocess (c_parser *parser)
6646{
6647  tree name = NULL;
6648
6649  c_parser_consume_pragma (parser);
6650  if (c_parser_next_token_is (parser, CPP_STRING))
6651    {
6652      name = c_parser_peek_token (parser)->value;
6653      c_parser_consume_token (parser);
6654    }
6655  else
6656    c_parser_error (parser, "expected string literal");
6657  c_parser_skip_to_pragma_eol (parser);
6658
6659  if (name)
6660    c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
6661}
6662
6663/* OpenMP 2.5 parsing routines.  */
6664
6665/* Returns name of the next clause.
6666   If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6667   the token is not consumed.  Otherwise appropriate pragma_omp_clause is
6668   returned and the token is consumed.  */
6669
6670static pragma_omp_clause
6671c_parser_omp_clause_name (c_parser *parser)
6672{
6673  pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
6674
6675  if (c_parser_next_token_is_keyword (parser, RID_IF))
6676    result = PRAGMA_OMP_CLAUSE_IF;
6677  else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
6678    result = PRAGMA_OMP_CLAUSE_DEFAULT;
6679  else if (c_parser_next_token_is (parser, CPP_NAME))
6680    {
6681      const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6682
6683      switch (p[0])
6684	{
6685	case 'c':
6686	  if (!strcmp ("copyin", p))
6687	    result = PRAGMA_OMP_CLAUSE_COPYIN;
6688          else if (!strcmp ("copyprivate", p))
6689	    result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
6690	  break;
6691	case 'f':
6692	  if (!strcmp ("firstprivate", p))
6693	    result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
6694	  break;
6695	case 'l':
6696	  if (!strcmp ("lastprivate", p))
6697	    result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
6698	  break;
6699	case 'n':
6700	  if (!strcmp ("nowait", p))
6701	    result = PRAGMA_OMP_CLAUSE_NOWAIT;
6702	  else if (!strcmp ("num_threads", p))
6703	    result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
6704	  break;
6705	case 'o':
6706	  if (!strcmp ("ordered", p))
6707	    result = PRAGMA_OMP_CLAUSE_ORDERED;
6708	  break;
6709	case 'p':
6710	  if (!strcmp ("private", p))
6711	    result = PRAGMA_OMP_CLAUSE_PRIVATE;
6712	  break;
6713	case 'r':
6714	  if (!strcmp ("reduction", p))
6715	    result = PRAGMA_OMP_CLAUSE_REDUCTION;
6716	  break;
6717	case 's':
6718	  if (!strcmp ("schedule", p))
6719	    result = PRAGMA_OMP_CLAUSE_SCHEDULE;
6720	  else if (!strcmp ("shared", p))
6721	    result = PRAGMA_OMP_CLAUSE_SHARED;
6722	  break;
6723	}
6724    }
6725
6726  if (result != PRAGMA_OMP_CLAUSE_NONE)
6727    c_parser_consume_token (parser);
6728
6729  return result;
6730}
6731
6732/* Validate that a clause of the given type does not already exist.  */
6733
6734static void
6735check_no_duplicate_clause (tree clauses, enum tree_code code, const char *name)
6736{
6737  tree c;
6738
6739  for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
6740    if (OMP_CLAUSE_CODE (c) == code)
6741      {
6742	error ("too many %qs clauses", name);
6743	break;
6744      }
6745}
6746
6747/* OpenMP 2.5:
6748   variable-list:
6749     identifier
6750     variable-list , identifier
6751
6752   If KIND is nonzero, create the appropriate node and install the decl
6753   in OMP_CLAUSE_DECL and add the node to the head of the list.
6754
6755   If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6756   return the list created.  */
6757
6758static tree
6759c_parser_omp_variable_list (c_parser *parser, enum omp_clause_code kind,
6760                            tree list)
6761{
6762  if (c_parser_next_token_is_not (parser, CPP_NAME)
6763      || c_parser_peek_token (parser)->id_kind != C_ID_ID)
6764    c_parser_error (parser, "expected identifier");
6765
6766  while (c_parser_next_token_is (parser, CPP_NAME)
6767	 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
6768    {
6769      tree t = lookup_name (c_parser_peek_token (parser)->value);
6770
6771      if (t == NULL_TREE)
6772	undeclared_variable (c_parser_peek_token (parser)->value,
6773			     c_parser_peek_token (parser)->location);
6774      else if (t == error_mark_node)
6775	;
6776      else if (kind != 0)
6777	{
6778	  tree u = build_omp_clause (kind);
6779	  OMP_CLAUSE_DECL (u) = t;
6780	  OMP_CLAUSE_CHAIN (u) = list;
6781	  list = u;
6782	}
6783      else
6784	list = tree_cons (t, NULL_TREE, list);
6785
6786      c_parser_consume_token (parser);
6787
6788      if (c_parser_next_token_is_not (parser, CPP_COMMA))
6789	break;
6790
6791      c_parser_consume_token (parser);
6792    }
6793
6794  return list;
6795}
6796
6797/* Similarly, but expect leading and trailing parenthesis.  This is a very
6798   common case for omp clauses.  */
6799
6800static tree
6801c_parser_omp_var_list_parens (c_parser *parser, enum tree_code kind, tree list)
6802{
6803  if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6804    {
6805      list = c_parser_omp_variable_list (parser, kind, list);
6806      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6807    }
6808  return list;
6809}
6810
6811/* OpenMP 2.5:
6812   copyin ( variable-list ) */
6813
6814static tree
6815c_parser_omp_clause_copyin (c_parser *parser, tree list)
6816{
6817  return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
6818}
6819
6820/* OpenMP 2.5:
6821   copyprivate ( variable-list ) */
6822
6823static tree
6824c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
6825{
6826  return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
6827}
6828
6829/* OpenMP 2.5:
6830   default ( shared | none ) */
6831
6832static tree
6833c_parser_omp_clause_default (c_parser *parser, tree list)
6834{
6835  enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
6836  tree c;
6837
6838  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6839    return list;
6840  if (c_parser_next_token_is (parser, CPP_NAME))
6841    {
6842      const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6843
6844      switch (p[0])
6845	{
6846	case 'n':
6847	  if (strcmp ("none", p) != 0)
6848	    goto invalid_kind;
6849	  kind = OMP_CLAUSE_DEFAULT_NONE;
6850	  break;
6851
6852	case 's':
6853	  if (strcmp ("shared", p) != 0)
6854	    goto invalid_kind;
6855	  kind = OMP_CLAUSE_DEFAULT_SHARED;
6856	  break;
6857
6858	default:
6859	  goto invalid_kind;
6860	}
6861
6862      c_parser_consume_token (parser);
6863    }
6864  else
6865    {
6866    invalid_kind:
6867      c_parser_error (parser, "expected %<none%> or %<shared%>");
6868    }
6869  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6870
6871  if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
6872    return list;
6873
6874  check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
6875  c = build_omp_clause (OMP_CLAUSE_DEFAULT);
6876  OMP_CLAUSE_CHAIN (c) = list;
6877  OMP_CLAUSE_DEFAULT_KIND (c) = kind;
6878
6879  return c;
6880}
6881
6882/* OpenMP 2.5:
6883   firstprivate ( variable-list ) */
6884
6885static tree
6886c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
6887{
6888  return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
6889}
6890
6891/* OpenMP 2.5:
6892   if ( expression ) */
6893
6894static tree
6895c_parser_omp_clause_if (c_parser *parser, tree list)
6896{
6897  if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6898    {
6899      tree t = c_parser_paren_condition (parser);
6900      tree c;
6901
6902      check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
6903
6904      c = build_omp_clause (OMP_CLAUSE_IF);
6905      OMP_CLAUSE_IF_EXPR (c) = t;
6906      OMP_CLAUSE_CHAIN (c) = list;
6907      list = c;
6908    }
6909  else
6910    c_parser_error (parser, "expected %<(%>");
6911
6912  return list;
6913}
6914
6915/* OpenMP 2.5:
6916   lastprivate ( variable-list ) */
6917
6918static tree
6919c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
6920{
6921  return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
6922}
6923
6924/* OpenMP 2.5:
6925   nowait */
6926
6927static tree
6928c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
6929{
6930  tree c;
6931
6932  check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
6933
6934  c = build_omp_clause (OMP_CLAUSE_NOWAIT);
6935  OMP_CLAUSE_CHAIN (c) = list;
6936  return c;
6937}
6938
6939/* OpenMP 2.5:
6940   num_threads ( expression ) */
6941
6942static tree
6943c_parser_omp_clause_num_threads (c_parser *parser, tree list)
6944{
6945  if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6946    {
6947      tree c, t = c_parser_expression (parser).value;
6948
6949      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6950
6951      if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
6952	{
6953	  c_parser_error (parser, "expected integer expression");
6954	  return list;
6955	}
6956
6957      /* Attempt to statically determine when the number isn't positive.  */
6958      c = fold_build2 (LE_EXPR, boolean_type_node, t,
6959		       build_int_cst (TREE_TYPE (t), 0));
6960      if (c == boolean_true_node)
6961	{
6962	  warning (0, "%<num_threads%> value must be positive");
6963	  t = integer_one_node;
6964	}
6965
6966      check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
6967
6968      c = build_omp_clause (OMP_CLAUSE_NUM_THREADS);
6969      OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
6970      OMP_CLAUSE_CHAIN (c) = list;
6971      list = c;
6972    }
6973
6974  return list;
6975}
6976
6977/* OpenMP 2.5:
6978   ordered */
6979
6980static tree
6981c_parser_omp_clause_ordered (c_parser *parser ATTRIBUTE_UNUSED, tree list)
6982{
6983  tree c;
6984
6985  check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
6986
6987  c = build_omp_clause (OMP_CLAUSE_ORDERED);
6988  OMP_CLAUSE_CHAIN (c) = list;
6989  return c;
6990}
6991
6992/* OpenMP 2.5:
6993   private ( variable-list ) */
6994
6995static tree
6996c_parser_omp_clause_private (c_parser *parser, tree list)
6997{
6998  return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
6999}
7000
7001/* OpenMP 2.5:
7002   reduction ( reduction-operator : variable-list )
7003
7004   reduction-operator:
7005     One of: + * - & ^ | && || */
7006
7007static tree
7008c_parser_omp_clause_reduction (c_parser *parser, tree list)
7009{
7010  if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7011    {
7012      enum tree_code code;
7013
7014      switch (c_parser_peek_token (parser)->type)
7015	{
7016	case CPP_PLUS:
7017	  code = PLUS_EXPR;
7018	  break;
7019	case CPP_MULT:
7020	  code = MULT_EXPR;
7021	  break;
7022	case CPP_MINUS:
7023	  code = MINUS_EXPR;
7024	  break;
7025	case CPP_AND:
7026	  code = BIT_AND_EXPR;
7027	  break;
7028	case CPP_XOR:
7029	  code = BIT_XOR_EXPR;
7030	  break;
7031	case CPP_OR:
7032	  code = BIT_IOR_EXPR;
7033	  break;
7034	case CPP_AND_AND:
7035	  code = TRUTH_ANDIF_EXPR;
7036	  break;
7037	case CPP_OR_OR:
7038	  code = TRUTH_ORIF_EXPR;
7039	  break;
7040	default:
7041	  c_parser_error (parser,
7042			  "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7043			  "%<^%>, %<|%>, %<&&%>, or %<||%>");
7044	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7045	  return list;
7046	}
7047      c_parser_consume_token (parser);
7048      if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7049	{
7050	  tree nl, c;
7051
7052	  nl = c_parser_omp_variable_list (parser, OMP_CLAUSE_REDUCTION, list);
7053	  for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
7054	    OMP_CLAUSE_REDUCTION_CODE (c) = code;
7055
7056	  list = nl;
7057	}
7058      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7059    }
7060  return list;
7061}
7062
7063/* OpenMP 2.5:
7064   schedule ( schedule-kind )
7065   schedule ( schedule-kind , expression )
7066
7067   schedule-kind:
7068     static | dynamic | guided | runtime
7069*/
7070
7071static tree
7072c_parser_omp_clause_schedule (c_parser *parser, tree list)
7073{
7074  tree c, t;
7075
7076  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7077    return list;
7078
7079  c = build_omp_clause (OMP_CLAUSE_SCHEDULE);
7080
7081  if (c_parser_next_token_is (parser, CPP_NAME))
7082    {
7083      tree kind = c_parser_peek_token (parser)->value;
7084      const char *p = IDENTIFIER_POINTER (kind);
7085
7086      switch (p[0])
7087	{
7088	case 'd':
7089	  if (strcmp ("dynamic", p) != 0)
7090	    goto invalid_kind;
7091	  OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7092	  break;
7093
7094        case 'g':
7095	  if (strcmp ("guided", p) != 0)
7096	    goto invalid_kind;
7097	  OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7098	  break;
7099
7100	case 'r':
7101	  if (strcmp ("runtime", p) != 0)
7102	    goto invalid_kind;
7103	  OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7104	  break;
7105
7106	default:
7107	  goto invalid_kind;
7108	}
7109    }
7110  else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7111    OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7112  else
7113    goto invalid_kind;
7114
7115  c_parser_consume_token (parser);
7116  if (c_parser_next_token_is (parser, CPP_COMMA))
7117    {
7118      c_parser_consume_token (parser);
7119
7120      t = c_parser_expr_no_commas (parser, NULL).value;
7121
7122      if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7123	error ("schedule %<runtime%> does not take "
7124	       "a %<chunk_size%> parameter");
7125      else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7126	OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7127      else
7128	c_parser_error (parser, "expected integer expression");
7129
7130      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7131    }
7132  else
7133    c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7134			       "expected %<,%> or %<)%>");
7135
7136  check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7137  OMP_CLAUSE_CHAIN (c) = list;
7138  return c;
7139
7140 invalid_kind:
7141  c_parser_error (parser, "invalid schedule kind");
7142  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7143  return list;
7144}
7145
7146/* OpenMP 2.5:
7147   shared ( variable-list ) */
7148
7149static tree
7150c_parser_omp_clause_shared (c_parser *parser, tree list)
7151{
7152  return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7153}
7154
7155/* Parse all OpenMP clauses.  The set clauses allowed by the directive
7156   is a bitmask in MASK.  Return the list of clauses found; the result
7157   of clause default goes in *pdefault.  */
7158
7159static tree
7160c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7161			  const char *where)
7162{
7163  tree clauses = NULL;
7164
7165  while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7166    {
7167      const pragma_omp_clause c_kind = c_parser_omp_clause_name (parser);
7168      const char *c_name;
7169      tree prev = clauses;
7170
7171      switch (c_kind)
7172	{
7173	case PRAGMA_OMP_CLAUSE_COPYIN:
7174	  clauses = c_parser_omp_clause_copyin (parser, clauses);
7175	  c_name = "copyin";
7176	  break;
7177	case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7178	  clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7179	  c_name = "copyprivate";
7180	  break;
7181	case PRAGMA_OMP_CLAUSE_DEFAULT:
7182	  clauses = c_parser_omp_clause_default (parser, clauses);
7183	  c_name = "default";
7184	  break;
7185	case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7186	  clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7187	  c_name = "firstprivate";
7188	  break;
7189	case PRAGMA_OMP_CLAUSE_IF:
7190	  clauses = c_parser_omp_clause_if (parser, clauses);
7191	  c_name = "if";
7192	  break;
7193	case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7194	  clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7195	  c_name = "lastprivate";
7196	  break;
7197	case PRAGMA_OMP_CLAUSE_NOWAIT:
7198	  clauses = c_parser_omp_clause_nowait (parser, clauses);
7199	  c_name = "nowait";
7200	  break;
7201	case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7202	  clauses = c_parser_omp_clause_num_threads (parser, clauses);
7203	  c_name = "num_threads";
7204	  break;
7205	case PRAGMA_OMP_CLAUSE_ORDERED:
7206	  clauses = c_parser_omp_clause_ordered (parser, clauses);
7207	  c_name = "ordered";
7208	  break;
7209	case PRAGMA_OMP_CLAUSE_PRIVATE:
7210	  clauses = c_parser_omp_clause_private (parser, clauses);
7211	  c_name = "private";
7212	  break;
7213	case PRAGMA_OMP_CLAUSE_REDUCTION:
7214	  clauses = c_parser_omp_clause_reduction (parser, clauses);
7215	  c_name = "reduction";
7216	  break;
7217	case PRAGMA_OMP_CLAUSE_SCHEDULE:
7218	  clauses = c_parser_omp_clause_schedule (parser, clauses);
7219	  c_name = "schedule";
7220	  break;
7221	case PRAGMA_OMP_CLAUSE_SHARED:
7222	  clauses = c_parser_omp_clause_shared (parser, clauses);
7223	  c_name = "shared";
7224	  break;
7225	default:
7226	  c_parser_error (parser, "expected %<#pragma omp%> clause");
7227	  goto saw_error;
7228	}
7229
7230      if (((mask >> c_kind) & 1) == 0 && !parser->error)
7231	{
7232	  /* Remove the invalid clause(s) from the list to avoid
7233	     confusing the rest of the compiler.  */
7234	  clauses = prev;
7235	  error ("%qs is not valid for %qs", c_name, where);
7236	}
7237    }
7238
7239 saw_error:
7240  c_parser_skip_to_pragma_eol (parser);
7241
7242  return c_finish_omp_clauses (clauses);
7243}
7244
7245/* OpenMP 2.5:
7246   structured-block:
7247     statement
7248
7249   In practice, we're also interested in adding the statement to an
7250   outer node.  So it is convenient if we work around the fact that
7251   c_parser_statement calls add_stmt.  */
7252
7253static tree
7254c_parser_omp_structured_block (c_parser *parser)
7255{
7256  tree stmt = push_stmt_list ();
7257  c_parser_statement (parser);
7258  return pop_stmt_list (stmt);
7259}
7260
7261/* OpenMP 2.5:
7262   # pragma omp atomic new-line
7263     expression-stmt
7264
7265   expression-stmt:
7266     x binop= expr | x++ | ++x | x-- | --x
7267   binop:
7268     +, *, -, /, &, ^, |, <<, >>
7269
7270  where x is an lvalue expression with scalar type.  */
7271
7272static void
7273c_parser_omp_atomic (c_parser *parser)
7274{
7275  tree lhs, rhs;
7276  tree stmt;
7277  enum tree_code code;
7278
7279  c_parser_skip_to_pragma_eol (parser);
7280
7281  lhs = c_parser_unary_expression (parser).value;
7282  switch (TREE_CODE (lhs))
7283    {
7284    case ERROR_MARK:
7285    saw_error:
7286      c_parser_skip_to_end_of_block_or_statement (parser);
7287      return;
7288
7289    case PREINCREMENT_EXPR:
7290    case POSTINCREMENT_EXPR:
7291      lhs = TREE_OPERAND (lhs, 0);
7292      code = PLUS_EXPR;
7293      rhs = integer_one_node;
7294      break;
7295
7296    case PREDECREMENT_EXPR:
7297    case POSTDECREMENT_EXPR:
7298      lhs = TREE_OPERAND (lhs, 0);
7299      code = MINUS_EXPR;
7300      rhs = integer_one_node;
7301      break;
7302
7303    default:
7304      switch (c_parser_peek_token (parser)->type)
7305	{
7306	case CPP_MULT_EQ:
7307	  code = MULT_EXPR;
7308	  break;
7309	case CPP_DIV_EQ:
7310	  code = TRUNC_DIV_EXPR;
7311	  break;
7312	case CPP_PLUS_EQ:
7313	  code = PLUS_EXPR;
7314	  break;
7315	case CPP_MINUS_EQ:
7316	  code = MINUS_EXPR;
7317	  break;
7318	case CPP_LSHIFT_EQ:
7319	  code = LSHIFT_EXPR;
7320	  break;
7321	case CPP_RSHIFT_EQ:
7322	  code = RSHIFT_EXPR;
7323	  break;
7324	case CPP_AND_EQ:
7325	  code = BIT_AND_EXPR;
7326	  break;
7327	case CPP_OR_EQ:
7328	  code = BIT_IOR_EXPR;
7329	  break;
7330	case CPP_XOR_EQ:
7331	  code = BIT_XOR_EXPR;
7332	  break;
7333	default:
7334	  c_parser_error (parser,
7335			  "invalid operator for %<#pragma omp atomic%>");
7336	  goto saw_error;
7337	}
7338
7339      c_parser_consume_token (parser);
7340      rhs = c_parser_expression (parser).value;
7341      break;
7342    }
7343  stmt = c_finish_omp_atomic (code, lhs, rhs);
7344  if (stmt != error_mark_node)
7345    add_stmt (stmt);
7346  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7347}
7348
7349
7350/* OpenMP 2.5:
7351   # pragma omp barrier new-line
7352*/
7353
7354static void
7355c_parser_omp_barrier (c_parser *parser)
7356{
7357  c_parser_consume_pragma (parser);
7358  c_parser_skip_to_pragma_eol (parser);
7359
7360  c_finish_omp_barrier ();
7361}
7362
7363/* OpenMP 2.5:
7364   # pragma omp critical [(name)] new-line
7365     structured-block
7366*/
7367
7368static tree
7369c_parser_omp_critical (c_parser *parser)
7370{
7371  tree stmt, name = NULL;
7372
7373  if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7374    {
7375      c_parser_consume_token (parser);
7376      if (c_parser_next_token_is (parser, CPP_NAME))
7377	{
7378	  name = c_parser_peek_token (parser)->value;
7379	  c_parser_consume_token (parser);
7380	  c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7381	}
7382      else
7383	c_parser_error (parser, "expected identifier");
7384    }
7385  else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7386    c_parser_error (parser, "expected %<(%> or end of line");
7387  c_parser_skip_to_pragma_eol (parser);
7388
7389  stmt = c_parser_omp_structured_block (parser);
7390  return c_finish_omp_critical (stmt, name);
7391}
7392
7393/* OpenMP 2.5:
7394   # pragma omp flush flush-vars[opt] new-line
7395
7396   flush-vars:
7397     ( variable-list ) */
7398
7399static void
7400c_parser_omp_flush (c_parser *parser)
7401{
7402  c_parser_consume_pragma (parser);
7403  if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7404    c_parser_omp_var_list_parens (parser, 0, NULL);
7405  else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7406    c_parser_error (parser, "expected %<(%> or end of line");
7407  c_parser_skip_to_pragma_eol (parser);
7408
7409  c_finish_omp_flush ();
7410}
7411
7412/* Parse the restricted form of the for statment allowed by OpenMP.
7413   The real trick here is to determine the loop control variable early
7414   so that we can push a new decl if necessary to make it private.  */
7415
7416static tree
7417c_parser_omp_for_loop (c_parser *parser)
7418{
7419  tree decl, cond, incr, save_break, save_cont, body, init;
7420  location_t loc;
7421
7422  if (!c_parser_next_token_is_keyword (parser, RID_FOR))
7423    {
7424      c_parser_error (parser, "for statement expected");
7425      return NULL;
7426    }
7427  loc = c_parser_peek_token (parser)->location;
7428  c_parser_consume_token (parser);
7429
7430  if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7431    return NULL;
7432
7433  /* Parse the initialization declaration or expression.  */
7434  if (c_parser_next_token_starts_declspecs (parser))
7435    {
7436      c_parser_declaration_or_fndef (parser, true, true, true, true);
7437      decl = check_for_loop_decls ();
7438      if (decl == NULL)
7439	goto error_init;
7440      init = decl;
7441    }
7442  else if (c_parser_next_token_is (parser, CPP_NAME)
7443	   && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
7444    {
7445      decl = c_parser_postfix_expression (parser).value;
7446
7447      c_parser_require (parser, CPP_EQ, "expected %<=%>");
7448
7449      init = c_parser_expr_no_commas (parser, NULL).value;
7450      init = build_modify_expr (decl, NOP_EXPR, init);
7451      init = c_process_expr_stmt (init);
7452
7453      c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7454    }
7455  else
7456    goto error_init;
7457
7458  /* Parse the loop condition.  */
7459  cond = NULL_TREE;
7460  if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
7461    {
7462      cond = c_parser_expression_conv (parser).value;
7463      cond = c_objc_common_truthvalue_conversion (cond);
7464      if (EXPR_P (cond))
7465	SET_EXPR_LOCATION (cond, input_location);
7466    }
7467  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7468
7469  /* Parse the increment expression.  */
7470  incr = NULL_TREE;
7471  if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
7472    incr = c_process_expr_stmt (c_parser_expression (parser).value);
7473  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7474
7475 parse_body:
7476  save_break = c_break_label;
7477  c_break_label = size_one_node;
7478  save_cont = c_cont_label;
7479  c_cont_label = NULL_TREE;
7480  body = push_stmt_list ();
7481
7482  add_stmt (c_parser_c99_block_statement (parser));
7483  if (c_cont_label)
7484    add_stmt (build1 (LABEL_EXPR, void_type_node, c_cont_label));
7485
7486  body = pop_stmt_list (body);
7487  c_break_label = save_break;
7488  c_cont_label = save_cont;
7489
7490  /* Only bother calling c_finish_omp_for if we havn't already generated
7491     an error from the initialization parsing.  */
7492  if (decl != NULL && decl != error_mark_node && init != error_mark_node)
7493    return c_finish_omp_for (loc, decl, init, cond, incr, body, NULL);
7494  return NULL;
7495
7496 error_init:
7497  c_parser_error (parser, "expected iteration declaration or initialization");
7498  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7499  decl = init = cond = incr = NULL_TREE;
7500  goto parse_body;
7501}
7502
7503/* OpenMP 2.5:
7504   #pragma omp for for-clause[optseq] new-line
7505     for-loop
7506*/
7507
7508#define OMP_FOR_CLAUSE_MASK				\
7509	( (1u << PRAGMA_OMP_CLAUSE_PRIVATE)		\
7510	| (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
7511	| (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE)		\
7512	| (1u << PRAGMA_OMP_CLAUSE_REDUCTION)		\
7513	| (1u << PRAGMA_OMP_CLAUSE_ORDERED)		\
7514	| (1u << PRAGMA_OMP_CLAUSE_SCHEDULE)		\
7515	| (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7516
7517static tree
7518c_parser_omp_for (c_parser *parser)
7519{
7520  tree block, clauses, ret;
7521
7522  clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
7523				      "#pragma omp for");
7524
7525  block = c_begin_compound_stmt (true);
7526  ret = c_parser_omp_for_loop (parser);
7527  if (ret)
7528    OMP_FOR_CLAUSES (ret) = clauses;
7529  block = c_end_compound_stmt (block, true);
7530  add_stmt (block);
7531
7532  return ret;
7533}
7534
7535/* OpenMP 2.5:
7536   # pragma omp master new-line
7537     structured-block
7538*/
7539
7540static tree
7541c_parser_omp_master (c_parser *parser)
7542{
7543  c_parser_skip_to_pragma_eol (parser);
7544  return c_finish_omp_master (c_parser_omp_structured_block (parser));
7545}
7546
7547/* OpenMP 2.5:
7548   # pragma omp ordered new-line
7549     structured-block
7550*/
7551
7552static tree
7553c_parser_omp_ordered (c_parser *parser)
7554{
7555  c_parser_skip_to_pragma_eol (parser);
7556  return c_finish_omp_ordered (c_parser_omp_structured_block (parser));
7557}
7558
7559/* OpenMP 2.5:
7560
7561   section-scope:
7562     { section-sequence }
7563
7564   section-sequence:
7565     section-directive[opt] structured-block
7566     section-sequence section-directive structured-block  */
7567
7568static tree
7569c_parser_omp_sections_scope (c_parser *parser)
7570{
7571  tree stmt, substmt;
7572  bool error_suppress = false;
7573  location_t loc;
7574
7575  if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7576    {
7577      /* Avoid skipping until the end of the block.  */
7578      parser->error = false;
7579      return NULL_TREE;
7580    }
7581
7582  stmt = push_stmt_list ();
7583
7584  loc = c_parser_peek_token (parser)->location;
7585  if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
7586    {
7587      substmt = push_stmt_list ();
7588
7589      while (1)
7590	{
7591          c_parser_statement (parser);
7592
7593	  if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7594	    break;
7595	  if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7596	    break;
7597	  if (c_parser_next_token_is (parser, CPP_EOF))
7598	    break;
7599	}
7600
7601      substmt = pop_stmt_list (substmt);
7602      substmt = build1 (OMP_SECTION, void_type_node, substmt);
7603      SET_EXPR_LOCATION (substmt, loc);
7604      add_stmt (substmt);
7605    }
7606
7607  while (1)
7608    {
7609      if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7610	break;
7611      if (c_parser_next_token_is (parser, CPP_EOF))
7612	break;
7613
7614      loc = c_parser_peek_token (parser)->location;
7615      if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7616	{
7617	  c_parser_consume_pragma (parser);
7618	  c_parser_skip_to_pragma_eol (parser);
7619	  error_suppress = false;
7620	}
7621      else if (!error_suppress)
7622	{
7623	  error ("expected %<#pragma omp section%> or %<}%>");
7624	  error_suppress = true;
7625	}
7626
7627      substmt = c_parser_omp_structured_block (parser);
7628      substmt = build1 (OMP_SECTION, void_type_node, substmt);
7629      SET_EXPR_LOCATION (substmt, loc);
7630      add_stmt (substmt);
7631    }
7632  c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
7633			     "expected %<#pragma omp section%> or %<}%>");
7634
7635  substmt = pop_stmt_list (stmt);
7636
7637  stmt = make_node (OMP_SECTIONS);
7638  TREE_TYPE (stmt) = void_type_node;
7639  OMP_SECTIONS_BODY (stmt) = substmt;
7640
7641  return add_stmt (stmt);
7642}
7643
7644/* OpenMP 2.5:
7645   # pragma omp sections sections-clause[optseq] newline
7646     sections-scope
7647*/
7648
7649#define OMP_SECTIONS_CLAUSE_MASK			\
7650	( (1u << PRAGMA_OMP_CLAUSE_PRIVATE)		\
7651	| (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
7652	| (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE)		\
7653	| (1u << PRAGMA_OMP_CLAUSE_REDUCTION)		\
7654	| (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7655
7656static tree
7657c_parser_omp_sections (c_parser *parser)
7658{
7659  tree block, clauses, ret;
7660
7661  clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
7662				      "#pragma omp sections");
7663
7664  block = c_begin_compound_stmt (true);
7665  ret = c_parser_omp_sections_scope (parser);
7666  if (ret)
7667    OMP_SECTIONS_CLAUSES (ret) = clauses;
7668  block = c_end_compound_stmt (block, true);
7669  add_stmt (block);
7670
7671  return ret;
7672}
7673
7674/* OpenMP 2.5:
7675   # pragma parallel parallel-clause new-line
7676   # pragma parallel for parallel-for-clause new-line
7677   # pragma parallel sections parallel-sections-clause new-line
7678*/
7679
7680#define OMP_PARALLEL_CLAUSE_MASK			\
7681	( (1u << PRAGMA_OMP_CLAUSE_IF)			\
7682	| (1u << PRAGMA_OMP_CLAUSE_PRIVATE)		\
7683	| (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
7684	| (1u << PRAGMA_OMP_CLAUSE_DEFAULT)		\
7685	| (1u << PRAGMA_OMP_CLAUSE_SHARED)		\
7686	| (1u << PRAGMA_OMP_CLAUSE_COPYIN)		\
7687	| (1u << PRAGMA_OMP_CLAUSE_REDUCTION)		\
7688	| (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
7689
7690static tree
7691c_parser_omp_parallel (c_parser *parser)
7692{
7693  enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
7694  const char *p_name = "#pragma omp parallel";
7695  tree stmt, clauses, par_clause, ws_clause, block;
7696  unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
7697
7698  if (c_parser_next_token_is_keyword (parser, RID_FOR))
7699    {
7700      c_parser_consume_token (parser);
7701      p_kind = PRAGMA_OMP_PARALLEL_FOR;
7702      p_name = "#pragma omp parallel for";
7703      mask |= OMP_FOR_CLAUSE_MASK;
7704      mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
7705    }
7706  else if (c_parser_next_token_is (parser, CPP_NAME))
7707    {
7708      const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7709      if (strcmp (p, "sections") == 0)
7710	{
7711	  c_parser_consume_token (parser);
7712	  p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
7713	  p_name = "#pragma omp parallel sections";
7714	  mask |= OMP_SECTIONS_CLAUSE_MASK;
7715	  mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
7716	}
7717    }
7718
7719  clauses = c_parser_omp_all_clauses (parser, mask, p_name);
7720
7721  switch (p_kind)
7722    {
7723    case PRAGMA_OMP_PARALLEL:
7724      block = c_begin_omp_parallel ();
7725      c_parser_statement (parser);
7726      stmt = c_finish_omp_parallel (clauses, block);
7727      break;
7728
7729    case PRAGMA_OMP_PARALLEL_FOR:
7730      block = c_begin_omp_parallel ();
7731      c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
7732      stmt = c_parser_omp_for_loop (parser);
7733      if (stmt)
7734	OMP_FOR_CLAUSES (stmt) = ws_clause;
7735      stmt = c_finish_omp_parallel (par_clause, block);
7736      OMP_PARALLEL_COMBINED (stmt) = 1;
7737      break;
7738
7739    case PRAGMA_OMP_PARALLEL_SECTIONS:
7740      block = c_begin_omp_parallel ();
7741      c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
7742      stmt = c_parser_omp_sections_scope (parser);
7743      if (stmt)
7744	OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
7745      stmt = c_finish_omp_parallel (par_clause, block);
7746      OMP_PARALLEL_COMBINED (stmt) = 1;
7747      break;
7748
7749    default:
7750      gcc_unreachable ();
7751    }
7752
7753  return stmt;
7754}
7755
7756/* OpenMP 2.5:
7757   # pragma omp single single-clause[optseq] new-line
7758     structured-block
7759*/
7760
7761#define OMP_SINGLE_CLAUSE_MASK				\
7762	( (1u << PRAGMA_OMP_CLAUSE_PRIVATE)		\
7763	| (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
7764	| (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE)		\
7765	| (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7766
7767static tree
7768c_parser_omp_single (c_parser *parser)
7769{
7770  tree stmt = make_node (OMP_SINGLE);
7771  TREE_TYPE (stmt) = void_type_node;
7772
7773  OMP_SINGLE_CLAUSES (stmt)
7774    = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
7775				"#pragma omp single");
7776  OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
7777
7778  return add_stmt (stmt);
7779}
7780
7781
7782/* Main entry point to parsing most OpenMP pragmas.  */
7783
7784static void
7785c_parser_omp_construct (c_parser *parser)
7786{
7787  enum pragma_kind p_kind;
7788  location_t loc;
7789  tree stmt;
7790
7791  loc = c_parser_peek_token (parser)->location;
7792  p_kind = c_parser_peek_token (parser)->pragma_kind;
7793  c_parser_consume_pragma (parser);
7794
7795  /* For all constructs below except #pragma omp atomic
7796     MUST_NOT_THROW catch handlers are needed when exceptions
7797     are enabled.  */
7798  if (p_kind != PRAGMA_OMP_ATOMIC)
7799    c_maybe_initialize_eh ();
7800
7801  switch (p_kind)
7802    {
7803    case PRAGMA_OMP_ATOMIC:
7804      c_parser_omp_atomic (parser);
7805      return;
7806    case PRAGMA_OMP_CRITICAL:
7807      stmt = c_parser_omp_critical (parser);
7808      break;
7809    case PRAGMA_OMP_FOR:
7810      stmt = c_parser_omp_for (parser);
7811      break;
7812    case PRAGMA_OMP_MASTER:
7813      stmt = c_parser_omp_master (parser);
7814      break;
7815    case PRAGMA_OMP_ORDERED:
7816      stmt = c_parser_omp_ordered (parser);
7817      break;
7818    case PRAGMA_OMP_PARALLEL:
7819      stmt = c_parser_omp_parallel (parser);
7820      break;
7821    case PRAGMA_OMP_SECTIONS:
7822      stmt = c_parser_omp_sections (parser);
7823      break;
7824    case PRAGMA_OMP_SINGLE:
7825      stmt = c_parser_omp_single (parser);
7826      break;
7827    default:
7828      gcc_unreachable ();
7829    }
7830
7831  if (stmt)
7832    SET_EXPR_LOCATION (stmt, loc);
7833}
7834
7835
7836/* OpenMP 2.5:
7837   # pragma omp threadprivate (variable-list) */
7838
7839static void
7840c_parser_omp_threadprivate (c_parser *parser)
7841{
7842  tree vars, t;
7843
7844  c_parser_consume_pragma (parser);
7845  vars = c_parser_omp_var_list_parens (parser, 0, NULL);
7846
7847  if (!targetm.have_tls)
7848    sorry ("threadprivate variables not supported in this target");
7849
7850  /* Mark every variable in VARS to be assigned thread local storage.  */
7851  for (t = vars; t; t = TREE_CHAIN (t))
7852    {
7853      tree v = TREE_PURPOSE (t);
7854
7855      /* If V had already been marked threadprivate, it doesn't matter
7856	 whether it had been used prior to this point.  */
7857      if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
7858	error ("%qE declared %<threadprivate%> after first use", v);
7859      else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
7860	error ("automatic variable %qE cannot be %<threadprivate%>", v);
7861      else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
7862	error ("%<threadprivate%> %qE has incomplete type", v);
7863      else
7864	{
7865	  if (! DECL_THREAD_LOCAL_P (v))
7866	    {
7867	      DECL_TLS_MODEL (v) = decl_default_tls_model (v);
7868	      /* If rtl has been already set for this var, call
7869		 make_decl_rtl once again, so that encode_section_info
7870		 has a chance to look at the new decl flags.  */
7871	      if (DECL_RTL_SET_P (v))
7872		make_decl_rtl (v);
7873	    }
7874	  C_DECL_THREADPRIVATE_P (v) = 1;
7875	}
7876    }
7877
7878  c_parser_skip_to_pragma_eol (parser);
7879}
7880
7881
7882/* Parse a single source file.  */
7883
7884void
7885c_parse_file (void)
7886{
7887  /* Use local storage to begin.  If the first token is a pragma, parse it.
7888     If it is #pragma GCC pch_preprocess, then this will load a PCH file
7889     which will cause garbage collection.  */
7890  c_parser tparser;
7891
7892  memset (&tparser, 0, sizeof tparser);
7893  the_parser = &tparser;
7894
7895  if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
7896    c_parser_pragma_pch_preprocess (&tparser);
7897
7898  the_parser = GGC_NEW (c_parser);
7899  *the_parser = tparser;
7900
7901  c_parser_translation_unit (the_parser);
7902  the_parser = NULL;
7903}
7904
7905#include "gt-c-parser.h"
7906