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