Changes in / [4a8c875:9554d9b]


Ignore:
Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/GenPoly.cc

    r4a8c875 r9554d9b  
    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                 }
    7666        }
    7767
    7868        Type *isPolyType( Type *type, const TypeSubstitution *env ) {
    79                 type = replaceTypeInst( type, env );
    80                
    8169                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
    8275                        return type;
    8376                } else if ( StructInstType *structType = dynamic_cast< StructInstType* >( type ) ) {
     
    9083
    9184        Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) {
    92                 type = replaceTypeInst( type, env );
    93                
    9485                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
    9591                        if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) {
    9692                                return type;
     
    105101
    106102        Type *isPolyPtr( Type *type, const TypeSubstitution *env ) {
    107                 type = replaceTypeInst( type, env );
    108                
    109103                if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
    110104                        return isPolyType( ptr->get_base(), env );
    111                 }
     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
    112112                return 0;
    113113        }
    114114
    115115        Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) {
    116                 type = replaceTypeInst( type, env );
    117                
    118116                if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
    119117                        return isPolyType( ptr->get_base(), tyVars, env );
    120                 }
     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
    121125                return 0;
    122126        }
     
    128132
    129133                while ( true ) {
    130                         type = replaceTypeInst( type, env );
    131                
    132134                        if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
    133135                                type = ptr->get_base();
    134136                                ++(*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;
    135143                        } else break;
    136144                }
     
    145153
    146154                while ( true ) {
    147                         type = replaceTypeInst( type, env );
    148                
    149155                        if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
    150156                                type = ptr->get_base();
    151157                                ++(*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;
    152164                        } else break;
    153165                }
  • src/GenPoly/GenPoly.h

    r4a8c875 r9554d9b  
    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

    r4a8c875 r9554d9b  
    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
    9474        if ( i == typeEnv.end() ) {
    9575                return 0;
     
    9777                return i->second;
    9878        } // if
    99 #endif
    10079}
    10180
Note: See TracChangeset for help on using the changeset viewer.