Changeset eb0aedb for src/ResolvExpr/ConversionCost.cc
- Timestamp:
- Jan 10, 2018, 11:12:53 AM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 80e8582
- Parents:
- b8a4f47
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/ConversionCost.cc
rb8a4f47 reb0aedb 44 44 EqvClass eqvClass; 45 45 NamedTypeDecl *namedType; 46 PRINT( std::cerr << "type inst " << destAsTypeInst-> get_name(); )47 if ( env.lookup( destAsTypeInst-> get_name(), eqvClass ) ) {46 PRINT( std::cerr << "type inst " << destAsTypeInst->name; ) 47 if ( env.lookup( destAsTypeInst->name, eqvClass ) ) { 48 48 if ( eqvClass.type ) { 49 49 return conversionCost( src, eqvClass.type, indexer, env ); … … 51 51 return Cost::infinity; 52 52 } 53 } else if ( ( namedType = indexer.lookupType( destAsTypeInst-> get_name()) ) ) {53 } else if ( ( namedType = indexer.lookupType( destAsTypeInst->name ) ) ) { 54 54 PRINT( std::cerr << " found" << std::endl; ) 55 55 TypeDecl *type = dynamic_cast< TypeDecl* >( namedType ); 56 56 // all typedefs should be gone by this point 57 57 assert( type ); 58 if ( type-> get_base()) {59 return conversionCost( src, type-> get_base(), indexer, env ) + Cost::safe;58 if ( type->base ) { 59 return conversionCost( src, type->base, indexer, env ) + Cost::safe; 60 60 } // if 61 61 } // if … … 95 95 if ( diff > 0 ) { 96 96 // TODO: document this 97 Cost cost = convertToReferenceCost( strict_dynamic_cast< ReferenceType * >( src )-> get_base(), dest, diff-1, indexer, env, func );97 Cost cost = convertToReferenceCost( strict_dynamic_cast< ReferenceType * >( src )->base, dest, diff-1, indexer, env, func ); 98 98 cost.incReference(); 99 99 return cost; 100 100 } else if ( diff < -1 ) { 101 101 // TODO: document this 102 Cost cost = convertToReferenceCost( src, strict_dynamic_cast< ReferenceType * >( dest )-> get_base(), diff+1, indexer, env, func );102 Cost cost = convertToReferenceCost( src, strict_dynamic_cast< ReferenceType * >( dest )->base, diff+1, indexer, env, func ); 103 103 cost.incReference(); 104 104 return cost; … … 108 108 if ( srcAsRef && destAsRef ) { // pointer-like conversions between references 109 109 PRINT( std::cerr << "converting between references" << std::endl; ) 110 Type::Qualifiers tq1 = srcAsRef-> get_base()->get_qualifiers();111 Type::Qualifiers tq2 = destAsRef-> get_base()->get_qualifiers();112 if ( tq1 <= tq2 && typesCompatibleIgnoreQualifiers( srcAsRef-> get_base(), destAsRef->get_base(), indexer, env ) ) {110 Type::Qualifiers tq1 = srcAsRef->base->get_qualifiers(); 111 Type::Qualifiers tq2 = destAsRef->base->get_qualifiers(); 112 if ( tq1 <= tq2 && typesCompatibleIgnoreQualifiers( srcAsRef->base, destAsRef->base, indexer, env ) ) { 113 113 PRINT( std::cerr << " :: compatible and good qualifiers" << std::endl; ) 114 114 if ( tq1 == tq2 ) { … … 120 120 } 121 121 } else { // xxx - this discards reference qualifiers from consideration -- reducing qualifiers is a safe conversion; is this right? 122 int assignResult = func( srcAsRef-> get_base(), destAsRef->get_base(), env, indexer );122 int assignResult = func( srcAsRef->base, destAsRef->base, env, indexer ); 123 123 PRINT( std::cerr << "comparing references: " << assignResult << " " << srcAsRef << " " << destAsRef << std::endl; ) 124 124 if ( assignResult > 0 ) { … … 138 138 assert( diff == -1 && destAsRef ); 139 139 PRINT( std::cerr << "dest is: " << dest << " / src is: " << src << std::endl; ) 140 if ( typesCompatibleIgnoreQualifiers( src, destAsRef-> get_base(), indexer, env ) ) {140 if ( typesCompatibleIgnoreQualifiers( src, destAsRef->base, indexer, env ) ) { 141 141 PRINT( std::cerr << "converting compatible base type" << std::endl; ) 142 142 if ( src->get_lvalue() ) { … … 146 146 ) 147 147 // lvalue-to-reference conversion: cv lvalue T => cv T & 148 if ( src->get_qualifiers() == destAsRef-> get_base()->get_qualifiers() ) {148 if ( src->get_qualifiers() == destAsRef->base->get_qualifiers() ) { 149 149 return Cost::reference; // cost needs to be non-zero to add cast 150 } if ( src->get_qualifiers() < destAsRef-> get_base()->get_qualifiers() ) {150 } if ( src->get_qualifiers() < destAsRef->base->get_qualifiers() ) { 151 151 return Cost::safe; // cost needs to be higher than previous cast to differentiate adding qualifiers vs. keeping same 152 152 } else { 153 153 return Cost::unsafe; 154 154 } // if 155 } else if ( destAsRef-> get_base()->get_const() ) {155 } else if ( destAsRef->base->get_const() ) { 156 156 PRINT( std::cerr << "rvalue to const ref conversion" << std::endl; ) 157 157 // rvalue-to-const-reference conversion: T => const T & … … 281 281 if ( PointerType *destAsPtr = dynamic_cast< PointerType* >( dest ) ) { 282 282 PRINT( std::cerr << pointerType << " ===> " << destAsPtr << std::endl; ) 283 Type::Qualifiers tq1 = pointerType-> get_base()->get_qualifiers();284 Type::Qualifiers tq2 = destAsPtr-> get_base()->get_qualifiers();285 if ( tq1 <= tq2 && typesCompatibleIgnoreQualifiers( pointerType-> get_base(), destAsPtr->get_base(), indexer, env ) ) {283 Type::Qualifiers tq1 = pointerType->base->get_qualifiers(); 284 Type::Qualifiers tq2 = destAsPtr->base->get_qualifiers(); 285 if ( tq1 <= tq2 && typesCompatibleIgnoreQualifiers( pointerType->base, destAsPtr->base, indexer, env ) ) { 286 286 PRINT( std::cerr << " :: compatible and good qualifiers" << std::endl; ) 287 287 if ( tq1 == tq2 ) { … … 363 363 EqvClass eqvClass; 364 364 NamedTypeDecl *namedType; 365 if ( env.lookup( inst-> get_name(), eqvClass ) ) {365 if ( env.lookup( inst->name, eqvClass ) ) { 366 366 cost = conversionCost( eqvClass.type, dest, indexer, env ); 367 367 } else if ( TypeInstType *destAsInst = dynamic_cast< TypeInstType* >( dest ) ) { 368 if ( inst-> get_name() == destAsInst->get_name()) {368 if ( inst->name == destAsInst->name ) { 369 369 cost = Cost::zero; 370 370 } 371 } else if ( ( namedType = indexer.lookupType( inst-> get_name()) ) ) {371 } else if ( ( namedType = indexer.lookupType( inst->name ) ) ) { 372 372 TypeDecl *type = dynamic_cast< TypeDecl* >( namedType ); 373 373 // all typedefs should be gone by this point 374 374 assert( type ); 375 if ( type-> get_base()) {376 cost = conversionCost( type-> get_base(), dest, indexer, env ) + Cost::safe;375 if ( type->base ) { 376 cost = conversionCost( type->base, dest, indexer, env ) + Cost::safe; 377 377 } // if 378 378 } // if … … 382 382 Cost c = Cost::zero; 383 383 if ( TupleType * destAsTuple = dynamic_cast< TupleType * >( dest ) ) { 384 std::list< Type * >::const_iterator srcIt = tupleType-> get_types().begin();385 std::list< Type * >::const_iterator destIt = destAsTuple-> get_types().begin();386 while ( srcIt != tupleType-> get_types().end() && destIt != destAsTuple->get_types().end() ) {384 std::list< Type * >::const_iterator srcIt = tupleType->types.begin(); 385 std::list< Type * >::const_iterator destIt = destAsTuple->types.begin(); 386 while ( srcIt != tupleType->types.end() && destIt != destAsTuple->types.end() ) { 387 387 Cost newCost = conversionCost( *srcIt++, *destIt++, indexer, env ); 388 388 if ( newCost == Cost::infinity ) { … … 391 391 c += newCost; 392 392 } // while 393 if ( destIt != destAsTuple-> get_types().end() ) {393 if ( destIt != destAsTuple->types.end() ) { 394 394 cost = Cost::infinity; 395 395 } else {
Note: See TracChangeset
for help on using the changeset viewer.