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 | // |
---|
7 | // MLEMutator.h -- |
---|
8 | // |
---|
9 | // Author : Rodolfo G. Esteves |
---|
10 | // Created On : Mon May 18 07:44:20 2015 |
---|
11 | // Last Modified By : Rob Schluntz |
---|
12 | // Last Modified On : Wed Jun 03 15:06:36 2015 |
---|
13 | // Update Count : 25 |
---|
14 | // |
---|
15 | |
---|
16 | #ifndef MLE_MUTATOR_H |
---|
17 | #define MLE_MUTATOR_H |
---|
18 | |
---|
19 | #include <map> |
---|
20 | #include <list> |
---|
21 | |
---|
22 | #include "Common/utility.h" |
---|
23 | #include "SynTree/SynTree.h" |
---|
24 | #include "SynTree/Mutator.h" |
---|
25 | #include "SynTree/Label.h" |
---|
26 | |
---|
27 | #include "LabelGenerator.h" |
---|
28 | |
---|
29 | namespace ControlStruct { |
---|
30 | class MLEMutator : public Mutator { |
---|
31 | class Entry; |
---|
32 | public: |
---|
33 | MLEMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : targetTable( t ), breakLabel(std::string("")), generator( gen ) {} |
---|
34 | ~MLEMutator(); |
---|
35 | |
---|
36 | CompoundStmt *mutate( CompoundStmt *cmpndStmt ); |
---|
37 | Statement *mutate( WhileStmt *whileStmt ); |
---|
38 | Statement *mutate( ForStmt *forStmt ); |
---|
39 | Statement *mutate( BranchStmt *branchStmt ) throw ( SemanticError ); |
---|
40 | |
---|
41 | Statement *mutate( CaseStmt *caseStmt ); |
---|
42 | Statement *mutate( SwitchStmt *switchStmt ); |
---|
43 | Statement *mutate( ChooseStmt *switchStmt ); |
---|
44 | |
---|
45 | Statement *mutateLoop( Statement *bodyLoop, Entry &e ); |
---|
46 | |
---|
47 | Label &get_breakLabel() { return breakLabel; } |
---|
48 | void set_breakLabel( Label newValue ) { breakLabel = newValue; } |
---|
49 | private: |
---|
50 | class Entry { |
---|
51 | public: |
---|
52 | explicit Entry( Statement *_loop, Label _breakExit, Label _contExit = Label("") ) : |
---|
53 | loop( _loop ), breakExit( _breakExit ), contExit( _contExit ), breakUsed(false), contUsed(false) {} |
---|
54 | |
---|
55 | bool operator==( const Statement *stmt ) { return ( loop == stmt ); } |
---|
56 | bool operator!=( const Statement *stmt ) { return ( loop != stmt ); } |
---|
57 | |
---|
58 | bool operator==( const Entry &other ) { return ( loop == other.get_loop() ); } |
---|
59 | |
---|
60 | Statement *get_loop() const { return loop; } |
---|
61 | |
---|
62 | Label useContExit() { contUsed = true; return contExit; } |
---|
63 | Label useBreakExit() { breakUsed = true; return breakExit; } |
---|
64 | |
---|
65 | bool isContUsed() const { return contUsed; } |
---|
66 | bool isBreakUsed() const { return breakUsed; } |
---|
67 | |
---|
68 | private: |
---|
69 | Statement *loop; |
---|
70 | Label breakExit, contExit; |
---|
71 | bool breakUsed, contUsed; |
---|
72 | }; |
---|
73 | |
---|
74 | std::map< Label, Statement * > *targetTable; |
---|
75 | std::list< Entry > enclosingBlocks, enclosingLoops, enclosingSwitches; |
---|
76 | Label breakLabel; |
---|
77 | LabelGenerator *generator; |
---|
78 | |
---|
79 | template< typename LoopClass > |
---|
80 | Statement *handleLoopStmt( LoopClass *loopStmt ); |
---|
81 | |
---|
82 | template< typename SwitchClass > |
---|
83 | Statement *handleSwitchStmt( SwitchClass *switchStmt ); |
---|
84 | |
---|
85 | void fixBlock( std::list< Statement * > &kids ); |
---|
86 | }; |
---|
87 | } // namespace ControlStruct |
---|
88 | |
---|
89 | #endif // MLE_MUTATOR_H |
---|
90 | |
---|
91 | // Local Variables: // |
---|
92 | // tab-width: 4 // |
---|
93 | // mode: c++ // |
---|
94 | // compile-command: "make install" // |
---|
95 | // End: // |
---|