Changes in src/Parser/StatementNode.cc [401e61f:ee3c93d]
- File:
-
- 1 edited
-
src/Parser/StatementNode.cc (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/StatementNode.cc
r401e61f ree3c93d 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 76 if ( e ) 77 return new ExprStmt( e ); 78 else 79 return new NullStmt(); 80 } 79 81 80 82 Expression * build_if_control( IfCtl * ctl, std::list< Statement * > & init ) { … … 98 100 delete ctl; 99 101 return cond; 100 } // build_if_control102 } 101 103 102 104 Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) { 103 Statement * thenb, * elseb = nullptr;105 Statement * thenb, * elseb = 0; 104 106 std::list< Statement * > branches; 105 107 buildMoveList< Statement, StatementNode >( then_stmt, branches ); … … 117 119 Expression * cond = build_if_control( ctl, init ); 118 120 return new IfStmt( cond, thenb, elseb, init ); 119 } // build_if121 } 120 122 121 123 Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt ) { … … 133 135 // branches.size() == 0 for switch (...) {}, i.e., no declaration or statements 134 136 return new SwitchStmt( maybeMoveBuild< Expression >(ctl), branches ); 135 } // build_switch 136 137 } 137 138 Statement * build_case( ExpressionNode * ctl ) { 138 139 std::list< Statement * > branches; 139 140 return new CaseStmt( maybeMoveBuild< Expression >(ctl), branches ); 140 } // build_case 141 141 } 142 142 Statement * build_default() { 143 143 std::list< Statement * > branches; 144 144 return new CaseStmt( nullptr, branches, true ); 145 } // build_default146 147 Statement * build_while( IfCtl * ctl, StatementNode * stmt) {145 } 146 147 Statement * build_while( ExpressionNode * ctl, StatementNode * stmt, bool kind ) { 148 148 std::list< Statement * > branches; 149 149 buildMoveList< Statement, StatementNode >( stmt, branches ); … … 151 151 152 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 153 return new WhileStmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), init, kind ); 154 } 165 155 166 156 Statement * build_for( ForCtl * forctl, StatementNode * stmt ) { … … 184 174 delete forctl; 185 175 return new ForStmt( init, cond, incr, branches.front() ); 186 } // build_for176 } 187 177 188 178 Statement * build_branch( BranchStmt::Type kind ) { 189 179 Statement * ret = new BranchStmt( "", kind ); 190 180 return ret; 191 } // build_branch 192 181 } 193 182 Statement * build_branch( std::string * identifier, BranchStmt::Type kind ) { 194 183 Statement * ret = new BranchStmt( * identifier, kind ); 195 184 delete identifier; // allocated by lexer 196 185 return ret; 197 } // build_branch 198 186 } 199 187 Statement * build_computedgoto( ExpressionNode * ctl ) { 200 188 return new BranchStmt( maybeMoveBuild< Expression >(ctl), BranchStmt::Goto ); 201 } // build_computedgoto189 } 202 190 203 191 Statement * build_return( ExpressionNode * ctl ) { … … 205 193 buildMoveList( ctl, exps ); 206 194 return new ReturnStmt( exps.size() > 0 ? exps.back() : nullptr ); 207 } // build_return195 } 208 196 209 197 Statement * build_throw( ExpressionNode * ctl ) { … … 212 200 assertf( exps.size() < 2, "This means we are leaking memory"); 213 201 return new ThrowStmt( ThrowStmt::Terminate, !exps.empty() ? exps.back() : nullptr ); 214 } // build_throw202 } 215 203 216 204 Statement * build_resume( ExpressionNode * ctl ) { … … 219 207 assertf( exps.size() < 2, "This means we are leaking memory"); 220 208 return new ThrowStmt( ThrowStmt::Resume, !exps.empty() ? exps.back() : nullptr ); 221 } // build_resume209 } 222 210 223 211 Statement * build_resume_at( ExpressionNode * ctl, ExpressionNode * target ) { … … 225 213 (void)target; 226 214 assertf( false, "resume at (non-local throw) is not yet supported," ); 227 } // build_resume_at215 } 228 216 229 217 Statement * build_try( StatementNode * try_stmt, StatementNode * catch_stmt, StatementNode * finally_stmt ) { … … 233 221 FinallyStmt * finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) ); 234 222 return new TryStmt( tryBlock, branches, finallyBlock ); 235 } // build_try 236 223 } 237 224 Statement * build_catch( CatchStmt::Kind kind, DeclarationNode * decl, ExpressionNode * cond, StatementNode * body ) { 238 225 std::list< Statement * > branches; … … 240 227 assert( branches.size() == 1 ); 241 228 return new CatchStmt( kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), branches.front() ); 242 } // build_catch 243 229 } 244 230 Statement * build_finally( StatementNode * stmt ) { 245 231 std::list< Statement * > branches; … … 247 233 assert( branches.size() == 1 ); 248 234 return new FinallyStmt( dynamic_cast< CompoundStmt * >( branches.front() ) ); 249 } // build_finally235 } 250 236 251 237 WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when ) { … … 268 254 269 255 return node; 270 } // build_waitfor256 } 271 257 272 258 WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when, WaitForStmt * node ) { … … 287 273 288 274 return node; 289 } // build_waitfor275 } 290 276 291 277 WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when ) { … … 296 282 node->timeout.statement = maybeMoveBuild<Statement >( stmt ); 297 283 node->timeout.condition = notZeroExpr( maybeMoveBuild<Expression>( when ) ); 298 } else { 284 } 285 else { 299 286 node->orelse.statement = maybeMoveBuild<Statement >( stmt ); 300 287 node->orelse.condition = notZeroExpr( maybeMoveBuild<Expression>( when ) ); 301 } // if288 } 302 289 303 290 return node; 304 } // build_waitfor_timeout291 } 305 292 306 293 WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when, StatementNode * else_stmt, ExpressionNode * else_when ) { … … 315 302 316 303 return node; 317 } // build_waitfor_timeout304 } 318 305 319 306 WithStmt * build_with( ExpressionNode * exprs, StatementNode * stmt ) { … … 322 309 Statement * s = maybeMoveBuild<Statement>( stmt ); 323 310 return new WithStmt( e, s ); 324 } // build_with311 } 325 312 326 313 Statement * build_compound( StatementNode * first ) { … … 328 315 buildMoveList( first, cs->get_kids() ); 329 316 return cs; 330 } // build_compound317 } 331 318 332 319 Statement * build_asm( bool voltile, Expression * instruction, ExpressionNode * output, ExpressionNode * input, ExpressionNode * clobber, LabelNode * gotolabels ) { … … 338 325 buildMoveList( clobber, clob ); 339 326 return new AsmStmt( voltile, instruction, out, in, clob, gotolabels ? gotolabels->labels : noLabels ); 340 } // build_asm327 } 341 328 342 329 Statement * build_directive( string * directive ) { 343 330 return new DirectiveStmt( *directive ); 344 } // build_directive331 } 345 332 346 333 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.