OSDN Git Service

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