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