Changeset 8488c715 for src/GenPoly/GenPoly.cc
- Timestamp:
- Jan 22, 2016, 3:30:43 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, string, with_gc
- Children:
- 73a28e2
- Parents:
- 6d160d7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/GenPoly.cc
r6d160d7 r8488c715 127 127 } 128 128 129 Type *hasPolyBase( Type *type, const TypeSubstitution *env ) { 130 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) { 131 return hasPolyBase( ptr->get_base(), env ); 132 } else if ( env ) { 133 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) { 134 if ( Type *newType = env->lookup( typeInst->get_name() ) ) { 135 return hasPolyBase( newType, env ); 136 } // if 137 } // if 129 Type * hasPolyBase( Type *type, int *levels, const TypeSubstitution *env ) { 130 int dummy; 131 if ( ! levels ) { levels = &dummy; } 132 *levels = 0; 133 134 while ( true ) { 135 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) { 136 type = ptr->get_base(); 137 ++(*levels); 138 } else if ( env ) { 139 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) { 140 if ( Type *newType = env->lookup( typeInst->get_name() ) ) { 141 type = newType; 142 } else break; 143 } else break; 144 } else break; 138 145 } 139 146 … … 141 148 } 142 149 143 Type *hasPolyBase( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) { 144 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) { 145 return hasPolyBase( ptr->get_base(), tyVars, env ); 146 } else if ( env ) { 147 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) { 148 if ( Type *newType = env->lookup( typeInst->get_name() ) ) { 149 return hasPolyBase( newType, tyVars, env ); 150 } // if 151 } // if 150 Type * hasPolyBase( Type *type, const TyVarMap &tyVars, int *levels, const TypeSubstitution *env ) { 151 int dummy; 152 if ( ! levels ) { levels = &dummy; } 153 *levels = 0; 154 155 while ( true ) { 156 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) { 157 type = ptr->get_base(); 158 ++(*levels); 159 } else if ( env ) { 160 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) { 161 if ( Type *newType = env->lookup( typeInst->get_name() ) ) { 162 type = newType; 163 } else break; 164 } else break; 165 } else break; 152 166 } 153 167 … … 164 178 } 165 179 166 VariableExpr *getBaseVar( Expression *expr ) { 167 if ( VariableExpr *varExpr = dynamic_cast< VariableExpr* >( expr ) ) { 168 // found the variable directly 169 return varExpr; 170 } else if ( AddressExpr *addressExpr = dynamic_cast< AddressExpr* >( expr ) ) { 171 return getBaseVar( addressExpr->get_arg() ); 172 } else if ( UntypedExpr *untypedExpr = dynamic_cast< UntypedExpr* >( expr ) ) { 173 // look for compiler-inserted dereference operator 174 NameExpr *fn = dynamic_cast< NameExpr* >( untypedExpr->get_function() ); 175 if ( ! fn || fn->get_name() != std::string("*?") ) return 0; 176 return getBaseVar( *untypedExpr->begin_args() ); 177 } else return 0; 180 VariableExpr * getBaseVar( Expression *expr, int *levels ) { 181 int dummy; 182 if ( ! levels ) { levels = &dummy; } 183 *levels = 0; 184 185 while ( true ) { 186 if ( VariableExpr *varExpr = dynamic_cast< VariableExpr* >( expr ) ) { 187 return varExpr; 188 } else if ( AddressExpr *addressExpr = dynamic_cast< AddressExpr* >( expr ) ) { 189 expr = addressExpr->get_arg(); 190 } else if ( UntypedExpr *untypedExpr = dynamic_cast< UntypedExpr* >( expr ) ) { 191 // look for compiler-inserted dereference operator 192 NameExpr *fn = dynamic_cast< NameExpr* >( untypedExpr->get_function() ); 193 if ( ! fn || fn->get_name() != std::string("*?") ) return 0; 194 expr = *untypedExpr->begin_args(); 195 } else break; 196 197 ++(*levels); 198 } 199 200 return 0; 178 201 } 179 202
Note: See TracChangeset
for help on using the changeset viewer.