Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    rf5c3b6c r5fe35d6  
    393393                        if ( skipCopyConstruct( result ) ) return; // skip certain non-copyable types
    394394
    395                         // type may involve type variables, so apply type substitution to get temporary variable's actual type,
    396                         // since result type may not be substituted (e.g., if the type does not appear in the parameter list)
     395                        // type may involve type variables, so apply type substitution to get temporary variable's actual type.
    397396                        // Use applyFree so that types bound in function pointers are not substituted, e.g. in forall(dtype T) void (*)(T).
     397                        result = result->clone();
    398398                        env->applyFree( result );
    399399                        ObjectDecl * tmp = ObjectDecl::newObject( "__tmp", result, nullptr );
     
    570570
    571571                        if ( returnDecl ) {
    572                                 ApplicationExpr * assign = createBitwiseAssignment( new VariableExpr( returnDecl ), callExpr );
     572                                UntypedExpr * assign = new UntypedExpr( new NameExpr( "?=?" ) );
     573                                assign->get_args().push_back( new VariableExpr( returnDecl ) );
     574                                assign->get_args().push_back( callExpr );
     575                                // know the result type of the assignment is the type of the LHS (minus the pointer), so
     576                                // add that onto the assignment expression so that later steps have the necessary information
     577                                assign->set_result( returnDecl->get_type()->clone() );
     578
    573579                                Expression * retExpr = new CommaExpr( assign, new VariableExpr( returnDecl ) );
    574580                                // move env from callExpr to retExpr
     
    937943                }
    938944
    939                 void addIds( SymTab::Indexer & indexer, const std::list< DeclarationWithType * > & decls ) {
    940                         for ( auto d : decls ) {
    941                                 indexer.addId( d );
    942                         }
    943                 }
    944 
    945                 void addTypes( SymTab::Indexer & indexer, const std::list< TypeDecl * > & tds ) {
    946                         for ( auto td : tds ) {
    947                                 indexer.addType( td );
    948                                 addIds( indexer, td->assertions );
    949                         }
    950                 }
    951 
    952945                void GenStructMemberCalls::previsit( FunctionDecl * funcDecl ) {
    953946                        GuardValue( function );
     
    1006999                                // need to explicitly re-add function parameters to the indexer in order to resolve copy constructors
    10071000                                auto guard = makeFuncGuard( [this]() { indexer.enterScope(); }, [this]() { indexer.leaveScope(); } );
    1008                                 addTypes( indexer, function->type->forall );
    1009                                 addIds( indexer, function->type->returnVals );
    1010                                 addIds( indexer, function->type->parameters );
     1001                                indexer.addFunctionType( function->type );
    10111002
    10121003                                // need to iterate through members in reverse in order for
     
    10231014                                        // insert and resolve default/copy constructor call for each field that's unhandled
    10241015                                        std::list< Statement * > stmt;
    1025                                         Expression * arg2 = 0;
     1016                                        Expression * arg2 = nullptr;
    10261017                                        if ( isCopyConstructor( function ) ) {
    10271018                                                // if copy ctor, need to pass second-param-of-this-function.field
     
    11551146                        assert( ctorExpr->result && ctorExpr->get_result()->size() == 1 );
    11561147
     1148                        // xxx - ideally we would reuse the temporary generated from the copy constructor passes from within firstArg if it exists and not generate a temporary if it's unnecessary.
     1149                        ObjectDecl * tmp = ObjectDecl::newObject( tempNamer.newName(), ctorExpr->get_result()->clone(), nullptr );
     1150                        declsToAddBefore.push_back( tmp );
     1151
    11571152                        // xxx - this can be TupleAssignExpr now. Need to properly handle this case.
    11581153                        ApplicationExpr * callExpr = strict_dynamic_cast< ApplicationExpr * > ( ctorExpr->get_callExpr() );
     
    11601155                        ctorExpr->set_callExpr( nullptr );
    11611156                        ctorExpr->set_env( nullptr );
    1162 
    1163                         // xxx - ideally we would reuse the temporary generated from the copy constructor passes from within firstArg if it exists and not generate a temporary if it's unnecessary.
    1164                         ObjectDecl * tmp = ObjectDecl::newObject( tempNamer.newName(), callExpr->args.front()->result->clone(), nullptr );
    1165                         declsToAddBefore.push_back( tmp );
    11661157                        delete ctorExpr;
    11671158
Note: See TracChangeset for help on using the changeset viewer.