Changeset 5382492 for src/InitTweak


Ignore:
Timestamp:
Apr 26, 2016, 11:36:36 AM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
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, with_gc
Children:
668edd6b
Parents:
cf18eea
Message:

save type substitution and apply it when creating temporary variables for copy construction

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    rcf18eea r5382492  
    1010// Created On       : Wed Jan 13 16:29:30 2016
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Mon Apr 25 15:16:12 2016
     12// Last Modified On : Tue Apr 26 11:35:31 2016
    1313// Update Count     : 30
    1414//
     
    3838        }
    3939
    40         class InsertImplicitCalls : public Mutator {
     40        class InsertImplicitCalls : public GenPoly::PolyMutator {
    4141        public:
    4242                /// wrap function application expressions as ImplicitCopyCtorExpr nodes
     
    150150
    151151                // wrap each function call so that it is easy to identify nodes that have to be copy constructed
    152                 return new ImplicitCopyCtorExpr( appExpr );
     152                ImplicitCopyCtorExpr * expr = new ImplicitCopyCtorExpr( appExpr );
     153                // save a copy of the type substitution onto the new node so that it is easy to find.
     154                // The substitution is needed to obtain the type of temporary variables so that copy constructor
     155                // calls can be resolved. Normally this is what PolyMutator is for, but the pass that resolves
     156                // copy constructor calls must be an Indexer. We could alternatively make a PolyIndexer which
     157                // saves the environment, or compute the types of temporaries here, but it's more simpler to
     158                // save the environment here, and more cohesive to compute temporary variables and resolve copy
     159                // constructor calls together.
     160                assert( env );
     161                expr->set_env( env->clone() );
     162                return expr;
    153163        }
    154164
     
    185195                // take each argument and attempt to copy construct it.
    186196                for ( Expression * & arg : appExpr->get_args() ) {
     197                        PRINT( std::cerr << "Type Substitution: " << *impCpCtorExpr->get_env() << std::endl; )
    187198                        // xxx - need to handle tuple arguments
    188199                        assert( ! arg->get_results().empty() );
    189200                        Type * result = arg->get_results().front();
    190201                        if ( skipCopyConstruct( result ) ) continue; // skip certain non-copyable types
    191                         ObjectDecl * tmp = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, result->clone(), 0 );
     202                        // type may involve type variables, so apply type substitution to get temporary variable's actual type
     203                        result = result->clone();
     204                        impCpCtorExpr->get_env()->apply( result );
     205                        ObjectDecl * tmp = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, result, 0 );
    192206                        tmp->get_type()->set_isConst( false );
    193207
Note: See TracChangeset for help on using the changeset viewer.