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, 2001, 2002, 2003 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
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. */
32 %expect 10 /* shift/reduce conflicts, and no reduce/reduce conflicts. */
38 #include "coretypes.h"
45 #include "c-pragma.h" /* For YYDEBUG definition, and parse_in. */
57 /* Like YYERROR but do call yyerror. */
58 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
60 /* Like the default stack expander, except (1) use realloc when possible,
61 (2) impose no hard maxiumum on stack size, (3) REALLY do not use alloca.
63 Irritatingly, YYSTYPE is defined after this %{ %} block, so we cannot
64 give malloced_yyvs its proper type. This is ok since all we need from
65 it is to be able to free it. */
67 static short *malloced_yyss;
68 static void *malloced_yyvs;
70 #define yyoverflow(MSG, SS, SSSIZE, VS, VSSIZE, YYSSZ) \
75 newsize = *(YYSSZ) *= 2; \
79 really_call_realloc (*(SS), newsize * sizeof (short)); \
81 really_call_realloc (*(VS), newsize * sizeof (YYSTYPE)); \
85 newss = (short *) really_call_malloc (newsize * sizeof (short)); \
86 newvs = (YYSTYPE *) really_call_malloc (newsize * sizeof (YYSTYPE)); \
88 memcpy (newss, *(SS), (SSSIZE)); \
90 memcpy (newvs, *(VS), (VSSIZE)); \
92 if (!newss || !newvs) \
99 malloced_yyss = newss; \
100 malloced_yyvs = (void *) newvs; \
106 %union {long itype; tree ttype; enum tree_code code;
107 location_t location; }
109 /* All identifiers that are not reserved words
110 and are not declared typedefs in the current block */
113 /* All identifiers that are declared typedefs in the current block.
114 In some contexts, they are treated just like IDENTIFIER,
115 but they can also serve as typespecs in declarations. */
118 /* Reserved words that specify storage class.
119 yylval contains an IDENTIFIER_NODE which indicates which one. */
120 %token SCSPEC /* Storage class other than static. */
121 %token STATIC /* Static storage class. */
123 /* Reserved words that specify type.
124 yylval contains an IDENTIFIER_NODE which indicates which one. */
127 /* Reserved words that qualify type: "const", "volatile", or "restrict".
128 yylval contains an IDENTIFIER_NODE which indicates which one. */
131 /* Character or numeric constants.
132 yylval is the node for the constant. */
135 /* String constants in raw form.
136 yylval is a STRING_CST node. */
140 /* "...", used for functions with variable arglists. */
143 /* the reserved words */
144 /* SCO include files test "ASM", so use something else. */
145 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
146 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
147 %token ATTRIBUTE EXTENSION LABEL
148 %token REALPART IMAGPART VA_ARG CHOOSE_EXPR TYPES_COMPATIBLE_P
149 %token PTR_VALUE PTR_BASE PTR_EXTENT
152 /* Add precedence rules to solve dangling else s/r conflict */
156 /* Define the operator tokens and their precedences.
157 The value is an integer because, if used, it is the tree code
158 to use in the expression made from the operator. */
160 %right <code> ASSIGN '='
161 %right <code> '?' ':'
167 %left <code> EQCOMPARE
168 %left <code> ARITHCOMPARE
169 %left <code> LSHIFT RSHIFT
171 %left <code> '*' '/' '%'
172 %right <code> UNARY PLUSPLUS MINUSMINUS
174 %left <code> POINTSAT '.' '(' '['
176 /* The Objective-C keywords. These are included in C and in
177 Objective C, so that the token codes are the same in both. */
178 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
179 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
183 %type <ttype> ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
184 %type <ttype> BREAK CONTINUE RETURN GOTO ASM_KEYWORD SIZEOF TYPEOF ALIGNOF
186 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
187 %type <ttype> expr_no_commas cast_expr unary_expr primary STRING
188 %type <ttype> declspecs_nosc_nots_nosa_noea declspecs_nosc_nots_nosa_ea
189 %type <ttype> declspecs_nosc_nots_sa_noea declspecs_nosc_nots_sa_ea
190 %type <ttype> declspecs_nosc_ts_nosa_noea declspecs_nosc_ts_nosa_ea
191 %type <ttype> declspecs_nosc_ts_sa_noea declspecs_nosc_ts_sa_ea
192 %type <ttype> declspecs_sc_nots_nosa_noea declspecs_sc_nots_nosa_ea
193 %type <ttype> declspecs_sc_nots_sa_noea declspecs_sc_nots_sa_ea
194 %type <ttype> declspecs_sc_ts_nosa_noea declspecs_sc_ts_nosa_ea
195 %type <ttype> declspecs_sc_ts_sa_noea declspecs_sc_ts_sa_ea
196 %type <ttype> declspecs_ts declspecs_nots
197 %type <ttype> declspecs_ts_nosa declspecs_nots_nosa
198 %type <ttype> declspecs_nosc_ts declspecs_nosc_nots declspecs_nosc declspecs
199 %type <ttype> maybe_type_quals_attrs typespec_nonattr typespec_attr
200 %type <ttype> typespec_reserved_nonattr typespec_reserved_attr
201 %type <ttype> typespec_nonreserved_nonattr
203 %type <ttype> scspec SCSPEC STATIC TYPESPEC TYPE_QUAL maybe_type_qual
204 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
205 %type <ttype> init maybeasm
206 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
207 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
208 %type <ttype> any_word extension
210 %type <ttype> compstmt compstmt_start compstmt_nostart compstmt_primary_start
211 %type <ttype> do_stmt_start poplevel stmt label
213 %type <ttype> c99_block_start c99_block_end
214 %type <ttype> declarator
215 %type <ttype> notype_declarator after_type_declarator
216 %type <ttype> parm_declarator
217 %type <ttype> parm_declarator_starttypename parm_declarator_nostarttypename
218 %type <ttype> array_declarator
220 %type <ttype> structsp_attr structsp_nonattr
221 %type <ttype> component_decl_list component_decl_list2
222 %type <ttype> component_decl components components_notype component_declarator
223 %type <ttype> component_notype_declarator
224 %type <ttype> enumlist enumerator
225 %type <ttype> struct_head union_head enum_head
226 %type <ttype> typename absdcl absdcl1 absdcl1_ea absdcl1_noea
227 %type <ttype> direct_absdcl1 absdcl_maybe_attribute
228 %type <ttype> xexpr parms parm firstparm identifiers
230 %type <ttype> parmlist parmlist_1 parmlist_2
231 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
232 %type <ttype> identifiers_or_typenames
234 %type <itype> setspecs setspecs_fp
236 %type <location> save_location
239 /* the Objective-C nonterminals */
241 %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
242 %type <ttype> methoddecl unaryselector keywordselector selector
243 %type <ttype> keyworddecl receiver objcmessageexpr messageargs
244 %type <ttype> keywordexpr keywordarglist keywordarg
245 %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
246 %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
247 %type <ttype> non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
249 %type <ttype> CLASSNAME OBJECTNAME OBJC_STRING
253 /* Number of statements (loosely speaking) and compound statements
255 static int stmt_count;
256 static int compstmt_count;
258 /* Input location of the end of the body of last simple_if;
259 used by the stmt-rule immediately after simple_if returns. */
260 static location_t if_stmt_locus;
263 /* List of types and structure classes of the current declaration. */
264 static GTY(()) tree current_declspecs;
265 static GTY(()) tree prefix_attributes;
267 /* List of all the attributes applying to the identifier currently being
268 declared; includes prefix_attributes and possibly some more attributes
269 just after a comma. */
270 static GTY(()) tree all_prefix_attributes;
272 /* Stack of saved values of current_declspecs, prefix_attributes and
273 all_prefix_attributes. */
274 static GTY(()) tree declspec_stack;
276 /* PUSH_DECLSPEC_STACK is called from setspecs; POP_DECLSPEC_STACK
277 should be called from the productions making use of setspecs. */
278 #define PUSH_DECLSPEC_STACK \
280 declspec_stack = tree_cons (build_tree_list (prefix_attributes, \
281 all_prefix_attributes), \
286 #define POP_DECLSPEC_STACK \
288 current_declspecs = TREE_VALUE (declspec_stack); \
289 prefix_attributes = TREE_PURPOSE (TREE_PURPOSE (declspec_stack)); \
290 all_prefix_attributes = TREE_VALUE (TREE_PURPOSE (declspec_stack)); \
291 declspec_stack = TREE_CHAIN (declspec_stack); \
294 /* For __extension__, save/restore the warning flags which are
295 controlled by __extension__. */
296 #define SAVE_EXT_FLAGS() \
298 | (warn_pointer_arith << 1) \
299 | (warn_traditional << 2) \
302 #define RESTORE_EXT_FLAGS(tval) \
304 int val = tree_low_cst (tval, 0); \
305 pedantic = val & 1; \
306 warn_pointer_arith = (val >> 1) & 1; \
307 warn_traditional = (val >> 2) & 1; \
308 flag_iso = (val >> 3) & 1; \
312 /* Objective-C specific parser/lexer information */
314 static enum tree_code objc_inherit_code;
315 static int objc_pq_context = 0, objc_public_flag = 0;
317 /* The following flag is needed to contextualize ObjC lexical analysis.
318 In some cases (e.g., 'int NSObject;'), it is undesirable to bind
319 an identifier to an ObjC class, even if a class with that name
321 static int objc_need_raw_identifier;
322 #define OBJC_NEED_RAW_IDENTIFIER(VAL) objc_need_raw_identifier = VAL
326 #define OBJC_NEED_RAW_IDENTIFIER(VAL) /* nothing */
329 static bool parsing_iso_function_signature;
331 /* Tell yyparse how to print a token's value, if yydebug is set. */
333 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
335 static void yyprint (FILE *, int, YYSTYPE);
336 static void yyerror (const char *);
337 static int yylexname (void);
338 static inline int _yylex (void);
339 static int yylex (void);
340 static void init_reswords (void);
342 /* Initialisation routine for this file. */
354 pedwarn ("ISO C forbids an empty source file");
359 /* In case there were missing closebraces,
360 get us back to the global binding level. */
361 while (! global_bindings_p ())
363 /* __FUNCTION__ is defined at file scope (""). This
364 call may not be necessary as my tests indicate it
365 still works without it. */
366 finish_fname_decls ();
371 /* the reason for the strange actions in this rule
372 is so that notype_initdecls when reached via datadef
373 can find a valid list of type and sc specs in $0. */
376 {$<ttype>$ = NULL_TREE; } extdef
377 | extdefs {$<ttype>$ = NULL_TREE; ggc_collect(); } extdef
382 { parsing_iso_function_signature = false; } /* Reset after any external definition. */
391 | ASM_KEYWORD '(' expr ')' ';'
393 if ((TREE_CODE ($3) == ADDR_EXPR
394 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
395 || TREE_CODE ($3) == STRING_CST)
398 error ("argument of `asm' is not a constant string"); }
400 { RESTORE_EXT_FLAGS ($1); }
404 setspecs notype_initdecls ';'
406 error ("ISO C forbids data definition with no type or storage class");
408 warning ("data definition has no type or storage class");
410 POP_DECLSPEC_STACK; }
411 | declspecs_nots setspecs notype_initdecls ';'
412 { POP_DECLSPEC_STACK; }
413 | declspecs_ts setspecs initdecls ';'
414 { POP_DECLSPEC_STACK; }
421 pedwarn ("ISO C does not allow extra `;' outside of a function"); }
425 declspecs_ts setspecs declarator
426 { if (! start_function (current_declspecs, $3,
427 all_prefix_attributes))
430 old_style_parm_decls save_location
431 { DECL_SOURCE_LOCATION (current_function_decl) = $6;
432 store_parm_decls (); }
434 { finish_function (0, 1);
435 POP_DECLSPEC_STACK; }
436 | declspecs_ts setspecs declarator error
437 { POP_DECLSPEC_STACK; }
438 | declspecs_nots setspecs notype_declarator
439 { if (! start_function (current_declspecs, $3,
440 all_prefix_attributes))
443 old_style_parm_decls save_location
444 { DECL_SOURCE_LOCATION (current_function_decl) = $6;
445 store_parm_decls (); }
447 { finish_function (0, 1);
448 POP_DECLSPEC_STACK; }
449 | declspecs_nots setspecs notype_declarator error
450 { POP_DECLSPEC_STACK; }
451 | setspecs notype_declarator
452 { if (! start_function (NULL_TREE, $2,
453 all_prefix_attributes))
456 old_style_parm_decls save_location
457 { DECL_SOURCE_LOCATION (current_function_decl) = $5;
458 store_parm_decls (); }
460 { finish_function (0, 1);
461 POP_DECLSPEC_STACK; }
462 | setspecs notype_declarator error
463 { POP_DECLSPEC_STACK; }
478 { $$ = NEGATE_EXPR; }
482 if (warn_traditional && !in_system_header)
483 warning ("traditional C rejects the unary plus operator");
487 { $$ = PREINCREMENT_EXPR; }
489 { $$ = PREDECREMENT_EXPR; }
491 { $$ = BIT_NOT_EXPR; }
493 { $$ = TRUTH_NOT_EXPR; }
496 expr: nonnull_exprlist
497 { $$ = build_compound_expr ($1); }
508 { $$ = build_tree_list (NULL_TREE, $1); }
509 | nonnull_exprlist ',' expr_no_commas
510 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
515 | '*' cast_expr %prec UNARY
516 { $$ = build_indirect_ref ($2, "unary *"); }
517 /* __extension__ turns off -pedantic for following primary. */
518 | extension cast_expr %prec UNARY
520 RESTORE_EXT_FLAGS ($1); }
521 | unop cast_expr %prec UNARY
522 { $$ = build_unary_op ($1, $2, 0);
523 overflow_warning ($$); }
524 /* Refer to the address of a label as a pointer. */
526 { $$ = finish_label_address_expr ($2); }
527 | sizeof unary_expr %prec UNARY
529 if (TREE_CODE ($2) == COMPONENT_REF
530 && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
531 error ("`sizeof' applied to a bit-field");
532 $$ = c_sizeof (TREE_TYPE ($2)); }
533 | sizeof '(' typename ')' %prec HYPERUNARY
535 $$ = c_sizeof (groktypename ($3)); }
536 | alignof unary_expr %prec UNARY
538 $$ = c_alignof_expr ($2); }
539 | alignof '(' typename ')' %prec HYPERUNARY
541 $$ = c_alignof (groktypename ($3)); }
542 | REALPART cast_expr %prec UNARY
543 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
544 | IMAGPART cast_expr %prec UNARY
545 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
549 SIZEOF { skip_evaluation++; }
553 ALIGNOF { skip_evaluation++; }
557 TYPEOF { skip_evaluation++; }
562 | '(' typename ')' cast_expr %prec UNARY
563 { $$ = c_cast_expr ($2, $4); }
568 | expr_no_commas '+' expr_no_commas
569 { $$ = parser_build_binary_op ($2, $1, $3); }
570 | expr_no_commas '-' expr_no_commas
571 { $$ = parser_build_binary_op ($2, $1, $3); }
572 | expr_no_commas '*' expr_no_commas
573 { $$ = parser_build_binary_op ($2, $1, $3); }
574 | expr_no_commas '/' expr_no_commas
575 { $$ = parser_build_binary_op ($2, $1, $3); }
576 | expr_no_commas '%' expr_no_commas
577 { $$ = parser_build_binary_op ($2, $1, $3); }
578 | expr_no_commas LSHIFT expr_no_commas
579 { $$ = parser_build_binary_op ($2, $1, $3); }
580 | expr_no_commas RSHIFT expr_no_commas
581 { $$ = parser_build_binary_op ($2, $1, $3); }
582 | expr_no_commas ARITHCOMPARE expr_no_commas
583 { $$ = parser_build_binary_op ($2, $1, $3); }
584 | expr_no_commas EQCOMPARE expr_no_commas
585 { $$ = parser_build_binary_op ($2, $1, $3); }
586 | expr_no_commas '&' expr_no_commas
587 { $$ = parser_build_binary_op ($2, $1, $3); }
588 | expr_no_commas '|' expr_no_commas
589 { $$ = parser_build_binary_op ($2, $1, $3); }
590 | expr_no_commas '^' expr_no_commas
591 { $$ = parser_build_binary_op ($2, $1, $3); }
592 | expr_no_commas ANDAND
593 { $1 = c_common_truthvalue_conversion
594 (default_conversion ($1));
595 skip_evaluation += $1 == boolean_false_node; }
597 { skip_evaluation -= $1 == boolean_false_node;
598 $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
599 | expr_no_commas OROR
600 { $1 = c_common_truthvalue_conversion
601 (default_conversion ($1));
602 skip_evaluation += $1 == boolean_true_node; }
604 { skip_evaluation -= $1 == boolean_true_node;
605 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
607 { $1 = c_common_truthvalue_conversion
608 (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 = c_common_truthvalue_conversion
622 (default_conversion ($<ttype>2));
623 skip_evaluation += $1 == boolean_true_node; }
625 { skip_evaluation -= $1 == boolean_true_node;
626 $$ = build_conditional_expr ($1, $<ttype>2, $5); }
627 | expr_no_commas '=' expr_no_commas
629 $$ = build_modify_expr ($1, NOP_EXPR, $3);
630 class = TREE_CODE_CLASS (TREE_CODE ($$));
631 if (IS_EXPR_CODE_CLASS (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
638 c_common_truthvalue_conversion. */
639 class = TREE_CODE_CLASS (TREE_CODE ($$));
640 if (IS_EXPR_CODE_CLASS (class))
641 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK);
648 if (yychar == YYEMPTY)
650 $$ = build_external_ref ($1, yychar == '(');
655 { $$ = fname_decl (C_RID_CODE ($$), $$); }
656 | '(' typename ')' '{'
657 { start_init (NULL_TREE, NULL, 0);
658 $2 = groktypename ($2);
659 really_start_incremental_init ($2); }
660 initlist_maybe_comma '}' %prec UNARY
661 { tree constructor = pop_init_level (0);
665 if (pedantic && ! flag_isoc99)
666 pedwarn ("ISO C89 forbids compound literals");
667 $$ = build_compound_literal (type, constructor);
670 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
671 if (IS_EXPR_CODE_CLASS (class))
672 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
675 { $$ = error_mark_node; }
676 | compstmt_primary_start compstmt_nostart ')'
677 { tree saved_last_tree;
680 pedwarn ("ISO C forbids braced-groups within expressions");
683 saved_last_tree = COMPOUND_BODY ($1);
684 RECHAIN_STMTS ($1, COMPOUND_BODY ($1));
685 last_tree = saved_last_tree;
686 TREE_CHAIN (last_tree) = NULL_TREE;
688 last_expr_type = void_type_node;
689 $$ = build1 (STMT_EXPR, last_expr_type, $1);
690 TREE_SIDE_EFFECTS ($$) = 1;
692 | compstmt_primary_start error ')'
695 last_tree = COMPOUND_BODY ($1);
696 TREE_CHAIN (last_tree) = NULL_TREE;
697 $$ = error_mark_node;
699 | primary '(' exprlist ')' %prec '.'
700 { $$ = build_function_call ($1, $3); }
701 | VA_ARG '(' expr_no_commas ',' typename ')'
702 { $$ = build_va_arg ($3, groktypename ($5)); }
704 | CHOOSE_EXPR '(' expr_no_commas ',' expr_no_commas ',' expr_no_commas ')'
710 if (TREE_CODE (c) != INTEGER_CST)
711 error ("first argument to __builtin_choose_expr not a constant");
712 $$ = integer_zerop (c) ? $7 : $5;
714 | TYPES_COMPATIBLE_P '(' typename ',' typename ')'
718 e1 = TYPE_MAIN_VARIANT (groktypename ($3));
719 e2 = TYPE_MAIN_VARIANT (groktypename ($5));
721 $$ = comptypes (e1, e2)
722 ? build_int_2 (1, 0) : build_int_2 (0, 0);
724 | primary '[' expr ']' %prec '.'
725 { $$ = build_array_ref ($1, $3); }
726 | primary '.' identifier
729 if (!is_public ($1, $3))
730 $$ = error_mark_node;
733 $$ = build_component_ref ($1, $3);
735 | primary POINTSAT identifier
737 tree expr = build_indirect_ref ($1, "->");
740 if (!is_public (expr, $3))
741 $$ = error_mark_node;
744 $$ = build_component_ref (expr, $3);
747 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
749 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
752 { $$ = build_message_expr ($1); }
754 { $$ = build_selector_expr ($1); }
756 { $$ = build_protocol_expr ($1); }
758 { $$ = build_encode_expr ($1); }
760 { $$ = build_objc_string_object ($1); }
764 old_style_parm_decls:
765 old_style_parm_decls_1
767 parsing_iso_function_signature = false; /* Reset after decls. */
771 old_style_parm_decls_1:
774 if (warn_traditional && !in_system_header
775 && parsing_iso_function_signature)
776 warning ("traditional C rejects ISO C style function definitions");
777 parsing_iso_function_signature = false; /* Reset after warning. */
782 /* The following are analogous to lineno_decl, decls and decl
783 except that they do not allow nested functions.
784 They are used for old-style parm decls. */
786 save_location datadecl
793 | datadecls lineno_datadecl
794 | lineno_datadecl errstmt
797 /* We don't allow prefix attributes here because they cause reduce/reduce
798 conflicts: we can't know whether we're parsing a function decl with
799 attribute suffix, or function defn with attribute prefix on first old
802 declspecs_ts_nosa setspecs initdecls ';'
803 { POP_DECLSPEC_STACK; }
804 | declspecs_nots_nosa setspecs notype_initdecls ';'
805 { POP_DECLSPEC_STACK; }
806 | declspecs_ts_nosa ';'
807 { shadow_tag_warned ($1, 1);
808 pedwarn ("empty declaration"); }
809 | declspecs_nots_nosa ';'
810 { pedwarn ("empty declaration"); }
813 /* This combination which saves a lineno before a decl
814 is the normal thing to use, rather than decl itself.
815 This is to avoid shift/reduce conflicts in contexts
816 where statement labels are allowed. */
822 /* records the type and storage class specs to use for processing
823 the declarators that follow.
824 Maintains a stack of outer-level values of current_declspecs,
825 for the sake of parm declarations nested in function declarators. */
826 setspecs: /* empty */
827 { pending_xref_error ();
829 split_specs_attrs ($<ttype>0,
830 ¤t_declspecs, &prefix_attributes);
831 all_prefix_attributes = prefix_attributes; }
834 /* Possibly attributes after a comma, which should reset all_prefix_attributes
835 to prefix_attributes with these ones chained on the front. */
838 { all_prefix_attributes = chainon ($1, prefix_attributes); }
842 declspecs_ts setspecs initdecls ';'
843 { POP_DECLSPEC_STACK; }
844 | declspecs_nots setspecs notype_initdecls ';'
845 { POP_DECLSPEC_STACK; }
846 | declspecs_ts setspecs nested_function
847 { POP_DECLSPEC_STACK; }
848 | declspecs_nots setspecs notype_nested_function
849 { POP_DECLSPEC_STACK; }
853 { RESTORE_EXT_FLAGS ($1); }
856 /* A list of declaration specifiers. These are:
858 - Storage class specifiers (scspec), which for GCC currently includes
859 function specifiers ("inline").
861 - Type specifiers (typespec_*).
863 - Type qualifiers (TYPE_QUAL).
865 - Attribute specifier lists (attributes).
867 These are stored as a TREE_LIST; the head of the list is the last
868 item in the specifier list. Each entry in the list has either a
869 TREE_PURPOSE that is an attribute specifier list, or a TREE_VALUE that
870 is a single other specifier or qualifier; and a TREE_CHAIN that is the
871 rest of the list. TREE_STATIC is set on the list if something other
872 than a storage class specifier or attribute has been seen; this is used
873 to warn for the obsolescent usage of storage class specifiers other than
874 at the start of the list. (Doing this properly would require function
875 specifiers to be handled separately from storage class specifiers.)
877 The various cases below are classified according to:
879 (a) Whether a storage class specifier is included or not; some
880 places in the grammar disallow storage class specifiers (_sc or _nosc).
882 (b) Whether a type specifier has been seen; after a type specifier,
883 a typedef name is an identifier to redeclare (_ts or _nots).
885 (c) Whether the list starts with an attribute; in certain places,
886 the grammar requires specifiers that don't start with an attribute
889 (d) Whether the list ends with an attribute (or a specifier such that
890 any following attribute would have been parsed as part of that specifier);
891 this avoids shift-reduce conflicts in the parsing of attributes
896 (i) Distinguish between function specifiers and storage class specifiers,
897 at least for the purpose of warnings about obsolescent usage.
899 (ii) Halve the number of productions here by eliminating the _sc/_nosc
900 distinction and instead checking where required that storage class
901 specifiers aren't present. */
903 /* Declspecs which contain at least one type specifier or typedef name.
904 (Just `const' or `volatile' is not enough.)
905 A typedef'd name following these is taken as a name to be declared.
906 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
908 declspecs_nosc_nots_nosa_noea:
910 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
911 TREE_STATIC ($$) = 1; }
912 | declspecs_nosc_nots_nosa_noea TYPE_QUAL
913 { $$ = tree_cons (NULL_TREE, $2, $1);
914 TREE_STATIC ($$) = 1; }
915 | declspecs_nosc_nots_nosa_ea TYPE_QUAL
916 { $$ = tree_cons (NULL_TREE, $2, $1);
917 TREE_STATIC ($$) = 1; }
920 declspecs_nosc_nots_nosa_ea:
921 declspecs_nosc_nots_nosa_noea attributes
922 { $$ = tree_cons ($2, NULL_TREE, $1);
923 TREE_STATIC ($$) = TREE_STATIC ($1); }
926 declspecs_nosc_nots_sa_noea:
927 declspecs_nosc_nots_sa_noea TYPE_QUAL
928 { $$ = tree_cons (NULL_TREE, $2, $1);
929 TREE_STATIC ($$) = 1; }
930 | declspecs_nosc_nots_sa_ea TYPE_QUAL
931 { $$ = tree_cons (NULL_TREE, $2, $1);
932 TREE_STATIC ($$) = 1; }
935 declspecs_nosc_nots_sa_ea:
937 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE);
938 TREE_STATIC ($$) = 0; }
939 | declspecs_nosc_nots_sa_noea attributes
940 { $$ = tree_cons ($2, NULL_TREE, $1);
941 TREE_STATIC ($$) = TREE_STATIC ($1); }
944 declspecs_nosc_ts_nosa_noea:
946 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
947 TREE_STATIC ($$) = 1; }
948 | declspecs_nosc_ts_nosa_noea TYPE_QUAL
949 { $$ = tree_cons (NULL_TREE, $2, $1);
950 TREE_STATIC ($$) = 1; }
951 | declspecs_nosc_ts_nosa_ea TYPE_QUAL
952 { $$ = tree_cons (NULL_TREE, $2, $1);
953 TREE_STATIC ($$) = 1; }
954 | declspecs_nosc_ts_nosa_noea typespec_reserved_nonattr
955 { $$ = tree_cons (NULL_TREE, $2, $1);
956 TREE_STATIC ($$) = 1; }
957 | declspecs_nosc_ts_nosa_ea typespec_reserved_nonattr
958 { $$ = tree_cons (NULL_TREE, $2, $1);
959 TREE_STATIC ($$) = 1; }
960 | declspecs_nosc_nots_nosa_noea typespec_nonattr
961 { $$ = tree_cons (NULL_TREE, $2, $1);
962 TREE_STATIC ($$) = 1; }
963 | declspecs_nosc_nots_nosa_ea typespec_nonattr
964 { $$ = tree_cons (NULL_TREE, $2, $1);
965 TREE_STATIC ($$) = 1; }
968 declspecs_nosc_ts_nosa_ea:
970 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
971 TREE_STATIC ($$) = 1; }
972 | declspecs_nosc_ts_nosa_noea attributes
973 { $$ = tree_cons ($2, NULL_TREE, $1);
974 TREE_STATIC ($$) = TREE_STATIC ($1); }
975 | declspecs_nosc_ts_nosa_noea typespec_reserved_attr
976 { $$ = tree_cons (NULL_TREE, $2, $1);
977 TREE_STATIC ($$) = 1; }
978 | declspecs_nosc_ts_nosa_ea typespec_reserved_attr
979 { $$ = tree_cons (NULL_TREE, $2, $1);
980 TREE_STATIC ($$) = 1; }
981 | declspecs_nosc_nots_nosa_noea typespec_attr
982 { $$ = tree_cons (NULL_TREE, $2, $1);
983 TREE_STATIC ($$) = 1; }
984 | declspecs_nosc_nots_nosa_ea typespec_attr
985 { $$ = tree_cons (NULL_TREE, $2, $1);
986 TREE_STATIC ($$) = 1; }
989 declspecs_nosc_ts_sa_noea:
990 declspecs_nosc_ts_sa_noea TYPE_QUAL
991 { $$ = tree_cons (NULL_TREE, $2, $1);
992 TREE_STATIC ($$) = 1; }
993 | declspecs_nosc_ts_sa_ea TYPE_QUAL
994 { $$ = tree_cons (NULL_TREE, $2, $1);
995 TREE_STATIC ($$) = 1; }
996 | declspecs_nosc_ts_sa_noea typespec_reserved_nonattr
997 { $$ = tree_cons (NULL_TREE, $2, $1);
998 TREE_STATIC ($$) = 1; }
999 | declspecs_nosc_ts_sa_ea typespec_reserved_nonattr
1000 { $$ = tree_cons (NULL_TREE, $2, $1);
1001 TREE_STATIC ($$) = 1; }
1002 | declspecs_nosc_nots_sa_noea typespec_nonattr
1003 { $$ = tree_cons (NULL_TREE, $2, $1);
1004 TREE_STATIC ($$) = 1; }
1005 | declspecs_nosc_nots_sa_ea typespec_nonattr
1006 { $$ = tree_cons (NULL_TREE, $2, $1);
1007 TREE_STATIC ($$) = 1; }
1010 declspecs_nosc_ts_sa_ea:
1011 declspecs_nosc_ts_sa_noea attributes
1012 { $$ = tree_cons ($2, NULL_TREE, $1);
1013 TREE_STATIC ($$) = TREE_STATIC ($1); }
1014 | declspecs_nosc_ts_sa_noea typespec_reserved_attr
1015 { $$ = tree_cons (NULL_TREE, $2, $1);
1016 TREE_STATIC ($$) = 1; }
1017 | declspecs_nosc_ts_sa_ea typespec_reserved_attr
1018 { $$ = tree_cons (NULL_TREE, $2, $1);
1019 TREE_STATIC ($$) = 1; }
1020 | declspecs_nosc_nots_sa_noea typespec_attr
1021 { $$ = tree_cons (NULL_TREE, $2, $1);
1022 TREE_STATIC ($$) = 1; }
1023 | declspecs_nosc_nots_sa_ea typespec_attr
1024 { $$ = tree_cons (NULL_TREE, $2, $1);
1025 TREE_STATIC ($$) = 1; }
1028 declspecs_sc_nots_nosa_noea:
1030 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
1031 TREE_STATIC ($$) = 0; }
1032 | declspecs_sc_nots_nosa_noea TYPE_QUAL
1033 { $$ = tree_cons (NULL_TREE, $2, $1);
1034 TREE_STATIC ($$) = 1; }
1035 | declspecs_sc_nots_nosa_ea TYPE_QUAL
1036 { $$ = tree_cons (NULL_TREE, $2, $1);
1037 TREE_STATIC ($$) = 1; }
1038 | declspecs_nosc_nots_nosa_noea scspec
1039 { if (extra_warnings && TREE_STATIC ($1))
1040 warning ("`%s' is not at beginning of declaration",
1041 IDENTIFIER_POINTER ($2));
1042 $$ = tree_cons (NULL_TREE, $2, $1);
1043 TREE_STATIC ($$) = TREE_STATIC ($1); }
1044 | declspecs_nosc_nots_nosa_ea scspec
1045 { if (extra_warnings && TREE_STATIC ($1))
1046 warning ("`%s' is not at beginning of declaration",
1047 IDENTIFIER_POINTER ($2));
1048 $$ = tree_cons (NULL_TREE, $2, $1);
1049 TREE_STATIC ($$) = TREE_STATIC ($1); }
1050 | declspecs_sc_nots_nosa_noea scspec
1051 { if (extra_warnings && TREE_STATIC ($1))
1052 warning ("`%s' is not at beginning of declaration",
1053 IDENTIFIER_POINTER ($2));
1054 $$ = tree_cons (NULL_TREE, $2, $1);
1055 TREE_STATIC ($$) = TREE_STATIC ($1); }
1056 | declspecs_sc_nots_nosa_ea scspec
1057 { if (extra_warnings && TREE_STATIC ($1))
1058 warning ("`%s' is not at beginning of declaration",
1059 IDENTIFIER_POINTER ($2));
1060 $$ = tree_cons (NULL_TREE, $2, $1);
1061 TREE_STATIC ($$) = TREE_STATIC ($1); }
1064 declspecs_sc_nots_nosa_ea:
1065 declspecs_sc_nots_nosa_noea attributes
1066 { $$ = tree_cons ($2, NULL_TREE, $1);
1067 TREE_STATIC ($$) = TREE_STATIC ($1); }
1070 declspecs_sc_nots_sa_noea:
1071 declspecs_sc_nots_sa_noea TYPE_QUAL
1072 { $$ = tree_cons (NULL_TREE, $2, $1);
1073 TREE_STATIC ($$) = 1; }
1074 | declspecs_sc_nots_sa_ea TYPE_QUAL
1075 { $$ = tree_cons (NULL_TREE, $2, $1);
1076 TREE_STATIC ($$) = 1; }
1077 | declspecs_nosc_nots_sa_noea scspec
1078 { if (extra_warnings && TREE_STATIC ($1))
1079 warning ("`%s' is not at beginning of declaration",
1080 IDENTIFIER_POINTER ($2));
1081 $$ = tree_cons (NULL_TREE, $2, $1);
1082 TREE_STATIC ($$) = TREE_STATIC ($1); }
1083 | declspecs_nosc_nots_sa_ea scspec
1084 { if (extra_warnings && TREE_STATIC ($1))
1085 warning ("`%s' is not at beginning of declaration",
1086 IDENTIFIER_POINTER ($2));
1087 $$ = tree_cons (NULL_TREE, $2, $1);
1088 TREE_STATIC ($$) = TREE_STATIC ($1); }
1089 | declspecs_sc_nots_sa_noea scspec
1090 { if (extra_warnings && TREE_STATIC ($1))
1091 warning ("`%s' is not at beginning of declaration",
1092 IDENTIFIER_POINTER ($2));
1093 $$ = tree_cons (NULL_TREE, $2, $1);
1094 TREE_STATIC ($$) = TREE_STATIC ($1); }
1095 | declspecs_sc_nots_sa_ea scspec
1096 { if (extra_warnings && TREE_STATIC ($1))
1097 warning ("`%s' is not at beginning of declaration",
1098 IDENTIFIER_POINTER ($2));
1099 $$ = tree_cons (NULL_TREE, $2, $1);
1100 TREE_STATIC ($$) = TREE_STATIC ($1); }
1103 declspecs_sc_nots_sa_ea:
1104 declspecs_sc_nots_sa_noea attributes
1105 { $$ = tree_cons ($2, NULL_TREE, $1);
1106 TREE_STATIC ($$) = TREE_STATIC ($1); }
1109 declspecs_sc_ts_nosa_noea:
1110 declspecs_sc_ts_nosa_noea TYPE_QUAL
1111 { $$ = tree_cons (NULL_TREE, $2, $1);
1112 TREE_STATIC ($$) = 1; }
1113 | declspecs_sc_ts_nosa_ea TYPE_QUAL
1114 { $$ = tree_cons (NULL_TREE, $2, $1);
1115 TREE_STATIC ($$) = 1; }
1116 | declspecs_sc_ts_nosa_noea typespec_reserved_nonattr
1117 { $$ = tree_cons (NULL_TREE, $2, $1);
1118 TREE_STATIC ($$) = 1; }
1119 | declspecs_sc_ts_nosa_ea typespec_reserved_nonattr
1120 { $$ = tree_cons (NULL_TREE, $2, $1);
1121 TREE_STATIC ($$) = 1; }
1122 | declspecs_sc_nots_nosa_noea typespec_nonattr
1123 { $$ = tree_cons (NULL_TREE, $2, $1);
1124 TREE_STATIC ($$) = 1; }
1125 | declspecs_sc_nots_nosa_ea typespec_nonattr
1126 { $$ = tree_cons (NULL_TREE, $2, $1);
1127 TREE_STATIC ($$) = 1; }
1128 | declspecs_nosc_ts_nosa_noea scspec
1129 { if (extra_warnings && TREE_STATIC ($1))
1130 warning ("`%s' is not at beginning of declaration",
1131 IDENTIFIER_POINTER ($2));
1132 $$ = tree_cons (NULL_TREE, $2, $1);
1133 TREE_STATIC ($$) = TREE_STATIC ($1); }
1134 | declspecs_nosc_ts_nosa_ea scspec
1135 { if (extra_warnings && TREE_STATIC ($1))
1136 warning ("`%s' is not at beginning of declaration",
1137 IDENTIFIER_POINTER ($2));
1138 $$ = tree_cons (NULL_TREE, $2, $1);
1139 TREE_STATIC ($$) = TREE_STATIC ($1); }
1140 | declspecs_sc_ts_nosa_noea scspec
1141 { if (extra_warnings && TREE_STATIC ($1))
1142 warning ("`%s' is not at beginning of declaration",
1143 IDENTIFIER_POINTER ($2));
1144 $$ = tree_cons (NULL_TREE, $2, $1);
1145 TREE_STATIC ($$) = TREE_STATIC ($1); }
1146 | declspecs_sc_ts_nosa_ea scspec
1147 { if (extra_warnings && TREE_STATIC ($1))
1148 warning ("`%s' is not at beginning of declaration",
1149 IDENTIFIER_POINTER ($2));
1150 $$ = tree_cons (NULL_TREE, $2, $1);
1151 TREE_STATIC ($$) = TREE_STATIC ($1); }
1154 declspecs_sc_ts_nosa_ea:
1155 declspecs_sc_ts_nosa_noea attributes
1156 { $$ = tree_cons ($2, NULL_TREE, $1);
1157 TREE_STATIC ($$) = TREE_STATIC ($1); }
1158 | declspecs_sc_ts_nosa_noea typespec_reserved_attr
1159 { $$ = tree_cons (NULL_TREE, $2, $1);
1160 TREE_STATIC ($$) = 1; }
1161 | declspecs_sc_ts_nosa_ea typespec_reserved_attr
1162 { $$ = tree_cons (NULL_TREE, $2, $1);
1163 TREE_STATIC ($$) = 1; }
1164 | declspecs_sc_nots_nosa_noea typespec_attr
1165 { $$ = tree_cons (NULL_TREE, $2, $1);
1166 TREE_STATIC ($$) = 1; }
1167 | declspecs_sc_nots_nosa_ea typespec_attr
1168 { $$ = tree_cons (NULL_TREE, $2, $1);
1169 TREE_STATIC ($$) = 1; }
1172 declspecs_sc_ts_sa_noea:
1173 declspecs_sc_ts_sa_noea TYPE_QUAL
1174 { $$ = tree_cons (NULL_TREE, $2, $1);
1175 TREE_STATIC ($$) = 1; }
1176 | declspecs_sc_ts_sa_ea TYPE_QUAL
1177 { $$ = tree_cons (NULL_TREE, $2, $1);
1178 TREE_STATIC ($$) = 1; }
1179 | declspecs_sc_ts_sa_noea typespec_reserved_nonattr
1180 { $$ = tree_cons (NULL_TREE, $2, $1);
1181 TREE_STATIC ($$) = 1; }
1182 | declspecs_sc_ts_sa_ea typespec_reserved_nonattr
1183 { $$ = tree_cons (NULL_TREE, $2, $1);
1184 TREE_STATIC ($$) = 1; }
1185 | declspecs_sc_nots_sa_noea typespec_nonattr
1186 { $$ = tree_cons (NULL_TREE, $2, $1);
1187 TREE_STATIC ($$) = 1; }
1188 | declspecs_sc_nots_sa_ea typespec_nonattr
1189 { $$ = tree_cons (NULL_TREE, $2, $1);
1190 TREE_STATIC ($$) = 1; }
1191 | declspecs_nosc_ts_sa_noea scspec
1192 { if (extra_warnings && TREE_STATIC ($1))
1193 warning ("`%s' is not at beginning of declaration",
1194 IDENTIFIER_POINTER ($2));
1195 $$ = tree_cons (NULL_TREE, $2, $1);
1196 TREE_STATIC ($$) = TREE_STATIC ($1); }
1197 | declspecs_nosc_ts_sa_ea scspec
1198 { if (extra_warnings && TREE_STATIC ($1))
1199 warning ("`%s' is not at beginning of declaration",
1200 IDENTIFIER_POINTER ($2));
1201 $$ = tree_cons (NULL_TREE, $2, $1);
1202 TREE_STATIC ($$) = TREE_STATIC ($1); }
1203 | declspecs_sc_ts_sa_noea scspec
1204 { if (extra_warnings && TREE_STATIC ($1))
1205 warning ("`%s' is not at beginning of declaration",
1206 IDENTIFIER_POINTER ($2));
1207 $$ = tree_cons (NULL_TREE, $2, $1);
1208 TREE_STATIC ($$) = TREE_STATIC ($1); }
1209 | declspecs_sc_ts_sa_ea scspec
1210 { if (extra_warnings && TREE_STATIC ($1))
1211 warning ("`%s' is not at beginning of declaration",
1212 IDENTIFIER_POINTER ($2));
1213 $$ = tree_cons (NULL_TREE, $2, $1);
1214 TREE_STATIC ($$) = TREE_STATIC ($1); }
1217 declspecs_sc_ts_sa_ea:
1218 declspecs_sc_ts_sa_noea attributes
1219 { $$ = tree_cons ($2, NULL_TREE, $1);
1220 TREE_STATIC ($$) = TREE_STATIC ($1); }
1221 | declspecs_sc_ts_sa_noea typespec_reserved_attr
1222 { $$ = tree_cons (NULL_TREE, $2, $1);
1223 TREE_STATIC ($$) = 1; }
1224 | declspecs_sc_ts_sa_ea typespec_reserved_attr
1225 { $$ = tree_cons (NULL_TREE, $2, $1);
1226 TREE_STATIC ($$) = 1; }
1227 | declspecs_sc_nots_sa_noea typespec_attr
1228 { $$ = tree_cons (NULL_TREE, $2, $1);
1229 TREE_STATIC ($$) = 1; }
1230 | declspecs_sc_nots_sa_ea typespec_attr
1231 { $$ = tree_cons (NULL_TREE, $2, $1);
1232 TREE_STATIC ($$) = 1; }
1235 /* Particular useful classes of declspecs. */
1237 declspecs_nosc_ts_nosa_noea
1238 | declspecs_nosc_ts_nosa_ea
1239 | declspecs_nosc_ts_sa_noea
1240 | declspecs_nosc_ts_sa_ea
1241 | declspecs_sc_ts_nosa_noea
1242 | declspecs_sc_ts_nosa_ea
1243 | declspecs_sc_ts_sa_noea
1244 | declspecs_sc_ts_sa_ea
1248 declspecs_nosc_nots_nosa_noea
1249 | declspecs_nosc_nots_nosa_ea
1250 | declspecs_nosc_nots_sa_noea
1251 | declspecs_nosc_nots_sa_ea
1252 | declspecs_sc_nots_nosa_noea
1253 | declspecs_sc_nots_nosa_ea
1254 | declspecs_sc_nots_sa_noea
1255 | declspecs_sc_nots_sa_ea
1259 declspecs_nosc_ts_nosa_noea
1260 | declspecs_nosc_ts_nosa_ea
1261 | declspecs_sc_ts_nosa_noea
1262 | declspecs_sc_ts_nosa_ea
1265 declspecs_nots_nosa:
1266 declspecs_nosc_nots_nosa_noea
1267 | declspecs_nosc_nots_nosa_ea
1268 | declspecs_sc_nots_nosa_noea
1269 | declspecs_sc_nots_nosa_ea
1273 declspecs_nosc_ts_nosa_noea
1274 | declspecs_nosc_ts_nosa_ea
1275 | declspecs_nosc_ts_sa_noea
1276 | declspecs_nosc_ts_sa_ea
1279 declspecs_nosc_nots:
1280 declspecs_nosc_nots_nosa_noea
1281 | declspecs_nosc_nots_nosa_ea
1282 | declspecs_nosc_nots_sa_noea
1283 | declspecs_nosc_nots_sa_ea
1287 declspecs_nosc_ts_nosa_noea
1288 | declspecs_nosc_ts_nosa_ea
1289 | declspecs_nosc_ts_sa_noea
1290 | declspecs_nosc_ts_sa_ea
1291 | declspecs_nosc_nots_nosa_noea
1292 | declspecs_nosc_nots_nosa_ea
1293 | declspecs_nosc_nots_sa_noea
1294 | declspecs_nosc_nots_sa_ea
1298 declspecs_nosc_nots_nosa_noea
1299 | declspecs_nosc_nots_nosa_ea
1300 | declspecs_nosc_nots_sa_noea
1301 | declspecs_nosc_nots_sa_ea
1302 | declspecs_nosc_ts_nosa_noea
1303 | declspecs_nosc_ts_nosa_ea
1304 | declspecs_nosc_ts_sa_noea
1305 | declspecs_nosc_ts_sa_ea
1306 | declspecs_sc_nots_nosa_noea
1307 | declspecs_sc_nots_nosa_ea
1308 | declspecs_sc_nots_sa_noea
1309 | declspecs_sc_nots_sa_ea
1310 | declspecs_sc_ts_nosa_noea
1311 | declspecs_sc_ts_nosa_ea
1312 | declspecs_sc_ts_sa_noea
1313 | declspecs_sc_ts_sa_ea
1316 /* A (possibly empty) sequence of type qualifiers and attributes. */
1317 maybe_type_quals_attrs:
1320 | declspecs_nosc_nots
1324 /* A type specifier (but not a type qualifier).
1325 Once we have seen one of these in a declaration,
1326 if a typedef name appears then it is being redeclared.
1328 The _reserved versions start with a reserved word and may appear anywhere
1329 in the declaration specifiers; the _nonreserved versions may only
1330 appear before any other type specifiers, and after that are (if names)
1333 FIXME: should the _nonreserved version be restricted to names being
1334 redeclared only? The other entries there relate only the GNU extensions
1335 and Objective C, and are historically parsed thus, and don't make sense
1336 after other type specifiers, but it might be cleaner to count them as
1339 _attr means: specifiers that either end with attributes,
1340 or are such that any following attributes would
1341 be parsed as part of the specifier.
1343 _nonattr: specifiers. */
1346 typespec_reserved_nonattr
1347 | typespec_nonreserved_nonattr
1351 typespec_reserved_attr
1354 typespec_reserved_nonattr:
1356 { OBJC_NEED_RAW_IDENTIFIER (1); }
1360 typespec_reserved_attr:
1364 typespec_nonreserved_nonattr:
1366 { /* For a typedef name, record the meaning, not the name.
1367 In case of `foo foo, bar;'. */
1368 $$ = lookup_name ($1); }
1370 | CLASSNAME protocolrefs
1371 { $$ = get_static_reference ($1, $2); }
1372 | OBJECTNAME protocolrefs
1373 { $$ = get_object_reference ($2); }
1375 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>"
1376 - nisse@lysator.liu.se */
1377 | non_empty_protocolrefs
1378 { $$ = get_object_reference ($1); }
1380 | typeof '(' expr ')'
1381 { skip_evaluation--; $$ = TREE_TYPE ($3); }
1382 | typeof '(' typename ')'
1383 { skip_evaluation--; $$ = groktypename ($3); }
1386 /* typespec_nonreserved_attr does not exist. */
1390 | initdecls ',' maybe_resetattrs initdcl
1395 | notype_initdecls ',' maybe_resetattrs notype_initdcl
1401 | ASM_KEYWORD '(' STRING ')'
1406 declarator maybeasm maybe_attribute '='
1407 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1408 chainon ($3, all_prefix_attributes));
1409 start_init ($<ttype>$, $2, global_bindings_p ()); }
1411 /* Note how the declaration of the variable is in effect while its init is parsed! */
1413 finish_decl ($<ttype>5, $6, $2); }
1414 | declarator maybeasm maybe_attribute
1415 { tree d = start_decl ($1, current_declspecs, 0,
1416 chainon ($3, all_prefix_attributes));
1417 finish_decl (d, NULL_TREE, $2);
1422 notype_declarator maybeasm maybe_attribute '='
1423 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1424 chainon ($3, all_prefix_attributes));
1425 start_init ($<ttype>$, $2, global_bindings_p ()); }
1427 /* Note how the declaration of the variable is in effect while its init is parsed! */
1429 finish_decl ($<ttype>5, $6, $2); }
1430 | notype_declarator maybeasm maybe_attribute
1431 { tree d = start_decl ($1, current_declspecs, 0,
1432 chainon ($3, all_prefix_attributes));
1433 finish_decl (d, NULL_TREE, $2); }
1435 /* the * rules are dummies to accept the Apollo extended syntax
1436 so that the header files compile. */
1447 | attributes attribute
1448 { $$ = chainon ($1, $2); }
1452 ATTRIBUTE '(' '(' attribute_list ')' ')'
1459 | attribute_list ',' attrib
1460 { $$ = chainon ($1, $3); }
1467 { $$ = build_tree_list ($1, NULL_TREE); }
1468 | any_word '(' IDENTIFIER ')'
1469 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1470 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1471 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1472 | any_word '(' exprlist ')'
1473 { $$ = build_tree_list ($1, $3); }
1476 /* This still leaves out most reserved keywords,
1477 shouldn't we include them? */
1491 /* Initializers. `init' is the entry point. */
1496 { really_start_incremental_init (NULL_TREE); }
1497 initlist_maybe_comma '}'
1498 { $$ = pop_init_level (0); }
1500 { $$ = error_mark_node; }
1503 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1504 initlist_maybe_comma:
1507 pedwarn ("ISO C forbids empty initializer braces"); }
1508 | initlist1 maybecomma
1513 | initlist1 ',' initelt
1516 /* `initelt' is a single element of an initializer.
1517 It may use braces. */
1519 designator_list '=' initval
1520 { if (pedantic && ! flag_isoc99)
1521 pedwarn ("ISO C89 forbids specifying subobject to initialize"); }
1522 | designator initval
1524 pedwarn ("obsolete use of designated initializer without `='"); }
1526 { set_init_label ($1);
1528 pedwarn ("obsolete use of designated initializer with `:'"); }
1536 { push_init_level (0); }
1537 initlist_maybe_comma '}'
1538 { process_init_element (pop_init_level (0)); }
1540 { process_init_element ($1); }
1546 | designator_list designator
1551 { set_init_label ($2); }
1552 | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
1553 { set_init_index ($2, $4);
1555 pedwarn ("ISO C forbids specifying range of elements to initialize"); }
1556 | '[' expr_no_commas ']'
1557 { set_init_index ($2, NULL_TREE); }
1563 pedwarn ("ISO C forbids nested functions");
1565 push_function_context ();
1566 if (! start_function (current_declspecs, $1,
1567 all_prefix_attributes))
1569 pop_function_context ();
1572 parsing_iso_function_signature = false; /* Don't warn about nested functions. */
1574 old_style_parm_decls save_location
1575 { tree decl = current_function_decl;
1576 DECL_SOURCE_LOCATION (decl) = $4;
1577 store_parm_decls (); }
1578 /* This used to use compstmt_or_error.
1579 That caused a bug with input `f(g) int g {}',
1580 where the use of YYERROR1 above caused an error
1581 which then was handled by compstmt_or_error.
1582 There followed a repeated execution of that same rule,
1583 which called YYERROR1 again, and so on. */
1585 { tree decl = current_function_decl;
1586 finish_function (1, 1);
1587 pop_function_context ();
1588 add_decl_stmt (decl); }
1591 notype_nested_function:
1594 pedwarn ("ISO C forbids nested functions");
1596 push_function_context ();
1597 if (! start_function (current_declspecs, $1,
1598 all_prefix_attributes))
1600 pop_function_context ();
1603 parsing_iso_function_signature = false; /* Don't warn about nested functions. */
1605 old_style_parm_decls save_location
1606 { tree decl = current_function_decl;
1607 DECL_SOURCE_LOCATION (decl) = $4;
1608 store_parm_decls (); }
1609 /* This used to use compstmt_or_error.
1610 That caused a bug with input `f(g) int g {}',
1611 where the use of YYERROR1 above caused an error
1612 which then was handled by compstmt_or_error.
1613 There followed a repeated execution of that same rule,
1614 which called YYERROR1 again, and so on. */
1616 { tree decl = current_function_decl;
1617 finish_function (1, 1);
1618 pop_function_context ();
1619 add_decl_stmt (decl); }
1622 /* Any kind of declarator (thus, all declarators allowed
1623 after an explicit typespec). */
1626 after_type_declarator
1630 /* A declarator that is allowed only after an explicit typespec. */
1632 after_type_declarator:
1633 '(' maybe_attribute after_type_declarator ')'
1634 { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
1635 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1636 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1637 /* | after_type_declarator '(' error ')' %prec '.'
1638 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1639 poplevel (0, 0, 0); } */
1640 | after_type_declarator array_declarator %prec '.'
1641 { $$ = set_array_declarator_type ($2, $1, 0); }
1642 | '*' maybe_type_quals_attrs after_type_declarator %prec UNARY
1643 { $$ = make_pointer_declarator ($2, $3); }
1650 /* Kinds of declarator that can appear in a parameter list
1651 in addition to notype_declarator. This is like after_type_declarator
1652 but does not allow a typedef name in parentheses as an identifier
1653 (because it would conflict with a function with that typedef as arg). */
1655 parm_declarator_starttypename
1656 | parm_declarator_nostarttypename
1659 parm_declarator_starttypename:
1660 parm_declarator_starttypename '(' parmlist_or_identifiers %prec '.'
1661 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1662 /* | parm_declarator_starttypename '(' error ')' %prec '.'
1663 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1664 poplevel (0, 0, 0); } */
1665 | parm_declarator_starttypename array_declarator %prec '.'
1666 { $$ = set_array_declarator_type ($2, $1, 0); }
1673 parm_declarator_nostarttypename:
1674 parm_declarator_nostarttypename '(' parmlist_or_identifiers %prec '.'
1675 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1676 /* | parm_declarator_nostarttypename '(' error ')' %prec '.'
1677 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1678 poplevel (0, 0, 0); } */
1679 | parm_declarator_nostarttypename array_declarator %prec '.'
1680 { $$ = set_array_declarator_type ($2, $1, 0); }
1681 | '*' maybe_type_quals_attrs parm_declarator_starttypename %prec UNARY
1682 { $$ = make_pointer_declarator ($2, $3); }
1683 | '*' maybe_type_quals_attrs parm_declarator_nostarttypename %prec UNARY
1684 { $$ = make_pointer_declarator ($2, $3); }
1685 | '(' maybe_attribute parm_declarator_nostarttypename ')'
1686 { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
1689 /* A declarator allowed whether or not there has been
1690 an explicit typespec. These cannot redeclare a typedef-name. */
1693 notype_declarator '(' parmlist_or_identifiers %prec '.'
1694 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1695 /* | notype_declarator '(' error ')' %prec '.'
1696 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1697 poplevel (0, 0, 0); } */
1698 | '(' maybe_attribute notype_declarator ')'
1699 { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
1700 | '*' maybe_type_quals_attrs notype_declarator %prec UNARY
1701 { $$ = make_pointer_declarator ($2, $3); }
1702 | notype_declarator array_declarator %prec '.'
1703 { $$ = set_array_declarator_type ($2, $1, 0); }
1728 /* structsp_attr: struct/union/enum specifiers that either
1729 end with attributes, or are such that any following attributes would
1730 be parsed as part of the struct/union/enum specifier.
1732 structsp_nonattr: other struct/union/enum specifiers. */
1735 struct_head identifier '{'
1736 { $$ = start_struct (RECORD_TYPE, $2);
1737 /* Start scope of tag before parsing components. */
1739 component_decl_list '}' maybe_attribute
1740 { $$ = finish_struct ($<ttype>4, nreverse ($5),
1741 chainon ($1, $7)); }
1742 | struct_head '{' component_decl_list '}' maybe_attribute
1743 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1744 nreverse ($3), chainon ($1, $5));
1746 | union_head identifier '{'
1747 { $$ = start_struct (UNION_TYPE, $2); }
1748 component_decl_list '}' maybe_attribute
1749 { $$ = finish_struct ($<ttype>4, nreverse ($5),
1750 chainon ($1, $7)); }
1751 | union_head '{' component_decl_list '}' maybe_attribute
1752 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1753 nreverse ($3), chainon ($1, $5));
1755 | enum_head identifier '{'
1756 { $$ = start_enum ($2); }
1757 enumlist maybecomma_warn '}' maybe_attribute
1758 { $$ = finish_enum ($<ttype>4, nreverse ($5),
1759 chainon ($1, $8)); }
1761 { $$ = start_enum (NULL_TREE); }
1762 enumlist maybecomma_warn '}' maybe_attribute
1763 { $$ = finish_enum ($<ttype>3, nreverse ($4),
1764 chainon ($1, $7)); }
1768 struct_head identifier
1769 { $$ = xref_tag (RECORD_TYPE, $2); }
1770 | union_head identifier
1771 { $$ = xref_tag (UNION_TYPE, $2); }
1772 | enum_head identifier
1773 { $$ = xref_tag (ENUMERAL_TYPE, $2);
1774 /* In ISO C, enumerated types can be referred to
1775 only if already defined. */
1776 if (pedantic && !COMPLETE_TYPE_P ($$))
1777 pedwarn ("ISO C forbids forward references to `enum' types"); }
1788 { if (pedantic && ! flag_isoc99)
1789 pedwarn ("comma at end of enumerator list"); }
1792 /* We chain the components in reverse order. They are put in forward
1793 order in structsp_attr.
1795 Note that component_declarator returns single decls, so components
1796 and components_notype can use TREE_CHAIN directly, wheras components
1797 and components_notype return lists (of comma separated decls), so
1798 component_decl_list and component_decl_list2 must use chainon.
1800 The theory behind all this is that there will be more semicolon
1801 separated fields than comma separated fields, and so we'll be
1802 minimizing the number of node traversals required by chainon. */
1804 component_decl_list:
1805 component_decl_list2
1807 | component_decl_list2 component_decl
1808 { $$ = chainon ($2, $1);
1809 pedwarn ("no semicolon at end of struct or union"); }
1812 component_decl_list2: /* empty */
1814 | component_decl_list2 component_decl ';'
1815 { $$ = chainon ($2, $1); }
1816 | component_decl_list2 ';'
1818 pedwarn ("extra semicolon in struct or union specified"); }
1820 /* foo(sizeof(struct{ @defs(ClassName)})); */
1821 | DEFS '(' CLASSNAME ')'
1823 tree interface = lookup_interface ($3);
1826 $$ = nreverse (get_class_ivars (interface));
1829 error ("cannot find interface declaration for `%s'",
1830 IDENTIFIER_POINTER ($3));
1838 declspecs_nosc_ts setspecs components
1840 POP_DECLSPEC_STACK; }
1841 | declspecs_nosc_ts setspecs
1843 /* Support for unnamed structs or unions as members of
1844 structs or unions (which is [a] useful and [b] supports
1847 pedwarn ("ISO C doesn't support unnamed structs/unions");
1849 $$ = grokfield(NULL, current_declspecs, NULL_TREE);
1850 POP_DECLSPEC_STACK; }
1851 | declspecs_nosc_nots setspecs components_notype
1853 POP_DECLSPEC_STACK; }
1854 | declspecs_nosc_nots
1856 pedwarn ("ISO C forbids member declarations with no members");
1861 | extension component_decl
1863 RESTORE_EXT_FLAGS ($1); }
1867 component_declarator
1868 | components ',' maybe_resetattrs component_declarator
1869 { TREE_CHAIN ($4) = $1; $$ = $4; }
1873 component_notype_declarator
1874 | components_notype ',' maybe_resetattrs component_notype_declarator
1875 { TREE_CHAIN ($4) = $1; $$ = $4; }
1878 component_declarator:
1879 declarator maybe_attribute
1880 { $$ = grokfield ($1, current_declspecs, NULL_TREE);
1881 decl_attributes (&$$,
1882 chainon ($2, all_prefix_attributes), 0); }
1883 | declarator ':' expr_no_commas maybe_attribute
1884 { $$ = grokfield ($1, current_declspecs, $3);
1885 decl_attributes (&$$,
1886 chainon ($4, all_prefix_attributes), 0); }
1887 | ':' expr_no_commas maybe_attribute
1888 { $$ = grokfield (NULL_TREE, current_declspecs, $2);
1889 decl_attributes (&$$,
1890 chainon ($3, all_prefix_attributes), 0); }
1893 component_notype_declarator:
1894 notype_declarator maybe_attribute
1895 { $$ = grokfield ($1, current_declspecs, NULL_TREE);
1896 decl_attributes (&$$,
1897 chainon ($2, all_prefix_attributes), 0); }
1898 | notype_declarator ':' expr_no_commas maybe_attribute
1899 { $$ = grokfield ($1, current_declspecs, $3);
1900 decl_attributes (&$$,
1901 chainon ($4, all_prefix_attributes), 0); }
1902 | ':' expr_no_commas maybe_attribute
1903 { $$ = grokfield (NULL_TREE, current_declspecs, $2);
1904 decl_attributes (&$$,
1905 chainon ($3, all_prefix_attributes), 0); }
1908 /* We chain the enumerators in reverse order.
1909 They are put in forward order in structsp_attr. */
1913 | enumlist ',' enumerator
1914 { if ($1 == error_mark_node)
1917 TREE_CHAIN ($3) = $1, $$ = $3; }
1919 { $$ = error_mark_node; }
1925 { $$ = build_enumerator ($1, NULL_TREE); }
1926 | identifier '=' expr_no_commas
1927 { $$ = build_enumerator ($1, $3); }
1932 { pending_xref_error ();
1935 { $$ = build_tree_list ($<ttype>2, $3); }
1938 absdcl: /* an absolute declarator */
1944 absdcl_maybe_attribute: /* absdcl maybe_attribute, but not just attributes */
1946 { $$ = build_tree_list (build_tree_list (current_declspecs,
1948 all_prefix_attributes); }
1950 { $$ = build_tree_list (build_tree_list (current_declspecs,
1952 all_prefix_attributes); }
1953 | absdcl1_noea attributes
1954 { $$ = build_tree_list (build_tree_list (current_declspecs,
1956 chainon ($2, all_prefix_attributes)); }
1959 absdcl1: /* a nonempty absolute declarator */
1966 | '*' maybe_type_quals_attrs absdcl1_noea
1967 { $$ = make_pointer_declarator ($2, $3); }
1971 '*' maybe_type_quals_attrs
1972 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1973 | '*' maybe_type_quals_attrs absdcl1_ea
1974 { $$ = make_pointer_declarator ($2, $3); }
1978 '(' maybe_attribute absdcl1 ')'
1979 { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
1980 | direct_absdcl1 '(' parmlist
1981 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1982 | direct_absdcl1 array_declarator
1983 { $$ = set_array_declarator_type ($2, $1, 1); }
1985 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1987 { $$ = set_array_declarator_type ($1, NULL_TREE, 1); }
1990 /* The [...] part of a declarator for an array type. */
1993 '[' maybe_type_quals_attrs expr ']'
1994 { $$ = build_array_declarator ($3, $2, 0, 0); }
1995 | '[' maybe_type_quals_attrs ']'
1996 { $$ = build_array_declarator (NULL_TREE, $2, 0, 0); }
1997 | '[' maybe_type_quals_attrs '*' ']'
1998 { $$ = build_array_declarator (NULL_TREE, $2, 0, 1); }
1999 | '[' STATIC maybe_type_quals_attrs expr ']'
2000 { $$ = build_array_declarator ($4, $3, 1, 0); }
2001 /* declspecs_nosc_nots is a synonym for type_quals_attrs. */
2002 | '[' declspecs_nosc_nots STATIC expr ']'
2003 { $$ = build_array_declarator ($4, $2, 1, 0); }
2006 /* A nonempty series of declarations and statements (possibly followed by
2007 some labels) that can form the body of a compound statement.
2008 NOTE: we don't allow labels on declarations; this might seem like a
2009 natural extension, but there would be a conflict between attributes
2010 on the label and prefix attributes on the declaration. */
2013 lineno_stmt_decl_or_labels_ending_stmt
2014 | lineno_stmt_decl_or_labels_ending_decl
2015 | lineno_stmt_decl_or_labels_ending_label
2017 pedwarn ("deprecated use of label at end of compound statement");
2019 | lineno_stmt_decl_or_labels_ending_error
2022 lineno_stmt_decl_or_labels_ending_stmt:
2024 | lineno_stmt_decl_or_labels_ending_stmt lineno_stmt
2025 | lineno_stmt_decl_or_labels_ending_decl lineno_stmt
2026 | lineno_stmt_decl_or_labels_ending_label lineno_stmt
2027 | lineno_stmt_decl_or_labels_ending_error lineno_stmt
2030 lineno_stmt_decl_or_labels_ending_decl:
2032 | lineno_stmt_decl_or_labels_ending_stmt lineno_decl
2033 { if (pedantic && !flag_isoc99)
2034 pedwarn ("ISO C89 forbids mixed declarations and code"); }
2035 | lineno_stmt_decl_or_labels_ending_decl lineno_decl
2036 | lineno_stmt_decl_or_labels_ending_error lineno_decl
2039 lineno_stmt_decl_or_labels_ending_label:
2041 | lineno_stmt_decl_or_labels_ending_stmt lineno_label
2042 | lineno_stmt_decl_or_labels_ending_decl lineno_label
2043 | lineno_stmt_decl_or_labels_ending_label lineno_label
2044 | lineno_stmt_decl_or_labels_ending_error lineno_label
2047 lineno_stmt_decl_or_labels_ending_error:
2049 | lineno_stmt_decl_or_labels errstmt
2052 lineno_stmt_decl_or_labels:
2053 lineno_stmt_decl_or_labels_ending_stmt
2054 | lineno_stmt_decl_or_labels_ending_decl
2055 | lineno_stmt_decl_or_labels_ending_label
2056 | lineno_stmt_decl_or_labels_ending_error
2062 pushlevel: /* empty */
2065 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
2067 if (objc_method_context)
2073 poplevel: /* empty */
2074 { $$ = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0); }
2077 /* Start and end blocks created for the new scopes of C99. */
2078 c99_block_start: /* empty */
2081 $$ = c_begin_compound_stmt ();
2084 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
2086 if (objc_method_context)
2095 /* Productions using c99_block_start and c99_block_end will need to do what's
2096 in compstmt: RECHAIN_STMTS ($1, COMPOUND_BODY ($1)); $$ = $2; where
2097 $1 is the value of c99_block_start and $2 of c99_block_end. */
2098 c99_block_end: /* empty */
2101 tree scope_stmt = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
2102 $$ = poplevel (kept_level_p (), 0, 0);
2103 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmt))
2104 = SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmt))
2111 /* Read zero or more forward-declarations for labels
2112 that nested functions can jump to. */
2117 pedwarn ("ISO C forbids label declarations"); }
2122 | label_decls label_decl
2126 LABEL identifiers_or_typenames ';'
2128 for (link = $2; link; link = TREE_CHAIN (link))
2130 tree label = shadow_label (TREE_VALUE (link));
2131 C_DECLARED_LABEL_FLAG (label) = 1;
2132 add_decl_stmt (label);
2137 /* This is the body of a function definition.
2138 It causes syntax errors to ignore to the next openbrace. */
2145 compstmt_start: '{' { compstmt_count++;
2146 $$ = c_begin_compound_stmt (); }
2149 compstmt_nostart: '}'
2150 { $$ = convert (void_type_node, integer_zero_node); }
2151 | pushlevel maybe_label_decls compstmt_contents_nonempty '}' poplevel
2152 { $$ = poplevel (kept_level_p (), 1, 0);
2153 SCOPE_STMT_BLOCK (TREE_PURPOSE ($5))
2154 = SCOPE_STMT_BLOCK (TREE_VALUE ($5))
2158 compstmt_contents_nonempty:
2163 compstmt_primary_start:
2165 { if (current_function_decl == 0)
2167 error ("braced-group within expression allowed only inside a function");
2170 /* We must force a BLOCK for this level
2171 so that, if it is not expanded later,
2172 there is a way to turn off the entire subtree of blocks
2173 that are contained in it. */
2175 push_label_level ();
2177 $$ = add_stmt (build_stmt (COMPOUND_STMT, last_tree));
2181 compstmt: compstmt_start compstmt_nostart
2182 { RECHAIN_STMTS ($1, COMPOUND_BODY ($1));
2183 last_expr_type = NULL_TREE;
2187 /* Value is number of statements counted as of the closeparen. */
2189 if_prefix c99_block_lineno_labeled_stmt
2190 { c_finish_then (); }
2191 /* Make sure c_expand_end_cond is run once
2192 for each call to c_expand_start_cond.
2193 Otherwise a crash is likely. */
2198 /* We must build the IF_STMT node before parsing its
2199 condition so that STMT_LINENO refers to the line
2200 containing the "if", and not the line containing
2201 the close-parenthesis.
2203 c_begin_if_stmt returns the IF_STMT node, which
2204 we later pass to c_expand_start_cond to fill
2205 in the condition and other tidbits. */
2207 { $<ttype>$ = c_begin_if_stmt (); }
2209 { c_expand_start_cond (c_common_truthvalue_conversion ($4),
2210 compstmt_count,$<ttype>2);
2211 $<itype>$ = stmt_count;
2212 if_stmt_locus = $<location>-1; }
2215 /* This is a subroutine of stmt.
2216 It is used twice, once for valid DO statements
2217 and once for catching errors in parsing the end test. */
2223 = add_stmt (build_stmt (DO_STMT, NULL_TREE,
2225 /* In the event that a parse error prevents
2226 parsing the complete do-statement, set the
2227 condition now. Otherwise, we can get crashes at
2228 RTL-generation time. */
2229 DO_COND ($<ttype>$) = error_mark_node; }
2230 c99_block_lineno_labeled_stmt WHILE
2232 RECHAIN_STMTS ($$, DO_BODY ($$)); }
2235 /* The forced readahead in here is because we might be at the end of a
2236 line, and the line and file won't be bumped until yylex absorbs the
2237 first token on the next line. */
2240 { if (yychar == YYEMPTY)
2242 $$ = input_location; }
2245 lineno_labeled_stmt:
2247 | lineno_label lineno_labeled_stmt
2250 /* Like lineno_labeled_stmt, but a block in C99. */
2251 c99_block_lineno_labeled_stmt:
2252 c99_block_start lineno_labeled_stmt c99_block_end
2254 RECHAIN_STMTS ($1, COMPOUND_BODY ($1)); }
2261 STMT_LINENO ($2) = $1.line;
2262 /* ??? We currently have no way of recording
2263 the filename for a statement. This probably
2264 matters little in practice at the moment,
2265 but I suspect that problems will occur when
2266 doing inlining at the tree level. */
2275 STMT_LINENO ($2) = $1.line;
2280 select_or_iter_stmt:
2282 { c_expand_start_else ();
2283 $<itype>1 = stmt_count; }
2284 c99_block_lineno_labeled_stmt
2286 c_expand_end_cond ();
2287 if (extra_warnings && stmt_count == $<itype>1)
2288 warning ("empty body in an else-statement"); }
2289 | simple_if %prec IF
2290 { c_expand_end_cond ();
2291 /* This warning is here instead of in simple_if, because we
2292 do not want a warning if an empty if is followed by an
2293 else statement. Increment stmt_count so we don't
2294 give a second error if this is a nested `if'. */
2295 if (extra_warnings && stmt_count++ == $<itype>1)
2296 warning ("%Hempty body in an if-statement",
2298 /* Make sure c_expand_end_cond is run once
2299 for each call to c_expand_start_cond.
2300 Otherwise a crash is likely. */
2301 | simple_if ELSE error
2302 { c_expand_end_cond (); }
2303 /* We must build the WHILE_STMT node before parsing its
2304 condition so that STMT_LINENO refers to the line
2305 containing the "while", and not the line containing
2306 the close-parenthesis.
2308 c_begin_while_stmt returns the WHILE_STMT node, which
2309 we later pass to c_finish_while_stmt_cond to fill
2310 in the condition and other tidbits. */
2313 $<ttype>$ = c_begin_while_stmt (); }
2315 { $4 = c_common_truthvalue_conversion ($4);
2316 c_finish_while_stmt_cond
2317 (c_common_truthvalue_conversion ($4), $<ttype>2);
2318 $<ttype>$ = add_stmt ($<ttype>2); }
2319 c99_block_lineno_labeled_stmt
2320 { RECHAIN_STMTS ($<ttype>6, WHILE_BODY ($<ttype>6)); }
2323 { DO_COND ($1) = c_common_truthvalue_conversion ($3); }
2324 | do_stmt_start error
2327 { $<ttype>$ = build_stmt (FOR_STMT, NULL_TREE, NULL_TREE,
2328 NULL_TREE, NULL_TREE);
2329 add_stmt ($<ttype>$); }
2332 RECHAIN_STMTS ($<ttype>2, FOR_INIT_STMT ($<ttype>2)); }
2335 FOR_COND ($<ttype>2)
2336 = c_common_truthvalue_conversion ($6); }
2338 { FOR_EXPR ($<ttype>2) = $9; }
2339 c99_block_lineno_labeled_stmt
2340 { RECHAIN_STMTS ($<ttype>2, FOR_BODY ($<ttype>2)); }
2341 | SWITCH '(' expr ')'
2343 $<ttype>$ = c_start_case ($3); }
2344 c99_block_lineno_labeled_stmt
2345 { c_finish_case (); }
2350 { add_stmt (build_stmt (EXPR_STMT, $1)); }
2352 { check_for_loop_decls (); }
2355 /* Parse a single real statement, not including any labels. */
2358 { stmt_count++; $$ = $1; }
2361 $$ = c_expand_expr_stmt ($1); }
2362 | c99_block_start select_or_iter_stmt c99_block_end
2364 RECHAIN_STMTS ($1, COMPOUND_BODY ($1));
2368 $$ = add_stmt (build_break_stmt ()); }
2371 $$ = add_stmt (build_continue_stmt ()); }
2374 $$ = c_expand_return (NULL_TREE); }
2377 $$ = c_expand_return ($2); }
2378 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
2380 $$ = simple_asm_stmt ($4); }
2381 /* This is the case with just output operands. */
2382 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
2384 $$ = build_asm_stmt ($2, $4, $6, NULL_TREE, NULL_TREE); }
2385 /* This is the case with input operands as well. */
2386 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
2387 asm_operands ')' ';'
2389 $$ = build_asm_stmt ($2, $4, $6, $8, NULL_TREE); }
2390 /* This is the case with clobbered registers as well. */
2391 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
2392 asm_operands ':' asm_clobbers ')' ';'
2394 $$ = build_asm_stmt ($2, $4, $6, $8, $10); }
2395 | GOTO identifier ';'
2398 decl = lookup_label ($2);
2401 TREE_USED (decl) = 1;
2402 $$ = add_stmt (build_stmt (GOTO_STMT, decl));
2409 pedwarn ("ISO C forbids `goto *expr;'");
2411 $3 = convert (ptr_type_node, $3);
2412 $$ = add_stmt (build_stmt (GOTO_STMT, $3)); }
2417 /* Any kind of label, including jump labels and case labels.
2418 ANSI C accepts labels only before statements, but we allow them
2419 also at the end of a compound statement. */
2421 label: CASE expr_no_commas ':'
2423 $$ = do_case ($2, NULL_TREE); }
2424 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
2426 $$ = do_case ($2, $4); }
2429 $$ = do_case (NULL_TREE, NULL_TREE); }
2430 | identifier save_location ':' maybe_attribute
2431 { tree label = define_label ($2, $1);
2435 decl_attributes (&label, $4, 0);
2436 $$ = add_stmt (build_stmt (LABEL_STMT, label));
2443 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
2447 { emit_line_note (input_location);
2450 { emit_line_note (input_location); }
2459 /* These are the operands other than the first string and colon
2460 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2461 asm_operands: /* empty */
2463 | nonnull_asm_operands
2466 nonnull_asm_operands:
2468 | nonnull_asm_operands ',' asm_operand
2469 { $$ = chainon ($1, $3); }
2474 { $$ = build_tree_list (build_tree_list (NULL_TREE, $1), $3); }
2475 | '[' identifier ']' STRING '(' expr ')'
2476 { $2 = build_string (IDENTIFIER_LENGTH ($2),
2477 IDENTIFIER_POINTER ($2));
2478 $$ = build_tree_list (build_tree_list ($2, $4), $6); }
2483 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
2484 | asm_clobbers ',' STRING
2485 { $$ = tree_cons (NULL_TREE, $3, $1); }
2488 /* This is what appears inside the parens in a function declarator.
2489 Its value is a list of ..._TYPE nodes. Attributes must appear here
2490 to avoid a conflict with their appearance after an open parenthesis
2491 in an abstract declarator, as in
2492 "void bar (int (__attribute__((__mode__(SI))) int foo));". */
2496 clear_parm_order ();
2497 declare_parm_level (0); }
2500 parmlist_tags_warning ();
2501 poplevel (0, 0, 0); }
2509 pedwarn ("ISO C forbids forward parameter declarations");
2510 /* Mark the forward decls as such. */
2511 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2512 TREE_ASM_WRITTEN (parm) = 1;
2513 clear_parm_order (); }
2515 { /* Dummy action so attributes are in known place
2516 on parser stack. */ }
2520 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2523 /* This is what appears inside the parens in a function declarator.
2524 Is value is represented in the format that grokdeclarator expects. */
2525 parmlist_2: /* empty */
2526 { $$ = get_parm_info (0); }
2528 { $$ = get_parm_info (0);
2529 /* Gcc used to allow this as an extension. However, it does
2530 not work for all targets, and thus has been disabled.
2531 Also, since func (...) and func () are indistinguishable,
2532 it caused problems with the code in expand_builtin which
2533 tries to verify that BUILT_IN_NEXT_ARG is being used
2535 error ("ISO C requires a named argument before `...'");
2538 { $$ = get_parm_info (1);
2539 parsing_iso_function_signature = true;
2541 | parms ',' ELLIPSIS
2542 { $$ = get_parm_info (0); }
2547 { push_parm_decl ($1); }
2549 { push_parm_decl ($3); }
2552 /* A single parameter declaration or parameter type name,
2553 as found in a parmlist. */
2555 declspecs_ts setspecs parm_declarator maybe_attribute
2556 { $$ = build_tree_list (build_tree_list (current_declspecs,
2558 chainon ($4, all_prefix_attributes));
2559 POP_DECLSPEC_STACK; }
2560 | declspecs_ts setspecs notype_declarator maybe_attribute
2561 { $$ = build_tree_list (build_tree_list (current_declspecs,
2563 chainon ($4, all_prefix_attributes));
2564 POP_DECLSPEC_STACK; }
2565 | declspecs_ts setspecs absdcl_maybe_attribute
2567 POP_DECLSPEC_STACK; }
2568 | declspecs_nots setspecs notype_declarator maybe_attribute
2569 { $$ = build_tree_list (build_tree_list (current_declspecs,
2571 chainon ($4, all_prefix_attributes));
2572 POP_DECLSPEC_STACK; }
2574 | declspecs_nots setspecs absdcl_maybe_attribute
2576 POP_DECLSPEC_STACK; }
2579 /* The first parm, which must suck attributes from off the top of the parser
2582 declspecs_ts_nosa setspecs_fp parm_declarator maybe_attribute
2583 { $$ = build_tree_list (build_tree_list (current_declspecs,
2585 chainon ($4, all_prefix_attributes));
2586 POP_DECLSPEC_STACK; }
2587 | declspecs_ts_nosa setspecs_fp notype_declarator maybe_attribute
2588 { $$ = build_tree_list (build_tree_list (current_declspecs,
2590 chainon ($4, all_prefix_attributes));
2591 POP_DECLSPEC_STACK; }
2592 | declspecs_ts_nosa setspecs_fp absdcl_maybe_attribute
2594 POP_DECLSPEC_STACK; }
2595 | declspecs_nots_nosa setspecs_fp notype_declarator maybe_attribute
2596 { $$ = build_tree_list (build_tree_list (current_declspecs,
2598 chainon ($4, all_prefix_attributes));
2599 POP_DECLSPEC_STACK; }
2601 | declspecs_nots_nosa setspecs_fp absdcl_maybe_attribute
2603 POP_DECLSPEC_STACK; }
2608 { prefix_attributes = chainon (prefix_attributes, $<ttype>-2);
2609 all_prefix_attributes = prefix_attributes; }
2612 /* This is used in a function definition
2613 where either a parmlist or an identifier list is ok.
2614 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2615 parmlist_or_identifiers:
2618 clear_parm_order ();
2619 declare_parm_level (1); }
2620 parmlist_or_identifiers_1
2622 parmlist_tags_warning ();
2623 poplevel (0, 0, 0); }
2626 parmlist_or_identifiers_1:
2630 for (t = $1; t; t = TREE_CHAIN (t))
2631 if (TREE_VALUE (t) == NULL_TREE)
2632 error ("`...' in old-style identifier list");
2633 $$ = tree_cons (NULL_TREE, NULL_TREE, $1);
2635 /* Make sure we have a parmlist after attributes. */
2637 && (TREE_CODE ($$) != TREE_LIST
2638 || TREE_PURPOSE ($$) == 0
2639 || TREE_CODE (TREE_PURPOSE ($$)) != PARM_DECL))
2644 /* A nonempty list of identifiers. */
2647 { $$ = build_tree_list (NULL_TREE, $1); }
2648 | identifiers ',' IDENTIFIER
2649 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2652 /* A nonempty list of identifiers, including typenames. */
2653 identifiers_or_typenames:
2655 { $$ = build_tree_list (NULL_TREE, $1); }
2656 | identifiers_or_typenames ',' identifier
2657 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2662 { $$ = SAVE_EXT_FLAGS();
2664 warn_pointer_arith = 0;
2665 warn_traditional = 0;
2670 /* Objective-C productions. */
2680 if (objc_implementation_context)
2682 finish_class (objc_implementation_context);
2683 objc_ivar_chain = NULL_TREE;
2684 objc_implementation_context = NULL_TREE;
2687 warning ("`@end' must appear in an implementation context");
2691 /* A nonempty list of identifiers. */
2694 { $$ = build_tree_list (NULL_TREE, $1); }
2695 | identifier_list ',' identifier
2696 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2700 CLASS identifier_list ';'
2702 objc_declare_class ($2);
2707 ALIAS identifier identifier ';'
2709 objc_declare_alias ($2, $3);
2714 INTERFACE identifier protocolrefs '{'
2716 objc_interface_context = objc_ivar_context
2717 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2718 objc_public_flag = 0;
2722 continue_class (objc_interface_context);
2727 finish_class (objc_interface_context);
2728 objc_interface_context = NULL_TREE;
2731 | INTERFACE identifier protocolrefs
2733 objc_interface_context
2734 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2735 continue_class (objc_interface_context);
2740 finish_class (objc_interface_context);
2741 objc_interface_context = NULL_TREE;
2744 | INTERFACE identifier ':' identifier protocolrefs '{'
2746 objc_interface_context = objc_ivar_context
2747 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2748 objc_public_flag = 0;
2752 continue_class (objc_interface_context);
2757 finish_class (objc_interface_context);
2758 objc_interface_context = NULL_TREE;
2761 | INTERFACE identifier ':' identifier protocolrefs
2763 objc_interface_context
2764 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2765 continue_class (objc_interface_context);
2770 finish_class (objc_interface_context);
2771 objc_interface_context = NULL_TREE;
2774 | IMPLEMENTATION identifier '{'
2776 objc_implementation_context = objc_ivar_context
2777 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2778 objc_public_flag = 0;
2783 = continue_class (objc_implementation_context);
2786 | IMPLEMENTATION identifier
2788 objc_implementation_context
2789 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2791 = continue_class (objc_implementation_context);
2794 | IMPLEMENTATION identifier ':' identifier '{'
2796 objc_implementation_context = objc_ivar_context
2797 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2798 objc_public_flag = 0;
2803 = continue_class (objc_implementation_context);
2806 | IMPLEMENTATION identifier ':' identifier
2808 objc_implementation_context
2809 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2811 = continue_class (objc_implementation_context);
2814 | INTERFACE identifier '(' identifier ')' protocolrefs
2816 objc_interface_context
2817 = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2818 continue_class (objc_interface_context);
2823 finish_class (objc_interface_context);
2824 objc_interface_context = NULL_TREE;
2827 | IMPLEMENTATION identifier '(' identifier ')'
2829 objc_implementation_context
2830 = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2832 = continue_class (objc_implementation_context);
2837 PROTOCOL identifier protocolrefs
2839 objc_pq_context = 1;
2840 objc_interface_context
2841 = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2845 objc_pq_context = 0;
2846 finish_protocol(objc_interface_context);
2847 objc_interface_context = NULL_TREE;
2849 /* The @protocol forward-declaration production introduces a
2850 reduce/reduce conflict on ';', which should be resolved in
2851 favor of the production 'identifier_list -> identifier'. */
2852 | PROTOCOL identifier_list ';'
2854 objc_declare_protocols ($2);
2863 | non_empty_protocolrefs
2866 non_empty_protocolrefs:
2867 ARITHCOMPARE identifier_list ARITHCOMPARE
2869 if ($1 == LT_EXPR && $3 == GT_EXPR)
2877 ivar_decl_list visibility_spec ivar_decls
2882 PRIVATE { objc_public_flag = 2; }
2883 | PROTECTED { objc_public_flag = 0; }
2884 | PUBLIC { objc_public_flag = 1; }
2892 | ivar_decls ivar_decl ';'
2896 pedwarn ("extra semicolon in struct or union specified");
2901 /* There is a shift-reduce conflict here, because `components' may
2902 start with a `typename'. It happens that shifting (the default resolution)
2903 does the right thing, because it treats the `typename' as part of
2904 a `typed_typespecs'.
2906 It is possible that this same technique would allow the distinction
2907 between `notype_initdecls' and `initdecls' to be eliminated.
2908 But I am being cautious and not trying it. */
2911 declspecs_nosc_ts setspecs ivars
2913 POP_DECLSPEC_STACK; }
2914 | declspecs_nosc_nots setspecs ivars
2916 POP_DECLSPEC_STACK; }
2925 | ivars ',' maybe_resetattrs ivar_declarator
2931 $$ = add_instance_variable (objc_ivar_context,
2933 $1, current_declspecs,
2936 | declarator ':' expr_no_commas
2938 $$ = add_instance_variable (objc_ivar_context,
2940 $1, current_declspecs, $3);
2942 | ':' expr_no_commas
2944 $$ = add_instance_variable (objc_ivar_context,
2947 current_declspecs, $2);
2953 { objc_inherit_code = CLASS_METHOD_DECL; }
2955 { objc_inherit_code = INSTANCE_METHOD_DECL; }
2961 objc_pq_context = 1;
2962 if (!objc_implementation_context)
2963 fatal_error ("method definition not in class context");
2967 objc_pq_context = 0;
2968 if (objc_inherit_code == CLASS_METHOD_DECL)
2969 add_class_method (objc_implementation_context, $3);
2971 add_instance_method (objc_implementation_context, $3);
2972 start_method_def ($3);
2976 continue_method_def ();
2980 finish_method_def ();
2984 /* the reason for the strange actions in this rule
2985 is so that notype_initdecls when reached via datadef
2986 can find a valid list of type and sc specs in $0. */
2990 | {$<ttype>$ = NULL_TREE; } methodprotolist2
2993 methodprotolist2: /* eliminates a shift/reduce conflict */
2996 | methodprotolist2 methodproto
2997 | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
3008 /* Remember protocol qualifiers in prototypes. */
3009 objc_pq_context = 1;
3013 /* Forget protocol qualifiers here. */
3014 objc_pq_context = 0;
3015 if (objc_inherit_code == CLASS_METHOD_DECL)
3016 add_class_method (objc_interface_context, $3);
3018 add_instance_method (objc_interface_context, $3);
3024 '(' typename ')' unaryselector
3026 $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
3031 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
3034 | '(' typename ')' keywordselector optparmlist
3036 $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
3039 | keywordselector optparmlist
3041 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
3045 /* "optarglist" assumes that start_method_def has already been called...
3046 if it is not, the "xdecls" will not be placed in the proper scope */
3053 /* to get around the following situation: "int foo (int a) int b; {}" that
3054 is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
3069 declspecs_ts setspecs myparms ';'
3070 { POP_DECLSPEC_STACK; }
3072 { shadow_tag ($1); }
3073 | declspecs_nots ';'
3074 { pedwarn ("empty declaration"); }
3079 { push_parm_decl ($1); }
3080 | myparms ',' myparm
3081 { push_parm_decl ($3); }
3084 /* A single parameter declaration or parameter type name,
3085 as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
3088 parm_declarator maybe_attribute
3089 { $$ = build_tree_list (build_tree_list (current_declspecs,
3091 chainon ($2, all_prefix_attributes)); }
3092 | notype_declarator maybe_attribute
3093 { $$ = build_tree_list (build_tree_list (current_declspecs,
3095 chainon ($2, all_prefix_attributes)); }
3096 | absdcl_maybe_attribute
3107 /* oh what a kludge! */
3108 $$ = objc_ellipsis_node;
3116 /* returns a tree list node generated by get_parm_info */
3129 | keywordselector keyworddecl
3131 $$ = chainon ($1, $2);
3144 ENUM | STRUCT | UNION | IF | ELSE | WHILE | DO | FOR
3145 | SWITCH | CASE | DEFAULT | BREAK | CONTINUE | RETURN
3146 | GOTO | ASM_KEYWORD | SIZEOF | TYPEOF | ALIGNOF
3147 | TYPESPEC | TYPE_QUAL
3151 selector ':' '(' typename ')' identifier
3153 $$ = build_keyword_decl ($1, $4, $6);
3156 | selector ':' identifier
3158 $$ = build_keyword_decl ($1, NULL_TREE, $3);
3161 | ':' '(' typename ')' identifier
3163 $$ = build_keyword_decl (NULL_TREE, $3, $5);
3168 $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
3179 | keywordarglist keywordarg
3181 $$ = chainon ($1, $2);
3189 if (TREE_CHAIN ($1) == NULL_TREE)
3190 /* just return the expr., remove a level of indirection */
3191 $$ = TREE_VALUE ($1);
3193 /* we have a comma expr., we will collapse later */
3199 selector ':' keywordexpr
3201 $$ = build_tree_list ($1, $3);
3205 $$ = build_tree_list (NULL_TREE, $2);
3213 $$ = get_class_reference ($1);
3218 '[' receiver messageargs ']'
3219 { $$ = build_tree_list ($2, $3); }
3229 | keywordnamelist keywordname
3231 $$ = chainon ($1, $2);
3238 $$ = build_tree_list ($1, NULL_TREE);
3242 $$ = build_tree_list (NULL_TREE, NULL_TREE);
3247 SELECTOR '(' selectorarg ')'
3254 PROTOCOL '(' identifier ')'
3260 /* extension to support C-structures in the archiver */
3263 ENCODE '(' typename ')'
3265 $$ = groktypename ($3);
3272 /* yylex() is a thin wrapper around c_lex(), all it does is translate
3273 cpplib.h's token codes into yacc's token codes. */
3275 static enum cpp_ttype last_token;
3277 /* The reserved keyword table. */
3281 ENUM_BITFIELD(rid) rid : 16;
3282 unsigned int disable : 16;
3285 /* Disable mask. Keywords are disabled if (reswords[i].disable & mask) is
3287 #define D_C89 0x01 /* not in C89 */
3288 #define D_EXT 0x02 /* GCC extension */
3289 #define D_EXT89 0x04 /* GCC extension incorporated in C99 */
3290 #define D_OBJC 0x08 /* Objective C only */
3292 static const struct resword reswords[] =
3294 { "_Bool", RID_BOOL, 0 },
3295 { "_Complex", RID_COMPLEX, 0 },
3296 { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
3297 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
3298 { "__alignof", RID_ALIGNOF, 0 },
3299 { "__alignof__", RID_ALIGNOF, 0 },
3300 { "__asm", RID_ASM, 0 },
3301 { "__asm__", RID_ASM, 0 },
3302 { "__attribute", RID_ATTRIBUTE, 0 },
3303 { "__attribute__", RID_ATTRIBUTE, 0 },
3304 { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
3305 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
3306 { "__builtin_va_arg", RID_VA_ARG, 0 },
3307 { "__complex", RID_COMPLEX, 0 },
3308 { "__complex__", RID_COMPLEX, 0 },
3309 { "__const", RID_CONST, 0 },
3310 { "__const__", RID_CONST, 0 },
3311 { "__extension__", RID_EXTENSION, 0 },
3312 { "__func__", RID_C99_FUNCTION_NAME, 0 },
3313 { "__imag", RID_IMAGPART, 0 },
3314 { "__imag__", RID_IMAGPART, 0 },
3315 { "__inline", RID_INLINE, 0 },
3316 { "__inline__", RID_INLINE, 0 },
3317 { "__label__", RID_LABEL, 0 },
3318 { "__ptrbase", RID_PTRBASE, 0 },
3319 { "__ptrbase__", RID_PTRBASE, 0 },
3320 { "__ptrextent", RID_PTREXTENT, 0 },
3321 { "__ptrextent__", RID_PTREXTENT, 0 },
3322 { "__ptrvalue", RID_PTRVALUE, 0 },
3323 { "__ptrvalue__", RID_PTRVALUE, 0 },
3324 { "__real", RID_REALPART, 0 },
3325 { "__real__", RID_REALPART, 0 },
3326 { "__restrict", RID_RESTRICT, 0 },
3327 { "__restrict__", RID_RESTRICT, 0 },
3328 { "__signed", RID_SIGNED, 0 },
3329 { "__signed__", RID_SIGNED, 0 },
3330 { "__thread", RID_THREAD, 0 },
3331 { "__typeof", RID_TYPEOF, 0 },
3332 { "__typeof__", RID_TYPEOF, 0 },
3333 { "__volatile", RID_VOLATILE, 0 },
3334 { "__volatile__", RID_VOLATILE, 0 },
3335 { "asm", RID_ASM, D_EXT },
3336 { "auto", RID_AUTO, 0 },
3337 { "break", RID_BREAK, 0 },
3338 { "case", RID_CASE, 0 },
3339 { "char", RID_CHAR, 0 },
3340 { "const", RID_CONST, 0 },
3341 { "continue", RID_CONTINUE, 0 },
3342 { "default", RID_DEFAULT, 0 },
3343 { "do", RID_DO, 0 },
3344 { "double", RID_DOUBLE, 0 },
3345 { "else", RID_ELSE, 0 },
3346 { "enum", RID_ENUM, 0 },
3347 { "extern", RID_EXTERN, 0 },
3348 { "float", RID_FLOAT, 0 },
3349 { "for", RID_FOR, 0 },
3350 { "goto", RID_GOTO, 0 },
3351 { "if", RID_IF, 0 },
3352 { "inline", RID_INLINE, D_EXT89 },
3353 { "int", RID_INT, 0 },
3354 { "long", RID_LONG, 0 },
3355 { "register", RID_REGISTER, 0 },
3356 { "restrict", RID_RESTRICT, D_C89 },
3357 { "return", RID_RETURN, 0 },
3358 { "short", RID_SHORT, 0 },
3359 { "signed", RID_SIGNED, 0 },
3360 { "sizeof", RID_SIZEOF, 0 },
3361 { "static", RID_STATIC, 0 },
3362 { "struct", RID_STRUCT, 0 },
3363 { "switch", RID_SWITCH, 0 },
3364 { "typedef", RID_TYPEDEF, 0 },
3365 { "typeof", RID_TYPEOF, D_EXT },
3366 { "union", RID_UNION, 0 },
3367 { "unsigned", RID_UNSIGNED, 0 },
3368 { "void", RID_VOID, 0 },
3369 { "volatile", RID_VOLATILE, 0 },
3370 { "while", RID_WHILE, 0 },
3372 { "id", RID_ID, D_OBJC },
3374 /* These objc keywords are recognized only immediately after
3376 { "class", RID_AT_CLASS, D_OBJC },
3377 { "compatibility_alias", RID_AT_ALIAS, D_OBJC },
3378 { "defs", RID_AT_DEFS, D_OBJC },
3379 { "encode", RID_AT_ENCODE, D_OBJC },
3380 { "end", RID_AT_END, D_OBJC },
3381 { "implementation", RID_AT_IMPLEMENTATION, D_OBJC },
3382 { "interface", RID_AT_INTERFACE, D_OBJC },
3383 { "private", RID_AT_PRIVATE, D_OBJC },
3384 { "protected", RID_AT_PROTECTED, D_OBJC },
3385 { "protocol", RID_AT_PROTOCOL, D_OBJC },
3386 { "public", RID_AT_PUBLIC, D_OBJC },
3387 { "selector", RID_AT_SELECTOR, D_OBJC },
3389 /* These are recognized only in protocol-qualifier context
3391 { "bycopy", RID_BYCOPY, D_OBJC },
3392 { "byref", RID_BYREF, D_OBJC },
3393 { "in", RID_IN, D_OBJC },
3394 { "inout", RID_INOUT, D_OBJC },
3395 { "oneway", RID_ONEWAY, D_OBJC },
3396 { "out", RID_OUT, D_OBJC },
3399 #define N_reswords (sizeof reswords / sizeof (struct resword))
3401 /* Table mapping from RID_* constants to yacc token numbers.
3402 Unfortunately we have to have entries for all the keywords in all
3404 static const short rid_to_yy[RID_MAX] =
3406 /* RID_STATIC */ STATIC,
3407 /* RID_UNSIGNED */ TYPESPEC,
3408 /* RID_LONG */ TYPESPEC,
3409 /* RID_CONST */ TYPE_QUAL,
3410 /* RID_EXTERN */ SCSPEC,
3411 /* RID_REGISTER */ SCSPEC,
3412 /* RID_TYPEDEF */ SCSPEC,
3413 /* RID_SHORT */ TYPESPEC,
3414 /* RID_INLINE */ SCSPEC,
3415 /* RID_VOLATILE */ TYPE_QUAL,
3416 /* RID_SIGNED */ TYPESPEC,
3417 /* RID_AUTO */ SCSPEC,
3418 /* RID_RESTRICT */ TYPE_QUAL,
3421 /* RID_COMPLEX */ TYPESPEC,
3422 /* RID_THREAD */ SCSPEC,
3426 /* RID_VIRTUAL */ 0,
3427 /* RID_EXPLICIT */ 0,
3429 /* RID_MUTABLE */ 0,
3432 /* RID_IN */ TYPE_QUAL,
3433 /* RID_OUT */ TYPE_QUAL,
3434 /* RID_INOUT */ TYPE_QUAL,
3435 /* RID_BYCOPY */ TYPE_QUAL,
3436 /* RID_BYREF */ TYPE_QUAL,
3437 /* RID_ONEWAY */ TYPE_QUAL,
3440 /* RID_INT */ TYPESPEC,
3441 /* RID_CHAR */ TYPESPEC,
3442 /* RID_FLOAT */ TYPESPEC,
3443 /* RID_DOUBLE */ TYPESPEC,
3444 /* RID_VOID */ TYPESPEC,
3445 /* RID_ENUM */ ENUM,
3446 /* RID_STRUCT */ STRUCT,
3447 /* RID_UNION */ UNION,
3449 /* RID_ELSE */ ELSE,
3450 /* RID_WHILE */ WHILE,
3453 /* RID_SWITCH */ SWITCH,
3454 /* RID_CASE */ CASE,
3455 /* RID_DEFAULT */ DEFAULT,
3456 /* RID_BREAK */ BREAK,
3457 /* RID_CONTINUE */ CONTINUE,
3458 /* RID_RETURN */ RETURN,
3459 /* RID_GOTO */ GOTO,
3460 /* RID_SIZEOF */ SIZEOF,
3463 /* RID_ASM */ ASM_KEYWORD,
3464 /* RID_TYPEOF */ TYPEOF,
3465 /* RID_ALIGNOF */ ALIGNOF,
3466 /* RID_ATTRIBUTE */ ATTRIBUTE,
3467 /* RID_VA_ARG */ VA_ARG,
3468 /* RID_EXTENSION */ EXTENSION,
3469 /* RID_IMAGPART */ IMAGPART,
3470 /* RID_REALPART */ REALPART,
3471 /* RID_LABEL */ LABEL,
3472 /* RID_PTRBASE */ PTR_BASE,
3473 /* RID_PTREXTENT */ PTR_EXTENT,
3474 /* RID_PTRVALUE */ PTR_VALUE,
3476 /* RID_CHOOSE_EXPR */ CHOOSE_EXPR,
3477 /* RID_TYPES_COMPATIBLE_P */ TYPES_COMPATIBLE_P,
3479 /* RID_FUNCTION_NAME */ FUNC_NAME,
3480 /* RID_PRETTY_FUNCTION_NAME */ FUNC_NAME,
3481 /* RID_C99_FUNCTION_NAME */ FUNC_NAME,
3484 /* RID_BOOL */ TYPESPEC,
3488 /* RID_PRIVATE */ 0,
3489 /* RID_PROTECTED */ 0,
3490 /* RID_TEMPLATE */ 0,
3495 /* RID_NAMESPACE */ 0,
3497 /* RID_OPERATOR */ 0,
3502 /* RID_TYPENAME */ 0,
3507 /* RID_CONSTCAST */ 0,
3508 /* RID_DYNCAST */ 0,
3509 /* RID_REINTCAST */ 0,
3510 /* RID_STATCAST */ 0,
3513 /* RID_ID */ OBJECTNAME,
3514 /* RID_AT_ENCODE */ ENCODE,
3515 /* RID_AT_END */ END,
3516 /* RID_AT_CLASS */ CLASS,
3517 /* RID_AT_ALIAS */ ALIAS,
3518 /* RID_AT_DEFS */ DEFS,
3519 /* RID_AT_PRIVATE */ PRIVATE,
3520 /* RID_AT_PROTECTED */ PROTECTED,
3521 /* RID_AT_PUBLIC */ PUBLIC,
3522 /* RID_AT_PROTOCOL */ PROTOCOL,
3523 /* RID_AT_SELECTOR */ SELECTOR,
3524 /* RID_AT_INTERFACE */ INTERFACE,
3525 /* RID_AT_IMPLEMENTATION */ IMPLEMENTATION
3529 init_reswords (void)
3533 int mask = (flag_isoc99 ? 0 : D_C89)
3534 | (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0);
3536 if (!c_dialect_objc ())
3539 ridpointers = (tree *) ggc_calloc ((int) RID_MAX, sizeof (tree));
3540 for (i = 0; i < N_reswords; i++)
3542 /* If a keyword is disabled, do not enter it into the table
3543 and so create a canonical spelling that isn't a keyword. */
3544 if (reswords[i].disable & mask)
3547 id = get_identifier (reswords[i].word);
3548 C_RID_CODE (id) = reswords[i].rid;
3549 C_IS_RESERVED_WORD (id) = 1;
3550 ridpointers [(int) reswords[i].rid] = id;
3554 #define NAME(type) cpp_type2name (type)
3557 yyerror (const char *msgid)
3559 const char *string = _(msgid);
3561 if (last_token == CPP_EOF)
3562 error ("%s at end of input", string);
3563 else if (last_token == CPP_CHAR || last_token == CPP_WCHAR)
3565 unsigned int val = TREE_INT_CST_LOW (yylval.ttype);
3566 const char *const ell = (last_token == CPP_CHAR) ? "" : "L";
3567 if (val <= UCHAR_MAX && ISGRAPH (val))
3568 error ("%s before %s'%c'", string, ell, val);
3570 error ("%s before %s'\\x%x'", string, ell, val);
3572 else if (last_token == CPP_STRING
3573 || last_token == CPP_WSTRING)
3574 error ("%s before string constant", string);
3575 else if (last_token == CPP_NUMBER)
3576 error ("%s before numeric constant", string);
3577 else if (last_token == CPP_NAME)
3578 error ("%s before \"%s\"", string, IDENTIFIER_POINTER (yylval.ttype));
3580 error ("%s before '%s' token", string, NAME(last_token));
3589 int objc_force_identifier = objc_need_raw_identifier;
3590 OBJC_NEED_RAW_IDENTIFIER (0);
3593 if (C_IS_RESERVED_WORD (yylval.ttype))
3595 enum rid rid_code = C_RID_CODE (yylval.ttype);
3598 /* Turn non-typedefed refs to "id" into plain identifiers; this
3599 allows constructs like "void foo(id id);" to work. */
3600 if (rid_code == RID_ID)
3602 decl = lookup_name (yylval.ttype);
3603 if (decl == NULL_TREE || TREE_CODE (decl) != TYPE_DECL)
3607 if (!OBJC_IS_AT_KEYWORD (rid_code)
3608 && (!OBJC_IS_PQ_KEYWORD (rid_code) || objc_pq_context))
3611 /* Return the canonical spelling for this keyword. */
3612 yylval.ttype = ridpointers[(int) rid_code];
3613 return rid_to_yy[(int) rid_code];
3617 decl = lookup_name (yylval.ttype);
3620 if (TREE_CODE (decl) == TYPE_DECL)
3626 tree objc_interface_decl = is_class_name (yylval.ttype);
3627 /* ObjC class names are in the same namespace as variables and
3628 typedefs, and hence are shadowed by local declarations. */
3629 if (objc_interface_decl
3630 && (global_bindings_p ()
3631 || (!objc_force_identifier && !decl)))
3633 yylval.ttype = objc_interface_decl;
3646 last_token = c_lex (&yylval.ttype);
3649 case CPP_EQ: return '=';
3650 case CPP_NOT: return '!';
3651 case CPP_GREATER: yylval.code = GT_EXPR; return ARITHCOMPARE;
3652 case CPP_LESS: yylval.code = LT_EXPR; return ARITHCOMPARE;
3653 case CPP_PLUS: yylval.code = PLUS_EXPR; return '+';
3654 case CPP_MINUS: yylval.code = MINUS_EXPR; return '-';
3655 case CPP_MULT: yylval.code = MULT_EXPR; return '*';
3656 case CPP_DIV: yylval.code = TRUNC_DIV_EXPR; return '/';
3657 case CPP_MOD: yylval.code = TRUNC_MOD_EXPR; return '%';
3658 case CPP_AND: yylval.code = BIT_AND_EXPR; return '&';
3659 case CPP_OR: yylval.code = BIT_IOR_EXPR; return '|';
3660 case CPP_XOR: yylval.code = BIT_XOR_EXPR; return '^';
3661 case CPP_RSHIFT: yylval.code = RSHIFT_EXPR; return RSHIFT;
3662 case CPP_LSHIFT: yylval.code = LSHIFT_EXPR; return LSHIFT;
3664 case CPP_COMPL: return '~';
3665 case CPP_AND_AND: return ANDAND;
3666 case CPP_OR_OR: return OROR;
3667 case CPP_QUERY: return '?';
3668 case CPP_OPEN_PAREN: return '(';
3669 case CPP_EQ_EQ: yylval.code = EQ_EXPR; return EQCOMPARE;
3670 case CPP_NOT_EQ: yylval.code = NE_EXPR; return EQCOMPARE;
3671 case CPP_GREATER_EQ:yylval.code = GE_EXPR; return ARITHCOMPARE;
3672 case CPP_LESS_EQ: yylval.code = LE_EXPR; return ARITHCOMPARE;
3674 case CPP_PLUS_EQ: yylval.code = PLUS_EXPR; return ASSIGN;
3675 case CPP_MINUS_EQ: yylval.code = MINUS_EXPR; return ASSIGN;
3676 case CPP_MULT_EQ: yylval.code = MULT_EXPR; return ASSIGN;
3677 case CPP_DIV_EQ: yylval.code = TRUNC_DIV_EXPR; return ASSIGN;
3678 case CPP_MOD_EQ: yylval.code = TRUNC_MOD_EXPR; return ASSIGN;
3679 case CPP_AND_EQ: yylval.code = BIT_AND_EXPR; return ASSIGN;
3680 case CPP_OR_EQ: yylval.code = BIT_IOR_EXPR; return ASSIGN;
3681 case CPP_XOR_EQ: yylval.code = BIT_XOR_EXPR; return ASSIGN;
3682 case CPP_RSHIFT_EQ: yylval.code = RSHIFT_EXPR; return ASSIGN;
3683 case CPP_LSHIFT_EQ: yylval.code = LSHIFT_EXPR; return ASSIGN;
3685 case CPP_OPEN_SQUARE: return '[';
3686 case CPP_CLOSE_SQUARE: return ']';
3687 case CPP_OPEN_BRACE: return '{';
3688 case CPP_CLOSE_BRACE: return '}';
3689 case CPP_ELLIPSIS: return ELLIPSIS;
3691 case CPP_PLUS_PLUS: return PLUSPLUS;
3692 case CPP_MINUS_MINUS: return MINUSMINUS;
3693 case CPP_DEREF: return POINTSAT;
3694 case CPP_DOT: return '.';
3696 /* The following tokens may affect the interpretation of any
3697 identifiers following, if doing Objective-C. */
3698 case CPP_COLON: OBJC_NEED_RAW_IDENTIFIER (0); return ':';
3699 case CPP_COMMA: OBJC_NEED_RAW_IDENTIFIER (0); return ',';
3700 case CPP_CLOSE_PAREN: OBJC_NEED_RAW_IDENTIFIER (0); return ')';
3701 case CPP_SEMICOLON: OBJC_NEED_RAW_IDENTIFIER (0); return ';';
3707 return yylexname ();
3710 /* This only happens in Objective-C; it must be a keyword. */
3711 return rid_to_yy [(int) C_RID_CODE (yylval.ttype)];
3722 case CPP_OBJC_STRING:
3725 /* These tokens are C++ specific (and will not be generated
3726 in C mode, but let's be cautious). */
3728 case CPP_DEREF_STAR:
3734 /* These tokens should not survive translation phase 4. */
3737 error ("syntax error at '%s' token", NAME(last_token));
3750 timevar_push (TV_LEX);
3752 timevar_pop (TV_LEX);
3756 /* Function used when yydebug is set, to print a token in more detail. */
3759 yyprint (FILE *file, int yychar, YYSTYPE yyl)
3763 fprintf (file, " [%s]", NAME(last_token));
3774 if (IDENTIFIER_POINTER (t))
3775 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
3779 fprintf (file, " %s", GET_MODE_NAME (TYPE_MODE (TREE_TYPE (t))));
3780 if (TREE_CODE (t) == INTEGER_CST)
3783 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
3784 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
3790 /* This is not the ideal place to put these, but we have to get them out
3791 of c-lex.c because cp/lex.c has its own versions. */
3793 /* Free malloced parser stacks if necessary. */
3796 free_parser_stacks (void)
3800 free (malloced_yyss);
3801 free (malloced_yyvs);
3805 #include "gt-c-parse.h"