Ignore:
Timestamp:
Jan 21, 2020, 6:14:40 PM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
9d6317f
Parents:
26fd986 (diff), 5cdeecd (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/MLEMutator.cc

    r26fd986 r5518719  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Jan 16 15:33:00 2020
    13 // Update Count     : 221
     12// Last Modified On : Tue Jan 21 10:33:00 2020
     13// Update Count     : 222
    1414//
    1515
     
    3333
    3434namespace ControlStruct {
    35         MLEMutator::~MLEMutator() {
     35        MultiLevelExitMutator::~MultiLevelExitMutator() {
    3636                delete targetTable;
    3737                targetTable = 0;
    3838        }
    3939        namespace {
    40                 bool isLoop( const MLEMutator::Entry & e ) { return dynamic_cast< WhileStmt * >( e.get_controlStructure() ) || dynamic_cast< ForStmt * >( e.get_controlStructure() ); }
    41                 bool isSwitch( const MLEMutator::Entry & e ) { return dynamic_cast< SwitchStmt *>( e.get_controlStructure() ); }
    42 
    43                 bool isBreakTarget( const MLEMutator::Entry & e ) { return isLoop( e ) || isSwitch( e ) || dynamic_cast< CompoundStmt *>( e.get_controlStructure() ); }
    44                 bool isContinueTarget( const MLEMutator::Entry & e ) { return isLoop( e ); }
    45                 bool isFallthroughTarget( const MLEMutator::Entry & e ) { return dynamic_cast< CaseStmt *>( e.get_controlStructure() );; }
    46                 bool isFallthroughDefaultTarget( const MLEMutator::Entry & e ) { return isSwitch( e ); }
     40                bool isLoop( const MultiLevelExitMutator::Entry & e ) {
     41                        return dynamic_cast< WhileStmt * >( e.get_controlStructure() )
     42                                || dynamic_cast< ForStmt * >( e.get_controlStructure() );
     43                }
     44                bool isSwitch( const MultiLevelExitMutator::Entry & e ) {
     45                        return dynamic_cast< SwitchStmt *>( e.get_controlStructure() );
     46                }
     47
     48                bool isBreakTarget( const MultiLevelExitMutator::Entry & e ) {
     49                        return isLoop( e ) || isSwitch( e )
     50                                || dynamic_cast< CompoundStmt *>( e.get_controlStructure() );
     51                }
     52                bool isContinueTarget( const MultiLevelExitMutator::Entry & e ) {
     53                        return isLoop( e );
     54                }
     55                bool isFallthroughTarget( const MultiLevelExitMutator::Entry & e ) {
     56                        return dynamic_cast< CaseStmt *>( e.get_controlStructure() );
     57                }
     58                bool isFallthroughDefaultTarget( const MultiLevelExitMutator::Entry & e ) {
     59                        return isSwitch( e );
     60                }
    4761        } // namespace
    4862
     
    5064        // through the breakLabel field tha they need a place to jump to on a break statement, add the break label to the
    5165        // body of statements
    52         void MLEMutator::fixBlock( std::list< Statement * > &kids, bool caseClause ) {
     66        void MultiLevelExitMutator::fixBlock( std::list< Statement * > &kids, bool caseClause ) {
    5367                SemanticErrorException errors;
    5468
     
    8195        }
    8296
    83         void MLEMutator::premutate( CompoundStmt *cmpndStmt ) {
     97        void MultiLevelExitMutator::premutate( CompoundStmt *cmpndStmt ) {
    8498                visit_children = false;
    8599                bool labeledBlock = !(cmpndStmt->labels.empty());
     
    118132                        }
    119133                }
    120                 assertf( false, "Could not find label '%s' on statement %s", originalTarget.get_name().c_str(), toString( stmt ).c_str() );
    121         }
    122 
    123 
    124         Statement *MLEMutator::postmutate( BranchStmt *branchStmt ) throw ( SemanticErrorException ) {
     134                assertf( false, "Could not find label '%s' on statement %s",
     135                        originalTarget.get_name().c_str(), toString( stmt ).c_str() );
     136        }
     137
     138
     139        Statement *MultiLevelExitMutator::postmutate( BranchStmt *branchStmt )
     140                        throw ( SemanticErrorException ) {
    125141                std::string originalTarget = branchStmt->originalTarget;
    126142
     
    230246        }
    231247
    232         Statement *MLEMutator::mutateLoop( Statement *bodyLoop, Entry &e ) {
     248        Statement *MultiLevelExitMutator::mutateLoop( Statement *bodyLoop, Entry &e ) {
    233249                // only generate these when needed
    234250                if( !e.isContUsed() && !e.isBreakUsed() ) return bodyLoop;
     
    253269
    254270        template< typename LoopClass >
    255         void MLEMutator::prehandleLoopStmt( LoopClass * loopStmt ) {
     271        void MultiLevelExitMutator::prehandleLoopStmt( LoopClass * loopStmt ) {
    256272                // remember this as the most recent enclosing loop, then mutate the body of the loop -- this will determine
    257273                // whether brkLabel and contLabel are used with branch statements and will recursively do the same to nested
     
    264280
    265281        template< typename LoopClass >
    266         Statement * MLEMutator::posthandleLoopStmt( LoopClass * loopStmt ) {
     282        Statement * MultiLevelExitMutator::posthandleLoopStmt( LoopClass * loopStmt ) {
    267283                assert( ! enclosingControlStructures.empty() );
    268284                Entry &e = enclosingControlStructures.back();
     
    275291        }
    276292
    277         void MLEMutator::premutate( WhileStmt * whileStmt ) {
     293        void MultiLevelExitMutator::premutate( WhileStmt * whileStmt ) {
    278294                return prehandleLoopStmt( whileStmt );
    279295        }
    280296
    281         void MLEMutator::premutate( ForStmt * forStmt ) {
     297        void MultiLevelExitMutator::premutate( ForStmt * forStmt ) {
    282298                return prehandleLoopStmt( forStmt );
    283299        }
    284300
    285         Statement * MLEMutator::postmutate( WhileStmt * whileStmt ) {
     301        Statement * MultiLevelExitMutator::postmutate( WhileStmt * whileStmt ) {
    286302                return posthandleLoopStmt( whileStmt );
    287303        }
    288304
    289         Statement * MLEMutator::postmutate( ForStmt * forStmt ) {
     305        Statement * MultiLevelExitMutator::postmutate( ForStmt * forStmt ) {
    290306                return posthandleLoopStmt( forStmt );
    291307        }
    292308
    293         void MLEMutator::premutate( IfStmt * ifStmt ) {
     309        void MultiLevelExitMutator::premutate( IfStmt * ifStmt ) {
    294310                // generate a label for breaking out of a labeled if
    295311                bool labeledBlock = !(ifStmt->get_labels().empty());
     
    301317        }
    302318
    303         Statement * MLEMutator::postmutate( IfStmt * ifStmt ) {
     319        Statement * MultiLevelExitMutator::postmutate( IfStmt * ifStmt ) {
    304320                bool labeledBlock = !(ifStmt->get_labels().empty());
    305321                if ( labeledBlock ) {
     
    311327        }
    312328
    313         void MLEMutator::premutate( TryStmt * tryStmt ) {
     329        void MultiLevelExitMutator::premutate( TryStmt * tryStmt ) {
    314330                // generate a label for breaking out of a labeled if
    315331                bool labeledBlock = !(tryStmt->get_labels().empty());
     
    321337        }
    322338
    323         Statement * MLEMutator::postmutate( TryStmt * tryStmt ) {
     339        Statement * MultiLevelExitMutator::postmutate( TryStmt * tryStmt ) {
    324340                bool labeledBlock = !(tryStmt->get_labels().empty());
    325341                if ( labeledBlock ) {
     
    331347        }
    332348
    333         void MLEMutator::premutate( FinallyStmt * ) {
     349        void MultiLevelExitMutator::premutate( FinallyStmt * ) {
    334350                GuardAction([this, old = std::move(enclosingControlStructures)]() {
    335351                        enclosingControlStructures = std::move(old);
     
    338354        }
    339355
    340         void MLEMutator::premutate( CaseStmt *caseStmt ) {
     356        void MultiLevelExitMutator::premutate( CaseStmt *caseStmt ) {
    341357                visit_children = false;
    342358
     
    377393        }
    378394
    379         void MLEMutator::premutate( SwitchStmt *switchStmt ) {
     395        void MultiLevelExitMutator::premutate( SwitchStmt *switchStmt ) {
    380396                // generate a label for breaking out of a labeled switch
    381397                Label brkLabel = generator->newLabel("switchBreak", switchStmt);
     
    403419        }
    404420
    405         Statement * MLEMutator::postmutate( SwitchStmt * switchStmt ) {
     421        Statement * MultiLevelExitMutator::postmutate( SwitchStmt * switchStmt ) {
    406422                Entry &e = enclosingControlStructures.back();
    407423                assert ( e == switchStmt );
Note: See TracChangeset for help on using the changeset viewer.