Changeset 0ddb713 for src/SymTab/Validate.cc
- Timestamp:
- Dec 2, 2015, 11:58:59 AM (8 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, with_gc
- Children:
- 9cb8e88d
- Parents:
- 9ed3237 (diff), f2b2029 (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/SymTab/Validate.cc
r9ed3237 r0ddb713 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 21:50:04 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue Aug 11 16:59:35201513 // Update Count : 19611 // Last Modified By : Rob Schluntz 12 // Last Modified On : Fri Nov 20 16:33:52 2015 13 // Update Count : 201 14 14 // 15 15 … … 126 126 }; 127 127 128 class A ddStructAssignment: public Visitor {128 class AutogenerateRoutines : public Visitor { 129 129 public: 130 130 /// Generates assignment operators for aggregate types as required 131 static void a ddStructAssignment( std::list< Declaration * > &translationUnit );131 static void autogenerateRoutines( 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 ddStructAssignment() : functionNesting( 0 ) {}154 AutogenerateRoutines() : 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 // 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 ); 198 AutogenerateRoutines::autogenerateRoutines( translationUnit ); 201 199 acceptAll( translationUnit, pass3 ); 202 200 } … … 502 500 static const std::list< std::string > noLabels; 503 501 504 void A ddStructAssignment::addStructAssignment( std::list< Declaration * > &translationUnit ) {505 A ddStructAssignmentvisitor;502 void AutogenerateRoutines::autogenerateRoutines( std::list< Declaration * > &translationUnit ) { 503 AutogenerateRoutines visitor; 506 504 acceptAndAdd( translationUnit, visitor, false ); 507 505 } … … 627 625 } 628 626 627 /// Clones a reference type, replacing any parameters it may have with a clone of the provided list 628 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 } 629 635 630 636 Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) { 631 637 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 632 633 ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 ); 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 ); 634 649 assignType->get_returnVals().push_back( returnVal ); 635 650 636 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 );651 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), cloneWithParams( refType, structParams ) ), 0 ); 637 652 assignType->get_parameters().push_back( dstParam ); 638 653 639 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );654 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, structParams ), 0 ); 640 655 assignType->get_parameters().push_back( srcParam ); 641 656 … … 673 688 Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType, unsigned int functionNesting ) { 674 689 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 675 676 ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 ); 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 ); 677 701 assignType->get_returnVals().push_back( returnVal ); 678 702 679 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 );703 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), cloneWithParams( refType, unionParams ) ), 0 ); 680 704 assignType->get_parameters().push_back( dstParam ); 681 705 682 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );706 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, unionParams ), 0 ); 683 707 assignType->get_parameters().push_back( srcParam ); 684 708 … … 691 715 copy->get_args().push_back( new VariableExpr( dstParam ) ); 692 716 copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) ); 693 copy->get_args().push_back( new SizeofExpr( refType->clone() ) );717 copy->get_args().push_back( new SizeofExpr( cloneWithParams( refType, unionParams ) ) ); 694 718 695 719 assignDecl->get_statements()->get_kids().push_back( new ExprStmt( noLabels, copy ) ); … … 699 723 } 700 724 701 void A ddStructAssignment::visit( EnumDecl *enumDecl ) {725 void AutogenerateRoutines::visit( EnumDecl *enumDecl ) { 702 726 if ( ! enumDecl->get_members().empty() ) { 703 727 EnumInstType *enumInst = new EnumInstType( Type::Qualifiers(), enumDecl->get_name() ); … … 708 732 } 709 733 710 void A ddStructAssignment::visit( StructDecl *structDecl ) {734 void AutogenerateRoutines::visit( StructDecl *structDecl ) { 711 735 if ( ! structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) { 712 StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() );713 structInst ->set_baseStruct( structDecl );714 declsToAdd.push_back( makeStructAssignment( structDecl, structInst, functionNesting ) );736 StructInstType structInst( Type::Qualifiers(), structDecl->get_name() ); 737 structInst.set_baseStruct( structDecl ); 738 declsToAdd.push_back( makeStructAssignment( structDecl, &structInst, functionNesting ) ); 715 739 structsDone.insert( structDecl->get_name() ); 716 740 } // if 717 741 } 718 742 719 void A ddStructAssignment::visit( UnionDecl *unionDecl ) {743 void AutogenerateRoutines::visit( UnionDecl *unionDecl ) { 720 744 if ( ! unionDecl->get_members().empty() ) { 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 A ddStructAssignment::visit( TypeDecl *typeDecl ) {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 AutogenerateRoutines::visit( TypeDecl *typeDecl ) { 728 752 CompoundStmt *stmts = 0; 729 753 TypeInstType *typeInst = new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), false ); … … 753 777 } 754 778 755 void A ddStructAssignment::visit( FunctionType *) {779 void AutogenerateRoutines::visit( FunctionType *) { 756 780 // ensure that we don't add assignment ops for types defined as part of the function 757 781 } 758 782 759 void A ddStructAssignment::visit( PointerType *) {783 void AutogenerateRoutines::visit( PointerType *) { 760 784 // ensure that we don't add assignment ops for types defined as part of the pointer 761 785 } 762 786 763 void A ddStructAssignment::visit( ContextDecl *) {787 void AutogenerateRoutines::visit( ContextDecl *) { 764 788 // ensure that we don't add assignment ops for types defined as part of the context 765 789 } 766 790 767 791 template< typename StmtClass > 768 inline void A ddStructAssignment::visitStatement( StmtClass *stmt ) {792 inline void AutogenerateRoutines::visitStatement( StmtClass *stmt ) { 769 793 std::set< std::string > oldStructs = structsDone; 770 794 addVisit( stmt, *this ); … … 772 796 } 773 797 774 void A ddStructAssignment::visit( FunctionDecl *functionDecl ) {798 void AutogenerateRoutines::visit( FunctionDecl *functionDecl ) { 775 799 maybeAccept( functionDecl->get_functionType(), *this ); 776 800 acceptAll( functionDecl->get_oldDecls(), *this ); … … 780 804 } 781 805 782 void A ddStructAssignment::visit( CompoundStmt *compoundStmt ) {806 void AutogenerateRoutines::visit( CompoundStmt *compoundStmt ) { 783 807 visitStatement( compoundStmt ); 784 808 } 785 809 786 void A ddStructAssignment::visit( IfStmt *ifStmt ) {810 void AutogenerateRoutines::visit( IfStmt *ifStmt ) { 787 811 visitStatement( ifStmt ); 788 812 } 789 813 790 void A ddStructAssignment::visit( WhileStmt *whileStmt ) {814 void AutogenerateRoutines::visit( WhileStmt *whileStmt ) { 791 815 visitStatement( whileStmt ); 792 816 } 793 817 794 void A ddStructAssignment::visit( ForStmt *forStmt ) {818 void AutogenerateRoutines::visit( ForStmt *forStmt ) { 795 819 visitStatement( forStmt ); 796 820 } 797 821 798 void A ddStructAssignment::visit( SwitchStmt *switchStmt ) {822 void AutogenerateRoutines::visit( SwitchStmt *switchStmt ) { 799 823 visitStatement( switchStmt ); 800 824 } 801 825 802 void A ddStructAssignment::visit( ChooseStmt *switchStmt ) {826 void AutogenerateRoutines::visit( ChooseStmt *switchStmt ) { 803 827 visitStatement( switchStmt ); 804 828 } 805 829 806 void A ddStructAssignment::visit( CaseStmt *caseStmt ) {830 void AutogenerateRoutines::visit( CaseStmt *caseStmt ) { 807 831 visitStatement( caseStmt ); 808 832 } 809 833 810 void A ddStructAssignment::visit( CatchStmt *cathStmt ) {834 void AutogenerateRoutines::visit( CatchStmt *cathStmt ) { 811 835 visitStatement( cathStmt ); 812 836 }
Note: See TracChangeset
for help on using the changeset viewer.