Do not report -Wnested-extern errors for __FUNCTION__/__PRETTY_FUNCTION__.
[official-gcc.git] / gcc / c-parse.in
blob04879dc2e93e146e32618030109226ff4e3acfe4
1 /* YACC parser for C syntax and for Objective C.  -*-c-*-
2    Copyright (C) 1987, 1988, 1989, 1992 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
20 /* This file defines the grammar of C and that of Objective C.
21    ifobjc ... end ifobjc  conditionals contain code for Objective C only.
22    ifc ... end ifc  conditionals contain code for C only.
23    Sed commands in Makefile.in are used to convert this file into
24    c-parse.y and into objc-parse.y.  */
26 /* To whomever it may concern: I have heard that such a thing was once
27 written by AT&T, but I have never seen it.  */
29 ifobjc
30 %expect 20
31 end ifobjc
32 ifc
33 %expect 8
35 /* These are the 8 conflicts you should get in parse.output;
36    the state numbers may vary if minor changes in the grammar are made.
38 State 41 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
39 State 92 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
40 State 99 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
41 State 103 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
42 State 119 contains 1 shift/reduce conflict.  (See comment at component_decl.)
43 State 183 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
44 State 193 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
45 State 199 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
47 end ifc
50 #include <stdio.h>
51 #include <errno.h>
52 #include <setjmp.h>
54 #include "config.h"
55 #include "tree.h"
56 #include "input.h"
57 #include "c-lex.h"
58 #include "c-tree.h"
59 #include "flags.h"
61 #ifdef MULTIBYTE_CHARS
62 #include <stdlib.h>
63 #include <locale.h>
64 #endif
66 ifobjc
67 #include "objc-act.h"
68 end ifobjc
70 /* Since parsers are distinct for each language, put the language string
71    definition here.  */
72 ifobjc
73 char *language_string = "GNU Obj-C";
74 end ifobjc
75 ifc
76 char *language_string = "GNU C";
77 end ifc
79 #ifndef errno
80 extern int errno;
81 #endif
83 void yyerror ();
85 /* Like YYERROR but do call yyerror.  */
86 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
88 /* Cause the `yydebug' variable to be defined.  */
89 #define YYDEBUG 1
92 %start program
94 %union {long itype; tree ttype; enum tree_code code;
95         char *filename; int lineno; }
97 /* All identifiers that are not reserved words
98    and are not declared typedefs in the current block */
99 %token IDENTIFIER
101 /* All identifiers that are declared typedefs in the current block.
102    In some contexts, they are treated just like IDENTIFIER,
103    but they can also serve as typespecs in declarations.  */
104 %token TYPENAME
106 /* Reserved words that specify storage class.
107    yylval contains an IDENTIFIER_NODE which indicates which one.  */
108 %token SCSPEC
110 /* Reserved words that specify type.
111    yylval contains an IDENTIFIER_NODE which indicates which one.  */
112 %token TYPESPEC
114 /* Reserved words that qualify type: "const" or "volatile".
115    yylval contains an IDENTIFIER_NODE which indicates which one.  */
116 %token TYPE_QUAL
118 /* Character or numeric constants.
119    yylval is the node for the constant.  */
120 %token CONSTANT
122 /* String constants in raw form.
123    yylval is a STRING_CST node.  */
124 %token STRING
126 /* "...", used for functions with variable arglists.  */
127 %token ELLIPSIS
129 /* the reserved words */
130 /* SCO include files test "ASM", so use something else. */
131 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
132 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF ALIGN
133 %token ATTRIBUTE EXTENSION LABEL
134 %token REALPART IMAGPART
136 /* Add precedence rules to solve dangling else s/r conflict */
137 %nonassoc IF
138 %nonassoc ELSE
140 /* Define the operator tokens and their precedences.
141    The value is an integer because, if used, it is the tree code
142    to use in the expression made from the operator.  */
144 %right <code> ASSIGN '='
145 %right <code> '?' ':'
146 %left <code> OROR
147 %left <code> ANDAND
148 %left <code> '|'
149 %left <code> '^'
150 %left <code> '&'
151 %left <code> EQCOMPARE
152 %left <code> ARITHCOMPARE
153 %left <code> LSHIFT RSHIFT
154 %left <code> '+' '-'
155 %left <code> '*' '/' '%'
156 %right <code> UNARY PLUSPLUS MINUSMINUS
157 %left HYPERUNARY
158 %left <code> POINTSAT '.' '(' '['
160 /* The Objective-C keywords.  These are included in C and in
161    Objective C, so that the token codes are the same in both.  */
162 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
163 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
165 /* Objective-C string constants in raw form.
166    yylval is an OBJC_STRING_CST node.  */
167 %token OBJC_STRING
170 %type <code> unop
172 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
173 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
174 %type <ttype> typed_declspecs reserved_declspecs
175 %type <ttype> typed_typespecs reserved_typespecquals
176 %type <ttype> declmods typespec typespecqual_reserved
177 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
178 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
179 %type <ttype> init maybeasm
180 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
181 %type <ttype> maybe_attribute attribute_list attrib
183 %type <ttype> compstmt
185 %type <ttype> declarator
186 %type <ttype> notype_declarator after_type_declarator
187 %type <ttype> parm_declarator
189 %type <ttype> structsp component_decl_list component_decl_list2
190 %type <ttype> component_decl components component_declarator
191 %type <ttype> enumlist enumerator
192 %type <ttype> typename absdcl absdcl1 type_quals
193 %type <ttype> xexpr parms parm identifiers
195 %type <ttype> parmlist parmlist_1 parmlist_2
196 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
197 %type <ttype> identifiers_or_typenames
199 %type <itype> setspecs
201 %type <filename> save_filename
202 %type <lineno> save_lineno
204 ifobjc
205 /* the Objective-C nonterminals */
207 %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
208 %type <ttype> methoddecl unaryselector keywordselector selector
209 %type <ttype> keyworddecl receiver objcmessageexpr messageargs
210 %type <ttype> keywordexpr keywordarglist keywordarg
211 %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
212 %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
213 %type <ttype> objc_string protocolrefs identifier_list objcprotocolexpr
214 %type <ttype> CLASSNAME OBJC_STRING OBJECTNAME
215 end ifobjc
218 /* Number of statements (loosely speaking) seen so far.  */
219 static int stmt_count;
221 /* Input file and line number of the end of the body of last simple_if;
222    used by the stmt-rule immediately after simple_if returns.  */
223 static char *if_stmt_file;
224 static int if_stmt_line;
226 /* List of types and structure classes of the current declaration.  */
227 static tree current_declspecs;
229 /* Stack of saved values of current_declspecs.  */
230 static tree declspec_stack;
232 /* 1 if we explained undeclared var errors.  */
233 static int undeclared_variable_notice;
235 ifobjc
236 /* Objective-C specific information */
238 tree objc_interface_context;
239 tree objc_implementation_context;
240 tree objc_method_context;
241 tree objc_ivar_chain;
242 tree objc_ivar_context;
243 enum tree_code objc_inherit_code;
244 int objc_receiver_context;
245 int objc_public_flag;
247 end ifobjc
249 /* Tell yyparse how to print a token's value, if yydebug is set.  */
251 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
252 extern void yyprint ();
256 program: /* empty */
257                 { if (pedantic)
258                     pedwarn ("ANSI C forbids an empty source file");
259 ifobjc
260                   objc_finish ();
261 end ifobjc
262                 }
263         | extdefs
264                 {
265                   /* In case there were missing closebraces,
266                      get us back to the global binding level.  */
267                   while (! global_bindings_p ())
268                     poplevel (0, 0, 0);
269 ifobjc
270                   objc_finish ();
271 end ifobjc
272                 }
273         ;
275 /* the reason for the strange actions in this rule
276  is so that notype_initdecls when reached via datadef
277  can find a valid list of type and sc specs in $0. */
279 extdefs:
280         {$<ttype>$ = NULL_TREE; } extdef
281         | extdefs {$<ttype>$ = NULL_TREE; } extdef
282         ;
284 extdef:
285         fndef
286         | datadef
287 ifobjc
288         | objcdef
289 end ifobjc
290         | ASM_KEYWORD '(' expr ')' ';'
291                 { STRIP_NOPS ($3);
292                   if ((TREE_CODE ($3) == ADDR_EXPR
293                        && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
294                       || TREE_CODE ($3) == STRING_CST)
295                     assemble_asm ($3);
296                   else
297                     error ("argument of `asm' is not a constant string"); }
298         ;
300 datadef:
301           setspecs notype_initdecls ';'
302                 { if (pedantic)
303                     error ("ANSI C forbids data definition with no type or storage class");
304                   else if (!flag_traditional)
305                     warning ("data definition has no type or storage class"); }
306         | declmods setspecs notype_initdecls ';'
307           {}
308         | typed_declspecs setspecs initdecls ';'
309           {}
310         | declmods ';'
311           { pedwarn ("empty declaration"); }
312         | typed_declspecs ';'
313           { shadow_tag ($1); }
314         | error ';'
315         | error '}'
316         | ';'
317                 { if (pedantic)
318                     pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
319         ;
321 fndef:
322           typed_declspecs setspecs declarator
323                 { if (! start_function ($1, $3, 0))
324                     YYERROR1;
325                   reinit_parse_for_function (); }
326           xdecls
327                 { store_parm_decls (); }
328           compstmt_or_error
329                 { finish_function (0); }
330         | typed_declspecs setspecs declarator error
331                 { }
332         | declmods setspecs notype_declarator
333                 { if (! start_function ($1, $3, 0))
334                     YYERROR1;
335                   reinit_parse_for_function (); }
336           xdecls
337                 { store_parm_decls (); }
338           compstmt_or_error
339                 { finish_function (0); }
340         | declmods setspecs notype_declarator error
341                 { }
342         | setspecs notype_declarator
343                 { if (! start_function (NULL_TREE, $2, 0))
344                     YYERROR1;
345                   reinit_parse_for_function (); }
346           xdecls
347                 { store_parm_decls (); }
348           compstmt_or_error
349                 { finish_function (0); }
350         | setspecs notype_declarator error
351                 { }
352         ;
354 identifier:
355         IDENTIFIER
356         | TYPENAME
357 ifobjc
358         | OBJECTNAME
359         | CLASSNAME
360 end ifobjc
361         ;
363 unop:     '&'
364                 { $$ = ADDR_EXPR; }
365         | '-'
366                 { $$ = NEGATE_EXPR; }
367         | '+'
368                 { $$ = CONVERT_EXPR; }
369         | PLUSPLUS
370                 { $$ = PREINCREMENT_EXPR; }
371         | MINUSMINUS
372                 { $$ = PREDECREMENT_EXPR; }
373         | '~'
374                 { $$ = BIT_NOT_EXPR; }
375         | '!'
376                 { $$ = TRUTH_NOT_EXPR; }
377         ;
379 expr:   nonnull_exprlist
380                 { $$ = build_compound_expr ($1); }
381         ;
383 exprlist:
384           /* empty */
385                 { $$ = NULL_TREE; }
386         | nonnull_exprlist
387         ;
389 nonnull_exprlist:
390         expr_no_commas
391                 { $$ = build_tree_list (NULL_TREE, $1); }
392         | nonnull_exprlist ',' expr_no_commas
393                 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
394         ;
396 unary_expr:
397         primary
398         | '*' cast_expr   %prec UNARY
399                 { $$ = build_indirect_ref ($2, "unary *"); }
400         /* __extension__ turns off -pedantic for following primary.  */
401         | EXTENSION
402                 { $<itype>1 = pedantic;
403                   pedantic = 0; }
404           cast_expr       %prec UNARY
405                 { $$ = $3;
406                   pedantic = $<itype>1; }
407         | unop cast_expr  %prec UNARY
408                 { $$ = build_unary_op ($1, $2, 0);
409                   overflow_warning ($$); }
410         /* Refer to the address of a label as a pointer.  */
411         | ANDAND identifier
412                 { tree label = lookup_label ($2);
413                   if (label == 0)
414                     $$ = null_pointer_node;
415                   else
416                     {
417                       TREE_USED (label) = 1;
418                       $$ = build1 (ADDR_EXPR, ptr_type_node, label);
419                       TREE_CONSTANT ($$) = 1;
420                     }
421                 }
422 /* This seems to be impossible on some machines, so let's turn it off.
423    You can use __builtin_next_arg to find the anonymous stack args.
424         | '&' ELLIPSIS
425                 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
426                   $$ = error_mark_node;
427                   if (TREE_VALUE (tree_last (types)) == void_type_node)
428                     error ("`&...' used in function with fixed number of arguments");
429                   else
430                     {
431                       if (pedantic)
432                         pedwarn ("ANSI C forbids `&...'");
433                       $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
434                       $$ = build_unary_op (ADDR_EXPR, $$, 0);
435                     } }
437         | SIZEOF unary_expr  %prec UNARY
438                 { if (TREE_CODE ($2) == COMPONENT_REF
439                       && DECL_BIT_FIELD (TREE_OPERAND ($2, 1)))
440                     error ("`sizeof' applied to a bit-field");
441                   $$ = c_sizeof (TREE_TYPE ($2)); }
442         | SIZEOF '(' typename ')'  %prec HYPERUNARY
443                 { $$ = c_sizeof (groktypename ($3)); }
444         | ALIGNOF unary_expr  %prec UNARY
445                 { $$ = c_alignof_expr ($2); }
446         | ALIGNOF '(' typename ')'  %prec HYPERUNARY
447                 { $$ = c_alignof (groktypename ($3)); }
448         | REALPART cast_expr %prec UNARY
449                 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
450         | IMAGPART cast_expr %prec UNARY
451                 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
452         ;
454 cast_expr:
455         unary_expr
456         | '(' typename ')' cast_expr  %prec UNARY
457                 { tree type = groktypename ($2);
458                   $$ = build_c_cast (type, $4); }
459         | '(' typename ')' '{' 
460                 { start_init (NULL_TREE, NULL, 0);
461                   $2 = groktypename ($2);
462                   really_start_incremental_init ($2); }
463           initlist_maybe_comma '}'  %prec UNARY
464                 { char *name;
465                   tree result = pop_init_level (0);
466                   tree type = $2;
467                   finish_init ();
469                   if (pedantic)
470                     pedwarn ("ANSI C forbids constructor expressions");
471                   if (TYPE_NAME (type) != 0)
472                     {
473                       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
474                         name = IDENTIFIER_POINTER (TYPE_NAME (type));
475                       else
476                         name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
477                     }
478                   else
479                     name = "";
480                   $$ = result;
481                   if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
482                     {
483                       int failure = complete_array_type (type, $$, 1);
484                       if (failure)
485                         abort ();
486                     }
487                 }
488         ;
490 expr_no_commas:
491           cast_expr
492         | expr_no_commas '+' expr_no_commas
493                 { $$ = parser_build_binary_op ($2, $1, $3); }
494         | expr_no_commas '-' expr_no_commas
495                 { $$ = parser_build_binary_op ($2, $1, $3); }
496         | expr_no_commas '*' expr_no_commas
497                 { $$ = parser_build_binary_op ($2, $1, $3); }
498         | expr_no_commas '/' expr_no_commas
499                 { $$ = parser_build_binary_op ($2, $1, $3); }
500         | expr_no_commas '%' expr_no_commas
501                 { $$ = parser_build_binary_op ($2, $1, $3); }
502         | expr_no_commas LSHIFT expr_no_commas
503                 { $$ = parser_build_binary_op ($2, $1, $3); }
504         | expr_no_commas RSHIFT expr_no_commas
505                 { $$ = parser_build_binary_op ($2, $1, $3); }
506         | expr_no_commas ARITHCOMPARE expr_no_commas
507                 { $$ = parser_build_binary_op ($2, $1, $3); }
508         | expr_no_commas EQCOMPARE expr_no_commas
509                 { $$ = parser_build_binary_op ($2, $1, $3); }
510         | expr_no_commas '&' expr_no_commas
511                 { $$ = parser_build_binary_op ($2, $1, $3); }
512         | expr_no_commas '|' expr_no_commas
513                 { $$ = parser_build_binary_op ($2, $1, $3); }
514         | expr_no_commas '^' expr_no_commas
515                 { $$ = parser_build_binary_op ($2, $1, $3); }
516         | expr_no_commas ANDAND expr_no_commas
517                 { $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $3); }
518         | expr_no_commas OROR expr_no_commas
519                 { $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $3); }
520         | expr_no_commas '?' xexpr ':' expr_no_commas
521                 { $$ = build_conditional_expr ($1, $3, $5); }
522         | expr_no_commas '=' expr_no_commas
523                 { $$ = build_modify_expr ($1, NOP_EXPR, $3);
524                   C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
525         | expr_no_commas ASSIGN expr_no_commas
526                 { $$ = build_modify_expr ($1, $2, $3);
527                   /* This inhibits warnings in truthvalue_conversion.  */
528                   C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); }
529         ;
531 primary:
532         IDENTIFIER
533                 {
534                   tree context;
536                   $$ = lastiddecl;
537                   if (!$$ || $$ == error_mark_node)
538                     {
539                       if (yychar == YYEMPTY)
540                         yychar = YYLEX;
541                       if (yychar == '(')
542                         {
543 ifobjc
544                           tree decl;
546                           if (objc_receiver_context
547                               && ! (objc_receiver_context
548                                     && strcmp (IDENTIFIER_POINTER ($1), "super")))
549                             /* we have a message to super */
550                             $$ = get_super_receiver ();
551                           else if (objc_method_context
552                                    && (decl = is_ivar (objc_ivar_chain, $1)))
553                             {
554                               if (is_private (decl))
555                                 $$ = error_mark_node;
556                               else
557                                 $$ = build_ivar_reference ($1);
558                             }
559                           else
560 end ifobjc
561                             {
562                               /* Ordinary implicit function declaration.  */
563                               $$ = implicitly_declare ($1);
564                               assemble_external ($$);
565                               TREE_USED ($$) = 1;
566                             }
567                         }
568                       else if (current_function_decl == 0)
569                         {
570                           error ("`%s' undeclared here (not in a function)",
571                                  IDENTIFIER_POINTER ($1));
572                           $$ = error_mark_node;
573                         }
574                       else
575                         {
576 ifobjc
577                           tree decl;
579                           if (objc_receiver_context
580                               && ! strcmp (IDENTIFIER_POINTER ($1), "super"))
581                             /* we have a message to super */
582                             $$ = get_super_receiver ();
583                           else if (objc_method_context
584                                    && (decl = is_ivar (objc_ivar_chain, $1)))
585                             {
586                               if (is_private (decl))
587                                 $$ = error_mark_node;
588                               else
589                                 $$ = build_ivar_reference ($1);
590                             }
591                           else
592 end ifobjc
593                             {
594                               if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
595                                   || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
596                                 {
597                                   error ("`%s' undeclared (first use this function)",
598                                          IDENTIFIER_POINTER ($1));
600                                   if (! undeclared_variable_notice)
601                                     {
602                                       error ("(Each undeclared identifier is reported only once");
603                                       error ("for each function it appears in.)");
604                                       undeclared_variable_notice = 1;
605                                     }
606                                 }
607                               $$ = error_mark_node;
608                               /* Prevent repeated error messages.  */
609                               IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
610                               IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
611                             }
612                         }
613                     }
614                   else if (TREE_TYPE ($$) == error_mark_node)
615                     $$ = error_mark_node;
616                   else if (C_DECL_ANTICIPATED ($$))
617                     {
618                       /* The first time we see a build-in function used,
619                          if it has not been declared.  */
620                       C_DECL_ANTICIPATED ($$) = 0;
621                       if (yychar == YYEMPTY)
622                         yychar = YYLEX;
623                       if (yychar == '(')
624                         {
625                           /* Omit the implicit declaration we
626                              would ordinarily do, so we don't lose
627                              the actual built in type.
628                              But print a diagnostic for the mismatch.  */
629 ifobjc
630                           if (objc_method_context
631                               && is_ivar (objc_ivar_chain, $1))
632                             error ("Instance variable `%s' implicitly declared as function",
633                                    IDENTIFIER_POINTER (DECL_NAME ($$)));
634                           else
635 end ifobjc
636                             if (TREE_CODE ($$) != FUNCTION_DECL)
637                               error ("`%s' implicitly declared as function",
638                                      IDENTIFIER_POINTER (DECL_NAME ($$)));
639                           else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
640                                     != TYPE_MODE (integer_type_node))
641                                    && (TREE_TYPE (TREE_TYPE ($$))
642                                        != void_type_node))
643                             pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
644                                      IDENTIFIER_POINTER (DECL_NAME ($$)));
645                           /* If it really returns void, change that to int.  */
646                           if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
647                             TREE_TYPE ($$)
648                               = build_function_type (integer_type_node,
649                                                      TYPE_ARG_TYPES (TREE_TYPE ($$)));
650                         }
651                       else
652                         pedwarn ("built-in function `%s' used without declaration",
653                                  IDENTIFIER_POINTER (DECL_NAME ($$)));
655                       /* Do what we would ordinarily do when a fn is used.  */
656                       assemble_external ($$);
657                       TREE_USED ($$) = 1;
658                     }
659                   else
660                     {
661                       assemble_external ($$);
662                       TREE_USED ($$) = 1;
663 ifobjc
664                       /* we have a definition - still check if iVariable */
666                       if (!objc_receiver_context
667                           || (objc_receiver_context
668                               && strcmp (IDENTIFIER_POINTER ($1), "super")))
669                         {
670                           tree decl;
672                           if (objc_method_context
673                               && (decl = is_ivar (objc_ivar_chain, $1)))
674                             {
675                               if (IDENTIFIER_LOCAL_VALUE ($1))
676                                 warning ("local declaration of `%s' hides instance variable",
677                                          IDENTIFIER_POINTER ($1));
678                               else
679                                 {
680                                   if (is_private (decl))
681                                     $$ = error_mark_node;
682                                   else
683                                     $$ = build_ivar_reference ($1);
684                                 }
685                             }
686                         }
687                       else /* we have a message to super */
688                         $$ = get_super_receiver ();
689 end ifobjc
690                     }
692                   if (TREE_CODE ($$) == CONST_DECL)
693                     {
694                       $$ = DECL_INITIAL ($$);
695                       /* This is to prevent an enum whose value is 0
696                          from being considered a null pointer constant.  */
697                       $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
698                       TREE_CONSTANT ($$) = 1;
699                     }
700                 }
701         | CONSTANT
702         | string
703                 { $$ = combine_strings ($1); }
704         | '(' expr ')'
705                 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
706                   if (class == 'e' || class == '1'
707                       || class == '2' || class == '<')
708                     C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
709                   $$ = $2; }
710         | '(' error ')'
711                 { $$ = error_mark_node; }
712         | '('
713                 { if (current_function_decl == 0)
714                     {
715                       error ("braced-group within expression allowed only inside a function");
716                       YYERROR;
717                     }
718                   /* We must force a BLOCK for this level
719                      so that, if it is not expanded later,
720                      there is a way to turn off the entire subtree of blocks
721                      that are contained in it.  */
722                   keep_next_level ();
723                   push_iterator_stack ();
724                   push_label_level ();
725                   $<ttype>$ = expand_start_stmt_expr (); }
726           compstmt ')'
727                 { tree rtl_exp;
728                   if (pedantic)
729                     pedwarn ("ANSI C forbids braced-groups within expressions");
730                   pop_iterator_stack ();
731                   pop_label_level ();
732                   rtl_exp = expand_end_stmt_expr ($<ttype>2);
733                   /* The statements have side effects, so the group does.  */
734                   TREE_SIDE_EFFECTS (rtl_exp) = 1;
736                   if (TREE_CODE ($3) == BLOCK)
737                     {
738                       /* Make a BIND_EXPR for the BLOCK already made.  */
739                       $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
740                                   NULL_TREE, rtl_exp, $3);
741                       /* Remove the block from the tree at this point.
742                          It gets put back at the proper place
743                          when the BIND_EXPR is expanded.  */
744                       delete_block ($3);
745                     }
746                   else
747                     $$ = $3;
748                 }
749         | primary '(' exprlist ')'   %prec '.'
750                 { $$ = build_function_call ($1, $3); }
751         | primary '[' expr ']'   %prec '.'
752                 { $$ = build_array_ref ($1, $3); }
753         | primary '.' identifier
754                 {
755 ifobjc
756                   if (doing_objc_thang)
757                     {
758                       if (is_public ($1, $3))
759                         $$ = build_component_ref ($1, $3);
760                       else
761                         $$ = error_mark_node;
762                     }
763                   else
764 end ifobjc
765                     $$ = build_component_ref ($1, $3);
766                 }
767         | primary POINTSAT identifier
768                 {
769                   tree expr = build_indirect_ref ($1, "->");
771 ifobjc
772                   if (doing_objc_thang)
773                     {
774                       if (is_public (expr, $3))
775                         $$ = build_component_ref (expr, $3);
776                       else
777                         $$ = error_mark_node;
778                     }
779                   else
780 end ifobjc
781                     $$ = build_component_ref (expr, $3);
782                 }
783         | primary PLUSPLUS
784                 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
785         | primary MINUSMINUS
786                 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
787 ifobjc
788         | objcmessageexpr
789                 { $$ = build_message_expr ($1); }
790         | objcselectorexpr
791                 { $$ = build_selector_expr ($1); }
792         | objcprotocolexpr
793                 { $$ = build_protocol_expr ($1); }
794         | objcencodeexpr
795                 { $$ = build_encode_expr ($1); }
796         | objc_string
797                 { $$ = build_objc_string_object ($1); }
798 end ifobjc
799         ;
801 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it.  */
802 string:
803           STRING
804         | string STRING
805                 { $$ = chainon ($1, $2); }
806         ;
808 ifobjc
809 /* Produces an OBJC_STRING_CST with prehaps more OBJC_STRING_CSTs chained
810    onto it.  */
811 objc_string:
812           OBJC_STRING
813         | objc_string OBJC_STRING
814                 { $$ = chainon ($1, $2); }
815         ;
816 end ifobjc
818 xdecls:
819         /* empty */
820         | datadecls
821         | datadecls ELLIPSIS
822                 /* ... is used here to indicate a varargs function.  */
823                 { c_mark_varargs ();
824                   if (pedantic)
825                     pedwarn ("ANSI C does not permit use of `varargs.h'"); }
826         ;
828 /* The following are analogous to lineno_decl, decls and decl
829    except that they do not allow nested functions.
830    They are used for old-style parm decls.  */
831 lineno_datadecl:
832           save_filename save_lineno datadecl
833                 { }
834         ;
836 datadecls:
837         lineno_datadecl
838         | errstmt
839         | datadecls lineno_datadecl
840         | lineno_datadecl errstmt
841         ;
843 datadecl:
844         typed_declspecs setspecs initdecls ';'
845                 { current_declspecs = TREE_VALUE (declspec_stack);
846                   declspec_stack = TREE_CHAIN (declspec_stack);
847                   resume_momentary ($2); }
848         | declmods setspecs notype_initdecls ';'
849                 { current_declspecs = TREE_VALUE (declspec_stack);
850                   declspec_stack = TREE_CHAIN (declspec_stack);
851                   resume_momentary ($2); }
852         | typed_declspecs ';'
853                 { shadow_tag_warned ($1, 1);
854                   pedwarn ("empty declaration"); }
855         | declmods ';'
856                 { pedwarn ("empty declaration"); }
857         ;
859 /* This combination which saves a lineno before a decl
860    is the normal thing to use, rather than decl itself.
861    This is to avoid shift/reduce conflicts in contexts
862    where statement labels are allowed.  */
863 lineno_decl:
864           save_filename save_lineno decl
865                 { }
866         ;
868 decls:
869         lineno_decl
870         | errstmt
871         | decls lineno_decl
872         | lineno_decl errstmt
873         ;
875 /* records the type and storage class specs to use for processing
876    the declarators that follow.
877    Maintains a stack of outer-level values of current_declspecs,
878    for the sake of parm declarations nested in function declarators.  */
879 setspecs: /* empty */
880                 { $$ = suspend_momentary ();
881                   pending_xref_error ();
882                   declspec_stack = tree_cons (NULL_TREE, current_declspecs,
883                                               declspec_stack);
884                   current_declspecs = $<ttype>0; }
885         ;
887 decl:
888         typed_declspecs setspecs initdecls ';'
889                 { current_declspecs = TREE_VALUE (declspec_stack);
890                   declspec_stack = TREE_CHAIN (declspec_stack);
891                   resume_momentary ($2); }
892         | declmods setspecs notype_initdecls ';'
893                 { current_declspecs = TREE_VALUE (declspec_stack);
894                   declspec_stack = TREE_CHAIN (declspec_stack);
895                   resume_momentary ($2); }
896         | typed_declspecs setspecs nested_function
897                 { current_declspecs = TREE_VALUE (declspec_stack);
898                   declspec_stack = TREE_CHAIN (declspec_stack);
899                   resume_momentary ($2); }
900         | declmods setspecs notype_nested_function
901                 { current_declspecs = TREE_VALUE (declspec_stack);
902                   declspec_stack = TREE_CHAIN (declspec_stack);
903                   resume_momentary ($2); }
904         | typed_declspecs ';'
905                 { shadow_tag ($1); }
906         | declmods ';'
907                 { pedwarn ("empty declaration"); }
908         ;
910 /* Declspecs which contain at least one type specifier or typedef name.
911    (Just `const' or `volatile' is not enough.)
912    A typedef'd name following these is taken as a name to be declared.  */
914 typed_declspecs:
915           typespec reserved_declspecs
916                 { $$ = tree_cons (NULL_TREE, $1, $2); }
917         | declmods typespec reserved_declspecs
918                 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
919         ;
921 reserved_declspecs:  /* empty */
922                 { $$ = NULL_TREE; }
923         | reserved_declspecs typespecqual_reserved
924                 { $$ = tree_cons (NULL_TREE, $2, $1); }
925         | reserved_declspecs SCSPEC
926                 { if (extra_warnings)
927                     warning ("`%s' is not at beginning of declaration",
928                              IDENTIFIER_POINTER ($2));
929                   $$ = tree_cons (NULL_TREE, $2, $1); }
930         ;
932 /* List of just storage classes and type modifiers.
933    A declaration can start with just this, but then it cannot be used
934    to redeclare a typedef-name.  */
936 declmods:
937           TYPE_QUAL
938                 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
939                   TREE_STATIC ($$) = 1; }
940         | SCSPEC
941                 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
942         | declmods TYPE_QUAL
943                 { $$ = tree_cons (NULL_TREE, $2, $1);
944                   TREE_STATIC ($$) = 1; }
945         | declmods SCSPEC
946                 { if (extra_warnings && TREE_STATIC ($1))
947                     warning ("`%s' is not at beginning of declaration",
948                              IDENTIFIER_POINTER ($2));
949                   $$ = tree_cons (NULL_TREE, $2, $1);
950                   TREE_STATIC ($$) = TREE_STATIC ($1); }
951         ;
954 /* Used instead of declspecs where storage classes are not allowed
955    (that is, for typenames and structure components).
956    Don't accept a typedef-name if anything but a modifier precedes it.  */
958 typed_typespecs:
959           typespec reserved_typespecquals
960                 { $$ = tree_cons (NULL_TREE, $1, $2); }
961         | nonempty_type_quals typespec reserved_typespecquals
962                 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
963         ;
965 reserved_typespecquals:  /* empty */
966                 { $$ = NULL_TREE; }
967         | reserved_typespecquals typespecqual_reserved
968                 { $$ = tree_cons (NULL_TREE, $2, $1); }
969         ;
971 /* A typespec (but not a type qualifier).
972    Once we have seen one of these in a declaration,
973    if a typedef name appears then it is being redeclared.  */
975 typespec: TYPESPEC
976         | structsp
977         | TYPENAME
978                 { /* For a typedef name, record the meaning, not the name.
979                      In case of `foo foo, bar;'.  */
980                   $$ = lookup_name ($1); }
981 ifobjc
982         | CLASSNAME protocolrefs
983                 { $$ = get_static_reference ($1, $2); }
984         | OBJECTNAME protocolrefs
985                 { $$ = get_object_reference ($2); }
986 end ifobjc
987         | TYPEOF '(' expr ')'
988                 { $$ = TREE_TYPE ($3); }
989         | TYPEOF '(' typename ')'
990                 { $$ = groktypename ($3); }
991         ;
993 /* A typespec that is a reserved word, or a type qualifier.  */
995 typespecqual_reserved: TYPESPEC
996         | TYPE_QUAL
997         | structsp
998         ;
1000 initdecls:
1001         initdcl
1002         | initdecls ',' initdcl
1003         ;
1005 notype_initdecls:
1006         notype_initdcl
1007         | notype_initdecls ',' initdcl
1008         ;
1010 maybeasm:
1011           /* empty */
1012                 { $$ = NULL_TREE; }
1013         | ASM_KEYWORD '(' string ')'
1014                 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
1015                   $$ = $3;
1016                 }
1017         ;
1019 initdcl:
1020           declarator maybeasm maybe_attribute '='
1021                 { $<ttype>$ = start_decl ($1, current_declspecs, 1);
1022                   start_init ($<ttype>$, $2, global_bindings_p ()); }
1023           init
1024 /* Note how the declaration of the variable is in effect while its init is parsed! */
1025                 { finish_init ();
1026                   decl_attributes ($<ttype>5, $3);
1027                   finish_decl ($<ttype>5, $6, $2); }
1028         | declarator maybeasm maybe_attribute
1029                 { tree d = start_decl ($1, current_declspecs, 0);
1030                   decl_attributes (d, $3);
1031                   finish_decl (d, NULL_TREE, $2); }
1032         ;
1034 notype_initdcl:
1035           notype_declarator maybeasm maybe_attribute '='
1036                 { $<ttype>$ = start_decl ($1, current_declspecs, 1);
1037                   start_init ($<ttype>$, $2, global_bindings_p ()); }
1038           init
1039 /* Note how the declaration of the variable is in effect while its init is parsed! */
1040                 { finish_init ();
1041                   decl_attributes ($<ttype>5, $3);
1042                   finish_decl ($<ttype>5, $6, $2); }
1043         | notype_declarator maybeasm maybe_attribute
1044                 { tree d = start_decl ($1, current_declspecs, 0);
1045                   decl_attributes (d, $3);
1046                   finish_decl (d, NULL_TREE, $2); }
1047         ;
1048 /* the * rules are dummies to accept the Apollo extended syntax
1049    so that the header files compile. */
1050 maybe_attribute:
1051     /* empty */
1052                 { $$ = NULL_TREE; }
1053     | ATTRIBUTE '(' '(' attribute_list ')' ')'
1054                 { $$ = $4; }
1055     ;
1057 attribute_list
1058     : attrib
1059         { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1060     | attribute_list ',' attrib
1061         { $$ = tree_cons (NULL_TREE, $3, $1); }
1062     ;
1064 attrib
1065     : IDENTIFIER
1066         { if (strcmp (IDENTIFIER_POINTER ($1), "packed")
1067               && strcmp (IDENTIFIER_POINTER ($1), "noreturn"))
1068             warning ("`%s' attribute directive ignored",
1069                      IDENTIFIER_POINTER ($1));
1070           $$ = $1; }
1071     | TYPE_QUAL
1072     | IDENTIFIER '(' IDENTIFIER ')'
1073         { /* If not "mode (m)", then issue warning.  */
1074           if (strcmp (IDENTIFIER_POINTER ($1), "mode") != 0)
1075             {
1076               warning ("`%s' attribute directive ignored",
1077                        IDENTIFIER_POINTER ($1));
1078               $$ = $1;
1079             }
1080           else
1081             $$ = tree_cons ($1, $3, NULL_TREE); }
1082     | IDENTIFIER '(' CONSTANT ')'
1083         { /* if not "aligned(n)", then issue warning */
1084           if (strcmp (IDENTIFIER_POINTER ($1), "aligned") != 0
1085               || TREE_CODE ($3) != INTEGER_CST)
1086             {
1087               warning ("`%s' attribute directive ignored",
1088                        IDENTIFIER_POINTER ($1));
1089               $$ = $1;
1090             }
1091           else
1092             $$ = tree_cons ($1, $3, NULL_TREE); }
1093     | IDENTIFIER '(' IDENTIFIER ',' CONSTANT ',' CONSTANT ')'
1094         { /* if not "format(...)", then issue warning */
1095           if (strcmp (IDENTIFIER_POINTER ($1), "format") != 0
1096               || TREE_CODE ($5) != INTEGER_CST
1097               || TREE_CODE ($7) != INTEGER_CST)
1098             {
1099               warning ("`%s' attribute directive ignored",
1100                        IDENTIFIER_POINTER ($1));
1101               $$ = $1;
1102             }
1103           else
1104             $$ = tree_cons ($1,
1105                             tree_cons ($3,
1106                                        tree_cons ($5, $7, NULL_TREE),
1107                                        NULL_TREE),
1108                             NULL_TREE); }
1109     ;
1111 /* Initializers.  `init' is the entry point.  */
1113 init:
1114         expr_no_commas
1115         | '{'
1116                 { really_start_incremental_init (NULL_TREE);
1117                   /* Note that the call to clear_momentary
1118                      is in process_init_element.  */
1119                   push_momentary (); }
1120           initlist_maybe_comma '}'
1121                 { $$ = pop_init_level (0);
1122                   pop_momentary (); }
1124         | error
1125                 { $$ = error_mark_node;
1126                   pop_momentary (); }
1127         ;
1129 /* `initlist_maybe_comma' is the guts of an initializer in braces.  */
1130 initlist_maybe_comma:
1131           /* empty */
1132                 { if (pedantic)
1133                     pedwarn ("ANSI C forbids empty initializer braces"); }
1134         | initlist1 maybecomma
1135         ;
1137 initlist1:
1138           initelt
1139         | initlist1 ',' initelt
1140         ;
1142 /* `initelt' is a single element of an initializer.
1143    It may use braces.  */
1144 initelt:
1145         expr_no_commas
1146                 { process_init_element ($1); }
1147         | '{' 
1148                 { push_init_level (0); }
1149           initlist_maybe_comma '}'
1150                 { process_init_element (pop_init_level (0)); }
1151         | error
1152         /* These are for labeled elements.  The syntax for an array element
1153            initializer conflicts with the syntax for an Objective-C message,
1154            so don't include these productions in the Objective-C grammer.  */
1156         | '[' expr_no_commas ELLIPSIS expr_no_commas ']' '='
1157                 { set_init_index ($2, $4); }
1158           initelt
1159         | '[' expr_no_commas ']' '='
1160                 { set_init_index ($2, NULL_TREE); }
1161           initelt
1162 end ifc
1163         | identifier ':'
1164                 { set_init_label ($1); }
1165           initelt
1166         | '.' identifier '='
1167                 { set_init_label ($2); }
1168           initelt
1169         ;
1171 nested_function:
1172           declarator
1173                 { push_c_function_context ();
1174                   if (! start_function (current_declspecs, $1, 1))
1175                     {
1176                       pop_c_function_context ();
1177                       YYERROR1;
1178                     }
1179                   reinit_parse_for_function ();
1180                   store_parm_decls (); }
1181 /* This used to use compstmt_or_error.
1182    That caused a bug with input `f(g) int g {}',
1183    where the use of YYERROR1 above caused an error
1184    which then was handled by compstmt_or_error.
1185    There followed a repeated execution of that same rule,
1186    which called YYERROR1 again, and so on.  */
1187           compstmt
1188                 { finish_function (1);
1189                   pop_c_function_context (); }
1190         ;
1192 notype_nested_function:
1193           notype_declarator
1194                 { push_c_function_context ();
1195                   if (! start_function (current_declspecs, $1, 1))
1196                     {
1197                       pop_c_function_context ();
1198                       YYERROR1;
1199                     }
1200                   reinit_parse_for_function ();
1201                   store_parm_decls (); }
1202 /* This used to use compstmt_or_error.
1203    That caused a bug with input `f(g) int g {}',
1204    where the use of YYERROR1 above caused an error
1205    which then was handled by compstmt_or_error.
1206    There followed a repeated execution of that same rule,
1207    which called YYERROR1 again, and so on.  */
1208           compstmt
1209                 { finish_function (1);
1210                   pop_c_function_context (); }
1211         ;
1213 /* Any kind of declarator (thus, all declarators allowed
1214    after an explicit typespec).  */
1216 declarator:
1217           after_type_declarator
1218         | notype_declarator
1219         ;
1221 /* A declarator that is allowed only after an explicit typespec.  */
1223 after_type_declarator:
1224           '(' after_type_declarator ')'
1225                 { $$ = $2; }
1226         | after_type_declarator '(' parmlist_or_identifiers  %prec '.'
1227                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1228 /*      | after_type_declarator '(' error ')'  %prec '.'
1229                 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1230                   poplevel (0, 0, 0); }  */
1231         | after_type_declarator '[' expr ']'  %prec '.'
1232                 { $$ = build_nt (ARRAY_REF, $1, $3); }
1233         | after_type_declarator '[' ']'  %prec '.'
1234                 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1235         | '*' type_quals after_type_declarator  %prec UNARY
1236                 { $$ = make_pointer_declarator ($2, $3); }
1237         | TYPENAME
1238 ifobjc
1239         | OBJECTNAME
1240 end ifobjc
1241         ;
1243 /* Kinds of declarator that can appear in a parameter list
1244    in addition to notype_declarator.  This is like after_type_declarator
1245    but does not allow a typedef name in parentheses as an identifier
1246    (because it would conflict with a function with that typedef as arg).  */
1248 parm_declarator:
1249           parm_declarator '(' parmlist_or_identifiers  %prec '.'
1250                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1251 /*      | parm_declarator '(' error ')'  %prec '.'
1252                 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1253                   poplevel (0, 0, 0); }  */
1254         | parm_declarator '[' expr ']'  %prec '.'
1255                 { $$ = build_nt (ARRAY_REF, $1, $3); }
1256         | parm_declarator '[' ']'  %prec '.'
1257                 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1258         | '*' type_quals parm_declarator  %prec UNARY
1259                 { $$ = make_pointer_declarator ($2, $3); }
1260         | TYPENAME
1261         ;
1263 /* A declarator allowed whether or not there has been
1264    an explicit typespec.  These cannot redeclare a typedef-name.  */
1266 notype_declarator:
1267           notype_declarator '(' parmlist_or_identifiers  %prec '.'
1268                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1269 /*      | notype_declarator '(' error ')'  %prec '.'
1270                 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1271                   poplevel (0, 0, 0); }  */
1272         | '(' notype_declarator ')'
1273                 { $$ = $2; }
1274         | '*' type_quals notype_declarator  %prec UNARY
1275                 { $$ = make_pointer_declarator ($2, $3); }
1276         | notype_declarator '[' expr ']'  %prec '.'
1277                 { $$ = build_nt (ARRAY_REF, $1, $3); }
1278         | notype_declarator '[' ']'  %prec '.'
1279                 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1280         | IDENTIFIER
1281         ;
1283 structsp:
1284           STRUCT identifier '{'
1285                 { $$ = start_struct (RECORD_TYPE, $2);
1286                   /* Start scope of tag before parsing components.  */
1287                 }
1288           component_decl_list '}'
1289                 { $$ = finish_struct ($<ttype>4, $5);
1290                   /* Really define the structure.  */
1291                 }
1292         | STRUCT '{' component_decl_list '}'
1293                 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1294                                       $3); }
1295         | STRUCT identifier
1296                 { $$ = xref_tag (RECORD_TYPE, $2); }
1297         | UNION identifier '{'
1298                 { $$ = start_struct (UNION_TYPE, $2); }
1299           component_decl_list '}'
1300                 { $$ = finish_struct ($<ttype>4, $5); }
1301         | UNION '{' component_decl_list '}'
1302                 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1303                                       $3); }
1304         | UNION identifier
1305                 { $$ = xref_tag (UNION_TYPE, $2); }
1306         | ENUM identifier '{'
1307                 { $<itype>3 = suspend_momentary ();
1308                   $$ = start_enum ($2); }
1309           enumlist maybecomma_warn '}'
1310                 { $$ = finish_enum ($<ttype>4, nreverse ($5));
1311                   resume_momentary ($<itype>3); }
1312         | ENUM '{'
1313                 { $<itype>2 = suspend_momentary ();
1314                   $$ = start_enum (NULL_TREE); }
1315           enumlist maybecomma_warn '}'
1316                 { $$ = finish_enum ($<ttype>3, nreverse ($4));
1317                   resume_momentary ($<itype>2); }
1318         | ENUM identifier
1319                 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1320         ;
1322 maybecomma:
1323           /* empty */
1324         | ','
1325         ;
1327 maybecomma_warn:
1328           /* empty */
1329         | ','
1330                 { if (pedantic) pedwarn ("comma at end of enumerator list"); }
1331         ;
1333 component_decl_list:
1334           component_decl_list2
1335                 { $$ = $1; }
1336         | component_decl_list2 component_decl
1337                 { $$ = chainon ($1, $2);
1338                   pedwarn ("no semicolon at end of struct or union"); }
1339         ;
1341 component_decl_list2:   /* empty */
1342                 { $$ = NULL_TREE; }
1343         | component_decl_list2 component_decl ';'
1344                 { $$ = chainon ($1, $2); }
1345         | component_decl_list2 ';'
1346                 { if (pedantic)
1347                     pedwarn ("extra semicolon in struct or union specified"); }
1348 ifobjc
1349         /* foo(sizeof(struct{ @defs(ClassName)})); */
1350         | DEFS '(' CLASSNAME ')'
1351                 {
1352                   tree interface = lookup_interface ($3);
1354                   if (interface)
1355                     $$ = get_class_ivars (interface);
1356                   else
1357                     {
1358                       error ("Cannot find interface declaration for `%s'",
1359                              IDENTIFIER_POINTER ($3));
1360                       $$ = NULL_TREE;
1361                     }
1362                 }
1363 end ifobjc
1364         ;
1366 /* There is a shift-reduce conflict here, because `components' may
1367    start with a `typename'.  It happens that shifting (the default resolution)
1368    does the right thing, because it treats the `typename' as part of
1369    a `typed_typespecs'.
1371    It is possible that this same technique would allow the distinction
1372    between `notype_initdecls' and `initdecls' to be eliminated.
1373    But I am being cautious and not trying it.  */
1375 component_decl:
1376           typed_typespecs setspecs components
1377                 { $$ = $3;
1378                   current_declspecs = TREE_VALUE (declspec_stack);
1379                   declspec_stack = TREE_CHAIN (declspec_stack);
1380                   resume_momentary ($2); }
1381         | typed_typespecs
1382                 { if (pedantic)
1383                     pedwarn ("ANSI C forbids member declarations with no members");
1384                   shadow_tag($1);
1385                   $$ = NULL_TREE; }
1386         | nonempty_type_quals setspecs components
1387                 { $$ = $3;
1388                   current_declspecs = TREE_VALUE (declspec_stack);
1389                   declspec_stack = TREE_CHAIN (declspec_stack);
1390                   resume_momentary ($2); }
1391         | nonempty_type_quals
1392                 { if (pedantic)
1393                     pedwarn ("ANSI C forbids member declarations with no members");
1394                   shadow_tag($1);
1395                   $$ = NULL_TREE; }
1396         | error
1397                 { $$ = NULL_TREE; }
1398         ;
1400 components:
1401           component_declarator
1402         | components ',' component_declarator
1403                 { $$ = chainon ($1, $3); }
1404         ;
1406 component_declarator:
1407           save_filename save_lineno declarator maybe_attribute
1408                 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1409                   decl_attributes ($$, $4); }
1410         | save_filename save_lineno
1411           declarator ':' expr_no_commas maybe_attribute
1412                 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1413                   decl_attributes ($$, $6); }
1414         | save_filename save_lineno ':' expr_no_commas maybe_attribute
1415                 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1416                   decl_attributes ($$, $5); }
1417         ;
1419 /* We chain the enumerators in reverse order.
1420    They are put in forward order where enumlist is used.
1421    (The order used to be significant, but no longer is so.
1422    However, we still maintain the order, just to be clean.)  */
1424 enumlist:
1425           enumerator
1426         | enumlist ',' enumerator
1427                 { $$ = chainon ($3, $1); }
1428         ;
1431 enumerator:
1432           identifier
1433                 { $$ = build_enumerator ($1, NULL_TREE); }
1434         | identifier '=' expr_no_commas
1435                 { $$ = build_enumerator ($1, $3); }
1436         ;
1438 typename:
1439         typed_typespecs absdcl
1440                 { $$ = build_tree_list ($1, $2); }
1441         | nonempty_type_quals absdcl
1442                 { $$ = build_tree_list ($1, $2); }
1443         ;
1445 absdcl:   /* an absolute declarator */
1446         /* empty */
1447                 { $$ = NULL_TREE; }
1448         | absdcl1
1449         ;
1451 nonempty_type_quals:
1452           TYPE_QUAL
1453                 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1454         | nonempty_type_quals TYPE_QUAL
1455                 { $$ = tree_cons (NULL_TREE, $2, $1); }
1456         ;
1458 type_quals:
1459           /* empty */
1460                 { $$ = NULL_TREE; }
1461         | type_quals TYPE_QUAL
1462                 { $$ = tree_cons (NULL_TREE, $2, $1); }
1463         ;
1465 absdcl1:  /* a nonempty absolute declarator */
1466           '(' absdcl1 ')'
1467                 { $$ = $2; }
1468           /* `(typedef)1' is `int'.  */
1469         | '*' type_quals absdcl1  %prec UNARY
1470                 { $$ = make_pointer_declarator ($2, $3); }
1471         | '*' type_quals  %prec UNARY
1472                 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1473         | absdcl1 '(' parmlist  %prec '.'
1474                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1475         | absdcl1 '[' expr ']'  %prec '.'
1476                 { $$ = build_nt (ARRAY_REF, $1, $3); }
1477         | absdcl1 '[' ']'  %prec '.'
1478                 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1479         | '(' parmlist  %prec '.'
1480                 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1481         | '[' expr ']'  %prec '.'
1482                 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1483         | '[' ']'  %prec '.'
1484                 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1485         ;
1487 /* at least one statement, the first of which parses without error.  */
1488 /* stmts is used only after decls, so an invalid first statement
1489    is actually regarded as an invalid decl and part of the decls.  */
1491 stmts:
1492           lineno_stmt_or_label
1493         | stmts lineno_stmt_or_label
1494         | stmts errstmt
1495         ;
1497 xstmts:
1498         /* empty */
1499         | stmts
1500         ;
1502 errstmt:  error ';'
1503         ;
1505 pushlevel:  /* empty */
1506                 { emit_line_note (input_filename, lineno);
1507                   pushlevel (0);
1508                   clear_last_expr ();
1509                   push_momentary ();
1510                   expand_start_bindings (0);
1511 ifobjc
1512                   if (objc_method_context)
1513                     add_objc_decls ();
1514 end ifobjc
1515                 }
1516         ;
1518 /* Read zero or more forward-declarations for labels
1519    that nested functions can jump to.  */
1520 maybe_label_decls:
1521           /* empty */
1522         | label_decls
1523                 { if (pedantic)
1524                     pedwarn ("ANSI C forbids label declarations"); }
1525         ;
1527 label_decls:
1528           label_decl
1529         | label_decls label_decl
1530         ;
1532 label_decl:
1533           LABEL identifiers_or_typenames ';'
1534                 { tree link;
1535                   for (link = $2; link; link = TREE_CHAIN (link))
1536                     {
1537                       tree label = shadow_label (TREE_VALUE (link));
1538                       C_DECLARED_LABEL_FLAG (label) = 1;
1539                       declare_nonlocal_label (label);
1540                     }
1541                 }
1542         ;
1544 /* This is the body of a function definition.
1545    It causes syntax errors to ignore to the next openbrace.  */
1546 compstmt_or_error:
1547           compstmt
1548                 {}
1549         | error compstmt
1550         ;
1552 compstmt: '{' '}'
1553                 { $$ = convert (void_type_node, integer_zero_node); }
1554         | '{' pushlevel maybe_label_decls decls xstmts '}'
1555                 { emit_line_note (input_filename, lineno);
1556                   expand_end_bindings (getdecls (), 1, 0);
1557                   $$ = poplevel (1, 1, 0);
1558                   pop_momentary (); }
1559         | '{' pushlevel maybe_label_decls error '}'
1560                 { emit_line_note (input_filename, lineno);
1561                   expand_end_bindings (getdecls (), kept_level_p (), 0);
1562                   $$ = poplevel (kept_level_p (), 0, 0);
1563                   pop_momentary (); }
1564         | '{' pushlevel maybe_label_decls stmts '}'
1565                 { emit_line_note (input_filename, lineno);
1566                   expand_end_bindings (getdecls (), kept_level_p (), 0);
1567                   $$ = poplevel (kept_level_p (), 0, 0);
1568                   pop_momentary (); }
1569         ;
1571 /* Value is number of statements counted as of the closeparen.  */
1572 simple_if:
1573           if_prefix lineno_labeled_stmt
1574 /* Make sure expand_end_cond is run once
1575    for each call to expand_start_cond.
1576    Otherwise a crash is likely.  */
1577         | if_prefix error
1578         ;
1580 if_prefix:
1581           IF '(' expr ')'
1582                 { emit_line_note ($<filename>-1, $<lineno>0);
1583                   expand_start_cond (truthvalue_conversion ($3), 0);
1584                   $<itype>$ = stmt_count;
1585                   if_stmt_file = $<filename>-1;
1586                   if_stmt_line = $<lineno>0;
1587                   position_after_white_space (); }
1588         ;
1590 /* This is a subroutine of stmt.
1591    It is used twice, once for valid DO statements
1592    and once for catching errors in parsing the end test.  */
1593 do_stmt_start:
1594           DO
1595                 { stmt_count++;
1596                   emit_line_note ($<filename>-1, $<lineno>0);
1597                   /* See comment in `while' alternative, above.  */
1598                   emit_nop ();
1599                   expand_start_loop_continue_elsewhere (1);
1600                   position_after_white_space (); }
1601           lineno_labeled_stmt WHILE
1602                 { expand_loop_continue_here (); }
1603         ;
1605 save_filename:
1606                 { $$ = input_filename; }
1607         ;
1609 save_lineno:
1610                 { $$ = lineno; }
1611         ;
1613 lineno_labeled_stmt:
1614           save_filename save_lineno stmt
1615                 { }
1616 /*      | save_filename save_lineno error
1617                 { }
1619         | save_filename save_lineno label lineno_labeled_stmt
1620                 { }
1621         ;
1623 lineno_stmt_or_label:
1624           save_filename save_lineno stmt_or_label
1625                 { }
1626         ;
1628 stmt_or_label:
1629           stmt
1630         | label
1631                 { int next;
1632                   position_after_white_space ();
1633                   next = getc (finput);
1634                   ungetc (next, finput);
1635                   if (pedantic && next == '}')
1636                     pedwarn ("ANSI C forbids label at end of compound statement");
1637                 }
1638         ;
1640 /* Parse a single real statement, not including any labels.  */
1641 stmt:
1642           compstmt
1643                 { stmt_count++; }
1644         | all_iter_stmt 
1645         | expr ';'
1646                 { stmt_count++;
1647                   emit_line_note ($<filename>-1, $<lineno>0);
1648                   /* Call default_conversion to get an error
1649                      on referring to a register array if pedantic.  */
1650                   if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1651                       || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1652                     $1 = default_conversion ($1);
1653                   iterator_expand ($1);
1654                   clear_momentary (); }
1655         | simple_if ELSE
1656                 { expand_start_else ();
1657                   $<itype>1 = stmt_count;
1658                   position_after_white_space (); }
1659           lineno_labeled_stmt
1660                 { expand_end_cond ();
1661                   if (extra_warnings && stmt_count == $<itype>1)
1662                     warning ("empty body in an else-statement"); }
1663         | simple_if %prec IF
1664                 { expand_end_cond ();
1665                   /* This warning is here instead of in simple_if, because we
1666                      do not want a warning if an empty if is followed by an
1667                      else statement.  */
1668                   if (extra_warnings && stmt_count == $<itype>1)
1669                     warning_with_file_and_line (if_stmt_file, if_stmt_line,
1670                                                 "empty body in an if-statement"); }
1671 /* Make sure expand_end_cond is run once
1672    for each call to expand_start_cond.
1673    Otherwise a crash is likely.  */
1674         | simple_if ELSE error
1675                 { expand_end_cond (); }
1676         | WHILE
1677                 { stmt_count++;
1678                   emit_line_note ($<filename>-1, $<lineno>0);
1679                   /* The emit_nop used to come before emit_line_note,
1680                      but that made the nop seem like part of the preceding line.
1681                      And that was confusing when the preceding line was
1682                      inside of an if statement and was not really executed.
1683                      I think it ought to work to put the nop after the line number.
1684                      We will see.  --rms, July 15, 1991.  */
1685                   emit_nop (); }
1686           '(' expr ')'
1687                 { /* Don't start the loop till we have succeeded
1688                      in parsing the end test.  This is to make sure
1689                      that we end every loop we start.  */
1690                   expand_start_loop (1);
1691                   emit_line_note (input_filename, lineno);
1692                   expand_exit_loop_if_false (NULL_PTR,
1693                                              truthvalue_conversion ($4));
1694                   position_after_white_space (); }
1695           lineno_labeled_stmt
1696                 { expand_end_loop (); }
1697         | do_stmt_start
1698           '(' expr ')' ';'
1699                 { emit_line_note (input_filename, lineno);
1700                   expand_exit_loop_if_false (NULL_PTR,
1701                                              truthvalue_conversion ($3));
1702                   expand_end_loop ();
1703                   clear_momentary (); }
1704 /* This rule is needed to make sure we end every loop we start.  */
1705         | do_stmt_start error
1706                 { expand_end_loop ();
1707                   clear_momentary (); }
1708         | FOR
1709           '(' xexpr ';'
1710                 { stmt_count++;
1711                   emit_line_note ($<filename>-1, $<lineno>0);
1712                   /* See comment in `while' alternative, above.  */
1713                   emit_nop ();
1714                   if ($3) c_expand_expr_stmt ($3);
1715                   /* Next step is to call expand_start_loop_continue_elsewhere,
1716                      but wait till after we parse the entire for (...).
1717                      Otherwise, invalid input might cause us to call that
1718                      fn without calling expand_end_loop.  */
1719                 }
1720           xexpr ';'
1721                 /* Can't emit now; wait till after expand_start_loop...  */
1722                 { $<lineno>7 = lineno;
1723                   $<filename>$ = input_filename; }
1724           xexpr ')'
1725                 { 
1726                   /* Start the loop.  Doing this after parsing
1727                      all the expressions ensures we will end the loop.  */
1728                   expand_start_loop_continue_elsewhere (1);
1729                   /* Emit the end-test, with a line number.  */
1730                   emit_line_note ($<filename>8, $<lineno>7);
1731                   if ($6)
1732                     expand_exit_loop_if_false (NULL_PTR,
1733                                                truthvalue_conversion ($6));
1734                   /* Don't let the tree nodes for $9 be discarded by
1735                      clear_momentary during the parsing of the next stmt.  */
1736                   push_momentary ();
1737                   $<lineno>7 = lineno;
1738                   $<filename>8 = input_filename;
1739                   position_after_white_space (); }
1740           lineno_labeled_stmt
1741                 { /* Emit the increment expression, with a line number.  */
1742                   emit_line_note ($<filename>8, $<lineno>7);
1743                   expand_loop_continue_here ();
1744                   if ($9)
1745                     c_expand_expr_stmt ($9);
1746                   pop_momentary ();
1747                   expand_end_loop (); }
1748         | SWITCH '(' expr ')'
1749                 { stmt_count++;
1750                   emit_line_note ($<filename>-1, $<lineno>0);
1751                   c_expand_start_case ($3);
1752                   /* Don't let the tree nodes for $3 be discarded by
1753                      clear_momentary during the parsing of the next stmt.  */
1754                   push_momentary ();
1755                   position_after_white_space (); }
1756           lineno_labeled_stmt
1757                 { expand_end_case ($3);
1758                   pop_momentary (); }
1759         | BREAK ';'
1760                 { stmt_count++;
1761                   emit_line_note ($<filename>-1, $<lineno>0);
1762                   if ( ! expand_exit_something ())
1763                     error ("break statement not within loop or switch"); }
1764         | CONTINUE ';'
1765                 { stmt_count++;
1766                   emit_line_note ($<filename>-1, $<lineno>0);
1767                   if (! expand_continue_loop (NULL_PTR))
1768                     error ("continue statement not within a loop"); }
1769         | RETURN ';'
1770                 { stmt_count++;
1771                   emit_line_note ($<filename>-1, $<lineno>0);
1772                   c_expand_return (NULL_TREE); }
1773         | RETURN expr ';'
1774                 { stmt_count++;
1775                   emit_line_note ($<filename>-1, $<lineno>0);
1776                   c_expand_return ($2); }
1777         | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
1778                 { stmt_count++;
1779                   emit_line_note ($<filename>-1, $<lineno>0);
1780                   STRIP_NOPS ($4);
1781                   if ((TREE_CODE ($4) == ADDR_EXPR
1782                        && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
1783                       || TREE_CODE ($4) == STRING_CST)
1784                     expand_asm ($4);
1785                   else
1786                     error ("argument of `asm' is not a constant string"); }
1787         /* This is the case with just output operands.  */
1788         | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
1789                 { stmt_count++;
1790                   emit_line_note ($<filename>-1, $<lineno>0);
1791                   c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
1792                                          $2 == ridpointers[(int)RID_VOLATILE],
1793                                          input_filename, lineno); }
1794         /* This is the case with input operands as well.  */
1795         | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
1796                 { stmt_count++;
1797                   emit_line_note ($<filename>-1, $<lineno>0);
1798                   c_expand_asm_operands ($4, $6, $8, NULL_TREE,
1799                                          $2 == ridpointers[(int)RID_VOLATILE],
1800                                          input_filename, lineno); }
1801         /* This is the case with clobbered registers as well.  */
1802         | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
1803           asm_operands ':' asm_clobbers ')' ';'
1804                 { stmt_count++;
1805                   emit_line_note ($<filename>-1, $<lineno>0);
1806                   c_expand_asm_operands ($4, $6, $8, $10,
1807                                          $2 == ridpointers[(int)RID_VOLATILE],
1808                                          input_filename, lineno); }
1809         | GOTO identifier ';'
1810                 { tree decl;
1811                   stmt_count++;
1812                   emit_line_note ($<filename>-1, $<lineno>0);
1813                   decl = lookup_label ($2);
1814                   if (decl != 0)
1815                     {
1816                       TREE_USED (decl) = 1;
1817                       expand_goto (decl);
1818                     }
1819                 }
1820         | GOTO '*' expr ';'
1821                 { stmt_count++;
1822                   emit_line_note ($<filename>-1, $<lineno>0);
1823                   expand_computed_goto (convert (ptr_type_node, $3)); }
1824         | ';'
1825         ;
1827 all_iter_stmt:
1828           all_iter_stmt_simple
1829 /*      | all_iter_stmt_with_decl */
1830         ;
1832 all_iter_stmt_simple:
1833           FOR '(' primary ')' 
1834           {
1835             /* The value returned by this action is  */
1836             /*      1 if everything is OK */ 
1837             /*      0 in case of error or already bound iterator */
1839             $<itype>$ = 0;
1840             if (TREE_CODE ($3) != VAR_DECL)
1841               error ("invalid `for (ITERATOR)' syntax");
1842             else if (! ITERATOR_P ($3))
1843               error ("`%s' is not an iterator",
1844                      IDENTIFIER_POINTER (DECL_NAME ($3)));
1845             else if (ITERATOR_BOUND_P ($3))
1846               error ("`for (%s)' inside expansion of same iterator",
1847                      IDENTIFIER_POINTER (DECL_NAME ($3)));
1848             else
1849               {
1850                 $<itype>$ = 1;
1851                 iterator_for_loop_start ($3);
1852               }
1853           }
1854           lineno_labeled_stmt
1855           {
1856             if ($<itype>5)
1857               iterator_for_loop_end ($3);
1858           }
1860 /*  This really should allow any kind of declaration,
1861     for generality.  Fix it before turning it back on.
1863 all_iter_stmt_with_decl:
1864           FOR '(' ITERATOR pushlevel setspecs iterator_spec ')' 
1865           {
1866 */          /* The value returned by this action is  */
1867             /*      1 if everything is OK */ 
1868             /*      0 in case of error or already bound iterator */
1870             iterator_for_loop_start ($6);
1871           }
1872           lineno_labeled_stmt
1873           {
1874             iterator_for_loop_end ($6);
1875             emit_line_note (input_filename, lineno);
1876             expand_end_bindings (getdecls (), 1, 0);
1877             $<ttype>$ = poplevel (1, 1, 0);
1878             pop_momentary ();       
1879           }
1882 /* Any kind of label, including jump labels and case labels.
1883    ANSI C accepts labels only before statements, but we allow them
1884    also at the end of a compound statement.  */
1886 label:    CASE expr_no_commas ':'
1887                 { register tree value = check_case_value ($2);
1888                   register tree label
1889                     = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1891                   stmt_count++;
1893                   if (value != error_mark_node)
1894                     {
1895                       tree duplicate;
1896                       int success = pushcase (value, convert_and_check,
1897                                               label, &duplicate);
1898                       if (success == 1)
1899                         error ("case label not within a switch statement");
1900                       else if (success == 2)
1901                         {
1902                           error ("duplicate case value");
1903                           error_with_decl (duplicate, "this is the first entry for that value");
1904                         }
1905                       else if (success == 3)
1906                         warning ("case value out of range");
1907                       else if (success == 5)
1908                         error ("case label within scope of cleanup or variable array");
1909                     }
1910                   position_after_white_space (); }
1911         | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
1912                 { register tree value1 = check_case_value ($2);
1913                   register tree value2 = check_case_value ($4);
1914                   register tree label
1915                     = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1917                   stmt_count++;
1919                   if (value1 != error_mark_node && value2 != error_mark_node)
1920                     {
1921                       tree duplicate;
1922                       int success = pushcase_range (value1, value2,
1923                                                     convert_and_check, label,
1924                                                     &duplicate);
1925                       if (success == 1)
1926                         error ("case label not within a switch statement");
1927                       else if (success == 2)
1928                         {
1929                           error ("duplicate case value");
1930                           error_with_decl (duplicate, "this is the first entry for that value");
1931                         }
1932                       else if (success == 3)
1933                         warning ("case value out of range");
1934                       else if (success == 4)
1935                         warning ("empty case range");
1936                       else if (success == 5)
1937                         error ("case label within scope of cleanup or variable array");
1938                     }
1939                   position_after_white_space (); }
1940         | DEFAULT ':'
1941                 {
1942                   tree duplicate;
1943                   register tree label
1944                     = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1945                   int success = pushcase (NULL_TREE, 0, label, &duplicate);
1946                   stmt_count++;
1947                   if (success == 1)
1948                     error ("default label not within a switch statement");
1949                   else if (success == 2)
1950                     {
1951                       error ("multiple default labels in one switch");
1952                       error_with_decl (duplicate, "this is the first default label");
1953                     }
1954                   position_after_white_space (); }
1955         | identifier ':'
1956                 { tree label = define_label (input_filename, lineno, $1);
1957                   stmt_count++;
1958                   emit_nop ();
1959                   if (label)
1960                     expand_label (label);
1961                   position_after_white_space (); }
1962         ;
1964 /* Either a type-qualifier or nothing.  First thing in an `asm' statement.  */
1966 maybe_type_qual:
1967         /* empty */
1968                 { emit_line_note (input_filename, lineno); }
1969         | TYPE_QUAL
1970                 { emit_line_note (input_filename, lineno); }
1971         ;
1973 xexpr:
1974         /* empty */
1975                 { $$ = NULL_TREE; }
1976         | expr
1977         ;
1979 /* These are the operands other than the first string and colon
1980    in  asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x))  */
1981 asm_operands: /* empty */
1982                 { $$ = NULL_TREE; }
1983         | nonnull_asm_operands
1984         ;
1986 nonnull_asm_operands:
1987           asm_operand
1988         | nonnull_asm_operands ',' asm_operand
1989                 { $$ = chainon ($1, $3); }
1990         ;
1992 asm_operand:
1993           STRING '(' expr ')'
1994                 { $$ = build_tree_list ($1, $3); }
1995         ;
1997 asm_clobbers:
1998           string
1999                 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
2000         | asm_clobbers ',' string
2001                 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
2002         ;
2004 /* This is what appears inside the parens in a function declarator.
2005    Its value is a list of ..._TYPE nodes.  */
2006 parmlist:
2007                 { pushlevel (0);
2008                   clear_parm_order ();
2009                   declare_parm_level (0); }
2010           parmlist_1
2011                 { $$ = $2;
2012                   parmlist_tags_warning ();
2013                   poplevel (0, 0, 0); }
2014         ;
2016 parmlist_1:
2017           parmlist_2 ')'
2018         | parms ';'
2019                 { tree parm;
2020                   if (pedantic)
2021                     pedwarn ("ANSI C forbids forward parameter declarations");
2022                   /* Mark the forward decls as such.  */
2023                   for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2024                     TREE_ASM_WRITTEN (parm) = 1;
2025                   clear_parm_order (); }
2026           parmlist_1
2027                 { $$ = $4; }
2028         | error ')'
2029                 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2030         ;
2032 /* This is what appears inside the parens in a function declarator.
2033    Is value is represented in the format that grokdeclarator expects.  */
2034 parmlist_2:  /* empty */
2035                 { $$ = get_parm_info (0); }
2036         | ELLIPSIS
2037                 { $$ = get_parm_info (0);
2038                   if (pedantic)
2039                     pedwarn ("ANSI C requires a named argument before `...'");
2040                 }
2041         | parms
2042                 { $$ = get_parm_info (1); }
2043         | parms ',' ELLIPSIS
2044                 { $$ = get_parm_info (0); }
2045         ;
2047 parms:
2048         parm
2049                 { push_parm_decl ($1); }
2050         | parms ',' parm
2051                 { push_parm_decl ($3); }
2052         ;
2054 /* A single parameter declaration or parameter type name,
2055    as found in a parmlist.  */
2056 parm:
2057           typed_declspecs parm_declarator
2058                 { $$ = build_tree_list ($1, $2) ; }
2059         | typed_declspecs notype_declarator
2060                 { $$ = build_tree_list ($1, $2) ; }
2061         | typed_declspecs absdcl
2062                 { $$ = build_tree_list ($1, $2); }
2063         | declmods notype_declarator
2064                 { $$ = build_tree_list ($1, $2) ; }
2065         | declmods absdcl
2066                 { $$ = build_tree_list ($1, $2); }
2067         ;
2069 /* This is used in a function definition
2070    where either a parmlist or an identifier list is ok.
2071    Its value is a list of ..._TYPE nodes or a list of identifiers.  */
2072 parmlist_or_identifiers:
2073                 { pushlevel (0);
2074                   clear_parm_order ();
2075                   declare_parm_level (1); }
2076           parmlist_or_identifiers_1
2077                 { $$ = $2;
2078                   parmlist_tags_warning ();
2079                   poplevel (0, 0, 0); }
2080         ;
2082 parmlist_or_identifiers_1:
2083           parmlist_1
2084         | identifiers ')'
2085                 { tree t;
2086                   for (t = $1; t; t = TREE_CHAIN (t))
2087                     if (TREE_VALUE (t) == NULL_TREE)
2088                       error ("`...' in old-style identifier list");
2089                   $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2090         ;
2092 /* A nonempty list of identifiers.  */
2093 identifiers:
2094         IDENTIFIER
2095                 { $$ = build_tree_list (NULL_TREE, $1); }
2096         | identifiers ',' IDENTIFIER
2097                 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2098         ;
2100 /* A nonempty list of identifiers, including typenames.  */
2101 identifiers_or_typenames:
2102         identifier
2103                 { $$ = build_tree_list (NULL_TREE, $1); }
2104         | identifiers_or_typenames ',' identifier
2105                 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2106         ;
2108 ifobjc
2109 /* Objective-C productions.  */
2111 objcdef:
2112           classdef
2113         | classdecl
2114         | aliasdecl
2115         | protocoldef
2116         | methoddef
2117         | END
2118                 {
2119                   if (objc_implementation_context)
2120                     {
2121                       finish_class (objc_implementation_context);
2122                       objc_ivar_chain = NULL_TREE;
2123                       objc_implementation_context = NULL_TREE;
2124                     }
2125                   else
2126                     warning ("`@end' must appear in an implementation context");
2127                 }
2128         ;
2130 /* A nonempty list of identifiers.  */
2131 identifier_list:
2132         identifier
2133                 { $$ = build_tree_list (NULL_TREE, $1); }
2134         | identifier_list ',' identifier
2135                 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2136         ;
2138 classdecl:
2139           CLASS identifier_list ';'
2140                 {
2141                   objc_declare_class ($2);
2142                 }
2144 aliasdecl:
2145           ALIAS identifier identifier ';'
2146                 {
2147                   objc_declare_alias ($2, $3);
2148                 }
2150 classdef:
2151           INTERFACE identifier protocolrefs '{'
2152                 {
2153                   objc_interface_context = objc_ivar_context
2154                     = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2155                   objc_public_flag = 0;
2156                 }
2157           ivar_decl_list '}'
2158                 {
2159                   continue_class (objc_interface_context);
2160                 }
2161           methodprotolist
2162           END
2163                 {
2164                   finish_class (objc_interface_context);
2165                   objc_interface_context = NULL_TREE;
2166                 }
2168         | INTERFACE identifier protocolrefs
2169                 {
2170                   objc_interface_context
2171                     = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2172                   continue_class (objc_interface_context);
2173                 }
2174           methodprotolist
2175           END
2176                 {
2177                   finish_class (objc_interface_context);
2178                   objc_interface_context = NULL_TREE;
2179                 }
2181         | INTERFACE identifier ':' identifier protocolrefs '{'
2182                 {
2183                   objc_interface_context = objc_ivar_context
2184                     = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2185                   objc_public_flag = 0;
2186                 }
2187           ivar_decl_list '}'
2188                 {
2189                   continue_class (objc_interface_context);
2190                 }
2191           methodprotolist
2192           END
2193                 {
2194                   finish_class (objc_interface_context);
2195                   objc_interface_context = NULL_TREE;
2196                 }
2198         | INTERFACE identifier ':' identifier protocolrefs
2199                 {
2200                   objc_interface_context
2201                     = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2202                   continue_class (objc_interface_context);
2203                 }
2204           methodprotolist
2205           END
2206                 {
2207                   finish_class (objc_interface_context);
2208                   objc_interface_context = NULL_TREE;
2209                 }
2211         | IMPLEMENTATION identifier '{'
2212                 {
2213                   objc_implementation_context = objc_ivar_context
2214                     = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2215                   objc_public_flag = 0;
2216                 }
2217           ivar_decl_list '}'
2218                 {
2219                   objc_ivar_chain
2220                     = continue_class (objc_implementation_context);
2221                 }
2223         | IMPLEMENTATION identifier
2224                 {
2225                   objc_implementation_context
2226                     = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2227                   objc_ivar_chain
2228                     = continue_class (objc_implementation_context);
2229                 }
2231         | IMPLEMENTATION identifier ':' identifier '{'
2232                 {
2233                   objc_implementation_context = objc_ivar_context
2234                     = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2235                   objc_public_flag = 0;
2236                 }
2237           ivar_decl_list '}'
2238                 {
2239                   objc_ivar_chain
2240                     = continue_class (objc_implementation_context);
2241                 }
2243         | IMPLEMENTATION identifier ':' identifier
2244                 {
2245                   objc_implementation_context
2246                     = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2247                   objc_ivar_chain
2248                     = continue_class (objc_implementation_context);
2249                 }
2251         | INTERFACE identifier '(' identifier ')' protocolrefs
2252                 {
2253                   objc_interface_context
2254                     = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2255                   continue_class (objc_interface_context);
2256                 }
2257           methodprotolist
2258           END
2259                 {
2260                   finish_class (objc_interface_context);
2261                   objc_interface_context = NULL_TREE;
2262                 }
2264         | IMPLEMENTATION identifier '(' identifier ')'
2265                 {
2266                   objc_implementation_context
2267                     = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2268                   objc_ivar_chain
2269                     = continue_class (objc_implementation_context);
2270                 }
2271         ;
2273 protocoldef:
2274           PROTOCOL identifier protocolrefs
2275                 {
2276                   remember_protocol_qualifiers ();
2277                   objc_interface_context
2278                     = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2279                 }
2280           methodprotolist END
2281                 {
2282                   forget_protocol_qualifiers();
2283                   finish_protocol(objc_interface_context);
2284                   objc_interface_context = NULL_TREE;
2285                 }
2286         ;
2288 protocolrefs:
2289           /* empty */
2290                 {
2291                   $$ = NULL_TREE;
2292                 }
2293         | ARITHCOMPARE identifier_list ARITHCOMPARE
2294                 {
2295                   if ($1 == LT_EXPR && $3 == GT_EXPR)
2296                     $$ = $2;
2297                   else
2298                     YYERROR1;
2299                 }
2300         ;
2302 ivar_decl_list:
2303           ivar_decl_list visibility_spec ivar_decls
2304         | ivar_decls
2305         ;
2307 visibility_spec:
2308           PRIVATE { objc_public_flag = 2; }
2309         | PROTECTED { objc_public_flag = 0; }
2310         | PUBLIC { objc_public_flag = 1; }
2311         ;
2313 ivar_decls:
2314           /* empty */
2315                 {
2316                   $$ = NULL_TREE;
2317                 }
2318         | ivar_decls ivar_decl ';'
2319         | ivar_decls ';'
2320                 {
2321                   if (pedantic)
2322                     pedwarn ("extra semicolon in struct or union specified");
2323                 }
2324         ;
2327 /* There is a shift-reduce conflict here, because `components' may
2328    start with a `typename'.  It happens that shifting (the default resolution)
2329    does the right thing, because it treats the `typename' as part of
2330    a `typed_typespecs'.
2332    It is possible that this same technique would allow the distinction
2333    between `notype_initdecls' and `initdecls' to be eliminated.
2334    But I am being cautious and not trying it.  */
2336 ivar_decl:
2337         typed_typespecs setspecs ivars
2338                 {
2339                   $$ = $3;
2340                   resume_momentary ($2);
2341                 }
2342         | nonempty_type_quals setspecs ivars
2343                 {
2344                   $$ = $3;
2345                   resume_momentary ($2);
2346                 }
2347         | error
2348                 { $$ = NULL_TREE; }
2349         ;
2351 ivars:
2352           /* empty */
2353                 { $$ = NULL_TREE; }
2354         | ivar_declarator
2355         | ivars ',' ivar_declarator
2356         ;
2358 ivar_declarator:
2359           declarator
2360                 {
2361                   $$ = add_instance_variable (objc_ivar_context,
2362                                               objc_public_flag,
2363                                               $1, current_declspecs,
2364                                               NULL_TREE);
2365                 }
2366         | declarator ':' expr_no_commas
2367                 {
2368                   $$ = add_instance_variable (objc_ivar_context,
2369                                               objc_public_flag,
2370                                               $1, current_declspecs, $3);
2371                 }
2372         | ':' expr_no_commas
2373                 {
2374                   $$ = add_instance_variable (objc_ivar_context,
2375                                               objc_public_flag,
2376                                               NULL_TREE,
2377                                               current_declspecs, $2);
2378                 }
2379         ;
2381 methoddef:
2382           '+'
2383                 {
2384                   remember_protocol_qualifiers ();
2385                   if (objc_implementation_context)
2386                     objc_inherit_code = CLASS_METHOD_DECL;
2387                   else
2388                     fatal ("method definition not in class context");
2389                 }
2390           methoddecl
2391                 {
2392                   forget_protocol_qualifiers ();
2393                   add_class_method (objc_implementation_context, $3);
2394                   start_method_def ($3);
2395                   objc_method_context = $3;
2396                 }
2397           optarglist
2398                 {
2399                   continue_method_def ();
2400                 }
2401           compstmt_or_error
2402                 {
2403                   finish_method_def ();
2404                   objc_method_context = NULL_TREE;
2405                 }
2407         | '-'
2408                 {
2409                   remember_protocol_qualifiers ();
2410                   if (objc_implementation_context)
2411                     objc_inherit_code = INSTANCE_METHOD_DECL;
2412                   else
2413                     fatal ("method definition not in class context");
2414                 }
2415           methoddecl
2416                 {
2417                   forget_protocol_qualifiers ();
2418                   add_instance_method (objc_implementation_context, $3);
2419                   start_method_def ($3);
2420                   objc_method_context = $3;
2421                 }
2422           optarglist
2423                 {
2424                   continue_method_def ();
2425                 }
2426           compstmt_or_error
2427                 {
2428                   finish_method_def ();
2429                   objc_method_context = NULL_TREE;
2430                 }
2431         ;
2433 /* the reason for the strange actions in this rule
2434  is so that notype_initdecls when reached via datadef
2435  can find a valid list of type and sc specs in $0. */
2437 methodprotolist:
2438           /* empty  */
2439         | {$<ttype>$ = NULL_TREE; } methodprotolist2
2440         ;
2442 methodprotolist2:                /* eliminates a shift/reduce conflict */
2443            methodproto
2444         |  datadef
2445         | methodprotolist2 methodproto
2446         | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
2447         ;
2449 semi_or_error:
2450           ';'
2451         | error
2452         ;
2454 methodproto:
2455           '+'
2456                 {
2457                   objc_inherit_code = CLASS_METHOD_DECL;
2458                 }
2459           methoddecl
2460                 {
2461                   add_class_method (objc_interface_context, $3);
2462                 }
2463           semi_or_error
2465         | '-'
2466                 {
2467                   objc_inherit_code = INSTANCE_METHOD_DECL;
2468                 }
2469           methoddecl
2470                 {
2471                   add_instance_method (objc_interface_context, $3);
2472                 }
2473           semi_or_error
2474         ;
2476 methoddecl:
2477           '(' typename ')' unaryselector
2478                 {
2479                   $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
2480                 }
2482         | unaryselector
2483                 {
2484                   $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
2485                 }
2487         | '(' typename ')' keywordselector optparmlist
2488                 {
2489                   $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
2490                 }
2492         | keywordselector optparmlist
2493                 {
2494                   $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
2495                 }
2496         ;
2498 /* "optarglist" assumes that start_method_def has already been called...
2499    if it is not, the "xdecls" will not be placed in the proper scope */
2501 optarglist:
2502           /* empty */
2503         | ';' myxdecls
2504         ;
2506 /* to get around the following situation: "int foo (int a) int b; {}" that
2507    is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
2509 myxdecls:
2510           /* empty */
2511         | mydecls
2512         ;
2514 mydecls:
2515         mydecl
2516         | errstmt
2517         | mydecls mydecl
2518         | mydecl errstmt
2519         ;
2521 mydecl:
2522         typed_declspecs setspecs myparms ';'
2523                 { resume_momentary ($2); }
2524         | typed_declspecs ';'
2525                 { shadow_tag ($1); }
2526         | declmods ';'
2527                 { pedwarn ("empty declaration"); }
2528         ;
2530 myparms:
2531         myparm
2532                 { push_parm_decl ($1); }
2533         | myparms ',' myparm
2534                 { push_parm_decl ($3); }
2535         ;
2537 /* A single parameter declaration or parameter type name,
2538    as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
2540 myparm:
2541           parm_declarator
2542                 { $$ = build_tree_list (current_declspecs, $1)  ; }
2543         | notype_declarator
2544                 { $$ = build_tree_list (current_declspecs, $1)  ; }
2545         | absdcl
2546                 { $$ = build_tree_list (current_declspecs, $1)  ; }
2547         ;
2549 optparmlist:
2550           /* empty */
2551                 {
2552                   $$ = NULL_TREE;
2553                 }
2554         | ',' ELLIPSIS
2555                 {
2556                   /* oh what a kludge! */
2557                   $$ = (tree)1;
2558                 }
2559         | ','
2560                 {
2561                   pushlevel (0);
2562                 }
2563           parmlist_2
2564                 {
2565                   /* returns a tree list node generated by get_parm_info */
2566                   $$ = $3;
2567                   poplevel (0, 0, 0);
2568                 }
2569         ;
2571 unaryselector:
2572           selector
2573         ;
2575 keywordselector:
2576           keyworddecl
2578         | keywordselector keyworddecl
2579                 {
2580                   $$ = chainon ($1, $2);
2581                 }
2582         ;
2584 selector:
2585           IDENTIFIER
2586         | TYPENAME
2587         | OBJECTNAME
2588         | reservedwords
2589         ;
2591 reservedwords:
2592           ENUM { $$ = get_identifier (token_buffer); }
2593         | STRUCT { $$ = get_identifier (token_buffer); }
2594         | UNION { $$ = get_identifier (token_buffer); }
2595         | IF { $$ = get_identifier (token_buffer); }
2596         | ELSE { $$ = get_identifier (token_buffer); }
2597         | WHILE { $$ = get_identifier (token_buffer); }
2598         | DO { $$ = get_identifier (token_buffer); }
2599         | FOR { $$ = get_identifier (token_buffer); }
2600         | SWITCH { $$ = get_identifier (token_buffer); }
2601         | CASE { $$ = get_identifier (token_buffer); }
2602         | DEFAULT { $$ = get_identifier (token_buffer); }
2603         | BREAK { $$ = get_identifier (token_buffer); }
2604         | CONTINUE { $$ = get_identifier (token_buffer); }
2605         | RETURN  { $$ = get_identifier (token_buffer); }
2606         | GOTO { $$ = get_identifier (token_buffer); }
2607         | ASM_KEYWORD { $$ = get_identifier (token_buffer); }
2608         | SIZEOF { $$ = get_identifier (token_buffer); }
2609         | TYPEOF { $$ = get_identifier (token_buffer); }
2610         | ALIGNOF { $$ = get_identifier (token_buffer); }
2611         | TYPESPEC | TYPE_QUAL
2612         ;
2614 keyworddecl:
2615           selector ':' '(' typename ')' identifier
2616                 {
2617                   $$ = build_keyword_decl ($1, $4, $6);
2618                 }
2620         | selector ':' identifier
2621                 {
2622                   $$ = build_keyword_decl ($1, NULL_TREE, $3);
2623                 }
2625         | ':' '(' typename ')' identifier
2626                 {
2627                   $$ = build_keyword_decl (NULL_TREE, $3, $5);
2628                 }
2630         | ':' identifier
2631                 {
2632                   $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
2633                 }
2634         ;
2636 messageargs:
2637           selector
2638         | keywordarglist
2639         ;
2641 keywordarglist:
2642           keywordarg
2643         | keywordarglist keywordarg
2644                 {
2645                   $$ = chainon ($1, $2);
2646                 }
2647         ;
2650 keywordexpr:
2651           nonnull_exprlist
2652                 {
2653                   if (TREE_CHAIN ($1) == NULL_TREE)
2654                     /* just return the expr., remove a level of indirection */
2655                     $$ = TREE_VALUE ($1);
2656                   else
2657                     /* we have a comma expr., we will collapse later */
2658                     $$ = $1;
2659                 }
2660         ;
2662 keywordarg:
2663           selector ':' keywordexpr
2664                 {
2665                   $$ = build_tree_list ($1, $3);
2666                 }
2667         | ':' keywordexpr
2668                 {
2669                   $$ = build_tree_list (NULL_TREE, $2);
2670                 }
2671         ;
2673 receiver:
2674           expr
2675         | CLASSNAME
2676                 {
2677                   $$ = get_class_reference ($1);
2678                 }
2679         ;
2681 objcmessageexpr:
2682           '['
2683                 { objc_receiver_context = 1; }
2684           receiver
2685                 { objc_receiver_context = 0; }
2686           messageargs ']'
2687                 {
2688                   $$ = build_tree_list ($3, $5);
2689                 }
2690         ;
2692 selectorarg:
2693           selector
2694         | keywordnamelist
2695         ;
2697 keywordnamelist:
2698           keywordname
2699         | keywordnamelist keywordname
2700                 {
2701                   $$ = chainon ($1, $2);
2702                 }
2703         ;
2705 keywordname:
2706           selector ':'
2707                 {
2708                   $$ = build_tree_list ($1, NULL_TREE);
2709                 }
2710         | ':'
2711                 {
2712                   $$ = build_tree_list (NULL_TREE, NULL_TREE);
2713                 }
2714         ;
2716 objcselectorexpr:
2717           SELECTOR '(' selectorarg ')'
2718                 {
2719                   $$ = $3;
2720                 }
2721         ;
2723 objcprotocolexpr:
2724           PROTOCOL '(' identifier ')'
2725                 {
2726                   $$ = $3;
2727                 }
2728         ;
2730 /* extension to support C-structures in the archiver */
2732 objcencodeexpr:
2733           ENCODE '(' typename ')'
2734                 {
2735                   $$ = groktypename ($3);
2736                 }
2737         ;
2739 end ifobjc