Changeset 738a9b4 for src/Parser/StatementNode.cpp
- Timestamp:
- Sep 23, 2024, 11:08:40 PM (6 weeks ago)
- Branches:
- master
- Children:
- 569b118
- Parents:
- fca78f1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/StatementNode.cpp
rfca78f1 r738a9b4 11 11 // Created On : Sat May 16 14:59:41 2015 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Mon Sep 9 21:49:15 202414 // Update Count : 43 113 // Last Modified On : Mon Sep 23 22:50:35 2024 14 // Update Count : 432 15 15 // 16 16 … … 105 105 } // ClauseNode::append_last_case 106 106 107 ast::Stmt * build_expr( CodeLocation const & location, ExpressionNode * ct l ) {108 if ( ast::Expr * e = maybeMoveBuild( ct l ) ) {107 ast::Stmt * build_expr( CodeLocation const & location, ExpressionNode * ctrl ) { 108 if ( ast::Expr * e = maybeMoveBuild( ctrl ) ) { 109 109 return new ast::ExprStmt( location, e ); 110 110 } else { … … 113 113 } // build_expr 114 114 115 static ast::Expr * build_if_control( CondCt l * ctl,115 static ast::Expr * build_if_control( CondCtrl * ctrl, 116 116 std::vector<ast::ptr<ast::Stmt>> & inits ) { 117 117 assert( inits.empty() ); 118 if ( nullptr != ct l->init ) {119 buildMoveList( ct l->init, inits );118 if ( nullptr != ctrl->init ) { 119 buildMoveList( ctrl->init, inits ); 120 120 } // if 121 121 122 122 ast::Expr * cond = nullptr; 123 if ( ct l->condition ) {124 cond = maybeMoveBuild( ct l->condition );123 if ( ctrl->condition ) { 124 cond = maybeMoveBuild( ctrl->condition ); 125 125 } else { 126 126 for ( ast::ptr<ast::Stmt> & stmt : inits ) { … … 132 132 } 133 133 } 134 delete ct l;134 delete ctrl; 135 135 return cond; 136 136 } // build_if_control 137 137 138 ast::Stmt * build_if( const CodeLocation & location, CondCt l * ctl, StatementNode * then, StatementNode * else_ ) {139 std::vector<ast::ptr<ast::Stmt>> astinit; 140 ast::Expr * astcond = build_if_control( ct l, astinit ); // ctl deleted, cond/init set138 ast::Stmt * build_if( const CodeLocation & location, CondCtrl * ctrl, StatementNode * then, StatementNode * else_ ) { 139 std::vector<ast::ptr<ast::Stmt>> astinit; // maybe empty 140 ast::Expr * astcond = build_if_control( ctrl, astinit ); // ctrl deleted, cond/init set 141 141 142 142 ast::Stmt const * astthen = buildMoveSingle( then ); … … 148 148 } // build_if 149 149 150 ast::Stmt * build_switch( const CodeLocation & location, bool isSwitch, ExpressionNode * ct l, ClauseNode * stmt ) {150 ast::Stmt * build_switch( const CodeLocation & location, bool isSwitch, ExpressionNode * ctrl, ClauseNode * stmt ) { 151 151 std::vector<ast::ptr<ast::CaseClause>> aststmt; 152 152 buildMoveList( stmt, aststmt ); … … 169 169 // aststmt.size() == 0 for switch (...) {}, i.e., no declaration or statements 170 170 return new ast::SwitchStmt( location, 171 maybeMoveBuild( ct l ), std::move( aststmt ) );171 maybeMoveBuild( ctrl ), std::move( aststmt ) ); 172 172 } // build_switch 173 173 174 ast::CaseClause * build_case( const CodeLocation & location, ExpressionNode * ct l ) {174 ast::CaseClause * build_case( const CodeLocation & location, ExpressionNode * ctrl ) { 175 175 // stmt starts empty and then added to 176 auto expr = maybeMoveBuild( ct l );176 auto expr = maybeMoveBuild( ctrl ); 177 177 return new ast::CaseClause( location, expr, {} ); 178 178 } // build_case … … 183 183 } // build_default 184 184 185 ast::Stmt * build_while( const CodeLocation & location, CondCt l * ctl, StatementNode * stmt, StatementNode * else_ ) {185 ast::Stmt * build_while( const CodeLocation & location, CondCtrl * ctrl, StatementNode * stmt, StatementNode * else_ ) { 186 186 std::vector<ast::ptr<ast::Stmt>> astinit; // maybe empty 187 ast::Expr * astcond = build_if_control( ct l, astinit ); // ctl deleted, cond/init set187 ast::Expr * astcond = build_if_control( ctrl, astinit ); // ctrl deleted, cond/init set 188 188 189 189 return new ast::WhileDoStmt( location, … … 196 196 } // build_while 197 197 198 ast::Stmt * build_do_while( const CodeLocation & location, ExpressionNode * ct l, StatementNode * stmt, StatementNode * else_ ) {198 ast::Stmt * build_do_while( const CodeLocation & location, ExpressionNode * ctrl, StatementNode * stmt, StatementNode * else_ ) { 199 199 // do-while cannot have declarations in the contitional, so init is always empty 200 200 return new ast::WhileDoStmt( location, 201 maybeMoveBuild( ct l ),201 maybeMoveBuild( ctrl ), 202 202 buildMoveSingle( stmt ), 203 203 buildMoveOptional( else_ ), … … 207 207 } // build_do_while 208 208 209 ast::Stmt * build_for( const CodeLocation & location, ForCtrl * forct l, StatementNode * stmt, StatementNode * else_ ) {209 ast::Stmt * build_for( const CodeLocation & location, ForCtrl * forctrl, StatementNode * stmt, StatementNode * else_ ) { 210 210 std::vector<ast::ptr<ast::Stmt>> astinit; // maybe empty 211 buildMoveList( forct l->init, astinit );212 213 if ( forct l->range_over ) {214 ast::Expr * range_over = maybeMoveBuild( forct l->range_over );215 bool isIncreasing = forct l->kind == OperKinds::LEThan;211 buildMoveList( forctrl->init, astinit ); 212 213 if ( forctrl->range_over ) { 214 ast::Expr * range_over = maybeMoveBuild( forctrl->range_over ); 215 bool isIncreasing = forctrl->kind == OperKinds::LEThan; 216 216 // Copy all the data needed before the delete. 217 delete forct l;217 delete forctrl; 218 218 return new ast::ForeachStmt( location, 219 219 std::move( astinit ), … … 226 226 227 227 ast::Expr * astcond = nullptr; // maybe empty 228 astcond = maybeMoveBuild( forct l->condition );228 astcond = maybeMoveBuild( forctrl->condition ); 229 229 230 230 ast::Expr * astincr = nullptr; // maybe empty 231 astincr = maybeMoveBuild( forct l->change );232 delete forct l;231 astincr = maybeMoveBuild( forctrl->change ); 232 delete forctrl; 233 233 234 234 return new ast::ForStmt( location, … … 257 257 } // build_branch 258 258 259 ast::Stmt * build_computedgoto( ExpressionNode * ct l ) {260 ast::Expr * expr = maybeMoveBuild( ct l );259 ast::Stmt * build_computedgoto( ExpressionNode * ctrl ) { 260 ast::Expr * expr = maybeMoveBuild( ctrl ); 261 261 return new ast::BranchStmt( expr->location, expr ); 262 262 } // build_computedgoto 263 263 264 ast::Stmt * build_return( const CodeLocation & location, ExpressionNode * ct l ) {264 ast::Stmt * build_return( const CodeLocation & location, ExpressionNode * ctrl ) { 265 265 std::vector<ast::ptr<ast::Expr>> exps; 266 buildMoveList( ct l, exps );266 buildMoveList( ctrl, exps ); 267 267 return new ast::ReturnStmt( location, 268 268 exps.size() > 0 ? exps.back().release() : nullptr … … 272 272 static ast::Stmt * build_throw_stmt( 273 273 const CodeLocation & location, 274 ExpressionNode * ct l,274 ExpressionNode * ctrl, 275 275 ast::ExceptionKind kind ) { 276 276 std::vector<ast::ptr<ast::Expr>> exps; 277 buildMoveList( ct l, exps );277 buildMoveList( ctrl, exps ); 278 278 assertf( exps.size() < 2, "CFA internal error: leaking memory" ); 279 279 return new ast::ThrowStmt( location, … … 284 284 } 285 285 286 ast::Stmt * build_throw( const CodeLocation & loc, ExpressionNode * ct l ) {287 return build_throw_stmt( loc, ct l, ast::Terminate );286 ast::Stmt * build_throw( const CodeLocation & loc, ExpressionNode * ctrl ) { 287 return build_throw_stmt( loc, ctrl, ast::Terminate ); 288 288 } // build_throw 289 289 290 ast::Stmt * build_resume( const CodeLocation & loc, ExpressionNode * ct l ) {291 return build_throw_stmt( loc, ct l, ast::Resume );290 ast::Stmt * build_resume( const CodeLocation & loc, ExpressionNode * ctrl ) { 291 return build_throw_stmt( loc, ctrl, ast::Resume ); 292 292 } // build_resume 293 293 294 ast::Stmt * build_resume_at( ExpressionNode * ct l, ExpressionNode * target ) {295 (void)ct l;294 ast::Stmt * build_resume_at( ExpressionNode * ctrl, ExpressionNode * target ) { 295 (void)ctrl; 296 296 (void)target; 297 297 assertf( false, "resume at (non-local throw) is not yet supported," ); … … 516 516 } // build_corun 517 517 518 ast::Stmt * build_cofor( const CodeLocation & location, ForCtrl * forct l, StatementNode * stmt ) {518 ast::Stmt * build_cofor( const CodeLocation & location, ForCtrl * forctrl, StatementNode * stmt ) { 519 519 std::vector<ast::ptr<ast::Stmt>> astinit; // maybe empty 520 buildMoveList( forct l->init, astinit );520 buildMoveList( forctrl->init, astinit ); 521 521 522 522 ast::Expr * astcond = nullptr; // maybe empty 523 astcond = maybeMoveBuild( forct l->condition );523 astcond = maybeMoveBuild( forctrl->condition ); 524 524 525 525 ast::Expr * astincr = nullptr; // maybe empty 526 astincr = maybeMoveBuild( forct l->change );527 delete forct l;526 astincr = maybeMoveBuild( forctrl->change ); 527 delete forctrl; 528 528 529 529 return new ast::CoforStmt( location,
Note: See TracChangeset
for help on using the changeset viewer.