Changeset cb921d4
- Timestamp:
- Nov 8, 2021, 11:12:46 AM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- a5a08a05
- Parents:
- de31a1d
- Location:
- src/ControlStruct
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/FixLabels.cpp
rde31a1d rcb921d4 10 10 // Created On : Mon Nov 1 09:39:00 2021 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Nov 5 19:20:00 202113 // Update Count : 212 // Last Modified On : Mon Nov 8 10:53:00 2021 13 // Update Count : 3 14 14 // 15 15 … … 28 28 class FixLabelsCore final : public ast::WithGuards { 29 29 LabelToStmt labelTable; 30 LabelGenerator * label_gen;31 30 public: 32 FixLabelsCore( LabelGenerator * gen = nullptr ) : 33 labelTable(), 34 label_gen( gen ? gen : LabelGenerator::getGenerator() ) 35 {} 31 FixLabelsCore( LabelGenerator * gen = nullptr ) : labelTable() {} 36 32 37 33 void previsit( const ast::FunctionDecl * ); … … 59 55 } 60 56 return ast::mutate_field( decl, &ast::FunctionDecl::stmts, 61 multiLevelExitUpdate( decl->stmts.get(), labelTable , label_gen) );57 multiLevelExitUpdate( decl->stmts.get(), labelTable ) ); 62 58 } 63 59 -
src/ControlStruct/MultiLevelExit.cpp
rde31a1d rcb921d4 10 10 // Created On : Mon Nov 1 13:48:00 2021 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Nov 5 19:20:00 202113 // Update Count : 112 // Last Modified On : Mon Nov 8 10:56:00 2021 13 // Update Count : 2 14 14 // 15 15 … … 105 105 public ast::WithVisitorRef<MultiLevelExitCore>, 106 106 public ast::WithShortCircuiting, public ast::WithGuards { 107 MultiLevelExitCore( const LabelToStmt & lt , LabelGenerator * lg);107 MultiLevelExitCore( const LabelToStmt & lt ); 108 108 109 109 void previsit( const ast::FunctionDecl * ); … … 131 131 std::vector<Entry> enclosing_control_structures; 132 132 ast::Label break_label; 133 LabelGenerator * label_gen;134 133 bool inFinally; 135 134 … … 154 153 } 155 154 156 MultiLevelExitCore::MultiLevelExitCore( 157 const LabelToStmt & lt, LabelGenerator * lg ) : 158 target_table( lt ), break_label( CodeLocation(), "" ), label_gen( lg ), 155 MultiLevelExitCore::MultiLevelExitCore( const LabelToStmt & lt ) : 156 target_table( lt ), break_label( CodeLocation(), "" ), 159 157 inFinally( false ) 160 158 {} … … 169 167 bool isLabeled = !stmt->labels.empty(); 170 168 if ( isLabeled ) { 171 ast::Label breakLabel = label_gen->newLabel( "blockBreak", stmt );169 ast::Label breakLabel = LabelGenerator::newLabel( "blockBreak", stmt ); 172 170 enclosing_control_structures.emplace_back( stmt, breakLabel ); 173 171 GuardAction( [this]() { enclosing_control_structures.pop_back(); } ); … … 380 378 ast::CaseStmt * mutStmt = ast::mutate( stmt ); 381 379 382 ast::Label fallLabel = label_gen->newLabel( "fallThrough", stmt );380 ast::Label fallLabel = LabelGenerator::newLabel( "fallThrough", stmt ); 383 381 if ( !mutStmt->stmts.empty() ) { 384 382 // Ensure that the stack isn't corrupted by exceptions in fixBlock. … … 419 417 bool labeledBlock = !stmt->labels.empty(); 420 418 if ( labeledBlock ) { 421 ast::Label breakLabel = label_gen->newLabel( "blockBreak", stmt );419 ast::Label breakLabel = LabelGenerator::newLabel( "blockBreak", stmt ); 422 420 enclosing_control_structures.emplace_back( stmt, breakLabel ); 423 421 GuardAction( [this](){ enclosing_control_structures.pop_back(); } ); … … 442 440 443 441 void MultiLevelExitCore::previsit( const ast::SwitchStmt * stmt ) { 444 ast::Label label = label_gen->newLabel( "switchBreak", stmt );442 ast::Label label = LabelGenerator::newLabel( "switchBreak", stmt ); 445 443 auto it = std::find_if( stmt->stmts.rbegin(), stmt->stmts.rend(), isDefaultCase ); 446 444 … … 448 446 ? (it)->strict_as<ast::CaseStmt>() : nullptr; 449 447 ast::Label defaultLabel = defaultCase 450 ? label_gen->newLabel( "fallThroughDefault", defaultCase )448 ? LabelGenerator::newLabel( "fallThroughDefault", defaultCase ) 451 449 : ast::Label( stmt->location, "" ); 452 450 enclosing_control_structures.emplace_back( stmt, label, defaultLabel ); … … 506 504 bool isLabeled = !stmt->labels.empty(); 507 505 if ( isLabeled ) { 508 ast::Label breakLabel = label_gen->newLabel( "blockBreak", stmt );506 ast::Label breakLabel = LabelGenerator::newLabel( "blockBreak", stmt ); 509 507 enclosing_control_structures.emplace_back( stmt, breakLabel ); 510 508 GuardAction([this](){ enclosing_control_structures.pop_back(); } ); … … 551 549 // Remember is loop before going onto mutate the body. 552 550 // The labels will be folded in if they are used. 553 ast::Label breakLabel = label_gen->newLabel( "loopBreak", loopStmt );554 ast::Label contLabel = label_gen->newLabel( "loopContinue", loopStmt );551 ast::Label breakLabel = LabelGenerator::newLabel( "loopBreak", loopStmt ); 552 ast::Label contLabel = LabelGenerator::newLabel( "loopContinue", loopStmt ); 555 553 enclosing_control_structures.emplace_back( loopStmt, breakLabel, contLabel ); 556 554 GuardAction( [this](){ enclosing_control_structures.pop_back(); } ); … … 607 605 const ast::CompoundStmt * multiLevelExitUpdate( 608 606 const ast::CompoundStmt * stmt, 609 const LabelToStmt & labelTable, 610 LabelGenerator * labelGen ) { 607 const LabelToStmt & labelTable ) { 611 608 // Must start in the body, so FunctionDecls can be a stopping point. 612 ast::Pass<MultiLevelExitCore> visitor( labelTable , labelGen);609 ast::Pass<MultiLevelExitCore> visitor( labelTable ); 613 610 const ast::CompoundStmt * ret = stmt->accept( visitor ); 614 611 return ret; -
src/ControlStruct/MultiLevelExit.hpp
rde31a1d rcb921d4 10 10 // Created On : Mon Nov 1 13:49:00 2021 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Nov 5 19:20:00 202113 // Update Count : 112 // Last Modified On : Mon Nov 8 10:53:00 2021 13 // Update Count : 3 14 14 // 15 15 … … 31 31 /// Mutate a function body to handle multi-level exits. 32 32 const ast::CompoundStmt * multiLevelExitUpdate( 33 const ast::CompoundStmt *, const LabelToStmt & , LabelGenerator *);33 const ast::CompoundStmt *, const LabelToStmt & ); 34 34 35 35 }
Note: See TracChangeset
for help on using the changeset viewer.