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-97, 1998 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.) */
68 #ifdef MULTIBYTE_CHARS
73 /* Since parsers are distinct for each language, put the language string
75 char *language_string = "GNU C";
77 /* Like YYERROR but do call yyerror. */
78 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
80 /* Cause the `yydebug' variable to be defined. */
86 %union {long itype; tree ttype; enum tree_code code;
87 char *filename; int lineno; int ends_in_label; }
89 /* All identifiers that are not reserved words
90 and are not declared typedefs in the current block */
93 /* All identifiers that are declared typedefs in the current block.
94 In some contexts, they are treated just like IDENTIFIER,
95 but they can also serve as typespecs in declarations. */
98 /* Reserved words that specify storage class.
99 yylval contains an IDENTIFIER_NODE which indicates which one. */
102 /* Reserved words that specify type.
103 yylval contains an IDENTIFIER_NODE which indicates which one. */
106 /* Reserved words that qualify type: "const" or "volatile".
107 yylval contains an IDENTIFIER_NODE which indicates which one. */
110 /* Character or numeric constants.
111 yylval is the node for the constant. */
114 /* String constants in raw form.
115 yylval is a STRING_CST node. */
118 /* "...", used for functions with variable arglists. */
121 /* the reserved words */
122 /* SCO include files test "ASM", so use something else. */
123 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
124 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
125 %token ATTRIBUTE EXTENSION LABEL
126 %token REALPART IMAGPART
128 /* Add precedence rules to solve dangling else s/r conflict */
132 /* Define the operator tokens and their precedences.
133 The value is an integer because, if used, it is the tree code
134 to use in the expression made from the operator. */
136 %right <code> ASSIGN '='
137 %right <code> '?' ':'
143 %left <code> EQCOMPARE
144 %left <code> ARITHCOMPARE
145 %left <code> LSHIFT RSHIFT
147 %left <code> '*' '/' '%'
148 %right <code> UNARY PLUSPLUS MINUSMINUS
150 %left <code> POINTSAT '.' '(' '['
152 /* The Objective-C keywords. These are included in C and in
153 Objective C, so that the token codes are the same in both. */
154 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
155 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
157 /* Objective-C string constants in raw form.
158 yylval is an OBJC_STRING_CST node. */
164 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
165 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
166 %type <ttype> typed_declspecs reserved_declspecs
167 %type <ttype> typed_typespecs reserved_typespecquals
168 %type <ttype> declmods typespec typespecqual_reserved
169 %type <ttype> typed_declspecs_no_prefix_attr reserved_declspecs_no_prefix_attr
170 %type <ttype> declmods_no_prefix_attr
171 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
172 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
173 %type <ttype> init maybeasm
174 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
175 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
176 %type <ttype> any_word
178 %type <ttype> compstmt
180 %type <ttype> declarator
181 %type <ttype> notype_declarator after_type_declarator
182 %type <ttype> parm_declarator
184 %type <ttype> structsp component_decl_list component_decl_list2
185 %type <ttype> component_decl components component_declarator
186 %type <ttype> enumlist enumerator
187 %type <ttype> typename absdcl absdcl1 type_quals
188 %type <ttype> xexpr parms parm identifiers
190 %type <ttype> parmlist parmlist_1 parmlist_2
191 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
192 %type <ttype> identifiers_or_typenames
194 %type <itype> setspecs
196 %type <ends_in_label> lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
198 %type <filename> save_filename
199 %type <lineno> save_lineno
203 /* Number of statements (loosely speaking) and compound statements
205 static int stmt_count;
206 static int compstmt_count;
208 /* Input file and line number of the end of the body of last simple_if;
209 used by the stmt-rule immediately after simple_if returns. */
210 static char *if_stmt_file;
211 static int if_stmt_line;
213 /* List of types and structure classes of the current declaration. */
214 static tree current_declspecs = NULL_TREE;
215 static tree prefix_attributes = NULL_TREE;
217 /* Stack of saved values of current_declspecs and prefix_attributes. */
218 static tree declspec_stack;
220 /* 1 if we explained undeclared var errors. */
221 static int undeclared_variable_notice;
224 /* Tell yyparse how to print a token's value, if yydebug is set. */
226 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
227 extern void yyprint PROTO ((FILE *, int, YYSTYPE));
233 pedwarn ("ANSI C forbids an empty source file");
238 /* In case there were missing closebraces,
239 get us back to the global binding level. */
240 while (! global_bindings_p ())
246 /* the reason for the strange actions in this rule
247 is so that notype_initdecls when reached via datadef
248 can find a valid list of type and sc specs in $0. */
251 {$<ttype>$ = NULL_TREE; } extdef
252 | extdefs {$<ttype>$ = NULL_TREE; } extdef
258 | ASM_KEYWORD '(' expr ')' ';'
260 if ((TREE_CODE ($3) == ADDR_EXPR
261 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
262 || TREE_CODE ($3) == STRING_CST)
265 error ("argument of `asm' is not a constant string"); }
267 { pedantic = $<itype>1; }
271 setspecs notype_initdecls ';'
273 error ("ANSI C forbids data definition with no type or storage class");
274 else if (!flag_traditional)
275 warning ("data definition has no type or storage class");
277 current_declspecs = TREE_VALUE (declspec_stack);
278 prefix_attributes = TREE_PURPOSE (declspec_stack);
279 declspec_stack = TREE_CHAIN (declspec_stack);
280 resume_momentary ($1); }
281 | declmods setspecs notype_initdecls ';'
282 { current_declspecs = TREE_VALUE (declspec_stack);
283 prefix_attributes = TREE_PURPOSE (declspec_stack);
284 declspec_stack = TREE_CHAIN (declspec_stack);
285 resume_momentary ($2); }
286 | typed_declspecs setspecs 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); }
292 { pedwarn ("empty declaration"); }
293 | typed_declspecs ';'
299 pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
303 typed_declspecs setspecs declarator
304 { if (! start_function (current_declspecs, $3,
305 prefix_attributes, NULL_TREE, 0))
307 reinit_parse_for_function (); }
309 { store_parm_decls (); }
311 { finish_function (0);
312 current_declspecs = TREE_VALUE (declspec_stack);
313 prefix_attributes = TREE_PURPOSE (declspec_stack);
314 declspec_stack = TREE_CHAIN (declspec_stack);
315 resume_momentary ($2); }
316 | typed_declspecs setspecs declarator error
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 | declmods setspecs notype_declarator
322 { if (! start_function (current_declspecs, $3,
323 prefix_attributes, NULL_TREE, 0))
325 reinit_parse_for_function (); }
327 { store_parm_decls (); }
329 { finish_function (0);
330 current_declspecs = TREE_VALUE (declspec_stack);
331 prefix_attributes = TREE_PURPOSE (declspec_stack);
332 declspec_stack = TREE_CHAIN (declspec_stack);
333 resume_momentary ($2); }
334 | declmods setspecs notype_declarator error
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 | setspecs notype_declarator
340 { if (! start_function (NULL_TREE, $2,
341 prefix_attributes, NULL_TREE, 0))
343 reinit_parse_for_function (); }
345 { store_parm_decls (); }
347 { finish_function (0);
348 current_declspecs = TREE_VALUE (declspec_stack);
349 prefix_attributes = TREE_PURPOSE (declspec_stack);
350 declspec_stack = TREE_CHAIN (declspec_stack);
351 resume_momentary ($1); }
352 | setspecs notype_declarator error
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); }
367 { $$ = NEGATE_EXPR; }
369 { $$ = CONVERT_EXPR; }
371 { $$ = PREINCREMENT_EXPR; }
373 { $$ = PREDECREMENT_EXPR; }
375 { $$ = BIT_NOT_EXPR; }
377 { $$ = TRUTH_NOT_EXPR; }
380 expr: nonnull_exprlist
381 { $$ = build_compound_expr ($1); }
392 { $$ = build_tree_list (NULL_TREE, $1); }
393 | nonnull_exprlist ',' expr_no_commas
394 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
399 | '*' cast_expr %prec UNARY
400 { $$ = build_indirect_ref ($2, "unary *"); }
401 /* __extension__ turns off -pedantic for following primary. */
402 | extension cast_expr %prec UNARY
404 pedantic = $<itype>1; }
405 | unop cast_expr %prec UNARY
406 { $$ = build_unary_op ($1, $2, 0);
407 overflow_warning ($$); }
408 /* Refer to the address of a label as a pointer. */
410 { tree label = lookup_label ($2);
412 pedwarn ("ANSI C forbids `&&'");
414 $$ = null_pointer_node;
417 TREE_USED (label) = 1;
418 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
419 TREE_CONSTANT ($$) = 1;
422 /* This seems to be impossible on some machines, so let's turn it off.
423 You can use __builtin_next_arg to find the anonymous stack args.
425 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
426 $$ = error_mark_node;
427 if (TREE_VALUE (tree_last (types)) == void_type_node)
428 error ("`&...' used in function with fixed number of arguments");
432 pedwarn ("ANSI C forbids `&...'");
433 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
434 $$ = build_unary_op (ADDR_EXPR, $$, 0);
437 | sizeof unary_expr %prec UNARY
439 if (TREE_CODE ($2) == COMPONENT_REF
440 && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
441 error ("`sizeof' applied to a bit-field");
442 $$ = c_sizeof (TREE_TYPE ($2)); }
443 | sizeof '(' typename ')' %prec HYPERUNARY
445 $$ = c_sizeof (groktypename ($3)); }
446 | alignof unary_expr %prec UNARY
448 $$ = c_alignof_expr ($2); }
449 | alignof '(' typename ')' %prec HYPERUNARY
451 $$ = c_alignof (groktypename ($3)); }
452 | REALPART cast_expr %prec UNARY
453 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
454 | IMAGPART cast_expr %prec UNARY
455 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
459 SIZEOF { skip_evaluation++; }
463 ALIGNOF { skip_evaluation++; }
468 | '(' typename ')' cast_expr %prec UNARY
469 { tree type = groktypename ($2);
470 $$ = build_c_cast (type, $4); }
471 | '(' typename ')' '{'
472 { start_init (NULL_TREE, NULL, 0);
473 $2 = groktypename ($2);
474 really_start_incremental_init ($2); }
475 initlist_maybe_comma '}' %prec UNARY
477 tree result = pop_init_level (0);
482 pedwarn ("ANSI C forbids constructor expressions");
483 if (TYPE_NAME (type) != 0)
485 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
486 name = IDENTIFIER_POINTER (TYPE_NAME (type));
488 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
493 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
495 int failure = complete_array_type (type, $$, 1);
504 | expr_no_commas '+' expr_no_commas
505 { $$ = parser_build_binary_op ($2, $1, $3); }
506 | expr_no_commas '-' expr_no_commas
507 { $$ = parser_build_binary_op ($2, $1, $3); }
508 | expr_no_commas '*' expr_no_commas
509 { $$ = parser_build_binary_op ($2, $1, $3); }
510 | expr_no_commas '/' expr_no_commas
511 { $$ = parser_build_binary_op ($2, $1, $3); }
512 | expr_no_commas '%' expr_no_commas
513 { $$ = parser_build_binary_op ($2, $1, $3); }
514 | expr_no_commas LSHIFT expr_no_commas
515 { $$ = parser_build_binary_op ($2, $1, $3); }
516 | expr_no_commas RSHIFT expr_no_commas
517 { $$ = parser_build_binary_op ($2, $1, $3); }
518 | expr_no_commas ARITHCOMPARE expr_no_commas
519 { $$ = parser_build_binary_op ($2, $1, $3); }
520 | expr_no_commas EQCOMPARE expr_no_commas
521 { $$ = parser_build_binary_op ($2, $1, $3); }
522 | expr_no_commas '&' expr_no_commas
523 { $$ = parser_build_binary_op ($2, $1, $3); }
524 | expr_no_commas '|' expr_no_commas
525 { $$ = parser_build_binary_op ($2, $1, $3); }
526 | expr_no_commas '^' expr_no_commas
527 { $$ = parser_build_binary_op ($2, $1, $3); }
528 | expr_no_commas ANDAND
529 { $1 = truthvalue_conversion (default_conversion ($1));
530 skip_evaluation += $1 == boolean_false_node; }
532 { skip_evaluation -= $1 == boolean_false_node;
533 $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
534 | expr_no_commas OROR
535 { $1 = truthvalue_conversion (default_conversion ($1));
536 skip_evaluation += $1 == boolean_true_node; }
538 { skip_evaluation -= $1 == boolean_true_node;
539 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
541 { $1 = truthvalue_conversion (default_conversion ($1));
542 skip_evaluation += $1 == boolean_false_node; }
544 { skip_evaluation += (($1 == boolean_true_node)
545 - ($1 == boolean_false_node)); }
547 { skip_evaluation -= $1 == boolean_true_node;
548 $$ = build_conditional_expr ($1, $4, $7); }
551 pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
552 /* Make sure first operand is calculated only once. */
553 $<ttype>2 = save_expr ($1);
554 $1 = truthvalue_conversion (default_conversion ($<ttype>2));
555 skip_evaluation += $1 == boolean_true_node; }
557 { skip_evaluation -= $1 == boolean_true_node;
558 $$ = build_conditional_expr ($1, $<ttype>2, $5); }
559 | expr_no_commas '=' expr_no_commas
560 { $$ = build_modify_expr ($1, NOP_EXPR, $3);
561 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
562 | expr_no_commas ASSIGN expr_no_commas
563 { $$ = build_modify_expr ($1, $2, $3);
564 /* This inhibits warnings in truthvalue_conversion. */
565 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); }
572 if (!$$ || $$ == error_mark_node)
574 if (yychar == YYEMPTY)
579 /* Ordinary implicit function declaration. */
580 $$ = implicitly_declare ($1);
581 assemble_external ($$);
585 else if (current_function_decl == 0)
587 error ("`%s' undeclared here (not in a function)",
588 IDENTIFIER_POINTER ($1));
589 $$ = error_mark_node;
594 if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
595 || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
597 error ("`%s' undeclared (first use in this function)",
598 IDENTIFIER_POINTER ($1));
600 if (! undeclared_variable_notice)
602 error ("(Each undeclared identifier is reported only once");
603 error ("for each function it appears in.)");
604 undeclared_variable_notice = 1;
607 $$ = error_mark_node;
608 /* Prevent repeated error messages. */
609 IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
610 IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
614 else if (TREE_TYPE ($$) == error_mark_node)
615 $$ = error_mark_node;
616 else if (C_DECL_ANTICIPATED ($$))
618 /* The first time we see a build-in function used,
619 if it has not been declared. */
620 C_DECL_ANTICIPATED ($$) = 0;
621 if (yychar == YYEMPTY)
625 /* Omit the implicit declaration we
626 would ordinarily do, so we don't lose
627 the actual built in type.
628 But print a diagnostic for the mismatch. */
629 if (TREE_CODE ($$) != FUNCTION_DECL)
630 error ("`%s' implicitly declared as function",
631 IDENTIFIER_POINTER (DECL_NAME ($$)));
632 else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
633 != TYPE_MODE (integer_type_node))
634 && (TREE_TYPE (TREE_TYPE ($$))
636 pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
637 IDENTIFIER_POINTER (DECL_NAME ($$)));
638 /* If it really returns void, change that to int. */
639 if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
641 = build_function_type (integer_type_node,
642 TYPE_ARG_TYPES (TREE_TYPE ($$)));
645 pedwarn ("built-in function `%s' used without declaration",
646 IDENTIFIER_POINTER (DECL_NAME ($$)));
648 /* Do what we would ordinarily do when a fn is used. */
649 assemble_external ($$);
654 assemble_external ($$);
658 if (TREE_CODE ($$) == CONST_DECL)
660 $$ = DECL_INITIAL ($$);
661 /* This is to prevent an enum whose value is 0
662 from being considered a null pointer constant. */
663 $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
664 TREE_CONSTANT ($$) = 1;
669 { $$ = combine_strings ($1); }
671 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
672 if (class == 'e' || class == '1'
673 || class == '2' || class == '<')
674 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
677 { $$ = error_mark_node; }
679 { if (current_function_decl == 0)
681 error ("braced-group within expression allowed only inside a function");
684 /* We must force a BLOCK for this level
685 so that, if it is not expanded later,
686 there is a way to turn off the entire subtree of blocks
687 that are contained in it. */
689 push_iterator_stack ();
691 $<ttype>$ = expand_start_stmt_expr (); }
695 pedwarn ("ANSI C forbids braced-groups within expressions");
696 pop_iterator_stack ();
698 rtl_exp = expand_end_stmt_expr ($<ttype>2);
699 /* The statements have side effects, so the group does. */
700 TREE_SIDE_EFFECTS (rtl_exp) = 1;
702 if (TREE_CODE ($3) == BLOCK)
704 /* Make a BIND_EXPR for the BLOCK already made. */
705 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
706 NULL_TREE, rtl_exp, $3);
707 /* Remove the block from the tree at this point.
708 It gets put back at the proper place
709 when the BIND_EXPR is expanded. */
715 | primary '(' exprlist ')' %prec '.'
716 { $$ = build_function_call ($1, $3); }
717 | primary '[' expr ']' %prec '.'
718 { $$ = build_array_ref ($1, $3); }
719 | primary '.' identifier
721 $$ = build_component_ref ($1, $3);
723 | primary POINTSAT identifier
725 tree expr = build_indirect_ref ($1, "->");
727 $$ = build_component_ref (expr, $3);
730 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
732 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
735 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
739 { $$ = chainon ($1, $2); }
743 old_style_parm_decls:
747 /* ... is used here to indicate a varargs function. */
750 pedwarn ("ANSI C does not permit use of `varargs.h'"); }
753 /* The following are analogous to lineno_decl, decls and decl
754 except that they do not allow nested functions.
755 They are used for old-style parm decls. */
757 save_filename save_lineno datadecl
764 | datadecls lineno_datadecl
765 | lineno_datadecl errstmt
768 /* We don't allow prefix attributes here because they cause reduce/reduce
769 conflicts: we can't know whether we're parsing a function decl with
770 attribute suffix, or function defn with attribute prefix on first old
773 typed_declspecs_no_prefix_attr setspecs initdecls ';'
774 { current_declspecs = TREE_VALUE (declspec_stack);
775 prefix_attributes = TREE_PURPOSE (declspec_stack);
776 declspec_stack = TREE_CHAIN (declspec_stack);
777 resume_momentary ($2); }
778 | declmods_no_prefix_attr setspecs notype_initdecls ';'
779 { current_declspecs = TREE_VALUE (declspec_stack);
780 prefix_attributes = TREE_PURPOSE (declspec_stack);
781 declspec_stack = TREE_CHAIN (declspec_stack);
782 resume_momentary ($2); }
783 | typed_declspecs_no_prefix_attr ';'
784 { shadow_tag_warned ($1, 1);
785 pedwarn ("empty declaration"); }
786 | declmods_no_prefix_attr ';'
787 { pedwarn ("empty declaration"); }
790 /* This combination which saves a lineno before a decl
791 is the normal thing to use, rather than decl itself.
792 This is to avoid shift/reduce conflicts in contexts
793 where statement labels are allowed. */
795 save_filename save_lineno decl
803 | lineno_decl errstmt
806 /* records the type and storage class specs to use for processing
807 the declarators that follow.
808 Maintains a stack of outer-level values of current_declspecs,
809 for the sake of parm declarations nested in function declarators. */
810 setspecs: /* empty */
811 { $$ = suspend_momentary ();
812 pending_xref_error ();
813 declspec_stack = tree_cons (prefix_attributes,
816 split_specs_attrs ($<ttype>0,
817 ¤t_declspecs, &prefix_attributes); }
820 /* ??? Yuck. See after_type_declarator. */
821 setattrs: /* empty */
822 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
826 typed_declspecs setspecs initdecls ';'
827 { current_declspecs = TREE_VALUE (declspec_stack);
828 prefix_attributes = TREE_PURPOSE (declspec_stack);
829 declspec_stack = TREE_CHAIN (declspec_stack);
830 resume_momentary ($2); }
831 | declmods setspecs notype_initdecls ';'
832 { current_declspecs = TREE_VALUE (declspec_stack);
833 prefix_attributes = TREE_PURPOSE (declspec_stack);
834 declspec_stack = TREE_CHAIN (declspec_stack);
835 resume_momentary ($2); }
836 | typed_declspecs setspecs nested_function
837 { current_declspecs = TREE_VALUE (declspec_stack);
838 prefix_attributes = TREE_PURPOSE (declspec_stack);
839 declspec_stack = TREE_CHAIN (declspec_stack);
840 resume_momentary ($2); }
841 | declmods setspecs notype_nested_function
842 { current_declspecs = TREE_VALUE (declspec_stack);
843 prefix_attributes = TREE_PURPOSE (declspec_stack);
844 declspec_stack = TREE_CHAIN (declspec_stack);
845 resume_momentary ($2); }
846 | typed_declspecs ';'
849 { pedwarn ("empty declaration"); }
851 { pedantic = $<itype>1; }
854 /* Declspecs which contain at least one type specifier or typedef name.
855 (Just `const' or `volatile' is not enough.)
856 A typedef'd name following these is taken as a name to be declared.
857 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
860 typespec reserved_declspecs
861 { $$ = tree_cons (NULL_TREE, $1, $2); }
862 | declmods typespec reserved_declspecs
863 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
866 reserved_declspecs: /* empty */
868 | reserved_declspecs typespecqual_reserved
869 { $$ = tree_cons (NULL_TREE, $2, $1); }
870 | reserved_declspecs SCSPEC
871 { if (extra_warnings)
872 warning ("`%s' is not at beginning of declaration",
873 IDENTIFIER_POINTER ($2));
874 $$ = tree_cons (NULL_TREE, $2, $1); }
875 | reserved_declspecs attributes
876 { $$ = tree_cons ($2, NULL_TREE, $1); }
879 typed_declspecs_no_prefix_attr:
880 typespec reserved_declspecs_no_prefix_attr
881 { $$ = tree_cons (NULL_TREE, $1, $2); }
882 | declmods_no_prefix_attr typespec reserved_declspecs_no_prefix_attr
883 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
886 reserved_declspecs_no_prefix_attr:
889 | reserved_declspecs_no_prefix_attr typespecqual_reserved
890 { $$ = tree_cons (NULL_TREE, $2, $1); }
891 | reserved_declspecs_no_prefix_attr SCSPEC
892 { if (extra_warnings)
893 warning ("`%s' is not at beginning of declaration",
894 IDENTIFIER_POINTER ($2));
895 $$ = tree_cons (NULL_TREE, $2, $1); }
898 /* List of just storage classes, type modifiers, and prefix attributes.
899 A declaration can start with just this, but then it cannot be used
900 to redeclare a typedef-name.
901 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
904 declmods_no_prefix_attr
907 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
908 | declmods declmods_no_prefix_attr
909 { $$ = chainon ($2, $1); }
910 | declmods attributes
911 { $$ = tree_cons ($2, NULL_TREE, $1); }
914 declmods_no_prefix_attr:
916 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
917 TREE_STATIC ($$) = 1; }
919 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
920 | declmods_no_prefix_attr TYPE_QUAL
921 { $$ = tree_cons (NULL_TREE, $2, $1);
922 TREE_STATIC ($$) = 1; }
923 | declmods_no_prefix_attr SCSPEC
924 { if (extra_warnings && TREE_STATIC ($1))
925 warning ("`%s' is not at beginning of declaration",
926 IDENTIFIER_POINTER ($2));
927 $$ = tree_cons (NULL_TREE, $2, $1);
928 TREE_STATIC ($$) = TREE_STATIC ($1); }
932 /* Used instead of declspecs where storage classes are not allowed
933 (that is, for typenames and structure components).
934 Don't accept a typedef-name if anything but a modifier precedes it. */
937 typespec reserved_typespecquals
938 { $$ = tree_cons (NULL_TREE, $1, $2); }
939 | nonempty_type_quals typespec reserved_typespecquals
940 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
943 reserved_typespecquals: /* empty */
945 | reserved_typespecquals typespecqual_reserved
946 { $$ = tree_cons (NULL_TREE, $2, $1); }
949 /* A typespec (but not a type qualifier).
950 Once we have seen one of these in a declaration,
951 if a typedef name appears then it is being redeclared. */
956 { /* For a typedef name, record the meaning, not the name.
957 In case of `foo foo, bar;'. */
958 $$ = lookup_name ($1); }
959 | TYPEOF '(' expr ')'
960 { $$ = TREE_TYPE ($3); }
961 | TYPEOF '(' typename ')'
962 { $$ = groktypename ($3); }
965 /* A typespec that is a reserved word, or a type qualifier. */
967 typespecqual_reserved: TYPESPEC
974 | initdecls ',' initdcl
979 | notype_initdecls ',' initdcl
985 | ASM_KEYWORD '(' string ')'
986 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
992 declarator maybeasm maybe_attribute '='
993 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
994 $3, prefix_attributes);
995 start_init ($<ttype>$, $2, global_bindings_p ()); }
997 /* Note how the declaration of the variable is in effect while its init is parsed! */
999 finish_decl ($<ttype>5, $6, $2); }
1000 | declarator maybeasm maybe_attribute
1001 { tree d = start_decl ($1, current_declspecs, 0,
1002 $3, prefix_attributes);
1003 finish_decl (d, NULL_TREE, $2);
1008 notype_declarator maybeasm maybe_attribute '='
1009 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1010 $3, prefix_attributes);
1011 start_init ($<ttype>$, $2, global_bindings_p ()); }
1013 /* Note how the declaration of the variable is in effect while its init is parsed! */
1015 decl_attributes ($<ttype>5, $3, prefix_attributes);
1016 finish_decl ($<ttype>5, $6, $2); }
1017 | notype_declarator maybeasm maybe_attribute
1018 { tree d = start_decl ($1, current_declspecs, 0,
1019 $3, prefix_attributes);
1020 finish_decl (d, NULL_TREE, $2); }
1022 /* the * rules are dummies to accept the Apollo extended syntax
1023 so that the header files compile. */
1034 | attributes attribute
1035 { $$ = chainon ($1, $2); }
1039 ATTRIBUTE '(' '(' attribute_list ')' ')'
1046 | attribute_list ',' attrib
1047 { $$ = chainon ($1, $3); }
1054 { $$ = build_tree_list ($1, NULL_TREE); }
1055 | any_word '(' IDENTIFIER ')'
1056 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1057 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1058 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1059 | any_word '(' exprlist ')'
1060 { $$ = build_tree_list ($1, $3); }
1063 /* This still leaves out most reserved keywords,
1064 shouldn't we include them? */
1073 /* Initializers. `init' is the entry point. */
1078 { really_start_incremental_init (NULL_TREE);
1079 /* Note that the call to clear_momentary
1080 is in process_init_element. */
1081 push_momentary (); }
1082 initlist_maybe_comma '}'
1083 { $$ = pop_init_level (0);
1084 if ($$ == error_mark_node
1085 && ! (yychar == STRING || yychar == CONSTANT))
1088 pop_momentary_nofree (); }
1091 { $$ = error_mark_node; }
1094 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1095 initlist_maybe_comma:
1098 pedwarn ("ANSI C forbids empty initializer braces"); }
1099 | initlist1 maybecomma
1104 | initlist1 ',' initelt
1107 /* `initelt' is a single element of an initializer.
1108 It may use braces. */
1111 { process_init_element ($1); }
1113 { push_init_level (0); }
1114 initlist_maybe_comma '}'
1115 { process_init_element (pop_init_level (0)); }
1117 /* These are for labeled elements. The syntax for an array element
1118 initializer conflicts with the syntax for an Objective-C message,
1119 so don't include these productions in the Objective-C grammar. */
1120 | '[' expr_no_commas ELLIPSIS expr_no_commas ']' '='
1121 { set_init_index ($2, $4); }
1123 | '[' expr_no_commas ']' '='
1124 { set_init_index ($2, NULL_TREE); }
1126 | '[' expr_no_commas ']'
1127 { set_init_index ($2, NULL_TREE); }
1130 { set_init_label ($1); }
1132 | '.' identifier '='
1133 { set_init_label ($2); }
1139 { push_c_function_context ();
1140 if (! start_function (current_declspecs, $1,
1141 prefix_attributes, NULL_TREE, 1))
1143 pop_c_function_context ();
1146 reinit_parse_for_function (); }
1147 old_style_parm_decls
1148 { store_parm_decls (); }
1149 /* This used to use compstmt_or_error.
1150 That caused a bug with input `f(g) int g {}',
1151 where the use of YYERROR1 above caused an error
1152 which then was handled by compstmt_or_error.
1153 There followed a repeated execution of that same rule,
1154 which called YYERROR1 again, and so on. */
1156 { finish_function (1);
1157 pop_c_function_context (); }
1160 notype_nested_function:
1162 { push_c_function_context ();
1163 if (! start_function (current_declspecs, $1,
1164 prefix_attributes, NULL_TREE, 1))
1166 pop_c_function_context ();
1169 reinit_parse_for_function (); }
1170 old_style_parm_decls
1171 { store_parm_decls (); }
1172 /* This used to use compstmt_or_error.
1173 That caused a bug with input `f(g) int g {}',
1174 where the use of YYERROR1 above caused an error
1175 which then was handled by compstmt_or_error.
1176 There followed a repeated execution of that same rule,
1177 which called YYERROR1 again, and so on. */
1179 { finish_function (1);
1180 pop_c_function_context (); }
1183 /* Any kind of declarator (thus, all declarators allowed
1184 after an explicit typespec). */
1187 after_type_declarator
1191 /* A declarator that is allowed only after an explicit typespec. */
1193 after_type_declarator:
1194 '(' after_type_declarator ')'
1196 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1197 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1198 /* | after_type_declarator '(' error ')' %prec '.'
1199 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1200 poplevel (0, 0, 0); } */
1201 | after_type_declarator '[' expr ']' %prec '.'
1202 { $$ = build_nt (ARRAY_REF, $1, $3); }
1203 | after_type_declarator '[' ']' %prec '.'
1204 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1205 | '*' type_quals after_type_declarator %prec UNARY
1206 { $$ = make_pointer_declarator ($2, $3); }
1207 /* ??? Yuck. setattrs is a quick hack. We can't use
1208 prefix_attributes because $1 only applies to this
1209 declarator. We assume setspecs has already been done.
1210 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1211 attributes could be recognized here or in `attributes'). */
1212 | attributes setattrs after_type_declarator
1217 /* Kinds of declarator that can appear in a parameter list
1218 in addition to notype_declarator. This is like after_type_declarator
1219 but does not allow a typedef name in parentheses as an identifier
1220 (because it would conflict with a function with that typedef as arg). */
1223 parm_declarator '(' parmlist_or_identifiers %prec '.'
1224 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1225 /* | parm_declarator '(' error ')' %prec '.'
1226 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1227 poplevel (0, 0, 0); } */
1228 | parm_declarator '[' expr ']' %prec '.'
1229 { $$ = build_nt (ARRAY_REF, $1, $3); }
1230 | parm_declarator '[' ']' %prec '.'
1231 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1232 | '*' type_quals parm_declarator %prec UNARY
1233 { $$ = make_pointer_declarator ($2, $3); }
1234 /* ??? Yuck. setattrs is a quick hack. We can't use
1235 prefix_attributes because $1 only applies to this
1236 declarator. We assume setspecs has already been done.
1237 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1238 attributes could be recognized here or in `attributes'). */
1239 | attributes setattrs parm_declarator
1244 /* A declarator allowed whether or not there has been
1245 an explicit typespec. These cannot redeclare a typedef-name. */
1248 notype_declarator '(' parmlist_or_identifiers %prec '.'
1249 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1250 /* | notype_declarator '(' error ')' %prec '.'
1251 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1252 poplevel (0, 0, 0); } */
1253 | '(' notype_declarator ')'
1255 | '*' type_quals notype_declarator %prec UNARY
1256 { $$ = make_pointer_declarator ($2, $3); }
1257 | notype_declarator '[' expr ']' %prec '.'
1258 { $$ = build_nt (ARRAY_REF, $1, $3); }
1259 | notype_declarator '[' ']' %prec '.'
1260 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1261 /* ??? Yuck. setattrs is a quick hack. We can't use
1262 prefix_attributes because $1 only applies to this
1263 declarator. We assume setspecs has already been done.
1264 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1265 attributes could be recognized here or in `attributes'). */
1266 | attributes setattrs notype_declarator
1272 STRUCT identifier '{'
1273 { $$ = start_struct (RECORD_TYPE, $2);
1274 /* Start scope of tag before parsing components. */
1276 component_decl_list '}' maybe_attribute
1277 { $$ = finish_struct ($<ttype>4, $5, $7); }
1278 | STRUCT '{' component_decl_list '}' maybe_attribute
1279 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1283 { $$ = xref_tag (RECORD_TYPE, $2); }
1284 | UNION identifier '{'
1285 { $$ = start_struct (UNION_TYPE, $2); }
1286 component_decl_list '}' maybe_attribute
1287 { $$ = finish_struct ($<ttype>4, $5, $7); }
1288 | UNION '{' component_decl_list '}' maybe_attribute
1289 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1293 { $$ = xref_tag (UNION_TYPE, $2); }
1294 | ENUM identifier '{'
1295 { $<itype>3 = suspend_momentary ();
1296 $$ = start_enum ($2); }
1297 enumlist maybecomma_warn '}' maybe_attribute
1298 { $$ = finish_enum ($<ttype>4, nreverse ($5), $8);
1299 resume_momentary ($<itype>3); }
1301 { $<itype>2 = suspend_momentary ();
1302 $$ = start_enum (NULL_TREE); }
1303 enumlist maybecomma_warn '}' maybe_attribute
1304 { $$ = finish_enum ($<ttype>3, nreverse ($4), $7);
1305 resume_momentary ($<itype>2); }
1307 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1318 { if (pedantic) pedwarn ("comma at end of enumerator list"); }
1321 component_decl_list:
1322 component_decl_list2
1324 | component_decl_list2 component_decl
1325 { $$ = chainon ($1, $2);
1326 pedwarn ("no semicolon at end of struct or union"); }
1329 component_decl_list2: /* empty */
1331 | component_decl_list2 component_decl ';'
1332 { $$ = chainon ($1, $2); }
1333 | component_decl_list2 ';'
1335 pedwarn ("extra semicolon in struct or union specified"); }
1338 /* There is a shift-reduce conflict here, because `components' may
1339 start with a `typename'. It happens that shifting (the default resolution)
1340 does the right thing, because it treats the `typename' as part of
1341 a `typed_typespecs'.
1343 It is possible that this same technique would allow the distinction
1344 between `notype_initdecls' and `initdecls' to be eliminated.
1345 But I am being cautious and not trying it. */
1348 typed_typespecs setspecs components
1350 current_declspecs = TREE_VALUE (declspec_stack);
1351 prefix_attributes = TREE_PURPOSE (declspec_stack);
1352 declspec_stack = TREE_CHAIN (declspec_stack);
1353 resume_momentary ($2); }
1356 pedwarn ("ANSI C forbids member declarations with no members");
1359 | nonempty_type_quals setspecs components
1361 current_declspecs = TREE_VALUE (declspec_stack);
1362 prefix_attributes = TREE_PURPOSE (declspec_stack);
1363 declspec_stack = TREE_CHAIN (declspec_stack);
1364 resume_momentary ($2); }
1365 | nonempty_type_quals
1367 pedwarn ("ANSI C forbids member declarations with no members");
1372 | extension component_decl
1374 pedantic = $<itype>1; }
1378 component_declarator
1379 | components ',' component_declarator
1380 { $$ = chainon ($1, $3); }
1383 component_declarator:
1384 save_filename save_lineno declarator maybe_attribute
1385 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1386 decl_attributes ($$, $4, prefix_attributes); }
1387 | save_filename save_lineno
1388 declarator ':' expr_no_commas maybe_attribute
1389 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1390 decl_attributes ($$, $6, prefix_attributes); }
1391 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1392 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1393 decl_attributes ($$, $5, prefix_attributes); }
1396 /* We chain the enumerators in reverse order.
1397 They are put in forward order where enumlist is used.
1398 (The order used to be significant, but no longer is so.
1399 However, we still maintain the order, just to be clean.) */
1403 | enumlist ',' enumerator
1404 { if ($1 == error_mark_node)
1407 $$ = chainon ($3, $1); }
1409 { $$ = error_mark_node; }
1415 { $$ = build_enumerator ($1, NULL_TREE); }
1416 | identifier '=' expr_no_commas
1417 { $$ = build_enumerator ($1, $3); }
1421 typed_typespecs absdcl
1422 { $$ = build_tree_list ($1, $2); }
1423 | nonempty_type_quals absdcl
1424 { $$ = build_tree_list ($1, $2); }
1427 absdcl: /* an absolute declarator */
1433 nonempty_type_quals:
1435 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1436 | nonempty_type_quals TYPE_QUAL
1437 { $$ = tree_cons (NULL_TREE, $2, $1); }
1443 | type_quals TYPE_QUAL
1444 { $$ = tree_cons (NULL_TREE, $2, $1); }
1447 absdcl1: /* a nonempty absolute declarator */
1450 /* `(typedef)1' is `int'. */
1451 | '*' type_quals absdcl1 %prec UNARY
1452 { $$ = make_pointer_declarator ($2, $3); }
1453 | '*' type_quals %prec UNARY
1454 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1455 | absdcl1 '(' parmlist %prec '.'
1456 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1457 | absdcl1 '[' expr ']' %prec '.'
1458 { $$ = build_nt (ARRAY_REF, $1, $3); }
1459 | absdcl1 '[' ']' %prec '.'
1460 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1461 | '(' parmlist %prec '.'
1462 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1463 | '[' expr ']' %prec '.'
1464 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1466 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1467 /* ??? It appears we have to support attributes here, however
1468 using prefix_attributes is wrong. */
1471 /* at least one statement, the first of which parses without error. */
1472 /* stmts is used only after decls, so an invalid first statement
1473 is actually regarded as an invalid decl and part of the decls. */
1476 lineno_stmt_or_labels
1479 pedwarn ("ANSI C forbids label at end of compound statement");
1483 lineno_stmt_or_labels:
1484 lineno_stmt_or_label
1485 | lineno_stmt_or_labels lineno_stmt_or_label
1487 | lineno_stmt_or_labels errstmt
1499 pushlevel: /* empty */
1500 { emit_line_note (input_filename, lineno);
1504 expand_start_bindings (0);
1508 /* Read zero or more forward-declarations for labels
1509 that nested functions can jump to. */
1514 pedwarn ("ANSI C forbids label declarations"); }
1519 | label_decls label_decl
1523 LABEL identifiers_or_typenames ';'
1525 for (link = $2; link; link = TREE_CHAIN (link))
1527 tree label = shadow_label (TREE_VALUE (link));
1528 C_DECLARED_LABEL_FLAG (label) = 1;
1529 declare_nonlocal_label (label);
1534 /* This is the body of a function definition.
1535 It causes syntax errors to ignore to the next openbrace. */
1542 compstmt_start: '{' { compstmt_count++; }
1544 compstmt: compstmt_start '}'
1545 { $$ = convert (void_type_node, integer_zero_node); }
1546 | compstmt_start pushlevel maybe_label_decls decls xstmts '}'
1547 { emit_line_note (input_filename, lineno);
1548 expand_end_bindings (getdecls (), 1, 0);
1549 $$ = poplevel (1, 1, 0);
1550 if (yychar == CONSTANT || yychar == STRING)
1551 pop_momentary_nofree ();
1554 | compstmt_start pushlevel maybe_label_decls error '}'
1555 { emit_line_note (input_filename, lineno);
1556 expand_end_bindings (getdecls (), kept_level_p (), 0);
1557 $$ = poplevel (kept_level_p (), 0, 0);
1558 if (yychar == CONSTANT || yychar == STRING)
1559 pop_momentary_nofree ();
1562 | compstmt_start pushlevel maybe_label_decls stmts '}'
1563 { emit_line_note (input_filename, lineno);
1564 expand_end_bindings (getdecls (), kept_level_p (), 0);
1565 $$ = poplevel (kept_level_p (), 0, 0);
1566 if (yychar == CONSTANT || yychar == STRING)
1567 pop_momentary_nofree ();
1572 /* Value is number of statements counted as of the closeparen. */
1574 if_prefix lineno_labeled_stmt
1575 /* Make sure c_expand_end_cond is run once
1576 for each call to c_expand_start_cond.
1577 Otherwise a crash is likely. */
1583 { emit_line_note ($<filename>-1, $<lineno>0);
1584 c_expand_start_cond (truthvalue_conversion ($3), 0,
1586 $<itype>$ = stmt_count;
1587 if_stmt_file = $<filename>-1;
1588 if_stmt_line = $<lineno>0;
1589 position_after_white_space (); }
1592 /* This is a subroutine of stmt.
1593 It is used twice, once for valid DO statements
1594 and once for catching errors in parsing the end test. */
1599 emit_line_note ($<filename>-1, $<lineno>0);
1600 /* See comment in `while' alternative, above. */
1602 expand_start_loop_continue_elsewhere (1);
1603 position_after_white_space (); }
1604 lineno_labeled_stmt WHILE
1605 { expand_loop_continue_here (); }
1609 { $$ = input_filename; }
1616 lineno_labeled_stmt:
1617 save_filename save_lineno stmt
1619 /* | save_filename save_lineno error
1622 | save_filename save_lineno label lineno_labeled_stmt
1626 lineno_stmt_or_label:
1627 save_filename save_lineno stmt_or_label
1638 /* Parse a single real statement, not including any labels. */
1645 emit_line_note ($<filename>-1, $<lineno>0);
1646 /* It appears that this should not be done--that a non-lvalue array
1647 shouldn't get an error if the value isn't used.
1648 Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1649 if it appears as a top-level expression,
1650 but says nothing about non-lvalue arrays. */
1652 /* Call default_conversion to get an error
1653 on referring to a register array if pedantic. */
1654 if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1655 || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1656 $1 = default_conversion ($1);
1658 iterator_expand ($1);
1659 clear_momentary (); }
1661 { c_expand_start_else ();
1662 $<itype>1 = stmt_count;
1663 position_after_white_space (); }
1665 { c_expand_end_cond ();
1666 if (extra_warnings && stmt_count == $<itype>1)
1667 warning ("empty body in an else-statement"); }
1668 | simple_if %prec IF
1669 { c_expand_end_cond ();
1670 /* This warning is here instead of in simple_if, because we
1671 do not want a warning if an empty if is followed by an
1672 else statement. Increment stmt_count so we don't
1673 give a second error if this is a nested `if'. */
1674 if (extra_warnings && stmt_count++ == $<itype>1)
1675 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1676 "empty body in an if-statement"); }
1677 /* Make sure c_expand_end_cond is run once
1678 for each call to c_expand_start_cond.
1679 Otherwise a crash is likely. */
1680 | simple_if ELSE error
1681 { c_expand_end_cond (); }
1684 emit_line_note ($<filename>-1, $<lineno>0);
1685 /* The emit_nop used to come before emit_line_note,
1686 but that made the nop seem like part of the preceding line.
1687 And that was confusing when the preceding line was
1688 inside of an if statement and was not really executed.
1689 I think it ought to work to put the nop after the line number.
1690 We will see. --rms, July 15, 1991. */
1693 { /* Don't start the loop till we have succeeded
1694 in parsing the end test. This is to make sure
1695 that we end every loop we start. */
1696 expand_start_loop (1);
1697 emit_line_note (input_filename, lineno);
1698 expand_exit_loop_if_false (NULL_PTR,
1699 truthvalue_conversion ($4));
1700 position_after_white_space (); }
1702 { expand_end_loop (); }
1705 { emit_line_note (input_filename, lineno);
1706 expand_exit_loop_if_false (NULL_PTR,
1707 truthvalue_conversion ($3));
1709 clear_momentary (); }
1710 /* This rule is needed to make sure we end every loop we start. */
1711 | do_stmt_start error
1712 { expand_end_loop ();
1713 clear_momentary (); }
1717 emit_line_note ($<filename>-1, $<lineno>0);
1718 /* See comment in `while' alternative, above. */
1720 if ($3) c_expand_expr_stmt ($3);
1721 /* Next step is to call expand_start_loop_continue_elsewhere,
1722 but wait till after we parse the entire for (...).
1723 Otherwise, invalid input might cause us to call that
1724 fn without calling expand_end_loop. */
1727 /* Can't emit now; wait till after expand_start_loop... */
1728 { $<lineno>7 = lineno;
1729 $<filename>$ = input_filename; }
1732 /* Start the loop. Doing this after parsing
1733 all the expressions ensures we will end the loop. */
1734 expand_start_loop_continue_elsewhere (1);
1735 /* Emit the end-test, with a line number. */
1736 emit_line_note ($<filename>8, $<lineno>7);
1738 expand_exit_loop_if_false (NULL_PTR,
1739 truthvalue_conversion ($6));
1740 /* Don't let the tree nodes for $9 be discarded by
1741 clear_momentary during the parsing of the next stmt. */
1743 $<lineno>7 = lineno;
1744 $<filename>8 = input_filename;
1745 position_after_white_space (); }
1747 { /* Emit the increment expression, with a line number. */
1748 emit_line_note ($<filename>8, $<lineno>7);
1749 expand_loop_continue_here ();
1751 c_expand_expr_stmt ($9);
1752 if (yychar == CONSTANT || yychar == STRING)
1753 pop_momentary_nofree ();
1756 expand_end_loop (); }
1757 | SWITCH '(' expr ')'
1759 emit_line_note ($<filename>-1, $<lineno>0);
1760 c_expand_start_case ($3);
1761 /* Don't let the tree nodes for $3 be discarded by
1762 clear_momentary during the parsing of the next stmt. */
1764 position_after_white_space (); }
1766 { expand_end_case ($3);
1767 if (yychar == CONSTANT || yychar == STRING)
1768 pop_momentary_nofree ();
1773 emit_line_note ($<filename>-1, $<lineno>0);
1774 if ( ! expand_exit_something ())
1775 error ("break statement not within loop or switch"); }
1778 emit_line_note ($<filename>-1, $<lineno>0);
1779 if (! expand_continue_loop (NULL_PTR))
1780 error ("continue statement not within a loop"); }
1783 emit_line_note ($<filename>-1, $<lineno>0);
1784 c_expand_return (NULL_TREE); }
1787 emit_line_note ($<filename>-1, $<lineno>0);
1788 c_expand_return ($2); }
1789 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
1791 emit_line_note ($<filename>-1, $<lineno>0);
1793 if ((TREE_CODE ($4) == ADDR_EXPR
1794 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
1795 || TREE_CODE ($4) == STRING_CST)
1798 error ("argument of `asm' is not a constant string"); }
1799 /* This is the case with just output operands. */
1800 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
1802 emit_line_note ($<filename>-1, $<lineno>0);
1803 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
1804 $2 == ridpointers[(int)RID_VOLATILE],
1805 input_filename, lineno); }
1806 /* This is the case with input operands as well. */
1807 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
1809 emit_line_note ($<filename>-1, $<lineno>0);
1810 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
1811 $2 == ridpointers[(int)RID_VOLATILE],
1812 input_filename, lineno); }
1813 /* This is the case with clobbered registers as well. */
1814 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
1815 asm_operands ':' asm_clobbers ')' ';'
1817 emit_line_note ($<filename>-1, $<lineno>0);
1818 c_expand_asm_operands ($4, $6, $8, $10,
1819 $2 == ridpointers[(int)RID_VOLATILE],
1820 input_filename, lineno); }
1821 | GOTO identifier ';'
1824 emit_line_note ($<filename>-1, $<lineno>0);
1825 decl = lookup_label ($2);
1828 TREE_USED (decl) = 1;
1834 pedwarn ("ANSI C forbids `goto *expr;'");
1836 emit_line_note ($<filename>-1, $<lineno>0);
1837 expand_computed_goto (convert (ptr_type_node, $3)); }
1842 all_iter_stmt_simple
1843 /* | all_iter_stmt_with_decl */
1846 all_iter_stmt_simple:
1849 /* The value returned by this action is */
1850 /* 1 if everything is OK */
1851 /* 0 in case of error or already bound iterator */
1854 if (TREE_CODE ($3) != VAR_DECL)
1855 error ("invalid `for (ITERATOR)' syntax");
1856 else if (! ITERATOR_P ($3))
1857 error ("`%s' is not an iterator",
1858 IDENTIFIER_POINTER (DECL_NAME ($3)));
1859 else if (ITERATOR_BOUND_P ($3))
1860 error ("`for (%s)' inside expansion of same iterator",
1861 IDENTIFIER_POINTER (DECL_NAME ($3)));
1865 iterator_for_loop_start ($3);
1871 iterator_for_loop_end ($3);
1874 /* This really should allow any kind of declaration,
1875 for generality. Fix it before turning it back on.
1877 all_iter_stmt_with_decl:
1878 FOR '(' ITERATOR pushlevel setspecs iterator_spec ')'
1880 */ /* The value returned by this action is */
1881 /* 1 if everything is OK */
1882 /* 0 in case of error or already bound iterator */
1884 iterator_for_loop_start ($6);
1888 iterator_for_loop_end ($6);
1889 emit_line_note (input_filename, lineno);
1890 expand_end_bindings (getdecls (), 1, 0);
1891 $<ttype>$ = poplevel (1, 1, 0);
1892 if (yychar == CONSTANT || yychar == STRING)
1893 pop_momentary_nofree ();
1899 /* Any kind of label, including jump labels and case labels.
1900 ANSI C accepts labels only before statements, but we allow them
1901 also at the end of a compound statement. */
1903 label: CASE expr_no_commas ':'
1904 { register tree value = check_case_value ($2);
1906 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1910 if (value != error_mark_node)
1913 int success = pushcase (value, convert_and_check,
1916 error ("case label not within a switch statement");
1917 else if (success == 2)
1919 error ("duplicate case value");
1920 error_with_decl (duplicate, "this is the first entry for that value");
1922 else if (success == 3)
1923 warning ("case value out of range");
1924 else if (success == 5)
1925 error ("case label within scope of cleanup or variable array");
1927 position_after_white_space (); }
1928 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
1929 { register tree value1 = check_case_value ($2);
1930 register tree value2 = check_case_value ($4);
1932 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1935 pedwarn ("ANSI C forbids case ranges");
1938 if (value1 != error_mark_node && value2 != error_mark_node)
1941 int success = pushcase_range (value1, value2,
1942 convert_and_check, label,
1945 error ("case label not within a switch statement");
1946 else if (success == 2)
1948 error ("duplicate case value");
1949 error_with_decl (duplicate, "this is the first entry for that value");
1951 else if (success == 3)
1952 warning ("case value out of range");
1953 else if (success == 4)
1954 warning ("empty case range");
1955 else if (success == 5)
1956 error ("case label within scope of cleanup or variable array");
1958 position_after_white_space (); }
1963 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1964 int success = pushcase (NULL_TREE, 0, label, &duplicate);
1967 error ("default label not within a switch statement");
1968 else if (success == 2)
1970 error ("multiple default labels in one switch");
1971 error_with_decl (duplicate, "this is the first default label");
1973 position_after_white_space (); }
1975 { tree label = define_label (input_filename, lineno, $1);
1979 expand_label (label);
1980 position_after_white_space (); }
1983 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
1987 { emit_line_note (input_filename, lineno);
1990 { emit_line_note (input_filename, lineno); }
1999 /* These are the operands other than the first string and colon
2000 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2001 asm_operands: /* empty */
2003 | nonnull_asm_operands
2006 nonnull_asm_operands:
2008 | nonnull_asm_operands ',' asm_operand
2009 { $$ = chainon ($1, $3); }
2014 { $$ = build_tree_list ($1, $3); }
2019 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
2020 | asm_clobbers ',' string
2021 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
2024 /* This is what appears inside the parens in a function declarator.
2025 Its value is a list of ..._TYPE nodes. */
2028 clear_parm_order ();
2029 declare_parm_level (0); }
2032 parmlist_tags_warning ();
2033 poplevel (0, 0, 0); }
2041 pedwarn ("ANSI C forbids forward parameter declarations");
2042 /* Mark the forward decls as such. */
2043 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2044 TREE_ASM_WRITTEN (parm) = 1;
2045 clear_parm_order (); }
2049 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2052 /* This is what appears inside the parens in a function declarator.
2053 Is value is represented in the format that grokdeclarator expects. */
2054 parmlist_2: /* empty */
2055 { $$ = get_parm_info (0); }
2057 { $$ = get_parm_info (0);
2058 /* Gcc used to allow this as an extension. However, it does
2059 not work for all targets, and thus has been disabled.
2060 Also, since func (...) and func () are indistinguishable,
2061 it caused problems with the code in expand_builtin which
2062 tries to verify that BUILT_IN_NEXT_ARG is being used
2064 error ("ANSI C requires a named argument before `...'");
2067 { $$ = get_parm_info (1); }
2068 | parms ',' ELLIPSIS
2069 { $$ = get_parm_info (0); }
2074 { push_parm_decl ($1); }
2076 { push_parm_decl ($3); }
2079 /* A single parameter declaration or parameter type name,
2080 as found in a parmlist. */
2082 typed_declspecs setspecs parm_declarator maybe_attribute
2083 { $$ = build_tree_list (build_tree_list (current_declspecs,
2085 build_tree_list (prefix_attributes,
2087 current_declspecs = TREE_VALUE (declspec_stack);
2088 prefix_attributes = TREE_PURPOSE (declspec_stack);
2089 declspec_stack = TREE_CHAIN (declspec_stack);
2090 resume_momentary ($2); }
2091 | typed_declspecs setspecs notype_declarator maybe_attribute
2092 { $$ = build_tree_list (build_tree_list (current_declspecs,
2094 build_tree_list (prefix_attributes,
2096 current_declspecs = TREE_VALUE (declspec_stack);
2097 prefix_attributes = TREE_PURPOSE (declspec_stack);
2098 declspec_stack = TREE_CHAIN (declspec_stack);
2099 resume_momentary ($2); }
2100 | typed_declspecs setspecs absdcl maybe_attribute
2101 { $$ = build_tree_list (build_tree_list (current_declspecs,
2103 build_tree_list (prefix_attributes,
2105 current_declspecs = TREE_VALUE (declspec_stack);
2106 prefix_attributes = TREE_PURPOSE (declspec_stack);
2107 declspec_stack = TREE_CHAIN (declspec_stack);
2108 resume_momentary ($2); }
2109 | declmods setspecs notype_declarator maybe_attribute
2110 { $$ = build_tree_list (build_tree_list (current_declspecs,
2112 build_tree_list (prefix_attributes,
2114 current_declspecs = TREE_VALUE (declspec_stack);
2115 prefix_attributes = TREE_PURPOSE (declspec_stack);
2116 declspec_stack = TREE_CHAIN (declspec_stack);
2117 resume_momentary ($2); }
2119 | declmods setspecs absdcl maybe_attribute
2120 { $$ = build_tree_list (build_tree_list (current_declspecs,
2122 build_tree_list (prefix_attributes,
2124 current_declspecs = TREE_VALUE (declspec_stack);
2125 prefix_attributes = TREE_PURPOSE (declspec_stack);
2126 declspec_stack = TREE_CHAIN (declspec_stack);
2127 resume_momentary ($2); }
2130 /* This is used in a function definition
2131 where either a parmlist or an identifier list is ok.
2132 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2133 parmlist_or_identifiers:
2135 clear_parm_order ();
2136 declare_parm_level (1); }
2137 parmlist_or_identifiers_1
2139 parmlist_tags_warning ();
2140 poplevel (0, 0, 0); }
2143 parmlist_or_identifiers_1:
2147 for (t = $1; t; t = TREE_CHAIN (t))
2148 if (TREE_VALUE (t) == NULL_TREE)
2149 error ("`...' in old-style identifier list");
2150 $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2153 /* A nonempty list of identifiers. */
2156 { $$ = build_tree_list (NULL_TREE, $1); }
2157 | identifiers ',' IDENTIFIER
2158 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2161 /* A nonempty list of identifiers, including typenames. */
2162 identifiers_or_typenames:
2164 { $$ = build_tree_list (NULL_TREE, $1); }
2165 | identifiers_or_typenames ',' identifier
2166 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2171 { $<itype>$ = pedantic;