- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/ConversionCost.cpp
r85855b0 r5ccc733 162 162 Cost conversionCost( 163 163 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue, 164 164 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 } 237 243 } else { 238 244 assert( -1 == diff ); 239 245 const ast::ReferenceType * dstAsRef = dynamic_cast< const ast::ReferenceType * >( dst ); 240 246 assert( dstAsRef ); 241 if ( typesCompatibleIgnoreQualifiers( src, dstAsRef->base, env ) ) { 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 ) ) { 242 253 if ( srcIsLvalue ) { 243 254 if ( src->qualifiers == dstAsRef->base->qualifiers ) { … … 284 295 if ( const ast::BasicType * dstAsBasic = dynamic_cast< const ast::BasicType * >( dst ) ) { 285 296 conversionCostFromBasicToBasic( basicType, dstAsBasic ); 286 } 287 if ( dstAsEnumInst->base && !dstAsEnumInst->base->is Typed) {288 cost = Cost:: unsafe;297 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 298 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isCfa ) { 299 cost = Cost::safe; 289 300 } 290 301 } … … 366 377 if ( auto dstInst = dynamic_cast<const ast::EnumInstType *>( dst ) ) { 367 378 cost = enumCastCost(inst, dstInst, symtab, env); 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(); 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(); 379 384 } 380 385 … … 454 459 // assuming 0p is supposed to be used for pointers? 455 460 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 456 if ( dstAsEnumInst->base && !dstAsEnumInst->base->is Typed) {457 cost = Cost:: unsafe;461 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isCfa ) { 462 cost = Cost::safe; 458 463 } 459 464 } … … 475 480 } 476 481 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 477 if ( dstAsEnumInst->base && !dstAsEnumInst->base->is Typed) {478 cost = Cost:: unsafe;482 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isCfa ) { 483 cost = Cost::safe; 479 484 } 480 485 }
Note: See TracChangeset
for help on using the changeset viewer.