Changeset 3e5db5b4 for src


Ignore:
Timestamp:
Feb 1, 2022, 12:03:50 PM (3 years ago)
Author:
caparsons <caparson@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
34c32f0
Parents:
cef7430
Message:

added comments to loop portion of pass

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/MultiLevelExit.cpp

    rcef7430 r3e5db5b4  
    7272        bool isFallDefaultTarget() const { return SwitchStmt == kind; }
    7373
     74        // These routines set a target as being "used" by a BranchStmt
    7475        ast::Label useContExit() { assert( kind <= WhileStmt ); return useTarget(secondTarget); }
    7576        ast::Label useBreakExit() { assert( CaseStmt != kind ); return useTarget(firstTarget); }
     
    7778        ast::Label useFallDefaultExit() { assert( SwitchStmt == kind ); return useTarget(secondTarget); }
    7879
     80        // These routines check if a specific label for a statement is used by a BranchStmt
    7981        bool isContUsed() const { assert( kind <= WhileStmt ); return secondTarget.used; }
    8082        bool isBreakUsed() const { assert( CaseStmt != kind ); return firstTarget.used; }
     
    165167                const ast::CompoundStmt * stmt ) {
    166168        visit_children = false;
     169
     170        // if the stmt is labelled then generate a label to check in postvisit if the label is used
    167171        bool isLabeled = !stmt->labels.empty();
    168172        if ( isLabeled ) {
     
    218222}
    219223
     224// This routine updates targets on enclosing control structures to indicate which
     225//     label is used by the BranchStmt that is passed
    220226const ast::BranchStmt * MultiLevelExitCore::postvisit( const ast::BranchStmt * stmt ) {
    221227        std::vector<Entry>::reverse_iterator targetEntry =
    222228                enclosing_control_structures.rend();
     229
     230        // Labels on different stmts require different approaches to access
    223231        switch ( stmt->kind ) {
    224232        case ast::BranchStmt::Goto:
     
    257265                break;
    258266        }
     267        // handle fallthrough in case/switch stmts
    259268        case ast::BranchStmt::FallThrough: {
    260269                targetEntry = findEnclosingControlStructure( isFallthroughTarget );
     
    534543        }
    535544
     545        // if continue is used insert a continue label into the back of the body of the loop
    536546        if ( entry.isContUsed() ) {
    537547                ast::CompoundStmt * new_body = new ast::CompoundStmt( body->location );
     548                // {}
    538549                new_body->kids.push_back( body );
     550                // {
     551                //  body
     552                // }
    539553                new_body->kids.push_back(
    540554                        labelledNullStmt( body->location, entry.useContExit() ) );
     555                // {
     556                //  body
     557                //  ContinueLabel: {}
     558                // }
    541559                return new_body;
    542560        }
     
    552570        ast::Label contLabel = LabelGenerator::newLabel( "loopContinue", loopStmt );
    553571        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
    554576        GuardAction( [this](){ enclosing_control_structures.pop_back(); } );
    555577}
     
    564586        return ast::mutate_field(
    565587                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
    566591}
    567592
Note: See TracChangeset for help on using the changeset viewer.