Changeset 5382492


Ignore:
Timestamp:
Apr 26, 2016, 11:36:36 AM (8 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

Location:
src
Files:
3 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
  • src/SynTree/TypeSubstitution.cc

    rcf18eea r5382492  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // TypeSubstitution.cc -- 
     7// TypeSubstitution.cc --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:29:15 2016
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Apr 26 11:15:29 2016
    1313// Update Count     : 3
    1414//
     
    9696        BoundVarsType::const_iterator bound = boundVars.find( inst->get_name() );
    9797        if ( bound != boundVars.end() ) return inst;
    98        
     98
    9999        TypeEnvType::const_iterator i = typeEnv.find( inst->get_name() );
    100100        if ( i == typeEnv.end() ) {
     
    217217}
    218218
     219std::ostream & operator<<( std::ostream & out, const TypeSubstitution & sub ) {
     220        sub.print( out );
     221        return out;
     222}
     223
     224
    219225// Local Variables: //
    220226// tab-width: 4 //
  • src/SynTree/TypeSubstitution.h

    rcf18eea r5382492  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // TypeSubstitution.h -- 
     7// TypeSubstitution.h --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:33:19 2016
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Apr 26 11:15:07 2016
    1313// Update Count     : 2
    1414//
     
    3333        TypeSubstitution( const TypeSubstitution &other );
    3434        virtual ~TypeSubstitution();
    35        
     35
    3636        TypeSubstitution &operator=( const TypeSubstitution &other );
    37        
     37
    3838        template< typename SynTreeClass > int apply( SynTreeClass *&input );
    3939        template< typename SynTreeClass > int applyFree( SynTreeClass *&input );
    40        
     40
    4141        void add( std::string formalType, Type *actualType );
    4242        void add( const TypeSubstitution &other );
     
    4444        Type *lookup( std::string formalType ) const;
    4545        bool empty() const;
    46        
     46
    4747        template< typename FormalIterator, typename ActualIterator >
    4848        void add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin );
    49        
     49
    5050        template< typename TypeInstListIterator >
    5151        void extract( TypeInstListIterator begin, TypeInstListIterator end, TypeSubstitution &result );
    52        
     52
    5353        void normalize();
    5454
     
    6363        /// Records type variable bindings from forall-statements and instantiations of generic types
    6464        template< typename TypeClass > Type *handleAggregateType( TypeClass *type );
    65        
     65
    6666        virtual Type* mutate(VoidType *basicType);
    6767        virtual Type* mutate(BasicType *basicType);
     
    7575        virtual Type* mutate(TupleType *tupleType);
    7676        virtual Type* mutate(VarArgsType *varArgsType);
    77        
     77
    7878        // TODO: worry about traversing into a forall-qualified function type or type decl with assertions
    79        
     79
    8080        void initialize( const TypeSubstitution &src, TypeSubstitution &dest );
    8181
     
    136136        return subCount;
    137137}
    138        
     138
    139139template< typename SynTreeClass >
    140140int TypeSubstitution::applyFree( SynTreeClass *&input ) {
     
    149149        return subCount;
    150150}
    151        
     151
    152152template< typename TypeInstListIterator >
    153153void TypeSubstitution::extract( TypeInstListIterator begin, TypeInstListIterator end, TypeSubstitution &result ) {
     
    173173}
    174174
     175std::ostream & operator<<( std::ostream & out, const TypeSubstitution & sub );
     176
    175177#endif // TYPESUBSTITUTION_H
    176178
Note: See TracChangeset for help on using the changeset viewer.