Changeset 9ddcee1 for src/ResolvExpr/CandidateFinder.cpp
- Timestamp:
- Feb 1, 2024, 5:13:04 PM (6 months ago)
- Branches:
- master
- Children:
- 020fa10
- Parents:
- 496ffc17
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CandidateFinder.cpp
r496ffc17 r9ddcee1 659 659 void postvisit( const ast::OffsetofExpr * offsetofExpr ); 660 660 void postvisit( const ast::OffsetPackExpr * offsetPackExpr ); 661 void postvisit( const ast::EnumPosExpr * enumPosExpr );662 661 void postvisit( const ast::LogicalExpr * logicalExpr ); 663 662 void postvisit( const ast::ConditionalExpr * conditionalExpr ); … … 1507 1506 void Finder::postvisit( const ast::OffsetPackExpr * offsetPackExpr ) { 1508 1507 addCandidate( offsetPackExpr, tenv ); 1509 }1510 1511 void Finder::postvisit( const ast::EnumPosExpr * enumPosExpr ) {1512 CandidateFinder finder( context, tenv );1513 finder.find( enumPosExpr->expr );1514 CandidateList winners = findMinCost( finder.candidates );1515 if ( winners.size() != 1 ) SemanticError( enumPosExpr->expr.get(), "Ambiguous expression in position. ");1516 CandidateRef & choice = winners.front();1517 auto refExpr = referenceToRvalueConversion( choice->expr, choice->cost );1518 auto refResult = (refExpr->result).as<ast::EnumInstType>();1519 if ( !refResult ) {1520 SemanticError( refExpr, "Position for Non enum type is not supported" );1521 }1522 // determineEnumPosConstant( enumPosExpr, refResult );1523 1524 const ast::NameExpr * const nameExpr = enumPosExpr->expr.strict_as<ast::NameExpr>();1525 const ast::EnumDecl * base = refResult->base;1526 if ( !base ) {1527 SemanticError( enumPosExpr, "Cannot be reference to a defined enumeration type" );1528 }1529 auto it = std::find_if( std::begin( base->members ), std::end( base->members ),1530 [nameExpr]( ast::ptr<ast::Decl> decl ) { return decl->name == nameExpr->name; } );1531 unsigned position = it - base->members.begin();1532 addCandidate( ast::ConstantExpr::from_int( enumPosExpr->location, position ), tenv );1533 1508 } 1534 1509
Note: See TracChangeset
for help on using the changeset viewer.