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