Changeset de8a0a4 for src/ResolvExpr/CandidateFinder.cpp
- Timestamp:
- Jan 26, 2025, 6:37:05 PM (3 months ago)
- Branches:
- master
- Children:
- a950021
- Parents:
- 0f070a4 (diff), 11f92fac (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/ResolvExpr/CandidateFinder.cpp ¶
r0f070a4 rde8a0a4 672 672 void postvisit( const ast::SizeofExpr * sizeofExpr ); 673 673 void postvisit( const ast::AlignofExpr * alignofExpr ); 674 void postvisit( const ast::CountofExpr * countExpr ); 674 675 void postvisit( const ast::AddressExpr * addressExpr ); 675 676 void postvisit( const ast::LabelAddressExpr * labelExpr ); … … 697 698 void postvisit( const ast::UntypedInitExpr * initExpr ); 698 699 void postvisit( const ast::QualifiedNameExpr * qualifiedExpr ); 699 void postvisit( const ast::CountExpr * countExpr );700 700 701 701 void postvisit( const ast::InitExpr * ) { … … 941 941 } 942 942 } 943 944 943 945 944 /// Adds aggregate member interpretations … … 1269 1268 ? conversionCost( fromType, toType, cand->expr->get_lvalue(), symtab, cand->env ) 1270 1269 : castCost( fromType, toType, cand->expr->get_lvalue(), symtab, cand->env ); 1271 1270 1272 1271 // Redefine enum cast 1273 1272 auto argAsEnum = fromType.as<ast::EnumInstType>(); … … 1493 1492 } 1494 1493 1495 void Finder::postvisit( const ast::CountExpr * countExpr ) { 1496 const ast::UntypedExpr * untyped = nullptr; 1497 if ( countExpr->type ) { 1498 auto enumInst = countExpr->type.as<ast::EnumInstType>(); 1499 if ( enumInst ) { 1500 addCandidate( ast::ConstantExpr::from_ulong(countExpr->location, enumInst->base->members.size()), tenv ); 1501 return; 1502 } 1503 auto untypedFirst = ast::UntypedExpr::createCall( countExpr->location, "lowerBound", {} ); 1504 auto castFirst = new ast::CastExpr( countExpr->location, untypedFirst , countExpr->type ); 1505 untyped = ast::UntypedExpr::createCall( 1506 countExpr->location, "Countof", { castFirst } 1507 ); 1508 } 1509 if (!untyped) untyped = ast::UntypedExpr::createCall( 1510 countExpr->location, "Countof", { countExpr->expr } 1494 void Finder::postvisit( const ast::CountofExpr * countExpr ) { 1495 if ( auto enumInst = countExpr->type.as<ast::EnumInstType>() ) { 1496 addCandidate( ast::ConstantExpr::from_ulong( countExpr->location, enumInst->base->members.size()), tenv ); 1497 return; 1498 } 1499 auto untypedFirst = ast::UntypedExpr::createCall( countExpr->location, "lowerBound", {} ); 1500 auto castFirst = new ast::CastExpr( countExpr->location, untypedFirst , countExpr->type ); 1501 const ast::UntypedExpr * untyped = ast::UntypedExpr::createCall( 1502 countExpr->location, "Countof", { castFirst } 1511 1503 ); 1512 1504 CandidateFinder finder( context, tenv ); … … 1514 1506 CandidateList winners = findMinCost( finder.candidates ); 1515 1507 if ( winners.size() == 0 ) { 1516 SemanticError( countExpr ->expr, "Countof is not implemented for operand: " );1517 } 1518 if ( winners.size() != 1519 SemanticError( countExpr ->expr, "Ambiguous expression in countof operand: " );1508 SemanticError( countExpr, "Countof is not implemented: " ); 1509 } 1510 if ( winners.size() != 1 ) { 1511 SemanticError( countExpr, "Ambiguous expression in countof: " ); 1520 1512 } 1521 1513 CandidateRef & choice = winners.front();
Note: See TracChangeset
for help on using the changeset viewer.