1 /* YACC parser for C syntax and for Objective C. -*-c-*-
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996,
3 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* This file defines the grammar of C and that of Objective C.
23 ifobjc ... end ifobjc conditionals contain code for Objective C only.
24 ifc ... end ifc conditionals contain code for C only.
25 Sed commands in Makefile.in are used to convert this file into
26 c-parse.y and into objc-parse.y. */
28 /* To whomever it may concern: I have heard that such a thing was once
29 written by AT&T, but I have never seen it. */
55 #ifdef MULTIBYTE_CHARS
63 /* Since parsers are distinct for each language, put the language string
66 const char * const language_string = "GNU Objective-C";
69 const char * const language_string = "GNU C";
72 /* Like YYERROR but do call yyerror. */
73 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
75 /* Cause the `yydebug' variable to be defined. */
81 %union {long itype; tree ttype; enum tree_code code;
82 const char *filename; int lineno; int ends_in_label; }
84 /* All identifiers that are not reserved words
85 and are not declared typedefs in the current block */
88 /* All identifiers that are declared typedefs in the current block.
89 In some contexts, they are treated just like IDENTIFIER,
90 but they can also serve as typespecs in declarations. */
93 /* Reserved words that specify storage class.
94 yylval contains an IDENTIFIER_NODE which indicates which one. */
97 /* Reserved words that specify type.
98 yylval contains an IDENTIFIER_NODE which indicates which one. */
101 /* Reserved words that qualify type: "const", "volatile", or "restrict".
102 yylval contains an IDENTIFIER_NODE which indicates which one. */
105 /* Character or numeric constants.
106 yylval is the node for the constant. */
109 /* String constants in raw form.
110 yylval is a STRING_CST node. */
113 /* "...", used for functions with variable arglists. */
116 /* the reserved words */
117 /* SCO include files test "ASM", so use something else. */
118 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
119 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
120 %token ATTRIBUTE EXTENSION LABEL
121 %token REALPART IMAGPART VA_ARG
122 %token PTR_VALUE PTR_BASE PTR_EXTENT
124 /* Add precedence rules to solve dangling else s/r conflict */
128 /* Define the operator tokens and their precedences.
129 The value is an integer because, if used, it is the tree code
130 to use in the expression made from the operator. */
132 %right <code> ASSIGN '='
133 %right <code> '?' ':'
139 %left <code> EQCOMPARE
140 %left <code> ARITHCOMPARE
141 %left <code> LSHIFT RSHIFT
143 %left <code> '*' '/' '%'
144 %right <code> UNARY PLUSPLUS MINUSMINUS
146 %left <code> POINTSAT '.' '(' '['
148 /* The Objective-C keywords. These are included in C and in
149 Objective C, so that the token codes are the same in both. */
150 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
151 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
153 /* Objective-C string constants in raw form.
154 yylval is an STRING_CST node. */
159 %type <ttype> ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
160 %type <ttype> BREAK CONTINUE RETURN GOTO ASM_KEYWORD SIZEOF TYPEOF ALIGNOF
162 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
163 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
164 %type <ttype> typed_declspecs reserved_declspecs
165 %type <ttype> typed_typespecs reserved_typespecquals
166 %type <ttype> declmods typespec typespecqual_reserved
167 %type <ttype> typed_declspecs_no_prefix_attr reserved_declspecs_no_prefix_attr
168 %type <ttype> declmods_no_prefix_attr
169 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
170 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
171 %type <ttype> init maybeasm
172 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
173 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
174 %type <ttype> any_word extension
176 %type <ttype> compstmt compstmt_nostart compstmt_primary_start
178 %type <ttype> declarator
179 %type <ttype> notype_declarator after_type_declarator
180 %type <ttype> parm_declarator
182 %type <ttype> structsp component_decl_list component_decl_list2
183 %type <ttype> component_decl components component_declarator
184 %type <ttype> enumlist enumerator
185 %type <ttype> struct_head union_head enum_head
186 %type <ttype> typename absdcl absdcl1 type_quals
187 %type <ttype> xexpr parms parm identifiers
189 %type <ttype> parmlist parmlist_1 parmlist_2
190 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
191 %type <ttype> identifiers_or_typenames
193 %type <itype> setspecs
195 %type <ends_in_label> lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
197 %type <filename> save_filename
198 %type <lineno> save_lineno
201 /* the Objective-C nonterminals */
203 %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
204 %type <ttype> methoddecl unaryselector keywordselector selector
205 %type <ttype> keyworddecl receiver objcmessageexpr messageargs
206 %type <ttype> keywordexpr keywordarglist keywordarg
207 %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
208 %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
209 %type <ttype> objc_string non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
211 %type <ttype> CLASSNAME OBJC_STRING OBJECTNAME
215 /* Number of statements (loosely speaking) and compound statements
217 static int stmt_count;
218 static int compstmt_count;
220 /* Input file and line number of the end of the body of last simple_if;
221 used by the stmt-rule immediately after simple_if returns. */
222 static const char *if_stmt_file;
223 static int if_stmt_line;
225 /* List of types and structure classes of the current declaration. */
226 static tree current_declspecs = NULL_TREE;
227 static tree prefix_attributes = NULL_TREE;
229 /* Stack of saved values of current_declspecs and prefix_attributes. */
230 static tree declspec_stack;
232 /* For __extension__, save/restore the warning flags which are
233 controlled by __extension__. */
234 #define SAVE_WARN_FLAGS() \
235 size_int (pedantic | (warn_pointer_arith << 1))
236 #define RESTORE_WARN_FLAGS(tval) \
238 int val = tree_low_cst (tval, 0); \
239 pedantic = val & 1; \
240 warn_pointer_arith = (val >> 1) & 1; \
244 /* Objective-C specific information */
246 tree objc_interface_context;
247 tree objc_implementation_context;
248 tree objc_method_context;
249 tree objc_ivar_chain;
250 tree objc_ivar_context;
251 enum tree_code objc_inherit_code;
252 int objc_receiver_context;
253 int objc_public_flag;
257 /* Tell yyparse how to print a token's value, if yydebug is set. */
259 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
261 static void yyprint PARAMS ((FILE *, int, YYSTYPE));
262 static void yyerror PARAMS ((const char *));
263 static inline int _yylex PARAMS ((void));
264 static int yylex PARAMS ((void));
265 static void init_reswords PARAMS ((void));
267 /* Add GC roots for variables local to this file. */
271 ggc_add_tree_root (&declspec_stack, 1);
272 ggc_add_tree_root (¤t_declspecs, 1);
273 ggc_add_tree_root (&prefix_attributes, 1);
275 ggc_add_tree_root (&objc_interface_context, 1);
276 ggc_add_tree_root (&objc_implementation_context, 1);
277 ggc_add_tree_root (&objc_method_context, 1);
278 ggc_add_tree_root (&objc_ivar_chain, 1);
279 ggc_add_tree_root (&objc_ivar_context, 1);
288 pedwarn ("ISO C forbids an empty source file");
293 /* In case there were missing closebraces,
294 get us back to the global binding level. */
295 while (! global_bindings_p ())
301 /* the reason for the strange actions in this rule
302 is so that notype_initdecls when reached via datadef
303 can find a valid list of type and sc specs in $0. */
306 {$<ttype>$ = NULL_TREE; } extdef
307 | extdefs {$<ttype>$ = NULL_TREE; ggc_collect(); } extdef
316 | ASM_KEYWORD '(' expr ')' ';'
318 if ((TREE_CODE ($3) == ADDR_EXPR
319 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
320 || TREE_CODE ($3) == STRING_CST)
323 error ("argument of `asm' is not a constant string"); }
325 { RESTORE_WARN_FLAGS ($1); }
329 setspecs notype_initdecls ';'
331 error ("ISO C forbids data definition with no type or storage class");
332 else if (!flag_traditional)
333 warning ("data definition has no type or storage class");
335 current_declspecs = TREE_VALUE (declspec_stack);
336 prefix_attributes = TREE_PURPOSE (declspec_stack);
337 declspec_stack = TREE_CHAIN (declspec_stack); }
338 | declmods setspecs notype_initdecls ';'
339 { current_declspecs = TREE_VALUE (declspec_stack);
340 prefix_attributes = TREE_PURPOSE (declspec_stack);
341 declspec_stack = TREE_CHAIN (declspec_stack); }
342 | typed_declspecs setspecs initdecls ';'
343 { current_declspecs = TREE_VALUE (declspec_stack);
344 prefix_attributes = TREE_PURPOSE (declspec_stack);
345 declspec_stack = TREE_CHAIN (declspec_stack); }
347 { pedwarn ("empty declaration"); }
348 | typed_declspecs ';'
354 pedwarn ("ISO C does not allow extra `;' outside of a function"); }
358 typed_declspecs setspecs declarator
359 { if (! start_function (current_declspecs, $3,
360 prefix_attributes, NULL_TREE))
364 { store_parm_decls (); }
366 { finish_function (0);
367 current_declspecs = TREE_VALUE (declspec_stack);
368 prefix_attributes = TREE_PURPOSE (declspec_stack);
369 declspec_stack = TREE_CHAIN (declspec_stack); }
370 | typed_declspecs setspecs declarator error
371 { current_declspecs = TREE_VALUE (declspec_stack);
372 prefix_attributes = TREE_PURPOSE (declspec_stack);
373 declspec_stack = TREE_CHAIN (declspec_stack); }
374 | declmods setspecs notype_declarator
375 { if (! start_function (current_declspecs, $3,
376 prefix_attributes, NULL_TREE))
380 { store_parm_decls (); }
382 { finish_function (0);
383 current_declspecs = TREE_VALUE (declspec_stack);
384 prefix_attributes = TREE_PURPOSE (declspec_stack);
385 declspec_stack = TREE_CHAIN (declspec_stack); }
386 | declmods setspecs notype_declarator error
387 { current_declspecs = TREE_VALUE (declspec_stack);
388 prefix_attributes = TREE_PURPOSE (declspec_stack);
389 declspec_stack = TREE_CHAIN (declspec_stack); }
390 | setspecs notype_declarator
391 { if (! start_function (NULL_TREE, $2,
392 prefix_attributes, NULL_TREE))
396 { store_parm_decls (); }
398 { finish_function (0);
399 current_declspecs = TREE_VALUE (declspec_stack);
400 prefix_attributes = TREE_PURPOSE (declspec_stack);
401 declspec_stack = TREE_CHAIN (declspec_stack); }
402 | setspecs notype_declarator error
403 { current_declspecs = TREE_VALUE (declspec_stack);
404 prefix_attributes = TREE_PURPOSE (declspec_stack);
405 declspec_stack = TREE_CHAIN (declspec_stack); }
420 { $$ = NEGATE_EXPR; }
424 if (warn_traditional && !in_system_header)
425 warning ("traditional C rejects the unary plus operator");
429 { $$ = PREINCREMENT_EXPR; }
431 { $$ = PREDECREMENT_EXPR; }
433 { $$ = BIT_NOT_EXPR; }
435 { $$ = TRUTH_NOT_EXPR; }
438 expr: nonnull_exprlist
439 { $$ = build_compound_expr ($1); }
450 { $$ = build_tree_list (NULL_TREE, $1); }
451 | nonnull_exprlist ',' expr_no_commas
452 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
457 | '*' cast_expr %prec UNARY
458 { $$ = build_indirect_ref ($2, "unary *"); }
459 /* __extension__ turns off -pedantic for following primary. */
460 | extension cast_expr %prec UNARY
462 RESTORE_WARN_FLAGS ($1); }
463 | unop cast_expr %prec UNARY
464 { $$ = build_unary_op ($1, $2, 0);
465 overflow_warning ($$); }
466 /* Refer to the address of a label as a pointer. */
468 { tree label = lookup_label ($2);
470 pedwarn ("ISO C forbids `&&'");
472 $$ = null_pointer_node;
475 TREE_USED (label) = 1;
476 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
477 TREE_CONSTANT ($$) = 1;
480 /* This seems to be impossible on some machines, so let's turn it off.
481 You can use __builtin_next_arg to find the anonymous stack args.
483 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
484 $$ = error_mark_node;
485 if (TREE_VALUE (tree_last (types)) == void_type_node)
486 error ("`&...' used in function with fixed number of arguments");
490 pedwarn ("ISO C forbids `&...'");
491 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
492 $$ = build_unary_op (ADDR_EXPR, $$, 0);
495 | sizeof unary_expr %prec UNARY
497 if (TREE_CODE ($2) == COMPONENT_REF
498 && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
499 error ("`sizeof' applied to a bit-field");
500 $$ = c_sizeof (TREE_TYPE ($2)); }
501 | sizeof '(' typename ')' %prec HYPERUNARY
503 $$ = c_sizeof (groktypename ($3)); }
504 | alignof unary_expr %prec UNARY
506 $$ = c_alignof_expr ($2); }
507 | alignof '(' typename ')' %prec HYPERUNARY
509 $$ = c_alignof (groktypename ($3)); }
510 | REALPART cast_expr %prec UNARY
511 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
512 | IMAGPART cast_expr %prec UNARY
513 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
514 | VA_ARG '(' expr_no_commas ',' typename ')'
515 { $$ = build_va_arg ($3, groktypename ($5)); }
519 SIZEOF { skip_evaluation++; }
523 ALIGNOF { skip_evaluation++; }
528 | '(' typename ')' cast_expr %prec UNARY
530 int SAVED_warn_strict_prototypes = warn_strict_prototypes;
531 /* This avoids warnings about unprototyped casts on
532 integers. E.g. "#define SIG_DFL (void(*)())0". */
533 if (TREE_CODE ($4) == INTEGER_CST)
534 warn_strict_prototypes = 0;
535 type = groktypename ($2);
536 warn_strict_prototypes = SAVED_warn_strict_prototypes;
537 $$ = build_c_cast (type, $4); }
538 | '(' typename ')' '{'
539 { start_init (NULL_TREE, NULL, 0);
540 $2 = groktypename ($2);
541 really_start_incremental_init ($2); }
542 initlist_maybe_comma '}' %prec UNARY
544 tree result = pop_init_level (0);
548 if (pedantic && ! flag_isoc99)
549 pedwarn ("ISO C89 forbids constructor expressions");
550 if (TYPE_NAME (type) != 0)
552 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
553 name = IDENTIFIER_POINTER (TYPE_NAME (type));
555 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
560 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
562 int failure = complete_array_type (type, $$, 1);
571 | expr_no_commas '+' expr_no_commas
572 { $$ = parser_build_binary_op ($2, $1, $3); }
573 | expr_no_commas '-' expr_no_commas
574 { $$ = parser_build_binary_op ($2, $1, $3); }
575 | expr_no_commas '*' expr_no_commas
576 { $$ = parser_build_binary_op ($2, $1, $3); }
577 | expr_no_commas '/' expr_no_commas
578 { $$ = parser_build_binary_op ($2, $1, $3); }
579 | expr_no_commas '%' expr_no_commas
580 { $$ = parser_build_binary_op ($2, $1, $3); }
581 | expr_no_commas LSHIFT expr_no_commas
582 { $$ = parser_build_binary_op ($2, $1, $3); }
583 | expr_no_commas RSHIFT expr_no_commas
584 { $$ = parser_build_binary_op ($2, $1, $3); }
585 | expr_no_commas ARITHCOMPARE expr_no_commas
586 { $$ = parser_build_binary_op ($2, $1, $3); }
587 | expr_no_commas EQCOMPARE expr_no_commas
588 { $$ = parser_build_binary_op ($2, $1, $3); }
589 | expr_no_commas '&' expr_no_commas
590 { $$ = parser_build_binary_op ($2, $1, $3); }
591 | expr_no_commas '|' expr_no_commas
592 { $$ = parser_build_binary_op ($2, $1, $3); }
593 | expr_no_commas '^' expr_no_commas
594 { $$ = parser_build_binary_op ($2, $1, $3); }
595 | expr_no_commas ANDAND
596 { $1 = truthvalue_conversion (default_conversion ($1));
597 skip_evaluation += $1 == boolean_false_node; }
599 { skip_evaluation -= $1 == boolean_false_node;
600 $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
601 | expr_no_commas OROR
602 { $1 = truthvalue_conversion (default_conversion ($1));
603 skip_evaluation += $1 == boolean_true_node; }
605 { skip_evaluation -= $1 == boolean_true_node;
606 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
608 { $1 = truthvalue_conversion (default_conversion ($1));
609 skip_evaluation += $1 == boolean_false_node; }
611 { skip_evaluation += (($1 == boolean_true_node)
612 - ($1 == boolean_false_node)); }
614 { skip_evaluation -= $1 == boolean_true_node;
615 $$ = build_conditional_expr ($1, $4, $7); }
618 pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
619 /* Make sure first operand is calculated only once. */
620 $<ttype>2 = save_expr ($1);
621 $1 = truthvalue_conversion (default_conversion ($<ttype>2));
622 skip_evaluation += $1 == boolean_true_node; }
624 { skip_evaluation -= $1 == boolean_true_node;
625 $$ = build_conditional_expr ($1, $<ttype>2, $5); }
626 | expr_no_commas '=' expr_no_commas
628 $$ = build_modify_expr ($1, NOP_EXPR, $3);
629 class = TREE_CODE_CLASS (TREE_CODE ($$));
630 if (class == 'e' || class == '1'
631 || class == '2' || class == '<')
632 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR);
634 | expr_no_commas ASSIGN expr_no_commas
636 $$ = build_modify_expr ($1, $2, $3);
637 /* This inhibits warnings in truthvalue_conversion. */
638 class = TREE_CODE_CLASS (TREE_CODE ($$));
639 if (class == 'e' || class == '1'
640 || class == '2' || class == '<')
641 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK);
648 if (yychar == YYEMPTY)
650 $$ = build_external_ref ($1, yychar == '(');
654 { $$ = combine_strings ($1); }
656 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
657 if (class == 'e' || class == '1'
658 || class == '2' || class == '<')
659 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
662 { $$ = error_mark_node; }
663 | compstmt_primary_start compstmt_nostart ')'
666 pedwarn ("ISO C forbids braced-groups within expressions");
668 rtl_exp = expand_end_stmt_expr ($1);
669 /* The statements have side effects, so the group does. */
670 TREE_SIDE_EFFECTS (rtl_exp) = 1;
672 if (TREE_CODE ($2) == BLOCK)
674 /* Make a BIND_EXPR for the BLOCK already made. */
675 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
676 NULL_TREE, rtl_exp, $2);
677 /* Remove the block from the tree at this point.
678 It gets put back at the proper place
679 when the BIND_EXPR is expanded. */
685 | compstmt_primary_start error ')'
687 /* Make sure we call expand_end_stmt_expr. Otherwise
688 we are likely to lose sequences and crash later. */
690 expand_end_stmt_expr ($1);
691 $$ = error_mark_node;
693 | primary '(' exprlist ')' %prec '.'
694 { $$ = build_function_call ($1, $3); }
695 | primary '[' expr ']' %prec '.'
696 { $$ = build_array_ref ($1, $3); }
697 | primary '.' identifier
700 if (doing_objc_thang)
702 if (is_public ($1, $3))
703 $$ = build_component_ref ($1, $3);
705 $$ = error_mark_node;
709 $$ = build_component_ref ($1, $3);
711 | primary POINTSAT identifier
713 tree expr = build_indirect_ref ($1, "->");
716 if (doing_objc_thang)
718 if (is_public (expr, $3))
719 $$ = build_component_ref (expr, $3);
721 $$ = error_mark_node;
725 $$ = build_component_ref (expr, $3);
728 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
730 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
733 { $$ = build_message_expr ($1); }
735 { $$ = build_selector_expr ($1); }
737 { $$ = build_protocol_expr ($1); }
739 { $$ = build_encode_expr ($1); }
741 { $$ = build_objc_string_object ($1); }
745 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
751 static int last_lineno = 0;
752 static const char *last_input_filename = 0;
754 $$ = chainon ($1, $2);
756 if (warn_traditional && !in_system_header
757 && (lineno != last_lineno || !last_input_filename ||
758 strcmp (last_input_filename, input_filename)))
760 warning ("traditional C rejects string concatenation");
761 last_lineno = lineno;
762 last_input_filename = input_filename;
769 /* Produces an STRING_CST with perhaps more STRING_CSTs chained
770 onto it, which is to be read as an ObjC string object. */
773 | objc_string OBJC_STRING
774 { $$ = chainon ($1, $2); }
778 old_style_parm_decls:
782 /* ... is used here to indicate a varargs function. */
785 pedwarn ("ISO C does not permit use of `varargs.h'"); }
788 /* The following are analogous to lineno_decl, decls and decl
789 except that they do not allow nested functions.
790 They are used for old-style parm decls. */
792 save_filename save_lineno datadecl
799 | datadecls lineno_datadecl
800 | lineno_datadecl errstmt
803 /* We don't allow prefix attributes here because they cause reduce/reduce
804 conflicts: we can't know whether we're parsing a function decl with
805 attribute suffix, or function defn with attribute prefix on first old
808 typed_declspecs_no_prefix_attr setspecs initdecls ';'
809 { current_declspecs = TREE_VALUE (declspec_stack);
810 prefix_attributes = TREE_PURPOSE (declspec_stack);
811 declspec_stack = TREE_CHAIN (declspec_stack); }
812 | declmods_no_prefix_attr setspecs notype_initdecls ';'
813 { current_declspecs = TREE_VALUE (declspec_stack);
814 prefix_attributes = TREE_PURPOSE (declspec_stack);
815 declspec_stack = TREE_CHAIN (declspec_stack); }
816 | typed_declspecs_no_prefix_attr ';'
817 { shadow_tag_warned ($1, 1);
818 pedwarn ("empty declaration"); }
819 | declmods_no_prefix_attr ';'
820 { pedwarn ("empty declaration"); }
823 /* This combination which saves a lineno before a decl
824 is the normal thing to use, rather than decl itself.
825 This is to avoid shift/reduce conflicts in contexts
826 where statement labels are allowed. */
828 save_filename save_lineno decl
836 | lineno_decl errstmt
839 /* records the type and storage class specs to use for processing
840 the declarators that follow.
841 Maintains a stack of outer-level values of current_declspecs,
842 for the sake of parm declarations nested in function declarators. */
843 setspecs: /* empty */
844 { pending_xref_error ();
845 declspec_stack = tree_cons (prefix_attributes,
848 split_specs_attrs ($<ttype>0,
849 ¤t_declspecs, &prefix_attributes); }
852 /* ??? Yuck. See after_type_declarator. */
853 setattrs: /* empty */
854 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
858 typed_declspecs setspecs initdecls ';'
859 { current_declspecs = TREE_VALUE (declspec_stack);
860 prefix_attributes = TREE_PURPOSE (declspec_stack);
861 declspec_stack = TREE_CHAIN (declspec_stack); }
862 | declmods setspecs notype_initdecls ';'
863 { current_declspecs = TREE_VALUE (declspec_stack);
864 prefix_attributes = TREE_PURPOSE (declspec_stack);
865 declspec_stack = TREE_CHAIN (declspec_stack); }
866 | typed_declspecs setspecs nested_function
867 { current_declspecs = TREE_VALUE (declspec_stack);
868 prefix_attributes = TREE_PURPOSE (declspec_stack);
869 declspec_stack = TREE_CHAIN (declspec_stack); }
870 | declmods setspecs notype_nested_function
871 { current_declspecs = TREE_VALUE (declspec_stack);
872 prefix_attributes = TREE_PURPOSE (declspec_stack);
873 declspec_stack = TREE_CHAIN (declspec_stack); }
874 | typed_declspecs ';'
877 { pedwarn ("empty declaration"); }
879 { RESTORE_WARN_FLAGS ($1); }
882 /* Declspecs which contain at least one type specifier or typedef name.
883 (Just `const' or `volatile' is not enough.)
884 A typedef'd name following these is taken as a name to be declared.
885 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
888 typespec reserved_declspecs
889 { $$ = tree_cons (NULL_TREE, $1, $2); }
890 | declmods typespec reserved_declspecs
891 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
894 reserved_declspecs: /* empty */
896 | reserved_declspecs typespecqual_reserved
897 { $$ = tree_cons (NULL_TREE, $2, $1); }
898 | reserved_declspecs SCSPEC
899 { if (extra_warnings)
900 warning ("`%s' is not at beginning of declaration",
901 IDENTIFIER_POINTER ($2));
902 $$ = tree_cons (NULL_TREE, $2, $1); }
903 | reserved_declspecs attributes
904 { $$ = tree_cons ($2, NULL_TREE, $1); }
907 typed_declspecs_no_prefix_attr:
908 typespec reserved_declspecs_no_prefix_attr
909 { $$ = tree_cons (NULL_TREE, $1, $2); }
910 | declmods_no_prefix_attr typespec reserved_declspecs_no_prefix_attr
911 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
914 reserved_declspecs_no_prefix_attr:
917 | reserved_declspecs_no_prefix_attr typespecqual_reserved
918 { $$ = tree_cons (NULL_TREE, $2, $1); }
919 | reserved_declspecs_no_prefix_attr SCSPEC
920 { if (extra_warnings)
921 warning ("`%s' is not at beginning of declaration",
922 IDENTIFIER_POINTER ($2));
923 $$ = tree_cons (NULL_TREE, $2, $1); }
926 /* List of just storage classes, type modifiers, and prefix attributes.
927 A declaration can start with just this, but then it cannot be used
928 to redeclare a typedef-name.
929 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
932 declmods_no_prefix_attr
935 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
936 | declmods declmods_no_prefix_attr
937 { $$ = chainon ($2, $1); }
938 | declmods attributes
939 { $$ = tree_cons ($2, NULL_TREE, $1); }
942 declmods_no_prefix_attr:
944 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
945 TREE_STATIC ($$) = 1; }
947 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
948 | declmods_no_prefix_attr TYPE_QUAL
949 { $$ = tree_cons (NULL_TREE, $2, $1);
950 TREE_STATIC ($$) = 1; }
951 | declmods_no_prefix_attr SCSPEC
952 { if (extra_warnings && TREE_STATIC ($1))
953 warning ("`%s' is not at beginning of declaration",
954 IDENTIFIER_POINTER ($2));
955 $$ = tree_cons (NULL_TREE, $2, $1);
956 TREE_STATIC ($$) = TREE_STATIC ($1); }
960 /* Used instead of declspecs where storage classes are not allowed
961 (that is, for typenames and structure components).
962 Don't accept a typedef-name if anything but a modifier precedes it. */
965 typespec reserved_typespecquals
966 { $$ = tree_cons (NULL_TREE, $1, $2); }
967 | nonempty_type_quals typespec reserved_typespecquals
968 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
971 reserved_typespecquals: /* empty */
973 | reserved_typespecquals typespecqual_reserved
974 { $$ = tree_cons (NULL_TREE, $2, $1); }
977 /* A typespec (but not a type qualifier).
978 Once we have seen one of these in a declaration,
979 if a typedef name appears then it is being redeclared. */
984 { /* For a typedef name, record the meaning, not the name.
985 In case of `foo foo, bar;'. */
986 $$ = lookup_name ($1); }
988 | CLASSNAME protocolrefs
989 { $$ = get_static_reference ($1, $2); }
990 | OBJECTNAME protocolrefs
991 { $$ = get_object_reference ($2); }
993 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>"
994 - nisse@lysator.liu.se */
995 | non_empty_protocolrefs
996 { $$ = get_object_reference ($1); }
998 | TYPEOF '(' expr ')'
999 { $$ = TREE_TYPE ($3); }
1000 | TYPEOF '(' typename ')'
1001 { $$ = groktypename ($3); }
1004 /* A typespec that is a reserved word, or a type qualifier. */
1006 typespecqual_reserved: TYPESPEC
1013 | initdecls ',' initdcl
1018 | notype_initdecls ',' initdcl
1024 | ASM_KEYWORD '(' string ')'
1025 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
1031 declarator maybeasm maybe_attribute '='
1032 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1033 $3, prefix_attributes);
1034 start_init ($<ttype>$, $2, global_bindings_p ()); }
1036 /* Note how the declaration of the variable is in effect while its init is parsed! */
1038 finish_decl ($<ttype>5, $6, $2); }
1039 | declarator maybeasm maybe_attribute
1040 { tree d = start_decl ($1, current_declspecs, 0,
1041 $3, prefix_attributes);
1042 finish_decl (d, NULL_TREE, $2);
1047 notype_declarator maybeasm maybe_attribute '='
1048 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1049 $3, prefix_attributes);
1050 start_init ($<ttype>$, $2, global_bindings_p ()); }
1052 /* Note how the declaration of the variable is in effect while its init is parsed! */
1054 decl_attributes ($<ttype>5, $3, prefix_attributes);
1055 finish_decl ($<ttype>5, $6, $2); }
1056 | notype_declarator maybeasm maybe_attribute
1057 { tree d = start_decl ($1, current_declspecs, 0,
1058 $3, prefix_attributes);
1059 finish_decl (d, NULL_TREE, $2); }
1061 /* the * rules are dummies to accept the Apollo extended syntax
1062 so that the header files compile. */
1073 | attributes attribute
1074 { $$ = chainon ($1, $2); }
1078 ATTRIBUTE '(' '(' attribute_list ')' ')'
1085 | attribute_list ',' attrib
1086 { $$ = chainon ($1, $3); }
1093 { $$ = build_tree_list ($1, NULL_TREE); }
1094 | any_word '(' IDENTIFIER ')'
1095 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1096 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1097 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1098 | any_word '(' exprlist ')'
1099 { $$ = build_tree_list ($1, $3); }
1102 /* This still leaves out most reserved keywords,
1103 shouldn't we include them? */
1112 /* Initializers. `init' is the entry point. */
1117 { really_start_incremental_init (NULL_TREE); }
1118 initlist_maybe_comma '}'
1119 { $$ = pop_init_level (0); }
1121 { $$ = error_mark_node; }
1124 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1125 initlist_maybe_comma:
1128 pedwarn ("ISO C forbids empty initializer braces"); }
1129 | initlist1 maybecomma
1134 | initlist1 ',' initelt
1137 /* `initelt' is a single element of an initializer.
1138 It may use braces. */
1140 designator_list '=' initval
1141 | designator initval
1143 { set_init_label ($1); }
1150 { push_init_level (0); }
1151 initlist_maybe_comma '}'
1152 { process_init_element (pop_init_level (0)); }
1154 { process_init_element ($1); }
1160 | designator_list designator
1165 { set_init_label ($2); }
1166 /* These are for labeled elements. The syntax for an array element
1167 initializer conflicts with the syntax for an Objective-C message,
1168 so don't include these productions in the Objective-C grammar. */
1170 | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
1171 { set_init_index ($2, $4); }
1172 | '[' expr_no_commas ']'
1173 { set_init_index ($2, NULL_TREE); }
1180 pedwarn ("ISO C forbids nested functions");
1182 push_function_context ();
1183 if (! start_function (current_declspecs, $1,
1184 prefix_attributes, NULL_TREE))
1186 pop_function_context ();
1190 old_style_parm_decls
1191 { store_parm_decls (); }
1192 /* This used to use compstmt_or_error.
1193 That caused a bug with input `f(g) int g {}',
1194 where the use of YYERROR1 above caused an error
1195 which then was handled by compstmt_or_error.
1196 There followed a repeated execution of that same rule,
1197 which called YYERROR1 again, and so on. */
1199 { finish_function (1);
1200 pop_function_context (); }
1203 notype_nested_function:
1206 pedwarn ("ISO C forbids nested functions");
1208 push_function_context ();
1209 if (! start_function (current_declspecs, $1,
1210 prefix_attributes, NULL_TREE))
1212 pop_function_context ();
1216 old_style_parm_decls
1217 { store_parm_decls (); }
1218 /* This used to use compstmt_or_error.
1219 That caused a bug with input `f(g) int g {}',
1220 where the use of YYERROR1 above caused an error
1221 which then was handled by compstmt_or_error.
1222 There followed a repeated execution of that same rule,
1223 which called YYERROR1 again, and so on. */
1225 { finish_function (1);
1226 pop_function_context (); }
1229 /* Any kind of declarator (thus, all declarators allowed
1230 after an explicit typespec). */
1233 after_type_declarator
1237 /* A declarator that is allowed only after an explicit typespec. */
1239 after_type_declarator:
1240 '(' after_type_declarator ')'
1242 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1243 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1244 /* | after_type_declarator '(' error ')' %prec '.'
1245 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1246 poplevel (0, 0, 0); } */
1247 | after_type_declarator '[' expr ']' %prec '.'
1248 { $$ = build_nt (ARRAY_REF, $1, $3); }
1249 | after_type_declarator '[' ']' %prec '.'
1250 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1251 | '*' type_quals after_type_declarator %prec UNARY
1252 { $$ = make_pointer_declarator ($2, $3); }
1253 /* ??? Yuck. setattrs is a quick hack. We can't use
1254 prefix_attributes because $1 only applies to this
1255 declarator. We assume setspecs has already been done.
1256 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1257 attributes could be recognized here or in `attributes'). */
1258 | attributes setattrs after_type_declarator
1266 /* Kinds of declarator that can appear in a parameter list
1267 in addition to notype_declarator. This is like after_type_declarator
1268 but does not allow a typedef name in parentheses as an identifier
1269 (because it would conflict with a function with that typedef as arg). */
1272 parm_declarator '(' parmlist_or_identifiers %prec '.'
1273 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1274 /* | parm_declarator '(' error ')' %prec '.'
1275 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1276 poplevel (0, 0, 0); } */
1278 | parm_declarator '[' '*' ']' %prec '.'
1279 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1281 error ("`[*]' in parameter declaration only allowed in ISO C 99");
1284 | parm_declarator '[' expr ']' %prec '.'
1285 { $$ = build_nt (ARRAY_REF, $1, $3); }
1286 | parm_declarator '[' ']' %prec '.'
1287 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1288 | '*' type_quals parm_declarator %prec UNARY
1289 { $$ = make_pointer_declarator ($2, $3); }
1290 /* ??? Yuck. setattrs is a quick hack. We can't use
1291 prefix_attributes because $1 only applies to this
1292 declarator. We assume setspecs has already been done.
1293 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1294 attributes could be recognized here or in `attributes'). */
1295 | attributes setattrs parm_declarator
1300 /* A declarator allowed whether or not there has been
1301 an explicit typespec. These cannot redeclare a typedef-name. */
1304 notype_declarator '(' parmlist_or_identifiers %prec '.'
1305 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1306 /* | notype_declarator '(' error ')' %prec '.'
1307 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1308 poplevel (0, 0, 0); } */
1309 | '(' notype_declarator ')'
1311 | '*' type_quals notype_declarator %prec UNARY
1312 { $$ = make_pointer_declarator ($2, $3); }
1314 | notype_declarator '[' '*' ']' %prec '.'
1315 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1317 error ("`[*]' in parameter declaration only allowed in ISO C 99");
1320 | notype_declarator '[' expr ']' %prec '.'
1321 { $$ = build_nt (ARRAY_REF, $1, $3); }
1322 | notype_declarator '[' ']' %prec '.'
1323 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1324 /* ??? Yuck. setattrs is a quick hack. We can't use
1325 prefix_attributes because $1 only applies to this
1326 declarator. We assume setspecs has already been done.
1327 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1328 attributes could be recognized here or in `attributes'). */
1329 | attributes setattrs notype_declarator
1356 struct_head identifier '{'
1357 { $$ = start_struct (RECORD_TYPE, $2);
1358 /* Start scope of tag before parsing components. */
1360 component_decl_list '}' maybe_attribute
1361 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1362 | struct_head '{' component_decl_list '}' maybe_attribute
1363 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1364 $3, chainon ($1, $5));
1366 | struct_head identifier
1367 { $$ = xref_tag (RECORD_TYPE, $2); }
1368 | union_head identifier '{'
1369 { $$ = start_struct (UNION_TYPE, $2); }
1370 component_decl_list '}' maybe_attribute
1371 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1372 | union_head '{' component_decl_list '}' maybe_attribute
1373 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1374 $3, chainon ($1, $5));
1376 | union_head identifier
1377 { $$ = xref_tag (UNION_TYPE, $2); }
1378 | enum_head identifier '{'
1379 { $$ = start_enum ($2); }
1380 enumlist maybecomma_warn '}' maybe_attribute
1381 { $$ = finish_enum ($<ttype>4, nreverse ($5),
1382 chainon ($1, $8)); }
1384 { $$ = start_enum (NULL_TREE); }
1385 enumlist maybecomma_warn '}' maybe_attribute
1386 { $$ = finish_enum ($<ttype>3, nreverse ($4),
1387 chainon ($1, $7)); }
1388 | enum_head identifier
1389 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1400 { if (pedantic && ! flag_isoc99)
1401 pedwarn ("comma at end of enumerator list"); }
1404 component_decl_list:
1405 component_decl_list2
1407 | component_decl_list2 component_decl
1408 { $$ = chainon ($1, $2);
1409 pedwarn ("no semicolon at end of struct or union"); }
1412 component_decl_list2: /* empty */
1414 | component_decl_list2 component_decl ';'
1415 { $$ = chainon ($1, $2); }
1416 | component_decl_list2 ';'
1418 pedwarn ("extra semicolon in struct or union specified"); }
1420 /* foo(sizeof(struct{ @defs(ClassName)})); */
1421 | DEFS '(' CLASSNAME ')'
1423 tree interface = lookup_interface ($3);
1426 $$ = get_class_ivars (interface);
1429 error ("Cannot find interface declaration for `%s'",
1430 IDENTIFIER_POINTER ($3));
1437 /* There is a shift-reduce conflict here, because `components' may
1438 start with a `typename'. It happens that shifting (the default resolution)
1439 does the right thing, because it treats the `typename' as part of
1440 a `typed_typespecs'.
1442 It is possible that this same technique would allow the distinction
1443 between `notype_initdecls' and `initdecls' to be eliminated.
1444 But I am being cautious and not trying it. */
1447 typed_typespecs setspecs components
1449 current_declspecs = TREE_VALUE (declspec_stack);
1450 prefix_attributes = TREE_PURPOSE (declspec_stack);
1451 declspec_stack = TREE_CHAIN (declspec_stack); }
1452 | typed_typespecs setspecs save_filename save_lineno maybe_attribute
1454 /* Support for unnamed structs or unions as members of
1455 structs or unions (which is [a] useful and [b] supports
1458 pedwarn ("ISO C doesn't support unnamed structs/unions");
1460 $$ = grokfield($3, $4, NULL, current_declspecs, NULL_TREE);
1461 current_declspecs = TREE_VALUE (declspec_stack);
1462 prefix_attributes = TREE_PURPOSE (declspec_stack);
1463 declspec_stack = TREE_CHAIN (declspec_stack);
1465 | nonempty_type_quals setspecs components
1467 current_declspecs = TREE_VALUE (declspec_stack);
1468 prefix_attributes = TREE_PURPOSE (declspec_stack);
1469 declspec_stack = TREE_CHAIN (declspec_stack); }
1470 | nonempty_type_quals
1472 pedwarn ("ISO C forbids member declarations with no members");
1477 | extension component_decl
1479 RESTORE_WARN_FLAGS ($1); }
1483 component_declarator
1484 | components ',' component_declarator
1485 { $$ = chainon ($1, $3); }
1488 component_declarator:
1489 save_filename save_lineno declarator maybe_attribute
1490 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1491 decl_attributes ($$, $4, prefix_attributes); }
1492 | save_filename save_lineno
1493 declarator ':' expr_no_commas maybe_attribute
1494 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1495 decl_attributes ($$, $6, prefix_attributes); }
1496 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1497 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1498 decl_attributes ($$, $5, prefix_attributes); }
1501 /* We chain the enumerators in reverse order.
1502 They are put in forward order where enumlist is used.
1503 (The order used to be significant, but no longer is so.
1504 However, we still maintain the order, just to be clean.) */
1508 | enumlist ',' enumerator
1509 { if ($1 == error_mark_node)
1512 $$ = chainon ($3, $1); }
1514 { $$ = error_mark_node; }
1520 { $$ = build_enumerator ($1, NULL_TREE); }
1521 | identifier '=' expr_no_commas
1522 { $$ = build_enumerator ($1, $3); }
1526 typed_typespecs absdcl
1527 { $$ = build_tree_list ($1, $2); }
1528 | nonempty_type_quals absdcl
1529 { $$ = build_tree_list ($1, $2); }
1532 absdcl: /* an absolute declarator */
1538 nonempty_type_quals:
1540 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1541 | nonempty_type_quals TYPE_QUAL
1542 { $$ = tree_cons (NULL_TREE, $2, $1); }
1548 | type_quals TYPE_QUAL
1549 { $$ = tree_cons (NULL_TREE, $2, $1); }
1552 absdcl1: /* a nonempty absolute declarator */
1555 /* `(typedef)1' is `int'. */
1556 | '*' type_quals absdcl1 %prec UNARY
1557 { $$ = make_pointer_declarator ($2, $3); }
1558 | '*' type_quals %prec UNARY
1559 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1560 | absdcl1 '(' parmlist %prec '.'
1561 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1562 | absdcl1 '[' expr ']' %prec '.'
1563 { $$ = build_nt (ARRAY_REF, $1, $3); }
1564 | absdcl1 '[' ']' %prec '.'
1565 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1566 | '(' parmlist %prec '.'
1567 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1568 | '[' expr ']' %prec '.'
1569 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1571 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1572 /* ??? It appears we have to support attributes here, however
1573 using prefix_attributes is wrong. */
1574 | attributes setattrs absdcl1
1578 /* at least one statement, the first of which parses without error. */
1579 /* stmts is used only after decls, so an invalid first statement
1580 is actually regarded as an invalid decl and part of the decls. */
1583 lineno_stmt_or_labels
1586 pedwarn ("ISO C forbids label at end of compound statement");
1590 lineno_stmt_or_labels:
1591 lineno_stmt_or_label
1592 | lineno_stmt_or_labels lineno_stmt_or_label
1594 | lineno_stmt_or_labels errstmt
1606 pushlevel: /* empty */
1607 { emit_line_note (input_filename, lineno);
1610 expand_start_bindings (0);
1612 if (objc_method_context)
1618 /* Read zero or more forward-declarations for labels
1619 that nested functions can jump to. */
1624 pedwarn ("ISO C forbids label declarations"); }
1629 | label_decls label_decl
1633 LABEL identifiers_or_typenames ';'
1635 for (link = $2; link; link = TREE_CHAIN (link))
1637 tree label = shadow_label (TREE_VALUE (link));
1638 C_DECLARED_LABEL_FLAG (label) = 1;
1639 declare_nonlocal_label (label);
1644 /* This is the body of a function definition.
1645 It causes syntax errors to ignore to the next openbrace. */
1652 compstmt_start: '{' { compstmt_count++; }
1654 compstmt_nostart: '}'
1655 { $$ = convert (void_type_node, integer_zero_node); }
1656 | pushlevel maybe_label_decls decls xstmts '}'
1657 { emit_line_note (input_filename, lineno);
1658 expand_end_bindings (getdecls (), 1, 0);
1659 $$ = poplevel (1, 1, 0); }
1660 | pushlevel maybe_label_decls error '}'
1661 { emit_line_note (input_filename, lineno);
1662 expand_end_bindings (getdecls (), kept_level_p (), 0);
1663 $$ = poplevel (kept_level_p (), 0, 0); }
1664 | pushlevel maybe_label_decls stmts '}'
1665 { emit_line_note (input_filename, lineno);
1666 expand_end_bindings (getdecls (), kept_level_p (), 0);
1667 $$ = poplevel (kept_level_p (), 0, 0); }
1670 compstmt_primary_start:
1672 { if (current_function_decl == 0)
1674 error ("braced-group within expression allowed only inside a function");
1677 /* We must force a BLOCK for this level
1678 so that, if it is not expanded later,
1679 there is a way to turn off the entire subtree of blocks
1680 that are contained in it. */
1682 push_label_level ();
1683 $$ = expand_start_stmt_expr ();
1687 compstmt: compstmt_start compstmt_nostart
1691 /* Value is number of statements counted as of the closeparen. */
1693 if_prefix lineno_labeled_stmt
1694 /* Make sure c_expand_end_cond is run once
1695 for each call to c_expand_start_cond.
1696 Otherwise a crash is likely. */
1702 { emit_line_note ($<filename>-1, $<lineno>0);
1703 c_expand_start_cond (truthvalue_conversion ($3), 0,
1705 $<itype>$ = stmt_count;
1706 if_stmt_file = $<filename>-1;
1707 if_stmt_line = $<lineno>0; }
1710 /* This is a subroutine of stmt.
1711 It is used twice, once for valid DO statements
1712 and once for catching errors in parsing the end test. */
1717 emit_line_note ($<filename>-1, $<lineno>0);
1718 /* See comment in `while' alternative, above. */
1720 expand_start_loop_continue_elsewhere (1); }
1721 lineno_labeled_stmt WHILE
1722 { expand_loop_continue_here (); }
1725 /* The forced readahead in here is because we might be at the end of a
1726 line, and the line and file won't be bumped until yylex absorbs the
1727 first token on the next line. */
1729 { if (yychar == YYEMPTY)
1731 $$ = input_filename; }
1735 { if (yychar == YYEMPTY)
1740 lineno_labeled_stmt:
1741 save_filename save_lineno stmt
1743 /* | save_filename save_lineno error
1746 | save_filename save_lineno label lineno_labeled_stmt
1750 lineno_stmt_or_label:
1751 save_filename save_lineno stmt_or_label
1762 /* Parse a single real statement, not including any labels. */
1768 emit_line_note ($<filename>-1, $<lineno>0);
1769 /* It appears that this should not be done--that a non-lvalue array
1770 shouldn't get an error if the value isn't used.
1771 Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1772 if it appears as a top-level expression,
1773 but says nothing about non-lvalue arrays. */
1775 /* Call default_conversion to get an error
1776 on referring to a register array if pedantic. */
1777 if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1778 || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1779 $1 = default_conversion ($1);
1781 expand_expr_stmt ($1); }
1783 { c_expand_start_else ();
1784 $<itype>1 = stmt_count; }
1786 { c_expand_end_cond ();
1787 if (extra_warnings && stmt_count == $<itype>1)
1788 warning ("empty body in an else-statement"); }
1789 | simple_if %prec IF
1790 { c_expand_end_cond ();
1791 /* This warning is here instead of in simple_if, because we
1792 do not want a warning if an empty if is followed by an
1793 else statement. Increment stmt_count so we don't
1794 give a second error if this is a nested `if'. */
1795 if (extra_warnings && stmt_count++ == $<itype>1)
1796 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1797 "empty body in an if-statement"); }
1798 /* Make sure c_expand_end_cond is run once
1799 for each call to c_expand_start_cond.
1800 Otherwise a crash is likely. */
1801 | simple_if ELSE error
1802 { c_expand_end_cond (); }
1805 emit_line_note ($<filename>-1, $<lineno>0);
1806 /* The emit_nop used to come before emit_line_note,
1807 but that made the nop seem like part of the preceding line.
1808 And that was confusing when the preceding line was
1809 inside of an if statement and was not really executed.
1810 I think it ought to work to put the nop after the line number.
1811 We will see. --rms, July 15, 1991. */
1814 { /* Don't start the loop till we have succeeded
1815 in parsing the end test. This is to make sure
1816 that we end every loop we start. */
1817 expand_start_loop (1);
1818 emit_line_note (input_filename, lineno);
1819 expand_exit_loop_if_false (NULL_PTR,
1820 truthvalue_conversion ($4)); }
1822 { expand_end_loop (); }
1825 { emit_line_note (input_filename, lineno);
1826 expand_exit_loop_if_false (NULL_PTR,
1827 truthvalue_conversion ($3));
1828 expand_end_loop (); }
1829 /* This rule is needed to make sure we end every loop we start. */
1830 | do_stmt_start error
1831 { expand_end_loop (); }
1835 emit_line_note ($<filename>-1, $<lineno>0);
1836 /* See comment in `while' alternative, above. */
1838 if ($3) c_expand_expr_stmt ($3);
1839 /* Next step is to call expand_start_loop_continue_elsewhere,
1840 but wait till after we parse the entire for (...).
1841 Otherwise, invalid input might cause us to call that
1842 fn without calling expand_end_loop. */
1845 /* Can't emit now; wait till after expand_start_loop... */
1846 { $<lineno>7 = lineno;
1847 $<filename>$ = input_filename; }
1850 /* Start the loop. Doing this after parsing
1851 all the expressions ensures we will end the loop. */
1852 expand_start_loop_continue_elsewhere (1);
1853 /* Emit the end-test, with a line number. */
1854 emit_line_note ($<filename>8, $<lineno>7);
1856 expand_exit_loop_if_false (NULL_PTR,
1857 truthvalue_conversion ($6));
1858 $<lineno>7 = lineno;
1859 $<filename>8 = input_filename; }
1861 { /* Emit the increment expression, with a line number. */
1862 emit_line_note ($<filename>8, $<lineno>7);
1863 expand_loop_continue_here ();
1865 c_expand_expr_stmt ($9);
1866 expand_end_loop (); }
1867 | SWITCH '(' expr ')'
1869 emit_line_note ($<filename>-1, $<lineno>0);
1870 c_expand_start_case ($3); }
1872 { expand_end_case ($3); }
1874 { build_break_stmt ();
1876 genrtl_break_stmt (); }
1878 { build_continue_stmt ();
1880 genrtl_continue_stmt (); }
1883 c_expand_return (NULL_TREE); }
1886 c_expand_return ($2); }
1887 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
1889 emit_line_note ($<filename>-1, $<lineno>0);
1891 if ((TREE_CODE ($4) == ADDR_EXPR
1892 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
1893 || TREE_CODE ($4) == STRING_CST)
1896 error ("argument of `asm' is not a constant string"); }
1897 /* This is the case with just output operands. */
1898 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
1900 emit_line_note ($<filename>-1, $<lineno>0);
1901 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
1902 $2 == ridpointers[(int)RID_VOLATILE],
1903 input_filename, lineno); }
1904 /* This is the case with input operands as well. */
1905 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
1907 emit_line_note ($<filename>-1, $<lineno>0);
1908 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
1909 $2 == ridpointers[(int)RID_VOLATILE],
1910 input_filename, lineno); }
1911 /* This is the case with clobbered registers as well. */
1912 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
1913 asm_operands ':' asm_clobbers ')' ';'
1915 emit_line_note ($<filename>-1, $<lineno>0);
1916 c_expand_asm_operands ($4, $6, $8, $10,
1917 $2 == ridpointers[(int)RID_VOLATILE],
1918 input_filename, lineno); }
1919 | GOTO identifier ';'
1922 emit_line_note ($<filename>-1, $<lineno>0);
1923 decl = lookup_label ($2);
1926 TREE_USED (decl) = 1;
1932 pedwarn ("ISO C forbids `goto *expr;'");
1934 emit_line_note ($<filename>-1, $<lineno>0);
1935 expand_computed_goto (convert (ptr_type_node, $3)); }
1939 /* Any kind of label, including jump labels and case labels.
1940 ANSI C accepts labels only before statements, but we allow them
1941 also at the end of a compound statement. */
1943 label: CASE expr_no_commas ':'
1945 do_case ($2, NULL_TREE); }
1946 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
1951 do_case (NULL_TREE, NULL_TREE); }
1952 | identifier save_filename save_lineno ':' maybe_attribute
1953 { tree label = define_label ($2, $3, $1);
1958 expand_label (label);
1959 decl_attributes (label, $5, NULL_TREE);
1964 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
1968 { emit_line_note (input_filename, lineno);
1971 { emit_line_note (input_filename, lineno); }
1980 /* These are the operands other than the first string and colon
1981 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
1982 asm_operands: /* empty */
1984 | nonnull_asm_operands
1987 nonnull_asm_operands:
1989 | nonnull_asm_operands ',' asm_operand
1990 { $$ = chainon ($1, $3); }
1995 { $$ = build_tree_list ($1, $3); }
2000 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
2001 | asm_clobbers ',' string
2002 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
2005 /* This is what appears inside the parens in a function declarator.
2006 Its value is a list of ..._TYPE nodes. */
2009 clear_parm_order ();
2010 declare_parm_level (0); }
2013 parmlist_tags_warning ();
2014 poplevel (0, 0, 0); }
2022 pedwarn ("ISO C forbids forward parameter declarations");
2023 /* Mark the forward decls as such. */
2024 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2025 TREE_ASM_WRITTEN (parm) = 1;
2026 clear_parm_order (); }
2030 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2033 /* This is what appears inside the parens in a function declarator.
2034 Is value is represented in the format that grokdeclarator expects. */
2035 parmlist_2: /* empty */
2036 { $$ = get_parm_info (0); }
2038 { $$ = get_parm_info (0);
2039 /* Gcc used to allow this as an extension. However, it does
2040 not work for all targets, and thus has been disabled.
2041 Also, since func (...) and func () are indistinguishable,
2042 it caused problems with the code in expand_builtin which
2043 tries to verify that BUILT_IN_NEXT_ARG is being used
2045 error ("ISO C requires a named argument before `...'");
2048 { $$ = get_parm_info (1); }
2049 | parms ',' ELLIPSIS
2050 { $$ = get_parm_info (0); }
2055 { push_parm_decl ($1); }
2057 { push_parm_decl ($3); }
2060 /* A single parameter declaration or parameter type name,
2061 as found in a parmlist. */
2063 typed_declspecs setspecs parm_declarator maybe_attribute
2064 { $$ = build_tree_list (build_tree_list (current_declspecs,
2066 build_tree_list (prefix_attributes,
2068 current_declspecs = TREE_VALUE (declspec_stack);
2069 prefix_attributes = TREE_PURPOSE (declspec_stack);
2070 declspec_stack = TREE_CHAIN (declspec_stack); }
2071 | typed_declspecs setspecs notype_declarator maybe_attribute
2072 { $$ = build_tree_list (build_tree_list (current_declspecs,
2074 build_tree_list (prefix_attributes,
2076 current_declspecs = TREE_VALUE (declspec_stack);
2077 prefix_attributes = TREE_PURPOSE (declspec_stack);
2078 declspec_stack = TREE_CHAIN (declspec_stack); }
2079 | typed_declspecs setspecs absdcl maybe_attribute
2080 { $$ = build_tree_list (build_tree_list (current_declspecs,
2082 build_tree_list (prefix_attributes,
2084 current_declspecs = TREE_VALUE (declspec_stack);
2085 prefix_attributes = TREE_PURPOSE (declspec_stack);
2086 declspec_stack = TREE_CHAIN (declspec_stack); }
2087 | declmods setspecs notype_declarator maybe_attribute
2088 { $$ = build_tree_list (build_tree_list (current_declspecs,
2090 build_tree_list (prefix_attributes,
2092 current_declspecs = TREE_VALUE (declspec_stack);
2093 prefix_attributes = TREE_PURPOSE (declspec_stack);
2094 declspec_stack = TREE_CHAIN (declspec_stack); }
2096 | declmods setspecs absdcl maybe_attribute
2097 { $$ = build_tree_list (build_tree_list (current_declspecs,
2099 build_tree_list (prefix_attributes,
2101 current_declspecs = TREE_VALUE (declspec_stack);
2102 prefix_attributes = TREE_PURPOSE (declspec_stack);
2103 declspec_stack = TREE_CHAIN (declspec_stack); }
2106 /* This is used in a function definition
2107 where either a parmlist or an identifier list is ok.
2108 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2109 parmlist_or_identifiers:
2111 clear_parm_order ();
2112 declare_parm_level (1); }
2113 parmlist_or_identifiers_1
2115 parmlist_tags_warning ();
2116 poplevel (0, 0, 0); }
2119 parmlist_or_identifiers_1:
2123 for (t = $1; t; t = TREE_CHAIN (t))
2124 if (TREE_VALUE (t) == NULL_TREE)
2125 error ("`...' in old-style identifier list");
2126 $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2129 /* A nonempty list of identifiers. */
2132 { $$ = build_tree_list (NULL_TREE, $1); }
2133 | identifiers ',' IDENTIFIER
2134 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2137 /* A nonempty list of identifiers, including typenames. */
2138 identifiers_or_typenames:
2140 { $$ = build_tree_list (NULL_TREE, $1); }
2141 | identifiers_or_typenames ',' identifier
2142 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2147 { $$ = SAVE_WARN_FLAGS();
2149 warn_pointer_arith = 0; }
2153 /* Objective-C productions. */
2163 if (objc_implementation_context)
2165 finish_class (objc_implementation_context);
2166 objc_ivar_chain = NULL_TREE;
2167 objc_implementation_context = NULL_TREE;
2170 warning ("`@end' must appear in an implementation context");
2174 /* A nonempty list of identifiers. */
2177 { $$ = build_tree_list (NULL_TREE, $1); }
2178 | identifier_list ',' identifier
2179 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2183 CLASS identifier_list ';'
2185 objc_declare_class ($2);
2189 ALIAS identifier identifier ';'
2191 objc_declare_alias ($2, $3);
2195 INTERFACE identifier protocolrefs '{'
2197 objc_interface_context = objc_ivar_context
2198 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2199 objc_public_flag = 0;
2203 continue_class (objc_interface_context);
2208 finish_class (objc_interface_context);
2209 objc_interface_context = NULL_TREE;
2212 | INTERFACE identifier protocolrefs
2214 objc_interface_context
2215 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2216 continue_class (objc_interface_context);
2221 finish_class (objc_interface_context);
2222 objc_interface_context = NULL_TREE;
2225 | INTERFACE identifier ':' identifier protocolrefs '{'
2227 objc_interface_context = objc_ivar_context
2228 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2229 objc_public_flag = 0;
2233 continue_class (objc_interface_context);
2238 finish_class (objc_interface_context);
2239 objc_interface_context = NULL_TREE;
2242 | INTERFACE identifier ':' identifier protocolrefs
2244 objc_interface_context
2245 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2246 continue_class (objc_interface_context);
2251 finish_class (objc_interface_context);
2252 objc_interface_context = NULL_TREE;
2255 | IMPLEMENTATION identifier '{'
2257 objc_implementation_context = objc_ivar_context
2258 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2259 objc_public_flag = 0;
2264 = continue_class (objc_implementation_context);
2267 | IMPLEMENTATION identifier
2269 objc_implementation_context
2270 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2272 = continue_class (objc_implementation_context);
2275 | IMPLEMENTATION identifier ':' identifier '{'
2277 objc_implementation_context = objc_ivar_context
2278 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2279 objc_public_flag = 0;
2284 = continue_class (objc_implementation_context);
2287 | IMPLEMENTATION identifier ':' identifier
2289 objc_implementation_context
2290 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2292 = continue_class (objc_implementation_context);
2295 | INTERFACE identifier '(' identifier ')' protocolrefs
2297 objc_interface_context
2298 = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2299 continue_class (objc_interface_context);
2304 finish_class (objc_interface_context);
2305 objc_interface_context = NULL_TREE;
2308 | IMPLEMENTATION identifier '(' identifier ')'
2310 objc_implementation_context
2311 = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2313 = continue_class (objc_implementation_context);
2318 PROTOCOL identifier protocolrefs
2320 remember_protocol_qualifiers ();
2321 objc_interface_context
2322 = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2326 forget_protocol_qualifiers();
2327 finish_protocol(objc_interface_context);
2328 objc_interface_context = NULL_TREE;
2337 | non_empty_protocolrefs
2340 non_empty_protocolrefs:
2341 ARITHCOMPARE identifier_list ARITHCOMPARE
2343 if ($1 == LT_EXPR && $3 == GT_EXPR)
2351 ivar_decl_list visibility_spec ivar_decls
2356 PRIVATE { objc_public_flag = 2; }
2357 | PROTECTED { objc_public_flag = 0; }
2358 | PUBLIC { objc_public_flag = 1; }
2366 | ivar_decls ivar_decl ';'
2370 pedwarn ("extra semicolon in struct or union specified");
2375 /* There is a shift-reduce conflict here, because `components' may
2376 start with a `typename'. It happens that shifting (the default resolution)
2377 does the right thing, because it treats the `typename' as part of
2378 a `typed_typespecs'.
2380 It is possible that this same technique would allow the distinction
2381 between `notype_initdecls' and `initdecls' to be eliminated.
2382 But I am being cautious and not trying it. */
2385 typed_typespecs setspecs ivars
2387 current_declspecs = TREE_VALUE (declspec_stack);
2388 prefix_attributes = TREE_PURPOSE (declspec_stack);
2389 declspec_stack = TREE_CHAIN (declspec_stack); }
2390 | nonempty_type_quals setspecs ivars
2392 current_declspecs = TREE_VALUE (declspec_stack);
2393 prefix_attributes = TREE_PURPOSE (declspec_stack);
2394 declspec_stack = TREE_CHAIN (declspec_stack); }
2403 | ivars ',' ivar_declarator
2409 $$ = add_instance_variable (objc_ivar_context,
2411 $1, current_declspecs,
2414 | declarator ':' expr_no_commas
2416 $$ = add_instance_variable (objc_ivar_context,
2418 $1, current_declspecs, $3);
2420 | ':' expr_no_commas
2422 $$ = add_instance_variable (objc_ivar_context,
2425 current_declspecs, $2);
2432 remember_protocol_qualifiers ();
2433 if (objc_implementation_context)
2434 objc_inherit_code = CLASS_METHOD_DECL;
2436 fatal ("method definition not in class context");
2440 forget_protocol_qualifiers ();
2441 add_class_method (objc_implementation_context, $3);
2442 start_method_def ($3);
2443 objc_method_context = $3;
2447 continue_method_def ();
2451 finish_method_def ();
2452 objc_method_context = NULL_TREE;
2457 remember_protocol_qualifiers ();
2458 if (objc_implementation_context)
2459 objc_inherit_code = INSTANCE_METHOD_DECL;
2461 fatal ("method definition not in class context");
2465 forget_protocol_qualifiers ();
2466 add_instance_method (objc_implementation_context, $3);
2467 start_method_def ($3);
2468 objc_method_context = $3;
2472 continue_method_def ();
2476 finish_method_def ();
2477 objc_method_context = NULL_TREE;
2481 /* the reason for the strange actions in this rule
2482 is so that notype_initdecls when reached via datadef
2483 can find a valid list of type and sc specs in $0. */
2487 | {$<ttype>$ = NULL_TREE; } methodprotolist2
2490 methodprotolist2: /* eliminates a shift/reduce conflict */
2493 | methodprotolist2 methodproto
2494 | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
2505 /* Remember protocol qualifiers in prototypes. */
2506 remember_protocol_qualifiers ();
2507 objc_inherit_code = CLASS_METHOD_DECL;
2511 /* Forget protocol qualifiers here. */
2512 forget_protocol_qualifiers ();
2513 add_class_method (objc_interface_context, $3);
2519 /* Remember protocol qualifiers in prototypes. */
2520 remember_protocol_qualifiers ();
2521 objc_inherit_code = INSTANCE_METHOD_DECL;
2525 /* Forget protocol qualifiers here. */
2526 forget_protocol_qualifiers ();
2527 add_instance_method (objc_interface_context, $3);
2533 '(' typename ')' unaryselector
2535 $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
2540 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
2543 | '(' typename ')' keywordselector optparmlist
2545 $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
2548 | keywordselector optparmlist
2550 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
2554 /* "optarglist" assumes that start_method_def has already been called...
2555 if it is not, the "xdecls" will not be placed in the proper scope */
2562 /* to get around the following situation: "int foo (int a) int b; {}" that
2563 is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
2578 typed_declspecs setspecs myparms ';'
2579 { current_declspecs = TREE_VALUE (declspec_stack);
2580 prefix_attributes = TREE_PURPOSE (declspec_stack);
2581 declspec_stack = TREE_CHAIN (declspec_stack); }
2582 | typed_declspecs ';'
2583 { shadow_tag ($1); }
2585 { pedwarn ("empty declaration"); }
2590 { push_parm_decl ($1); }
2591 | myparms ',' myparm
2592 { push_parm_decl ($3); }
2595 /* A single parameter declaration or parameter type name,
2596 as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
2599 parm_declarator maybe_attribute
2600 { $$ = build_tree_list (build_tree_list (current_declspecs,
2602 build_tree_list (prefix_attributes,
2604 | notype_declarator maybe_attribute
2605 { $$ = build_tree_list (build_tree_list (current_declspecs,
2607 build_tree_list (prefix_attributes,
2609 | absdcl maybe_attribute
2610 { $$ = build_tree_list (build_tree_list (current_declspecs,
2612 build_tree_list (prefix_attributes,
2623 /* oh what a kludge! */
2624 $$ = objc_ellipsis_node;
2632 /* returns a tree list node generated by get_parm_info */
2645 | keywordselector keyworddecl
2647 $$ = chainon ($1, $2);
2659 ENUM | STRUCT | UNION | IF | ELSE | WHILE | DO | FOR
2660 | SWITCH | CASE | DEFAULT | BREAK | CONTINUE | RETURN
2661 | GOTO | ASM_KEYWORD | SIZEOF | TYPEOF | ALIGNOF
2662 | TYPESPEC | TYPE_QUAL
2666 selector ':' '(' typename ')' identifier
2668 $$ = build_keyword_decl ($1, $4, $6);
2671 | selector ':' identifier
2673 $$ = build_keyword_decl ($1, NULL_TREE, $3);
2676 | ':' '(' typename ')' identifier
2678 $$ = build_keyword_decl (NULL_TREE, $3, $5);
2683 $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
2694 | keywordarglist keywordarg
2696 $$ = chainon ($1, $2);
2704 if (TREE_CHAIN ($1) == NULL_TREE)
2705 /* just return the expr., remove a level of indirection */
2706 $$ = TREE_VALUE ($1);
2708 /* we have a comma expr., we will collapse later */
2714 selector ':' keywordexpr
2716 $$ = build_tree_list ($1, $3);
2720 $$ = build_tree_list (NULL_TREE, $2);
2728 $$ = get_class_reference ($1);
2734 { objc_receiver_context = 1; }
2736 { objc_receiver_context = 0; }
2739 $$ = build_tree_list ($3, $5);
2750 | keywordnamelist keywordname
2752 $$ = chainon ($1, $2);
2759 $$ = build_tree_list ($1, NULL_TREE);
2763 $$ = build_tree_list (NULL_TREE, NULL_TREE);
2768 SELECTOR '(' selectorarg ')'
2775 PROTOCOL '(' identifier ')'
2781 /* extension to support C-structures in the archiver */
2784 ENCODE '(' typename ')'
2786 $$ = groktypename ($3);
2793 /* yylex() is a thin wrapper around c_lex(), all it does is translate
2794 cpplib.h's token codes into yacc's token codes. */
2796 static enum cpp_ttype last_token;
2798 extern cpp_reader parse_in;
2801 /* The reserved keyword table. */
2805 ENUM_BITFIELD(rid) rid : 16;
2806 unsigned int disable : 16;
2809 /* Disable mask. Keywords are disabled if (reswords[i].disable & mask) is
2811 #define D_TRAD 0x01 /* not in traditional C */
2812 #define D_C89 0x02 /* not in C89 */
2813 #define D_EXT 0x04 /* GCC extension */
2814 #define D_EXT89 0x08 /* GCC extension incorporated in C99 */
2815 #define D_OBJC 0x10 /* Objective C only */
2816 #define D_YES 0x20 /* always starts disabled */
2818 static const struct resword reswords[] =
2820 { "_Complex", RID_COMPLEX, 0 },
2821 { "__alignof", RID_ALIGNOF, 0 },
2822 { "__alignof__", RID_ALIGNOF, 0 },
2823 { "__asm", RID_ASM, 0 },
2824 { "__asm__", RID_ASM, 0 },
2825 { "__attribute", RID_ATTRIBUTE, 0 },
2826 { "__attribute__", RID_ATTRIBUTE, 0 },
2827 { "__bounded", RID_BOUNDED, 0 },
2828 { "__bounded__", RID_BOUNDED, 0 },
2829 { "__builtin_va_arg", RID_VA_ARG, 0 },
2830 { "__complex", RID_COMPLEX, 0 },
2831 { "__complex__", RID_COMPLEX, 0 },
2832 { "__const", RID_CONST, 0 },
2833 { "__const__", RID_CONST, 0 },
2834 { "__extension__", RID_EXTENSION, 0 },
2835 { "__imag", RID_IMAGPART, 0 },
2836 { "__imag__", RID_IMAGPART, 0 },
2837 { "__inline", RID_INLINE, 0 },
2838 { "__inline__", RID_INLINE, 0 },
2839 { "__label__", RID_LABEL, 0 },
2840 { "__ptrbase", RID_PTRBASE, 0 },
2841 { "__ptrbase__", RID_PTRBASE, 0 },
2842 { "__ptrextent", RID_PTREXTENT, 0 },
2843 { "__ptrextent__", RID_PTREXTENT, 0 },
2844 { "__ptrvalue", RID_PTRVALUE, 0 },
2845 { "__ptrvalue__", RID_PTRVALUE, 0 },
2846 { "__real", RID_REALPART, 0 },
2847 { "__real__", RID_REALPART, 0 },
2848 { "__restrict", RID_RESTRICT, 0 },
2849 { "__restrict__", RID_RESTRICT, 0 },
2850 { "__signed", RID_SIGNED, 0 },
2851 { "__signed__", RID_SIGNED, 0 },
2852 { "__typeof", RID_TYPEOF, 0 },
2853 { "__typeof__", RID_TYPEOF, 0 },
2854 { "__unbounded", RID_UNBOUNDED, 0 },
2855 { "__unbounded__", RID_UNBOUNDED, 0 },
2856 { "__volatile", RID_VOLATILE, 0 },
2857 { "__volatile__", RID_VOLATILE, 0 },
2858 { "asm", RID_ASM, D_EXT },
2859 { "auto", RID_AUTO, 0 },
2860 { "break", RID_BREAK, 0 },
2861 { "case", RID_CASE, 0 },
2862 { "char", RID_CHAR, 0 },
2863 { "const", RID_CONST, D_TRAD },
2864 { "continue", RID_CONTINUE, 0 },
2865 { "default", RID_DEFAULT, 0 },
2866 { "do", RID_DO, 0 },
2867 { "double", RID_DOUBLE, 0 },
2868 { "else", RID_ELSE, 0 },
2869 { "enum", RID_ENUM, 0 },
2870 { "extern", RID_EXTERN, 0 },
2871 { "float", RID_FLOAT, 0 },
2872 { "for", RID_FOR, 0 },
2873 { "goto", RID_GOTO, 0 },
2874 { "if", RID_IF, 0 },
2875 { "inline", RID_INLINE, D_TRAD|D_EXT89 },
2876 { "int", RID_INT, 0 },
2877 { "long", RID_LONG, 0 },
2878 { "register", RID_REGISTER, 0 },
2879 { "restrict", RID_RESTRICT, D_TRAD|D_C89 },
2880 { "return", RID_RETURN, 0 },
2881 { "short", RID_SHORT, 0 },
2882 { "signed", RID_SIGNED, D_TRAD },
2883 { "sizeof", RID_SIZEOF, 0 },
2884 { "static", RID_STATIC, 0 },
2885 { "struct", RID_STRUCT, 0 },
2886 { "switch", RID_SWITCH, 0 },
2887 { "typedef", RID_TYPEDEF, 0 },
2888 { "typeof", RID_TYPEOF, D_TRAD|D_EXT },
2889 { "union", RID_UNION, 0 },
2890 { "unsigned", RID_UNSIGNED, 0 },
2891 { "void", RID_VOID, 0 },
2892 { "volatile", RID_VOLATILE, D_TRAD },
2893 { "while", RID_WHILE, 0 },
2895 { "@class", RID_AT_CLASS, D_OBJC },
2896 { "@compatibility_alias", RID_AT_ALIAS, D_OBJC },
2897 { "@defs", RID_AT_DEFS, D_OBJC },
2898 { "@encode", RID_AT_ENCODE, D_OBJC },
2899 { "@end", RID_AT_END, D_OBJC },
2900 { "@implementation", RID_AT_IMPLEMENTATION, D_OBJC },
2901 { "@interface", RID_AT_INTERFACE, D_OBJC },
2902 { "@private", RID_AT_PRIVATE, D_OBJC },
2903 { "@protected", RID_AT_PROTECTED, D_OBJC },
2904 { "@protocol", RID_AT_PROTOCOL, D_OBJC },
2905 { "@public", RID_AT_PUBLIC, D_OBJC },
2906 { "@selector", RID_AT_SELECTOR, D_OBJC },
2907 { "id", RID_ID, D_OBJC },
2908 { "bycopy", RID_BYCOPY, D_OBJC|D_YES },
2909 { "byref", RID_BYREF, D_OBJC|D_YES },
2910 { "in", RID_IN, D_OBJC|D_YES },
2911 { "inout", RID_INOUT, D_OBJC|D_YES },
2912 { "oneway", RID_ONEWAY, D_OBJC|D_YES },
2913 { "out", RID_OUT, D_OBJC|D_YES },
2916 #define N_reswords (sizeof reswords / sizeof (struct resword))
2918 /* Table mapping from RID_* constants to yacc token numbers.
2919 Unfortunately we have to have entries for all the keywords in all
2921 static const short rid_to_yy[RID_MAX] =
2923 /* RID_STATIC */ SCSPEC,
2924 /* RID_UNSIGNED */ TYPESPEC,
2925 /* RID_LONG */ TYPESPEC,
2926 /* RID_CONST */ TYPE_QUAL,
2927 /* RID_EXTERN */ SCSPEC,
2928 /* RID_REGISTER */ SCSPEC,
2929 /* RID_TYPEDEF */ SCSPEC,
2930 /* RID_SHORT */ TYPESPEC,
2931 /* RID_INLINE */ SCSPEC,
2932 /* RID_VOLATILE */ TYPE_QUAL,
2933 /* RID_SIGNED */ TYPESPEC,
2934 /* RID_AUTO */ SCSPEC,
2935 /* RID_RESTRICT */ TYPE_QUAL,
2938 /* RID_BOUNDED */ TYPE_QUAL,
2939 /* RID_UNBOUNDED */ TYPE_QUAL,
2940 /* RID_COMPLEX */ TYPESPEC,
2944 /* RID_VIRTUAL */ 0,
2945 /* RID_EXPLICIT */ 0,
2947 /* RID_MUTABLE */ 0,
2950 /* RID_IN */ TYPE_QUAL,
2951 /* RID_OUT */ TYPE_QUAL,
2952 /* RID_INOUT */ TYPE_QUAL,
2953 /* RID_BYCOPY */ TYPE_QUAL,
2954 /* RID_BYREF */ TYPE_QUAL,
2955 /* RID_ONEWAY */ TYPE_QUAL,
2958 /* RID_INT */ TYPESPEC,
2959 /* RID_CHAR */ TYPESPEC,
2960 /* RID_FLOAT */ TYPESPEC,
2961 /* RID_DOUBLE */ TYPESPEC,
2962 /* RID_VOID */ TYPESPEC,
2963 /* RID_ENUM */ ENUM,
2964 /* RID_STRUCT */ STRUCT,
2965 /* RID_UNION */ UNION,
2967 /* RID_ELSE */ ELSE,
2968 /* RID_WHILE */ WHILE,
2971 /* RID_SWITCH */ SWITCH,
2972 /* RID_CASE */ CASE,
2973 /* RID_DEFAULT */ DEFAULT,
2974 /* RID_BREAK */ BREAK,
2975 /* RID_CONTINUE */ CONTINUE,
2976 /* RID_RETURN */ RETURN,
2977 /* RID_GOTO */ GOTO,
2978 /* RID_SIZEOF */ SIZEOF,
2981 /* RID_ASM */ ASM_KEYWORD,
2982 /* RID_TYPEOF */ TYPEOF,
2983 /* RID_ALIGNOF */ ALIGNOF,
2984 /* RID_ATTRIBUTE */ ATTRIBUTE,
2985 /* RID_VA_ARG */ VA_ARG,
2986 /* RID_EXTENSION */ EXTENSION,
2987 /* RID_IMAGPART */ IMAGPART,
2988 /* RID_REALPART */ REALPART,
2989 /* RID_LABEL */ LABEL,
2990 /* RID_PTRBASE */ PTR_BASE,
2991 /* RID_PTREXTENT */ PTR_EXTENT,
2992 /* RID_PTRVALUE */ PTR_VALUE,
2999 /* RID_PRIVATE */ 0,
3000 /* RID_PROTECTED */ 0,
3001 /* RID_TEMPLATE */ 0,
3006 /* RID_NAMESPACE */ 0,
3008 /* RID_OPERATOR */ 0,
3013 /* RID_TYPENAME */ 0,
3018 /* RID_CONSTCAST */ 0,
3019 /* RID_DYNCAST */ 0,
3020 /* RID_REINTCAST */ 0,
3021 /* RID_STATCAST */ 0,
3023 /* alternate spellings */
3037 /* RID_ID */ OBJECTNAME,
3038 /* RID_AT_ENCODE */ ENCODE,
3039 /* RID_AT_END */ END,
3040 /* RID_AT_CLASS */ CLASS,
3041 /* RID_AT_ALIAS */ ALIAS,
3042 /* RID_AT_DEFS */ DEFS,
3043 /* RID_AT_PRIVATE */ PRIVATE,
3044 /* RID_AT_PROTECTED */ PROTECTED,
3045 /* RID_AT_PUBLIC */ PUBLIC,
3046 /* RID_AT_PROTOCOL */ PROTOCOL,
3047 /* RID_AT_SELECTOR */ SELECTOR,
3048 /* RID_AT_INTERFACE */ INTERFACE,
3049 /* RID_AT_IMPLEMENTATION */ IMPLEMENTATION
3057 int mask = ((doing_objc_thang ? 0 : D_OBJC)
3058 | (flag_isoc99 ? 0 : D_C89)
3059 | (flag_traditional ? D_TRAD : 0)
3060 | (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0));
3062 /* It is not necessary to register ridpointers as a GC root, because
3063 all the trees it points to are permanently interned in the
3064 get_identifier hash anyway. */
3065 ridpointers = (tree *) xcalloc ((int) RID_MAX, sizeof (tree));
3066 for (i = 0; i < N_reswords; i++)
3068 /* If a keyword is disabled, do not enter it into the table
3069 and so create a canonical spelling that isn't a keyword. */
3070 if (reswords[i].disable & mask)
3073 id = get_identifier (reswords[i].word);
3074 C_RID_CODE (id) = reswords[i].rid;
3075 ridpointers [(int) reswords[i].rid] = id;
3077 /* Objective C does tricky things with enabling and disabling
3078 keywords. So these we must not elide in the test above, but
3079 wait and not mark them reserved now. */
3080 if (! (reswords[i].disable & D_YES))
3081 C_IS_RESERVED_WORD (id) = 1;
3086 init_parse (filename)
3087 const char *filename;
3089 add_c_tree_codes ();
3091 /* Make identifier nodes long enough for the language-specific slots. */
3092 set_identifier_size (sizeof (struct lang_identifier));
3097 return init_c_lex (filename);
3104 cpp_finish (&parse_in, 0 /* no printer */);
3105 errorcount += parse_in.errors;
3112 #define NAME(type) cpp_type2name (type)
3117 #define TK(e, s) STRINGX(e),
3119 static const char *type2name[N_TTYPES] = { TTYPE_TABLE };
3120 #define NAME(type) type2name[type]
3127 const char *string = _(msgid);
3129 if (last_token == CPP_EOF)
3130 error ("%s at end of input", string);
3131 else if (last_token == CPP_CHAR || last_token == CPP_WCHAR)
3133 unsigned int val = TREE_INT_CST_LOW (yylval.ttype);
3134 const char *ell = (last_token == CPP_CHAR) ? "" : "L";
3135 if (val <= UCHAR_MAX && ISGRAPH (val))
3136 error ("%s before %s'%c'", string, ell, val);
3138 error ("%s before %s'\\x%x'", string, ell, val);
3140 else if (last_token == CPP_STRING
3141 || last_token == CPP_WSTRING
3142 || last_token == CPP_OSTRING)
3143 error ("%s before string constant", string);
3144 else if (last_token == CPP_NUMBER
3145 || last_token == CPP_INT
3146 || last_token == CPP_FLOAT)
3147 error ("%s before numeric constant", string);
3148 else if (last_token == CPP_NAME)
3149 error ("%s before \"%s\"", string, IDENTIFIER_POINTER (yylval.ttype));
3151 error ("%s before '%s' token", string, NAME(last_token));
3158 last_token = c_lex (&yylval.ttype);
3162 case CPP_EQ: return '=';
3163 case CPP_NOT: return '!';
3164 case CPP_GREATER: yylval.code = GT_EXPR; return ARITHCOMPARE;
3165 case CPP_LESS: yylval.code = LT_EXPR; return ARITHCOMPARE;
3166 case CPP_PLUS: yylval.code = PLUS_EXPR; return '+';
3167 case CPP_MINUS: yylval.code = MINUS_EXPR; return '-';
3168 case CPP_MULT: yylval.code = MULT_EXPR; return '*';
3169 case CPP_DIV: yylval.code = TRUNC_DIV_EXPR; return '/';
3170 case CPP_MOD: yylval.code = TRUNC_MOD_EXPR; return '%';
3171 case CPP_AND: yylval.code = BIT_AND_EXPR; return '&';
3172 case CPP_OR: yylval.code = BIT_IOR_EXPR; return '|';
3173 case CPP_XOR: yylval.code = BIT_XOR_EXPR; return '^';
3174 case CPP_RSHIFT: yylval.code = RSHIFT_EXPR; return RSHIFT;
3175 case CPP_LSHIFT: yylval.code = LSHIFT_EXPR; return LSHIFT;
3177 case CPP_COMPL: return '~';
3178 case CPP_AND_AND: return ANDAND;
3179 case CPP_OR_OR: return OROR;
3180 case CPP_QUERY: return '?';
3181 case CPP_COLON: return ':';
3182 case CPP_COMMA: return ',';
3183 case CPP_OPEN_PAREN: return '(';
3184 case CPP_CLOSE_PAREN: return ')';
3185 case CPP_EQ_EQ: yylval.code = EQ_EXPR; return EQCOMPARE;
3186 case CPP_NOT_EQ: yylval.code = NE_EXPR; return EQCOMPARE;
3187 case CPP_GREATER_EQ:yylval.code = GE_EXPR; return ARITHCOMPARE;
3188 case CPP_LESS_EQ: yylval.code = LE_EXPR; return ARITHCOMPARE;
3190 case CPP_PLUS_EQ: yylval.code = PLUS_EXPR; return ASSIGN;
3191 case CPP_MINUS_EQ: yylval.code = MINUS_EXPR; return ASSIGN;
3192 case CPP_MULT_EQ: yylval.code = MULT_EXPR; return ASSIGN;
3193 case CPP_DIV_EQ: yylval.code = TRUNC_DIV_EXPR; return ASSIGN;
3194 case CPP_MOD_EQ: yylval.code = TRUNC_MOD_EXPR; return ASSIGN;
3195 case CPP_AND_EQ: yylval.code = BIT_AND_EXPR; return ASSIGN;
3196 case CPP_OR_EQ: yylval.code = BIT_IOR_EXPR; return ASSIGN;
3197 case CPP_XOR_EQ: yylval.code = BIT_XOR_EXPR; return ASSIGN;
3198 case CPP_RSHIFT_EQ: yylval.code = RSHIFT_EXPR; return ASSIGN;
3199 case CPP_LSHIFT_EQ: yylval.code = LSHIFT_EXPR; return ASSIGN;
3201 case CPP_OPEN_SQUARE: return '[';
3202 case CPP_CLOSE_SQUARE: return ']';
3203 case CPP_OPEN_BRACE: return '{';
3204 case CPP_CLOSE_BRACE: return '}';
3205 case CPP_SEMICOLON: return ';';
3206 case CPP_ELLIPSIS: return ELLIPSIS;
3208 case CPP_PLUS_PLUS: return PLUSPLUS;
3209 case CPP_MINUS_MINUS: return MINUSMINUS;
3210 case CPP_DEREF: return POINTSAT;
3211 case CPP_DOT: return '.';
3215 cpp_pop_buffer (&parse_in);
3216 if (! CPP_BUFFER (&parse_in))
3222 if (C_IS_RESERVED_WORD (yylval.ttype))
3224 enum rid rid_code = C_RID_CODE (yylval.ttype);
3225 /* Return the canonical spelling for this keyword. */
3226 yylval.ttype = ridpointers[(int) rid_code];
3227 return rid_to_yy[(int) rid_code];
3230 if (IDENTIFIER_POINTER (yylval.ttype)[0] == '@')
3232 error ("invalid identifier `%s'", IDENTIFIER_POINTER (yylval.ttype));
3239 decl = lookup_name (yylval.ttype);
3243 if (TREE_CODE (decl) == TYPE_DECL)
3245 /* A user-invisible read-only initialized variable
3246 should be replaced by its value.
3247 We handle only strings since that's the only case used in C. */
3248 else if (TREE_CODE (decl) == VAR_DECL
3249 && DECL_IGNORED_P (decl)
3250 && TREE_READONLY (decl)
3251 && DECL_INITIAL (decl) != 0
3252 && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
3254 tree stringval = DECL_INITIAL (decl);
3256 /* Copy the string value so that we won't clobber anything
3257 if we put something in the TREE_CHAIN of this one. */
3258 yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
3259 TREE_STRING_POINTER (stringval));
3263 else if (doing_objc_thang)
3265 tree objc_interface_decl = is_class_name (yylval.ttype);
3267 if (objc_interface_decl)
3269 yylval.ttype = objc_interface_decl;
3291 /* These tokens are C++ specific (and will not be generated
3292 in C mode, but let's be cautious). */
3294 case CPP_DEREF_STAR:
3300 /* These tokens should not survive translation phase 4. */
3304 error ("syntax error before '%s' token", NAME(last_token));
3318 timevar_push (TV_LEX);
3320 timevar_pop (TV_LEX);
3324 /* Sets the value of the 'yydebug' variable to VALUE.
3325 This is a function so we don't have to have YYDEBUG defined
3326 in order to build the compiler. */
3335 warning ("YYDEBUG not defined.");
3339 /* Function used when yydebug is set, to print a token in more detail. */
3342 yyprint (file, yychar, yyl)
3349 fprintf (file, " [%s]", NAME(last_token));
3359 if (IDENTIFIER_POINTER (t))
3360 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
3364 fprintf (file, " %s", GET_MODE_NAME (TYPE_MODE (TREE_TYPE (t))));
3365 if (TREE_CODE (t) == INTEGER_CST)
3367 #if HOST_BITS_PER_WIDE_INT == 64
3368 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
3371 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
3378 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
3384 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
3389 /* This is not the ideal place to put these, but we have to get them out
3390 of c-lex.c because cp/lex.c has its own versions. */
3392 /* Return something to represent absolute declarators containing a *.
3393 TARGET is the absolute declarator that the * contains.
3394 TYPE_QUALS is a list of modifiers such as const or volatile
3395 to apply to the pointer type, represented as identifiers.
3397 We return an INDIRECT_REF whose "contents" are TARGET
3398 and whose type is the modifier list. */
3401 make_pointer_declarator (type_quals, target)
3402 tree type_quals, target;
3404 return build1 (INDIRECT_REF, type_quals, target);