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