1 /* YACC parser for C syntax and for Objective C. -*-c-*-
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004 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"
41 #include "langhooks.h"
46 #include "c-pragma.h" /* For YYDEBUG definition, and parse_in. */
58 /* Like YYERROR but do call yyerror. */
59 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
61 /* Like the default stack expander, except (1) use realloc when possible,
62 (2) impose no hard maxiumum on stack size, (3) REALLY do not use alloca.
64 Irritatingly, YYSTYPE is defined after this %{ %} block, so we cannot
65 give malloced_yyvs its proper type. This is ok since all we need from
66 it is to be able to free it. */
68 static short *malloced_yyss;
69 static void *malloced_yyvs;
71 #define yyoverflow(MSG, SS, SSSIZE, VS, VSSIZE, YYSSZ) \
76 newsize = *(YYSSZ) *= 2; \
79 newss = really_call_realloc (*(SS), newsize * sizeof (short)); \
80 newvs = really_call_realloc (*(VS), newsize * sizeof (YYSTYPE)); \
84 newss = really_call_malloc (newsize * sizeof (short)); \
85 newvs = really_call_malloc (newsize * sizeof (YYSTYPE)); \
87 memcpy (newss, *(SS), (SSSIZE)); \
89 memcpy (newvs, *(VS), (VSSIZE)); \
91 if (!newss || !newvs) \
98 malloced_yyss = newss; \
99 malloced_yyvs = (void *) newvs; \
105 %union {long itype; tree ttype; enum tree_code code;
106 location_t location; }
108 /* All identifiers that are not reserved words
109 and are not declared typedefs in the current block */
112 /* All identifiers that are declared typedefs in the current block.
113 In some contexts, they are treated just like IDENTIFIER,
114 but they can also serve as typespecs in declarations. */
117 /* Reserved words that specify storage class.
118 yylval contains an IDENTIFIER_NODE which indicates which one. */
119 %token SCSPEC /* Storage class other than static. */
120 %token STATIC /* Static storage class. */
122 /* Reserved words that specify type.
123 yylval contains an IDENTIFIER_NODE which indicates which one. */
126 /* Reserved words that qualify type: "const", "volatile", or "restrict".
127 yylval contains an IDENTIFIER_NODE which indicates which one. */
130 /* Character or numeric constants.
131 yylval is the node for the constant. */
134 /* String constants in raw form.
135 yylval is a STRING_CST node. */
139 /* "...", used for functions with variable arglists. */
142 /* the reserved words */
143 /* SCO include files test "ASM", so use something else. */
144 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
145 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
146 %token ATTRIBUTE EXTENSION LABEL
147 %token REALPART IMAGPART VA_ARG CHOOSE_EXPR TYPES_COMPATIBLE_P
148 %token PTR_VALUE PTR_BASE PTR_EXTENT
149 %token FUNC_NAME OFFSETOF
151 /* Add precedence rules to solve dangling else s/r conflict */
155 /* Define the operator tokens and their precedences.
156 The value is an integer because, if used, it is the tree code
157 to use in the expression made from the operator. */
159 %right <code> ASSIGN '='
160 %right <code> '?' ':'
166 %left <code> EQCOMPARE
167 %left <code> ARITHCOMPARE
168 %left <code> LSHIFT RSHIFT
170 %left <code> '*' '/' '%'
171 %right <code> UNARY PLUSPLUS MINUSMINUS
173 %left <code> POINTSAT '.' '(' '['
175 /* The Objective-C keywords. These are included in C and in
176 Objective C, so that the token codes are the same in both. */
177 %token AT_INTERFACE AT_IMPLEMENTATION AT_END AT_SELECTOR AT_DEFS AT_ENCODE
178 %token CLASSNAME AT_PUBLIC AT_PRIVATE AT_PROTECTED AT_PROTOCOL
179 %token OBJECTNAME AT_CLASS AT_ALIAS
180 %token AT_THROW AT_TRY AT_CATCH AT_FINALLY AT_SYNCHRONIZED
184 %type <ttype> ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
185 %type <ttype> BREAK CONTINUE RETURN GOTO ASM_KEYWORD SIZEOF TYPEOF ALIGNOF
187 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
188 %type <ttype> expr_no_commas cast_expr unary_expr primary STRING
189 %type <ttype> declspecs_nosc_nots_nosa_noea declspecs_nosc_nots_nosa_ea
190 %type <ttype> declspecs_nosc_nots_sa_noea declspecs_nosc_nots_sa_ea
191 %type <ttype> declspecs_nosc_ts_nosa_noea declspecs_nosc_ts_nosa_ea
192 %type <ttype> declspecs_nosc_ts_sa_noea declspecs_nosc_ts_sa_ea
193 %type <ttype> declspecs_sc_nots_nosa_noea declspecs_sc_nots_nosa_ea
194 %type <ttype> declspecs_sc_nots_sa_noea declspecs_sc_nots_sa_ea
195 %type <ttype> declspecs_sc_ts_nosa_noea declspecs_sc_ts_nosa_ea
196 %type <ttype> declspecs_sc_ts_sa_noea declspecs_sc_ts_sa_ea
197 %type <ttype> declspecs_ts declspecs_nots
198 %type <ttype> declspecs_ts_nosa declspecs_nots_nosa
199 %type <ttype> declspecs_nosc_ts declspecs_nosc_nots declspecs_nosc declspecs
200 %type <ttype> maybe_type_quals_attrs typespec_nonattr typespec_attr
201 %type <ttype> typespec_reserved_nonattr typespec_reserved_attr
202 %type <ttype> typespec_nonreserved_nonattr
203 %type <ttype> offsetof_member_designator
205 %type <ttype> scspec SCSPEC STATIC TYPESPEC TYPE_QUAL maybe_volatile
206 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl init
207 %type <ttype> simple_asm_expr maybeasm asm_stmt asm_argument
208 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
209 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
210 %type <ttype> any_word
212 %type <ttype> compstmt compstmt_start compstmt_primary_start
213 %type <ttype> do_stmt_start stmt label
215 %type <ttype> c99_block_start c99_block_lineno_labeled_stmt
216 %type <ttype> declarator
217 %type <ttype> notype_declarator after_type_declarator
218 %type <ttype> parm_declarator
219 %type <ttype> parm_declarator_starttypename parm_declarator_nostarttypename
220 %type <ttype> array_declarator
222 %type <ttype> structsp_attr structsp_nonattr
223 %type <ttype> component_decl_list component_decl_list2
224 %type <ttype> component_decl components components_notype component_declarator
225 %type <ttype> component_notype_declarator
226 %type <ttype> enumlist enumerator
227 %type <ttype> struct_head union_head enum_head
228 %type <ttype> typename absdcl absdcl1 absdcl1_ea absdcl1_noea
229 %type <ttype> direct_absdcl1 absdcl_maybe_attribute
230 %type <ttype> xexpr parms parm firstparm identifiers
232 %type <ttype> parmlist parmlist_1 parmlist_2
233 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
234 %type <ttype> identifiers_or_typenames
236 %type <itype> setspecs setspecs_fp extension
238 %type <location> save_location
241 /* the Objective-C nonterminals */
243 %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
244 %type <ttype> methoddecl unaryselector keywordselector selector
245 %type <ttype> keyworddecl receiver objcmessageexpr messageargs
246 %type <ttype> keywordexpr keywordarglist keywordarg
247 %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
248 %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
249 %type <ttype> non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
251 %type <ttype> CLASSNAME OBJECTNAME OBJC_STRING
253 %type <ttype> superclass
257 /* Number of statements (loosely speaking) and compound statements
259 static int stmt_count;
260 static int compstmt_count;
262 /* List of types and structure classes of the current declaration. */
263 static GTY(()) tree current_declspecs;
264 static GTY(()) tree prefix_attributes;
266 /* List of all the attributes applying to the identifier currently being
267 declared; includes prefix_attributes and possibly some more attributes
268 just after a comma. */
269 static GTY(()) tree all_prefix_attributes;
271 /* Stack of saved values of current_declspecs, prefix_attributes and
272 all_prefix_attributes. */
273 static GTY(()) tree declspec_stack;
275 /* PUSH_DECLSPEC_STACK is called from setspecs; POP_DECLSPEC_STACK
276 should be called from the productions making use of setspecs. */
277 #define PUSH_DECLSPEC_STACK \
279 declspec_stack = tree_cons (build_tree_list (prefix_attributes, \
280 all_prefix_attributes), \
285 #define POP_DECLSPEC_STACK \
287 current_declspecs = TREE_VALUE (declspec_stack); \
288 prefix_attributes = TREE_PURPOSE (TREE_PURPOSE (declspec_stack)); \
289 all_prefix_attributes = TREE_VALUE (TREE_PURPOSE (declspec_stack)); \
290 declspec_stack = TREE_CHAIN (declspec_stack); \
293 /* For __extension__, save/restore the warning flags which are
294 controlled by __extension__. */
295 #define SAVE_EXT_FLAGS() \
297 | (warn_pointer_arith << 1) \
298 | (warn_traditional << 2) \
301 #define RESTORE_EXT_FLAGS(val) \
303 pedantic = val & 1; \
304 warn_pointer_arith = (val >> 1) & 1; \
305 warn_traditional = (val >> 2) & 1; \
306 flag_iso = (val >> 3) & 1; \
310 /* Objective-C specific parser/lexer information */
312 static enum tree_code objc_inherit_code;
313 static int objc_pq_context = 0, objc_public_flag = 0;
315 /* The following flag is needed to contextualize ObjC lexical analysis.
316 In some cases (e.g., 'int NSObject;'), it is undesirable to bind
317 an identifier to an ObjC class, even if a class with that name
319 static int objc_need_raw_identifier;
320 #define OBJC_NEED_RAW_IDENTIFIER(VAL) objc_need_raw_identifier = VAL
324 #define OBJC_NEED_RAW_IDENTIFIER(VAL) /* nothing */
327 /* Tell yyparse how to print a token's value, if yydebug is set. */
329 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
331 static void yyprint (FILE *, int, YYSTYPE);
332 static void yyerror (const char *);
333 static int yylexname (void);
334 static inline int _yylex (void);
335 static int yylex (void);
336 static void init_reswords (void);
338 /* Initialisation routine for this file. */
350 pedwarn ("ISO C forbids an empty source file");
355 /* the reason for the strange actions in this rule
356 is so that notype_initdecls when reached via datadef
357 can find a valid list of type and sc specs in $0. */
360 {$<ttype>$ = NULL_TREE; } extdef
361 | extdefs {$<ttype>$ = NULL_TREE; ggc_collect(); } extdef
369 { RESTORE_EXT_FLAGS ($1); }
376 setspecs notype_initdecls ';'
378 error ("ISO C forbids data definition with no type or storage class");
380 warning ("data definition has no type or storage class");
382 POP_DECLSPEC_STACK; }
383 | declspecs_nots setspecs notype_initdecls ';'
384 { POP_DECLSPEC_STACK; }
385 | declspecs_ts setspecs initdecls ';'
386 { POP_DECLSPEC_STACK; }
393 pedwarn ("ISO C does not allow extra `;' outside of a function"); }
397 declspecs_ts setspecs declarator
398 { if (! start_function (current_declspecs, $3,
399 all_prefix_attributes))
402 old_style_parm_decls save_location
403 { DECL_SOURCE_LOCATION (current_function_decl) = $6;
404 store_parm_decls (); }
406 { finish_function ();
407 POP_DECLSPEC_STACK; }
408 | declspecs_ts setspecs declarator error
409 { POP_DECLSPEC_STACK; }
410 | declspecs_nots setspecs notype_declarator
411 { if (! start_function (current_declspecs, $3,
412 all_prefix_attributes))
415 old_style_parm_decls save_location
416 { DECL_SOURCE_LOCATION (current_function_decl) = $6;
417 store_parm_decls (); }
419 { finish_function ();
420 POP_DECLSPEC_STACK; }
421 | declspecs_nots setspecs notype_declarator error
422 { POP_DECLSPEC_STACK; }
423 | setspecs notype_declarator
424 { if (! start_function (NULL_TREE, $2,
425 all_prefix_attributes))
428 old_style_parm_decls save_location
429 { DECL_SOURCE_LOCATION (current_function_decl) = $5;
430 store_parm_decls (); }
432 { finish_function ();
433 POP_DECLSPEC_STACK; }
434 | setspecs notype_declarator error
435 { POP_DECLSPEC_STACK; }
450 { $$ = NEGATE_EXPR; }
454 if (warn_traditional && !in_system_header)
455 warning ("traditional C rejects the unary plus operator");
459 { $$ = PREINCREMENT_EXPR; }
461 { $$ = PREDECREMENT_EXPR; }
463 { $$ = BIT_NOT_EXPR; }
465 { $$ = TRUTH_NOT_EXPR; }
468 expr: nonnull_exprlist
469 { $$ = build_compound_expr ($1); }
480 { $$ = build_tree_list (NULL_TREE, $1); }
481 | nonnull_exprlist ',' expr_no_commas
482 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
487 | '*' cast_expr %prec UNARY
488 { $$ = build_indirect_ref ($2, "unary *"); }
489 /* __extension__ turns off -pedantic for following primary. */
490 | extension cast_expr %prec UNARY
492 RESTORE_EXT_FLAGS ($1); }
493 | unop cast_expr %prec UNARY
494 { $$ = build_unary_op ($1, $2, 0);
495 overflow_warning ($$); }
496 /* Refer to the address of a label as a pointer. */
498 { $$ = finish_label_address_expr ($2); }
499 | sizeof unary_expr %prec UNARY
501 if (TREE_CODE ($2) == COMPONENT_REF
502 && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
503 error ("`sizeof' applied to a bit-field");
504 $$ = c_sizeof (TREE_TYPE ($2)); }
505 | sizeof '(' typename ')' %prec HYPERUNARY
507 $$ = c_sizeof (groktypename ($3)); }
508 | alignof unary_expr %prec UNARY
510 $$ = c_alignof_expr ($2); }
511 | alignof '(' typename ')' %prec HYPERUNARY
513 $$ = c_alignof (groktypename ($3)); }
514 | REALPART cast_expr %prec UNARY
515 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
516 | IMAGPART cast_expr %prec UNARY
517 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
521 SIZEOF { skip_evaluation++; }
525 ALIGNOF { skip_evaluation++; }
529 TYPEOF { skip_evaluation++; }
534 | '(' typename ')' cast_expr %prec UNARY
535 { $$ = c_cast_expr ($2, $4); }
540 | expr_no_commas '+' expr_no_commas
541 { $$ = parser_build_binary_op ($2, $1, $3); }
542 | expr_no_commas '-' expr_no_commas
543 { $$ = parser_build_binary_op ($2, $1, $3); }
544 | expr_no_commas '*' expr_no_commas
545 { $$ = parser_build_binary_op ($2, $1, $3); }
546 | expr_no_commas '/' expr_no_commas
547 { $$ = parser_build_binary_op ($2, $1, $3); }
548 | expr_no_commas '%' expr_no_commas
549 { $$ = parser_build_binary_op ($2, $1, $3); }
550 | expr_no_commas LSHIFT expr_no_commas
551 { $$ = parser_build_binary_op ($2, $1, $3); }
552 | expr_no_commas RSHIFT expr_no_commas
553 { $$ = parser_build_binary_op ($2, $1, $3); }
554 | expr_no_commas ARITHCOMPARE expr_no_commas
555 { $$ = parser_build_binary_op ($2, $1, $3); }
556 | expr_no_commas EQCOMPARE expr_no_commas
557 { $$ = parser_build_binary_op ($2, $1, $3); }
558 | expr_no_commas '&' expr_no_commas
559 { $$ = parser_build_binary_op ($2, $1, $3); }
560 | expr_no_commas '|' expr_no_commas
561 { $$ = parser_build_binary_op ($2, $1, $3); }
562 | expr_no_commas '^' expr_no_commas
563 { $$ = parser_build_binary_op ($2, $1, $3); }
564 | expr_no_commas ANDAND
565 { $1 = lang_hooks.truthvalue_conversion
566 (default_conversion ($1));
567 skip_evaluation += $1 == truthvalue_false_node; }
569 { skip_evaluation -= $1 == truthvalue_false_node;
570 $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
571 | expr_no_commas OROR
572 { $1 = lang_hooks.truthvalue_conversion
573 (default_conversion ($1));
574 skip_evaluation += $1 == truthvalue_true_node; }
576 { skip_evaluation -= $1 == truthvalue_true_node;
577 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
579 { $1 = lang_hooks.truthvalue_conversion
580 (default_conversion ($1));
581 skip_evaluation += $1 == truthvalue_false_node; }
583 { skip_evaluation += (($1 == truthvalue_true_node)
584 - ($1 == truthvalue_false_node)); }
586 { skip_evaluation -= $1 == truthvalue_true_node;
587 $$ = build_conditional_expr ($1, $4, $7); }
590 pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
591 /* Make sure first operand is calculated only once. */
592 $<ttype>2 = save_expr (default_conversion ($1));
593 $1 = lang_hooks.truthvalue_conversion ($<ttype>2);
594 skip_evaluation += $1 == truthvalue_true_node; }
596 { skip_evaluation -= $1 == truthvalue_true_node;
597 $$ = build_conditional_expr ($1, $<ttype>2, $5); }
598 | expr_no_commas '=' expr_no_commas
600 $$ = build_modify_expr ($1, NOP_EXPR, $3);
601 class = TREE_CODE_CLASS (TREE_CODE ($$));
602 if (IS_EXPR_CODE_CLASS (class))
603 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR);
605 | expr_no_commas ASSIGN expr_no_commas
607 $$ = build_modify_expr ($1, $2, $3);
608 /* This inhibits warnings in
609 c_common_truthvalue_conversion. */
610 class = TREE_CODE_CLASS (TREE_CODE ($$));
611 if (IS_EXPR_CODE_CLASS (class))
612 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK);
619 if (yychar == YYEMPTY)
621 $$ = build_external_ref ($1, yychar == '(');
626 { $$ = fname_decl (C_RID_CODE ($$), $$); }
627 | '(' typename ')' '{'
628 { start_init (NULL_TREE, NULL, 0);
629 $2 = groktypename ($2);
630 really_start_incremental_init ($2); }
631 initlist_maybe_comma '}' %prec UNARY
632 { tree constructor = pop_init_level (0);
636 if (pedantic && ! flag_isoc99)
637 pedwarn ("ISO C90 forbids compound literals");
638 $$ = build_compound_literal (type, constructor);
641 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
642 if (IS_EXPR_CODE_CLASS (class))
643 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
646 { $$ = error_mark_node; }
647 | compstmt_primary_start compstmt_nostart ')'
649 pedwarn ("ISO C forbids braced-groups within expressions");
650 $$ = c_finish_stmt_expr ($1);
652 | compstmt_primary_start error ')'
653 { c_finish_stmt_expr ($1);
654 $$ = error_mark_node;
656 | primary '(' exprlist ')' %prec '.'
657 { $$ = build_function_call ($1, $3); }
658 | VA_ARG '(' expr_no_commas ',' typename ')'
659 { $$ = build_va_arg ($3, groktypename ($5)); }
661 | OFFSETOF '(' typename ',' offsetof_member_designator ')'
662 { $$ = build_offsetof (groktypename ($3), $5); }
663 | OFFSETOF '(' error ')'
664 { $$ = error_mark_node; }
665 | CHOOSE_EXPR '(' expr_no_commas ',' expr_no_commas ','
672 if (TREE_CODE (c) != INTEGER_CST)
673 error ("first argument to __builtin_choose_expr not"
675 $$ = integer_zerop (c) ? $7 : $5;
677 | CHOOSE_EXPR '(' error ')'
678 { $$ = error_mark_node; }
679 | TYPES_COMPATIBLE_P '(' typename ',' typename ')'
683 e1 = TYPE_MAIN_VARIANT (groktypename ($3));
684 e2 = TYPE_MAIN_VARIANT (groktypename ($5));
686 $$ = comptypes (e1, e2)
687 ? build_int_2 (1, 0) : build_int_2 (0, 0);
689 | TYPES_COMPATIBLE_P '(' error ')'
690 { $$ = error_mark_node; }
691 | primary '[' expr ']' %prec '.'
692 { $$ = build_array_ref ($1, $3); }
693 | primary '.' identifier
694 { $$ = build_component_ref ($1, $3); }
695 | primary POINTSAT identifier
697 tree expr = build_indirect_ref ($1, "->");
698 $$ = build_component_ref (expr, $3);
701 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
703 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
706 { $$ = build_message_expr ($1); }
708 { $$ = build_selector_expr ($1); }
710 { $$ = build_protocol_expr ($1); }
712 { $$ = build_encode_expr ($1); }
714 { $$ = build_objc_string_object ($1); }
718 /* This is the second argument to __builtin_offsetof. We must have one
719 identifier, and beyond that we want to accept sub structure and sub
720 array references. We return tree list where each element has
721 PURPOSE set for component refs or VALUE set for array refs. We'll
722 turn this into something real inside build_offsetof. */
724 offsetof_member_designator:
726 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
727 | offsetof_member_designator '.' identifier
728 { $$ = tree_cons ($3, NULL_TREE, $1); }
729 | offsetof_member_designator '[' expr ']'
730 { $$ = tree_cons (NULL_TREE, $3, $1); }
733 old_style_parm_decls:
738 /* The following are analogous to lineno_decl, decls and decl
739 except that they do not allow nested functions.
740 They are used for old-style parm decls. */
742 save_location datadecl
749 | datadecls lineno_datadecl
750 | lineno_datadecl errstmt
753 /* We don't allow prefix attributes here because they cause reduce/reduce
754 conflicts: we can't know whether we're parsing a function decl with
755 attribute suffix, or function defn with attribute prefix on first old
758 declspecs_ts_nosa setspecs initdecls ';'
759 { POP_DECLSPEC_STACK; }
760 | declspecs_nots_nosa setspecs notype_initdecls ';'
761 { POP_DECLSPEC_STACK; }
762 | declspecs_ts_nosa ';'
763 { shadow_tag_warned ($1, 1);
764 pedwarn ("empty declaration"); }
765 | declspecs_nots_nosa ';'
766 { pedwarn ("empty declaration"); }
769 /* This combination which saves a lineno before a decl
770 is the normal thing to use, rather than decl itself.
771 This is to avoid shift/reduce conflicts in contexts
772 where statement labels are allowed. */
778 /* records the type and storage class specs to use for processing
779 the declarators that follow.
780 Maintains a stack of outer-level values of current_declspecs,
781 for the sake of parm declarations nested in function declarators. */
782 setspecs: /* empty */
783 { pending_xref_error ();
785 split_specs_attrs ($<ttype>0,
786 ¤t_declspecs, &prefix_attributes);
787 all_prefix_attributes = prefix_attributes; }
790 /* Possibly attributes after a comma, which should reset all_prefix_attributes
791 to prefix_attributes with these ones chained on the front. */
794 { all_prefix_attributes = chainon ($1, prefix_attributes); }
798 declspecs_ts setspecs initdecls ';'
799 { POP_DECLSPEC_STACK; }
800 | declspecs_nots setspecs notype_initdecls ';'
801 { POP_DECLSPEC_STACK; }
802 | declspecs_ts setspecs nested_function
803 { POP_DECLSPEC_STACK; }
804 | declspecs_nots setspecs notype_nested_function
805 { POP_DECLSPEC_STACK; }
809 { RESTORE_EXT_FLAGS ($1); }
812 /* A list of declaration specifiers. These are:
814 - Storage class specifiers (scspec), which for GCC currently includes
815 function specifiers ("inline").
817 - Type specifiers (typespec_*).
819 - Type qualifiers (TYPE_QUAL).
821 - Attribute specifier lists (attributes).
823 These are stored as a TREE_LIST; the head of the list is the last
824 item in the specifier list. Each entry in the list has either a
825 TREE_PURPOSE that is an attribute specifier list, or a TREE_VALUE that
826 is a single other specifier or qualifier; and a TREE_CHAIN that is the
827 rest of the list. TREE_STATIC is set on the list if something other
828 than a storage class specifier or attribute has been seen; this is used
829 to warn for the obsolescent usage of storage class specifiers other than
830 at the start of the list. (Doing this properly would require function
831 specifiers to be handled separately from storage class specifiers.)
833 The various cases below are classified according to:
835 (a) Whether a storage class specifier is included or not; some
836 places in the grammar disallow storage class specifiers (_sc or _nosc).
838 (b) Whether a type specifier has been seen; after a type specifier,
839 a typedef name is an identifier to redeclare (_ts or _nots).
841 (c) Whether the list starts with an attribute; in certain places,
842 the grammar requires specifiers that don't start with an attribute
845 (d) Whether the list ends with an attribute (or a specifier such that
846 any following attribute would have been parsed as part of that specifier);
847 this avoids shift-reduce conflicts in the parsing of attributes
852 (i) Distinguish between function specifiers and storage class specifiers,
853 at least for the purpose of warnings about obsolescent usage.
855 (ii) Halve the number of productions here by eliminating the _sc/_nosc
856 distinction and instead checking where required that storage class
857 specifiers aren't present. */
859 /* Declspecs which contain at least one type specifier or typedef name.
860 (Just `const' or `volatile' is not enough.)
861 A typedef'd name following these is taken as a name to be declared.
862 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
864 declspecs_nosc_nots_nosa_noea:
866 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
867 TREE_STATIC ($$) = 1; }
868 | declspecs_nosc_nots_nosa_noea TYPE_QUAL
869 { $$ = tree_cons (NULL_TREE, $2, $1);
870 TREE_STATIC ($$) = 1; }
871 | declspecs_nosc_nots_nosa_ea TYPE_QUAL
872 { $$ = tree_cons (NULL_TREE, $2, $1);
873 TREE_STATIC ($$) = 1; }
876 declspecs_nosc_nots_nosa_ea:
877 declspecs_nosc_nots_nosa_noea attributes
878 { $$ = tree_cons ($2, NULL_TREE, $1);
879 TREE_STATIC ($$) = TREE_STATIC ($1); }
882 declspecs_nosc_nots_sa_noea:
883 declspecs_nosc_nots_sa_noea TYPE_QUAL
884 { $$ = tree_cons (NULL_TREE, $2, $1);
885 TREE_STATIC ($$) = 1; }
886 | declspecs_nosc_nots_sa_ea TYPE_QUAL
887 { $$ = tree_cons (NULL_TREE, $2, $1);
888 TREE_STATIC ($$) = 1; }
891 declspecs_nosc_nots_sa_ea:
893 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE);
894 TREE_STATIC ($$) = 0; }
895 | declspecs_nosc_nots_sa_noea attributes
896 { $$ = tree_cons ($2, NULL_TREE, $1);
897 TREE_STATIC ($$) = TREE_STATIC ($1); }
900 declspecs_nosc_ts_nosa_noea:
902 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
903 TREE_STATIC ($$) = 1; }
904 | declspecs_nosc_ts_nosa_noea TYPE_QUAL
905 { $$ = tree_cons (NULL_TREE, $2, $1);
906 TREE_STATIC ($$) = 1; }
907 | declspecs_nosc_ts_nosa_ea TYPE_QUAL
908 { $$ = tree_cons (NULL_TREE, $2, $1);
909 TREE_STATIC ($$) = 1; }
910 | declspecs_nosc_ts_nosa_noea typespec_reserved_nonattr
911 { $$ = tree_cons (NULL_TREE, $2, $1);
912 TREE_STATIC ($$) = 1; }
913 | declspecs_nosc_ts_nosa_ea typespec_reserved_nonattr
914 { $$ = tree_cons (NULL_TREE, $2, $1);
915 TREE_STATIC ($$) = 1; }
916 | declspecs_nosc_nots_nosa_noea typespec_nonattr
917 { $$ = tree_cons (NULL_TREE, $2, $1);
918 TREE_STATIC ($$) = 1; }
919 | declspecs_nosc_nots_nosa_ea typespec_nonattr
920 { $$ = tree_cons (NULL_TREE, $2, $1);
921 TREE_STATIC ($$) = 1; }
924 declspecs_nosc_ts_nosa_ea:
926 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
927 TREE_STATIC ($$) = 1; }
928 | declspecs_nosc_ts_nosa_noea attributes
929 { $$ = tree_cons ($2, NULL_TREE, $1);
930 TREE_STATIC ($$) = TREE_STATIC ($1); }
931 | declspecs_nosc_ts_nosa_noea typespec_reserved_attr
932 { $$ = tree_cons (NULL_TREE, $2, $1);
933 TREE_STATIC ($$) = 1; }
934 | declspecs_nosc_ts_nosa_ea typespec_reserved_attr
935 { $$ = tree_cons (NULL_TREE, $2, $1);
936 TREE_STATIC ($$) = 1; }
937 | declspecs_nosc_nots_nosa_noea typespec_attr
938 { $$ = tree_cons (NULL_TREE, $2, $1);
939 TREE_STATIC ($$) = 1; }
940 | declspecs_nosc_nots_nosa_ea typespec_attr
941 { $$ = tree_cons (NULL_TREE, $2, $1);
942 TREE_STATIC ($$) = 1; }
945 declspecs_nosc_ts_sa_noea:
946 declspecs_nosc_ts_sa_noea TYPE_QUAL
947 { $$ = tree_cons (NULL_TREE, $2, $1);
948 TREE_STATIC ($$) = 1; }
949 | declspecs_nosc_ts_sa_ea TYPE_QUAL
950 { $$ = tree_cons (NULL_TREE, $2, $1);
951 TREE_STATIC ($$) = 1; }
952 | declspecs_nosc_ts_sa_noea typespec_reserved_nonattr
953 { $$ = tree_cons (NULL_TREE, $2, $1);
954 TREE_STATIC ($$) = 1; }
955 | declspecs_nosc_ts_sa_ea typespec_reserved_nonattr
956 { $$ = tree_cons (NULL_TREE, $2, $1);
957 TREE_STATIC ($$) = 1; }
958 | declspecs_nosc_nots_sa_noea typespec_nonattr
959 { $$ = tree_cons (NULL_TREE, $2, $1);
960 TREE_STATIC ($$) = 1; }
961 | declspecs_nosc_nots_sa_ea typespec_nonattr
962 { $$ = tree_cons (NULL_TREE, $2, $1);
963 TREE_STATIC ($$) = 1; }
966 declspecs_nosc_ts_sa_ea:
967 declspecs_nosc_ts_sa_noea attributes
968 { $$ = tree_cons ($2, NULL_TREE, $1);
969 TREE_STATIC ($$) = TREE_STATIC ($1); }
970 | declspecs_nosc_ts_sa_noea typespec_reserved_attr
971 { $$ = tree_cons (NULL_TREE, $2, $1);
972 TREE_STATIC ($$) = 1; }
973 | declspecs_nosc_ts_sa_ea typespec_reserved_attr
974 { $$ = tree_cons (NULL_TREE, $2, $1);
975 TREE_STATIC ($$) = 1; }
976 | declspecs_nosc_nots_sa_noea typespec_attr
977 { $$ = tree_cons (NULL_TREE, $2, $1);
978 TREE_STATIC ($$) = 1; }
979 | declspecs_nosc_nots_sa_ea typespec_attr
980 { $$ = tree_cons (NULL_TREE, $2, $1);
981 TREE_STATIC ($$) = 1; }
984 declspecs_sc_nots_nosa_noea:
986 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
987 TREE_STATIC ($$) = 0; }
988 | declspecs_sc_nots_nosa_noea TYPE_QUAL
989 { $$ = tree_cons (NULL_TREE, $2, $1);
990 TREE_STATIC ($$) = 1; }
991 | declspecs_sc_nots_nosa_ea TYPE_QUAL
992 { $$ = tree_cons (NULL_TREE, $2, $1);
993 TREE_STATIC ($$) = 1; }
994 | declspecs_nosc_nots_nosa_noea scspec
995 { if (extra_warnings && TREE_STATIC ($1))
996 warning ("`%s' is not at beginning of declaration",
997 IDENTIFIER_POINTER ($2));
998 $$ = tree_cons (NULL_TREE, $2, $1);
999 TREE_STATIC ($$) = TREE_STATIC ($1); }
1000 | declspecs_nosc_nots_nosa_ea scspec
1001 { if (extra_warnings && TREE_STATIC ($1))
1002 warning ("`%s' is not at beginning of declaration",
1003 IDENTIFIER_POINTER ($2));
1004 $$ = tree_cons (NULL_TREE, $2, $1);
1005 TREE_STATIC ($$) = TREE_STATIC ($1); }
1006 | declspecs_sc_nots_nosa_noea scspec
1007 { if (extra_warnings && TREE_STATIC ($1))
1008 warning ("`%s' is not at beginning of declaration",
1009 IDENTIFIER_POINTER ($2));
1010 $$ = tree_cons (NULL_TREE, $2, $1);
1011 TREE_STATIC ($$) = TREE_STATIC ($1); }
1012 | declspecs_sc_nots_nosa_ea scspec
1013 { if (extra_warnings && TREE_STATIC ($1))
1014 warning ("`%s' is not at beginning of declaration",
1015 IDENTIFIER_POINTER ($2));
1016 $$ = tree_cons (NULL_TREE, $2, $1);
1017 TREE_STATIC ($$) = TREE_STATIC ($1); }
1020 declspecs_sc_nots_nosa_ea:
1021 declspecs_sc_nots_nosa_noea attributes
1022 { $$ = tree_cons ($2, NULL_TREE, $1);
1023 TREE_STATIC ($$) = TREE_STATIC ($1); }
1026 declspecs_sc_nots_sa_noea:
1027 declspecs_sc_nots_sa_noea TYPE_QUAL
1028 { $$ = tree_cons (NULL_TREE, $2, $1);
1029 TREE_STATIC ($$) = 1; }
1030 | declspecs_sc_nots_sa_ea TYPE_QUAL
1031 { $$ = tree_cons (NULL_TREE, $2, $1);
1032 TREE_STATIC ($$) = 1; }
1033 | declspecs_nosc_nots_sa_noea scspec
1034 { if (extra_warnings && TREE_STATIC ($1))
1035 warning ("`%s' is not at beginning of declaration",
1036 IDENTIFIER_POINTER ($2));
1037 $$ = tree_cons (NULL_TREE, $2, $1);
1038 TREE_STATIC ($$) = TREE_STATIC ($1); }
1039 | declspecs_nosc_nots_sa_ea scspec
1040 { if (extra_warnings && TREE_STATIC ($1))
1041 warning ("`%s' is not at beginning of declaration",
1042 IDENTIFIER_POINTER ($2));
1043 $$ = tree_cons (NULL_TREE, $2, $1);
1044 TREE_STATIC ($$) = TREE_STATIC ($1); }
1045 | declspecs_sc_nots_sa_noea scspec
1046 { if (extra_warnings && TREE_STATIC ($1))
1047 warning ("`%s' is not at beginning of declaration",
1048 IDENTIFIER_POINTER ($2));
1049 $$ = tree_cons (NULL_TREE, $2, $1);
1050 TREE_STATIC ($$) = TREE_STATIC ($1); }
1051 | declspecs_sc_nots_sa_ea scspec
1052 { if (extra_warnings && TREE_STATIC ($1))
1053 warning ("`%s' is not at beginning of declaration",
1054 IDENTIFIER_POINTER ($2));
1055 $$ = tree_cons (NULL_TREE, $2, $1);
1056 TREE_STATIC ($$) = TREE_STATIC ($1); }
1059 declspecs_sc_nots_sa_ea:
1060 declspecs_sc_nots_sa_noea attributes
1061 { $$ = tree_cons ($2, NULL_TREE, $1);
1062 TREE_STATIC ($$) = TREE_STATIC ($1); }
1065 declspecs_sc_ts_nosa_noea:
1066 declspecs_sc_ts_nosa_noea TYPE_QUAL
1067 { $$ = tree_cons (NULL_TREE, $2, $1);
1068 TREE_STATIC ($$) = 1; }
1069 | declspecs_sc_ts_nosa_ea TYPE_QUAL
1070 { $$ = tree_cons (NULL_TREE, $2, $1);
1071 TREE_STATIC ($$) = 1; }
1072 | declspecs_sc_ts_nosa_noea typespec_reserved_nonattr
1073 { $$ = tree_cons (NULL_TREE, $2, $1);
1074 TREE_STATIC ($$) = 1; }
1075 | declspecs_sc_ts_nosa_ea typespec_reserved_nonattr
1076 { $$ = tree_cons (NULL_TREE, $2, $1);
1077 TREE_STATIC ($$) = 1; }
1078 | declspecs_sc_nots_nosa_noea typespec_nonattr
1079 { $$ = tree_cons (NULL_TREE, $2, $1);
1080 TREE_STATIC ($$) = 1; }
1081 | declspecs_sc_nots_nosa_ea typespec_nonattr
1082 { $$ = tree_cons (NULL_TREE, $2, $1);
1083 TREE_STATIC ($$) = 1; }
1084 | declspecs_nosc_ts_nosa_noea scspec
1085 { if (extra_warnings && TREE_STATIC ($1))
1086 warning ("`%s' is not at beginning of declaration",
1087 IDENTIFIER_POINTER ($2));
1088 $$ = tree_cons (NULL_TREE, $2, $1);
1089 TREE_STATIC ($$) = TREE_STATIC ($1); }
1090 | declspecs_nosc_ts_nosa_ea scspec
1091 { if (extra_warnings && TREE_STATIC ($1))
1092 warning ("`%s' is not at beginning of declaration",
1093 IDENTIFIER_POINTER ($2));
1094 $$ = tree_cons (NULL_TREE, $2, $1);
1095 TREE_STATIC ($$) = TREE_STATIC ($1); }
1096 | declspecs_sc_ts_nosa_noea scspec
1097 { if (extra_warnings && TREE_STATIC ($1))
1098 warning ("`%s' is not at beginning of declaration",
1099 IDENTIFIER_POINTER ($2));
1100 $$ = tree_cons (NULL_TREE, $2, $1);
1101 TREE_STATIC ($$) = TREE_STATIC ($1); }
1102 | declspecs_sc_ts_nosa_ea scspec
1103 { if (extra_warnings && TREE_STATIC ($1))
1104 warning ("`%s' is not at beginning of declaration",
1105 IDENTIFIER_POINTER ($2));
1106 $$ = tree_cons (NULL_TREE, $2, $1);
1107 TREE_STATIC ($$) = TREE_STATIC ($1); }
1110 declspecs_sc_ts_nosa_ea:
1111 declspecs_sc_ts_nosa_noea attributes
1112 { $$ = tree_cons ($2, NULL_TREE, $1);
1113 TREE_STATIC ($$) = TREE_STATIC ($1); }
1114 | declspecs_sc_ts_nosa_noea typespec_reserved_attr
1115 { $$ = tree_cons (NULL_TREE, $2, $1);
1116 TREE_STATIC ($$) = 1; }
1117 | declspecs_sc_ts_nosa_ea typespec_reserved_attr
1118 { $$ = tree_cons (NULL_TREE, $2, $1);
1119 TREE_STATIC ($$) = 1; }
1120 | declspecs_sc_nots_nosa_noea typespec_attr
1121 { $$ = tree_cons (NULL_TREE, $2, $1);
1122 TREE_STATIC ($$) = 1; }
1123 | declspecs_sc_nots_nosa_ea typespec_attr
1124 { $$ = tree_cons (NULL_TREE, $2, $1);
1125 TREE_STATIC ($$) = 1; }
1128 declspecs_sc_ts_sa_noea:
1129 declspecs_sc_ts_sa_noea TYPE_QUAL
1130 { $$ = tree_cons (NULL_TREE, $2, $1);
1131 TREE_STATIC ($$) = 1; }
1132 | declspecs_sc_ts_sa_ea TYPE_QUAL
1133 { $$ = tree_cons (NULL_TREE, $2, $1);
1134 TREE_STATIC ($$) = 1; }
1135 | declspecs_sc_ts_sa_noea typespec_reserved_nonattr
1136 { $$ = tree_cons (NULL_TREE, $2, $1);
1137 TREE_STATIC ($$) = 1; }
1138 | declspecs_sc_ts_sa_ea typespec_reserved_nonattr
1139 { $$ = tree_cons (NULL_TREE, $2, $1);
1140 TREE_STATIC ($$) = 1; }
1141 | declspecs_sc_nots_sa_noea typespec_nonattr
1142 { $$ = tree_cons (NULL_TREE, $2, $1);
1143 TREE_STATIC ($$) = 1; }
1144 | declspecs_sc_nots_sa_ea typespec_nonattr
1145 { $$ = tree_cons (NULL_TREE, $2, $1);
1146 TREE_STATIC ($$) = 1; }
1147 | declspecs_nosc_ts_sa_noea scspec
1148 { if (extra_warnings && TREE_STATIC ($1))
1149 warning ("`%s' is not at beginning of declaration",
1150 IDENTIFIER_POINTER ($2));
1151 $$ = tree_cons (NULL_TREE, $2, $1);
1152 TREE_STATIC ($$) = TREE_STATIC ($1); }
1153 | declspecs_nosc_ts_sa_ea scspec
1154 { if (extra_warnings && TREE_STATIC ($1))
1155 warning ("`%s' is not at beginning of declaration",
1156 IDENTIFIER_POINTER ($2));
1157 $$ = tree_cons (NULL_TREE, $2, $1);
1158 TREE_STATIC ($$) = TREE_STATIC ($1); }
1159 | declspecs_sc_ts_sa_noea scspec
1160 { if (extra_warnings && TREE_STATIC ($1))
1161 warning ("`%s' is not at beginning of declaration",
1162 IDENTIFIER_POINTER ($2));
1163 $$ = tree_cons (NULL_TREE, $2, $1);
1164 TREE_STATIC ($$) = TREE_STATIC ($1); }
1165 | declspecs_sc_ts_sa_ea scspec
1166 { if (extra_warnings && TREE_STATIC ($1))
1167 warning ("`%s' is not at beginning of declaration",
1168 IDENTIFIER_POINTER ($2));
1169 $$ = tree_cons (NULL_TREE, $2, $1);
1170 TREE_STATIC ($$) = TREE_STATIC ($1); }
1173 declspecs_sc_ts_sa_ea:
1174 declspecs_sc_ts_sa_noea attributes
1175 { $$ = tree_cons ($2, NULL_TREE, $1);
1176 TREE_STATIC ($$) = TREE_STATIC ($1); }
1177 | declspecs_sc_ts_sa_noea typespec_reserved_attr
1178 { $$ = tree_cons (NULL_TREE, $2, $1);
1179 TREE_STATIC ($$) = 1; }
1180 | declspecs_sc_ts_sa_ea typespec_reserved_attr
1181 { $$ = tree_cons (NULL_TREE, $2, $1);
1182 TREE_STATIC ($$) = 1; }
1183 | declspecs_sc_nots_sa_noea typespec_attr
1184 { $$ = tree_cons (NULL_TREE, $2, $1);
1185 TREE_STATIC ($$) = 1; }
1186 | declspecs_sc_nots_sa_ea typespec_attr
1187 { $$ = tree_cons (NULL_TREE, $2, $1);
1188 TREE_STATIC ($$) = 1; }
1191 /* Particular useful classes of declspecs. */
1193 declspecs_nosc_ts_nosa_noea
1194 | declspecs_nosc_ts_nosa_ea
1195 | declspecs_nosc_ts_sa_noea
1196 | declspecs_nosc_ts_sa_ea
1197 | declspecs_sc_ts_nosa_noea
1198 | declspecs_sc_ts_nosa_ea
1199 | declspecs_sc_ts_sa_noea
1200 | declspecs_sc_ts_sa_ea
1204 declspecs_nosc_nots_nosa_noea
1205 | declspecs_nosc_nots_nosa_ea
1206 | declspecs_nosc_nots_sa_noea
1207 | declspecs_nosc_nots_sa_ea
1208 | declspecs_sc_nots_nosa_noea
1209 | declspecs_sc_nots_nosa_ea
1210 | declspecs_sc_nots_sa_noea
1211 | declspecs_sc_nots_sa_ea
1215 declspecs_nosc_ts_nosa_noea
1216 | declspecs_nosc_ts_nosa_ea
1217 | declspecs_sc_ts_nosa_noea
1218 | declspecs_sc_ts_nosa_ea
1221 declspecs_nots_nosa:
1222 declspecs_nosc_nots_nosa_noea
1223 | declspecs_nosc_nots_nosa_ea
1224 | declspecs_sc_nots_nosa_noea
1225 | declspecs_sc_nots_nosa_ea
1229 declspecs_nosc_ts_nosa_noea
1230 | declspecs_nosc_ts_nosa_ea
1231 | declspecs_nosc_ts_sa_noea
1232 | declspecs_nosc_ts_sa_ea
1235 declspecs_nosc_nots:
1236 declspecs_nosc_nots_nosa_noea
1237 | declspecs_nosc_nots_nosa_ea
1238 | declspecs_nosc_nots_sa_noea
1239 | declspecs_nosc_nots_sa_ea
1243 declspecs_nosc_ts_nosa_noea
1244 | declspecs_nosc_ts_nosa_ea
1245 | declspecs_nosc_ts_sa_noea
1246 | declspecs_nosc_ts_sa_ea
1247 | declspecs_nosc_nots_nosa_noea
1248 | declspecs_nosc_nots_nosa_ea
1249 | declspecs_nosc_nots_sa_noea
1250 | declspecs_nosc_nots_sa_ea
1254 declspecs_nosc_nots_nosa_noea
1255 | declspecs_nosc_nots_nosa_ea
1256 | declspecs_nosc_nots_sa_noea
1257 | declspecs_nosc_nots_sa_ea
1258 | declspecs_nosc_ts_nosa_noea
1259 | declspecs_nosc_ts_nosa_ea
1260 | declspecs_nosc_ts_sa_noea
1261 | declspecs_nosc_ts_sa_ea
1262 | declspecs_sc_nots_nosa_noea
1263 | declspecs_sc_nots_nosa_ea
1264 | declspecs_sc_nots_sa_noea
1265 | declspecs_sc_nots_sa_ea
1266 | declspecs_sc_ts_nosa_noea
1267 | declspecs_sc_ts_nosa_ea
1268 | declspecs_sc_ts_sa_noea
1269 | declspecs_sc_ts_sa_ea
1272 /* A (possibly empty) sequence of type qualifiers and attributes. */
1273 maybe_type_quals_attrs:
1276 | declspecs_nosc_nots
1280 /* A type specifier (but not a type qualifier).
1281 Once we have seen one of these in a declaration,
1282 if a typedef name appears then it is being redeclared.
1284 The _reserved versions start with a reserved word and may appear anywhere
1285 in the declaration specifiers; the _nonreserved versions may only
1286 appear before any other type specifiers, and after that are (if names)
1289 FIXME: should the _nonreserved version be restricted to names being
1290 redeclared only? The other entries there relate only the GNU extensions
1291 and Objective C, and are historically parsed thus, and don't make sense
1292 after other type specifiers, but it might be cleaner to count them as
1295 _attr means: specifiers that either end with attributes,
1296 or are such that any following attributes would
1297 be parsed as part of the specifier.
1299 _nonattr: specifiers. */
1302 typespec_reserved_nonattr
1303 | typespec_nonreserved_nonattr
1307 typespec_reserved_attr
1310 typespec_reserved_nonattr:
1312 { OBJC_NEED_RAW_IDENTIFIER (1); }
1316 typespec_reserved_attr:
1320 typespec_nonreserved_nonattr:
1322 { /* For a typedef name, record the meaning, not the name.
1323 In case of `foo foo, bar;'. */
1324 $$ = lookup_name ($1); }
1326 | CLASSNAME protocolrefs
1327 { $$ = get_static_reference ($1, $2); }
1328 | OBJECTNAME protocolrefs
1329 { $$ = get_protocol_reference ($2); }
1331 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>"
1332 - nisse@lysator.liu.se */
1333 | non_empty_protocolrefs
1334 { $$ = get_protocol_reference ($1); }
1336 | typeof '(' expr ')'
1337 { skip_evaluation--;
1338 if (TREE_CODE ($3) == COMPONENT_REF
1339 && DECL_C_BIT_FIELD (TREE_OPERAND ($3, 1)))
1340 error ("`typeof' applied to a bit-field");
1341 $$ = TREE_TYPE ($3); }
1342 | typeof '(' typename ')'
1343 { skip_evaluation--; $$ = groktypename ($3); }
1346 /* typespec_nonreserved_attr does not exist. */
1350 | initdecls ',' maybe_resetattrs initdcl
1355 | notype_initdecls ',' maybe_resetattrs notype_initdcl
1359 declarator maybeasm maybe_attribute '='
1360 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1361 chainon ($3, all_prefix_attributes));
1362 start_init ($<ttype>$, $2, global_bindings_p ()); }
1364 /* Note how the declaration of the variable is in effect while its init is parsed! */
1366 finish_decl ($<ttype>5, $6, $2); }
1367 | declarator maybeasm maybe_attribute
1368 { tree d = start_decl ($1, current_declspecs, 0,
1369 chainon ($3, all_prefix_attributes));
1370 finish_decl (d, NULL_TREE, $2);
1375 notype_declarator maybeasm maybe_attribute '='
1376 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1377 chainon ($3, all_prefix_attributes));
1378 start_init ($<ttype>$, $2, global_bindings_p ()); }
1380 /* Note how the declaration of the variable is in effect while its init is parsed! */
1382 finish_decl ($<ttype>5, $6, $2); }
1383 | notype_declarator maybeasm maybe_attribute
1384 { tree d = start_decl ($1, current_declspecs, 0,
1385 chainon ($3, all_prefix_attributes));
1386 finish_decl (d, NULL_TREE, $2); }
1388 /* the * rules are dummies to accept the Apollo extended syntax
1389 so that the header files compile. */
1400 | attributes attribute
1401 { $$ = chainon ($1, $2); }
1405 ATTRIBUTE stop_string_translation
1406 '(' '(' attribute_list ')' ')' start_string_translation
1408 | ATTRIBUTE error start_string_translation
1415 | attribute_list ',' attrib
1416 { $$ = chainon ($1, $3); }
1423 { $$ = build_tree_list ($1, NULL_TREE); }
1424 | any_word '(' IDENTIFIER ')'
1425 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1426 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1427 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1428 | any_word '(' exprlist ')'
1429 { $$ = build_tree_list ($1, $3); }
1432 /* This still leaves out most reserved keywords,
1433 shouldn't we include them? */
1447 /* Initializers. `init' is the entry point. */
1452 { really_start_incremental_init (NULL_TREE); }
1453 initlist_maybe_comma '}'
1454 { $$ = pop_init_level (0); }
1456 { $$ = error_mark_node; }
1459 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1460 initlist_maybe_comma:
1463 pedwarn ("ISO C forbids empty initializer braces"); }
1464 | initlist1 maybecomma
1469 | initlist1 ',' initelt
1472 /* `initelt' is a single element of an initializer.
1473 It may use braces. */
1475 designator_list '=' initval
1476 { if (pedantic && ! flag_isoc99)
1477 pedwarn ("ISO C90 forbids specifying subobject to initialize"); }
1478 | designator initval
1480 pedwarn ("obsolete use of designated initializer without `='"); }
1482 { set_init_label ($1);
1484 pedwarn ("obsolete use of designated initializer with `:'"); }
1492 { push_init_level (0); }
1493 initlist_maybe_comma '}'
1494 { process_init_element (pop_init_level (0)); }
1496 { process_init_element ($1); }
1502 | designator_list designator
1507 { set_init_label ($2); }
1508 | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
1509 { set_init_index ($2, $4);
1511 pedwarn ("ISO C forbids specifying range of elements to initialize"); }
1512 | '[' expr_no_commas ']'
1513 { set_init_index ($2, NULL_TREE); }
1519 pedwarn ("ISO C forbids nested functions");
1521 push_function_context ();
1522 if (! start_function (current_declspecs, $1,
1523 all_prefix_attributes))
1525 pop_function_context ();
1529 old_style_parm_decls save_location
1530 { tree decl = current_function_decl;
1531 DECL_SOURCE_LOCATION (decl) = $4;
1532 store_parm_decls (); }
1533 /* This used to use compstmt_or_error. That caused a bug with
1534 input `f(g) int g {}', where the use of YYERROR1 above caused
1535 an error which then was handled by compstmt_or_error. There
1536 followed a repeated execution of that same rule, which called
1537 YYERROR1 again, and so on. */
1539 { tree decl = current_function_decl;
1542 pop_function_context ();
1543 add_stmt (build_stmt (DECL_STMT, decl)); }
1546 notype_nested_function:
1549 pedwarn ("ISO C forbids nested functions");
1551 push_function_context ();
1552 if (! start_function (current_declspecs, $1,
1553 all_prefix_attributes))
1555 pop_function_context ();
1559 old_style_parm_decls save_location
1560 { tree decl = current_function_decl;
1561 DECL_SOURCE_LOCATION (decl) = $4;
1562 store_parm_decls (); }
1563 /* This used to use compstmt_or_error. That caused a bug with
1564 input `f(g) int g {}', where the use of YYERROR1 above caused
1565 an error which then was handled by compstmt_or_error. There
1566 followed a repeated execution of that same rule, which called
1567 YYERROR1 again, and so on. */
1569 { tree decl = current_function_decl;
1572 pop_function_context ();
1573 add_stmt (build_stmt (DECL_STMT, decl)); }
1576 /* Any kind of declarator (thus, all declarators allowed
1577 after an explicit typespec). */
1580 after_type_declarator
1584 /* A declarator that is allowed only after an explicit typespec. */
1586 after_type_declarator:
1587 '(' maybe_attribute after_type_declarator ')'
1588 { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
1589 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1590 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1591 | after_type_declarator array_declarator %prec '.'
1592 { $$ = set_array_declarator_type ($2, $1, 0); }
1593 | '*' maybe_type_quals_attrs after_type_declarator %prec UNARY
1594 { $$ = make_pointer_declarator ($2, $3); }
1601 /* Kinds of declarator that can appear in a parameter list
1602 in addition to notype_declarator. This is like after_type_declarator
1603 but does not allow a typedef name in parentheses as an identifier
1604 (because it would conflict with a function with that typedef as arg). */
1606 parm_declarator_starttypename
1607 | parm_declarator_nostarttypename
1610 parm_declarator_starttypename:
1611 parm_declarator_starttypename '(' parmlist_or_identifiers %prec '.'
1612 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1613 | parm_declarator_starttypename array_declarator %prec '.'
1614 { $$ = set_array_declarator_type ($2, $1, 0); }
1621 parm_declarator_nostarttypename:
1622 parm_declarator_nostarttypename '(' parmlist_or_identifiers %prec '.'
1623 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1624 | parm_declarator_nostarttypename array_declarator %prec '.'
1625 { $$ = set_array_declarator_type ($2, $1, 0); }
1626 | '*' maybe_type_quals_attrs parm_declarator_starttypename %prec UNARY
1627 { $$ = make_pointer_declarator ($2, $3); }
1628 | '*' maybe_type_quals_attrs parm_declarator_nostarttypename %prec UNARY
1629 { $$ = make_pointer_declarator ($2, $3); }
1630 | '(' maybe_attribute parm_declarator_nostarttypename ')'
1631 { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
1634 /* A declarator allowed whether or not there has been
1635 an explicit typespec. These cannot redeclare a typedef-name. */
1638 notype_declarator '(' parmlist_or_identifiers %prec '.'
1639 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1640 | '(' maybe_attribute notype_declarator ')'
1641 { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
1642 | '*' maybe_type_quals_attrs notype_declarator %prec UNARY
1643 { $$ = make_pointer_declarator ($2, $3); }
1644 | notype_declarator array_declarator %prec '.'
1645 { $$ = set_array_declarator_type ($2, $1, 0); }
1670 /* structsp_attr: struct/union/enum specifiers that either
1671 end with attributes, or are such that any following attributes would
1672 be parsed as part of the struct/union/enum specifier.
1674 structsp_nonattr: other struct/union/enum specifiers. */
1677 struct_head identifier '{'
1678 { $$ = start_struct (RECORD_TYPE, $2);
1679 /* Start scope of tag before parsing components. */
1681 component_decl_list '}' maybe_attribute
1682 { $$ = finish_struct ($<ttype>4, nreverse ($5),
1683 chainon ($1, $7)); }
1684 | struct_head '{' component_decl_list '}' maybe_attribute
1685 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1686 nreverse ($3), chainon ($1, $5));
1688 | union_head identifier '{'
1689 { $$ = start_struct (UNION_TYPE, $2); }
1690 component_decl_list '}' maybe_attribute
1691 { $$ = finish_struct ($<ttype>4, nreverse ($5),
1692 chainon ($1, $7)); }
1693 | union_head '{' component_decl_list '}' maybe_attribute
1694 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1695 nreverse ($3), chainon ($1, $5));
1697 | enum_head identifier '{'
1698 { $$ = start_enum ($2); }
1699 enumlist maybecomma_warn '}' maybe_attribute
1700 { $$ = finish_enum ($<ttype>4, nreverse ($5),
1701 chainon ($1, $8)); }
1703 { $$ = start_enum (NULL_TREE); }
1704 enumlist maybecomma_warn '}' maybe_attribute
1705 { $$ = finish_enum ($<ttype>3, nreverse ($4),
1706 chainon ($1, $7)); }
1710 struct_head identifier
1711 { $$ = xref_tag (RECORD_TYPE, $2); }
1712 | union_head identifier
1713 { $$ = xref_tag (UNION_TYPE, $2); }
1714 | enum_head identifier
1715 { $$ = xref_tag (ENUMERAL_TYPE, $2);
1716 /* In ISO C, enumerated types can be referred to
1717 only if already defined. */
1718 if (pedantic && !COMPLETE_TYPE_P ($$))
1719 pedwarn ("ISO C forbids forward references to `enum' types"); }
1730 { if (pedantic && ! flag_isoc99)
1731 pedwarn ("comma at end of enumerator list"); }
1734 /* We chain the components in reverse order. They are put in forward
1735 order in structsp_attr.
1737 Note that component_declarator returns single decls, so components
1738 and components_notype can use TREE_CHAIN directly, wheras components
1739 and components_notype return lists (of comma separated decls), so
1740 component_decl_list and component_decl_list2 must use chainon.
1742 The theory behind all this is that there will be more semicolon
1743 separated fields than comma separated fields, and so we'll be
1744 minimizing the number of node traversals required by chainon. */
1746 component_decl_list:
1747 component_decl_list2
1749 | component_decl_list2 component_decl
1750 { $$ = chainon ($2, $1);
1751 pedwarn ("no semicolon at end of struct or union"); }
1754 component_decl_list2: /* empty */
1756 | component_decl_list2 component_decl ';'
1757 { $$ = chainon ($2, $1); }
1758 | component_decl_list2 ';'
1760 pedwarn ("extra semicolon in struct or union specified"); }
1762 /* foo(sizeof(struct{ @defs(ClassName)})); */
1763 | AT_DEFS '(' CLASSNAME ')'
1764 { $$ = nreverse (get_class_ivars_from_name ($3)); }
1769 declspecs_nosc_ts setspecs components
1771 POP_DECLSPEC_STACK; }
1772 | declspecs_nosc_ts setspecs
1774 /* Support for unnamed structs or unions as members of
1775 structs or unions (which is [a] useful and [b] supports
1778 pedwarn ("ISO C doesn't support unnamed structs/unions");
1780 $$ = grokfield(NULL, current_declspecs, NULL_TREE);
1781 POP_DECLSPEC_STACK; }
1782 | declspecs_nosc_nots setspecs components_notype
1784 POP_DECLSPEC_STACK; }
1785 | declspecs_nosc_nots
1787 pedwarn ("ISO C forbids member declarations with no members");
1788 shadow_tag_warned ($1, pedantic);
1792 | extension component_decl
1794 RESTORE_EXT_FLAGS ($1); }
1798 component_declarator
1799 | components ',' maybe_resetattrs component_declarator
1800 { TREE_CHAIN ($4) = $1; $$ = $4; }
1804 component_notype_declarator
1805 | components_notype ',' maybe_resetattrs component_notype_declarator
1806 { TREE_CHAIN ($4) = $1; $$ = $4; }
1809 component_declarator:
1810 declarator maybe_attribute
1811 { $$ = grokfield ($1, current_declspecs, NULL_TREE);
1812 decl_attributes (&$$,
1813 chainon ($2, all_prefix_attributes), 0); }
1814 | declarator ':' expr_no_commas maybe_attribute
1815 { $$ = grokfield ($1, current_declspecs, $3);
1816 decl_attributes (&$$,
1817 chainon ($4, all_prefix_attributes), 0); }
1818 | ':' expr_no_commas maybe_attribute
1819 { $$ = grokfield (NULL_TREE, current_declspecs, $2);
1820 decl_attributes (&$$,
1821 chainon ($3, all_prefix_attributes), 0); }
1824 component_notype_declarator:
1825 notype_declarator maybe_attribute
1826 { $$ = grokfield ($1, current_declspecs, NULL_TREE);
1827 decl_attributes (&$$,
1828 chainon ($2, all_prefix_attributes), 0); }
1829 | notype_declarator ':' expr_no_commas maybe_attribute
1830 { $$ = grokfield ($1, current_declspecs, $3);
1831 decl_attributes (&$$,
1832 chainon ($4, all_prefix_attributes), 0); }
1833 | ':' expr_no_commas maybe_attribute
1834 { $$ = grokfield (NULL_TREE, current_declspecs, $2);
1835 decl_attributes (&$$,
1836 chainon ($3, all_prefix_attributes), 0); }
1839 /* We chain the enumerators in reverse order.
1840 They are put in forward order in structsp_attr. */
1844 | enumlist ',' enumerator
1845 { if ($1 == error_mark_node)
1848 TREE_CHAIN ($3) = $1, $$ = $3; }
1850 { $$ = error_mark_node; }
1856 { $$ = build_enumerator ($1, NULL_TREE); }
1857 | identifier '=' expr_no_commas
1858 { $$ = build_enumerator ($1, $3); }
1863 { pending_xref_error ();
1866 { $$ = build_tree_list ($<ttype>2, $3); }
1869 absdcl: /* an absolute declarator */
1875 absdcl_maybe_attribute: /* absdcl maybe_attribute, but not just attributes */
1877 { $$ = build_tree_list (build_tree_list (current_declspecs,
1879 all_prefix_attributes); }
1881 { $$ = build_tree_list (build_tree_list (current_declspecs,
1883 all_prefix_attributes); }
1884 | absdcl1_noea attributes
1885 { $$ = build_tree_list (build_tree_list (current_declspecs,
1887 chainon ($2, all_prefix_attributes)); }
1890 absdcl1: /* a nonempty absolute declarator */
1897 | '*' maybe_type_quals_attrs absdcl1_noea
1898 { $$ = make_pointer_declarator ($2, $3); }
1902 '*' maybe_type_quals_attrs
1903 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1904 | '*' maybe_type_quals_attrs absdcl1_ea
1905 { $$ = make_pointer_declarator ($2, $3); }
1909 '(' maybe_attribute absdcl1 ')'
1910 { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
1911 | direct_absdcl1 '(' parmlist
1912 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1913 | direct_absdcl1 array_declarator
1914 { $$ = set_array_declarator_type ($2, $1, 1); }
1916 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1918 { $$ = set_array_declarator_type ($1, NULL_TREE, 1); }
1921 /* The [...] part of a declarator for an array type. */
1924 '[' maybe_type_quals_attrs expr_no_commas ']'
1925 { $$ = build_array_declarator ($3, $2, 0, 0); }
1926 | '[' maybe_type_quals_attrs ']'
1927 { $$ = build_array_declarator (NULL_TREE, $2, 0, 0); }
1928 | '[' maybe_type_quals_attrs '*' ']'
1929 { $$ = build_array_declarator (NULL_TREE, $2, 0, 1); }
1930 | '[' STATIC maybe_type_quals_attrs expr_no_commas ']'
1931 { $$ = build_array_declarator ($4, $3, 1, 0); }
1932 /* declspecs_nosc_nots is a synonym for type_quals_attrs. */
1933 | '[' declspecs_nosc_nots STATIC expr_no_commas ']'
1934 { $$ = build_array_declarator ($4, $2, 1, 0); }
1937 /* A nonempty series of declarations and statements (possibly followed by
1938 some labels) that can form the body of a compound statement.
1939 NOTE: we don't allow labels on declarations; this might seem like a
1940 natural extension, but there would be a conflict between attributes
1941 on the label and prefix attributes on the declaration. */
1944 lineno_stmt_decl_or_labels_ending_stmt
1945 | lineno_stmt_decl_or_labels_ending_decl
1946 | lineno_stmt_decl_or_labels_ending_label
1948 error ("label at end of compound statement");
1950 | lineno_stmt_decl_or_labels_ending_error
1953 lineno_stmt_decl_or_labels_ending_stmt:
1955 | lineno_stmt_decl_or_labels_ending_stmt lineno_stmt
1956 | lineno_stmt_decl_or_labels_ending_decl lineno_stmt
1957 | lineno_stmt_decl_or_labels_ending_label lineno_stmt
1958 | lineno_stmt_decl_or_labels_ending_error lineno_stmt
1961 lineno_stmt_decl_or_labels_ending_decl:
1963 | lineno_stmt_decl_or_labels_ending_stmt lineno_decl
1965 if ((pedantic && !flag_isoc99)
1966 || warn_declaration_after_statement)
1967 pedwarn_c90 ("ISO C90 forbids mixed declarations and code");
1969 | lineno_stmt_decl_or_labels_ending_decl lineno_decl
1970 | lineno_stmt_decl_or_labels_ending_error lineno_decl
1973 lineno_stmt_decl_or_labels_ending_label:
1975 | lineno_stmt_decl_or_labels_ending_stmt lineno_label
1976 | lineno_stmt_decl_or_labels_ending_decl lineno_label
1977 | lineno_stmt_decl_or_labels_ending_label lineno_label
1978 | lineno_stmt_decl_or_labels_ending_error lineno_label
1981 lineno_stmt_decl_or_labels_ending_error:
1983 | lineno_stmt_decl_or_labels errstmt
1986 lineno_stmt_decl_or_labels:
1987 lineno_stmt_decl_or_labels_ending_stmt
1988 | lineno_stmt_decl_or_labels_ending_decl
1989 | lineno_stmt_decl_or_labels_ending_label
1990 | lineno_stmt_decl_or_labels_ending_error
1996 /* Start and end blocks created for the new scopes of C99. */
1997 c99_block_start: /* empty */
1998 { $$ = c_begin_compound_stmt (flag_isoc99); }
2001 /* Read zero or more forward-declarations for labels
2002 that nested functions can jump to. */
2007 pedwarn ("ISO C forbids label declarations"); }
2012 | label_decls label_decl
2016 LABEL identifiers_or_typenames ';'
2018 for (link = $2; link; link = TREE_CHAIN (link))
2020 tree label = declare_label (TREE_VALUE (link));
2021 C_DECLARED_LABEL_FLAG (label) = 1;
2022 add_stmt (build_stmt (DECL_STMT, label));
2027 /* This is the body of a function definition.
2028 It causes syntax errors to ignore to the next openbrace. */
2035 compstmt_start: '{' { compstmt_count++;
2036 $$ = c_begin_compound_stmt (true); }
2039 compstmt_nostart: '}'
2040 | maybe_label_decls compstmt_contents_nonempty '}'
2043 compstmt_contents_nonempty:
2048 compstmt_primary_start:
2050 { if (current_function_decl == 0)
2052 error ("braced-group within expression allowed "
2053 "only inside a function");
2057 $$ = c_begin_stmt_expr ();
2061 compstmt: compstmt_start compstmt_nostart
2062 { $$ = c_end_compound_stmt ($1, true); }
2066 /* We must build the if statement node before parsing its
2067 condition so that we get its location pointing to the
2068 line containing the "if", and not the line containing
2069 the close-parenthesis. */
2071 { c_begin_if_stmt (); }
2073 { c_finish_if_cond ($4, compstmt_count, ++stmt_count); }
2077 if_prefix c99_block_lineno_labeled_stmt
2078 { c_finish_then ($2); }
2079 /* Make sure c_finish_if_stmt is run for each call to
2080 c_begin_if_stmt. Otherwise a crash is likely. */
2084 /* This is a subroutine of stmt.
2085 It is used twice, once for valid DO statements
2086 and once for catching errors in parsing the end test. */
2091 c_in_iteration_stmt++;
2093 = add_stmt (build_stmt (DO_STMT, NULL_TREE,
2095 /* In the event that a parse error prevents
2096 parsing the complete do-statement, set the
2097 condition now. Otherwise, we can get crashes at
2098 RTL-generation time. */
2099 DO_COND ($<ttype>$) = error_mark_node; }
2100 c99_block_lineno_labeled_stmt WHILE
2103 c_in_iteration_stmt--; }
2106 /* The forced readahead in here is because we might be at the end of a
2107 line, and the line and file won't be bumped until yylex absorbs the
2108 first token on the next line. */
2111 { if (yychar == YYEMPTY)
2113 $$ = input_location; }
2116 lineno_labeled_stmt:
2118 | lineno_label lineno_labeled_stmt
2121 /* Like lineno_labeled_stmt, but a block in C99. */
2122 c99_block_lineno_labeled_stmt:
2123 c99_block_start lineno_labeled_stmt
2124 { $$ = c_end_compound_stmt ($1, flag_isoc99); }
2130 /* Two cases cannot and do not have line numbers associated:
2131 If stmt is degenerate, such as "2;", then stmt is an
2132 INTEGER_CST, which cannot hold line numbers. But that's
2133 ok because the statement will either be changed to a
2134 MODIFY_EXPR during gimplification of the statement expr,
2135 or discarded. If stmt was compound, but without new
2136 variables, we will have skipped the creation of a BIND
2137 and will have a bare STATEMENT_LIST. But that's ok
2138 because (recursively) all of the component statments
2139 should already have line numbers assigned. */
2140 if ($2 && EXPR_P ($2))
2142 SET_EXPR_LOCUS ($2, NULL);
2143 annotate_with_locus ($2, $1);
2152 SET_EXPR_LOCUS ($2, NULL);
2153 annotate_with_locus ($2, $1);
2158 select_or_iter_stmt:
2160 { c_begin_else (stmt_count); }
2161 c99_block_lineno_labeled_stmt
2162 { c_finish_else ($4); c_finish_if_stmt (stmt_count); }
2163 | simple_if %prec IF
2164 { c_finish_if_stmt (stmt_count); }
2165 | simple_if ELSE error
2166 { c_finish_if_stmt (stmt_count + 1); }
2167 /* We must build the WHILE_STMT node before parsing its
2168 condition so that EXPR_LOCUS refers to the line
2169 containing the "while", and not the line containing
2170 the close-parenthesis.
2172 c_begin_while_stmt returns the WHILE_STMT node, which
2173 we later pass to c_finish_while_stmt_cond to fill
2174 in the condition and other tidbits. */
2177 $<ttype>$ = c_begin_while_stmt (); }
2179 { c_in_iteration_stmt++;
2180 c_finish_while_stmt_cond ($4, $<ttype>2); }
2181 c99_block_lineno_labeled_stmt
2182 { c_in_iteration_stmt--;
2183 c_finish_while_stmt ($7, $<ttype>2); }
2186 { DO_COND ($1) = lang_hooks.truthvalue_conversion ($3); }
2187 | do_stmt_start error
2190 { $<ttype>$ = c_begin_for_stmt (); }
2193 c_finish_for_stmt_init ($<ttype>2); }
2195 { c_finish_for_stmt_cond ($6, $<ttype>2); }
2197 { c_in_iteration_stmt++;
2198 c_finish_for_stmt_incr ($9, $<ttype>2); }
2199 c99_block_lineno_labeled_stmt
2200 { c_finish_for_stmt ($12, $<ttype>2);
2201 c_in_iteration_stmt--; }
2202 | SWITCH '(' expr ')'
2204 $<ttype>$ = c_start_case ($3);
2206 c99_block_lineno_labeled_stmt
2207 { c_finish_case ($6);
2213 { c_finish_expr_stmt ($1); }
2215 { check_for_loop_decls (); }
2224 /* Parse a single real statement, not including any labels. */
2227 { stmt_count++; add_stmt ($1); }
2229 { stmt_count++; c_finish_expr_stmt ($1); }
2230 | c99_block_start select_or_iter_stmt
2231 { add_stmt (c_end_compound_stmt ($1, flag_isoc99)); }
2234 if (!(c_in_iteration_stmt || c_in_case_stmt))
2235 error ("break statement not within loop or switch");
2237 add_stmt (build_break_stmt ()); }
2240 if (!c_in_iteration_stmt)
2241 error ("continue statement not within a loop");
2243 add_stmt (build_continue_stmt ()); }
2245 { stmt_count++; c_finish_return (NULL_TREE); }
2247 { stmt_count++; c_finish_return ($2); }
2249 | GOTO identifier ';'
2252 decl = lookup_label ($2);
2255 TREE_USED (decl) = 1;
2256 add_stmt (build_stmt (GOTO_EXPR, decl));
2261 pedwarn ("ISO C forbids `goto *expr;'");
2263 $3 = convert (ptr_type_node, $3);
2264 add_stmt (build_stmt (GOTO_EXPR, $3)); }
2269 { stmt_count++; objc_build_throw_stmt ($2); }
2271 { stmt_count++; objc_build_throw_stmt (NULL_TREE); }
2272 | objc_try_catch_stmt
2274 | AT_SYNCHRONIZED '(' expr ')' save_location compstmt
2275 { stmt_count++; objc_build_synchronized ($5, $3, $6); }
2279 AT_CATCH '(' parm ')'
2280 { objc_begin_catch_clause ($3); }
2284 objc_catch_prefix '{' compstmt_nostart
2285 { objc_finish_catch_clause (); }
2286 | objc_catch_prefix '{' error '}'
2287 { objc_finish_catch_clause (); }
2290 objc_opt_catch_list:
2292 | objc_opt_catch_list objc_catch_clause
2295 objc_try_catch_clause:
2296 AT_TRY save_location compstmt
2297 { stmt_count++; objc_begin_try_stmt ($2, $3); }
2301 objc_finally_clause:
2302 AT_FINALLY save_location compstmt
2303 { objc_build_finally_clause ($2, $3); }
2306 objc_try_catch_stmt:
2307 objc_try_catch_clause
2308 { objc_finish_try_stmt (); }
2309 | objc_try_catch_clause objc_finally_clause
2310 { objc_finish_try_stmt (); }
2314 /* Any kind of label, including jump labels and case labels.
2315 ANSI C accepts labels only before statements, but we allow them
2316 also at the end of a compound statement. */
2318 label: CASE expr_no_commas ':'
2320 $$ = do_case ($2, NULL_TREE); }
2321 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
2323 $$ = do_case ($2, $4); }
2326 $$ = do_case (NULL_TREE, NULL_TREE); }
2327 | identifier save_location ':' maybe_attribute
2328 { tree label = define_label ($2, $1);
2332 decl_attributes (&label, $4, 0);
2333 $$ = add_stmt (build_stmt (LABEL_EXPR, label));
2340 /* Asm expressions and statements */
2342 /* simple_asm_expr is used in restricted contexts, where a full
2343 expression with inputs and outputs does not make sense. */
2345 ASM_KEYWORD stop_string_translation
2346 '(' STRING ')' start_string_translation
2350 /* maybeasm: used for assembly names for declarations */
2357 /* asmdef: asm() outside a function body. */
2360 { assemble_asm ($1); }
2361 | ASM_KEYWORD error start_string_translation ';'
2365 /* Full-blown asm statement with inputs, outputs, clobbers, and
2366 volatile tag allowed. */
2368 ASM_KEYWORD maybe_volatile stop_string_translation
2369 '(' asm_argument ')' start_string_translation ';'
2371 $$ = build_asm_stmt ($2, $5); }
2377 { $$ = build_asm_expr ($1, 0, 0, 0, true); }
2378 /* output operands */
2379 | STRING ':' asm_operands
2380 { $$ = build_asm_expr ($1, $3, 0, 0, false); }
2381 /* output and input operands */
2382 | STRING ':' asm_operands ':' asm_operands
2383 { $$ = build_asm_expr ($1, $3, $5, 0, false); }
2384 /* output and input operands and clobbers */
2385 | STRING ':' asm_operands ':' asm_operands ':' asm_clobbers
2386 { $$ = build_asm_expr ($1, $3, $5, $7, false); }
2389 /* Either 'volatile' or nothing. First thing in an `asm' statement. */
2395 { if ($1 != ridpointers[RID_VOLATILE])
2397 warning ("%E qualifier ignored on asm", $1);
2405 /* These are the operands other than the first string and colon
2406 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2407 asm_operands: /* empty */
2409 | nonnull_asm_operands
2412 nonnull_asm_operands:
2414 | nonnull_asm_operands ',' asm_operand
2415 { $$ = chainon ($1, $3); }
2419 STRING start_string_translation '(' expr ')' stop_string_translation
2420 { $$ = build_tree_list (build_tree_list (NULL_TREE, $1), $4); }
2421 | '[' identifier ']' STRING start_string_translation
2422 '(' expr ')' stop_string_translation
2423 { $2 = build_string (IDENTIFIER_LENGTH ($2),
2424 IDENTIFIER_POINTER ($2));
2425 $$ = build_tree_list (build_tree_list ($2, $4), $7); }
2430 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
2431 | asm_clobbers ',' STRING
2432 { $$ = tree_cons (NULL_TREE, $3, $1); }
2435 stop_string_translation:
2436 { c_lex_string_translate = 0; }
2439 start_string_translation:
2440 { c_lex_string_translate = 1; }
2444 /* This is what appears inside the parens in a function declarator.
2445 Its value is a list of ..._TYPE nodes. Attributes must appear here
2446 to avoid a conflict with their appearance after an open parenthesis
2447 in an abstract declarator, as in
2448 "void bar (int (__attribute__((__mode__(SI))) int foo));". */
2452 declare_parm_level (); }
2461 { mark_forward_parm_decls (); }
2463 { /* Dummy action so attributes are in known place
2464 on parser stack. */ }
2468 { $$ = make_node (TREE_LIST); }
2471 /* This is what appears inside the parens in a function declarator.
2472 Is value is represented in the format that grokdeclarator expects. */
2473 parmlist_2: /* empty */
2474 { $$ = make_node (TREE_LIST); }
2476 { $$ = make_node (TREE_LIST);
2477 /* Suppress -Wold-style-definition for this case. */
2478 TREE_CHAIN ($$) = error_mark_node;
2479 error ("ISO C requires a named argument before `...'");
2482 { $$ = get_parm_info (/*ellipsis=*/false); }
2483 | parms ',' ELLIPSIS
2484 { $$ = get_parm_info (/*ellipsis=*/true); }
2489 { push_parm_decl ($1); }
2491 { push_parm_decl ($3); }
2494 /* A single parameter declaration or parameter type name,
2495 as found in a parmlist. */
2497 declspecs_ts setspecs parm_declarator maybe_attribute
2498 { $$ = build_tree_list (build_tree_list (current_declspecs,
2500 chainon ($4, all_prefix_attributes));
2501 POP_DECLSPEC_STACK; }
2502 | declspecs_ts setspecs notype_declarator maybe_attribute
2503 { $$ = build_tree_list (build_tree_list (current_declspecs,
2505 chainon ($4, all_prefix_attributes));
2506 POP_DECLSPEC_STACK; }
2507 | declspecs_ts setspecs absdcl_maybe_attribute
2509 POP_DECLSPEC_STACK; }
2510 | declspecs_nots setspecs notype_declarator maybe_attribute
2511 { $$ = build_tree_list (build_tree_list (current_declspecs,
2513 chainon ($4, all_prefix_attributes));
2514 POP_DECLSPEC_STACK; }
2516 | declspecs_nots setspecs absdcl_maybe_attribute
2518 POP_DECLSPEC_STACK; }
2521 /* The first parm, which must suck attributes from off the top of the parser
2524 declspecs_ts_nosa setspecs_fp parm_declarator maybe_attribute
2525 { $$ = build_tree_list (build_tree_list (current_declspecs,
2527 chainon ($4, all_prefix_attributes));
2528 POP_DECLSPEC_STACK; }
2529 | declspecs_ts_nosa setspecs_fp notype_declarator maybe_attribute
2530 { $$ = build_tree_list (build_tree_list (current_declspecs,
2532 chainon ($4, all_prefix_attributes));
2533 POP_DECLSPEC_STACK; }
2534 | declspecs_ts_nosa setspecs_fp absdcl_maybe_attribute
2536 POP_DECLSPEC_STACK; }
2537 | declspecs_nots_nosa setspecs_fp notype_declarator maybe_attribute
2538 { $$ = build_tree_list (build_tree_list (current_declspecs,
2540 chainon ($4, all_prefix_attributes));
2541 POP_DECLSPEC_STACK; }
2543 | declspecs_nots_nosa setspecs_fp absdcl_maybe_attribute
2545 POP_DECLSPEC_STACK; }
2550 { prefix_attributes = chainon (prefix_attributes, $<ttype>-2);
2551 all_prefix_attributes = prefix_attributes; }
2554 /* This is used in a function definition
2555 where either a parmlist or an identifier list is ok.
2556 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2557 parmlist_or_identifiers:
2560 declare_parm_level (); }
2561 parmlist_or_identifiers_1
2566 parmlist_or_identifiers_1:
2570 for (t = $1; t; t = TREE_CHAIN (t))
2571 if (TREE_VALUE (t) == NULL_TREE)
2572 error ("`...' in old-style identifier list");
2573 $$ = tree_cons (NULL_TREE, NULL_TREE, $1);
2575 /* Make sure we have a parmlist after attributes. */
2577 && (TREE_CODE ($$) != TREE_LIST
2578 || TREE_PURPOSE ($$) == 0
2579 || TREE_CODE (TREE_PURPOSE ($$)) != PARM_DECL))
2584 /* A nonempty list of identifiers. */
2587 { $$ = build_tree_list (NULL_TREE, $1); }
2588 | identifiers ',' IDENTIFIER
2589 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2592 /* A nonempty list of identifiers, including typenames. */
2593 identifiers_or_typenames:
2595 { $$ = build_tree_list (NULL_TREE, $1); }
2596 | identifiers_or_typenames ',' identifier
2597 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2602 { $$ = SAVE_EXT_FLAGS();
2604 warn_pointer_arith = 0;
2605 warn_traditional = 0;
2610 /* Objective-C productions. */
2620 if (objc_implementation_context)
2622 finish_class (objc_implementation_context);
2623 objc_ivar_chain = NULL_TREE;
2624 objc_implementation_context = NULL_TREE;
2627 warning ("`@end' must appear in an implementation context");
2631 /* A nonempty list of identifiers. */
2634 { $$ = build_tree_list (NULL_TREE, $1); }
2635 | identifier_list ',' identifier
2636 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2640 AT_CLASS identifier_list ';'
2642 objc_declare_class ($2);
2647 AT_ALIAS identifier identifier ';'
2649 objc_declare_alias ($2, $3);
2654 ':' identifier { $$ = $2; }
2655 | /* NULL */ %prec HYPERUNARY { $$ = NULL_TREE; }
2659 '{' ivar_decl_list '}'
2664 AT_INTERFACE identifier superclass protocolrefs
2666 objc_interface_context = objc_ivar_context
2667 = start_class (CLASS_INTERFACE_TYPE, $2, $3, $4);
2668 objc_public_flag = 0;
2672 continue_class (objc_interface_context);
2674 methodprotolist AT_END
2676 finish_class (objc_interface_context);
2677 objc_interface_context = NULL_TREE;
2680 | AT_IMPLEMENTATION identifier superclass
2682 objc_implementation_context = objc_ivar_context
2683 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $3, NULL_TREE);
2684 objc_public_flag = 0;
2689 = continue_class (objc_implementation_context);
2692 | AT_INTERFACE identifier '(' identifier ')' protocolrefs
2694 objc_interface_context
2695 = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2696 continue_class (objc_interface_context);
2698 methodprotolist AT_END
2700 finish_class (objc_interface_context);
2701 objc_interface_context = NULL_TREE;
2704 | AT_IMPLEMENTATION identifier '(' identifier ')'
2706 objc_implementation_context
2707 = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2709 = continue_class (objc_implementation_context);
2714 AT_PROTOCOL identifier protocolrefs
2716 objc_pq_context = 1;
2717 objc_interface_context
2718 = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2720 methodprotolist AT_END
2722 objc_pq_context = 0;
2723 finish_protocol(objc_interface_context);
2724 objc_interface_context = NULL_TREE;
2726 /* The @protocol forward-declaration production introduces a
2727 reduce/reduce conflict on ';', which should be resolved in
2728 favor of the production 'identifier_list -> identifier'. */
2729 | AT_PROTOCOL identifier_list ';'
2731 objc_declare_protocols ($2);
2740 | non_empty_protocolrefs
2743 non_empty_protocolrefs:
2744 ARITHCOMPARE identifier_list ARITHCOMPARE
2746 if ($1 == LT_EXPR && $3 == GT_EXPR)
2754 ivar_decl_list visibility_spec ivar_decls
2759 AT_PRIVATE { objc_public_flag = 2; }
2760 | AT_PROTECTED { objc_public_flag = 0; }
2761 | AT_PUBLIC { objc_public_flag = 1; }
2769 | ivar_decls ivar_decl ';'
2773 pedwarn ("extra semicolon in struct or union specified");
2778 /* There is a shift-reduce conflict here, because `components' may
2779 start with a `typename'. It happens that shifting (the default resolution)
2780 does the right thing, because it treats the `typename' as part of
2781 a `typed_typespecs'.
2783 It is possible that this same technique would allow the distinction
2784 between `notype_initdecls' and `initdecls' to be eliminated.
2785 But I am being cautious and not trying it. */
2788 declspecs_nosc_ts setspecs ivars
2790 POP_DECLSPEC_STACK; }
2791 | declspecs_nosc_nots setspecs ivars
2793 POP_DECLSPEC_STACK; }
2802 | ivars ',' maybe_resetattrs ivar_declarator
2808 $$ = add_instance_variable (objc_ivar_context,
2810 $1, current_declspecs,
2813 | declarator ':' expr_no_commas
2815 $$ = add_instance_variable (objc_ivar_context,
2817 $1, current_declspecs, $3);
2819 | ':' expr_no_commas
2821 $$ = add_instance_variable (objc_ivar_context,
2824 current_declspecs, $2);
2830 { objc_inherit_code = CLASS_METHOD_DECL; }
2832 { objc_inherit_code = INSTANCE_METHOD_DECL; }
2838 objc_pq_context = 1;
2839 if (!objc_implementation_context)
2840 fatal_error ("method definition not in class context");
2844 objc_pq_context = 0;
2845 objc_add_method (objc_implementation_context,
2847 objc_inherit_code == CLASS_METHOD_DECL);
2848 start_method_def ($3);
2852 continue_method_def ();
2856 finish_method_def ();
2860 /* the reason for the strange actions in this rule
2861 is so that notype_initdecls when reached via datadef
2862 can find a valid list of type and sc specs in $0. */
2866 | methodprotolist methodproto
2867 | methodprotolist { $<ttype>$ = NULL_TREE; } datadef
2878 /* Remember protocol qualifiers in prototypes. */
2879 objc_pq_context = 1;
2883 /* Forget protocol qualifiers here. */
2884 objc_pq_context = 0;
2885 objc_add_method (objc_interface_context,
2887 objc_inherit_code == CLASS_METHOD_DECL);
2893 '(' typename ')' unaryselector
2895 $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
2900 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
2903 | '(' typename ')' keywordselector optparmlist
2905 $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
2908 | keywordselector optparmlist
2910 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
2914 /* "optarglist" assumes that start_method_def has already been called...
2915 if it is not, the "xdecls" will not be placed in the proper scope */
2922 /* to get around the following situation: "int foo (int a) int b; {}" that
2923 is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
2938 declspecs_ts setspecs myparms ';'
2939 { POP_DECLSPEC_STACK; }
2941 { shadow_tag ($1); }
2942 | declspecs_nots ';'
2943 { pedwarn ("empty declaration"); }
2948 { push_parm_decl ($1); }
2949 | myparms ',' myparm
2950 { push_parm_decl ($3); }
2953 /* A single parameter declaration or parameter type name,
2954 as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
2957 parm_declarator maybe_attribute
2958 { $$ = build_tree_list (build_tree_list (current_declspecs,
2960 chainon ($2, all_prefix_attributes)); }
2961 | notype_declarator maybe_attribute
2962 { $$ = build_tree_list (build_tree_list (current_declspecs,
2964 chainon ($2, all_prefix_attributes)); }
2965 | absdcl_maybe_attribute
2976 /* oh what a kludge! */
2977 $$ = objc_ellipsis_node;
2985 /* returns a tree list node generated by get_parm_info */
2998 | keywordselector keyworddecl
3000 $$ = chainon ($1, $2);
3013 ENUM | STRUCT | UNION | IF | ELSE | WHILE | DO | FOR
3014 | SWITCH | CASE | DEFAULT | BREAK | CONTINUE | RETURN
3015 | GOTO | ASM_KEYWORD | SIZEOF | TYPEOF | ALIGNOF
3016 | TYPESPEC | TYPE_QUAL
3020 selector ':' '(' typename ')' identifier
3022 $$ = build_keyword_decl ($1, $4, $6);
3025 | selector ':' identifier
3027 $$ = build_keyword_decl ($1, NULL_TREE, $3);
3030 | ':' '(' typename ')' identifier
3032 $$ = build_keyword_decl (NULL_TREE, $3, $5);
3037 $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
3048 | keywordarglist keywordarg
3050 $$ = chainon ($1, $2);
3058 if (TREE_CHAIN ($1) == NULL_TREE)
3059 /* just return the expr., remove a level of indirection */
3060 $$ = TREE_VALUE ($1);
3062 /* we have a comma expr., we will collapse later */
3068 selector ':' keywordexpr
3070 $$ = build_tree_list ($1, $3);
3074 $$ = build_tree_list (NULL_TREE, $2);
3082 $$ = get_class_reference ($1);
3086 $$ = get_class_reference ($1);
3091 '[' receiver messageargs ']'
3092 { $$ = build_tree_list ($2, $3); }
3102 | keywordnamelist keywordname
3104 $$ = chainon ($1, $2);
3111 $$ = build_tree_list ($1, NULL_TREE);
3115 $$ = build_tree_list (NULL_TREE, NULL_TREE);
3120 AT_SELECTOR '(' selectorarg ')'
3127 AT_PROTOCOL '(' identifier ')'
3133 /* extension to support C-structures in the archiver */
3136 AT_ENCODE '(' typename ')'
3138 $$ = groktypename ($3);
3145 /* yylex() is a thin wrapper around c_lex(), all it does is translate
3146 cpplib.h's token codes into yacc's token codes. */
3148 static enum cpp_ttype last_token;
3150 /* The reserved keyword table. */
3154 ENUM_BITFIELD(rid) rid : 16;
3155 unsigned int disable : 16;
3158 /* Disable mask. Keywords are disabled if (reswords[i].disable & mask) is
3160 #define D_C89 0x01 /* not in C89 */
3161 #define D_EXT 0x02 /* GCC extension */
3162 #define D_EXT89 0x04 /* GCC extension incorporated in C99 */
3163 #define D_OBJC 0x08 /* Objective C only */
3165 static const struct resword reswords[] =
3167 { "_Bool", RID_BOOL, 0 },
3168 { "_Complex", RID_COMPLEX, 0 },
3169 { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
3170 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
3171 { "__alignof", RID_ALIGNOF, 0 },
3172 { "__alignof__", RID_ALIGNOF, 0 },
3173 { "__asm", RID_ASM, 0 },
3174 { "__asm__", RID_ASM, 0 },
3175 { "__attribute", RID_ATTRIBUTE, 0 },
3176 { "__attribute__", RID_ATTRIBUTE, 0 },
3177 { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
3178 { "__builtin_offsetof", RID_OFFSETOF, 0 },
3179 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
3180 { "__builtin_va_arg", RID_VA_ARG, 0 },
3181 { "__complex", RID_COMPLEX, 0 },
3182 { "__complex__", RID_COMPLEX, 0 },
3183 { "__const", RID_CONST, 0 },
3184 { "__const__", RID_CONST, 0 },
3185 { "__extension__", RID_EXTENSION, 0 },
3186 { "__func__", RID_C99_FUNCTION_NAME, 0 },
3187 { "__imag", RID_IMAGPART, 0 },
3188 { "__imag__", RID_IMAGPART, 0 },
3189 { "__inline", RID_INLINE, 0 },
3190 { "__inline__", RID_INLINE, 0 },
3191 { "__label__", RID_LABEL, 0 },
3192 { "__ptrbase", RID_PTRBASE, 0 },
3193 { "__ptrbase__", RID_PTRBASE, 0 },
3194 { "__ptrextent", RID_PTREXTENT, 0 },
3195 { "__ptrextent__", RID_PTREXTENT, 0 },
3196 { "__ptrvalue", RID_PTRVALUE, 0 },
3197 { "__ptrvalue__", RID_PTRVALUE, 0 },
3198 { "__real", RID_REALPART, 0 },
3199 { "__real__", RID_REALPART, 0 },
3200 { "__restrict", RID_RESTRICT, 0 },
3201 { "__restrict__", RID_RESTRICT, 0 },
3202 { "__signed", RID_SIGNED, 0 },
3203 { "__signed__", RID_SIGNED, 0 },
3204 { "__thread", RID_THREAD, 0 },
3205 { "__typeof", RID_TYPEOF, 0 },
3206 { "__typeof__", RID_TYPEOF, 0 },
3207 { "__volatile", RID_VOLATILE, 0 },
3208 { "__volatile__", RID_VOLATILE, 0 },
3209 { "asm", RID_ASM, D_EXT },
3210 { "auto", RID_AUTO, 0 },
3211 { "break", RID_BREAK, 0 },
3212 { "case", RID_CASE, 0 },
3213 { "char", RID_CHAR, 0 },
3214 { "const", RID_CONST, 0 },
3215 { "continue", RID_CONTINUE, 0 },
3216 { "default", RID_DEFAULT, 0 },
3217 { "do", RID_DO, 0 },
3218 { "double", RID_DOUBLE, 0 },
3219 { "else", RID_ELSE, 0 },
3220 { "enum", RID_ENUM, 0 },
3221 { "extern", RID_EXTERN, 0 },
3222 { "float", RID_FLOAT, 0 },
3223 { "for", RID_FOR, 0 },
3224 { "goto", RID_GOTO, 0 },
3225 { "if", RID_IF, 0 },
3226 { "inline", RID_INLINE, D_EXT89 },
3227 { "int", RID_INT, 0 },
3228 { "long", RID_LONG, 0 },
3229 { "register", RID_REGISTER, 0 },
3230 { "restrict", RID_RESTRICT, D_C89 },
3231 { "return", RID_RETURN, 0 },
3232 { "short", RID_SHORT, 0 },
3233 { "signed", RID_SIGNED, 0 },
3234 { "sizeof", RID_SIZEOF, 0 },
3235 { "static", RID_STATIC, 0 },
3236 { "struct", RID_STRUCT, 0 },
3237 { "switch", RID_SWITCH, 0 },
3238 { "typedef", RID_TYPEDEF, 0 },
3239 { "typeof", RID_TYPEOF, D_EXT },
3240 { "union", RID_UNION, 0 },
3241 { "unsigned", RID_UNSIGNED, 0 },
3242 { "void", RID_VOID, 0 },
3243 { "volatile", RID_VOLATILE, 0 },
3244 { "while", RID_WHILE, 0 },
3246 { "id", RID_ID, D_OBJC },
3248 /* These objc keywords are recognized only immediately after
3250 { "class", RID_AT_CLASS, D_OBJC },
3251 { "compatibility_alias", RID_AT_ALIAS, D_OBJC },
3252 { "defs", RID_AT_DEFS, D_OBJC },
3253 { "encode", RID_AT_ENCODE, D_OBJC },
3254 { "end", RID_AT_END, D_OBJC },
3255 { "implementation", RID_AT_IMPLEMENTATION, D_OBJC },
3256 { "interface", RID_AT_INTERFACE, D_OBJC },
3257 { "private", RID_AT_PRIVATE, D_OBJC },
3258 { "protected", RID_AT_PROTECTED, D_OBJC },
3259 { "protocol", RID_AT_PROTOCOL, D_OBJC },
3260 { "public", RID_AT_PUBLIC, D_OBJC },
3261 { "selector", RID_AT_SELECTOR, D_OBJC },
3262 { "throw", RID_AT_THROW, D_OBJC },
3263 { "try", RID_AT_TRY, D_OBJC },
3264 { "catch", RID_AT_CATCH, D_OBJC },
3265 { "finally", RID_AT_FINALLY, D_OBJC },
3266 { "synchronized", RID_AT_SYNCHRONIZED, D_OBJC },
3267 /* These are recognized only in protocol-qualifier context
3269 { "bycopy", RID_BYCOPY, D_OBJC },
3270 { "byref", RID_BYREF, D_OBJC },
3271 { "in", RID_IN, D_OBJC },
3272 { "inout", RID_INOUT, D_OBJC },
3273 { "oneway", RID_ONEWAY, D_OBJC },
3274 { "out", RID_OUT, D_OBJC },
3277 #define N_reswords (sizeof reswords / sizeof (struct resword))
3279 /* Table mapping from RID_* constants to yacc token numbers.
3280 Unfortunately we have to have entries for all the keywords in all
3282 static const short rid_to_yy[RID_MAX] =
3284 /* RID_STATIC */ STATIC,
3285 /* RID_UNSIGNED */ TYPESPEC,
3286 /* RID_LONG */ TYPESPEC,
3287 /* RID_CONST */ TYPE_QUAL,
3288 /* RID_EXTERN */ SCSPEC,
3289 /* RID_REGISTER */ SCSPEC,
3290 /* RID_TYPEDEF */ SCSPEC,
3291 /* RID_SHORT */ TYPESPEC,
3292 /* RID_INLINE */ SCSPEC,
3293 /* RID_VOLATILE */ TYPE_QUAL,
3294 /* RID_SIGNED */ TYPESPEC,
3295 /* RID_AUTO */ SCSPEC,
3296 /* RID_RESTRICT */ TYPE_QUAL,
3299 /* RID_COMPLEX */ TYPESPEC,
3300 /* RID_THREAD */ SCSPEC,
3304 /* RID_VIRTUAL */ 0,
3305 /* RID_EXPLICIT */ 0,
3307 /* RID_MUTABLE */ 0,
3310 /* RID_IN */ TYPE_QUAL,
3311 /* RID_OUT */ TYPE_QUAL,
3312 /* RID_INOUT */ TYPE_QUAL,
3313 /* RID_BYCOPY */ TYPE_QUAL,
3314 /* RID_BYREF */ TYPE_QUAL,
3315 /* RID_ONEWAY */ TYPE_QUAL,
3318 /* RID_INT */ TYPESPEC,
3319 /* RID_CHAR */ TYPESPEC,
3320 /* RID_FLOAT */ TYPESPEC,
3321 /* RID_DOUBLE */ TYPESPEC,
3322 /* RID_VOID */ TYPESPEC,
3323 /* RID_ENUM */ ENUM,
3324 /* RID_STRUCT */ STRUCT,
3325 /* RID_UNION */ UNION,
3327 /* RID_ELSE */ ELSE,
3328 /* RID_WHILE */ WHILE,
3331 /* RID_SWITCH */ SWITCH,
3332 /* RID_CASE */ CASE,
3333 /* RID_DEFAULT */ DEFAULT,
3334 /* RID_BREAK */ BREAK,
3335 /* RID_CONTINUE */ CONTINUE,
3336 /* RID_RETURN */ RETURN,
3337 /* RID_GOTO */ GOTO,
3338 /* RID_SIZEOF */ SIZEOF,
3341 /* RID_ASM */ ASM_KEYWORD,
3342 /* RID_TYPEOF */ TYPEOF,
3343 /* RID_ALIGNOF */ ALIGNOF,
3344 /* RID_ATTRIBUTE */ ATTRIBUTE,
3345 /* RID_VA_ARG */ VA_ARG,
3346 /* RID_EXTENSION */ EXTENSION,
3347 /* RID_IMAGPART */ IMAGPART,
3348 /* RID_REALPART */ REALPART,
3349 /* RID_LABEL */ LABEL,
3350 /* RID_PTRBASE */ PTR_BASE,
3351 /* RID_PTREXTENT */ PTR_EXTENT,
3352 /* RID_PTRVALUE */ PTR_VALUE,
3354 /* RID_CHOOSE_EXPR */ CHOOSE_EXPR,
3355 /* RID_TYPES_COMPATIBLE_P */ TYPES_COMPATIBLE_P,
3357 /* RID_FUNCTION_NAME */ FUNC_NAME,
3358 /* RID_PRETTY_FUNCTION_NAME */ FUNC_NAME,
3359 /* RID_C99_FUNCTION_NAME */ FUNC_NAME,
3362 /* RID_BOOL */ TYPESPEC,
3366 /* RID_PRIVATE */ 0,
3367 /* RID_PROTECTED */ 0,
3368 /* RID_TEMPLATE */ 0,
3373 /* RID_NAMESPACE */ 0,
3375 /* RID_OFFSETOF */ OFFSETOF,
3376 /* RID_OPERATOR */ 0,
3381 /* RID_TYPENAME */ 0,
3386 /* RID_CONSTCAST */ 0,
3387 /* RID_DYNCAST */ 0,
3388 /* RID_REINTCAST */ 0,
3389 /* RID_STATCAST */ 0,
3392 /* RID_ID */ OBJECTNAME,
3393 /* RID_AT_ENCODE */ AT_ENCODE,
3394 /* RID_AT_END */ AT_END,
3395 /* RID_AT_CLASS */ AT_CLASS,
3396 /* RID_AT_ALIAS */ AT_ALIAS,
3397 /* RID_AT_DEFS */ AT_DEFS,
3398 /* RID_AT_PRIVATE */ AT_PRIVATE,
3399 /* RID_AT_PROTECTED */ AT_PROTECTED,
3400 /* RID_AT_PUBLIC */ AT_PUBLIC,
3401 /* RID_AT_PROTOCOL */ AT_PROTOCOL,
3402 /* RID_AT_SELECTOR */ AT_SELECTOR,
3403 /* RID_AT_THROW */ AT_THROW,
3404 /* RID_AT_TRY */ AT_TRY,
3405 /* RID_AT_CATCH */ AT_CATCH,
3406 /* RID_AT_FINALLY */ AT_FINALLY,
3407 /* RID_AT_SYNCHRONIZED */ AT_SYNCHRONIZED,
3408 /* RID_AT_INTERFACE */ AT_INTERFACE,
3409 /* RID_AT_IMPLEMENTATION */ AT_IMPLEMENTATION
3413 init_reswords (void)
3417 int mask = (flag_isoc99 ? 0 : D_C89)
3418 | (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0);
3420 if (!c_dialect_objc ())
3423 ridpointers = ggc_calloc ((int) RID_MAX, sizeof (tree));
3424 for (i = 0; i < N_reswords; i++)
3426 /* If a keyword is disabled, do not enter it into the table
3427 and so create a canonical spelling that isn't a keyword. */
3428 if (reswords[i].disable & mask)
3431 id = get_identifier (reswords[i].word);
3432 C_RID_CODE (id) = reswords[i].rid;
3433 C_IS_RESERVED_WORD (id) = 1;
3434 ridpointers [(int) reswords[i].rid] = id;
3438 #define NAME(type) cpp_type2name (type)
3441 yyerror (const char *msgid)
3443 c_parse_error (msgid, last_token, yylval.ttype);
3452 int objc_force_identifier = objc_need_raw_identifier;
3453 OBJC_NEED_RAW_IDENTIFIER (0);
3456 if (C_IS_RESERVED_WORD (yylval.ttype))
3458 enum rid rid_code = C_RID_CODE (yylval.ttype);
3461 /* Turn non-typedefed refs to "id" into plain identifiers; this
3462 allows constructs like "void foo(id id);" to work. */
3463 if (rid_code == RID_ID)
3465 decl = lookup_name (yylval.ttype);
3466 if (decl == NULL_TREE || TREE_CODE (decl) != TYPE_DECL)
3470 if (!OBJC_IS_AT_KEYWORD (rid_code)
3471 && (!OBJC_IS_PQ_KEYWORD (rid_code) || objc_pq_context))
3474 /* Return the canonical spelling for this keyword. */
3475 yylval.ttype = ridpointers[(int) rid_code];
3476 return rid_to_yy[(int) rid_code];
3480 decl = lookup_name (yylval.ttype);
3483 if (TREE_CODE (decl) == TYPE_DECL)
3489 tree objc_interface_decl = is_class_name (yylval.ttype);
3490 /* ObjC class names are in the same namespace as variables and
3491 typedefs, and hence are shadowed by local declarations. */
3492 if (objc_interface_decl
3493 && (global_bindings_p ()
3494 || (!objc_force_identifier && !decl)))
3496 yylval.ttype = objc_interface_decl;
3509 last_token = c_lex (&yylval.ttype);
3512 case CPP_EQ: return '=';
3513 case CPP_NOT: return '!';
3514 case CPP_GREATER: yylval.code = GT_EXPR; return ARITHCOMPARE;
3515 case CPP_LESS: yylval.code = LT_EXPR; return ARITHCOMPARE;
3516 case CPP_PLUS: yylval.code = PLUS_EXPR; return '+';
3517 case CPP_MINUS: yylval.code = MINUS_EXPR; return '-';
3518 case CPP_MULT: yylval.code = MULT_EXPR; return '*';
3519 case CPP_DIV: yylval.code = TRUNC_DIV_EXPR; return '/';
3520 case CPP_MOD: yylval.code = TRUNC_MOD_EXPR; return '%';
3521 case CPP_AND: yylval.code = BIT_AND_EXPR; return '&';
3522 case CPP_OR: yylval.code = BIT_IOR_EXPR; return '|';
3523 case CPP_XOR: yylval.code = BIT_XOR_EXPR; return '^';
3524 case CPP_RSHIFT: yylval.code = RSHIFT_EXPR; return RSHIFT;
3525 case CPP_LSHIFT: yylval.code = LSHIFT_EXPR; return LSHIFT;
3527 case CPP_COMPL: return '~';
3528 case CPP_AND_AND: return ANDAND;
3529 case CPP_OR_OR: return OROR;
3530 case CPP_QUERY: return '?';
3531 case CPP_OPEN_PAREN: return '(';
3532 case CPP_EQ_EQ: yylval.code = EQ_EXPR; return EQCOMPARE;
3533 case CPP_NOT_EQ: yylval.code = NE_EXPR; return EQCOMPARE;
3534 case CPP_GREATER_EQ:yylval.code = GE_EXPR; return ARITHCOMPARE;
3535 case CPP_LESS_EQ: yylval.code = LE_EXPR; return ARITHCOMPARE;
3537 case CPP_PLUS_EQ: yylval.code = PLUS_EXPR; return ASSIGN;
3538 case CPP_MINUS_EQ: yylval.code = MINUS_EXPR; return ASSIGN;
3539 case CPP_MULT_EQ: yylval.code = MULT_EXPR; return ASSIGN;
3540 case CPP_DIV_EQ: yylval.code = TRUNC_DIV_EXPR; return ASSIGN;
3541 case CPP_MOD_EQ: yylval.code = TRUNC_MOD_EXPR; return ASSIGN;
3542 case CPP_AND_EQ: yylval.code = BIT_AND_EXPR; return ASSIGN;
3543 case CPP_OR_EQ: yylval.code = BIT_IOR_EXPR; return ASSIGN;
3544 case CPP_XOR_EQ: yylval.code = BIT_XOR_EXPR; return ASSIGN;
3545 case CPP_RSHIFT_EQ: yylval.code = RSHIFT_EXPR; return ASSIGN;
3546 case CPP_LSHIFT_EQ: yylval.code = LSHIFT_EXPR; return ASSIGN;
3548 case CPP_OPEN_SQUARE: return '[';
3549 case CPP_CLOSE_SQUARE: return ']';
3550 case CPP_OPEN_BRACE: return '{';
3551 case CPP_CLOSE_BRACE: return '}';
3552 case CPP_ELLIPSIS: return ELLIPSIS;
3554 case CPP_PLUS_PLUS: return PLUSPLUS;
3555 case CPP_MINUS_MINUS: return MINUSMINUS;
3556 case CPP_DEREF: return POINTSAT;
3557 case CPP_DOT: return '.';
3559 /* The following tokens may affect the interpretation of any
3560 identifiers following, if doing Objective-C. */
3561 case CPP_COLON: OBJC_NEED_RAW_IDENTIFIER (0); return ':';
3562 case CPP_COMMA: OBJC_NEED_RAW_IDENTIFIER (0); return ',';
3563 case CPP_CLOSE_PAREN: OBJC_NEED_RAW_IDENTIFIER (0); return ')';
3564 case CPP_SEMICOLON: OBJC_NEED_RAW_IDENTIFIER (0); return ';';
3570 return yylexname ();
3573 /* This only happens in Objective-C; it must be a keyword. */
3574 return rid_to_yy [(int) C_RID_CODE (yylval.ttype)];
3585 case CPP_OBJC_STRING:
3588 /* These tokens are C++ specific (and will not be generated
3589 in C mode, but let's be cautious). */
3591 case CPP_DEREF_STAR:
3597 /* These tokens should not survive translation phase 4. */
3600 error ("syntax error at '%s' token", NAME(last_token));
3613 timevar_push (TV_LEX);
3615 timevar_pop (TV_LEX);
3619 /* Function used when yydebug is set, to print a token in more detail. */
3622 yyprint (FILE *file, int yychar, YYSTYPE yyl)
3626 fprintf (file, " [%s]", NAME(last_token));
3637 if (IDENTIFIER_POINTER (t))
3638 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
3642 fprintf (file, " %s", GET_MODE_NAME (TYPE_MODE (TREE_TYPE (t))));
3643 if (TREE_CODE (t) == INTEGER_CST)
3646 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
3647 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
3653 /* This is not the ideal place to put this, but we have to get it out
3654 of c-lex.c because cp/lex.c has its own version. */
3656 /* Parse the file. */
3664 free (malloced_yyss);
3665 free (malloced_yyvs);
3670 #include "gt-c-parse.h"