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