Changes in src/SymTab/Validate.cc [32d281d:1cbca6e]
- File:
-
- 1 edited
-
src/SymTab/Validate.cc (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
r32d281d r1cbca6e 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 21:50:04 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Fri Nov 20 16:33:52201513 // Update Count : 20111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Aug 11 16:59:35 2015 13 // Update Count : 196 14 14 // 15 15 … … 126 126 }; 127 127 128 class A utogenerateRoutines: public Visitor {128 class AddStructAssignment : public Visitor { 129 129 public: 130 130 /// Generates assignment operators for aggregate types as required 131 static void a utogenerateRoutines( std::list< Declaration * > &translationUnit );131 static void addStructAssignment( std::list< Declaration * > &translationUnit ); 132 132 133 133 std::list< Declaration * > &get_declsToAdd() { return declsToAdd; } … … 152 152 virtual void visit( CatchStmt *catchStmt ); 153 153 154 A utogenerateRoutines() : functionNesting( 0 ) {}154 AddStructAssignment() : functionNesting( 0 ) {} 155 155 private: 156 156 template< typename StmtClass > void visitStatement( StmtClass *stmt ); … … 196 196 acceptAll( translationUnit, pass1 ); 197 197 acceptAll( translationUnit, pass2 ); 198 AutogenerateRoutines::autogenerateRoutines( translationUnit ); 198 // need to collect all of the assignment operators prior to 199 // this point and only generate assignment operators if one doesn't exist 200 AddStructAssignment::addStructAssignment( translationUnit ); 199 201 acceptAll( translationUnit, pass3 ); 200 202 } … … 500 502 static const std::list< std::string > noLabels; 501 503 502 void A utogenerateRoutines::autogenerateRoutines( std::list< Declaration * > &translationUnit ) {503 A utogenerateRoutinesvisitor;504 void AddStructAssignment::addStructAssignment( std::list< Declaration * > &translationUnit ) { 505 AddStructAssignment visitor; 504 506 acceptAndAdd( translationUnit, visitor, false ); 505 507 } … … 625 627 } 626 628 627 /// Clones a reference type, replacing any parameters it may have with a clone of the provided list628 template< typename GenericInstType >629 GenericInstType *cloneWithParams( GenericInstType *refType, const std::list< Expression* >& params ) {630 GenericInstType *clone = refType->clone();631 clone->get_parameters().clear();632 cloneAll( params, clone->get_parameters() );633 return clone;634 }635 629 636 630 Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) { 637 631 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 638 639 // Make function polymorphic in same parameters as generic struct, if applicable 640 std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters(); 641 std::list< Expression* > structParams; // List of matching parameters to put on types 642 for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) { 643 TypeDecl *typeParam = (*param)->clone(); 644 assignType->get_forall().push_back( typeParam ); 645 structParams.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam ) ) ); 646 } 647 648 ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, structParams ), 0 ); 632 633 ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 ); 649 634 assignType->get_returnVals().push_back( returnVal ); 650 635 651 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), cloneWithParams( refType, structParams) ), 0 );636 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 ); 652 637 assignType->get_parameters().push_back( dstParam ); 653 638 654 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, structParams ), 0 );639 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 ); 655 640 assignType->get_parameters().push_back( srcParam ); 656 641 … … 688 673 Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType, unsigned int functionNesting ) { 689 674 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 690 691 // Make function polymorphic in same parameters as generic union, if applicable 692 std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters(); 693 std::list< Expression* > unionParams; // List of matching parameters to put on types 694 for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) { 695 TypeDecl *typeParam = (*param)->clone(); 696 assignType->get_forall().push_back( typeParam ); 697 unionParams.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam ) ) ); 698 } 699 700 ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, unionParams ), 0 ); 675 676 ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 ); 701 677 assignType->get_returnVals().push_back( returnVal ); 702 678 703 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), cloneWithParams( refType, unionParams) ), 0 );679 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 ); 704 680 assignType->get_parameters().push_back( dstParam ); 705 681 706 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, unionParams ), 0 );682 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 ); 707 683 assignType->get_parameters().push_back( srcParam ); 708 684 … … 715 691 copy->get_args().push_back( new VariableExpr( dstParam ) ); 716 692 copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) ); 717 copy->get_args().push_back( new SizeofExpr( cloneWithParams( refType, unionParams) ) );693 copy->get_args().push_back( new SizeofExpr( refType->clone() ) ); 718 694 719 695 assignDecl->get_statements()->get_kids().push_back( new ExprStmt( noLabels, copy ) ); … … 723 699 } 724 700 725 void A utogenerateRoutines::visit( EnumDecl *enumDecl ) {701 void AddStructAssignment::visit( EnumDecl *enumDecl ) { 726 702 if ( ! enumDecl->get_members().empty() ) { 727 703 EnumInstType *enumInst = new EnumInstType( Type::Qualifiers(), enumDecl->get_name() ); … … 732 708 } 733 709 734 void A utogenerateRoutines::visit( StructDecl *structDecl ) {710 void AddStructAssignment::visit( StructDecl *structDecl ) { 735 711 if ( ! structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) { 736 StructInstType structInst( Type::Qualifiers(), structDecl->get_name() );737 structInst .set_baseStruct( structDecl );738 declsToAdd.push_back( makeStructAssignment( structDecl, &structInst, functionNesting ) );712 StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() ); 713 structInst->set_baseStruct( structDecl ); 714 declsToAdd.push_back( makeStructAssignment( structDecl, structInst, functionNesting ) ); 739 715 structsDone.insert( structDecl->get_name() ); 740 716 } // if 741 717 } 742 718 743 void A utogenerateRoutines::visit( UnionDecl *unionDecl ) {719 void AddStructAssignment::visit( UnionDecl *unionDecl ) { 744 720 if ( ! unionDecl->get_members().empty() ) { 745 UnionInstType unionInst( Type::Qualifiers(), unionDecl->get_name() );746 unionInst .set_baseUnion( unionDecl );747 declsToAdd.push_back( makeUnionAssignment( unionDecl, &unionInst, functionNesting ) );748 } // if 749 } 750 751 void A utogenerateRoutines::visit( TypeDecl *typeDecl ) {721 UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() ); 722 unionInst->set_baseUnion( unionDecl ); 723 declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst, functionNesting ) ); 724 } // if 725 } 726 727 void AddStructAssignment::visit( TypeDecl *typeDecl ) { 752 728 CompoundStmt *stmts = 0; 753 729 TypeInstType *typeInst = new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), false ); … … 777 753 } 778 754 779 void A utogenerateRoutines::visit( FunctionType *) {755 void AddStructAssignment::visit( FunctionType *) { 780 756 // ensure that we don't add assignment ops for types defined as part of the function 781 757 } 782 758 783 void A utogenerateRoutines::visit( PointerType *) {759 void AddStructAssignment::visit( PointerType *) { 784 760 // ensure that we don't add assignment ops for types defined as part of the pointer 785 761 } 786 762 787 void A utogenerateRoutines::visit( ContextDecl *) {763 void AddStructAssignment::visit( ContextDecl *) { 788 764 // ensure that we don't add assignment ops for types defined as part of the context 789 765 } 790 766 791 767 template< typename StmtClass > 792 inline void A utogenerateRoutines::visitStatement( StmtClass *stmt ) {768 inline void AddStructAssignment::visitStatement( StmtClass *stmt ) { 793 769 std::set< std::string > oldStructs = structsDone; 794 770 addVisit( stmt, *this ); … … 796 772 } 797 773 798 void A utogenerateRoutines::visit( FunctionDecl *functionDecl ) {774 void AddStructAssignment::visit( FunctionDecl *functionDecl ) { 799 775 maybeAccept( functionDecl->get_functionType(), *this ); 800 776 acceptAll( functionDecl->get_oldDecls(), *this ); … … 804 780 } 805 781 806 void A utogenerateRoutines::visit( CompoundStmt *compoundStmt ) {782 void AddStructAssignment::visit( CompoundStmt *compoundStmt ) { 807 783 visitStatement( compoundStmt ); 808 784 } 809 785 810 void A utogenerateRoutines::visit( IfStmt *ifStmt ) {786 void AddStructAssignment::visit( IfStmt *ifStmt ) { 811 787 visitStatement( ifStmt ); 812 788 } 813 789 814 void A utogenerateRoutines::visit( WhileStmt *whileStmt ) {790 void AddStructAssignment::visit( WhileStmt *whileStmt ) { 815 791 visitStatement( whileStmt ); 816 792 } 817 793 818 void A utogenerateRoutines::visit( ForStmt *forStmt ) {794 void AddStructAssignment::visit( ForStmt *forStmt ) { 819 795 visitStatement( forStmt ); 820 796 } 821 797 822 void A utogenerateRoutines::visit( SwitchStmt *switchStmt ) {798 void AddStructAssignment::visit( SwitchStmt *switchStmt ) { 823 799 visitStatement( switchStmt ); 824 800 } 825 801 826 void A utogenerateRoutines::visit( ChooseStmt *switchStmt ) {802 void AddStructAssignment::visit( ChooseStmt *switchStmt ) { 827 803 visitStatement( switchStmt ); 828 804 } 829 805 830 void A utogenerateRoutines::visit( CaseStmt *caseStmt ) {806 void AddStructAssignment::visit( CaseStmt *caseStmt ) { 831 807 visitStatement( caseStmt ); 832 808 } 833 809 834 void A utogenerateRoutines::visit( CatchStmt *cathStmt ) {810 void AddStructAssignment::visit( CatchStmt *cathStmt ) { 835 811 visitStatement( cathStmt ); 836 812 }
Note:
See TracChangeset
for help on using the changeset viewer.