- File:
-
- 1 edited
-
src/ResolvExpr/ConversionCost.cc (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/ConversionCost.cc
r748c751 r76fe046 278 278 if ( const ast::BasicType * dstAsBasic = dynamic_cast< const ast::BasicType * >( dst ) ) { 279 279 conversionCostFromBasicToBasic( basicType, dstAsBasic ); 280 } else if ( dynamic_cast< const ast::EnumAttrType *>(dst) ) { 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) ) { 281 291 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 282 292 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 }288 293 } 289 294 } … … 361 366 } 362 367 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 } 368 void ConversionCost::postvisit( const ast::EnumInstType * ) { 372 369 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 373 370 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); … … 377 374 } 378 375 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 } 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 404 392 } 405 393 … … 478 466 cost.incSafe( maxIntCost + 2 ); 479 467 // 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 }485 468 } 486 469 } … … 500 483 cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] ); 501 484 } 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 }507 485 } 508 486 }
Note:
See TracChangeset
for help on using the changeset viewer.