Changes in src/SymTab/Validate.cc [98735ef:d3b7937]
- File:
-
- 1 edited
-
src/SymTab/Validate.cc (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
r98735ef rd3b7937 382 382 // it's not a semantic error if the struct is not found, just an implicit forward declaration 383 383 if ( st ) { 384 //assert( ! structInst->get_baseStruct() || structInst->get_baseStruct()->get_members().empty() || ! st->get_members().empty() );384 assert( ! structInst->get_baseStruct() || structInst->get_baseStruct()->get_members().empty() || ! st->get_members().empty() ); 385 385 structInst->set_baseStruct( st ); 386 386 } // if … … 585 585 } 586 586 587 template< typename OutputIterator >588 void makeUnionFieldsAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, UnionInstType *unionType, OutputIterator out ) {589 UntypedExpr *copy = new UntypedExpr( new NameExpr( "__builtin_memcpy" ) );590 copy->get_args().push_back( new VariableExpr( dstParam ) );591 copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) );592 copy->get_args().push_back( new SizeofExpr( unionType ) );593 594 *out++ = new ExprStmt( noLabels, copy );595 }596 597 587 //E ?=?(E volatile*, int), 598 588 // ?=?(E _Atomic volatile*, int); … … 659 649 } 660 650 661 /// Creates a new type decl that's the same as src, but renamed and with only the ?=? assertion (for complete types only)662 TypeDecl *cloneAndRename( TypeDecl *src, const std::string &name ) {663 TypeDecl *dst = new TypeDecl( name, src->get_storageClass(), 0, src->get_kind() );664 665 if ( src->get_kind() == TypeDecl::Any ) {666 // just include assignment operator assertion667 TypeInstType *assignParamType = new TypeInstType( Type::Qualifiers(), name, dst );668 FunctionType *assignFunctionType = new FunctionType( Type::Qualifiers(), false );669 assignFunctionType->get_returnVals().push_back(670 new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, assignParamType->clone(), 0 ) );671 assignFunctionType->get_parameters().push_back(672 new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), assignParamType->clone() ), 0 ) );673 assignFunctionType->get_parameters().push_back(674 new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, assignParamType, 0 ) );675 FunctionDecl *assignAssert = new FunctionDecl( "?=?", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, assignFunctionType, 0, false, false );676 dst->get_assertions().push_back( assignAssert );677 }678 679 return dst;680 }681 682 651 Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) { 683 652 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 684 653 685 654 // Make function polymorphic in same parameters as generic struct, if applicable 686 bool isGeneric = false; // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for union)687 655 std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters(); 688 656 std::list< Expression* > structParams; // List of matching parameters to put on types 689 TypeSubstitution genericSubs; // Substitutions to make to member types of struct690 657 for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) { 691 isGeneric = true; 692 TypeDecl *typeParam = cloneAndRename( *param, "_autoassign_" + aggregateDecl->get_name() + "_" + (*param)->get_name() ); 658 TypeDecl *typeParam = (*param)->clone(); 693 659 assignType->get_forall().push_back( typeParam ); 694 TypeInstType *newParamType = new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam ); 695 genericSubs.add( (*param)->get_name(), newParamType ); 696 structParams.push_back( new TypeExpr( newParamType ) ); 660 structParams.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam ) ) ); 697 661 } 698 662 699 ObjectDecl *returnVal = new ObjectDecl( " _ret", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, structParams ), 0 );663 ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, structParams ), 0 ); 700 664 assignType->get_returnVals().push_back( returnVal ); 701 665 … … 725 689 } 726 690 727 if ( isGeneric ) { 728 // rewrite member type in terms of the type variables on this operator 729 DeclarationWithType *fixedMember = dwt->clone(); 730 genericSubs.apply( fixedMember ); 731 732 // assign to both destination and return value 733 if ( ArrayType *array = dynamic_cast< ArrayType * >( fixedMember->get_type() ) ) { 734 makeArrayAssignment( srcParam, dstParam, fixedMember, array, back_inserter( assignDecl->get_statements()->get_kids() ) ); 735 makeArrayAssignment( srcParam, returnVal, fixedMember, array, back_inserter( assignDecl->get_statements()->get_kids() ) ); 736 } else { 737 makeScalarAssignment( srcParam, dstParam, fixedMember, back_inserter( assignDecl->get_statements()->get_kids() ) ); 738 makeScalarAssignment( srcParam, returnVal, fixedMember, back_inserter( assignDecl->get_statements()->get_kids() ) ); 739 } // if 691 if ( ArrayType *array = dynamic_cast< ArrayType * >( dwt->get_type() ) ) { 692 makeArrayAssignment( srcParam, dstParam, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) ); 740 693 } else { 741 // assign to destination 742 if ( ArrayType *array = dynamic_cast< ArrayType * >( dwt->get_type() ) ) { 743 makeArrayAssignment( srcParam, dstParam, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) ); 744 } else { 745 makeScalarAssignment( srcParam, dstParam, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) ); 746 } // if 694 makeScalarAssignment( srcParam, dstParam, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) ); 747 695 } // if 748 696 } // if 749 697 } // for 750 if ( ! isGeneric )assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );698 assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) ); 751 699 752 700 return assignDecl; … … 757 705 758 706 // Make function polymorphic in same parameters as generic union, if applicable 759 bool isGeneric = false; // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for struct)760 707 std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters(); 761 708 std::list< Expression* > unionParams; // List of matching parameters to put on types 762 709 for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) { 763 isGeneric = true; 764 TypeDecl *typeParam = cloneAndRename( *param, "_autoassign_" + aggregateDecl->get_name() + "_" + (*param)->get_name() ); 710 TypeDecl *typeParam = (*param)->clone(); 765 711 assignType->get_forall().push_back( typeParam ); 766 712 unionParams.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam ) ) ); 767 713 } 768 714 769 ObjectDecl *returnVal = new ObjectDecl( " _ret", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, unionParams ), 0 );715 ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, unionParams ), 0 ); 770 716 assignType->get_returnVals().push_back( returnVal ); 771 717 … … 781 727 assignDecl->fixUniqueId(); 782 728 783 makeUnionFieldsAssignment( srcParam, dstParam, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) ); 784 if ( isGeneric ) makeUnionFieldsAssignment( srcParam, returnVal, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) ); 785 786 if ( ! isGeneric ) assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) ); 729 UntypedExpr *copy = new UntypedExpr( new NameExpr( "__builtin_memcpy" ) ); 730 copy->get_args().push_back( new VariableExpr( dstParam ) ); 731 copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) ); 732 copy->get_args().push_back( new SizeofExpr( cloneWithParams( refType, unionParams ) ) ); 733 734 assignDecl->get_statements()->get_kids().push_back( new ExprStmt( noLabels, copy ) ); 735 assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) ); 787 736 788 737 return assignDecl;
Note:
See TracChangeset
for help on using the changeset viewer.