| [51587aa] | 1 | // | 
|---|
|  | 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo | 
|---|
|  | 3 | // | 
|---|
|  | 4 | // The contents of this file are covered under the licence agreement in the | 
|---|
|  | 5 | // file "LICENCE" distributed with Cforall. | 
|---|
|  | 6 | // | 
|---|
| [0f8e4ac] | 7 | // MLEMutator.h -- | 
|---|
| [51587aa] | 8 | // | 
|---|
| [843054c2] | 9 | // Author           : Rodolfo G. Esteves | 
|---|
| [51587aa] | 10 | // Created On       : Mon May 18 07:44:20 2015 | 
|---|
| [adcc065] | 11 | // Last Modified By : Peter A. Buhr | 
|---|
| [6b0b624] | 12 | // Last Modified On : Sat Jul 22 09:19:59 2017 | 
|---|
|  | 13 | // Update Count     : 35 | 
|---|
| [51587aa] | 14 | // | 
|---|
| [a08ba92] | 15 |  | 
|---|
| [6b0b624] | 16 | #pragma once | 
|---|
| [51b73452] | 17 |  | 
|---|
|  | 18 | #include <map> | 
|---|
|  | 19 | #include <list> | 
|---|
|  | 20 |  | 
|---|
| [d3b7937] | 21 | #include "Common/utility.h" | 
|---|
| [51b73452] | 22 | #include "SynTree/SynTree.h" | 
|---|
|  | 23 | #include "SynTree/Mutator.h" | 
|---|
| [0f8e4ac] | 24 | #include "SynTree/Label.h" | 
|---|
| [51b73452] | 25 |  | 
|---|
|  | 26 | #include "LabelGenerator.h" | 
|---|
|  | 27 |  | 
|---|
|  | 28 | namespace ControlStruct { | 
|---|
| [a08ba92] | 29 | class MLEMutator : public Mutator { | 
|---|
|  | 30 | class Entry; | 
|---|
| [adcc065] | 31 | typedef Mutator Parent; | 
|---|
| [d9a0e76] | 32 | public: | 
|---|
| [a08ba92] | 33 | MLEMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : targetTable( t ), breakLabel(std::string("")), generator( gen ) {} | 
|---|
|  | 34 | ~MLEMutator(); | 
|---|
| [d9a0e76] | 35 |  | 
|---|
| [6a37d13] | 36 | virtual CompoundStmt *mutate( CompoundStmt *cmpndStmt ) override; | 
|---|
| [adcc065] | 37 | virtual Statement *mutate( WhileStmt *whileStmt ) override; | 
|---|
|  | 38 | virtual Statement *mutate( ForStmt *forStmt ) override; | 
|---|
|  | 39 | virtual Statement *mutate( BranchStmt *branchStmt ) throw ( SemanticError ) override; | 
|---|
| [99f11dd] | 40 | virtual Statement *mutate( CaseStmt *caseStmt ) override; | 
|---|
| [adcc065] | 41 | virtual Statement *mutate( IfStmt *ifStmt ) override; | 
|---|
|  | 42 | virtual Statement *mutate( SwitchStmt *switchStmt ) override; | 
|---|
| [d9a0e76] | 43 |  | 
|---|
| [a08ba92] | 44 | Statement *mutateLoop( Statement *bodyLoop, Entry &e ); | 
|---|
| [d9a0e76] | 45 |  | 
|---|
| [a08ba92] | 46 | Label &get_breakLabel() { return breakLabel; } | 
|---|
|  | 47 | void set_breakLabel( Label newValue ) { breakLabel = newValue; } | 
|---|
|  | 48 | private: | 
|---|
|  | 49 | class Entry { | 
|---|
|  | 50 | public: | 
|---|
| [27de955] | 51 | explicit Entry( Statement *_loop, Label _breakExit, Label _contExit = Label("") ) : | 
|---|
|  | 52 | loop( _loop ), breakExit( _breakExit ), contExit( _contExit ), breakUsed(false), contUsed(false) {} | 
|---|
| [d9a0e76] | 53 |  | 
|---|
| [a08ba92] | 54 | bool operator==( const Statement *stmt ) { return ( loop == stmt ); } | 
|---|
|  | 55 | bool operator!=( const Statement *stmt ) { return ( loop != stmt ); } | 
|---|
| [d9a0e76] | 56 |  | 
|---|
| [e39aa0f] | 57 | bool operator==( const Entry &other ) { return ( loop == other.get_controlStructure() ); } | 
|---|
| [d9a0e76] | 58 |  | 
|---|
| [e39aa0f] | 59 | Statement *get_controlStructure() const { return loop; } | 
|---|
| [51b73452] | 60 |  | 
|---|
| [27de955] | 61 | Label useContExit() { contUsed = true; return contExit; } | 
|---|
|  | 62 | Label useBreakExit() { breakUsed = true; return breakExit; } | 
|---|
| [a08ba92] | 63 |  | 
|---|
| [27de955] | 64 | bool isContUsed() const { return contUsed; } | 
|---|
|  | 65 | bool isBreakUsed() const { return breakUsed; } | 
|---|
| [a08ba92] | 66 | private: | 
|---|
|  | 67 | Statement *loop; | 
|---|
| [27de955] | 68 | Label breakExit, contExit; | 
|---|
|  | 69 | bool breakUsed, contUsed; | 
|---|
| [a08ba92] | 70 | }; | 
|---|
|  | 71 |  | 
|---|
|  | 72 | std::map< Label, Statement * > *targetTable; | 
|---|
| [e39aa0f] | 73 | std::list< Entry > enclosingControlStructures; | 
|---|
| [a08ba92] | 74 | Label breakLabel; | 
|---|
|  | 75 | LabelGenerator *generator; | 
|---|
| [be5aa1b] | 76 |  | 
|---|
| [27de955] | 77 | template< typename LoopClass > | 
|---|
|  | 78 | Statement *handleLoopStmt( LoopClass *loopStmt ); | 
|---|
|  | 79 |  | 
|---|
| [adcc065] | 80 | template< typename IfClass > | 
|---|
|  | 81 | Statement *handleIfStmt( IfClass *switchStmt ); | 
|---|
|  | 82 |  | 
|---|
| [0f8e4ac] | 83 | template< typename SwitchClass > | 
|---|
| [27de955] | 84 | Statement *handleSwitchStmt( SwitchClass *switchStmt ); | 
|---|
|  | 85 |  | 
|---|
|  | 86 | void fixBlock( std::list< Statement * > &kids ); | 
|---|
| [a08ba92] | 87 | }; | 
|---|
| [51b73452] | 88 | } // namespace ControlStruct | 
|---|
|  | 89 |  | 
|---|
| [51587aa] | 90 | // Local Variables: // | 
|---|
|  | 91 | // tab-width: 4 // | 
|---|
|  | 92 | // mode: c++ // | 
|---|
|  | 93 | // compile-command: "make install" // | 
|---|
|  | 94 | // End: // | 
|---|