- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CandidateFinder.cpp
r59c8dff r4a89b52 52 52 #include "Common/Stats/Counter.h" 53 53 54 #include "AST/Inspect.hpp" // for getFunctionName55 56 54 #define PRINT( text ) if ( resolvep ) { text } 57 55 … … 658 656 void postvisit( const ast::OffsetofExpr * offsetofExpr ); 659 657 void postvisit( const ast::OffsetPackExpr * offsetPackExpr ); 660 void postvisit( const ast::EnumPosExpr * enumPosExpr );661 658 void postvisit( const ast::LogicalExpr * logicalExpr ); 662 659 void postvisit( const ast::ConditionalExpr * conditionalExpr ); … … 1474 1471 void Finder::postvisit( const ast::OffsetPackExpr * offsetPackExpr ) { 1475 1472 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 );1500 1473 } 1501 1474
Note:
See TracChangeset
for help on using the changeset viewer.