Changeset f80e0218 for src/GenPoly/GenPoly.cc
- Timestamp:
- Jun 30, 2016, 4:32:56 PM (10 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:
- ea29e73
- Parents:
- 1b5c81ed (diff), 84d4d6f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
src/GenPoly/GenPoly.cc (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/GenPoly.cc
r1b5c81ed rf80e0218 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // GenPoly.cc -- 7 // GenPoly.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue Dec 15 16:11:18 201511 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed May 25 13:39:21 2016 13 13 // Update Count : 13 14 14 // … … 66 66 } 67 67 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 } 76 68 77 Type *isPolyType( Type *type, const TypeSubstitution *env ) { 78 type = replaceTypeInst( type, env ); 79 69 80 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 81 return type; 76 82 } else if ( StructInstType *structType = dynamic_cast< StructInstType* >( type ) ) { … … 81 87 return 0; 82 88 } 83 89 84 90 Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) { 91 type = replaceTypeInst( type, env ); 92 85 93 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 94 if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) { 92 95 return type; … … 101 104 102 105 Type *isPolyPtr( Type *type, const TypeSubstitution *env ) { 106 type = replaceTypeInst( type, env ); 107 103 108 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) { 104 109 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 112 return 0; 113 } 114 110 } 111 return 0; 112 } 113 115 114 Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) { 115 type = replaceTypeInst( type, env ); 116 116 117 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) { 117 118 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 119 } 125 120 return 0; 126 121 } … … 132 127 133 128 while ( true ) { 129 type = replaceTypeInst( type, env ); 130 134 131 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) { 135 132 type = ptr->get_base(); 136 133 ++(*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 134 } else break; 144 135 } … … 146 137 return isPolyType( type, env ); 147 138 } 148 139 149 140 Type * hasPolyBase( Type *type, const TyVarMap &tyVars, int *levels, const TypeSubstitution *env ) { 150 141 int dummy; … … 153 144 154 145 while ( true ) { 146 type = replaceTypeInst( type, env ); 147 155 148 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) { 156 149 type = ptr->get_base(); 157 150 ++(*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 151 } else break; 165 152 } … … 185 172 if ( VariableExpr *varExpr = dynamic_cast< VariableExpr* >( expr ) ) { 186 173 return varExpr; 174 } else if ( MemberExpr *memberExpr = dynamic_cast< MemberExpr* >( expr ) ) { 175 expr = memberExpr->get_aggregate(); 187 176 } else if ( AddressExpr *addressExpr = dynamic_cast< AddressExpr* >( expr ) ) { 188 177 expr = addressExpr->get_arg(); … … 192 181 if ( ! fn || fn->get_name() != std::string("*?") ) return 0; 193 182 expr = *untypedExpr->begin_args(); 183 } else if ( CommaExpr *commaExpr = dynamic_cast< CommaExpr* >( expr ) ) { 184 // copy constructors insert comma exprs, look at second argument which contains the variable 185 expr = commaExpr->get_arg2(); 186 continue; 194 187 } else break; 195 188 … … 209 202 } 210 203 } 211 204 212 205 void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ) { 213 206 for ( TyVarMap::const_iterator i = tyVarMap.begin(); i != tyVarMap.end(); ++i ) {
Note:
See TracChangeset
for help on using the changeset viewer.