Changes in src/Parser/StatementNode.cc [8cc5cb0:321f55d]
- File:
-
- 1 edited
-
src/Parser/StatementNode.cc (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/StatementNode.cc
r8cc5cb0 r321f55d 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 11 16:19:45201613 // Update Count : 21012 // Last Modified On : Wed Aug 10 22:08:38 2016 13 // Update Count : 173 14 14 // 15 15 … … 118 118 119 119 StatementNode *StatementNode::append_last_case( StatementNode *stmt ) { 120 assert( false );121 120 if ( stmt != 0 ) { 122 121 StatementNode *next = ( StatementNode *)get_link(); 123 122 if ( next && ( next->get_type() == StatementNode::Case || next->get_type() == StatementNode::Default ) ) 124 next->append_last_case ( stmt );123 next->append_last_case ( stmt ); 125 124 else 126 125 if ( block == 0 ) … … 129 128 block->set_link( stmt ); 130 129 } // if 131 return this;132 }133 134 StatementNode *StatementNode2::append_last_case( StatementNode *stmt ) {135 StatementNode *prev = this;136 for ( StatementNode * curr = prev; curr != nullptr; curr = (StatementNode *)curr->get_link() ) {137 StatementNode2 *node = dynamic_cast<StatementNode2 *>(curr);138 assert( node );139 assert( dynamic_cast<CaseStmt *>(node->stmt) );140 prev = curr;141 } // for142 StatementNode2 *node = dynamic_cast<StatementNode2 *>(prev);143 std::list<Statement *> stmts;144 buildList( stmt, stmts );145 CaseStmt * caseStmt;146 caseStmt = dynamic_cast<CaseStmt *>(node->stmt);147 caseStmt->get_statements().splice( caseStmt->get_statements().end(), stmts );148 130 return this; 149 131 } … … 223 205 return new NullStmt( labs ); 224 206 } 225 assert( false );226 207 case If: 227 208 // { … … 239 220 assert( false ); 240 221 case Switch: 241 // return new SwitchStmt( labs, maybeBuild<Expression>(get_control()), branches );222 //return new SwitchStmt( labs, maybeBuild<Expression>(get_control()), branches ); 242 223 assert( false ); 243 224 case Case: 244 //return new CaseStmt( labs, maybeBuild<Expression>(get_control() ), branches );225 return new CaseStmt( labs, maybeBuild<Expression>(get_control() ), branches ); 245 226 assert( false ); 246 227 case Default: 247 //return new CaseStmt( labs, 0, branches, true );228 return new CaseStmt( labs, 0, branches, true ); 248 229 assert( false ); 249 230 case While: … … 279 260 assert( false ); 280 261 case Goto: 281 // { 282 // if ( get_target() == "" ) { // computed goto 283 // assert( get_control() != 0 ); 284 // return new BranchStmt( labs, maybeBuild<Expression>(get_control()), BranchStmt::Goto ); 285 // } // if 286 287 // return new BranchStmt( labs, get_target(), BranchStmt::Goto ); 288 // } 289 assert( false ); 262 { 263 if ( get_target() == "" ) { // computed goto 264 assert( get_control() != 0 ); 265 return new BranchStmt( labs, maybeBuild<Expression>(get_control()), BranchStmt::Goto ); 266 } // if 267 268 return new BranchStmt( labs, get_target(), BranchStmt::Goto ); 269 } 290 270 case Break: 291 //return new BranchStmt( labs, get_target(), BranchStmt::Break );271 return new BranchStmt( labs, get_target(), BranchStmt::Break ); 292 272 assert( false ); 293 273 case Continue: 294 //return new BranchStmt( labs, get_target(), BranchStmt::Continue );274 return new BranchStmt( labs, get_target(), BranchStmt::Continue ); 295 275 assert( false ); 296 276 case Return: 297 277 case Throw : 298 // buildList( get_control(), exps ); 299 // if ( exps.size() ==0 ) 300 // return new ReturnStmt( labs, 0, type == Throw ); 301 // if ( exps.size() > 0 ) 302 // return new ReturnStmt( labs, exps.back(), type == Throw ); 303 assert( false ); 278 buildList( get_control(), exps ); 279 if ( exps.size() ==0 ) 280 return new ReturnStmt( labs, 0, type == Throw ); 281 if ( exps.size() > 0 ) 282 return new ReturnStmt( labs, exps.back(), type == Throw ); 304 283 case Try: 305 284 { … … 335 314 } 336 315 337 Statement *build_expr( ExpressionNode *ctl ) {338 Expression *e = maybeBuild< Expression >( ctl );339 340 if ( e )341 return new ExprStmt( noLabels, e );342 else343 return new NullStmt( noLabels );344 }345 346 316 Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt ) { 347 317 Statement *thenb, *elseb = 0; … … 368 338 Statement *build_case( ExpressionNode *ctl ) { 369 339 std::list<Statement *> branches; 340 buildList<Statement, StatementNode>( nullptr, branches ); 370 341 return new CaseStmt( noLabels, maybeBuild<Expression>(ctl), branches ); 371 342 } … … 406 377 Statement *build_branch( std::string identifier, BranchStmt::Type kind ) { 407 378 return new BranchStmt( noLabels, identifier, kind ); 408 }409 Statement *build_computedgoto( ExpressionNode *ctl ) {410 return new BranchStmt( noLabels, maybeBuild<Expression>(ctl), BranchStmt::Goto );411 }412 413 Statement *build_return( ExpressionNode *ctl ) {414 std::list<Expression *> exps;415 buildList( ctl, exps );416 return new ReturnStmt( noLabels, exps.size() > 0 ? exps.back() : nullptr );417 }418 Statement *build_throw( ExpressionNode *ctl ) {419 std::list<Expression *> exps;420 buildList( ctl, exps );421 return new ReturnStmt( noLabels, exps.size() > 0 ? exps.back() : nullptr, true );422 379 } 423 380
Note:
See TracChangeset
for help on using the changeset viewer.