- File:
-
- 1 edited
-
src/ResolvExpr/ConversionCost.cc (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/ConversionCost.cc
rfc1a3e2 r748c751 59 59 // GENERATED START, DO NOT EDIT 60 60 // GENERATED BY BasicTypes-gen.cc 61 static const int costMatrix[ast::Basic Kind::NUMBER_OF_BASIC_TYPES][ast::BasicKind::NUMBER_OF_BASIC_TYPES] = { // path length from root to node61 static const int costMatrix[ast::BasicType::NUMBER_OF_BASIC_TYPES][ast::BasicType::NUMBER_OF_BASIC_TYPES] = { // path length from root to node 62 62 /* B C SC UC SI SUI I UI LI LUI LLI LLUI IB UIB _FH _FH _F _FC F FC _FX _FXC FD _FDC D DC F80X_FDXC F80 _FB_FLDC FB LD LDC _FBX_FLDXC */ 63 63 /* B */ { 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 17, 16, 18, 17, }, … … 101 101 // GENERATED END 102 102 static_assert( 103 sizeof(costMatrix)/sizeof(costMatrix[0][0]) == ast::Basic Kind::NUMBER_OF_BASIC_TYPES * ast::BasicKind::NUMBER_OF_BASIC_TYPES,103 sizeof(costMatrix)/sizeof(costMatrix[0][0]) == ast::BasicType::NUMBER_OF_BASIC_TYPES * ast::BasicType::NUMBER_OF_BASIC_TYPES, 104 104 "Missing row in the cost matrix" 105 105 ); … … 107 107 // GENERATED START, DO NOT EDIT 108 108 // GENERATED BY BasicTypes-gen.cc 109 static const int signMatrix[ast::Basic Kind::NUMBER_OF_BASIC_TYPES][ast::BasicKind::NUMBER_OF_BASIC_TYPES] = { // number of sign changes in safe conversion109 static const int signMatrix[ast::BasicType::NUMBER_OF_BASIC_TYPES][ast::BasicType::NUMBER_OF_BASIC_TYPES] = { // number of sign changes in safe conversion 110 110 /* B C SC UC SI SUI I UI LI LUI LLI LLUI IB UIB _FH _FH _F _FC F FC _FX _FXC FD _FDC D DC F80X_FDXC F80 _FB_FLDC FB LD LDC _FBX_FLDXC */ 111 111 /* B */ { 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, … … 148 148 // GENERATED END 149 149 static_assert( 150 sizeof(signMatrix)/sizeof(signMatrix[0][0]) == ast::Basic Kind::NUMBER_OF_BASIC_TYPES * ast::BasicKind::NUMBER_OF_BASIC_TYPES,150 sizeof(signMatrix)/sizeof(signMatrix[0][0]) == ast::BasicType::NUMBER_OF_BASIC_TYPES * ast::BasicType::NUMBER_OF_BASIC_TYPES, 151 151 "Missing row in the sign matrix" 152 152 ); … … 279 279 conversionCostFromBasicToBasic( basicType, dstAsBasic ); 280 280 } else if ( dynamic_cast< const ast::EnumAttrType *>(dst) ) { 281 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::Basic Kind::SignedInt ) };281 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 282 282 cost = costCalc( basicType, integer, srcIsLvalue, symtab, env ); 283 283 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { … … 369 369 } 370 370 } 371 return; 372 } 373 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) }; 371 } 372 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 374 373 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); 375 374 if ( cost < Cost::unsafe ) { … … 379 378 380 379 void ConversionCost::postvisit( const ast::EnumAttrType * src ) { 381 auto dstAsEnumAttrType = dynamic_cast<const ast::EnumAttrType *>(dst);380 auto dstAsEnumAttrType = dynamic_cast<const ast::EnumAttrType *>(dst); 382 381 assert( src->attr != ast::EnumAttribute::Label ); 383 if ( src->attr == ast::EnumAttribute::Value ) {384 if ( dstAsEnumAttrType && dstAsEnumAttrType->attr == ast::EnumAttribute::Value) {385 cost = costCalc( src->instance, dstAsEnumAttrType->instance, srcIsLvalue, symtab, env );386 } else {387 auto baseType = src->instance->base->base;388 cost = costCalc( baseType, dst, srcIsLvalue, symtab, env );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 ); 389 388 if ( cost < Cost::infinity ) { 390 389 cost.incUnsafe(); 391 390 } 392 }393 } else { // ast::EnumAttribute::Posn394 if ( auto dstBase = dynamic_cast<const ast::EnumInstType *>( dst ) ) {395 cost = costCalc( src->instance, dstBase, srcIsLvalue, symtab, env );396 if ( cost < Cost::unsafe ) cost.incSafe();397 } else {398 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) };399 cost = costCalc( integer, dst, srcIsLvalue, symtab, env );400 if ( cost < Cost::unsafe ) {401 cost.incSafe();402 }403 }404 }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 } 405 404 } 406 405 … … 461 460 } else if ( const ast::BasicType * dstAsBasic = 462 461 dynamic_cast< const ast::BasicType * >( dst ) ) { 463 int tableResult = costMatrix[ ast::Basic Kind::SignedInt ][ dstAsBasic->kind ];462 int tableResult = costMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ]; 464 463 if ( -1 == tableResult ) { 465 464 cost = Cost::unsafe; … … 467 466 cost = Cost::zero; 468 467 cost.incSafe( tableResult + 1 ); 469 cost.incSign( signMatrix[ ast::Basic Kind::SignedInt ][ dstAsBasic->kind ] );468 cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] ); 470 469 } 471 470 // this has the effect of letting any expr such as x+0, x+1 to be typed … … 493 492 } else if ( const ast::BasicType * dstAsBasic = 494 493 dynamic_cast< const ast::BasicType * >( dst ) ) { 495 int tableResult = costMatrix[ ast::Basic Kind::SignedInt ][ dstAsBasic->kind ];494 int tableResult = costMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ]; 496 495 if ( -1 == tableResult ) { 497 496 cost = Cost::unsafe; … … 499 498 cost = Cost::zero; 500 499 cost.incSafe( tableResult + 1 ); 501 cost.incSign( signMatrix[ ast::Basic Kind::SignedInt ][ dstAsBasic->kind ] );500 cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] ); 502 501 } 503 502 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
Note:
See TracChangeset
for help on using the changeset viewer.