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