Changeset 59c8dff for src/ResolvExpr/CandidateFinder.cpp
- Timestamp:
- Jan 19, 2024, 2:42:58 AM (5 months ago)
- Branches:
- master
- Children:
- f988834
- Parents:
- 8b4faf6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CandidateFinder.cpp
r8b4faf6 r59c8dff 52 52 #include "Common/Stats/Counter.h" 53 53 54 #include "AST/Inspect.hpp" // for getFunctionName 55 54 56 #define PRINT( text ) if ( resolvep ) { text } 55 57 … … 656 658 void postvisit( const ast::OffsetofExpr * offsetofExpr ); 657 659 void postvisit( const ast::OffsetPackExpr * offsetPackExpr ); 660 void postvisit( const ast::EnumPosExpr * enumPosExpr ); 658 661 void postvisit( const ast::LogicalExpr * logicalExpr ); 659 662 void postvisit( const ast::ConditionalExpr * conditionalExpr ); … … 1471 1474 void Finder::postvisit( const ast::OffsetPackExpr * offsetPackExpr ) { 1472 1475 addCandidate( offsetPackExpr, tenv ); 1476 } 1477 1478 void Finder::postvisit( const ast::EnumPosExpr * enumPosExpr ) { 1479 CandidateFinder finder( context, tenv ); 1480 finder.find( enumPosExpr->expr ); 1481 CandidateList winners = findMinCost( finder.candidates ); 1482 if ( winners.size() != 1 ) SemanticError( enumPosExpr->expr.get(), "Ambiguous expression in position. "); 1483 CandidateRef & choice = winners.front(); 1484 auto refExpr = referenceToRvalueConversion( choice->expr, choice->cost ); 1485 auto refResult = (refExpr->result).as<ast::EnumInstType>(); 1486 if ( !refResult ) { 1487 SemanticError( refExpr, "Position for Non enum type is not supported" ); 1488 } 1489 // determineEnumPosConstant( enumPosExpr, refResult ); 1490 1491 const ast::NameExpr * const nameExpr = enumPosExpr->expr.strict_as<ast::NameExpr>(); 1492 const ast::EnumDecl * base = refResult->base; 1493 if ( !base ) { 1494 SemanticError( enumPosExpr, "Cannot be reference to a defined enumeration type" ); 1495 } 1496 auto it = std::find_if( std::begin( base->members ), std::end( base->members ), 1497 [nameExpr]( ast::ptr<ast::Decl> decl ) { return decl->name == nameExpr->name; } ); 1498 unsigned position = it - base->members.begin(); 1499 addCandidate( ast::ConstantExpr::from_int( enumPosExpr->location, position ), tenv ); 1473 1500 } 1474 1501
Note: See TracChangeset
for help on using the changeset viewer.