Changeset 3e5db5b4 for src/ControlStruct
- Timestamp:
- Feb 1, 2022, 12:03:50 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- 34c32f0
- Parents:
- cef7430
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/ControlStruct/MultiLevelExit.cpp ¶
rcef7430 r3e5db5b4 72 72 bool isFallDefaultTarget() const { return SwitchStmt == kind; } 73 73 74 // These routines set a target as being "used" by a BranchStmt 74 75 ast::Label useContExit() { assert( kind <= WhileStmt ); return useTarget(secondTarget); } 75 76 ast::Label useBreakExit() { assert( CaseStmt != kind ); return useTarget(firstTarget); } … … 77 78 ast::Label useFallDefaultExit() { assert( SwitchStmt == kind ); return useTarget(secondTarget); } 78 79 80 // These routines check if a specific label for a statement is used by a BranchStmt 79 81 bool isContUsed() const { assert( kind <= WhileStmt ); return secondTarget.used; } 80 82 bool isBreakUsed() const { assert( CaseStmt != kind ); return firstTarget.used; } … … 165 167 const ast::CompoundStmt * stmt ) { 166 168 visit_children = false; 169 170 // if the stmt is labelled then generate a label to check in postvisit if the label is used 167 171 bool isLabeled = !stmt->labels.empty(); 168 172 if ( isLabeled ) { … … 218 222 } 219 223 224 // This routine updates targets on enclosing control structures to indicate which 225 // label is used by the BranchStmt that is passed 220 226 const ast::BranchStmt * MultiLevelExitCore::postvisit( const ast::BranchStmt * stmt ) { 221 227 std::vector<Entry>::reverse_iterator targetEntry = 222 228 enclosing_control_structures.rend(); 229 230 // Labels on different stmts require different approaches to access 223 231 switch ( stmt->kind ) { 224 232 case ast::BranchStmt::Goto: … … 257 265 break; 258 266 } 267 // handle fallthrough in case/switch stmts 259 268 case ast::BranchStmt::FallThrough: { 260 269 targetEntry = findEnclosingControlStructure( isFallthroughTarget ); … … 534 543 } 535 544 545 // if continue is used insert a continue label into the back of the body of the loop 536 546 if ( entry.isContUsed() ) { 537 547 ast::CompoundStmt * new_body = new ast::CompoundStmt( body->location ); 548 // {} 538 549 new_body->kids.push_back( body ); 550 // { 551 // body 552 // } 539 553 new_body->kids.push_back( 540 554 labelledNullStmt( body->location, entry.useContExit() ) ); 555 // { 556 // body 557 // ContinueLabel: {} 558 // } 541 559 return new_body; 542 560 } … … 552 570 ast::Label contLabel = LabelGenerator::newLabel( "loopContinue", loopStmt ); 553 571 enclosing_control_structures.emplace_back( loopStmt, breakLabel, contLabel ); 572 // labels are added temporarily to see if they are used and then added permanently in postvisit if ther are used 573 // children will tag labels as being used during their traversal which occurs before postvisit 574 575 // GuardAction calls the lambda after the node is done being visited 554 576 GuardAction( [this](){ enclosing_control_structures.pop_back(); } ); 555 577 } … … 564 586 return ast::mutate_field( 565 587 loopStmt, &LoopNode::body, mutateLoop( loopStmt->body, entry ) ); 588 // this call to mutate_field compares loopStmt->body and the result of mutateLoop 589 // if they are the same the node isn't mutated, if they differ then the new mutated node is returned 590 // the stmts will only differ if a label is used 566 591 } 567 592
Note: See TracChangeset
for help on using the changeset viewer.