OSDN Git Service

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