]> gcc.gnu.org Git - gcc.git/blob - gcc/c-parse.in
90th Cygnus<->FSF quick merge
[gcc.git] / gcc / c-parse.in
1 /* YACC parser for C syntax and for Objective C. -*-c-*-
2 Copyright (C) 1987, 88, 89, 92-5, 1996 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 /* This file defines the grammar of C and that of Objective C.
22 ifobjc ... end ifobjc conditionals contain code for Objective C only.
23 ifc ... end ifc conditionals contain code for C only.
24 Sed commands in Makefile.in are used to convert this file into
25 c-parse.y and into objc-parse.y. */
26
27 /* To whomever it may concern: I have heard that such a thing was once
28 written by AT&T, but I have never seen it. */
29
30 ifobjc
31 %expect 66
32 end ifobjc
33 ifc
34 %expect 46
35
36 /* These are the 23 conflicts you should get in parse.output;
37 the state numbers may vary if minor changes in the grammar are made.
38
39 State 42 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTE.)
40 State 44 contains 1 shift/reduce conflict. (Two ways to recover from error.)
41 State 103 contains 1 shift/reduce conflict. (Two ways to recover from error.)
42 State 110 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTE.)
43 State 111 contains 1 shift/reduce conflict. (Two ways to recover from error.)
44 State 115 contains 1 shift/reduce conflict. (Two ways to recover from error.)
45 State 132 contains 1 shift/reduce conflict. (See comment at component_decl.)
46 State 180 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTE.)
47 State 194 contains 2 shift/reduce conflict. (Four ways to parse this.)
48 State 202 contains 1 shift/reduce conflict. (Two ways to recover from error.)
49 State 214 contains 1 shift/reduce conflict. (Two ways to recover from error.)
50 State 220 contains 1 shift/reduce conflict. (Two ways to recover from error.)
51 State 304 contains 2 shift/reduce conflicts. (Four ways to parse this.)
52 State 335 contains 2 shift/reduce conflicts. (Four ways to parse this.)
53 State 347 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTES.)
54 State 352 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTES.)
55 State 383 contains 2 shift/reduce conflicts. (Four ways to parse this.)
56 State 434 contains 2 shift/reduce conflicts. (Four ways to parse this.) */
57
58 end ifc
59
60 %{
61 #include <stdio.h>
62 #include <errno.h>
63 #include <setjmp.h>
64
65 #include "config.h"
66 #include "tree.h"
67 #include "input.h"
68 #include "c-lex.h"
69 #include "c-tree.h"
70 #include "flags.h"
71
72 #ifdef MULTIBYTE_CHARS
73 #include <stdlib.h>
74 #include <locale.h>
75 #endif
76
77 ifobjc
78 #include "objc-act.h"
79 end ifobjc
80
81 /* Since parsers are distinct for each language, put the language string
82 definition here. */
83 ifobjc
84 char *language_string = "GNU Obj-C";
85 end ifobjc
86 ifc
87 char *language_string = "GNU C";
88 end ifc
89
90 #ifndef errno
91 extern int errno;
92 #endif
93
94 void yyerror ();
95
96 /* Like YYERROR but do call yyerror. */
97 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
98
99 /* Cause the `yydebug' variable to be defined. */
100 #define YYDEBUG 1
101 %}
102
103 %start program
104
105 %union {long itype; tree ttype; enum tree_code code;
106 char *filename; int lineno; int ends_in_label; }
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
120
121 /* Reserved words that specify type.
122 yylval contains an IDENTIFIER_NODE which indicates which one. */
123 %token TYPESPEC
124
125 /* Reserved words that qualify type: "const" or "volatile".
126 yylval contains an IDENTIFIER_NODE which indicates which one. */
127 %token TYPE_QUAL
128
129 /* Character or numeric constants.
130 yylval is the node for the constant. */
131 %token CONSTANT
132
133 /* String constants in raw form.
134 yylval is a STRING_CST node. */
135 %token STRING
136
137 /* "...", used for functions with variable arglists. */
138 %token ELLIPSIS
139
140 /* the reserved words */
141 /* SCO include files test "ASM", so use something else. */
142 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
143 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
144 %token ATTRIBUTE EXTENSION LABEL
145 %token REALPART IMAGPART
146
147 /* Add precedence rules to solve dangling else s/r conflict */
148 %nonassoc IF
149 %nonassoc ELSE
150
151 /* Define the operator tokens and their precedences.
152 The value is an integer because, if used, it is the tree code
153 to use in the expression made from the operator. */
154
155 %right <code> ASSIGN '='
156 %right <code> '?' ':'
157 %left <code> OROR
158 %left <code> ANDAND
159 %left <code> '|'
160 %left <code> '^'
161 %left <code> '&'
162 %left <code> EQCOMPARE
163 %left <code> ARITHCOMPARE
164 %left <code> LSHIFT RSHIFT
165 %left <code> '+' '-'
166 %left <code> '*' '/' '%'
167 %right <code> UNARY PLUSPLUS MINUSMINUS
168 %left HYPERUNARY
169 %left <code> POINTSAT '.' '(' '['
170
171 /* The Objective-C keywords. These are included in C and in
172 Objective C, so that the token codes are the same in both. */
173 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
174 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
175
176 /* Objective-C string constants in raw form.
177 yylval is an OBJC_STRING_CST node. */
178 %token OBJC_STRING
179
180
181 %type <code> unop
182
183 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
184 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
185 %type <ttype> typed_declspecs reserved_declspecs
186 %type <ttype> typed_typespecs reserved_typespecquals
187 %type <ttype> declmods typespec typespecqual_reserved
188 %type <ttype> typed_declspecs_no_prefix_attr reserved_declspecs_no_prefix_attr
189 %type <ttype> declmods_no_prefix_attr
190 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
191 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
192 %type <ttype> init maybeasm
193 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
194 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
195 %type <ttype> any_word
196
197 %type <ttype> compstmt
198
199 %type <ttype> declarator
200 %type <ttype> notype_declarator after_type_declarator
201 %type <ttype> parm_declarator
202
203 %type <ttype> structsp component_decl_list component_decl_list2
204 %type <ttype> component_decl components component_declarator
205 %type <ttype> enumlist enumerator
206 %type <ttype> typename absdcl absdcl1 type_quals
207 %type <ttype> xexpr parms parm identifiers
208
209 %type <ttype> parmlist parmlist_1 parmlist_2
210 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
211 %type <ttype> identifiers_or_typenames
212
213 %type <itype> setspecs
214
215 %type <ends_in_label> lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
216
217 %type <filename> save_filename
218 %type <lineno> save_lineno
219 \f
220 ifobjc
221 /* the Objective-C nonterminals */
222
223 %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
224 %type <ttype> methoddecl unaryselector keywordselector selector
225 %type <ttype> keyworddecl receiver objcmessageexpr messageargs
226 %type <ttype> keywordexpr keywordarglist keywordarg
227 %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
228 %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
229 %type <ttype> objc_string non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
230
231 %type <ttype> CLASSNAME OBJC_STRING OBJECTNAME
232 end ifobjc
233 \f
234 %{
235 /* Number of statements (loosely speaking) seen so far. */
236 static int stmt_count;
237
238 /* Input file and line number of the end of the body of last simple_if;
239 used by the stmt-rule immediately after simple_if returns. */
240 static char *if_stmt_file;
241 static int if_stmt_line;
242
243 /* List of types and structure classes of the current declaration. */
244 static tree current_declspecs = NULL_TREE;
245 static tree prefix_attributes = NULL_TREE;
246
247 /* Stack of saved values of current_declspecs and prefix_attributes. */
248 static tree declspec_stack;
249
250 /* 1 if we explained undeclared var errors. */
251 static int undeclared_variable_notice;
252
253 ifobjc
254 /* Objective-C specific information */
255
256 tree objc_interface_context;
257 tree objc_implementation_context;
258 tree objc_method_context;
259 tree objc_ivar_chain;
260 tree objc_ivar_context;
261 enum tree_code objc_inherit_code;
262 int objc_receiver_context;
263 int objc_public_flag;
264
265 end ifobjc
266
267 /* Tell yyparse how to print a token's value, if yydebug is set. */
268
269 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
270 extern void yyprint ();
271 %}
272 \f
273 %%
274 program: /* empty */
275 { if (pedantic)
276 pedwarn ("ANSI C forbids an empty source file");
277 finish_file ();
278 }
279 | extdefs
280 {
281 /* In case there were missing closebraces,
282 get us back to the global binding level. */
283 while (! global_bindings_p ())
284 poplevel (0, 0, 0);
285 finish_file ();
286 }
287 ;
288
289 /* the reason for the strange actions in this rule
290 is so that notype_initdecls when reached via datadef
291 can find a valid list of type and sc specs in $0. */
292
293 extdefs:
294 {$<ttype>$ = NULL_TREE; } extdef
295 | extdefs {$<ttype>$ = NULL_TREE; } extdef
296 ;
297
298 extdef:
299 fndef
300 | datadef
301 ifobjc
302 | objcdef
303 end ifobjc
304 | ASM_KEYWORD '(' expr ')' ';'
305 { STRIP_NOPS ($3);
306 if ((TREE_CODE ($3) == ADDR_EXPR
307 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
308 || TREE_CODE ($3) == STRING_CST)
309 assemble_asm ($3);
310 else
311 error ("argument of `asm' is not a constant string"); }
312 | extension extdef
313 { pedantic = $<itype>1; }
314 ;
315
316 datadef:
317 setspecs notype_initdecls ';'
318 { if (pedantic)
319 error ("ANSI C forbids data definition with no type or storage class");
320 else if (!flag_traditional)
321 warning ("data definition has no type or storage class");
322
323 current_declspecs = TREE_VALUE (declspec_stack);
324 prefix_attributes = TREE_PURPOSE (declspec_stack);
325 declspec_stack = TREE_CHAIN (declspec_stack);
326 resume_momentary ($1); }
327 | declmods setspecs notype_initdecls ';'
328 { current_declspecs = TREE_VALUE (declspec_stack);
329 prefix_attributes = TREE_PURPOSE (declspec_stack);
330 declspec_stack = TREE_CHAIN (declspec_stack);
331 resume_momentary ($2); }
332 | typed_declspecs setspecs initdecls ';'
333 { current_declspecs = TREE_VALUE (declspec_stack);
334 prefix_attributes = TREE_PURPOSE (declspec_stack);
335 declspec_stack = TREE_CHAIN (declspec_stack);
336 resume_momentary ($2); }
337 | declmods ';'
338 { pedwarn ("empty declaration"); }
339 | typed_declspecs ';'
340 { shadow_tag ($1); }
341 | error ';'
342 | error '}'
343 | ';'
344 { if (pedantic)
345 pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
346 ;
347 \f
348 fndef:
349 typed_declspecs setspecs declarator
350 { if (! start_function (current_declspecs, $3,
351 prefix_attributes, NULL_TREE, 0))
352 YYERROR1;
353 reinit_parse_for_function (); }
354 old_style_parm_decls
355 { store_parm_decls (); }
356 compstmt_or_error
357 { finish_function (0);
358 current_declspecs = TREE_VALUE (declspec_stack);
359 prefix_attributes = TREE_PURPOSE (declspec_stack);
360 declspec_stack = TREE_CHAIN (declspec_stack);
361 resume_momentary ($2); }
362 | typed_declspecs setspecs declarator error
363 { current_declspecs = TREE_VALUE (declspec_stack);
364 prefix_attributes = TREE_PURPOSE (declspec_stack);
365 declspec_stack = TREE_CHAIN (declspec_stack);
366 resume_momentary ($2); }
367 | declmods setspecs notype_declarator
368 { if (! start_function (current_declspecs, $3,
369 prefix_attributes, NULL_TREE, 0))
370 YYERROR1;
371 reinit_parse_for_function (); }
372 old_style_parm_decls
373 { store_parm_decls (); }
374 compstmt_or_error
375 { finish_function (0);
376 current_declspecs = TREE_VALUE (declspec_stack);
377 prefix_attributes = TREE_PURPOSE (declspec_stack);
378 declspec_stack = TREE_CHAIN (declspec_stack);
379 resume_momentary ($2); }
380 | declmods setspecs notype_declarator error
381 { current_declspecs = TREE_VALUE (declspec_stack);
382 prefix_attributes = TREE_PURPOSE (declspec_stack);
383 declspec_stack = TREE_CHAIN (declspec_stack);
384 resume_momentary ($2); }
385 | setspecs notype_declarator
386 { if (! start_function (NULL_TREE, $2,
387 prefix_attributes, NULL_TREE, 0))
388 YYERROR1;
389 reinit_parse_for_function (); }
390 old_style_parm_decls
391 { store_parm_decls (); }
392 compstmt_or_error
393 { finish_function (0);
394 current_declspecs = TREE_VALUE (declspec_stack);
395 prefix_attributes = TREE_PURPOSE (declspec_stack);
396 declspec_stack = TREE_CHAIN (declspec_stack);
397 resume_momentary ($1); }
398 | setspecs notype_declarator error
399 { current_declspecs = TREE_VALUE (declspec_stack);
400 prefix_attributes = TREE_PURPOSE (declspec_stack);
401 declspec_stack = TREE_CHAIN (declspec_stack);
402 resume_momentary ($1); }
403 ;
404
405 identifier:
406 IDENTIFIER
407 | TYPENAME
408 ifobjc
409 | OBJECTNAME
410 | CLASSNAME
411 end ifobjc
412 ;
413
414 unop: '&'
415 { $$ = ADDR_EXPR; }
416 | '-'
417 { $$ = NEGATE_EXPR; }
418 | '+'
419 { $$ = CONVERT_EXPR; }
420 | PLUSPLUS
421 { $$ = PREINCREMENT_EXPR; }
422 | MINUSMINUS
423 { $$ = PREDECREMENT_EXPR; }
424 | '~'
425 { $$ = BIT_NOT_EXPR; }
426 | '!'
427 { $$ = TRUTH_NOT_EXPR; }
428 ;
429
430 expr: nonnull_exprlist
431 { $$ = build_compound_expr ($1); }
432 ;
433
434 exprlist:
435 /* empty */
436 { $$ = NULL_TREE; }
437 | nonnull_exprlist
438 ;
439
440 nonnull_exprlist:
441 expr_no_commas
442 { $$ = build_tree_list (NULL_TREE, $1); }
443 | nonnull_exprlist ',' expr_no_commas
444 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
445 ;
446
447 unary_expr:
448 primary
449 | '*' cast_expr %prec UNARY
450 { $$ = build_indirect_ref ($2, "unary *"); }
451 /* __extension__ turns off -pedantic for following primary. */
452 | extension cast_expr %prec UNARY
453 { $$ = $2;
454 pedantic = $<itype>1; }
455 | unop cast_expr %prec UNARY
456 { $$ = build_unary_op ($1, $2, 0);
457 overflow_warning ($$); }
458 /* Refer to the address of a label as a pointer. */
459 | ANDAND identifier
460 { tree label = lookup_label ($2);
461 if (pedantic)
462 pedwarn ("ANSI C forbids `&&'");
463 if (label == 0)
464 $$ = null_pointer_node;
465 else
466 {
467 TREE_USED (label) = 1;
468 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
469 TREE_CONSTANT ($$) = 1;
470 }
471 }
472 /* This seems to be impossible on some machines, so let's turn it off.
473 You can use __builtin_next_arg to find the anonymous stack args.
474 | '&' ELLIPSIS
475 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
476 $$ = error_mark_node;
477 if (TREE_VALUE (tree_last (types)) == void_type_node)
478 error ("`&...' used in function with fixed number of arguments");
479 else
480 {
481 if (pedantic)
482 pedwarn ("ANSI C forbids `&...'");
483 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
484 $$ = build_unary_op (ADDR_EXPR, $$, 0);
485 } }
486 */
487 | sizeof unary_expr %prec UNARY
488 { skip_evaluation--;
489 if (TREE_CODE ($2) == COMPONENT_REF
490 && DECL_BIT_FIELD (TREE_OPERAND ($2, 1)))
491 error ("`sizeof' applied to a bit-field");
492 $$ = c_sizeof (TREE_TYPE ($2)); }
493 | sizeof '(' typename ')' %prec HYPERUNARY
494 { skip_evaluation--;
495 $$ = c_sizeof (groktypename ($3)); }
496 | alignof unary_expr %prec UNARY
497 { skip_evaluation--;
498 $$ = c_alignof_expr ($2); }
499 | alignof '(' typename ')' %prec HYPERUNARY
500 { skip_evaluation--;
501 $$ = c_alignof (groktypename ($3)); }
502 | REALPART cast_expr %prec UNARY
503 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
504 | IMAGPART cast_expr %prec UNARY
505 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
506 ;
507
508 sizeof:
509 SIZEOF { skip_evaluation++; }
510 ;
511
512 alignof:
513 ALIGNOF { skip_evaluation++; }
514 ;
515
516 cast_expr:
517 unary_expr
518 | '(' typename ')' cast_expr %prec UNARY
519 { tree type = groktypename ($2);
520 $$ = build_c_cast (type, $4); }
521 | '(' typename ')' '{'
522 { start_init (NULL_TREE, NULL, 0);
523 $2 = groktypename ($2);
524 really_start_incremental_init ($2); }
525 initlist_maybe_comma '}' %prec UNARY
526 { char *name;
527 tree result = pop_init_level (0);
528 tree type = $2;
529 finish_init ();
530
531 if (pedantic)
532 pedwarn ("ANSI C forbids constructor expressions");
533 if (TYPE_NAME (type) != 0)
534 {
535 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
536 name = IDENTIFIER_POINTER (TYPE_NAME (type));
537 else
538 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
539 }
540 else
541 name = "";
542 $$ = result;
543 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
544 {
545 int failure = complete_array_type (type, $$, 1);
546 if (failure)
547 abort ();
548 }
549 }
550 ;
551
552 expr_no_commas:
553 cast_expr
554 | expr_no_commas '+' expr_no_commas
555 { $$ = parser_build_binary_op ($2, $1, $3); }
556 | expr_no_commas '-' 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 LSHIFT expr_no_commas
565 { $$ = parser_build_binary_op ($2, $1, $3); }
566 | expr_no_commas RSHIFT expr_no_commas
567 { $$ = parser_build_binary_op ($2, $1, $3); }
568 | expr_no_commas ARITHCOMPARE expr_no_commas
569 { $$ = parser_build_binary_op ($2, $1, $3); }
570 | expr_no_commas EQCOMPARE expr_no_commas
571 { $$ = parser_build_binary_op ($2, $1, $3); }
572 | expr_no_commas '&' expr_no_commas
573 { $$ = parser_build_binary_op ($2, $1, $3); }
574 | expr_no_commas '|' expr_no_commas
575 { $$ = parser_build_binary_op ($2, $1, $3); }
576 | expr_no_commas '^' expr_no_commas
577 { $$ = parser_build_binary_op ($2, $1, $3); }
578 | expr_no_commas ANDAND
579 { $1 = truthvalue_conversion (default_conversion ($1));
580 $<itype>2 = $1 == boolean_false_node;
581 skip_evaluation += $<itype>2; }
582 expr_no_commas
583 { skip_evaluation -= $<itype>2;
584 $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
585 | expr_no_commas OROR
586 { $1 = truthvalue_conversion (default_conversion ($1));
587 $<itype>3 = $1 == boolean_true_node;
588 skip_evaluation += $<itype>3; }
589 expr_no_commas
590 { skip_evaluation -= $<itype>3;
591 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
592 | expr_no_commas '?'
593 { $1 = truthvalue_conversion (default_conversion ($1));
594 $<itype>3 = $1 == boolean_true_node;
595 $<itype>2 = $1 == boolean_false_node;
596 skip_evaluation += $<itype>2; }
597 expr ':'
598 { skip_evaluation += $<itype>3 - $<itype>2; }
599 expr_no_commas
600 { skip_evaluation -= $<itype>3;
601 $$ = build_conditional_expr ($1, $4, $7); }
602 | expr_no_commas '?'
603 { if (pedantic)
604 pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
605 /* Make sure first operand is calculated only once. */
606 $<ttype>2 = save_expr ($1);
607 $1 = truthvalue_conversion (default_conversion ($<ttype>2));
608 $<itype>3 = $1 == boolean_true_node;
609 skip_evaluation += $<itype>3; }
610 ':' expr_no_commas
611 { skip_evaluation -= $<itype>3;
612 $$ = build_conditional_expr ($1, $<ttype>2, $5); }
613 | expr_no_commas '=' expr_no_commas
614 { $$ = build_modify_expr ($1, NOP_EXPR, $3);
615 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
616 | expr_no_commas ASSIGN expr_no_commas
617 { $$ = build_modify_expr ($1, $2, $3);
618 /* This inhibits warnings in truthvalue_conversion. */
619 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); }
620 ;
621
622 primary:
623 IDENTIFIER
624 {
625 $$ = lastiddecl;
626 if (!$$ || $$ == error_mark_node)
627 {
628 if (yychar == YYEMPTY)
629 yychar = YYLEX;
630 if (yychar == '(')
631 {
632 ifobjc
633 tree decl;
634
635 if (objc_receiver_context
636 && ! (objc_receiver_context
637 && strcmp (IDENTIFIER_POINTER ($1), "super")))
638 /* we have a message to super */
639 $$ = get_super_receiver ();
640 else if (objc_method_context
641 && (decl = is_ivar (objc_ivar_chain, $1)))
642 {
643 if (is_private (decl))
644 $$ = error_mark_node;
645 else
646 $$ = build_ivar_reference ($1);
647 }
648 else
649 end ifobjc
650 {
651 /* Ordinary implicit function declaration. */
652 $$ = implicitly_declare ($1);
653 assemble_external ($$);
654 TREE_USED ($$) = 1;
655 }
656 }
657 else if (current_function_decl == 0)
658 {
659 error ("`%s' undeclared here (not in a function)",
660 IDENTIFIER_POINTER ($1));
661 $$ = error_mark_node;
662 }
663 else
664 {
665 ifobjc
666 tree decl;
667
668 if (objc_receiver_context
669 && ! strcmp (IDENTIFIER_POINTER ($1), "super"))
670 /* we have a message to super */
671 $$ = get_super_receiver ();
672 else if (objc_method_context
673 && (decl = is_ivar (objc_ivar_chain, $1)))
674 {
675 if (is_private (decl))
676 $$ = error_mark_node;
677 else
678 $$ = build_ivar_reference ($1);
679 }
680 else
681 end ifobjc
682 {
683 if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
684 || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
685 {
686 error ("`%s' undeclared (first use this function)",
687 IDENTIFIER_POINTER ($1));
688
689 if (! undeclared_variable_notice)
690 {
691 error ("(Each undeclared identifier is reported only once");
692 error ("for each function it appears in.)");
693 undeclared_variable_notice = 1;
694 }
695 }
696 $$ = error_mark_node;
697 /* Prevent repeated error messages. */
698 IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
699 IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
700 }
701 }
702 }
703 else if (TREE_TYPE ($$) == error_mark_node)
704 $$ = error_mark_node;
705 else if (C_DECL_ANTICIPATED ($$))
706 {
707 /* The first time we see a build-in function used,
708 if it has not been declared. */
709 C_DECL_ANTICIPATED ($$) = 0;
710 if (yychar == YYEMPTY)
711 yychar = YYLEX;
712 if (yychar == '(')
713 {
714 /* Omit the implicit declaration we
715 would ordinarily do, so we don't lose
716 the actual built in type.
717 But print a diagnostic for the mismatch. */
718 ifobjc
719 if (objc_method_context
720 && is_ivar (objc_ivar_chain, $1))
721 error ("Instance variable `%s' implicitly declared as function",
722 IDENTIFIER_POINTER (DECL_NAME ($$)));
723 else
724 end ifobjc
725 if (TREE_CODE ($$) != FUNCTION_DECL)
726 error ("`%s' implicitly declared as function",
727 IDENTIFIER_POINTER (DECL_NAME ($$)));
728 else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
729 != TYPE_MODE (integer_type_node))
730 && (TREE_TYPE (TREE_TYPE ($$))
731 != void_type_node))
732 pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
733 IDENTIFIER_POINTER (DECL_NAME ($$)));
734 /* If it really returns void, change that to int. */
735 if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
736 TREE_TYPE ($$)
737 = build_function_type (integer_type_node,
738 TYPE_ARG_TYPES (TREE_TYPE ($$)));
739 }
740 else
741 pedwarn ("built-in function `%s' used without declaration",
742 IDENTIFIER_POINTER (DECL_NAME ($$)));
743
744 /* Do what we would ordinarily do when a fn is used. */
745 assemble_external ($$);
746 TREE_USED ($$) = 1;
747 }
748 else
749 {
750 assemble_external ($$);
751 TREE_USED ($$) = 1;
752 ifobjc
753 /* we have a definition - still check if iVariable */
754
755 if (!objc_receiver_context
756 || (objc_receiver_context
757 && strcmp (IDENTIFIER_POINTER ($1), "super")))
758 {
759 tree decl;
760
761 if (objc_method_context
762 && (decl = is_ivar (objc_ivar_chain, $1)))
763 {
764 if (IDENTIFIER_LOCAL_VALUE ($1))
765 warning ("local declaration of `%s' hides instance variable",
766 IDENTIFIER_POINTER ($1));
767 else
768 {
769 if (is_private (decl))
770 $$ = error_mark_node;
771 else
772 $$ = build_ivar_reference ($1);
773 }
774 }
775 }
776 else /* we have a message to super */
777 $$ = get_super_receiver ();
778 end ifobjc
779 }
780
781 if (TREE_CODE ($$) == CONST_DECL)
782 {
783 $$ = DECL_INITIAL ($$);
784 /* This is to prevent an enum whose value is 0
785 from being considered a null pointer constant. */
786 $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
787 TREE_CONSTANT ($$) = 1;
788 }
789 }
790 | CONSTANT
791 | string
792 { $$ = combine_strings ($1); }
793 | '(' expr ')'
794 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
795 if (class == 'e' || class == '1'
796 || class == '2' || class == '<')
797 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
798 $$ = $2; }
799 | '(' error ')'
800 { $$ = error_mark_node; }
801 | '('
802 { if (current_function_decl == 0)
803 {
804 error ("braced-group within expression allowed only inside a function");
805 YYERROR;
806 }
807 /* We must force a BLOCK for this level
808 so that, if it is not expanded later,
809 there is a way to turn off the entire subtree of blocks
810 that are contained in it. */
811 keep_next_level ();
812 push_iterator_stack ();
813 push_label_level ();
814 $<ttype>$ = expand_start_stmt_expr (); }
815 compstmt ')'
816 { tree rtl_exp;
817 if (pedantic)
818 pedwarn ("ANSI C forbids braced-groups within expressions");
819 pop_iterator_stack ();
820 pop_label_level ();
821 rtl_exp = expand_end_stmt_expr ($<ttype>2);
822 /* The statements have side effects, so the group does. */
823 TREE_SIDE_EFFECTS (rtl_exp) = 1;
824
825 if (TREE_CODE ($3) == BLOCK)
826 {
827 /* Make a BIND_EXPR for the BLOCK already made. */
828 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
829 NULL_TREE, rtl_exp, $3);
830 /* Remove the block from the tree at this point.
831 It gets put back at the proper place
832 when the BIND_EXPR is expanded. */
833 delete_block ($3);
834 }
835 else
836 $$ = $3;
837 }
838 | primary '(' exprlist ')' %prec '.'
839 { $$ = build_function_call ($1, $3); }
840 | primary '[' expr ']' %prec '.'
841 { $$ = build_array_ref ($1, $3); }
842 | primary '.' identifier
843 {
844 ifobjc
845 if (doing_objc_thang)
846 {
847 if (is_public ($1, $3))
848 $$ = build_component_ref ($1, $3);
849 else
850 $$ = error_mark_node;
851 }
852 else
853 end ifobjc
854 $$ = build_component_ref ($1, $3);
855 }
856 | primary POINTSAT identifier
857 {
858 tree expr = build_indirect_ref ($1, "->");
859
860 ifobjc
861 if (doing_objc_thang)
862 {
863 if (is_public (expr, $3))
864 $$ = build_component_ref (expr, $3);
865 else
866 $$ = error_mark_node;
867 }
868 else
869 end ifobjc
870 $$ = build_component_ref (expr, $3);
871 }
872 | primary PLUSPLUS
873 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
874 | primary MINUSMINUS
875 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
876 ifobjc
877 | objcmessageexpr
878 { $$ = build_message_expr ($1); }
879 | objcselectorexpr
880 { $$ = build_selector_expr ($1); }
881 | objcprotocolexpr
882 { $$ = build_protocol_expr ($1); }
883 | objcencodeexpr
884 { $$ = build_encode_expr ($1); }
885 | objc_string
886 { $$ = build_objc_string_object ($1); }
887 end ifobjc
888 ;
889
890 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
891 string:
892 STRING
893 | string STRING
894 { $$ = chainon ($1, $2); }
895 ;
896
897 ifobjc
898 /* Produces an OBJC_STRING_CST with perhaps more OBJC_STRING_CSTs chained
899 onto it. */
900 objc_string:
901 OBJC_STRING
902 | objc_string OBJC_STRING
903 { $$ = chainon ($1, $2); }
904 ;
905 end ifobjc
906
907 old_style_parm_decls:
908 /* empty */
909 | datadecls
910 | datadecls ELLIPSIS
911 /* ... is used here to indicate a varargs function. */
912 { c_mark_varargs ();
913 if (pedantic)
914 pedwarn ("ANSI C does not permit use of `varargs.h'"); }
915 ;
916
917 /* The following are analogous to lineno_decl, decls and decl
918 except that they do not allow nested functions.
919 They are used for old-style parm decls. */
920 lineno_datadecl:
921 save_filename save_lineno datadecl
922 { }
923 ;
924
925 datadecls:
926 lineno_datadecl
927 | errstmt
928 | datadecls lineno_datadecl
929 | lineno_datadecl errstmt
930 ;
931
932 /* We don't allow prefix attributes here because they cause reduce/reduce
933 conflicts: we can't know whether we're parsing a function decl with
934 attribute suffix, or function defn with attribute prefix on first old
935 style parm. */
936 datadecl:
937 typed_declspecs_no_prefix_attr setspecs initdecls ';'
938 { current_declspecs = TREE_VALUE (declspec_stack);
939 prefix_attributes = TREE_PURPOSE (declspec_stack);
940 declspec_stack = TREE_CHAIN (declspec_stack);
941 resume_momentary ($2); }
942 | declmods_no_prefix_attr setspecs notype_initdecls ';'
943 { current_declspecs = TREE_VALUE (declspec_stack);
944 prefix_attributes = TREE_PURPOSE (declspec_stack);
945 declspec_stack = TREE_CHAIN (declspec_stack);
946 resume_momentary ($2); }
947 | typed_declspecs_no_prefix_attr ';'
948 { shadow_tag_warned ($1, 1);
949 pedwarn ("empty declaration"); }
950 | declmods_no_prefix_attr ';'
951 { pedwarn ("empty declaration"); }
952 ;
953
954 /* This combination which saves a lineno before a decl
955 is the normal thing to use, rather than decl itself.
956 This is to avoid shift/reduce conflicts in contexts
957 where statement labels are allowed. */
958 lineno_decl:
959 save_filename save_lineno decl
960 { }
961 ;
962
963 decls:
964 lineno_decl
965 | errstmt
966 | decls lineno_decl
967 | lineno_decl errstmt
968 ;
969
970 /* records the type and storage class specs to use for processing
971 the declarators that follow.
972 Maintains a stack of outer-level values of current_declspecs,
973 for the sake of parm declarations nested in function declarators. */
974 setspecs: /* empty */
975 { $$ = suspend_momentary ();
976 pending_xref_error ();
977 declspec_stack = tree_cons (prefix_attributes,
978 current_declspecs,
979 declspec_stack);
980 split_specs_attrs ($<ttype>0,
981 &current_declspecs, &prefix_attributes); }
982 ;
983
984 /* ??? Yuck. See after_type_declarator. */
985 setattrs: /* empty */
986 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
987 ;
988
989 decl:
990 typed_declspecs setspecs initdecls ';'
991 { current_declspecs = TREE_VALUE (declspec_stack);
992 prefix_attributes = TREE_PURPOSE (declspec_stack);
993 declspec_stack = TREE_CHAIN (declspec_stack);
994 resume_momentary ($2); }
995 | declmods setspecs notype_initdecls ';'
996 { current_declspecs = TREE_VALUE (declspec_stack);
997 prefix_attributes = TREE_PURPOSE (declspec_stack);
998 declspec_stack = TREE_CHAIN (declspec_stack);
999 resume_momentary ($2); }
1000 | typed_declspecs setspecs nested_function
1001 { current_declspecs = TREE_VALUE (declspec_stack);
1002 prefix_attributes = TREE_PURPOSE (declspec_stack);
1003 declspec_stack = TREE_CHAIN (declspec_stack);
1004 resume_momentary ($2); }
1005 | declmods setspecs notype_nested_function
1006 { current_declspecs = TREE_VALUE (declspec_stack);
1007 prefix_attributes = TREE_PURPOSE (declspec_stack);
1008 declspec_stack = TREE_CHAIN (declspec_stack);
1009 resume_momentary ($2); }
1010 | typed_declspecs ';'
1011 { shadow_tag ($1); }
1012 | declmods ';'
1013 { pedwarn ("empty declaration"); }
1014 | extension decl
1015 { pedantic = $<itype>1; }
1016 ;
1017
1018 /* Declspecs which contain at least one type specifier or typedef name.
1019 (Just `const' or `volatile' is not enough.)
1020 A typedef'd name following these is taken as a name to be declared.
1021 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
1022
1023 typed_declspecs:
1024 typespec reserved_declspecs
1025 { $$ = tree_cons (NULL_TREE, $1, $2); }
1026 | declmods typespec reserved_declspecs
1027 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1028 ;
1029
1030 reserved_declspecs: /* empty */
1031 { $$ = NULL_TREE; }
1032 | reserved_declspecs typespecqual_reserved
1033 { $$ = tree_cons (NULL_TREE, $2, $1); }
1034 | reserved_declspecs SCSPEC
1035 { if (extra_warnings)
1036 warning ("`%s' is not at beginning of declaration",
1037 IDENTIFIER_POINTER ($2));
1038 $$ = tree_cons (NULL_TREE, $2, $1); }
1039 | reserved_declspecs attributes
1040 { $$ = tree_cons ($2, NULL_TREE, $1); }
1041 ;
1042
1043 typed_declspecs_no_prefix_attr:
1044 typespec reserved_declspecs_no_prefix_attr
1045 { $$ = tree_cons (NULL_TREE, $1, $2); }
1046 | declmods_no_prefix_attr typespec reserved_declspecs_no_prefix_attr
1047 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1048 ;
1049
1050 reserved_declspecs_no_prefix_attr:
1051 /* empty */
1052 { $$ = NULL_TREE; }
1053 | reserved_declspecs_no_prefix_attr typespecqual_reserved
1054 { $$ = tree_cons (NULL_TREE, $2, $1); }
1055 | reserved_declspecs_no_prefix_attr SCSPEC
1056 { if (extra_warnings)
1057 warning ("`%s' is not at beginning of declaration",
1058 IDENTIFIER_POINTER ($2));
1059 $$ = tree_cons (NULL_TREE, $2, $1); }
1060 ;
1061
1062 /* List of just storage classes, type modifiers, and prefix attributes.
1063 A declaration can start with just this, but then it cannot be used
1064 to redeclare a typedef-name.
1065 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
1066
1067 declmods:
1068 declmods_no_prefix_attr
1069 { $$ = $1; }
1070 | attributes
1071 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
1072 | declmods declmods_no_prefix_attr
1073 { $$ = chainon ($2, $1); }
1074 | declmods attributes
1075 { $$ = tree_cons ($2, NULL_TREE, $1); }
1076 ;
1077
1078 declmods_no_prefix_attr:
1079 TYPE_QUAL
1080 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
1081 TREE_STATIC ($$) = 1; }
1082 | SCSPEC
1083 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1084 | declmods_no_prefix_attr TYPE_QUAL
1085 { $$ = tree_cons (NULL_TREE, $2, $1);
1086 TREE_STATIC ($$) = 1; }
1087 | declmods_no_prefix_attr SCSPEC
1088 { if (extra_warnings && TREE_STATIC ($1))
1089 warning ("`%s' is not at beginning of declaration",
1090 IDENTIFIER_POINTER ($2));
1091 $$ = tree_cons (NULL_TREE, $2, $1);
1092 TREE_STATIC ($$) = TREE_STATIC ($1); }
1093 ;
1094
1095
1096 /* Used instead of declspecs where storage classes are not allowed
1097 (that is, for typenames and structure components).
1098 Don't accept a typedef-name if anything but a modifier precedes it. */
1099
1100 typed_typespecs:
1101 typespec reserved_typespecquals
1102 { $$ = tree_cons (NULL_TREE, $1, $2); }
1103 | nonempty_type_quals typespec reserved_typespecquals
1104 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1105 ;
1106
1107 reserved_typespecquals: /* empty */
1108 { $$ = NULL_TREE; }
1109 | reserved_typespecquals typespecqual_reserved
1110 { $$ = tree_cons (NULL_TREE, $2, $1); }
1111 ;
1112
1113 /* A typespec (but not a type qualifier).
1114 Once we have seen one of these in a declaration,
1115 if a typedef name appears then it is being redeclared. */
1116
1117 typespec: TYPESPEC
1118 | structsp
1119 | TYPENAME
1120 { /* For a typedef name, record the meaning, not the name.
1121 In case of `foo foo, bar;'. */
1122 $$ = lookup_name ($1); }
1123 ifobjc
1124 | CLASSNAME protocolrefs
1125 { $$ = get_static_reference ($1, $2); }
1126 | OBJECTNAME protocolrefs
1127 { $$ = get_object_reference ($2); }
1128
1129 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>"
1130 - nisse@lysator.liu.se */
1131 | non_empty_protocolrefs
1132 { $$ = get_object_reference ($1); }
1133 end ifobjc
1134 | TYPEOF '(' expr ')'
1135 { $$ = TREE_TYPE ($3); }
1136 | TYPEOF '(' typename ')'
1137 { $$ = groktypename ($3); }
1138 ;
1139
1140 /* A typespec that is a reserved word, or a type qualifier. */
1141
1142 typespecqual_reserved: TYPESPEC
1143 | TYPE_QUAL
1144 | structsp
1145 ;
1146
1147 initdecls:
1148 initdcl
1149 | initdecls ',' initdcl
1150 ;
1151
1152 notype_initdecls:
1153 notype_initdcl
1154 | notype_initdecls ',' initdcl
1155 ;
1156
1157 maybeasm:
1158 /* empty */
1159 { $$ = NULL_TREE; }
1160 | ASM_KEYWORD '(' string ')'
1161 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
1162 $$ = $3;
1163 }
1164 ;
1165
1166 initdcl:
1167 declarator maybeasm maybe_attribute '='
1168 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1169 $3, prefix_attributes);
1170 start_init ($<ttype>$, $2, global_bindings_p ()); }
1171 init
1172 /* Note how the declaration of the variable is in effect while its init is parsed! */
1173 { finish_init ();
1174 finish_decl ($<ttype>5, $6, $2); }
1175 | declarator maybeasm maybe_attribute
1176 { tree d = start_decl ($1, current_declspecs, 0,
1177 $3, prefix_attributes);
1178 finish_decl (d, NULL_TREE, $2);
1179 }
1180 ;
1181
1182 notype_initdcl:
1183 notype_declarator maybeasm maybe_attribute '='
1184 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1185 $3, prefix_attributes);
1186 start_init ($<ttype>$, $2, global_bindings_p ()); }
1187 init
1188 /* Note how the declaration of the variable is in effect while its init is parsed! */
1189 { finish_init ();
1190 decl_attributes ($<ttype>5, $3, prefix_attributes);
1191 finish_decl ($<ttype>5, $6, $2); }
1192 | notype_declarator maybeasm maybe_attribute
1193 { tree d = start_decl ($1, current_declspecs, 0,
1194 $3, prefix_attributes);
1195 finish_decl (d, NULL_TREE, $2); }
1196 ;
1197 /* the * rules are dummies to accept the Apollo extended syntax
1198 so that the header files compile. */
1199 maybe_attribute:
1200 /* empty */
1201 { $$ = NULL_TREE; }
1202 | attributes
1203 { $$ = $1; }
1204 ;
1205
1206 attributes:
1207 attribute
1208 { $$ = $1; }
1209 | attributes attribute
1210 { $$ = chainon ($1, $2); }
1211 ;
1212
1213 attribute:
1214 ATTRIBUTE '(' '(' attribute_list ')' ')'
1215 { $$ = $4; }
1216 ;
1217
1218 attribute_list:
1219 attrib
1220 { $$ = $1; }
1221 | attribute_list ',' attrib
1222 { $$ = chainon ($1, $3); }
1223 ;
1224
1225 attrib:
1226 /* empty */
1227 { $$ = NULL_TREE; }
1228 | any_word
1229 { $$ = build_tree_list ($1, NULL_TREE); }
1230 | any_word '(' IDENTIFIER ')'
1231 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1232 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1233 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1234 | any_word '(' exprlist ')'
1235 { $$ = build_tree_list ($1, $3); }
1236 ;
1237
1238 /* This still leaves out most reserved keywords,
1239 shouldn't we include them? */
1240
1241 any_word:
1242 identifier
1243 | SCSPEC
1244 | TYPESPEC
1245 | TYPE_QUAL
1246 ;
1247 \f
1248 /* Initializers. `init' is the entry point. */
1249
1250 init:
1251 expr_no_commas
1252 | '{'
1253 { really_start_incremental_init (NULL_TREE);
1254 /* Note that the call to clear_momentary
1255 is in process_init_element. */
1256 push_momentary (); }
1257 initlist_maybe_comma '}'
1258 { $$ = pop_init_level (0);
1259 if ($$ == error_mark_node
1260 && ! (yychar == STRING || yychar == CONSTANT))
1261 pop_momentary ();
1262 else
1263 pop_momentary_nofree (); }
1264
1265 | error
1266 { $$ = error_mark_node; }
1267 ;
1268
1269 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1270 initlist_maybe_comma:
1271 /* empty */
1272 { if (pedantic)
1273 pedwarn ("ANSI C forbids empty initializer braces"); }
1274 | initlist1 maybecomma
1275 ;
1276
1277 initlist1:
1278 initelt
1279 | initlist1 ',' initelt
1280 ;
1281
1282 /* `initelt' is a single element of an initializer.
1283 It may use braces. */
1284 initelt:
1285 expr_no_commas
1286 { process_init_element ($1); }
1287 | '{'
1288 { push_init_level (0); }
1289 initlist_maybe_comma '}'
1290 { process_init_element (pop_init_level (0)); }
1291 | error
1292 /* These are for labeled elements. The syntax for an array element
1293 initializer conflicts with the syntax for an Objective-C message,
1294 so don't include these productions in the Objective-C grammar. */
1295 ifc
1296 | '[' expr_no_commas ELLIPSIS expr_no_commas ']' '='
1297 { set_init_index ($2, $4); }
1298 initelt
1299 | '[' expr_no_commas ']' '='
1300 { set_init_index ($2, NULL_TREE); }
1301 initelt
1302 | '[' expr_no_commas ']'
1303 { set_init_index ($2, NULL_TREE); }
1304 initelt
1305 end ifc
1306 | identifier ':'
1307 { set_init_label ($1); }
1308 initelt
1309 | '.' identifier '='
1310 { set_init_label ($2); }
1311 initelt
1312 ;
1313 \f
1314 nested_function:
1315 declarator
1316 { push_c_function_context ();
1317 if (! start_function (current_declspecs, $1,
1318 prefix_attributes, NULL_TREE, 1))
1319 {
1320 pop_c_function_context ();
1321 YYERROR1;
1322 }
1323 reinit_parse_for_function (); }
1324 old_style_parm_decls
1325 { store_parm_decls (); }
1326 /* This used to use compstmt_or_error.
1327 That caused a bug with input `f(g) int g {}',
1328 where the use of YYERROR1 above caused an error
1329 which then was handled by compstmt_or_error.
1330 There followed a repeated execution of that same rule,
1331 which called YYERROR1 again, and so on. */
1332 compstmt
1333 { finish_function (1);
1334 pop_c_function_context (); }
1335 ;
1336
1337 notype_nested_function:
1338 notype_declarator
1339 { push_c_function_context ();
1340 if (! start_function (current_declspecs, $1,
1341 prefix_attributes, NULL_TREE, 1))
1342 {
1343 pop_c_function_context ();
1344 YYERROR1;
1345 }
1346 reinit_parse_for_function (); }
1347 old_style_parm_decls
1348 { store_parm_decls (); }
1349 /* This used to use compstmt_or_error.
1350 That caused a bug with input `f(g) int g {}',
1351 where the use of YYERROR1 above caused an error
1352 which then was handled by compstmt_or_error.
1353 There followed a repeated execution of that same rule,
1354 which called YYERROR1 again, and so on. */
1355 compstmt
1356 { finish_function (1);
1357 pop_c_function_context (); }
1358 ;
1359
1360 /* Any kind of declarator (thus, all declarators allowed
1361 after an explicit typespec). */
1362
1363 declarator:
1364 after_type_declarator
1365 | notype_declarator
1366 ;
1367
1368 /* A declarator that is allowed only after an explicit typespec. */
1369
1370 after_type_declarator:
1371 '(' after_type_declarator ')'
1372 { $$ = $2; }
1373 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1374 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1375 /* | after_type_declarator '(' error ')' %prec '.'
1376 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1377 poplevel (0, 0, 0); } */
1378 | after_type_declarator '[' expr ']' %prec '.'
1379 { $$ = build_nt (ARRAY_REF, $1, $3); }
1380 | after_type_declarator '[' ']' %prec '.'
1381 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1382 | '*' type_quals after_type_declarator %prec UNARY
1383 { $$ = make_pointer_declarator ($2, $3); }
1384 /* ??? Yuck. setattrs is a quick hack. We can't use
1385 prefix_attributes because $1 only applies to this
1386 declarator. We assume setspecs has already been done.
1387 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1388 attributes could be recognized here or in `attributes'). */
1389 | attributes setattrs after_type_declarator
1390 { $$ = $3; }
1391 | TYPENAME
1392 ifobjc
1393 | OBJECTNAME
1394 end ifobjc
1395 ;
1396
1397 /* Kinds of declarator that can appear in a parameter list
1398 in addition to notype_declarator. This is like after_type_declarator
1399 but does not allow a typedef name in parentheses as an identifier
1400 (because it would conflict with a function with that typedef as arg). */
1401
1402 parm_declarator:
1403 parm_declarator '(' parmlist_or_identifiers %prec '.'
1404 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1405 /* | parm_declarator '(' error ')' %prec '.'
1406 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1407 poplevel (0, 0, 0); } */
1408 | parm_declarator '[' expr ']' %prec '.'
1409 { $$ = build_nt (ARRAY_REF, $1, $3); }
1410 | parm_declarator '[' ']' %prec '.'
1411 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1412 | '*' type_quals parm_declarator %prec UNARY
1413 { $$ = make_pointer_declarator ($2, $3); }
1414 /* ??? Yuck. setattrs is a quick hack. We can't use
1415 prefix_attributes because $1 only applies to this
1416 declarator. We assume setspecs has already been done.
1417 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1418 attributes could be recognized here or in `attributes'). */
1419 | attributes setattrs parm_declarator
1420 { $$ = $3; }
1421 | TYPENAME
1422 ;
1423
1424 /* A declarator allowed whether or not there has been
1425 an explicit typespec. These cannot redeclare a typedef-name. */
1426
1427 notype_declarator:
1428 notype_declarator '(' parmlist_or_identifiers %prec '.'
1429 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1430 /* | notype_declarator '(' error ')' %prec '.'
1431 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1432 poplevel (0, 0, 0); } */
1433 | '(' notype_declarator ')'
1434 { $$ = $2; }
1435 | '*' type_quals notype_declarator %prec UNARY
1436 { $$ = make_pointer_declarator ($2, $3); }
1437 | notype_declarator '[' expr ']' %prec '.'
1438 { $$ = build_nt (ARRAY_REF, $1, $3); }
1439 | notype_declarator '[' ']' %prec '.'
1440 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1441 /* ??? Yuck. setattrs is a quick hack. We can't use
1442 prefix_attributes because $1 only applies to this
1443 declarator. We assume setspecs has already been done.
1444 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1445 attributes could be recognized here or in `attributes'). */
1446 | attributes setattrs notype_declarator
1447 { $$ = $3; }
1448 | IDENTIFIER
1449 ;
1450
1451 structsp:
1452 STRUCT identifier '{'
1453 { $$ = start_struct (RECORD_TYPE, $2);
1454 /* Start scope of tag before parsing components. */
1455 }
1456 component_decl_list '}' maybe_attribute
1457 { $$ = finish_struct ($<ttype>4, $5, $7); }
1458 | STRUCT '{' component_decl_list '}' maybe_attribute
1459 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1460 $3, $5);
1461 }
1462 | STRUCT identifier
1463 { $$ = xref_tag (RECORD_TYPE, $2); }
1464 | UNION identifier '{'
1465 { $$ = start_struct (UNION_TYPE, $2); }
1466 component_decl_list '}' maybe_attribute
1467 { $$ = finish_struct ($<ttype>4, $5, $7); }
1468 | UNION '{' component_decl_list '}' maybe_attribute
1469 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1470 $3, $5);
1471 }
1472 | UNION identifier
1473 { $$ = xref_tag (UNION_TYPE, $2); }
1474 | ENUM identifier '{'
1475 { $<itype>3 = suspend_momentary ();
1476 $$ = start_enum ($2); }
1477 enumlist maybecomma_warn '}' maybe_attribute
1478 { $$ = finish_enum ($<ttype>4, nreverse ($5), $8);
1479 resume_momentary ($<itype>3); }
1480 | ENUM '{'
1481 { $<itype>2 = suspend_momentary ();
1482 $$ = start_enum (NULL_TREE); }
1483 enumlist maybecomma_warn '}' maybe_attribute
1484 { $$ = finish_enum ($<ttype>3, nreverse ($4), $7);
1485 resume_momentary ($<itype>2); }
1486 | ENUM identifier
1487 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1488 ;
1489
1490 maybecomma:
1491 /* empty */
1492 | ','
1493 ;
1494
1495 maybecomma_warn:
1496 /* empty */
1497 | ','
1498 { if (pedantic) pedwarn ("comma at end of enumerator list"); }
1499 ;
1500
1501 component_decl_list:
1502 component_decl_list2
1503 { $$ = $1; }
1504 | component_decl_list2 component_decl
1505 { $$ = chainon ($1, $2);
1506 pedwarn ("no semicolon at end of struct or union"); }
1507 ;
1508
1509 component_decl_list2: /* empty */
1510 { $$ = NULL_TREE; }
1511 | component_decl_list2 component_decl ';'
1512 { $$ = chainon ($1, $2); }
1513 | component_decl_list2 ';'
1514 { if (pedantic)
1515 pedwarn ("extra semicolon in struct or union specified"); }
1516 ifobjc
1517 /* foo(sizeof(struct{ @defs(ClassName)})); */
1518 | DEFS '(' CLASSNAME ')'
1519 {
1520 tree interface = lookup_interface ($3);
1521
1522 if (interface)
1523 $$ = get_class_ivars (interface);
1524 else
1525 {
1526 error ("Cannot find interface declaration for `%s'",
1527 IDENTIFIER_POINTER ($3));
1528 $$ = NULL_TREE;
1529 }
1530 }
1531 end ifobjc
1532 ;
1533
1534 /* There is a shift-reduce conflict here, because `components' may
1535 start with a `typename'. It happens that shifting (the default resolution)
1536 does the right thing, because it treats the `typename' as part of
1537 a `typed_typespecs'.
1538
1539 It is possible that this same technique would allow the distinction
1540 between `notype_initdecls' and `initdecls' to be eliminated.
1541 But I am being cautious and not trying it. */
1542
1543 component_decl:
1544 typed_typespecs setspecs components
1545 { $$ = $3;
1546 current_declspecs = TREE_VALUE (declspec_stack);
1547 prefix_attributes = TREE_PURPOSE (declspec_stack);
1548 declspec_stack = TREE_CHAIN (declspec_stack);
1549 resume_momentary ($2); }
1550 | typed_typespecs
1551 { if (pedantic)
1552 pedwarn ("ANSI C forbids member declarations with no members");
1553 shadow_tag($1);
1554 $$ = NULL_TREE; }
1555 | nonempty_type_quals setspecs components
1556 { $$ = $3;
1557 current_declspecs = TREE_VALUE (declspec_stack);
1558 prefix_attributes = TREE_PURPOSE (declspec_stack);
1559 declspec_stack = TREE_CHAIN (declspec_stack);
1560 resume_momentary ($2); }
1561 | nonempty_type_quals
1562 { if (pedantic)
1563 pedwarn ("ANSI C forbids member declarations with no members");
1564 shadow_tag($1);
1565 $$ = NULL_TREE; }
1566 | error
1567 { $$ = NULL_TREE; }
1568 | extension component_decl
1569 { $$ = $2;
1570 pedantic = $<itype>1; }
1571 ;
1572
1573 components:
1574 component_declarator
1575 | components ',' component_declarator
1576 { $$ = chainon ($1, $3); }
1577 ;
1578
1579 component_declarator:
1580 save_filename save_lineno declarator maybe_attribute
1581 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1582 decl_attributes ($$, $4, prefix_attributes); }
1583 | save_filename save_lineno
1584 declarator ':' expr_no_commas maybe_attribute
1585 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1586 decl_attributes ($$, $6, prefix_attributes); }
1587 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1588 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1589 decl_attributes ($$, $5, prefix_attributes); }
1590 ;
1591
1592 /* We chain the enumerators in reverse order.
1593 They are put in forward order where enumlist is used.
1594 (The order used to be significant, but no longer is so.
1595 However, we still maintain the order, just to be clean.) */
1596
1597 enumlist:
1598 enumerator
1599 | enumlist ',' enumerator
1600 { if ($1 == error_mark_node)
1601 $$ = $1;
1602 else
1603 $$ = chainon ($3, $1); }
1604 | error
1605 { $$ = error_mark_node; }
1606 ;
1607
1608
1609 enumerator:
1610 identifier
1611 { $$ = build_enumerator ($1, NULL_TREE); }
1612 | identifier '=' expr_no_commas
1613 { $$ = build_enumerator ($1, $3); }
1614 ;
1615
1616 typename:
1617 typed_typespecs absdcl
1618 { $$ = build_tree_list ($1, $2); }
1619 | nonempty_type_quals absdcl
1620 { $$ = build_tree_list ($1, $2); }
1621 ;
1622
1623 absdcl: /* an absolute declarator */
1624 /* empty */
1625 { $$ = NULL_TREE; }
1626 | absdcl1
1627 ;
1628
1629 nonempty_type_quals:
1630 TYPE_QUAL
1631 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1632 | nonempty_type_quals TYPE_QUAL
1633 { $$ = tree_cons (NULL_TREE, $2, $1); }
1634 ;
1635
1636 type_quals:
1637 /* empty */
1638 { $$ = NULL_TREE; }
1639 | type_quals TYPE_QUAL
1640 { $$ = tree_cons (NULL_TREE, $2, $1); }
1641 ;
1642
1643 absdcl1: /* a nonempty absolute declarator */
1644 '(' absdcl1 ')'
1645 { $$ = $2; }
1646 /* `(typedef)1' is `int'. */
1647 | '*' type_quals absdcl1 %prec UNARY
1648 { $$ = make_pointer_declarator ($2, $3); }
1649 | '*' type_quals %prec UNARY
1650 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1651 | absdcl1 '(' parmlist %prec '.'
1652 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1653 | absdcl1 '[' expr ']' %prec '.'
1654 { $$ = build_nt (ARRAY_REF, $1, $3); }
1655 | absdcl1 '[' ']' %prec '.'
1656 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1657 | '(' parmlist %prec '.'
1658 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1659 | '[' expr ']' %prec '.'
1660 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1661 | '[' ']' %prec '.'
1662 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1663 /* ??? It appears we have to support attributes here, however
1664 using prefix_attributes is wrong. */
1665 ;
1666
1667 /* at least one statement, the first of which parses without error. */
1668 /* stmts is used only after decls, so an invalid first statement
1669 is actually regarded as an invalid decl and part of the decls. */
1670
1671 stmts:
1672 lineno_stmt_or_labels
1673 {
1674 if (pedantic && $1)
1675 pedwarn ("ANSI C forbids label at end of compound statement");
1676 }
1677 ;
1678
1679 lineno_stmt_or_labels:
1680 lineno_stmt_or_label
1681 | lineno_stmt_or_labels lineno_stmt_or_label
1682 { $$ = $2; }
1683 | lineno_stmt_or_labels errstmt
1684 { $$ = 0; }
1685 ;
1686
1687 xstmts:
1688 /* empty */
1689 | stmts
1690 ;
1691
1692 errstmt: error ';'
1693 ;
1694
1695 pushlevel: /* empty */
1696 { emit_line_note (input_filename, lineno);
1697 pushlevel (0);
1698 clear_last_expr ();
1699 push_momentary ();
1700 expand_start_bindings (0);
1701 ifobjc
1702 if (objc_method_context)
1703 add_objc_decls ();
1704 end ifobjc
1705 }
1706 ;
1707
1708 /* Read zero or more forward-declarations for labels
1709 that nested functions can jump to. */
1710 maybe_label_decls:
1711 /* empty */
1712 | label_decls
1713 { if (pedantic)
1714 pedwarn ("ANSI C forbids label declarations"); }
1715 ;
1716
1717 label_decls:
1718 label_decl
1719 | label_decls label_decl
1720 ;
1721
1722 label_decl:
1723 LABEL identifiers_or_typenames ';'
1724 { tree link;
1725 for (link = $2; link; link = TREE_CHAIN (link))
1726 {
1727 tree label = shadow_label (TREE_VALUE (link));
1728 C_DECLARED_LABEL_FLAG (label) = 1;
1729 declare_nonlocal_label (label);
1730 }
1731 }
1732 ;
1733
1734 /* This is the body of a function definition.
1735 It causes syntax errors to ignore to the next openbrace. */
1736 compstmt_or_error:
1737 compstmt
1738 {}
1739 | error compstmt
1740 ;
1741
1742 compstmt: '{' '}'
1743 { $$ = convert (void_type_node, integer_zero_node); }
1744 | '{' pushlevel maybe_label_decls decls xstmts '}'
1745 { emit_line_note (input_filename, lineno);
1746 expand_end_bindings (getdecls (), 1, 0);
1747 $$ = poplevel (1, 1, 0);
1748 if (yychar == CONSTANT || yychar == STRING)
1749 pop_momentary_nofree ();
1750 else
1751 pop_momentary (); }
1752 | '{' pushlevel maybe_label_decls error '}'
1753 { emit_line_note (input_filename, lineno);
1754 expand_end_bindings (getdecls (), kept_level_p (), 0);
1755 $$ = poplevel (kept_level_p (), 0, 0);
1756 if (yychar == CONSTANT || yychar == STRING)
1757 pop_momentary_nofree ();
1758 else
1759 pop_momentary (); }
1760 | '{' pushlevel maybe_label_decls stmts '}'
1761 { emit_line_note (input_filename, lineno);
1762 expand_end_bindings (getdecls (), kept_level_p (), 0);
1763 $$ = poplevel (kept_level_p (), 0, 0);
1764 if (yychar == CONSTANT || yychar == STRING)
1765 pop_momentary_nofree ();
1766 else
1767 pop_momentary (); }
1768 ;
1769
1770 /* Value is number of statements counted as of the closeparen. */
1771 simple_if:
1772 if_prefix lineno_labeled_stmt
1773 /* Make sure expand_end_cond is run once
1774 for each call to expand_start_cond.
1775 Otherwise a crash is likely. */
1776 | if_prefix error
1777 ;
1778
1779 if_prefix:
1780 IF '(' expr ')'
1781 { emit_line_note ($<filename>-1, $<lineno>0);
1782 expand_start_cond (truthvalue_conversion ($3), 0);
1783 $<itype>$ = stmt_count;
1784 if_stmt_file = $<filename>-1;
1785 if_stmt_line = $<lineno>0;
1786 position_after_white_space (); }
1787 ;
1788
1789 /* This is a subroutine of stmt.
1790 It is used twice, once for valid DO statements
1791 and once for catching errors in parsing the end test. */
1792 do_stmt_start:
1793 DO
1794 { stmt_count++;
1795 emit_line_note ($<filename>-1, $<lineno>0);
1796 /* See comment in `while' alternative, above. */
1797 emit_nop ();
1798 expand_start_loop_continue_elsewhere (1);
1799 position_after_white_space (); }
1800 lineno_labeled_stmt WHILE
1801 { expand_loop_continue_here (); }
1802 ;
1803
1804 save_filename:
1805 { $$ = input_filename; }
1806 ;
1807
1808 save_lineno:
1809 { $$ = lineno; }
1810 ;
1811
1812 lineno_labeled_stmt:
1813 save_filename save_lineno stmt
1814 { }
1815 /* | save_filename save_lineno error
1816 { }
1817 */
1818 | save_filename save_lineno label lineno_labeled_stmt
1819 { }
1820 ;
1821
1822 lineno_stmt_or_label:
1823 save_filename save_lineno stmt_or_label
1824 { $$ = $3; }
1825 ;
1826
1827 stmt_or_label:
1828 stmt
1829 { $$ = 0; }
1830 | label
1831 { $$ = 1; }
1832 ;
1833
1834 /* Parse a single real statement, not including any labels. */
1835 stmt:
1836 compstmt
1837 { stmt_count++; }
1838 | all_iter_stmt
1839 | expr ';'
1840 { stmt_count++;
1841 emit_line_note ($<filename>-1, $<lineno>0);
1842 /* It appears that this should not be done--that a non-lvalue array
1843 shouldn't get an error if the value isn't used.
1844 Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1845 if it appears as a top-level expression,
1846 but says nothing about non-lvalue arrays. */
1847 #if 0
1848 /* Call default_conversion to get an error
1849 on referring to a register array if pedantic. */
1850 if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1851 || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1852 $1 = default_conversion ($1);
1853 #endif
1854 iterator_expand ($1);
1855 clear_momentary (); }
1856 | simple_if ELSE
1857 { expand_start_else ();
1858 $<itype>1 = stmt_count;
1859 position_after_white_space (); }
1860 lineno_labeled_stmt
1861 { expand_end_cond ();
1862 if (extra_warnings && stmt_count == $<itype>1)
1863 warning ("empty body in an else-statement"); }
1864 | simple_if %prec IF
1865 { expand_end_cond ();
1866 /* This warning is here instead of in simple_if, because we
1867 do not want a warning if an empty if is followed by an
1868 else statement. Increment stmt_count so we don't
1869 give a second error if this is a nested `if'. */
1870 if (extra_warnings && stmt_count++ == $<itype>1)
1871 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1872 "empty body in an if-statement"); }
1873 /* Make sure expand_end_cond is run once
1874 for each call to expand_start_cond.
1875 Otherwise a crash is likely. */
1876 | simple_if ELSE error
1877 { expand_end_cond (); }
1878 | WHILE
1879 { stmt_count++;
1880 emit_line_note ($<filename>-1, $<lineno>0);
1881 /* The emit_nop used to come before emit_line_note,
1882 but that made the nop seem like part of the preceding line.
1883 And that was confusing when the preceding line was
1884 inside of an if statement and was not really executed.
1885 I think it ought to work to put the nop after the line number.
1886 We will see. --rms, July 15, 1991. */
1887 emit_nop (); }
1888 '(' expr ')'
1889 { /* Don't start the loop till we have succeeded
1890 in parsing the end test. This is to make sure
1891 that we end every loop we start. */
1892 expand_start_loop (1);
1893 emit_line_note (input_filename, lineno);
1894 expand_exit_loop_if_false (NULL_PTR,
1895 truthvalue_conversion ($4));
1896 position_after_white_space (); }
1897 lineno_labeled_stmt
1898 { expand_end_loop (); }
1899 | do_stmt_start
1900 '(' expr ')' ';'
1901 { emit_line_note (input_filename, lineno);
1902 expand_exit_loop_if_false (NULL_PTR,
1903 truthvalue_conversion ($3));
1904 expand_end_loop ();
1905 clear_momentary (); }
1906 /* This rule is needed to make sure we end every loop we start. */
1907 | do_stmt_start error
1908 { expand_end_loop ();
1909 clear_momentary (); }
1910 | FOR
1911 '(' xexpr ';'
1912 { stmt_count++;
1913 emit_line_note ($<filename>-1, $<lineno>0);
1914 /* See comment in `while' alternative, above. */
1915 emit_nop ();
1916 if ($3) c_expand_expr_stmt ($3);
1917 /* Next step is to call expand_start_loop_continue_elsewhere,
1918 but wait till after we parse the entire for (...).
1919 Otherwise, invalid input might cause us to call that
1920 fn without calling expand_end_loop. */
1921 }
1922 xexpr ';'
1923 /* Can't emit now; wait till after expand_start_loop... */
1924 { $<lineno>7 = lineno;
1925 $<filename>$ = input_filename; }
1926 xexpr ')'
1927 {
1928 /* Start the loop. Doing this after parsing
1929 all the expressions ensures we will end the loop. */
1930 expand_start_loop_continue_elsewhere (1);
1931 /* Emit the end-test, with a line number. */
1932 emit_line_note ($<filename>8, $<lineno>7);
1933 if ($6)
1934 expand_exit_loop_if_false (NULL_PTR,
1935 truthvalue_conversion ($6));
1936 /* Don't let the tree nodes for $9 be discarded by
1937 clear_momentary during the parsing of the next stmt. */
1938 push_momentary ();
1939 $<lineno>7 = lineno;
1940 $<filename>8 = input_filename;
1941 position_after_white_space (); }
1942 lineno_labeled_stmt
1943 { /* Emit the increment expression, with a line number. */
1944 emit_line_note ($<filename>8, $<lineno>7);
1945 expand_loop_continue_here ();
1946 if ($9)
1947 c_expand_expr_stmt ($9);
1948 if (yychar == CONSTANT || yychar == STRING)
1949 pop_momentary_nofree ();
1950 else
1951 pop_momentary ();
1952 expand_end_loop (); }
1953 | SWITCH '(' expr ')'
1954 { stmt_count++;
1955 emit_line_note ($<filename>-1, $<lineno>0);
1956 c_expand_start_case ($3);
1957 /* Don't let the tree nodes for $3 be discarded by
1958 clear_momentary during the parsing of the next stmt. */
1959 push_momentary ();
1960 position_after_white_space (); }
1961 lineno_labeled_stmt
1962 { expand_end_case ($3);
1963 if (yychar == CONSTANT || yychar == STRING)
1964 pop_momentary_nofree ();
1965 else
1966 pop_momentary (); }
1967 | BREAK ';'
1968 { stmt_count++;
1969 emit_line_note ($<filename>-1, $<lineno>0);
1970 if ( ! expand_exit_something ())
1971 error ("break statement not within loop or switch"); }
1972 | CONTINUE ';'
1973 { stmt_count++;
1974 emit_line_note ($<filename>-1, $<lineno>0);
1975 if (! expand_continue_loop (NULL_PTR))
1976 error ("continue statement not within a loop"); }
1977 | RETURN ';'
1978 { stmt_count++;
1979 emit_line_note ($<filename>-1, $<lineno>0);
1980 c_expand_return (NULL_TREE); }
1981 | RETURN expr ';'
1982 { stmt_count++;
1983 emit_line_note ($<filename>-1, $<lineno>0);
1984 c_expand_return ($2); }
1985 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
1986 { stmt_count++;
1987 emit_line_note ($<filename>-1, $<lineno>0);
1988 STRIP_NOPS ($4);
1989 if ((TREE_CODE ($4) == ADDR_EXPR
1990 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
1991 || TREE_CODE ($4) == STRING_CST)
1992 expand_asm ($4);
1993 else
1994 error ("argument of `asm' is not a constant string"); }
1995 /* This is the case with just output operands. */
1996 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
1997 { stmt_count++;
1998 emit_line_note ($<filename>-1, $<lineno>0);
1999 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
2000 $2 == ridpointers[(int)RID_VOLATILE],
2001 input_filename, lineno); }
2002 /* This is the case with input operands as well. */
2003 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
2004 { stmt_count++;
2005 emit_line_note ($<filename>-1, $<lineno>0);
2006 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
2007 $2 == ridpointers[(int)RID_VOLATILE],
2008 input_filename, lineno); }
2009 /* This is the case with clobbered registers as well. */
2010 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
2011 asm_operands ':' asm_clobbers ')' ';'
2012 { stmt_count++;
2013 emit_line_note ($<filename>-1, $<lineno>0);
2014 c_expand_asm_operands ($4, $6, $8, $10,
2015 $2 == ridpointers[(int)RID_VOLATILE],
2016 input_filename, lineno); }
2017 | GOTO identifier ';'
2018 { tree decl;
2019 stmt_count++;
2020 emit_line_note ($<filename>-1, $<lineno>0);
2021 decl = lookup_label ($2);
2022 if (decl != 0)
2023 {
2024 TREE_USED (decl) = 1;
2025 expand_goto (decl);
2026 }
2027 }
2028 | GOTO '*' expr ';'
2029 { if (pedantic)
2030 pedwarn ("ANSI C forbids `goto *expr;'");
2031 stmt_count++;
2032 emit_line_note ($<filename>-1, $<lineno>0);
2033 expand_computed_goto (convert (ptr_type_node, $3)); }
2034 | ';'
2035 ;
2036
2037 all_iter_stmt:
2038 all_iter_stmt_simple
2039 /* | all_iter_stmt_with_decl */
2040 ;
2041
2042 all_iter_stmt_simple:
2043 FOR '(' primary ')'
2044 {
2045 /* The value returned by this action is */
2046 /* 1 if everything is OK */
2047 /* 0 in case of error or already bound iterator */
2048
2049 $<itype>$ = 0;
2050 if (TREE_CODE ($3) != VAR_DECL)
2051 error ("invalid `for (ITERATOR)' syntax");
2052 else if (! ITERATOR_P ($3))
2053 error ("`%s' is not an iterator",
2054 IDENTIFIER_POINTER (DECL_NAME ($3)));
2055 else if (ITERATOR_BOUND_P ($3))
2056 error ("`for (%s)' inside expansion of same iterator",
2057 IDENTIFIER_POINTER (DECL_NAME ($3)));
2058 else
2059 {
2060 $<itype>$ = 1;
2061 iterator_for_loop_start ($3);
2062 }
2063 }
2064 lineno_labeled_stmt
2065 {
2066 if ($<itype>5)
2067 iterator_for_loop_end ($3);
2068 }
2069
2070 /* This really should allow any kind of declaration,
2071 for generality. Fix it before turning it back on.
2072
2073 all_iter_stmt_with_decl:
2074 FOR '(' ITERATOR pushlevel setspecs iterator_spec ')'
2075 {
2076 */ /* The value returned by this action is */
2077 /* 1 if everything is OK */
2078 /* 0 in case of error or already bound iterator */
2079 /*
2080 iterator_for_loop_start ($6);
2081 }
2082 lineno_labeled_stmt
2083 {
2084 iterator_for_loop_end ($6);
2085 emit_line_note (input_filename, lineno);
2086 expand_end_bindings (getdecls (), 1, 0);
2087 $<ttype>$ = poplevel (1, 1, 0);
2088 if (yychar == CONSTANT || yychar == STRING)
2089 pop_momentary_nofree ();
2090 else
2091 pop_momentary ();
2092 }
2093 */
2094
2095 /* Any kind of label, including jump labels and case labels.
2096 ANSI C accepts labels only before statements, but we allow them
2097 also at the end of a compound statement. */
2098
2099 label: CASE expr_no_commas ':'
2100 { register tree value = check_case_value ($2);
2101 register tree label
2102 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2103
2104 stmt_count++;
2105
2106 if (value != error_mark_node)
2107 {
2108 tree duplicate;
2109 int success = pushcase (value, convert_and_check,
2110 label, &duplicate);
2111 if (success == 1)
2112 error ("case label not within a switch statement");
2113 else if (success == 2)
2114 {
2115 error ("duplicate case value");
2116 error_with_decl (duplicate, "this is the first entry for that value");
2117 }
2118 else if (success == 3)
2119 warning ("case value out of range");
2120 else if (success == 5)
2121 error ("case label within scope of cleanup or variable array");
2122 }
2123 position_after_white_space (); }
2124 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
2125 { register tree value1 = check_case_value ($2);
2126 register tree value2 = check_case_value ($4);
2127 register tree label
2128 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2129
2130 if (pedantic)
2131 pedwarn ("ANSI C forbids case ranges");
2132 stmt_count++;
2133
2134 if (value1 != error_mark_node && value2 != error_mark_node)
2135 {
2136 tree duplicate;
2137 int success = pushcase_range (value1, value2,
2138 convert_and_check, label,
2139 &duplicate);
2140 if (success == 1)
2141 error ("case label not within a switch statement");
2142 else if (success == 2)
2143 {
2144 error ("duplicate case value");
2145 error_with_decl (duplicate, "this is the first entry for that value");
2146 }
2147 else if (success == 3)
2148 warning ("case value out of range");
2149 else if (success == 4)
2150 warning ("empty case range");
2151 else if (success == 5)
2152 error ("case label within scope of cleanup or variable array");
2153 }
2154 position_after_white_space (); }
2155 | DEFAULT ':'
2156 {
2157 tree duplicate;
2158 register tree label
2159 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2160 int success = pushcase (NULL_TREE, 0, label, &duplicate);
2161 stmt_count++;
2162 if (success == 1)
2163 error ("default label not within a switch statement");
2164 else if (success == 2)
2165 {
2166 error ("multiple default labels in one switch");
2167 error_with_decl (duplicate, "this is the first default label");
2168 }
2169 position_after_white_space (); }
2170 | identifier ':'
2171 { tree label = define_label (input_filename, lineno, $1);
2172 stmt_count++;
2173 emit_nop ();
2174 if (label)
2175 expand_label (label);
2176 position_after_white_space (); }
2177 ;
2178
2179 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
2180
2181 maybe_type_qual:
2182 /* empty */
2183 { emit_line_note (input_filename, lineno);
2184 $$ = NULL_TREE; }
2185 | TYPE_QUAL
2186 { emit_line_note (input_filename, lineno); }
2187 ;
2188
2189 xexpr:
2190 /* empty */
2191 { $$ = NULL_TREE; }
2192 | expr
2193 ;
2194
2195 /* These are the operands other than the first string and colon
2196 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2197 asm_operands: /* empty */
2198 { $$ = NULL_TREE; }
2199 | nonnull_asm_operands
2200 ;
2201
2202 nonnull_asm_operands:
2203 asm_operand
2204 | nonnull_asm_operands ',' asm_operand
2205 { $$ = chainon ($1, $3); }
2206 ;
2207
2208 asm_operand:
2209 STRING '(' expr ')'
2210 { $$ = build_tree_list ($1, $3); }
2211 ;
2212
2213 asm_clobbers:
2214 string
2215 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
2216 | asm_clobbers ',' string
2217 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
2218 ;
2219 \f
2220 /* This is what appears inside the parens in a function declarator.
2221 Its value is a list of ..._TYPE nodes. */
2222 parmlist:
2223 { pushlevel (0);
2224 clear_parm_order ();
2225 declare_parm_level (0); }
2226 parmlist_1
2227 { $$ = $2;
2228 parmlist_tags_warning ();
2229 poplevel (0, 0, 0); }
2230 ;
2231
2232 parmlist_1:
2233 parmlist_2 ')'
2234 | parms ';'
2235 { tree parm;
2236 if (pedantic)
2237 pedwarn ("ANSI C forbids forward parameter declarations");
2238 /* Mark the forward decls as such. */
2239 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2240 TREE_ASM_WRITTEN (parm) = 1;
2241 clear_parm_order (); }
2242 parmlist_1
2243 { $$ = $4; }
2244 | error ')'
2245 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2246 ;
2247
2248 /* This is what appears inside the parens in a function declarator.
2249 Is value is represented in the format that grokdeclarator expects. */
2250 parmlist_2: /* empty */
2251 { $$ = get_parm_info (0); }
2252 | ELLIPSIS
2253 { $$ = get_parm_info (0);
2254 /* Gcc used to allow this as an extension. However, it does
2255 not work for all targets, and thus has been disabled.
2256 Also, since func (...) and func () are indistinguishable,
2257 it caused problems with the code in expand_builtin which
2258 tries to verify that BUILT_IN_NEXT_ARG is being used
2259 correctly. */
2260 error ("ANSI C requires a named argument before `...'");
2261 }
2262 | parms
2263 { $$ = get_parm_info (1); }
2264 | parms ',' ELLIPSIS
2265 { $$ = get_parm_info (0); }
2266 ;
2267
2268 parms:
2269 parm
2270 { push_parm_decl ($1); }
2271 | parms ',' parm
2272 { push_parm_decl ($3); }
2273 ;
2274
2275 /* A single parameter declaration or parameter type name,
2276 as found in a parmlist. */
2277 parm:
2278 typed_declspecs setspecs parm_declarator maybe_attribute
2279 { $$ = build_tree_list (build_tree_list (current_declspecs,
2280 $3),
2281 build_tree_list (prefix_attributes,
2282 $4));
2283 current_declspecs = TREE_VALUE (declspec_stack);
2284 prefix_attributes = TREE_PURPOSE (declspec_stack);
2285 declspec_stack = TREE_CHAIN (declspec_stack);
2286 resume_momentary ($2); }
2287 | typed_declspecs setspecs notype_declarator maybe_attribute
2288 { $$ = build_tree_list (build_tree_list (current_declspecs,
2289 $3),
2290 build_tree_list (prefix_attributes,
2291 $4));
2292 current_declspecs = TREE_VALUE (declspec_stack);
2293 prefix_attributes = TREE_PURPOSE (declspec_stack);
2294 declspec_stack = TREE_CHAIN (declspec_stack);
2295 resume_momentary ($2); }
2296 | typed_declspecs setspecs absdcl maybe_attribute
2297 { $$ = build_tree_list (build_tree_list (current_declspecs,
2298 $3),
2299 build_tree_list (prefix_attributes,
2300 $4));
2301 current_declspecs = TREE_VALUE (declspec_stack);
2302 prefix_attributes = TREE_PURPOSE (declspec_stack);
2303 declspec_stack = TREE_CHAIN (declspec_stack);
2304 resume_momentary ($2); }
2305 | declmods setspecs notype_declarator maybe_attribute
2306 { $$ = build_tree_list (build_tree_list (current_declspecs,
2307 $3),
2308 build_tree_list (prefix_attributes,
2309 $4));
2310 current_declspecs = TREE_VALUE (declspec_stack);
2311 prefix_attributes = TREE_PURPOSE (declspec_stack);
2312 declspec_stack = TREE_CHAIN (declspec_stack);
2313 resume_momentary ($2); }
2314
2315 | declmods setspecs absdcl maybe_attribute
2316 { $$ = build_tree_list (build_tree_list (current_declspecs,
2317 $3),
2318 build_tree_list (prefix_attributes,
2319 $4));
2320 current_declspecs = TREE_VALUE (declspec_stack);
2321 prefix_attributes = TREE_PURPOSE (declspec_stack);
2322 declspec_stack = TREE_CHAIN (declspec_stack);
2323 resume_momentary ($2); }
2324 ;
2325
2326 /* This is used in a function definition
2327 where either a parmlist or an identifier list is ok.
2328 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2329 parmlist_or_identifiers:
2330 { pushlevel (0);
2331 clear_parm_order ();
2332 declare_parm_level (1); }
2333 parmlist_or_identifiers_1
2334 { $$ = $2;
2335 parmlist_tags_warning ();
2336 poplevel (0, 0, 0); }
2337 ;
2338
2339 parmlist_or_identifiers_1:
2340 parmlist_1
2341 | identifiers ')'
2342 { tree t;
2343 for (t = $1; t; t = TREE_CHAIN (t))
2344 if (TREE_VALUE (t) == NULL_TREE)
2345 error ("`...' in old-style identifier list");
2346 $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2347 ;
2348
2349 /* A nonempty list of identifiers. */
2350 identifiers:
2351 IDENTIFIER
2352 { $$ = build_tree_list (NULL_TREE, $1); }
2353 | identifiers ',' IDENTIFIER
2354 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2355 ;
2356
2357 /* A nonempty list of identifiers, including typenames. */
2358 identifiers_or_typenames:
2359 identifier
2360 { $$ = build_tree_list (NULL_TREE, $1); }
2361 | identifiers_or_typenames ',' identifier
2362 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2363 ;
2364
2365 extension:
2366 EXTENSION
2367 { $<itype>$ = pedantic;
2368 pedantic = 0; }
2369 ;
2370 \f
2371 ifobjc
2372 /* Objective-C productions. */
2373
2374 objcdef:
2375 classdef
2376 | classdecl
2377 | aliasdecl
2378 | protocoldef
2379 | methoddef
2380 | END
2381 {
2382 if (objc_implementation_context)
2383 {
2384 finish_class (objc_implementation_context);
2385 objc_ivar_chain = NULL_TREE;
2386 objc_implementation_context = NULL_TREE;
2387 }
2388 else
2389 warning ("`@end' must appear in an implementation context");
2390 }
2391 ;
2392
2393 /* A nonempty list of identifiers. */
2394 identifier_list:
2395 identifier
2396 { $$ = build_tree_list (NULL_TREE, $1); }
2397 | identifier_list ',' identifier
2398 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2399 ;
2400
2401 classdecl:
2402 CLASS identifier_list ';'
2403 {
2404 objc_declare_class ($2);
2405 }
2406
2407 aliasdecl:
2408 ALIAS identifier identifier ';'
2409 {
2410 objc_declare_alias ($2, $3);
2411 }
2412
2413 classdef:
2414 INTERFACE identifier protocolrefs '{'
2415 {
2416 objc_interface_context = objc_ivar_context
2417 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2418 objc_public_flag = 0;
2419 }
2420 ivar_decl_list '}'
2421 {
2422 continue_class (objc_interface_context);
2423 }
2424 methodprotolist
2425 END
2426 {
2427 finish_class (objc_interface_context);
2428 objc_interface_context = NULL_TREE;
2429 }
2430
2431 | INTERFACE identifier protocolrefs
2432 {
2433 objc_interface_context
2434 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2435 continue_class (objc_interface_context);
2436 }
2437 methodprotolist
2438 END
2439 {
2440 finish_class (objc_interface_context);
2441 objc_interface_context = NULL_TREE;
2442 }
2443
2444 | INTERFACE identifier ':' identifier protocolrefs '{'
2445 {
2446 objc_interface_context = objc_ivar_context
2447 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2448 objc_public_flag = 0;
2449 }
2450 ivar_decl_list '}'
2451 {
2452 continue_class (objc_interface_context);
2453 }
2454 methodprotolist
2455 END
2456 {
2457 finish_class (objc_interface_context);
2458 objc_interface_context = NULL_TREE;
2459 }
2460
2461 | INTERFACE identifier ':' identifier protocolrefs
2462 {
2463 objc_interface_context
2464 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2465 continue_class (objc_interface_context);
2466 }
2467 methodprotolist
2468 END
2469 {
2470 finish_class (objc_interface_context);
2471 objc_interface_context = NULL_TREE;
2472 }
2473
2474 | IMPLEMENTATION identifier '{'
2475 {
2476 objc_implementation_context = objc_ivar_context
2477 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2478 objc_public_flag = 0;
2479 }
2480 ivar_decl_list '}'
2481 {
2482 objc_ivar_chain
2483 = continue_class (objc_implementation_context);
2484 }
2485
2486 | IMPLEMENTATION identifier
2487 {
2488 objc_implementation_context
2489 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2490 objc_ivar_chain
2491 = continue_class (objc_implementation_context);
2492 }
2493
2494 | IMPLEMENTATION identifier ':' identifier '{'
2495 {
2496 objc_implementation_context = objc_ivar_context
2497 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2498 objc_public_flag = 0;
2499 }
2500 ivar_decl_list '}'
2501 {
2502 objc_ivar_chain
2503 = continue_class (objc_implementation_context);
2504 }
2505
2506 | IMPLEMENTATION identifier ':' identifier
2507 {
2508 objc_implementation_context
2509 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2510 objc_ivar_chain
2511 = continue_class (objc_implementation_context);
2512 }
2513
2514 | INTERFACE identifier '(' identifier ')' protocolrefs
2515 {
2516 objc_interface_context
2517 = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2518 continue_class (objc_interface_context);
2519 }
2520 methodprotolist
2521 END
2522 {
2523 finish_class (objc_interface_context);
2524 objc_interface_context = NULL_TREE;
2525 }
2526
2527 | IMPLEMENTATION identifier '(' identifier ')'
2528 {
2529 objc_implementation_context
2530 = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2531 objc_ivar_chain
2532 = continue_class (objc_implementation_context);
2533 }
2534 ;
2535
2536 protocoldef:
2537 PROTOCOL identifier protocolrefs
2538 {
2539 remember_protocol_qualifiers ();
2540 objc_interface_context
2541 = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2542 }
2543 methodprotolist END
2544 {
2545 forget_protocol_qualifiers();
2546 finish_protocol(objc_interface_context);
2547 objc_interface_context = NULL_TREE;
2548 }
2549 ;
2550
2551 protocolrefs:
2552 /* empty */
2553 {
2554 $$ = NULL_TREE;
2555 }
2556 | non_empty_protocolrefs
2557 ;
2558
2559 non_empty_protocolrefs:
2560 ARITHCOMPARE identifier_list ARITHCOMPARE
2561 {
2562 if ($1 == LT_EXPR && $3 == GT_EXPR)
2563 $$ = $2;
2564 else
2565 YYERROR1;
2566 }
2567 ;
2568
2569 ivar_decl_list:
2570 ivar_decl_list visibility_spec ivar_decls
2571 | ivar_decls
2572 ;
2573
2574 visibility_spec:
2575 PRIVATE { objc_public_flag = 2; }
2576 | PROTECTED { objc_public_flag = 0; }
2577 | PUBLIC { objc_public_flag = 1; }
2578 ;
2579
2580 ivar_decls:
2581 /* empty */
2582 {
2583 $$ = NULL_TREE;
2584 }
2585 | ivar_decls ivar_decl ';'
2586 | ivar_decls ';'
2587 {
2588 if (pedantic)
2589 pedwarn ("extra semicolon in struct or union specified");
2590 }
2591 ;
2592
2593
2594 /* There is a shift-reduce conflict here, because `components' may
2595 start with a `typename'. It happens that shifting (the default resolution)
2596 does the right thing, because it treats the `typename' as part of
2597 a `typed_typespecs'.
2598
2599 It is possible that this same technique would allow the distinction
2600 between `notype_initdecls' and `initdecls' to be eliminated.
2601 But I am being cautious and not trying it. */
2602
2603 ivar_decl:
2604 typed_typespecs setspecs ivars
2605 { $$ = $3;
2606 current_declspecs = TREE_VALUE (declspec_stack);
2607 prefix_attributes = TREE_PURPOSE (declspec_stack);
2608 declspec_stack = TREE_CHAIN (declspec_stack);
2609 resume_momentary ($2); }
2610 | nonempty_type_quals setspecs ivars
2611 { $$ = $3;
2612 current_declspecs = TREE_VALUE (declspec_stack);
2613 prefix_attributes = TREE_PURPOSE (declspec_stack);
2614 declspec_stack = TREE_CHAIN (declspec_stack);
2615 resume_momentary ($2); }
2616 | error
2617 { $$ = NULL_TREE; }
2618 ;
2619
2620 ivars:
2621 /* empty */
2622 { $$ = NULL_TREE; }
2623 | ivar_declarator
2624 | ivars ',' ivar_declarator
2625 ;
2626
2627 ivar_declarator:
2628 declarator
2629 {
2630 $$ = add_instance_variable (objc_ivar_context,
2631 objc_public_flag,
2632 $1, current_declspecs,
2633 NULL_TREE);
2634 }
2635 | declarator ':' expr_no_commas
2636 {
2637 $$ = add_instance_variable (objc_ivar_context,
2638 objc_public_flag,
2639 $1, current_declspecs, $3);
2640 }
2641 | ':' expr_no_commas
2642 {
2643 $$ = add_instance_variable (objc_ivar_context,
2644 objc_public_flag,
2645 NULL_TREE,
2646 current_declspecs, $2);
2647 }
2648 ;
2649
2650 methoddef:
2651 '+'
2652 {
2653 remember_protocol_qualifiers ();
2654 if (objc_implementation_context)
2655 objc_inherit_code = CLASS_METHOD_DECL;
2656 else
2657 fatal ("method definition not in class context");
2658 }
2659 methoddecl
2660 {
2661 forget_protocol_qualifiers ();
2662 add_class_method (objc_implementation_context, $3);
2663 start_method_def ($3);
2664 objc_method_context = $3;
2665 }
2666 optarglist
2667 {
2668 continue_method_def ();
2669 }
2670 compstmt_or_error
2671 {
2672 finish_method_def ();
2673 objc_method_context = NULL_TREE;
2674 }
2675
2676 | '-'
2677 {
2678 remember_protocol_qualifiers ();
2679 if (objc_implementation_context)
2680 objc_inherit_code = INSTANCE_METHOD_DECL;
2681 else
2682 fatal ("method definition not in class context");
2683 }
2684 methoddecl
2685 {
2686 forget_protocol_qualifiers ();
2687 add_instance_method (objc_implementation_context, $3);
2688 start_method_def ($3);
2689 objc_method_context = $3;
2690 }
2691 optarglist
2692 {
2693 continue_method_def ();
2694 }
2695 compstmt_or_error
2696 {
2697 finish_method_def ();
2698 objc_method_context = NULL_TREE;
2699 }
2700 ;
2701
2702 /* the reason for the strange actions in this rule
2703 is so that notype_initdecls when reached via datadef
2704 can find a valid list of type and sc specs in $0. */
2705
2706 methodprotolist:
2707 /* empty */
2708 | {$<ttype>$ = NULL_TREE; } methodprotolist2
2709 ;
2710
2711 methodprotolist2: /* eliminates a shift/reduce conflict */
2712 methodproto
2713 | datadef
2714 | methodprotolist2 methodproto
2715 | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
2716 ;
2717
2718 semi_or_error:
2719 ';'
2720 | error
2721 ;
2722
2723 methodproto:
2724 '+'
2725 {
2726 objc_inherit_code = CLASS_METHOD_DECL;
2727 }
2728 methoddecl
2729 {
2730 add_class_method (objc_interface_context, $3);
2731 }
2732 semi_or_error
2733
2734 | '-'
2735 {
2736 objc_inherit_code = INSTANCE_METHOD_DECL;
2737 }
2738 methoddecl
2739 {
2740 add_instance_method (objc_interface_context, $3);
2741 }
2742 semi_or_error
2743 ;
2744
2745 methoddecl:
2746 '(' typename ')' unaryselector
2747 {
2748 $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
2749 }
2750
2751 | unaryselector
2752 {
2753 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
2754 }
2755
2756 | '(' typename ')' keywordselector optparmlist
2757 {
2758 $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
2759 }
2760
2761 | keywordselector optparmlist
2762 {
2763 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
2764 }
2765 ;
2766
2767 /* "optarglist" assumes that start_method_def has already been called...
2768 if it is not, the "xdecls" will not be placed in the proper scope */
2769
2770 optarglist:
2771 /* empty */
2772 | ';' myxdecls
2773 ;
2774
2775 /* to get around the following situation: "int foo (int a) int b; {}" that
2776 is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
2777
2778 myxdecls:
2779 /* empty */
2780 | mydecls
2781 ;
2782
2783 mydecls:
2784 mydecl
2785 | errstmt
2786 | mydecls mydecl
2787 | mydecl errstmt
2788 ;
2789
2790 mydecl:
2791 typed_declspecs setspecs myparms ';'
2792 { current_declspecs = TREE_VALUE (declspec_stack);
2793 prefix_attributes = TREE_PURPOSE (declspec_stack);
2794 declspec_stack = TREE_CHAIN (declspec_stack);
2795 resume_momentary ($2); }
2796 | typed_declspecs ';'
2797 { shadow_tag ($1); }
2798 | declmods ';'
2799 { pedwarn ("empty declaration"); }
2800 ;
2801
2802 myparms:
2803 myparm
2804 { push_parm_decl ($1); }
2805 | myparms ',' myparm
2806 { push_parm_decl ($3); }
2807 ;
2808
2809 /* A single parameter declaration or parameter type name,
2810 as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
2811
2812 myparm:
2813 parm_declarator maybe_attribute
2814 { $$ = build_tree_list (build_tree_list (current_declspecs,
2815 $1),
2816 build_tree_list (prefix_attributes,
2817 $2)); }
2818 | notype_declarator maybe_attribute
2819 { $$ = build_tree_list (build_tree_list (current_declspecs,
2820 $1),
2821 build_tree_list (prefix_attributes,
2822 $2)); }
2823 | absdcl maybe_attribute
2824 { $$ = build_tree_list (build_tree_list (current_declspecs,
2825 $1),
2826 build_tree_list (prefix_attributes,
2827 $2)); }
2828 ;
2829
2830 optparmlist:
2831 /* empty */
2832 {
2833 $$ = NULL_TREE;
2834 }
2835 | ',' ELLIPSIS
2836 {
2837 /* oh what a kludge! */
2838 $$ = (tree)1;
2839 }
2840 | ','
2841 {
2842 pushlevel (0);
2843 }
2844 parmlist_2
2845 {
2846 /* returns a tree list node generated by get_parm_info */
2847 $$ = $3;
2848 poplevel (0, 0, 0);
2849 }
2850 ;
2851
2852 unaryselector:
2853 selector
2854 ;
2855
2856 keywordselector:
2857 keyworddecl
2858
2859 | keywordselector keyworddecl
2860 {
2861 $$ = chainon ($1, $2);
2862 }
2863 ;
2864
2865 selector:
2866 IDENTIFIER
2867 | TYPENAME
2868 | OBJECTNAME
2869 | reservedwords
2870 ;
2871
2872 reservedwords:
2873 ENUM { $$ = get_identifier (token_buffer); }
2874 | STRUCT { $$ = get_identifier (token_buffer); }
2875 | UNION { $$ = get_identifier (token_buffer); }
2876 | IF { $$ = get_identifier (token_buffer); }
2877 | ELSE { $$ = get_identifier (token_buffer); }
2878 | WHILE { $$ = get_identifier (token_buffer); }
2879 | DO { $$ = get_identifier (token_buffer); }
2880 | FOR { $$ = get_identifier (token_buffer); }
2881 | SWITCH { $$ = get_identifier (token_buffer); }
2882 | CASE { $$ = get_identifier (token_buffer); }
2883 | DEFAULT { $$ = get_identifier (token_buffer); }
2884 | BREAK { $$ = get_identifier (token_buffer); }
2885 | CONTINUE { $$ = get_identifier (token_buffer); }
2886 | RETURN { $$ = get_identifier (token_buffer); }
2887 | GOTO { $$ = get_identifier (token_buffer); }
2888 | ASM_KEYWORD { $$ = get_identifier (token_buffer); }
2889 | SIZEOF { $$ = get_identifier (token_buffer); }
2890 | TYPEOF { $$ = get_identifier (token_buffer); }
2891 | ALIGNOF { $$ = get_identifier (token_buffer); }
2892 | TYPESPEC | TYPE_QUAL
2893 ;
2894
2895 keyworddecl:
2896 selector ':' '(' typename ')' identifier
2897 {
2898 $$ = build_keyword_decl ($1, $4, $6);
2899 }
2900
2901 | selector ':' identifier
2902 {
2903 $$ = build_keyword_decl ($1, NULL_TREE, $3);
2904 }
2905
2906 | ':' '(' typename ')' identifier
2907 {
2908 $$ = build_keyword_decl (NULL_TREE, $3, $5);
2909 }
2910
2911 | ':' identifier
2912 {
2913 $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
2914 }
2915 ;
2916
2917 messageargs:
2918 selector
2919 | keywordarglist
2920 ;
2921
2922 keywordarglist:
2923 keywordarg
2924 | keywordarglist keywordarg
2925 {
2926 $$ = chainon ($1, $2);
2927 }
2928 ;
2929
2930
2931 keywordexpr:
2932 nonnull_exprlist
2933 {
2934 if (TREE_CHAIN ($1) == NULL_TREE)
2935 /* just return the expr., remove a level of indirection */
2936 $$ = TREE_VALUE ($1);
2937 else
2938 /* we have a comma expr., we will collapse later */
2939 $$ = $1;
2940 }
2941 ;
2942
2943 keywordarg:
2944 selector ':' keywordexpr
2945 {
2946 $$ = build_tree_list ($1, $3);
2947 }
2948 | ':' keywordexpr
2949 {
2950 $$ = build_tree_list (NULL_TREE, $2);
2951 }
2952 ;
2953
2954 receiver:
2955 expr
2956 | CLASSNAME
2957 {
2958 $$ = get_class_reference ($1);
2959 }
2960 ;
2961
2962 objcmessageexpr:
2963 '['
2964 { objc_receiver_context = 1; }
2965 receiver
2966 { objc_receiver_context = 0; }
2967 messageargs ']'
2968 {
2969 $$ = build_tree_list ($3, $5);
2970 }
2971 ;
2972
2973 selectorarg:
2974 selector
2975 | keywordnamelist
2976 ;
2977
2978 keywordnamelist:
2979 keywordname
2980 | keywordnamelist keywordname
2981 {
2982 $$ = chainon ($1, $2);
2983 }
2984 ;
2985
2986 keywordname:
2987 selector ':'
2988 {
2989 $$ = build_tree_list ($1, NULL_TREE);
2990 }
2991 | ':'
2992 {
2993 $$ = build_tree_list (NULL_TREE, NULL_TREE);
2994 }
2995 ;
2996
2997 objcselectorexpr:
2998 SELECTOR '(' selectorarg ')'
2999 {
3000 $$ = $3;
3001 }
3002 ;
3003
3004 objcprotocolexpr:
3005 PROTOCOL '(' identifier ')'
3006 {
3007 $$ = $3;
3008 }
3009 ;
3010
3011 /* extension to support C-structures in the archiver */
3012
3013 objcencodeexpr:
3014 ENCODE '(' typename ')'
3015 {
3016 $$ = groktypename ($3);
3017 }
3018 ;
3019
3020 end ifobjc
3021 %%
This page took 0.233105 seconds and 5 git commands to generate.