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