regmove.c (optimize_reg_copy_1): Undo Aug 18 change.
[gcc.git] / gcc / c-parse.y
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.
4
5 This file is part of GNU CC.
6
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.
11
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.
16
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. */
21
22 /* This file defines the grammar of C and that of Objective C.
23 ifobjc ... end ifobjc conditionals contain code for Objective C only.
24 ifc ... end ifc conditionals contain code for C only.
25 Sed commands in Makefile.in are used to convert this file into
26 c-parse.y and into objc-parse.y. */
27
28 /* To whomever it may concern: I have heard that such a thing was once
29 written by AT&T, but I have never seen it. */
30
31 %expect 46
32
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.
35
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.) */
54
55
56 %{
57 #include "config.h"
58 #include "system.h"
59 #include <setjmp.h>
60
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"
68
69 #ifdef MULTIBYTE_CHARS
70 #include <locale.h>
71 #endif
72
73
74 /* Since parsers are distinct for each language, put the language string
75 definition here. */
76 char *language_string = "GNU C";
77
78 /* Like YYERROR but do call yyerror. */
79 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
80
81 /* Cause the `yydebug' variable to be defined. */
82 #define YYDEBUG 1
83 %}
84
85 %start program
86
87 %union {long itype; tree ttype; enum tree_code code;
88 char *filename; int lineno; int ends_in_label; }
89
90 /* All identifiers that are not reserved words
91 and are not declared typedefs in the current block */
92 %token IDENTIFIER
93
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
98
99 /* Reserved words that specify storage class.
100 yylval contains an IDENTIFIER_NODE which indicates which one. */
101 %token SCSPEC
102
103 /* Reserved words that specify type.
104 yylval contains an IDENTIFIER_NODE which indicates which one. */
105 %token TYPESPEC
106
107 /* Reserved words that qualify type: "const", "volatile", or "restrict".
108 yylval contains an IDENTIFIER_NODE which indicates which one. */
109 %token TYPE_QUAL
110
111 /* Character or numeric constants.
112 yylval is the node for the constant. */
113 %token CONSTANT
114
115 /* String constants in raw form.
116 yylval is a STRING_CST node. */
117 %token STRING
118
119 /* "...", used for functions with variable arglists. */
120 %token ELLIPSIS
121
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
128
129 /* Add precedence rules to solve dangling else s/r conflict */
130 %nonassoc IF
131 %nonassoc ELSE
132
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. */
136
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 '.' '(' '['
152
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
157
158 /* Objective-C string constants in raw form.
159 yylval is an OBJC_STRING_CST node. */
160 %token OBJC_STRING
161
162
163 %type <code> unop
164
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
178
179 %type <ttype> compstmt
180
181 %type <ttype> declarator
182 %type <ttype> notype_declarator after_type_declarator
183 %type <ttype> parm_declarator
184
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
191
192 %type <ttype> parmlist parmlist_1 parmlist_2
193 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
194 %type <ttype> identifiers_or_typenames
195
196 %type <itype> setspecs
197
198 %type <ends_in_label> lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
199
200 %type <filename> save_filename
201 %type <lineno> save_lineno
202 \f
203 \f
204 %{
205 /* Number of statements (loosely speaking) and compound statements
206 seen so far. */
207 static int stmt_count;
208 static int compstmt_count;
209
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;
214
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;
218
219 /* Stack of saved values of current_declspecs and prefix_attributes. */
220 static tree declspec_stack;
221
222 /* 1 if we explained undeclared var errors. */
223 static int undeclared_variable_notice;
224
225
226 /* Tell yyparse how to print a token's value, if yydebug is set. */
227
228 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
229 extern void yyprint PROTO ((FILE *, int, YYSTYPE));
230 %}
231 \f
232 %%
233 program: /* empty */
234 { if (pedantic)
235 pedwarn ("ANSI C forbids an empty source file");
236 finish_file ();
237 }
238 | extdefs
239 {
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 ();
245 }
246 ;
247
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. */
251
252 extdefs:
253 {$<ttype>$ = NULL_TREE; } extdef
254 | extdefs {$<ttype>$ = NULL_TREE; } extdef
255 ;
256
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; }
270 ;
271
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");
278
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"); }
302 ;
303 \f
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); }
359 ;
360
361 identifier:
362 IDENTIFIER
363 | TYPENAME
364 ;
365
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; }
380 ;
381
382 expr: nonnull_exprlist
383 { $$ = build_compound_expr ($1); }
384 ;
385
386 exprlist:
387 /* empty */
388 { $$ = NULL_TREE; }
389 | nonnull_exprlist
390 ;
391
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)); }
397 ;
398
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
418 {
419 TREE_USED (label) = 1;
420 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
421 TREE_CONSTANT ($$) = 1;
422 }
423 }
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
432 {
433 if (pedantic)
434 pedwarn ("ANSI C forbids `&...'");
435 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
436 $$ = build_unary_op (ADDR_EXPR, $$, 0);
437 } }
438 */
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); }
458 ;
459
460 sizeof:
461 SIZEOF { skip_evaluation++; }
462 ;
463
464 alignof:
465 ALIGNOF { skip_evaluation++; }
466 ;
467
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 ();
482
483 if (pedantic && ! flag_isoc9x)
484 pedwarn ("ANSI C forbids constructor expressions");
485 if (TYPE_NAME (type) != 0)
486 {
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)));
491 }
492 else
493 name = "";
494 $$ = result;
495 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
496 {
497 int failure = complete_array_type (type, $$, 1);
498 if (failure)
499 abort ();
500 }
501 }
502 ;
503
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 { $$ = build_modify_expr ($1, NOP_EXPR, $3);
563 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
564 | expr_no_commas ASSIGN expr_no_commas
565 { $$ = build_modify_expr ($1, $2, $3);
566 /* This inhibits warnings in truthvalue_conversion. */
567 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); }
568 ;
569
570 primary:
571 IDENTIFIER
572 {
573 $$ = lastiddecl;
574 if (!$$ || $$ == error_mark_node)
575 {
576 if (yychar == YYEMPTY)
577 yychar = YYLEX;
578 if (yychar == '(')
579 {
580 {
581 /* Ordinary implicit function declaration. */
582 $$ = implicitly_declare ($1);
583 assemble_external ($$);
584 TREE_USED ($$) = 1;
585 }
586 }
587 else if (current_function_decl == 0)
588 {
589 error ("`%s' undeclared here (not in a function)",
590 IDENTIFIER_POINTER ($1));
591 $$ = error_mark_node;
592 }
593 else
594 {
595 {
596 if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
597 || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
598 {
599 error ("`%s' undeclared (first use in this function)",
600 IDENTIFIER_POINTER ($1));
601
602 if (! undeclared_variable_notice)
603 {
604 error ("(Each undeclared identifier is reported only once");
605 error ("for each function it appears in.)");
606 undeclared_variable_notice = 1;
607 }
608 }
609 $$ = error_mark_node;
610 /* Prevent repeated error messages. */
611 IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
612 IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
613 }
614 }
615 }
616 else if (TREE_TYPE ($$) == error_mark_node)
617 $$ = error_mark_node;
618 else if (C_DECL_ANTICIPATED ($$))
619 {
620 /* The first time we see a build-in function used,
621 if it has not been declared. */
622 C_DECL_ANTICIPATED ($$) = 0;
623 if (yychar == YYEMPTY)
624 yychar = YYLEX;
625 if (yychar == '(')
626 {
627 /* Omit the implicit declaration we
628 would ordinarily do, so we don't lose
629 the actual built in type.
630 But print a diagnostic for the mismatch. */
631 if (TREE_CODE ($$) != FUNCTION_DECL)
632 error ("`%s' implicitly declared as function",
633 IDENTIFIER_POINTER (DECL_NAME ($$)));
634 else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
635 != TYPE_MODE (integer_type_node))
636 && (TREE_TYPE (TREE_TYPE ($$))
637 != void_type_node))
638 pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
639 IDENTIFIER_POINTER (DECL_NAME ($$)));
640 /* If it really returns void, change that to int. */
641 if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
642 TREE_TYPE ($$)
643 = build_function_type (integer_type_node,
644 TYPE_ARG_TYPES (TREE_TYPE ($$)));
645 }
646 else
647 pedwarn ("built-in function `%s' used without declaration",
648 IDENTIFIER_POINTER (DECL_NAME ($$)));
649
650 /* Do what we would ordinarily do when a fn is used. */
651 assemble_external ($$);
652 TREE_USED ($$) = 1;
653 }
654 else
655 {
656 assemble_external ($$);
657 TREE_USED ($$) = 1;
658 }
659
660 if (TREE_CODE ($$) == CONST_DECL)
661 {
662 $$ = DECL_INITIAL ($$);
663 /* This is to prevent an enum whose value is 0
664 from being considered a null pointer constant. */
665 $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
666 TREE_CONSTANT ($$) = 1;
667 }
668 }
669 | CONSTANT
670 | string
671 { $$ = combine_strings ($1); }
672 | '(' expr ')'
673 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
674 if (class == 'e' || class == '1'
675 || class == '2' || class == '<')
676 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
677 $$ = $2; }
678 | '(' error ')'
679 { $$ = error_mark_node; }
680 | '('
681 { if (current_function_decl == 0)
682 {
683 error ("braced-group within expression allowed only inside a function");
684 YYERROR;
685 }
686 /* We must force a BLOCK for this level
687 so that, if it is not expanded later,
688 there is a way to turn off the entire subtree of blocks
689 that are contained in it. */
690 keep_next_level ();
691 push_iterator_stack ();
692 push_label_level ();
693 $<ttype>$ = expand_start_stmt_expr (); }
694 compstmt ')'
695 { tree rtl_exp;
696 if (pedantic)
697 pedwarn ("ANSI C forbids braced-groups within expressions");
698 pop_iterator_stack ();
699 pop_label_level ();
700 rtl_exp = expand_end_stmt_expr ($<ttype>2);
701 /* The statements have side effects, so the group does. */
702 TREE_SIDE_EFFECTS (rtl_exp) = 1;
703
704 if (TREE_CODE ($3) == BLOCK)
705 {
706 /* Make a BIND_EXPR for the BLOCK already made. */
707 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
708 NULL_TREE, rtl_exp, $3);
709 /* Remove the block from the tree at this point.
710 It gets put back at the proper place
711 when the BIND_EXPR is expanded. */
712 delete_block ($3);
713 }
714 else
715 $$ = $3;
716 }
717 | primary '(' exprlist ')' %prec '.'
718 { $$ = build_function_call ($1, $3); }
719 | primary '[' expr ']' %prec '.'
720 { $$ = build_array_ref ($1, $3); }
721 | primary '.' identifier
722 {
723 $$ = build_component_ref ($1, $3);
724 }
725 | primary POINTSAT identifier
726 {
727 tree expr = build_indirect_ref ($1, "->");
728
729 $$ = build_component_ref (expr, $3);
730 }
731 | primary PLUSPLUS
732 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
733 | primary MINUSMINUS
734 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
735 ;
736
737 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
738 string:
739 STRING
740 | string STRING
741 { $$ = chainon ($1, $2); }
742 ;
743
744
745 old_style_parm_decls:
746 /* empty */
747 | datadecls
748 | datadecls ELLIPSIS
749 /* ... is used here to indicate a varargs function. */
750 { c_mark_varargs ();
751 if (pedantic)
752 pedwarn ("ANSI C does not permit use of `varargs.h'"); }
753 ;
754
755 /* The following are analogous to lineno_decl, decls and decl
756 except that they do not allow nested functions.
757 They are used for old-style parm decls. */
758 lineno_datadecl:
759 save_filename save_lineno datadecl
760 { }
761 ;
762
763 datadecls:
764 lineno_datadecl
765 | errstmt
766 | datadecls lineno_datadecl
767 | lineno_datadecl errstmt
768 ;
769
770 /* We don't allow prefix attributes here because they cause reduce/reduce
771 conflicts: we can't know whether we're parsing a function decl with
772 attribute suffix, or function defn with attribute prefix on first old
773 style parm. */
774 datadecl:
775 typed_declspecs_no_prefix_attr setspecs initdecls ';'
776 { current_declspecs = TREE_VALUE (declspec_stack);
777 prefix_attributes = TREE_PURPOSE (declspec_stack);
778 declspec_stack = TREE_CHAIN (declspec_stack);
779 resume_momentary ($2); }
780 | declmods_no_prefix_attr setspecs notype_initdecls ';'
781 { current_declspecs = TREE_VALUE (declspec_stack);
782 prefix_attributes = TREE_PURPOSE (declspec_stack);
783 declspec_stack = TREE_CHAIN (declspec_stack);
784 resume_momentary ($2); }
785 | typed_declspecs_no_prefix_attr ';'
786 { shadow_tag_warned ($1, 1);
787 pedwarn ("empty declaration"); }
788 | declmods_no_prefix_attr ';'
789 { pedwarn ("empty declaration"); }
790 ;
791
792 /* This combination which saves a lineno before a decl
793 is the normal thing to use, rather than decl itself.
794 This is to avoid shift/reduce conflicts in contexts
795 where statement labels are allowed. */
796 lineno_decl:
797 save_filename save_lineno decl
798 { }
799 ;
800
801 decls:
802 lineno_decl
803 | errstmt
804 | decls lineno_decl
805 | lineno_decl errstmt
806 ;
807
808 /* records the type and storage class specs to use for processing
809 the declarators that follow.
810 Maintains a stack of outer-level values of current_declspecs,
811 for the sake of parm declarations nested in function declarators. */
812 setspecs: /* empty */
813 { $$ = suspend_momentary ();
814 pending_xref_error ();
815 declspec_stack = tree_cons (prefix_attributes,
816 current_declspecs,
817 declspec_stack);
818 split_specs_attrs ($<ttype>0,
819 &current_declspecs, &prefix_attributes); }
820 ;
821
822 /* ??? Yuck. See after_type_declarator. */
823 setattrs: /* empty */
824 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
825 ;
826
827 decl:
828 typed_declspecs setspecs initdecls ';'
829 { current_declspecs = TREE_VALUE (declspec_stack);
830 prefix_attributes = TREE_PURPOSE (declspec_stack);
831 declspec_stack = TREE_CHAIN (declspec_stack);
832 resume_momentary ($2); }
833 | declmods setspecs notype_initdecls ';'
834 { current_declspecs = TREE_VALUE (declspec_stack);
835 prefix_attributes = TREE_PURPOSE (declspec_stack);
836 declspec_stack = TREE_CHAIN (declspec_stack);
837 resume_momentary ($2); }
838 | typed_declspecs setspecs nested_function
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_nested_function
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 ';'
849 { shadow_tag ($1); }
850 | declmods ';'
851 { pedwarn ("empty declaration"); }
852 | extension decl
853 { pedantic = $<itype>1; }
854 ;
855
856 /* Declspecs which contain at least one type specifier or typedef name.
857 (Just `const' or `volatile' is not enough.)
858 A typedef'd name following these is taken as a name to be declared.
859 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
860
861 typed_declspecs:
862 typespec reserved_declspecs
863 { $$ = tree_cons (NULL_TREE, $1, $2); }
864 | declmods typespec reserved_declspecs
865 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
866 ;
867
868 reserved_declspecs: /* empty */
869 { $$ = NULL_TREE; }
870 | reserved_declspecs typespecqual_reserved
871 { $$ = tree_cons (NULL_TREE, $2, $1); }
872 | reserved_declspecs SCSPEC
873 { if (extra_warnings)
874 warning ("`%s' is not at beginning of declaration",
875 IDENTIFIER_POINTER ($2));
876 $$ = tree_cons (NULL_TREE, $2, $1); }
877 | reserved_declspecs attributes
878 { $$ = tree_cons ($2, NULL_TREE, $1); }
879 ;
880
881 typed_declspecs_no_prefix_attr:
882 typespec reserved_declspecs_no_prefix_attr
883 { $$ = tree_cons (NULL_TREE, $1, $2); }
884 | declmods_no_prefix_attr typespec reserved_declspecs_no_prefix_attr
885 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
886 ;
887
888 reserved_declspecs_no_prefix_attr:
889 /* empty */
890 { $$ = NULL_TREE; }
891 | reserved_declspecs_no_prefix_attr typespecqual_reserved
892 { $$ = tree_cons (NULL_TREE, $2, $1); }
893 | reserved_declspecs_no_prefix_attr SCSPEC
894 { if (extra_warnings)
895 warning ("`%s' is not at beginning of declaration",
896 IDENTIFIER_POINTER ($2));
897 $$ = tree_cons (NULL_TREE, $2, $1); }
898 ;
899
900 /* List of just storage classes, type modifiers, and prefix attributes.
901 A declaration can start with just this, but then it cannot be used
902 to redeclare a typedef-name.
903 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
904
905 declmods:
906 declmods_no_prefix_attr
907 { $$ = $1; }
908 | attributes
909 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
910 | declmods declmods_no_prefix_attr
911 { $$ = chainon ($2, $1); }
912 | declmods attributes
913 { $$ = tree_cons ($2, NULL_TREE, $1); }
914 ;
915
916 declmods_no_prefix_attr:
917 TYPE_QUAL
918 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
919 TREE_STATIC ($$) = 1; }
920 | SCSPEC
921 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
922 | declmods_no_prefix_attr TYPE_QUAL
923 { $$ = tree_cons (NULL_TREE, $2, $1);
924 TREE_STATIC ($$) = 1; }
925 | declmods_no_prefix_attr SCSPEC
926 { if (extra_warnings && TREE_STATIC ($1))
927 warning ("`%s' is not at beginning of declaration",
928 IDENTIFIER_POINTER ($2));
929 $$ = tree_cons (NULL_TREE, $2, $1);
930 TREE_STATIC ($$) = TREE_STATIC ($1); }
931 ;
932
933
934 /* Used instead of declspecs where storage classes are not allowed
935 (that is, for typenames and structure components).
936 Don't accept a typedef-name if anything but a modifier precedes it. */
937
938 typed_typespecs:
939 typespec reserved_typespecquals
940 { $$ = tree_cons (NULL_TREE, $1, $2); }
941 | nonempty_type_quals typespec reserved_typespecquals
942 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
943 ;
944
945 reserved_typespecquals: /* empty */
946 { $$ = NULL_TREE; }
947 | reserved_typespecquals typespecqual_reserved
948 { $$ = tree_cons (NULL_TREE, $2, $1); }
949 ;
950
951 /* A typespec (but not a type qualifier).
952 Once we have seen one of these in a declaration,
953 if a typedef name appears then it is being redeclared. */
954
955 typespec: TYPESPEC
956 | structsp
957 | TYPENAME
958 { /* For a typedef name, record the meaning, not the name.
959 In case of `foo foo, bar;'. */
960 $$ = lookup_name ($1); }
961 | TYPEOF '(' expr ')'
962 { $$ = TREE_TYPE ($3); }
963 | TYPEOF '(' typename ')'
964 { $$ = groktypename ($3); }
965 ;
966
967 /* A typespec that is a reserved word, or a type qualifier. */
968
969 typespecqual_reserved: TYPESPEC
970 | TYPE_QUAL
971 | structsp
972 ;
973
974 initdecls:
975 initdcl
976 | initdecls ',' initdcl
977 ;
978
979 notype_initdecls:
980 notype_initdcl
981 | notype_initdecls ',' initdcl
982 ;
983
984 maybeasm:
985 /* empty */
986 { $$ = NULL_TREE; }
987 | ASM_KEYWORD '(' string ')'
988 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
989 $$ = $3;
990 }
991 ;
992
993 initdcl:
994 declarator maybeasm maybe_attribute '='
995 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
996 $3, prefix_attributes);
997 start_init ($<ttype>$, $2, global_bindings_p ()); }
998 init
999 /* Note how the declaration of the variable is in effect while its init is parsed! */
1000 { finish_init ();
1001 finish_decl ($<ttype>5, $6, $2); }
1002 | declarator maybeasm maybe_attribute
1003 { tree d = start_decl ($1, current_declspecs, 0,
1004 $3, prefix_attributes);
1005 finish_decl (d, NULL_TREE, $2);
1006 }
1007 ;
1008
1009 notype_initdcl:
1010 notype_declarator maybeasm maybe_attribute '='
1011 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1012 $3, prefix_attributes);
1013 start_init ($<ttype>$, $2, global_bindings_p ()); }
1014 init
1015 /* Note how the declaration of the variable is in effect while its init is parsed! */
1016 { finish_init ();
1017 decl_attributes ($<ttype>5, $3, prefix_attributes);
1018 finish_decl ($<ttype>5, $6, $2); }
1019 | notype_declarator maybeasm maybe_attribute
1020 { tree d = start_decl ($1, current_declspecs, 0,
1021 $3, prefix_attributes);
1022 finish_decl (d, NULL_TREE, $2); }
1023 ;
1024 /* the * rules are dummies to accept the Apollo extended syntax
1025 so that the header files compile. */
1026 maybe_attribute:
1027 /* empty */
1028 { $$ = NULL_TREE; }
1029 | attributes
1030 { $$ = $1; }
1031 ;
1032
1033 attributes:
1034 attribute
1035 { $$ = $1; }
1036 | attributes attribute
1037 { $$ = chainon ($1, $2); }
1038 ;
1039
1040 attribute:
1041 ATTRIBUTE '(' '(' attribute_list ')' ')'
1042 { $$ = $4; }
1043 ;
1044
1045 attribute_list:
1046 attrib
1047 { $$ = $1; }
1048 | attribute_list ',' attrib
1049 { $$ = chainon ($1, $3); }
1050 ;
1051
1052 attrib:
1053 /* empty */
1054 { $$ = NULL_TREE; }
1055 | any_word
1056 { $$ = build_tree_list ($1, NULL_TREE); }
1057 | any_word '(' IDENTIFIER ')'
1058 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1059 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1060 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1061 | any_word '(' exprlist ')'
1062 { $$ = build_tree_list ($1, $3); }
1063 ;
1064
1065 /* This still leaves out most reserved keywords,
1066 shouldn't we include them? */
1067
1068 any_word:
1069 identifier
1070 | SCSPEC
1071 | TYPESPEC
1072 | TYPE_QUAL
1073 ;
1074 \f
1075 /* Initializers. `init' is the entry point. */
1076
1077 init:
1078 expr_no_commas
1079 | '{'
1080 { really_start_incremental_init (NULL_TREE);
1081 /* Note that the call to clear_momentary
1082 is in process_init_element. */
1083 push_momentary (); }
1084 initlist_maybe_comma '}'
1085 { $$ = pop_init_level (0);
1086 if ($$ == error_mark_node
1087 && ! (yychar == STRING || yychar == CONSTANT))
1088 pop_momentary ();
1089 else
1090 pop_momentary_nofree (); }
1091
1092 | error
1093 { $$ = error_mark_node; }
1094 ;
1095
1096 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1097 initlist_maybe_comma:
1098 /* empty */
1099 { if (pedantic)
1100 pedwarn ("ANSI C forbids empty initializer braces"); }
1101 | initlist1 maybecomma
1102 ;
1103
1104 initlist1:
1105 initelt
1106 | initlist1 ',' initelt
1107 ;
1108
1109 /* `initelt' is a single element of an initializer.
1110 It may use braces. */
1111 initelt:
1112 designator_list '=' initval
1113 | designator initval
1114 | identifier ':'
1115 { set_init_label ($1); }
1116 initval
1117 | initval
1118 ;
1119
1120 initval:
1121 '{'
1122 { push_init_level (0); }
1123 initlist_maybe_comma '}'
1124 { process_init_element (pop_init_level (0)); }
1125 | expr_no_commas
1126 { process_init_element ($1); }
1127 | error
1128 ;
1129
1130 designator_list:
1131 designator
1132 | designator_list designator
1133 ;
1134
1135 designator:
1136 '.' identifier
1137 { set_init_label ($2); }
1138 /* These are for labeled elements. The syntax for an array element
1139 initializer conflicts with the syntax for an Objective-C message,
1140 so don't include these productions in the Objective-C grammar. */
1141 | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
1142 { set_init_index ($2, $4); }
1143 | '[' expr_no_commas ']'
1144 { set_init_index ($2, NULL_TREE); }
1145 ;
1146 \f
1147 nested_function:
1148 declarator
1149 { push_c_function_context ();
1150 if (! start_function (current_declspecs, $1,
1151 prefix_attributes, NULL_TREE, 1))
1152 {
1153 pop_c_function_context ();
1154 YYERROR1;
1155 }
1156 reinit_parse_for_function (); }
1157 old_style_parm_decls
1158 { store_parm_decls (); }
1159 /* This used to use compstmt_or_error.
1160 That caused a bug with input `f(g) int g {}',
1161 where the use of YYERROR1 above caused an error
1162 which then was handled by compstmt_or_error.
1163 There followed a repeated execution of that same rule,
1164 which called YYERROR1 again, and so on. */
1165 compstmt
1166 { finish_function (1);
1167 pop_c_function_context (); }
1168 ;
1169
1170 notype_nested_function:
1171 notype_declarator
1172 { push_c_function_context ();
1173 if (! start_function (current_declspecs, $1,
1174 prefix_attributes, NULL_TREE, 1))
1175 {
1176 pop_c_function_context ();
1177 YYERROR1;
1178 }
1179 reinit_parse_for_function (); }
1180 old_style_parm_decls
1181 { store_parm_decls (); }
1182 /* This used to use compstmt_or_error.
1183 That caused a bug with input `f(g) int g {}',
1184 where the use of YYERROR1 above caused an error
1185 which then was handled by compstmt_or_error.
1186 There followed a repeated execution of that same rule,
1187 which called YYERROR1 again, and so on. */
1188 compstmt
1189 { finish_function (1);
1190 pop_c_function_context (); }
1191 ;
1192
1193 /* Any kind of declarator (thus, all declarators allowed
1194 after an explicit typespec). */
1195
1196 declarator:
1197 after_type_declarator
1198 | notype_declarator
1199 ;
1200
1201 /* A declarator that is allowed only after an explicit typespec. */
1202
1203 after_type_declarator:
1204 '(' after_type_declarator ')'
1205 { $$ = $2; }
1206 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1207 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1208 /* | after_type_declarator '(' error ')' %prec '.'
1209 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1210 poplevel (0, 0, 0); } */
1211 | after_type_declarator '[' expr ']' %prec '.'
1212 { $$ = build_nt (ARRAY_REF, $1, $3); }
1213 | after_type_declarator '[' ']' %prec '.'
1214 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1215 | '*' type_quals after_type_declarator %prec UNARY
1216 { $$ = make_pointer_declarator ($2, $3); }
1217 /* ??? Yuck. setattrs is a quick hack. We can't use
1218 prefix_attributes because $1 only applies to this
1219 declarator. We assume setspecs has already been done.
1220 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1221 attributes could be recognized here or in `attributes'). */
1222 | attributes setattrs after_type_declarator
1223 { $$ = $3; }
1224 | TYPENAME
1225 ;
1226
1227 /* Kinds of declarator that can appear in a parameter list
1228 in addition to notype_declarator. This is like after_type_declarator
1229 but does not allow a typedef name in parentheses as an identifier
1230 (because it would conflict with a function with that typedef as arg). */
1231
1232 parm_declarator:
1233 parm_declarator '(' parmlist_or_identifiers %prec '.'
1234 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1235 /* | parm_declarator '(' error ')' %prec '.'
1236 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1237 poplevel (0, 0, 0); } */
1238 | parm_declarator '[' '*' ']' %prec '.'
1239 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1240 if (! flag_isoc9x)
1241 error ("`[*]' in parameter declaration only allowed in ISO C 9x");
1242 }
1243 | parm_declarator '[' expr ']' %prec '.'
1244 { $$ = build_nt (ARRAY_REF, $1, $3); }
1245 | parm_declarator '[' ']' %prec '.'
1246 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1247 | '*' type_quals parm_declarator %prec UNARY
1248 { $$ = make_pointer_declarator ($2, $3); }
1249 /* ??? Yuck. setattrs is a quick hack. We can't use
1250 prefix_attributes because $1 only applies to this
1251 declarator. We assume setspecs has already been done.
1252 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1253 attributes could be recognized here or in `attributes'). */
1254 | attributes setattrs parm_declarator
1255 { $$ = $3; }
1256 | TYPENAME
1257 ;
1258
1259 /* A declarator allowed whether or not there has been
1260 an explicit typespec. These cannot redeclare a typedef-name. */
1261
1262 notype_declarator:
1263 notype_declarator '(' parmlist_or_identifiers %prec '.'
1264 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1265 /* | notype_declarator '(' error ')' %prec '.'
1266 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1267 poplevel (0, 0, 0); } */
1268 | '(' notype_declarator ')'
1269 { $$ = $2; }
1270 | '*' type_quals notype_declarator %prec UNARY
1271 { $$ = make_pointer_declarator ($2, $3); }
1272 | notype_declarator '[' '*' ']' %prec '.'
1273 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1274 if (! flag_isoc9x)
1275 error ("`[*]' in parameter declaration only allowed in ISO C 9x");
1276 }
1277 | notype_declarator '[' expr ']' %prec '.'
1278 { $$ = build_nt (ARRAY_REF, $1, $3); }
1279 | notype_declarator '[' ']' %prec '.'
1280 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1281 /* ??? Yuck. setattrs is a quick hack. We can't use
1282 prefix_attributes because $1 only applies to this
1283 declarator. We assume setspecs has already been done.
1284 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1285 attributes could be recognized here or in `attributes'). */
1286 | attributes setattrs notype_declarator
1287 { $$ = $3; }
1288 | IDENTIFIER
1289 ;
1290
1291 struct_head:
1292 STRUCT
1293 { $$ = NULL_TREE; }
1294 | STRUCT attributes
1295 { $$ = $2; }
1296 ;
1297
1298 union_head:
1299 UNION
1300 { $$ = NULL_TREE; }
1301 | UNION attributes
1302 { $$ = $2; }
1303 ;
1304
1305 enum_head:
1306 ENUM
1307 { $$ = NULL_TREE; }
1308 | ENUM attributes
1309 { $$ = $2; }
1310 ;
1311
1312 structsp:
1313 struct_head identifier '{'
1314 { $$ = start_struct (RECORD_TYPE, $2);
1315 /* Start scope of tag before parsing components. */
1316 }
1317 component_decl_list '}' maybe_attribute
1318 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1319 | struct_head '{' component_decl_list '}' maybe_attribute
1320 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1321 $3, chainon ($1, $5));
1322 }
1323 | struct_head identifier
1324 { $$ = xref_tag (RECORD_TYPE, $2); }
1325 | union_head identifier '{'
1326 { $$ = start_struct (UNION_TYPE, $2); }
1327 component_decl_list '}' maybe_attribute
1328 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1329 | union_head '{' component_decl_list '}' maybe_attribute
1330 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1331 $3, chainon ($1, $5));
1332 }
1333 | union_head identifier
1334 { $$ = xref_tag (UNION_TYPE, $2); }
1335 | enum_head identifier '{'
1336 { $<itype>3 = suspend_momentary ();
1337 $$ = start_enum ($2); }
1338 enumlist maybecomma_warn '}' maybe_attribute
1339 { $$= finish_enum ($<ttype>4, nreverse ($5), chainon ($1, $8));
1340 resume_momentary ($<itype>3); }
1341 | enum_head '{'
1342 { $<itype>2 = suspend_momentary ();
1343 $$ = start_enum (NULL_TREE); }
1344 enumlist maybecomma_warn '}' maybe_attribute
1345 { $$= finish_enum ($<ttype>3, nreverse ($4), chainon ($1, $7));
1346 resume_momentary ($<itype>2); }
1347 | enum_head identifier
1348 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1349 ;
1350
1351 maybecomma:
1352 /* empty */
1353 | ','
1354 ;
1355
1356 maybecomma_warn:
1357 /* empty */
1358 | ','
1359 { if (pedantic && ! flag_isoc9x)
1360 pedwarn ("comma at end of enumerator list"); }
1361 ;
1362
1363 component_decl_list:
1364 component_decl_list2
1365 { $$ = $1; }
1366 | component_decl_list2 component_decl
1367 { $$ = chainon ($1, $2);
1368 pedwarn ("no semicolon at end of struct or union"); }
1369 ;
1370
1371 component_decl_list2: /* empty */
1372 { $$ = NULL_TREE; }
1373 | component_decl_list2 component_decl ';'
1374 { $$ = chainon ($1, $2); }
1375 | component_decl_list2 ';'
1376 { if (pedantic)
1377 pedwarn ("extra semicolon in struct or union specified"); }
1378 ;
1379
1380 /* There is a shift-reduce conflict here, because `components' may
1381 start with a `typename'. It happens that shifting (the default resolution)
1382 does the right thing, because it treats the `typename' as part of
1383 a `typed_typespecs'.
1384
1385 It is possible that this same technique would allow the distinction
1386 between `notype_initdecls' and `initdecls' to be eliminated.
1387 But I am being cautious and not trying it. */
1388
1389 component_decl:
1390 typed_typespecs setspecs components
1391 { $$ = $3;
1392 current_declspecs = TREE_VALUE (declspec_stack);
1393 prefix_attributes = TREE_PURPOSE (declspec_stack);
1394 declspec_stack = TREE_CHAIN (declspec_stack);
1395 resume_momentary ($2); }
1396 | typed_typespecs
1397 { if (pedantic)
1398 pedwarn ("ANSI C forbids member declarations with no members");
1399 shadow_tag($1);
1400 $$ = NULL_TREE; }
1401 | nonempty_type_quals setspecs components
1402 { $$ = $3;
1403 current_declspecs = TREE_VALUE (declspec_stack);
1404 prefix_attributes = TREE_PURPOSE (declspec_stack);
1405 declspec_stack = TREE_CHAIN (declspec_stack);
1406 resume_momentary ($2); }
1407 | nonempty_type_quals
1408 { if (pedantic)
1409 pedwarn ("ANSI C forbids member declarations with no members");
1410 shadow_tag($1);
1411 $$ = NULL_TREE; }
1412 | error
1413 { $$ = NULL_TREE; }
1414 | extension component_decl
1415 { $$ = $2;
1416 pedantic = $<itype>1; }
1417 ;
1418
1419 components:
1420 component_declarator
1421 | components ',' component_declarator
1422 { $$ = chainon ($1, $3); }
1423 ;
1424
1425 component_declarator:
1426 save_filename save_lineno declarator maybe_attribute
1427 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1428 decl_attributes ($$, $4, prefix_attributes); }
1429 | save_filename save_lineno
1430 declarator ':' expr_no_commas maybe_attribute
1431 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1432 decl_attributes ($$, $6, prefix_attributes); }
1433 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1434 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1435 decl_attributes ($$, $5, prefix_attributes); }
1436 ;
1437
1438 /* We chain the enumerators in reverse order.
1439 They are put in forward order where enumlist is used.
1440 (The order used to be significant, but no longer is so.
1441 However, we still maintain the order, just to be clean.) */
1442
1443 enumlist:
1444 enumerator
1445 | enumlist ',' enumerator
1446 { if ($1 == error_mark_node)
1447 $$ = $1;
1448 else
1449 $$ = chainon ($3, $1); }
1450 | error
1451 { $$ = error_mark_node; }
1452 ;
1453
1454
1455 enumerator:
1456 identifier
1457 { $$ = build_enumerator ($1, NULL_TREE); }
1458 | identifier '=' expr_no_commas
1459 { $$ = build_enumerator ($1, $3); }
1460 ;
1461
1462 typename:
1463 typed_typespecs absdcl
1464 { $$ = build_tree_list ($1, $2); }
1465 | nonempty_type_quals absdcl
1466 { $$ = build_tree_list ($1, $2); }
1467 ;
1468
1469 absdcl: /* an absolute declarator */
1470 /* empty */
1471 { $$ = NULL_TREE; }
1472 | absdcl1
1473 ;
1474
1475 nonempty_type_quals:
1476 TYPE_QUAL
1477 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1478 | nonempty_type_quals TYPE_QUAL
1479 { $$ = tree_cons (NULL_TREE, $2, $1); }
1480 ;
1481
1482 type_quals:
1483 /* empty */
1484 { $$ = NULL_TREE; }
1485 | type_quals TYPE_QUAL
1486 { $$ = tree_cons (NULL_TREE, $2, $1); }
1487 ;
1488
1489 absdcl1: /* a nonempty absolute declarator */
1490 '(' absdcl1 ')'
1491 { $$ = $2; }
1492 /* `(typedef)1' is `int'. */
1493 | '*' type_quals absdcl1 %prec UNARY
1494 { $$ = make_pointer_declarator ($2, $3); }
1495 | '*' type_quals %prec UNARY
1496 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1497 | absdcl1 '(' parmlist %prec '.'
1498 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1499 | absdcl1 '[' expr ']' %prec '.'
1500 { $$ = build_nt (ARRAY_REF, $1, $3); }
1501 | absdcl1 '[' ']' %prec '.'
1502 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1503 | '(' parmlist %prec '.'
1504 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1505 | '[' expr ']' %prec '.'
1506 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1507 | '[' ']' %prec '.'
1508 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1509 /* ??? It appears we have to support attributes here, however
1510 using prefix_attributes is wrong. */
1511 ;
1512
1513 /* at least one statement, the first of which parses without error. */
1514 /* stmts is used only after decls, so an invalid first statement
1515 is actually regarded as an invalid decl and part of the decls. */
1516
1517 stmts:
1518 lineno_stmt_or_labels
1519 {
1520 if (pedantic && $1)
1521 pedwarn ("ANSI C forbids label at end of compound statement");
1522 }
1523 ;
1524
1525 lineno_stmt_or_labels:
1526 lineno_stmt_or_label
1527 | lineno_stmt_or_labels lineno_stmt_or_label
1528 { $$ = $2; }
1529 | lineno_stmt_or_labels errstmt
1530 { $$ = 0; }
1531 ;
1532
1533 xstmts:
1534 /* empty */
1535 | stmts
1536 ;
1537
1538 errstmt: error ';'
1539 ;
1540
1541 pushlevel: /* empty */
1542 { emit_line_note (input_filename, lineno);
1543 pushlevel (0);
1544 clear_last_expr ();
1545 push_momentary ();
1546 expand_start_bindings (0);
1547 }
1548 ;
1549
1550 /* Read zero or more forward-declarations for labels
1551 that nested functions can jump to. */
1552 maybe_label_decls:
1553 /* empty */
1554 | label_decls
1555 { if (pedantic)
1556 pedwarn ("ANSI C forbids label declarations"); }
1557 ;
1558
1559 label_decls:
1560 label_decl
1561 | label_decls label_decl
1562 ;
1563
1564 label_decl:
1565 LABEL identifiers_or_typenames ';'
1566 { tree link;
1567 for (link = $2; link; link = TREE_CHAIN (link))
1568 {
1569 tree label = shadow_label (TREE_VALUE (link));
1570 C_DECLARED_LABEL_FLAG (label) = 1;
1571 declare_nonlocal_label (label);
1572 }
1573 }
1574 ;
1575
1576 /* This is the body of a function definition.
1577 It causes syntax errors to ignore to the next openbrace. */
1578 compstmt_or_error:
1579 compstmt
1580 {}
1581 | error compstmt
1582 ;
1583
1584 compstmt_start: '{' { compstmt_count++; }
1585
1586 compstmt: compstmt_start '}'
1587 { $$ = convert (void_type_node, integer_zero_node); }
1588 | compstmt_start pushlevel maybe_label_decls decls xstmts '}'
1589 { emit_line_note (input_filename, lineno);
1590 expand_end_bindings (getdecls (), 1, 0);
1591 $$ = poplevel (1, 1, 0);
1592 if (yychar == CONSTANT || yychar == STRING)
1593 pop_momentary_nofree ();
1594 else
1595 pop_momentary (); }
1596 | compstmt_start pushlevel maybe_label_decls error '}'
1597 { emit_line_note (input_filename, lineno);
1598 expand_end_bindings (getdecls (), kept_level_p (), 0);
1599 $$ = poplevel (kept_level_p (), 0, 0);
1600 if (yychar == CONSTANT || yychar == STRING)
1601 pop_momentary_nofree ();
1602 else
1603 pop_momentary (); }
1604 | compstmt_start pushlevel maybe_label_decls stmts '}'
1605 { emit_line_note (input_filename, lineno);
1606 expand_end_bindings (getdecls (), kept_level_p (), 0);
1607 $$ = poplevel (kept_level_p (), 0, 0);
1608 if (yychar == CONSTANT || yychar == STRING)
1609 pop_momentary_nofree ();
1610 else
1611 pop_momentary (); }
1612 ;
1613
1614 /* Value is number of statements counted as of the closeparen. */
1615 simple_if:
1616 if_prefix lineno_labeled_stmt
1617 /* Make sure c_expand_end_cond is run once
1618 for each call to c_expand_start_cond.
1619 Otherwise a crash is likely. */
1620 | if_prefix error
1621 ;
1622
1623 if_prefix:
1624 IF '(' expr ')'
1625 { emit_line_note ($<filename>-1, $<lineno>0);
1626 c_expand_start_cond (truthvalue_conversion ($3), 0,
1627 compstmt_count);
1628 $<itype>$ = stmt_count;
1629 if_stmt_file = $<filename>-1;
1630 if_stmt_line = $<lineno>0;
1631 position_after_white_space (); }
1632 ;
1633
1634 /* This is a subroutine of stmt.
1635 It is used twice, once for valid DO statements
1636 and once for catching errors in parsing the end test. */
1637 do_stmt_start:
1638 DO
1639 { stmt_count++;
1640 compstmt_count++;
1641 emit_line_note ($<filename>-1, $<lineno>0);
1642 /* See comment in `while' alternative, above. */
1643 emit_nop ();
1644 expand_start_loop_continue_elsewhere (1);
1645 position_after_white_space (); }
1646 lineno_labeled_stmt WHILE
1647 { expand_loop_continue_here (); }
1648 ;
1649
1650 save_filename:
1651 { $$ = input_filename; }
1652 ;
1653
1654 save_lineno:
1655 { $$ = lineno; }
1656 ;
1657
1658 lineno_labeled_stmt:
1659 save_filename save_lineno stmt
1660 { }
1661 /* | save_filename save_lineno error
1662 { }
1663 */
1664 | save_filename save_lineno label lineno_labeled_stmt
1665 { }
1666 ;
1667
1668 lineno_stmt_or_label:
1669 save_filename save_lineno stmt_or_label
1670 { $$ = $3; }
1671 ;
1672
1673 stmt_or_label:
1674 stmt
1675 { $$ = 0; }
1676 | label
1677 { $$ = 1; }
1678 ;
1679
1680 /* Parse a single real statement, not including any labels. */
1681 stmt:
1682 compstmt
1683 { stmt_count++; }
1684 | all_iter_stmt
1685 | expr ';'
1686 { stmt_count++;
1687 emit_line_note ($<filename>-1, $<lineno>0);
1688 /* It appears that this should not be done--that a non-lvalue array
1689 shouldn't get an error if the value isn't used.
1690 Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1691 if it appears as a top-level expression,
1692 but says nothing about non-lvalue arrays. */
1693 #if 0
1694 /* Call default_conversion to get an error
1695 on referring to a register array if pedantic. */
1696 if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1697 || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1698 $1 = default_conversion ($1);
1699 #endif
1700 iterator_expand ($1);
1701 clear_momentary (); }
1702 | simple_if ELSE
1703 { c_expand_start_else ();
1704 $<itype>1 = stmt_count;
1705 position_after_white_space (); }
1706 lineno_labeled_stmt
1707 { c_expand_end_cond ();
1708 if (extra_warnings && stmt_count == $<itype>1)
1709 warning ("empty body in an else-statement"); }
1710 | simple_if %prec IF
1711 { c_expand_end_cond ();
1712 /* This warning is here instead of in simple_if, because we
1713 do not want a warning if an empty if is followed by an
1714 else statement. Increment stmt_count so we don't
1715 give a second error if this is a nested `if'. */
1716 if (extra_warnings && stmt_count++ == $<itype>1)
1717 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1718 "empty body in an if-statement"); }
1719 /* Make sure c_expand_end_cond is run once
1720 for each call to c_expand_start_cond.
1721 Otherwise a crash is likely. */
1722 | simple_if ELSE error
1723 { c_expand_end_cond (); }
1724 | WHILE
1725 { stmt_count++;
1726 emit_line_note ($<filename>-1, $<lineno>0);
1727 /* The emit_nop used to come before emit_line_note,
1728 but that made the nop seem like part of the preceding line.
1729 And that was confusing when the preceding line was
1730 inside of an if statement and was not really executed.
1731 I think it ought to work to put the nop after the line number.
1732 We will see. --rms, July 15, 1991. */
1733 emit_nop (); }
1734 '(' expr ')'
1735 { /* Don't start the loop till we have succeeded
1736 in parsing the end test. This is to make sure
1737 that we end every loop we start. */
1738 expand_start_loop (1);
1739 emit_line_note (input_filename, lineno);
1740 expand_exit_loop_if_false (NULL_PTR,
1741 truthvalue_conversion ($4));
1742 position_after_white_space (); }
1743 lineno_labeled_stmt
1744 { expand_end_loop (); }
1745 | do_stmt_start
1746 '(' expr ')' ';'
1747 { emit_line_note (input_filename, lineno);
1748 expand_exit_loop_if_false (NULL_PTR,
1749 truthvalue_conversion ($3));
1750 expand_end_loop ();
1751 clear_momentary (); }
1752 /* This rule is needed to make sure we end every loop we start. */
1753 | do_stmt_start error
1754 { expand_end_loop ();
1755 clear_momentary (); }
1756 | FOR
1757 '(' xexpr ';'
1758 { stmt_count++;
1759 emit_line_note ($<filename>-1, $<lineno>0);
1760 /* See comment in `while' alternative, above. */
1761 emit_nop ();
1762 if ($3) c_expand_expr_stmt ($3);
1763 /* Next step is to call expand_start_loop_continue_elsewhere,
1764 but wait till after we parse the entire for (...).
1765 Otherwise, invalid input might cause us to call that
1766 fn without calling expand_end_loop. */
1767 }
1768 xexpr ';'
1769 /* Can't emit now; wait till after expand_start_loop... */
1770 { $<lineno>7 = lineno;
1771 $<filename>$ = input_filename; }
1772 xexpr ')'
1773 {
1774 /* Start the loop. Doing this after parsing
1775 all the expressions ensures we will end the loop. */
1776 expand_start_loop_continue_elsewhere (1);
1777 /* Emit the end-test, with a line number. */
1778 emit_line_note ($<filename>8, $<lineno>7);
1779 if ($6)
1780 expand_exit_loop_if_false (NULL_PTR,
1781 truthvalue_conversion ($6));
1782 /* Don't let the tree nodes for $9 be discarded by
1783 clear_momentary during the parsing of the next stmt. */
1784 push_momentary ();
1785 $<lineno>7 = lineno;
1786 $<filename>8 = input_filename;
1787 position_after_white_space (); }
1788 lineno_labeled_stmt
1789 { /* Emit the increment expression, with a line number. */
1790 emit_line_note ($<filename>8, $<lineno>7);
1791 expand_loop_continue_here ();
1792 if ($9)
1793 c_expand_expr_stmt ($9);
1794 if (yychar == CONSTANT || yychar == STRING)
1795 pop_momentary_nofree ();
1796 else
1797 pop_momentary ();
1798 expand_end_loop (); }
1799 | SWITCH '(' expr ')'
1800 { stmt_count++;
1801 emit_line_note ($<filename>-1, $<lineno>0);
1802 c_expand_start_case ($3);
1803 /* Don't let the tree nodes for $3 be discarded by
1804 clear_momentary during the parsing of the next stmt. */
1805 push_momentary ();
1806 position_after_white_space (); }
1807 lineno_labeled_stmt
1808 { expand_end_case ($3);
1809 if (yychar == CONSTANT || yychar == STRING)
1810 pop_momentary_nofree ();
1811 else
1812 pop_momentary (); }
1813 | BREAK ';'
1814 { stmt_count++;
1815 emit_line_note ($<filename>-1, $<lineno>0);
1816 if ( ! expand_exit_something ())
1817 error ("break statement not within loop or switch"); }
1818 | CONTINUE ';'
1819 { stmt_count++;
1820 emit_line_note ($<filename>-1, $<lineno>0);
1821 if (! expand_continue_loop (NULL_PTR))
1822 error ("continue statement not within a loop"); }
1823 | RETURN ';'
1824 { stmt_count++;
1825 emit_line_note ($<filename>-1, $<lineno>0);
1826 c_expand_return (NULL_TREE); }
1827 | RETURN expr ';'
1828 { stmt_count++;
1829 emit_line_note ($<filename>-1, $<lineno>0);
1830 c_expand_return ($2); }
1831 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
1832 { stmt_count++;
1833 emit_line_note ($<filename>-1, $<lineno>0);
1834 STRIP_NOPS ($4);
1835 if ((TREE_CODE ($4) == ADDR_EXPR
1836 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
1837 || TREE_CODE ($4) == STRING_CST)
1838 expand_asm ($4);
1839 else
1840 error ("argument of `asm' is not a constant string"); }
1841 /* This is the case with just output operands. */
1842 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
1843 { stmt_count++;
1844 emit_line_note ($<filename>-1, $<lineno>0);
1845 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
1846 $2 == ridpointers[(int)RID_VOLATILE],
1847 input_filename, lineno); }
1848 /* This is the case with input operands as well. */
1849 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
1850 { stmt_count++;
1851 emit_line_note ($<filename>-1, $<lineno>0);
1852 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
1853 $2 == ridpointers[(int)RID_VOLATILE],
1854 input_filename, lineno); }
1855 /* This is the case with clobbered registers as well. */
1856 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
1857 asm_operands ':' asm_clobbers ')' ';'
1858 { stmt_count++;
1859 emit_line_note ($<filename>-1, $<lineno>0);
1860 c_expand_asm_operands ($4, $6, $8, $10,
1861 $2 == ridpointers[(int)RID_VOLATILE],
1862 input_filename, lineno); }
1863 | GOTO identifier ';'
1864 { tree decl;
1865 stmt_count++;
1866 emit_line_note ($<filename>-1, $<lineno>0);
1867 decl = lookup_label ($2);
1868 if (decl != 0)
1869 {
1870 TREE_USED (decl) = 1;
1871 expand_goto (decl);
1872 }
1873 }
1874 | GOTO '*' expr ';'
1875 { if (pedantic)
1876 pedwarn ("ANSI C forbids `goto *expr;'");
1877 stmt_count++;
1878 emit_line_note ($<filename>-1, $<lineno>0);
1879 expand_computed_goto (convert (ptr_type_node, $3)); }
1880 | ';'
1881 ;
1882
1883 all_iter_stmt:
1884 all_iter_stmt_simple
1885 /* | all_iter_stmt_with_decl */
1886 ;
1887
1888 all_iter_stmt_simple:
1889 FOR '(' primary ')'
1890 {
1891 /* The value returned by this action is */
1892 /* 1 if everything is OK */
1893 /* 0 in case of error or already bound iterator */
1894
1895 $<itype>$ = 0;
1896 if (TREE_CODE ($3) != VAR_DECL)
1897 error ("invalid `for (ITERATOR)' syntax");
1898 else if (! ITERATOR_P ($3))
1899 error ("`%s' is not an iterator",
1900 IDENTIFIER_POINTER (DECL_NAME ($3)));
1901 else if (ITERATOR_BOUND_P ($3))
1902 error ("`for (%s)' inside expansion of same iterator",
1903 IDENTIFIER_POINTER (DECL_NAME ($3)));
1904 else
1905 {
1906 $<itype>$ = 1;
1907 iterator_for_loop_start ($3);
1908 }
1909 }
1910 lineno_labeled_stmt
1911 {
1912 if ($<itype>5)
1913 iterator_for_loop_end ($3);
1914 }
1915
1916 /* This really should allow any kind of declaration,
1917 for generality. Fix it before turning it back on.
1918
1919 all_iter_stmt_with_decl:
1920 FOR '(' ITERATOR pushlevel setspecs iterator_spec ')'
1921 {
1922 */ /* The value returned by this action is */
1923 /* 1 if everything is OK */
1924 /* 0 in case of error or already bound iterator */
1925 /*
1926 iterator_for_loop_start ($6);
1927 }
1928 lineno_labeled_stmt
1929 {
1930 iterator_for_loop_end ($6);
1931 emit_line_note (input_filename, lineno);
1932 expand_end_bindings (getdecls (), 1, 0);
1933 $<ttype>$ = poplevel (1, 1, 0);
1934 if (yychar == CONSTANT || yychar == STRING)
1935 pop_momentary_nofree ();
1936 else
1937 pop_momentary ();
1938 }
1939 */
1940
1941 /* Any kind of label, including jump labels and case labels.
1942 ANSI C accepts labels only before statements, but we allow them
1943 also at the end of a compound statement. */
1944
1945 label: CASE expr_no_commas ':'
1946 { register tree value = check_case_value ($2);
1947 register tree label
1948 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1949
1950 stmt_count++;
1951
1952 if (value != error_mark_node)
1953 {
1954 tree duplicate;
1955 int success;
1956
1957 if (pedantic && ! INTEGRAL_TYPE_P (TREE_TYPE (value)))
1958 pedwarn ("label must have integral type in ANSI C");
1959
1960 success = pushcase (value, convert_and_check,
1961 label, &duplicate);
1962
1963 if (success == 1)
1964 error ("case label not within a switch statement");
1965 else if (success == 2)
1966 {
1967 error ("duplicate case value");
1968 error_with_decl (duplicate, "this is the first entry for that value");
1969 }
1970 else if (success == 3)
1971 warning ("case value out of range");
1972 else if (success == 5)
1973 error ("case label within scope of cleanup or variable array");
1974 }
1975 position_after_white_space (); }
1976 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
1977 { register tree value1 = check_case_value ($2);
1978 register tree value2 = check_case_value ($4);
1979 register tree label
1980 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1981
1982 if (pedantic)
1983 pedwarn ("ANSI C forbids case ranges");
1984 stmt_count++;
1985
1986 if (value1 != error_mark_node && value2 != error_mark_node)
1987 {
1988 tree duplicate;
1989 int success = pushcase_range (value1, value2,
1990 convert_and_check, label,
1991 &duplicate);
1992 if (success == 1)
1993 error ("case label not within a switch statement");
1994 else if (success == 2)
1995 {
1996 error ("duplicate case value");
1997 error_with_decl (duplicate, "this is the first entry for that value");
1998 }
1999 else if (success == 3)
2000 warning ("case value out of range");
2001 else if (success == 4)
2002 warning ("empty case range");
2003 else if (success == 5)
2004 error ("case label within scope of cleanup or variable array");
2005 }
2006 position_after_white_space (); }
2007 | DEFAULT ':'
2008 {
2009 tree duplicate;
2010 register tree label
2011 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2012 int success = pushcase (NULL_TREE, 0, label, &duplicate);
2013 stmt_count++;
2014 if (success == 1)
2015 error ("default label not within a switch statement");
2016 else if (success == 2)
2017 {
2018 error ("multiple default labels in one switch");
2019 error_with_decl (duplicate, "this is the first default label");
2020 }
2021 position_after_white_space (); }
2022 | identifier ':' maybe_attribute
2023 { tree label = define_label (input_filename, lineno, $1);
2024 stmt_count++;
2025 emit_nop ();
2026 if (label)
2027 {
2028 expand_label (label);
2029 decl_attributes (label, $3, NULL_TREE);
2030 }
2031 position_after_white_space (); }
2032 ;
2033
2034 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
2035
2036 maybe_type_qual:
2037 /* empty */
2038 { emit_line_note (input_filename, lineno);
2039 $$ = NULL_TREE; }
2040 | TYPE_QUAL
2041 { emit_line_note (input_filename, lineno); }
2042 ;
2043
2044 xexpr:
2045 /* empty */
2046 { $$ = NULL_TREE; }
2047 | expr
2048 ;
2049
2050 /* These are the operands other than the first string and colon
2051 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2052 asm_operands: /* empty */
2053 { $$ = NULL_TREE; }
2054 | nonnull_asm_operands
2055 ;
2056
2057 nonnull_asm_operands:
2058 asm_operand
2059 | nonnull_asm_operands ',' asm_operand
2060 { $$ = chainon ($1, $3); }
2061 ;
2062
2063 asm_operand:
2064 STRING '(' expr ')'
2065 { $$ = build_tree_list ($1, $3); }
2066 ;
2067
2068 asm_clobbers:
2069 string
2070 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
2071 | asm_clobbers ',' string
2072 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
2073 ;
2074 \f
2075 /* This is what appears inside the parens in a function declarator.
2076 Its value is a list of ..._TYPE nodes. */
2077 parmlist:
2078 { pushlevel (0);
2079 clear_parm_order ();
2080 declare_parm_level (0); }
2081 parmlist_1
2082 { $$ = $2;
2083 parmlist_tags_warning ();
2084 poplevel (0, 0, 0); }
2085 ;
2086
2087 parmlist_1:
2088 parmlist_2 ')'
2089 | parms ';'
2090 { tree parm;
2091 if (pedantic)
2092 pedwarn ("ANSI C forbids forward parameter declarations");
2093 /* Mark the forward decls as such. */
2094 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2095 TREE_ASM_WRITTEN (parm) = 1;
2096 clear_parm_order (); }
2097 parmlist_1
2098 { $$ = $4; }
2099 | error ')'
2100 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2101 ;
2102
2103 /* This is what appears inside the parens in a function declarator.
2104 Is value is represented in the format that grokdeclarator expects. */
2105 parmlist_2: /* empty */
2106 { $$ = get_parm_info (0); }
2107 | ELLIPSIS
2108 { $$ = get_parm_info (0);
2109 /* Gcc used to allow this as an extension. However, it does
2110 not work for all targets, and thus has been disabled.
2111 Also, since func (...) and func () are indistinguishable,
2112 it caused problems with the code in expand_builtin which
2113 tries to verify that BUILT_IN_NEXT_ARG is being used
2114 correctly. */
2115 error ("ANSI C requires a named argument before `...'");
2116 }
2117 | parms
2118 { $$ = get_parm_info (1); }
2119 | parms ',' ELLIPSIS
2120 { $$ = get_parm_info (0); }
2121 ;
2122
2123 parms:
2124 parm
2125 { push_parm_decl ($1); }
2126 | parms ',' parm
2127 { push_parm_decl ($3); }
2128 ;
2129
2130 /* A single parameter declaration or parameter type name,
2131 as found in a parmlist. */
2132 parm:
2133 typed_declspecs setspecs parm_declarator maybe_attribute
2134 { $$ = build_tree_list (build_tree_list (current_declspecs,
2135 $3),
2136 build_tree_list (prefix_attributes,
2137 $4));
2138 current_declspecs = TREE_VALUE (declspec_stack);
2139 prefix_attributes = TREE_PURPOSE (declspec_stack);
2140 declspec_stack = TREE_CHAIN (declspec_stack);
2141 resume_momentary ($2); }
2142 | typed_declspecs setspecs notype_declarator maybe_attribute
2143 { $$ = build_tree_list (build_tree_list (current_declspecs,
2144 $3),
2145 build_tree_list (prefix_attributes,
2146 $4));
2147 current_declspecs = TREE_VALUE (declspec_stack);
2148 prefix_attributes = TREE_PURPOSE (declspec_stack);
2149 declspec_stack = TREE_CHAIN (declspec_stack);
2150 resume_momentary ($2); }
2151 | typed_declspecs setspecs absdcl maybe_attribute
2152 { $$ = build_tree_list (build_tree_list (current_declspecs,
2153 $3),
2154 build_tree_list (prefix_attributes,
2155 $4));
2156 current_declspecs = TREE_VALUE (declspec_stack);
2157 prefix_attributes = TREE_PURPOSE (declspec_stack);
2158 declspec_stack = TREE_CHAIN (declspec_stack);
2159 resume_momentary ($2); }
2160 | declmods setspecs notype_declarator maybe_attribute
2161 { $$ = build_tree_list (build_tree_list (current_declspecs,
2162 $3),
2163 build_tree_list (prefix_attributes,
2164 $4));
2165 current_declspecs = TREE_VALUE (declspec_stack);
2166 prefix_attributes = TREE_PURPOSE (declspec_stack);
2167 declspec_stack = TREE_CHAIN (declspec_stack);
2168 resume_momentary ($2); }
2169
2170 | declmods setspecs absdcl maybe_attribute
2171 { $$ = build_tree_list (build_tree_list (current_declspecs,
2172 $3),
2173 build_tree_list (prefix_attributes,
2174 $4));
2175 current_declspecs = TREE_VALUE (declspec_stack);
2176 prefix_attributes = TREE_PURPOSE (declspec_stack);
2177 declspec_stack = TREE_CHAIN (declspec_stack);
2178 resume_momentary ($2); }
2179 ;
2180
2181 /* This is used in a function definition
2182 where either a parmlist or an identifier list is ok.
2183 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2184 parmlist_or_identifiers:
2185 { pushlevel (0);
2186 clear_parm_order ();
2187 declare_parm_level (1); }
2188 parmlist_or_identifiers_1
2189 { $$ = $2;
2190 parmlist_tags_warning ();
2191 poplevel (0, 0, 0); }
2192 ;
2193
2194 parmlist_or_identifiers_1:
2195 parmlist_1
2196 | identifiers ')'
2197 { tree t;
2198 for (t = $1; t; t = TREE_CHAIN (t))
2199 if (TREE_VALUE (t) == NULL_TREE)
2200 error ("`...' in old-style identifier list");
2201 $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2202 ;
2203
2204 /* A nonempty list of identifiers. */
2205 identifiers:
2206 IDENTIFIER
2207 { $$ = build_tree_list (NULL_TREE, $1); }
2208 | identifiers ',' IDENTIFIER
2209 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2210 ;
2211
2212 /* A nonempty list of identifiers, including typenames. */
2213 identifiers_or_typenames:
2214 identifier
2215 { $$ = build_tree_list (NULL_TREE, $1); }
2216 | identifiers_or_typenames ',' identifier
2217 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2218 ;
2219
2220 extension:
2221 EXTENSION
2222 { $<itype>$ = pedantic;
2223 pedantic = 0; }
2224 ;
2225 \f
2226 %%