Changeset 02c80cdc for src/ResolvExpr
- Timestamp:
- Apr 19, 2024, 11:30:55 AM (23 months ago)
- Branches:
- master, stuck-waitfor-destruct
- Children:
- 358e1152, 4e08a54
- Parents:
- d4264e8 (diff), 19313be5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src/ResolvExpr
- Files:
-
- 6 edited
-
CandidateFinder.cpp (modified) (5 diffs)
-
CommonType.cc (modified) (8 diffs)
-
ConversionCost.cc (modified) (12 diffs)
-
PtrsCastable.cc (modified) (1 diff)
-
ResolveTypeof.cc (modified) (2 diffs)
-
Resolver.cc (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CandidateFinder.cpp
rd4264e8 r02c80cdc 513 513 // add new result 514 514 assert( common ); 515 // auto attrType = common.as<ast::EnumAttrType>();516 // if ( attrType && ( attrType->attr == ast::EnumAttribute::Value ) ) {517 // auto callExpr = new ast::UntypedExpr(518 // expr->location, new ast::NameExpr( expr->location, "valueE"), {expr} );519 // CandidateFinder finder( context, env );520 // finder.find( callExpr );521 // CandidateList winners = findMinCost( finder.candidates );522 // if (winners.size() != 1) {523 // SemanticError( callExpr, "Ambiguous expression in valueE" );524 // }525 // CandidateRef & choice = winners.front();526 // choice->expr = referenceToRvalueConversion( choice->expr, choice->cost );527 528 // results.emplace_back(529 // i, choice->expr,530 // std::move( env ), std::move( need ), std::move( have ), std::move( open ),531 // nextArg + 1, nTuples, expl.cost, expl.exprs.size() == 1 ? 0 : 1, j );532 // } else {533 515 results.emplace_back( 534 516 i, expr, std::move( env ), std::move( need ), std::move( have ), std::move( open ), … … 921 903 CandidateList winners = findMinCost( finder.candidates ); 922 904 if (winners.size() != 1) { 923 SemanticError( callExpr, "Ambiguous expression in valueE " );905 SemanticError( callExpr, "Ambiguous expression in valueE..." ); 924 906 } 925 907 CandidateRef & choice = winners.front(); 926 // choice->cost.incSafe();908 choice->cost.incVar(); 927 909 candidates.emplace_back( std::move(choice) ); 928 910 } … … 1800 1782 CandidateList winners = findMinCost( finder.candidates ); 1801 1783 if (winners.size() != 1) { 1802 SemanticError( callExpr, "Ambiguous expression in valueE " );1784 SemanticError( callExpr, "Ambiguous expression in valueE..." ); 1803 1785 } 1804 1786 CandidateRef & choice = winners.front(); … … 2150 2132 } 2151 2133 2152 const ast::Expr * getValueEnumCall( const ast::Expr * expr, 2153 const ResolveContext & context, const ast::TypeEnvironment & env ) { 2154 auto callExpr = new ast::UntypedExpr( 2155 expr->location, new ast::NameExpr( expr->location, "valueE"), {expr} ); 2156 CandidateFinder finder( context, env ); 2157 finder.find( callExpr ); 2158 CandidateList winners = findMinCost( finder.candidates ); 2159 if (winners.size() != 1) { 2160 SemanticError( callExpr, "Ambiguous expression in valueE" ); 2161 } 2162 CandidateRef & choice = winners.front(); 2163 return choice->expr; 2134 // get the valueE(...) ApplicationExpr that returns the enum value 2135 const ast::Expr * getValueEnumCall( 2136 const ast::Expr * expr, 2137 const ResolvExpr::ResolveContext & context, const ast::TypeEnvironment & env ) { 2138 auto callExpr = new ast::UntypedExpr( 2139 expr->location, new ast::NameExpr( expr->location, "valueE"), {expr} ); 2140 CandidateFinder finder( context, env ); 2141 finder.find( callExpr ); 2142 CandidateList winners = findMinCost( finder.candidates ); 2143 if (winners.size() != 1) { 2144 SemanticError( callExpr, "Ambiguous expression in valueE..." ); 2145 } 2146 CandidateRef & choice = winners.front(); 2147 return choice->expr; 2164 2148 } 2165 2149 … … 2176 2160 } 2177 2161 ), 2178 new ast::BasicType( ast::Basic Type::SignedInt )2162 new ast::BasicType( ast::BasicKind::SignedInt ) 2179 2163 ); 2180 2164 } -
src/ResolvExpr/CommonType.cc
rd4264e8 r02c80cdc 38 38 // GENERATED START, DO NOT EDIT 39 39 // GENERATED BY BasicTypes-gen.cc 40 #define BT ast::Basic Type::41 static const BTKind commonTypes[BT NUMBER_OF_BASIC_TYPES][BT NUMBER_OF_BASIC_TYPES] = { // nearest common ancestor40 #define BT ast::BasicKind:: 41 static const ast::BasicKind commonTypes[BT NUMBER_OF_BASIC_TYPES][BT NUMBER_OF_BASIC_TYPES] = { // nearest common ancestor 42 42 /* B C SC UC SI SUI 43 43 I UI LI LUI LLI LLUI … … 339 339 // GENERATED END 340 340 static_assert( 341 sizeof(commonTypes)/sizeof(commonTypes[0][0]) == ast::Basic Type::NUMBER_OF_BASIC_TYPES * ast::BasicType::NUMBER_OF_BASIC_TYPES,341 sizeof(commonTypes)/sizeof(commonTypes[0][0]) == ast::BasicKind::NUMBER_OF_BASIC_TYPES * ast::BasicKind::NUMBER_OF_BASIC_TYPES, 342 342 "Each basic type kind should have a corresponding row in the combined type matrix" 343 343 ); … … 366 366 void postvisit( const ast::BasicType * basic ) { 367 367 if ( auto basic2 = dynamic_cast< const ast::BasicType * >( type2 ) ) { 368 ast::Basic Type::Kind kind;368 ast::BasicKind kind; 369 369 if (basic->kind != basic2->kind && !widen.first && !widen.second) return; 370 370 else if (!widen.first) kind = basic->kind; // widen.second … … 386 386 const ast::EnumDecl* enumDecl = enumInst->base; 387 387 if ( !enumDecl->base ) { 388 ast::Basic Type::Kind kind = commonTypes[ basic->kind ][ ast::BasicType::SignedInt ];388 ast::BasicKind kind = commonTypes[ basic->kind ][ ast::BasicKind::SignedInt ]; 389 389 if ( 390 390 ( ( kind == basic->kind && basic->qualifiers >= type2->qualifiers ) … … 398 398 } else if ( auto type2AsAttr = dynamic_cast< const ast::EnumAttrType * >( type2 ) ) { 399 399 if ( type2AsAttr->attr == ast::EnumAttribute::Posn ) { 400 ast::Basic Type::Kind kind = commonTypes[ basic->kind ][ ast::BasicType::SignedInt ];400 ast::BasicKind kind = commonTypes[ basic->kind ][ ast::BasicKind::SignedInt ]; 401 401 if ( 402 402 ( ( kind == basic->kind && basic->qualifiers >= type2->qualifiers ) … … 649 649 void postvisit( const ast::EnumInstType * enumInst ) { 650 650 if ( enumInst->base && !enumInst->base->base ) { 651 auto basicType = new ast::BasicType( ast::Basic Type::UnsignedInt );651 auto basicType = new ast::BasicType( ast::BasicKind::UnsignedInt ); 652 652 result = commonType( basicType, type2, tenv, need, have, open, widen); 653 653 } … … 674 674 } else if ( widen.second && dynamic_cast< const ast::OneType * >( type2 ) ) { 675 675 result = new ast::BasicType{ 676 ast::Basic Type::SignedInt, zero->qualifiers | type2->qualifiers };676 ast::BasicKind::SignedInt, zero->qualifiers | type2->qualifiers }; 677 677 } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( type2 ) ) { 678 678 const ast::EnumDecl * enumDecl = enumInst->base; … … 695 695 } else if ( widen.second && dynamic_cast< const ast::ZeroType * >( type2 ) ) { 696 696 result = new ast::BasicType{ 697 ast::Basic Type::SignedInt, one->qualifiers | type2->qualifiers };697 ast::BasicKind::SignedInt, one->qualifiers | type2->qualifiers }; 698 698 } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( type2 ) ) { 699 699 const ast::EnumDecl * enumDecl = enumInst->base; -
src/ResolvExpr/ConversionCost.cc
rd4264e8 r02c80cdc 59 59 // GENERATED START, DO NOT EDIT 60 60 // GENERATED BY BasicTypes-gen.cc 61 static const int costMatrix[ast::Basic Type::NUMBER_OF_BASIC_TYPES][ast::BasicType::NUMBER_OF_BASIC_TYPES] = { // path length from root to node61 static const int costMatrix[ast::BasicKind::NUMBER_OF_BASIC_TYPES][ast::BasicKind::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 Type::NUMBER_OF_BASIC_TYPES * ast::BasicType::NUMBER_OF_BASIC_TYPES,103 sizeof(costMatrix)/sizeof(costMatrix[0][0]) == ast::BasicKind::NUMBER_OF_BASIC_TYPES * ast::BasicKind::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 Type::NUMBER_OF_BASIC_TYPES][ast::BasicType::NUMBER_OF_BASIC_TYPES] = { // number of sign changes in safe conversion109 static const int signMatrix[ast::BasicKind::NUMBER_OF_BASIC_TYPES][ast::BasicKind::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 Type::NUMBER_OF_BASIC_TYPES * ast::BasicType::NUMBER_OF_BASIC_TYPES,150 sizeof(signMatrix)/sizeof(signMatrix[0][0]) == ast::BasicKind::NUMBER_OF_BASIC_TYPES * ast::BasicKind::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 Type::SignedInt ) };281 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) }; 282 282 cost = costCalc( basicType, integer, srcIsLvalue, symtab, env ); 283 283 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { … … 362 362 363 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(); 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; 382 369 } 383 370 } 384 371 return; 385 } 386 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::Basic Type::SignedInt ) };372 } 373 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) }; 387 374 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); 388 375 if ( cost < Cost::unsafe ) { … … 393 380 void ConversionCost::postvisit( const ast::EnumAttrType * src ) { 394 381 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 ) { 382 assert( src->attr != ast::EnumAttribute::Label ); 383 if ( src->attr == ast::EnumAttribute::Value ) { 401 384 if ( dstAsEnumAttrType && dstAsEnumAttrType->attr == ast::EnumAttribute::Value) { 402 385 cost = costCalc( src->instance, dstAsEnumAttrType->instance, srcIsLvalue, symtab, env ); … … 413 396 if ( cost < Cost::unsafe ) cost.incSafe(); 414 397 } else { 415 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::Basic Type::SignedInt ) };398 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) }; 416 399 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); 417 400 if ( cost < Cost::unsafe ) { … … 478 461 } else if ( const ast::BasicType * dstAsBasic = 479 462 dynamic_cast< const ast::BasicType * >( dst ) ) { 480 int tableResult = costMatrix[ ast::Basic Type::SignedInt ][ dstAsBasic->kind ];463 int tableResult = costMatrix[ ast::BasicKind::SignedInt ][ dstAsBasic->kind ]; 481 464 if ( -1 == tableResult ) { 482 465 cost = Cost::unsafe; … … 484 467 cost = Cost::zero; 485 468 cost.incSafe( tableResult + 1 ); 486 cost.incSign( signMatrix[ ast::Basic Type::SignedInt ][ dstAsBasic->kind ] );469 cost.incSign( signMatrix[ ast::BasicKind::SignedInt ][ dstAsBasic->kind ] ); 487 470 } 488 471 // this has the effect of letting any expr such as x+0, x+1 to be typed … … 510 493 } else if ( const ast::BasicType * dstAsBasic = 511 494 dynamic_cast< const ast::BasicType * >( dst ) ) { 512 int tableResult = costMatrix[ ast::Basic Type::SignedInt ][ dstAsBasic->kind ];495 int tableResult = costMatrix[ ast::BasicKind::SignedInt ][ dstAsBasic->kind ]; 513 496 if ( -1 == tableResult ) { 514 497 cost = Cost::unsafe; … … 516 499 cost = Cost::zero; 517 500 cost.incSafe( tableResult + 1 ); 518 cost.incSign( signMatrix[ ast::Basic Type::SignedInt ][ dstAsBasic->kind ] );501 cost.incSign( signMatrix[ ast::BasicKind::SignedInt ][ dstAsBasic->kind ] ); 519 502 } 520 503 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { -
src/ResolvExpr/PtrsCastable.cc
rd4264e8 r02c80cdc 100 100 result = 1; 101 101 } else if ( auto bt = dynamic_cast< const ast::BasicType * >( dst ) ) { 102 if ( bt->kind == ast::Basic Type::SignedInt ) {102 if ( bt->kind == ast::BasicKind::SignedInt ) { 103 103 result = 0; 104 104 } else { -
src/ResolvExpr/ResolveTypeof.cc
rd4264e8 r02c80cdc 63 63 if ( newType.as< ast::EnumInstType >() ) { 64 64 newType = new ast::BasicType( 65 ast::Basic Type::SignedInt, newType->qualifiers, copy(newType->attributes) );65 ast::BasicKind::SignedInt, newType->qualifiers, copy(newType->attributes) ); 66 66 } 67 67 reset_qualifiers( … … 91 91 auto mutType = mutate(arrayType); 92 92 auto globalSizeType = context.global.sizeType; 93 ast::ptr<ast::Type> sizetype = globalSizeType ? globalSizeType : new ast::BasicType( ast::BasicType::LongUnsignedInt);93 ast::ptr<ast::Type> sizetype = globalSizeType ? globalSizeType : new ast::BasicType( ast::BasicKind::LongUnsignedInt ); 94 94 mutType->dimension = findSingleExpression(arrayType->dimension, sizetype, context ); 95 95 -
src/ResolvExpr/Resolver.cc
rd4264e8 r02c80cdc 351 351 bool isCharType( const ast::Type * t ) { 352 352 if ( auto bt = dynamic_cast< const ast::BasicType * >( t ) ) { 353 return bt->kind == ast::Basic Type::Char354 || bt->kind == ast::Basic Type::SignedChar355 || bt->kind == ast::Basic Type::UnsignedChar;353 return bt->kind == ast::BasicKind::Char 354 || bt->kind == ast::BasicKind::SignedChar 355 || bt->kind == ast::BasicKind::UnsignedChar; 356 356 } 357 357 return false; … … 458 458 if (attr->params.size() == 1) { 459 459 auto arg = attr->params.front(); 460 auto resolved = ResolvExpr::findSingleExpression( arg, new ast::BasicType( ast::Basic Type::LongLongSignedInt ), context );460 auto resolved = ResolvExpr::findSingleExpression( arg, new ast::BasicType( ast::BasicKind::LongLongSignedInt ), context ); 461 461 auto result = eval(arg); 462 462 … … 624 624 objectDecl = fixObjectType( objectDecl, context ); 625 625 currentObject = ast::CurrentObject{ 626 objectDecl->location, new ast::BasicType{ ast::Basic Type::SignedInt } };626 objectDecl->location, new ast::BasicType{ ast::BasicKind::SignedInt } }; 627 627 } 628 628 } else { … … 1095 1095 // resolve the timeout as a size_t, the conditions like IfStmt, and stmts normally 1096 1096 ast::ptr< ast::Type > target = 1097 new ast::BasicType{ ast::Basic Type::LongLongUnsignedInt };1097 new ast::BasicType{ ast::BasicKind::LongLongUnsignedInt }; 1098 1098 auto timeout_time = findSingleExpression( stmt->timeout_time, target, context ); 1099 1099 auto timeout_cond = findCondExpression( stmt->timeout_cond, context );
Note:
See TracChangeset
for help on using the changeset viewer.