Changeset 32d281d
- Timestamp:
- Nov 26, 2015, 3:46:03 PM (9 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:
- f5234f3
- Parents:
- 7e23d0a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
r7e23d0a r32d281d 625 625 } 626 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 } 627 635 628 636 Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) { … … 631 639 // Make function polymorphic in same parameters as generic struct, if applicable 632 640 std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters(); 641 std::list< Expression* > structParams; // List of matching parameters to put on types 633 642 for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) { 634 assignType->get_forall().push_back( (*param)->clone() ); 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 ) ) ); 635 646 } 636 647 637 ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 );648 ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, structParams ), 0 ); 638 649 assignType->get_returnVals().push_back( returnVal ); 639 650 640 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 ); 641 652 assignType->get_parameters().push_back( dstParam ); 642 653 643 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 ); 644 655 assignType->get_parameters().push_back( srcParam ); 645 656 … … 677 688 Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType, unsigned int functionNesting ) { 678 689 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 679 680 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 ); 681 701 assignType->get_returnVals().push_back( returnVal ); 682 702 683 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 ); 684 704 assignType->get_parameters().push_back( dstParam ); 685 705 686 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 ); 687 707 assignType->get_parameters().push_back( srcParam ); 688 708 … … 695 715 copy->get_args().push_back( new VariableExpr( dstParam ) ); 696 716 copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) ); 697 copy->get_args().push_back( new SizeofExpr( refType->clone() ) );717 copy->get_args().push_back( new SizeofExpr( cloneWithParams( refType, unionParams ) ) ); 698 718 699 719 assignDecl->get_statements()->get_kids().push_back( new ExprStmt( noLabels, copy ) ); … … 714 734 void AutogenerateRoutines::visit( StructDecl *structDecl ) { 715 735 if ( ! structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) { 716 StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() );717 structInst ->set_baseStruct( structDecl );718 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 ) ); 719 739 structsDone.insert( structDecl->get_name() ); 720 740 } // if … … 723 743 void AutogenerateRoutines::visit( UnionDecl *unionDecl ) { 724 744 if ( ! unionDecl->get_members().empty() ) { 725 UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() );726 unionInst ->set_baseUnion( unionDecl );727 declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst, functionNesting ) );745 UnionInstType unionInst( Type::Qualifiers(), unionDecl->get_name() ); 746 unionInst.set_baseUnion( unionDecl ); 747 declsToAdd.push_back( makeUnionAssignment( unionDecl, &unionInst, functionNesting ) ); 728 748 } // if 729 749 }
Note: See TracChangeset
for help on using the changeset viewer.