[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 |
|
---|
[d180746] | 18 | #include <list> // for list
|
---|
| 19 | #include <map> // for map
|
---|
| 20 | #include <string> // for string
|
---|
[51b73452] | 21 |
|
---|
[94e025a2] | 22 | #include "Common/PassVisitor.h"
|
---|
[d180746] | 23 | #include "Common/SemanticError.h" // for SemanticError
|
---|
| 24 | #include "SynTree/Label.h" // for Label
|
---|
| 25 | #include "SynTree/Mutator.h" // for Mutator
|
---|
| 26 | #include "SynTree/SynTree.h" // for Visitor Nodes
|
---|
[51b73452] | 27 |
|
---|
| 28 | namespace ControlStruct {
|
---|
[94e025a2] | 29 | class LabelGenerator;
|
---|
[d180746] | 30 |
|
---|
[94e025a2] | 31 | class MLEMutator : public WithVisitorRef<MLEMutator>, public WithShortCircuiting {
|
---|
[a08ba92] | 32 | class Entry;
|
---|
[d180746] | 33 |
|
---|
[d9a0e76] | 34 | public:
|
---|
[a08ba92] | 35 | MLEMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : targetTable( t ), breakLabel(std::string("")), generator( gen ) {}
|
---|
| 36 | ~MLEMutator();
|
---|
[d9a0e76] | 37 |
|
---|
[94e025a2] | 38 | void premutate( CompoundStmt *cmpndStmt );
|
---|
| 39 | Statement * postmutate( BranchStmt *branchStmt ) throw ( SemanticError );
|
---|
| 40 | void premutate( WhileStmt *whileStmt );
|
---|
| 41 | Statement * postmutate( WhileStmt *whileStmt );
|
---|
| 42 | void premutate( ForStmt *forStmt );
|
---|
| 43 | Statement * postmutate( ForStmt *forStmt );
|
---|
| 44 | void premutate( CaseStmt *caseStmt );
|
---|
| 45 | void premutate( IfStmt *ifStmt );
|
---|
| 46 | Statement * postmutate( IfStmt *ifStmt );
|
---|
| 47 | void premutate( SwitchStmt *switchStmt );
|
---|
| 48 | Statement * postmutate( SwitchStmt *switchStmt );
|
---|
[d9a0e76] | 49 |
|
---|
[a08ba92] | 50 | Statement *mutateLoop( Statement *bodyLoop, Entry &e );
|
---|
[d9a0e76] | 51 |
|
---|
[a08ba92] | 52 | Label &get_breakLabel() { return breakLabel; }
|
---|
| 53 | void set_breakLabel( Label newValue ) { breakLabel = newValue; }
|
---|
| 54 | private:
|
---|
| 55 | class Entry {
|
---|
| 56 | public:
|
---|
[27de955] | 57 | explicit Entry( Statement *_loop, Label _breakExit, Label _contExit = Label("") ) :
|
---|
| 58 | loop( _loop ), breakExit( _breakExit ), contExit( _contExit ), breakUsed(false), contUsed(false) {}
|
---|
[d9a0e76] | 59 |
|
---|
[94e025a2] | 60 | bool operator==( const Statement *stmt ) { return loop == stmt; }
|
---|
| 61 | bool operator!=( const Statement *stmt ) { return loop != stmt; }
|
---|
[d9a0e76] | 62 |
|
---|
[94e025a2] | 63 | bool operator==( const Entry &other ) { return loop == other.get_controlStructure(); }
|
---|
[d9a0e76] | 64 |
|
---|
[e39aa0f] | 65 | Statement *get_controlStructure() const { return loop; }
|
---|
[51b73452] | 66 |
|
---|
[27de955] | 67 | Label useContExit() { contUsed = true; return contExit; }
|
---|
| 68 | Label useBreakExit() { breakUsed = true; return breakExit; }
|
---|
[a08ba92] | 69 |
|
---|
[27de955] | 70 | bool isContUsed() const { return contUsed; }
|
---|
| 71 | bool isBreakUsed() const { return breakUsed; }
|
---|
[a08ba92] | 72 | private:
|
---|
| 73 | Statement *loop;
|
---|
[27de955] | 74 | Label breakExit, contExit;
|
---|
| 75 | bool breakUsed, contUsed;
|
---|
[a08ba92] | 76 | };
|
---|
| 77 |
|
---|
| 78 | std::map< Label, Statement * > *targetTable;
|
---|
[e39aa0f] | 79 | std::list< Entry > enclosingControlStructures;
|
---|
[a08ba92] | 80 | Label breakLabel;
|
---|
| 81 | LabelGenerator *generator;
|
---|
[be5aa1b] | 82 |
|
---|
[27de955] | 83 | template< typename LoopClass >
|
---|
[94e025a2] | 84 | void prehandleLoopStmt( LoopClass * loopStmt );
|
---|
[27de955] | 85 |
|
---|
[94e025a2] | 86 | template< typename LoopClass >
|
---|
| 87 | Statement * posthandleLoopStmt( LoopClass * loopStmt );
|
---|
[27de955] | 88 |
|
---|
| 89 | void fixBlock( std::list< Statement * > &kids );
|
---|
[a08ba92] | 90 | };
|
---|
[51b73452] | 91 | } // namespace ControlStruct
|
---|
| 92 |
|
---|
[51587aa] | 93 | // Local Variables: //
|
---|
| 94 | // tab-width: 4 //
|
---|
| 95 | // mode: c++ //
|
---|
| 96 | // compile-command: "make install" //
|
---|
| 97 | // End: //
|
---|