Changeset 32a2a99 for src/Parser/TypeData.cc
- Timestamp:
- Aug 30, 2016, 4:25:55 PM (8 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, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 90e2334, fa463f1
- Parents:
- a2a8d2a6 (diff), ced2e989 (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/TypeData.cc
ra2a8d2a6 r32a2a99 10 10 // Created On : Sat May 16 15:12:51 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 18 23:48:44201613 // Update Count : 6412 // Last Modified On : Sun Aug 28 18:28:58 2016 13 // Update Count : 223 14 14 // 15 15 … … 94 94 break; 95 95 } // switch 96 } 96 } // TypeData::TypeData 97 97 98 98 TypeData::~TypeData() { … … 163 163 break; 164 164 } // switch 165 } 166 167 TypeData * TypeData::clone() const {168 TypeData * newtype = new TypeData( kind );165 } // TypeData::~TypeData 166 167 TypeData * TypeData::clone() const { 168 TypeData * newtype = new TypeData( kind ); 169 169 newtype->qualifiers = qualifiers; 170 170 newtype->base = maybeClone( base ); … … 238 238 } // switch 239 239 return newtype; 240 } 240 } // TypeData::clone 241 241 242 242 void TypeData::print( std::ostream &os, int indent ) const { … … 244 244 using std::string; 245 245 246 printEnums( qualifiers.begin(), qualifiers.end(), DeclarationNode::qualifierName, os ); 246 for ( int i = 0; i < DeclarationNode::NoOfQualifier; i += 1 ) { 247 if ( qualifiers[i] ) os << DeclarationNode::qualifierName[ i ] << ' '; 248 } // for 247 249 248 250 if ( forall ) { … … 416 418 assert( false ); 417 419 } // switch 418 } 419 420 TypeData *TypeData::extractAggregate( bool toplevel ) const { 421 TypeData *ret = 0; 422 423 switch ( kind ) { 424 case Aggregate: 425 if ( ! toplevel && aggregate->fields ) { 426 ret = clone(); 427 ret->qualifiers.clear(); 428 } // if 429 break; 430 case Enum: 431 if ( ! toplevel && enumeration->constants ) { 432 ret = clone(); 433 ret->qualifiers.clear(); 434 } // if 435 break; 436 case AggregateInst: 437 if ( aggInst->aggregate ) { 438 ret = aggInst->aggregate->extractAggregate( false ); 439 } // if 440 break; 441 default: 442 if ( base ) { 443 ret = base->extractAggregate( false ); 444 } // if 445 } // switch 446 return ret; 447 } 448 449 void buildForall( const DeclarationNode *firstNode, std::list< TypeDecl* > &outputList ) { 420 } // TypeData::print 421 422 void buildForall( const DeclarationNode * firstNode, std::list< TypeDecl* > &outputList ) { 450 423 buildList( firstNode, outputList ); 451 424 for ( std::list< TypeDecl* >::iterator i = outputList.begin(); i != outputList.end(); ++i ) { … … 453 426 // add assertion parameters to `type' tyvars in reverse order 454 427 // add dtor: void ^?{}(T *) 455 FunctionType * dtorType = new FunctionType( Type::Qualifiers(), false );428 FunctionType * dtorType = new FunctionType( Type::Qualifiers(), false ); 456 429 dtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0 ) ); 457 430 (*i)->get_assertions().push_front( new FunctionDecl( "^?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, dtorType, 0, false, false ) ); 458 431 459 432 // add copy ctor: void ?{}(T *, T) 460 FunctionType * copyCtorType = new FunctionType( Type::Qualifiers(), false );433 FunctionType * copyCtorType = new FunctionType( Type::Qualifiers(), false ); 461 434 copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0 ) ); 462 435 copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0 ) ); … … 464 437 465 438 // add default ctor: void ?{}(T *) 466 FunctionType * ctorType = new FunctionType( Type::Qualifiers(), false );439 FunctionType * ctorType = new FunctionType( Type::Qualifiers(), false ); 467 440 ctorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0 ) ); 468 441 (*i)->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, ctorType, 0, false, false ) ); 469 442 470 443 // add assignment operator: T * ?=?(T *, T) 471 FunctionType * assignType = new FunctionType( Type::Qualifiers(), false );444 FunctionType * assignType = new FunctionType( Type::Qualifiers(), false ); 472 445 assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0 ) ); 473 446 assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0 ) ); … … 478 451 } 479 452 480 Declaration *TypeData::buildDecl( std::string name, DeclarationNode::StorageClass sc, Expression *bitfieldWidth, bool isInline, bool isNoreturn, LinkageSpec::Spec linkage, Initializer *init ) const { 481 if ( kind == TypeData::Function ) { 482 FunctionDecl *decl; 483 if ( function->hasBody ) { 484 if ( function->body ) { 485 Statement *stmt = function->body->build(); 486 CompoundStmt *body = dynamic_cast< CompoundStmt* >( stmt ); 487 assert( body ); 488 decl = new FunctionDecl( name, sc, linkage, buildFunction(), body, isInline, isNoreturn ); 489 } else { 490 // std::list< Label > ls; 491 decl = new FunctionDecl( name, sc, linkage, buildFunction(), new CompoundStmt( std::list< Label >() ), isInline, isNoreturn ); 492 } // if 493 } else { 494 decl = new FunctionDecl( name, sc, linkage, buildFunction(), 0, isInline, isNoreturn ); 495 } // if 496 for ( DeclarationNode *cur = function->idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) { 497 if ( cur->get_name() != "" ) { 498 decl->get_oldIdents().insert( decl->get_oldIdents().end(), cur->get_name() ); 499 } // if 500 } // for 501 buildList( function->oldDeclList, decl->get_oldDecls() ); 502 return decl; 503 } else if ( kind == TypeData::Aggregate ) { 504 return buildAggregate(); 505 } else if ( kind == TypeData::Enum ) { 506 return buildEnum(); 507 } else if ( kind == TypeData::Symbolic ) { 508 return buildSymbolic( name, sc ); 509 } else if ( kind == TypeData::Variable ) { 510 return buildVariable(); 511 } else { 512 return new ObjectDecl( name, sc, linkage, bitfieldWidth, build(), init, std::list< Attribute * >(), isInline, isNoreturn ); 513 } // if 514 return 0; 515 } 516 517 Type *TypeData::build() const { 518 switch ( kind ) { 519 case Unknown: 453 Type * typebuild( const TypeData * td ) { 454 assert( td ); 455 switch ( td->kind ) { 456 case TypeData::Unknown: 520 457 // fill in implicit int 521 return new BasicType( buildQualifiers( ), BasicType::SignedInt );522 case Basic:523 return buildBasicType( );524 case Pointer:525 return buildPointer( );526 case Array:527 return buildArray( );528 case Function:529 return buildFunction( );530 case AggregateInst:531 return buildAggInst( );532 case EnumConstant:458 return new BasicType( buildQualifiers( td ), BasicType::SignedInt ); 459 case TypeData::Basic: 460 return buildBasicType( td ); 461 case TypeData::Pointer: 462 return buildPointer( td ); 463 case TypeData::Array: 464 return buildArray( td ); 465 case TypeData::Function: 466 return buildFunction( td ); 467 case TypeData::AggregateInst: 468 return buildAggInst( td ); 469 case TypeData::EnumConstant: 533 470 // the name gets filled in later -- by SymTab::Validate 534 return new EnumInstType( buildQualifiers( ), "" );535 case SymbolicInst:536 return buildSymbolicInst( );;537 case T uple:538 return buildTuple( );539 case Type of:540 return buildTypeof( );541 case Builtin:542 return new VarArgsType( buildQualifiers( ) );543 case Attr:544 return buildAttr( );545 case Symbolic:546 case Enum:547 case Aggregate:548 case Variable:471 return new EnumInstType( buildQualifiers( td ), "" ); 472 case TypeData::SymbolicInst: 473 return buildSymbolicInst( td );; 474 case TypeData::Tuple: 475 return buildTuple( td ); 476 case TypeData::Typeof: 477 return buildTypeof( td ); 478 case TypeData::Builtin: 479 return new VarArgsType( buildQualifiers( td ) ); 480 case TypeData::Attr: 481 return buildAttr( td ); 482 case TypeData::Symbolic: 483 case TypeData::Enum: 484 case TypeData::Aggregate: 485 case TypeData::Variable: 549 486 assert( false ); 550 487 } // switch 551 488 return 0; 552 } 553 554 Type::Qualifiers TypeData::buildQualifiers() const { 489 } // typebuild 490 491 TypeData * typeextractAggregate( const TypeData * td, bool toplevel ) { 492 TypeData * ret = 0; 493 494 switch ( td->kind ) { 495 case TypeData::Aggregate: 496 if ( ! toplevel && td->aggregate->fields ) { 497 ret = td->clone(); 498 } // if 499 break; 500 case TypeData::Enum: 501 if ( ! toplevel && td->enumeration->constants ) { 502 ret = td->clone(); 503 } // if 504 break; 505 case TypeData::AggregateInst: 506 if ( td->aggInst->aggregate ) { 507 ret = typeextractAggregate( td->aggInst->aggregate, false ); 508 } // if 509 break; 510 default: 511 if ( td->base ) { 512 ret = typeextractAggregate( td->base, false ); 513 } // if 514 } // switch 515 return ret; 516 } // typeextractAggregate 517 518 Type::Qualifiers buildQualifiers( const TypeData * td ) { 555 519 Type::Qualifiers q; 556 for ( std::list< DeclarationNode::Qualifier >::const_iterator i = qualifiers.begin(); i != qualifiers.end(); ++i ) { 557 switch ( *i ) { 558 case DeclarationNode::Const: 559 q.isConst = true; 560 break; 561 case DeclarationNode::Volatile: 562 q.isVolatile = true; 563 break; 564 case DeclarationNode::Restrict: 565 q.isRestrict = true; 566 break; 567 case DeclarationNode::Lvalue: 568 q.isLvalue = true; 569 break; 570 case DeclarationNode::Atomic: 571 q.isAtomic = true; 572 break; 573 } // switch 574 } // for 520 q.isConst = td->qualifiers[ DeclarationNode::Const ]; 521 q.isVolatile = td->qualifiers[ DeclarationNode::Volatile ]; 522 q.isRestrict = td->qualifiers[ DeclarationNode::Restrict ]; 523 q.isLvalue = td->qualifiers[ DeclarationNode::Lvalue ]; 524 q.isAtomic = td->qualifiers[ DeclarationNode::Atomic ];; 575 525 return q; 576 } 577 578 Type * TypeData::buildBasicType() const{526 } // buildQualifiers 527 528 Type * buildBasicType( const TypeData * td ) { 579 529 static const BasicType::Kind kindMap[] = { BasicType::Char, BasicType::SignedInt, BasicType::Float, BasicType::Double, 580 530 BasicType::Char /* void */, BasicType::Bool, BasicType::DoubleComplex, … … 585 535 BasicType::Kind ret; 586 536 587 for ( std::list< DeclarationNode::BasicType >::const_iterator i = basic->typeSpec.begin(); i !=basic->typeSpec.end(); ++i ) {537 for ( std::list< DeclarationNode::BasicType >::const_iterator i = td->basic->typeSpec.begin(); i != td->basic->typeSpec.end(); ++i ) { 588 538 if ( ! init ) { 589 539 init = true; 590 540 if ( *i == DeclarationNode::Void ) { 591 if ( basic->typeSpec.size() != 1 || !basic->modifiers.empty() ) {592 throw SemanticError( "invalid type specifier \"void\" in type: ", t his);541 if ( td->basic->typeSpec.size() != 1 || ! td->basic->modifiers.empty() ) { 542 throw SemanticError( "invalid type specifier \"void\" in type: ", td ); 593 543 } else { 594 return new VoidType( buildQualifiers( ) );544 return new VoidType( buildQualifiers( td ) ); 595 545 } // if 596 546 } else { … … 601 551 case DeclarationNode::Float: 602 552 if ( sawDouble ) { 603 throw SemanticError( "invalid type specifier \"float\" in type: ", t his);553 throw SemanticError( "invalid type specifier \"float\" in type: ", td ); 604 554 } else { 605 555 switch ( ret ) { … … 611 561 break; 612 562 default: 613 throw SemanticError( "invalid type specifier \"float\" in type: ", t his);563 throw SemanticError( "invalid type specifier \"float\" in type: ", td ); 614 564 } // switch 615 565 } // if … … 617 567 case DeclarationNode::Double: 618 568 if ( sawDouble ) { 619 throw SemanticError( "duplicate type specifier \"double\" in type: ", t his);569 throw SemanticError( "duplicate type specifier \"double\" in type: ", td ); 620 570 } else { 621 571 switch ( ret ) { … … 624 574 break; 625 575 default: 626 throw SemanticError( "invalid type specifier \"double\" in type: ", t his);576 throw SemanticError( "invalid type specifier \"double\" in type: ", td ); 627 577 } // switch 628 578 } // if … … 637 587 break; 638 588 default: 639 throw SemanticError( "invalid type specifier \"_Complex\" in type: ", t his);589 throw SemanticError( "invalid type specifier \"_Complex\" in type: ", td ); 640 590 } // switch 641 591 break; … … 649 599 break; 650 600 default: 651 throw SemanticError( "invalid type specifier \"_Imaginary\" in type: ", t his);601 throw SemanticError( "invalid type specifier \"_Imaginary\" in type: ", td ); 652 602 } // switch 653 603 break; 654 604 default: 655 throw SemanticError( std::string( "invalid type specifier \"" ) + DeclarationNode::basicTypeName[ *i ] + "\" in type: ", t his);605 throw SemanticError( std::string( "invalid type specifier \"" ) + DeclarationNode::basicTypeName[ *i ] + "\" in type: ", td ); 656 606 } // switch 657 607 } // if … … 661 611 } // for 662 612 663 for ( std::list< DeclarationNode::Modifier >::const_iterator i = basic->modifiers.begin(); i !=basic->modifiers.end(); ++i ) {613 for ( std::list< DeclarationNode::Modifier >::const_iterator i = td->basic->modifiers.begin(); i != td->basic->modifiers.end(); ++i ) { 664 614 switch ( *i ) { 665 615 case DeclarationNode::Long: … … 691 641 break; 692 642 default: 693 throw SemanticError( "invalid type modifier \"long\" in type: ", t his);643 throw SemanticError( "invalid type modifier \"long\" in type: ", td ); 694 644 } // switch 695 645 } // if … … 708 658 break; 709 659 default: 710 throw SemanticError( "invalid type modifier \"short\" in type: ", t his);660 throw SemanticError( "invalid type modifier \"short\" in type: ", td ); 711 661 } // switch 712 662 } // if … … 717 667 ret = BasicType::SignedInt; 718 668 } else if ( sawSigned ) { 719 throw SemanticError( "duplicate type modifer \"signed\" in type: ", t his);669 throw SemanticError( "duplicate type modifer \"signed\" in type: ", td ); 720 670 } else { 721 671 switch ( ret ) { … … 733 683 break; 734 684 default: 735 throw SemanticError( "invalid type modifer \"signed\" in type: ", t his);685 throw SemanticError( "invalid type modifer \"signed\" in type: ", td ); 736 686 } // switch 737 687 } // if … … 742 692 ret = BasicType::UnsignedInt; 743 693 } else if ( sawSigned ) { 744 throw SemanticError( "invalid type modifer \"unsigned\" in type: ", t his);694 throw SemanticError( "invalid type modifer \"unsigned\" in type: ", td ); 745 695 } else { 746 696 switch ( ret ) { … … 761 711 break; 762 712 default: 763 throw SemanticError( "invalid type modifer \"unsigned\" in type: ", t his);713 throw SemanticError( "invalid type modifer \"unsigned\" in type: ", td ); 764 714 } // switch 765 715 } // if … … 772 722 } // for 773 723 774 BasicType * bt;724 BasicType * bt; 775 725 if ( ! init ) { 776 bt = new BasicType( buildQualifiers( ), BasicType::SignedInt );726 bt = new BasicType( buildQualifiers( td ), BasicType::SignedInt ); 777 727 } else { 778 bt = new BasicType( buildQualifiers( ), ret );728 bt = new BasicType( buildQualifiers( td ), ret ); 779 729 } // if 780 buildForall( forall, bt->get_forall() );730 buildForall( td->forall, bt->get_forall() ); 781 731 return bt; 782 } 783 784 785 PointerType *TypeData::buildPointer() const { 786 PointerType *pt; 787 if ( base ) { 788 pt = new PointerType( buildQualifiers(), base->build() ); 732 } // buildBasicType 733 734 PointerType * buildPointer( const TypeData * td ) { 735 PointerType * pt; 736 if ( td->base ) { 737 pt = new PointerType( buildQualifiers( td ), typebuild( td->base ) ); 789 738 } else { 790 pt = new PointerType( buildQualifiers( ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );739 pt = new PointerType( buildQualifiers( td ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); 791 740 } // if 792 buildForall( forall, pt->get_forall() );741 buildForall( td->forall, pt->get_forall() ); 793 742 return pt; 794 } 795 796 ArrayType * TypeData::buildArray() const{797 ArrayType * at;798 if ( base ) {799 at = new ArrayType( buildQualifiers( ), base->build(), maybeBuild< Expression >(array->dimension ),800 array->isVarLen,array->isStatic );743 } // buildPointer 744 745 ArrayType * buildArray( const TypeData * td ) { 746 ArrayType * at; 747 if ( td->base ) { 748 at = new ArrayType( buildQualifiers( td ), typebuild( td->base ), maybeBuild< Expression >( td->array->dimension ), 749 td->array->isVarLen, td->array->isStatic ); 801 750 } else { 802 at = new ArrayType( buildQualifiers( ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ),803 maybeBuild< Expression >( array->dimension ), array->isVarLen,array->isStatic );751 at = new ArrayType( buildQualifiers( td ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 752 maybeBuild< Expression >( td->array->dimension ), td->array->isVarLen, td->array->isStatic ); 804 753 } // if 805 buildForall( forall, at->get_forall() );754 buildForall( td->forall, at->get_forall() ); 806 755 return at; 807 } 808 809 FunctionType *TypeData::buildFunction() const { 810 assert( kind == Function ); 811 bool hasEllipsis = function->params ? function->params->get_hasEllipsis() : true; 812 if ( ! function->params ) hasEllipsis = ! function->newStyle; 813 FunctionType *ft = new FunctionType( buildQualifiers(), hasEllipsis ); 814 buildList( function->params, ft->get_parameters() ); 815 buildForall( forall, ft->get_forall() ); 816 if ( base ) { 817 switch ( base->kind ) { 818 case Tuple: 819 buildList( base->tuple->members, ft->get_returnVals() ); 756 } // buildPointer 757 758 AggregateDecl * buildAggregate( const TypeData * td ) { 759 assert( td->kind == TypeData::Aggregate ); 760 AggregateDecl * at; 761 switch ( td->aggregate->kind ) { 762 case DeclarationNode::Struct: 763 at = new StructDecl( td->aggregate->name ); 764 buildForall( td->aggregate->params, at->get_parameters() ); 765 break; 766 case DeclarationNode::Union: 767 at = new UnionDecl( td->aggregate->name ); 768 buildForall( td->aggregate->params, at->get_parameters() ); 769 break; 770 case DeclarationNode::Trait: 771 at = new TraitDecl( td->aggregate->name ); 772 buildList( td->aggregate->params, at->get_parameters() ); 773 break; 774 default: 775 assert( false ); 776 } // switch 777 778 buildList( td->aggregate->fields, at->get_members() ); 779 at->set_body( td->aggregate->body ); 780 781 return at; 782 } // buildAggregate 783 784 ReferenceToType * buildAggInst( const TypeData * td ) { 785 assert( td->kind == TypeData::AggregateInst ); 786 787 ReferenceToType * ret; 788 if ( td->aggInst->aggregate->kind == TypeData::Enum ) { 789 ret = new EnumInstType( buildQualifiers( td ), td->aggInst->aggregate->enumeration->name ); 790 } else { 791 assert( td->aggInst->aggregate->kind == TypeData::Aggregate ); 792 switch ( td->aggInst->aggregate->aggregate->kind ) { 793 case DeclarationNode::Struct: 794 ret = new StructInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name ); 795 break; 796 case DeclarationNode::Union: 797 ret = new UnionInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name ); 798 break; 799 case DeclarationNode::Trait: 800 ret = new TraitInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name ); 820 801 break; 821 802 default: 822 ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType* >( base->buildDecl( "", DeclarationNode::NoStorageClass, 0, false, false, LinkageSpec::Cforall ) ) ); 803 assert( false ); 804 } // switch 805 } // if 806 buildList( td->aggInst->params, ret->get_parameters() ); 807 buildForall( td->forall, ret->get_forall() ); 808 return ret; 809 } // buildAggInst 810 811 NamedTypeDecl * buildSymbolic( const TypeData * td, const std::string & name, DeclarationNode::StorageClass sc ) { 812 assert( td->kind == TypeData::Symbolic ); 813 NamedTypeDecl * ret; 814 assert( td->base ); 815 if ( td->symbolic->isTypedef ) { 816 ret = new TypedefDecl( name, sc, typebuild( td->base ) ); 817 } else { 818 ret = new TypeDecl( name, sc, typebuild( td->base ), TypeDecl::Any ); 819 } // if 820 buildList( td->symbolic->params, ret->get_parameters() ); 821 buildList( td->symbolic->assertions, ret->get_assertions() ); 822 return ret; 823 } // buildSymbolic 824 825 TypeDecl * buildVariable( const TypeData * td ) { 826 assert( td->kind == TypeData::Variable ); 827 static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype }; 828 829 TypeDecl * ret = new TypeDecl( td->variable->name, DeclarationNode::NoStorageClass, 0, kindMap[ td->variable->tyClass ] ); 830 buildList( td->variable->assertions, ret->get_assertions() ); 831 return ret; 832 } // buildSymbolic 833 834 EnumDecl * buildEnum( const TypeData * td ) { 835 assert( td->kind == TypeData::Enum ); 836 EnumDecl * ret = new EnumDecl( td->enumeration->name ); 837 buildList( td->enumeration->constants, ret->get_members() ); 838 std::list< Declaration * >::iterator members = ret->get_members().begin(); 839 for ( const DeclarationNode * cur = td->enumeration-> constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) { 840 if ( cur->has_enumeratorValue() ) { 841 ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members); 842 member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ), std::list< Expression * >() ) ); 843 } // if 844 } // for 845 return ret; 846 } // buildEnum 847 848 TypeInstType * buildSymbolicInst( const TypeData * td ) { 849 assert( td->kind == TypeData::SymbolicInst ); 850 TypeInstType * ret = new TypeInstType( buildQualifiers( td ), td->symbolic->name, false ); 851 buildList( td->symbolic->actuals, ret->get_parameters() ); 852 buildForall( td->forall, ret->get_forall() ); 853 return ret; 854 } // buildSymbolicInst 855 856 TupleType * buildTuple( const TypeData * td ) { 857 assert( td->kind == TypeData::Tuple ); 858 TupleType * ret = new TupleType( buildQualifiers( td ) ); 859 buildTypeList( td->tuple->members, ret->get_types() ); 860 buildForall( td->forall, ret->get_forall() ); 861 return ret; 862 } // buildTuple 863 864 TypeofType * buildTypeof( const TypeData * td ) { 865 assert( td->kind == TypeData::Typeof ); 866 assert( td->typeexpr ); 867 assert( td->typeexpr->expr ); 868 return new TypeofType( buildQualifiers( td ), td->typeexpr->expr->build() ); 869 } // buildTypeof 870 871 AttrType * buildAttr( const TypeData * td ) { 872 assert( td->kind == TypeData::Attr ); 873 assert( td->attr ); 874 AttrType * ret; 875 if ( td->attr->expr ) { 876 ret = new AttrType( buildQualifiers( td ), td->attr->name, td->attr->expr->build() ); 877 } else { 878 assert( td->attr->type ); 879 ret = new AttrType( buildQualifiers( td ), td->attr->name, td->attr->type->buildType() ); 880 } // if 881 return ret; 882 } // buildAttr 883 884 Declaration * buildDecl( const TypeData * td, std::string name, DeclarationNode::StorageClass sc, Expression * bitfieldWidth, bool isInline, bool isNoreturn, LinkageSpec::Spec linkage, Initializer * init ) { 885 if ( td->kind == TypeData::Function ) { 886 FunctionDecl * decl; 887 if ( td->function->hasBody ) { 888 if ( td->function->body ) { 889 Statement * stmt = td->function->body->build(); 890 CompoundStmt * body = dynamic_cast< CompoundStmt* >( stmt ); 891 assert( body ); 892 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), body, isInline, isNoreturn ); 893 } else { 894 // std::list< Label > ls; 895 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), new CompoundStmt( std::list< Label >() ), isInline, isNoreturn ); 896 } // if 897 } else { 898 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), 0, isInline, isNoreturn ); 899 } // if 900 for ( DeclarationNode * cur = td->function->idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) { 901 if ( cur->get_name() != "" ) { 902 decl->get_oldIdents().insert( decl->get_oldIdents().end(), cur->get_name() ); 903 } // if 904 } // for 905 buildList( td->function->oldDeclList, decl->get_oldDecls() ); 906 return decl; 907 } else if ( td->kind == TypeData::Aggregate ) { 908 return buildAggregate( td ); 909 } else if ( td->kind == TypeData::Enum ) { 910 return buildEnum( td ); 911 } else if ( td->kind == TypeData::Symbolic ) { 912 return buildSymbolic( td, name, sc ); 913 } else if ( td->kind == TypeData::Variable ) { 914 return buildVariable( td ); 915 } else { 916 return new ObjectDecl( name, sc, linkage, bitfieldWidth, typebuild( td ), init, std::list< Attribute * >(), isInline, isNoreturn ); 917 } // if 918 return 0; 919 } // buildDecl 920 921 FunctionType * buildFunction( const TypeData * td ) { 922 assert( td->kind == TypeData::Function ); 923 bool hasEllipsis = td->function->params ? td->function->params->get_hasEllipsis() : true; 924 if ( ! td->function->params ) hasEllipsis = ! td->function->newStyle; 925 FunctionType * ft = new FunctionType( buildQualifiers( td ), hasEllipsis ); 926 buildList( td->function->params, ft->get_parameters() ); 927 buildForall( td->forall, ft->get_forall() ); 928 if ( td->base ) { 929 switch ( td->base->kind ) { 930 case TypeData::Tuple: 931 buildList( td->base->tuple->members, ft->get_returnVals() ); 932 break; 933 default: 934 ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType* >( buildDecl( td->base, "", DeclarationNode::NoStorageClass, 0, false, false, LinkageSpec::Cforall ) ) ); 823 935 } // switch 824 936 } else { … … 826 938 } // if 827 939 return ft; 828 } 829 830 AggregateDecl *TypeData::buildAggregate() const { 831 assert( kind == Aggregate ); 832 AggregateDecl *at; 833 switch ( aggregate->kind ) { 834 case DeclarationNode::Struct: 835 at = new StructDecl( aggregate->name ); 836 buildForall( aggregate->params, at->get_parameters() ); 837 break; 838 case DeclarationNode::Union: 839 at = new UnionDecl( aggregate->name ); 840 buildForall( aggregate->params, at->get_parameters() ); 841 break; 842 case DeclarationNode::Trait: 843 at = new TraitDecl( aggregate->name ); 844 buildList( aggregate->params, at->get_parameters() ); 845 break; 846 default: 847 assert( false ); 848 } // switch 849 850 buildList( aggregate->fields, at->get_members() ); 851 at->set_body( aggregate->body ); 852 853 return at; 854 } 855 856 ReferenceToType *TypeData::buildAggInst() const { 857 assert( kind == AggregateInst ); 858 859 ReferenceToType *ret; 860 if ( aggInst->aggregate->kind == Enum ) { 861 ret = new EnumInstType( buildQualifiers(), aggInst->aggregate->enumeration->name ); 862 } else { 863 assert( aggInst->aggregate->kind == Aggregate ); 864 switch ( aggInst->aggregate->aggregate->kind ) { 865 case DeclarationNode::Struct: 866 ret = new StructInstType( buildQualifiers(), aggInst->aggregate->aggregate->name ); 867 break; 868 case DeclarationNode::Union: 869 ret = new UnionInstType( buildQualifiers(), aggInst->aggregate->aggregate->name ); 870 break; 871 case DeclarationNode::Trait: 872 ret = new TraitInstType( buildQualifiers(), aggInst->aggregate->aggregate->name ); 873 break; 874 default: 875 assert( false ); 876 } // switch 877 } // if 878 buildList( aggInst->params, ret->get_parameters() ); 879 buildForall( forall, ret->get_forall() ); 880 return ret; 881 } 882 883 NamedTypeDecl *TypeData::buildSymbolic( const std::string &name, DeclarationNode::StorageClass sc ) const { 884 assert( kind == Symbolic ); 885 NamedTypeDecl *ret; 886 if ( symbolic->isTypedef ) { 887 ret = new TypedefDecl( name, sc, maybeBuild< Type >( base ) ); 888 } else { 889 ret = new TypeDecl( name, sc, maybeBuild< Type >( base ), TypeDecl::Any ); 890 } // if 891 buildList( symbolic->params, ret->get_parameters() ); 892 buildList( symbolic->assertions, ret->get_assertions() ); 893 return ret; 894 } 895 896 TypeDecl *TypeData::buildVariable() const { 897 assert( kind == Variable ); 898 static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype }; 899 900 TypeDecl *ret = new TypeDecl( variable->name, DeclarationNode::NoStorageClass, 0, kindMap[ variable->tyClass ] ); 901 buildList( variable->assertions, ret->get_assertions() ); 902 return ret; 903 } 904 905 EnumDecl *TypeData::buildEnum() const { 906 assert( kind == Enum ); 907 EnumDecl *ret = new EnumDecl( enumeration->name ); 908 buildList( enumeration->constants, ret->get_members() ); 909 std::list< Declaration * >::iterator members = ret->get_members().begin(); 910 for ( const DeclarationNode *cur = enumeration->constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) { 911 if ( cur->has_enumeratorValue() ) { 912 ObjectDecl *member = dynamic_cast< ObjectDecl * >(*members); 913 member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ), std::list< Expression * >() ) ); 914 } // if 915 } // for 916 return ret; 917 } 918 919 TypeInstType *TypeData::buildSymbolicInst() const { 920 assert( kind == SymbolicInst ); 921 TypeInstType *ret = new TypeInstType( buildQualifiers(), symbolic->name, false ); 922 buildList( symbolic->actuals, ret->get_parameters() ); 923 buildForall( forall, ret->get_forall() ); 924 return ret; 925 } 926 927 TupleType *TypeData::buildTuple() const { 928 assert( kind == Tuple ); 929 TupleType *ret = new TupleType( buildQualifiers() ); 930 buildTypeList( tuple->members, ret->get_types() ); 931 buildForall( forall, ret->get_forall() ); 932 return ret; 933 } 934 935 TypeofType *TypeData::buildTypeof() const { 936 assert( kind == Typeof ); 937 assert( typeexpr ); 938 assert( typeexpr->expr ); 939 TypeofType *ret = new TypeofType( buildQualifiers(), typeexpr->expr->build() ); 940 return ret; 941 } 942 943 AttrType *TypeData::buildAttr() const { 944 assert( kind == Attr ); 945 assert( attr ); 946 AttrType *ret; 947 if ( attr->expr ) { 948 ret = new AttrType( buildQualifiers(), attr->name, attr->expr->build() ); 949 } else { 950 assert( attr->type ); 951 ret = new AttrType( buildQualifiers(), attr->name, attr->type->buildType() ); 952 } // if 953 return ret; 954 } 940 } // buildFunction 955 941 956 942 // Local Variables: //
Note: See TracChangeset
for help on using the changeset viewer.