Changes in / [13ca524:43ffef1]


Ignore:
Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Unify.cc

    r13ca524 r43ffef1  
    508508                handleRefType( inst, other );
    509509                if ( ! result ) return;
    510                 // Check that parameters of types unify, if any
     510                // Check that parameters of type unify, if any
    511511                std::list< Expression* > params = inst->get_parameters();
    512                 std::list< Expression* > otherParams = ((RefType*)other)->get_parameters();
    513 
    514                 std::list< Expression* >::const_iterator it = params.begin(), jt = otherParams.begin();
    515                 for ( ; it != params.end() && jt != otherParams.end(); ++it, ++jt ) {
    516                         TypeExpr *param = dynamic_cast< TypeExpr* >(*it);
    517                         assert(param && "Aggregate parameters should be type expressions");
    518                         TypeExpr *otherParam = dynamic_cast< TypeExpr* >(*jt);
    519                         assert(otherParam && "Aggregate parameters should be type expressions");
    520 
    521                         if ( ! unifyExact( param->get_type(), otherParam->get_type(), env, needAssertions, haveAssertions, openVars, WidenMode(false, false), indexer ) ) {
     512                if ( ! params.empty() ) {
     513                        std::list< TypeDecl* > *baseParams = inst->get_baseParameters();
     514                        if ( ! baseParams ) {
    522515                                result = false;
    523516                                return;
    524517                        }
     518                        std::list< Expression* >::const_iterator it = params.begin();
     519                        std::list< TypeDecl* >::const_iterator baseIt = baseParams->begin();
     520                        while ( it != params.end() && baseIt != baseParams->end()) {
     521                                TypeExpr *param = dynamic_cast< TypeExpr* >(*it);
     522                                assert(param && "Aggregate parameters should be type expressions");
     523                                TypeInstType baseType(Type::Qualifiers(), (*baseIt)->get_name(), *baseIt);
     524                                if ( ! unifyExact( param->get_type(), &baseType, env, needAssertions, haveAssertions, openVars, WidenMode(false, false), indexer ) ) {
     525                                        result = false;
     526                                        return;
     527                                }
     528                               
     529                                ++it;
     530                                ++baseIt;
     531                        }
     532                        if ( it != params.end() || baseIt != baseParams->end() ) {
     533                                result = false;
     534                        }
    525535                }
    526                 result = ( it == params.end() && jt == otherParams.end() );
    527536        }
    528537
  • src/SymTab/Validate.cc

    r13ca524 r43ffef1  
    625625        }
    626626
    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         }
    635627
    636628        Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) {
     
    639631                // Make function polymorphic in same parameters as generic struct, if applicable
    640632                std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters();
    641                 std::list< Expression* > structParams;  // List of matching parameters to put on types
    642633                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 ) ) );
     634                        assignType->get_forall().push_back( (*param)->clone() );
    646635                }
    647636 
    648                 ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, structParams ), 0 );
     637                ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 );
    649638                assignType->get_returnVals().push_back( returnVal );
    650639 
    651                 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), cloneWithParams( refType, structParams ) ), 0 );
     640                ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 );
    652641                assignType->get_parameters().push_back( dstParam );
    653642 
    654                 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, structParams ), 0 );
     643                ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );
    655644                assignType->get_parameters().push_back( srcParam );
    656645
     
    688677        Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType, unsigned int functionNesting ) {
    689678                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 );
     679 
     680                ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 );
    701681                assignType->get_returnVals().push_back( returnVal );
    702682 
    703                 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), cloneWithParams( refType, unionParams ) ), 0 );
     683                ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 );
    704684                assignType->get_parameters().push_back( dstParam );
    705685 
    706                 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, unionParams ), 0 );
     686                ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );
    707687                assignType->get_parameters().push_back( srcParam );
    708688 
     
    715695                copy->get_args().push_back( new VariableExpr( dstParam ) );
    716696                copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) );
    717                 copy->get_args().push_back( new SizeofExpr( cloneWithParams( refType, unionParams ) ) );
     697                copy->get_args().push_back( new SizeofExpr( refType->clone() ) );
    718698
    719699                assignDecl->get_statements()->get_kids().push_back( new ExprStmt( noLabels, copy ) );
     
    734714        void AutogenerateRoutines::visit( StructDecl *structDecl ) {
    735715                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 ) );
     716                        StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() );
     717                        structInst->set_baseStruct( structDecl );
     718                        declsToAdd.push_back( makeStructAssignment( structDecl, structInst, functionNesting ) );
    739719                        structsDone.insert( structDecl->get_name() );
    740720                } // if
     
    743723        void AutogenerateRoutines::visit( UnionDecl *unionDecl ) {
    744724                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 ) );
     725                        UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() );
     726                        unionInst->set_baseUnion( unionDecl );
     727                        declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst, functionNesting ) );
    748728                } // if
    749729        }
Note: See TracChangeset for help on using the changeset viewer.