Daily bump.
[official-gcc.git] / gcc / c-parse.y
blobbb69dfed3137d742cd66acfef1a09502ab86d571
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)
10 any later version.
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. */
31 %expect 51
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.) */
57 #include "config.h"
58 #include "system.h"
59 #include <setjmp.h>
61 #include "tree.h"
62 #include "input.h"
63 #include "c-lex.h"
64 #include "c-tree.h"
65 #include "flags.h"
66 #include "output.h"
67 #include "toplev.h"
69 #ifdef MULTIBYTE_CHARS
70 #include <locale.h>
71 #endif
74 /* Since parsers are distinct for each language, put the language string
75 definition here. */
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. */
82 #define YYDEBUG 1
85 %start program
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 */
92 %token IDENTIFIER
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. */
97 %token TYPENAME
99 /* Reserved words that specify storage class.
100 yylval contains an IDENTIFIER_NODE which indicates which one. */
101 %token SCSPEC
103 /* Reserved words that specify type.
104 yylval contains an IDENTIFIER_NODE which indicates which one. */
105 %token TYPESPEC
107 /* Reserved words that qualify type: "const", "volatile", or "restrict".
108 yylval contains an IDENTIFIER_NODE which indicates which one. */
109 %token TYPE_QUAL
111 /* Character or numeric constants.
112 yylval is the node for the constant. */
113 %token CONSTANT
115 /* String constants in raw form.
116 yylval is a STRING_CST node. */
117 %token STRING
119 /* "...", used for functions with variable arglists. */
120 %token ELLIPSIS
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
129 /* Add precedence rules to solve dangling else s/r conflict */
130 %nonassoc IF
131 %nonassoc ELSE
133 /* Define the operator tokens and their precedences.
134 The value is an integer because, if used, it is the tree code
135 to use in the expression made from the operator. */
137 %right <code> ASSIGN '='
138 %right <code> '?' ':'
139 %left <code> OROR
140 %left <code> ANDAND
141 %left <code> '|'
142 %left <code> '^'
143 %left <code> '&'
144 %left <code> EQCOMPARE
145 %left <code> ARITHCOMPARE
146 %left <code> LSHIFT RSHIFT
147 %left <code> '+' '-'
148 %left <code> '*' '/' '%'
149 %right <code> UNARY PLUSPLUS MINUSMINUS
150 %left HYPERUNARY
151 %left <code> POINTSAT '.' '(' '['
153 /* The Objective-C keywords. These are included in C and in
154 Objective C, so that the token codes are the same in both. */
155 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
156 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
158 /* Objective-C string constants in raw form.
159 yylval is an OBJC_STRING_CST node. */
160 %token OBJC_STRING
163 %type <code> unop
165 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
166 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
167 %type <ttype> typed_declspecs reserved_declspecs
168 %type <ttype> typed_typespecs reserved_typespecquals
169 %type <ttype> declmods typespec typespecqual_reserved
170 %type <ttype> typed_declspecs_no_prefix_attr reserved_declspecs_no_prefix_attr
171 %type <ttype> declmods_no_prefix_attr
172 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
173 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
174 %type <ttype> init maybeasm
175 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
176 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
177 %type <ttype> any_word
179 %type <ttype> compstmt
181 %type <ttype> declarator
182 %type <ttype> notype_declarator after_type_declarator
183 %type <ttype> parm_declarator
185 %type <ttype> structsp component_decl_list component_decl_list2
186 %type <ttype> component_decl components component_declarator
187 %type <ttype> enumlist enumerator
188 %type <ttype> struct_head union_head enum_head
189 %type <ttype> typename absdcl absdcl1 type_quals
190 %type <ttype> xexpr parms parm identifiers
192 %type <ttype> parmlist parmlist_1 parmlist_2
193 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
194 %type <ttype> identifiers_or_typenames
196 %type <itype> setspecs
198 %type <ends_in_label> lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
200 %type <filename> save_filename
201 %type <lineno> save_lineno
205 /* Number of statements (loosely speaking) and compound statements
206 seen so far. */
207 static int stmt_count;
208 static int compstmt_count;
210 /* Input file and line number of the end of the body of last simple_if;
211 used by the stmt-rule immediately after simple_if returns. */
212 static char *if_stmt_file;
213 static int if_stmt_line;
215 /* List of types and structure classes of the current declaration. */
216 static tree current_declspecs = NULL_TREE;
217 static tree prefix_attributes = NULL_TREE;
219 /* Stack of saved values of current_declspecs and prefix_attributes. */
220 static tree declspec_stack;
222 /* 1 if we explained undeclared var errors. */
223 static int undeclared_variable_notice;
226 /* Tell yyparse how to print a token's value, if yydebug is set. */
228 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
229 extern void yyprint PROTO ((FILE *, int, YYSTYPE));
233 program: /* empty */
234 { if (pedantic)
235 pedwarn ("ANSI C forbids an empty source file");
236 finish_file ();
238 | extdefs
240 /* In case there were missing closebraces,
241 get us back to the global binding level. */
242 while (! global_bindings_p ())
243 poplevel (0, 0, 0);
244 finish_file ();
248 /* the reason for the strange actions in this rule
249 is so that notype_initdecls when reached via datadef
250 can find a valid list of type and sc specs in $0. */
252 extdefs:
253 {$<ttype>$ = NULL_TREE; } extdef
254 | extdefs {$<ttype>$ = NULL_TREE; } extdef
257 extdef:
258 fndef
259 | datadef
260 | ASM_KEYWORD '(' expr ')' ';'
261 { STRIP_NOPS ($3);
262 if ((TREE_CODE ($3) == ADDR_EXPR
263 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
264 || TREE_CODE ($3) == STRING_CST)
265 assemble_asm ($3);
266 else
267 error ("argument of `asm' is not a constant string"); }
268 | extension extdef
269 { pedantic = $<itype>1; }
272 datadef:
273 setspecs notype_initdecls ';'
274 { if (pedantic)
275 error ("ANSI C forbids data definition with no type or storage class");
276 else if (!flag_traditional)
277 warning ("data definition has no type or storage class");
279 current_declspecs = TREE_VALUE (declspec_stack);
280 prefix_attributes = TREE_PURPOSE (declspec_stack);
281 declspec_stack = TREE_CHAIN (declspec_stack);
282 resume_momentary ($1); }
283 | declmods setspecs notype_initdecls ';'
284 { current_declspecs = TREE_VALUE (declspec_stack);
285 prefix_attributes = TREE_PURPOSE (declspec_stack);
286 declspec_stack = TREE_CHAIN (declspec_stack);
287 resume_momentary ($2); }
288 | typed_declspecs setspecs initdecls ';'
289 { current_declspecs = TREE_VALUE (declspec_stack);
290 prefix_attributes = TREE_PURPOSE (declspec_stack);
291 declspec_stack = TREE_CHAIN (declspec_stack);
292 resume_momentary ($2); }
293 | declmods ';'
294 { pedwarn ("empty declaration"); }
295 | typed_declspecs ';'
296 { shadow_tag ($1); }
297 | error ';'
298 | error '}'
299 | ';'
300 { if (pedantic)
301 pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
304 fndef:
305 typed_declspecs setspecs declarator
306 { if (! start_function (current_declspecs, $3,
307 prefix_attributes, NULL_TREE, 0))
308 YYERROR1;
309 reinit_parse_for_function (); }
310 old_style_parm_decls
311 { store_parm_decls (); }
312 compstmt_or_error
313 { finish_function (0);
314 current_declspecs = TREE_VALUE (declspec_stack);
315 prefix_attributes = TREE_PURPOSE (declspec_stack);
316 declspec_stack = TREE_CHAIN (declspec_stack);
317 resume_momentary ($2); }
318 | typed_declspecs setspecs declarator error
319 { current_declspecs = TREE_VALUE (declspec_stack);
320 prefix_attributes = TREE_PURPOSE (declspec_stack);
321 declspec_stack = TREE_CHAIN (declspec_stack);
322 resume_momentary ($2); }
323 | declmods setspecs notype_declarator
324 { if (! start_function (current_declspecs, $3,
325 prefix_attributes, NULL_TREE, 0))
326 YYERROR1;
327 reinit_parse_for_function (); }
328 old_style_parm_decls
329 { store_parm_decls (); }
330 compstmt_or_error
331 { finish_function (0);
332 current_declspecs = TREE_VALUE (declspec_stack);
333 prefix_attributes = TREE_PURPOSE (declspec_stack);
334 declspec_stack = TREE_CHAIN (declspec_stack);
335 resume_momentary ($2); }
336 | declmods setspecs notype_declarator error
337 { current_declspecs = TREE_VALUE (declspec_stack);
338 prefix_attributes = TREE_PURPOSE (declspec_stack);
339 declspec_stack = TREE_CHAIN (declspec_stack);
340 resume_momentary ($2); }
341 | setspecs notype_declarator
342 { if (! start_function (NULL_TREE, $2,
343 prefix_attributes, NULL_TREE, 0))
344 YYERROR1;
345 reinit_parse_for_function (); }
346 old_style_parm_decls
347 { store_parm_decls (); }
348 compstmt_or_error
349 { finish_function (0);
350 current_declspecs = TREE_VALUE (declspec_stack);
351 prefix_attributes = TREE_PURPOSE (declspec_stack);
352 declspec_stack = TREE_CHAIN (declspec_stack);
353 resume_momentary ($1); }
354 | setspecs notype_declarator error
355 { current_declspecs = TREE_VALUE (declspec_stack);
356 prefix_attributes = TREE_PURPOSE (declspec_stack);
357 declspec_stack = TREE_CHAIN (declspec_stack);
358 resume_momentary ($1); }
361 identifier:
362 IDENTIFIER
363 | TYPENAME
366 unop: '&'
367 { $$ = ADDR_EXPR; }
368 | '-'
369 { $$ = NEGATE_EXPR; }
370 | '+'
371 { $$ = CONVERT_EXPR; }
372 | PLUSPLUS
373 { $$ = PREINCREMENT_EXPR; }
374 | MINUSMINUS
375 { $$ = PREDECREMENT_EXPR; }
376 | '~'
377 { $$ = BIT_NOT_EXPR; }
378 | '!'
379 { $$ = TRUTH_NOT_EXPR; }
382 expr: nonnull_exprlist
383 { $$ = build_compound_expr ($1); }
386 exprlist:
387 /* empty */
388 { $$ = NULL_TREE; }
389 | nonnull_exprlist
392 nonnull_exprlist:
393 expr_no_commas
394 { $$ = build_tree_list (NULL_TREE, $1); }
395 | nonnull_exprlist ',' expr_no_commas
396 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
399 unary_expr:
400 primary
401 | '*' cast_expr %prec UNARY
402 { $$ = build_indirect_ref ($2, "unary *"); }
403 /* __extension__ turns off -pedantic for following primary. */
404 | extension cast_expr %prec UNARY
405 { $$ = $2;
406 pedantic = $<itype>1; }
407 | unop cast_expr %prec UNARY
408 { $$ = build_unary_op ($1, $2, 0);
409 overflow_warning ($$); }
410 /* Refer to the address of a label as a pointer. */
411 | ANDAND identifier
412 { tree label = lookup_label ($2);
413 if (pedantic)
414 pedwarn ("ANSI C forbids `&&'");
415 if (label == 0)
416 $$ = null_pointer_node;
417 else
419 TREE_USED (label) = 1;
420 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
421 TREE_CONSTANT ($$) = 1;
424 /* This seems to be impossible on some machines, so let's turn it off.
425 You can use __builtin_next_arg to find the anonymous stack args.
426 | '&' ELLIPSIS
427 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
428 $$ = error_mark_node;
429 if (TREE_VALUE (tree_last (types)) == void_type_node)
430 error ("`&...' used in function with fixed number of arguments");
431 else
433 if (pedantic)
434 pedwarn ("ANSI C forbids `&...'");
435 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
436 $$ = build_unary_op (ADDR_EXPR, $$, 0);
439 | sizeof unary_expr %prec UNARY
440 { skip_evaluation--;
441 if (TREE_CODE ($2) == COMPONENT_REF
442 && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
443 error ("`sizeof' applied to a bit-field");
444 $$ = c_sizeof (TREE_TYPE ($2)); }
445 | sizeof '(' typename ')' %prec HYPERUNARY
446 { skip_evaluation--;
447 $$ = c_sizeof (groktypename ($3)); }
448 | alignof unary_expr %prec UNARY
449 { skip_evaluation--;
450 $$ = c_alignof_expr ($2); }
451 | alignof '(' typename ')' %prec HYPERUNARY
452 { skip_evaluation--;
453 $$ = c_alignof (groktypename ($3)); }
454 | REALPART cast_expr %prec UNARY
455 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
456 | IMAGPART cast_expr %prec UNARY
457 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
460 sizeof:
461 SIZEOF { skip_evaluation++; }
464 alignof:
465 ALIGNOF { skip_evaluation++; }
468 cast_expr:
469 unary_expr
470 | '(' typename ')' cast_expr %prec UNARY
471 { tree type = groktypename ($2);
472 $$ = build_c_cast (type, $4); }
473 | '(' typename ')' '{'
474 { start_init (NULL_TREE, NULL, 0);
475 $2 = groktypename ($2);
476 really_start_incremental_init ($2); }
477 initlist_maybe_comma '}' %prec UNARY
478 { char *name;
479 tree result = pop_init_level (0);
480 tree type = $2;
481 finish_init ();
483 if (pedantic && ! flag_isoc9x)
484 pedwarn ("ANSI C forbids constructor expressions");
485 if (TYPE_NAME (type) != 0)
487 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
488 name = IDENTIFIER_POINTER (TYPE_NAME (type));
489 else
490 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
492 else
493 name = "";
494 $$ = result;
495 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
497 int failure = complete_array_type (type, $$, 1);
498 if (failure)
499 abort ();
504 expr_no_commas:
505 cast_expr
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 '%' expr_no_commas
515 { $$ = parser_build_binary_op ($2, $1, $3); }
516 | expr_no_commas LSHIFT expr_no_commas
517 { $$ = parser_build_binary_op ($2, $1, $3); }
518 | expr_no_commas RSHIFT expr_no_commas
519 { $$ = parser_build_binary_op ($2, $1, $3); }
520 | expr_no_commas ARITHCOMPARE expr_no_commas
521 { $$ = parser_build_binary_op ($2, $1, $3); }
522 | expr_no_commas EQCOMPARE 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 '^' expr_no_commas
529 { $$ = parser_build_binary_op ($2, $1, $3); }
530 | expr_no_commas ANDAND
531 { $1 = truthvalue_conversion (default_conversion ($1));
532 skip_evaluation += $1 == boolean_false_node; }
533 expr_no_commas
534 { skip_evaluation -= $1 == boolean_false_node;
535 $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
536 | expr_no_commas OROR
537 { $1 = truthvalue_conversion (default_conversion ($1));
538 skip_evaluation += $1 == boolean_true_node; }
539 expr_no_commas
540 { skip_evaluation -= $1 == boolean_true_node;
541 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
542 | expr_no_commas '?'
543 { $1 = truthvalue_conversion (default_conversion ($1));
544 skip_evaluation += $1 == boolean_false_node; }
545 expr ':'
546 { skip_evaluation += (($1 == boolean_true_node)
547 - ($1 == boolean_false_node)); }
548 expr_no_commas
549 { skip_evaluation -= $1 == boolean_true_node;
550 $$ = build_conditional_expr ($1, $4, $7); }
551 | expr_no_commas '?'
552 { if (pedantic)
553 pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
554 /* Make sure first operand is calculated only once. */
555 $<ttype>2 = save_expr ($1);
556 $1 = truthvalue_conversion (default_conversion ($<ttype>2));
557 skip_evaluation += $1 == boolean_true_node; }
558 ':' expr_no_commas
559 { skip_evaluation -= $1 == boolean_true_node;
560 $$ = build_conditional_expr ($1, $<ttype>2, $5); }
561 | expr_no_commas '=' expr_no_commas
562 { char class;
563 $$ = build_modify_expr ($1, NOP_EXPR, $3);
564 class = TREE_CODE_CLASS (TREE_CODE ($$));
565 if (class == 'e' || class == '1'
566 || class == '2' || class == '<')
567 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR);
569 | expr_no_commas ASSIGN expr_no_commas
570 { char class;
571 $$ = build_modify_expr ($1, $2, $3);
572 /* This inhibits warnings in truthvalue_conversion. */
573 class = TREE_CODE_CLASS (TREE_CODE ($$));
574 if (class == 'e' || class == '1'
575 || class == '2' || class == '<')
576 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK);
580 primary:
581 IDENTIFIER
583 $$ = lastiddecl;
584 if (!$$ || $$ == error_mark_node)
586 if (yychar == YYEMPTY)
587 yychar = YYLEX;
588 if (yychar == '(')
591 /* Ordinary implicit function declaration. */
592 $$ = implicitly_declare ($1);
593 assemble_external ($$);
594 TREE_USED ($$) = 1;
597 else if (current_function_decl == 0)
599 error ("`%s' undeclared here (not in a function)",
600 IDENTIFIER_POINTER ($1));
601 $$ = error_mark_node;
603 else
606 if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
607 || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
609 error ("`%s' undeclared (first use in this function)",
610 IDENTIFIER_POINTER ($1));
612 if (! undeclared_variable_notice)
614 error ("(Each undeclared identifier is reported only once");
615 error ("for each function it appears in.)");
616 undeclared_variable_notice = 1;
619 $$ = error_mark_node;
620 /* Prevent repeated error messages. */
621 IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
622 IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
626 else if (TREE_TYPE ($$) == error_mark_node)
627 $$ = error_mark_node;
628 else if (C_DECL_ANTICIPATED ($$))
630 /* The first time we see a build-in function used,
631 if it has not been declared. */
632 C_DECL_ANTICIPATED ($$) = 0;
633 if (yychar == YYEMPTY)
634 yychar = YYLEX;
635 if (yychar == '(')
637 /* Omit the implicit declaration we
638 would ordinarily do, so we don't lose
639 the actual built in type.
640 But print a diagnostic for the mismatch. */
641 if (TREE_CODE ($$) != FUNCTION_DECL)
642 error ("`%s' implicitly declared as function",
643 IDENTIFIER_POINTER (DECL_NAME ($$)));
644 else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
645 != TYPE_MODE (integer_type_node))
646 && (TREE_TYPE (TREE_TYPE ($$))
647 != void_type_node))
648 pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
649 IDENTIFIER_POINTER (DECL_NAME ($$)));
650 /* If it really returns void, change that to int. */
651 if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
652 TREE_TYPE ($$)
653 = build_function_type (integer_type_node,
654 TYPE_ARG_TYPES (TREE_TYPE ($$)));
656 else
657 pedwarn ("built-in function `%s' used without declaration",
658 IDENTIFIER_POINTER (DECL_NAME ($$)));
660 /* Do what we would ordinarily do when a fn is used. */
661 assemble_external ($$);
662 TREE_USED ($$) = 1;
664 else
666 assemble_external ($$);
667 TREE_USED ($$) = 1;
670 if (TREE_CODE ($$) == CONST_DECL)
672 $$ = DECL_INITIAL ($$);
673 /* This is to prevent an enum whose value is 0
674 from being considered a null pointer constant. */
675 $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
676 TREE_CONSTANT ($$) = 1;
679 | CONSTANT
680 | string
681 { $$ = combine_strings ($1); }
682 | '(' expr ')'
683 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
684 if (class == 'e' || class == '1'
685 || class == '2' || class == '<')
686 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
687 $$ = $2; }
688 | '(' error ')'
689 { $$ = error_mark_node; }
690 | '('
691 { if (current_function_decl == 0)
693 error ("braced-group within expression allowed only inside a function");
694 YYERROR;
696 /* We must force a BLOCK for this level
697 so that, if it is not expanded later,
698 there is a way to turn off the entire subtree of blocks
699 that are contained in it. */
700 keep_next_level ();
701 push_iterator_stack ();
702 push_label_level ();
703 $<ttype>$ = expand_start_stmt_expr (); }
704 compstmt ')'
705 { tree rtl_exp;
706 if (pedantic)
707 pedwarn ("ANSI C forbids braced-groups within expressions");
708 pop_iterator_stack ();
709 pop_label_level ();
710 rtl_exp = expand_end_stmt_expr ($<ttype>2);
711 /* The statements have side effects, so the group does. */
712 TREE_SIDE_EFFECTS (rtl_exp) = 1;
714 if (TREE_CODE ($3) == BLOCK)
716 /* Make a BIND_EXPR for the BLOCK already made. */
717 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
718 NULL_TREE, rtl_exp, $3);
719 /* Remove the block from the tree at this point.
720 It gets put back at the proper place
721 when the BIND_EXPR is expanded. */
722 delete_block ($3);
724 else
725 $$ = $3;
727 | primary '(' exprlist ')' %prec '.'
728 { $$ = build_function_call ($1, $3); }
729 | primary '[' expr ']' %prec '.'
730 { $$ = build_array_ref ($1, $3); }
731 | primary '.' identifier
733 $$ = build_component_ref ($1, $3);
735 | primary POINTSAT identifier
737 tree expr = build_indirect_ref ($1, "->");
739 $$ = build_component_ref (expr, $3);
741 | primary PLUSPLUS
742 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
743 | primary MINUSMINUS
744 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
747 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
748 string:
749 STRING
750 | string STRING
751 { $$ = chainon ($1, $2); }
755 old_style_parm_decls:
756 /* empty */
757 | datadecls
758 | datadecls ELLIPSIS
759 /* ... is used here to indicate a varargs function. */
760 { c_mark_varargs ();
761 if (pedantic)
762 pedwarn ("ANSI C does not permit use of `varargs.h'"); }
765 /* The following are analogous to lineno_decl, decls and decl
766 except that they do not allow nested functions.
767 They are used for old-style parm decls. */
768 lineno_datadecl:
769 save_filename save_lineno datadecl
773 datadecls:
774 lineno_datadecl
775 | errstmt
776 | datadecls lineno_datadecl
777 | lineno_datadecl errstmt
780 /* We don't allow prefix attributes here because they cause reduce/reduce
781 conflicts: we can't know whether we're parsing a function decl with
782 attribute suffix, or function defn with attribute prefix on first old
783 style parm. */
784 datadecl:
785 typed_declspecs_no_prefix_attr setspecs initdecls ';'
786 { current_declspecs = TREE_VALUE (declspec_stack);
787 prefix_attributes = TREE_PURPOSE (declspec_stack);
788 declspec_stack = TREE_CHAIN (declspec_stack);
789 resume_momentary ($2); }
790 | declmods_no_prefix_attr setspecs notype_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 | typed_declspecs_no_prefix_attr ';'
796 { shadow_tag_warned ($1, 1);
797 pedwarn ("empty declaration"); }
798 | declmods_no_prefix_attr ';'
799 { pedwarn ("empty declaration"); }
802 /* This combination which saves a lineno before a decl
803 is the normal thing to use, rather than decl itself.
804 This is to avoid shift/reduce conflicts in contexts
805 where statement labels are allowed. */
806 lineno_decl:
807 save_filename save_lineno decl
811 decls:
812 lineno_decl
813 | errstmt
814 | decls lineno_decl
815 | lineno_decl errstmt
818 /* records the type and storage class specs to use for processing
819 the declarators that follow.
820 Maintains a stack of outer-level values of current_declspecs,
821 for the sake of parm declarations nested in function declarators. */
822 setspecs: /* empty */
823 { $$ = suspend_momentary ();
824 pending_xref_error ();
825 declspec_stack = tree_cons (prefix_attributes,
826 current_declspecs,
827 declspec_stack);
828 split_specs_attrs ($<ttype>0,
829 &current_declspecs, &prefix_attributes); }
832 /* ??? Yuck. See after_type_declarator. */
833 setattrs: /* empty */
834 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
837 decl:
838 typed_declspecs setspecs initdecls ';'
839 { current_declspecs = TREE_VALUE (declspec_stack);
840 prefix_attributes = TREE_PURPOSE (declspec_stack);
841 declspec_stack = TREE_CHAIN (declspec_stack);
842 resume_momentary ($2); }
843 | declmods setspecs notype_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 | typed_declspecs setspecs nested_function
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 | declmods setspecs notype_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 | typed_declspecs ';'
859 { shadow_tag ($1); }
860 | declmods ';'
861 { pedwarn ("empty declaration"); }
862 | extension decl
863 { pedantic = $<itype>1; }
866 /* Declspecs which contain at least one type specifier or typedef name.
867 (Just `const' or `volatile' is not enough.)
868 A typedef'd name following these is taken as a name to be declared.
869 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
871 typed_declspecs:
872 typespec reserved_declspecs
873 { $$ = tree_cons (NULL_TREE, $1, $2); }
874 | declmods typespec reserved_declspecs
875 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
878 reserved_declspecs: /* empty */
879 { $$ = NULL_TREE; }
880 | reserved_declspecs typespecqual_reserved
881 { $$ = tree_cons (NULL_TREE, $2, $1); }
882 | reserved_declspecs SCSPEC
883 { if (extra_warnings)
884 warning ("`%s' is not at beginning of declaration",
885 IDENTIFIER_POINTER ($2));
886 $$ = tree_cons (NULL_TREE, $2, $1); }
887 | reserved_declspecs attributes
888 { $$ = tree_cons ($2, NULL_TREE, $1); }
891 typed_declspecs_no_prefix_attr:
892 typespec reserved_declspecs_no_prefix_attr
893 { $$ = tree_cons (NULL_TREE, $1, $2); }
894 | declmods_no_prefix_attr typespec reserved_declspecs_no_prefix_attr
895 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
898 reserved_declspecs_no_prefix_attr:
899 /* empty */
900 { $$ = NULL_TREE; }
901 | reserved_declspecs_no_prefix_attr typespecqual_reserved
902 { $$ = tree_cons (NULL_TREE, $2, $1); }
903 | reserved_declspecs_no_prefix_attr SCSPEC
904 { if (extra_warnings)
905 warning ("`%s' is not at beginning of declaration",
906 IDENTIFIER_POINTER ($2));
907 $$ = tree_cons (NULL_TREE, $2, $1); }
910 /* List of just storage classes, type modifiers, and prefix attributes.
911 A declaration can start with just this, but then it cannot be used
912 to redeclare a typedef-name.
913 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
915 declmods:
916 declmods_no_prefix_attr
917 { $$ = $1; }
918 | attributes
919 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
920 | declmods declmods_no_prefix_attr
921 { $$ = chainon ($2, $1); }
922 | declmods attributes
923 { $$ = tree_cons ($2, NULL_TREE, $1); }
926 declmods_no_prefix_attr:
927 TYPE_QUAL
928 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
929 TREE_STATIC ($$) = 1; }
930 | SCSPEC
931 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
932 | declmods_no_prefix_attr TYPE_QUAL
933 { $$ = tree_cons (NULL_TREE, $2, $1);
934 TREE_STATIC ($$) = 1; }
935 | declmods_no_prefix_attr SCSPEC
936 { if (extra_warnings && TREE_STATIC ($1))
937 warning ("`%s' is not at beginning of declaration",
938 IDENTIFIER_POINTER ($2));
939 $$ = tree_cons (NULL_TREE, $2, $1);
940 TREE_STATIC ($$) = TREE_STATIC ($1); }
944 /* Used instead of declspecs where storage classes are not allowed
945 (that is, for typenames and structure components).
946 Don't accept a typedef-name if anything but a modifier precedes it. */
948 typed_typespecs:
949 typespec reserved_typespecquals
950 { $$ = tree_cons (NULL_TREE, $1, $2); }
951 | nonempty_type_quals typespec reserved_typespecquals
952 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
955 reserved_typespecquals: /* empty */
956 { $$ = NULL_TREE; }
957 | reserved_typespecquals typespecqual_reserved
958 { $$ = tree_cons (NULL_TREE, $2, $1); }
961 /* A typespec (but not a type qualifier).
962 Once we have seen one of these in a declaration,
963 if a typedef name appears then it is being redeclared. */
965 typespec: TYPESPEC
966 | structsp
967 | TYPENAME
968 { /* For a typedef name, record the meaning, not the name.
969 In case of `foo foo, bar;'. */
970 $$ = lookup_name ($1); }
971 | TYPEOF '(' expr ')'
972 { $$ = TREE_TYPE ($3); }
973 | TYPEOF '(' typename ')'
974 { $$ = groktypename ($3); }
977 /* A typespec that is a reserved word, or a type qualifier. */
979 typespecqual_reserved: TYPESPEC
980 | TYPE_QUAL
981 | structsp
984 initdecls:
985 initdcl
986 | initdecls ',' initdcl
989 notype_initdecls:
990 notype_initdcl
991 | notype_initdecls ',' initdcl
994 maybeasm:
995 /* empty */
996 { $$ = NULL_TREE; }
997 | ASM_KEYWORD '(' string ')'
998 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
999 $$ = $3;
1003 initdcl:
1004 declarator maybeasm maybe_attribute '='
1005 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1006 $3, prefix_attributes);
1007 start_init ($<ttype>$, $2, global_bindings_p ()); }
1008 init
1009 /* Note how the declaration of the variable is in effect while its init is parsed! */
1010 { finish_init ();
1011 finish_decl ($<ttype>5, $6, $2); }
1012 | declarator maybeasm maybe_attribute
1013 { tree d = start_decl ($1, current_declspecs, 0,
1014 $3, prefix_attributes);
1015 finish_decl (d, NULL_TREE, $2);
1019 notype_initdcl:
1020 notype_declarator maybeasm maybe_attribute '='
1021 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1022 $3, prefix_attributes);
1023 start_init ($<ttype>$, $2, global_bindings_p ()); }
1024 init
1025 /* Note how the declaration of the variable is in effect while its init is parsed! */
1026 { finish_init ();
1027 decl_attributes ($<ttype>5, $3, prefix_attributes);
1028 finish_decl ($<ttype>5, $6, $2); }
1029 | notype_declarator maybeasm maybe_attribute
1030 { tree d = start_decl ($1, current_declspecs, 0,
1031 $3, prefix_attributes);
1032 finish_decl (d, NULL_TREE, $2); }
1034 /* the * rules are dummies to accept the Apollo extended syntax
1035 so that the header files compile. */
1036 maybe_attribute:
1037 /* empty */
1038 { $$ = NULL_TREE; }
1039 | attributes
1040 { $$ = $1; }
1043 attributes:
1044 attribute
1045 { $$ = $1; }
1046 | attributes attribute
1047 { $$ = chainon ($1, $2); }
1050 attribute:
1051 ATTRIBUTE '(' '(' attribute_list ')' ')'
1052 { $$ = $4; }
1055 attribute_list:
1056 attrib
1057 { $$ = $1; }
1058 | attribute_list ',' attrib
1059 { $$ = chainon ($1, $3); }
1062 attrib:
1063 /* empty */
1064 { $$ = NULL_TREE; }
1065 | any_word
1066 { $$ = build_tree_list ($1, NULL_TREE); }
1067 | any_word '(' IDENTIFIER ')'
1068 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1069 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1070 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1071 | any_word '(' exprlist ')'
1072 { $$ = build_tree_list ($1, $3); }
1075 /* This still leaves out most reserved keywords,
1076 shouldn't we include them? */
1078 any_word:
1079 identifier
1080 | SCSPEC
1081 | TYPESPEC
1082 | TYPE_QUAL
1085 /* Initializers. `init' is the entry point. */
1087 init:
1088 expr_no_commas
1089 | '{'
1090 { really_start_incremental_init (NULL_TREE);
1091 /* Note that the call to clear_momentary
1092 is in process_init_element. */
1093 push_momentary (); }
1094 initlist_maybe_comma '}'
1095 { $$ = pop_init_level (0);
1096 if ($$ == error_mark_node
1097 && ! (yychar == STRING || yychar == CONSTANT))
1098 pop_momentary ();
1099 else
1100 pop_momentary_nofree (); }
1102 | error
1103 { $$ = error_mark_node; }
1106 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1107 initlist_maybe_comma:
1108 /* empty */
1109 { if (pedantic)
1110 pedwarn ("ANSI C forbids empty initializer braces"); }
1111 | initlist1 maybecomma
1114 initlist1:
1115 initelt
1116 | initlist1 ',' initelt
1119 /* `initelt' is a single element of an initializer.
1120 It may use braces. */
1121 initelt:
1122 designator_list '=' initval
1123 | designator initval
1124 | identifier ':'
1125 { set_init_label ($1); }
1126 initval
1127 | initval
1130 initval:
1132 { push_init_level (0); }
1133 initlist_maybe_comma '}'
1134 { process_init_element (pop_init_level (0)); }
1135 | expr_no_commas
1136 { process_init_element ($1); }
1137 | error
1140 designator_list:
1141 designator
1142 | designator_list designator
1145 designator:
1146 '.' identifier
1147 { set_init_label ($2); }
1148 /* These are for labeled elements. The syntax for an array element
1149 initializer conflicts with the syntax for an Objective-C message,
1150 so don't include these productions in the Objective-C grammar. */
1151 | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
1152 { set_init_index ($2, $4); }
1153 | '[' expr_no_commas ']'
1154 { set_init_index ($2, NULL_TREE); }
1157 nested_function:
1158 declarator
1159 { push_c_function_context ();
1160 if (! start_function (current_declspecs, $1,
1161 prefix_attributes, NULL_TREE, 1))
1163 pop_c_function_context ();
1164 YYERROR1;
1166 reinit_parse_for_function (); }
1167 old_style_parm_decls
1168 { store_parm_decls (); }
1169 /* This used to use compstmt_or_error.
1170 That caused a bug with input `f(g) int g {}',
1171 where the use of YYERROR1 above caused an error
1172 which then was handled by compstmt_or_error.
1173 There followed a repeated execution of that same rule,
1174 which called YYERROR1 again, and so on. */
1175 compstmt
1176 { finish_function (1);
1177 pop_c_function_context (); }
1180 notype_nested_function:
1181 notype_declarator
1182 { push_c_function_context ();
1183 if (! start_function (current_declspecs, $1,
1184 prefix_attributes, NULL_TREE, 1))
1186 pop_c_function_context ();
1187 YYERROR1;
1189 reinit_parse_for_function (); }
1190 old_style_parm_decls
1191 { store_parm_decls (); }
1192 /* This used to use compstmt_or_error.
1193 That caused a bug with input `f(g) int g {}',
1194 where the use of YYERROR1 above caused an error
1195 which then was handled by compstmt_or_error.
1196 There followed a repeated execution of that same rule,
1197 which called YYERROR1 again, and so on. */
1198 compstmt
1199 { finish_function (1);
1200 pop_c_function_context (); }
1203 /* Any kind of declarator (thus, all declarators allowed
1204 after an explicit typespec). */
1206 declarator:
1207 after_type_declarator
1208 | notype_declarator
1211 /* A declarator that is allowed only after an explicit typespec. */
1213 after_type_declarator:
1214 '(' after_type_declarator ')'
1215 { $$ = $2; }
1216 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1217 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1218 /* | after_type_declarator '(' error ')' %prec '.'
1219 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1220 poplevel (0, 0, 0); } */
1221 | after_type_declarator '[' expr ']' %prec '.'
1222 { $$ = build_nt (ARRAY_REF, $1, $3); }
1223 | after_type_declarator '[' ']' %prec '.'
1224 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1225 | '*' type_quals after_type_declarator %prec UNARY
1226 { $$ = make_pointer_declarator ($2, $3); }
1227 /* ??? Yuck. setattrs is a quick hack. We can't use
1228 prefix_attributes because $1 only applies to this
1229 declarator. We assume setspecs has already been done.
1230 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1231 attributes could be recognized here or in `attributes'). */
1232 | attributes setattrs after_type_declarator
1233 { $$ = $3; }
1234 | TYPENAME
1237 /* Kinds of declarator that can appear in a parameter list
1238 in addition to notype_declarator. This is like after_type_declarator
1239 but does not allow a typedef name in parentheses as an identifier
1240 (because it would conflict with a function with that typedef as arg). */
1242 parm_declarator:
1243 parm_declarator '(' parmlist_or_identifiers %prec '.'
1244 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1245 /* | parm_declarator '(' error ')' %prec '.'
1246 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1247 poplevel (0, 0, 0); } */
1248 | parm_declarator '[' '*' ']' %prec '.'
1249 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1250 if (! flag_isoc9x)
1251 error ("`[*]' in parameter declaration only allowed in ISO C 9x");
1253 | parm_declarator '[' expr ']' %prec '.'
1254 { $$ = build_nt (ARRAY_REF, $1, $3); }
1255 | parm_declarator '[' ']' %prec '.'
1256 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1257 | '*' type_quals parm_declarator %prec UNARY
1258 { $$ = make_pointer_declarator ($2, $3); }
1259 /* ??? Yuck. setattrs is a quick hack. We can't use
1260 prefix_attributes because $1 only applies to this
1261 declarator. We assume setspecs has already been done.
1262 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1263 attributes could be recognized here or in `attributes'). */
1264 | attributes setattrs parm_declarator
1265 { $$ = $3; }
1266 | TYPENAME
1269 /* A declarator allowed whether or not there has been
1270 an explicit typespec. These cannot redeclare a typedef-name. */
1272 notype_declarator:
1273 notype_declarator '(' parmlist_or_identifiers %prec '.'
1274 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1275 /* | notype_declarator '(' error ')' %prec '.'
1276 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1277 poplevel (0, 0, 0); } */
1278 | '(' notype_declarator ')'
1279 { $$ = $2; }
1280 | '*' type_quals notype_declarator %prec UNARY
1281 { $$ = make_pointer_declarator ($2, $3); }
1282 | notype_declarator '[' '*' ']' %prec '.'
1283 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1284 if (! flag_isoc9x)
1285 error ("`[*]' in parameter declaration only allowed in ISO C 9x");
1287 | notype_declarator '[' expr ']' %prec '.'
1288 { $$ = build_nt (ARRAY_REF, $1, $3); }
1289 | notype_declarator '[' ']' %prec '.'
1290 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1291 /* ??? Yuck. setattrs is a quick hack. We can't use
1292 prefix_attributes because $1 only applies to this
1293 declarator. We assume setspecs has already been done.
1294 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1295 attributes could be recognized here or in `attributes'). */
1296 | attributes setattrs notype_declarator
1297 { $$ = $3; }
1298 | IDENTIFIER
1301 struct_head:
1302 STRUCT
1303 { $$ = NULL_TREE; }
1304 | STRUCT attributes
1305 { $$ = $2; }
1308 union_head:
1309 UNION
1310 { $$ = NULL_TREE; }
1311 | UNION attributes
1312 { $$ = $2; }
1315 enum_head:
1316 ENUM
1317 { $$ = NULL_TREE; }
1318 | ENUM attributes
1319 { $$ = $2; }
1322 structsp:
1323 struct_head identifier '{'
1324 { $$ = start_struct (RECORD_TYPE, $2);
1325 /* Start scope of tag before parsing components. */
1327 component_decl_list '}' maybe_attribute
1328 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1329 | struct_head '{' component_decl_list '}' maybe_attribute
1330 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1331 $3, chainon ($1, $5));
1333 | struct_head identifier
1334 { $$ = xref_tag (RECORD_TYPE, $2); }
1335 | union_head identifier '{'
1336 { $$ = start_struct (UNION_TYPE, $2); }
1337 component_decl_list '}' maybe_attribute
1338 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1339 | union_head '{' component_decl_list '}' maybe_attribute
1340 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1341 $3, chainon ($1, $5));
1343 | union_head identifier
1344 { $$ = xref_tag (UNION_TYPE, $2); }
1345 | enum_head identifier '{'
1346 { $<itype>3 = suspend_momentary ();
1347 $$ = start_enum ($2); }
1348 enumlist maybecomma_warn '}' maybe_attribute
1349 { $$= finish_enum ($<ttype>4, nreverse ($5), chainon ($1, $8));
1350 resume_momentary ($<itype>3); }
1351 | enum_head '{'
1352 { $<itype>2 = suspend_momentary ();
1353 $$ = start_enum (NULL_TREE); }
1354 enumlist maybecomma_warn '}' maybe_attribute
1355 { $$= finish_enum ($<ttype>3, nreverse ($4), chainon ($1, $7));
1356 resume_momentary ($<itype>2); }
1357 | enum_head identifier
1358 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1361 maybecomma:
1362 /* empty */
1363 | ','
1366 maybecomma_warn:
1367 /* empty */
1368 | ','
1369 { if (pedantic && ! flag_isoc9x)
1370 pedwarn ("comma at end of enumerator list"); }
1373 component_decl_list:
1374 component_decl_list2
1375 { $$ = $1; }
1376 | component_decl_list2 component_decl
1377 { $$ = chainon ($1, $2);
1378 pedwarn ("no semicolon at end of struct or union"); }
1381 component_decl_list2: /* empty */
1382 { $$ = NULL_TREE; }
1383 | component_decl_list2 component_decl ';'
1384 { $$ = chainon ($1, $2); }
1385 | component_decl_list2 ';'
1386 { if (pedantic)
1387 pedwarn ("extra semicolon in struct or union specified"); }
1390 /* There is a shift-reduce conflict here, because `components' may
1391 start with a `typename'. It happens that shifting (the default resolution)
1392 does the right thing, because it treats the `typename' as part of
1393 a `typed_typespecs'.
1395 It is possible that this same technique would allow the distinction
1396 between `notype_initdecls' and `initdecls' to be eliminated.
1397 But I am being cautious and not trying it. */
1399 component_decl:
1400 typed_typespecs setspecs components
1401 { $$ = $3;
1402 current_declspecs = TREE_VALUE (declspec_stack);
1403 prefix_attributes = TREE_PURPOSE (declspec_stack);
1404 declspec_stack = TREE_CHAIN (declspec_stack);
1405 resume_momentary ($2); }
1406 | typed_typespecs
1407 { if (pedantic)
1408 pedwarn ("ANSI C forbids member declarations with no members");
1409 shadow_tag($1);
1410 $$ = NULL_TREE; }
1411 | nonempty_type_quals setspecs components
1412 { $$ = $3;
1413 current_declspecs = TREE_VALUE (declspec_stack);
1414 prefix_attributes = TREE_PURPOSE (declspec_stack);
1415 declspec_stack = TREE_CHAIN (declspec_stack);
1416 resume_momentary ($2); }
1417 | nonempty_type_quals
1418 { if (pedantic)
1419 pedwarn ("ANSI C forbids member declarations with no members");
1420 shadow_tag($1);
1421 $$ = NULL_TREE; }
1422 | error
1423 { $$ = NULL_TREE; }
1424 | extension component_decl
1425 { $$ = $2;
1426 pedantic = $<itype>1; }
1429 components:
1430 component_declarator
1431 | components ',' component_declarator
1432 { $$ = chainon ($1, $3); }
1435 component_declarator:
1436 save_filename save_lineno declarator maybe_attribute
1437 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1438 decl_attributes ($$, $4, prefix_attributes); }
1439 | save_filename save_lineno
1440 declarator ':' expr_no_commas maybe_attribute
1441 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1442 decl_attributes ($$, $6, prefix_attributes); }
1443 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1444 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1445 decl_attributes ($$, $5, prefix_attributes); }
1448 /* We chain the enumerators in reverse order.
1449 They are put in forward order where enumlist is used.
1450 (The order used to be significant, but no longer is so.
1451 However, we still maintain the order, just to be clean.) */
1453 enumlist:
1454 enumerator
1455 | enumlist ',' enumerator
1456 { if ($1 == error_mark_node)
1457 $$ = $1;
1458 else
1459 $$ = chainon ($3, $1); }
1460 | error
1461 { $$ = error_mark_node; }
1465 enumerator:
1466 identifier
1467 { $$ = build_enumerator ($1, NULL_TREE); }
1468 | identifier '=' expr_no_commas
1469 { $$ = build_enumerator ($1, $3); }
1472 typename:
1473 typed_typespecs absdcl
1474 { $$ = build_tree_list ($1, $2); }
1475 | nonempty_type_quals absdcl
1476 { $$ = build_tree_list ($1, $2); }
1479 absdcl: /* an absolute declarator */
1480 /* empty */
1481 { $$ = NULL_TREE; }
1482 | absdcl1
1485 nonempty_type_quals:
1486 TYPE_QUAL
1487 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1488 | nonempty_type_quals TYPE_QUAL
1489 { $$ = tree_cons (NULL_TREE, $2, $1); }
1492 type_quals:
1493 /* empty */
1494 { $$ = NULL_TREE; }
1495 | type_quals TYPE_QUAL
1496 { $$ = tree_cons (NULL_TREE, $2, $1); }
1499 absdcl1: /* a nonempty absolute declarator */
1500 '(' absdcl1 ')'
1501 { $$ = $2; }
1502 /* `(typedef)1' is `int'. */
1503 | '*' type_quals absdcl1 %prec UNARY
1504 { $$ = make_pointer_declarator ($2, $3); }
1505 | '*' type_quals %prec UNARY
1506 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1507 | absdcl1 '(' parmlist %prec '.'
1508 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1509 | absdcl1 '[' expr ']' %prec '.'
1510 { $$ = build_nt (ARRAY_REF, $1, $3); }
1511 | absdcl1 '[' ']' %prec '.'
1512 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1513 | '(' parmlist %prec '.'
1514 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1515 | '[' expr ']' %prec '.'
1516 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1517 | '[' ']' %prec '.'
1518 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1519 /* ??? It appears we have to support attributes here, however
1520 using prefix_attributes is wrong. */
1521 | attributes setattrs absdcl1
1522 { $$ = $3; }
1525 /* at least one statement, the first of which parses without error. */
1526 /* stmts is used only after decls, so an invalid first statement
1527 is actually regarded as an invalid decl and part of the decls. */
1529 stmts:
1530 lineno_stmt_or_labels
1532 if (pedantic && $1)
1533 pedwarn ("ANSI C forbids label at end of compound statement");
1537 lineno_stmt_or_labels:
1538 lineno_stmt_or_label
1539 | lineno_stmt_or_labels lineno_stmt_or_label
1540 { $$ = $2; }
1541 | lineno_stmt_or_labels errstmt
1542 { $$ = 0; }
1545 xstmts:
1546 /* empty */
1547 | stmts
1550 errstmt: error ';'
1553 pushlevel: /* empty */
1554 { emit_line_note (input_filename, lineno);
1555 pushlevel (0);
1556 clear_last_expr ();
1557 push_momentary ();
1558 expand_start_bindings (0);
1562 /* Read zero or more forward-declarations for labels
1563 that nested functions can jump to. */
1564 maybe_label_decls:
1565 /* empty */
1566 | label_decls
1567 { if (pedantic)
1568 pedwarn ("ANSI C forbids label declarations"); }
1571 label_decls:
1572 label_decl
1573 | label_decls label_decl
1576 label_decl:
1577 LABEL identifiers_or_typenames ';'
1578 { tree link;
1579 for (link = $2; link; link = TREE_CHAIN (link))
1581 tree label = shadow_label (TREE_VALUE (link));
1582 C_DECLARED_LABEL_FLAG (label) = 1;
1583 declare_nonlocal_label (label);
1588 /* This is the body of a function definition.
1589 It causes syntax errors to ignore to the next openbrace. */
1590 compstmt_or_error:
1591 compstmt
1593 | error compstmt
1596 compstmt_start: '{' { compstmt_count++; }
1598 compstmt: compstmt_start '}'
1599 { $$ = convert (void_type_node, integer_zero_node); }
1600 | compstmt_start pushlevel maybe_label_decls decls xstmts '}'
1601 { emit_line_note (input_filename, lineno);
1602 expand_end_bindings (getdecls (), 1, 0);
1603 $$ = poplevel (1, 1, 0);
1604 if (yychar == CONSTANT || yychar == STRING)
1605 pop_momentary_nofree ();
1606 else
1607 pop_momentary (); }
1608 | compstmt_start pushlevel maybe_label_decls error '}'
1609 { emit_line_note (input_filename, lineno);
1610 expand_end_bindings (getdecls (), kept_level_p (), 0);
1611 $$ = poplevel (kept_level_p (), 0, 0);
1612 if (yychar == CONSTANT || yychar == STRING)
1613 pop_momentary_nofree ();
1614 else
1615 pop_momentary (); }
1616 | compstmt_start pushlevel maybe_label_decls stmts '}'
1617 { emit_line_note (input_filename, lineno);
1618 expand_end_bindings (getdecls (), kept_level_p (), 0);
1619 $$ = poplevel (kept_level_p (), 0, 0);
1620 if (yychar == CONSTANT || yychar == STRING)
1621 pop_momentary_nofree ();
1622 else
1623 pop_momentary (); }
1626 /* Value is number of statements counted as of the closeparen. */
1627 simple_if:
1628 if_prefix lineno_labeled_stmt
1629 /* Make sure c_expand_end_cond is run once
1630 for each call to c_expand_start_cond.
1631 Otherwise a crash is likely. */
1632 | if_prefix error
1635 if_prefix:
1636 IF '(' expr ')'
1637 { emit_line_note ($<filename>-1, $<lineno>0);
1638 c_expand_start_cond (truthvalue_conversion ($3), 0,
1639 compstmt_count);
1640 $<itype>$ = stmt_count;
1641 if_stmt_file = $<filename>-1;
1642 if_stmt_line = $<lineno>0;
1643 position_after_white_space (); }
1646 /* This is a subroutine of stmt.
1647 It is used twice, once for valid DO statements
1648 and once for catching errors in parsing the end test. */
1649 do_stmt_start:
1651 { stmt_count++;
1652 compstmt_count++;
1653 emit_line_note ($<filename>-1, $<lineno>0);
1654 /* See comment in `while' alternative, above. */
1655 emit_nop ();
1656 expand_start_loop_continue_elsewhere (1);
1657 position_after_white_space (); }
1658 lineno_labeled_stmt WHILE
1659 { expand_loop_continue_here (); }
1662 save_filename:
1663 { $$ = input_filename; }
1666 save_lineno:
1667 { $$ = lineno; }
1670 lineno_labeled_stmt:
1671 save_filename save_lineno stmt
1673 /* | save_filename save_lineno error
1676 | save_filename save_lineno label lineno_labeled_stmt
1680 lineno_stmt_or_label:
1681 save_filename save_lineno stmt_or_label
1682 { $$ = $3; }
1685 stmt_or_label:
1686 stmt
1687 { $$ = 0; }
1688 | label
1689 { $$ = 1; }
1692 /* Parse a single real statement, not including any labels. */
1693 stmt:
1694 compstmt
1695 { stmt_count++; }
1696 | all_iter_stmt
1697 | expr ';'
1698 { stmt_count++;
1699 emit_line_note ($<filename>-1, $<lineno>0);
1700 /* It appears that this should not be done--that a non-lvalue array
1701 shouldn't get an error if the value isn't used.
1702 Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1703 if it appears as a top-level expression,
1704 but says nothing about non-lvalue arrays. */
1705 #if 0
1706 /* Call default_conversion to get an error
1707 on referring to a register array if pedantic. */
1708 if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1709 || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1710 $1 = default_conversion ($1);
1711 #endif
1712 iterator_expand ($1);
1713 clear_momentary (); }
1714 | simple_if ELSE
1715 { c_expand_start_else ();
1716 $<itype>1 = stmt_count;
1717 position_after_white_space (); }
1718 lineno_labeled_stmt
1719 { c_expand_end_cond ();
1720 if (extra_warnings && stmt_count == $<itype>1)
1721 warning ("empty body in an else-statement"); }
1722 | simple_if %prec IF
1723 { c_expand_end_cond ();
1724 /* This warning is here instead of in simple_if, because we
1725 do not want a warning if an empty if is followed by an
1726 else statement. Increment stmt_count so we don't
1727 give a second error if this is a nested `if'. */
1728 if (extra_warnings && stmt_count++ == $<itype>1)
1729 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1730 "empty body in an if-statement"); }
1731 /* Make sure c_expand_end_cond is run once
1732 for each call to c_expand_start_cond.
1733 Otherwise a crash is likely. */
1734 | simple_if ELSE error
1735 { c_expand_end_cond (); }
1736 | WHILE
1737 { stmt_count++;
1738 emit_line_note ($<filename>-1, $<lineno>0);
1739 /* The emit_nop used to come before emit_line_note,
1740 but that made the nop seem like part of the preceding line.
1741 And that was confusing when the preceding line was
1742 inside of an if statement and was not really executed.
1743 I think it ought to work to put the nop after the line number.
1744 We will see. --rms, July 15, 1991. */
1745 emit_nop (); }
1746 '(' expr ')'
1747 { /* Don't start the loop till we have succeeded
1748 in parsing the end test. This is to make sure
1749 that we end every loop we start. */
1750 expand_start_loop (1);
1751 emit_line_note (input_filename, lineno);
1752 expand_exit_loop_if_false (NULL_PTR,
1753 truthvalue_conversion ($4));
1754 position_after_white_space (); }
1755 lineno_labeled_stmt
1756 { expand_end_loop (); }
1757 | do_stmt_start
1758 '(' expr ')' ';'
1759 { emit_line_note (input_filename, lineno);
1760 expand_exit_loop_if_false (NULL_PTR,
1761 truthvalue_conversion ($3));
1762 expand_end_loop ();
1763 clear_momentary (); }
1764 /* This rule is needed to make sure we end every loop we start. */
1765 | do_stmt_start error
1766 { expand_end_loop ();
1767 clear_momentary (); }
1768 | FOR
1769 '(' xexpr ';'
1770 { stmt_count++;
1771 emit_line_note ($<filename>-1, $<lineno>0);
1772 /* See comment in `while' alternative, above. */
1773 emit_nop ();
1774 if ($3) c_expand_expr_stmt ($3);
1775 /* Next step is to call expand_start_loop_continue_elsewhere,
1776 but wait till after we parse the entire for (...).
1777 Otherwise, invalid input might cause us to call that
1778 fn without calling expand_end_loop. */
1780 xexpr ';'
1781 /* Can't emit now; wait till after expand_start_loop... */
1782 { $<lineno>7 = lineno;
1783 $<filename>$ = input_filename; }
1784 xexpr ')'
1786 /* Start the loop. Doing this after parsing
1787 all the expressions ensures we will end the loop. */
1788 expand_start_loop_continue_elsewhere (1);
1789 /* Emit the end-test, with a line number. */
1790 emit_line_note ($<filename>8, $<lineno>7);
1791 if ($6)
1792 expand_exit_loop_if_false (NULL_PTR,
1793 truthvalue_conversion ($6));
1794 /* Don't let the tree nodes for $9 be discarded by
1795 clear_momentary during the parsing of the next stmt. */
1796 push_momentary ();
1797 $<lineno>7 = lineno;
1798 $<filename>8 = input_filename;
1799 position_after_white_space (); }
1800 lineno_labeled_stmt
1801 { /* Emit the increment expression, with a line number. */
1802 emit_line_note ($<filename>8, $<lineno>7);
1803 expand_loop_continue_here ();
1804 if ($9)
1805 c_expand_expr_stmt ($9);
1806 if (yychar == CONSTANT || yychar == STRING)
1807 pop_momentary_nofree ();
1808 else
1809 pop_momentary ();
1810 expand_end_loop (); }
1811 | SWITCH '(' expr ')'
1812 { stmt_count++;
1813 emit_line_note ($<filename>-1, $<lineno>0);
1814 c_expand_start_case ($3);
1815 /* Don't let the tree nodes for $3 be discarded by
1816 clear_momentary during the parsing of the next stmt. */
1817 push_momentary ();
1818 position_after_white_space (); }
1819 lineno_labeled_stmt
1820 { expand_end_case ($3);
1821 if (yychar == CONSTANT || yychar == STRING)
1822 pop_momentary_nofree ();
1823 else
1824 pop_momentary (); }
1825 | BREAK ';'
1826 { stmt_count++;
1827 emit_line_note ($<filename>-1, $<lineno>0);
1828 if ( ! expand_exit_something ())
1829 error ("break statement not within loop or switch"); }
1830 | CONTINUE ';'
1831 { stmt_count++;
1832 emit_line_note ($<filename>-1, $<lineno>0);
1833 if (! expand_continue_loop (NULL_PTR))
1834 error ("continue statement not within a loop"); }
1835 | RETURN ';'
1836 { stmt_count++;
1837 emit_line_note ($<filename>-1, $<lineno>0);
1838 c_expand_return (NULL_TREE); }
1839 | RETURN expr ';'
1840 { stmt_count++;
1841 emit_line_note ($<filename>-1, $<lineno>0);
1842 c_expand_return ($2); }
1843 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
1844 { stmt_count++;
1845 emit_line_note ($<filename>-1, $<lineno>0);
1846 STRIP_NOPS ($4);
1847 if ((TREE_CODE ($4) == ADDR_EXPR
1848 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
1849 || TREE_CODE ($4) == STRING_CST)
1850 expand_asm ($4);
1851 else
1852 error ("argument of `asm' is not a constant string"); }
1853 /* This is the case with just output operands. */
1854 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
1855 { stmt_count++;
1856 emit_line_note ($<filename>-1, $<lineno>0);
1857 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
1858 $2 == ridpointers[(int)RID_VOLATILE],
1859 input_filename, lineno); }
1860 /* This is the case with input operands as well. */
1861 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
1862 { stmt_count++;
1863 emit_line_note ($<filename>-1, $<lineno>0);
1864 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
1865 $2 == ridpointers[(int)RID_VOLATILE],
1866 input_filename, lineno); }
1867 /* This is the case with clobbered registers as well. */
1868 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
1869 asm_operands ':' asm_clobbers ')' ';'
1870 { stmt_count++;
1871 emit_line_note ($<filename>-1, $<lineno>0);
1872 c_expand_asm_operands ($4, $6, $8, $10,
1873 $2 == ridpointers[(int)RID_VOLATILE],
1874 input_filename, lineno); }
1875 | GOTO identifier ';'
1876 { tree decl;
1877 stmt_count++;
1878 emit_line_note ($<filename>-1, $<lineno>0);
1879 decl = lookup_label ($2);
1880 if (decl != 0)
1882 TREE_USED (decl) = 1;
1883 expand_goto (decl);
1886 | GOTO '*' expr ';'
1887 { if (pedantic)
1888 pedwarn ("ANSI C forbids `goto *expr;'");
1889 stmt_count++;
1890 emit_line_note ($<filename>-1, $<lineno>0);
1891 expand_computed_goto (convert (ptr_type_node, $3)); }
1892 | ';'
1895 all_iter_stmt:
1896 all_iter_stmt_simple
1897 /* | all_iter_stmt_with_decl */
1900 all_iter_stmt_simple:
1901 FOR '(' primary ')'
1903 /* The value returned by this action is */
1904 /* 1 if everything is OK */
1905 /* 0 in case of error or already bound iterator */
1907 $<itype>$ = 0;
1908 if (TREE_CODE ($3) != VAR_DECL)
1909 error ("invalid `for (ITERATOR)' syntax");
1910 else if (! ITERATOR_P ($3))
1911 error ("`%s' is not an iterator",
1912 IDENTIFIER_POINTER (DECL_NAME ($3)));
1913 else if (ITERATOR_BOUND_P ($3))
1914 error ("`for (%s)' inside expansion of same iterator",
1915 IDENTIFIER_POINTER (DECL_NAME ($3)));
1916 else
1918 $<itype>$ = 1;
1919 iterator_for_loop_start ($3);
1922 lineno_labeled_stmt
1924 if ($<itype>5)
1925 iterator_for_loop_end ($3);
1928 /* This really should allow any kind of declaration,
1929 for generality. Fix it before turning it back on.
1931 all_iter_stmt_with_decl:
1932 FOR '(' ITERATOR pushlevel setspecs iterator_spec ')'
1934 */ /* The value returned by this action is */
1935 /* 1 if everything is OK */
1936 /* 0 in case of error or already bound iterator */
1938 iterator_for_loop_start ($6);
1940 lineno_labeled_stmt
1942 iterator_for_loop_end ($6);
1943 emit_line_note (input_filename, lineno);
1944 expand_end_bindings (getdecls (), 1, 0);
1945 $<ttype>$ = poplevel (1, 1, 0);
1946 if (yychar == CONSTANT || yychar == STRING)
1947 pop_momentary_nofree ();
1948 else
1949 pop_momentary ();
1953 /* Any kind of label, including jump labels and case labels.
1954 ANSI C accepts labels only before statements, but we allow them
1955 also at the end of a compound statement. */
1957 label: CASE expr_no_commas ':'
1958 { register tree value = check_case_value ($2);
1959 register tree label
1960 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1962 stmt_count++;
1964 if (value != error_mark_node)
1966 tree duplicate;
1967 int success;
1969 if (pedantic && ! INTEGRAL_TYPE_P (TREE_TYPE (value)))
1970 pedwarn ("label must have integral type in ANSI C");
1972 success = pushcase (value, convert_and_check,
1973 label, &duplicate);
1975 if (success == 1)
1976 error ("case label not within a switch statement");
1977 else if (success == 2)
1979 error ("duplicate case value");
1980 error_with_decl (duplicate, "this is the first entry for that value");
1982 else if (success == 3)
1983 warning ("case value out of range");
1984 else if (success == 5)
1985 error ("case label within scope of cleanup or variable array");
1987 position_after_white_space (); }
1988 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
1989 { register tree value1 = check_case_value ($2);
1990 register tree value2 = check_case_value ($4);
1991 register tree label
1992 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1994 if (pedantic)
1995 pedwarn ("ANSI C forbids case ranges");
1996 stmt_count++;
1998 if (value1 != error_mark_node && value2 != error_mark_node)
2000 tree duplicate;
2001 int success = pushcase_range (value1, value2,
2002 convert_and_check, label,
2003 &duplicate);
2004 if (success == 1)
2005 error ("case label not within a switch statement");
2006 else if (success == 2)
2008 error ("duplicate case value");
2009 error_with_decl (duplicate, "this is the first entry for that value");
2011 else if (success == 3)
2012 warning ("case value out of range");
2013 else if (success == 4)
2014 warning ("empty case range");
2015 else if (success == 5)
2016 error ("case label within scope of cleanup or variable array");
2018 position_after_white_space (); }
2019 | DEFAULT ':'
2021 tree duplicate;
2022 register tree label
2023 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2024 int success = pushcase (NULL_TREE, 0, label, &duplicate);
2025 stmt_count++;
2026 if (success == 1)
2027 error ("default label not within a switch statement");
2028 else if (success == 2)
2030 error ("multiple default labels in one switch");
2031 error_with_decl (duplicate, "this is the first default label");
2033 position_after_white_space (); }
2034 | identifier ':' maybe_attribute
2035 { tree label = define_label (input_filename, lineno, $1);
2036 stmt_count++;
2037 emit_nop ();
2038 if (label)
2040 expand_label (label);
2041 decl_attributes (label, $3, NULL_TREE);
2043 position_after_white_space (); }
2046 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
2048 maybe_type_qual:
2049 /* empty */
2050 { emit_line_note (input_filename, lineno);
2051 $$ = NULL_TREE; }
2052 | TYPE_QUAL
2053 { emit_line_note (input_filename, lineno); }
2056 xexpr:
2057 /* empty */
2058 { $$ = NULL_TREE; }
2059 | expr
2062 /* These are the operands other than the first string and colon
2063 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2064 asm_operands: /* empty */
2065 { $$ = NULL_TREE; }
2066 | nonnull_asm_operands
2069 nonnull_asm_operands:
2070 asm_operand
2071 | nonnull_asm_operands ',' asm_operand
2072 { $$ = chainon ($1, $3); }
2075 asm_operand:
2076 STRING '(' expr ')'
2077 { $$ = build_tree_list ($1, $3); }
2080 asm_clobbers:
2081 string
2082 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
2083 | asm_clobbers ',' string
2084 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
2087 /* This is what appears inside the parens in a function declarator.
2088 Its value is a list of ..._TYPE nodes. */
2089 parmlist:
2090 { pushlevel (0);
2091 clear_parm_order ();
2092 declare_parm_level (0); }
2093 parmlist_1
2094 { $$ = $2;
2095 parmlist_tags_warning ();
2096 poplevel (0, 0, 0); }
2099 parmlist_1:
2100 parmlist_2 ')'
2101 | parms ';'
2102 { tree parm;
2103 if (pedantic)
2104 pedwarn ("ANSI C forbids forward parameter declarations");
2105 /* Mark the forward decls as such. */
2106 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2107 TREE_ASM_WRITTEN (parm) = 1;
2108 clear_parm_order (); }
2109 parmlist_1
2110 { $$ = $4; }
2111 | error ')'
2112 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2115 /* This is what appears inside the parens in a function declarator.
2116 Is value is represented in the format that grokdeclarator expects. */
2117 parmlist_2: /* empty */
2118 { $$ = get_parm_info (0); }
2119 | ELLIPSIS
2120 { $$ = get_parm_info (0);
2121 /* Gcc used to allow this as an extension. However, it does
2122 not work for all targets, and thus has been disabled.
2123 Also, since func (...) and func () are indistinguishable,
2124 it caused problems with the code in expand_builtin which
2125 tries to verify that BUILT_IN_NEXT_ARG is being used
2126 correctly. */
2127 error ("ANSI C requires a named argument before `...'");
2129 | parms
2130 { $$ = get_parm_info (1); }
2131 | parms ',' ELLIPSIS
2132 { $$ = get_parm_info (0); }
2135 parms:
2136 parm
2137 { push_parm_decl ($1); }
2138 | parms ',' parm
2139 { push_parm_decl ($3); }
2142 /* A single parameter declaration or parameter type name,
2143 as found in a parmlist. */
2144 parm:
2145 typed_declspecs setspecs parm_declarator maybe_attribute
2146 { $$ = build_tree_list (build_tree_list (current_declspecs,
2147 $3),
2148 build_tree_list (prefix_attributes,
2149 $4));
2150 current_declspecs = TREE_VALUE (declspec_stack);
2151 prefix_attributes = TREE_PURPOSE (declspec_stack);
2152 declspec_stack = TREE_CHAIN (declspec_stack);
2153 resume_momentary ($2); }
2154 | typed_declspecs setspecs notype_declarator maybe_attribute
2155 { $$ = build_tree_list (build_tree_list (current_declspecs,
2156 $3),
2157 build_tree_list (prefix_attributes,
2158 $4));
2159 current_declspecs = TREE_VALUE (declspec_stack);
2160 prefix_attributes = TREE_PURPOSE (declspec_stack);
2161 declspec_stack = TREE_CHAIN (declspec_stack);
2162 resume_momentary ($2); }
2163 | typed_declspecs setspecs absdcl maybe_attribute
2164 { $$ = build_tree_list (build_tree_list (current_declspecs,
2165 $3),
2166 build_tree_list (prefix_attributes,
2167 $4));
2168 current_declspecs = TREE_VALUE (declspec_stack);
2169 prefix_attributes = TREE_PURPOSE (declspec_stack);
2170 declspec_stack = TREE_CHAIN (declspec_stack);
2171 resume_momentary ($2); }
2172 | declmods setspecs notype_declarator maybe_attribute
2173 { $$ = build_tree_list (build_tree_list (current_declspecs,
2174 $3),
2175 build_tree_list (prefix_attributes,
2176 $4));
2177 current_declspecs = TREE_VALUE (declspec_stack);
2178 prefix_attributes = TREE_PURPOSE (declspec_stack);
2179 declspec_stack = TREE_CHAIN (declspec_stack);
2180 resume_momentary ($2); }
2182 | declmods setspecs absdcl maybe_attribute
2183 { $$ = build_tree_list (build_tree_list (current_declspecs,
2184 $3),
2185 build_tree_list (prefix_attributes,
2186 $4));
2187 current_declspecs = TREE_VALUE (declspec_stack);
2188 prefix_attributes = TREE_PURPOSE (declspec_stack);
2189 declspec_stack = TREE_CHAIN (declspec_stack);
2190 resume_momentary ($2); }
2193 /* This is used in a function definition
2194 where either a parmlist or an identifier list is ok.
2195 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2196 parmlist_or_identifiers:
2197 { pushlevel (0);
2198 clear_parm_order ();
2199 declare_parm_level (1); }
2200 parmlist_or_identifiers_1
2201 { $$ = $2;
2202 parmlist_tags_warning ();
2203 poplevel (0, 0, 0); }
2206 parmlist_or_identifiers_1:
2207 parmlist_1
2208 | identifiers ')'
2209 { tree t;
2210 for (t = $1; t; t = TREE_CHAIN (t))
2211 if (TREE_VALUE (t) == NULL_TREE)
2212 error ("`...' in old-style identifier list");
2213 $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2216 /* A nonempty list of identifiers. */
2217 identifiers:
2218 IDENTIFIER
2219 { $$ = build_tree_list (NULL_TREE, $1); }
2220 | identifiers ',' IDENTIFIER
2221 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2224 /* A nonempty list of identifiers, including typenames. */
2225 identifiers_or_typenames:
2226 identifier
2227 { $$ = build_tree_list (NULL_TREE, $1); }
2228 | identifiers_or_typenames ',' identifier
2229 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2232 extension:
2233 EXTENSION
2234 { $<itype>$ = pedantic;
2235 pedantic = 0; }