- File:
-
- 1 edited
-
src/ResolvExpr/CandidateFinder.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CandidateFinder.cpp
r857b5f9 r6b95feb 672 672 void postvisit( const ast::SizeofExpr * sizeofExpr ); 673 673 void postvisit( const ast::AlignofExpr * alignofExpr ); 674 void postvisit( const ast::CountofExpr * countExpr );675 674 void postvisit( const ast::AddressExpr * addressExpr ); 676 675 void postvisit( const ast::LabelAddressExpr * labelExpr ); … … 698 697 void postvisit( const ast::UntypedInitExpr * initExpr ); 699 698 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 943 944 944 945 /// Adds aggregate member interpretations … … 1268 1269 ? conversionCost( fromType, toType, cand->expr->get_lvalue(), symtab, cand->env ) 1269 1270 : castCost( fromType, toType, cand->expr->get_lvalue(), symtab, cand->env ); 1270 1271 1271 1272 // Redefine enum cast 1272 1273 auto argAsEnum = fromType.as<ast::EnumInstType>(); … … 1492 1493 } 1493 1494 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 } 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 } 1503 1511 ); 1504 1512 CandidateFinder finder( context, tenv ); … … 1506 1514 CandidateList winners = findMinCost( finder.candidates ); 1507 1515 if ( winners.size() == 0 ) { 1508 SemanticError( countExpr , "Countof is not implemented: " );1509 } 1510 if ( winners.size() != 1 ) {1511 SemanticError( countExpr , "Ambiguous expression in countof: " );1516 SemanticError( countExpr->expr, "Countof is not implemented for operand: " ); 1517 } 1518 if ( winners.size() != 1 ) { 1519 SemanticError( countExpr->expr, "Ambiguous expression in countof operand: " ); 1512 1520 } 1513 1521 CandidateRef & choice = winners.front();
Note:
See TracChangeset
for help on using the changeset viewer.