1 /*WARNING: This file is automatically generated!*/
2 /* YACC parser for C syntax and for Objective C. -*-c-*-
3 Copyright (C) 1987, 88, 89, 92-98, 1999 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* This file defines the grammar of C and that of Objective C.
23 ifobjc ... end ifobjc conditionals contain code for Objective C only.
24 ifc ... end ifc conditionals contain code for C only.
25 Sed commands in Makefile.in are used to convert this file into
26 c-parse.y and into objc-parse.y. */
28 /* To whomever it may concern: I have heard that such a thing was once
29 written by AT&T, but I have never seen it. */
33 /* These are the 23 conflicts you should get in parse.output;
34 the state numbers may vary if minor changes in the grammar are made.
36 State 42 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTE.)
37 State 44 contains 1 shift/reduce conflict. (Two ways to recover from error.)
38 State 103 contains 1 shift/reduce conflict. (Two ways to recover from error.)
39 State 110 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTE.)
40 State 111 contains 1 shift/reduce conflict. (Two ways to recover from error.)
41 State 115 contains 1 shift/reduce conflict. (Two ways to recover from error.)
42 State 132 contains 1 shift/reduce conflict. (See comment at component_decl.)
43 State 180 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTE.)
44 State 194 contains 2 shift/reduce conflict. (Four ways to parse this.)
45 State 202 contains 1 shift/reduce conflict. (Two ways to recover from error.)
46 State 214 contains 1 shift/reduce conflict. (Two ways to recover from error.)
47 State 220 contains 1 shift/reduce conflict. (Two ways to recover from error.)
48 State 304 contains 2 shift/reduce conflicts. (Four ways to parse this.)
49 State 335 contains 2 shift/reduce conflicts. (Four ways to parse this.)
50 State 347 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTES.)
51 State 352 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTES.)
52 State 383 contains 2 shift/reduce conflicts. (Four ways to parse this.)
53 State 434 contains 2 shift/reduce conflicts. (Four ways to parse this.) */
69 #ifdef MULTIBYTE_CHARS
74 /* Since parsers are distinct for each language, put the language string
76 char *language_string = "GNU C";
78 /* Like YYERROR but do call yyerror. */
79 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
81 /* Cause the `yydebug' variable to be defined. */
87 %union {long itype; tree ttype; enum tree_code code;
88 char *filename; int lineno; int ends_in_label; }
90 /* All identifiers that are not reserved words
91 and are not declared typedefs in the current block */
94 /* All identifiers that are declared typedefs in the current block.
95 In some contexts, they are treated just like IDENTIFIER,
96 but they can also serve as typespecs in declarations. */
99 /* Reserved words that specify storage class.
100 yylval contains an IDENTIFIER_NODE which indicates which one. */
103 /* Reserved words that specify type.
104 yylval contains an IDENTIFIER_NODE which indicates which one. */
107 /* Reserved words that qualify type: "const", "volatile", or "restrict".
108 yylval contains an IDENTIFIER_NODE which indicates which one. */
111 /* Character or numeric constants.
112 yylval is the node for the constant. */
115 /* String constants in raw form.
116 yylval is a STRING_CST node. */
119 /* "...", used for functions with variable arglists. */
122 /* the reserved words */
123 /* SCO include files test "ASM", so use something else. */
124 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
125 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
126 %token ATTRIBUTE EXTENSION LABEL
127 %token REALPART IMAGPART VA_ARG
129 /* Used in c-lex.c for parsing pragmas. */
132 /* Add precedence rules to solve dangling else s/r conflict */
136 /* Define the operator tokens and their precedences.
137 The value is an integer because, if used, it is the tree code
138 to use in the expression made from the operator. */
140 %right <code> ASSIGN '='
141 %right <code> '?' ':'
147 %left <code> EQCOMPARE
148 %left <code> ARITHCOMPARE
149 %left <code> LSHIFT RSHIFT
151 %left <code> '*' '/' '%'
152 %right <code> UNARY PLUSPLUS MINUSMINUS
154 %left <code> POINTSAT '.' '(' '['
156 /* The Objective-C keywords. These are included in C and in
157 Objective C, so that the token codes are the same in both. */
158 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
159 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
161 /* Objective-C string constants in raw form.
162 yylval is an OBJC_STRING_CST node. */
168 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
169 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
170 %type <ttype> typed_declspecs reserved_declspecs
171 %type <ttype> typed_typespecs reserved_typespecquals
172 %type <ttype> declmods typespec typespecqual_reserved
173 %type <ttype> typed_declspecs_no_prefix_attr reserved_declspecs_no_prefix_attr
174 %type <ttype> declmods_no_prefix_attr
175 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
176 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
177 %type <ttype> init maybeasm
178 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
179 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
180 %type <ttype> any_word
182 %type <ttype> compstmt
184 %type <ttype> declarator
185 %type <ttype> notype_declarator after_type_declarator
186 %type <ttype> parm_declarator
188 %type <ttype> structsp component_decl_list component_decl_list2
189 %type <ttype> component_decl components component_declarator
190 %type <ttype> enumlist enumerator
191 %type <ttype> struct_head union_head enum_head
192 %type <ttype> typename absdcl absdcl1 type_quals
193 %type <ttype> xexpr parms parm identifiers
195 %type <ttype> parmlist parmlist_1 parmlist_2
196 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
197 %type <ttype> identifiers_or_typenames
199 %type <itype> setspecs
201 %type <ends_in_label> lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
203 %type <filename> save_filename
204 %type <lineno> save_lineno
208 /* Number of statements (loosely speaking) and compound statements
210 static int stmt_count;
211 static int compstmt_count;
213 /* Input file and line number of the end of the body of last simple_if;
214 used by the stmt-rule immediately after simple_if returns. */
215 static char *if_stmt_file;
216 static int if_stmt_line;
218 /* List of types and structure classes of the current declaration. */
219 static tree current_declspecs = NULL_TREE;
220 static tree prefix_attributes = NULL_TREE;
222 /* Stack of saved values of current_declspecs and prefix_attributes. */
223 static tree declspec_stack;
225 /* 1 if we explained undeclared var errors. */
226 static int undeclared_variable_notice;
229 /* Tell yyparse how to print a token's value, if yydebug is set. */
231 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
232 extern void yyprint PROTO ((FILE *, int, YYSTYPE));
238 pedwarn ("ANSI C forbids an empty source file");
243 /* In case there were missing closebraces,
244 get us back to the global binding level. */
245 while (! global_bindings_p ())
251 /* the reason for the strange actions in this rule
252 is so that notype_initdecls when reached via datadef
253 can find a valid list of type and sc specs in $0. */
256 {$<ttype>$ = NULL_TREE; } extdef
257 | extdefs {$<ttype>$ = NULL_TREE; } extdef
263 | ASM_KEYWORD '(' expr ')' ';'
265 if ((TREE_CODE ($3) == ADDR_EXPR
266 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
267 || TREE_CODE ($3) == STRING_CST)
270 error ("argument of `asm' is not a constant string"); }
272 { pedantic = $<itype>1; }
276 setspecs notype_initdecls ';'
278 error ("ANSI C forbids data definition with no type or storage class");
279 else if (!flag_traditional)
280 warning ("data definition has no type or storage class");
282 current_declspecs = TREE_VALUE (declspec_stack);
283 prefix_attributes = TREE_PURPOSE (declspec_stack);
284 declspec_stack = TREE_CHAIN (declspec_stack);
285 resume_momentary ($1); }
286 | declmods setspecs notype_initdecls ';'
287 { current_declspecs = TREE_VALUE (declspec_stack);
288 prefix_attributes = TREE_PURPOSE (declspec_stack);
289 declspec_stack = TREE_CHAIN (declspec_stack);
290 resume_momentary ($2); }
291 | typed_declspecs setspecs initdecls ';'
292 { current_declspecs = TREE_VALUE (declspec_stack);
293 prefix_attributes = TREE_PURPOSE (declspec_stack);
294 declspec_stack = TREE_CHAIN (declspec_stack);
295 resume_momentary ($2); }
297 { pedwarn ("empty declaration"); }
298 | typed_declspecs ';'
304 pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
308 typed_declspecs setspecs declarator
309 { if (! start_function (current_declspecs, $3,
310 prefix_attributes, NULL_TREE, 0))
312 reinit_parse_for_function (); }
314 { store_parm_decls (); }
316 { finish_function (0);
317 current_declspecs = TREE_VALUE (declspec_stack);
318 prefix_attributes = TREE_PURPOSE (declspec_stack);
319 declspec_stack = TREE_CHAIN (declspec_stack);
320 resume_momentary ($2); }
321 | typed_declspecs setspecs declarator error
322 { current_declspecs = TREE_VALUE (declspec_stack);
323 prefix_attributes = TREE_PURPOSE (declspec_stack);
324 declspec_stack = TREE_CHAIN (declspec_stack);
325 resume_momentary ($2); }
326 | declmods setspecs notype_declarator
327 { if (! start_function (current_declspecs, $3,
328 prefix_attributes, NULL_TREE, 0))
330 reinit_parse_for_function (); }
332 { store_parm_decls (); }
334 { finish_function (0);
335 current_declspecs = TREE_VALUE (declspec_stack);
336 prefix_attributes = TREE_PURPOSE (declspec_stack);
337 declspec_stack = TREE_CHAIN (declspec_stack);
338 resume_momentary ($2); }
339 | declmods setspecs notype_declarator error
340 { current_declspecs = TREE_VALUE (declspec_stack);
341 prefix_attributes = TREE_PURPOSE (declspec_stack);
342 declspec_stack = TREE_CHAIN (declspec_stack);
343 resume_momentary ($2); }
344 | setspecs notype_declarator
345 { if (! start_function (NULL_TREE, $2,
346 prefix_attributes, NULL_TREE, 0))
348 reinit_parse_for_function (); }
350 { store_parm_decls (); }
352 { finish_function (0);
353 current_declspecs = TREE_VALUE (declspec_stack);
354 prefix_attributes = TREE_PURPOSE (declspec_stack);
355 declspec_stack = TREE_CHAIN (declspec_stack);
356 resume_momentary ($1); }
357 | setspecs notype_declarator error
358 { current_declspecs = TREE_VALUE (declspec_stack);
359 prefix_attributes = TREE_PURPOSE (declspec_stack);
360 declspec_stack = TREE_CHAIN (declspec_stack);
361 resume_momentary ($1); }
372 { $$ = NEGATE_EXPR; }
374 { $$ = CONVERT_EXPR; }
376 { $$ = PREINCREMENT_EXPR; }
378 { $$ = PREDECREMENT_EXPR; }
380 { $$ = BIT_NOT_EXPR; }
382 { $$ = TRUTH_NOT_EXPR; }
385 expr: nonnull_exprlist
386 { $$ = build_compound_expr ($1); }
397 { $$ = build_tree_list (NULL_TREE, $1); }
398 | nonnull_exprlist ',' expr_no_commas
399 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
404 | '*' cast_expr %prec UNARY
405 { $$ = build_indirect_ref ($2, "unary *"); }
406 /* __extension__ turns off -pedantic for following primary. */
407 | extension cast_expr %prec UNARY
409 pedantic = $<itype>1; }
410 | unop cast_expr %prec UNARY
411 { $$ = build_unary_op ($1, $2, 0);
412 overflow_warning ($$); }
413 /* Refer to the address of a label as a pointer. */
415 { tree label = lookup_label ($2);
417 pedwarn ("ANSI C forbids `&&'");
419 $$ = null_pointer_node;
422 TREE_USED (label) = 1;
423 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
424 TREE_CONSTANT ($$) = 1;
427 /* This seems to be impossible on some machines, so let's turn it off.
428 You can use __builtin_next_arg to find the anonymous stack args.
430 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
431 $$ = error_mark_node;
432 if (TREE_VALUE (tree_last (types)) == void_type_node)
433 error ("`&...' used in function with fixed number of arguments");
437 pedwarn ("ANSI C forbids `&...'");
438 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
439 $$ = build_unary_op (ADDR_EXPR, $$, 0);
442 | sizeof unary_expr %prec UNARY
444 if (TREE_CODE ($2) == COMPONENT_REF
445 && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
446 error ("`sizeof' applied to a bit-field");
447 $$ = c_sizeof (TREE_TYPE ($2)); }
448 | sizeof '(' typename ')' %prec HYPERUNARY
450 $$ = c_sizeof (groktypename ($3)); }
451 | alignof unary_expr %prec UNARY
453 $$ = c_alignof_expr ($2); }
454 | alignof '(' typename ')' %prec HYPERUNARY
456 $$ = c_alignof (groktypename ($3)); }
457 | REALPART cast_expr %prec UNARY
458 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
459 | IMAGPART cast_expr %prec UNARY
460 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
461 | VA_ARG '(' expr_no_commas ',' typename ')'
462 { $$ = build_va_arg ($3, groktypename ($5)); }
466 SIZEOF { skip_evaluation++; }
470 ALIGNOF { skip_evaluation++; }
475 | '(' typename ')' cast_expr %prec UNARY
476 { tree type = groktypename ($2);
477 $$ = build_c_cast (type, $4); }
478 | '(' typename ')' '{'
479 { start_init (NULL_TREE, NULL, 0);
480 $2 = groktypename ($2);
481 really_start_incremental_init ($2); }
482 initlist_maybe_comma '}' %prec UNARY
484 tree result = pop_init_level (0);
488 if (pedantic && ! flag_isoc9x)
489 pedwarn ("ANSI C forbids constructor expressions");
490 if (TYPE_NAME (type) != 0)
492 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
493 name = IDENTIFIER_POINTER (TYPE_NAME (type));
495 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
500 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
502 int failure = complete_array_type (type, $$, 1);
511 | expr_no_commas '+' expr_no_commas
512 { $$ = parser_build_binary_op ($2, $1, $3); }
513 | expr_no_commas '-' expr_no_commas
514 { $$ = parser_build_binary_op ($2, $1, $3); }
515 | expr_no_commas '*' expr_no_commas
516 { $$ = parser_build_binary_op ($2, $1, $3); }
517 | expr_no_commas '/' expr_no_commas
518 { $$ = parser_build_binary_op ($2, $1, $3); }
519 | expr_no_commas '%' expr_no_commas
520 { $$ = parser_build_binary_op ($2, $1, $3); }
521 | expr_no_commas LSHIFT expr_no_commas
522 { $$ = parser_build_binary_op ($2, $1, $3); }
523 | expr_no_commas RSHIFT expr_no_commas
524 { $$ = parser_build_binary_op ($2, $1, $3); }
525 | expr_no_commas ARITHCOMPARE expr_no_commas
526 { $$ = parser_build_binary_op ($2, $1, $3); }
527 | expr_no_commas EQCOMPARE expr_no_commas
528 { $$ = parser_build_binary_op ($2, $1, $3); }
529 | expr_no_commas '&' expr_no_commas
530 { $$ = parser_build_binary_op ($2, $1, $3); }
531 | expr_no_commas '|' expr_no_commas
532 { $$ = parser_build_binary_op ($2, $1, $3); }
533 | expr_no_commas '^' expr_no_commas
534 { $$ = parser_build_binary_op ($2, $1, $3); }
535 | expr_no_commas ANDAND
536 { $1 = truthvalue_conversion (default_conversion ($1));
537 skip_evaluation += $1 == boolean_false_node; }
539 { skip_evaluation -= $1 == boolean_false_node;
540 $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
541 | expr_no_commas OROR
542 { $1 = truthvalue_conversion (default_conversion ($1));
543 skip_evaluation += $1 == boolean_true_node; }
545 { skip_evaluation -= $1 == boolean_true_node;
546 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
548 { $1 = truthvalue_conversion (default_conversion ($1));
549 skip_evaluation += $1 == boolean_false_node; }
551 { skip_evaluation += (($1 == boolean_true_node)
552 - ($1 == boolean_false_node)); }
554 { skip_evaluation -= $1 == boolean_true_node;
555 $$ = build_conditional_expr ($1, $4, $7); }
558 pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
559 /* Make sure first operand is calculated only once. */
560 $<ttype>2 = save_expr ($1);
561 $1 = truthvalue_conversion (default_conversion ($<ttype>2));
562 skip_evaluation += $1 == boolean_true_node; }
564 { skip_evaluation -= $1 == boolean_true_node;
565 $$ = build_conditional_expr ($1, $<ttype>2, $5); }
566 | expr_no_commas '=' expr_no_commas
568 $$ = build_modify_expr ($1, NOP_EXPR, $3);
569 class = TREE_CODE_CLASS (TREE_CODE ($$));
570 if (class == 'e' || class == '1'
571 || class == '2' || class == '<')
572 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR);
574 | expr_no_commas ASSIGN expr_no_commas
576 $$ = build_modify_expr ($1, $2, $3);
577 /* This inhibits warnings in truthvalue_conversion. */
578 class = TREE_CODE_CLASS (TREE_CODE ($$));
579 if (class == 'e' || class == '1'
580 || class == '2' || class == '<')
581 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK);
589 if (!$$ || $$ == error_mark_node)
591 if (yychar == YYEMPTY)
596 /* Ordinary implicit function declaration. */
597 $$ = implicitly_declare ($1);
598 assemble_external ($$);
602 else if (current_function_decl == 0)
604 error ("`%s' undeclared here (not in a function)",
605 IDENTIFIER_POINTER ($1));
606 $$ = error_mark_node;
611 if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
612 || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
614 error ("`%s' undeclared (first use in this function)",
615 IDENTIFIER_POINTER ($1));
617 if (! undeclared_variable_notice)
619 error ("(Each undeclared identifier is reported only once");
620 error ("for each function it appears in.)");
621 undeclared_variable_notice = 1;
624 $$ = error_mark_node;
625 /* Prevent repeated error messages. */
626 IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
627 IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
631 else if (TREE_TYPE ($$) == error_mark_node)
632 $$ = error_mark_node;
633 else if (C_DECL_ANTICIPATED ($$))
635 /* The first time we see a build-in function used,
636 if it has not been declared. */
637 C_DECL_ANTICIPATED ($$) = 0;
638 if (yychar == YYEMPTY)
642 /* Omit the implicit declaration we
643 would ordinarily do, so we don't lose
644 the actual built in type.
645 But print a diagnostic for the mismatch. */
646 if (TREE_CODE ($$) != FUNCTION_DECL)
647 error ("`%s' implicitly declared as function",
648 IDENTIFIER_POINTER (DECL_NAME ($$)));
649 else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
650 != TYPE_MODE (integer_type_node))
651 && (TREE_TYPE (TREE_TYPE ($$))
653 pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
654 IDENTIFIER_POINTER (DECL_NAME ($$)));
655 /* If it really returns void, change that to int. */
656 if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
658 = build_function_type (integer_type_node,
659 TYPE_ARG_TYPES (TREE_TYPE ($$)));
662 pedwarn ("built-in function `%s' used without declaration",
663 IDENTIFIER_POINTER (DECL_NAME ($$)));
665 /* Do what we would ordinarily do when a fn is used. */
666 assemble_external ($$);
671 assemble_external ($$);
675 if (TREE_CODE ($$) == CONST_DECL)
677 $$ = DECL_INITIAL ($$);
678 /* This is to prevent an enum whose value is 0
679 from being considered a null pointer constant. */
680 $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
681 TREE_CONSTANT ($$) = 1;
686 { $$ = combine_strings ($1); }
688 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
689 if (class == 'e' || class == '1'
690 || class == '2' || class == '<')
691 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
694 { $$ = error_mark_node; }
696 { if (current_function_decl == 0)
698 error ("braced-group within expression allowed only inside a function");
701 /* We must force a BLOCK for this level
702 so that, if it is not expanded later,
703 there is a way to turn off the entire subtree of blocks
704 that are contained in it. */
706 push_iterator_stack ();
708 $<ttype>$ = expand_start_stmt_expr (); }
712 pedwarn ("ANSI C forbids braced-groups within expressions");
713 pop_iterator_stack ();
715 rtl_exp = expand_end_stmt_expr ($<ttype>2);
716 /* The statements have side effects, so the group does. */
717 TREE_SIDE_EFFECTS (rtl_exp) = 1;
719 if (TREE_CODE ($3) == BLOCK)
721 /* Make a BIND_EXPR for the BLOCK already made. */
722 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
723 NULL_TREE, rtl_exp, $3);
724 /* Remove the block from the tree at this point.
725 It gets put back at the proper place
726 when the BIND_EXPR is expanded. */
732 | primary '(' exprlist ')' %prec '.'
733 { $$ = build_function_call ($1, $3); }
734 | primary '[' expr ']' %prec '.'
735 { $$ = build_array_ref ($1, $3); }
736 | primary '.' identifier
738 $$ = build_component_ref ($1, $3);
740 | primary POINTSAT identifier
742 tree expr = build_indirect_ref ($1, "->");
744 $$ = build_component_ref (expr, $3);
747 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
749 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
752 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
756 { $$ = chainon ($1, $2); }
760 old_style_parm_decls:
764 /* ... is used here to indicate a varargs function. */
767 pedwarn ("ANSI C does not permit use of `varargs.h'"); }
770 /* The following are analogous to lineno_decl, decls and decl
771 except that they do not allow nested functions.
772 They are used for old-style parm decls. */
774 save_filename save_lineno datadecl
781 | datadecls lineno_datadecl
782 | lineno_datadecl errstmt
785 /* We don't allow prefix attributes here because they cause reduce/reduce
786 conflicts: we can't know whether we're parsing a function decl with
787 attribute suffix, or function defn with attribute prefix on first old
790 typed_declspecs_no_prefix_attr setspecs initdecls ';'
791 { current_declspecs = TREE_VALUE (declspec_stack);
792 prefix_attributes = TREE_PURPOSE (declspec_stack);
793 declspec_stack = TREE_CHAIN (declspec_stack);
794 resume_momentary ($2); }
795 | declmods_no_prefix_attr setspecs notype_initdecls ';'
796 { current_declspecs = TREE_VALUE (declspec_stack);
797 prefix_attributes = TREE_PURPOSE (declspec_stack);
798 declspec_stack = TREE_CHAIN (declspec_stack);
799 resume_momentary ($2); }
800 | typed_declspecs_no_prefix_attr ';'
801 { shadow_tag_warned ($1, 1);
802 pedwarn ("empty declaration"); }
803 | declmods_no_prefix_attr ';'
804 { pedwarn ("empty declaration"); }
807 /* This combination which saves a lineno before a decl
808 is the normal thing to use, rather than decl itself.
809 This is to avoid shift/reduce conflicts in contexts
810 where statement labels are allowed. */
812 save_filename save_lineno decl
820 | lineno_decl errstmt
823 /* records the type and storage class specs to use for processing
824 the declarators that follow.
825 Maintains a stack of outer-level values of current_declspecs,
826 for the sake of parm declarations nested in function declarators. */
827 setspecs: /* empty */
828 { $$ = suspend_momentary ();
829 pending_xref_error ();
830 declspec_stack = tree_cons (prefix_attributes,
833 split_specs_attrs ($<ttype>0,
834 ¤t_declspecs, &prefix_attributes); }
837 /* ??? Yuck. See after_type_declarator. */
838 setattrs: /* empty */
839 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
843 typed_declspecs setspecs initdecls ';'
844 { current_declspecs = TREE_VALUE (declspec_stack);
845 prefix_attributes = TREE_PURPOSE (declspec_stack);
846 declspec_stack = TREE_CHAIN (declspec_stack);
847 resume_momentary ($2); }
848 | declmods setspecs notype_initdecls ';'
849 { current_declspecs = TREE_VALUE (declspec_stack);
850 prefix_attributes = TREE_PURPOSE (declspec_stack);
851 declspec_stack = TREE_CHAIN (declspec_stack);
852 resume_momentary ($2); }
853 | typed_declspecs setspecs nested_function
854 { current_declspecs = TREE_VALUE (declspec_stack);
855 prefix_attributes = TREE_PURPOSE (declspec_stack);
856 declspec_stack = TREE_CHAIN (declspec_stack);
857 resume_momentary ($2); }
858 | declmods setspecs notype_nested_function
859 { current_declspecs = TREE_VALUE (declspec_stack);
860 prefix_attributes = TREE_PURPOSE (declspec_stack);
861 declspec_stack = TREE_CHAIN (declspec_stack);
862 resume_momentary ($2); }
863 | typed_declspecs ';'
866 { pedwarn ("empty declaration"); }
868 { pedantic = $<itype>1; }
871 /* Declspecs which contain at least one type specifier or typedef name.
872 (Just `const' or `volatile' is not enough.)
873 A typedef'd name following these is taken as a name to be declared.
874 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
877 typespec reserved_declspecs
878 { $$ = tree_cons (NULL_TREE, $1, $2); }
879 | declmods typespec reserved_declspecs
880 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
883 reserved_declspecs: /* empty */
885 | reserved_declspecs typespecqual_reserved
886 { $$ = tree_cons (NULL_TREE, $2, $1); }
887 | reserved_declspecs SCSPEC
888 { if (extra_warnings)
889 warning ("`%s' is not at beginning of declaration",
890 IDENTIFIER_POINTER ($2));
891 $$ = tree_cons (NULL_TREE, $2, $1); }
892 | reserved_declspecs attributes
893 { $$ = tree_cons ($2, NULL_TREE, $1); }
896 typed_declspecs_no_prefix_attr:
897 typespec reserved_declspecs_no_prefix_attr
898 { $$ = tree_cons (NULL_TREE, $1, $2); }
899 | declmods_no_prefix_attr typespec reserved_declspecs_no_prefix_attr
900 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
903 reserved_declspecs_no_prefix_attr:
906 | reserved_declspecs_no_prefix_attr typespecqual_reserved
907 { $$ = tree_cons (NULL_TREE, $2, $1); }
908 | reserved_declspecs_no_prefix_attr SCSPEC
909 { if (extra_warnings)
910 warning ("`%s' is not at beginning of declaration",
911 IDENTIFIER_POINTER ($2));
912 $$ = tree_cons (NULL_TREE, $2, $1); }
915 /* List of just storage classes, type modifiers, and prefix attributes.
916 A declaration can start with just this, but then it cannot be used
917 to redeclare a typedef-name.
918 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
921 declmods_no_prefix_attr
924 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
925 | declmods declmods_no_prefix_attr
926 { $$ = chainon ($2, $1); }
927 | declmods attributes
928 { $$ = tree_cons ($2, NULL_TREE, $1); }
931 declmods_no_prefix_attr:
933 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
934 TREE_STATIC ($$) = 1; }
936 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
937 | declmods_no_prefix_attr TYPE_QUAL
938 { $$ = tree_cons (NULL_TREE, $2, $1);
939 TREE_STATIC ($$) = 1; }
940 | declmods_no_prefix_attr SCSPEC
941 { if (extra_warnings && TREE_STATIC ($1))
942 warning ("`%s' is not at beginning of declaration",
943 IDENTIFIER_POINTER ($2));
944 $$ = tree_cons (NULL_TREE, $2, $1);
945 TREE_STATIC ($$) = TREE_STATIC ($1); }
949 /* Used instead of declspecs where storage classes are not allowed
950 (that is, for typenames and structure components).
951 Don't accept a typedef-name if anything but a modifier precedes it. */
954 typespec reserved_typespecquals
955 { $$ = tree_cons (NULL_TREE, $1, $2); }
956 | nonempty_type_quals typespec reserved_typespecquals
957 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
960 reserved_typespecquals: /* empty */
962 | reserved_typespecquals typespecqual_reserved
963 { $$ = tree_cons (NULL_TREE, $2, $1); }
966 /* A typespec (but not a type qualifier).
967 Once we have seen one of these in a declaration,
968 if a typedef name appears then it is being redeclared. */
973 { /* For a typedef name, record the meaning, not the name.
974 In case of `foo foo, bar;'. */
975 $$ = lookup_name ($1); }
976 | TYPEOF '(' expr ')'
977 { $$ = TREE_TYPE ($3); }
978 | TYPEOF '(' typename ')'
979 { $$ = groktypename ($3); }
982 /* A typespec that is a reserved word, or a type qualifier. */
984 typespecqual_reserved: TYPESPEC
991 | initdecls ',' initdcl
996 | notype_initdecls ',' initdcl
1002 | ASM_KEYWORD '(' string ')'
1003 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
1009 declarator maybeasm maybe_attribute '='
1010 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1011 $3, prefix_attributes);
1012 start_init ($<ttype>$, $2, global_bindings_p ()); }
1014 /* Note how the declaration of the variable is in effect while its init is parsed! */
1016 finish_decl ($<ttype>5, $6, $2); }
1017 | declarator maybeasm maybe_attribute
1018 { tree d = start_decl ($1, current_declspecs, 0,
1019 $3, prefix_attributes);
1020 finish_decl (d, NULL_TREE, $2);
1025 notype_declarator maybeasm maybe_attribute '='
1026 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1027 $3, prefix_attributes);
1028 start_init ($<ttype>$, $2, global_bindings_p ()); }
1030 /* Note how the declaration of the variable is in effect while its init is parsed! */
1032 decl_attributes ($<ttype>5, $3, prefix_attributes);
1033 finish_decl ($<ttype>5, $6, $2); }
1034 | notype_declarator maybeasm maybe_attribute
1035 { tree d = start_decl ($1, current_declspecs, 0,
1036 $3, prefix_attributes);
1037 finish_decl (d, NULL_TREE, $2); }
1039 /* the * rules are dummies to accept the Apollo extended syntax
1040 so that the header files compile. */
1051 | attributes attribute
1052 { $$ = chainon ($1, $2); }
1056 ATTRIBUTE '(' '(' attribute_list ')' ')'
1063 | attribute_list ',' attrib
1064 { $$ = chainon ($1, $3); }
1071 { $$ = build_tree_list ($1, NULL_TREE); }
1072 | any_word '(' IDENTIFIER ')'
1073 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1074 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1075 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1076 | any_word '(' exprlist ')'
1077 { $$ = build_tree_list ($1, $3); }
1080 /* This still leaves out most reserved keywords,
1081 shouldn't we include them? */
1090 /* Initializers. `init' is the entry point. */
1095 { really_start_incremental_init (NULL_TREE);
1096 /* Note that the call to clear_momentary
1097 is in process_init_element. */
1098 push_momentary (); }
1099 initlist_maybe_comma '}'
1100 { $$ = pop_init_level (0);
1101 if ($$ == error_mark_node
1102 && ! (yychar == STRING || yychar == CONSTANT))
1105 pop_momentary_nofree (); }
1108 { $$ = error_mark_node; }
1111 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1112 initlist_maybe_comma:
1115 pedwarn ("ANSI C forbids empty initializer braces"); }
1116 | initlist1 maybecomma
1121 | initlist1 ',' initelt
1124 /* `initelt' is a single element of an initializer.
1125 It may use braces. */
1127 designator_list '=' initval
1128 | designator initval
1130 { set_init_label ($1); }
1137 { push_init_level (0); }
1138 initlist_maybe_comma '}'
1139 { process_init_element (pop_init_level (0)); }
1141 { process_init_element ($1); }
1147 | designator_list designator
1152 { set_init_label ($2); }
1153 /* These are for labeled elements. The syntax for an array element
1154 initializer conflicts with the syntax for an Objective-C message,
1155 so don't include these productions in the Objective-C grammar. */
1156 | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
1157 { set_init_index ($2, $4); }
1158 | '[' expr_no_commas ']'
1159 { set_init_index ($2, NULL_TREE); }
1164 { push_c_function_context ();
1165 if (! start_function (current_declspecs, $1,
1166 prefix_attributes, NULL_TREE, 1))
1168 pop_c_function_context ();
1171 reinit_parse_for_function (); }
1172 old_style_parm_decls
1173 { store_parm_decls (); }
1174 /* This used to use compstmt_or_error.
1175 That caused a bug with input `f(g) int g {}',
1176 where the use of YYERROR1 above caused an error
1177 which then was handled by compstmt_or_error.
1178 There followed a repeated execution of that same rule,
1179 which called YYERROR1 again, and so on. */
1181 { finish_function (1);
1182 pop_c_function_context (); }
1185 notype_nested_function:
1187 { push_c_function_context ();
1188 if (! start_function (current_declspecs, $1,
1189 prefix_attributes, NULL_TREE, 1))
1191 pop_c_function_context ();
1194 reinit_parse_for_function (); }
1195 old_style_parm_decls
1196 { store_parm_decls (); }
1197 /* This used to use compstmt_or_error.
1198 That caused a bug with input `f(g) int g {}',
1199 where the use of YYERROR1 above caused an error
1200 which then was handled by compstmt_or_error.
1201 There followed a repeated execution of that same rule,
1202 which called YYERROR1 again, and so on. */
1204 { finish_function (1);
1205 pop_c_function_context (); }
1208 /* Any kind of declarator (thus, all declarators allowed
1209 after an explicit typespec). */
1212 after_type_declarator
1216 /* A declarator that is allowed only after an explicit typespec. */
1218 after_type_declarator:
1219 '(' after_type_declarator ')'
1221 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1222 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1223 /* | after_type_declarator '(' error ')' %prec '.'
1224 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1225 poplevel (0, 0, 0); } */
1226 | after_type_declarator '[' expr ']' %prec '.'
1227 { $$ = build_nt (ARRAY_REF, $1, $3); }
1228 | after_type_declarator '[' ']' %prec '.'
1229 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1230 | '*' type_quals after_type_declarator %prec UNARY
1231 { $$ = make_pointer_declarator ($2, $3); }
1232 /* ??? Yuck. setattrs is a quick hack. We can't use
1233 prefix_attributes because $1 only applies to this
1234 declarator. We assume setspecs has already been done.
1235 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1236 attributes could be recognized here or in `attributes'). */
1237 | attributes setattrs after_type_declarator
1242 /* Kinds of declarator that can appear in a parameter list
1243 in addition to notype_declarator. This is like after_type_declarator
1244 but does not allow a typedef name in parentheses as an identifier
1245 (because it would conflict with a function with that typedef as arg). */
1248 parm_declarator '(' parmlist_or_identifiers %prec '.'
1249 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1250 /* | parm_declarator '(' error ')' %prec '.'
1251 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1252 poplevel (0, 0, 0); } */
1253 | parm_declarator '[' '*' ']' %prec '.'
1254 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1256 error ("`[*]' in parameter declaration only allowed in ISO C 9x");
1258 | parm_declarator '[' expr ']' %prec '.'
1259 { $$ = build_nt (ARRAY_REF, $1, $3); }
1260 | parm_declarator '[' ']' %prec '.'
1261 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1262 | '*' type_quals parm_declarator %prec UNARY
1263 { $$ = make_pointer_declarator ($2, $3); }
1264 /* ??? Yuck. setattrs is a quick hack. We can't use
1265 prefix_attributes because $1 only applies to this
1266 declarator. We assume setspecs has already been done.
1267 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1268 attributes could be recognized here or in `attributes'). */
1269 | attributes setattrs parm_declarator
1274 /* A declarator allowed whether or not there has been
1275 an explicit typespec. These cannot redeclare a typedef-name. */
1278 notype_declarator '(' parmlist_or_identifiers %prec '.'
1279 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1280 /* | notype_declarator '(' error ')' %prec '.'
1281 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1282 poplevel (0, 0, 0); } */
1283 | '(' notype_declarator ')'
1285 | '*' type_quals notype_declarator %prec UNARY
1286 { $$ = make_pointer_declarator ($2, $3); }
1287 | notype_declarator '[' '*' ']' %prec '.'
1288 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1290 error ("`[*]' in parameter declaration only allowed in ISO C 9x");
1292 | notype_declarator '[' expr ']' %prec '.'
1293 { $$ = build_nt (ARRAY_REF, $1, $3); }
1294 | notype_declarator '[' ']' %prec '.'
1295 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1296 /* ??? Yuck. setattrs is a quick hack. We can't use
1297 prefix_attributes because $1 only applies to this
1298 declarator. We assume setspecs has already been done.
1299 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1300 attributes could be recognized here or in `attributes'). */
1301 | attributes setattrs notype_declarator
1328 struct_head identifier '{'
1329 { $$ = start_struct (RECORD_TYPE, $2);
1330 /* Start scope of tag before parsing components. */
1332 component_decl_list '}' maybe_attribute
1333 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1334 | struct_head '{' component_decl_list '}' maybe_attribute
1335 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1336 $3, chainon ($1, $5));
1338 | struct_head identifier
1339 { $$ = xref_tag (RECORD_TYPE, $2); }
1340 | union_head identifier '{'
1341 { $$ = start_struct (UNION_TYPE, $2); }
1342 component_decl_list '}' maybe_attribute
1343 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1344 | union_head '{' component_decl_list '}' maybe_attribute
1345 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1346 $3, chainon ($1, $5));
1348 | union_head identifier
1349 { $$ = xref_tag (UNION_TYPE, $2); }
1350 | enum_head identifier '{'
1351 { $<itype>3 = suspend_momentary ();
1352 $$ = start_enum ($2); }
1353 enumlist maybecomma_warn '}' maybe_attribute
1354 { $$= finish_enum ($<ttype>4, nreverse ($5), chainon ($1, $8));
1355 resume_momentary ($<itype>3); }
1357 { $<itype>2 = suspend_momentary ();
1358 $$ = start_enum (NULL_TREE); }
1359 enumlist maybecomma_warn '}' maybe_attribute
1360 { $$= finish_enum ($<ttype>3, nreverse ($4), chainon ($1, $7));
1361 resume_momentary ($<itype>2); }
1362 | enum_head identifier
1363 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1374 { if (pedantic && ! flag_isoc9x)
1375 pedwarn ("comma at end of enumerator list"); }
1378 component_decl_list:
1379 component_decl_list2
1381 | component_decl_list2 component_decl
1382 { $$ = chainon ($1, $2);
1383 pedwarn ("no semicolon at end of struct or union"); }
1386 component_decl_list2: /* empty */
1388 | component_decl_list2 component_decl ';'
1389 { $$ = chainon ($1, $2); }
1390 | component_decl_list2 ';'
1392 pedwarn ("extra semicolon in struct or union specified"); }
1395 /* There is a shift-reduce conflict here, because `components' may
1396 start with a `typename'. It happens that shifting (the default resolution)
1397 does the right thing, because it treats the `typename' as part of
1398 a `typed_typespecs'.
1400 It is possible that this same technique would allow the distinction
1401 between `notype_initdecls' and `initdecls' to be eliminated.
1402 But I am being cautious and not trying it. */
1405 typed_typespecs setspecs components
1407 current_declspecs = TREE_VALUE (declspec_stack);
1408 prefix_attributes = TREE_PURPOSE (declspec_stack);
1409 declspec_stack = TREE_CHAIN (declspec_stack);
1410 resume_momentary ($2); }
1413 pedwarn ("ANSI C forbids member declarations with no members");
1416 | nonempty_type_quals setspecs components
1418 current_declspecs = TREE_VALUE (declspec_stack);
1419 prefix_attributes = TREE_PURPOSE (declspec_stack);
1420 declspec_stack = TREE_CHAIN (declspec_stack);
1421 resume_momentary ($2); }
1422 | nonempty_type_quals
1424 pedwarn ("ANSI C forbids member declarations with no members");
1429 | extension component_decl
1431 pedantic = $<itype>1; }
1435 component_declarator
1436 | components ',' component_declarator
1437 { $$ = chainon ($1, $3); }
1440 component_declarator:
1441 save_filename save_lineno declarator maybe_attribute
1442 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1443 decl_attributes ($$, $4, prefix_attributes); }
1444 | save_filename save_lineno
1445 declarator ':' expr_no_commas maybe_attribute
1446 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1447 decl_attributes ($$, $6, prefix_attributes); }
1448 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1449 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1450 decl_attributes ($$, $5, prefix_attributes); }
1453 /* We chain the enumerators in reverse order.
1454 They are put in forward order where enumlist is used.
1455 (The order used to be significant, but no longer is so.
1456 However, we still maintain the order, just to be clean.) */
1460 | enumlist ',' enumerator
1461 { if ($1 == error_mark_node)
1464 $$ = chainon ($3, $1); }
1466 { $$ = error_mark_node; }
1472 { $$ = build_enumerator ($1, NULL_TREE); }
1473 | identifier '=' expr_no_commas
1474 { $$ = build_enumerator ($1, $3); }
1478 typed_typespecs absdcl
1479 { $$ = build_tree_list ($1, $2); }
1480 | nonempty_type_quals absdcl
1481 { $$ = build_tree_list ($1, $2); }
1484 absdcl: /* an absolute declarator */
1490 nonempty_type_quals:
1492 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1493 | nonempty_type_quals TYPE_QUAL
1494 { $$ = tree_cons (NULL_TREE, $2, $1); }
1500 | type_quals TYPE_QUAL
1501 { $$ = tree_cons (NULL_TREE, $2, $1); }
1504 absdcl1: /* a nonempty absolute declarator */
1507 /* `(typedef)1' is `int'. */
1508 | '*' type_quals absdcl1 %prec UNARY
1509 { $$ = make_pointer_declarator ($2, $3); }
1510 | '*' type_quals %prec UNARY
1511 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1512 | absdcl1 '(' parmlist %prec '.'
1513 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1514 | absdcl1 '[' expr ']' %prec '.'
1515 { $$ = build_nt (ARRAY_REF, $1, $3); }
1516 | absdcl1 '[' ']' %prec '.'
1517 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1518 | '(' parmlist %prec '.'
1519 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1520 | '[' expr ']' %prec '.'
1521 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1523 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1524 /* ??? It appears we have to support attributes here, however
1525 using prefix_attributes is wrong. */
1526 | attributes setattrs absdcl1
1530 /* at least one statement, the first of which parses without error. */
1531 /* stmts is used only after decls, so an invalid first statement
1532 is actually regarded as an invalid decl and part of the decls. */
1535 lineno_stmt_or_labels
1538 pedwarn ("ANSI C forbids label at end of compound statement");
1542 lineno_stmt_or_labels:
1543 lineno_stmt_or_label
1544 | lineno_stmt_or_labels lineno_stmt_or_label
1546 | lineno_stmt_or_labels errstmt
1558 pushlevel: /* empty */
1559 { emit_line_note (input_filename, lineno);
1563 expand_start_bindings (0);
1567 /* Read zero or more forward-declarations for labels
1568 that nested functions can jump to. */
1573 pedwarn ("ANSI C forbids label declarations"); }
1578 | label_decls label_decl
1582 LABEL identifiers_or_typenames ';'
1584 for (link = $2; link; link = TREE_CHAIN (link))
1586 tree label = shadow_label (TREE_VALUE (link));
1587 C_DECLARED_LABEL_FLAG (label) = 1;
1588 declare_nonlocal_label (label);
1593 /* This is the body of a function definition.
1594 It causes syntax errors to ignore to the next openbrace. */
1601 compstmt_start: '{' { compstmt_count++; }
1603 compstmt: compstmt_start '}'
1604 { $$ = convert (void_type_node, integer_zero_node); }
1605 | compstmt_start pushlevel maybe_label_decls decls xstmts '}'
1606 { emit_line_note (input_filename, lineno);
1607 expand_end_bindings (getdecls (), 1, 0);
1608 $$ = poplevel (1, 1, 0);
1609 if (yychar == CONSTANT || yychar == STRING)
1610 pop_momentary_nofree ();
1613 | compstmt_start pushlevel maybe_label_decls error '}'
1614 { emit_line_note (input_filename, lineno);
1615 expand_end_bindings (getdecls (), kept_level_p (), 0);
1616 $$ = poplevel (kept_level_p (), 0, 0);
1617 if (yychar == CONSTANT || yychar == STRING)
1618 pop_momentary_nofree ();
1621 | compstmt_start pushlevel maybe_label_decls stmts '}'
1622 { emit_line_note (input_filename, lineno);
1623 expand_end_bindings (getdecls (), kept_level_p (), 0);
1624 $$ = poplevel (kept_level_p (), 0, 0);
1625 if (yychar == CONSTANT || yychar == STRING)
1626 pop_momentary_nofree ();
1631 /* Value is number of statements counted as of the closeparen. */
1633 if_prefix lineno_labeled_stmt
1634 /* Make sure c_expand_end_cond is run once
1635 for each call to c_expand_start_cond.
1636 Otherwise a crash is likely. */
1642 { emit_line_note ($<filename>-1, $<lineno>0);
1643 c_expand_start_cond (truthvalue_conversion ($3), 0,
1645 $<itype>$ = stmt_count;
1646 if_stmt_file = $<filename>-1;
1647 if_stmt_line = $<lineno>0;
1648 position_after_white_space (); }
1651 /* This is a subroutine of stmt.
1652 It is used twice, once for valid DO statements
1653 and once for catching errors in parsing the end test. */
1658 emit_line_note ($<filename>-1, $<lineno>0);
1659 /* See comment in `while' alternative, above. */
1661 expand_start_loop_continue_elsewhere (1);
1662 position_after_white_space (); }
1663 lineno_labeled_stmt WHILE
1664 { expand_loop_continue_here (); }
1668 { $$ = input_filename; }
1675 lineno_labeled_stmt:
1676 save_filename save_lineno stmt
1678 /* | save_filename save_lineno error
1681 | save_filename save_lineno label lineno_labeled_stmt
1685 lineno_stmt_or_label:
1686 save_filename save_lineno stmt_or_label
1697 /* Parse a single real statement, not including any labels. */
1704 emit_line_note ($<filename>-1, $<lineno>0);
1705 /* It appears that this should not be done--that a non-lvalue array
1706 shouldn't get an error if the value isn't used.
1707 Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1708 if it appears as a top-level expression,
1709 but says nothing about non-lvalue arrays. */
1711 /* Call default_conversion to get an error
1712 on referring to a register array if pedantic. */
1713 if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1714 || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1715 $1 = default_conversion ($1);
1717 iterator_expand ($1);
1718 clear_momentary (); }
1720 { c_expand_start_else ();
1721 $<itype>1 = stmt_count;
1722 position_after_white_space (); }
1724 { c_expand_end_cond ();
1725 if (extra_warnings && stmt_count == $<itype>1)
1726 warning ("empty body in an else-statement"); }
1727 | simple_if %prec IF
1728 { c_expand_end_cond ();
1729 /* This warning is here instead of in simple_if, because we
1730 do not want a warning if an empty if is followed by an
1731 else statement. Increment stmt_count so we don't
1732 give a second error if this is a nested `if'. */
1733 if (extra_warnings && stmt_count++ == $<itype>1)
1734 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1735 "empty body in an if-statement"); }
1736 /* Make sure c_expand_end_cond is run once
1737 for each call to c_expand_start_cond.
1738 Otherwise a crash is likely. */
1739 | simple_if ELSE error
1740 { c_expand_end_cond (); }
1743 emit_line_note ($<filename>-1, $<lineno>0);
1744 /* The emit_nop used to come before emit_line_note,
1745 but that made the nop seem like part of the preceding line.
1746 And that was confusing when the preceding line was
1747 inside of an if statement and was not really executed.
1748 I think it ought to work to put the nop after the line number.
1749 We will see. --rms, July 15, 1991. */
1752 { /* Don't start the loop till we have succeeded
1753 in parsing the end test. This is to make sure
1754 that we end every loop we start. */
1755 expand_start_loop (1);
1756 emit_line_note (input_filename, lineno);
1757 expand_exit_loop_if_false (NULL_PTR,
1758 truthvalue_conversion ($4));
1759 position_after_white_space (); }
1761 { expand_end_loop (); }
1764 { emit_line_note (input_filename, lineno);
1765 expand_exit_loop_if_false (NULL_PTR,
1766 truthvalue_conversion ($3));
1768 clear_momentary (); }
1769 /* This rule is needed to make sure we end every loop we start. */
1770 | do_stmt_start error
1771 { expand_end_loop ();
1772 clear_momentary (); }
1776 emit_line_note ($<filename>-1, $<lineno>0);
1777 /* See comment in `while' alternative, above. */
1779 if ($3) c_expand_expr_stmt ($3);
1780 /* Next step is to call expand_start_loop_continue_elsewhere,
1781 but wait till after we parse the entire for (...).
1782 Otherwise, invalid input might cause us to call that
1783 fn without calling expand_end_loop. */
1786 /* Can't emit now; wait till after expand_start_loop... */
1787 { $<lineno>7 = lineno;
1788 $<filename>$ = input_filename; }
1791 /* Start the loop. Doing this after parsing
1792 all the expressions ensures we will end the loop. */
1793 expand_start_loop_continue_elsewhere (1);
1794 /* Emit the end-test, with a line number. */
1795 emit_line_note ($<filename>8, $<lineno>7);
1797 expand_exit_loop_if_false (NULL_PTR,
1798 truthvalue_conversion ($6));
1799 /* Don't let the tree nodes for $9 be discarded by
1800 clear_momentary during the parsing of the next stmt. */
1802 $<lineno>7 = lineno;
1803 $<filename>8 = input_filename;
1804 position_after_white_space (); }
1806 { /* Emit the increment expression, with a line number. */
1807 emit_line_note ($<filename>8, $<lineno>7);
1808 expand_loop_continue_here ();
1810 c_expand_expr_stmt ($9);
1811 if (yychar == CONSTANT || yychar == STRING)
1812 pop_momentary_nofree ();
1815 expand_end_loop (); }
1816 | SWITCH '(' expr ')'
1818 emit_line_note ($<filename>-1, $<lineno>0);
1819 c_expand_start_case ($3);
1820 /* Don't let the tree nodes for $3 be discarded by
1821 clear_momentary during the parsing of the next stmt. */
1823 position_after_white_space (); }
1825 { expand_end_case ($3);
1826 if (yychar == CONSTANT || yychar == STRING)
1827 pop_momentary_nofree ();
1832 emit_line_note ($<filename>-1, $<lineno>0);
1833 if ( ! expand_exit_something ())
1834 error ("break statement not within loop or switch"); }
1837 emit_line_note ($<filename>-1, $<lineno>0);
1838 if (! expand_continue_loop (NULL_PTR))
1839 error ("continue statement not within a loop"); }
1842 emit_line_note ($<filename>-1, $<lineno>0);
1843 c_expand_return (NULL_TREE); }
1846 emit_line_note ($<filename>-1, $<lineno>0);
1847 c_expand_return ($2); }
1848 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
1850 emit_line_note ($<filename>-1, $<lineno>0);
1852 if ((TREE_CODE ($4) == ADDR_EXPR
1853 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
1854 || TREE_CODE ($4) == STRING_CST)
1857 error ("argument of `asm' is not a constant string"); }
1858 /* This is the case with just output operands. */
1859 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
1861 emit_line_note ($<filename>-1, $<lineno>0);
1862 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
1863 $2 == ridpointers[(int)RID_VOLATILE],
1864 input_filename, lineno); }
1865 /* This is the case with input operands as well. */
1866 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
1868 emit_line_note ($<filename>-1, $<lineno>0);
1869 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
1870 $2 == ridpointers[(int)RID_VOLATILE],
1871 input_filename, lineno); }
1872 /* This is the case with clobbered registers as well. */
1873 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
1874 asm_operands ':' asm_clobbers ')' ';'
1876 emit_line_note ($<filename>-1, $<lineno>0);
1877 c_expand_asm_operands ($4, $6, $8, $10,
1878 $2 == ridpointers[(int)RID_VOLATILE],
1879 input_filename, lineno); }
1880 | GOTO identifier ';'
1883 emit_line_note ($<filename>-1, $<lineno>0);
1884 decl = lookup_label ($2);
1887 TREE_USED (decl) = 1;
1893 pedwarn ("ANSI C forbids `goto *expr;'");
1895 emit_line_note ($<filename>-1, $<lineno>0);
1896 expand_computed_goto (convert (ptr_type_node, $3)); }
1901 all_iter_stmt_simple
1902 /* | all_iter_stmt_with_decl */
1905 all_iter_stmt_simple:
1908 /* The value returned by this action is */
1909 /* 1 if everything is OK */
1910 /* 0 in case of error or already bound iterator */
1913 if (TREE_CODE ($3) != VAR_DECL)
1914 error ("invalid `for (ITERATOR)' syntax");
1915 else if (! ITERATOR_P ($3))
1916 error ("`%s' is not an iterator",
1917 IDENTIFIER_POINTER (DECL_NAME ($3)));
1918 else if (ITERATOR_BOUND_P ($3))
1919 error ("`for (%s)' inside expansion of same iterator",
1920 IDENTIFIER_POINTER (DECL_NAME ($3)));
1924 iterator_for_loop_start ($3);
1930 iterator_for_loop_end ($3);
1933 /* This really should allow any kind of declaration,
1934 for generality. Fix it before turning it back on.
1936 all_iter_stmt_with_decl:
1937 FOR '(' ITERATOR pushlevel setspecs iterator_spec ')'
1939 */ /* The value returned by this action is */
1940 /* 1 if everything is OK */
1941 /* 0 in case of error or already bound iterator */
1943 iterator_for_loop_start ($6);
1947 iterator_for_loop_end ($6);
1948 emit_line_note (input_filename, lineno);
1949 expand_end_bindings (getdecls (), 1, 0);
1950 $<ttype>$ = poplevel (1, 1, 0);
1951 if (yychar == CONSTANT || yychar == STRING)
1952 pop_momentary_nofree ();
1958 /* Any kind of label, including jump labels and case labels.
1959 ANSI C accepts labels only before statements, but we allow them
1960 also at the end of a compound statement. */
1962 label: CASE expr_no_commas ':'
1963 { register tree value = check_case_value ($2);
1965 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1969 if (value != error_mark_node)
1974 if (pedantic && ! INTEGRAL_TYPE_P (TREE_TYPE (value)))
1975 pedwarn ("label must have integral type in ANSI C");
1977 success = pushcase (value, convert_and_check,
1981 error ("case label not within a switch statement");
1982 else if (success == 2)
1984 error ("duplicate case value");
1985 error_with_decl (duplicate, "this is the first entry for that value");
1987 else if (success == 3)
1988 warning ("case value out of range");
1989 else if (success == 5)
1990 error ("case label within scope of cleanup or variable array");
1992 position_after_white_space (); }
1993 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
1994 { register tree value1 = check_case_value ($2);
1995 register tree value2 = check_case_value ($4);
1997 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2000 pedwarn ("ANSI C forbids case ranges");
2003 if (value1 != error_mark_node && value2 != error_mark_node)
2006 int success = pushcase_range (value1, value2,
2007 convert_and_check, label,
2010 error ("case label not within a switch statement");
2011 else if (success == 2)
2013 error ("duplicate case value");
2014 error_with_decl (duplicate, "this is the first entry for that value");
2016 else if (success == 3)
2017 warning ("case value out of range");
2018 else if (success == 4)
2019 warning ("empty case range");
2020 else if (success == 5)
2021 error ("case label within scope of cleanup or variable array");
2023 position_after_white_space (); }
2028 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2029 int success = pushcase (NULL_TREE, 0, label, &duplicate);
2032 error ("default label not within a switch statement");
2033 else if (success == 2)
2035 error ("multiple default labels in one switch");
2036 error_with_decl (duplicate, "this is the first default label");
2038 position_after_white_space (); }
2039 | identifier ':' maybe_attribute
2040 { tree label = define_label (input_filename, lineno, $1);
2045 expand_label (label);
2046 decl_attributes (label, $3, NULL_TREE);
2048 position_after_white_space (); }
2051 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
2055 { emit_line_note (input_filename, lineno);
2058 { emit_line_note (input_filename, lineno); }
2067 /* These are the operands other than the first string and colon
2068 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2069 asm_operands: /* empty */
2071 | nonnull_asm_operands
2074 nonnull_asm_operands:
2076 | nonnull_asm_operands ',' asm_operand
2077 { $$ = chainon ($1, $3); }
2082 { $$ = build_tree_list ($1, $3); }
2087 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
2088 | asm_clobbers ',' string
2089 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
2092 /* This is what appears inside the parens in a function declarator.
2093 Its value is a list of ..._TYPE nodes. */
2096 clear_parm_order ();
2097 declare_parm_level (0); }
2100 parmlist_tags_warning ();
2101 poplevel (0, 0, 0); }
2109 pedwarn ("ANSI C forbids forward parameter declarations");
2110 /* Mark the forward decls as such. */
2111 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2112 TREE_ASM_WRITTEN (parm) = 1;
2113 clear_parm_order (); }
2117 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2120 /* This is what appears inside the parens in a function declarator.
2121 Is value is represented in the format that grokdeclarator expects. */
2122 parmlist_2: /* empty */
2123 { $$ = get_parm_info (0); }
2125 { $$ = get_parm_info (0);
2126 /* Gcc used to allow this as an extension. However, it does
2127 not work for all targets, and thus has been disabled.
2128 Also, since func (...) and func () are indistinguishable,
2129 it caused problems with the code in expand_builtin which
2130 tries to verify that BUILT_IN_NEXT_ARG is being used
2132 error ("ANSI C requires a named argument before `...'");
2135 { $$ = get_parm_info (1); }
2136 | parms ',' ELLIPSIS
2137 { $$ = get_parm_info (0); }
2142 { push_parm_decl ($1); }
2144 { push_parm_decl ($3); }
2147 /* A single parameter declaration or parameter type name,
2148 as found in a parmlist. */
2150 typed_declspecs setspecs parm_declarator maybe_attribute
2151 { $$ = build_tree_list (build_tree_list (current_declspecs,
2153 build_tree_list (prefix_attributes,
2155 current_declspecs = TREE_VALUE (declspec_stack);
2156 prefix_attributes = TREE_PURPOSE (declspec_stack);
2157 declspec_stack = TREE_CHAIN (declspec_stack);
2158 resume_momentary ($2); }
2159 | typed_declspecs setspecs notype_declarator maybe_attribute
2160 { $$ = build_tree_list (build_tree_list (current_declspecs,
2162 build_tree_list (prefix_attributes,
2164 current_declspecs = TREE_VALUE (declspec_stack);
2165 prefix_attributes = TREE_PURPOSE (declspec_stack);
2166 declspec_stack = TREE_CHAIN (declspec_stack);
2167 resume_momentary ($2); }
2168 | typed_declspecs setspecs absdcl maybe_attribute
2169 { $$ = build_tree_list (build_tree_list (current_declspecs,
2171 build_tree_list (prefix_attributes,
2173 current_declspecs = TREE_VALUE (declspec_stack);
2174 prefix_attributes = TREE_PURPOSE (declspec_stack);
2175 declspec_stack = TREE_CHAIN (declspec_stack);
2176 resume_momentary ($2); }
2177 | declmods setspecs notype_declarator maybe_attribute
2178 { $$ = build_tree_list (build_tree_list (current_declspecs,
2180 build_tree_list (prefix_attributes,
2182 current_declspecs = TREE_VALUE (declspec_stack);
2183 prefix_attributes = TREE_PURPOSE (declspec_stack);
2184 declspec_stack = TREE_CHAIN (declspec_stack);
2185 resume_momentary ($2); }
2187 | declmods setspecs absdcl maybe_attribute
2188 { $$ = build_tree_list (build_tree_list (current_declspecs,
2190 build_tree_list (prefix_attributes,
2192 current_declspecs = TREE_VALUE (declspec_stack);
2193 prefix_attributes = TREE_PURPOSE (declspec_stack);
2194 declspec_stack = TREE_CHAIN (declspec_stack);
2195 resume_momentary ($2); }
2198 /* This is used in a function definition
2199 where either a parmlist or an identifier list is ok.
2200 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2201 parmlist_or_identifiers:
2203 clear_parm_order ();
2204 declare_parm_level (1); }
2205 parmlist_or_identifiers_1
2207 parmlist_tags_warning ();
2208 poplevel (0, 0, 0); }
2211 parmlist_or_identifiers_1:
2215 for (t = $1; t; t = TREE_CHAIN (t))
2216 if (TREE_VALUE (t) == NULL_TREE)
2217 error ("`...' in old-style identifier list");
2218 $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2221 /* A nonempty list of identifiers. */
2224 { $$ = build_tree_list (NULL_TREE, $1); }
2225 | identifiers ',' IDENTIFIER
2226 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2229 /* A nonempty list of identifiers, including typenames. */
2230 identifiers_or_typenames:
2232 { $$ = build_tree_list (NULL_TREE, $1); }
2233 | identifiers_or_typenames ',' identifier
2234 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2239 { $<itype>$ = pedantic;