Changeset 17cd4eb for translator/Parser
- Timestamp:
- Jan 7, 2015, 6:04:42 PM (11 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 0b8cd722
- Parents:
- d9a0e76
- Location:
- translator/Parser
- Files:
-
- 5 edited
-
DeclarationNode.cc (modified) (2 diffs)
-
InitializerNode.cc (modified) (3 diffs)
-
ParseNode.h (modified) (1 diff)
-
TypeData.cc (modified) (13 diffs)
-
cfa.y (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
translator/Parser/DeclarationNode.cc
rd9a0e76 r17cd4eb 19 19 /* these must remain in the same order as the corresponding DeclarationNode enumerations */ 20 20 const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue" }; 21 const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", " bool", "complex", "imaginary" };21 const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary" }; 22 22 const char *DeclarationNode::modifierName[] = { "signed", "unsigned", "short", "long" }; 23 23 const char *DeclarationNode::tyConName[] = { "struct", "union", "context" }; … … 799 799 } else if ( StructDecl *agg = dynamic_cast< StructDecl* >( decl ) ) { 800 800 StructInstType *inst = new StructInstType( Type::Qualifiers(), agg->get_name() ); 801 *out++ = new ObjectDecl( "", Declaration::NoStorageClass, linkage, 0, inst, 0 );801 *out++ = new ObjectDecl( "", Declaration::NoStorageClass, linkage, 0, inst, 0 ); 802 802 delete agg; 803 803 } else if ( UnionDecl *agg = dynamic_cast< UnionDecl* >( decl ) ) { 804 804 UnionInstType *inst = new UnionInstType( Type::Qualifiers(), agg->get_name() ); 805 *out++ = new ObjectDecl( "", Declaration::NoStorageClass, linkage, 0, inst, 0 );805 *out++ = new ObjectDecl( "", Declaration::NoStorageClass, linkage, 0, inst, 0 ); 806 806 } 807 807 } -
translator/Parser/InitializerNode.cc
rd9a0e76 r17cd4eb 43 43 if ( designator != 0 ) { 44 44 os << "designated by: ("; 45 ExpressionNode *curdes = designator;45 ExpressionNode *curdes = designator; 46 46 while( curdes != 0) { 47 47 curdes->printOneLine(os); 48 48 curdes = (ExpressionNode *)(curdes->get_link()); 49 49 if ( curdes ) os << ", "; 50 } 50 } // while 51 51 os << ")"; 52 } 52 } // if 53 53 if ( expr ) expr->printOneLine(os); 54 54 } else { // It's an aggregate … … 57 57 next_init()->printOneLine(os); 58 58 if (aggregate) os << "--]"; 59 } 59 } // if 60 60 61 61 InitializerNode *moreInit; … … 88 88 if ( get_expression() != 0) 89 89 return new SingleInit( get_expression()->build(), designators ); 90 } 90 } // if 91 91 92 92 return 0; -
translator/Parser/ParseNode.h
rd9a0e76 r17cd4eb 456 456 ExpressionNode *get_expression() const { return expr; } 457 457 458 InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; }458 InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; } 459 459 ExpressionNode *get_designators() const { return designator; } 460 460 -
translator/Parser/TypeData.cc
rd9a0e76 r17cd4eb 560 560 if ( *i == DeclarationNode::Void ) { 561 561 if ( basic->typeSpec.size() != 1 || !basic->modifiers.empty() ) { 562 throw SemanticError( "invalid type specifier \"void\" in type ", this );562 throw SemanticError( "invalid type specifier \"void\" in type: ", this ); 563 563 } else { 564 564 return new VoidType( buildQualifiers() ); … … 571 571 case DeclarationNode::Float: 572 572 if ( sawDouble ) { 573 throw SemanticError( "invalid type specifier \"float\" in type ", this );573 throw SemanticError( "invalid type specifier \"float\" in type: ", this ); 574 574 } else { 575 575 switch ( ret ) { … … 581 581 break; 582 582 default: 583 throw SemanticError( "invalid type specifier \"float\" in type ", this );583 throw SemanticError( "invalid type specifier \"float\" in type: ", this ); 584 584 } 585 585 } … … 587 587 case DeclarationNode::Double: 588 588 if ( sawDouble ) { 589 throw SemanticError( "duplicate type specifier \"double\" in type ", this );589 throw SemanticError( "duplicate type specifier \"double\" in type: ", this ); 590 590 } else { 591 591 switch ( ret ) { … … 594 594 break; 595 595 default: 596 throw SemanticError( "invalid type specifier \"double\" in type ", this );596 throw SemanticError( "invalid type specifier \"double\" in type: ", this ); 597 597 } 598 598 } … … 609 609 break; 610 610 default: 611 throw SemanticError( "invalid type specifier \" complex\" in type", this );611 throw SemanticError( "invalid type specifier \"_Complex\" in type: ", this ); 612 612 } 613 613 break; … … 623 623 break; 624 624 default: 625 throw SemanticError( "invalid type specifier \" imaginary\" in type", this );625 throw SemanticError( "invalid type specifier \"_Imaginary\" in type: ", this ); 626 626 } 627 627 break; 628 628 629 629 default: 630 throw SemanticError( std::string( "invalid type specifier \"" ) + DeclarationNode::basicTypeName[ *i ] + "\" in type ", this );630 throw SemanticError( std::string( "invalid type specifier \"" ) + DeclarationNode::basicTypeName[ *i ] + "\" in type: ", this ); 631 631 } 632 632 } … … 666 666 break; 667 667 default: 668 throw SemanticError( "invalid type modifier \"long\" in type ", this );668 throw SemanticError( "invalid type modifier \"long\" in type: ", this ); 669 669 } 670 670 } … … 683 683 break; 684 684 default: 685 throw SemanticError( "invalid type modifier \"short\" in type ", this );685 throw SemanticError( "invalid type modifier \"short\" in type: ", this ); 686 686 } 687 687 } … … 692 692 ret = BasicType::SignedInt; 693 693 } else if ( sawSigned ) { 694 throw SemanticError( "duplicate type modifer \"signed\" in type ", this );694 throw SemanticError( "duplicate type modifer \"signed\" in type: ", this ); 695 695 } else { 696 696 switch ( ret ) { … … 702 702 break; 703 703 default: 704 throw SemanticError( "invalid type modifer \"signed\" in type ", this );704 throw SemanticError( "invalid type modifer \"signed\" in type: ", this ); 705 705 } 706 706 } … … 711 711 ret = BasicType::UnsignedInt; 712 712 } else if ( sawSigned ) { 713 throw SemanticError( "invalid type modifer \"unsigned\" in type ", this );713 throw SemanticError( "invalid type modifer \"unsigned\" in type: ", this ); 714 714 } else { 715 715 switch ( ret ) { … … 727 727 break; 728 728 default: 729 throw SemanticError( "invalid type modifer \"unsigned\" in type ", this );729 throw SemanticError( "invalid type modifer \"unsigned\" in type: ", this ); 730 730 } 731 731 } -
translator/Parser/cfa.y
rd9a0e76 r17cd4eb 10 10 * Created On : Sat Sep 1 20:22:55 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Tue Nov 25 23:52:54 201413 * Update Count : 89012 * Last Modified On : Wed Jan 7 09:19:57 2015 13 * Update Count : 906 14 14 */ 15 15 … … 294 294 /* ENUMERATIONconstant is not included here; it is treated as a variable with type 295 295 "enumeration constant". */ 296 INTEGERconstant { $$ = new ConstantNode(ConstantNode::Integer, $1); }297 | FLOATINGconstant { $$ = new ConstantNode(ConstantNode::Float, $1); }298 | CHARACTERconstant { $$ = new ConstantNode(ConstantNode::Character, $1); }296 INTEGERconstant { $$ = new ConstantNode(ConstantNode::Integer, $1); } 297 | FLOATINGconstant { $$ = new ConstantNode(ConstantNode::Float, $1); } 298 | CHARACTERconstant { $$ = new ConstantNode(ConstantNode::Character, $1); } 299 299 ; 300 300 … … 320 320 321 321 string_literal_list: /* juxtaposed strings are concatenated */ 322 STRINGliteral { $$ = new ConstantNode(ConstantNode::String, $1); }323 | string_literal_list STRINGliteral { $$ = $1->append( $2 ); }322 STRINGliteral { $$ = new ConstantNode(ConstantNode::String, $1); } 323 | string_literal_list STRINGliteral { $$ = $1->append( $2 ); } 324 324 ; 325 325 … … 352 352 { $$ = new CompositeExprNode($1, $3); } 353 353 | postfix_expression '.' no_attr_identifier 354 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::FieldSel), $1, 355 new VarRefNode($3)); } 354 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::FieldSel), $1, new VarRefNode($3)); } 356 355 | postfix_expression '.' '[' push field_list pop ']' /* CFA, tuple field selector */ 357 356 | postfix_expression ARROW no_attr_identifier 358 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::PFieldSel), $1, 359 new VarRefNode($3)); } 357 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::PFieldSel), $1, new VarRefNode($3)); } 360 358 | postfix_expression ARROW '[' push field_list pop ']' /* CFA, tuple field selector */ 361 359 | postfix_expression ICR … … 371 369 argument_expression 372 370 | argument_expression_list ',' argument_expression 373 { $$ = (ExpressionNode *)($1->set_link($3)); }371 { $$ = (ExpressionNode *)($1->set_link($3)); } 374 372 ; 375 373 … … 379 377 | assignment_expression 380 378 | no_attr_identifier ':' assignment_expression 381 { $$ = $3->set_asArgName($1); }379 { $$ = $3->set_asArgName($1); } 382 380 /* Only a list of no_attr_identifier_or_typedef_name is allowed in this context. However, there 383 381 is insufficient look ahead to distinguish between this list of parameter names and a tuple, … … 391 389 field_list: /* CFA, tuple field selector */ 392 390 field 393 | field_list ',' field { $$ = (ExpressionNode *)$1->set_link( $3 ); }391 | field_list ',' field { $$ = (ExpressionNode *)$1->set_link( $3 ); } 394 392 ; 395 393 396 394 field: /* CFA, tuple field selector */ 397 395 no_attr_identifier 398 { $$ = new VarRefNode( $1 ); }396 { $$ = new VarRefNode( $1 ); } 399 397 | no_attr_identifier '.' field 400 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::FieldSel), new VarRefNode( $1 ), $3); }398 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::FieldSel), new VarRefNode( $1 ), $3); } 401 399 | no_attr_identifier '.' '[' push field_list pop ']' 402 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::FieldSel), new VarRefNode( $1 ), $5); }400 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::FieldSel), new VarRefNode( $1 ), $5); } 403 401 | no_attr_identifier ARROW field 404 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::PFieldSel), new VarRefNode( $1 ), $3); }402 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::PFieldSel), new VarRefNode( $1 ), $3); } 405 403 | no_attr_identifier ARROW '[' push field_list pop ']' 406 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::PFieldSel), new VarRefNode( $1 ), $5); }404 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::PFieldSel), new VarRefNode( $1 ), $5); } 407 405 ; 408 406 … … 440 438 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::AlignOf), new TypeValueNode($3)); } 441 439 | ANDAND no_attr_identifier /* GCC, address of label */ 442 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::LabelAddress), 443 new VarRefNode($2, true)); } 440 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::LabelAddress), new VarRefNode($2, true)); } 444 441 ; 445 442 446 443 unary_operator: 447 '&' { $$ = new OperatorNode(OperatorNode::AddressOf); }448 | '+' { $$ = new OperatorNode(OperatorNode::UnPlus); }449 | '-' { $$ = new OperatorNode(OperatorNode::UnMinus); }450 | '~' { $$ = new OperatorNode(OperatorNode::BitNeg); }444 '&' { $$ = new OperatorNode(OperatorNode::AddressOf); } 445 | '+' { $$ = new OperatorNode(OperatorNode::UnPlus); } 446 | '-' { $$ = new OperatorNode(OperatorNode::UnMinus); } 447 | '~' { $$ = new OperatorNode(OperatorNode::BitNeg); } 451 448 ; 452 449 … … 454 451 unary_expression 455 452 | '(' type_name_no_function ')' cast_expression 456 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Cast), 457 new TypeValueNode($2), $4); } 453 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Cast), new TypeValueNode($2), $4); } 458 454 | '(' type_name_no_function ')' tuple 459 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Cast), 460 new TypeValueNode($2), $4); } 455 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Cast), new TypeValueNode($2), $4); } 461 456 ; 462 457 … … 464 459 cast_expression 465 460 | multiplicative_expression '*' cast_expression 466 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Mul),$1,$3); }461 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Mul),$1,$3); } 467 462 | multiplicative_expression '/' cast_expression 468 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Div),$1,$3); }463 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Div),$1,$3); } 469 464 | multiplicative_expression '%' cast_expression 470 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Mod),$1,$3); }465 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Mod),$1,$3); } 471 466 ; 472 467 … … 474 469 multiplicative_expression 475 470 | additive_expression '+' multiplicative_expression 476 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Plus),$1,$3); }471 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Plus),$1,$3); } 477 472 | additive_expression '-' multiplicative_expression 478 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Minus),$1,$3); }473 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Minus),$1,$3); } 479 474 ; 480 475 … … 482 477 additive_expression 483 478 | shift_expression LS additive_expression 484 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::LShift),$1,$3); }479 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::LShift),$1,$3); } 485 480 | shift_expression RS additive_expression 486 481 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::RShift),$1,$3); } … … 558 553 conditional_expression 559 554 | unary_expression '=' assignment_expression 560 { $$ =new CompositeExprNode(new OperatorNode(OperatorNode::Assign), $1, $3); }555 { $$ =new CompositeExprNode(new OperatorNode(OperatorNode::Assign), $1, $3); } 561 556 | unary_expression assignment_operator assignment_expression 562 { $$ =new CompositeExprNode($2, $1, $3); }557 { $$ =new CompositeExprNode($2, $1, $3); } 563 558 | tuple assignment_opt /* CFA, tuple expression */ 564 559 { … … 1209 1204 typedefTable.enterScope(); 1210 1205 } 1211 type_parameter_list ')' /* CFA */1206 type_parameter_list ')' /* CFA */ 1212 1207 { 1213 1208 typedefTable.leaveScope(); … … 1630 1625 1631 1626 initializer_opt: 1632 /* empty */ { $$ = 0; }1633 | '=' initializer { $$ = $2; }1627 /* empty */ { $$ = 0; } 1628 | '=' initializer { $$ = $2; } 1634 1629 ; 1635 1630 1636 1631 initializer: 1637 assignment_expression { $$ = new InitializerNode($1); }1638 | '{' initializer_list comma_opt '}' { $$ = new InitializerNode($2, true); }1632 assignment_expression { $$ = new InitializerNode($1); } 1633 | '{' initializer_list comma_opt '}' { $$ = new InitializerNode($2, true); } 1639 1634 ; 1640 1635 1641 1636 initializer_list: 1642 1637 initializer 1643 | designation initializer { $$ = $2->set_designators( $1 ); }1644 | initializer_list ',' initializer { $$ = (InitializerNode *)( $1->set_link($3) ); }1638 | designation initializer { $$ = $2->set_designators( $1 ); } 1639 | initializer_list ',' initializer { $$ = (InitializerNode *)( $1->set_link($3) ); } 1645 1640 | initializer_list ',' designation initializer 1646 { $$ = (InitializerNode *)( $1->set_link( $4->set_designators($3) ) ); }1641 { $$ = (InitializerNode *)( $1->set_link( $4->set_designators($3) ) ); } 1647 1642 ; 1648 1643 … … 1659 1654 designation: 1660 1655 designator_list ':' /* ANSI99, CFA uses ":" instead of "=" */ 1661 | no_attr_identifier_or_typedef_name ':' /* GCC, field name */1662 { $$ = new VarRefNode( $1 ); }1656 | no_attr_identifier_or_typedef_name ':' /* GCC, field name */ 1657 { $$ = new VarRefNode( $1 ); } 1663 1658 ; 1664 1659 1665 1660 designator_list: /* ANSI99 */ 1666 1661 designator 1667 | designator_list designator { $$ = (ExpressionNode *)($1->set_link( $2 )); }1662 | designator_list designator { $$ = (ExpressionNode *)($1->set_link( $2 )); } 1668 1663 ; 1669 1664 1670 1665 designator: 1671 1666 '.' no_attr_identifier_or_typedef_name /* ANSI99, field name */ 1672 { $$ = new VarRefNode( $2 ); }1667 { $$ = new VarRefNode( $2 ); } 1673 1668 | '[' push assignment_expression pop ']' /* ANSI99, single array element */ 1674 1669 /* assignment_expression used instead of constant_expression because of shift/reduce conflicts 1675 1670 with tuple. */ 1676 { $$ = $3; }1671 { $$ = $3; } 1677 1672 | '[' push subrange pop ']' /* CFA, multiple array elements */ 1678 { $$ = $3; }1673 { $$ = $3; } 1679 1674 | '[' push constant_expression ELLIPSIS constant_expression pop ']' /* GCC, multiple array elements */ 1680 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Range), $3, $5); }1675 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Range), $3, $5); } 1681 1676 | '.' '[' push field_list pop ']' /* CFA, tuple field selector */ 1682 { $$ = $4; }1677 { $$ = $4; } 1683 1678 ; 1684 1679 … … 2492 2487 ISO/IEC 9899:1999 Section 6.7.5.2(1) : "The optional type qualifiers and the keyword static shall 2493 2488 appear only in a declaration of a function parameter with an array type, and then only in the 2494 outermost array type derivation." 2495 */ 2489 outermost array type derivation." */ 2496 2490 2497 2491 array_parameter_1st_dimension: 2498 2492 '[' push pop ']' 2499 2493 { $$ = DeclarationNode::newArray( 0, 0, false ); } 2494 // multi_array_dimension handles the '[' '*' ']' case 2500 2495 | '[' push type_qualifier_list '*' pop ']' /* remaining ANSI99 */ 2501 2496 { $$ = DeclarationNode::newVarArray( $3 ); } 2497 | '[' push type_qualifier_list pop ']' 2498 { $$ = DeclarationNode::newArray( 0, $3, false ); } 2499 // multi_array_dimension handles the '[' assignment_expression ']' case 2502 2500 | '[' push type_qualifier_list assignment_expression pop ']' 2503 2501 { $$ = DeclarationNode::newArray( $4, $3, false ); } 2504 | '[' push STATIC assignment_expression pop ']' 2505 { $$ = DeclarationNode::newArray( $4, 0, true ); } 2506 | '[' push STATIC type_qualifier_list assignment_expression pop ']' 2502 | '[' push STATIC type_qualifier_list_opt assignment_expression pop ']' 2507 2503 { $$ = DeclarationNode::newArray( $5, $4, true ); } 2504 | '[' push type_qualifier_list STATIC assignment_expression pop ']' 2505 { $$ = DeclarationNode::newArray( $5, $3, true ); } 2508 2506 ; 2509 2507
Note:
See TracChangeset
for help on using the changeset viewer.