- File:
-
- 1 edited
-
src/ControlStruct/MLEMutator.cc (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/MLEMutator.cc
rbe5aa1b r843054c2 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Wed May 27 16:19:32201513 // Update Count : 4411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:32:26 2015 13 // Update Count : 2 14 14 // 15 15 … … 28 28 CompoundStmt* MLEMutator::mutate( CompoundStmt *cmpndStmt ) { 29 29 bool labeledBlock = false; 30 if ( !( cmpndStmt->get_labels().empty()) ) {30 if ( !((cmpndStmt->get_labels()).empty()) ) { 31 31 labeledBlock = true; 32 32 enclosingBlocks.push_back( Entry( cmpndStmt ) ); … … 42 42 std::list<Label> ls; ls.push_back( get_breakLabel() ); 43 43 kids.push_back( new NullStmt( ls ) ); 44 } else {44 } else 45 45 (*next)->get_labels().push_back( get_breakLabel() ); 46 }47 46 48 47 set_breakLabel(""); … … 52 51 if ( labeledBlock ) { 53 52 assert( ! enclosingBlocks.empty() ); 54 if ( ! enclosingBlocks.back().get_breakExit().empty() ) {53 if ( ! enclosingBlocks.back().get_breakExit().empty() ) 55 54 set_breakLabel( enclosingBlocks.back().get_breakExit() ); 56 }57 55 enclosingBlocks.pop_back(); 58 56 } // if … … 87 85 88 86 Statement *MLEMutator::mutate( BranchStmt *branchStmt ) throw ( SemanticError ) { 89 std::string originalTarget = branchStmt->get_originalTarget();90 91 87 if ( branchStmt->get_type() == BranchStmt::Goto ) 92 88 return branchStmt; 93 89 94 90 // test if continue target is a loop 95 if ( branchStmt->get_type() == BranchStmt::Continue) { 96 if ( enclosingLoops.empty() ) { 97 throw SemanticError( "'continue' outside a loop" ); 98 } else if ( std::find( enclosingLoops.begin(), enclosingLoops.end(), (*targetTable)[branchStmt->get_target()] ) == enclosingLoops.end() ) { 99 throw SemanticError( "'continue' target label must be an enclosing loop: " + originalTarget ); 100 } 101 } 91 if ( branchStmt->get_type() == BranchStmt::Continue && enclosingLoops.empty() ) 92 throw SemanticError( "'continue' outside a loop" ); 102 93 103 94 if ( branchStmt->get_type() == BranchStmt::Break && (enclosingLoops.empty() && enclosingSwitches.empty() && enclosingBlocks.empty() ) ) … … 107 98 108 99 if ( targetTable->find( branchStmt->get_target() ) == targetTable->end() ) 109 throw SemanticError("The label defined in the exit loop statement does not exist : " + originalTarget); // shouldn't happen (since that's already checked)100 throw SemanticError("The label defined in the exit loop statement does not exist." ); // shouldn't happen (since that's already checked) 110 101 111 102 std::list< Entry >::iterator check; … … 115 106 // neither in loop nor in block, checking if in switch/choose 116 107 if ( (check = std::find( enclosingSwitches.begin(), enclosingSwitches.end(), (*targetTable)[branchStmt->get_target()] )) == enclosingSwitches.end() ) 117 throw SemanticError("The target specified in the exit loop statement does not correspond to an enclosing control structure: " + originalTarget);108 throw SemanticError("The target specified in the exit loop statement does not correspond to an enclosing loop."); 118 109 119 110 if ( enclosingLoops.back() == (*check) ) … … 123 114 switch ( branchStmt->get_type() ) { 124 115 case BranchStmt::Break: 125 if ( check->get_breakExit() != "" ) {126 newLabel = check->get_breakExit();127 }else {128 newLabel = generator->newLabel();129 check->set_breakExit( newLabel );130 } // if131 break;116 if ( check->get_breakExit() != "" ) 117 newLabel = check->get_breakExit(); 118 else { 119 newLabel = generator->newLabel(); 120 check->set_breakExit( newLabel ); 121 } // if 122 break; 132 123 case BranchStmt::Continue: 133 if ( check->get_contExit() != "" ) {134 newLabel = check->get_contExit();135 }else {136 newLabel = generator->newLabel();137 check->set_contExit( newLabel );138 } // if139 break;124 if ( check->get_contExit() != "" ) 125 newLabel = check->get_contExit(); 126 else { 127 newLabel = generator->newLabel(); 128 check->set_contExit( newLabel ); 129 } // if 130 break; 140 131 default: 141 return 0; // shouldn't be here132 return 0; // shouldn't be here 142 133 } // switch 143 134 … … 145 136 } 146 137 147 template< typename SwitchClass > 148 Statement *handleSwitchStmt( SwitchClass *switchStmt, MLEMutator &mutator ) { 149 // set up some aliases so that the rest of the code isn't messy 150 typedef MLEMutator::Entry Entry; 151 LabelGenerator *generator = mutator.generator; 152 std::list< Entry > &enclosingSwitches = mutator.enclosingSwitches; 153 138 139 Statement *MLEMutator::mutate( SwitchStmt *switchStmt ) { 154 140 Label brkLabel = generator->newLabel(); 155 141 enclosingSwitches.push_back( Entry(switchStmt, "", brkLabel) ); 156 mutateAll( switchStmt->get_branches(), mutator); {142 mutateAll( switchStmt->get_branches(), *this ); { 157 143 // check if this is necessary (if there is a break to this point, otherwise do not generate 158 144 std::list<Label> temp; temp.push_back( brkLabel ); … … 164 150 } 165 151 166 Statement *MLEMutator::mutate( SwitchStmt *switchStmt ) {167 return handleSwitchStmt( switchStmt, *this );168 }169 170 152 Statement *MLEMutator::mutate( ChooseStmt *switchStmt ) { 171 return handleSwitchStmt( switchStmt, *this ); 153 Label brkLabel = generator->newLabel(); 154 enclosingSwitches.push_back( Entry(switchStmt,"", brkLabel) ); 155 mutateAll( switchStmt->get_branches(), *this ); { 156 // check if this is necessary (if there is a break to this point, otherwise do not generate 157 std::list<Label> temp; temp.push_back( brkLabel ); 158 switchStmt->get_branches().push_back( new BranchStmt( temp, Label(""), BranchStmt::Break ) ); 159 } 160 assert ( enclosingSwitches.back() == switchStmt ); 161 enclosingSwitches.pop_back(); 162 return switchStmt; 172 163 } 173 164
Note:
See TracChangeset
for help on using the changeset viewer.