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