Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r32d281d rf066321  
    1010// Created On       : Sun May 17 21:50:04 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri Nov 20 16:33:52 2015
    13 // Update Count     : 201
     12// Last Modified On : Thu Nov 19 10:44:55 2015
     13// Update Count     : 199
    1414//
    1515
     
    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 ) {
    637629                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 );
     630 
     631                ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 );
    649632                assignType->get_returnVals().push_back( returnVal );
    650633 
    651                 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), cloneWithParams( refType, structParams ) ), 0 );
     634                ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 );
    652635                assignType->get_parameters().push_back( dstParam );
    653636 
    654                 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, structParams ), 0 );
     637                ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );
    655638                assignType->get_parameters().push_back( srcParam );
    656639
     
    688671        Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType, unsigned int functionNesting ) {
    689672                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 );
     673 
     674                ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 );
    701675                assignType->get_returnVals().push_back( returnVal );
    702676 
    703                 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), cloneWithParams( refType, unionParams ) ), 0 );
     677                ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 );
    704678                assignType->get_parameters().push_back( dstParam );
    705679 
    706                 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, unionParams ), 0 );
     680                ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );
    707681                assignType->get_parameters().push_back( srcParam );
    708682 
     
    715689                copy->get_args().push_back( new VariableExpr( dstParam ) );
    716690                copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) );
    717                 copy->get_args().push_back( new SizeofExpr( cloneWithParams( refType, unionParams ) ) );
     691                copy->get_args().push_back( new SizeofExpr( refType->clone() ) );
    718692
    719693                assignDecl->get_statements()->get_kids().push_back( new ExprStmt( noLabels, copy ) );
     
    734708        void AutogenerateRoutines::visit( StructDecl *structDecl ) {
    735709                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 ) );
     710                        StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() );
     711                        structInst->set_baseStruct( structDecl );
     712                        declsToAdd.push_back( makeStructAssignment( structDecl, structInst, functionNesting ) );
    739713                        structsDone.insert( structDecl->get_name() );
    740714                } // if
     
    743717        void AutogenerateRoutines::visit( UnionDecl *unionDecl ) {
    744718                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 ) );
     719                        UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() );
     720                        unionInst->set_baseUnion( unionDecl );
     721                        declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst, functionNesting ) );
    748722                } // if
    749723        }
Note: See TracChangeset for help on using the changeset viewer.