- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/ConversionCost.cpp
r5ccc733 r85855b0 162 162 Cost conversionCost( 163 163 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue, 164 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env164 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env 165 165 ) { 166 166 if ( const ast::TypeInstType * inst = dynamic_cast< const ast::TypeInstType * >( dst ) ) { … … 235 235 return ast::Pass<ConversionCost>::read( src, dst, srcIsLvalue, symtab, env, conversionCost ); 236 236 } 237 if (const ast::EnumInstType * srcAsInst = dynamic_cast< const ast::EnumInstType * >( src )) {238 if (srcAsInst->base && !srcAsInst->base->isCfa) {239 static const ast::BasicType* integer = new ast::BasicType( ast::BasicKind::UnsignedInt );240 return ast::Pass<ConversionCost>::read( integer, dst, srcIsLvalue, symtab, env, conversionCost );241 }242 }243 237 } else { 244 238 assert( -1 == diff ); 245 239 const ast::ReferenceType * dstAsRef = dynamic_cast< const ast::ReferenceType * >( dst ); 246 240 assert( dstAsRef ); 247 auto dstBaseType = dstAsRef->base; 248 const ast::Type * newSrc = src; 249 if ( dynamic_cast< const ast::EnumInstType * >( src ) && dstBaseType.as<ast::BasicType>() ) { 250 newSrc = new ast::BasicType( ast::BasicKind::UnsignedInt ); 251 } 252 if ( typesCompatibleIgnoreQualifiers( newSrc, dstAsRef->base, env ) ) { 241 if ( typesCompatibleIgnoreQualifiers( src, dstAsRef->base, env ) ) { 253 242 if ( srcIsLvalue ) { 254 243 if ( src->qualifiers == dstAsRef->base->qualifiers ) { … … 295 284 if ( const ast::BasicType * dstAsBasic = dynamic_cast< const ast::BasicType * >( dst ) ) { 296 285 conversionCostFromBasicToBasic( basicType, dstAsBasic ); 297 } 298 if ( dstAsEnumInst->base && !dstAsEnumInst->base->is Cfa) {299 cost = Cost:: safe;286 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 287 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isTyped ) { 288 cost = Cost::unsafe; 300 289 } 301 290 } … … 377 366 if ( auto dstInst = dynamic_cast<const ast::EnumInstType *>( dst ) ) { 378 367 cost = enumCastCost(inst, dstInst, symtab, env); 379 } else if ( !inst->base->isCfa ) { 380 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) }; 381 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); 382 } 383 // cost.incUnsafe(); 368 return; 369 } 370 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) }; 371 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); 372 if ( !inst->base->isTyped ) { 373 if ( cost < Cost::unsafe ) { 374 cost.incSafe(); 375 } 376 return; 377 } 378 cost.incUnsafe(); 384 379 } 385 380 … … 459 454 // assuming 0p is supposed to be used for pointers? 460 455 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 461 if ( dstAsEnumInst->base && !dstAsEnumInst->base->is Cfa) {462 cost = Cost:: safe;456 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isTyped ) { 457 cost = Cost::unsafe; 463 458 } 464 459 } … … 480 475 } 481 476 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 482 if ( dstAsEnumInst->base && !dstAsEnumInst->base->is Cfa) {483 cost = Cost:: safe;477 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isTyped ) { 478 cost = Cost::unsafe; 484 479 } 485 480 }
Note: See TracChangeset
for help on using the changeset viewer.