Changeset e24955a for src/GenPoly


Ignore:
Timestamp:
May 26, 2016, 8:54:33 PM (8 years ago)
Author:
Aaron Moss <a3moss@…>
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:
4a8c875, aad5a48
Parents:
084184b
Message:

Fixed infinite loops in GenPoly?

Location:
src/GenPoly
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/GenPoly.cc

    r084184b re24955a  
    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

    r084184b re24955a  
    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
Note: See TracChangeset for help on using the changeset viewer.