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