Changes in src/Parser/StatementNode.cc [2f22cc4:658fafe4]
- File:
-
- 1 edited
-
src/Parser/StatementNode.cc (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/StatementNode.cc
r2f22cc4 r658fafe4 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Aug 10 13:54:21201613 // Update Count : 1 7012 // Last Modified On : Tue Jul 12 17:21:02 2016 13 // Update Count : 133 14 14 // 15 15 … … 106 106 return this; 107 107 } 108 109 // StatementNode *StatementNode::add_controlexp( ExpressionNode *e ) { 110 // if ( control && e ) 111 // control->add_to_list( e ); // xxx - check this 112 // return this; 113 // } 108 114 109 115 StatementNode *StatementNode::append_block( StatementNode *stmt ) { … … 170 176 } // if 171 177 if ( block ) { 172 os << string( indent + ParseNode::indent_by, ' ' ) << " Cases: " << endl;178 os << string( indent + ParseNode::indent_by, ' ' ) << "Branches of execution: " << endl; 173 179 block->printList( os, indent + 2 * ParseNode::indent_by ); 174 180 } // if … … 206 212 } 207 213 case If: 208 // { 209 // Statement *thenb = 0, *elseb = 0; 210 // assert( branches.size() >= 1 ); 211 212 // thenb = branches.front(); 213 // branches.pop_front(); 214 // if ( ! branches.empty() ) { 215 // elseb = branches.front(); 216 // branches.pop_front(); 217 // } // if 218 // return new IfStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), thenb, elseb ); 219 // } 220 assert( false ); 214 { 215 Statement *thenb = 0, *elseb = 0; 216 assert( branches.size() >= 1 ); 217 218 thenb = branches.front(); 219 branches.pop_front(); 220 if ( ! branches.empty() ) { 221 elseb = branches.front(); 222 branches.pop_front(); 223 } // if 224 return new IfStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), thenb, elseb ); 225 } 226 case While: 227 assert( branches.size() == 1 ); 228 return new WhileStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), branches.front() ); 229 case Do: 230 assert( branches.size() == 1 ); 231 return new WhileStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), branches.front(), true ); 232 case For: 233 { 234 assert( branches.size() == 1 ); 235 236 ForCtlExprNode *ctl = dynamic_cast<ForCtlExprNode *>( get_control() ); 237 assert( ctl != 0 ); 238 239 std::list<Statement *> init; 240 if ( ctl->get_init() != 0 ) { 241 buildList( ctl->get_init(), init ); 242 } // if 243 244 Expression *cond = 0; 245 if ( ctl->get_condition() != 0 ) 246 cond = notZeroExpr( maybeBuild<Expression>(ctl->get_condition()) ); 247 248 Expression *incr = 0; 249 if ( ctl->get_change() != 0 ) 250 incr = maybeBuild<Expression>(ctl->get_change()); 251 252 return new ForStmt( labs, init, cond, incr, branches.front() ); 253 } 221 254 case Switch: 222 //return new SwitchStmt( labs, maybeBuild<Expression>(get_control()), branches ); 223 assert( false ); 255 return new SwitchStmt( labs, maybeBuild<Expression>(get_control()), branches ); 224 256 case Case: 225 return new CaseStmt( labs, maybeBuild<Expression>(get_control() ), branches );257 return new CaseStmt( labs, maybeBuild<Expression>(get_control()), branches ); 226 258 case Default: 227 259 return new CaseStmt( labs, 0, branches, true ); 228 case While:229 // assert( branches.size() == 1 );230 // return new WhileStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), branches.front() );231 assert( false );232 case Do:233 // assert( branches.size() == 1 );234 // return new WhileStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), branches.front(), true );235 assert( false );236 case For:237 // {238 // assert( branches.size() == 1 );239 240 // ForCtlExprNode *ctl = dynamic_cast<ForCtlExprNode *>( get_control() );241 // assert( ctl != 0 );242 243 // std::list<Statement *> init;244 // if ( ctl->get_init() != 0 ) {245 // buildList( ctl->get_init(), init );246 // } // if247 248 // Expression *cond = 0;249 // if ( ctl->get_condition() != 0 )250 // cond = notZeroExpr( maybeBuild<Expression>(ctl->get_condition()) );251 252 // Expression *incr = 0;253 // if ( ctl->get_change() != 0 )254 // incr = maybeBuild<Expression>(ctl->get_change());255 256 // return new ForStmt( labs, init, cond, incr, branches.front() );257 // }258 assert( false );259 260 case Goto: 260 261 { … … 310 311 } 311 312 312 Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt ) {313 Statement *thenb, *elseb = 0;314 std::list<Statement *> branches;315 buildList<Statement, StatementNode>( then_stmt, branches );316 assert( branches.size() >= 1 );317 thenb = branches.front();318 319 if ( else_stmt ) {320 std::list<Statement *> branches;321 buildList<Statement, StatementNode>( else_stmt, branches );322 assert( branches.size() >= 1 );323 elseb = branches.front();324 } // if325 return new IfStmt( noLabels, notZeroExpr( maybeBuild<Expression>(ctl) ), thenb, elseb );326 }327 328 Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt ) {329 std::list<Statement *> branches;330 buildList<Statement, StatementNode>( stmt, branches );331 assert( branches.size() >= 1 );332 return new SwitchStmt( noLabels, maybeBuild<Expression>(ctl), branches );333 }334 335 Statement *build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind ) {336 std::list<Statement *> branches;337 buildList<Statement, StatementNode>( stmt, branches );338 assert( branches.size() == 1 );339 return new WhileStmt( noLabels, notZeroExpr( maybeBuild<Expression>(ctl) ), branches.front(), kind );340 }341 342 Statement *build_for( ForCtl *forctl, StatementNode *stmt ) {343 std::list<Statement *> branches;344 buildList<Statement, StatementNode>( stmt, branches );345 assert( branches.size() == 1 );346 347 std::list<Statement *> init;348 if ( forctl->init != 0 ) {349 buildList( forctl->init, init );350 } // if351 352 Expression *cond = 0;353 if ( forctl->condition != 0 )354 cond = notZeroExpr( maybeBuild<Expression>(forctl->condition) );355 356 Expression *incr = 0;357 if ( forctl->change != 0 )358 incr = maybeBuild<Expression>(forctl->change);359 360 delete forctl;361 return new ForStmt( noLabels, init, cond, incr, branches.front() );362 }363 364 313 365 314 CompoundStmtNode::CompoundStmtNode() : first( 0 ), last( 0 ) {} … … 407 356 408 357 409 AsmStmtNode::AsmStmtNode( Type t, bool voltile, Constant Expr *instruction, ExpressionNode *output, ExpressionNode *input, ExpressionNode *clobber, LabelNode *gotolabels ) :358 AsmStmtNode::AsmStmtNode( Type t, bool voltile, ConstantNode *instruction, ExpressionNode *output, ExpressionNode *input, ConstantNode *clobber, LabelNode *gotolabels ) : 410 359 StatementNode( t ), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ) { 411 360 if ( gotolabels ) { … … 416 365 417 366 AsmStmtNode::~AsmStmtNode() { 418 delete output; delete input; delete clobber;367 delete instruction; delete output; delete input; delete clobber; 419 368 } 420 369 … … 424 373 if ( instruction ) { 425 374 os << string( indent + ParseNode::indent_by, ' ' ) << "Instruction:" << endl; 426 //instruction->printList( os, indent + 2 * ParseNode::indent_by );375 instruction->printList( os, indent + 2 * ParseNode::indent_by ); 427 376 } // if 428 377 if ( output ) { … … 436 385 if ( clobber ) { 437 386 os << string( indent + ParseNode::indent_by, ' ' ) << "Clobber:" << endl; 438 //clobber->printList( os, indent + 2 * ParseNode::indent_by );387 clobber->printList( os, indent + 2 * ParseNode::indent_by ); 439 388 } // if 440 389 if ( ! gotolabels.empty() ) { … … 465 414 buildList( clobber, clob ); 466 415 std::list< Label > gotolabs = gotolabels; 467 return new AsmStmt( labs, voltile, instruction, out, in, clob, gotolabs );416 return new AsmStmt( labs, voltile, (ConstantExpr *)maybeBuild< Expression >( instruction ), out, in, clob, gotolabs ); 468 417 } 469 418
Note:
See TracChangeset
for help on using the changeset viewer.