- File:
-
- 1 edited
-
src/ResolvExpr/ConversionCost.cc (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/ConversionCost.cc
r76fe046 r748c751 278 278 if ( const ast::BasicType * dstAsBasic = dynamic_cast< const ast::BasicType * >( dst ) ) { 279 279 conversionCostFromBasicToBasic( basicType, dstAsBasic ); 280 } 281 else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 282 auto enumDecl = enumInst->base; 283 if ( enumDecl->base.get() ) { 284 // cost = costCalc( basicType, baseType, srcIsLvalue, symtab, env ); 285 // cost.incUnsafe(); 286 cost = Cost::infinity; 287 } else { 288 cost = Cost::unsafe; 289 } 290 } else if ( dynamic_cast< const ast::EnumPosType *>(dst) ) { 280 } else if ( dynamic_cast< const ast::EnumAttrType *>(dst) ) { 291 281 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 292 282 cost = costCalc( basicType, integer, srcIsLvalue, symtab, env ); 283 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 284 if ( dstAsEnumInst->base && !dstAsEnumInst->base->base ) { 285 cost = Cost::zero; 286 cost.incUnsafe(); 287 } 293 288 } 294 289 } … … 366 361 } 367 362 368 void ConversionCost::postvisit( const ast::EnumInstType * ) { 363 void ConversionCost::postvisit( const ast::EnumInstType * inst ) { 364 if ( auto dstAsInst = dynamic_cast<const ast::EnumInstType *>( dst ) ) { 365 if (inst->base && dstAsInst->base) { 366 if (inst->base->name == dstAsInst->base->name) { 367 cost = Cost::zero; 368 return; 369 } 370 } 371 } 369 372 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 370 373 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); … … 374 377 } 375 378 376 void ConversionCost::postvisit( const ast::EnumPosType * src ) { 377 if ( dynamic_cast<const ast::EnumPosType *>( dst ) ) { 378 // cost = costCalc( src->instance, dstBase->instance, srcIsLvalue, symtab, env ); 379 // if ( cost < Cost::unsafe ) cost.incSafe(); 380 cost = Cost::zero; 381 } else if ( auto dstBase = dynamic_cast<const ast::EnumInstType *>( dst ) ) { 382 cost = costCalc( src->instance, dstBase, srcIsLvalue, symtab, env ); 383 if ( cost < Cost::unsafe ) cost.incSafe(); 384 } else { 385 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 386 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); 387 if ( cost < Cost::unsafe ) { 388 cost.incSafe(); 389 } 390 } 391 379 void ConversionCost::postvisit( const ast::EnumAttrType * src ) { 380 auto dstAsEnumAttrType = dynamic_cast<const ast::EnumAttrType *>(dst); 381 assert( src->attr != ast::EnumAttribute::Label ); 382 if ( src->attr == ast::EnumAttribute::Value ) { 383 if ( dstAsEnumAttrType && dstAsEnumAttrType->attr == ast::EnumAttribute::Value) { 384 cost = costCalc( src->instance, dstAsEnumAttrType->instance, srcIsLvalue, symtab, env ); 385 } else { 386 auto baseType = src->instance->base->base; 387 cost = costCalc( baseType, dst, srcIsLvalue, symtab, env ); 388 if ( cost < Cost::infinity ) { 389 cost.incUnsafe(); 390 } 391 } 392 } else { // ast::EnumAttribute::Posn 393 if ( auto dstBase = dynamic_cast<const ast::EnumInstType *>( dst ) ) { 394 cost = costCalc( src->instance, dstBase, srcIsLvalue, symtab, env ); 395 if ( cost < Cost::unsafe ) cost.incSafe(); 396 } else { 397 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 398 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); 399 if ( cost < Cost::unsafe ) { 400 cost.incSafe(); 401 } 402 } 403 } 392 404 } 393 405 … … 466 478 cost.incSafe( maxIntCost + 2 ); 467 479 // assuming 0p is supposed to be used for pointers? 480 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 481 if ( dstAsEnumInst->base && !dstAsEnumInst->base->base ) { 482 cost = Cost::zero; 483 cost.incUnsafe(); 484 } 468 485 } 469 486 } … … 483 500 cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] ); 484 501 } 502 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 503 if ( dstAsEnumInst->base && !dstAsEnumInst->base->base ) { 504 cost = Cost::zero; 505 cost.incUnsafe(); 506 } 485 507 } 486 508 }
Note:
See TracChangeset
for help on using the changeset viewer.