Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/MLEMutator.cc

    r9d6317f r397c101a  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Jan 22 11:50:00 2020
    13 // Update Count     : 223
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Oct 22 17:22:44 2019
     13// Update Count     : 220
    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
    62 
    63         void MultiLevelExitMutator::premutate( FunctionDecl * ) {
    64                 visit_children = false;
    65         }
    6648
    6749        // break labels have to come after the statement they break out of, so mutate a statement, then if they inform us
    6850        // through the breakLabel field tha they need a place to jump to on a break statement, add the break label to the
    6951        // body of statements
    70         void MultiLevelExitMutator::fixBlock( std::list< Statement * > &kids, bool caseClause ) {
     52        void MLEMutator::fixBlock( std::list< Statement * > &kids, bool caseClause ) {
    7153                SemanticErrorException errors;
    7254
     
    9981        }
    10082
    101         void MultiLevelExitMutator::premutate( CompoundStmt *cmpndStmt ) {
     83        void MLEMutator::premutate( CompoundStmt *cmpndStmt ) {
    10284                visit_children = false;
    10385                bool labeledBlock = !(cmpndStmt->labels.empty());
     
    136118                        }
    137119                }
    138                 assertf( false, "Could not find label '%s' on statement %s",
    139                         originalTarget.get_name().c_str(), toString( stmt ).c_str() );
    140         }
    141 
    142 
    143         Statement *MultiLevelExitMutator::postmutate( BranchStmt *branchStmt )
    144                         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 ) {
    145125                std::string originalTarget = branchStmt->originalTarget;
    146126
     
    250230        }
    251231
    252         Statement *MultiLevelExitMutator::mutateLoop( Statement *bodyLoop, Entry &e ) {
     232        Statement *MLEMutator::mutateLoop( Statement *bodyLoop, Entry &e ) {
    253233                // only generate these when needed
    254234                if( !e.isContUsed() && !e.isBreakUsed() ) return bodyLoop;
     
    273253
    274254        template< typename LoopClass >
    275         void MultiLevelExitMutator::prehandleLoopStmt( LoopClass * loopStmt ) {
     255        void MLEMutator::prehandleLoopStmt( LoopClass * loopStmt ) {
    276256                // remember this as the most recent enclosing loop, then mutate the body of the loop -- this will determine
    277257                // whether brkLabel and contLabel are used with branch statements and will recursively do the same to nested
     
    284264
    285265        template< typename LoopClass >
    286         Statement * MultiLevelExitMutator::posthandleLoopStmt( LoopClass * loopStmt ) {
     266        Statement * MLEMutator::posthandleLoopStmt( LoopClass * loopStmt ) {
    287267                assert( ! enclosingControlStructures.empty() );
    288268                Entry &e = enclosingControlStructures.back();
     
    295275        }
    296276
    297         void MultiLevelExitMutator::premutate( WhileStmt * whileStmt ) {
     277        void MLEMutator::premutate( WhileStmt * whileStmt ) {
    298278                return prehandleLoopStmt( whileStmt );
    299279        }
    300280
    301         void MultiLevelExitMutator::premutate( ForStmt * forStmt ) {
     281        void MLEMutator::premutate( ForStmt * forStmt ) {
    302282                return prehandleLoopStmt( forStmt );
    303283        }
    304284
    305         Statement * MultiLevelExitMutator::postmutate( WhileStmt * whileStmt ) {
     285        Statement * MLEMutator::postmutate( WhileStmt * whileStmt ) {
    306286                return posthandleLoopStmt( whileStmt );
    307287        }
    308288
    309         Statement * MultiLevelExitMutator::postmutate( ForStmt * forStmt ) {
     289        Statement * MLEMutator::postmutate( ForStmt * forStmt ) {
    310290                return posthandleLoopStmt( forStmt );
    311291        }
    312292
    313         void MultiLevelExitMutator::premutate( IfStmt * ifStmt ) {
     293        void MLEMutator::premutate( IfStmt * ifStmt ) {
    314294                // generate a label for breaking out of a labeled if
    315295                bool labeledBlock = !(ifStmt->get_labels().empty());
     
    321301        }
    322302
    323         Statement * MultiLevelExitMutator::postmutate( IfStmt * ifStmt ) {
     303        Statement * MLEMutator::postmutate( IfStmt * ifStmt ) {
    324304                bool labeledBlock = !(ifStmt->get_labels().empty());
    325305                if ( labeledBlock ) {
     
    331311        }
    332312
    333         void MultiLevelExitMutator::premutate( TryStmt * tryStmt ) {
     313        void MLEMutator::premutate( TryStmt * tryStmt ) {
    334314                // generate a label for breaking out of a labeled if
    335315                bool labeledBlock = !(tryStmt->get_labels().empty());
     
    341321        }
    342322
    343         Statement * MultiLevelExitMutator::postmutate( TryStmt * tryStmt ) {
     323        Statement * MLEMutator::postmutate( TryStmt * tryStmt ) {
    344324                bool labeledBlock = !(tryStmt->get_labels().empty());
    345325                if ( labeledBlock ) {
     
    351331        }
    352332
    353         void MultiLevelExitMutator::premutate( FinallyStmt * ) {
    354                 GuardAction([this, old = std::move(enclosingControlStructures)]() {
    355                         enclosingControlStructures = std::move(old);
    356                 });
    357                 enclosingControlStructures = std::list<Entry>();
    358                 GuardValue( inFinally );
    359                 inFinally = true;
    360         }
    361 
    362         void MultiLevelExitMutator::premutate( ReturnStmt *returnStmt ) {
    363                 if ( inFinally ) {
    364                         SemanticError( returnStmt->location, "'return' may not appear in a finally clause" );
    365                 }
    366         }
    367 
    368         void MultiLevelExitMutator::premutate( CaseStmt *caseStmt ) {
     333        void MLEMutator::premutate( CaseStmt *caseStmt ) {
    369334                visit_children = false;
    370335
     
    405370        }
    406371
    407         void MultiLevelExitMutator::premutate( SwitchStmt *switchStmt ) {
     372        void MLEMutator::premutate( SwitchStmt *switchStmt ) {
    408373                // generate a label for breaking out of a labeled switch
    409374                Label brkLabel = generator->newLabel("switchBreak", switchStmt);
     
    431396        }
    432397
    433         Statement * MultiLevelExitMutator::postmutate( SwitchStmt * switchStmt ) {
     398        Statement * MLEMutator::postmutate( SwitchStmt * switchStmt ) {
    434399                Entry &e = enclosingControlStructures.back();
    435400                assert ( e == switchStmt );
Note: See TracChangeset for help on using the changeset viewer.