]> gcc.gnu.org Git - gcc.git/blob - gcc/c-parse.in
c-common.c (verify_sequence_points): Export.
[gcc.git] / gcc / c-parse.in
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.
4
5 This file is part of GCC.
6
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
10 version.
11
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
15 for more details.
16
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
20 02111-1307, USA. */
21
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. */
27
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. */
30
31 @@ifc
32 %expect 10 /* shift/reduce conflicts, and no reduce/reduce conflicts. */
33 @@end_ifc
34
35 %{
36 #include "config.h"
37 #include "system.h"
38 #include "coretypes.h"
39 #include "tm.h"
40 #include "tree.h"
41 #include "langhooks.h"
42 #include "input.h"
43 #include "cpplib.h"
44 #include "intl.h"
45 #include "timevar.h"
46 #include "c-pragma.h" /* For YYDEBUG definition, and parse_in. */
47 #include "c-tree.h"
48 #include "flags.h"
49 #include "varray.h"
50 #include "output.h"
51 #include "toplev.h"
52 #include "ggc.h"
53
54 @@ifobjc
55 #include "objc-act.h"
56 @@end_ifobjc
57
58 /* Like YYERROR but do call yyerror. */
59 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
60
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.
63
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. */
67
68 static short *malloced_yyss;
69 static void *malloced_yyvs;
70
71 #define yyoverflow(MSG, SS, SSSIZE, VS, VSSIZE, YYSSZ) \
72 do { \
73 size_t newsize; \
74 short *newss; \
75 YYSTYPE *newvs; \
76 newsize = *(YYSSZ) *= 2; \
77 if (malloced_yyss) \
78 { \
79 newss = really_call_realloc (*(SS), newsize * sizeof (short)); \
80 newvs = really_call_realloc (*(VS), newsize * sizeof (YYSTYPE)); \
81 } \
82 else \
83 { \
84 newss = really_call_malloc (newsize * sizeof (short)); \
85 newvs = really_call_malloc (newsize * sizeof (YYSTYPE)); \
86 if (newss) \
87 memcpy (newss, *(SS), (SSSIZE)); \
88 if (newvs) \
89 memcpy (newvs, *(VS), (VSSIZE)); \
90 } \
91 if (!newss || !newvs) \
92 { \
93 yyerror (MSG); \
94 return 2; \
95 } \
96 *(SS) = newss; \
97 *(VS) = newvs; \
98 malloced_yyss = newss; \
99 malloced_yyvs = (void *) newvs; \
100 } while (0)
101 %}
102
103 %start program
104
105 %union {long itype; tree ttype; enum tree_code code;
106 location_t location; }
107
108 /* All identifiers that are not reserved words
109 and are not declared typedefs in the current block */
110 %token IDENTIFIER
111
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. */
115 %token TYPENAME
116
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. */
121
122 /* Reserved words that specify type.
123 yylval contains an IDENTIFIER_NODE which indicates which one. */
124 %token TYPESPEC
125
126 /* Reserved words that qualify type: "const", "volatile", or "restrict".
127 yylval contains an IDENTIFIER_NODE which indicates which one. */
128 %token TYPE_QUAL
129
130 /* Character or numeric constants.
131 yylval is the node for the constant. */
132 %token CONSTANT
133
134 /* String constants in raw form.
135 yylval is a STRING_CST node. */
136
137 %token STRING
138
139 /* "...", used for functions with variable arglists. */
140 %token ELLIPSIS
141
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
150
151 /* Add precedence rules to solve dangling else s/r conflict */
152 %nonassoc IF
153 %nonassoc ELSE
154
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. */
158
159 %right <code> ASSIGN '='
160 %right <code> '?' ':'
161 %left <code> OROR
162 %left <code> ANDAND
163 %left <code> '|'
164 %left <code> '^'
165 %left <code> '&'
166 %left <code> EQCOMPARE
167 %left <code> ARITHCOMPARE
168 %left <code> LSHIFT RSHIFT
169 %left <code> '+' '-'
170 %left <code> '*' '/' '%'
171 %right <code> UNARY PLUSPLUS MINUSMINUS
172 %left HYPERUNARY
173 %left <code> POINTSAT '.' '(' '['
174
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
181 %token OBJC_STRING
182
183 %type <code> unop
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
186
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
204
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
211
212 %type <ttype> compstmt compstmt_start compstmt_primary_start
213 %type <ttype> do_stmt_start stmt label
214
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
221
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
231
232 %type <ttype> parmlist parmlist_1 parmlist_2
233 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
234 %type <ttype> identifiers_or_typenames
235
236 %type <itype> setspecs setspecs_fp extension
237
238 %type <location> save_location
239 \f
240 @@ifobjc
241 /* the Objective-C nonterminals */
242
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
250
251 %type <ttype> CLASSNAME OBJECTNAME OBJC_STRING
252
253 %type <ttype> superclass
254 @@end_ifobjc
255 \f
256 %{
257 /* Number of statements (loosely speaking) and compound statements
258 seen so far. */
259 static int stmt_count;
260 static int compstmt_count;
261
262 /* List of types and structure classes of the current declaration. */
263 static GTY(()) tree current_declspecs;
264 static GTY(()) tree prefix_attributes;
265
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;
270
271 /* Stack of saved values of current_declspecs, prefix_attributes and
272 all_prefix_attributes. */
273 static GTY(()) tree declspec_stack;
274
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 \
278 do { \
279 declspec_stack = tree_cons (build_tree_list (prefix_attributes, \
280 all_prefix_attributes), \
281 current_declspecs, \
282 declspec_stack); \
283 } while (0)
284
285 #define POP_DECLSPEC_STACK \
286 do { \
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); \
291 } while (0)
292
293 /* For __extension__, save/restore the warning flags which are
294 controlled by __extension__. */
295 #define SAVE_EXT_FLAGS() \
296 (pedantic \
297 | (warn_pointer_arith << 1) \
298 | (warn_traditional << 2) \
299 | (flag_iso << 3))
300
301 #define RESTORE_EXT_FLAGS(val) \
302 do { \
303 pedantic = val & 1; \
304 warn_pointer_arith = (val >> 1) & 1; \
305 warn_traditional = (val >> 2) & 1; \
306 flag_iso = (val >> 3) & 1; \
307 } while (0)
308
309 @@ifobjc
310 /* Objective-C specific parser/lexer information */
311
312 static enum tree_code objc_inherit_code;
313 static int objc_pq_context = 0, objc_public_flag = 0;
314
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
318 exists. */
319 static int objc_need_raw_identifier;
320 #define OBJC_NEED_RAW_IDENTIFIER(VAL) objc_need_raw_identifier = VAL
321 @@end_ifobjc
322
323 @@ifc
324 #define OBJC_NEED_RAW_IDENTIFIER(VAL) /* nothing */
325 @@end_ifc
326
327 /* Tell yyparse how to print a token's value, if yydebug is set. */
328
329 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
330
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);
337
338 /* Initialisation routine for this file. */
339 void
340 c_parse_init (void)
341 {
342 init_reswords ();
343 }
344
345 %}
346 \f
347 %%
348 program: /* empty */
349 { if (pedantic)
350 pedwarn ("ISO C forbids an empty source file");
351 }
352 | extdefs
353 ;
354
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. */
358
359 extdefs:
360 {$<ttype>$ = NULL_TREE; } extdef
361 | extdefs {$<ttype>$ = NULL_TREE; ggc_collect(); } extdef
362 ;
363
364 extdef:
365 fndef
366 | datadef
367 | asmdef
368 | extension extdef
369 { RESTORE_EXT_FLAGS ($1); }
370 @@ifobjc
371 | objcdef
372 @@end_ifobjc
373 ;
374
375 datadef:
376 setspecs notype_initdecls ';'
377 { if (pedantic)
378 error ("ISO C forbids data definition with no type or storage class");
379 else
380 warning ("data definition has no type or storage class");
381
382 POP_DECLSPEC_STACK; }
383 | declspecs_nots setspecs notype_initdecls ';'
384 { POP_DECLSPEC_STACK; }
385 | declspecs_ts setspecs initdecls ';'
386 { POP_DECLSPEC_STACK; }
387 | declspecs ';'
388 { shadow_tag ($1); }
389 | error ';'
390 | error '}'
391 | ';'
392 { if (pedantic)
393 pedwarn ("ISO C does not allow extra `;' outside of a function"); }
394 ;
395 \f
396 fndef:
397 declspecs_ts setspecs declarator
398 { if (! start_function (current_declspecs, $3,
399 all_prefix_attributes))
400 YYERROR1;
401 }
402 old_style_parm_decls save_location
403 { DECL_SOURCE_LOCATION (current_function_decl) = $6;
404 store_parm_decls (); }
405 compstmt_or_error
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))
413 YYERROR1;
414 }
415 old_style_parm_decls save_location
416 { DECL_SOURCE_LOCATION (current_function_decl) = $6;
417 store_parm_decls (); }
418 compstmt_or_error
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))
426 YYERROR1;
427 }
428 old_style_parm_decls save_location
429 { DECL_SOURCE_LOCATION (current_function_decl) = $5;
430 store_parm_decls (); }
431 compstmt_or_error
432 { finish_function ();
433 POP_DECLSPEC_STACK; }
434 | setspecs notype_declarator error
435 { POP_DECLSPEC_STACK; }
436 ;
437
438 identifier:
439 IDENTIFIER
440 | TYPENAME
441 @@ifobjc
442 | OBJECTNAME
443 | CLASSNAME
444 @@end_ifobjc
445 ;
446
447 unop: '&'
448 { $$ = ADDR_EXPR; }
449 | '-'
450 { $$ = NEGATE_EXPR; }
451 | '+'
452 { $$ = CONVERT_EXPR;
453 @@ifc
454 if (warn_traditional && !in_system_header)
455 warning ("traditional C rejects the unary plus operator");
456 @@end_ifc
457 }
458 | PLUSPLUS
459 { $$ = PREINCREMENT_EXPR; }
460 | MINUSMINUS
461 { $$ = PREDECREMENT_EXPR; }
462 | '~'
463 { $$ = BIT_NOT_EXPR; }
464 | '!'
465 { $$ = TRUTH_NOT_EXPR; }
466 ;
467
468 expr: nonnull_exprlist
469 { $$ = build_compound_expr ($1); }
470 ;
471
472 exprlist:
473 /* empty */
474 { $$ = NULL_TREE; }
475 | nonnull_exprlist
476 ;
477
478 nonnull_exprlist:
479 expr_no_commas
480 { $$ = build_tree_list (NULL_TREE, $1); }
481 | nonnull_exprlist ',' expr_no_commas
482 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
483 ;
484
485 unary_expr:
486 primary
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
491 { $$ = $2;
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. */
497 | ANDAND identifier
498 { $$ = finish_label_address_expr ($2); }
499 | sizeof unary_expr %prec UNARY
500 { skip_evaluation--;
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
506 { skip_evaluation--;
507 $$ = c_sizeof (groktypename ($3)); }
508 | alignof unary_expr %prec UNARY
509 { skip_evaluation--;
510 $$ = c_alignof_expr ($2); }
511 | alignof '(' typename ')' %prec HYPERUNARY
512 { skip_evaluation--;
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); }
518 ;
519
520 sizeof:
521 SIZEOF { skip_evaluation++; }
522 ;
523
524 alignof:
525 ALIGNOF { skip_evaluation++; }
526 ;
527
528 typeof:
529 TYPEOF { skip_evaluation++; }
530 ;
531
532 cast_expr:
533 unary_expr
534 | '(' typename ')' cast_expr %prec UNARY
535 { $$ = c_cast_expr ($2, $4); }
536 ;
537
538 expr_no_commas:
539 cast_expr
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; }
568 expr_no_commas
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; }
575 expr_no_commas
576 { skip_evaluation -= $1 == truthvalue_true_node;
577 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
578 | expr_no_commas '?'
579 { $1 = lang_hooks.truthvalue_conversion
580 (default_conversion ($1));
581 skip_evaluation += $1 == truthvalue_false_node; }
582 expr ':'
583 { skip_evaluation += (($1 == truthvalue_true_node)
584 - ($1 == truthvalue_false_node)); }
585 expr_no_commas
586 { skip_evaluation -= $1 == truthvalue_true_node;
587 $$ = build_conditional_expr ($1, $4, $7); }
588 | expr_no_commas '?'
589 { if (pedantic)
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; }
595 ':' expr_no_commas
596 { skip_evaluation -= $1 == truthvalue_true_node;
597 $$ = build_conditional_expr ($1, $<ttype>2, $5); }
598 | expr_no_commas '=' expr_no_commas
599 { char class;
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);
604 }
605 | expr_no_commas ASSIGN expr_no_commas
606 { char class;
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);
613 }
614 ;
615
616 primary:
617 IDENTIFIER
618 {
619 if (yychar == YYEMPTY)
620 yychar = YYLEX;
621 $$ = build_external_ref ($1, yychar == '(');
622 }
623 | CONSTANT
624 | STRING
625 | FUNC_NAME
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);
633 tree type = $2;
634 finish_init ();
635
636 if (pedantic && ! flag_isoc99)
637 pedwarn ("ISO C90 forbids compound literals");
638 $$ = build_compound_literal (type, constructor);
639 }
640 | '(' expr ')'
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);
644 $$ = $2; }
645 | '(' error ')'
646 { $$ = error_mark_node; }
647 | compstmt_primary_start compstmt_nostart ')'
648 { if (pedantic)
649 pedwarn ("ISO C forbids braced-groups within expressions");
650 $$ = c_finish_stmt_expr ($1);
651 }
652 | compstmt_primary_start error ')'
653 { c_finish_stmt_expr ($1);
654 $$ = error_mark_node;
655 }
656 | primary '(' exprlist ')' %prec '.'
657 { $$ = build_function_call ($1, $3); }
658 | VA_ARG '(' expr_no_commas ',' typename ')'
659 { $$ = build_va_arg ($3, groktypename ($5)); }
660
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 ','
666 expr_no_commas ')'
667 {
668 tree c;
669
670 c = fold ($3);
671 STRIP_NOPS (c);
672 if (TREE_CODE (c) != INTEGER_CST)
673 error ("first argument to __builtin_choose_expr not"
674 " a constant");
675 $$ = integer_zerop (c) ? $7 : $5;
676 }
677 | CHOOSE_EXPR '(' error ')'
678 { $$ = error_mark_node; }
679 | TYPES_COMPATIBLE_P '(' typename ',' typename ')'
680 {
681 tree e1, e2;
682
683 e1 = TYPE_MAIN_VARIANT (groktypename ($3));
684 e2 = TYPE_MAIN_VARIANT (groktypename ($5));
685
686 $$ = comptypes (e1, e2)
687 ? build_int_2 (1, 0) : build_int_2 (0, 0);
688 }
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
696 {
697 tree expr = build_indirect_ref ($1, "->");
698 $$ = build_component_ref (expr, $3);
699 }
700 | primary PLUSPLUS
701 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
702 | primary MINUSMINUS
703 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
704 @@ifobjc
705 | objcmessageexpr
706 { $$ = build_message_expr ($1); }
707 | objcselectorexpr
708 { $$ = build_selector_expr ($1); }
709 | objcprotocolexpr
710 { $$ = build_protocol_expr ($1); }
711 | objcencodeexpr
712 { $$ = build_encode_expr ($1); }
713 | OBJC_STRING
714 { $$ = build_objc_string_object ($1); }
715 @@end_ifobjc
716 ;
717
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. */
723
724 offsetof_member_designator:
725 identifier
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); }
731 ;
732
733 old_style_parm_decls:
734 /* empty */
735 | datadecls
736 ;
737
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. */
741 lineno_datadecl:
742 save_location datadecl
743 { }
744 ;
745
746 datadecls:
747 lineno_datadecl
748 | errstmt
749 | datadecls lineno_datadecl
750 | lineno_datadecl errstmt
751 ;
752
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
756 style parm. */
757 datadecl:
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"); }
767 ;
768
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. */
773 lineno_decl:
774 save_location decl
775 { }
776 ;
777
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 ();
784 PUSH_DECLSPEC_STACK;
785 split_specs_attrs ($<ttype>0,
786 &current_declspecs, &prefix_attributes);
787 all_prefix_attributes = prefix_attributes; }
788 ;
789
790 /* Possibly attributes after a comma, which should reset all_prefix_attributes
791 to prefix_attributes with these ones chained on the front. */
792 maybe_resetattrs:
793 maybe_attribute
794 { all_prefix_attributes = chainon ($1, prefix_attributes); }
795 ;
796
797 decl:
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; }
806 | declspecs ';'
807 { shadow_tag ($1); }
808 | extension decl
809 { RESTORE_EXT_FLAGS ($1); }
810 ;
811
812 /* A list of declaration specifiers. These are:
813
814 - Storage class specifiers (scspec), which for GCC currently includes
815 function specifiers ("inline").
816
817 - Type specifiers (typespec_*).
818
819 - Type qualifiers (TYPE_QUAL).
820
821 - Attribute specifier lists (attributes).
822
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.)
832
833 The various cases below are classified according to:
834
835 (a) Whether a storage class specifier is included or not; some
836 places in the grammar disallow storage class specifiers (_sc or _nosc).
837
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).
840
841 (c) Whether the list starts with an attribute; in certain places,
842 the grammar requires specifiers that don't start with an attribute
843 (_sa or _nosa).
844
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
848 (_ea or _noea).
849
850 TODO:
851
852 (i) Distinguish between function specifiers and storage class specifiers,
853 at least for the purpose of warnings about obsolescent usage.
854
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. */
858
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. */
863
864 declspecs_nosc_nots_nosa_noea:
865 TYPE_QUAL
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; }
874 ;
875
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); }
880 ;
881
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; }
889 ;
890
891 declspecs_nosc_nots_sa_ea:
892 attributes
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); }
898 ;
899
900 declspecs_nosc_ts_nosa_noea:
901 typespec_nonattr
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; }
922 ;
923
924 declspecs_nosc_ts_nosa_ea:
925 typespec_attr
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; }
943 ;
944
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; }
964 ;
965
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; }
982 ;
983
984 declspecs_sc_nots_nosa_noea:
985 scspec
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); }
1018 ;
1019
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); }
1024 ;
1025
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); }
1057 ;
1058
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); }
1063 ;
1064
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); }
1108 ;
1109
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; }
1126 ;
1127
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); }
1171 ;
1172
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; }
1189 ;
1190
1191 /* Particular useful classes of declspecs. */
1192 declspecs_ts:
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
1201 ;
1202
1203 declspecs_nots:
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
1212 ;
1213
1214 declspecs_ts_nosa:
1215 declspecs_nosc_ts_nosa_noea
1216 | declspecs_nosc_ts_nosa_ea
1217 | declspecs_sc_ts_nosa_noea
1218 | declspecs_sc_ts_nosa_ea
1219 ;
1220
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
1226 ;
1227
1228 declspecs_nosc_ts:
1229 declspecs_nosc_ts_nosa_noea
1230 | declspecs_nosc_ts_nosa_ea
1231 | declspecs_nosc_ts_sa_noea
1232 | declspecs_nosc_ts_sa_ea
1233 ;
1234
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
1240 ;
1241
1242 declspecs_nosc:
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
1251 ;
1252
1253 declspecs:
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
1270 ;
1271
1272 /* A (possibly empty) sequence of type qualifiers and attributes. */
1273 maybe_type_quals_attrs:
1274 /* empty */
1275 { $$ = NULL_TREE; }
1276 | declspecs_nosc_nots
1277 { $$ = $1; }
1278 ;
1279
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.
1283
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)
1287 being redeclared.
1288
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
1293 _reserved.
1294
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.
1298
1299 _nonattr: specifiers. */
1300
1301 typespec_nonattr:
1302 typespec_reserved_nonattr
1303 | typespec_nonreserved_nonattr
1304 ;
1305
1306 typespec_attr:
1307 typespec_reserved_attr
1308 ;
1309
1310 typespec_reserved_nonattr:
1311 TYPESPEC
1312 { OBJC_NEED_RAW_IDENTIFIER (1); }
1313 | structsp_nonattr
1314 ;
1315
1316 typespec_reserved_attr:
1317 structsp_attr
1318 ;
1319
1320 typespec_nonreserved_nonattr:
1321 TYPENAME
1322 { /* For a typedef name, record the meaning, not the name.
1323 In case of `foo foo, bar;'. */
1324 $$ = lookup_name ($1); }
1325 @@ifobjc
1326 | CLASSNAME protocolrefs
1327 { $$ = get_static_reference ($1, $2); }
1328 | OBJECTNAME protocolrefs
1329 { $$ = get_protocol_reference ($2); }
1330
1331 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>"
1332 - nisse@lysator.liu.se */
1333 | non_empty_protocolrefs
1334 { $$ = get_protocol_reference ($1); }
1335 @@end_ifobjc
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); }
1344 ;
1345
1346 /* typespec_nonreserved_attr does not exist. */
1347
1348 initdecls:
1349 initdcl
1350 | initdecls ',' maybe_resetattrs initdcl
1351 ;
1352
1353 notype_initdecls:
1354 notype_initdcl
1355 | notype_initdecls ',' maybe_resetattrs notype_initdcl
1356 ;
1357
1358 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 ()); }
1363 init
1364 /* Note how the declaration of the variable is in effect while its init is parsed! */
1365 { finish_init ();
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);
1371 }
1372 ;
1373
1374 notype_initdcl:
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 ()); }
1379 init
1380 /* Note how the declaration of the variable is in effect while its init is parsed! */
1381 { finish_init ();
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); }
1387 ;
1388 /* the * rules are dummies to accept the Apollo extended syntax
1389 so that the header files compile. */
1390 maybe_attribute:
1391 /* empty */
1392 { $$ = NULL_TREE; }
1393 | attributes
1394 { $$ = $1; }
1395 ;
1396
1397 attributes:
1398 attribute
1399 { $$ = $1; }
1400 | attributes attribute
1401 { $$ = chainon ($1, $2); }
1402 ;
1403
1404 attribute:
1405 ATTRIBUTE stop_string_translation
1406 '(' '(' attribute_list ')' ')' start_string_translation
1407 { $$ = $5; }
1408 | ATTRIBUTE error start_string_translation
1409 {}
1410 ;
1411
1412 attribute_list:
1413 attrib
1414 { $$ = $1; }
1415 | attribute_list ',' attrib
1416 { $$ = chainon ($1, $3); }
1417 ;
1418
1419 attrib:
1420 /* empty */
1421 { $$ = NULL_TREE; }
1422 | any_word
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); }
1430 ;
1431
1432 /* This still leaves out most reserved keywords,
1433 shouldn't we include them? */
1434
1435 any_word:
1436 identifier
1437 | scspec
1438 | TYPESPEC
1439 | TYPE_QUAL
1440 ;
1441
1442 scspec:
1443 STATIC
1444 | SCSPEC
1445 ;
1446 \f
1447 /* Initializers. `init' is the entry point. */
1448
1449 init:
1450 expr_no_commas
1451 | '{'
1452 { really_start_incremental_init (NULL_TREE); }
1453 initlist_maybe_comma '}'
1454 { $$ = pop_init_level (0); }
1455 | error
1456 { $$ = error_mark_node; }
1457 ;
1458
1459 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1460 initlist_maybe_comma:
1461 /* empty */
1462 { if (pedantic)
1463 pedwarn ("ISO C forbids empty initializer braces"); }
1464 | initlist1 maybecomma
1465 ;
1466
1467 initlist1:
1468 initelt
1469 | initlist1 ',' initelt
1470 ;
1471
1472 /* `initelt' is a single element of an initializer.
1473 It may use braces. */
1474 initelt:
1475 designator_list '=' initval
1476 { if (pedantic && ! flag_isoc99)
1477 pedwarn ("ISO C90 forbids specifying subobject to initialize"); }
1478 | designator initval
1479 { if (pedantic)
1480 pedwarn ("obsolete use of designated initializer without `='"); }
1481 | identifier ':'
1482 { set_init_label ($1);
1483 if (pedantic)
1484 pedwarn ("obsolete use of designated initializer with `:'"); }
1485 initval
1486 {}
1487 | initval
1488 ;
1489
1490 initval:
1491 '{'
1492 { push_init_level (0); }
1493 initlist_maybe_comma '}'
1494 { process_init_element (pop_init_level (0)); }
1495 | expr_no_commas
1496 { process_init_element ($1); }
1497 | error
1498 ;
1499
1500 designator_list:
1501 designator
1502 | designator_list designator
1503 ;
1504
1505 designator:
1506 '.' identifier
1507 { set_init_label ($2); }
1508 | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
1509 { set_init_index ($2, $4);
1510 if (pedantic)
1511 pedwarn ("ISO C forbids specifying range of elements to initialize"); }
1512 | '[' expr_no_commas ']'
1513 { set_init_index ($2, NULL_TREE); }
1514 ;
1515 \f
1516 nested_function:
1517 declarator
1518 { if (pedantic)
1519 pedwarn ("ISO C forbids nested functions");
1520
1521 push_function_context ();
1522 if (! start_function (current_declspecs, $1,
1523 all_prefix_attributes))
1524 {
1525 pop_function_context ();
1526 YYERROR1;
1527 }
1528 }
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. */
1538 compstmt
1539 { tree decl = current_function_decl;
1540 add_stmt ($6);
1541 finish_function ();
1542 pop_function_context ();
1543 add_stmt (build_stmt (DECL_STMT, decl)); }
1544 ;
1545
1546 notype_nested_function:
1547 notype_declarator
1548 { if (pedantic)
1549 pedwarn ("ISO C forbids nested functions");
1550
1551 push_function_context ();
1552 if (! start_function (current_declspecs, $1,
1553 all_prefix_attributes))
1554 {
1555 pop_function_context ();
1556 YYERROR1;
1557 }
1558 }
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. */
1568 compstmt
1569 { tree decl = current_function_decl;
1570 add_stmt ($6);
1571 finish_function ();
1572 pop_function_context ();
1573 add_stmt (build_stmt (DECL_STMT, decl)); }
1574 ;
1575
1576 /* Any kind of declarator (thus, all declarators allowed
1577 after an explicit typespec). */
1578
1579 declarator:
1580 after_type_declarator
1581 | notype_declarator
1582 ;
1583
1584 /* A declarator that is allowed only after an explicit typespec. */
1585
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); }
1595 | TYPENAME
1596 @@ifobjc
1597 | OBJECTNAME
1598 @@end_ifobjc
1599 ;
1600
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). */
1605 parm_declarator:
1606 parm_declarator_starttypename
1607 | parm_declarator_nostarttypename
1608 ;
1609
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); }
1615 | TYPENAME
1616 @@ifobjc
1617 | OBJECTNAME
1618 @@end_ifobjc
1619 ;
1620
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; }
1632 ;
1633
1634 /* A declarator allowed whether or not there has been
1635 an explicit typespec. These cannot redeclare a typedef-name. */
1636
1637 notype_declarator:
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); }
1646 | IDENTIFIER
1647 ;
1648
1649 struct_head:
1650 STRUCT
1651 { $$ = NULL_TREE; }
1652 | STRUCT attributes
1653 { $$ = $2; }
1654 ;
1655
1656 union_head:
1657 UNION
1658 { $$ = NULL_TREE; }
1659 | UNION attributes
1660 { $$ = $2; }
1661 ;
1662
1663 enum_head:
1664 ENUM
1665 { $$ = NULL_TREE; }
1666 | ENUM attributes
1667 { $$ = $2; }
1668 ;
1669
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.
1673
1674 structsp_nonattr: other struct/union/enum specifiers. */
1675
1676 structsp_attr:
1677 struct_head identifier '{'
1678 { $$ = start_struct (RECORD_TYPE, $2);
1679 /* Start scope of tag before parsing components. */
1680 }
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));
1687 }
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));
1696 }
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)); }
1702 | enum_head '{'
1703 { $$ = start_enum (NULL_TREE); }
1704 enumlist maybecomma_warn '}' maybe_attribute
1705 { $$ = finish_enum ($<ttype>3, nreverse ($4),
1706 chainon ($1, $7)); }
1707 ;
1708
1709 structsp_nonattr:
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"); }
1720 ;
1721
1722 maybecomma:
1723 /* empty */
1724 | ','
1725 ;
1726
1727 maybecomma_warn:
1728 /* empty */
1729 | ','
1730 { if (pedantic && ! flag_isoc99)
1731 pedwarn ("comma at end of enumerator list"); }
1732 ;
1733
1734 /* We chain the components in reverse order. They are put in forward
1735 order in structsp_attr.
1736
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.
1741
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. */
1745
1746 component_decl_list:
1747 component_decl_list2
1748 { $$ = $1; }
1749 | component_decl_list2 component_decl
1750 { $$ = chainon ($2, $1);
1751 pedwarn ("no semicolon at end of struct or union"); }
1752 ;
1753
1754 component_decl_list2: /* empty */
1755 { $$ = NULL_TREE; }
1756 | component_decl_list2 component_decl ';'
1757 { $$ = chainon ($2, $1); }
1758 | component_decl_list2 ';'
1759 { if (pedantic)
1760 pedwarn ("extra semicolon in struct or union specified"); }
1761 @@ifobjc
1762 /* foo(sizeof(struct{ @defs(ClassName)})); */
1763 | AT_DEFS '(' CLASSNAME ')'
1764 { $$ = nreverse (get_class_ivars_from_name ($3)); }
1765 @@end_ifobjc
1766 ;
1767
1768 component_decl:
1769 declspecs_nosc_ts setspecs components
1770 { $$ = $3;
1771 POP_DECLSPEC_STACK; }
1772 | declspecs_nosc_ts setspecs
1773 {
1774 /* Support for unnamed structs or unions as members of
1775 structs or unions (which is [a] useful and [b] supports
1776 MS P-SDK). */
1777 if (pedantic)
1778 pedwarn ("ISO C doesn't support unnamed structs/unions");
1779
1780 $$ = grokfield(NULL, current_declspecs, NULL_TREE);
1781 POP_DECLSPEC_STACK; }
1782 | declspecs_nosc_nots setspecs components_notype
1783 { $$ = $3;
1784 POP_DECLSPEC_STACK; }
1785 | declspecs_nosc_nots
1786 { if (pedantic)
1787 pedwarn ("ISO C forbids member declarations with no members");
1788 shadow_tag_warned ($1, pedantic);
1789 $$ = NULL_TREE; }
1790 | error
1791 { $$ = NULL_TREE; }
1792 | extension component_decl
1793 { $$ = $2;
1794 RESTORE_EXT_FLAGS ($1); }
1795 ;
1796
1797 components:
1798 component_declarator
1799 | components ',' maybe_resetattrs component_declarator
1800 { TREE_CHAIN ($4) = $1; $$ = $4; }
1801 ;
1802
1803 components_notype:
1804 component_notype_declarator
1805 | components_notype ',' maybe_resetattrs component_notype_declarator
1806 { TREE_CHAIN ($4) = $1; $$ = $4; }
1807 ;
1808
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); }
1822 ;
1823
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); }
1837 ;
1838
1839 /* We chain the enumerators in reverse order.
1840 They are put in forward order in structsp_attr. */
1841
1842 enumlist:
1843 enumerator
1844 | enumlist ',' enumerator
1845 { if ($1 == error_mark_node)
1846 $$ = $1;
1847 else
1848 TREE_CHAIN ($3) = $1, $$ = $3; }
1849 | error
1850 { $$ = error_mark_node; }
1851 ;
1852
1853
1854 enumerator:
1855 identifier
1856 { $$ = build_enumerator ($1, NULL_TREE); }
1857 | identifier '=' expr_no_commas
1858 { $$ = build_enumerator ($1, $3); }
1859 ;
1860
1861 typename:
1862 declspecs_nosc
1863 { pending_xref_error ();
1864 $<ttype>$ = $1; }
1865 absdcl
1866 { $$ = build_tree_list ($<ttype>2, $3); }
1867 ;
1868
1869 absdcl: /* an absolute declarator */
1870 /* empty */
1871 { $$ = NULL_TREE; }
1872 | absdcl1
1873 ;
1874
1875 absdcl_maybe_attribute: /* absdcl maybe_attribute, but not just attributes */
1876 /* empty */
1877 { $$ = build_tree_list (build_tree_list (current_declspecs,
1878 NULL_TREE),
1879 all_prefix_attributes); }
1880 | absdcl1
1881 { $$ = build_tree_list (build_tree_list (current_declspecs,
1882 $1),
1883 all_prefix_attributes); }
1884 | absdcl1_noea attributes
1885 { $$ = build_tree_list (build_tree_list (current_declspecs,
1886 $1),
1887 chainon ($2, all_prefix_attributes)); }
1888 ;
1889
1890 absdcl1: /* a nonempty absolute declarator */
1891 absdcl1_ea
1892 | absdcl1_noea
1893 ;
1894
1895 absdcl1_noea:
1896 direct_absdcl1
1897 | '*' maybe_type_quals_attrs absdcl1_noea
1898 { $$ = make_pointer_declarator ($2, $3); }
1899 ;
1900
1901 absdcl1_ea:
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); }
1906 ;
1907
1908 direct_absdcl1:
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); }
1915 | '(' parmlist
1916 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1917 | array_declarator
1918 { $$ = set_array_declarator_type ($1, NULL_TREE, 1); }
1919 ;
1920
1921 /* The [...] part of a declarator for an array type. */
1922
1923 array_declarator:
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); }
1935 ;
1936
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. */
1942
1943 stmts_and_decls:
1944 lineno_stmt_decl_or_labels_ending_stmt
1945 | lineno_stmt_decl_or_labels_ending_decl
1946 | lineno_stmt_decl_or_labels_ending_label
1947 {
1948 error ("label at end of compound statement");
1949 }
1950 | lineno_stmt_decl_or_labels_ending_error
1951 ;
1952
1953 lineno_stmt_decl_or_labels_ending_stmt:
1954 lineno_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
1959 ;
1960
1961 lineno_stmt_decl_or_labels_ending_decl:
1962 lineno_decl
1963 | lineno_stmt_decl_or_labels_ending_stmt lineno_decl
1964 {
1965 if ((pedantic && !flag_isoc99)
1966 || warn_declaration_after_statement)
1967 pedwarn_c90 ("ISO C90 forbids mixed declarations and code");
1968 }
1969 | lineno_stmt_decl_or_labels_ending_decl lineno_decl
1970 | lineno_stmt_decl_or_labels_ending_error lineno_decl
1971 ;
1972
1973 lineno_stmt_decl_or_labels_ending_label:
1974 lineno_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
1979 ;
1980
1981 lineno_stmt_decl_or_labels_ending_error:
1982 errstmt
1983 | lineno_stmt_decl_or_labels errstmt
1984 ;
1985
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
1991 ;
1992
1993 errstmt: error ';'
1994 ;
1995
1996 /* Start and end blocks created for the new scopes of C99. */
1997 c99_block_start: /* empty */
1998 { $$ = c_begin_compound_stmt (flag_isoc99); }
1999 ;
2000
2001 /* Read zero or more forward-declarations for labels
2002 that nested functions can jump to. */
2003 maybe_label_decls:
2004 /* empty */
2005 | label_decls
2006 { if (pedantic)
2007 pedwarn ("ISO C forbids label declarations"); }
2008 ;
2009
2010 label_decls:
2011 label_decl
2012 | label_decls label_decl
2013 ;
2014
2015 label_decl:
2016 LABEL identifiers_or_typenames ';'
2017 { tree link;
2018 for (link = $2; link; link = TREE_CHAIN (link))
2019 {
2020 tree label = declare_label (TREE_VALUE (link));
2021 C_DECLARED_LABEL_FLAG (label) = 1;
2022 add_stmt (build_stmt (DECL_STMT, label));
2023 }
2024 }
2025 ;
2026
2027 /* This is the body of a function definition.
2028 It causes syntax errors to ignore to the next openbrace. */
2029 compstmt_or_error:
2030 compstmt
2031 { add_stmt ($1); }
2032 | error compstmt
2033 ;
2034
2035 compstmt_start: '{' { compstmt_count++;
2036 $$ = c_begin_compound_stmt (true); }
2037 ;
2038
2039 compstmt_nostart: '}'
2040 | maybe_label_decls compstmt_contents_nonempty '}'
2041 ;
2042
2043 compstmt_contents_nonempty:
2044 stmts_and_decls
2045 | error
2046 ;
2047
2048 compstmt_primary_start:
2049 '(' '{'
2050 { if (current_function_decl == 0)
2051 {
2052 error ("braced-group within expression allowed "
2053 "only inside a function");
2054 YYERROR;
2055 }
2056 compstmt_count++;
2057 $$ = c_begin_stmt_expr ();
2058 }
2059 ;
2060
2061 compstmt: compstmt_start compstmt_nostart
2062 { $$ = c_end_compound_stmt ($1, true); }
2063 ;
2064
2065 if_prefix:
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. */
2070 IF
2071 { c_begin_if_stmt (); }
2072 '(' expr ')'
2073 { c_finish_if_cond ($4, compstmt_count, ++stmt_count); }
2074 ;
2075
2076 simple_if:
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. */
2081 | if_prefix error
2082 ;
2083
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. */
2087 do_stmt_start:
2088 DO
2089 { stmt_count++;
2090 compstmt_count++;
2091 c_in_iteration_stmt++;
2092 $<ttype>$
2093 = add_stmt (build_stmt (DO_STMT, NULL_TREE,
2094 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
2101 { $$ = $<ttype>2;
2102 DO_BODY ($$) = $3;
2103 c_in_iteration_stmt--; }
2104 ;
2105
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. */
2109
2110 save_location:
2111 { if (yychar == YYEMPTY)
2112 yychar = YYLEX;
2113 $$ = input_location; }
2114 ;
2115
2116 lineno_labeled_stmt:
2117 lineno_stmt
2118 | lineno_label lineno_labeled_stmt
2119 ;
2120
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); }
2125 ;
2126
2127 lineno_stmt:
2128 save_location stmt
2129 {
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))
2141 {
2142 SET_EXPR_LOCUS ($2, NULL);
2143 annotate_with_locus ($2, $1);
2144 }
2145 }
2146 ;
2147
2148 lineno_label:
2149 save_location label
2150 { if ($2)
2151 {
2152 SET_EXPR_LOCUS ($2, NULL);
2153 annotate_with_locus ($2, $1);
2154 }
2155 }
2156 ;
2157
2158 select_or_iter_stmt:
2159 simple_if ELSE
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.
2171
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. */
2175 | WHILE
2176 { stmt_count++;
2177 $<ttype>$ = c_begin_while_stmt (); }
2178 '(' expr ')'
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); }
2184 | do_stmt_start
2185 '(' expr ')' ';'
2186 { DO_COND ($1) = lang_hooks.truthvalue_conversion ($3); }
2187 | do_stmt_start error
2188 { }
2189 | FOR
2190 { $<ttype>$ = c_begin_for_stmt (); }
2191 '(' for_init_stmt
2192 { stmt_count++;
2193 c_finish_for_stmt_init ($<ttype>2); }
2194 xexpr ';'
2195 { c_finish_for_stmt_cond ($6, $<ttype>2); }
2196 xexpr ')'
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 ')'
2203 { stmt_count++;
2204 $<ttype>$ = c_start_case ($3);
2205 c_in_case_stmt++; }
2206 c99_block_lineno_labeled_stmt
2207 { c_finish_case ($6);
2208 c_in_case_stmt--; }
2209 ;
2210
2211 for_init_stmt:
2212 xexpr ';'
2213 { c_finish_expr_stmt ($1); }
2214 | decl
2215 { check_for_loop_decls (); }
2216 ;
2217
2218 xexpr:
2219 /* empty */
2220 { $$ = NULL_TREE; }
2221 | expr
2222 ;
2223
2224 /* Parse a single real statement, not including any labels. */
2225 stmt:
2226 compstmt
2227 { stmt_count++; add_stmt ($1); }
2228 | expr ';'
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)); }
2232 | BREAK ';'
2233 { stmt_count++;
2234 if (!(c_in_iteration_stmt || c_in_case_stmt))
2235 error ("break statement not within loop or switch");
2236 else
2237 add_stmt (build_break_stmt ()); }
2238 | CONTINUE ';'
2239 { stmt_count++;
2240 if (!c_in_iteration_stmt)
2241 error ("continue statement not within a loop");
2242 else
2243 add_stmt (build_continue_stmt ()); }
2244 | RETURN ';'
2245 { stmt_count++; c_expand_return (NULL_TREE); }
2246 | RETURN expr ';'
2247 { stmt_count++; c_expand_return ($2); }
2248 | asm_stmt
2249 | GOTO identifier ';'
2250 { tree decl;
2251 stmt_count++;
2252 decl = lookup_label ($2);
2253 if (decl != 0)
2254 {
2255 TREE_USED (decl) = 1;
2256 add_stmt (build_stmt (GOTO_EXPR, decl));
2257 }
2258 }
2259 | GOTO '*' expr ';'
2260 { if (pedantic)
2261 pedwarn ("ISO C forbids `goto *expr;'");
2262 stmt_count++;
2263 $3 = convert (ptr_type_node, $3);
2264 add_stmt (build_stmt (GOTO_EXPR, $3)); }
2265 | ';'
2266 { }
2267 @@ifobjc
2268 | AT_THROW expr ';'
2269 { stmt_count++; objc_build_throw_stmt ($2); }
2270 | AT_THROW ';'
2271 { stmt_count++; objc_build_throw_stmt (NULL_TREE); }
2272 | objc_try_catch_stmt
2273 { }
2274 | AT_SYNCHRONIZED '(' expr ')' save_location compstmt
2275 { stmt_count++; objc_build_synchronized ($5, $3, $6); }
2276 ;
2277
2278 objc_catch_prefix:
2279 AT_CATCH '(' parm ')'
2280 { objc_begin_catch_clause ($3); }
2281 ;
2282
2283 objc_catch_clause:
2284 objc_catch_prefix '{' compstmt_nostart
2285 { objc_finish_catch_clause (); }
2286 | objc_catch_prefix '{' error '}'
2287 { objc_finish_catch_clause (); }
2288 ;
2289
2290 objc_opt_catch_list:
2291 /* empty */
2292 | objc_opt_catch_list objc_catch_clause
2293 ;
2294
2295 objc_try_catch_clause:
2296 AT_TRY save_location compstmt
2297 { stmt_count++; objc_begin_try_stmt ($2, $3); }
2298 objc_opt_catch_list
2299 ;
2300
2301 objc_finally_clause:
2302 AT_FINALLY save_location compstmt
2303 { objc_build_finally_clause ($2, $3); }
2304 ;
2305
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 (); }
2311 @@end_ifobjc
2312 ;
2313
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. */
2317
2318 label: CASE expr_no_commas ':'
2319 { stmt_count++;
2320 $$ = do_case ($2, NULL_TREE); }
2321 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
2322 { stmt_count++;
2323 $$ = do_case ($2, $4); }
2324 | DEFAULT ':'
2325 { stmt_count++;
2326 $$ = do_case (NULL_TREE, NULL_TREE); }
2327 | identifier save_location ':' maybe_attribute
2328 { tree label = define_label ($2, $1);
2329 stmt_count++;
2330 if (label)
2331 {
2332 decl_attributes (&label, $4, 0);
2333 $$ = add_stmt (build_stmt (LABEL_EXPR, label));
2334 }
2335 else
2336 $$ = NULL_TREE;
2337 }
2338 ;
2339
2340 /* Asm expressions and statements */
2341
2342 /* simple_asm_expr is used in restricted contexts, where a full
2343 expression with inputs and outputs does not make sense. */
2344 simple_asm_expr:
2345 ASM_KEYWORD stop_string_translation
2346 '(' STRING ')' start_string_translation
2347 { $$ = $4; }
2348 ;
2349
2350 /* maybeasm: used for assembly names for declarations */
2351 maybeasm:
2352 /* empty */
2353 { $$ = NULL_TREE; }
2354 | simple_asm_expr
2355 ;
2356
2357 /* asmdef: asm() outside a function body. */
2358 asmdef:
2359 simple_asm_expr ';'
2360 { assemble_asm ($1); }
2361 | ASM_KEYWORD error start_string_translation ';'
2362 {}
2363 ;
2364
2365 /* Full-blown asm statement with inputs, outputs, clobbers, and
2366 volatile tag allowed. */
2367 asm_stmt:
2368 ASM_KEYWORD maybe_volatile stop_string_translation
2369 '(' asm_argument ')' start_string_translation ';'
2370 { stmt_count++;
2371 $$ = build_asm_stmt ($2, $5); }
2372 ;
2373
2374 asm_argument:
2375 /* no operands */
2376 STRING
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); }
2387 ;
2388
2389 /* Either 'volatile' or nothing. First thing in an `asm' statement. */
2390
2391 maybe_volatile:
2392 /* empty */
2393 { $$ = 0; }
2394 | TYPE_QUAL
2395 { if ($1 != ridpointers[RID_VOLATILE])
2396 {
2397 warning ("%E qualifier ignored on asm", $1);
2398 $$ = 0;
2399 }
2400 else
2401 $$ = $1;
2402 }
2403 ;
2404
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 */
2408 { $$ = NULL_TREE; }
2409 | nonnull_asm_operands
2410 ;
2411
2412 nonnull_asm_operands:
2413 asm_operand
2414 | nonnull_asm_operands ',' asm_operand
2415 { $$ = chainon ($1, $3); }
2416 ;
2417
2418 asm_operand:
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); }
2426 ;
2427
2428 asm_clobbers:
2429 STRING
2430 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
2431 | asm_clobbers ',' STRING
2432 { $$ = tree_cons (NULL_TREE, $3, $1); }
2433 ;
2434
2435 stop_string_translation:
2436 { c_lex_string_translate = 0; }
2437 ;
2438
2439 start_string_translation:
2440 { c_lex_string_translate = 1; }
2441 ;
2442
2443 \f
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));". */
2449 parmlist:
2450 maybe_attribute
2451 { push_scope ();
2452 declare_parm_level (); }
2453 parmlist_1
2454 { $$ = $3;
2455 pop_scope (); }
2456 ;
2457
2458 parmlist_1:
2459 parmlist_2 ')'
2460 | parms ';'
2461 { mark_forward_parm_decls (); }
2462 maybe_attribute
2463 { /* Dummy action so attributes are in known place
2464 on parser stack. */ }
2465 parmlist_1
2466 { $$ = $6; }
2467 | error ')'
2468 { $$ = make_node (TREE_LIST); }
2469 ;
2470
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); }
2475 | ELLIPSIS
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 `...'");
2480 }
2481 | parms
2482 { $$ = get_parm_info (/*ellipsis=*/false); }
2483 | parms ',' ELLIPSIS
2484 { $$ = get_parm_info (/*ellipsis=*/true); }
2485 ;
2486
2487 parms:
2488 firstparm
2489 { push_parm_decl ($1); }
2490 | parms ',' parm
2491 { push_parm_decl ($3); }
2492 ;
2493
2494 /* A single parameter declaration or parameter type name,
2495 as found in a parmlist. */
2496 parm:
2497 declspecs_ts setspecs parm_declarator maybe_attribute
2498 { $$ = build_tree_list (build_tree_list (current_declspecs,
2499 $3),
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,
2504 $3),
2505 chainon ($4, all_prefix_attributes));
2506 POP_DECLSPEC_STACK; }
2507 | declspecs_ts setspecs absdcl_maybe_attribute
2508 { $$ = $3;
2509 POP_DECLSPEC_STACK; }
2510 | declspecs_nots setspecs notype_declarator maybe_attribute
2511 { $$ = build_tree_list (build_tree_list (current_declspecs,
2512 $3),
2513 chainon ($4, all_prefix_attributes));
2514 POP_DECLSPEC_STACK; }
2515
2516 | declspecs_nots setspecs absdcl_maybe_attribute
2517 { $$ = $3;
2518 POP_DECLSPEC_STACK; }
2519 ;
2520
2521 /* The first parm, which must suck attributes from off the top of the parser
2522 stack. */
2523 firstparm:
2524 declspecs_ts_nosa setspecs_fp parm_declarator maybe_attribute
2525 { $$ = build_tree_list (build_tree_list (current_declspecs,
2526 $3),
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,
2531 $3),
2532 chainon ($4, all_prefix_attributes));
2533 POP_DECLSPEC_STACK; }
2534 | declspecs_ts_nosa setspecs_fp absdcl_maybe_attribute
2535 { $$ = $3;
2536 POP_DECLSPEC_STACK; }
2537 | declspecs_nots_nosa setspecs_fp notype_declarator maybe_attribute
2538 { $$ = build_tree_list (build_tree_list (current_declspecs,
2539 $3),
2540 chainon ($4, all_prefix_attributes));
2541 POP_DECLSPEC_STACK; }
2542
2543 | declspecs_nots_nosa setspecs_fp absdcl_maybe_attribute
2544 { $$ = $3;
2545 POP_DECLSPEC_STACK; }
2546 ;
2547
2548 setspecs_fp:
2549 setspecs
2550 { prefix_attributes = chainon (prefix_attributes, $<ttype>-2);
2551 all_prefix_attributes = prefix_attributes; }
2552 ;
2553
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:
2558 maybe_attribute
2559 { push_scope ();
2560 declare_parm_level (); }
2561 parmlist_or_identifiers_1
2562 { $$ = $3;
2563 pop_scope (); }
2564 ;
2565
2566 parmlist_or_identifiers_1:
2567 parmlist_1
2568 | identifiers ')'
2569 { tree t;
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);
2574
2575 /* Make sure we have a parmlist after attributes. */
2576 if ($<ttype>-1 != 0
2577 && (TREE_CODE ($$) != TREE_LIST
2578 || TREE_PURPOSE ($$) == 0
2579 || TREE_CODE (TREE_PURPOSE ($$)) != PARM_DECL))
2580 YYERROR1;
2581 }
2582 ;
2583
2584 /* A nonempty list of identifiers. */
2585 identifiers:
2586 IDENTIFIER
2587 { $$ = build_tree_list (NULL_TREE, $1); }
2588 | identifiers ',' IDENTIFIER
2589 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2590 ;
2591
2592 /* A nonempty list of identifiers, including typenames. */
2593 identifiers_or_typenames:
2594 identifier
2595 { $$ = build_tree_list (NULL_TREE, $1); }
2596 | identifiers_or_typenames ',' identifier
2597 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2598 ;
2599
2600 extension:
2601 EXTENSION
2602 { $$ = SAVE_EXT_FLAGS();
2603 pedantic = 0;
2604 warn_pointer_arith = 0;
2605 warn_traditional = 0;
2606 flag_iso = 0; }
2607 ;
2608 \f
2609 @@ifobjc
2610 /* Objective-C productions. */
2611
2612 objcdef:
2613 classdef
2614 | classdecl
2615 | aliasdecl
2616 | protocoldef
2617 | methoddef
2618 | AT_END
2619 {
2620 if (objc_implementation_context)
2621 {
2622 finish_class (objc_implementation_context);
2623 objc_ivar_chain = NULL_TREE;
2624 objc_implementation_context = NULL_TREE;
2625 }
2626 else
2627 warning ("`@end' must appear in an implementation context");
2628 }
2629 ;
2630
2631 /* A nonempty list of identifiers. */
2632 identifier_list:
2633 identifier
2634 { $$ = build_tree_list (NULL_TREE, $1); }
2635 | identifier_list ',' identifier
2636 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2637 ;
2638
2639 classdecl:
2640 AT_CLASS identifier_list ';'
2641 {
2642 objc_declare_class ($2);
2643 }
2644 ;
2645
2646 aliasdecl:
2647 AT_ALIAS identifier identifier ';'
2648 {
2649 objc_declare_alias ($2, $3);
2650 }
2651 ;
2652
2653 superclass:
2654 ':' identifier { $$ = $2; }
2655 | /* NULL */ %prec HYPERUNARY { $$ = NULL_TREE; }
2656 ;
2657
2658 class_ivars:
2659 '{' ivar_decl_list '}'
2660 | /* NULL */
2661 ;
2662
2663 classdef:
2664 AT_INTERFACE identifier superclass protocolrefs
2665 {
2666 objc_interface_context = objc_ivar_context
2667 = start_class (CLASS_INTERFACE_TYPE, $2, $3, $4);
2668 objc_public_flag = 0;
2669 }
2670 class_ivars
2671 {
2672 continue_class (objc_interface_context);
2673 }
2674 methodprotolist AT_END
2675 {
2676 finish_class (objc_interface_context);
2677 objc_interface_context = NULL_TREE;
2678 }
2679
2680 | AT_IMPLEMENTATION identifier superclass
2681 {
2682 objc_implementation_context = objc_ivar_context
2683 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $3, NULL_TREE);
2684 objc_public_flag = 0;
2685 }
2686 class_ivars
2687 {
2688 objc_ivar_chain
2689 = continue_class (objc_implementation_context);
2690 }
2691
2692 | AT_INTERFACE identifier '(' identifier ')' protocolrefs
2693 {
2694 objc_interface_context
2695 = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2696 continue_class (objc_interface_context);
2697 }
2698 methodprotolist AT_END
2699 {
2700 finish_class (objc_interface_context);
2701 objc_interface_context = NULL_TREE;
2702 }
2703
2704 | AT_IMPLEMENTATION identifier '(' identifier ')'
2705 {
2706 objc_implementation_context
2707 = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2708 objc_ivar_chain
2709 = continue_class (objc_implementation_context);
2710 }
2711 ;
2712
2713 protocoldef:
2714 AT_PROTOCOL identifier protocolrefs
2715 {
2716 objc_pq_context = 1;
2717 objc_interface_context
2718 = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2719 }
2720 methodprotolist AT_END
2721 {
2722 objc_pq_context = 0;
2723 finish_protocol(objc_interface_context);
2724 objc_interface_context = NULL_TREE;
2725 }
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 ';'
2730 {
2731 objc_declare_protocols ($2);
2732 }
2733 ;
2734
2735 protocolrefs:
2736 /* empty */
2737 {
2738 $$ = NULL_TREE;
2739 }
2740 | non_empty_protocolrefs
2741 ;
2742
2743 non_empty_protocolrefs:
2744 ARITHCOMPARE identifier_list ARITHCOMPARE
2745 {
2746 if ($1 == LT_EXPR && $3 == GT_EXPR)
2747 $$ = $2;
2748 else
2749 YYERROR1;
2750 }
2751 ;
2752
2753 ivar_decl_list:
2754 ivar_decl_list visibility_spec ivar_decls
2755 | ivar_decls
2756 ;
2757
2758 visibility_spec:
2759 AT_PRIVATE { objc_public_flag = 2; }
2760 | AT_PROTECTED { objc_public_flag = 0; }
2761 | AT_PUBLIC { objc_public_flag = 1; }
2762 ;
2763
2764 ivar_decls:
2765 /* empty */
2766 {
2767 $$ = NULL_TREE;
2768 }
2769 | ivar_decls ivar_decl ';'
2770 | ivar_decls ';'
2771 {
2772 if (pedantic)
2773 pedwarn ("extra semicolon in struct or union specified");
2774 }
2775 ;
2776
2777
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'.
2782
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. */
2786
2787 ivar_decl:
2788 declspecs_nosc_ts setspecs ivars
2789 { $$ = $3;
2790 POP_DECLSPEC_STACK; }
2791 | declspecs_nosc_nots setspecs ivars
2792 { $$ = $3;
2793 POP_DECLSPEC_STACK; }
2794 | error
2795 { $$ = NULL_TREE; }
2796 ;
2797
2798 ivars:
2799 /* empty */
2800 { $$ = NULL_TREE; }
2801 | ivar_declarator
2802 | ivars ',' maybe_resetattrs ivar_declarator
2803 ;
2804
2805 ivar_declarator:
2806 declarator
2807 {
2808 $$ = add_instance_variable (objc_ivar_context,
2809 objc_public_flag,
2810 $1, current_declspecs,
2811 NULL_TREE);
2812 }
2813 | declarator ':' expr_no_commas
2814 {
2815 $$ = add_instance_variable (objc_ivar_context,
2816 objc_public_flag,
2817 $1, current_declspecs, $3);
2818 }
2819 | ':' expr_no_commas
2820 {
2821 $$ = add_instance_variable (objc_ivar_context,
2822 objc_public_flag,
2823 NULL_TREE,
2824 current_declspecs, $2);
2825 }
2826 ;
2827
2828 methodtype:
2829 '+'
2830 { objc_inherit_code = CLASS_METHOD_DECL; }
2831 | '-'
2832 { objc_inherit_code = INSTANCE_METHOD_DECL; }
2833 ;
2834
2835 methoddef:
2836 methodtype
2837 {
2838 objc_pq_context = 1;
2839 if (!objc_implementation_context)
2840 fatal_error ("method definition not in class context");
2841 }
2842 methoddecl
2843 {
2844 objc_pq_context = 0;
2845 objc_add_method (objc_implementation_context,
2846 $3,
2847 objc_inherit_code == CLASS_METHOD_DECL);
2848 start_method_def ($3);
2849 }
2850 optarglist
2851 {
2852 continue_method_def ();
2853 }
2854 compstmt_or_error
2855 {
2856 finish_method_def ();
2857 }
2858 ;
2859
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. */
2863
2864 methodprotolist:
2865 /* empty */
2866 | methodprotolist methodproto
2867 | methodprotolist { $<ttype>$ = NULL_TREE; } datadef
2868 ;
2869
2870 semi_or_error:
2871 ';'
2872 | error
2873 ;
2874
2875 methodproto:
2876 methodtype
2877 {
2878 /* Remember protocol qualifiers in prototypes. */
2879 objc_pq_context = 1;
2880 }
2881 methoddecl
2882 {
2883 /* Forget protocol qualifiers here. */
2884 objc_pq_context = 0;
2885 objc_add_method (objc_interface_context,
2886 $3,
2887 objc_inherit_code == CLASS_METHOD_DECL);
2888 }
2889 semi_or_error
2890 ;
2891
2892 methoddecl:
2893 '(' typename ')' unaryselector
2894 {
2895 $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
2896 }
2897
2898 | unaryselector
2899 {
2900 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
2901 }
2902
2903 | '(' typename ')' keywordselector optparmlist
2904 {
2905 $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
2906 }
2907
2908 | keywordselector optparmlist
2909 {
2910 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
2911 }
2912 ;
2913
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 */
2916
2917 optarglist:
2918 /* empty */
2919 | ';' myxdecls
2920 ;
2921
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; { ... }" */
2924
2925 myxdecls:
2926 /* empty */
2927 | mydecls
2928 ;
2929
2930 mydecls:
2931 mydecl
2932 | errstmt
2933 | mydecls mydecl
2934 | mydecl errstmt
2935 ;
2936
2937 mydecl:
2938 declspecs_ts setspecs myparms ';'
2939 { POP_DECLSPEC_STACK; }
2940 | declspecs_ts ';'
2941 { shadow_tag ($1); }
2942 | declspecs_nots ';'
2943 { pedwarn ("empty declaration"); }
2944 ;
2945
2946 myparms:
2947 myparm
2948 { push_parm_decl ($1); }
2949 | myparms ',' myparm
2950 { push_parm_decl ($3); }
2951 ;
2952
2953 /* A single parameter declaration or parameter type name,
2954 as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
2955
2956 myparm:
2957 parm_declarator maybe_attribute
2958 { $$ = build_tree_list (build_tree_list (current_declspecs,
2959 $1),
2960 chainon ($2, all_prefix_attributes)); }
2961 | notype_declarator maybe_attribute
2962 { $$ = build_tree_list (build_tree_list (current_declspecs,
2963 $1),
2964 chainon ($2, all_prefix_attributes)); }
2965 | absdcl_maybe_attribute
2966 { $$ = $1; }
2967 ;
2968
2969 optparmlist:
2970 /* empty */
2971 {
2972 $$ = NULL_TREE;
2973 }
2974 | ',' ELLIPSIS
2975 {
2976 /* oh what a kludge! */
2977 $$ = objc_ellipsis_node;
2978 }
2979 | ','
2980 {
2981 push_scope ();
2982 }
2983 parmlist_2
2984 {
2985 /* returns a tree list node generated by get_parm_info */
2986 $$ = $3;
2987 pop_scope ();
2988 }
2989 ;
2990
2991 unaryselector:
2992 selector
2993 ;
2994
2995 keywordselector:
2996 keyworddecl
2997
2998 | keywordselector keyworddecl
2999 {
3000 $$ = chainon ($1, $2);
3001 }
3002 ;
3003
3004 selector:
3005 IDENTIFIER
3006 | TYPENAME
3007 | CLASSNAME
3008 | OBJECTNAME
3009 | reservedwords
3010 ;
3011
3012 reservedwords:
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
3017 ;
3018
3019 keyworddecl:
3020 selector ':' '(' typename ')' identifier
3021 {
3022 $$ = build_keyword_decl ($1, $4, $6);
3023 }
3024
3025 | selector ':' identifier
3026 {
3027 $$ = build_keyword_decl ($1, NULL_TREE, $3);
3028 }
3029
3030 | ':' '(' typename ')' identifier
3031 {
3032 $$ = build_keyword_decl (NULL_TREE, $3, $5);
3033 }
3034
3035 | ':' identifier
3036 {
3037 $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
3038 }
3039 ;
3040
3041 messageargs:
3042 selector
3043 | keywordarglist
3044 ;
3045
3046 keywordarglist:
3047 keywordarg
3048 | keywordarglist keywordarg
3049 {
3050 $$ = chainon ($1, $2);
3051 }
3052 ;
3053
3054
3055 keywordexpr:
3056 nonnull_exprlist
3057 {
3058 if (TREE_CHAIN ($1) == NULL_TREE)
3059 /* just return the expr., remove a level of indirection */
3060 $$ = TREE_VALUE ($1);
3061 else
3062 /* we have a comma expr., we will collapse later */
3063 $$ = $1;
3064 }
3065 ;
3066
3067 keywordarg:
3068 selector ':' keywordexpr
3069 {
3070 $$ = build_tree_list ($1, $3);
3071 }
3072 | ':' keywordexpr
3073 {
3074 $$ = build_tree_list (NULL_TREE, $2);
3075 }
3076 ;
3077
3078 receiver:
3079 expr
3080 | CLASSNAME
3081 {
3082 $$ = get_class_reference ($1);
3083 }
3084 | TYPENAME
3085 {
3086 $$ = get_class_reference ($1);
3087 }
3088 ;
3089
3090 objcmessageexpr:
3091 '[' receiver messageargs ']'
3092 { $$ = build_tree_list ($2, $3); }
3093 ;
3094
3095 selectorarg:
3096 selector
3097 | keywordnamelist
3098 ;
3099
3100 keywordnamelist:
3101 keywordname
3102 | keywordnamelist keywordname
3103 {
3104 $$ = chainon ($1, $2);
3105 }
3106 ;
3107
3108 keywordname:
3109 selector ':'
3110 {
3111 $$ = build_tree_list ($1, NULL_TREE);
3112 }
3113 | ':'
3114 {
3115 $$ = build_tree_list (NULL_TREE, NULL_TREE);
3116 }
3117 ;
3118
3119 objcselectorexpr:
3120 AT_SELECTOR '(' selectorarg ')'
3121 {
3122 $$ = $3;
3123 }
3124 ;
3125
3126 objcprotocolexpr:
3127 AT_PROTOCOL '(' identifier ')'
3128 {
3129 $$ = $3;
3130 }
3131 ;
3132
3133 /* extension to support C-structures in the archiver */
3134
3135 objcencodeexpr:
3136 AT_ENCODE '(' typename ')'
3137 {
3138 $$ = groktypename ($3);
3139 }
3140 ;
3141
3142 @@end_ifobjc
3143 %%
3144
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. */
3147
3148 static enum cpp_ttype last_token;
3149
3150 /* The reserved keyword table. */
3151 struct resword
3152 {
3153 const char *word;
3154 ENUM_BITFIELD(rid) rid : 16;
3155 unsigned int disable : 16;
3156 };
3157
3158 /* Disable mask. Keywords are disabled if (reswords[i].disable & mask) is
3159 _true_. */
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 */
3164
3165 static const struct resword reswords[] =
3166 {
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 },
3245 @@ifobjc
3246 { "id", RID_ID, D_OBJC },
3247
3248 /* These objc keywords are recognized only immediately after
3249 an '@'. */
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
3268 (see above) */
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 },
3275 @@end_ifobjc
3276 };
3277 #define N_reswords (sizeof reswords / sizeof (struct resword))
3278
3279 /* Table mapping from RID_* constants to yacc token numbers.
3280 Unfortunately we have to have entries for all the keywords in all
3281 three languages. */
3282 static const short rid_to_yy[RID_MAX] =
3283 {
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,
3297
3298 /* C extensions */
3299 /* RID_COMPLEX */ TYPESPEC,
3300 /* RID_THREAD */ SCSPEC,
3301
3302 /* C++ */
3303 /* RID_FRIEND */ 0,
3304 /* RID_VIRTUAL */ 0,
3305 /* RID_EXPLICIT */ 0,
3306 /* RID_EXPORT */ 0,
3307 /* RID_MUTABLE */ 0,
3308
3309 /* ObjC */
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,
3316
3317 /* C */
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,
3326 /* RID_IF */ IF,
3327 /* RID_ELSE */ ELSE,
3328 /* RID_WHILE */ WHILE,
3329 /* RID_DO */ DO,
3330 /* RID_FOR */ FOR,
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,
3339
3340 /* C extensions */
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,
3353
3354 /* RID_CHOOSE_EXPR */ CHOOSE_EXPR,
3355 /* RID_TYPES_COMPATIBLE_P */ TYPES_COMPATIBLE_P,
3356
3357 /* RID_FUNCTION_NAME */ FUNC_NAME,
3358 /* RID_PRETTY_FUNCTION_NAME */ FUNC_NAME,
3359 /* RID_C99_FUNCTION_NAME */ FUNC_NAME,
3360
3361 /* C++ */
3362 /* RID_BOOL */ TYPESPEC,
3363 /* RID_WCHAR */ 0,
3364 /* RID_CLASS */ 0,
3365 /* RID_PUBLIC */ 0,
3366 /* RID_PRIVATE */ 0,
3367 /* RID_PROTECTED */ 0,
3368 /* RID_TEMPLATE */ 0,
3369 /* RID_NULL */ 0,
3370 /* RID_CATCH */ 0,
3371 /* RID_DELETE */ 0,
3372 /* RID_FALSE */ 0,
3373 /* RID_NAMESPACE */ 0,
3374 /* RID_NEW */ 0,
3375 /* RID_OFFSETOF */ OFFSETOF,
3376 /* RID_OPERATOR */ 0,
3377 /* RID_THIS */ 0,
3378 /* RID_THROW */ 0,
3379 /* RID_TRUE */ 0,
3380 /* RID_TRY */ 0,
3381 /* RID_TYPENAME */ 0,
3382 /* RID_TYPEID */ 0,
3383 /* RID_USING */ 0,
3384
3385 /* casts */
3386 /* RID_CONSTCAST */ 0,
3387 /* RID_DYNCAST */ 0,
3388 /* RID_REINTCAST */ 0,
3389 /* RID_STATCAST */ 0,
3390
3391 /* Objective C */
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
3410 };
3411
3412 static void
3413 init_reswords (void)
3414 {
3415 unsigned int i;
3416 tree id;
3417 int mask = (flag_isoc99 ? 0 : D_C89)
3418 | (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0);
3419
3420 if (!c_dialect_objc ())
3421 mask |= D_OBJC;
3422
3423 ridpointers = ggc_calloc ((int) RID_MAX, sizeof (tree));
3424 for (i = 0; i < N_reswords; i++)
3425 {
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)
3429 continue;
3430
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;
3435 }
3436 }
3437
3438 #define NAME(type) cpp_type2name (type)
3439
3440 static void
3441 yyerror (const char *msgid)
3442 {
3443 c_parse_error (msgid, last_token, yylval.ttype);
3444 }
3445
3446 static int
3447 yylexname (void)
3448 {
3449 tree decl;
3450
3451 @@ifobjc
3452 int objc_force_identifier = objc_need_raw_identifier;
3453 OBJC_NEED_RAW_IDENTIFIER (0);
3454 @@end_ifobjc
3455
3456 if (C_IS_RESERVED_WORD (yylval.ttype))
3457 {
3458 enum rid rid_code = C_RID_CODE (yylval.ttype);
3459
3460 @@ifobjc
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)
3464 {
3465 decl = lookup_name (yylval.ttype);
3466 if (decl == NULL_TREE || TREE_CODE (decl) != TYPE_DECL)
3467 return IDENTIFIER;
3468 }
3469
3470 if (!OBJC_IS_AT_KEYWORD (rid_code)
3471 && (!OBJC_IS_PQ_KEYWORD (rid_code) || objc_pq_context))
3472 @@end_ifobjc
3473 {
3474 /* Return the canonical spelling for this keyword. */
3475 yylval.ttype = ridpointers[(int) rid_code];
3476 return rid_to_yy[(int) rid_code];
3477 }
3478 }
3479
3480 decl = lookup_name (yylval.ttype);
3481 if (decl)
3482 {
3483 if (TREE_CODE (decl) == TYPE_DECL)
3484 return TYPENAME;
3485 }
3486 @@ifobjc
3487 else
3488 {
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)))
3495 {
3496 yylval.ttype = objc_interface_decl;
3497 return CLASSNAME;
3498 }
3499 }
3500 @@end_ifobjc
3501
3502 return IDENTIFIER;
3503 }
3504
3505 static inline int
3506 _yylex (void)
3507 {
3508 get_next:
3509 last_token = c_lex (&yylval.ttype);
3510 switch (last_token)
3511 {
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;
3526
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;
3536
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;
3547
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;
3553
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 '.';
3558
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 ';';
3565
3566 case CPP_EOF:
3567 return 0;
3568
3569 case CPP_NAME:
3570 return yylexname ();
3571
3572 case CPP_AT_NAME:
3573 /* This only happens in Objective-C; it must be a keyword. */
3574 return rid_to_yy [(int) C_RID_CODE (yylval.ttype)];
3575
3576 case CPP_NUMBER:
3577 case CPP_CHAR:
3578 case CPP_WCHAR:
3579 return CONSTANT;
3580
3581 case CPP_STRING:
3582 case CPP_WSTRING:
3583 return STRING;
3584
3585 case CPP_OBJC_STRING:
3586 return OBJC_STRING;
3587
3588 /* These tokens are C++ specific (and will not be generated
3589 in C mode, but let's be cautious). */
3590 case CPP_SCOPE:
3591 case CPP_DEREF_STAR:
3592 case CPP_DOT_STAR:
3593 case CPP_MIN_EQ:
3594 case CPP_MAX_EQ:
3595 case CPP_MIN:
3596 case CPP_MAX:
3597 /* These tokens should not survive translation phase 4. */
3598 case CPP_HASH:
3599 case CPP_PASTE:
3600 error ("syntax error at '%s' token", NAME(last_token));
3601 goto get_next;
3602
3603 default:
3604 abort ();
3605 }
3606 /* NOTREACHED */
3607 }
3608
3609 static int
3610 yylex (void)
3611 {
3612 int r;
3613 timevar_push (TV_LEX);
3614 r = _yylex();
3615 timevar_pop (TV_LEX);
3616 return r;
3617 }
3618
3619 /* Function used when yydebug is set, to print a token in more detail. */
3620
3621 static void
3622 yyprint (FILE *file, int yychar, YYSTYPE yyl)
3623 {
3624 tree t = yyl.ttype;
3625
3626 fprintf (file, " [%s]", NAME(last_token));
3627
3628 switch (yychar)
3629 {
3630 case IDENTIFIER:
3631 case TYPENAME:
3632 case OBJECTNAME:
3633 case TYPESPEC:
3634 case TYPE_QUAL:
3635 case SCSPEC:
3636 case STATIC:
3637 if (IDENTIFIER_POINTER (t))
3638 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
3639 break;
3640
3641 case CONSTANT:
3642 fprintf (file, " %s", GET_MODE_NAME (TYPE_MODE (TREE_TYPE (t))));
3643 if (TREE_CODE (t) == INTEGER_CST)
3644 {
3645 fputs (" ", file);
3646 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
3647 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
3648 }
3649 break;
3650 }
3651 }
3652 \f
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. */
3655
3656 /* Parse the file. */
3657 void
3658 c_parse_file (void)
3659 {
3660 yyparse ();
3661
3662 if (malloced_yyss)
3663 {
3664 free (malloced_yyss);
3665 free (malloced_yyvs);
3666 malloced_yyss = 0;
3667 }
3668 }
3669
3670 #include "gt-c-parse.h"
This page took 0.193181 seconds and 5 git commands to generate.