Changes in / [4a8c875:9554d9b]
- Location:
- src
- Files:
-
- 3 edited
-
GenPoly/GenPoly.cc (modified) (5 diffs)
-
GenPoly/GenPoly.h (modified) (1 diff)
-
SynTree/TypeSubstitution.cc (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/GenPoly.cc
r4a8c875 r9554d9b 64 64 return false; 65 65 } 66 67 /// Replaces a TypeInstType by its referrent in the environment, if applicable68 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 }76 66 } 77 67 78 68 Type *isPolyType( Type *type, const TypeSubstitution *env ) { 79 type = replaceTypeInst( type, env );80 81 69 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 82 75 return type; 83 76 } else if ( StructInstType *structType = dynamic_cast< StructInstType* >( type ) ) { … … 90 83 91 84 Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) { 92 type = replaceTypeInst( type, env );93 94 85 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 95 91 if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) { 96 92 return type; … … 105 101 106 102 Type *isPolyPtr( Type *type, const TypeSubstitution *env ) { 107 type = replaceTypeInst( type, env );108 109 103 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) { 110 104 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 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 118 116 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) { 119 117 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 121 125 return 0; 122 126 } … … 128 132 129 133 while ( true ) { 130 type = replaceTypeInst( type, env );131 132 134 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) { 133 135 type = ptr->get_base(); 134 136 ++(*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; 135 143 } else break; 136 144 } … … 145 153 146 154 while ( true ) { 147 type = replaceTypeInst( type, env );148 149 155 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) { 150 156 type = ptr->get_base(); 151 157 ++(*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; 152 164 } else break; 153 165 } -
src/GenPoly/GenPoly.h
r4a8c875 r9554d9b 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 -
src/SynTree/TypeSubstitution.cc
r4a8c875 r9554d9b 72 72 Type *TypeSubstitution::lookup( std::string formalType ) const { 73 73 TypeEnvType::const_iterator i = typeEnv.find( formalType ); 74 75 // break on not in substitution set76 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 follow83 if ( formalType == typeName ) break;84 85 // Look for the type this maps to, returning previous mapping if none-such86 i = typeEnv.find( typeName );87 if ( i == typeEnv.end() ) return actualType;88 }89 90 // return type from substitution set91 return i->second;92 93 #if 094 74 if ( i == typeEnv.end() ) { 95 75 return 0; … … 97 77 return i->second; 98 78 } // if 99 #endif100 79 } 101 80
Note:
See TracChangeset
for help on using the changeset viewer.