Changes in src/Parser/StatementNode.cc [401e61f:cc32d83]
- File:
-
- 1 edited
-
src/Parser/StatementNode.cc (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/StatementNode.cc
r401e61f rcc32d83 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jun 5 08:58:34201813 // Update Count : 3 6212 // Last Modified On : Mon Apr 30 09:21:16 2018 13 // Update Count : 354 14 14 // 15 15 … … 69 69 caseStmt->get_statements().splice( caseStmt->get_statements().end(), stmts ); 70 70 return this; 71 } // StatementNode::append_last_case71 } 72 72 73 73 Statement * build_expr( ExpressionNode * ctl ) { 74 74 Expression * e = maybeMoveBuild< Expression >( ctl ); 75 75 76 if ( e ) return new ExprStmt( e ); 77 else return new NullStmt(); 78 } // build_expr 79 80 Expression * build_if_control( IfCtl * ctl, std::list< Statement * > & init ) { 76 if ( e ) 77 return new ExprStmt( e ); 78 else 79 return new NullStmt(); 80 } 81 82 Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) { 83 Statement * thenb, * elseb = 0; 84 std::list< Statement * > branches; 85 buildMoveList< Statement, StatementNode >( then_stmt, branches ); 86 assert( branches.size() == 1 ); 87 thenb = branches.front(); 88 89 if ( else_stmt ) { 90 std::list< Statement * > branches; 91 buildMoveList< Statement, StatementNode >( else_stmt, branches ); 92 assert( branches.size() == 1 ); 93 elseb = branches.front(); 94 } // if 95 96 std::list< Statement * > init; 81 97 if ( ctl->init != 0 ) { 82 98 buildMoveList( ctl->init, init ); … … 86 102 if ( ctl->condition ) { 87 103 // compare the provided condition against 0 88 cond = notZeroExpr( maybeMoveBuild< Expression >(ctl->condition) );104 cond = notZeroExpr( maybeMoveBuild< Expression >(ctl->condition) ); 89 105 } else { 90 106 for ( Statement * stmt : init ) { … … 97 113 } 98 114 delete ctl; 99 return cond;100 } // build_if_control101 102 Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) {103 Statement * thenb, * elseb = nullptr;104 std::list< Statement * > branches;105 buildMoveList< Statement, StatementNode >( then_stmt, branches );106 assert( branches.size() == 1 );107 thenb = branches.front();108 109 if ( else_stmt ) {110 std::list< Statement * > branches;111 buildMoveList< Statement, StatementNode >( else_stmt, branches );112 assert( branches.size() == 1 );113 elseb = branches.front();114 } // if115 116 std::list< Statement * > init;117 Expression * cond = build_if_control( ctl, init );118 115 return new IfStmt( cond, thenb, elseb, init ); 119 } // build_if116 } 120 117 121 118 Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt ) { … … 133 130 // branches.size() == 0 for switch (...) {}, i.e., no declaration or statements 134 131 return new SwitchStmt( maybeMoveBuild< Expression >(ctl), branches ); 135 } // build_switch 136 132 } 137 133 Statement * build_case( ExpressionNode * ctl ) { 138 134 std::list< Statement * > branches; 139 135 return new CaseStmt( maybeMoveBuild< Expression >(ctl), branches ); 140 } // build_case 141 136 } 142 137 Statement * build_default() { 143 138 std::list< Statement * > branches; 144 139 return new CaseStmt( nullptr, branches, true ); 145 } // build_default146 147 Statement * build_while( IfCtl * ctl, StatementNode * stmt) {140 } 141 142 Statement * build_while( ExpressionNode * ctl, StatementNode * stmt, bool kind ) { 148 143 std::list< Statement * > branches; 149 144 buildMoveList< Statement, StatementNode >( stmt, branches ); 150 145 assert( branches.size() == 1 ); 151 152 std::list< Statement * > init; 153 Expression * cond = build_if_control( ctl, init ); 154 return new WhileStmt( cond, branches.front(), init, false ); 155 } // build_while 156 157 Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt ) { 158 std::list< Statement * > branches; 159 buildMoveList< Statement, StatementNode >( stmt, branches ); 160 assert( branches.size() == 1 ); 161 162 std::list< Statement * > init; 163 return new WhileStmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), init, true ); 164 } // build_do_while 146 return new WhileStmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), kind ); 147 } 165 148 166 149 Statement * build_for( ForCtl * forctl, StatementNode * stmt ) { … … 184 167 delete forctl; 185 168 return new ForStmt( init, cond, incr, branches.front() ); 186 } // build_for169 } 187 170 188 171 Statement * build_branch( BranchStmt::Type kind ) { 189 172 Statement * ret = new BranchStmt( "", kind ); 190 173 return ret; 191 } // build_branch 192 174 } 193 175 Statement * build_branch( std::string * identifier, BranchStmt::Type kind ) { 194 176 Statement * ret = new BranchStmt( * identifier, kind ); 195 177 delete identifier; // allocated by lexer 196 178 return ret; 197 } // build_branch 198 179 } 199 180 Statement * build_computedgoto( ExpressionNode * ctl ) { 200 181 return new BranchStmt( maybeMoveBuild< Expression >(ctl), BranchStmt::Goto ); 201 } // build_computedgoto182 } 202 183 203 184 Statement * build_return( ExpressionNode * ctl ) { … … 205 186 buildMoveList( ctl, exps ); 206 187 return new ReturnStmt( exps.size() > 0 ? exps.back() : nullptr ); 207 } // build_return188 } 208 189 209 190 Statement * build_throw( ExpressionNode * ctl ) { … … 212 193 assertf( exps.size() < 2, "This means we are leaking memory"); 213 194 return new ThrowStmt( ThrowStmt::Terminate, !exps.empty() ? exps.back() : nullptr ); 214 } // build_throw195 } 215 196 216 197 Statement * build_resume( ExpressionNode * ctl ) { … … 219 200 assertf( exps.size() < 2, "This means we are leaking memory"); 220 201 return new ThrowStmt( ThrowStmt::Resume, !exps.empty() ? exps.back() : nullptr ); 221 } // build_resume202 } 222 203 223 204 Statement * build_resume_at( ExpressionNode * ctl, ExpressionNode * target ) { … … 225 206 (void)target; 226 207 assertf( false, "resume at (non-local throw) is not yet supported," ); 227 } // build_resume_at208 } 228 209 229 210 Statement * build_try( StatementNode * try_stmt, StatementNode * catch_stmt, StatementNode * finally_stmt ) { … … 233 214 FinallyStmt * finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) ); 234 215 return new TryStmt( tryBlock, branches, finallyBlock ); 235 } // build_try 236 216 } 237 217 Statement * build_catch( CatchStmt::Kind kind, DeclarationNode * decl, ExpressionNode * cond, StatementNode * body ) { 238 218 std::list< Statement * > branches; … … 240 220 assert( branches.size() == 1 ); 241 221 return new CatchStmt( kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), branches.front() ); 242 } // build_catch 243 222 } 244 223 Statement * build_finally( StatementNode * stmt ) { 245 224 std::list< Statement * > branches; … … 247 226 assert( branches.size() == 1 ); 248 227 return new FinallyStmt( dynamic_cast< CompoundStmt * >( branches.front() ) ); 249 } // build_finally228 } 250 229 251 230 WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when ) { … … 268 247 269 248 return node; 270 } // build_waitfor249 } 271 250 272 251 WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when, WaitForStmt * node ) { … … 287 266 288 267 return node; 289 } // build_waitfor268 } 290 269 291 270 WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when ) { … … 296 275 node->timeout.statement = maybeMoveBuild<Statement >( stmt ); 297 276 node->timeout.condition = notZeroExpr( maybeMoveBuild<Expression>( when ) ); 298 } else { 277 } 278 else { 299 279 node->orelse.statement = maybeMoveBuild<Statement >( stmt ); 300 280 node->orelse.condition = notZeroExpr( maybeMoveBuild<Expression>( when ) ); 301 } // if281 } 302 282 303 283 return node; 304 } // build_waitfor_timeout284 } 305 285 306 286 WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when, StatementNode * else_stmt, ExpressionNode * else_when ) { … … 315 295 316 296 return node; 317 } // build_waitfor_timeout297 } 318 298 319 299 WithStmt * build_with( ExpressionNode * exprs, StatementNode * stmt ) { … … 322 302 Statement * s = maybeMoveBuild<Statement>( stmt ); 323 303 return new WithStmt( e, s ); 324 } // build_with304 } 325 305 326 306 Statement * build_compound( StatementNode * first ) { … … 328 308 buildMoveList( first, cs->get_kids() ); 329 309 return cs; 330 } // build_compound310 } 331 311 332 312 Statement * build_asm( bool voltile, Expression * instruction, ExpressionNode * output, ExpressionNode * input, ExpressionNode * clobber, LabelNode * gotolabels ) { … … 338 318 buildMoveList( clobber, clob ); 339 319 return new AsmStmt( voltile, instruction, out, in, clob, gotolabels ? gotolabels->labels : noLabels ); 340 } // build_asm320 } 341 321 342 322 Statement * build_directive( string * directive ) { 343 323 return new DirectiveStmt( *directive ); 344 } // build_directive324 } 345 325 346 326 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.