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 : Peter A. Buhr
|
---|
12 | // Last Modified On : Tue Jul 12 17:37:01 2016
|
---|
13 | // Update Count : 34
|
---|
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 | typedef Mutator Parent;
|
---|
33 | public:
|
---|
34 | MLEMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : targetTable( t ), breakLabel(std::string("")), generator( gen ) {}
|
---|
35 | ~MLEMutator();
|
---|
36 |
|
---|
37 | virtual CompoundStmt *mutate( CompoundStmt *cmpndStmt ) override;
|
---|
38 | virtual Statement *mutate( WhileStmt *whileStmt ) override;
|
---|
39 | virtual Statement *mutate( ForStmt *forStmt ) override;
|
---|
40 | virtual Statement *mutate( BranchStmt *branchStmt ) throw ( SemanticError ) override;
|
---|
41 | virtual Statement *mutate( CaseStmt *caseStmt ) override;
|
---|
42 | virtual Statement *mutate( IfStmt *ifStmt ) override;
|
---|
43 | virtual Statement *mutate( SwitchStmt *switchStmt ) override;
|
---|
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_controlStructure() ); }
|
---|
59 |
|
---|
60 | Statement *get_controlStructure() 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 | private:
|
---|
68 | Statement *loop;
|
---|
69 | Label breakExit, contExit;
|
---|
70 | bool breakUsed, contUsed;
|
---|
71 | };
|
---|
72 |
|
---|
73 | std::map< Label, Statement * > *targetTable;
|
---|
74 | std::list< Entry > enclosingControlStructures;
|
---|
75 | Label breakLabel;
|
---|
76 | LabelGenerator *generator;
|
---|
77 |
|
---|
78 | template< typename LoopClass >
|
---|
79 | Statement *handleLoopStmt( LoopClass *loopStmt );
|
---|
80 |
|
---|
81 | template< typename IfClass >
|
---|
82 | Statement *handleIfStmt( IfClass *switchStmt );
|
---|
83 |
|
---|
84 | template< typename SwitchClass >
|
---|
85 | Statement *handleSwitchStmt( SwitchClass *switchStmt );
|
---|
86 |
|
---|
87 | void fixBlock( std::list< Statement * > &kids );
|
---|
88 | };
|
---|
89 | } // namespace ControlStruct
|
---|
90 |
|
---|
91 | #endif // MLE_MUTATOR_H
|
---|
92 |
|
---|
93 | // Local Variables: //
|
---|
94 | // tab-width: 4 //
|
---|
95 | // mode: c++ //
|
---|
96 | // compile-command: "make install" //
|
---|
97 | // End: //
|
---|