Changeset 5ccc733 for src/ResolvExpr
- Timestamp:
- Jun 29, 2024, 5:02:06 AM (7 months ago)
- Branches:
- master
- Children:
- 4117761
- Parents:
- 7552fde
- Location:
- src/ResolvExpr
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CastCost.cpp
r7552fde r5ccc733 54 54 cost = conversionCost( enumInst, dst, srcIsLvalue, symtab, env ); 55 55 56 if ( Cost::unsafe < cost) {56 if ( !enumInst->base->isCfa ) { 57 57 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) }; 58 58 Cost intCost = costCalc( integer, dst, srcIsLvalue, symtab, env ); 59 59 cost = intCost < cost? intCost: cost; 60 } 61 if ( enumInst->base->isTyped && enumInst->base->base ) { 60 } else if ( enumInst->base->isTyped() ) { 62 61 auto baseConversionCost = 63 62 castCost( enumInst->base->base, dst, srcIsLvalue, symtab, env ); … … 74 73 cost = conversionCost( basicType, dst, srcIsLvalue, symtab, env ); 75 74 if ( Cost::unsafe < cost ) { 76 if (auto enumInst = dynamic_cast<const ast::EnumInstType *>(dst)) { 77 // Always explict cast only for typed enum 78 if (enumInst->base->isTyped) cost = Cost::unsafe; 75 if ( dynamic_cast<const ast::EnumInstType *>(dst)) { 76 cost = Cost::unsafe; 79 77 } 80 78 } … … 85 83 cost = conversionCost( zero, dst, srcIsLvalue, symtab, env ); 86 84 if ( Cost::unsafe < cost ) { 87 if ( auto enumInst =dynamic_cast<const ast::EnumInstType *>(dst)) {88 if (enumInst->base->isTyped)cost = Cost::unsafe;85 if ( dynamic_cast<const ast::EnumInstType *>(dst)) { 86 cost = Cost::unsafe; 89 87 } 90 88 } … … 94 92 cost = conversionCost( one, dst, srcIsLvalue, symtab, env ); 95 93 if ( Cost::unsafe < cost ) { 96 if ( auto enumInst =dynamic_cast<const ast::EnumInstType *>(dst)) {97 if (enumInst->base->isTyped)cost = Cost::unsafe;94 if ( dynamic_cast<const ast::EnumInstType *>(dst)) { 95 cost = Cost::unsafe; 98 96 } 99 97 } -
src/ResolvExpr/CommonType.cpp
r7552fde r5ccc733 386 386 } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( type2 ) ) { 387 387 const ast::EnumDecl* enumDecl = enumInst->base; 388 if ( !enumDecl-> base) {388 if ( !enumDecl->isCfa ) { 389 389 ast::BasicKind kind = commonTypes[ basic->kind ][ ast::BasicKind::SignedInt ]; 390 390 if ( … … 642 642 const ast::EnumDecl* argDecl = argAsEnumInst->base; 643 643 if (argDecl->isSubTypeOf(paramDecl)) result = param; 644 } else if ( param->base && !param->base->is Typed) {644 } else if ( param->base && !param->base->isCfa ) { 645 645 auto basicType = new ast::BasicType( ast::BasicKind::UnsignedInt ); 646 646 result = commonType( basicType, type2, tenv, need, have, open, widen); -
src/ResolvExpr/ConversionCost.cpp
r7552fde r5ccc733 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 ) { … … 285 296 conversionCostFromBasicToBasic( basicType, dstAsBasic ); 286 297 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 287 if ( dstAsEnumInst->base && !dstAsEnumInst->base->is Typed) {288 cost = Cost:: unsafe;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 371 if ( !inst->base->isTyped ) { 379 } else if ( !inst->base->isCfa ) { 372 380 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) }; 373 381 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); 374 if ( cost < Cost::unsafe ) {375 cost.incSafe();376 }377 return;378 382 } 379 383 // cost.incUnsafe(); … … 455 459 // assuming 0p is supposed to be used for pointers? 456 460 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 457 if ( dstAsEnumInst->base && !dstAsEnumInst->base->is Typed) {458 cost = Cost:: unsafe;461 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isCfa ) { 462 cost = Cost::safe; 459 463 } 460 464 } … … 476 480 } 477 481 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 478 if ( dstAsEnumInst->base && !dstAsEnumInst->base->is Typed) {479 cost = Cost:: unsafe;482 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isCfa ) { 483 cost = Cost::safe; 480 484 } 481 485 }
Note: See TracChangeset
for help on using the changeset viewer.