Changeset cb921d4


Ignore:
Timestamp:
Nov 8, 2021, 11:12:46 AM (3 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
a5a08a05
Parents:
de31a1d
Message:

Changed some of the new ast code so they no longer pass around the empty LabelGenerator?.

Location:
src/ControlStruct
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/FixLabels.cpp

    rde31a1d rcb921d4  
    1010// Created On       : Mon Nov  1 09:39:00 2021
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Nov  5 19:20:00 2021
    13 // Update Count     : 2
     12// Last Modified On : Mon Nov  8 10:53:00 2021
     13// Update Count     : 3
    1414//
    1515
     
    2828class FixLabelsCore final : public ast::WithGuards {
    2929        LabelToStmt labelTable;
    30         LabelGenerator * label_gen;
    3130public:
    32         FixLabelsCore( LabelGenerator * gen = nullptr ) :
    33                 labelTable(),
    34                 label_gen( gen ? gen : LabelGenerator::getGenerator() )
    35         {}
     31        FixLabelsCore( LabelGenerator * gen = nullptr ) : labelTable() {}
    3632
    3733        void previsit( const ast::FunctionDecl * );
     
    5955        }
    6056        return ast::mutate_field( decl, &ast::FunctionDecl::stmts,
    61                 multiLevelExitUpdate( decl->stmts.get(), labelTable, label_gen ) );
     57                multiLevelExitUpdate( decl->stmts.get(), labelTable ) );
    6258}
    6359
  • src/ControlStruct/MultiLevelExit.cpp

    rde31a1d rcb921d4  
    1010// Created On       : Mon Nov  1 13:48:00 2021
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Nov  5 19:20:00 2021
    13 // Update Count     : 1
     12// Last Modified On : Mon Nov  8 10:56:00 2021
     13// Update Count     : 2
    1414//
    1515
     
    105105                public ast::WithVisitorRef<MultiLevelExitCore>,
    106106                public ast::WithShortCircuiting, public ast::WithGuards {
    107         MultiLevelExitCore( const LabelToStmt & lt, LabelGenerator * lg );
     107        MultiLevelExitCore( const LabelToStmt & lt );
    108108
    109109        void previsit( const ast::FunctionDecl * );
     
    131131        std::vector<Entry> enclosing_control_structures;
    132132        ast::Label break_label;
    133         LabelGenerator * label_gen;
    134133        bool inFinally;
    135134
     
    154153}
    155154
    156 MultiLevelExitCore::MultiLevelExitCore(
    157                 const LabelToStmt & lt, LabelGenerator * lg ) :
    158         target_table( lt ), break_label( CodeLocation(), "" ), label_gen( lg ),
     155MultiLevelExitCore::MultiLevelExitCore( const LabelToStmt & lt ) :
     156        target_table( lt ), break_label( CodeLocation(), "" ),
    159157        inFinally( false )
    160158{}
     
    169167        bool isLabeled = !stmt->labels.empty();
    170168        if ( isLabeled ) {
    171                 ast::Label breakLabel = label_gen->newLabel( "blockBreak", stmt );
     169                ast::Label breakLabel = LabelGenerator::newLabel( "blockBreak", stmt );
    172170                enclosing_control_structures.emplace_back( stmt, breakLabel );
    173171                GuardAction( [this]() { enclosing_control_structures.pop_back(); } );
     
    380378        ast::CaseStmt * mutStmt = ast::mutate( stmt );
    381379
    382         ast::Label fallLabel = label_gen->newLabel( "fallThrough", stmt );
     380        ast::Label fallLabel = LabelGenerator::newLabel( "fallThrough", stmt );
    383381        if ( !mutStmt->stmts.empty() ) {
    384382                // Ensure that the stack isn't corrupted by exceptions in fixBlock.
     
    419417        bool labeledBlock = !stmt->labels.empty();
    420418        if ( labeledBlock ) {
    421                 ast::Label breakLabel = label_gen->newLabel( "blockBreak", stmt );
     419                ast::Label breakLabel = LabelGenerator::newLabel( "blockBreak", stmt );
    422420                enclosing_control_structures.emplace_back( stmt, breakLabel );
    423421                GuardAction( [this](){ enclosing_control_structures.pop_back(); } );
     
    442440
    443441void MultiLevelExitCore::previsit( const ast::SwitchStmt * stmt ) {
    444         ast::Label label = label_gen->newLabel( "switchBreak", stmt );
     442        ast::Label label = LabelGenerator::newLabel( "switchBreak", stmt );
    445443        auto it = std::find_if( stmt->stmts.rbegin(), stmt->stmts.rend(), isDefaultCase );
    446444
     
    448446                ? (it)->strict_as<ast::CaseStmt>() : nullptr;
    449447        ast::Label defaultLabel = defaultCase
    450                 ? label_gen->newLabel( "fallThroughDefault", defaultCase )
     448                ? LabelGenerator::newLabel( "fallThroughDefault", defaultCase )
    451449                : ast::Label( stmt->location, "" );
    452450        enclosing_control_structures.emplace_back( stmt, label, defaultLabel );
     
    506504        bool isLabeled = !stmt->labels.empty();
    507505        if ( isLabeled ) {
    508                 ast::Label breakLabel = label_gen->newLabel( "blockBreak", stmt );
     506                ast::Label breakLabel = LabelGenerator::newLabel( "blockBreak", stmt );
    509507                enclosing_control_structures.emplace_back( stmt, breakLabel );
    510508                GuardAction([this](){ enclosing_control_structures.pop_back(); } );
     
    551549        // Remember is loop before going onto mutate the body.
    552550        // 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 );
    555553        enclosing_control_structures.emplace_back( loopStmt, breakLabel, contLabel );
    556554        GuardAction( [this](){ enclosing_control_structures.pop_back(); } );
     
    607605const ast::CompoundStmt * multiLevelExitUpdate(
    608606        const ast::CompoundStmt * stmt,
    609                 const LabelToStmt & labelTable,
    610                 LabelGenerator * labelGen ) {
     607                const LabelToStmt & labelTable ) {
    611608        // 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 );
    613610        const ast::CompoundStmt * ret = stmt->accept( visitor );
    614611        return ret;
  • src/ControlStruct/MultiLevelExit.hpp

    rde31a1d rcb921d4  
    1010// Created On       : Mon Nov  1 13:49:00 2021
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Nov  5 19:20:00 2021
    13 // Update Count     : 1
     12// Last Modified On : Mon Nov  8 10:53:00 2021
     13// Update Count     : 3
    1414//
    1515
     
    3131/// Mutate a function body to handle multi-level exits.
    3232const ast::CompoundStmt * multiLevelExitUpdate(
    33         const ast::CompoundStmt *, const LabelToStmt &, LabelGenerator *);
     33        const ast::CompoundStmt *, const LabelToStmt & );
    3434
    3535}
Note: See TracChangeset for help on using the changeset viewer.