1 /*WARNING: This file is automatically generated!*/
2 /* YACC parser for C syntax and for Objective C. -*-c-*-
3 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 1999, 2000 Free Software Foundation, Inc.
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
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. */
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. */
47 #ifdef MULTIBYTE_CHARS
52 /* Since parsers are distinct for each language, put the language string
54 const char * const language_string
= "GNU C";
56 /* Like YYERROR but do call yyerror. */
57 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
59 /* Cause the `yydebug' variable to be defined. */
65 %
union {long itype
; tree ttype
; enum tree_code code
;
66 char *filename
; int lineno
; int ends_in_label
; }
68 /* All identifiers that are not reserved words
69 and are not declared typedefs in the current block */
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. */
77 /* Reserved words that specify storage class.
78 yylval contains an IDENTIFIER_NODE which indicates which one. */
81 /* Reserved words that specify type.
82 yylval contains an IDENTIFIER_NODE which indicates which one. */
85 /* Reserved words that qualify type: "const", "volatile", or "restrict".
86 yylval contains an IDENTIFIER_NODE which indicates which one. */
89 /* Character or numeric constants.
90 yylval is the node for the constant. */
93 /* String constants in raw form.
94 yylval is a STRING_CST node. */
97 /* "...", used for functions with variable arglists. */
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
105 %token REALPART IMAGPART VA_ARG
107 /* Used in c-lex.c for parsing pragmas. */
110 /* Add precedence rules to solve dangling else s/r conflict */
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. */
118 %right
<code
> ASSIGN
'='
119 %right
<code
> '?' ':'
125 %left
<code
> EQCOMPARE
126 %left
<code
> ARITHCOMPARE
127 %left
<code
> LSHIFT RSHIFT
129 %left
<code
> '*' '/' '%'
130 %right
<code
> UNARY PLUSPLUS MINUSMINUS
132 %left
<code
> POINTSAT
'.' '(' '['
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
139 /* Objective-C string constants in raw form.
140 yylval is an OBJC_STRING_CST node. */
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
158 %type
<ttype
> any_word extension
160 %type
<ttype
> compstmt compstmt_nostart compstmt_primary_start
162 %type
<ttype
> declarator
163 %type
<ttype
> notype_declarator after_type_declarator
164 %type
<ttype
> parm_declarator
166 %type
<ttype
> structsp component_decl_list component_decl_list2
167 %type
<ttype
> component_decl components component_declarator
168 %type
<ttype
> enumlist enumerator
169 %type
<ttype
> struct_head union_head enum_head
170 %type
<ttype
> typename absdcl absdcl1 type_quals
171 %type
<ttype
> xexpr parms parm identifiers
173 %type
<ttype
> parmlist parmlist_1 parmlist_2
174 %type
<ttype
> parmlist_or_identifiers parmlist_or_identifiers_1
175 %type
<ttype
> identifiers_or_typenames
177 %type
<itype
> setspecs
179 %type
<ends_in_label
> lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
181 %type
<filename
> save_filename
182 %type
<lineno
> save_lineno
186 /* Number of statements (loosely speaking) and compound statements
188 static int stmt_count
;
189 static int compstmt_count
;
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. */
193 static char *if_stmt_file
;
194 static int if_stmt_line
;
196 /* List of types and structure classes of the current declaration. */
197 static tree current_declspecs
= NULL_TREE
;
198 static tree prefix_attributes
= NULL_TREE
;
200 /* Stack of saved values of current_declspecs and prefix_attributes. */
201 static tree declspec_stack
;
203 /* 1 if we explained undeclared var errors. */
204 static int undeclared_variable_notice
;
206 /* For __extension__, save/restore the warning flags which are
207 controlled by __extension__. */
208 #define SAVE_WARN_FLAGS() \
209 build_int_2
(pedantic |
(warn_pointer_arith
<< 1), 0)
210 #define RESTORE_WARN_FLAGS(tval) \
212 int val
= TREE_INT_CST_LOW
(tval
); \
213 pedantic
= val
& 1; \
214 warn_pointer_arith
= (val
>> 1) & 1; \
218 /* Tell yyparse how to print a token's value, if yydebug is set. */
220 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
221 extern
void yyprint PARAMS
((FILE *, int, YYSTYPE));
223 /* Add GC roots for variables local to this file. */
227 ggc_add_tree_root
(&declspec_stack
, 1);
228 ggc_add_tree_root
(¤t_declspecs
, 1);
229 ggc_add_tree_root
(&prefix_attributes
, 1);
237 pedwarn
("ANSI C forbids an empty source file");
242 /* In case there were missing closebraces,
243 get us back to the global binding level. */
244 while
(! global_bindings_p
())
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. */
255 {$
<ttype
>$
= NULL_TREE
; } extdef
256 | extdefs
{$
<ttype
>$
= NULL_TREE
; } extdef
262 | ASM_KEYWORD
'(' expr
')' ';'
264 if
((TREE_CODE
($3) == ADDR_EXPR
265 && TREE_CODE
(TREE_OPERAND
($3, 0)) == STRING_CST
)
266 || TREE_CODE
($3) == STRING_CST
)
269 error ("argument of `asm' is not a constant string"); }
271 { RESTORE_WARN_FLAGS
($1); }
275 setspecs notype_initdecls
';'
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");
281 current_declspecs
= TREE_VALUE
(declspec_stack
);
282 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
283 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
284 | declmods setspecs notype_initdecls
';'
285 { current_declspecs
= TREE_VALUE
(declspec_stack
);
286 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
287 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
288 | typed_declspecs setspecs initdecls
';'
289 { current_declspecs
= TREE_VALUE
(declspec_stack
);
290 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
291 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
293 { pedwarn
("empty declaration"); }
294 | typed_declspecs
';'
300 pedwarn
("ANSI C does not allow extra `;' outside of a function"); }
304 typed_declspecs setspecs declarator
305 { if
(! start_function
(current_declspecs
, $3,
306 prefix_attributes
, NULL_TREE
))
308 reinit_parse_for_function
(); }
310 { store_parm_decls
(); }
312 { finish_function
(0);
313 current_declspecs
= TREE_VALUE
(declspec_stack
);
314 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
315 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
316 | typed_declspecs setspecs declarator
error
317 { current_declspecs
= TREE_VALUE
(declspec_stack
);
318 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
319 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
320 | declmods setspecs notype_declarator
321 { if
(! start_function
(current_declspecs
, $3,
322 prefix_attributes
, NULL_TREE
))
324 reinit_parse_for_function
(); }
326 { store_parm_decls
(); }
328 { finish_function
(0);
329 current_declspecs
= TREE_VALUE
(declspec_stack
);
330 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
331 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
332 | declmods setspecs notype_declarator
error
333 { current_declspecs
= TREE_VALUE
(declspec_stack
);
334 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
335 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
336 | setspecs notype_declarator
337 { if
(! start_function
(NULL_TREE
, $2,
338 prefix_attributes
, NULL_TREE
))
340 reinit_parse_for_function
(); }
342 { store_parm_decls
(); }
344 { finish_function
(0);
345 current_declspecs
= TREE_VALUE
(declspec_stack
);
346 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
347 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
348 | setspecs notype_declarator
error
349 { current_declspecs
= TREE_VALUE
(declspec_stack
);
350 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
351 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
362 { $$
= NEGATE_EXPR
; }
364 { $$
= CONVERT_EXPR
; }
366 { $$
= PREINCREMENT_EXPR
; }
368 { $$
= PREDECREMENT_EXPR
; }
370 { $$
= BIT_NOT_EXPR
; }
372 { $$
= TRUTH_NOT_EXPR
; }
375 expr: nonnull_exprlist
376 { $$
= build_compound_expr
($1); }
387 { $$
= build_tree_list
(NULL_TREE
, $1); }
388 | nonnull_exprlist
',' expr_no_commas
389 { chainon
($1, build_tree_list
(NULL_TREE
, $3)); }
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
399 RESTORE_WARN_FLAGS
($1); }
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. */
405 { tree label
= lookup_label
($2);
407 pedwarn
("ANSI C forbids `&&'");
409 $$
= null_pointer_node
;
412 TREE_USED
(label
) = 1;
413 $$
= build1
(ADDR_EXPR
, ptr_type_node
, label
);
414 TREE_CONSTANT
($$
) = 1;
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.
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");
427 pedwarn ("ANSI C forbids `&...'");
428 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
429 $$ = build_unary_op (ADDR_EXPR, $$, 0);
432 | sizeof unary_expr %prec UNARY
434 if
(TREE_CODE
($2) == COMPONENT_REF
435 && DECL_C_BIT_FIELD
(TREE_OPERAND
($2, 1)))
436 error ("`sizeof' applied to a bit-field");
437 $$
= c_sizeof
(TREE_TYPE
($2)); }
438 | sizeof
'(' typename
')' %prec HYPERUNARY
440 $$
= c_sizeof
(groktypename
($3)); }
441 | alignof unary_expr %prec UNARY
443 $$
= c_alignof_expr
($2); }
444 | alignof
'(' typename
')' %prec HYPERUNARY
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); }
451 | VA_ARG
'(' expr_no_commas
',' typename
')'
452 { $$
= build_va_arg
($3, groktypename
($5)); }
456 SIZEOF
{ skip_evaluation
++; }
460 ALIGNOF
{ skip_evaluation
++; }
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
474 tree result
= pop_init_level
(0);
478 if
(pedantic
&& ! flag_isoc99
)
479 pedwarn
("ANSI C forbids constructor expressions");
480 if
(TYPE_NAME
(type
) != 0)
482 if
(TREE_CODE
(TYPE_NAME
(type
)) == IDENTIFIER_NODE
)
483 name
= IDENTIFIER_POINTER
(TYPE_NAME
(type
));
485 name
= IDENTIFIER_POINTER
(DECL_NAME
(TYPE_NAME
(type
)));
490 if
(TREE_CODE
(type
) == ARRAY_TYPE
&& TYPE_SIZE
(type
) == 0)
492 int failure
= complete_array_type
(type
, $$
, 1);
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
; }
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
; }
535 { skip_evaluation
-= $1 == boolean_true_node
;
536 $$
= parser_build_binary_op
(TRUTH_ORIF_EXPR
, $1, $4); }
538 { $1 = truthvalue_conversion
(default_conversion
($1));
539 skip_evaluation
+= $1 == boolean_false_node
; }
541 { skip_evaluation
+= (($1 == boolean_true_node
)
542 - ($1 == boolean_false_node
)); }
544 { skip_evaluation
-= $1 == boolean_true_node
;
545 $$
= build_conditional_expr
($1, $4, $7); }
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
; }
554 { skip_evaluation
-= $1 == boolean_true_node
;
555 $$
= build_conditional_expr
($1, $
<ttype
>2, $5); }
556 | expr_no_commas
'=' expr_no_commas
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
);
564 | expr_no_commas ASSIGN expr_no_commas
566 $$
= build_modify_expr
($1, $2, $3);
567 /* This inhibits warnings in truthvalue_conversion. */
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
);
579 if
(!$$ || $$
== error_mark_node
)
581 if
(yychar == YYEMPTY
)
586 /* Ordinary implicit function declaration. */
587 $$
= implicitly_declare
($1);
588 assemble_external
($$
);
592 else if
(current_function_decl
== 0)
594 error ("`%s' undeclared here (not in a function)",
595 IDENTIFIER_POINTER
($1));
596 $$
= error_mark_node
;
601 if
(IDENTIFIER_GLOBAL_VALUE
($1) != error_mark_node
602 || IDENTIFIER_ERROR_LOCUS
($1) != current_function_decl
)
604 error ("`%s' undeclared (first use in this function)",
605 IDENTIFIER_POINTER
($1));
607 if
(! undeclared_variable_notice
)
609 error ("(Each undeclared identifier is reported only once");
610 error ("for each function it appears in.)");
611 undeclared_variable_notice
= 1;
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
;
621 else if
(TREE_TYPE
($$
) == error_mark_node
)
622 $$
= error_mark_node
;
623 else if
(C_DECL_ANTICIPATED
($$
))
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
)
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
($$
))
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
)
648 = build_function_type
(integer_type_node
,
649 TYPE_ARG_TYPES
(TREE_TYPE
($$
)));
652 pedwarn
("built-in function `%s' used without declaration",
653 IDENTIFIER_POINTER
(DECL_NAME
($$
)));
655 /* Do what we would ordinarily do when a fn is used. */
656 assemble_external
($$
);
661 assemble_external
($$
);
665 if
(TREE_CODE
($$
) == CONST_DECL
)
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;
676 { $$
= combine_strings
($1); }
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
);
684 { $$
= error_mark_node
; }
685 | compstmt_primary_start compstmt_nostart
')'
688 pedwarn
("ANSI C forbids braced-groups within expressions");
689 pop_iterator_stack
();
691 rtl_exp
= expand_end_stmt_expr
($1);
692 /* The statements have side effects, so the group does. */
693 TREE_SIDE_EFFECTS
(rtl_exp
) = 1;
695 if
(TREE_CODE
($2) == BLOCK
)
697 /* Make a BIND_EXPR for the BLOCK already made. */
698 $$
= build
(BIND_EXPR
, TREE_TYPE
(rtl_exp
),
699 NULL_TREE
, rtl_exp
, $2);
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. */
708 | compstmt_primary_start
error ')'
710 /* Make sure we call expand_end_stmt_expr. Otherwise
711 we are likely to lose sequences and crash later. */
712 pop_iterator_stack
();
714 expand_end_stmt_expr
($1);
715 $$
= error_mark_node
;
717 | primary
'(' exprlist
')' %prec
'.'
718 { $$
= build_function_call
($1, $3); }
719 | primary
'[' expr
']' %prec
'.'
720 { $$
= build_array_ref
($1, $3); }
721 | primary
'.' identifier
723 $$
= build_component_ref
($1, $3);
725 | primary POINTSAT identifier
727 tree expr
= build_indirect_ref
($1, "->");
729 $$
= build_component_ref
(expr
, $3);
732 { $$
= build_unary_op
(POSTINCREMENT_EXPR
, $1, 0); }
734 { $$
= build_unary_op
(POSTDECREMENT_EXPR
, $1, 0); }
737 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
741 { $$
= chainon
($1, $2);
742 if
(warn_traditional
&& !in_system_header
)
743 warning
("Use of ANSI string concatenation");
748 old_style_parm_decls:
752 /* ... is used here to indicate a varargs function. */
755 pedwarn
("ANSI C does not permit use of `varargs.h'"); }
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. */
762 save_filename save_lineno datadecl
769 | datadecls lineno_datadecl
770 | lineno_datadecl errstmt
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
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 | declmods_no_prefix_attr setspecs notype_initdecls
';'
783 { current_declspecs
= TREE_VALUE
(declspec_stack
);
784 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
785 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
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"); }
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. */
798 save_filename save_lineno decl
806 | lineno_decl errstmt
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. */
813 setspecs: /* empty */
814 { pending_xref_error
();
815 declspec_stack
= tree_cons
(prefix_attributes
,
818 split_specs_attrs
($
<ttype
>0,
819 ¤t_declspecs
, &prefix_attributes
); }
822 /* ??? Yuck. See after_type_declarator. */
823 setattrs: /* empty */
824 { prefix_attributes
= chainon
(prefix_attributes
, $
<ttype
>0); }
828 typed_declspecs setspecs initdecls
';'
829 { current_declspecs
= TREE_VALUE
(declspec_stack
);
830 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
831 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
832 | declmods setspecs notype_initdecls
';'
833 { current_declspecs
= TREE_VALUE
(declspec_stack
);
834 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
835 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
836 | typed_declspecs setspecs nested_function
837 { current_declspecs
= TREE_VALUE
(declspec_stack
);
838 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
839 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
840 | declmods setspecs notype_nested_function
841 { current_declspecs
= TREE_VALUE
(declspec_stack
);
842 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
843 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
844 | typed_declspecs
';'
847 { pedwarn
("empty declaration"); }
849 { RESTORE_WARN_FLAGS
($1); }
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. */
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)); }
864 reserved_declspecs: /* empty */
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); }
877 typed_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)); }
884 reserved_declspecs_no_prefix_attr:
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); }
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. */
902 declmods_no_prefix_attr
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); }
912 declmods_no_prefix_attr:
914 { $$
= tree_cons
(NULL_TREE
, $1, NULL_TREE
);
915 TREE_STATIC
($$
) = 1; }
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); }
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. */
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)); }
941 reserved_typespecquals: /* empty */
943 | reserved_typespecquals typespecqual_reserved
944 { $$
= tree_cons
(NULL_TREE
, $2, $1); }
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. */
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); }
963 /* A typespec that is a reserved word, or a type qualifier. */
965 typespecqual_reserved: TYPESPEC
972 | initdecls
',' initdcl
977 | notype_initdecls
',' initdcl
983 | ASM_KEYWORD
'(' string ')'
984 { if
(TREE_CHAIN
($3)) $3 = combine_strings
($3);
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
()); }
995 /* Note how the declaration of the variable is in effect while its init is parsed! */
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);
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
()); }
1011 /* Note how the declaration of the variable is in effect while its init is parsed! */
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); }
1020 /* the * rules are dummies to accept the Apollo extended syntax
1021 so that the header files compile. */
1032 | attributes attribute
1033 { $$
= chainon
($1, $2); }
1037 ATTRIBUTE
'(' '(' attribute_list
')' ')'
1044 | attribute_list
',' attrib
1045 { $$
= chainon
($1, $3); }
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); }
1061 /* This still leaves out most reserved keywords,
1062 shouldn't we include them? */
1071 /* Initializers. `init' is the entry point. */
1076 { really_start_incremental_init
(NULL_TREE
); }
1077 initlist_maybe_comma
'}'
1078 { $$
= pop_init_level
(0); }
1080 { $$
= error_mark_node
; }
1083 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1084 initlist_maybe_comma:
1087 pedwarn
("ANSI C forbids empty initializer braces"); }
1088 | initlist1 maybecomma
1093 | initlist1
',' initelt
1096 /* `initelt' is a single element of an initializer.
1097 It may use braces. */
1099 designator_list
'=' initval
1100 | designator initval
1102 { set_init_label
($1); }
1109 { push_init_level
(0); }
1110 initlist_maybe_comma
'}'
1111 { process_init_element
(pop_init_level
(0)); }
1113 { process_init_element
($1); }
1119 | designator_list designator
1124 { set_init_label
($2); }
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. */
1128 |
'[' expr_no_commas ELLIPSIS expr_no_commas
']'
1129 { set_init_index
($2, $4); }
1130 |
'[' expr_no_commas
']'
1131 { set_init_index
($2, NULL_TREE
); }
1137 pedwarn
("ANSI C forbids nested functions");
1139 push_function_context
();
1140 if
(! start_function
(current_declspecs
, $1,
1141 prefix_attributes
, NULL_TREE
))
1143 pop_function_context
();
1146 reinit_parse_for_function
(); }
1147 old_style_parm_decls
1148 { store_parm_decls
(); }
1149 /* This used to use compstmt_or_error.
1150 That caused a bug with input `f(g) int g {}',
1151 where the use of YYERROR1 above caused an error
1152 which then was handled by compstmt_or_error.
1153 There followed a repeated execution of that same rule,
1154 which called YYERROR1 again, and so on. */
1156 { finish_function
(1);
1157 pop_function_context
(); }
1160 notype_nested_function:
1163 pedwarn
("ANSI C forbids nested functions");
1165 push_function_context
();
1166 if
(! start_function
(current_declspecs
, $1,
1167 prefix_attributes
, NULL_TREE
))
1169 pop_function_context
();
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. */
1182 { finish_function
(1);
1183 pop_function_context
(); }
1186 /* Any kind of declarator (thus, all declarators allowed
1187 after an explicit typespec). */
1190 after_type_declarator
1194 /* A declarator that is allowed only after an explicit typespec. */
1196 after_type_declarator:
1197 '(' after_type_declarator
')'
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
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). */
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); } */
1231 | parm_declarator
'[' '*' ']' %prec
'.'
1232 { $$
= build_nt
(ARRAY_REF
, $1, NULL_TREE
);
1234 error ("`[*]' in parameter declaration only allowed in ISO C 99");
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
1252 /* A declarator allowed whether or not there has been
1253 an explicit typespec. These cannot redeclare a typedef-name. */
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
')'
1263 |
'*' type_quals notype_declarator %prec UNARY
1264 { $$
= make_pointer_declarator
($2, $3); }
1265 | notype_declarator
'[' '*' ']' %prec
'.'
1266 { $$
= build_nt
(ARRAY_REF
, $1, NULL_TREE
);
1268 error ("`[*]' in parameter declaration only allowed in ISO C 99");
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
1306 struct_head identifier
'{'
1307 { $$
= start_struct
(RECORD_TYPE
, $2);
1308 /* Start scope of tag before parsing components. */
1310 component_decl_list
'}' maybe_attribute
1311 { $$
= finish_struct
($
<ttype
>4, $5, chainon
($1, $7)); }
1312 | struct_head
'{' component_decl_list
'}' maybe_attribute
1313 { $$
= finish_struct
(start_struct
(RECORD_TYPE
, NULL_TREE
),
1314 $3, chainon
($1, $5));
1316 | struct_head identifier
1317 { $$
= xref_tag
(RECORD_TYPE
, $2); }
1318 | union_head identifier
'{'
1319 { $$
= start_struct
(UNION_TYPE
, $2); }
1320 component_decl_list
'}' maybe_attribute
1321 { $$
= finish_struct
($
<ttype
>4, $5, chainon
($1, $7)); }
1322 | union_head
'{' component_decl_list
'}' maybe_attribute
1323 { $$
= finish_struct
(start_struct
(UNION_TYPE
, NULL_TREE
),
1324 $3, chainon
($1, $5));
1326 | union_head identifier
1327 { $$
= xref_tag
(UNION_TYPE
, $2); }
1328 | enum_head identifier
'{'
1329 { $$
= start_enum
($2); }
1330 enumlist maybecomma_warn
'}' maybe_attribute
1331 { $$
= finish_enum
($
<ttype
>4, nreverse
($5),
1332 chainon
($1, $8)); }
1334 { $$
= start_enum
(NULL_TREE
); }
1335 enumlist maybecomma_warn
'}' maybe_attribute
1336 { $$
= finish_enum
($
<ttype
>3, nreverse
($4),
1337 chainon
($1, $7)); }
1338 | enum_head identifier
1339 { $$
= xref_tag
(ENUMERAL_TYPE
, $2); }
1350 { if
(pedantic
&& ! flag_isoc99
)
1351 pedwarn
("comma at end of enumerator list"); }
1354 component_decl_list:
1355 component_decl_list2
1357 | component_decl_list2 component_decl
1358 { $$
= chainon
($1, $2);
1359 pedwarn
("no semicolon at end of struct or union"); }
1362 component_decl_list2: /* empty */
1364 | component_decl_list2 component_decl
';'
1365 { $$
= chainon
($1, $2); }
1366 | component_decl_list2
';'
1368 pedwarn
("extra semicolon in struct or union specified"); }
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'.
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. */
1381 typed_typespecs setspecs components
1383 current_declspecs
= TREE_VALUE
(declspec_stack
);
1384 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
1385 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
1386 | typed_typespecs setspecs save_filename save_lineno maybe_attribute
1388 /* Support for unnamed structs or unions as members of
1389 structs or unions (which is [a] useful and [b] supports
1392 pedwarn
("ANSI C doesn't support unnamed structs/unions");
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
);
1399 | nonempty_type_quals setspecs components
1401 current_declspecs
= TREE_VALUE
(declspec_stack
);
1402 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
1403 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
1404 | nonempty_type_quals
1406 pedwarn
("ANSI C forbids member declarations with no members");
1411 | extension component_decl
1413 RESTORE_WARN_FLAGS
($1); }
1417 component_declarator
1418 | components
',' component_declarator
1419 { $$
= chainon
($1, $3); }
1422 component_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
); }
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.) */
1442 | enumlist
',' enumerator
1443 { if
($1 == error_mark_node
)
1446 $$
= chainon
($3, $1); }
1448 { $$
= error_mark_node
; }
1454 { $$
= build_enumerator
($1, NULL_TREE
); }
1455 | identifier
'=' expr_no_commas
1456 { $$
= build_enumerator
($1, $3); }
1460 typed_typespecs absdcl
1461 { $$
= build_tree_list
($1, $2); }
1462 | nonempty_type_quals absdcl
1463 { $$
= build_tree_list
($1, $2); }
1466 absdcl: /* an absolute declarator */
1472 nonempty_type_quals:
1474 { $$
= tree_cons
(NULL_TREE
, $1, NULL_TREE
); }
1475 | nonempty_type_quals TYPE_QUAL
1476 { $$
= tree_cons
(NULL_TREE
, $2, $1); }
1482 | type_quals TYPE_QUAL
1483 { $$
= tree_cons
(NULL_TREE
, $2, $1); }
1486 absdcl1: /* a nonempty absolute declarator */
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); }
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. */
1508 | attributes setattrs absdcl1
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. */
1517 lineno_stmt_or_labels
1520 pedwarn
("ANSI C forbids label at end of compound statement");
1524 lineno_stmt_or_labels:
1525 lineno_stmt_or_label
1526 | lineno_stmt_or_labels lineno_stmt_or_label
1528 | lineno_stmt_or_labels errstmt
1540 pushlevel: /* empty */
1541 { emit_line_note
(input_filename
, lineno
);
1544 expand_start_bindings
(0);
1548 /* Read zero or more forward-declarations for labels
1549 that nested functions can jump to. */
1554 pedwarn
("ANSI C forbids label declarations"); }
1559 | label_decls label_decl
1563 LABEL identifiers_or_typenames
';'
1565 for
(link
= $2; link
; link
= TREE_CHAIN
(link
))
1567 tree label
= shadow_label
(TREE_VALUE
(link
));
1568 C_DECLARED_LABEL_FLAG
(label
) = 1;
1569 declare_nonlocal_label
(label
);
1574 /* This is the body of a function definition.
1575 It causes syntax errors to ignore to the next openbrace. */
1582 compstmt_start: '{' { compstmt_count
++; }
1584 compstmt_nostart: '}'
1585 { $$
= convert
(void_type_node
, integer_zero_node
); }
1586 | pushlevel maybe_label_decls decls xstmts
'}'
1587 { emit_line_note
(input_filename
, lineno
);
1588 expand_end_bindings
(getdecls
(), 1, 0);
1589 $$
= poplevel
(1, 1, 0); }
1590 | pushlevel maybe_label_decls
error '}'
1591 { emit_line_note
(input_filename
, lineno
);
1592 expand_end_bindings
(getdecls
(), kept_level_p
(), 0);
1593 $$
= poplevel
(kept_level_p
(), 0, 0); }
1594 | pushlevel maybe_label_decls stmts
'}'
1595 { emit_line_note
(input_filename
, lineno
);
1596 expand_end_bindings
(getdecls
(), kept_level_p
(), 0);
1597 $$
= poplevel
(kept_level_p
(), 0, 0); }
1600 compstmt_primary_start:
1602 { if
(current_function_decl
== 0)
1604 error ("braced-group within expression allowed only inside a function");
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. */
1612 push_iterator_stack
();
1613 push_label_level
();
1614 $$
= expand_start_stmt_expr
();
1618 compstmt: compstmt_start compstmt_nostart
1622 /* Value is number of statements counted as of the closeparen. */
1624 if_prefix lineno_labeled_stmt
1625 /* Make sure c_expand_end_cond is run once
1626 for each call to c_expand_start_cond.
1627 Otherwise a crash is likely. */
1633 { emit_line_note
($
<filename
>-1, $
<lineno
>0);
1634 c_expand_start_cond
(truthvalue_conversion
($3), 0,
1636 $
<itype
>$
= stmt_count
;
1637 if_stmt_file
= $
<filename
>-1;
1638 if_stmt_line
= $
<lineno
>0;
1639 position_after_white_space
(); }
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. */
1649 emit_line_note
($
<filename
>-1, $
<lineno
>0);
1650 /* See comment in `while' alternative, above. */
1652 expand_start_loop_continue_elsewhere
(1);
1653 position_after_white_space
(); }
1654 lineno_labeled_stmt WHILE
1655 { expand_loop_continue_here
(); }
1659 { $$
= input_filename
; }
1666 lineno_labeled_stmt:
1667 save_filename save_lineno stmt
1669 /* | save_filename save_lineno error
1672 | save_filename save_lineno label lineno_labeled_stmt
1676 lineno_stmt_or_label:
1677 save_filename save_lineno stmt_or_label
1688 /* Parse a single real statement, not including any labels. */
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. */
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);
1708 iterator_expand
($1); }
1710 { c_expand_start_else
();
1711 $
<itype
>1 = stmt_count
;
1712 position_after_white_space
(); }
1714 { c_expand_end_cond
();
1715 if
(extra_warnings
&& stmt_count
== $
<itype
>1)
1716 warning
("empty body in an else-statement"); }
1717 | simple_if %prec IF
1718 { c_expand_end_cond
();
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"); }
1726 /* Make sure c_expand_end_cond is run once
1727 for each call to c_expand_start_cond.
1728 Otherwise a crash is likely. */
1729 | simple_if ELSE
error
1730 { c_expand_end_cond
(); }
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. */
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
(); }
1751 { expand_end_loop
(); }
1754 { emit_line_note
(input_filename
, lineno
);
1755 expand_exit_loop_if_false
(NULL_PTR
,
1756 truthvalue_conversion
($3));
1757 expand_end_loop
(); }
1758 /* This rule is needed to make sure we end every loop we start. */
1759 | do_stmt_start
error
1760 { expand_end_loop
(); }
1764 emit_line_note
($
<filename
>-1, $
<lineno
>0);
1765 /* See comment in `while' alternative, above. */
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. */
1774 /* Can't emit now; wait till after expand_start_loop... */
1775 { $
<lineno
>7 = lineno
;
1776 $
<filename
>$
= input_filename
; }
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);
1785 expand_exit_loop_if_false
(NULL_PTR
,
1786 truthvalue_conversion
($6));
1787 $
<lineno
>7 = lineno
;
1788 $
<filename
>8 = input_filename
;
1789 position_after_white_space
(); }
1791 { /* Emit the increment expression, with a line number. */
1792 emit_line_note
($
<filename
>8, $
<lineno
>7);
1793 expand_loop_continue_here
();
1795 c_expand_expr_stmt
($9);
1796 expand_end_loop
(); }
1797 | SWITCH
'(' expr
')'
1799 emit_line_note
($
<filename
>-1, $
<lineno
>0);
1800 c_expand_start_case
($3);
1801 position_after_white_space
(); }
1803 { expand_end_case
($3); }
1806 emit_line_note
($
<filename
>-1, $
<lineno
>0);
1807 if
( ! expand_exit_something
())
1808 error ("break statement not within loop or switch"); }
1811 emit_line_note
($
<filename
>-1, $
<lineno
>0);
1812 if
(! expand_continue_loop
(NULL_PTR
))
1813 error ("continue statement not within a loop"); }
1816 emit_line_note
($
<filename
>-1, $
<lineno
>0);
1817 c_expand_return
(NULL_TREE
); }
1820 emit_line_note
($
<filename
>-1, $
<lineno
>0);
1821 c_expand_return
($2); }
1822 | ASM_KEYWORD maybe_type_qual
'(' expr
')' ';'
1824 emit_line_note
($
<filename
>-1, $
<lineno
>0);
1826 if
((TREE_CODE
($4) == ADDR_EXPR
1827 && TREE_CODE
(TREE_OPERAND
($4, 0)) == STRING_CST
)
1828 || TREE_CODE
($4) == STRING_CST
)
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
')' ';'
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
')' ';'
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
')' ';'
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
';'
1857 emit_line_note
($
<filename
>-1, $
<lineno
>0);
1858 decl
= lookup_label
($2);
1861 TREE_USED
(decl
) = 1;
1867 pedwarn
("ANSI C forbids `goto *expr;'");
1869 emit_line_note
($
<filename
>-1, $
<lineno
>0);
1870 expand_computed_goto
(convert
(ptr_type_node
, $3)); }
1875 all_iter_stmt_simple
1876 /* | all_iter_stmt_with_decl */
1879 all_iter_stmt_simple:
1882 /* The value returned by this action is */
1883 /* 1 if everything is OK */
1884 /* 0 in case of error or already bound iterator */
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)));
1898 iterator_for_loop_start
($3);
1904 iterator_for_loop_end
($3);
1907 /* This really should allow any kind of declaration,
1908 for generality. Fix it before turning it back on.
1910 all_iter_stmt_with_decl:
1911 FOR '(' ITERATOR pushlevel setspecs iterator_spec ')'
1913 */ /* The value returned by this action is */
1914 /* 1 if everything is OK */
1915 /* 0 in case of error or already bound iterator */
1917 iterator_for_loop_start ($6);
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);
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. */
1932 label: CASE expr_no_commas
':'
1933 { register tree value
= check_case_value
($2);
1935 = build_decl
(LABEL_DECL
, NULL_TREE
, NULL_TREE
);
1939 if
(value
!= error_mark_node
)
1944 if
(pedantic
&& ! INTEGRAL_TYPE_P
(TREE_TYPE
(value
)))
1945 pedwarn
("label must have integral type in ANSI C");
1947 success
= pushcase
(value
, convert_and_check
,
1951 error ("case label not within a switch statement");
1952 else if
(success
== 2)
1954 error ("duplicate case value");
1955 error_with_decl
(duplicate
, "this is the first entry for that value");
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");
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);
1967 = build_decl
(LABEL_DECL
, NULL_TREE
, NULL_TREE
);
1970 pedwarn
("ANSI C forbids case ranges");
1973 if
(value1
!= error_mark_node
&& value2
!= error_mark_node
)
1976 int success
= pushcase_range
(value1
, value2
,
1977 convert_and_check
, label
,
1980 error ("case label not within a switch statement");
1981 else if
(success
== 2)
1983 error ("duplicate case value");
1984 error_with_decl
(duplicate
, "this is the first entry for that value");
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");
1993 position_after_white_space
(); }
1998 = build_decl
(LABEL_DECL
, NULL_TREE
, NULL_TREE
);
1999 int success
= pushcase
(NULL_TREE
, 0, label
, &duplicate
);
2002 error ("default label not within a switch statement");
2003 else if
(success
== 2)
2005 error ("multiple default labels in one switch");
2006 error_with_decl
(duplicate
, "this is the first default label");
2008 position_after_white_space
(); }
2009 | identifier
':' maybe_attribute
2010 { tree label
= define_label
(input_filename
, lineno
, $1);
2015 expand_label
(label
);
2016 decl_attributes
(label
, $3, NULL_TREE
);
2018 position_after_white_space
(); }
2021 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
2025 { emit_line_note
(input_filename
, lineno
);
2028 { emit_line_note
(input_filename
, lineno
); }
2037 /* These are the operands other than the first string and colon
2038 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2039 asm_operands: /* empty */
2041 | nonnull_asm_operands
2044 nonnull_asm_operands:
2046 | nonnull_asm_operands
',' asm_operand
2047 { $$
= chainon
($1, $3); }
2052 { $$
= build_tree_list
($1, $3); }
2057 { $$
= tree_cons
(NULL_TREE
, combine_strings
($1), NULL_TREE
); }
2058 | asm_clobbers
',' string
2059 { $$
= tree_cons
(NULL_TREE
, combine_strings
($3), $1); }
2062 /* This is what appears inside the parens in a function declarator.
2063 Its value is a list of ..._TYPE nodes. */
2066 clear_parm_order
();
2067 declare_parm_level
(0); }
2070 parmlist_tags_warning
();
2071 poplevel
(0, 0, 0); }
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
(); }
2087 { $$
= tree_cons
(NULL_TREE
, NULL_TREE
, NULL_TREE
); }
2090 /* This is what appears inside the parens in a function declarator.
2091 Is value is represented in the format that grokdeclarator expects. */
2092 parmlist_2: /* empty */
2093 { $$
= get_parm_info
(0); }
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
2102 error ("ANSI C requires a named argument before `...'");
2105 { $$
= get_parm_info
(1); }
2106 | parms
',' ELLIPSIS
2107 { $$
= get_parm_info
(0); }
2112 { push_parm_decl
($1); }
2114 { push_parm_decl
($3); }
2117 /* A single parameter declaration or parameter type name,
2118 as found in a parmlist. */
2120 typed_declspecs setspecs parm_declarator maybe_attribute
2121 { $$
= build_tree_list
(build_tree_list
(current_declspecs
,
2123 build_tree_list
(prefix_attributes
,
2125 current_declspecs
= TREE_VALUE
(declspec_stack
);
2126 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
2127 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
2128 | typed_declspecs setspecs notype_declarator maybe_attribute
2129 { $$
= build_tree_list
(build_tree_list
(current_declspecs
,
2131 build_tree_list
(prefix_attributes
,
2133 current_declspecs
= TREE_VALUE
(declspec_stack
);
2134 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
2135 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
2136 | typed_declspecs setspecs absdcl maybe_attribute
2137 { $$
= build_tree_list
(build_tree_list
(current_declspecs
,
2139 build_tree_list
(prefix_attributes
,
2141 current_declspecs
= TREE_VALUE
(declspec_stack
);
2142 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
2143 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
2144 | declmods setspecs notype_declarator maybe_attribute
2145 { $$
= build_tree_list
(build_tree_list
(current_declspecs
,
2147 build_tree_list
(prefix_attributes
,
2149 current_declspecs
= TREE_VALUE
(declspec_stack
);
2150 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
2151 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
2153 | declmods setspecs absdcl maybe_attribute
2154 { $$
= build_tree_list
(build_tree_list
(current_declspecs
,
2156 build_tree_list
(prefix_attributes
,
2158 current_declspecs
= TREE_VALUE
(declspec_stack
);
2159 prefix_attributes
= TREE_PURPOSE
(declspec_stack
);
2160 declspec_stack
= TREE_CHAIN
(declspec_stack
); }
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. */
2166 parmlist_or_identifiers:
2168 clear_parm_order
();
2169 declare_parm_level
(1); }
2170 parmlist_or_identifiers_1
2172 parmlist_tags_warning
();
2173 poplevel
(0, 0, 0); }
2176 parmlist_or_identifiers_1:
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); }
2186 /* A nonempty list of identifiers. */
2189 { $$
= build_tree_list
(NULL_TREE
, $1); }
2190 | identifiers
',' IDENTIFIER
2191 { $$
= chainon
($1, build_tree_list
(NULL_TREE
, $3)); }
2194 /* A nonempty list of identifiers, including typenames. */
2195 identifiers_or_typenames:
2197 { $$
= build_tree_list
(NULL_TREE
, $1); }
2198 | identifiers_or_typenames
',' identifier
2199 { $$
= chainon
($1, build_tree_list
(NULL_TREE
, $3)); }
2204 { $$
= SAVE_WARN_FLAGS
();
2206 warn_pointer_arith
= 0; }