Regenerate after this patch:
[official-gcc.git] / gcc / objc / objc-parse.y
blob91324bb48b0d15ca9c85d78488df4d9b9bdb945f
1 /*WARNING: This file is automatically generated!*/
2 /* YACC parser for C syntax and for Objective C. -*-c-*-
3 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* This file defines the grammar of C and that of Objective C.
24 ifobjc ... end ifobjc conditionals contain code for Objective C only.
25 ifc ... end ifc conditionals contain code for C only.
26 Sed commands in Makefile.in are used to convert this file into
27 c-parse.y and into objc-parse.y. */
29 /* To whomever it may concern: I have heard that such a thing was once
30 written by AT&T, but I have never seen it. */
32 %expect 74
35 #include "config.h"
36 #include "system.h"
37 #include <setjmp.h>
38 #include "tree.h"
39 #include "input.h"
40 #include "c-lex.h"
41 #include "c-tree.h"
42 #include "flags.h"
43 #include "output.h"
44 #include "toplev.h"
45 #include "ggc.h"
47 #ifdef MULTIBYTE_CHARS
48 #include <locale.h>
49 #endif
51 #include "objc-act.h"
53 /* Since parsers are distinct for each language, put the language string
54 definition here. */
55 const char * const language_string = "GNU Obj-C";
57 /* Like YYERROR but do call yyerror. */
58 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
60 /* Cause the `yydebug' variable to be defined. */
61 #define YYDEBUG 1
64 %start program
66 %union {long itype; tree ttype; enum tree_code code;
67 const char *filename; int lineno; int ends_in_label; }
69 /* All identifiers that are not reserved words
70 and are not declared typedefs in the current block */
71 %token IDENTIFIER
73 /* All identifiers that are declared typedefs in the current block.
74 In some contexts, they are treated just like IDENTIFIER,
75 but they can also serve as typespecs in declarations. */
76 %token TYPENAME
78 /* Reserved words that specify storage class.
79 yylval contains an IDENTIFIER_NODE which indicates which one. */
80 %token SCSPEC
82 /* Reserved words that specify type.
83 yylval contains an IDENTIFIER_NODE which indicates which one. */
84 %token TYPESPEC
86 /* Reserved words that qualify type: "const", "volatile", or "restrict".
87 yylval contains an IDENTIFIER_NODE which indicates which one. */
88 %token TYPE_QUAL
90 /* Character or numeric constants.
91 yylval is the node for the constant. */
92 %token CONSTANT
94 /* String constants in raw form.
95 yylval is a STRING_CST node. */
96 %token STRING
98 /* "...", used for functions with variable arglists. */
99 %token ELLIPSIS
101 /* the reserved words */
102 /* SCO include files test "ASM", so use something else. */
103 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
104 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
105 %token ATTRIBUTE EXTENSION LABEL
106 %token REALPART IMAGPART VA_ARG
107 %token PTR_VALUE PTR_BASE PTR_EXTENT
109 /* Used in c-lex.c for parsing pragmas. */
110 %token END_OF_LINE
112 /* Add precedence rules to solve dangling else s/r conflict */
113 %nonassoc IF
114 %nonassoc ELSE
116 /* Define the operator tokens and their precedences.
117 The value is an integer because, if used, it is the tree code
118 to use in the expression made from the operator. */
120 %right <code> ASSIGN '='
121 %right <code> '?' ':'
122 %left <code> OROR
123 %left <code> ANDAND
124 %left <code> '|'
125 %left <code> '^'
126 %left <code> '&'
127 %left <code> EQCOMPARE
128 %left <code> ARITHCOMPARE
129 %left <code> LSHIFT RSHIFT
130 %left <code> '+' '-'
131 %left <code> '*' '/' '%'
132 %right <code> UNARY PLUSPLUS MINUSMINUS
133 %left HYPERUNARY
134 %left <code> POINTSAT '.' '(' '['
136 /* The Objective-C keywords. These are included in C and in
137 Objective C, so that the token codes are the same in both. */
138 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
139 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
141 /* Objective-C string constants in raw form.
142 yylval is an OBJC_STRING_CST node. */
143 %token OBJC_STRING
146 %type <code> unop
148 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
149 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
150 %type <ttype> typed_declspecs reserved_declspecs
151 %type <ttype> typed_typespecs reserved_typespecquals
152 %type <ttype> declmods typespec typespecqual_reserved
153 %type <ttype> typed_declspecs_no_prefix_attr reserved_declspecs_no_prefix_attr
154 %type <ttype> declmods_no_prefix_attr
155 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
156 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
157 %type <ttype> init maybeasm
158 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
159 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
160 %type <ttype> any_word extension
162 %type <ttype> compstmt compstmt_nostart compstmt_primary_start
164 %type <ttype> declarator
165 %type <ttype> notype_declarator after_type_declarator
166 %type <ttype> parm_declarator
168 %type <ttype> structsp component_decl_list component_decl_list2
169 %type <ttype> component_decl components component_declarator
170 %type <ttype> enumlist enumerator
171 %type <ttype> struct_head union_head enum_head
172 %type <ttype> typename absdcl absdcl1 type_quals
173 %type <ttype> xexpr parms parm identifiers
175 %type <ttype> parmlist parmlist_1 parmlist_2
176 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
177 %type <ttype> identifiers_or_typenames
179 %type <itype> setspecs
181 %type <ends_in_label> lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
183 %type <filename> save_filename
184 %type <lineno> save_lineno
186 /* the Objective-C nonterminals */
188 %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
189 %type <ttype> methoddecl unaryselector keywordselector selector
190 %type <ttype> keyworddecl receiver objcmessageexpr messageargs
191 %type <ttype> keywordexpr keywordarglist keywordarg
192 %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
193 %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
194 %type <ttype> objc_string non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
196 %type <ttype> CLASSNAME OBJC_STRING OBJECTNAME
199 /* Number of statements (loosely speaking) and compound statements
200 seen so far. */
201 static int stmt_count;
202 static int compstmt_count;
204 /* Input file and line number of the end of the body of last simple_if;
205 used by the stmt-rule immediately after simple_if returns. */
206 static const char *if_stmt_file;
207 static int if_stmt_line;
209 /* List of types and structure classes of the current declaration. */
210 static tree current_declspecs = NULL_TREE;
211 static tree prefix_attributes = NULL_TREE;
213 /* Stack of saved values of current_declspecs and prefix_attributes. */
214 static tree declspec_stack;
216 /* For __extension__, save/restore the warning flags which are
217 controlled by __extension__. */
218 #define SAVE_WARN_FLAGS() \
219 size_int (pedantic | (warn_pointer_arith << 1))
220 #define RESTORE_WARN_FLAGS(tval) \
221 do { \
222 int val = tree_low_cst (tval, 0); \
223 pedantic = val & 1; \
224 warn_pointer_arith = (val >> 1) & 1; \
225 } while (0)
227 /* Objective-C specific information */
229 tree objc_interface_context;
230 tree objc_implementation_context;
231 tree objc_method_context;
232 tree objc_ivar_chain;
233 tree objc_ivar_context;
234 enum tree_code objc_inherit_code;
235 int objc_receiver_context;
236 int objc_public_flag;
239 /* Tell yyparse how to print a token's value, if yydebug is set. */
241 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
242 extern void yyprint PARAMS ((FILE *, int, YYSTYPE));
244 /* Add GC roots for variables local to this file. */
245 void
246 c_parse_init ()
248 ggc_add_tree_root (&declspec_stack, 1);
249 ggc_add_tree_root (&current_declspecs, 1);
250 ggc_add_tree_root (&prefix_attributes, 1);
251 ggc_add_tree_root (&objc_interface_context, 1);
252 ggc_add_tree_root (&objc_implementation_context, 1);
253 ggc_add_tree_root (&objc_method_context, 1);
254 ggc_add_tree_root (&objc_ivar_chain, 1);
255 ggc_add_tree_root (&objc_ivar_context, 1);
261 program: /* empty */
262 { if (pedantic)
263 pedwarn ("ANSI C forbids an empty source file");
264 finish_file ();
266 | extdefs
268 /* In case there were missing closebraces,
269 get us back to the global binding level. */
270 while (! global_bindings_p ())
271 poplevel (0, 0, 0);
272 finish_file ();
276 /* the reason for the strange actions in this rule
277 is so that notype_initdecls when reached via datadef
278 can find a valid list of type and sc specs in $0. */
280 extdefs:
281 {$<ttype>$ = NULL_TREE; } extdef
282 | extdefs {$<ttype>$ = NULL_TREE; } extdef
285 extdef:
286 fndef
287 | datadef
288 | objcdef
289 | ASM_KEYWORD '(' expr ')' ';'
290 { STRIP_NOPS ($3);
291 if ((TREE_CODE ($3) == ADDR_EXPR
292 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
293 || TREE_CODE ($3) == STRING_CST)
294 assemble_asm ($3);
295 else
296 error ("argument of `asm' is not a constant string"); }
297 | extension extdef
298 { RESTORE_WARN_FLAGS ($1); }
301 datadef:
302 setspecs notype_initdecls ';'
303 { if (pedantic)
304 error ("ANSI C forbids data definition with no type or storage class");
305 else if (!flag_traditional)
306 warning ("data definition has no type or storage class");
308 current_declspecs = TREE_VALUE (declspec_stack);
309 prefix_attributes = TREE_PURPOSE (declspec_stack);
310 declspec_stack = TREE_CHAIN (declspec_stack); }
311 | declmods setspecs notype_initdecls ';'
312 { current_declspecs = TREE_VALUE (declspec_stack);
313 prefix_attributes = TREE_PURPOSE (declspec_stack);
314 declspec_stack = TREE_CHAIN (declspec_stack); }
315 | typed_declspecs setspecs initdecls ';'
316 { current_declspecs = TREE_VALUE (declspec_stack);
317 prefix_attributes = TREE_PURPOSE (declspec_stack);
318 declspec_stack = TREE_CHAIN (declspec_stack); }
319 | declmods ';'
320 { pedwarn ("empty declaration"); }
321 | typed_declspecs ';'
322 { shadow_tag ($1); }
323 | error ';'
324 | error '}'
325 | ';'
326 { if (pedantic)
327 pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
330 fndef:
331 typed_declspecs setspecs declarator
332 { if (! start_function (current_declspecs, $3,
333 prefix_attributes, NULL_TREE))
334 YYERROR1;
335 reinit_parse_for_function (); }
336 old_style_parm_decls
337 { store_parm_decls (); }
338 compstmt_or_error
339 { finish_function (0);
340 current_declspecs = TREE_VALUE (declspec_stack);
341 prefix_attributes = TREE_PURPOSE (declspec_stack);
342 declspec_stack = TREE_CHAIN (declspec_stack); }
343 | typed_declspecs setspecs declarator error
344 { current_declspecs = TREE_VALUE (declspec_stack);
345 prefix_attributes = TREE_PURPOSE (declspec_stack);
346 declspec_stack = TREE_CHAIN (declspec_stack); }
347 | declmods setspecs notype_declarator
348 { if (! start_function (current_declspecs, $3,
349 prefix_attributes, NULL_TREE))
350 YYERROR1;
351 reinit_parse_for_function (); }
352 old_style_parm_decls
353 { store_parm_decls (); }
354 compstmt_or_error
355 { finish_function (0);
356 current_declspecs = TREE_VALUE (declspec_stack);
357 prefix_attributes = TREE_PURPOSE (declspec_stack);
358 declspec_stack = TREE_CHAIN (declspec_stack); }
359 | declmods setspecs notype_declarator error
360 { current_declspecs = TREE_VALUE (declspec_stack);
361 prefix_attributes = TREE_PURPOSE (declspec_stack);
362 declspec_stack = TREE_CHAIN (declspec_stack); }
363 | setspecs notype_declarator
364 { if (! start_function (NULL_TREE, $2,
365 prefix_attributes, NULL_TREE))
366 YYERROR1;
367 reinit_parse_for_function (); }
368 old_style_parm_decls
369 { store_parm_decls (); }
370 compstmt_or_error
371 { finish_function (0);
372 current_declspecs = TREE_VALUE (declspec_stack);
373 prefix_attributes = TREE_PURPOSE (declspec_stack);
374 declspec_stack = TREE_CHAIN (declspec_stack); }
375 | setspecs notype_declarator error
376 { current_declspecs = TREE_VALUE (declspec_stack);
377 prefix_attributes = TREE_PURPOSE (declspec_stack);
378 declspec_stack = TREE_CHAIN (declspec_stack); }
381 identifier:
382 IDENTIFIER
383 | TYPENAME
384 | OBJECTNAME
385 | CLASSNAME
388 unop: '&'
389 { $$ = ADDR_EXPR; }
390 | '-'
391 { $$ = NEGATE_EXPR; }
392 | '+'
393 { $$ = CONVERT_EXPR; }
394 | PLUSPLUS
395 { $$ = PREINCREMENT_EXPR; }
396 | MINUSMINUS
397 { $$ = PREDECREMENT_EXPR; }
398 | '~'
399 { $$ = BIT_NOT_EXPR; }
400 | '!'
401 { $$ = TRUTH_NOT_EXPR; }
404 expr: nonnull_exprlist
405 { $$ = build_compound_expr ($1); }
408 exprlist:
409 /* empty */
410 { $$ = NULL_TREE; }
411 | nonnull_exprlist
414 nonnull_exprlist:
415 expr_no_commas
416 { $$ = build_tree_list (NULL_TREE, $1); }
417 | nonnull_exprlist ',' expr_no_commas
418 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
421 unary_expr:
422 primary
423 | '*' cast_expr %prec UNARY
424 { $$ = build_indirect_ref ($2, "unary *"); }
425 /* __extension__ turns off -pedantic for following primary. */
426 | extension cast_expr %prec UNARY
427 { $$ = $2;
428 RESTORE_WARN_FLAGS ($1); }
429 | unop cast_expr %prec UNARY
430 { $$ = build_unary_op ($1, $2, 0);
431 overflow_warning ($$); }
432 /* Refer to the address of a label as a pointer. */
433 | ANDAND identifier
434 { tree label = lookup_label ($2);
435 if (pedantic)
436 pedwarn ("ANSI C forbids `&&'");
437 if (label == 0)
438 $$ = null_pointer_node;
439 else
441 TREE_USED (label) = 1;
442 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
443 TREE_CONSTANT ($$) = 1;
446 /* This seems to be impossible on some machines, so let's turn it off.
447 You can use __builtin_next_arg to find the anonymous stack args.
448 | '&' ELLIPSIS
449 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
450 $$ = error_mark_node;
451 if (TREE_VALUE (tree_last (types)) == void_type_node)
452 error ("`&...' used in function with fixed number of arguments");
453 else
455 if (pedantic)
456 pedwarn ("ANSI C forbids `&...'");
457 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
458 $$ = build_unary_op (ADDR_EXPR, $$, 0);
461 | sizeof unary_expr %prec UNARY
462 { skip_evaluation--;
463 if (TREE_CODE ($2) == COMPONENT_REF
464 && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
465 error ("`sizeof' applied to a bit-field");
466 $$ = c_sizeof (TREE_TYPE ($2)); }
467 | sizeof '(' typename ')' %prec HYPERUNARY
468 { skip_evaluation--;
469 $$ = c_sizeof (groktypename ($3)); }
470 | alignof unary_expr %prec UNARY
471 { skip_evaluation--;
472 $$ = c_alignof_expr ($2); }
473 | alignof '(' typename ')' %prec HYPERUNARY
474 { skip_evaluation--;
475 $$ = c_alignof (groktypename ($3)); }
476 | REALPART cast_expr %prec UNARY
477 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
478 | IMAGPART cast_expr %prec UNARY
479 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
480 | VA_ARG '(' expr_no_commas ',' typename ')'
481 { $$ = build_va_arg ($3, groktypename ($5)); }
484 sizeof:
485 SIZEOF { skip_evaluation++; }
488 alignof:
489 ALIGNOF { skip_evaluation++; }
492 cast_expr:
493 unary_expr
494 | '(' typename ')' cast_expr %prec UNARY
495 { tree type = groktypename ($2);
496 $$ = build_c_cast (type, $4); }
497 | '(' typename ')' '{'
498 { start_init (NULL_TREE, NULL, 0);
499 $2 = groktypename ($2);
500 really_start_incremental_init ($2); }
501 initlist_maybe_comma '}' %prec UNARY
502 { const char *name;
503 tree result = pop_init_level (0);
504 tree type = $2;
505 finish_init ();
507 if (pedantic && ! flag_isoc99)
508 pedwarn ("ANSI C forbids constructor expressions");
509 if (TYPE_NAME (type) != 0)
511 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
512 name = IDENTIFIER_POINTER (TYPE_NAME (type));
513 else
514 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
516 else
517 name = "";
518 $$ = result;
519 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
521 int failure = complete_array_type (type, $$, 1);
522 if (failure)
523 abort ();
528 expr_no_commas:
529 cast_expr
530 | expr_no_commas '+' expr_no_commas
531 { $$ = parser_build_binary_op ($2, $1, $3); }
532 | expr_no_commas '-' expr_no_commas
533 { $$ = parser_build_binary_op ($2, $1, $3); }
534 | expr_no_commas '*' expr_no_commas
535 { $$ = parser_build_binary_op ($2, $1, $3); }
536 | expr_no_commas '/' expr_no_commas
537 { $$ = parser_build_binary_op ($2, $1, $3); }
538 | expr_no_commas '%' expr_no_commas
539 { $$ = parser_build_binary_op ($2, $1, $3); }
540 | expr_no_commas LSHIFT expr_no_commas
541 { $$ = parser_build_binary_op ($2, $1, $3); }
542 | expr_no_commas RSHIFT expr_no_commas
543 { $$ = parser_build_binary_op ($2, $1, $3); }
544 | expr_no_commas ARITHCOMPARE expr_no_commas
545 { $$ = parser_build_binary_op ($2, $1, $3); }
546 | expr_no_commas EQCOMPARE expr_no_commas
547 { $$ = parser_build_binary_op ($2, $1, $3); }
548 | expr_no_commas '&' expr_no_commas
549 { $$ = parser_build_binary_op ($2, $1, $3); }
550 | expr_no_commas '|' expr_no_commas
551 { $$ = parser_build_binary_op ($2, $1, $3); }
552 | expr_no_commas '^' expr_no_commas
553 { $$ = parser_build_binary_op ($2, $1, $3); }
554 | expr_no_commas ANDAND
555 { $1 = truthvalue_conversion (default_conversion ($1));
556 skip_evaluation += $1 == boolean_false_node; }
557 expr_no_commas
558 { skip_evaluation -= $1 == boolean_false_node;
559 $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
560 | expr_no_commas OROR
561 { $1 = truthvalue_conversion (default_conversion ($1));
562 skip_evaluation += $1 == boolean_true_node; }
563 expr_no_commas
564 { skip_evaluation -= $1 == boolean_true_node;
565 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
566 | expr_no_commas '?'
567 { $1 = truthvalue_conversion (default_conversion ($1));
568 skip_evaluation += $1 == boolean_false_node; }
569 expr ':'
570 { skip_evaluation += (($1 == boolean_true_node)
571 - ($1 == boolean_false_node)); }
572 expr_no_commas
573 { skip_evaluation -= $1 == boolean_true_node;
574 $$ = build_conditional_expr ($1, $4, $7); }
575 | expr_no_commas '?'
576 { if (pedantic)
577 pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
578 /* Make sure first operand is calculated only once. */
579 $<ttype>2 = save_expr ($1);
580 $1 = truthvalue_conversion (default_conversion ($<ttype>2));
581 skip_evaluation += $1 == boolean_true_node; }
582 ':' expr_no_commas
583 { skip_evaluation -= $1 == boolean_true_node;
584 $$ = build_conditional_expr ($1, $<ttype>2, $5); }
585 | expr_no_commas '=' expr_no_commas
586 { char class;
587 $$ = build_modify_expr ($1, NOP_EXPR, $3);
588 class = TREE_CODE_CLASS (TREE_CODE ($$));
589 if (class == 'e' || class == '1'
590 || class == '2' || class == '<')
591 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR);
593 | expr_no_commas ASSIGN expr_no_commas
594 { char class;
595 $$ = build_modify_expr ($1, $2, $3);
596 /* This inhibits warnings in truthvalue_conversion. */
597 class = TREE_CODE_CLASS (TREE_CODE ($$));
598 if (class == 'e' || class == '1'
599 || class == '2' || class == '<')
600 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK);
604 primary:
605 IDENTIFIER
607 if (yychar == YYEMPTY)
608 yychar = YYLEX;
609 $$ = build_external_ref ($1, yychar == '(');
611 | CONSTANT
612 | string
613 { $$ = combine_strings ($1); }
614 | '(' expr ')'
615 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
616 if (class == 'e' || class == '1'
617 || class == '2' || class == '<')
618 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
619 $$ = $2; }
620 | '(' error ')'
621 { $$ = error_mark_node; }
622 | compstmt_primary_start compstmt_nostart ')'
623 { tree rtl_exp;
624 if (pedantic)
625 pedwarn ("ANSI C forbids braced-groups within expressions");
626 pop_iterator_stack ();
627 pop_label_level ();
628 rtl_exp = expand_end_stmt_expr ($1);
629 /* The statements have side effects, so the group does. */
630 TREE_SIDE_EFFECTS (rtl_exp) = 1;
632 if (TREE_CODE ($2) == BLOCK)
634 /* Make a BIND_EXPR for the BLOCK already made. */
635 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
636 NULL_TREE, rtl_exp, $2);
637 /* Remove the block from the tree at this point.
638 It gets put back at the proper place
639 when the BIND_EXPR is expanded. */
640 delete_block ($2);
642 else
643 $$ = $2;
645 | compstmt_primary_start error ')'
647 /* Make sure we call expand_end_stmt_expr. Otherwise
648 we are likely to lose sequences and crash later. */
649 pop_iterator_stack ();
650 pop_label_level ();
651 expand_end_stmt_expr ($1);
652 $$ = error_mark_node;
654 | primary '(' exprlist ')' %prec '.'
655 { $$ = build_function_call ($1, $3); }
656 | primary '[' expr ']' %prec '.'
657 { $$ = build_array_ref ($1, $3); }
658 | primary '.' identifier
660 if (doing_objc_thang)
662 if (is_public ($1, $3))
663 $$ = build_component_ref ($1, $3);
664 else
665 $$ = error_mark_node;
667 else
668 $$ = build_component_ref ($1, $3);
670 | primary POINTSAT identifier
672 tree expr = build_indirect_ref ($1, "->");
674 if (doing_objc_thang)
676 if (is_public (expr, $3))
677 $$ = build_component_ref (expr, $3);
678 else
679 $$ = error_mark_node;
681 else
682 $$ = build_component_ref (expr, $3);
684 | primary PLUSPLUS
685 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
686 | primary MINUSMINUS
687 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
688 | objcmessageexpr
689 { $$ = build_message_expr ($1); }
690 | objcselectorexpr
691 { $$ = build_selector_expr ($1); }
692 | objcprotocolexpr
693 { $$ = build_protocol_expr ($1); }
694 | objcencodeexpr
695 { $$ = build_encode_expr ($1); }
696 | objc_string
697 { $$ = build_objc_string_object ($1); }
700 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
701 string:
702 STRING
703 | string STRING
704 { $$ = chainon ($1, $2);
708 /* Produces an OBJC_STRING_CST with perhaps more OBJC_STRING_CSTs chained
709 onto it. */
710 objc_string:
711 OBJC_STRING
712 | objc_string OBJC_STRING
713 { $$ = chainon ($1, $2); }
716 old_style_parm_decls:
717 /* empty */
718 | datadecls
719 | datadecls ELLIPSIS
720 /* ... is used here to indicate a varargs function. */
721 { c_mark_varargs ();
722 if (pedantic)
723 pedwarn ("ANSI C does not permit use of `varargs.h'"); }
726 /* The following are analogous to lineno_decl, decls and decl
727 except that they do not allow nested functions.
728 They are used for old-style parm decls. */
729 lineno_datadecl:
730 save_filename save_lineno datadecl
734 datadecls:
735 lineno_datadecl
736 | errstmt
737 | datadecls lineno_datadecl
738 | lineno_datadecl errstmt
741 /* We don't allow prefix attributes here because they cause reduce/reduce
742 conflicts: we can't know whether we're parsing a function decl with
743 attribute suffix, or function defn with attribute prefix on first old
744 style parm. */
745 datadecl:
746 typed_declspecs_no_prefix_attr setspecs initdecls ';'
747 { current_declspecs = TREE_VALUE (declspec_stack);
748 prefix_attributes = TREE_PURPOSE (declspec_stack);
749 declspec_stack = TREE_CHAIN (declspec_stack); }
750 | declmods_no_prefix_attr setspecs notype_initdecls ';'
751 { current_declspecs = TREE_VALUE (declspec_stack);
752 prefix_attributes = TREE_PURPOSE (declspec_stack);
753 declspec_stack = TREE_CHAIN (declspec_stack); }
754 | typed_declspecs_no_prefix_attr ';'
755 { shadow_tag_warned ($1, 1);
756 pedwarn ("empty declaration"); }
757 | declmods_no_prefix_attr ';'
758 { pedwarn ("empty declaration"); }
761 /* This combination which saves a lineno before a decl
762 is the normal thing to use, rather than decl itself.
763 This is to avoid shift/reduce conflicts in contexts
764 where statement labels are allowed. */
765 lineno_decl:
766 save_filename save_lineno decl
770 decls:
771 lineno_decl
772 | errstmt
773 | decls lineno_decl
774 | lineno_decl errstmt
777 /* records the type and storage class specs to use for processing
778 the declarators that follow.
779 Maintains a stack of outer-level values of current_declspecs,
780 for the sake of parm declarations nested in function declarators. */
781 setspecs: /* empty */
782 { pending_xref_error ();
783 declspec_stack = tree_cons (prefix_attributes,
784 current_declspecs,
785 declspec_stack);
786 split_specs_attrs ($<ttype>0,
787 &current_declspecs, &prefix_attributes); }
790 /* ??? Yuck. See after_type_declarator. */
791 setattrs: /* empty */
792 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
795 decl:
796 typed_declspecs setspecs initdecls ';'
797 { current_declspecs = TREE_VALUE (declspec_stack);
798 prefix_attributes = TREE_PURPOSE (declspec_stack);
799 declspec_stack = TREE_CHAIN (declspec_stack); }
800 | declmods setspecs notype_initdecls ';'
801 { current_declspecs = TREE_VALUE (declspec_stack);
802 prefix_attributes = TREE_PURPOSE (declspec_stack);
803 declspec_stack = TREE_CHAIN (declspec_stack); }
804 | typed_declspecs setspecs nested_function
805 { current_declspecs = TREE_VALUE (declspec_stack);
806 prefix_attributes = TREE_PURPOSE (declspec_stack);
807 declspec_stack = TREE_CHAIN (declspec_stack); }
808 | declmods setspecs notype_nested_function
809 { current_declspecs = TREE_VALUE (declspec_stack);
810 prefix_attributes = TREE_PURPOSE (declspec_stack);
811 declspec_stack = TREE_CHAIN (declspec_stack); }
812 | typed_declspecs ';'
813 { shadow_tag ($1); }
814 | declmods ';'
815 { pedwarn ("empty declaration"); }
816 | extension decl
817 { RESTORE_WARN_FLAGS ($1); }
820 /* Declspecs which contain at least one type specifier or typedef name.
821 (Just `const' or `volatile' is not enough.)
822 A typedef'd name following these is taken as a name to be declared.
823 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
825 typed_declspecs:
826 typespec reserved_declspecs
827 { $$ = tree_cons (NULL_TREE, $1, $2); }
828 | declmods typespec reserved_declspecs
829 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
832 reserved_declspecs: /* empty */
833 { $$ = NULL_TREE; }
834 | reserved_declspecs typespecqual_reserved
835 { $$ = tree_cons (NULL_TREE, $2, $1); }
836 | reserved_declspecs SCSPEC
837 { if (extra_warnings)
838 warning ("`%s' is not at beginning of declaration",
839 IDENTIFIER_POINTER ($2));
840 $$ = tree_cons (NULL_TREE, $2, $1); }
841 | reserved_declspecs attributes
842 { $$ = tree_cons ($2, NULL_TREE, $1); }
845 typed_declspecs_no_prefix_attr:
846 typespec reserved_declspecs_no_prefix_attr
847 { $$ = tree_cons (NULL_TREE, $1, $2); }
848 | declmods_no_prefix_attr typespec reserved_declspecs_no_prefix_attr
849 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
852 reserved_declspecs_no_prefix_attr:
853 /* empty */
854 { $$ = NULL_TREE; }
855 | reserved_declspecs_no_prefix_attr typespecqual_reserved
856 { $$ = tree_cons (NULL_TREE, $2, $1); }
857 | reserved_declspecs_no_prefix_attr SCSPEC
858 { if (extra_warnings)
859 warning ("`%s' is not at beginning of declaration",
860 IDENTIFIER_POINTER ($2));
861 $$ = tree_cons (NULL_TREE, $2, $1); }
864 /* List of just storage classes, type modifiers, and prefix attributes.
865 A declaration can start with just this, but then it cannot be used
866 to redeclare a typedef-name.
867 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
869 declmods:
870 declmods_no_prefix_attr
871 { $$ = $1; }
872 | attributes
873 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
874 | declmods declmods_no_prefix_attr
875 { $$ = chainon ($2, $1); }
876 | declmods attributes
877 { $$ = tree_cons ($2, NULL_TREE, $1); }
880 declmods_no_prefix_attr:
881 TYPE_QUAL
882 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
883 TREE_STATIC ($$) = 1; }
884 | SCSPEC
885 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
886 | declmods_no_prefix_attr TYPE_QUAL
887 { $$ = tree_cons (NULL_TREE, $2, $1);
888 TREE_STATIC ($$) = 1; }
889 | declmods_no_prefix_attr SCSPEC
890 { if (extra_warnings && TREE_STATIC ($1))
891 warning ("`%s' is not at beginning of declaration",
892 IDENTIFIER_POINTER ($2));
893 $$ = tree_cons (NULL_TREE, $2, $1);
894 TREE_STATIC ($$) = TREE_STATIC ($1); }
898 /* Used instead of declspecs where storage classes are not allowed
899 (that is, for typenames and structure components).
900 Don't accept a typedef-name if anything but a modifier precedes it. */
902 typed_typespecs:
903 typespec reserved_typespecquals
904 { $$ = tree_cons (NULL_TREE, $1, $2); }
905 | nonempty_type_quals typespec reserved_typespecquals
906 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
909 reserved_typespecquals: /* empty */
910 { $$ = NULL_TREE; }
911 | reserved_typespecquals typespecqual_reserved
912 { $$ = tree_cons (NULL_TREE, $2, $1); }
915 /* A typespec (but not a type qualifier).
916 Once we have seen one of these in a declaration,
917 if a typedef name appears then it is being redeclared. */
919 typespec: TYPESPEC
920 | structsp
921 | TYPENAME
922 { /* For a typedef name, record the meaning, not the name.
923 In case of `foo foo, bar;'. */
924 $$ = lookup_name ($1); }
925 | CLASSNAME protocolrefs
926 { $$ = get_static_reference ($1, $2); }
927 | OBJECTNAME protocolrefs
928 { $$ = get_object_reference ($2); }
930 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>"
931 - nisse@lysator.liu.se */
932 | non_empty_protocolrefs
933 { $$ = get_object_reference ($1); }
934 | TYPEOF '(' expr ')'
935 { $$ = TREE_TYPE ($3); }
936 | TYPEOF '(' typename ')'
937 { $$ = groktypename ($3); }
940 /* A typespec that is a reserved word, or a type qualifier. */
942 typespecqual_reserved: TYPESPEC
943 | TYPE_QUAL
944 | structsp
947 initdecls:
948 initdcl
949 | initdecls ',' initdcl
952 notype_initdecls:
953 notype_initdcl
954 | notype_initdecls ',' initdcl
957 maybeasm:
958 /* empty */
959 { $$ = NULL_TREE; }
960 | ASM_KEYWORD '(' string ')'
961 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
962 $$ = $3;
966 initdcl:
967 declarator maybeasm maybe_attribute '='
968 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
969 $3, prefix_attributes);
970 start_init ($<ttype>$, $2, global_bindings_p ()); }
971 init
972 /* Note how the declaration of the variable is in effect while its init is parsed! */
973 { finish_init ();
974 finish_decl ($<ttype>5, $6, $2); }
975 | declarator maybeasm maybe_attribute
976 { tree d = start_decl ($1, current_declspecs, 0,
977 $3, prefix_attributes);
978 finish_decl (d, NULL_TREE, $2);
982 notype_initdcl:
983 notype_declarator maybeasm maybe_attribute '='
984 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
985 $3, prefix_attributes);
986 start_init ($<ttype>$, $2, global_bindings_p ()); }
987 init
988 /* Note how the declaration of the variable is in effect while its init is parsed! */
989 { finish_init ();
990 decl_attributes ($<ttype>5, $3, prefix_attributes);
991 finish_decl ($<ttype>5, $6, $2); }
992 | notype_declarator maybeasm maybe_attribute
993 { tree d = start_decl ($1, current_declspecs, 0,
994 $3, prefix_attributes);
995 finish_decl (d, NULL_TREE, $2); }
997 /* the * rules are dummies to accept the Apollo extended syntax
998 so that the header files compile. */
999 maybe_attribute:
1000 /* empty */
1001 { $$ = NULL_TREE; }
1002 | attributes
1003 { $$ = $1; }
1006 attributes:
1007 attribute
1008 { $$ = $1; }
1009 | attributes attribute
1010 { $$ = chainon ($1, $2); }
1013 attribute:
1014 ATTRIBUTE '(' '(' attribute_list ')' ')'
1015 { $$ = $4; }
1018 attribute_list:
1019 attrib
1020 { $$ = $1; }
1021 | attribute_list ',' attrib
1022 { $$ = chainon ($1, $3); }
1025 attrib:
1026 /* empty */
1027 { $$ = NULL_TREE; }
1028 | any_word
1029 { $$ = build_tree_list ($1, NULL_TREE); }
1030 | any_word '(' IDENTIFIER ')'
1031 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1032 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1033 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1034 | any_word '(' exprlist ')'
1035 { $$ = build_tree_list ($1, $3); }
1038 /* This still leaves out most reserved keywords,
1039 shouldn't we include them? */
1041 any_word:
1042 identifier
1043 | SCSPEC
1044 | TYPESPEC
1045 | TYPE_QUAL
1048 /* Initializers. `init' is the entry point. */
1050 init:
1051 expr_no_commas
1052 | '{'
1053 { really_start_incremental_init (NULL_TREE); }
1054 initlist_maybe_comma '}'
1055 { $$ = pop_init_level (0); }
1056 | error
1057 { $$ = error_mark_node; }
1060 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1061 initlist_maybe_comma:
1062 /* empty */
1063 { if (pedantic)
1064 pedwarn ("ANSI C forbids empty initializer braces"); }
1065 | initlist1 maybecomma
1068 initlist1:
1069 initelt
1070 | initlist1 ',' initelt
1073 /* `initelt' is a single element of an initializer.
1074 It may use braces. */
1075 initelt:
1076 designator_list '=' initval
1077 | designator initval
1078 | identifier ':'
1079 { set_init_label ($1); }
1080 initval
1081 | initval
1084 initval:
1086 { push_init_level (0); }
1087 initlist_maybe_comma '}'
1088 { process_init_element (pop_init_level (0)); }
1089 | expr_no_commas
1090 { process_init_element ($1); }
1091 | error
1094 designator_list:
1095 designator
1096 | designator_list designator
1099 designator:
1100 '.' identifier
1101 { set_init_label ($2); }
1102 /* These are for labeled elements. The syntax for an array element
1103 initializer conflicts with the syntax for an Objective-C message,
1104 so don't include these productions in the Objective-C grammar. */
1107 nested_function:
1108 declarator
1109 { if (pedantic)
1110 pedwarn ("ANSI C forbids nested functions");
1112 push_function_context ();
1113 if (! start_function (current_declspecs, $1,
1114 prefix_attributes, NULL_TREE))
1116 pop_function_context ();
1117 YYERROR1;
1119 reinit_parse_for_function (); }
1120 old_style_parm_decls
1121 { store_parm_decls (); }
1122 /* This used to use compstmt_or_error.
1123 That caused a bug with input `f(g) int g {}',
1124 where the use of YYERROR1 above caused an error
1125 which then was handled by compstmt_or_error.
1126 There followed a repeated execution of that same rule,
1127 which called YYERROR1 again, and so on. */
1128 compstmt
1129 { finish_function (1);
1130 pop_function_context (); }
1133 notype_nested_function:
1134 notype_declarator
1135 { if (pedantic)
1136 pedwarn ("ANSI C forbids nested functions");
1138 push_function_context ();
1139 if (! start_function (current_declspecs, $1,
1140 prefix_attributes, NULL_TREE))
1142 pop_function_context ();
1143 YYERROR1;
1145 reinit_parse_for_function (); }
1146 old_style_parm_decls
1147 { store_parm_decls (); }
1148 /* This used to use compstmt_or_error.
1149 That caused a bug with input `f(g) int g {}',
1150 where the use of YYERROR1 above caused an error
1151 which then was handled by compstmt_or_error.
1152 There followed a repeated execution of that same rule,
1153 which called YYERROR1 again, and so on. */
1154 compstmt
1155 { finish_function (1);
1156 pop_function_context (); }
1159 /* Any kind of declarator (thus, all declarators allowed
1160 after an explicit typespec). */
1162 declarator:
1163 after_type_declarator
1164 | notype_declarator
1167 /* A declarator that is allowed only after an explicit typespec. */
1169 after_type_declarator:
1170 '(' after_type_declarator ')'
1171 { $$ = $2; }
1172 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1173 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1174 /* | after_type_declarator '(' error ')' %prec '.'
1175 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1176 poplevel (0, 0, 0); } */
1177 | after_type_declarator '[' expr ']' %prec '.'
1178 { $$ = build_nt (ARRAY_REF, $1, $3); }
1179 | after_type_declarator '[' ']' %prec '.'
1180 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1181 | '*' type_quals after_type_declarator %prec UNARY
1182 { $$ = make_pointer_declarator ($2, $3); }
1183 /* ??? Yuck. setattrs is a quick hack. We can't use
1184 prefix_attributes because $1 only applies to this
1185 declarator. We assume setspecs has already been done.
1186 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1187 attributes could be recognized here or in `attributes'). */
1188 | attributes setattrs after_type_declarator
1189 { $$ = $3; }
1190 | TYPENAME
1191 | OBJECTNAME
1194 /* Kinds of declarator that can appear in a parameter list
1195 in addition to notype_declarator. This is like after_type_declarator
1196 but does not allow a typedef name in parentheses as an identifier
1197 (because it would conflict with a function with that typedef as arg). */
1199 parm_declarator:
1200 parm_declarator '(' parmlist_or_identifiers %prec '.'
1201 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1202 /* | parm_declarator '(' error ')' %prec '.'
1203 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1204 poplevel (0, 0, 0); } */
1205 | parm_declarator '[' expr ']' %prec '.'
1206 { $$ = build_nt (ARRAY_REF, $1, $3); }
1207 | parm_declarator '[' ']' %prec '.'
1208 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1209 | '*' type_quals parm_declarator %prec UNARY
1210 { $$ = make_pointer_declarator ($2, $3); }
1211 /* ??? Yuck. setattrs is a quick hack. We can't use
1212 prefix_attributes because $1 only applies to this
1213 declarator. We assume setspecs has already been done.
1214 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1215 attributes could be recognized here or in `attributes'). */
1216 | attributes setattrs parm_declarator
1217 { $$ = $3; }
1218 | TYPENAME
1221 /* A declarator allowed whether or not there has been
1222 an explicit typespec. These cannot redeclare a typedef-name. */
1224 notype_declarator:
1225 notype_declarator '(' parmlist_or_identifiers %prec '.'
1226 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1227 /* | notype_declarator '(' error ')' %prec '.'
1228 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1229 poplevel (0, 0, 0); } */
1230 | '(' notype_declarator ')'
1231 { $$ = $2; }
1232 | '*' type_quals notype_declarator %prec UNARY
1233 { $$ = make_pointer_declarator ($2, $3); }
1234 | notype_declarator '[' expr ']' %prec '.'
1235 { $$ = build_nt (ARRAY_REF, $1, $3); }
1236 | notype_declarator '[' ']' %prec '.'
1237 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1238 /* ??? Yuck. setattrs is a quick hack. We can't use
1239 prefix_attributes because $1 only applies to this
1240 declarator. We assume setspecs has already been done.
1241 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1242 attributes could be recognized here or in `attributes'). */
1243 | attributes setattrs notype_declarator
1244 { $$ = $3; }
1245 | IDENTIFIER
1248 struct_head:
1249 STRUCT
1250 { $$ = NULL_TREE; }
1251 | STRUCT attributes
1252 { $$ = $2; }
1255 union_head:
1256 UNION
1257 { $$ = NULL_TREE; }
1258 | UNION attributes
1259 { $$ = $2; }
1262 enum_head:
1263 ENUM
1264 { $$ = NULL_TREE; }
1265 | ENUM attributes
1266 { $$ = $2; }
1269 structsp:
1270 struct_head identifier '{'
1271 { $$ = start_struct (RECORD_TYPE, $2);
1272 /* Start scope of tag before parsing components. */
1274 component_decl_list '}' maybe_attribute
1275 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1276 | struct_head '{' component_decl_list '}' maybe_attribute
1277 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1278 $3, chainon ($1, $5));
1280 | struct_head identifier
1281 { $$ = xref_tag (RECORD_TYPE, $2); }
1282 | union_head identifier '{'
1283 { $$ = start_struct (UNION_TYPE, $2); }
1284 component_decl_list '}' maybe_attribute
1285 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1286 | union_head '{' component_decl_list '}' maybe_attribute
1287 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1288 $3, chainon ($1, $5));
1290 | union_head identifier
1291 { $$ = xref_tag (UNION_TYPE, $2); }
1292 | enum_head identifier '{'
1293 { $$ = start_enum ($2); }
1294 enumlist maybecomma_warn '}' maybe_attribute
1295 { $$ = finish_enum ($<ttype>4, nreverse ($5),
1296 chainon ($1, $8)); }
1297 | enum_head '{'
1298 { $$ = start_enum (NULL_TREE); }
1299 enumlist maybecomma_warn '}' maybe_attribute
1300 { $$ = finish_enum ($<ttype>3, nreverse ($4),
1301 chainon ($1, $7)); }
1302 | enum_head identifier
1303 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1306 maybecomma:
1307 /* empty */
1308 | ','
1311 maybecomma_warn:
1312 /* empty */
1313 | ','
1314 { if (pedantic && ! flag_isoc99)
1315 pedwarn ("comma at end of enumerator list"); }
1318 component_decl_list:
1319 component_decl_list2
1320 { $$ = $1; }
1321 | component_decl_list2 component_decl
1322 { $$ = chainon ($1, $2);
1323 pedwarn ("no semicolon at end of struct or union"); }
1326 component_decl_list2: /* empty */
1327 { $$ = NULL_TREE; }
1328 | component_decl_list2 component_decl ';'
1329 { $$ = chainon ($1, $2); }
1330 | component_decl_list2 ';'
1331 { if (pedantic)
1332 pedwarn ("extra semicolon in struct or union specified"); }
1333 /* foo(sizeof(struct{ @defs(ClassName)})); */
1334 | DEFS '(' CLASSNAME ')'
1336 tree interface = lookup_interface ($3);
1338 if (interface)
1339 $$ = get_class_ivars (interface);
1340 else
1342 error ("Cannot find interface declaration for `%s'",
1343 IDENTIFIER_POINTER ($3));
1344 $$ = NULL_TREE;
1349 /* There is a shift-reduce conflict here, because `components' may
1350 start with a `typename'. It happens that shifting (the default resolution)
1351 does the right thing, because it treats the `typename' as part of
1352 a `typed_typespecs'.
1354 It is possible that this same technique would allow the distinction
1355 between `notype_initdecls' and `initdecls' to be eliminated.
1356 But I am being cautious and not trying it. */
1358 component_decl:
1359 typed_typespecs setspecs components
1360 { $$ = $3;
1361 current_declspecs = TREE_VALUE (declspec_stack);
1362 prefix_attributes = TREE_PURPOSE (declspec_stack);
1363 declspec_stack = TREE_CHAIN (declspec_stack); }
1364 | typed_typespecs setspecs save_filename save_lineno maybe_attribute
1366 /* Support for unnamed structs or unions as members of
1367 structs or unions (which is [a] useful and [b] supports
1368 MS P-SDK). */
1369 if (pedantic)
1370 pedwarn ("ANSI C doesn't support unnamed structs/unions");
1372 $$ = grokfield($3, $4, NULL, current_declspecs, NULL_TREE);
1373 current_declspecs = TREE_VALUE (declspec_stack);
1374 prefix_attributes = TREE_PURPOSE (declspec_stack);
1375 declspec_stack = TREE_CHAIN (declspec_stack);
1377 | nonempty_type_quals setspecs components
1378 { $$ = $3;
1379 current_declspecs = TREE_VALUE (declspec_stack);
1380 prefix_attributes = TREE_PURPOSE (declspec_stack);
1381 declspec_stack = TREE_CHAIN (declspec_stack); }
1382 | nonempty_type_quals
1383 { if (pedantic)
1384 pedwarn ("ANSI C forbids member declarations with no members");
1385 shadow_tag($1);
1386 $$ = NULL_TREE; }
1387 | error
1388 { $$ = NULL_TREE; }
1389 | extension component_decl
1390 { $$ = $2;
1391 RESTORE_WARN_FLAGS ($1); }
1394 components:
1395 component_declarator
1396 | components ',' component_declarator
1397 { $$ = chainon ($1, $3); }
1400 component_declarator:
1401 save_filename save_lineno declarator maybe_attribute
1402 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1403 decl_attributes ($$, $4, prefix_attributes); }
1404 | save_filename save_lineno
1405 declarator ':' expr_no_commas maybe_attribute
1406 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1407 decl_attributes ($$, $6, prefix_attributes); }
1408 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1409 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1410 decl_attributes ($$, $5, prefix_attributes); }
1413 /* We chain the enumerators in reverse order.
1414 They are put in forward order where enumlist is used.
1415 (The order used to be significant, but no longer is so.
1416 However, we still maintain the order, just to be clean.) */
1418 enumlist:
1419 enumerator
1420 | enumlist ',' enumerator
1421 { if ($1 == error_mark_node)
1422 $$ = $1;
1423 else
1424 $$ = chainon ($3, $1); }
1425 | error
1426 { $$ = error_mark_node; }
1430 enumerator:
1431 identifier
1432 { $$ = build_enumerator ($1, NULL_TREE); }
1433 | identifier '=' expr_no_commas
1434 { $$ = build_enumerator ($1, $3); }
1437 typename:
1438 typed_typespecs absdcl
1439 { $$ = build_tree_list ($1, $2); }
1440 | nonempty_type_quals absdcl
1441 { $$ = build_tree_list ($1, $2); }
1444 absdcl: /* an absolute declarator */
1445 /* empty */
1446 { $$ = NULL_TREE; }
1447 | absdcl1
1450 nonempty_type_quals:
1451 TYPE_QUAL
1452 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1453 | nonempty_type_quals TYPE_QUAL
1454 { $$ = tree_cons (NULL_TREE, $2, $1); }
1457 type_quals:
1458 /* empty */
1459 { $$ = NULL_TREE; }
1460 | type_quals TYPE_QUAL
1461 { $$ = tree_cons (NULL_TREE, $2, $1); }
1464 absdcl1: /* a nonempty absolute declarator */
1465 '(' absdcl1 ')'
1466 { $$ = $2; }
1467 /* `(typedef)1' is `int'. */
1468 | '*' type_quals absdcl1 %prec UNARY
1469 { $$ = make_pointer_declarator ($2, $3); }
1470 | '*' type_quals %prec UNARY
1471 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1472 | absdcl1 '(' parmlist %prec '.'
1473 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1474 | absdcl1 '[' expr ']' %prec '.'
1475 { $$ = build_nt (ARRAY_REF, $1, $3); }
1476 | absdcl1 '[' ']' %prec '.'
1477 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1478 | '(' parmlist %prec '.'
1479 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1480 | '[' expr ']' %prec '.'
1481 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1482 | '[' ']' %prec '.'
1483 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1484 /* ??? It appears we have to support attributes here, however
1485 using prefix_attributes is wrong. */
1486 | attributes setattrs absdcl1
1487 { $$ = $3; }
1490 /* at least one statement, the first of which parses without error. */
1491 /* stmts is used only after decls, so an invalid first statement
1492 is actually regarded as an invalid decl and part of the decls. */
1494 stmts:
1495 lineno_stmt_or_labels
1497 if (pedantic && $1)
1498 pedwarn ("ANSI C forbids label at end of compound statement");
1502 lineno_stmt_or_labels:
1503 lineno_stmt_or_label
1504 | lineno_stmt_or_labels lineno_stmt_or_label
1505 { $$ = $2; }
1506 | lineno_stmt_or_labels errstmt
1507 { $$ = 0; }
1510 xstmts:
1511 /* empty */
1512 | stmts
1515 errstmt: error ';'
1518 pushlevel: /* empty */
1519 { emit_line_note (input_filename, lineno);
1520 pushlevel (0);
1521 clear_last_expr ();
1522 expand_start_bindings (0);
1523 if (objc_method_context)
1524 add_objc_decls ();
1528 /* Read zero or more forward-declarations for labels
1529 that nested functions can jump to. */
1530 maybe_label_decls:
1531 /* empty */
1532 | label_decls
1533 { if (pedantic)
1534 pedwarn ("ANSI C forbids label declarations"); }
1537 label_decls:
1538 label_decl
1539 | label_decls label_decl
1542 label_decl:
1543 LABEL identifiers_or_typenames ';'
1544 { tree link;
1545 for (link = $2; link; link = TREE_CHAIN (link))
1547 tree label = shadow_label (TREE_VALUE (link));
1548 C_DECLARED_LABEL_FLAG (label) = 1;
1549 declare_nonlocal_label (label);
1554 /* This is the body of a function definition.
1555 It causes syntax errors to ignore to the next openbrace. */
1556 compstmt_or_error:
1557 compstmt
1559 | error compstmt
1562 compstmt_start: '{' { compstmt_count++; }
1564 compstmt_nostart: '}'
1565 { $$ = convert (void_type_node, integer_zero_node); }
1566 | pushlevel maybe_label_decls decls xstmts '}'
1567 { emit_line_note (input_filename, lineno);
1568 expand_end_bindings (getdecls (), 1, 0);
1569 $$ = poplevel (1, 1, 0); }
1570 | pushlevel maybe_label_decls error '}'
1571 { emit_line_note (input_filename, lineno);
1572 expand_end_bindings (getdecls (), kept_level_p (), 0);
1573 $$ = poplevel (kept_level_p (), 0, 0); }
1574 | pushlevel maybe_label_decls stmts '}'
1575 { emit_line_note (input_filename, lineno);
1576 expand_end_bindings (getdecls (), kept_level_p (), 0);
1577 $$ = poplevel (kept_level_p (), 0, 0); }
1580 compstmt_primary_start:
1581 '(' '{'
1582 { if (current_function_decl == 0)
1584 error ("braced-group within expression allowed only inside a function");
1585 YYERROR;
1587 /* We must force a BLOCK for this level
1588 so that, if it is not expanded later,
1589 there is a way to turn off the entire subtree of blocks
1590 that are contained in it. */
1591 keep_next_level ();
1592 push_iterator_stack ();
1593 push_label_level ();
1594 $$ = expand_start_stmt_expr ();
1595 compstmt_count++;
1598 compstmt: compstmt_start compstmt_nostart
1599 { $$ = $2; }
1602 /* Value is number of statements counted as of the closeparen. */
1603 simple_if:
1604 if_prefix lineno_labeled_stmt
1605 /* Make sure c_expand_end_cond is run once
1606 for each call to c_expand_start_cond.
1607 Otherwise a crash is likely. */
1608 | if_prefix error
1611 if_prefix:
1612 IF '(' expr ')'
1613 { emit_line_note ($<filename>-1, $<lineno>0);
1614 c_expand_start_cond (truthvalue_conversion ($3), 0,
1615 compstmt_count);
1616 $<itype>$ = stmt_count;
1617 if_stmt_file = $<filename>-1;
1618 if_stmt_line = $<lineno>0;
1619 position_after_white_space (); }
1622 /* This is a subroutine of stmt.
1623 It is used twice, once for valid DO statements
1624 and once for catching errors in parsing the end test. */
1625 do_stmt_start:
1627 { stmt_count++;
1628 compstmt_count++;
1629 emit_line_note ($<filename>-1, $<lineno>0);
1630 /* See comment in `while' alternative, above. */
1631 emit_nop ();
1632 expand_start_loop_continue_elsewhere (1);
1633 position_after_white_space (); }
1634 lineno_labeled_stmt WHILE
1635 { expand_loop_continue_here (); }
1638 save_filename:
1639 { $$ = input_filename; }
1642 save_lineno:
1643 { $$ = lineno; }
1646 lineno_labeled_stmt:
1647 save_filename save_lineno stmt
1649 /* | save_filename save_lineno error
1652 | save_filename save_lineno label lineno_labeled_stmt
1656 lineno_stmt_or_label:
1657 save_filename save_lineno stmt_or_label
1658 { $$ = $3; }
1661 stmt_or_label:
1662 stmt
1663 { $$ = 0; }
1664 | label
1665 { $$ = 1; }
1668 /* Parse a single real statement, not including any labels. */
1669 stmt:
1670 compstmt
1671 { stmt_count++; }
1672 | all_iter_stmt
1673 | expr ';'
1674 { stmt_count++;
1675 emit_line_note ($<filename>-1, $<lineno>0);
1676 /* It appears that this should not be done--that a non-lvalue array
1677 shouldn't get an error if the value isn't used.
1678 Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1679 if it appears as a top-level expression,
1680 but says nothing about non-lvalue arrays. */
1681 #if 0
1682 /* Call default_conversion to get an error
1683 on referring to a register array if pedantic. */
1684 if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1685 || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1686 $1 = default_conversion ($1);
1687 #endif
1688 iterator_expand ($1); }
1689 | simple_if ELSE
1690 { c_expand_start_else ();
1691 $<itype>1 = stmt_count;
1692 position_after_white_space (); }
1693 lineno_labeled_stmt
1694 { c_expand_end_cond ();
1695 if (extra_warnings && stmt_count == $<itype>1)
1696 warning ("empty body in an else-statement"); }
1697 | simple_if %prec IF
1698 { c_expand_end_cond ();
1699 /* This warning is here instead of in simple_if, because we
1700 do not want a warning if an empty if is followed by an
1701 else statement. Increment stmt_count so we don't
1702 give a second error if this is a nested `if'. */
1703 if (extra_warnings && stmt_count++ == $<itype>1)
1704 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1705 "empty body in an if-statement"); }
1706 /* Make sure c_expand_end_cond is run once
1707 for each call to c_expand_start_cond.
1708 Otherwise a crash is likely. */
1709 | simple_if ELSE error
1710 { c_expand_end_cond (); }
1711 | WHILE
1712 { stmt_count++;
1713 emit_line_note ($<filename>-1, $<lineno>0);
1714 /* The emit_nop used to come before emit_line_note,
1715 but that made the nop seem like part of the preceding line.
1716 And that was confusing when the preceding line was
1717 inside of an if statement and was not really executed.
1718 I think it ought to work to put the nop after the line number.
1719 We will see. --rms, July 15, 1991. */
1720 emit_nop (); }
1721 '(' expr ')'
1722 { /* Don't start the loop till we have succeeded
1723 in parsing the end test. This is to make sure
1724 that we end every loop we start. */
1725 expand_start_loop (1);
1726 emit_line_note (input_filename, lineno);
1727 expand_exit_loop_if_false (NULL_PTR,
1728 truthvalue_conversion ($4));
1729 position_after_white_space (); }
1730 lineno_labeled_stmt
1731 { expand_end_loop (); }
1732 | do_stmt_start
1733 '(' expr ')' ';'
1734 { emit_line_note (input_filename, lineno);
1735 expand_exit_loop_if_false (NULL_PTR,
1736 truthvalue_conversion ($3));
1737 expand_end_loop (); }
1738 /* This rule is needed to make sure we end every loop we start. */
1739 | do_stmt_start error
1740 { expand_end_loop (); }
1741 | FOR
1742 '(' xexpr ';'
1743 { stmt_count++;
1744 emit_line_note ($<filename>-1, $<lineno>0);
1745 /* See comment in `while' alternative, above. */
1746 emit_nop ();
1747 if ($3) c_expand_expr_stmt ($3);
1748 /* Next step is to call expand_start_loop_continue_elsewhere,
1749 but wait till after we parse the entire for (...).
1750 Otherwise, invalid input might cause us to call that
1751 fn without calling expand_end_loop. */
1753 xexpr ';'
1754 /* Can't emit now; wait till after expand_start_loop... */
1755 { $<lineno>7 = lineno;
1756 $<filename>$ = input_filename; }
1757 xexpr ')'
1759 /* Start the loop. Doing this after parsing
1760 all the expressions ensures we will end the loop. */
1761 expand_start_loop_continue_elsewhere (1);
1762 /* Emit the end-test, with a line number. */
1763 emit_line_note ($<filename>8, $<lineno>7);
1764 if ($6)
1765 expand_exit_loop_if_false (NULL_PTR,
1766 truthvalue_conversion ($6));
1767 $<lineno>7 = lineno;
1768 $<filename>8 = input_filename;
1769 position_after_white_space (); }
1770 lineno_labeled_stmt
1771 { /* Emit the increment expression, with a line number. */
1772 emit_line_note ($<filename>8, $<lineno>7);
1773 expand_loop_continue_here ();
1774 if ($9)
1775 c_expand_expr_stmt ($9);
1776 expand_end_loop (); }
1777 | SWITCH '(' expr ')'
1778 { stmt_count++;
1779 emit_line_note ($<filename>-1, $<lineno>0);
1780 c_expand_start_case ($3);
1781 position_after_white_space (); }
1782 lineno_labeled_stmt
1783 { expand_end_case ($3); }
1784 | BREAK ';'
1785 { tree break_stmt = build_break_stmt ();
1786 stmt_count++;
1787 genrtl_break_stmt (); }
1788 | CONTINUE ';'
1789 { tree continue_stmt = build_continue_stmt ();
1790 stmt_count++;
1791 genrtl_continue_stmt (); }
1792 | RETURN ';'
1793 { tree return_stmt = build_return_stmt (NULL_TREE);
1794 stmt_count++;
1795 genrtl_return_stmt (RETURN_EXPR(return_stmt)); }
1796 | RETURN expr ';'
1797 { tree return_stmt = build_return_stmt ($2);
1798 stmt_count++;
1799 genrtl_return_stmt (RETURN_EXPR(return_stmt)); }
1800 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
1801 { stmt_count++;
1802 emit_line_note ($<filename>-1, $<lineno>0);
1803 STRIP_NOPS ($4);
1804 if ((TREE_CODE ($4) == ADDR_EXPR
1805 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
1806 || TREE_CODE ($4) == STRING_CST)
1807 expand_asm ($4);
1808 else
1809 error ("argument of `asm' is not a constant string"); }
1810 /* This is the case with just output operands. */
1811 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
1812 { stmt_count++;
1813 emit_line_note ($<filename>-1, $<lineno>0);
1814 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
1815 $2 == ridpointers[(int)RID_VOLATILE],
1816 input_filename, lineno); }
1817 /* This is the case with input operands as well. */
1818 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
1819 { stmt_count++;
1820 emit_line_note ($<filename>-1, $<lineno>0);
1821 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
1822 $2 == ridpointers[(int)RID_VOLATILE],
1823 input_filename, lineno); }
1824 /* This is the case with clobbered registers as well. */
1825 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
1826 asm_operands ':' asm_clobbers ')' ';'
1827 { stmt_count++;
1828 emit_line_note ($<filename>-1, $<lineno>0);
1829 c_expand_asm_operands ($4, $6, $8, $10,
1830 $2 == ridpointers[(int)RID_VOLATILE],
1831 input_filename, lineno); }
1832 | GOTO identifier ';'
1833 { tree decl;
1834 stmt_count++;
1835 emit_line_note ($<filename>-1, $<lineno>0);
1836 decl = lookup_label ($2);
1837 if (decl != 0)
1839 TREE_USED (decl) = 1;
1840 expand_goto (decl);
1843 | GOTO '*' expr ';'
1844 { if (pedantic)
1845 pedwarn ("ANSI C forbids `goto *expr;'");
1846 stmt_count++;
1847 emit_line_note ($<filename>-1, $<lineno>0);
1848 expand_computed_goto (convert (ptr_type_node, $3)); }
1849 | ';'
1852 all_iter_stmt:
1853 all_iter_stmt_simple
1854 /* | all_iter_stmt_with_decl */
1857 all_iter_stmt_simple:
1858 FOR '(' primary ')'
1860 /* The value returned by this action is */
1861 /* 1 if everything is OK */
1862 /* 0 in case of error or already bound iterator */
1864 $<itype>$ = 0;
1865 if (TREE_CODE ($3) != VAR_DECL)
1866 error ("invalid `for (ITERATOR)' syntax");
1867 else if (! ITERATOR_P ($3))
1868 error ("`%s' is not an iterator",
1869 IDENTIFIER_POINTER (DECL_NAME ($3)));
1870 else if (ITERATOR_BOUND_P ($3))
1871 error ("`for (%s)' inside expansion of same iterator",
1872 IDENTIFIER_POINTER (DECL_NAME ($3)));
1873 else
1875 $<itype>$ = 1;
1876 iterator_for_loop_start ($3);
1879 lineno_labeled_stmt
1881 if ($<itype>5)
1882 iterator_for_loop_end ($3);
1885 /* This really should allow any kind of declaration,
1886 for generality. Fix it before turning it back on.
1888 all_iter_stmt_with_decl:
1889 FOR '(' ITERATOR pushlevel setspecs iterator_spec ')'
1891 */ /* The value returned by this action is */
1892 /* 1 if everything is OK */
1893 /* 0 in case of error or already bound iterator */
1895 iterator_for_loop_start ($6);
1897 lineno_labeled_stmt
1899 iterator_for_loop_end ($6);
1900 emit_line_note (input_filename, lineno);
1901 expand_end_bindings (getdecls (), 1, 0);
1902 $<ttype>$ = poplevel (1, 1, 0);
1906 /* Any kind of label, including jump labels and case labels.
1907 ANSI C accepts labels only before statements, but we allow them
1908 also at the end of a compound statement. */
1910 label: CASE expr_no_commas ':'
1911 { tree case_label_tree = build_case_label ($2, NULL_TREE);
1912 stmt_count++;
1913 genrtl_case_label(CASE_LOW(case_label_tree), CASE_HIGH(case_label_tree));
1914 position_after_white_space ();
1916 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
1917 { tree case_label_tree = build_case_label ($2, $4);
1918 stmt_count++;
1919 genrtl_case_label(CASE_LOW(case_label_tree), CASE_HIGH(case_label_tree));
1920 position_after_white_space ();
1922 | DEFAULT ':'
1923 { tree case_label_tree = build_case_label (NULL_TREE, NULL_TREE);
1924 stmt_count++;
1925 genrtl_case_label(CASE_LOW(case_label_tree), CASE_HIGH(case_label_tree));
1926 position_after_white_space ();
1928 | identifier ':' maybe_attribute
1929 { tree label = define_label (input_filename, lineno, $1);
1930 stmt_count++;
1931 emit_nop ();
1932 if (label)
1934 expand_label (label);
1935 decl_attributes (label, $3, NULL_TREE);
1937 position_after_white_space (); }
1940 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
1942 maybe_type_qual:
1943 /* empty */
1944 { emit_line_note (input_filename, lineno);
1945 $$ = NULL_TREE; }
1946 | TYPE_QUAL
1947 { emit_line_note (input_filename, lineno); }
1950 xexpr:
1951 /* empty */
1952 { $$ = NULL_TREE; }
1953 | expr
1956 /* These are the operands other than the first string and colon
1957 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
1958 asm_operands: /* empty */
1959 { $$ = NULL_TREE; }
1960 | nonnull_asm_operands
1963 nonnull_asm_operands:
1964 asm_operand
1965 | nonnull_asm_operands ',' asm_operand
1966 { $$ = chainon ($1, $3); }
1969 asm_operand:
1970 STRING '(' expr ')'
1971 { $$ = build_tree_list ($1, $3); }
1974 asm_clobbers:
1975 string
1976 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
1977 | asm_clobbers ',' string
1978 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
1981 /* This is what appears inside the parens in a function declarator.
1982 Its value is a list of ..._TYPE nodes. */
1983 parmlist:
1984 { pushlevel (0);
1985 clear_parm_order ();
1986 declare_parm_level (0); }
1987 parmlist_1
1988 { $$ = $2;
1989 parmlist_tags_warning ();
1990 poplevel (0, 0, 0); }
1993 parmlist_1:
1994 parmlist_2 ')'
1995 | parms ';'
1996 { tree parm;
1997 if (pedantic)
1998 pedwarn ("ANSI C forbids forward parameter declarations");
1999 /* Mark the forward decls as such. */
2000 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2001 TREE_ASM_WRITTEN (parm) = 1;
2002 clear_parm_order (); }
2003 parmlist_1
2004 { $$ = $4; }
2005 | error ')'
2006 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2009 /* This is what appears inside the parens in a function declarator.
2010 Is value is represented in the format that grokdeclarator expects. */
2011 parmlist_2: /* empty */
2012 { $$ = get_parm_info (0); }
2013 | ELLIPSIS
2014 { $$ = get_parm_info (0);
2015 /* Gcc used to allow this as an extension. However, it does
2016 not work for all targets, and thus has been disabled.
2017 Also, since func (...) and func () are indistinguishable,
2018 it caused problems with the code in expand_builtin which
2019 tries to verify that BUILT_IN_NEXT_ARG is being used
2020 correctly. */
2021 error ("ANSI C requires a named argument before `...'");
2023 | parms
2024 { $$ = get_parm_info (1); }
2025 | parms ',' ELLIPSIS
2026 { $$ = get_parm_info (0); }
2029 parms:
2030 parm
2031 { push_parm_decl ($1); }
2032 | parms ',' parm
2033 { push_parm_decl ($3); }
2036 /* A single parameter declaration or parameter type name,
2037 as found in a parmlist. */
2038 parm:
2039 typed_declspecs setspecs parm_declarator maybe_attribute
2040 { $$ = build_tree_list (build_tree_list (current_declspecs,
2041 $3),
2042 build_tree_list (prefix_attributes,
2043 $4));
2044 current_declspecs = TREE_VALUE (declspec_stack);
2045 prefix_attributes = TREE_PURPOSE (declspec_stack);
2046 declspec_stack = TREE_CHAIN (declspec_stack); }
2047 | typed_declspecs setspecs notype_declarator maybe_attribute
2048 { $$ = build_tree_list (build_tree_list (current_declspecs,
2049 $3),
2050 build_tree_list (prefix_attributes,
2051 $4));
2052 current_declspecs = TREE_VALUE (declspec_stack);
2053 prefix_attributes = TREE_PURPOSE (declspec_stack);
2054 declspec_stack = TREE_CHAIN (declspec_stack); }
2055 | typed_declspecs setspecs absdcl maybe_attribute
2056 { $$ = build_tree_list (build_tree_list (current_declspecs,
2057 $3),
2058 build_tree_list (prefix_attributes,
2059 $4));
2060 current_declspecs = TREE_VALUE (declspec_stack);
2061 prefix_attributes = TREE_PURPOSE (declspec_stack);
2062 declspec_stack = TREE_CHAIN (declspec_stack); }
2063 | declmods setspecs notype_declarator maybe_attribute
2064 { $$ = build_tree_list (build_tree_list (current_declspecs,
2065 $3),
2066 build_tree_list (prefix_attributes,
2067 $4));
2068 current_declspecs = TREE_VALUE (declspec_stack);
2069 prefix_attributes = TREE_PURPOSE (declspec_stack);
2070 declspec_stack = TREE_CHAIN (declspec_stack); }
2072 | declmods setspecs absdcl maybe_attribute
2073 { $$ = build_tree_list (build_tree_list (current_declspecs,
2074 $3),
2075 build_tree_list (prefix_attributes,
2076 $4));
2077 current_declspecs = TREE_VALUE (declspec_stack);
2078 prefix_attributes = TREE_PURPOSE (declspec_stack);
2079 declspec_stack = TREE_CHAIN (declspec_stack); }
2082 /* This is used in a function definition
2083 where either a parmlist or an identifier list is ok.
2084 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2085 parmlist_or_identifiers:
2086 { pushlevel (0);
2087 clear_parm_order ();
2088 declare_parm_level (1); }
2089 parmlist_or_identifiers_1
2090 { $$ = $2;
2091 parmlist_tags_warning ();
2092 poplevel (0, 0, 0); }
2095 parmlist_or_identifiers_1:
2096 parmlist_1
2097 | identifiers ')'
2098 { tree t;
2099 for (t = $1; t; t = TREE_CHAIN (t))
2100 if (TREE_VALUE (t) == NULL_TREE)
2101 error ("`...' in old-style identifier list");
2102 $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2105 /* A nonempty list of identifiers. */
2106 identifiers:
2107 IDENTIFIER
2108 { $$ = build_tree_list (NULL_TREE, $1); }
2109 | identifiers ',' IDENTIFIER
2110 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2113 /* A nonempty list of identifiers, including typenames. */
2114 identifiers_or_typenames:
2115 identifier
2116 { $$ = build_tree_list (NULL_TREE, $1); }
2117 | identifiers_or_typenames ',' identifier
2118 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2121 extension:
2122 EXTENSION
2123 { $$ = SAVE_WARN_FLAGS();
2124 pedantic = 0;
2125 warn_pointer_arith = 0; }
2128 /* Objective-C productions. */
2130 objcdef:
2131 classdef
2132 | classdecl
2133 | aliasdecl
2134 | protocoldef
2135 | methoddef
2136 | END
2138 if (objc_implementation_context)
2140 finish_class (objc_implementation_context);
2141 objc_ivar_chain = NULL_TREE;
2142 objc_implementation_context = NULL_TREE;
2144 else
2145 warning ("`@end' must appear in an implementation context");
2149 /* A nonempty list of identifiers. */
2150 identifier_list:
2151 identifier
2152 { $$ = build_tree_list (NULL_TREE, $1); }
2153 | identifier_list ',' identifier
2154 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2157 classdecl:
2158 CLASS identifier_list ';'
2160 objc_declare_class ($2);
2163 aliasdecl:
2164 ALIAS identifier identifier ';'
2166 objc_declare_alias ($2, $3);
2169 classdef:
2170 INTERFACE identifier protocolrefs '{'
2172 objc_interface_context = objc_ivar_context
2173 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2174 objc_public_flag = 0;
2176 ivar_decl_list '}'
2178 continue_class (objc_interface_context);
2180 methodprotolist
2183 finish_class (objc_interface_context);
2184 objc_interface_context = NULL_TREE;
2187 | INTERFACE identifier protocolrefs
2189 objc_interface_context
2190 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2191 continue_class (objc_interface_context);
2193 methodprotolist
2196 finish_class (objc_interface_context);
2197 objc_interface_context = NULL_TREE;
2200 | INTERFACE identifier ':' identifier protocolrefs '{'
2202 objc_interface_context = objc_ivar_context
2203 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2204 objc_public_flag = 0;
2206 ivar_decl_list '}'
2208 continue_class (objc_interface_context);
2210 methodprotolist
2213 finish_class (objc_interface_context);
2214 objc_interface_context = NULL_TREE;
2217 | INTERFACE identifier ':' identifier protocolrefs
2219 objc_interface_context
2220 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2221 continue_class (objc_interface_context);
2223 methodprotolist
2226 finish_class (objc_interface_context);
2227 objc_interface_context = NULL_TREE;
2230 | IMPLEMENTATION identifier '{'
2232 objc_implementation_context = objc_ivar_context
2233 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2234 objc_public_flag = 0;
2236 ivar_decl_list '}'
2238 objc_ivar_chain
2239 = continue_class (objc_implementation_context);
2242 | IMPLEMENTATION identifier
2244 objc_implementation_context
2245 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2246 objc_ivar_chain
2247 = continue_class (objc_implementation_context);
2250 | IMPLEMENTATION identifier ':' identifier '{'
2252 objc_implementation_context = objc_ivar_context
2253 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2254 objc_public_flag = 0;
2256 ivar_decl_list '}'
2258 objc_ivar_chain
2259 = continue_class (objc_implementation_context);
2262 | IMPLEMENTATION identifier ':' identifier
2264 objc_implementation_context
2265 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2266 objc_ivar_chain
2267 = continue_class (objc_implementation_context);
2270 | INTERFACE identifier '(' identifier ')' protocolrefs
2272 objc_interface_context
2273 = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2274 continue_class (objc_interface_context);
2276 methodprotolist
2279 finish_class (objc_interface_context);
2280 objc_interface_context = NULL_TREE;
2283 | IMPLEMENTATION identifier '(' identifier ')'
2285 objc_implementation_context
2286 = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2287 objc_ivar_chain
2288 = continue_class (objc_implementation_context);
2292 protocoldef:
2293 PROTOCOL identifier protocolrefs
2295 remember_protocol_qualifiers ();
2296 objc_interface_context
2297 = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2299 methodprotolist END
2301 forget_protocol_qualifiers();
2302 finish_protocol(objc_interface_context);
2303 objc_interface_context = NULL_TREE;
2307 protocolrefs:
2308 /* empty */
2310 $$ = NULL_TREE;
2312 | non_empty_protocolrefs
2315 non_empty_protocolrefs:
2316 ARITHCOMPARE identifier_list ARITHCOMPARE
2318 if ($1 == LT_EXPR && $3 == GT_EXPR)
2319 $$ = $2;
2320 else
2321 YYERROR1;
2325 ivar_decl_list:
2326 ivar_decl_list visibility_spec ivar_decls
2327 | ivar_decls
2330 visibility_spec:
2331 PRIVATE { objc_public_flag = 2; }
2332 | PROTECTED { objc_public_flag = 0; }
2333 | PUBLIC { objc_public_flag = 1; }
2336 ivar_decls:
2337 /* empty */
2339 $$ = NULL_TREE;
2341 | ivar_decls ivar_decl ';'
2342 | ivar_decls ';'
2344 if (pedantic)
2345 pedwarn ("extra semicolon in struct or union specified");
2350 /* There is a shift-reduce conflict here, because `components' may
2351 start with a `typename'. It happens that shifting (the default resolution)
2352 does the right thing, because it treats the `typename' as part of
2353 a `typed_typespecs'.
2355 It is possible that this same technique would allow the distinction
2356 between `notype_initdecls' and `initdecls' to be eliminated.
2357 But I am being cautious and not trying it. */
2359 ivar_decl:
2360 typed_typespecs setspecs ivars
2361 { $$ = $3;
2362 current_declspecs = TREE_VALUE (declspec_stack);
2363 prefix_attributes = TREE_PURPOSE (declspec_stack);
2364 declspec_stack = TREE_CHAIN (declspec_stack); }
2365 | nonempty_type_quals setspecs ivars
2366 { $$ = $3;
2367 current_declspecs = TREE_VALUE (declspec_stack);
2368 prefix_attributes = TREE_PURPOSE (declspec_stack);
2369 declspec_stack = TREE_CHAIN (declspec_stack); }
2370 | error
2371 { $$ = NULL_TREE; }
2374 ivars:
2375 /* empty */
2376 { $$ = NULL_TREE; }
2377 | ivar_declarator
2378 | ivars ',' ivar_declarator
2381 ivar_declarator:
2382 declarator
2384 $$ = add_instance_variable (objc_ivar_context,
2385 objc_public_flag,
2386 $1, current_declspecs,
2387 NULL_TREE);
2389 | declarator ':' expr_no_commas
2391 $$ = add_instance_variable (objc_ivar_context,
2392 objc_public_flag,
2393 $1, current_declspecs, $3);
2395 | ':' expr_no_commas
2397 $$ = add_instance_variable (objc_ivar_context,
2398 objc_public_flag,
2399 NULL_TREE,
2400 current_declspecs, $2);
2404 methoddef:
2407 remember_protocol_qualifiers ();
2408 if (objc_implementation_context)
2409 objc_inherit_code = CLASS_METHOD_DECL;
2410 else
2411 fatal ("method definition not in class context");
2413 methoddecl
2415 forget_protocol_qualifiers ();
2416 add_class_method (objc_implementation_context, $3);
2417 start_method_def ($3);
2418 objc_method_context = $3;
2420 optarglist
2422 continue_method_def ();
2424 compstmt_or_error
2426 finish_method_def ();
2427 objc_method_context = NULL_TREE;
2430 | '-'
2432 remember_protocol_qualifiers ();
2433 if (objc_implementation_context)
2434 objc_inherit_code = INSTANCE_METHOD_DECL;
2435 else
2436 fatal ("method definition not in class context");
2438 methoddecl
2440 forget_protocol_qualifiers ();
2441 add_instance_method (objc_implementation_context, $3);
2442 start_method_def ($3);
2443 objc_method_context = $3;
2445 optarglist
2447 continue_method_def ();
2449 compstmt_or_error
2451 finish_method_def ();
2452 objc_method_context = NULL_TREE;
2456 /* the reason for the strange actions in this rule
2457 is so that notype_initdecls when reached via datadef
2458 can find a valid list of type and sc specs in $0. */
2460 methodprotolist:
2461 /* empty */
2462 | {$<ttype>$ = NULL_TREE; } methodprotolist2
2465 methodprotolist2: /* eliminates a shift/reduce conflict */
2466 methodproto
2467 | datadef
2468 | methodprotolist2 methodproto
2469 | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
2472 semi_or_error:
2474 | error
2477 methodproto:
2480 /* Remember protocol qualifiers in prototypes. */
2481 remember_protocol_qualifiers ();
2482 objc_inherit_code = CLASS_METHOD_DECL;
2484 methoddecl
2486 /* Forget protocol qualifiers here. */
2487 forget_protocol_qualifiers ();
2488 add_class_method (objc_interface_context, $3);
2490 semi_or_error
2492 | '-'
2494 /* Remember protocol qualifiers in prototypes. */
2495 remember_protocol_qualifiers ();
2496 objc_inherit_code = INSTANCE_METHOD_DECL;
2498 methoddecl
2500 /* Forget protocol qualifiers here. */
2501 forget_protocol_qualifiers ();
2502 add_instance_method (objc_interface_context, $3);
2504 semi_or_error
2507 methoddecl:
2508 '(' typename ')' unaryselector
2510 $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
2513 | unaryselector
2515 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
2518 | '(' typename ')' keywordselector optparmlist
2520 $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
2523 | keywordselector optparmlist
2525 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
2529 /* "optarglist" assumes that start_method_def has already been called...
2530 if it is not, the "xdecls" will not be placed in the proper scope */
2532 optarglist:
2533 /* empty */
2534 | ';' myxdecls
2537 /* to get around the following situation: "int foo (int a) int b; {}" that
2538 is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
2540 myxdecls:
2541 /* empty */
2542 | mydecls
2545 mydecls:
2546 mydecl
2547 | errstmt
2548 | mydecls mydecl
2549 | mydecl errstmt
2552 mydecl:
2553 typed_declspecs setspecs myparms ';'
2554 { current_declspecs = TREE_VALUE (declspec_stack);
2555 prefix_attributes = TREE_PURPOSE (declspec_stack);
2556 declspec_stack = TREE_CHAIN (declspec_stack); }
2557 | typed_declspecs ';'
2558 { shadow_tag ($1); }
2559 | declmods ';'
2560 { pedwarn ("empty declaration"); }
2563 myparms:
2564 myparm
2565 { push_parm_decl ($1); }
2566 | myparms ',' myparm
2567 { push_parm_decl ($3); }
2570 /* A single parameter declaration or parameter type name,
2571 as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
2573 myparm:
2574 parm_declarator maybe_attribute
2575 { $$ = build_tree_list (build_tree_list (current_declspecs,
2576 $1),
2577 build_tree_list (prefix_attributes,
2578 $2)); }
2579 | notype_declarator maybe_attribute
2580 { $$ = build_tree_list (build_tree_list (current_declspecs,
2581 $1),
2582 build_tree_list (prefix_attributes,
2583 $2)); }
2584 | absdcl maybe_attribute
2585 { $$ = build_tree_list (build_tree_list (current_declspecs,
2586 $1),
2587 build_tree_list (prefix_attributes,
2588 $2)); }
2591 optparmlist:
2592 /* empty */
2594 $$ = NULL_TREE;
2596 | ',' ELLIPSIS
2598 /* oh what a kludge! */
2599 $$ = objc_ellipsis_node;
2601 | ','
2603 pushlevel (0);
2605 parmlist_2
2607 /* returns a tree list node generated by get_parm_info */
2608 $$ = $3;
2609 poplevel (0, 0, 0);
2613 unaryselector:
2614 selector
2617 keywordselector:
2618 keyworddecl
2620 | keywordselector keyworddecl
2622 $$ = chainon ($1, $2);
2626 selector:
2627 IDENTIFIER
2628 | TYPENAME
2629 | OBJECTNAME
2630 | reservedwords
2633 reservedwords:
2634 ENUM { $$ = get_identifier (token_buffer); }
2635 | STRUCT { $$ = get_identifier (token_buffer); }
2636 | UNION { $$ = get_identifier (token_buffer); }
2637 | IF { $$ = get_identifier (token_buffer); }
2638 | ELSE { $$ = get_identifier (token_buffer); }
2639 | WHILE { $$ = get_identifier (token_buffer); }
2640 | DO { $$ = get_identifier (token_buffer); }
2641 | FOR { $$ = get_identifier (token_buffer); }
2642 | SWITCH { $$ = get_identifier (token_buffer); }
2643 | CASE { $$ = get_identifier (token_buffer); }
2644 | DEFAULT { $$ = get_identifier (token_buffer); }
2645 | BREAK { $$ = get_identifier (token_buffer); }
2646 | CONTINUE { $$ = get_identifier (token_buffer); }
2647 | RETURN { $$ = get_identifier (token_buffer); }
2648 | GOTO { $$ = get_identifier (token_buffer); }
2649 | ASM_KEYWORD { $$ = get_identifier (token_buffer); }
2650 | SIZEOF { $$ = get_identifier (token_buffer); }
2651 | TYPEOF { $$ = get_identifier (token_buffer); }
2652 | ALIGNOF { $$ = get_identifier (token_buffer); }
2653 | TYPESPEC | TYPE_QUAL
2656 keyworddecl:
2657 selector ':' '(' typename ')' identifier
2659 $$ = build_keyword_decl ($1, $4, $6);
2662 | selector ':' identifier
2664 $$ = build_keyword_decl ($1, NULL_TREE, $3);
2667 | ':' '(' typename ')' identifier
2669 $$ = build_keyword_decl (NULL_TREE, $3, $5);
2672 | ':' identifier
2674 $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
2678 messageargs:
2679 selector
2680 | keywordarglist
2683 keywordarglist:
2684 keywordarg
2685 | keywordarglist keywordarg
2687 $$ = chainon ($1, $2);
2692 keywordexpr:
2693 nonnull_exprlist
2695 if (TREE_CHAIN ($1) == NULL_TREE)
2696 /* just return the expr., remove a level of indirection */
2697 $$ = TREE_VALUE ($1);
2698 else
2699 /* we have a comma expr., we will collapse later */
2700 $$ = $1;
2704 keywordarg:
2705 selector ':' keywordexpr
2707 $$ = build_tree_list ($1, $3);
2709 | ':' keywordexpr
2711 $$ = build_tree_list (NULL_TREE, $2);
2715 receiver:
2716 expr
2717 | CLASSNAME
2719 $$ = get_class_reference ($1);
2723 objcmessageexpr:
2725 { objc_receiver_context = 1; }
2726 receiver
2727 { objc_receiver_context = 0; }
2728 messageargs ']'
2730 $$ = build_tree_list ($3, $5);
2734 selectorarg:
2735 selector
2736 | keywordnamelist
2739 keywordnamelist:
2740 keywordname
2741 | keywordnamelist keywordname
2743 $$ = chainon ($1, $2);
2747 keywordname:
2748 selector ':'
2750 $$ = build_tree_list ($1, NULL_TREE);
2752 | ':'
2754 $$ = build_tree_list (NULL_TREE, NULL_TREE);
2758 objcselectorexpr:
2759 SELECTOR '(' selectorarg ')'
2761 $$ = $3;
2765 objcprotocolexpr:
2766 PROTOCOL '(' identifier ')'
2768 $$ = $3;
2772 /* extension to support C-structures in the archiver */
2774 objcencodeexpr:
2775 ENCODE '(' typename ')'
2777 $$ = groktypename ($3);