Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/MLEMutator.cc

    r5cdeecd rd62806c  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Jan 21 10:33:00 2020
    13 // Update Count     : 222
     12// Last Modified On : Thr Jan 16 15:33:00 2020
     13// Update Count     : 221
    1414//
    1515
     
    3333
    3434namespace ControlStruct {
    35         MultiLevelExitMutator::~MultiLevelExitMutator() {
     35        MLEMutator::~MLEMutator() {
    3636                delete targetTable;
    3737                targetTable = 0;
    3838        }
    3939        namespace {
    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                 }
     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 ); }
    6147        } // namespace
    6248
     
    6450        // through the breakLabel field tha they need a place to jump to on a break statement, add the break label to the
    6551        // body of statements
    66         void MultiLevelExitMutator::fixBlock( std::list< Statement * > &kids, bool caseClause ) {
     52        void MLEMutator::fixBlock( std::list< Statement * > &kids, bool caseClause ) {
    6753                SemanticErrorException errors;
    6854
     
    9581        }
    9682
    97         void MultiLevelExitMutator::premutate( CompoundStmt *cmpndStmt ) {
     83        void MLEMutator::premutate( CompoundStmt *cmpndStmt ) {
    9884                visit_children = false;
    9985                bool labeledBlock = !(cmpndStmt->labels.empty());
     
    132118                        }
    133119                }
    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 ) {
     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 ) {
    141125                std::string originalTarget = branchStmt->originalTarget;
    142126
     
    246230        }
    247231
    248         Statement *MultiLevelExitMutator::mutateLoop( Statement *bodyLoop, Entry &e ) {
     232        Statement *MLEMutator::mutateLoop( Statement *bodyLoop, Entry &e ) {
    249233                // only generate these when needed
    250234                if( !e.isContUsed() && !e.isBreakUsed() ) return bodyLoop;
     
    269253
    270254        template< typename LoopClass >
    271         void MultiLevelExitMutator::prehandleLoopStmt( LoopClass * loopStmt ) {
     255        void MLEMutator::prehandleLoopStmt( LoopClass * loopStmt ) {
    272256                // remember this as the most recent enclosing loop, then mutate the body of the loop -- this will determine
    273257                // whether brkLabel and contLabel are used with branch statements and will recursively do the same to nested
     
    280264
    281265        template< typename LoopClass >
    282         Statement * MultiLevelExitMutator::posthandleLoopStmt( LoopClass * loopStmt ) {
     266        Statement * MLEMutator::posthandleLoopStmt( LoopClass * loopStmt ) {
    283267                assert( ! enclosingControlStructures.empty() );
    284268                Entry &e = enclosingControlStructures.back();
     
    291275        }
    292276
    293         void MultiLevelExitMutator::premutate( WhileStmt * whileStmt ) {
     277        void MLEMutator::premutate( WhileStmt * whileStmt ) {
    294278                return prehandleLoopStmt( whileStmt );
    295279        }
    296280
    297         void MultiLevelExitMutator::premutate( ForStmt * forStmt ) {
     281        void MLEMutator::premutate( ForStmt * forStmt ) {
    298282                return prehandleLoopStmt( forStmt );
    299283        }
    300284
    301         Statement * MultiLevelExitMutator::postmutate( WhileStmt * whileStmt ) {
     285        Statement * MLEMutator::postmutate( WhileStmt * whileStmt ) {
    302286                return posthandleLoopStmt( whileStmt );
    303287        }
    304288
    305         Statement * MultiLevelExitMutator::postmutate( ForStmt * forStmt ) {
     289        Statement * MLEMutator::postmutate( ForStmt * forStmt ) {
    306290                return posthandleLoopStmt( forStmt );
    307291        }
    308292
    309         void MultiLevelExitMutator::premutate( IfStmt * ifStmt ) {
     293        void MLEMutator::premutate( IfStmt * ifStmt ) {
    310294                // generate a label for breaking out of a labeled if
    311295                bool labeledBlock = !(ifStmt->get_labels().empty());
     
    317301        }
    318302
    319         Statement * MultiLevelExitMutator::postmutate( IfStmt * ifStmt ) {
     303        Statement * MLEMutator::postmutate( IfStmt * ifStmt ) {
    320304                bool labeledBlock = !(ifStmt->get_labels().empty());
    321305                if ( labeledBlock ) {
     
    327311        }
    328312
    329         void MultiLevelExitMutator::premutate( TryStmt * tryStmt ) {
     313        void MLEMutator::premutate( TryStmt * tryStmt ) {
    330314                // generate a label for breaking out of a labeled if
    331315                bool labeledBlock = !(tryStmt->get_labels().empty());
     
    337321        }
    338322
    339         Statement * MultiLevelExitMutator::postmutate( TryStmt * tryStmt ) {
     323        Statement * MLEMutator::postmutate( TryStmt * tryStmt ) {
    340324                bool labeledBlock = !(tryStmt->get_labels().empty());
    341325                if ( labeledBlock ) {
     
    347331        }
    348332
    349         void MultiLevelExitMutator::premutate( FinallyStmt * ) {
     333        void MLEMutator::premutate( FinallyStmt * ) {
    350334                GuardAction([this, old = std::move(enclosingControlStructures)]() {
    351335                        enclosingControlStructures = std::move(old);
     
    354338        }
    355339
    356         void MultiLevelExitMutator::premutate( CaseStmt *caseStmt ) {
     340        void MLEMutator::premutate( CaseStmt *caseStmt ) {
    357341                visit_children = false;
    358342
     
    393377        }
    394378
    395         void MultiLevelExitMutator::premutate( SwitchStmt *switchStmt ) {
     379        void MLEMutator::premutate( SwitchStmt *switchStmt ) {
    396380                // generate a label for breaking out of a labeled switch
    397381                Label brkLabel = generator->newLabel("switchBreak", switchStmt);
     
    419403        }
    420404
    421         Statement * MultiLevelExitMutator::postmutate( SwitchStmt * switchStmt ) {
     405        Statement * MLEMutator::postmutate( SwitchStmt * switchStmt ) {
    422406                Entry &e = enclosingControlStructures.back();
    423407                assert ( e == switchStmt );
Note: See TracChangeset for help on using the changeset viewer.