Changes in / [5518719:26fd986]
- Location:
- src
- Files:
-
- 4 edited
-
ControlStruct/LabelFixer.cc (modified) (3 diffs)
-
ControlStruct/MLEMutator.cc (modified) (16 diffs)
-
ControlStruct/MLEMutator.h (modified) (2 diffs)
-
SynTree/Statement.cc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/LabelFixer.cc
r5518719 r26fd986 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Tue Jan 21 10:32:00 202013 // Update Count : 1 6011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Mar 11 22:26:02 2019 13 // Update Count : 159 14 14 // 15 15 … … 21 21 #include "ControlStruct/LabelGenerator.h" // for LabelGenerator 22 22 #include "LabelFixer.h" 23 #include "MLEMutator.h" // for M ultiLevelExitMutator23 #include "MLEMutator.h" // for MLEMutator 24 24 #include "SynTree/Declaration.h" // for FunctionDecl 25 25 #include "SynTree/Expression.h" // for NameExpr, Expression, Unty... … … 44 44 45 45 void LabelFixer::postvisit( FunctionDecl * functionDecl ) { 46 PassVisitor<M ultiLevelExitMutator> mlem( resolveJumps(), generator );47 functionDecl->acceptMutator( mlem );46 PassVisitor<MLEMutator> mlemut( resolveJumps(), generator ); 47 functionDecl->acceptMutator( mlemut ); 48 48 } 49 49 -
src/ControlStruct/MLEMutator.cc
r5518719 r26fd986 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : T ue Jan 21 10:33:00 202013 // Update Count : 22 212 // Last Modified On : Thr Jan 16 15:33:00 2020 13 // Update Count : 221 14 14 // 15 15 … … 33 33 34 34 namespace ControlStruct { 35 M ultiLevelExitMutator::~MultiLevelExitMutator() {35 MLEMutator::~MLEMutator() { 36 36 delete targetTable; 37 37 targetTable = 0; 38 38 } 39 39 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 ); } 61 47 } // namespace 62 48 … … 64 50 // through the breakLabel field tha they need a place to jump to on a break statement, add the break label to the 65 51 // body of statements 66 void M ultiLevelExitMutator::fixBlock( std::list< Statement * > &kids, bool caseClause ) {52 void MLEMutator::fixBlock( std::list< Statement * > &kids, bool caseClause ) { 67 53 SemanticErrorException errors; 68 54 … … 95 81 } 96 82 97 void M ultiLevelExitMutator::premutate( CompoundStmt *cmpndStmt ) {83 void MLEMutator::premutate( CompoundStmt *cmpndStmt ) { 98 84 visit_children = false; 99 85 bool labeledBlock = !(cmpndStmt->labels.empty()); … … 132 118 } 133 119 } 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 ) { 141 125 std::string originalTarget = branchStmt->originalTarget; 142 126 … … 246 230 } 247 231 248 Statement *M ultiLevelExitMutator::mutateLoop( Statement *bodyLoop, Entry &e ) {232 Statement *MLEMutator::mutateLoop( Statement *bodyLoop, Entry &e ) { 249 233 // only generate these when needed 250 234 if( !e.isContUsed() && !e.isBreakUsed() ) return bodyLoop; … … 269 253 270 254 template< typename LoopClass > 271 void M ultiLevelExitMutator::prehandleLoopStmt( LoopClass * loopStmt ) {255 void MLEMutator::prehandleLoopStmt( LoopClass * loopStmt ) { 272 256 // remember this as the most recent enclosing loop, then mutate the body of the loop -- this will determine 273 257 // whether brkLabel and contLabel are used with branch statements and will recursively do the same to nested … … 280 264 281 265 template< typename LoopClass > 282 Statement * M ultiLevelExitMutator::posthandleLoopStmt( LoopClass * loopStmt ) {266 Statement * MLEMutator::posthandleLoopStmt( LoopClass * loopStmt ) { 283 267 assert( ! enclosingControlStructures.empty() ); 284 268 Entry &e = enclosingControlStructures.back(); … … 291 275 } 292 276 293 void M ultiLevelExitMutator::premutate( WhileStmt * whileStmt ) {277 void MLEMutator::premutate( WhileStmt * whileStmt ) { 294 278 return prehandleLoopStmt( whileStmt ); 295 279 } 296 280 297 void M ultiLevelExitMutator::premutate( ForStmt * forStmt ) {281 void MLEMutator::premutate( ForStmt * forStmt ) { 298 282 return prehandleLoopStmt( forStmt ); 299 283 } 300 284 301 Statement * M ultiLevelExitMutator::postmutate( WhileStmt * whileStmt ) {285 Statement * MLEMutator::postmutate( WhileStmt * whileStmt ) { 302 286 return posthandleLoopStmt( whileStmt ); 303 287 } 304 288 305 Statement * M ultiLevelExitMutator::postmutate( ForStmt * forStmt ) {289 Statement * MLEMutator::postmutate( ForStmt * forStmt ) { 306 290 return posthandleLoopStmt( forStmt ); 307 291 } 308 292 309 void M ultiLevelExitMutator::premutate( IfStmt * ifStmt ) {293 void MLEMutator::premutate( IfStmt * ifStmt ) { 310 294 // generate a label for breaking out of a labeled if 311 295 bool labeledBlock = !(ifStmt->get_labels().empty()); … … 317 301 } 318 302 319 Statement * M ultiLevelExitMutator::postmutate( IfStmt * ifStmt ) {303 Statement * MLEMutator::postmutate( IfStmt * ifStmt ) { 320 304 bool labeledBlock = !(ifStmt->get_labels().empty()); 321 305 if ( labeledBlock ) { … … 327 311 } 328 312 329 void M ultiLevelExitMutator::premutate( TryStmt * tryStmt ) {313 void MLEMutator::premutate( TryStmt * tryStmt ) { 330 314 // generate a label for breaking out of a labeled if 331 315 bool labeledBlock = !(tryStmt->get_labels().empty()); … … 337 321 } 338 322 339 Statement * M ultiLevelExitMutator::postmutate( TryStmt * tryStmt ) {323 Statement * MLEMutator::postmutate( TryStmt * tryStmt ) { 340 324 bool labeledBlock = !(tryStmt->get_labels().empty()); 341 325 if ( labeledBlock ) { … … 347 331 } 348 332 349 void M ultiLevelExitMutator::premutate( FinallyStmt * ) {333 void MLEMutator::premutate( FinallyStmt * ) { 350 334 GuardAction([this, old = std::move(enclosingControlStructures)]() { 351 335 enclosingControlStructures = std::move(old); … … 354 338 } 355 339 356 void M ultiLevelExitMutator::premutate( CaseStmt *caseStmt ) {340 void MLEMutator::premutate( CaseStmt *caseStmt ) { 357 341 visit_children = false; 358 342 … … 393 377 } 394 378 395 void M ultiLevelExitMutator::premutate( SwitchStmt *switchStmt ) {379 void MLEMutator::premutate( SwitchStmt *switchStmt ) { 396 380 // generate a label for breaking out of a labeled switch 397 381 Label brkLabel = generator->newLabel("switchBreak", switchStmt); … … 419 403 } 420 404 421 Statement * M ultiLevelExitMutator::postmutate( SwitchStmt * switchStmt ) {405 Statement * MLEMutator::postmutate( SwitchStmt * switchStmt ) { 422 406 Entry &e = enclosingControlStructures.back(); 423 407 assert ( e == switchStmt ); -
src/ControlStruct/MLEMutator.h
r5518719 r26fd986 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : T ue Jan 21 10:33:00 202013 // Update Count : 4 712 // Last Modified On : Thr Jan 16 12:46:00 2020 13 // Update Count : 46 14 14 // 15 16 // Can anyone figure out what MLE stands for? 15 17 16 18 #pragma once … … 30 32 class LabelGenerator; 31 33 32 class MultiLevelExitMutator : public WithVisitorRef<MultiLevelExitMutator>, 33 public WithShortCircuiting, public WithGuards { 34 class MLEMutator : public WithVisitorRef<MLEMutator>, public WithShortCircuiting, public WithGuards { 34 35 public: 35 36 class Entry; 36 MultiLevelExitMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : 37 targetTable( t ), breakLabel(std::string("")), generator( gen ) {} 38 ~MultiLevelExitMutator(); 37 MLEMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : targetTable( t ), breakLabel(std::string("")), generator( gen ) {} 38 ~MLEMutator(); 39 39 40 40 void premutate( CompoundStmt *cmpndStmt ); -
src/SynTree/Statement.cc
r5518719 r26fd986 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Mon Jan 20 16:03:00202013 // Update Count : 7 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jan 10 14:20:47 2020 13 // Update Count : 70 14 14 // 15 15 … … 101 101 102 102 103 const char * BranchStmt::brType[] = { 104 "Goto", "Break", "Continue", "Fall Through", "Fall Through Default", 105 }; 103 const char * BranchStmt::brType[] = { "Goto", "Break", "Continue" }; 106 104 107 105 BranchStmt::BranchStmt( Label target, Type type ) throw ( SemanticErrorException ) : … … 121 119 122 120 void BranchStmt::print( std::ostream & os, Indenter indent ) const { 123 assert(type < 5);124 121 os << "Branch (" << brType[type] << ")" << endl ; 125 122 if ( target != "" ) os << indent+1 << "with target: " << target << endl;
Note:
See TracChangeset
for help on using the changeset viewer.