Changeset dc58e5d for src/ResolvExpr
- Timestamp:
- Apr 15, 2024, 12:24:36 PM (12 months ago)
- Branches:
- master
- Children:
- fb2e916
- Parents:
- af746cc (diff), 7a36848 (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. - Location:
- src/ResolvExpr
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/ResolvExpr/CandidateFinder.cpp ¶
raf746cc rdc58e5d 46 46 #include "AST/Type.hpp" 47 47 #include "Common/utility.h" // for move, copy 48 #include "Parser/parserutility.h" // for notZeroExpr49 48 #include "SymTab/Mangler.h" 50 49 #include "Tuples/Tuples.h" // for handleTupleAssignment … … 1514 1513 void Finder::postvisit( const ast::LogicalExpr * logicalExpr ) { 1515 1514 CandidateFinder finder1( context, tenv ); 1516 ast::ptr<ast::Expr> arg1 = notZeroExpr( logicalExpr->arg1 );1515 ast::ptr<ast::Expr> arg1 = createCondExpr( logicalExpr->arg1 ); 1517 1516 finder1.find( arg1, ResolveMode::withAdjustment() ); 1518 1517 if ( finder1.candidates.empty() ) return; 1519 1518 1520 1519 CandidateFinder finder2( context, tenv ); 1521 ast::ptr<ast::Expr> arg2 = notZeroExpr( logicalExpr->arg2 );1520 ast::ptr<ast::Expr> arg2 = createCondExpr( logicalExpr->arg2 ); 1522 1521 finder2.find( arg2, ResolveMode::withAdjustment() ); 1523 1522 if ( finder2.candidates.empty() ) return; … … 1545 1544 void Finder::postvisit( const ast::ConditionalExpr * conditionalExpr ) { 1546 1545 // candidates for condition 1547 ast::ptr<ast::Expr> arg1 = notZeroExpr( conditionalExpr->arg1 );1546 ast::ptr<ast::Expr> arg1 = createCondExpr( conditionalExpr->arg1 ); 1548 1547 CandidateFinder finder1( context, tenv ); 1549 1548 finder1.find( arg1, ResolveMode::withAdjustment() ); … … 2166 2165 CandidateRef & choice = winners.front(); 2167 2166 return choice->expr; 2168 // return std::move( choice->expr.get() ); 2167 } 2168 2169 const ast::Expr * createCondExpr( const ast::Expr * expr ) { 2170 assert( expr ); 2171 return new ast::CastExpr( expr->location, 2172 ast::UntypedExpr::createCall( expr->location, 2173 "?!=?", 2174 { 2175 expr, 2176 new ast::ConstantExpr( expr->location, 2177 new ast::ZeroType(), "0", std::make_optional( 0ull ) 2178 ), 2179 } 2180 ), 2181 new ast::BasicType( ast::BasicType::SignedInt ) 2182 ); 2169 2183 } 2170 2184 -
TabularUnified src/ResolvExpr/CandidateFinder.hpp ¶
raf746cc rdc58e5d 72 72 const ast::Expr * getValueEnumCall(const ast::Expr * expr, 73 73 const ResolvExpr::ResolveContext & context, const ast::TypeEnvironment & env ); 74 /// Wrap an expression to convert the result to a conditional result. 75 const ast::Expr * createCondExpr( const ast::Expr * expr ); 74 76 75 77 } // namespace ResolvExpr -
TabularUnified src/ResolvExpr/Resolver.cc ¶
raf746cc rdc58e5d 340 340 } 341 341 342 ast::ptr< ast::Expr > findCondExpression( 343 const ast::Expr * untyped, const ResolveContext & context 344 ) { 345 if ( nullptr == untyped ) return untyped; 346 ast::ptr<ast::Expr> condExpr = createCondExpr( untyped ); 347 return findIntegralExpression( condExpr, context ); 348 } 349 342 350 /// check if a type is a character type 343 351 bool isCharType( const ast::Type * t ) { … … 356 364 return it != end; 357 365 } 358 } 366 } // anonymous namespace 359 367 360 368 class Resolver final … … 729 737 const ast::IfStmt * Resolver::previsit( const ast::IfStmt * ifStmt ) { 730 738 return ast::mutate_field( 731 ifStmt, &ast::IfStmt::cond, find IntegralExpression( ifStmt->cond, context ) );739 ifStmt, &ast::IfStmt::cond, findCondExpression( ifStmt->cond, context ) ); 732 740 } 733 741 734 742 const ast::WhileDoStmt * Resolver::previsit( const ast::WhileDoStmt * whileDoStmt ) { 735 743 return ast::mutate_field( 736 whileDoStmt, &ast::WhileDoStmt::cond, find IntegralExpression( whileDoStmt->cond, context ) );744 whileDoStmt, &ast::WhileDoStmt::cond, findCondExpression( whileDoStmt->cond, context ) ); 737 745 } 738 746 … … 740 748 if ( forStmt->cond ) { 741 749 forStmt = ast::mutate_field( 742 forStmt, &ast::ForStmt::cond, find IntegralExpression( forStmt->cond, context ) );750 forStmt, &ast::ForStmt::cond, findCondExpression( forStmt->cond, context ) ); 743 751 } 744 752 … … 1075 1083 1076 1084 // Resolve the conditions as if it were an IfStmt, statements normally 1077 clause2->when_cond = find SingleExpression( clause.when_cond, context );1085 clause2->when_cond = findCondExpression( clause.when_cond, context ); 1078 1086 clause2->stmt = clause.stmt->accept( *visitor ); 1079 1087 … … 1089 1097 new ast::BasicType{ ast::BasicType::LongLongUnsignedInt }; 1090 1098 auto timeout_time = findSingleExpression( stmt->timeout_time, target, context ); 1091 auto timeout_cond = find SingleExpression( stmt->timeout_cond, context );1099 auto timeout_cond = findCondExpression( stmt->timeout_cond, context ); 1092 1100 auto timeout_stmt = stmt->timeout_stmt->accept( *visitor ); 1093 1101 … … 1102 1110 if ( stmt->else_stmt ) { 1103 1111 // resolve the condition like IfStmt, stmts normally 1104 auto else_cond = find SingleExpression( stmt->else_cond, context );1112 auto else_cond = findCondExpression( stmt->else_cond, context ); 1105 1113 auto else_stmt = stmt->else_stmt->accept( *visitor ); 1106 1114
Note: See TracChangeset
for help on using the changeset viewer.