Changeset af746cc for src/ResolvExpr/ConversionCost.cc
- Timestamp:
- Apr 15, 2024, 12:03:53 PM (7 months ago)
- Branches:
- master
- Children:
- dc58e5d
- Parents:
- d9bad51
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/ConversionCost.cc
rd9bad51 raf746cc 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 ( inst->base && inst->base->base ) { 365 if ( auto dstAsAttr = dynamic_cast<const ast::EnumAttrType *>( dst ) ) { 366 auto instAsAttr = ast::EnumAttrType( inst, dstAsAttr->attr ); 367 if ( instAsAttr.match(dstAsAttr) ) { 368 cost.incUnsafe(); 369 } 370 371 } else if ( auto dstAsInst = dynamic_cast<const ast::EnumInstType *>( dst ) ) { 372 if (inst->base && dstAsInst->base) { 373 if (inst->base == dstAsInst->base) { 374 cost.incUnsafe(); 375 } 376 } 377 } else { 378 auto instAsVal = ast::EnumAttrType( inst, ast::EnumAttribute::Value ); 379 cost = costCalc( &instAsVal, dst, srcIsLvalue, symtab, env ); 380 if ( cost < Cost::infinity ) { 381 cost.incUnsafe(); 382 } 383 } 384 return; 385 } 369 386 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 370 387 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); … … 374 391 } 375 392 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 393 void ConversionCost::postvisit( const ast::EnumAttrType * src ) { 394 auto dstAsEnumAttrType = dynamic_cast<const ast::EnumAttrType *>(dst); 395 if ( src->attr == ast::EnumAttribute::Label ) { 396 if ( dstAsEnumAttrType && dstAsEnumAttrType->attr == ast::EnumAttribute::Label ) { 397 cost = costCalc( src->instance, dstAsEnumAttrType->instance, srcIsLvalue, symtab, env ); 398 } 399 // Add Conversion To String 400 } else if ( src->attr == ast::EnumAttribute::Value ) { 401 if ( dstAsEnumAttrType && dstAsEnumAttrType->attr == ast::EnumAttribute::Value) { 402 cost = costCalc( src->instance, dstAsEnumAttrType->instance, srcIsLvalue, symtab, env ); 403 } else { 404 auto baseType = src->instance->base->base; 405 cost = costCalc( baseType, dst, srcIsLvalue, symtab, env ); 406 if ( cost < Cost::infinity ) { 407 cost.incUnsafe(); 408 } 409 } 410 } else { // ast::EnumAttribute::Posn 411 if ( auto dstBase = dynamic_cast<const ast::EnumInstType *>( dst ) ) { 412 cost = costCalc( src->instance, dstBase, srcIsLvalue, symtab, env ); 413 if ( cost < Cost::unsafe ) cost.incSafe(); 414 } else { 415 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 416 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); 417 if ( cost < Cost::unsafe ) { 418 cost.incSafe(); 419 } 420 } 421 } 392 422 } 393 423 … … 466 496 cost.incSafe( maxIntCost + 2 ); 467 497 // assuming 0p is supposed to be used for pointers? 498 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 499 if ( dstAsEnumInst->base && !dstAsEnumInst->base->base ) { 500 cost = Cost::zero; 501 cost.incUnsafe(); 502 } 468 503 } 469 504 } … … 483 518 cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] ); 484 519 } 520 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 521 if ( dstAsEnumInst->base && !dstAsEnumInst->base->base ) { 522 cost = Cost::zero; 523 cost.incUnsafe(); 524 } 485 525 } 486 526 }
Note: See TracChangeset
for help on using the changeset viewer.