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