Changeset f6aa89c for src/GenPoly/Box.cc


Ignore:
Timestamp:
Nov 3, 2022, 10:27:45 AM (20 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, master
Children:
7ed7b4a
Parents:
7cf8006
Message:

Cleaning old box pass for easier translation. Isolated the replaceWithConcrete helpers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r7cf8006 rf6aa89c  
    100100                        /// wraps a function application with a new temporary for the out-parameter return value
    101101                        Expression *addRetParam( ApplicationExpr *appExpr, Type *retType, std::list< Expression *>::iterator &arg );
    102                         /// Replaces all the type parameters of a generic type with their concrete equivalents under the current environment
    103                         void replaceParametersWithConcrete( ApplicationExpr *appExpr, std::list< Expression* >& params );
    104                         /// Replaces a polymorphic type with its concrete equivalant under the current environment (returns itself if concrete).
    105                         /// If `doClone` is set to false, will not clone interior types
    106                         Type *replaceWithConcrete( ApplicationExpr *appExpr, Type *type, bool doClone = true );
    107102                        /// wraps a function application returning a polymorphic type with a new temporary for the out-parameter return value
    108103                        Expression *addDynRetParam( ApplicationExpr *appExpr, Type *polyType, std::list< Expression *>::iterator &arg );
     
    450445                }
    451446
     447                /// Replaces a polymorphic type with its concrete equivalant under the current environment (returns itself if concrete).
     448                /// If `doClone` is set to false, will not clone interior types
     449                Type *replaceWithConcrete( Type *type, TypeSubstitution const * env, bool doClone = true );
     450
    452451                Pass1::Pass1() : tempNamer( "_temp" ) {}
    453452
     
    572571                        // a polymorphic return type may need to be added to the argument list
    573572                        if ( polyRetType ) {
    574                                 Type *concRetType = replaceWithConcrete( appExpr, polyRetType );
     573                                Type *concRetType = replaceWithConcrete( polyRetType, env );
    575574                                passArgTypeVars( appExpr, polyRetType, concRetType, arg, exprTyVars, seenTypes );
    576575                                ++fnArg; // skip the return parameter in the argument list
     
    620619                }
    621620
    622                 void Pass1::replaceParametersWithConcrete( ApplicationExpr *appExpr, std::list< Expression* >& params ) {
     621                /// Replaces all the type parameters of a generic type with their concrete equivalents under the current environment
     622                void replaceParametersWithConcrete( std::list< Expression* >& params, TypeSubstitution const * env ) {
    623623                        for ( Expression * const param : params ) {
    624624                                TypeExpr *paramType = dynamic_cast< TypeExpr* >( param );
    625625                                assertf(paramType, "Aggregate parameters should be type expressions");
    626                                 paramType->set_type( replaceWithConcrete( appExpr, paramType->get_type(), false ) );
    627                         }
    628                 }
    629 
    630                 Type *Pass1::replaceWithConcrete( ApplicationExpr *appExpr, Type *type, bool doClone ) {
     626                                paramType->set_type( replaceWithConcrete( paramType->get_type(), env, false ) );
     627                        }
     628                }
     629
     630                // See forward definition.
     631                Type *replaceWithConcrete( Type *type, TypeSubstitution const * env, bool doClone ) {
    631632                        if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) {
    632633                                Type *concrete = env->lookup( typeInst->get_name() );
     
    639640                                        structType = structType->clone();
    640641                                }
    641                                 replaceParametersWithConcrete( appExpr, structType->get_parameters() );
     642                                replaceParametersWithConcrete( structType->get_parameters(), env );
    642643                                return structType;
    643644                        } else if ( UnionInstType *unionType = dynamic_cast< UnionInstType* >( type ) ) {
     
    645646                                        unionType = unionType->clone();
    646647                                }
    647                                 replaceParametersWithConcrete( appExpr, unionType->get_parameters() );
     648                                replaceParametersWithConcrete( unionType->get_parameters(), env );
    648649                                return unionType;
    649650                        }
     
    653654                Expression *Pass1::addDynRetParam( ApplicationExpr *appExpr, Type *dynType, std::list< Expression *>::iterator &arg ) {
    654655                        assert( env );
    655                         Type *concrete = replaceWithConcrete( appExpr, dynType );
     656                        Type *concrete = replaceWithConcrete( dynType, env );
    656657                        // add out-parameter for return value
    657658                        return addRetParam( appExpr, concrete, arg );
     
    11151116                        arg = appExpr->get_args().begin();
    11161117
    1117                         Type *concRetType = replaceWithConcrete( appExpr, dynRetType );
     1118                        Type *concRetType = replaceWithConcrete( dynRetType, env );
    11181119                        passTypeVars( appExpr, concRetType, arg, exprTyVars ); // xxx - used to use dynRetType instead of concRetType; this changed so that the correct type paramaters are passed for return types (it should be the concrete type's parameters, not the formal type's)
    11191120                        addInferredParams( appExpr, function, arg, exprTyVars );
Note: See TracChangeset for help on using the changeset viewer.