Changes in src/ResolvExpr/CastCost.cc [ef5b828:3c89751]
- File:
-
- 1 edited
-
src/ResolvExpr/CastCost.cc (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CastCost.cc
ref5b828 r3c89751 37 37 struct CastCost_old : public ConversionCost { 38 38 public: 39 CastCost_old( const Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc );39 CastCost_old( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc ); 40 40 41 41 using ConversionCost::previsit; 42 42 using ConversionCost::postvisit; 43 void postvisit( constBasicType * basicType );44 void postvisit( constPointerType * pointerType );43 void postvisit( BasicType * basicType ); 44 void postvisit( PointerType * pointerType ); 45 45 }; 46 46 47 Cost castCost( const Type * src, const Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ) {48 if ( const TypeInstType * destAsTypeInst = dynamic_cast< const TypeInstType* >( dest ) ) {49 if ( const EqvClass * eqvClass = env.lookup( destAsTypeInst->name) ) {47 Cost castCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ) { 48 if ( TypeInstType *destAsTypeInst = dynamic_cast< TypeInstType* >( dest ) ) { 49 if ( const EqvClass* eqvClass = env.lookup( destAsTypeInst->get_name() ) ) { 50 50 if ( eqvClass->type ) { 51 51 return castCost( src, eqvClass->type, indexer, env ); … … 53 53 return Cost::infinity; 54 54 } 55 } else if ( const NamedTypeDecl * namedType = indexer.lookupType( destAsTypeInst->name) ) {55 } else if ( NamedTypeDecl *namedType = indexer.lookupType( destAsTypeInst->get_name() ) ) { 56 56 // all typedefs should be gone by this point 57 const TypeDecl * type = strict_dynamic_cast< const TypeDecl* >( namedType );57 TypeDecl *type = strict_dynamic_cast< TypeDecl* >( namedType ); 58 58 if ( type->base ) { 59 59 return castCost( src, type->base, indexer, env ) + Cost::safe; … … 74 74 PRINT( std::cerr << "compatible!" << std::endl; ) 75 75 return Cost::zero; 76 } else if ( dynamic_cast< const VoidType* >( dest ) ) {76 } else if ( dynamic_cast< VoidType* >( dest ) ) { 77 77 return Cost::safe; 78 } else if ( const ReferenceType * refType = dynamic_cast< constReferenceType * > ( dest ) ) {78 } else if ( ReferenceType * refType = dynamic_cast< ReferenceType * > ( dest ) ) { 79 79 PRINT( std::cerr << "conversionCost: dest is reference" << std::endl; ) 80 return convertToReferenceCost( src, refType, indexer, env, []( const Type * t1, constType * t2, const SymTab::Indexer & indexer, const TypeEnvironment & env ) {80 return convertToReferenceCost( src, refType, indexer, env, [](Type * t1, Type * t2, const SymTab::Indexer & indexer, const TypeEnvironment & env ) { 81 81 return ptrsCastable( t1, t2, env, indexer ); 82 82 }); 83 83 } else { 84 PassVisitor<CastCost_old> converter( 85 dest, indexer, env, 86 (Cost (*)( const Type *, constType *, const SymTab::Indexer &, const TypeEnvironment & ))84 PassVisitor<CastCost_old> converter( 85 dest, indexer, env, 86 (Cost (*)( Type *, Type *, const SymTab::Indexer &, const TypeEnvironment & )) 87 87 castCost ); 88 88 src->accept( converter ); … … 96 96 } 97 97 98 CastCost_old::CastCost_old( const Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc )98 CastCost_old::CastCost_old( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc ) 99 99 : ConversionCost( dest, indexer, env, costFunc ) { 100 100 } 101 101 102 void CastCost_old::postvisit( const BasicType *basicType ) {103 const PointerType * destAsPointer = dynamic_cast< const PointerType* >( dest );102 void CastCost_old::postvisit( BasicType *basicType ) { 103 PointerType *destAsPointer = dynamic_cast< PointerType* >( dest ); 104 104 if ( destAsPointer && basicType->isInteger() ) { 105 // necessary for, e.g. unsigned long => void *105 // necessary for, e.g. unsigned long => void* 106 106 cost = Cost::unsafe; 107 107 } else { … … 110 110 } 111 111 112 void CastCost_old::postvisit( const PointerType *pointerType ) {113 if ( const PointerType * destAsPtr = dynamic_cast< const PointerType* >( dest ) ) {114 if ( pointerType-> tq <= destAsPtr->tq&& typesCompatibleIgnoreQualifiers( pointerType->base, destAsPtr->base, indexer, env ) ) {112 void CastCost_old::postvisit( PointerType *pointerType ) { 113 if ( PointerType *destAsPtr = dynamic_cast< PointerType* >( dest ) ) { 114 if ( pointerType->get_qualifiers() <= destAsPtr->get_qualifiers() && typesCompatibleIgnoreQualifiers( pointerType->base, destAsPtr->base, indexer, env ) ) { 115 115 cost = Cost::safe; 116 116 } else { … … 125 125 } // if 126 126 } // if 127 } else if ( const BasicType * destAsBasic = dynamic_cast< const BasicType* >( dest ) ) {127 } else if ( BasicType *destAsBasic = dynamic_cast< BasicType* >( dest ) ) { 128 128 if ( destAsBasic->isInteger() ) { 129 // necessary for, e.g. void * => unsigned long129 // necessary for, e.g. void* => unsigned long 130 130 cost = Cost::unsafe; 131 131 } // if … … 138 138 using ConversionCost_new::postvisit; 139 139 140 CastCost_new( 141 const ast::Type * dst, const ast::SymbolTable & symtab, 140 CastCost_new( 141 const ast::Type * dst, const ast::SymbolTable & symtab, 142 142 const ast::TypeEnvironment & env, CostCalculation costFunc ) 143 143 : ConversionCost_new( dst, symtab, env, costFunc ) {} … … 182 182 } // anonymous namespace 183 183 184 Cost castCost( 185 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab, 186 const ast::TypeEnvironment & env 184 Cost castCost( 185 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab, 186 const ast::TypeEnvironment & env 187 187 ) { 188 188 if ( auto typeInst = dynamic_cast< const ast::TypeInstType * >( dst ) ) { … … 220 220 PRINT( std::cerr << "conversionCost: dest is reference" << std::endl; ) 221 221 #warning cast on ptrsCastable artifact of having two functions, remove when port done 222 return convertToReferenceCost( 223 src, refType, symtab, env, 224 ( int (*)( 225 const ast::Type *, const ast::Type *, const ast::SymbolTable &, 222 return convertToReferenceCost( 223 src, refType, symtab, env, 224 ( int (*)( 225 const ast::Type *, const ast::Type *, const ast::SymbolTable &, 226 226 const ast::TypeEnvironment & ) 227 227 ) ptrsCastable ); … … 229 229 #warning cast on castCost artifact of having two functions, remove when port done 230 230 ast::Pass< CastCost_new > converter{ 231 dst, symtab, env, 232 ( Cost (*)( 233 const ast::Type *, const ast::Type *, const ast::SymbolTable &, 231 dst, symtab, env, 232 ( Cost (*)( 233 const ast::Type *, const ast::Type *, const ast::SymbolTable &, 234 234 const ast::TypeEnvironment & ) 235 235 ) castCost };
Note:
See TracChangeset
for help on using the changeset viewer.