Changeset e24955a
- Timestamp:
- May 26, 2016, 8:54:33 PM (8 years ago)
- 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
- Location:
- src/GenPoly
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/GenPoly.cc
r084184b re24955a 64 64 return false; 65 65 } 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 } 66 76 } 67 77 68 78 Type *isPolyType( Type *type, const TypeSubstitution *env ) { 79 type = replaceTypeInst( type, env ); 80 69 81 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 } // if74 } // if75 82 return type; 76 83 } else if ( StructInstType *structType = dynamic_cast< StructInstType* >( type ) ) { … … 83 90 84 91 Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) { 92 type = replaceTypeInst( type, env ); 93 85 94 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 } // if90 } // if91 95 if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) { 92 96 return type; … … 101 105 102 106 Type *isPolyPtr( Type *type, const TypeSubstitution *env ) { 107 type = replaceTypeInst( type, env ); 108 103 109 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) { 104 110 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 } 112 112 return 0; 113 113 } 114 114 115 115 Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) { 116 type = replaceTypeInst( type, env ); 117 116 118 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) { 117 119 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 } 125 121 return 0; 126 122 } … … 132 128 133 129 while ( true ) { 130 type = replaceTypeInst( type, env ); 131 134 132 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) { 135 133 type = ptr->get_base(); 136 134 ++(*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;143 135 } else break; 144 136 } … … 153 145 154 146 while ( true ) { 147 type = replaceTypeInst( type, env ); 148 155 149 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) { 156 150 type = ptr->get_base(); 157 151 ++(*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;164 152 } else break; 165 153 } -
src/GenPoly/GenPoly.h
r084184b re24955a 31 31 namespace GenPoly { 32 32 typedef ErasableScopedMap< std::string, TypeDecl::Kind > TyVarMap; 33 33 34 34 /// A function needs an adapter if it returns a polymorphic value or if any of its 35 35 /// parameters have polymorphic type
Note: See TracChangeset
for help on using the changeset viewer.