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