OSDN Git Service

2002-06-21 Richard Henderson <rth@redhat.com>
[pf3gnuchains/gcc-fork.git] / gcc / c-parse.in
1 /* YACC parser for C syntax and for Objective C.  -*-c-*-
2    Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996,
3    1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
21
22 /* This file defines the grammar of C and that of Objective C.
23    ifobjc ... end ifobjc  conditionals contain code for Objective C only.
24    ifc ... end ifc  conditionals contain code for C only.
25    Sed commands in Makefile.in are used to convert this file into
26    c-parse.y and into objc-parse.y.  */
27
28 /* To whomever it may concern: I have heard that such a thing was once
29    written by AT&T, but I have never seen it.  */
30
31 ifobjc
32 %expect 31 /* shift/reduce conflicts, and 1 reduce/reduce conflict.  */
33 end ifobjc
34 ifc
35 %expect 10 /* shift/reduce conflicts, and no reduce/reduce conflicts.  */
36 end ifc
37
38 %{
39 #include "config.h"
40 #include "system.h"
41 #include "tree.h"
42 #include "input.h"
43 #include "cpplib.h"
44 #include "intl.h"
45 #include "timevar.h"
46 #include "c-pragma.h"           /* For YYDEBUG definition, and parse_in.  */
47 #include "c-tree.h"
48 #include "flags.h"
49 #include "output.h"
50 #include "toplev.h"
51 #include "ggc.h"
52
53 #ifdef MULTIBYTE_CHARS
54 #include <locale.h>
55 #endif
56
57 ifobjc
58 #include "objc-act.h"
59 end ifobjc
60
61 /* Like YYERROR but do call yyerror.  */
62 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
63
64 /* Like the default stack expander, except (1) use realloc when possible,
65    (2) impose no hard maxiumum on stack size, (3) REALLY do not use alloca.
66
67    Irritatingly, YYSTYPE is defined after this %{ %} block, so we cannot
68    give malloced_yyvs its proper type.  This is ok since all we need from
69    it is to be able to free it.  */
70
71 static short *malloced_yyss;
72 static void *malloced_yyvs;
73
74 #define yyoverflow(MSG, SS, SSSIZE, VS, VSSIZE, YYSSZ)                  \
75 do {                                                                    \
76   size_t newsize;                                                       \
77   short *newss;                                                         \
78   YYSTYPE *newvs;                                                       \
79   newsize = *(YYSSZ) *= 2;                                              \
80   if (malloced_yyss)                                                    \
81     {                                                                   \
82       newss = (short *)                                                 \
83         really_call_realloc (*(SS), newsize * sizeof (short));          \
84       newvs = (YYSTYPE *)                                               \
85         really_call_realloc (*(VS), newsize * sizeof (YYSTYPE));        \
86     }                                                                   \
87   else                                                                  \
88     {                                                                   \
89       newss = (short *) really_call_malloc (newsize * sizeof (short));  \
90       newvs = (YYSTYPE *) really_call_malloc (newsize * sizeof (YYSTYPE)); \
91       if (newss)                                                        \
92         memcpy (newss, *(SS), (SSSIZE));                                \
93       if (newvs)                                                        \
94         memcpy (newvs, *(VS), (VSSIZE));                                \
95     }                                                                   \
96   if (!newss || !newvs)                                                 \
97     {                                                                   \
98       yyerror (MSG);                                                    \
99       return 2;                                                         \
100     }                                                                   \
101   *(SS) = newss;                                                        \
102   *(VS) = newvs;                                                        \
103   malloced_yyss = newss;                                                \
104   malloced_yyvs = (void *) newvs;                                       \
105 } while (0)
106 %}
107
108 %start program
109
110 %union {long itype; tree ttype; enum tree_code code;
111         const char *filename; int lineno; }
112
113 /* All identifiers that are not reserved words
114    and are not declared typedefs in the current block */
115 %token IDENTIFIER
116
117 /* All identifiers that are declared typedefs in the current block.
118    In some contexts, they are treated just like IDENTIFIER,
119    but they can also serve as typespecs in declarations.  */
120 %token TYPENAME
121
122 /* Reserved words that specify storage class.
123    yylval contains an IDENTIFIER_NODE which indicates which one.  */
124 %token SCSPEC                   /* Storage class other than static.  */
125 %token STATIC                   /* Static storage class.  */
126
127 /* Reserved words that specify type.
128    yylval contains an IDENTIFIER_NODE which indicates which one.  */
129 %token TYPESPEC
130
131 /* Reserved words that qualify type: "const", "volatile", or "restrict".
132    yylval contains an IDENTIFIER_NODE which indicates which one.  */
133 %token TYPE_QUAL
134
135 /* Character or numeric constants.
136    yylval is the node for the constant.  */
137 %token CONSTANT
138
139 /* String constants in raw form.
140    yylval is a STRING_CST node.  */
141 %token STRING
142
143 /* "...", used for functions with variable arglists.  */
144 %token ELLIPSIS
145
146 /* the reserved words */
147 /* SCO include files test "ASM", so use something else. */
148 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
149 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
150 %token ATTRIBUTE EXTENSION LABEL
151 %token REALPART IMAGPART VA_ARG CHOOSE_EXPR TYPES_COMPATIBLE_P
152 %token PTR_VALUE PTR_BASE PTR_EXTENT
153
154 /* function name can be a string const or a var decl. */
155 %token STRING_FUNC_NAME VAR_FUNC_NAME
156
157 /* Add precedence rules to solve dangling else s/r conflict */
158 %nonassoc IF
159 %nonassoc ELSE
160
161 /* Define the operator tokens and their precedences.
162    The value is an integer because, if used, it is the tree code
163    to use in the expression made from the operator.  */
164
165 %right <code> ASSIGN '='
166 %right <code> '?' ':'
167 %left <code> OROR
168 %left <code> ANDAND
169 %left <code> '|'
170 %left <code> '^'
171 %left <code> '&'
172 %left <code> EQCOMPARE
173 %left <code> ARITHCOMPARE
174 %left <code> LSHIFT RSHIFT
175 %left <code> '+' '-'
176 %left <code> '*' '/' '%'
177 %right <code> UNARY PLUSPLUS MINUSMINUS
178 %left HYPERUNARY
179 %left <code> POINTSAT '.' '(' '['
180
181 /* The Objective-C keywords.  These are included in C and in
182    Objective C, so that the token codes are the same in both.  */
183 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
184 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
185
186 %type <code> unop
187 %type <ttype> ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
188 %type <ttype> BREAK CONTINUE RETURN GOTO ASM_KEYWORD SIZEOF TYPEOF ALIGNOF
189
190 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
191 %type <ttype> expr_no_commas cast_expr unary_expr primary STRING
192 %type <ttype> declspecs_nosc_nots_nosa_noea declspecs_nosc_nots_nosa_ea
193 %type <ttype> declspecs_nosc_nots_sa_noea declspecs_nosc_nots_sa_ea
194 %type <ttype> declspecs_nosc_ts_nosa_noea declspecs_nosc_ts_nosa_ea
195 %type <ttype> declspecs_nosc_ts_sa_noea declspecs_nosc_ts_sa_ea
196 %type <ttype> declspecs_sc_nots_nosa_noea declspecs_sc_nots_nosa_ea
197 %type <ttype> declspecs_sc_nots_sa_noea declspecs_sc_nots_sa_ea
198 %type <ttype> declspecs_sc_ts_nosa_noea declspecs_sc_ts_nosa_ea
199 %type <ttype> declspecs_sc_ts_sa_noea declspecs_sc_ts_sa_ea
200 %type <ttype> declspecs_ts declspecs_nots
201 %type <ttype> declspecs_ts_nosa declspecs_nots_nosa
202 %type <ttype> declspecs_nosc_ts declspecs_nosc_nots declspecs_nosc declspecs
203 %type <ttype> maybe_type_quals_attrs typespec_nonattr typespec_attr
204 %type <ttype> typespec_reserved_nonattr typespec_reserved_attr
205 %type <ttype> typespec_nonreserved_nonattr
206
207 %type <ttype> scspec SCSPEC STATIC TYPESPEC TYPE_QUAL maybe_type_qual
208 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
209 %type <ttype> init maybeasm
210 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
211 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
212 %type <ttype> any_word extension
213
214 %type <ttype> compstmt compstmt_start compstmt_nostart compstmt_primary_start
215 %type <ttype> do_stmt_start poplevel stmt label
216
217 %type <ttype> c99_block_start c99_block_end
218 %type <ttype> declarator
219 %type <ttype> notype_declarator after_type_declarator
220 %type <ttype> parm_declarator
221 %type <ttype> parm_declarator_starttypename parm_declarator_nostarttypename
222 %type <ttype> array_declarator
223
224 %type <ttype> structsp_attr structsp_nonattr
225 %type <ttype> component_decl_list component_decl_list2
226 %type <ttype> component_decl components components_notype component_declarator
227 %type <ttype> component_notype_declarator
228 %type <ttype> enumlist enumerator
229 %type <ttype> struct_head union_head enum_head
230 %type <ttype> typename absdcl absdcl1 absdcl1_ea absdcl1_noea
231 %type <ttype> direct_absdcl1 absdcl_maybe_attribute
232 %type <ttype> xexpr parms parm firstparm identifiers
233
234 %type <ttype> parmlist parmlist_1 parmlist_2
235 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
236 %type <ttype> identifiers_or_typenames
237
238 %type <itype> setspecs setspecs_fp
239
240 %type <filename> save_filename
241 %type <lineno> save_lineno
242 \f
243 ifobjc
244 /* the Objective-C nonterminals */
245
246 %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
247 %type <ttype> methoddecl unaryselector keywordselector selector
248 %type <ttype> keyworddecl receiver objcmessageexpr messageargs
249 %type <ttype> keywordexpr keywordarglist keywordarg
250 %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
251 %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
252 %type <ttype> objc_string non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
253
254 %type <ttype> CLASSNAME OBJECTNAME
255 end ifobjc
256 \f
257 %{
258 /* Number of statements (loosely speaking) and compound statements
259    seen so far.  */
260 static int stmt_count;
261 static int compstmt_count;
262
263 /* Input file and line number of the end of the body of last simple_if;
264    used by the stmt-rule immediately after simple_if returns.  */
265 static const char *if_stmt_file;
266 static int if_stmt_line;
267
268 /* List of types and structure classes of the current declaration.  */
269 static GTY(()) tree current_declspecs;
270 static GTY(()) tree prefix_attributes;
271
272 /* List of all the attributes applying to the identifier currently being
273    declared; includes prefix_attributes and possibly some more attributes
274    just after a comma.  */
275 static GTY(()) tree all_prefix_attributes;
276
277 /* Stack of saved values of current_declspecs, prefix_attributes and
278    all_prefix_attributes.  */
279 static GTY(()) tree declspec_stack;
280
281 /* PUSH_DECLSPEC_STACK is called from setspecs; POP_DECLSPEC_STACK
282    should be called from the productions making use of setspecs.  */
283 #define PUSH_DECLSPEC_STACK                                              \
284   do {                                                                   \
285     declspec_stack = tree_cons (build_tree_list (prefix_attributes,      \
286                                                  all_prefix_attributes), \
287                                 current_declspecs,                       \
288                                 declspec_stack);                         \
289   } while (0)
290
291 #define POP_DECLSPEC_STACK                                              \
292   do {                                                                  \
293     current_declspecs = TREE_VALUE (declspec_stack);                    \
294     prefix_attributes = TREE_PURPOSE (TREE_PURPOSE (declspec_stack));   \
295     all_prefix_attributes = TREE_VALUE (TREE_PURPOSE (declspec_stack)); \
296     declspec_stack = TREE_CHAIN (declspec_stack);                       \
297   } while (0)
298
299 /* For __extension__, save/restore the warning flags which are
300    controlled by __extension__.  */
301 #define SAVE_EXT_FLAGS()                        \
302         size_int (pedantic                      \
303                   | (warn_pointer_arith << 1)   \
304                   | (warn_traditional << 2)     \
305                   | (flag_iso << 3))
306
307 #define RESTORE_EXT_FLAGS(tval)                 \
308   do {                                          \
309     int val = tree_low_cst (tval, 0);           \
310     pedantic = val & 1;                         \
311     warn_pointer_arith = (val >> 1) & 1;        \
312     warn_traditional = (val >> 2) & 1;          \
313     flag_iso = (val >> 3) & 1;                  \
314   } while (0)
315
316 ifobjc
317 /* Objective-C specific parser/lexer information */
318
319 static enum tree_code objc_inherit_code;
320 static int objc_pq_context = 0, objc_public_flag = 0;
321
322 /* The following flag is needed to contextualize ObjC lexical analysis.
323    In some cases (e.g., 'int NSObject;'), it is undesirable to bind
324    an identifier to an ObjC class, even if a class with that name
325    exists.  */
326 static int objc_need_raw_identifier;
327 #define OBJC_NEED_RAW_IDENTIFIER(VAL)   objc_need_raw_identifier = VAL
328 end ifobjc
329
330 ifc
331 #define OBJC_NEED_RAW_IDENTIFIER(VAL)   /* nothing */
332 end ifc
333
334 /* Tell yyparse how to print a token's value, if yydebug is set.  */
335
336 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
337
338 static void yyprint       PARAMS ((FILE *, int, YYSTYPE));
339 static void yyerror       PARAMS ((const char *));
340 static int yylexname      PARAMS ((void));
341 static int yylexstring    PARAMS ((void));
342 static inline int _yylex  PARAMS ((void));
343 static int  yylex         PARAMS ((void));
344 static void init_reswords PARAMS ((void));
345
346   /* Initialisation routine for this file.  */
347 void
348 c_parse_init ()
349 {
350   init_reswords ();
351 }
352
353 %}
354 \f
355 %%
356 program: /* empty */
357                 { if (pedantic)
358                     pedwarn ("ISO C forbids an empty source file");
359                   finish_file ();
360                 }
361         | extdefs
362                 {
363                   /* In case there were missing closebraces,
364                      get us back to the global binding level.  */
365                   while (! global_bindings_p ())
366                     poplevel (0, 0, 0);
367                   /* __FUNCTION__ is defined at file scope ("").  This
368                      call may not be necessary as my tests indicate it
369                      still works without it.  */
370                   finish_fname_decls ();
371                   finish_file ();
372                 }
373         ;
374
375 /* the reason for the strange actions in this rule
376  is so that notype_initdecls when reached via datadef
377  can find a valid list of type and sc specs in $0. */
378
379 extdefs:
380         {$<ttype>$ = NULL_TREE; } extdef
381         | extdefs {$<ttype>$ = NULL_TREE; ggc_collect(); } extdef
382         ;
383
384 extdef:
385         fndef
386         | datadef
387 ifobjc
388         | objcdef
389 end ifobjc
390         | ASM_KEYWORD '(' expr ')' ';'
391                 { STRIP_NOPS ($3);
392                   if ((TREE_CODE ($3) == ADDR_EXPR
393                        && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
394                       || TREE_CODE ($3) == STRING_CST)
395                     assemble_asm ($3);
396                   else
397                     error ("argument of `asm' is not a constant string"); }
398         | extension extdef
399                 { RESTORE_EXT_FLAGS ($1); }
400         ;
401
402 datadef:
403           setspecs notype_initdecls ';'
404                 { if (pedantic)
405                     error ("ISO C forbids data definition with no type or storage class");
406                   else
407                     warning ("data definition has no type or storage class");
408
409                   POP_DECLSPEC_STACK; }
410         | declspecs_nots setspecs notype_initdecls ';'
411                 { POP_DECLSPEC_STACK; }
412         | declspecs_ts setspecs initdecls ';'
413                 { POP_DECLSPEC_STACK; }
414         | declspecs ';'
415           { shadow_tag ($1); }
416         | error ';'
417         | error '}'
418         | ';'
419                 { if (pedantic)
420                     pedwarn ("ISO C does not allow extra `;' outside of a function"); }
421         ;
422 \f
423 fndef:
424           declspecs_ts setspecs declarator
425                 { if (! start_function (current_declspecs, $3,
426                                         all_prefix_attributes))
427                     YYERROR1;
428                 }
429           old_style_parm_decls
430                 { store_parm_decls (); }
431           save_filename save_lineno compstmt_or_error
432                 { DECL_SOURCE_FILE (current_function_decl) = $7;
433                   DECL_SOURCE_LINE (current_function_decl) = $8;
434                   finish_function (0, 1);
435                   POP_DECLSPEC_STACK; }
436         | declspecs_ts setspecs declarator error
437                 { POP_DECLSPEC_STACK; }
438         | declspecs_nots setspecs notype_declarator
439                 { if (! start_function (current_declspecs, $3,
440                                         all_prefix_attributes))
441                     YYERROR1;
442                 }
443           old_style_parm_decls
444                 { store_parm_decls (); }
445           save_filename save_lineno compstmt_or_error
446                 { DECL_SOURCE_FILE (current_function_decl) = $7;
447                   DECL_SOURCE_LINE (current_function_decl) = $8;
448                   finish_function (0, 1);
449                   POP_DECLSPEC_STACK; }
450         | declspecs_nots setspecs notype_declarator error
451                 { POP_DECLSPEC_STACK; }
452         | setspecs notype_declarator
453                 { if (! start_function (NULL_TREE, $2,
454                                         all_prefix_attributes))
455                     YYERROR1;
456                 }
457           old_style_parm_decls
458                 { store_parm_decls (); }
459           save_filename save_lineno compstmt_or_error
460                 { DECL_SOURCE_FILE (current_function_decl) = $6;
461                   DECL_SOURCE_LINE (current_function_decl) = $7;
462                   finish_function (0, 1);
463                   POP_DECLSPEC_STACK; }
464         | setspecs notype_declarator error
465                 { POP_DECLSPEC_STACK; }
466         ;
467
468 identifier:
469         IDENTIFIER
470         | TYPENAME
471 ifobjc
472         | OBJECTNAME
473         | CLASSNAME
474 end ifobjc
475         ;
476
477 unop:     '&'
478                 { $$ = ADDR_EXPR; }
479         | '-'
480                 { $$ = NEGATE_EXPR; }
481         | '+'
482                 { $$ = CONVERT_EXPR;
483 ifc
484   if (warn_traditional && !in_system_header)
485     warning ("traditional C rejects the unary plus operator");
486 end ifc
487                 }
488         | PLUSPLUS
489                 { $$ = PREINCREMENT_EXPR; }
490         | MINUSMINUS
491                 { $$ = PREDECREMENT_EXPR; }
492         | '~'
493                 { $$ = BIT_NOT_EXPR; }
494         | '!'
495                 { $$ = TRUTH_NOT_EXPR; }
496         ;
497
498 expr:   nonnull_exprlist
499                 { $$ = build_compound_expr ($1); }
500         ;
501
502 exprlist:
503           /* empty */
504                 { $$ = NULL_TREE; }
505         | nonnull_exprlist
506         ;
507
508 nonnull_exprlist:
509         expr_no_commas
510                 { $$ = build_tree_list (NULL_TREE, $1); }
511         | nonnull_exprlist ',' expr_no_commas
512                 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
513         ;
514
515 unary_expr:
516         primary
517         | '*' cast_expr   %prec UNARY
518                 { $$ = build_indirect_ref ($2, "unary *"); }
519         /* __extension__ turns off -pedantic for following primary.  */
520         | extension cast_expr     %prec UNARY
521                 { $$ = $2;
522                   RESTORE_EXT_FLAGS ($1); }
523         | unop cast_expr  %prec UNARY
524                 { $$ = build_unary_op ($1, $2, 0);
525                   overflow_warning ($$); }
526         /* Refer to the address of a label as a pointer.  */
527         | ANDAND identifier
528                 { $$ = finish_label_address_expr ($2); }
529 /* This seems to be impossible on some machines, so let's turn it off.
530    You can use __builtin_next_arg to find the anonymous stack args.
531         | '&' ELLIPSIS
532                 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
533                   $$ = error_mark_node;
534                   if (TREE_VALUE (tree_last (types)) == void_type_node)
535                     error ("`&...' used in function with fixed number of arguments");
536                   else
537                     {
538                       if (pedantic)
539                         pedwarn ("ISO C forbids `&...'");
540                       $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
541                       $$ = build_unary_op (ADDR_EXPR, $$, 0);
542                     } }
543 */
544         | sizeof unary_expr  %prec UNARY
545                 { skip_evaluation--;
546                   if (TREE_CODE ($2) == COMPONENT_REF
547                       && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
548                     error ("`sizeof' applied to a bit-field");
549                   $$ = c_sizeof (TREE_TYPE ($2)); }
550         | sizeof '(' typename ')'  %prec HYPERUNARY
551                 { skip_evaluation--;
552                   $$ = c_sizeof (groktypename ($3)); }
553         | alignof unary_expr  %prec UNARY
554                 { skip_evaluation--;
555                   $$ = c_alignof_expr ($2); }
556         | alignof '(' typename ')'  %prec HYPERUNARY
557                 { skip_evaluation--;
558                   $$ = c_alignof (groktypename ($3)); }
559         | REALPART cast_expr %prec UNARY
560                 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
561         | IMAGPART cast_expr %prec UNARY
562                 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
563         ;
564
565 sizeof:
566         SIZEOF { skip_evaluation++; }
567         ;
568
569 alignof:
570         ALIGNOF { skip_evaluation++; }
571         ;
572
573 cast_expr:
574         unary_expr
575         | '(' typename ')' cast_expr  %prec UNARY
576                 { $$ = c_cast_expr ($2, $4); }
577         ;
578
579 expr_no_commas:
580           cast_expr
581         | expr_no_commas '+' expr_no_commas
582                 { $$ = parser_build_binary_op ($2, $1, $3); }
583         | expr_no_commas '-' expr_no_commas
584                 { $$ = parser_build_binary_op ($2, $1, $3); }
585         | expr_no_commas '*' expr_no_commas
586                 { $$ = parser_build_binary_op ($2, $1, $3); }
587         | expr_no_commas '/' expr_no_commas
588                 { $$ = parser_build_binary_op ($2, $1, $3); }
589         | expr_no_commas '%' expr_no_commas
590                 { $$ = parser_build_binary_op ($2, $1, $3); }
591         | expr_no_commas LSHIFT expr_no_commas
592                 { $$ = parser_build_binary_op ($2, $1, $3); }
593         | expr_no_commas RSHIFT expr_no_commas
594                 { $$ = parser_build_binary_op ($2, $1, $3); }
595         | expr_no_commas ARITHCOMPARE expr_no_commas
596                 { $$ = parser_build_binary_op ($2, $1, $3); }
597         | expr_no_commas EQCOMPARE expr_no_commas
598                 { $$ = parser_build_binary_op ($2, $1, $3); }
599         | expr_no_commas '&' expr_no_commas
600                 { $$ = parser_build_binary_op ($2, $1, $3); }
601         | expr_no_commas '|' expr_no_commas
602                 { $$ = parser_build_binary_op ($2, $1, $3); }
603         | expr_no_commas '^' expr_no_commas
604                 { $$ = parser_build_binary_op ($2, $1, $3); }
605         | expr_no_commas ANDAND
606                 { $1 = c_common_truthvalue_conversion
607                     (default_conversion ($1));
608                   skip_evaluation += $1 == boolean_false_node; }
609           expr_no_commas
610                 { skip_evaluation -= $1 == boolean_false_node;
611                   $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
612         | expr_no_commas OROR
613                 { $1 = c_common_truthvalue_conversion
614                     (default_conversion ($1));
615                   skip_evaluation += $1 == boolean_true_node; }
616           expr_no_commas
617                 { skip_evaluation -= $1 == boolean_true_node;
618                   $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
619         | expr_no_commas '?'
620                 { $1 = c_common_truthvalue_conversion
621                     (default_conversion ($1));
622                   skip_evaluation += $1 == boolean_false_node; }
623           expr ':'
624                 { skip_evaluation += (($1 == boolean_true_node)
625                                       - ($1 == boolean_false_node)); }
626           expr_no_commas
627                 { skip_evaluation -= $1 == boolean_true_node;
628                   $$ = build_conditional_expr ($1, $4, $7); }
629         | expr_no_commas '?'
630                 { if (pedantic)
631                     pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
632                   /* Make sure first operand is calculated only once.  */
633                   $<ttype>2 = save_expr ($1);
634                   $1 = c_common_truthvalue_conversion
635                     (default_conversion ($<ttype>2));
636                   skip_evaluation += $1 == boolean_true_node; }
637           ':' expr_no_commas
638                 { skip_evaluation -= $1 == boolean_true_node;
639                   $$ = build_conditional_expr ($1, $<ttype>2, $5); }
640         | expr_no_commas '=' expr_no_commas
641                 { char class;
642                   $$ = build_modify_expr ($1, NOP_EXPR, $3);
643                   class = TREE_CODE_CLASS (TREE_CODE ($$));
644                   if (IS_EXPR_CODE_CLASS (class))
645                     C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR);
646                 }
647         | expr_no_commas ASSIGN expr_no_commas
648                 { char class;
649                   $$ = build_modify_expr ($1, $2, $3);
650                   /* This inhibits warnings in
651                      c_common_truthvalue_conversion.  */
652                   class = TREE_CODE_CLASS (TREE_CODE ($$));
653                   if (IS_EXPR_CODE_CLASS (class))
654                     C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK);
655                 }
656         ;
657
658 primary:
659         IDENTIFIER
660                 {
661                   if (yychar == YYEMPTY)
662                     yychar = YYLEX;
663                   $$ = build_external_ref ($1, yychar == '(');
664                 }
665         | CONSTANT
666         | STRING
667                 { $$ = fix_string_type ($$); }
668         | VAR_FUNC_NAME
669                 { $$ = fname_decl (C_RID_CODE ($$), $$); }
670         | '(' typename ')' '{'
671                 { start_init (NULL_TREE, NULL, 0);
672                   $2 = groktypename ($2);
673                   really_start_incremental_init ($2); }
674           initlist_maybe_comma '}'  %prec UNARY
675                 { tree constructor = pop_init_level (0);
676                   tree type = $2;
677                   finish_init ();
678
679                   if (pedantic && ! flag_isoc99)
680                     pedwarn ("ISO C89 forbids compound literals");
681                   $$ = build_compound_literal (type, constructor);
682                 }
683         | '(' expr ')'
684                 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
685                   if (IS_EXPR_CODE_CLASS (class))
686                     C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
687                   $$ = $2; }
688         | '(' error ')'
689                 { $$ = error_mark_node; }
690         | compstmt_primary_start compstmt_nostart ')'
691                  { tree saved_last_tree;
692
693                    if (pedantic)
694                      pedwarn ("ISO C forbids braced-groups within expressions");
695                   pop_label_level ();
696
697                   saved_last_tree = COMPOUND_BODY ($1);
698                   RECHAIN_STMTS ($1, COMPOUND_BODY ($1));
699                   last_tree = saved_last_tree;
700                   TREE_CHAIN (last_tree) = NULL_TREE;
701                   if (!last_expr_type)
702                     last_expr_type = void_type_node;
703                   $$ = build1 (STMT_EXPR, last_expr_type, $1);
704                   TREE_SIDE_EFFECTS ($$) = 1;
705                 }
706         | compstmt_primary_start error ')'
707                 {
708                   pop_label_level ();
709                   last_tree = COMPOUND_BODY ($1);
710                   TREE_CHAIN (last_tree) = NULL_TREE;
711                   $$ = error_mark_node;
712                 }
713         | primary '(' exprlist ')'   %prec '.'
714                 { $$ = build_function_call ($1, $3); }
715         | VA_ARG '(' expr_no_commas ',' typename ')'
716                 { $$ = build_va_arg ($3, groktypename ($5)); }
717
718       | CHOOSE_EXPR '(' expr_no_commas ',' expr_no_commas ',' expr_no_commas ')'
719                 {
720                   tree c;
721
722                   c = fold ($3);
723                   STRIP_NOPS (c);
724                   if (TREE_CODE (c) != INTEGER_CST)
725                     error ("first argument to __builtin_choose_expr not a constant");
726                   $$ = integer_zerop (c) ? $7 : $5;
727                 }
728       | TYPES_COMPATIBLE_P '(' typename ',' typename ')'
729                 {
730                   tree e1, e2;
731
732                   e1 = TYPE_MAIN_VARIANT (groktypename ($3));
733                   e2 = TYPE_MAIN_VARIANT (groktypename ($5));
734
735                   $$ = comptypes (e1, e2)
736                     ? build_int_2 (1, 0) : build_int_2 (0, 0);
737                 }
738         | primary '[' expr ']'   %prec '.'
739                 { $$ = build_array_ref ($1, $3); }
740         | primary '.' identifier
741                 {
742 ifobjc
743                     if (!is_public ($1, $3))
744                       $$ = error_mark_node;
745                     else
746 end ifobjc
747                       $$ = build_component_ref ($1, $3);
748                 }
749         | primary POINTSAT identifier
750                 {
751                   tree expr = build_indirect_ref ($1, "->");
752
753 ifobjc
754                       if (!is_public (expr, $3))
755                         $$ = error_mark_node;
756                       else
757 end ifobjc
758                         $$ = build_component_ref (expr, $3);
759                 }
760         | primary PLUSPLUS
761                 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
762         | primary MINUSMINUS
763                 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
764 ifobjc
765         | objcmessageexpr
766                 { $$ = build_message_expr ($1); }
767         | objcselectorexpr
768                 { $$ = build_selector_expr ($1); }
769         | objcprotocolexpr
770                 { $$ = build_protocol_expr ($1); }
771         | objcencodeexpr
772                 { $$ = build_encode_expr ($1); }
773         | objc_string
774                 { $$ = build_objc_string_object ($1); }
775 end ifobjc
776         ;
777
778 ifobjc
779 /* Produces an STRING_CST with perhaps more STRING_CSTs chained
780    onto it, which is to be read as an ObjC string object.  */
781 objc_string:
782           '@' STRING
783                 { $$ = $2; }
784         | objc_string '@' STRING
785                 { $$ = chainon ($1, $3); }
786         ;
787 end ifobjc
788
789 old_style_parm_decls:
790         /* empty */
791         | datadecls
792         | datadecls ELLIPSIS
793                 /* ... is used here to indicate a varargs function.  */
794                 { c_mark_varargs ();
795                   if (pedantic)
796                     pedwarn ("ISO C does not permit use of `varargs.h'"); }
797         ;
798
799 /* The following are analogous to lineno_decl, decls and decl
800    except that they do not allow nested functions.
801    They are used for old-style parm decls.  */
802 lineno_datadecl:
803           save_filename save_lineno datadecl
804                 { }
805         ;
806
807 datadecls:
808         lineno_datadecl
809         | errstmt
810         | datadecls lineno_datadecl
811         | lineno_datadecl errstmt
812         ;
813
814 /* We don't allow prefix attributes here because they cause reduce/reduce
815    conflicts: we can't know whether we're parsing a function decl with
816    attribute suffix, or function defn with attribute prefix on first old
817    style parm.  */
818 datadecl:
819         declspecs_ts_nosa setspecs initdecls ';'
820                 { POP_DECLSPEC_STACK; }
821         | declspecs_nots_nosa setspecs notype_initdecls ';'
822                 { POP_DECLSPEC_STACK; }
823         | declspecs_ts_nosa ';'
824                 { shadow_tag_warned ($1, 1);
825                   pedwarn ("empty declaration"); }
826         | declspecs_nots_nosa ';'
827                 { pedwarn ("empty declaration"); }
828         ;
829
830 /* This combination which saves a lineno before a decl
831    is the normal thing to use, rather than decl itself.
832    This is to avoid shift/reduce conflicts in contexts
833    where statement labels are allowed.  */
834 lineno_decl:
835           save_filename save_lineno decl
836                 { }
837         ;
838
839 /* records the type and storage class specs to use for processing
840    the declarators that follow.
841    Maintains a stack of outer-level values of current_declspecs,
842    for the sake of parm declarations nested in function declarators.  */
843 setspecs: /* empty */
844                 { pending_xref_error ();
845                   PUSH_DECLSPEC_STACK;
846                   split_specs_attrs ($<ttype>0,
847                                      &current_declspecs, &prefix_attributes);
848                   all_prefix_attributes = prefix_attributes; }
849         ;
850
851 /* Possibly attributes after a comma, which should reset all_prefix_attributes
852    to prefix_attributes with these ones chained on the front.  */
853 maybe_resetattrs:
854           maybe_attribute
855                 { all_prefix_attributes = chainon ($1, prefix_attributes); }
856         ;
857
858 decl:
859         declspecs_ts setspecs initdecls ';'
860                 { POP_DECLSPEC_STACK; }
861         | declspecs_nots setspecs notype_initdecls ';'
862                 { POP_DECLSPEC_STACK; }
863         | declspecs_ts setspecs nested_function
864                 { POP_DECLSPEC_STACK; }
865         | declspecs_nots setspecs notype_nested_function
866                 { POP_DECLSPEC_STACK; }
867         | declspecs ';'
868                 { shadow_tag ($1); }
869         | extension decl
870                 { RESTORE_EXT_FLAGS ($1); }
871         ;
872
873 /* A list of declaration specifiers.  These are:
874
875    - Storage class specifiers (scspec), which for GCC currently includes
876    function specifiers ("inline").
877
878    - Type specifiers (typespec_*).
879
880    - Type qualifiers (TYPE_QUAL).
881
882    - Attribute specifier lists (attributes).
883
884    These are stored as a TREE_LIST; the head of the list is the last
885    item in the specifier list.  Each entry in the list has either a
886    TREE_PURPOSE that is an attribute specifier list, or a TREE_VALUE that
887    is a single other specifier or qualifier; and a TREE_CHAIN that is the
888    rest of the list.  TREE_STATIC is set on the list if something other
889    than a storage class specifier or attribute has been seen; this is used
890    to warn for the obsolescent usage of storage class specifiers other than
891    at the start of the list.  (Doing this properly would require function
892    specifiers to be handled separately from storage class specifiers.)
893
894    The various cases below are classified according to:
895
896    (a) Whether a storage class specifier is included or not; some
897    places in the grammar disallow storage class specifiers (_sc or _nosc).
898
899    (b) Whether a type specifier has been seen; after a type specifier,
900    a typedef name is an identifier to redeclare (_ts or _nots).
901
902    (c) Whether the list starts with an attribute; in certain places,
903    the grammar requires specifiers that don't start with an attribute
904    (_sa or _nosa).
905
906    (d) Whether the list ends with an attribute (or a specifier such that
907    any following attribute would have been parsed as part of that specifier);
908    this avoids shift-reduce conflicts in the parsing of attributes
909    (_ea or _noea).
910
911    TODO:
912
913    (i) Distinguish between function specifiers and storage class specifiers,
914    at least for the purpose of warnings about obsolescent usage.
915
916    (ii) Halve the number of productions here by eliminating the _sc/_nosc
917    distinction and instead checking where required that storage class
918    specifiers aren't present.  */
919
920 /* Declspecs which contain at least one type specifier or typedef name.
921    (Just `const' or `volatile' is not enough.)
922    A typedef'd name following these is taken as a name to be declared.
923    Declspecs have a non-NULL TREE_VALUE, attributes do not.  */
924
925 declspecs_nosc_nots_nosa_noea:
926           TYPE_QUAL
927                 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
928                   TREE_STATIC ($$) = 1; }
929         | declspecs_nosc_nots_nosa_noea TYPE_QUAL
930                 { $$ = tree_cons (NULL_TREE, $2, $1);
931                   TREE_STATIC ($$) = 1; }
932         | declspecs_nosc_nots_nosa_ea TYPE_QUAL
933                 { $$ = tree_cons (NULL_TREE, $2, $1);
934                   TREE_STATIC ($$) = 1; }
935         ;
936
937 declspecs_nosc_nots_nosa_ea:
938           declspecs_nosc_nots_nosa_noea attributes
939                 { $$ = tree_cons ($2, NULL_TREE, $1);
940                   TREE_STATIC ($$) = TREE_STATIC ($1); }
941         ;
942
943 declspecs_nosc_nots_sa_noea:
944           declspecs_nosc_nots_sa_noea TYPE_QUAL
945                 { $$ = tree_cons (NULL_TREE, $2, $1);
946                   TREE_STATIC ($$) = 1; }
947         | declspecs_nosc_nots_sa_ea TYPE_QUAL
948                 { $$ = tree_cons (NULL_TREE, $2, $1);
949                   TREE_STATIC ($$) = 1; }
950         ;
951
952 declspecs_nosc_nots_sa_ea:
953           attributes
954                 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE);
955                   TREE_STATIC ($$) = 0; }
956         | declspecs_nosc_nots_sa_noea attributes
957                 { $$ = tree_cons ($2, NULL_TREE, $1);
958                   TREE_STATIC ($$) = TREE_STATIC ($1); }
959         ;
960
961 declspecs_nosc_ts_nosa_noea:
962           typespec_nonattr
963                 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
964                   TREE_STATIC ($$) = 1; }
965         | declspecs_nosc_ts_nosa_noea TYPE_QUAL
966                 { $$ = tree_cons (NULL_TREE, $2, $1);
967                   TREE_STATIC ($$) = 1; }
968         | declspecs_nosc_ts_nosa_ea TYPE_QUAL
969                 { $$ = tree_cons (NULL_TREE, $2, $1);
970                   TREE_STATIC ($$) = 1; }
971         | declspecs_nosc_ts_nosa_noea typespec_reserved_nonattr
972                 { $$ = tree_cons (NULL_TREE, $2, $1);
973                   TREE_STATIC ($$) = 1; }
974         | declspecs_nosc_ts_nosa_ea typespec_reserved_nonattr
975                 { $$ = tree_cons (NULL_TREE, $2, $1);
976                   TREE_STATIC ($$) = 1; }
977         | declspecs_nosc_nots_nosa_noea typespec_nonattr
978                 { $$ = tree_cons (NULL_TREE, $2, $1);
979                   TREE_STATIC ($$) = 1; }
980         | declspecs_nosc_nots_nosa_ea typespec_nonattr
981                 { $$ = tree_cons (NULL_TREE, $2, $1);
982                   TREE_STATIC ($$) = 1; }
983         ;
984
985 declspecs_nosc_ts_nosa_ea:
986           typespec_attr
987                 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
988                   TREE_STATIC ($$) = 1; }
989         | declspecs_nosc_ts_nosa_noea attributes
990                 { $$ = tree_cons ($2, NULL_TREE, $1);
991                   TREE_STATIC ($$) = TREE_STATIC ($1); }
992         | declspecs_nosc_ts_nosa_noea typespec_reserved_attr
993                 { $$ = tree_cons (NULL_TREE, $2, $1);
994                   TREE_STATIC ($$) = 1; }
995         | declspecs_nosc_ts_nosa_ea typespec_reserved_attr
996                 { $$ = tree_cons (NULL_TREE, $2, $1);
997                   TREE_STATIC ($$) = 1; }
998         | declspecs_nosc_nots_nosa_noea typespec_attr
999                 { $$ = tree_cons (NULL_TREE, $2, $1);
1000                   TREE_STATIC ($$) = 1; }
1001         | declspecs_nosc_nots_nosa_ea typespec_attr
1002                 { $$ = tree_cons (NULL_TREE, $2, $1);
1003                   TREE_STATIC ($$) = 1; }
1004         ;
1005
1006 declspecs_nosc_ts_sa_noea:
1007           declspecs_nosc_ts_sa_noea TYPE_QUAL
1008                 { $$ = tree_cons (NULL_TREE, $2, $1);
1009                   TREE_STATIC ($$) = 1; }
1010         | declspecs_nosc_ts_sa_ea TYPE_QUAL
1011                 { $$ = tree_cons (NULL_TREE, $2, $1);
1012                   TREE_STATIC ($$) = 1; }
1013         | declspecs_nosc_ts_sa_noea typespec_reserved_nonattr
1014                 { $$ = tree_cons (NULL_TREE, $2, $1);
1015                   TREE_STATIC ($$) = 1; }
1016         | declspecs_nosc_ts_sa_ea typespec_reserved_nonattr
1017                 { $$ = tree_cons (NULL_TREE, $2, $1);
1018                   TREE_STATIC ($$) = 1; }
1019         | declspecs_nosc_nots_sa_noea typespec_nonattr
1020                 { $$ = tree_cons (NULL_TREE, $2, $1);
1021                   TREE_STATIC ($$) = 1; }
1022         | declspecs_nosc_nots_sa_ea typespec_nonattr
1023                 { $$ = tree_cons (NULL_TREE, $2, $1);
1024                   TREE_STATIC ($$) = 1; }
1025         ;
1026
1027 declspecs_nosc_ts_sa_ea:
1028           declspecs_nosc_ts_sa_noea attributes
1029                 { $$ = tree_cons ($2, NULL_TREE, $1);
1030                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1031         | declspecs_nosc_ts_sa_noea typespec_reserved_attr
1032                 { $$ = tree_cons (NULL_TREE, $2, $1);
1033                   TREE_STATIC ($$) = 1; }
1034         | declspecs_nosc_ts_sa_ea typespec_reserved_attr
1035                 { $$ = tree_cons (NULL_TREE, $2, $1);
1036                   TREE_STATIC ($$) = 1; }
1037         | declspecs_nosc_nots_sa_noea typespec_attr
1038                 { $$ = tree_cons (NULL_TREE, $2, $1);
1039                   TREE_STATIC ($$) = 1; }
1040         | declspecs_nosc_nots_sa_ea typespec_attr
1041                 { $$ = tree_cons (NULL_TREE, $2, $1);
1042                   TREE_STATIC ($$) = 1; }
1043         ;
1044
1045 declspecs_sc_nots_nosa_noea:
1046           scspec
1047                 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
1048                   TREE_STATIC ($$) = 0; }
1049         | declspecs_sc_nots_nosa_noea TYPE_QUAL
1050                 { $$ = tree_cons (NULL_TREE, $2, $1);
1051                   TREE_STATIC ($$) = 1; }
1052         | declspecs_sc_nots_nosa_ea TYPE_QUAL
1053                 { $$ = tree_cons (NULL_TREE, $2, $1);
1054                   TREE_STATIC ($$) = 1; }
1055         | declspecs_nosc_nots_nosa_noea scspec
1056                 { if (extra_warnings && TREE_STATIC ($1))
1057                     warning ("`%s' is not at beginning of declaration",
1058                              IDENTIFIER_POINTER ($2));
1059                   $$ = tree_cons (NULL_TREE, $2, $1);
1060                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1061         | declspecs_nosc_nots_nosa_ea scspec
1062                 { if (extra_warnings && TREE_STATIC ($1))
1063                     warning ("`%s' is not at beginning of declaration",
1064                              IDENTIFIER_POINTER ($2));
1065                   $$ = tree_cons (NULL_TREE, $2, $1);
1066                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1067         | declspecs_sc_nots_nosa_noea scspec
1068                 { if (extra_warnings && TREE_STATIC ($1))
1069                     warning ("`%s' is not at beginning of declaration",
1070                              IDENTIFIER_POINTER ($2));
1071                   $$ = tree_cons (NULL_TREE, $2, $1);
1072                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1073         | declspecs_sc_nots_nosa_ea scspec
1074                 { if (extra_warnings && TREE_STATIC ($1))
1075                     warning ("`%s' is not at beginning of declaration",
1076                              IDENTIFIER_POINTER ($2));
1077                   $$ = tree_cons (NULL_TREE, $2, $1);
1078                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1079         ;
1080
1081 declspecs_sc_nots_nosa_ea:
1082           declspecs_sc_nots_nosa_noea attributes
1083                 { $$ = tree_cons ($2, NULL_TREE, $1);
1084                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1085         ;
1086
1087 declspecs_sc_nots_sa_noea:
1088           declspecs_sc_nots_sa_noea TYPE_QUAL
1089                 { $$ = tree_cons (NULL_TREE, $2, $1);
1090                   TREE_STATIC ($$) = 1; }
1091         | declspecs_sc_nots_sa_ea TYPE_QUAL
1092                 { $$ = tree_cons (NULL_TREE, $2, $1);
1093                   TREE_STATIC ($$) = 1; }
1094         | declspecs_nosc_nots_sa_noea scspec
1095                 { if (extra_warnings && TREE_STATIC ($1))
1096                     warning ("`%s' is not at beginning of declaration",
1097                              IDENTIFIER_POINTER ($2));
1098                   $$ = tree_cons (NULL_TREE, $2, $1);
1099                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1100         | declspecs_nosc_nots_sa_ea scspec
1101                 { if (extra_warnings && TREE_STATIC ($1))
1102                     warning ("`%s' is not at beginning of declaration",
1103                              IDENTIFIER_POINTER ($2));
1104                   $$ = tree_cons (NULL_TREE, $2, $1);
1105                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1106         | declspecs_sc_nots_sa_noea scspec
1107                 { if (extra_warnings && TREE_STATIC ($1))
1108                     warning ("`%s' is not at beginning of declaration",
1109                              IDENTIFIER_POINTER ($2));
1110                   $$ = tree_cons (NULL_TREE, $2, $1);
1111                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1112         | declspecs_sc_nots_sa_ea scspec
1113                 { if (extra_warnings && TREE_STATIC ($1))
1114                     warning ("`%s' is not at beginning of declaration",
1115                              IDENTIFIER_POINTER ($2));
1116                   $$ = tree_cons (NULL_TREE, $2, $1);
1117                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1118         ;
1119
1120 declspecs_sc_nots_sa_ea:
1121           declspecs_sc_nots_sa_noea attributes
1122                 { $$ = tree_cons ($2, NULL_TREE, $1);
1123                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1124         ;
1125
1126 declspecs_sc_ts_nosa_noea:
1127           declspecs_sc_ts_nosa_noea TYPE_QUAL
1128                 { $$ = tree_cons (NULL_TREE, $2, $1);
1129                   TREE_STATIC ($$) = 1; }
1130         | declspecs_sc_ts_nosa_ea TYPE_QUAL
1131                 { $$ = tree_cons (NULL_TREE, $2, $1);
1132                   TREE_STATIC ($$) = 1; }
1133         | declspecs_sc_ts_nosa_noea typespec_reserved_nonattr
1134                 { $$ = tree_cons (NULL_TREE, $2, $1);
1135                   TREE_STATIC ($$) = 1; }
1136         | declspecs_sc_ts_nosa_ea typespec_reserved_nonattr
1137                 { $$ = tree_cons (NULL_TREE, $2, $1);
1138                   TREE_STATIC ($$) = 1; }
1139         | declspecs_sc_nots_nosa_noea typespec_nonattr
1140                 { $$ = tree_cons (NULL_TREE, $2, $1);
1141                   TREE_STATIC ($$) = 1; }
1142         | declspecs_sc_nots_nosa_ea typespec_nonattr
1143                 { $$ = tree_cons (NULL_TREE, $2, $1);
1144                   TREE_STATIC ($$) = 1; }
1145         | declspecs_nosc_ts_nosa_noea scspec
1146                 { if (extra_warnings && TREE_STATIC ($1))
1147                     warning ("`%s' is not at beginning of declaration",
1148                              IDENTIFIER_POINTER ($2));
1149                   $$ = tree_cons (NULL_TREE, $2, $1);
1150                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1151         | declspecs_nosc_ts_nosa_ea scspec
1152                 { if (extra_warnings && TREE_STATIC ($1))
1153                     warning ("`%s' is not at beginning of declaration",
1154                              IDENTIFIER_POINTER ($2));
1155                   $$ = tree_cons (NULL_TREE, $2, $1);
1156                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1157         | declspecs_sc_ts_nosa_noea scspec
1158                 { if (extra_warnings && TREE_STATIC ($1))
1159                     warning ("`%s' is not at beginning of declaration",
1160                              IDENTIFIER_POINTER ($2));
1161                   $$ = tree_cons (NULL_TREE, $2, $1);
1162                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1163         | declspecs_sc_ts_nosa_ea scspec
1164                 { if (extra_warnings && TREE_STATIC ($1))
1165                     warning ("`%s' is not at beginning of declaration",
1166                              IDENTIFIER_POINTER ($2));
1167                   $$ = tree_cons (NULL_TREE, $2, $1);
1168                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1169         ;
1170
1171 declspecs_sc_ts_nosa_ea:
1172           declspecs_sc_ts_nosa_noea attributes
1173                 { $$ = tree_cons ($2, NULL_TREE, $1);
1174                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1175         | declspecs_sc_ts_nosa_noea typespec_reserved_attr
1176                 { $$ = tree_cons (NULL_TREE, $2, $1);
1177                   TREE_STATIC ($$) = 1; }
1178         | declspecs_sc_ts_nosa_ea typespec_reserved_attr
1179                 { $$ = tree_cons (NULL_TREE, $2, $1);
1180                   TREE_STATIC ($$) = 1; }
1181         | declspecs_sc_nots_nosa_noea typespec_attr
1182                 { $$ = tree_cons (NULL_TREE, $2, $1);
1183                   TREE_STATIC ($$) = 1; }
1184         | declspecs_sc_nots_nosa_ea typespec_attr
1185                 { $$ = tree_cons (NULL_TREE, $2, $1);
1186                   TREE_STATIC ($$) = 1; }
1187         ;
1188
1189 declspecs_sc_ts_sa_noea:
1190           declspecs_sc_ts_sa_noea TYPE_QUAL
1191                 { $$ = tree_cons (NULL_TREE, $2, $1);
1192                   TREE_STATIC ($$) = 1; }
1193         | declspecs_sc_ts_sa_ea TYPE_QUAL
1194                 { $$ = tree_cons (NULL_TREE, $2, $1);
1195                   TREE_STATIC ($$) = 1; }
1196         | declspecs_sc_ts_sa_noea typespec_reserved_nonattr
1197                 { $$ = tree_cons (NULL_TREE, $2, $1);
1198                   TREE_STATIC ($$) = 1; }
1199         | declspecs_sc_ts_sa_ea typespec_reserved_nonattr
1200                 { $$ = tree_cons (NULL_TREE, $2, $1);
1201                   TREE_STATIC ($$) = 1; }
1202         | declspecs_sc_nots_sa_noea typespec_nonattr
1203                 { $$ = tree_cons (NULL_TREE, $2, $1);
1204                   TREE_STATIC ($$) = 1; }
1205         | declspecs_sc_nots_sa_ea typespec_nonattr
1206                 { $$ = tree_cons (NULL_TREE, $2, $1);
1207                   TREE_STATIC ($$) = 1; }
1208         | declspecs_nosc_ts_sa_noea scspec
1209                 { if (extra_warnings && TREE_STATIC ($1))
1210                     warning ("`%s' is not at beginning of declaration",
1211                              IDENTIFIER_POINTER ($2));
1212                   $$ = tree_cons (NULL_TREE, $2, $1);
1213                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1214         | declspecs_nosc_ts_sa_ea scspec
1215                 { if (extra_warnings && TREE_STATIC ($1))
1216                     warning ("`%s' is not at beginning of declaration",
1217                              IDENTIFIER_POINTER ($2));
1218                   $$ = tree_cons (NULL_TREE, $2, $1);
1219                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1220         | declspecs_sc_ts_sa_noea scspec
1221                 { if (extra_warnings && TREE_STATIC ($1))
1222                     warning ("`%s' is not at beginning of declaration",
1223                              IDENTIFIER_POINTER ($2));
1224                   $$ = tree_cons (NULL_TREE, $2, $1);
1225                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1226         | declspecs_sc_ts_sa_ea scspec
1227                 { if (extra_warnings && TREE_STATIC ($1))
1228                     warning ("`%s' is not at beginning of declaration",
1229                              IDENTIFIER_POINTER ($2));
1230                   $$ = tree_cons (NULL_TREE, $2, $1);
1231                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1232         ;
1233
1234 declspecs_sc_ts_sa_ea:
1235           declspecs_sc_ts_sa_noea attributes
1236                 { $$ = tree_cons ($2, NULL_TREE, $1);
1237                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1238         | declspecs_sc_ts_sa_noea typespec_reserved_attr
1239                 { $$ = tree_cons (NULL_TREE, $2, $1);
1240                   TREE_STATIC ($$) = 1; }
1241         | declspecs_sc_ts_sa_ea typespec_reserved_attr
1242                 { $$ = tree_cons (NULL_TREE, $2, $1);
1243                   TREE_STATIC ($$) = 1; }
1244         | declspecs_sc_nots_sa_noea typespec_attr
1245                 { $$ = tree_cons (NULL_TREE, $2, $1);
1246                   TREE_STATIC ($$) = 1; }
1247         | declspecs_sc_nots_sa_ea typespec_attr
1248                 { $$ = tree_cons (NULL_TREE, $2, $1);
1249                   TREE_STATIC ($$) = 1; }
1250         ;
1251
1252 /* Particular useful classes of declspecs.  */
1253 declspecs_ts:
1254           declspecs_nosc_ts_nosa_noea
1255         | declspecs_nosc_ts_nosa_ea
1256         | declspecs_nosc_ts_sa_noea
1257         | declspecs_nosc_ts_sa_ea
1258         | declspecs_sc_ts_nosa_noea
1259         | declspecs_sc_ts_nosa_ea
1260         | declspecs_sc_ts_sa_noea
1261         | declspecs_sc_ts_sa_ea
1262         ;
1263
1264 declspecs_nots:
1265           declspecs_nosc_nots_nosa_noea
1266         | declspecs_nosc_nots_nosa_ea
1267         | declspecs_nosc_nots_sa_noea
1268         | declspecs_nosc_nots_sa_ea
1269         | declspecs_sc_nots_nosa_noea
1270         | declspecs_sc_nots_nosa_ea
1271         | declspecs_sc_nots_sa_noea
1272         | declspecs_sc_nots_sa_ea
1273         ;
1274
1275 declspecs_ts_nosa:
1276           declspecs_nosc_ts_nosa_noea
1277         | declspecs_nosc_ts_nosa_ea
1278         | declspecs_sc_ts_nosa_noea
1279         | declspecs_sc_ts_nosa_ea
1280         ;
1281
1282 declspecs_nots_nosa:
1283           declspecs_nosc_nots_nosa_noea
1284         | declspecs_nosc_nots_nosa_ea
1285         | declspecs_sc_nots_nosa_noea
1286         | declspecs_sc_nots_nosa_ea
1287         ;
1288
1289 declspecs_nosc_ts:
1290           declspecs_nosc_ts_nosa_noea
1291         | declspecs_nosc_ts_nosa_ea
1292         | declspecs_nosc_ts_sa_noea
1293         | declspecs_nosc_ts_sa_ea
1294         ;
1295
1296 declspecs_nosc_nots:
1297           declspecs_nosc_nots_nosa_noea
1298         | declspecs_nosc_nots_nosa_ea
1299         | declspecs_nosc_nots_sa_noea
1300         | declspecs_nosc_nots_sa_ea
1301         ;
1302
1303 declspecs_nosc:
1304           declspecs_nosc_ts_nosa_noea
1305         | declspecs_nosc_ts_nosa_ea
1306         | declspecs_nosc_ts_sa_noea
1307         | declspecs_nosc_ts_sa_ea
1308         | declspecs_nosc_nots_nosa_noea
1309         | declspecs_nosc_nots_nosa_ea
1310         | declspecs_nosc_nots_sa_noea
1311         | declspecs_nosc_nots_sa_ea
1312         ;
1313
1314 declspecs:
1315           declspecs_nosc_nots_nosa_noea
1316         | declspecs_nosc_nots_nosa_ea
1317         | declspecs_nosc_nots_sa_noea
1318         | declspecs_nosc_nots_sa_ea
1319         | declspecs_nosc_ts_nosa_noea
1320         | declspecs_nosc_ts_nosa_ea
1321         | declspecs_nosc_ts_sa_noea
1322         | declspecs_nosc_ts_sa_ea
1323         | declspecs_sc_nots_nosa_noea
1324         | declspecs_sc_nots_nosa_ea
1325         | declspecs_sc_nots_sa_noea
1326         | declspecs_sc_nots_sa_ea
1327         | declspecs_sc_ts_nosa_noea
1328         | declspecs_sc_ts_nosa_ea
1329         | declspecs_sc_ts_sa_noea
1330         | declspecs_sc_ts_sa_ea
1331         ;
1332
1333 /* A (possibly empty) sequence of type qualifiers and attributes.  */
1334 maybe_type_quals_attrs:
1335           /* empty */
1336                 { $$ = NULL_TREE; }
1337         | declspecs_nosc_nots
1338                 { $$ = $1; }
1339         ;
1340
1341 /* A type specifier (but not a type qualifier).
1342    Once we have seen one of these in a declaration,
1343    if a typedef name appears then it is being redeclared.
1344
1345    The _reserved versions start with a reserved word and may appear anywhere
1346    in the declaration specifiers; the _nonreserved versions may only
1347    appear before any other type specifiers, and after that are (if names)
1348    being redeclared.
1349
1350    FIXME: should the _nonreserved version be restricted to names being
1351    redeclared only?  The other entries there relate only the GNU extensions
1352    and Objective C, and are historically parsed thus, and don't make sense
1353    after other type specifiers, but it might be cleaner to count them as
1354    _reserved.
1355
1356    _attr means: specifiers that either end with attributes,
1357    or are such that any following attributes would
1358    be parsed as part of the specifier.
1359
1360    _nonattr: specifiers.  */
1361
1362 typespec_nonattr:
1363           typespec_reserved_nonattr
1364         | typespec_nonreserved_nonattr
1365         ;
1366
1367 typespec_attr:
1368           typespec_reserved_attr
1369         ;
1370
1371 typespec_reserved_nonattr:
1372           TYPESPEC
1373                 { OBJC_NEED_RAW_IDENTIFIER (1); }
1374         | structsp_nonattr
1375         ;
1376
1377 typespec_reserved_attr:
1378           structsp_attr
1379         ;
1380
1381 typespec_nonreserved_nonattr:
1382           TYPENAME
1383                 { /* For a typedef name, record the meaning, not the name.
1384                      In case of `foo foo, bar;'.  */
1385                   $$ = lookup_name ($1); }
1386 ifobjc
1387         | CLASSNAME protocolrefs
1388                 { $$ = get_static_reference ($1, $2); }
1389         | OBJECTNAME protocolrefs
1390                 { $$ = get_object_reference ($2); }
1391
1392 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>"
1393    - nisse@lysator.liu.se */
1394         | non_empty_protocolrefs
1395                 { $$ = get_object_reference ($1); }
1396 end ifobjc
1397         | TYPEOF '(' expr ')'
1398                 { $$ = TREE_TYPE ($3); }
1399         | TYPEOF '(' typename ')'
1400                 { $$ = groktypename ($3); }
1401         ;
1402
1403 /* typespec_nonreserved_attr does not exist.  */
1404
1405 initdecls:
1406         initdcl
1407         | initdecls ',' maybe_resetattrs initdcl
1408         ;
1409
1410 notype_initdecls:
1411         notype_initdcl
1412         | notype_initdecls ',' maybe_resetattrs notype_initdcl
1413         ;
1414
1415 maybeasm:
1416           /* empty */
1417                 { $$ = NULL_TREE; }
1418         | ASM_KEYWORD '(' STRING ')'
1419                 { $$ = $3; }
1420         ;
1421
1422 initdcl:
1423           declarator maybeasm maybe_attribute '='
1424                 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1425                                           chainon ($3, all_prefix_attributes));
1426                   start_init ($<ttype>$, $2, global_bindings_p ()); }
1427           init
1428 /* Note how the declaration of the variable is in effect while its init is parsed! */
1429                 { finish_init ();
1430                   finish_decl ($<ttype>5, $6, $2); }
1431         | declarator maybeasm maybe_attribute
1432                 { tree d = start_decl ($1, current_declspecs, 0,
1433                                        chainon ($3, all_prefix_attributes));
1434                   finish_decl (d, NULL_TREE, $2);
1435                 }
1436         ;
1437
1438 notype_initdcl:
1439           notype_declarator maybeasm maybe_attribute '='
1440                 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1441                                           chainon ($3, all_prefix_attributes));
1442                   start_init ($<ttype>$, $2, global_bindings_p ()); }
1443           init
1444 /* Note how the declaration of the variable is in effect while its init is parsed! */
1445                 { finish_init ();
1446                   finish_decl ($<ttype>5, $6, $2); }
1447         | notype_declarator maybeasm maybe_attribute
1448                 { tree d = start_decl ($1, current_declspecs, 0,
1449                                        chainon ($3, all_prefix_attributes));
1450                   finish_decl (d, NULL_TREE, $2); }
1451         ;
1452 /* the * rules are dummies to accept the Apollo extended syntax
1453    so that the header files compile. */
1454 maybe_attribute:
1455       /* empty */
1456                 { $$ = NULL_TREE; }
1457         | attributes
1458                 { $$ = $1; }
1459         ;
1460
1461 attributes:
1462       attribute
1463                 { $$ = $1; }
1464         | attributes attribute
1465                 { $$ = chainon ($1, $2); }
1466         ;
1467
1468 attribute:
1469       ATTRIBUTE '(' '(' attribute_list ')' ')'
1470                 { $$ = $4; }
1471         ;
1472
1473 attribute_list:
1474       attrib
1475                 { $$ = $1; }
1476         | attribute_list ',' attrib
1477                 { $$ = chainon ($1, $3); }
1478         ;
1479
1480 attrib:
1481     /* empty */
1482                 { $$ = NULL_TREE; }
1483         | any_word
1484                 { $$ = build_tree_list ($1, NULL_TREE); }
1485         | any_word '(' IDENTIFIER ')'
1486                 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1487         | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1488                 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1489         | any_word '(' exprlist ')'
1490                 { $$ = build_tree_list ($1, $3); }
1491         ;
1492
1493 /* This still leaves out most reserved keywords,
1494    shouldn't we include them?  */
1495
1496 any_word:
1497           identifier
1498         | scspec
1499         | TYPESPEC
1500         | TYPE_QUAL
1501         ;
1502
1503 scspec:
1504           STATIC
1505         | SCSPEC
1506         ;
1507 \f
1508 /* Initializers.  `init' is the entry point.  */
1509
1510 init:
1511         expr_no_commas
1512         | '{'
1513                 { really_start_incremental_init (NULL_TREE); }
1514           initlist_maybe_comma '}'
1515                 { $$ = pop_init_level (0); }
1516         | error
1517                 { $$ = error_mark_node; }
1518         ;
1519
1520 /* `initlist_maybe_comma' is the guts of an initializer in braces.  */
1521 initlist_maybe_comma:
1522           /* empty */
1523                 { if (pedantic)
1524                     pedwarn ("ISO C forbids empty initializer braces"); }
1525         | initlist1 maybecomma
1526         ;
1527
1528 initlist1:
1529           initelt
1530         | initlist1 ',' initelt
1531         ;
1532
1533 /* `initelt' is a single element of an initializer.
1534    It may use braces.  */
1535 initelt:
1536           designator_list '=' initval
1537                 { if (pedantic && ! flag_isoc99)
1538                     pedwarn ("ISO C89 forbids specifying subobject to initialize"); }
1539         | designator initval
1540                 { if (pedantic)
1541                     pedwarn ("obsolete use of designated initializer without `='"); }
1542         | identifier ':'
1543                 { set_init_label ($1);
1544                   if (pedantic)
1545                     pedwarn ("obsolete use of designated initializer with `:'"); }
1546           initval
1547                 {}
1548         | initval
1549         ;
1550
1551 initval:
1552           '{'
1553                 { push_init_level (0); }
1554           initlist_maybe_comma '}'
1555                 { process_init_element (pop_init_level (0)); }
1556         | expr_no_commas
1557                 { process_init_element ($1); }
1558         | error
1559         ;
1560
1561 designator_list:
1562           designator
1563         | designator_list designator
1564         ;
1565
1566 designator:
1567           '.' identifier
1568                 { set_init_label ($2); }
1569         /* These are for labeled elements.  The syntax for an array element
1570            initializer conflicts with the syntax for an Objective-C message,
1571            so don't include these productions in the Objective-C grammar.  */
1572 ifc
1573         | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
1574                 { set_init_index ($2, $4);
1575                   if (pedantic)
1576                     pedwarn ("ISO C forbids specifying range of elements to initialize"); }
1577         | '[' expr_no_commas ']'
1578                 { set_init_index ($2, NULL_TREE); }
1579 end ifc
1580         ;
1581 \f
1582 nested_function:
1583           declarator
1584                 { if (pedantic)
1585                     pedwarn ("ISO C forbids nested functions");
1586
1587                   push_function_context ();
1588                   if (! start_function (current_declspecs, $1,
1589                                         all_prefix_attributes))
1590                     {
1591                       pop_function_context ();
1592                       YYERROR1;
1593                     }
1594                 }
1595            old_style_parm_decls
1596                 { store_parm_decls (); }
1597 /* This used to use compstmt_or_error.
1598    That caused a bug with input `f(g) int g {}',
1599    where the use of YYERROR1 above caused an error
1600    which then was handled by compstmt_or_error.
1601    There followed a repeated execution of that same rule,
1602    which called YYERROR1 again, and so on.  */
1603           save_filename save_lineno compstmt
1604                 { tree decl = current_function_decl;
1605                   DECL_SOURCE_FILE (decl) = $5;
1606                   DECL_SOURCE_LINE (decl) = $6;
1607                   finish_function (1, 1);
1608                   pop_function_context ();
1609                   add_decl_stmt (decl); }
1610         ;
1611
1612 notype_nested_function:
1613           notype_declarator
1614                 { if (pedantic)
1615                     pedwarn ("ISO C forbids nested functions");
1616
1617                   push_function_context ();
1618                   if (! start_function (current_declspecs, $1,
1619                                         all_prefix_attributes))
1620                     {
1621                       pop_function_context ();
1622                       YYERROR1;
1623                     }
1624                 }
1625           old_style_parm_decls
1626                 { store_parm_decls (); }
1627 /* This used to use compstmt_or_error.
1628    That caused a bug with input `f(g) int g {}',
1629    where the use of YYERROR1 above caused an error
1630    which then was handled by compstmt_or_error.
1631    There followed a repeated execution of that same rule,
1632    which called YYERROR1 again, and so on.  */
1633           save_filename save_lineno compstmt
1634                 { tree decl = current_function_decl;
1635                   DECL_SOURCE_FILE (decl) = $5;
1636                   DECL_SOURCE_LINE (decl) = $6;
1637                   finish_function (1, 1);
1638                   pop_function_context ();
1639                   add_decl_stmt (decl); }
1640         ;
1641
1642 /* Any kind of declarator (thus, all declarators allowed
1643    after an explicit typespec).  */
1644
1645 declarator:
1646           after_type_declarator
1647         | notype_declarator
1648         ;
1649
1650 /* A declarator that is allowed only after an explicit typespec.  */
1651
1652 after_type_declarator:
1653           '(' maybe_attribute after_type_declarator ')'
1654                 { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
1655         | after_type_declarator '(' parmlist_or_identifiers  %prec '.'
1656                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1657 /*      | after_type_declarator '(' error ')'  %prec '.'
1658                 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1659                   poplevel (0, 0, 0); }  */
1660         | after_type_declarator array_declarator  %prec '.'
1661                 { $$ = set_array_declarator_type ($2, $1, 0); }
1662         | '*' maybe_type_quals_attrs after_type_declarator  %prec UNARY
1663                 { $$ = make_pointer_declarator ($2, $3); }
1664         | TYPENAME
1665 ifobjc
1666         | OBJECTNAME
1667 end ifobjc
1668         ;
1669
1670 /* Kinds of declarator that can appear in a parameter list
1671    in addition to notype_declarator.  This is like after_type_declarator
1672    but does not allow a typedef name in parentheses as an identifier
1673    (because it would conflict with a function with that typedef as arg).  */
1674 parm_declarator:
1675           parm_declarator_starttypename
1676         | parm_declarator_nostarttypename
1677         ;
1678
1679 parm_declarator_starttypename:
1680           parm_declarator_starttypename '(' parmlist_or_identifiers  %prec '.'
1681                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1682 /*      | parm_declarator_starttypename '(' error ')'  %prec '.'
1683                 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1684                   poplevel (0, 0, 0); }  */
1685         | parm_declarator_starttypename array_declarator  %prec '.'
1686                 { $$ = set_array_declarator_type ($2, $1, 0); }
1687         | TYPENAME
1688 ifobjc
1689         | OBJECTNAME
1690 end ifobjc
1691         ;
1692
1693 parm_declarator_nostarttypename:
1694           parm_declarator_nostarttypename '(' parmlist_or_identifiers  %prec '.'
1695                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1696 /*      | parm_declarator_nostarttypename '(' error ')'  %prec '.'
1697                 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1698                   poplevel (0, 0, 0); }  */
1699         | parm_declarator_nostarttypename array_declarator  %prec '.'
1700                 { $$ = set_array_declarator_type ($2, $1, 0); }
1701         | '*' maybe_type_quals_attrs parm_declarator_starttypename  %prec UNARY
1702                 { $$ = make_pointer_declarator ($2, $3); }
1703         | '*' maybe_type_quals_attrs parm_declarator_nostarttypename  %prec UNARY
1704                 { $$ = make_pointer_declarator ($2, $3); }
1705         | '(' maybe_attribute parm_declarator_nostarttypename ')'
1706                 { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
1707         ;
1708
1709 /* A declarator allowed whether or not there has been
1710    an explicit typespec.  These cannot redeclare a typedef-name.  */
1711
1712 notype_declarator:
1713           notype_declarator '(' parmlist_or_identifiers  %prec '.'
1714                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1715 /*      | notype_declarator '(' error ')'  %prec '.'
1716                 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1717                   poplevel (0, 0, 0); }  */
1718         | '(' maybe_attribute notype_declarator ')'
1719                 { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
1720         | '*' maybe_type_quals_attrs notype_declarator  %prec UNARY
1721                 { $$ = make_pointer_declarator ($2, $3); }
1722         | notype_declarator array_declarator  %prec '.'
1723                 { $$ = set_array_declarator_type ($2, $1, 0); }
1724         | IDENTIFIER
1725         ;
1726
1727 struct_head:
1728           STRUCT
1729                 { $$ = NULL_TREE; }
1730         | STRUCT attributes
1731                 { $$ = $2; }
1732         ;
1733
1734 union_head:
1735           UNION
1736                 { $$ = NULL_TREE; }
1737         | UNION attributes
1738                 { $$ = $2; }
1739         ;
1740
1741 enum_head:
1742           ENUM
1743                 { $$ = NULL_TREE; }
1744         | ENUM attributes
1745                 { $$ = $2; }
1746         ;
1747
1748 /* structsp_attr: struct/union/enum specifiers that either
1749    end with attributes, or are such that any following attributes would
1750    be parsed as part of the struct/union/enum specifier.
1751
1752    structsp_nonattr: other struct/union/enum specifiers.  */
1753
1754 structsp_attr:
1755           struct_head identifier '{'
1756                 { $$ = start_struct (RECORD_TYPE, $2);
1757                   /* Start scope of tag before parsing components.  */
1758                 }
1759           component_decl_list '}' maybe_attribute
1760                 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1761         | struct_head '{' component_decl_list '}' maybe_attribute
1762                 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1763                                       $3, chainon ($1, $5));
1764                 }
1765         | union_head identifier '{'
1766                 { $$ = start_struct (UNION_TYPE, $2); }
1767           component_decl_list '}' maybe_attribute
1768                 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1769         | union_head '{' component_decl_list '}' maybe_attribute
1770                 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1771                                       $3, chainon ($1, $5));
1772                 }
1773         | enum_head identifier '{'
1774                 { $$ = start_enum ($2); }
1775           enumlist maybecomma_warn '}' maybe_attribute
1776                 { $$ = finish_enum ($<ttype>4, nreverse ($5),
1777                                     chainon ($1, $8)); }
1778         | enum_head '{'
1779                 { $$ = start_enum (NULL_TREE); }
1780           enumlist maybecomma_warn '}' maybe_attribute
1781                 { $$ = finish_enum ($<ttype>3, nreverse ($4),
1782                                     chainon ($1, $7)); }
1783         ;
1784
1785 structsp_nonattr:
1786           struct_head identifier
1787                 { $$ = xref_tag (RECORD_TYPE, $2); }
1788         | union_head identifier
1789                 { $$ = xref_tag (UNION_TYPE, $2); }
1790         | enum_head identifier
1791                 { $$ = xref_tag (ENUMERAL_TYPE, $2);
1792                   /* In ISO C, enumerated types can be referred to
1793                      only if already defined.  */
1794                   if (pedantic && !COMPLETE_TYPE_P ($$))
1795                     pedwarn ("ISO C forbids forward references to `enum' types"); }
1796         ;
1797
1798 maybecomma:
1799           /* empty */
1800         | ','
1801         ;
1802
1803 maybecomma_warn:
1804           /* empty */
1805         | ','
1806                 { if (pedantic && ! flag_isoc99)
1807                     pedwarn ("comma at end of enumerator list"); }
1808         ;
1809
1810 component_decl_list:
1811           component_decl_list2
1812                 { $$ = $1; }
1813         | component_decl_list2 component_decl
1814                 { $$ = chainon ($1, $2);
1815                   pedwarn ("no semicolon at end of struct or union"); }
1816         ;
1817
1818 component_decl_list2:   /* empty */
1819                 { $$ = NULL_TREE; }
1820         | component_decl_list2 component_decl ';'
1821                 { $$ = chainon ($1, $2); }
1822         | component_decl_list2 ';'
1823                 { if (pedantic)
1824                     pedwarn ("extra semicolon in struct or union specified"); }
1825 ifobjc
1826         /* foo(sizeof(struct{ @defs(ClassName)})); */
1827         | DEFS '(' CLASSNAME ')'
1828                 {
1829                   tree interface = lookup_interface ($3);
1830
1831                   if (interface)
1832                     $$ = get_class_ivars (interface);
1833                   else
1834                     {
1835                       error ("cannot find interface declaration for `%s'",
1836                              IDENTIFIER_POINTER ($3));
1837                       $$ = NULL_TREE;
1838                     }
1839                 }
1840 end ifobjc
1841         ;
1842
1843 component_decl:
1844           declspecs_nosc_ts setspecs components
1845                 { $$ = $3;
1846                   POP_DECLSPEC_STACK; }
1847         | declspecs_nosc_ts setspecs save_filename save_lineno
1848                 {
1849                   /* Support for unnamed structs or unions as members of
1850                      structs or unions (which is [a] useful and [b] supports
1851                      MS P-SDK).  */
1852                   if (pedantic)
1853                     pedwarn ("ISO C doesn't support unnamed structs/unions");
1854
1855                   $$ = grokfield($3, $4, NULL, current_declspecs, NULL_TREE);
1856                   POP_DECLSPEC_STACK; }
1857         | declspecs_nosc_nots setspecs components_notype
1858                 { $$ = $3;
1859                   POP_DECLSPEC_STACK; }
1860         | declspecs_nosc_nots
1861                 { if (pedantic)
1862                     pedwarn ("ISO C forbids member declarations with no members");
1863                   shadow_tag($1);
1864                   $$ = NULL_TREE; }
1865         | error
1866                 { $$ = NULL_TREE; }
1867         | extension component_decl
1868                 { $$ = $2;
1869                   RESTORE_EXT_FLAGS ($1); }
1870         ;
1871
1872 components:
1873           component_declarator
1874         | components ',' maybe_resetattrs component_declarator
1875                 { $$ = chainon ($1, $4); }
1876         ;
1877
1878 components_notype:
1879           component_notype_declarator
1880         | components_notype ',' maybe_resetattrs component_notype_declarator
1881                 { $$ = chainon ($1, $4); }
1882         ;
1883
1884 component_declarator:
1885           save_filename save_lineno declarator maybe_attribute
1886                 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1887                   decl_attributes (&$$, chainon ($4, all_prefix_attributes), 0); }
1888         | save_filename save_lineno
1889           declarator ':' expr_no_commas maybe_attribute
1890                 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1891                   decl_attributes (&$$, chainon ($6, all_prefix_attributes), 0); }
1892         | save_filename save_lineno ':' expr_no_commas maybe_attribute
1893                 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1894                   decl_attributes (&$$, chainon ($5, all_prefix_attributes), 0); }
1895         ;
1896
1897 component_notype_declarator:
1898           save_filename save_lineno notype_declarator maybe_attribute
1899                 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1900                   decl_attributes (&$$, chainon ($4, all_prefix_attributes), 0); }
1901         | save_filename save_lineno
1902           notype_declarator ':' expr_no_commas maybe_attribute
1903                 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1904                   decl_attributes (&$$, chainon ($6, all_prefix_attributes), 0); }
1905         | save_filename save_lineno ':' expr_no_commas maybe_attribute
1906                 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1907                   decl_attributes (&$$, chainon ($5, all_prefix_attributes), 0); }
1908         ;
1909
1910 /* We chain the enumerators in reverse order.
1911    They are put in forward order where enumlist is used.
1912    (The order used to be significant, but no longer is so.
1913    However, we still maintain the order, just to be clean.)  */
1914
1915 enumlist:
1916           enumerator
1917         | enumlist ',' enumerator
1918                 { if ($1 == error_mark_node)
1919                     $$ = $1;
1920                   else
1921                     $$ = chainon ($3, $1); }
1922         | error
1923                 { $$ = error_mark_node; }
1924         ;
1925
1926
1927 enumerator:
1928           identifier
1929                 { $$ = build_enumerator ($1, NULL_TREE); }
1930         | identifier '=' expr_no_commas
1931                 { $$ = build_enumerator ($1, $3); }
1932         ;
1933
1934 typename:
1935           declspecs_nosc
1936                 { pending_xref_error ();
1937                   $<ttype>$ = $1; }
1938           absdcl
1939                 { $$ = build_tree_list ($<ttype>2, $3); }
1940         ;
1941
1942 absdcl:   /* an absolute declarator */
1943         /* empty */
1944                 { $$ = NULL_TREE; }
1945         | absdcl1
1946         ;
1947
1948 absdcl_maybe_attribute:   /* absdcl maybe_attribute, but not just attributes */
1949         /* empty */
1950                 { $$ = build_tree_list (build_tree_list (current_declspecs,
1951                                                          NULL_TREE),
1952                                         all_prefix_attributes); }
1953         | absdcl1
1954                 { $$ = build_tree_list (build_tree_list (current_declspecs,
1955                                                          $1),
1956                                         all_prefix_attributes); }
1957         | absdcl1_noea attributes
1958                 { $$ = build_tree_list (build_tree_list (current_declspecs,
1959                                                          $1),
1960                                         chainon ($2, all_prefix_attributes)); }
1961         ;
1962
1963 absdcl1:  /* a nonempty absolute declarator */
1964           absdcl1_ea
1965         | absdcl1_noea
1966         ;
1967
1968 absdcl1_noea:
1969           direct_absdcl1
1970         | '*' maybe_type_quals_attrs absdcl1_noea
1971                 { $$ = make_pointer_declarator ($2, $3); }
1972         ;
1973
1974 absdcl1_ea:
1975           '*' maybe_type_quals_attrs
1976                 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1977         | '*' maybe_type_quals_attrs absdcl1_ea
1978                 { $$ = make_pointer_declarator ($2, $3); }
1979         ;
1980
1981 direct_absdcl1:
1982           '(' maybe_attribute absdcl1 ')'
1983                 { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
1984         | direct_absdcl1 '(' parmlist
1985                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1986         | direct_absdcl1 array_declarator
1987                 { $$ = set_array_declarator_type ($2, $1, 1); }
1988         | '(' parmlist
1989                 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1990         | array_declarator
1991                 { $$ = set_array_declarator_type ($1, NULL_TREE, 1); }
1992         ;
1993
1994 /* The [...] part of a declarator for an array type.  */
1995
1996 array_declarator:
1997         '[' maybe_type_quals_attrs expr ']'
1998                 { $$ = build_array_declarator ($3, $2, 0, 0); }
1999         | '[' maybe_type_quals_attrs ']'
2000                 { $$ = build_array_declarator (NULL_TREE, $2, 0, 0); }
2001         | '[' maybe_type_quals_attrs '*' ']'
2002                 { $$ = build_array_declarator (NULL_TREE, $2, 0, 1); }
2003         | '[' STATIC maybe_type_quals_attrs expr ']'
2004                 { $$ = build_array_declarator ($4, $3, 1, 0); }
2005         /* declspecs_nosc_nots is a synonym for type_quals_attrs.  */
2006         | '[' declspecs_nosc_nots STATIC expr ']'
2007                 { $$ = build_array_declarator ($4, $2, 1, 0); }
2008         ;
2009
2010 /* A nonempty series of declarations and statements (possibly followed by
2011    some labels) that can form the body of a compound statement.
2012    NOTE: we don't allow labels on declarations; this might seem like a
2013    natural extension, but there would be a conflict between attributes
2014    on the label and prefix attributes on the declaration.  */
2015
2016 stmts_and_decls:
2017           lineno_stmt_decl_or_labels_ending_stmt
2018         | lineno_stmt_decl_or_labels_ending_decl
2019         | lineno_stmt_decl_or_labels_ending_label
2020                 {
2021                   pedwarn ("deprecated use of label at end of compound statement");
2022                 }
2023         | lineno_stmt_decl_or_labels_ending_error
2024         ;
2025
2026 lineno_stmt_decl_or_labels_ending_stmt:
2027           lineno_stmt
2028         | lineno_stmt_decl_or_labels_ending_stmt lineno_stmt
2029         | lineno_stmt_decl_or_labels_ending_decl lineno_stmt
2030         | lineno_stmt_decl_or_labels_ending_label lineno_stmt
2031         | lineno_stmt_decl_or_labels_ending_error lineno_stmt
2032         ;
2033
2034 lineno_stmt_decl_or_labels_ending_decl:
2035           lineno_decl
2036         | lineno_stmt_decl_or_labels_ending_stmt lineno_decl
2037                 { if (pedantic && !flag_isoc99)
2038                     pedwarn ("ISO C89 forbids mixed declarations and code"); }
2039         | lineno_stmt_decl_or_labels_ending_decl lineno_decl
2040         | lineno_stmt_decl_or_labels_ending_error lineno_decl
2041         ;
2042
2043 lineno_stmt_decl_or_labels_ending_label:
2044           lineno_label
2045         | lineno_stmt_decl_or_labels_ending_stmt lineno_label
2046         | lineno_stmt_decl_or_labels_ending_decl lineno_label
2047         | lineno_stmt_decl_or_labels_ending_label lineno_label
2048         | lineno_stmt_decl_or_labels_ending_error lineno_label
2049         ;
2050
2051 lineno_stmt_decl_or_labels_ending_error:
2052         errstmt
2053         | lineno_stmt_decl_or_labels errstmt
2054         ;
2055
2056 lineno_stmt_decl_or_labels:
2057           lineno_stmt_decl_or_labels_ending_stmt
2058         | lineno_stmt_decl_or_labels_ending_decl
2059         | lineno_stmt_decl_or_labels_ending_label
2060         | lineno_stmt_decl_or_labels_ending_error
2061         ;
2062
2063 errstmt:  error ';'
2064         ;
2065
2066 pushlevel:  /* empty */
2067                 { pushlevel (0);
2068                   clear_last_expr ();
2069                   add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
2070 ifobjc
2071                   if (objc_method_context)
2072                     add_objc_decls ();
2073 end ifobjc
2074                 }
2075         ;
2076
2077 poplevel:  /* empty */
2078                 { $$ = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0); }
2079         ;
2080
2081 /* Start and end blocks created for the new scopes of C99.  */
2082 c99_block_start: /* empty */
2083                 { if (flag_isoc99)
2084                     {
2085                       $$ = c_begin_compound_stmt ();
2086                       pushlevel (0);
2087                       clear_last_expr ();
2088                       add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
2089 ifobjc
2090                       if (objc_method_context)
2091                         add_objc_decls ();
2092 end ifobjc
2093                     }
2094                   else
2095                     $$ = NULL_TREE;
2096                 }
2097         ;
2098
2099 /* Productions using c99_block_start and c99_block_end will need to do what's
2100    in compstmt: RECHAIN_STMTS ($1, COMPOUND_BODY ($1)); $$ = $2; where
2101    $1 is the value of c99_block_start and $2 of c99_block_end.  */
2102 c99_block_end: /* empty */
2103                 { if (flag_isoc99)
2104                     {
2105                       tree scope_stmt = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
2106                       $$ = poplevel (kept_level_p (), 0, 0);
2107                       SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmt))
2108                         = SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmt))
2109                         = $$;
2110                     }
2111                   else
2112                     $$ = NULL_TREE; }
2113         ;
2114
2115 /* Read zero or more forward-declarations for labels
2116    that nested functions can jump to.  */
2117 maybe_label_decls:
2118           /* empty */
2119         | label_decls
2120                 { if (pedantic)
2121                     pedwarn ("ISO C forbids label declarations"); }
2122         ;
2123
2124 label_decls:
2125           label_decl
2126         | label_decls label_decl
2127         ;
2128
2129 label_decl:
2130           LABEL identifiers_or_typenames ';'
2131                 { tree link;
2132                   for (link = $2; link; link = TREE_CHAIN (link))
2133                     {
2134                       tree label = shadow_label (TREE_VALUE (link));
2135                       C_DECLARED_LABEL_FLAG (label) = 1;
2136                       add_decl_stmt (label);
2137                     }
2138                 }
2139         ;
2140
2141 /* This is the body of a function definition.
2142    It causes syntax errors to ignore to the next openbrace.  */
2143 compstmt_or_error:
2144           compstmt
2145                 {}
2146         | error compstmt
2147         ;
2148
2149 compstmt_start: '{' { compstmt_count++;
2150                       $$ = c_begin_compound_stmt (); }
2151         ;
2152
2153 compstmt_nostart: '}'
2154                 { $$ = convert (void_type_node, integer_zero_node); }
2155         | pushlevel maybe_label_decls compstmt_contents_nonempty '}' poplevel
2156                 { $$ = poplevel (kept_level_p (), 1, 0);
2157                   SCOPE_STMT_BLOCK (TREE_PURPOSE ($5))
2158                     = SCOPE_STMT_BLOCK (TREE_VALUE ($5))
2159                     = $$; }
2160         ;
2161
2162 compstmt_contents_nonempty:
2163           stmts_and_decls
2164         | error
2165         ;
2166
2167 compstmt_primary_start:
2168         '(' '{'
2169                 { if (current_function_decl == 0)
2170                     {
2171                       error ("braced-group within expression allowed only inside a function");
2172                       YYERROR;
2173                     }
2174                   /* We must force a BLOCK for this level
2175                      so that, if it is not expanded later,
2176                      there is a way to turn off the entire subtree of blocks
2177                      that are contained in it.  */
2178                   keep_next_level ();
2179                   push_label_level ();
2180                   compstmt_count++;
2181                   $$ = add_stmt (build_stmt (COMPOUND_STMT, last_tree));
2182                 }
2183         ;
2184
2185 compstmt: compstmt_start compstmt_nostart
2186                 { RECHAIN_STMTS ($1, COMPOUND_BODY ($1));
2187                   last_expr_type = NULL_TREE;
2188                   $$ = $1; }
2189         ;
2190
2191 /* Value is number of statements counted as of the closeparen.  */
2192 simple_if:
2193           if_prefix c99_block_lineno_labeled_stmt
2194                 { c_finish_then (); }
2195 /* Make sure c_expand_end_cond is run once
2196    for each call to c_expand_start_cond.
2197    Otherwise a crash is likely.  */
2198         | if_prefix error
2199         ;
2200
2201 if_prefix:
2202           /* We must build the IF_STMT node before parsing its
2203              condition so that STMT_LINENO refers to the line
2204              containing the "if", and not the line containing
2205              the close-parenthesis.
2206
2207              c_begin_if_stmt returns the IF_STMT node, which
2208              we later pass to c_expand_start_cond to fill
2209              in the condition and other tidbits.  */
2210           IF
2211                 { $<ttype>$ = c_begin_if_stmt (); }
2212             '(' expr ')'
2213                 { c_expand_start_cond (c_common_truthvalue_conversion ($4),
2214                                        compstmt_count,$<ttype>2);
2215                   $<itype>$ = stmt_count;
2216                   if_stmt_file = $<filename>-2;
2217                   if_stmt_line = $<lineno>-1; }
2218         ;
2219
2220 /* This is a subroutine of stmt.
2221    It is used twice, once for valid DO statements
2222    and once for catching errors in parsing the end test.  */
2223 do_stmt_start:
2224           DO
2225                 { stmt_count++;
2226                   compstmt_count++;
2227                   $<ttype>$
2228                     = add_stmt (build_stmt (DO_STMT, NULL_TREE,
2229                                             NULL_TREE));
2230                   /* In the event that a parse error prevents
2231                      parsing the complete do-statement, set the
2232                      condition now.  Otherwise, we can get crashes at
2233                      RTL-generation time.  */
2234                   DO_COND ($<ttype>$) = error_mark_node; }
2235           c99_block_lineno_labeled_stmt WHILE
2236                 { $$ = $<ttype>2;
2237                   RECHAIN_STMTS ($$, DO_BODY ($$)); }
2238         ;
2239
2240 /* The forced readahead in here is because we might be at the end of a
2241    line, and the line and file won't be bumped until yylex absorbs the
2242    first token on the next line.  */
2243 save_filename:
2244                 { if (yychar == YYEMPTY)
2245                     yychar = YYLEX;
2246                   $$ = input_filename; }
2247         ;
2248
2249 save_lineno:
2250                 { if (yychar == YYEMPTY)
2251                     yychar = YYLEX;
2252                   $$ = lineno; }
2253         ;
2254
2255 lineno_labeled_stmt:
2256           lineno_stmt
2257         | lineno_label lineno_labeled_stmt
2258         ;
2259
2260 /* Like lineno_labeled_stmt, but a block in C99.  */
2261 c99_block_lineno_labeled_stmt:
2262           c99_block_start lineno_labeled_stmt c99_block_end
2263                 { if (flag_isoc99)
2264                     RECHAIN_STMTS ($1, COMPOUND_BODY ($1)); }
2265         ;
2266
2267 lineno_stmt:
2268           save_filename save_lineno stmt
2269                 { if ($3)
2270                     {
2271                       STMT_LINENO ($3) = $2;
2272                       /* ??? We currently have no way of recording
2273                          the filename for a statement.  This probably
2274                          matters little in practice at the moment,
2275                          but I suspect that problems will occur when
2276                          doing inlining at the tree level.  */
2277                     }
2278                 }
2279         ;
2280
2281 lineno_label:
2282           save_filename save_lineno label
2283                 { if ($3)
2284                     {
2285                       STMT_LINENO ($3) = $2;
2286                     }
2287                 }
2288         ;
2289
2290 select_or_iter_stmt:
2291           simple_if ELSE
2292                 { c_expand_start_else ();
2293                   $<itype>1 = stmt_count; }
2294           c99_block_lineno_labeled_stmt
2295                 { c_finish_else ();
2296                   c_expand_end_cond ();
2297                   if (extra_warnings && stmt_count == $<itype>1)
2298                     warning ("empty body in an else-statement"); }
2299         | simple_if %prec IF
2300                 { c_expand_end_cond ();
2301                   /* This warning is here instead of in simple_if, because we
2302                      do not want a warning if an empty if is followed by an
2303                      else statement.  Increment stmt_count so we don't
2304                      give a second error if this is a nested `if'.  */
2305                   if (extra_warnings && stmt_count++ == $<itype>1)
2306                     warning_with_file_and_line (if_stmt_file, if_stmt_line,
2307                                                 "empty body in an if-statement"); }
2308 /* Make sure c_expand_end_cond is run once
2309    for each call to c_expand_start_cond.
2310    Otherwise a crash is likely.  */
2311         | simple_if ELSE error
2312                 { c_expand_end_cond (); }
2313        /* We must build the WHILE_STMT node before parsing its
2314           condition so that STMT_LINENO refers to the line
2315           containing the "while", and not the line containing
2316           the close-parenthesis.
2317
2318           c_begin_while_stmt returns the WHILE_STMT node, which
2319           we later pass to c_finish_while_stmt_cond to fill
2320           in the condition and other tidbits.  */
2321         | WHILE
2322                 { stmt_count++;
2323                   $<ttype>$ = c_begin_while_stmt (); }
2324           '(' expr ')'
2325                 { $4 = c_common_truthvalue_conversion ($4);
2326                   c_finish_while_stmt_cond
2327                     (c_common_truthvalue_conversion ($4), $<ttype>2);
2328                   $<ttype>$ = add_stmt ($<ttype>2); }
2329           c99_block_lineno_labeled_stmt
2330                 { RECHAIN_STMTS ($<ttype>6, WHILE_BODY ($<ttype>6)); }
2331         | do_stmt_start
2332           '(' expr ')' ';'
2333                 { DO_COND ($1) = c_common_truthvalue_conversion ($3); }
2334         | do_stmt_start error
2335                 { }
2336         | FOR
2337                 { $<ttype>$ = build_stmt (FOR_STMT, NULL_TREE, NULL_TREE,
2338                                           NULL_TREE, NULL_TREE);
2339                   add_stmt ($<ttype>$); }
2340           '(' for_init_stmt
2341                 { stmt_count++;
2342                   RECHAIN_STMTS ($<ttype>2, FOR_INIT_STMT ($<ttype>2)); }
2343           xexpr ';'
2344                 { if ($6)
2345                     FOR_COND ($<ttype>2)
2346                       = c_common_truthvalue_conversion ($6); }
2347           xexpr ')'
2348                 { FOR_EXPR ($<ttype>2) = $9; }
2349           c99_block_lineno_labeled_stmt
2350                 { RECHAIN_STMTS ($<ttype>2, FOR_BODY ($<ttype>2)); }
2351         | SWITCH '(' expr ')'
2352                 { stmt_count++;
2353                   $<ttype>$ = c_start_case ($3); }
2354           c99_block_lineno_labeled_stmt
2355                 { c_finish_case (); }
2356         ;
2357
2358 for_init_stmt:
2359           xexpr ';'
2360                 { add_stmt (build_stmt (EXPR_STMT, $1)); }
2361         | decl
2362                 { check_for_loop_decls (); }
2363         ;
2364
2365 /* Parse a single real statement, not including any labels.  */
2366 stmt:
2367           compstmt
2368                 { stmt_count++; $$ = $1; }
2369         | expr ';'
2370                 { stmt_count++;
2371                   $$ = c_expand_expr_stmt ($1); }
2372         | c99_block_start select_or_iter_stmt c99_block_end
2373                 { if (flag_isoc99)
2374                     RECHAIN_STMTS ($1, COMPOUND_BODY ($1));
2375                   $$ = NULL_TREE; }
2376         | BREAK ';'
2377                 { stmt_count++;
2378                   $$ = add_stmt (build_break_stmt ()); }
2379         | CONTINUE ';'
2380                 { stmt_count++;
2381                   $$ = add_stmt (build_continue_stmt ()); }
2382         | RETURN ';'
2383                 { stmt_count++;
2384                   $$ = c_expand_return (NULL_TREE); }
2385         | RETURN expr ';'
2386                 { stmt_count++;
2387                   $$ = c_expand_return ($2); }
2388         | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
2389                 { stmt_count++;
2390                   $$ = simple_asm_stmt ($4); }
2391         /* This is the case with just output operands.  */
2392         | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
2393                 { stmt_count++;
2394                   $$ = build_asm_stmt ($2, $4, $6, NULL_TREE, NULL_TREE); }
2395         /* This is the case with input operands as well.  */
2396         | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
2397           asm_operands ')' ';'
2398                 { stmt_count++;
2399                   $$ = build_asm_stmt ($2, $4, $6, $8, NULL_TREE); }
2400         /* This is the case with clobbered registers as well.  */
2401         | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
2402           asm_operands ':' asm_clobbers ')' ';'
2403                 { stmt_count++;
2404                   $$ = build_asm_stmt ($2, $4, $6, $8, $10); }
2405         | GOTO identifier ';'
2406                 { tree decl;
2407                   stmt_count++;
2408                   decl = lookup_label ($2);
2409                   if (decl != 0)
2410                     {
2411                       TREE_USED (decl) = 1;
2412                       $$ = add_stmt (build_stmt (GOTO_STMT, decl));
2413                     }
2414                   else
2415                     $$ = NULL_TREE;
2416                 }
2417         | GOTO '*' expr ';'
2418                 { if (pedantic)
2419                     pedwarn ("ISO C forbids `goto *expr;'");
2420                   stmt_count++;
2421                   $3 = convert (ptr_type_node, $3);
2422                   $$ = add_stmt (build_stmt (GOTO_STMT, $3)); }
2423         | ';'
2424                 { $$ = NULL_TREE; }
2425         ;
2426
2427 /* Any kind of label, including jump labels and case labels.
2428    ANSI C accepts labels only before statements, but we allow them
2429    also at the end of a compound statement.  */
2430
2431 label:    CASE expr_no_commas ':'
2432                 { stmt_count++;
2433                   $$ = do_case ($2, NULL_TREE); }
2434         | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
2435                 { stmt_count++;
2436                   $$ = do_case ($2, $4); }
2437         | DEFAULT ':'
2438                 { stmt_count++;
2439                   $$ = do_case (NULL_TREE, NULL_TREE); }
2440         | identifier save_filename save_lineno ':' maybe_attribute
2441                 { tree label = define_label ($2, $3, $1);
2442                   stmt_count++;
2443                   if (label)
2444                     {
2445                       decl_attributes (&label, $5, 0);
2446                       $$ = add_stmt (build_stmt (LABEL_STMT, label));
2447                     }
2448                   else
2449                     $$ = NULL_TREE;
2450                 }
2451         ;
2452
2453 /* Either a type-qualifier or nothing.  First thing in an `asm' statement.  */
2454
2455 maybe_type_qual:
2456         /* empty */
2457                 { emit_line_note (input_filename, lineno);
2458                   $$ = NULL_TREE; }
2459         | TYPE_QUAL
2460                 { emit_line_note (input_filename, lineno); }
2461         ;
2462
2463 xexpr:
2464         /* empty */
2465                 { $$ = NULL_TREE; }
2466         | expr
2467         ;
2468
2469 /* These are the operands other than the first string and colon
2470    in  asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x))  */
2471 asm_operands: /* empty */
2472                 { $$ = NULL_TREE; }
2473         | nonnull_asm_operands
2474         ;
2475
2476 nonnull_asm_operands:
2477           asm_operand
2478         | nonnull_asm_operands ',' asm_operand
2479                 { $$ = chainon ($1, $3); }
2480         ;
2481
2482 asm_operand:
2483           STRING '(' expr ')'
2484                 { $$ = build_tree_list (build_tree_list (NULL_TREE, $1), $3); }
2485         | '[' identifier ']' STRING '(' expr ')'
2486                 { $2 = build_string (IDENTIFIER_LENGTH ($2),
2487                                      IDENTIFIER_POINTER ($2));
2488                   $$ = build_tree_list (build_tree_list ($2, $4), $6); }
2489         ;
2490
2491 asm_clobbers:
2492           STRING
2493                 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
2494         | asm_clobbers ',' STRING
2495                 { $$ = tree_cons (NULL_TREE, $3, $1); }
2496         ;
2497 \f
2498 /* This is what appears inside the parens in a function declarator.
2499    Its value is a list of ..._TYPE nodes.  Attributes must appear here
2500    to avoid a conflict with their appearance after an open parenthesis
2501    in an abstract declarator, as in
2502    "void bar (int (__attribute__((__mode__(SI))) int foo));".  */
2503 parmlist:
2504           maybe_attribute
2505                 { pushlevel (0);
2506                   clear_parm_order ();
2507                   declare_parm_level (0); }
2508           parmlist_1
2509                 { $$ = $3;
2510                   parmlist_tags_warning ();
2511                   poplevel (0, 0, 0); }
2512         ;
2513
2514 parmlist_1:
2515           parmlist_2 ')'
2516         | parms ';'
2517                 { tree parm;
2518                   if (pedantic)
2519                     pedwarn ("ISO C forbids forward parameter declarations");
2520                   /* Mark the forward decls as such.  */
2521                   for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2522                     TREE_ASM_WRITTEN (parm) = 1;
2523                   clear_parm_order (); }
2524           maybe_attribute
2525                 { /* Dummy action so attributes are in known place
2526                      on parser stack.  */ }
2527           parmlist_1
2528                 { $$ = $6; }
2529         | error ')'
2530                 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2531         ;
2532
2533 /* This is what appears inside the parens in a function declarator.
2534    Is value is represented in the format that grokdeclarator expects.  */
2535 parmlist_2:  /* empty */
2536                 { $$ = get_parm_info (0); }
2537         | ELLIPSIS
2538                 { $$ = get_parm_info (0);
2539                   /* Gcc used to allow this as an extension.  However, it does
2540                      not work for all targets, and thus has been disabled.
2541                      Also, since func (...) and func () are indistinguishable,
2542                      it caused problems with the code in expand_builtin which
2543                      tries to verify that BUILT_IN_NEXT_ARG is being used
2544                      correctly.  */
2545                   error ("ISO C requires a named argument before `...'");
2546                 }
2547         | parms
2548                 { $$ = get_parm_info (1); }
2549         | parms ',' ELLIPSIS
2550                 { $$ = get_parm_info (0); }
2551         ;
2552
2553 parms:
2554         firstparm
2555                 { push_parm_decl ($1); }
2556         | parms ',' parm
2557                 { push_parm_decl ($3); }
2558         ;
2559
2560 /* A single parameter declaration or parameter type name,
2561    as found in a parmlist.  */
2562 parm:
2563           declspecs_ts setspecs parm_declarator maybe_attribute
2564                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2565                                                          $3),
2566                                         chainon ($4, all_prefix_attributes));
2567                   POP_DECLSPEC_STACK; }
2568         | declspecs_ts setspecs notype_declarator maybe_attribute
2569                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2570                                                          $3),
2571                                         chainon ($4, all_prefix_attributes));
2572                   POP_DECLSPEC_STACK; }
2573         | declspecs_ts setspecs absdcl_maybe_attribute
2574                 { $$ = $3;
2575                   POP_DECLSPEC_STACK; }
2576         | declspecs_nots setspecs notype_declarator maybe_attribute
2577                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2578                                                          $3),
2579                                         chainon ($4, all_prefix_attributes));
2580                   POP_DECLSPEC_STACK; }
2581
2582         | declspecs_nots setspecs absdcl_maybe_attribute
2583                 { $$ = $3;
2584                   POP_DECLSPEC_STACK; }
2585         ;
2586
2587 /* The first parm, which must suck attributes from off the top of the parser
2588    stack.  */
2589 firstparm:
2590           declspecs_ts_nosa setspecs_fp parm_declarator maybe_attribute
2591                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2592                                                          $3),
2593                                         chainon ($4, all_prefix_attributes));
2594                   POP_DECLSPEC_STACK; }
2595         | declspecs_ts_nosa setspecs_fp notype_declarator maybe_attribute
2596                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2597                                                          $3),
2598                                         chainon ($4, all_prefix_attributes));
2599                   POP_DECLSPEC_STACK; }
2600         | declspecs_ts_nosa setspecs_fp absdcl_maybe_attribute
2601                 { $$ = $3;
2602                   POP_DECLSPEC_STACK; }
2603         | declspecs_nots_nosa setspecs_fp notype_declarator maybe_attribute
2604                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2605                                                          $3),
2606                                         chainon ($4, all_prefix_attributes));
2607                   POP_DECLSPEC_STACK; }
2608
2609         | declspecs_nots_nosa setspecs_fp absdcl_maybe_attribute
2610                 { $$ = $3;
2611                   POP_DECLSPEC_STACK; }
2612         ;
2613
2614 setspecs_fp:
2615           setspecs
2616                 { prefix_attributes = chainon (prefix_attributes, $<ttype>-2);
2617                   all_prefix_attributes = prefix_attributes; }
2618         ;
2619
2620 /* This is used in a function definition
2621    where either a parmlist or an identifier list is ok.
2622    Its value is a list of ..._TYPE nodes or a list of identifiers.  */
2623 parmlist_or_identifiers:
2624           maybe_attribute
2625                 { pushlevel (0);
2626                   clear_parm_order ();
2627                   declare_parm_level (1); }
2628           parmlist_or_identifiers_1
2629                 { $$ = $3;
2630                   parmlist_tags_warning ();
2631                   poplevel (0, 0, 0); }
2632         ;
2633
2634 parmlist_or_identifiers_1:
2635           parmlist_1
2636         | identifiers ')'
2637                 { tree t;
2638                   for (t = $1; t; t = TREE_CHAIN (t))
2639                     if (TREE_VALUE (t) == NULL_TREE)
2640                       error ("`...' in old-style identifier list");
2641                   $$ = tree_cons (NULL_TREE, NULL_TREE, $1);
2642
2643                   /* Make sure we have a parmlist after attributes.  */
2644                   if ($<ttype>-1 != 0
2645                       && (TREE_CODE ($$) != TREE_LIST
2646                           || TREE_PURPOSE ($$) == 0
2647                           || TREE_CODE (TREE_PURPOSE ($$)) != PARM_DECL))
2648                     YYERROR1;
2649                 }
2650         ;
2651
2652 /* A nonempty list of identifiers.  */
2653 identifiers:
2654         IDENTIFIER
2655                 { $$ = build_tree_list (NULL_TREE, $1); }
2656         | identifiers ',' IDENTIFIER
2657                 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2658         ;
2659
2660 /* A nonempty list of identifiers, including typenames.  */
2661 identifiers_or_typenames:
2662         identifier
2663                 { $$ = build_tree_list (NULL_TREE, $1); }
2664         | identifiers_or_typenames ',' identifier
2665                 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2666         ;
2667
2668 extension:
2669         EXTENSION
2670                 { $$ = SAVE_EXT_FLAGS();
2671                   pedantic = 0;
2672                   warn_pointer_arith = 0;
2673                   warn_traditional = 0;
2674                   flag_iso = 0; }
2675         ;
2676 \f
2677 ifobjc
2678 /* Objective-C productions.  */
2679
2680 objcdef:
2681           classdef
2682         | classdecl
2683         | aliasdecl
2684         | protocoldef
2685         | methoddef
2686         | END
2687                 {
2688                   if (objc_implementation_context)
2689                     {
2690                       finish_class (objc_implementation_context);
2691                       objc_ivar_chain = NULL_TREE;
2692                       objc_implementation_context = NULL_TREE;
2693                     }
2694                   else
2695                     warning ("`@end' must appear in an implementation context");
2696                 }
2697         ;
2698
2699 /* A nonempty list of identifiers.  */
2700 identifier_list:
2701         identifier
2702                 { $$ = build_tree_list (NULL_TREE, $1); }
2703         | identifier_list ',' identifier
2704                 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2705         ;
2706
2707 classdecl:
2708           CLASS identifier_list ';'
2709                 {
2710                   objc_declare_class ($2);
2711                 }
2712         ;
2713
2714 aliasdecl:
2715           ALIAS identifier identifier ';'
2716                 {
2717                   objc_declare_alias ($2, $3);
2718                 }
2719         ;
2720
2721 classdef:
2722           INTERFACE identifier protocolrefs '{'
2723                 {
2724                   objc_interface_context = objc_ivar_context
2725                     = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2726                   objc_public_flag = 0;
2727                 }
2728           ivar_decl_list '}'
2729                 {
2730                   continue_class (objc_interface_context);
2731                 }
2732           methodprotolist
2733           END
2734                 {
2735                   finish_class (objc_interface_context);
2736                   objc_interface_context = NULL_TREE;
2737                 }
2738
2739         | INTERFACE identifier protocolrefs
2740                 {
2741                   objc_interface_context
2742                     = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2743                   continue_class (objc_interface_context);
2744                 }
2745           methodprotolist
2746           END
2747                 {
2748                   finish_class (objc_interface_context);
2749                   objc_interface_context = NULL_TREE;
2750                 }
2751
2752         | INTERFACE identifier ':' identifier protocolrefs '{'
2753                 {
2754                   objc_interface_context = objc_ivar_context
2755                     = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2756                   objc_public_flag = 0;
2757                 }
2758           ivar_decl_list '}'
2759                 {
2760                   continue_class (objc_interface_context);
2761                 }
2762           methodprotolist
2763           END
2764                 {
2765                   finish_class (objc_interface_context);
2766                   objc_interface_context = NULL_TREE;
2767                 }
2768
2769         | INTERFACE identifier ':' identifier protocolrefs
2770                 {
2771                   objc_interface_context
2772                     = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2773                   continue_class (objc_interface_context);
2774                 }
2775           methodprotolist
2776           END
2777                 {
2778                   finish_class (objc_interface_context);
2779                   objc_interface_context = NULL_TREE;
2780                 }
2781
2782         | IMPLEMENTATION identifier '{'
2783                 {
2784                   objc_implementation_context = objc_ivar_context
2785                     = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2786                   objc_public_flag = 0;
2787                 }
2788           ivar_decl_list '}'
2789                 {
2790                   objc_ivar_chain
2791                     = continue_class (objc_implementation_context);
2792                 }
2793
2794         | IMPLEMENTATION identifier
2795                 {
2796                   objc_implementation_context
2797                     = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2798                   objc_ivar_chain
2799                     = continue_class (objc_implementation_context);
2800                 }
2801
2802         | IMPLEMENTATION identifier ':' identifier '{'
2803                 {
2804                   objc_implementation_context = objc_ivar_context
2805                     = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2806                   objc_public_flag = 0;
2807                 }
2808           ivar_decl_list '}'
2809                 {
2810                   objc_ivar_chain
2811                     = continue_class (objc_implementation_context);
2812                 }
2813
2814         | IMPLEMENTATION identifier ':' identifier
2815                 {
2816                   objc_implementation_context
2817                     = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2818                   objc_ivar_chain
2819                     = continue_class (objc_implementation_context);
2820                 }
2821
2822         | INTERFACE identifier '(' identifier ')' protocolrefs
2823                 {
2824                   objc_interface_context
2825                     = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2826                   continue_class (objc_interface_context);
2827                 }
2828           methodprotolist
2829           END
2830                 {
2831                   finish_class (objc_interface_context);
2832                   objc_interface_context = NULL_TREE;
2833                 }
2834
2835         | IMPLEMENTATION identifier '(' identifier ')'
2836                 {
2837                   objc_implementation_context
2838                     = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2839                   objc_ivar_chain
2840                     = continue_class (objc_implementation_context);
2841                 }
2842         ;
2843
2844 protocoldef:
2845           PROTOCOL identifier protocolrefs
2846                 {
2847                   objc_pq_context = 1;
2848                   objc_interface_context
2849                     = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2850                 }
2851           methodprotolist END
2852                 {
2853                   objc_pq_context = 0;
2854                   finish_protocol(objc_interface_context);
2855                   objc_interface_context = NULL_TREE;
2856                 }
2857         /* The @protocol forward-declaration production introduces a
2858            reduce/reduce conflict on ';', which should be resolved in
2859            favor of the production 'identifier_list -> identifier'.  */
2860         | PROTOCOL identifier_list ';'
2861                 {
2862                   objc_declare_protocols ($2);
2863                 }
2864         ;
2865
2866 protocolrefs:
2867           /* empty */
2868                 {
2869                   $$ = NULL_TREE;
2870                 }
2871         | non_empty_protocolrefs
2872         ;
2873
2874 non_empty_protocolrefs:
2875           ARITHCOMPARE identifier_list ARITHCOMPARE
2876                 {
2877                   if ($1 == LT_EXPR && $3 == GT_EXPR)
2878                     $$ = $2;
2879                   else
2880                     YYERROR1;
2881                 }
2882         ;
2883
2884 ivar_decl_list:
2885           ivar_decl_list visibility_spec ivar_decls
2886         | ivar_decls
2887         ;
2888
2889 visibility_spec:
2890           PRIVATE { objc_public_flag = 2; }
2891         | PROTECTED { objc_public_flag = 0; }
2892         | PUBLIC { objc_public_flag = 1; }
2893         ;
2894
2895 ivar_decls:
2896           /* empty */
2897                 {
2898                   $$ = NULL_TREE;
2899                 }
2900         | ivar_decls ivar_decl ';'
2901         | ivar_decls ';'
2902                 {
2903                   if (pedantic)
2904                     pedwarn ("extra semicolon in struct or union specified");
2905                 }
2906         ;
2907
2908
2909 /* There is a shift-reduce conflict here, because `components' may
2910    start with a `typename'.  It happens that shifting (the default resolution)
2911    does the right thing, because it treats the `typename' as part of
2912    a `typed_typespecs'.
2913
2914    It is possible that this same technique would allow the distinction
2915    between `notype_initdecls' and `initdecls' to be eliminated.
2916    But I am being cautious and not trying it.  */
2917
2918 ivar_decl:
2919         declspecs_nosc_ts setspecs ivars
2920                 { $$ = $3;
2921                   POP_DECLSPEC_STACK; }
2922         | declspecs_nosc_nots setspecs ivars
2923                 { $$ = $3;
2924                   POP_DECLSPEC_STACK; }
2925         | error
2926                 { $$ = NULL_TREE; }
2927         ;
2928
2929 ivars:
2930           /* empty */
2931                 { $$ = NULL_TREE; }
2932         | ivar_declarator
2933         | ivars ',' maybe_resetattrs ivar_declarator
2934         ;
2935
2936 ivar_declarator:
2937           declarator
2938                 {
2939                   $$ = add_instance_variable (objc_ivar_context,
2940                                               objc_public_flag,
2941                                               $1, current_declspecs,
2942                                               NULL_TREE);
2943                 }
2944         | declarator ':' expr_no_commas
2945                 {
2946                   $$ = add_instance_variable (objc_ivar_context,
2947                                               objc_public_flag,
2948                                               $1, current_declspecs, $3);
2949                 }
2950         | ':' expr_no_commas
2951                 {
2952                   $$ = add_instance_variable (objc_ivar_context,
2953                                               objc_public_flag,
2954                                               NULL_TREE,
2955                                               current_declspecs, $2);
2956                 }
2957         ;
2958
2959 methodtype:
2960           '+'
2961                 { objc_inherit_code = CLASS_METHOD_DECL; }
2962         | '-'
2963                 { objc_inherit_code = INSTANCE_METHOD_DECL; }
2964         ;
2965
2966 methoddef:
2967           methodtype
2968                 {
2969                   objc_pq_context = 1;
2970                   if (!objc_implementation_context)
2971                     fatal_error ("method definition not in class context");
2972                 }
2973           methoddecl
2974                 {
2975                   objc_pq_context = 0;
2976                   if (objc_inherit_code == CLASS_METHOD_DECL)
2977                     add_class_method (objc_implementation_context, $3);
2978                   else
2979                     add_instance_method (objc_implementation_context, $3);
2980                   start_method_def ($3);
2981                 }
2982           optarglist
2983                 {
2984                   continue_method_def ();
2985                 }
2986           compstmt_or_error
2987                 {
2988                   finish_method_def ();
2989                 }
2990         ;
2991
2992 /* the reason for the strange actions in this rule
2993  is so that notype_initdecls when reached via datadef
2994  can find a valid list of type and sc specs in $0. */
2995
2996 methodprotolist:
2997           /* empty  */
2998         | {$<ttype>$ = NULL_TREE; } methodprotolist2
2999         ;
3000
3001 methodprotolist2:                /* eliminates a shift/reduce conflict */
3002            methodproto
3003         |  datadef
3004         | methodprotolist2 methodproto
3005         | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
3006         ;
3007
3008 semi_or_error:
3009           ';'
3010         | error
3011         ;
3012
3013 methodproto:
3014           methodtype
3015                 {
3016                   /* Remember protocol qualifiers in prototypes.  */
3017                   objc_pq_context = 1;
3018                 }
3019           methoddecl
3020                 {
3021                   /* Forget protocol qualifiers here.  */
3022                   objc_pq_context = 0;
3023                   if (objc_inherit_code == CLASS_METHOD_DECL)
3024                     add_class_method (objc_interface_context, $3);
3025                   else
3026                     add_instance_method (objc_interface_context, $3);
3027                 }
3028           semi_or_error
3029         ;
3030
3031 methoddecl:
3032           '(' typename ')' unaryselector
3033                 {
3034                   $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
3035                 }
3036
3037         | unaryselector
3038                 {
3039                   $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
3040                 }
3041
3042         | '(' typename ')' keywordselector optparmlist
3043                 {
3044                   $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
3045                 }
3046
3047         | keywordselector optparmlist
3048                 {
3049                   $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
3050                 }
3051         ;
3052
3053 /* "optarglist" assumes that start_method_def has already been called...
3054    if it is not, the "xdecls" will not be placed in the proper scope */
3055
3056 optarglist:
3057           /* empty */
3058         | ';' myxdecls
3059         ;
3060
3061 /* to get around the following situation: "int foo (int a) int b; {}" that
3062    is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
3063
3064 myxdecls:
3065           /* empty */
3066         | mydecls
3067         ;
3068
3069 mydecls:
3070         mydecl
3071         | errstmt
3072         | mydecls mydecl
3073         | mydecl errstmt
3074         ;
3075
3076 mydecl:
3077         declspecs_ts setspecs myparms ';'
3078                 { POP_DECLSPEC_STACK; }
3079         | declspecs_ts ';'
3080                 { shadow_tag ($1); }
3081         | declspecs_nots ';'
3082                 { pedwarn ("empty declaration"); }
3083         ;
3084
3085 myparms:
3086         myparm
3087                 { push_parm_decl ($1); }
3088         | myparms ',' myparm
3089                 { push_parm_decl ($3); }
3090         ;
3091
3092 /* A single parameter declaration or parameter type name,
3093    as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
3094
3095 myparm:
3096           parm_declarator maybe_attribute
3097                 { $$ = build_tree_list (build_tree_list (current_declspecs,
3098                                                          $1),
3099                                         chainon ($2, all_prefix_attributes)); }
3100         | notype_declarator maybe_attribute
3101                 { $$ = build_tree_list (build_tree_list (current_declspecs,
3102                                                          $1),
3103                                         chainon ($2, all_prefix_attributes)); }
3104         | absdcl_maybe_attribute
3105                 { $$ = $1; }
3106         ;
3107
3108 optparmlist:
3109           /* empty */
3110                 {
3111                   $$ = NULL_TREE;
3112                 }
3113         | ',' ELLIPSIS
3114                 {
3115                   /* oh what a kludge! */
3116                   $$ = objc_ellipsis_node;
3117                 }
3118         | ','
3119                 {
3120                   pushlevel (0);
3121                 }
3122           parmlist_2
3123                 {
3124                   /* returns a tree list node generated by get_parm_info */
3125                   $$ = $3;
3126                   poplevel (0, 0, 0);
3127                 }
3128         ;
3129
3130 unaryselector:
3131           selector
3132         ;
3133
3134 keywordselector:
3135           keyworddecl
3136
3137         | keywordselector keyworddecl
3138                 {
3139                   $$ = chainon ($1, $2);
3140                 }
3141         ;
3142
3143 selector:
3144           IDENTIFIER
3145         | TYPENAME
3146         | CLASSNAME
3147         | OBJECTNAME
3148         | reservedwords
3149         ;
3150
3151 reservedwords:
3152           ENUM | STRUCT | UNION | IF | ELSE | WHILE | DO | FOR
3153         | SWITCH | CASE | DEFAULT | BREAK | CONTINUE | RETURN
3154         | GOTO | ASM_KEYWORD | SIZEOF | TYPEOF | ALIGNOF
3155         | TYPESPEC | TYPE_QUAL
3156         ;
3157
3158 keyworddecl:
3159           selector ':' '(' typename ')' identifier
3160                 {
3161                   $$ = build_keyword_decl ($1, $4, $6);
3162                 }
3163
3164         | selector ':' identifier
3165                 {
3166                   $$ = build_keyword_decl ($1, NULL_TREE, $3);
3167                 }
3168
3169         | ':' '(' typename ')' identifier
3170                 {
3171                   $$ = build_keyword_decl (NULL_TREE, $3, $5);
3172                 }
3173
3174         | ':' identifier
3175                 {
3176                   $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
3177                 }
3178         ;
3179
3180 messageargs:
3181           selector
3182         | keywordarglist
3183         ;
3184
3185 keywordarglist:
3186           keywordarg
3187         | keywordarglist keywordarg
3188                 {
3189                   $$ = chainon ($1, $2);
3190                 }
3191         ;
3192
3193
3194 keywordexpr:
3195           nonnull_exprlist
3196                 {
3197                   if (TREE_CHAIN ($1) == NULL_TREE)
3198                     /* just return the expr., remove a level of indirection */
3199                     $$ = TREE_VALUE ($1);
3200                   else
3201                     /* we have a comma expr., we will collapse later */
3202                     $$ = $1;
3203                 }
3204         ;
3205
3206 keywordarg:
3207           selector ':' keywordexpr
3208                 {
3209                   $$ = build_tree_list ($1, $3);
3210                 }
3211         | ':' keywordexpr
3212                 {
3213                   $$ = build_tree_list (NULL_TREE, $2);
3214                 }
3215         ;
3216
3217 receiver:
3218           expr
3219         | CLASSNAME
3220                 {
3221                   $$ = get_class_reference ($1);
3222                 }
3223         ;
3224
3225 objcmessageexpr:
3226           '['
3227                 { objc_receiver_context = 1; }
3228           receiver
3229                 { objc_receiver_context = 0; }
3230           messageargs ']'
3231                 {
3232                   $$ = build_tree_list ($3, $5);
3233                 }
3234         ;
3235
3236 selectorarg:
3237           selector
3238         | keywordnamelist
3239         ;
3240
3241 keywordnamelist:
3242           keywordname
3243         | keywordnamelist keywordname
3244                 {
3245                   $$ = chainon ($1, $2);
3246                 }
3247         ;
3248
3249 keywordname:
3250           selector ':'
3251                 {
3252                   $$ = build_tree_list ($1, NULL_TREE);
3253                 }
3254         | ':'
3255                 {
3256                   $$ = build_tree_list (NULL_TREE, NULL_TREE);
3257                 }
3258         ;
3259
3260 objcselectorexpr:
3261           SELECTOR '(' selectorarg ')'
3262                 {
3263                   $$ = $3;
3264                 }
3265         ;
3266
3267 objcprotocolexpr:
3268           PROTOCOL '(' identifier ')'
3269                 {
3270                   $$ = $3;
3271                 }
3272         ;
3273
3274 /* extension to support C-structures in the archiver */
3275
3276 objcencodeexpr:
3277           ENCODE '(' typename ')'
3278                 {
3279                   $$ = groktypename ($3);
3280                 }
3281         ;
3282
3283 end ifobjc
3284 %%
3285
3286 /* yylex() is a thin wrapper around c_lex(), all it does is translate
3287    cpplib.h's token codes into yacc's token codes.  */
3288
3289 static enum cpp_ttype last_token;
3290
3291 /* The reserved keyword table.  */
3292 struct resword
3293 {
3294   const char *word;
3295   ENUM_BITFIELD(rid) rid : 16;
3296   unsigned int disable   : 16;
3297 };
3298
3299 /* Disable mask.  Keywords are disabled if (reswords[i].disable & mask) is
3300    _true_.  */
3301 #define D_C89   0x01    /* not in C89 */
3302 #define D_EXT   0x02    /* GCC extension */
3303 #define D_EXT89 0x04    /* GCC extension incorporated in C99 */
3304 #define D_OBJC  0x08    /* Objective C only */
3305
3306 static const struct resword reswords[] =
3307 {
3308   { "_Bool",            RID_BOOL,       0 },
3309   { "_Complex",         RID_COMPLEX,    0 },
3310   { "__FUNCTION__",     RID_FUNCTION_NAME, 0 },
3311   { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
3312   { "__alignof",        RID_ALIGNOF,    0 },
3313   { "__alignof__",      RID_ALIGNOF,    0 },
3314   { "__asm",            RID_ASM,        0 },
3315   { "__asm__",          RID_ASM,        0 },
3316   { "__attribute",      RID_ATTRIBUTE,  0 },
3317   { "__attribute__",    RID_ATTRIBUTE,  0 },
3318   { "__bounded",        RID_BOUNDED,    0 },
3319   { "__bounded__",      RID_BOUNDED,    0 },
3320   { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
3321   { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
3322   { "__builtin_va_arg", RID_VA_ARG,     0 },
3323   { "__complex",        RID_COMPLEX,    0 },
3324   { "__complex__",      RID_COMPLEX,    0 },
3325   { "__const",          RID_CONST,      0 },
3326   { "__const__",        RID_CONST,      0 },
3327   { "__extension__",    RID_EXTENSION,  0 },
3328   { "__func__",         RID_C99_FUNCTION_NAME, 0 },
3329   { "__imag",           RID_IMAGPART,   0 },
3330   { "__imag__",         RID_IMAGPART,   0 },
3331   { "__inline",         RID_INLINE,     0 },
3332   { "__inline__",       RID_INLINE,     0 },
3333   { "__label__",        RID_LABEL,      0 },
3334   { "__ptrbase",        RID_PTRBASE,    0 },
3335   { "__ptrbase__",      RID_PTRBASE,    0 },
3336   { "__ptrextent",      RID_PTREXTENT,  0 },
3337   { "__ptrextent__",    RID_PTREXTENT,  0 },
3338   { "__ptrvalue",       RID_PTRVALUE,   0 },
3339   { "__ptrvalue__",     RID_PTRVALUE,   0 },
3340   { "__real",           RID_REALPART,   0 },
3341   { "__real__",         RID_REALPART,   0 },
3342   { "__restrict",       RID_RESTRICT,   0 },
3343   { "__restrict__",     RID_RESTRICT,   0 },
3344   { "__signed",         RID_SIGNED,     0 },
3345   { "__signed__",       RID_SIGNED,     0 },
3346   { "__thread",         RID_THREAD,     0 },
3347   { "__typeof",         RID_TYPEOF,     0 },
3348   { "__typeof__",       RID_TYPEOF,     0 },
3349   { "__unbounded",      RID_UNBOUNDED,  0 },
3350   { "__unbounded__",    RID_UNBOUNDED,  0 },
3351   { "__volatile",       RID_VOLATILE,   0 },
3352   { "__volatile__",     RID_VOLATILE,   0 },
3353   { "asm",              RID_ASM,        D_EXT },
3354   { "auto",             RID_AUTO,       0 },
3355   { "break",            RID_BREAK,      0 },
3356   { "case",             RID_CASE,       0 },
3357   { "char",             RID_CHAR,       0 },
3358   { "const",            RID_CONST,      0 },
3359   { "continue",         RID_CONTINUE,   0 },
3360   { "default",          RID_DEFAULT,    0 },
3361   { "do",               RID_DO,         0 },
3362   { "double",           RID_DOUBLE,     0 },
3363   { "else",             RID_ELSE,       0 },
3364   { "enum",             RID_ENUM,       0 },
3365   { "extern",           RID_EXTERN,     0 },
3366   { "float",            RID_FLOAT,      0 },
3367   { "for",              RID_FOR,        0 },
3368   { "goto",             RID_GOTO,       0 },
3369   { "if",               RID_IF,         0 },
3370   { "inline",           RID_INLINE,     D_EXT89 },
3371   { "int",              RID_INT,        0 },
3372   { "long",             RID_LONG,       0 },
3373   { "register",         RID_REGISTER,   0 },
3374   { "restrict",         RID_RESTRICT,   D_C89 },
3375   { "return",           RID_RETURN,     0 },
3376   { "short",            RID_SHORT,      0 },
3377   { "signed",           RID_SIGNED,     0 },
3378   { "sizeof",           RID_SIZEOF,     0 },
3379   { "static",           RID_STATIC,     0 },
3380   { "struct",           RID_STRUCT,     0 },
3381   { "switch",           RID_SWITCH,     0 },
3382   { "typedef",          RID_TYPEDEF,    0 },
3383   { "typeof",           RID_TYPEOF,     D_EXT },
3384   { "union",            RID_UNION,      0 },
3385   { "unsigned",         RID_UNSIGNED,   0 },
3386   { "void",             RID_VOID,       0 },
3387   { "volatile",         RID_VOLATILE,   0 },
3388   { "while",            RID_WHILE,      0 },
3389 ifobjc
3390   { "id",               RID_ID,                 D_OBJC },
3391
3392   /* These objc keywords are recognized only immediately after
3393      an '@'.  */
3394   { "class",            RID_AT_CLASS,           D_OBJC },
3395   { "compatibility_alias", RID_AT_ALIAS,        D_OBJC },
3396   { "defs",             RID_AT_DEFS,            D_OBJC },
3397   { "encode",           RID_AT_ENCODE,          D_OBJC },
3398   { "end",              RID_AT_END,             D_OBJC },
3399   { "implementation",   RID_AT_IMPLEMENTATION,  D_OBJC },
3400   { "interface",        RID_AT_INTERFACE,       D_OBJC },
3401   { "private",          RID_AT_PRIVATE,         D_OBJC },
3402   { "protected",        RID_AT_PROTECTED,       D_OBJC },
3403   { "protocol",         RID_AT_PROTOCOL,        D_OBJC },
3404   { "public",           RID_AT_PUBLIC,          D_OBJC },
3405   { "selector",         RID_AT_SELECTOR,        D_OBJC },
3406
3407   /* These are recognized only in protocol-qualifier context
3408      (see above) */
3409   { "bycopy",           RID_BYCOPY,             D_OBJC },
3410   { "byref",            RID_BYREF,              D_OBJC },
3411   { "in",               RID_IN,                 D_OBJC },
3412   { "inout",            RID_INOUT,              D_OBJC },
3413   { "oneway",           RID_ONEWAY,             D_OBJC },
3414   { "out",              RID_OUT,                D_OBJC },
3415 end ifobjc
3416 };
3417 #define N_reswords (sizeof reswords / sizeof (struct resword))
3418
3419 /* Table mapping from RID_* constants to yacc token numbers.
3420    Unfortunately we have to have entries for all the keywords in all
3421    three languages.  */
3422 static const short rid_to_yy[RID_MAX] =
3423 {
3424   /* RID_STATIC */      STATIC,
3425   /* RID_UNSIGNED */    TYPESPEC,
3426   /* RID_LONG */        TYPESPEC,
3427   /* RID_CONST */       TYPE_QUAL,
3428   /* RID_EXTERN */      SCSPEC,
3429   /* RID_REGISTER */    SCSPEC,
3430   /* RID_TYPEDEF */     SCSPEC,
3431   /* RID_SHORT */       TYPESPEC,
3432   /* RID_INLINE */      SCSPEC,
3433   /* RID_VOLATILE */    TYPE_QUAL,
3434   /* RID_SIGNED */      TYPESPEC,
3435   /* RID_AUTO */        SCSPEC,
3436   /* RID_RESTRICT */    TYPE_QUAL,
3437
3438   /* C extensions */
3439   /* RID_BOUNDED */     TYPE_QUAL,
3440   /* RID_UNBOUNDED */   TYPE_QUAL,
3441   /* RID_COMPLEX */     TYPESPEC,
3442   /* RID_THREAD */      SCSPEC,
3443
3444   /* C++ */
3445   /* RID_FRIEND */      0,
3446   /* RID_VIRTUAL */     0,
3447   /* RID_EXPLICIT */    0,
3448   /* RID_EXPORT */      0,
3449   /* RID_MUTABLE */     0,
3450
3451   /* ObjC */
3452   /* RID_IN */          TYPE_QUAL,
3453   /* RID_OUT */         TYPE_QUAL,
3454   /* RID_INOUT */       TYPE_QUAL,
3455   /* RID_BYCOPY */      TYPE_QUAL,
3456   /* RID_BYREF */       TYPE_QUAL,
3457   /* RID_ONEWAY */      TYPE_QUAL,
3458
3459   /* C */
3460   /* RID_INT */         TYPESPEC,
3461   /* RID_CHAR */        TYPESPEC,
3462   /* RID_FLOAT */       TYPESPEC,
3463   /* RID_DOUBLE */      TYPESPEC,
3464   /* RID_VOID */        TYPESPEC,
3465   /* RID_ENUM */        ENUM,
3466   /* RID_STRUCT */      STRUCT,
3467   /* RID_UNION */       UNION,
3468   /* RID_IF */          IF,
3469   /* RID_ELSE */        ELSE,
3470   /* RID_WHILE */       WHILE,
3471   /* RID_DO */          DO,
3472   /* RID_FOR */         FOR,
3473   /* RID_SWITCH */      SWITCH,
3474   /* RID_CASE */        CASE,
3475   /* RID_DEFAULT */     DEFAULT,
3476   /* RID_BREAK */       BREAK,
3477   /* RID_CONTINUE */    CONTINUE,
3478   /* RID_RETURN */      RETURN,
3479   /* RID_GOTO */        GOTO,
3480   /* RID_SIZEOF */      SIZEOF,
3481
3482   /* C extensions */
3483   /* RID_ASM */         ASM_KEYWORD,
3484   /* RID_TYPEOF */      TYPEOF,
3485   /* RID_ALIGNOF */     ALIGNOF,
3486   /* RID_ATTRIBUTE */   ATTRIBUTE,
3487   /* RID_VA_ARG */      VA_ARG,
3488   /* RID_EXTENSION */   EXTENSION,
3489   /* RID_IMAGPART */    IMAGPART,
3490   /* RID_REALPART */    REALPART,
3491   /* RID_LABEL */       LABEL,
3492   /* RID_PTRBASE */     PTR_BASE,
3493   /* RID_PTREXTENT */   PTR_EXTENT,
3494   /* RID_PTRVALUE */    PTR_VALUE,
3495
3496   /* RID_CHOOSE_EXPR */                 CHOOSE_EXPR,
3497   /* RID_TYPES_COMPATIBLE_P */          TYPES_COMPATIBLE_P,
3498
3499   /* RID_FUNCTION_NAME */               STRING_FUNC_NAME,
3500   /* RID_PRETTY_FUNCTION_NAME */        STRING_FUNC_NAME,
3501   /* RID_C99_FUNCTION_NAME */           VAR_FUNC_NAME,
3502
3503   /* C++ */
3504   /* RID_BOOL */        TYPESPEC,
3505   /* RID_WCHAR */       0,
3506   /* RID_CLASS */       0,
3507   /* RID_PUBLIC */      0,
3508   /* RID_PRIVATE */     0,
3509   /* RID_PROTECTED */   0,
3510   /* RID_TEMPLATE */    0,
3511   /* RID_NULL */        0,
3512   /* RID_CATCH */       0,
3513   /* RID_DELETE */      0,
3514   /* RID_FALSE */       0,
3515   /* RID_NAMESPACE */   0,
3516   /* RID_NEW */         0,
3517   /* RID_OPERATOR */    0,
3518   /* RID_THIS */        0,
3519   /* RID_THROW */       0,
3520   /* RID_TRUE */        0,
3521   /* RID_TRY */         0,
3522   /* RID_TYPENAME */    0,
3523   /* RID_TYPEID */      0,
3524   /* RID_USING */       0,
3525
3526   /* casts */
3527   /* RID_CONSTCAST */   0,
3528   /* RID_DYNCAST */     0,
3529   /* RID_REINTCAST */   0,
3530   /* RID_STATCAST */    0,
3531
3532   /* alternate spellings */
3533   /* RID_AND */         0,
3534   /* RID_AND_EQ */      0,
3535   /* RID_NOT */         0,
3536   /* RID_NOT_EQ */      0,
3537   /* RID_OR */          0,
3538   /* RID_OR_EQ */       0,
3539   /* RID_XOR */         0,
3540   /* RID_XOR_EQ */      0,
3541   /* RID_BITAND */      0,
3542   /* RID_BITOR */       0,
3543   /* RID_COMPL */       0,
3544
3545   /* Objective C */
3546   /* RID_ID */                  OBJECTNAME,
3547   /* RID_AT_ENCODE */           ENCODE,
3548   /* RID_AT_END */              END,
3549   /* RID_AT_CLASS */            CLASS,
3550   /* RID_AT_ALIAS */            ALIAS,
3551   /* RID_AT_DEFS */             DEFS,
3552   /* RID_AT_PRIVATE */          PRIVATE,
3553   /* RID_AT_PROTECTED */        PROTECTED,
3554   /* RID_AT_PUBLIC */           PUBLIC,
3555   /* RID_AT_PROTOCOL */         PROTOCOL,
3556   /* RID_AT_SELECTOR */         SELECTOR,
3557   /* RID_AT_INTERFACE */        INTERFACE,
3558   /* RID_AT_IMPLEMENTATION */   IMPLEMENTATION
3559 };
3560
3561 static void
3562 init_reswords ()
3563 {
3564   unsigned int i;
3565   tree id;
3566   int mask = (flag_isoc99 ? 0 : D_C89)
3567               | (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0);
3568
3569   if (c_language != clk_objective_c)
3570      mask |= D_OBJC;
3571
3572   /* It is not necessary to register ridpointers as a GC root, because
3573      all the trees it points to are permanently interned in the
3574      get_identifier hash anyway.  */
3575   ridpointers = (tree *) xcalloc ((int) RID_MAX, sizeof (tree));
3576   for (i = 0; i < N_reswords; i++)
3577     {
3578       /* If a keyword is disabled, do not enter it into the table
3579          and so create a canonical spelling that isn't a keyword.  */
3580       if (reswords[i].disable & mask)
3581         continue;
3582
3583       id = get_identifier (reswords[i].word);
3584       C_RID_CODE (id) = reswords[i].rid;
3585       C_IS_RESERVED_WORD (id) = 1;
3586       ridpointers [(int) reswords[i].rid] = id;
3587     }
3588 }
3589
3590 #define NAME(type) cpp_type2name (type)
3591
3592 static void
3593 yyerror (msgid)
3594      const char *msgid;
3595 {
3596   const char *string = _(msgid);
3597
3598   if (last_token == CPP_EOF)
3599     error ("%s at end of input", string);
3600   else if (last_token == CPP_CHAR || last_token == CPP_WCHAR)
3601     {
3602       unsigned int val = TREE_INT_CST_LOW (yylval.ttype);
3603       const char *const ell = (last_token == CPP_CHAR) ? "" : "L";
3604       if (val <= UCHAR_MAX && ISGRAPH (val))
3605         error ("%s before %s'%c'", string, ell, val);
3606       else
3607         error ("%s before %s'\\x%x'", string, ell, val);
3608     }
3609   else if (last_token == CPP_STRING
3610            || last_token == CPP_WSTRING)
3611     error ("%s before string constant", string);
3612   else if (last_token == CPP_NUMBER)
3613     error ("%s before numeric constant", string);
3614   else if (last_token == CPP_NAME)
3615     error ("%s before \"%s\"", string, IDENTIFIER_POINTER (yylval.ttype));
3616   else
3617     error ("%s before '%s' token", string, NAME(last_token));
3618 }
3619
3620 static int
3621 yylexname ()
3622 {
3623   tree decl;
3624
3625 ifobjc
3626   int objc_force_identifier = objc_need_raw_identifier;
3627   OBJC_NEED_RAW_IDENTIFIER (0);
3628 end ifobjc
3629
3630   if (C_IS_RESERVED_WORD (yylval.ttype))
3631     {
3632       enum rid rid_code = C_RID_CODE (yylval.ttype);
3633
3634 ifobjc
3635       /* Turn non-typedefed refs to "id" into plain identifiers; this
3636          allows constructs like "void foo(id id);" to work.  */
3637       if (rid_code == RID_ID)
3638       {
3639         decl = lookup_name (yylval.ttype);
3640         if (decl == NULL_TREE || TREE_CODE (decl) != TYPE_DECL)
3641           return IDENTIFIER;
3642       }
3643
3644       if (!OBJC_IS_AT_KEYWORD (rid_code)
3645           && (!OBJC_IS_PQ_KEYWORD (rid_code) || objc_pq_context))
3646 end ifobjc
3647       {
3648         int yycode = rid_to_yy[(int) rid_code];
3649         if (yycode == STRING_FUNC_NAME)
3650           {
3651             /* __FUNCTION__ and __PRETTY_FUNCTION__ get converted
3652                to string constants.  */
3653             const char *name = fname_string (rid_code);
3654
3655             yylval.ttype = build_string (strlen (name) + 1, name);
3656             C_ARTIFICIAL_STRING_P (yylval.ttype) = 1;
3657             last_token = CPP_STRING;  /* so yyerror won't choke */
3658             return STRING;
3659           }
3660
3661         /* Return the canonical spelling for this keyword.  */
3662         yylval.ttype = ridpointers[(int) rid_code];
3663         return yycode;
3664       }
3665     }
3666
3667   decl = lookup_name (yylval.ttype);
3668   if (decl)
3669     {
3670       if (TREE_CODE (decl) == TYPE_DECL)
3671         return TYPENAME;
3672     }
3673 ifobjc
3674   else
3675     {
3676       tree objc_interface_decl = is_class_name (yylval.ttype);
3677       /* ObjC class names are in the same namespace as variables and
3678          typedefs, and hence are shadowed by local declarations.  */
3679       if (objc_interface_decl
3680           && (global_bindings_p ()
3681               || (!objc_force_identifier && !decl)))
3682         {
3683           yylval.ttype = objc_interface_decl;
3684           return CLASSNAME;
3685         }
3686     }
3687 end ifobjc
3688
3689   return IDENTIFIER;
3690 }
3691
3692 /* Concatenate strings before returning them to the parser.  This isn't quite
3693    as good as having it done in the lexer, but it's better than nothing.  */
3694
3695 static int
3696 yylexstring ()
3697 {
3698   enum cpp_ttype next_type;
3699   tree orig = yylval.ttype;
3700
3701   next_type = c_lex (&yylval.ttype);
3702   if (next_type == CPP_STRING
3703       || next_type == CPP_WSTRING
3704       || (next_type == CPP_NAME && yylexname () == STRING))
3705     {
3706       varray_type strings;
3707
3708 ifc
3709       static int last_lineno = 0;
3710       static const char *last_input_filename = 0;
3711       if (warn_traditional && !in_system_header
3712           && (lineno != last_lineno || !last_input_filename ||
3713               strcmp (last_input_filename, input_filename)))
3714         {
3715           warning ("traditional C rejects string concatenation");
3716           last_lineno = lineno;
3717           last_input_filename = input_filename;
3718         }
3719 end ifc
3720
3721       VARRAY_TREE_INIT (strings, 32, "strings");
3722       VARRAY_PUSH_TREE (strings, orig);
3723
3724       do
3725         {
3726           VARRAY_PUSH_TREE (strings, yylval.ttype);
3727           next_type = c_lex (&yylval.ttype);
3728         }
3729       while (next_type == CPP_STRING
3730              || next_type == CPP_WSTRING
3731              || (next_type == CPP_NAME && yylexname () == STRING));
3732
3733       yylval.ttype = combine_strings (strings);
3734     }
3735   else
3736     yylval.ttype = orig;
3737
3738   /* We will have always read one token too many.  */
3739   _cpp_backup_tokens (parse_in, 1);
3740
3741   return STRING;
3742 }
3743
3744 static inline int
3745 _yylex ()
3746 {
3747  get_next:
3748   last_token = c_lex (&yylval.ttype);
3749   switch (last_token)
3750     {
3751     case CPP_EQ:                                        return '=';
3752     case CPP_NOT:                                       return '!';
3753     case CPP_GREATER:   yylval.code = GT_EXPR;          return ARITHCOMPARE;
3754     case CPP_LESS:      yylval.code = LT_EXPR;          return ARITHCOMPARE;
3755     case CPP_PLUS:      yylval.code = PLUS_EXPR;        return '+';
3756     case CPP_MINUS:     yylval.code = MINUS_EXPR;       return '-';
3757     case CPP_MULT:      yylval.code = MULT_EXPR;        return '*';
3758     case CPP_DIV:       yylval.code = TRUNC_DIV_EXPR;   return '/';
3759     case CPP_MOD:       yylval.code = TRUNC_MOD_EXPR;   return '%';
3760     case CPP_AND:       yylval.code = BIT_AND_EXPR;     return '&';
3761     case CPP_OR:        yylval.code = BIT_IOR_EXPR;     return '|';
3762     case CPP_XOR:       yylval.code = BIT_XOR_EXPR;     return '^';
3763     case CPP_RSHIFT:    yylval.code = RSHIFT_EXPR;      return RSHIFT;
3764     case CPP_LSHIFT:    yylval.code = LSHIFT_EXPR;      return LSHIFT;
3765
3766     case CPP_COMPL:                                     return '~';
3767     case CPP_AND_AND:                                   return ANDAND;
3768     case CPP_OR_OR:                                     return OROR;
3769     case CPP_QUERY:                                     return '?';
3770     case CPP_OPEN_PAREN:                                return '(';
3771     case CPP_EQ_EQ:     yylval.code = EQ_EXPR;          return EQCOMPARE;
3772     case CPP_NOT_EQ:    yylval.code = NE_EXPR;          return EQCOMPARE;
3773     case CPP_GREATER_EQ:yylval.code = GE_EXPR;          return ARITHCOMPARE;
3774     case CPP_LESS_EQ:   yylval.code = LE_EXPR;          return ARITHCOMPARE;
3775
3776     case CPP_PLUS_EQ:   yylval.code = PLUS_EXPR;        return ASSIGN;
3777     case CPP_MINUS_EQ:  yylval.code = MINUS_EXPR;       return ASSIGN;
3778     case CPP_MULT_EQ:   yylval.code = MULT_EXPR;        return ASSIGN;
3779     case CPP_DIV_EQ:    yylval.code = TRUNC_DIV_EXPR;   return ASSIGN;
3780     case CPP_MOD_EQ:    yylval.code = TRUNC_MOD_EXPR;   return ASSIGN;
3781     case CPP_AND_EQ:    yylval.code = BIT_AND_EXPR;     return ASSIGN;
3782     case CPP_OR_EQ:     yylval.code = BIT_IOR_EXPR;     return ASSIGN;
3783     case CPP_XOR_EQ:    yylval.code = BIT_XOR_EXPR;     return ASSIGN;
3784     case CPP_RSHIFT_EQ: yylval.code = RSHIFT_EXPR;      return ASSIGN;
3785     case CPP_LSHIFT_EQ: yylval.code = LSHIFT_EXPR;      return ASSIGN;
3786
3787     case CPP_OPEN_SQUARE:                               return '[';
3788     case CPP_CLOSE_SQUARE:                              return ']';
3789     case CPP_OPEN_BRACE:                                return '{';
3790     case CPP_CLOSE_BRACE:                               return '}';
3791     case CPP_ELLIPSIS:                                  return ELLIPSIS;
3792
3793     case CPP_PLUS_PLUS:                                 return PLUSPLUS;
3794     case CPP_MINUS_MINUS:                               return MINUSMINUS;
3795     case CPP_DEREF:                                     return POINTSAT;
3796     case CPP_DOT:                                       return '.';
3797
3798       /* The following tokens may affect the interpretation of any
3799          identifiers following, if doing Objective-C.  */
3800     case CPP_COLON:             OBJC_NEED_RAW_IDENTIFIER (0);   return ':';
3801     case CPP_COMMA:             OBJC_NEED_RAW_IDENTIFIER (0);   return ',';
3802     case CPP_CLOSE_PAREN:       OBJC_NEED_RAW_IDENTIFIER (0);   return ')';
3803     case CPP_SEMICOLON:         OBJC_NEED_RAW_IDENTIFIER (0);   return ';';
3804
3805     case CPP_EOF:
3806       return 0;
3807
3808     case CPP_NAME:
3809       {
3810         int ret = yylexname ();
3811         if (ret == STRING)
3812           return yylexstring ();
3813         else
3814           return ret;
3815       }
3816
3817     case CPP_NUMBER:
3818     case CPP_CHAR:
3819     case CPP_WCHAR:
3820       return CONSTANT;
3821
3822     case CPP_STRING:
3823     case CPP_WSTRING:
3824       return yylexstring ();
3825
3826       /* This token is Objective-C specific.  It gives the next token
3827          special significance.  */
3828     case CPP_ATSIGN:
3829 ifobjc
3830       {
3831         tree after_at;
3832         enum cpp_ttype after_at_type;
3833
3834         after_at_type = c_lex (&after_at);
3835
3836         if (after_at_type == CPP_NAME
3837             && C_IS_RESERVED_WORD (after_at)
3838             && OBJC_IS_AT_KEYWORD (C_RID_CODE (after_at)))
3839           {
3840             yylval.ttype = after_at;
3841             last_token = after_at_type;
3842             return rid_to_yy [(int) C_RID_CODE (after_at)];
3843           }
3844         _cpp_backup_tokens (parse_in, 1);
3845         return '@';
3846       }
3847 end ifobjc
3848
3849       /* These tokens are C++ specific (and will not be generated
3850          in C mode, but let's be cautious).  */
3851     case CPP_SCOPE:
3852     case CPP_DEREF_STAR:
3853     case CPP_DOT_STAR:
3854     case CPP_MIN_EQ:
3855     case CPP_MAX_EQ:
3856     case CPP_MIN:
3857     case CPP_MAX:
3858       /* These tokens should not survive translation phase 4.  */
3859     case CPP_HASH:
3860     case CPP_PASTE:
3861       error ("syntax error at '%s' token", NAME(last_token));
3862       goto get_next;
3863
3864     default:
3865       abort ();
3866     }
3867   /* NOTREACHED */
3868 }
3869
3870 static int
3871 yylex()
3872 {
3873   int r;
3874   timevar_push (TV_LEX);
3875   r = _yylex();
3876   timevar_pop (TV_LEX);
3877   return r;
3878 }
3879
3880 /* Function used when yydebug is set, to print a token in more detail.  */
3881
3882 static void
3883 yyprint (file, yychar, yyl)
3884      FILE *file;
3885      int yychar;
3886      YYSTYPE yyl;
3887 {
3888   tree t = yyl.ttype;
3889
3890   fprintf (file, " [%s]", NAME(last_token));
3891
3892   switch (yychar)
3893     {
3894     case IDENTIFIER:
3895     case TYPENAME:
3896     case OBJECTNAME:
3897     case TYPESPEC:
3898     case TYPE_QUAL:
3899     case SCSPEC:
3900     case STATIC:
3901       if (IDENTIFIER_POINTER (t))
3902         fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
3903       break;
3904
3905     case CONSTANT:
3906       fprintf (file, " %s", GET_MODE_NAME (TYPE_MODE (TREE_TYPE (t))));
3907       if (TREE_CODE (t) == INTEGER_CST)
3908         fprintf (file,
3909 #if HOST_BITS_PER_WIDE_INT == 64
3910 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
3911                  " 0x%x%016x",
3912 #else
3913 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
3914                  " 0x%lx%016lx",
3915 #else
3916                  " 0x%llx%016llx",
3917 #endif
3918 #endif
3919 #else
3920 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
3921                  " 0x%lx%08lx",
3922 #else
3923                  " 0x%x%08x",
3924 #endif
3925 #endif
3926                  TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
3927       break;
3928     }
3929 }
3930 \f
3931 /* This is not the ideal place to put these, but we have to get them out
3932    of c-lex.c because cp/lex.c has its own versions.  */
3933
3934 /* Free malloced parser stacks if necessary.  */
3935
3936 void
3937 free_parser_stacks ()
3938 {
3939   if (malloced_yyss)
3940     {
3941       free (malloced_yyss);
3942       free (malloced_yyvs);
3943     }
3944 }
3945
3946 #include "gt-c-parse.h"