Changes in / [9554d9b:4a8c875]


Ignore:
Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/GenPoly.cc

    r9554d9b r4a8c875  
    6464                        return false;
    6565                }
     66               
     67                /// Replaces a TypeInstType by its referrent in the environment, if applicable
     68                Type* replaceTypeInst( Type* type, const TypeSubstitution* env ) {
     69                        if ( ! env ) return type;
     70                        if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) {
     71                                Type *newType = env->lookup( typeInst->get_name() );
     72                                if ( newType ) return newType;
     73                        }
     74                        return type;
     75                }
    6676        }
    6777
    6878        Type *isPolyType( Type *type, const TypeSubstitution *env ) {
     79                type = replaceTypeInst( type, env );
     80               
    6981                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) {
    70                         if ( env ) {
    71                                 if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
    72                                         return isPolyType( newType, env );
    73                                 } // if
    74                         } // if
    7582                        return type;
    7683                } else if ( StructInstType *structType = dynamic_cast< StructInstType* >( type ) ) {
     
    8390
    8491        Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) {
     92                type = replaceTypeInst( type, env );
     93               
    8594                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) {
    86                         if ( env ) {
    87                                 if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
    88                                         return isPolyType( newType, tyVars, env );
    89                                 } // if
    90                         } // if
    9195                        if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) {
    9296                                return type;
     
    101105
    102106        Type *isPolyPtr( Type *type, const TypeSubstitution *env ) {
     107                type = replaceTypeInst( type, env );
     108               
    103109                if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
    104110                        return isPolyType( ptr->get_base(), env );
    105                 } else if ( env ) {
    106                         if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
    107                                 if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
    108                                         return isPolyPtr( newType, env );
    109                                 } // if
    110                         } // if
    111                 } // if
     111                }
    112112                return 0;
    113113        }
    114114
    115115        Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) {
     116                type = replaceTypeInst( type, env );
     117               
    116118                if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
    117119                        return isPolyType( ptr->get_base(), tyVars, env );
    118                 } else if ( env ) {
    119                         if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
    120                                 if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
    121                                         return isPolyPtr( newType, tyVars, env );
    122                                 } // if
    123                         } // if
    124                 } // if
     120                }
    125121                return 0;
    126122        }
     
    132128
    133129                while ( true ) {
     130                        type = replaceTypeInst( type, env );
     131               
    134132                        if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
    135133                                type = ptr->get_base();
    136134                                ++(*levels);
    137                         } else if ( env ) {
    138                                 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
    139                                         if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
    140                                                 type = newType;
    141                                         } else break;
    142                                 } else break;
    143135                        } else break;
    144136                }
     
    153145
    154146                while ( true ) {
     147                        type = replaceTypeInst( type, env );
     148               
    155149                        if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
    156150                                type = ptr->get_base();
    157151                                ++(*levels);
    158                         } else if ( env ) {
    159                                 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
    160                                         if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
    161                                                 type = newType;
    162                                         } else break;
    163                                 } else break;
    164152                        } else break;
    165153                }
  • src/GenPoly/GenPoly.h

    r9554d9b r4a8c875  
    3131namespace GenPoly {
    3232        typedef ErasableScopedMap< std::string, TypeDecl::Kind > TyVarMap;
    33 
     33       
    3434        /// A function needs an adapter if it returns a polymorphic value or if any of its
    3535        /// parameters have polymorphic type
  • src/SynTree/TypeSubstitution.cc

    r9554d9b r4a8c875  
    7272Type *TypeSubstitution::lookup( std::string formalType ) const {
    7373        TypeEnvType::const_iterator i = typeEnv.find( formalType );
     74       
     75        // break on not in substitution set
     76        if ( i == typeEnv.end() ) return 0;
     77       
     78        // attempt to transitively follow TypeInstType links.
     79        while ( TypeInstType *actualType = dynamic_cast< TypeInstType* >( i->second ) ) {
     80                const std::string& typeName = actualType->get_name();
     81               
     82                // break cycles in the transitive follow
     83                if ( formalType == typeName ) break;
     84               
     85                // Look for the type this maps to, returning previous mapping if none-such
     86                i = typeEnv.find( typeName );
     87                if ( i == typeEnv.end() ) return actualType;
     88        }
     89       
     90        // return type from substitution set
     91        return i->second;
     92       
     93#if 0
    7494        if ( i == typeEnv.end() ) {
    7595                return 0;
     
    7797                return i->second;
    7898        } // if
     99#endif
    79100}
    80101
Note: See TracChangeset for help on using the changeset viewer.