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