Changeset 7527e63 for src/Parser/parser.yy
- Timestamp:
- Aug 16, 2016, 3:20:06 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 1f6d4624
- Parents:
- 950f7a7 (diff), 7880579 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r950f7a7 r7527e63 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jul 12 20:52:53201613 // Update Count : 1 66112 // Last Modified On : Mon Aug 15 15:18:19 2016 13 // Update Count : 1891 14 14 // 15 15 … … 60 60 std::stack< LinkageSpec::Type > linkageStack; 61 61 TypedefTable typedefTable; 62 63 void appendStr( std::string &to, std::string *from ) { 64 // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string. 65 to.insert( to.length() - 1, from->substr( 1, from->length() - 2 ) ); 66 } // appendStr 62 67 %} 63 68 … … 116 121 DeclarationNode::TypeClass tclass; 117 122 StatementNode *sn; 118 ConstantNode *constant; 123 ConstantExpr *constant; 124 ForCtl *fctl; 119 125 LabelNode *label; 120 126 InitializerNode *in; 127 OperKinds op; 121 128 bool flag; 122 129 } … … 127 134 128 135 // expressions 129 %type< constant> constant136 %type<en> constant 130 137 %type<en> tuple tuple_expression_list 131 %type< en> ptrref_operator unary_operator assignment_operator138 %type<op> ptrref_operator unary_operator assignment_operator 132 139 %type<en> primary_expression postfix_expression unary_expression 133 140 %type<en> cast_expression multiplicative_expression additive_expression shift_expression … … 136 143 %type<en> constant_expression assignment_expression assignment_expression_opt 137 144 %type<en> comma_expression comma_expression_opt 138 %type<en> argument_expression_list argument_expression for_control_expression assignment_opt 145 %type<en> argument_expression_list argument_expression assignment_opt 146 %type<fctl> for_control_expression 139 147 %type<en> subrange 140 148 %type<en> asm_operands_opt asm_operands_list asm_operand 141 149 %type<label> label_list 142 %type< constant> asm_clobbers_list_opt150 %type<en> asm_clobbers_list_opt 143 151 %type<flag> asm_volatile_opt 144 152 … … 150 158 %type<sn> block_item_list block_item 151 159 %type<sn> case_clause 152 %type<en> case_value case_value_list153 %type<sn> case_ label case_label_list160 %type<en> case_value 161 %type<sn> case_value_list case_label case_label_list 154 162 %type<sn> switch_clause_list_opt switch_clause_list choose_clause_list_opt choose_clause_list 155 %type< pn> handler_list handler_clause finally_clause163 %type<sn> handler_list handler_clause finally_clause 156 164 157 165 // declarations … … 303 311 constant: 304 312 // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant". 305 INTEGERconstant { $$ = makeConstant( ConstantNode::Integer, $1); }306 | FLOATINGconstant { $$ = makeConstant( ConstantNode::Float, $1); }307 | CHARACTERconstant { $$ = makeConstant( ConstantNode::Character, $1); }313 INTEGERconstant { $$ = new ExpressionNode( build_constantInteger( *$1 ) ); } 314 | FLOATINGconstant { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); } 315 | CHARACTERconstant { $$ = new ExpressionNode( build_constantChar( *$1 ) ); } 308 316 ; 309 317 … … 330 338 331 339 string_literal_list: // juxtaposed strings are concatenated 332 STRINGliteral { $$ = makeConstantStr( ConstantNode::String, $1 ); } 333 | string_literal_list STRINGliteral { $$ = $1->appendstr( $2 ); } 340 STRINGliteral { $$ = build_constantStr( *$1 ); } 341 | string_literal_list STRINGliteral 342 { 343 appendStr( $1->get_constant()->get_value(), $2 ); 344 delete $2; // allocated by lexer 345 $$ = $1; 346 } 334 347 ; 335 348 … … 338 351 primary_expression: 339 352 IDENTIFIER // typedef name cannot be used as a variable name 340 { $$ = new VarRefNode( $1); }353 { $$ = new ExpressionNode( build_varref( $1 ) ); } 341 354 | zero_one 342 { $$ = new VarRefNode( $1); }355 { $$ = new ExpressionNode( build_varref( $1 ) ); } 343 356 | '(' comma_expression ')' 344 357 { $$ = $2; } 345 358 | '(' compound_statement ')' // GCC, lambda expression 346 { $$ = new ValofExprNode( $2); }359 { $$ = new ExpressionNode( build_valexpr( $2 ) ); } 347 360 ; 348 361 … … 354 367 // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is 355 368 // equivalent to the old x[i,j]. 356 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Index ), $1, $4); }369 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $4 ) ); } 357 370 | postfix_expression '(' argument_expression_list ')' 358 { $$ = new CompositeExprNode( $1, $3); }371 { $$ = new ExpressionNode( build_func( $1, $3 ) ); } 359 372 // ambiguity with .0 so space required after field-selection, e.g. 360 373 // struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1; 361 374 | postfix_expression '.' no_attr_identifier 362 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::FieldSel ), $1, new VarRefNode( $3 )); }375 { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); } 363 376 | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector 364 377 | postfix_expression ARROW no_attr_identifier 365 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PFieldSel ), $1, new VarRefNode( $3 )); }378 { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); } 366 379 | postfix_expression ARROW '[' push field_list pop ']' // CFA, tuple field selector 367 380 | postfix_expression ICR 368 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::IncrPost ), $1); }381 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::IncrPost, $1 ) ); } 369 382 | postfix_expression DECR 370 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::DecrPost ), $1); }383 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); } 371 384 | '(' type_name_no_function ')' '{' initializer_list comma_opt '}' // C99 372 { $$ = new CompoundLiteralNode( $2, new InitializerNode( $5, true) ); }385 { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); } 373 386 | postfix_expression '{' argument_expression_list '}' // CFA 374 387 { 375 Token fn; fn.str = new std::string( "?{}" ); // location undefined 376 $$ = new CompositeExprNode( new VarRefNode( fn ), (ExpressionNode *)( $1 )->set_link( $3 ) ); 388 Token fn; 389 fn.str = new std::string( "?{}" ); // location undefined 390 $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ); 377 391 } 378 392 ; … … 381 395 argument_expression 382 396 | argument_expression_list ',' argument_expression 383 { $$ = (ExpressionNode *)( $1->set_l ink( $3 )); }397 { $$ = (ExpressionNode *)( $1->set_last( $3 )); } 384 398 ; 385 399 … … 388 402 { $$ = 0; } // use default argument 389 403 | assignment_expression 390 | no_attr_identifier ':' assignment_expression391 { $$ = $3->set_argName( $1 ); }392 // Only a list of no_attr_identifier_or_type_name is allowed in this context. However, there is insufficient393 // look ahead to distinguish between this list of parameter names and a tuple, so the tuple form must be used394 // with an appropriate semantic check.395 | '[' push assignment_expression pop ']' ':' assignment_expression396 { $$ = $7->set_argName( $3 ); }397 | '[' push assignment_expression ',' tuple_expression_list pop ']' ':' assignment_expression398 { $$ = $9->set_argName( new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)$3->set_link( flattenCommas( $5 )))); }399 404 ; 400 405 401 406 field_list: // CFA, tuple field selector 402 407 field 403 | field_list ',' field { $$ = (ExpressionNode *)$1->set_l ink( $3 ); }408 | field_list ',' field { $$ = (ExpressionNode *)$1->set_last( $3 ); } 404 409 ; 405 410 406 411 field: // CFA, tuple field selector 407 412 no_attr_identifier 408 { $$ = new VarRefNode( $1); }413 { $$ = new ExpressionNode( build_varref( $1 ) ); } 409 414 // ambiguity with .0 so space required after field-selection, e.g. 410 415 // struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1; 411 416 | no_attr_identifier '.' field 412 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::FieldSel ), new VarRefNode( $1 ), $3); }417 { $$ = new ExpressionNode( build_fieldSel( $3, build_varref( $1 ) ) ); } 413 418 | no_attr_identifier '.' '[' push field_list pop ']' 414 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::FieldSel ), new VarRefNode( $1 ), $5); }419 { $$ = new ExpressionNode( build_fieldSel( $5, build_varref( $1 ) ) ); } 415 420 | no_attr_identifier ARROW field 416 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PFieldSel ), new VarRefNode( $1 ), $3); }421 { $$ = new ExpressionNode( build_pfieldSel( $3, build_varref( $1 ) ) ); } 417 422 | no_attr_identifier ARROW '[' push field_list pop ']' 418 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PFieldSel ), new VarRefNode( $1 ), $5); }423 { $$ = new ExpressionNode( build_pfieldSel( $5, build_varref( $1 ) ) ); } 419 424 ; 420 425 … … 426 431 { $$ = $1; } 427 432 | string_literal_list 428 { $$ = $1; }433 { $$ = new ExpressionNode( $1 ); } 429 434 | EXTENSION cast_expression // GCC 430 435 { $$ = $2->set_extension( true ); } 431 | ptrref_operator cast_expression // CFA432 { $$ = new CompositeExprNode( $1, $2 ); }433 436 // '*' ('&') is separated from unary_operator because of shift/reduce conflict in: 434 437 // { * X; } // dereference X 435 438 // { * int X; } // CFA declaration of pointer to int 439 | ptrref_operator cast_expression // CFA 440 { 441 switch ( $1 ) { 442 case OperKinds::AddressOf: 443 $$ = new ExpressionNode( build_addressOf( $2 ) ); 444 break; 445 case OperKinds::PointTo: 446 $$ = new ExpressionNode( build_unary_val( $1, $2 ) ); 447 break; 448 default: 449 assert( false ); 450 } 451 } 436 452 | unary_operator cast_expression 437 { $$ = new CompositeExprNode( $1, $2); }453 { $$ = new ExpressionNode( build_unary_val( $1, $2 ) ); } 438 454 | ICR unary_expression 439 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Incr ), $2); }455 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Incr, $2 ) ); } 440 456 | DECR unary_expression 441 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Decr ), $2); }457 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Decr, $2 ) ); } 442 458 | SIZEOF unary_expression 443 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::SizeOf ), $2); }459 { $$ = new ExpressionNode( build_sizeOfexpr( $2 ) ); } 444 460 | SIZEOF '(' type_name_no_function ')' 445 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::SizeOf ), new TypeValueNode( $3 )); } 461 { $$ = new ExpressionNode( build_sizeOftype( $3 ) ); } 462 | ALIGNOF unary_expression // GCC, variable alignment 463 { $$ = new ExpressionNode( build_alignOfexpr( $2 ) ); } 464 | ALIGNOF '(' type_name_no_function ')' // GCC, type alignment 465 { $$ = new ExpressionNode( build_alignOftype( $3 ) ); } 446 466 | OFFSETOF '(' type_name_no_function ',' no_attr_identifier ')' 447 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::OffsetOf ), new TypeValueNode( $3 ), new VarRefNode( $5 )); }467 { $$ = new ExpressionNode( build_offsetOf( $3, build_varref( $5 ) ) ); } 448 468 | ATTR_IDENTIFIER 449 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 )); } 469 { $$ = new ExpressionNode( build_attrexpr( build_varref( $1 ), nullptr ) ); } 470 | ATTR_IDENTIFIER '(' argument_expression ')' 471 { $$ = new ExpressionNode( build_attrexpr( build_varref( $1 ), $3 ) ); } 450 472 | ATTR_IDENTIFIER '(' type_name ')' 451 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 ), new TypeValueNode( $3 )); } 452 | ATTR_IDENTIFIER '(' argument_expression ')' 453 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 ), $3 ); } 454 | ALIGNOF unary_expression // GCC, variable alignment 455 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::AlignOf ), $2 ); } 456 | ALIGNOF '(' type_name_no_function ')' // GCC, type alignment 457 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::AlignOf ), new TypeValueNode( $3 ) ); } 473 { $$ = new ExpressionNode( build_attrtype( build_varref( $1 ), $3 ) ); } 458 474 // | ANDAND IDENTIFIER // GCC, address of label 459 // { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LabelAddress ), new VarRefNode( $2, true ) ); }475 // { $$ = new ExpressionNode( new OperatorNode( OperKinds::LabelAddress ), new ExpressionNode( build_varref( $2, true ) ); } 460 476 ; 461 477 462 478 ptrref_operator: 463 '*' { $$ = new OperatorNode( OperatorNode::PointTo ); }464 | '&' { $$ = new OperatorNode( OperatorNode::AddressOf ); }479 '*' { $$ = OperKinds::PointTo; } 480 | '&' { $$ = OperKinds::AddressOf; } 465 481 // GCC, address of label must be handled by semantic check for ref,ref,label 466 | ANDAND { $$ = new OperatorNode( OperatorNode::And ); }482 // | ANDAND { $$ = OperKinds::And; } 467 483 ; 468 484 469 485 unary_operator: 470 '+' { $$ = new OperatorNode( OperatorNode::UnPlus ); }471 | '-' { $$ = new OperatorNode( OperatorNode::UnMinus ); }472 | '!' { $$ = new OperatorNode( OperatorNode::Neg ); }473 | '~' { $$ = new OperatorNode( OperatorNode::BitNeg ); }486 '+' { $$ = OperKinds::UnPlus; } 487 | '-' { $$ = OperKinds::UnMinus; } 488 | '!' { $$ = OperKinds::Neg; } 489 | '~' { $$ = OperKinds::BitNeg; } 474 490 ; 475 491 … … 477 493 unary_expression 478 494 | '(' type_name_no_function ')' cast_expression 479 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cast ), new TypeValueNode( $2 ), $4); }495 { $$ = new ExpressionNode( build_cast( $2, $4 ) ); } 480 496 | '(' type_name_no_function ')' tuple 481 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cast ), new TypeValueNode( $2 ), $4); }497 { $$ = new ExpressionNode( build_cast( $2, $4 ) ); } 482 498 ; 483 499 … … 485 501 cast_expression 486 502 | multiplicative_expression '*' cast_expression 487 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Mul ), $1, $3); }503 { $$ = new ExpressionNode( build_binary_val( OperKinds::Mul, $1, $3 ) ); } 488 504 | multiplicative_expression '/' cast_expression 489 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Div ), $1, $3); }505 { $$ = new ExpressionNode( build_binary_val( OperKinds::Div, $1, $3 ) ); } 490 506 | multiplicative_expression '%' cast_expression 491 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Mod ), $1, $3); }507 { $$ = new ExpressionNode( build_binary_val( OperKinds::Mod, $1, $3 ) ); } 492 508 ; 493 509 … … 495 511 multiplicative_expression 496 512 | additive_expression '+' multiplicative_expression 497 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Plus ), $1, $3); }513 { $$ = new ExpressionNode( build_binary_val( OperKinds::Plus, $1, $3 ) ); } 498 514 | additive_expression '-' multiplicative_expression 499 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Minus ), $1, $3); }515 { $$ = new ExpressionNode( build_binary_val( OperKinds::Minus, $1, $3 ) ); } 500 516 ; 501 517 … … 503 519 additive_expression 504 520 | shift_expression LS additive_expression 505 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LShift ), $1, $3); }521 { $$ = new ExpressionNode( build_binary_val( OperKinds::LShift, $1, $3 ) ); } 506 522 | shift_expression RS additive_expression 507 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::RShift ), $1, $3); }523 { $$ = new ExpressionNode( build_binary_val( OperKinds::RShift, $1, $3 ) ); } 508 524 ; 509 525 … … 511 527 shift_expression 512 528 | relational_expression '<' shift_expression 513 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LThan ), $1, $3); }529 { $$ = new ExpressionNode( build_binary_val( OperKinds::LThan, $1, $3 ) ); } 514 530 | relational_expression '>' shift_expression 515 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::GThan ), $1, $3); }531 { $$ = new ExpressionNode( build_binary_val( OperKinds::GThan, $1, $3 ) ); } 516 532 | relational_expression LE shift_expression 517 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LEThan ), $1, $3); }533 { $$ = new ExpressionNode( build_binary_val( OperKinds::LEThan, $1, $3 ) ); } 518 534 | relational_expression GE shift_expression 519 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::GEThan ), $1, $3); }535 { $$ = new ExpressionNode( build_binary_val( OperKinds::GEThan, $1, $3 ) ); } 520 536 ; 521 537 … … 523 539 relational_expression 524 540 | equality_expression EQ relational_expression 525 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Eq ), $1, $3); }541 { $$ = new ExpressionNode( build_binary_val( OperKinds::Eq, $1, $3 ) ); } 526 542 | equality_expression NE relational_expression 527 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Neq ), $1, $3); }543 { $$ = new ExpressionNode( build_binary_val( OperKinds::Neq, $1, $3 ) ); } 528 544 ; 529 545 … … 531 547 equality_expression 532 548 | AND_expression '&' equality_expression 533 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::BitAnd ), $1, $3); }549 { $$ = new ExpressionNode( build_binary_val( OperKinds::BitAnd, $1, $3 ) ); } 534 550 ; 535 551 … … 537 553 AND_expression 538 554 | exclusive_OR_expression '^' AND_expression 539 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Xor ), $1, $3); }555 { $$ = new ExpressionNode( build_binary_val( OperKinds::Xor, $1, $3 ) ); } 540 556 ; 541 557 … … 543 559 exclusive_OR_expression 544 560 | inclusive_OR_expression '|' exclusive_OR_expression 545 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::BitOr ), $1, $3); }561 { $$ = new ExpressionNode( build_binary_val( OperKinds::BitOr, $1, $3 ) ); } 546 562 ; 547 563 … … 549 565 inclusive_OR_expression 550 566 | logical_AND_expression ANDAND inclusive_OR_expression 551 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::And ), $1, $3); }567 { $$ = new ExpressionNode( build_and_or( $1, $3, true ) ); } 552 568 ; 553 569 … … 555 571 logical_AND_expression 556 572 | logical_OR_expression OROR logical_AND_expression 557 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Or ), $1, $3); }573 { $$ = new ExpressionNode( build_and_or( $1, $3, false ) ); } 558 574 ; 559 575 … … 561 577 logical_OR_expression 562 578 | logical_OR_expression '?' comma_expression ':' conditional_expression 563 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cond ), (ExpressionNode *)mkList( (*$1, *$3, *$5 ) ) ); } 579 { $$ = new ExpressionNode( build_cond( $1, $3, $5 ) ); } 580 // FIX ME: this hack computes $1 twice 564 581 | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand 565 { $$ =new CompositeExprNode( new OperatorNode( OperatorNode::NCond ), $1, $4); }582 { $$ = new ExpressionNode( build_cond( $1, $1, $4 ) ); } 566 583 | logical_OR_expression '?' comma_expression ':' tuple // CFA, tuple expression 567 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cond ), (ExpressionNode *)mkList( (*$1, *$3, *$5 )) ); }584 { $$ = new ExpressionNode( build_cond( $1, $3, $5 ) ); } 568 585 ; 569 586 … … 575 592 // CFA, assignment is separated from assignment_operator to ensure no assignment operations for tuples 576 593 conditional_expression 577 | unary_expression '=' assignment_expression578 { $$ =new CompositeExprNode( new OperatorNode( OperatorNode::Assign ), $1, $3 ); }579 594 | unary_expression assignment_operator assignment_expression 580 { $$ = new CompositeExprNode( $2, $1, $3); }595 { $$ = new ExpressionNode( build_binary_ptr( $2, $1, $3 ) ); } 581 596 | tuple assignment_opt // CFA, tuple expression 582 { $$ = ( $2 == 0 ) ? $1 : new CompositeExprNode( new OperatorNode( OperatorNode::Assign ), $1, $2); }597 { $$ = ( $2 == 0 ) ? $1 : new ExpressionNode( build_binary_ptr( OperKinds::Assign, $1, $2 ) ); } 583 598 ; 584 599 585 600 assignment_expression_opt: 586 601 // empty 587 { $$ = n ew NullExprNode; }602 { $$ = nullptr; } 588 603 | assignment_expression 604 ; 605 606 assignment_operator: 607 '=' { $$ = OperKinds::Assign; } 608 | MULTassign { $$ = OperKinds::MulAssn; } 609 | DIVassign { $$ = OperKinds::DivAssn; } 610 | MODassign { $$ = OperKinds::ModAssn; } 611 | PLUSassign { $$ = OperKinds::PlusAssn; } 612 | MINUSassign { $$ = OperKinds::MinusAssn; } 613 | LSassign { $$ = OperKinds::LSAssn; } 614 | RSassign { $$ = OperKinds::RSAssn; } 615 | ANDassign { $$ = OperKinds::AndAssn; } 616 | ERassign { $$ = OperKinds::ERAssn; } 617 | ORassign { $$ = OperKinds::OrAssn; } 589 618 ; 590 619 … … 593 622 // comma_expression in new_identifier_parameter_array and new_abstract_array 594 623 '[' ']' 595 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC) ); }624 { $$ = new ExpressionNode( build_tuple() ); } 596 625 | '[' push assignment_expression pop ']' 597 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), $3); }626 { $$ = new ExpressionNode( build_tuple( $3 ) ); } 598 627 | '[' push ',' tuple_expression_list pop ']' 599 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)(new NullExprNode)->set_link( $4) ); }628 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $4 ) ) ); } 600 629 | '[' push assignment_expression ',' tuple_expression_list pop ']' 601 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)$3->set_link( flattenCommas( $5 ) ) ); }630 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $5 ) ) ); } 602 631 ; 603 632 … … 605 634 assignment_expression_opt 606 635 | tuple_expression_list ',' assignment_expression_opt 607 { $$ = (ExpressionNode *)$1->set_link( $3 ); } 608 ; 609 610 assignment_operator: 611 MULTassign { $$ = new OperatorNode( OperatorNode::MulAssn ); } 612 | DIVassign { $$ = new OperatorNode( OperatorNode::DivAssn ); } 613 | MODassign { $$ = new OperatorNode( OperatorNode::ModAssn ); } 614 | PLUSassign { $$ = new OperatorNode( OperatorNode::PlusAssn ); } 615 | MINUSassign { $$ = new OperatorNode( OperatorNode::MinusAssn ); } 616 | LSassign { $$ = new OperatorNode( OperatorNode::LSAssn ); } 617 | RSassign { $$ = new OperatorNode( OperatorNode::RSAssn ); } 618 | ANDassign { $$ = new OperatorNode( OperatorNode::AndAssn ); } 619 | ERassign { $$ = new OperatorNode( OperatorNode::ERAssn ); } 620 | ORassign { $$ = new OperatorNode( OperatorNode::OrAssn ); } 636 { $$ = (ExpressionNode *)$1->set_last( $3 ); } 621 637 ; 622 638 623 639 comma_expression: 624 640 assignment_expression 625 | comma_expression ',' assignment_expression // { $$ = (ExpressionNode *)$1->add_to_list( $3 ); }626 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Comma ), $1, $3); }641 | comma_expression ',' assignment_expression 642 { $$ = new ExpressionNode( build_comma( $1, $3 ) ); } 627 643 ; 628 644 … … 646 662 | '^' postfix_expression '{' argument_expression_list '}' ';' // CFA 647 663 { 648 Token fn; fn.str = new std::string( "^?{}" ); // location undefined649 $$ = new StatementNode( StatementNode::Exp, new CompositeExprNode( new VarRefNode( fn ),650 (ExpressionNode *)( $2 )->set_link( $4 ) ), 0);664 Token fn; 665 fn.str = new std::string( "^?{}" ); // location undefined 666 $$ = new StatementNode( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ) ) ); 651 667 } 652 668 ; … … 662 678 compound_statement: 663 679 '{' '}' 664 { $$ = new CompoundStmtNode( (StatementNode *)0); }680 { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); } 665 681 | '{' 666 682 // Two scopes are necessary because the block itself has a scope, but every declaration within the block also … … 669 685 local_label_declaration_opt // GCC, local labels 670 686 block_item_list pop '}' // C99, intermix declarations and statements 671 { $$ = new CompoundStmtNode( $5); }687 { $$ = new StatementNode( build_compound( $5 ) ); } 672 688 ; 673 689 … … 675 691 block_item 676 692 | block_item_list push block_item 677 { if ( $1 != 0 ) { $1->set_l ink( $3 ); $$ = $1; } }693 { if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } } 678 694 ; 679 695 … … 683 699 | EXTENSION declaration // GCC 684 700 { // mark all fields in list 685 for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_ link() )701 for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_next() ) 686 702 iter->set_extension( true ); 687 703 $$ = new StatementNode( $2 ); … … 695 711 statement 696 712 | statement_list statement 697 { if ( $1 != 0 ) { $1->set_l ink( $2 ); $$ = $1; } }713 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } } 698 714 ; 699 715 700 716 expression_statement: 701 717 comma_expression_opt ';' 702 { $$ = new StatementNode( StatementNode::Exp, $1, 0); }718 { $$ = new StatementNode( build_expr( $1 ) ); } 703 719 ; 704 720 … … 706 722 IF '(' comma_expression ')' statement %prec THEN 707 723 // explicitly deal with the shift/reduce conflict on if/else 708 { $$ = new StatementNode( StatementNode::If, $3, $5); }724 { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); } 709 725 | IF '(' comma_expression ')' statement ELSE statement 710 { $$ = new StatementNode( StatementNode::If, $3, (StatementNode *)mkList((*$5, *$7 )) ); }726 { $$ = new StatementNode( build_if( $3, $5, $7 ) ); } 711 727 | SWITCH '(' comma_expression ')' case_clause // CFA 712 { $$ = new StatementNode( StatementNode::Switch, $3, $5); }728 { $$ = new StatementNode( build_switch( $3, $5 ) ); } 713 729 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA 714 730 { 715 StatementNode *sw = new StatementNode( StatementNode::Switch, $3, $8);731 StatementNode *sw = new StatementNode( build_switch( $3, $8 ) ); 716 732 // The semantics of the declaration list is changed to include associated initialization, which is performed 717 733 // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound 718 734 // statement around the switch. Statements after the initial declaration list can never be executed, and 719 // therefore, are removed from the grammar even though C allows it. Change also applies to choose statement. 720 $$ = $7 != 0 ? new CompoundStmtNode( (StatementNode *)((new StatementNode( $7 ))->set_link( sw )) ) : sw; 735 // therefore, are removed from the grammar even though C allows it. The change also applies to choose 736 // statement. 737 $$ = $7 != 0 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw; 721 738 } 722 739 | CHOOSE '(' comma_expression ')' case_clause // CFA 723 { $$ = new StatementNode( StatementNode::Switch, $3, $5); }740 { $$ = new StatementNode( build_switch( $3, $5 ) ); } 724 741 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt choose_clause_list_opt '}' // CFA 725 742 { 726 StatementNode *sw = new StatementNode( StatementNode::Switch, $3, $8);727 $$ = $7 != 0 ? new CompoundStmtNode( (StatementNode *)((new StatementNode( $7 ))->set_link( sw )) ) : sw;743 StatementNode *sw = new StatementNode( build_switch( $3, $8 ) ); 744 $$ = $7 != 0 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw; 728 745 } 729 746 ; … … 735 752 constant_expression { $$ = $1; } 736 753 | constant_expression ELLIPSIS constant_expression // GCC, subrange 737 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $1, $3); }754 { $$ = new ExpressionNode( build_range( $1, $3 ) ); } 738 755 | subrange // CFA, subrange 739 756 ; 740 757 741 758 case_value_list: // CFA 742 case_value 743 | case_value_list ',' case_value744 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)(tupleContents( $1 ))->set_link( $3) ); }759 case_value { $$ = new StatementNode( build_case( $1 ) ); } 760 // convert case list, e.g., "case 1, 3, 5:" into "case 1: case 3: case 5" 761 | case_value_list ',' case_value { $$ = (StatementNode *)($1->set_last( new StatementNode( build_case( $3 ) ) ) ); } 745 762 ; 746 763 747 764 case_label: // CFA 748 CASE case_value_list ':' { $$ = new StatementNode( StatementNode::Case, $2, 0 ); }749 | DEFAULT ':' { $$ = new StatementNode( StatementNode::Default); }765 CASE case_value_list ':' { $$ = $2; } 766 | DEFAULT ':' { $$ = new StatementNode( build_default() ); } 750 767 // A semantic check is required to ensure only one default clause per switch/choose statement. 751 768 ; … … 753 770 case_label_list: // CFA 754 771 case_label 755 | case_label_list case_label { $$ = (StatementNode *)( $1->set_l ink( $2 )); }772 | case_label_list case_label { $$ = (StatementNode *)( $1->set_last( $2 )); } 756 773 ; 757 774 758 775 case_clause: // CFA 759 case_label_list statement { $$ = $1->append_last_case( new CompoundStmtNode( $2) ); }776 case_label_list statement { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); } 760 777 ; 761 778 … … 768 785 switch_clause_list: // CFA 769 786 case_label_list statement_list 770 { $$ = $1->append_last_case( new CompoundStmtNode( $2) ); }787 { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); } 771 788 | switch_clause_list case_label_list statement_list 772 { $$ = (StatementNode *)( $1->set_l ink( $2->append_last_case( new CompoundStmtNode( $3) ) ) ); }789 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( $3 ) ) ) ) ); } 773 790 ; 774 791 … … 783 800 { $$ = $1->append_last_case( $2 ); } 784 801 | case_label_list statement_list fall_through_opt 785 { $$ = $1->append_last_case( new CompoundStmtNode( (StatementNode *)mkList( (*$2, *$3 ) ) ) ); }802 { $$ = $1->append_last_case( new StatementNode( build_compound( (StatementNode *)$2->set_last( $3 ) ) ) ); } 786 803 | choose_clause_list case_label_list fall_through 787 { $$ = (StatementNode *)( $1->set_l ink( $2->append_last_case( $3 ))); }804 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( $3 ))); } 788 805 | choose_clause_list case_label_list statement_list fall_through_opt 789 { $$ = (StatementNode *)( $1->set_l ink( $2->append_last_case( new CompoundStmtNode( (StatementNode *)mkList( (*$3, *$4 ) ) ) ) ) ); }806 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( (StatementNode *)$3->set_last( $4 ) ) ) ) ) ); } 790 807 ; 791 808 792 809 fall_through_opt: // CFA 793 810 // empty 794 { $$ = new StatementNode( StatementNode::Break ); }// insert implicit break811 { $$ = new StatementNode( build_branch( "", BranchStmt::Break ) ); } // insert implicit break 795 812 | fall_through 796 813 ; … … 805 822 iteration_statement: 806 823 WHILE '(' comma_expression ')' statement 807 { $$ = new StatementNode( StatementNode::While, $3, $5); }824 { $$ = new StatementNode( build_while( $3, $5 ) ); } 808 825 | DO statement WHILE '(' comma_expression ')' ';' 809 { $$ = new StatementNode( StatementNode::Do, $5, $2); }826 { $$ = new StatementNode( build_while( $5, $2 ) ); } 810 827 | FOR '(' push for_control_expression ')' statement 811 { $$ = new StatementNode( StatementNode::For, $4, $6); }828 { $$ = new StatementNode( build_for( $4, $6 ) ); } 812 829 ; 813 830 814 831 for_control_expression: 815 832 comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt 816 { $$ = new ForCtl ExprNode( $1, $4, $6 ); }833 { $$ = new ForCtl( $1, $4, $6 ); } 817 834 | declaration comma_expression_opt ';' comma_expression_opt // C99 818 { $$ = new ForCtl ExprNode( $1, $2, $4 ); }819 ;835 { $$ = new ForCtl( $1, $2, $4 ); } 836 ; 820 837 821 838 jump_statement: 822 839 GOTO IDENTIFIER ';' 823 { $$ = new StatementNode( StatementNode::Goto, $2); }840 { $$ = new StatementNode( build_branch( *$2, BranchStmt::Goto ) ); } 824 841 | GOTO '*' comma_expression ';' // GCC, computed goto 825 842 // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3); 826 843 // whereas normal operator precedence yields goto (*i)+3; 827 { $$ = new StatementNode( StatementNode::Goto, $3); }844 { $$ = new StatementNode( build_computedgoto( $3 ) ); } 828 845 | CONTINUE ';' 829 846 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 830 { $$ = new StatementNode( StatementNode::Continue); }847 { $$ = new StatementNode( build_branch( "", BranchStmt::Continue ) ); } 831 848 | CONTINUE IDENTIFIER ';' // CFA, multi-level continue 832 849 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and 833 850 // the target of the transfer appears only at the start of an iteration statement. 834 { $$ = new StatementNode( StatementNode::Continue, $2 ); }851 { $$ = new StatementNode( build_branch( *$2, BranchStmt::Continue ) ); delete $2; } 835 852 | BREAK ';' 836 853 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 837 { $$ = new StatementNode( StatementNode::Break); }854 { $$ = new StatementNode( build_branch( "", BranchStmt::Break ) ); } 838 855 | BREAK IDENTIFIER ';' // CFA, multi-level exit 839 856 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and 840 857 // the target of the transfer appears only at the start of an iteration statement. 841 { $$ = new StatementNode( StatementNode::Break, $2 ); }858 { $$ = new StatementNode( build_branch( *$2, BranchStmt::Break ) ); delete $2; } 842 859 | RETURN comma_expression_opt ';' 843 { $$ = new StatementNode( StatementNode::Return, $2, 0 ); } 844 | THROW assignment_expression_opt ';' 845 { $$ = new StatementNode( StatementNode::Throw, $2, 0 ); } 846 // | THROW ';' 847 // { $$ = new StatementNode( StatementNode::Throw ); } 848 | THROWRESUME assignment_expression_opt ';' 849 { $$ = new StatementNode( StatementNode::Throw, $2, 0 ); } 850 | THROWRESUME assignment_expression_opt AT assignment_expression ';' 851 { $$ = new StatementNode( StatementNode::Throw, $2, 0 ); } 852 // | THROWRESUME ';' 853 // { $$ = new StatementNode( StatementNode::Throw ); } 860 { $$ = new StatementNode( build_return( $2 ) ); } 861 | THROW assignment_expression_opt ';' // handles rethrow 862 { $$ = new StatementNode( build_throw( $2 ) ); } 863 | THROWRESUME assignment_expression_opt ';' // handles reresume 864 { $$ = new StatementNode( build_throw( $2 ) ); } 865 | THROWRESUME assignment_expression_opt AT assignment_expression ';' // handles reresume 866 { $$ = new StatementNode( build_throw( $2 ) ); } 854 867 ; 855 868 856 869 exception_statement: 857 870 TRY compound_statement handler_list 858 { $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 )))); }871 { $$ = new StatementNode( build_try( $2, $3, 0 ) ); } 859 872 | TRY compound_statement finally_clause 860 { $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 )))); }873 { $$ = new StatementNode( build_try( $2, 0, $3 ) ); } 861 874 | TRY compound_statement handler_list finally_clause 862 { 863 $3->set_link( $4 ); 864 $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 )))); 865 } 875 { $$ = new StatementNode( build_try( $2, $3, $4 ) ); } 866 876 ; 867 877 868 878 handler_list: 869 // There must be at least one catch clause870 879 handler_clause 871 880 // ISO/IEC 9899:1999 Section 15.3(6 ) If present, a "..." handler shall be the last handler for its try block. 872 881 | CATCH '(' ELLIPSIS ')' compound_statement 873 { $$ = StatementNode::newCatchStmt( 0, $5, true); }882 { $$ = new StatementNode( build_catch( 0, $5, true ) ); } 874 883 | handler_clause CATCH '(' ELLIPSIS ')' compound_statement 875 { $$ = $1->set_link( StatementNode::newCatchStmt( 0, $6, true) ); }884 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); } 876 885 | CATCHRESUME '(' ELLIPSIS ')' compound_statement 877 { $$ = StatementNode::newCatchStmt( 0, $5, true); }886 { $$ = new StatementNode( build_catch( 0, $5, true ) ); } 878 887 | handler_clause CATCHRESUME '(' ELLIPSIS ')' compound_statement 879 { $$ = $1->set_link( StatementNode::newCatchStmt( 0, $6, true) ); }888 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); } 880 889 ; 881 890 882 891 handler_clause: 883 892 CATCH '(' push push exception_declaration pop ')' compound_statement pop 884 { $$ = StatementNode::newCatchStmt( $5, $8); }893 { $$ = new StatementNode( build_catch( $5, $8 ) ); } 885 894 | handler_clause CATCH '(' push push exception_declaration pop ')' compound_statement pop 886 { $$ = $1->set_link( StatementNode::newCatchStmt( $6, $9) ); }895 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); } 887 896 | CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop 888 { $$ = StatementNode::newCatchStmt( $5, $8); }897 { $$ = new StatementNode( build_catch( $5, $8 ) ); } 889 898 | handler_clause CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop 890 { $$ = $1->set_link( StatementNode::newCatchStmt( $6, $9) ); }899 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); } 891 900 ; 892 901 … … 894 903 FINALLY compound_statement 895 904 { 896 $$ = new StatementNode( StatementNode::Finally, 0, $2 ); 897 std::cout << "Just created a finally node" << std::endl; 905 $$ = new StatementNode( build_finally( $2 ) ); 898 906 } 899 907 ; … … 923 931 asm_statement: 924 932 ASM asm_volatile_opt '(' string_literal_list ')' ';' 925 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, 0); }933 { $$ = new StatementNode( build_asmstmt( $2, $4, 0 ) ); } 926 934 | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ')' ';' // remaining GCC 927 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6); }935 { $$ = new StatementNode( build_asmstmt( $2, $4, $6 ) ); } 928 936 | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ')' ';' 929 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6, $8); }937 { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8 ) ); } 930 938 | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';' 931 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6, $8, $10); }939 { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8, $10 ) ); } 932 940 | ASM asm_volatile_opt GOTO '(' string_literal_list ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';' 933 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $5, 0, $8, $10, $12); }941 { $$ = new StatementNode( build_asmstmt( $2, $5, 0, $8, $10, $12 ) ); } 934 942 ; 935 943 … … 950 958 asm_operand 951 959 | asm_operands_list ',' asm_operand 952 { $$ = (ExpressionNode *)$1->set_l ink( $3 ); }960 { $$ = (ExpressionNode *)$1->set_last( $3 ); } 953 961 ; 954 962 955 963 asm_operand: // GCC 956 964 string_literal_list '(' constant_expression ')' 957 { $$ = new AsmExprNode( 0, $1, $3); }965 { $$ = new ExpressionNode( build_asmexpr( 0, $1, $3 ) ); } 958 966 | '[' constant_expression ']' string_literal_list '(' constant_expression ')' 959 { $$ = new AsmExprNode( $2, $4, $6); }967 { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); } 960 968 ; 961 969 … … 964 972 { $$ = 0; } // use default argument 965 973 | string_literal_list 966 { $$ = $1; }974 { $$ = new ExpressionNode( $1 ); } 967 975 | asm_clobbers_list_opt ',' string_literal_list 968 { $$ = ( ConstantNode *)$1->set_link( $3); }976 { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); } 969 977 ; 970 978 971 979 label_list: 972 980 no_attr_identifier 973 { $$ = new LabelNode(); $$-> append_label($1 ); }981 { $$ = new LabelNode(); $$->labels.push_back( *$1 ); } 974 982 | label_list ',' no_attr_identifier 975 { $$ = $1; $1-> append_label($3 ); }983 { $$ = $1; $1->labels.push_back( *$3 ); } 976 984 ; 977 985 … … 1489 1497 | EXTENSION field_declaring_list ';' // GCC 1490 1498 { // mark all fields in list 1491 for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_ link() )1499 for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_next() ) 1492 1500 iter->set_extension( true ); 1493 1501 $$ = $2; … … 1735 1743 | initializer 1736 1744 | designation initializer { $$ = $2->set_designators( $1 ); } 1737 | initializer_list ',' initializer { $$ = (InitializerNode *)( $1->set_l ink( $3 ) ); }1745 | initializer_list ',' initializer { $$ = (InitializerNode *)( $1->set_last( $3 ) ); } 1738 1746 | initializer_list ',' designation initializer 1739 { $$ = (InitializerNode *)( $1->set_l ink( $4->set_designators( $3 ) ) ); }1747 { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); } 1740 1748 ; 1741 1749 … … 1753 1761 designator_list ':' // C99, CFA uses ":" instead of "=" 1754 1762 | no_attr_identifier_or_type_name ':' // GCC, field name 1755 { $$ = new VarRefNode( $1); }1763 { $$ = new ExpressionNode( build_varref( $1 ) ); } 1756 1764 ; 1757 1765 … … 1759 1767 designator 1760 1768 | designator_list designator 1761 { $$ = (ExpressionNode *)( $1->set_l ink( $2 )); }1762 //| designator_list designator { $$ = new CompositeExprNode( $1, $2 ); }1769 { $$ = (ExpressionNode *)( $1->set_last( $2 ) ); } 1770 //| designator_list designator { $$ = new ExpressionNode( $1, $2 ); } 1763 1771 ; 1764 1772 1765 1773 designator: 1766 // lexer ambiguity: designator ".0" is floating-point constant or designator for name 0 only ".0" and ".1" 1767 // allowed => semantic check 1768 FLOATINGconstant 1769 { $$ = new DesignatorNode( new VarRefNode( $1 ) ); } 1770 | '.' no_attr_identifier_or_type_name // C99, field name 1771 { $$ = new DesignatorNode( new VarRefNode( $2 ) ); } 1774 '.' no_attr_identifier_or_type_name // C99, field name 1775 { $$ = new ExpressionNode( build_varref( $2 ) ); } 1772 1776 | '[' push assignment_expression pop ']' // C99, single array element 1773 1777 // assignment_expression used instead of constant_expression because of shift/reduce conflicts with tuple. 1774 { $$ = new DesignatorNode( $3, true ); }1778 { $$ = $3; } 1775 1779 | '[' push subrange pop ']' // CFA, multiple array elements 1776 { $$ = new DesignatorNode( $3, true ); }1780 { $$ = $3; } 1777 1781 | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements 1778 { $$ = new DesignatorNode( new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $3, $5 ), true); }1782 { $$ = new ExpressionNode( build_range( $3, $5 ) ); } 1779 1783 | '.' '[' push field_list pop ']' // CFA, tuple field selector 1780 { $$ = new DesignatorNode( $4 ); }1784 { $$ = $4; } 1781 1785 ; 1782 1786 … … 1866 1870 type_name_list: // CFA 1867 1871 type_name 1868 { $$ = new TypeValueNode( $1); }1872 { $$ = new ExpressionNode( build_typevalue( $1 ) ); } 1869 1873 | assignment_expression 1870 1874 | type_name_list ',' type_name 1871 { $$ = (ExpressionNode *)( $1->set_l ink( new TypeValueNode( $3 ))); }1875 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( build_typevalue( $3 ) ) ) ); } 1872 1876 | type_name_list ',' assignment_expression 1873 { $$ = (ExpressionNode *)( $1->set_l ink( $3 )); }1877 { $$ = (ExpressionNode *)( $1->set_last( $3 )); } 1874 1878 ; 1875 1879 … … 2009 2013 | EXTENSION external_definition 2010 2014 { // mark all fields in list 2011 for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_ link() )2015 for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_next() ) 2012 2016 iter->set_extension( true ); 2013 2017 $$ = $2; … … 2105 2109 subrange: 2106 2110 constant_expression '~' constant_expression // CFA, integer subrange 2107 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $1, $3); }2111 { $$ = new ExpressionNode( build_range( $1, $3 ) ); } 2108 2112 ; 2109 2113
Note:
See TracChangeset
for help on using the changeset viewer.