- Timestamp:
- Apr 11, 2024, 3:43:48 PM (8 months ago)
- Branches:
- master
- Children:
- b78c54f
- Parents:
- c4024b46
- Location:
- src
- Files:
-
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/StatementNode.cc
rc4024b46 rab780e6 122 122 ast::Expr * cond = nullptr; 123 123 if ( ctl->condition ) { 124 // compare the provided condition against 0 125 cond = notZeroExpr( maybeMoveBuild( ctl->condition ) ); 124 cond = maybeMoveBuild( ctl->condition ); 126 125 } else { 127 126 for ( ast::ptr<ast::Stmt> & stmt : inits ) { … … 129 128 auto declStmt = stmt.strict_as<ast::DeclStmt>(); 130 129 auto dwt = declStmt->decl.strict_as<ast::DeclWithType>(); 131 ast::Expr * nze = n otZeroExpr( new ast::VariableExpr( dwt->location, dwt ));130 ast::Expr * nze = new ast::VariableExpr( dwt->location, dwt ); 132 131 cond = cond ? new ast::LogicalExpr( dwt->location, cond, nze, ast::AndExpr ) : nze; 133 132 } … … 200 199 // do-while cannot have declarations in the contitional, so init is always empty 201 200 return new ast::WhileDoStmt( location, 202 notZeroExpr( maybeMoveBuild( ctl )),201 maybeMoveBuild( ctl ), 203 202 buildMoveSingle( stmt ), 204 203 buildMoveOptional( else_ ), … … 213 212 214 213 ast::Expr * astcond = nullptr; // maybe empty 215 astcond = notZeroExpr( maybeMoveBuild( forctl->condition ));214 astcond = maybeMoveBuild( forctl->condition ); 216 215 217 216 ast::Expr * astincr = nullptr; // maybe empty … … 330 329 clause->target = maybeBuild( targetExpr ); 331 330 clause->stmt = maybeMoveBuild( stmt ); 332 clause->when_cond = notZeroExpr( maybeMoveBuild( when ));331 clause->when_cond = maybeMoveBuild( when ); 333 332 334 333 ExpressionNode * next = targetExpr->next; … … 345 344 ast::WaitForStmt * build_waitfor_else( const CodeLocation & location, ast::WaitForStmt * existing, ExpressionNode * when, StatementNode * stmt ) { 346 345 existing->else_stmt = maybeMoveBuild( stmt ); 347 existing->else_cond = notZeroExpr( maybeMoveBuild( when ));346 existing->else_cond = maybeMoveBuild( when ); 348 347 349 348 (void)location; … … 354 353 existing->timeout_time = maybeMoveBuild( timeout ); 355 354 existing->timeout_stmt = maybeMoveBuild( stmt ); 356 existing->timeout_cond = notZeroExpr( maybeMoveBuild( when ));355 existing->timeout_cond = maybeMoveBuild( when ); 357 356 358 357 (void)location; … … 362 361 ast::WaitUntilStmt::ClauseNode * build_waituntil_clause( const CodeLocation & loc, ExpressionNode * when, ExpressionNode * targetExpr, StatementNode * stmt ) { 363 362 ast::WhenClause * clause = new ast::WhenClause( loc ); 364 clause->when_cond = notZeroExpr( maybeMoveBuild( when ));363 clause->when_cond = maybeMoveBuild( when ); 365 364 clause->stmt = maybeMoveBuild( stmt ); 366 365 clause->target = maybeMoveBuild( targetExpr ); … … 369 368 ast::WaitUntilStmt::ClauseNode * build_waituntil_else( const CodeLocation & loc, ExpressionNode * when, StatementNode * stmt ) { 370 369 ast::WhenClause * clause = new ast::WhenClause( loc ); 371 clause->when_cond = notZeroExpr( maybeMoveBuild( when ));370 clause->when_cond = maybeMoveBuild( when ); 372 371 clause->stmt = maybeMoveBuild( stmt ); 373 372 return new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::ELSE, clause ); … … 508 507 509 508 ast::Expr * astcond = nullptr; // maybe empty 510 astcond = notZeroExpr( maybeMoveBuild( forctl->condition ));509 astcond = maybeMoveBuild( forctl->condition ); 511 510 512 511 ast::Expr * astincr = nullptr; // maybe empty -
src/Parser/module.mk
rc4024b46 rab780e6 31 31 Parser/parser.yy \ 32 32 Parser/ParserTypes.h \ 33 Parser/parserutility.cc \34 33 Parser/parserutility.h \ 35 34 Parser/RunParser.cpp \ -
src/Parser/parserutility.h
rc4024b46 rab780e6 17 17 18 18 #include "AST/Copy.hpp" // for shallowCopy 19 namespace ast {20 class Expr;21 }22 23 ast::Expr * notZeroExpr( const ast::Expr *orig );24 19 25 20 template< typename T > -
src/ResolvExpr/CandidateFinder.cpp
rc4024b46 rab780e6 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 … … 1587 1586 void Finder::postvisit( const ast::LogicalExpr * logicalExpr ) { 1588 1587 CandidateFinder finder1( context, tenv ); 1589 ast::ptr<ast::Expr> arg1 = notZeroExpr( logicalExpr->arg1 );1588 ast::ptr<ast::Expr> arg1 = createCondExpr( logicalExpr->arg1 ); 1590 1589 finder1.find( arg1, ResolveMode::withAdjustment() ); 1591 1590 if ( finder1.candidates.empty() ) return; 1592 1591 1593 1592 CandidateFinder finder2( context, tenv ); 1594 ast::ptr<ast::Expr> arg2 = notZeroExpr( logicalExpr->arg2 );1593 ast::ptr<ast::Expr> arg2 = createCondExpr( logicalExpr->arg2 ); 1595 1594 finder2.find( arg2, ResolveMode::withAdjustment() ); 1596 1595 if ( finder2.candidates.empty() ) return; … … 1618 1617 void Finder::postvisit( const ast::ConditionalExpr * conditionalExpr ) { 1619 1618 // candidates for condition 1620 ast::ptr<ast::Expr> arg1 = notZeroExpr( conditionalExpr->arg1 );1619 ast::ptr<ast::Expr> arg1 = createCondExpr( conditionalExpr->arg1 ); 1621 1620 CandidateFinder finder1( context, tenv ); 1622 1621 finder1.find( arg1, ResolveMode::withAdjustment() ); … … 2201 2200 } 2202 2201 2202 const ast::Expr * createCondExpr( const ast::Expr * expr ) { 2203 assert( expr ); 2204 return new ast::CastExpr( expr->location, 2205 ast::UntypedExpr::createCall( expr->location, 2206 "?!=?", 2207 { 2208 expr, 2209 new ast::ConstantExpr( expr->location, 2210 new ast::ZeroType(), "0", std::make_optional( 0ull ) 2211 ), 2212 } 2213 ), 2214 new ast::BasicType( ast::BasicType::SignedInt ) 2215 ); 2216 } 2217 2203 2218 } // namespace ResolvExpr 2204 2219 -
src/ResolvExpr/CandidateFinder.hpp
rc4024b46 rab780e6 70 70 const ast::Expr * expr, Cost & cost ); 71 71 72 /// Wrap an expression to convert the result to a conditional result. 73 const ast::Expr * createCondExpr( const ast::Expr * expr ); 74 72 75 } // namespace ResolvExpr 73 76 -
src/ResolvExpr/Resolver.cc
rc4024b46 rab780e6 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.