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 : Sat Jul 22 09:19:59 2017
|
---|
13 | // Update Count : 35
|
---|
14 | //
|
---|
15 |
|
---|
16 | #pragma once
|
---|
17 |
|
---|
18 | #include <list> // for list
|
---|
19 | #include <map> // for map
|
---|
20 | #include <string> // for string
|
---|
21 |
|
---|
22 | #include "Common/PassVisitor.h"
|
---|
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
|
---|
27 |
|
---|
28 | namespace ControlStruct {
|
---|
29 | class LabelGenerator;
|
---|
30 |
|
---|
31 | class MLEMutator : public WithVisitorRef<MLEMutator>, public WithShortCircuiting {
|
---|
32 | class Entry;
|
---|
33 |
|
---|
34 | public:
|
---|
35 | MLEMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : targetTable( t ), breakLabel(std::string("")), generator( gen ) {}
|
---|
36 | ~MLEMutator();
|
---|
37 |
|
---|
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 );
|
---|
49 |
|
---|
50 | Statement *mutateLoop( Statement *bodyLoop, Entry &e );
|
---|
51 |
|
---|
52 | Label &get_breakLabel() { return breakLabel; }
|
---|
53 | void set_breakLabel( Label newValue ) { breakLabel = newValue; }
|
---|
54 | private:
|
---|
55 | class Entry {
|
---|
56 | public:
|
---|
57 | explicit Entry( Statement *_loop, Label _breakExit, Label _contExit = Label("") ) :
|
---|
58 | loop( _loop ), breakExit( _breakExit ), contExit( _contExit ), breakUsed(false), contUsed(false) {}
|
---|
59 |
|
---|
60 | bool operator==( const Statement *stmt ) { return loop == stmt; }
|
---|
61 | bool operator!=( const Statement *stmt ) { return loop != stmt; }
|
---|
62 |
|
---|
63 | bool operator==( const Entry &other ) { return loop == other.get_controlStructure(); }
|
---|
64 |
|
---|
65 | Statement *get_controlStructure() const { return loop; }
|
---|
66 |
|
---|
67 | Label useContExit() { contUsed = true; return contExit; }
|
---|
68 | Label useBreakExit() { breakUsed = true; return breakExit; }
|
---|
69 |
|
---|
70 | bool isContUsed() const { return contUsed; }
|
---|
71 | bool isBreakUsed() const { return breakUsed; }
|
---|
72 | private:
|
---|
73 | Statement *loop;
|
---|
74 | Label breakExit, contExit;
|
---|
75 | bool breakUsed, contUsed;
|
---|
76 | };
|
---|
77 |
|
---|
78 | std::map< Label, Statement * > *targetTable;
|
---|
79 | std::list< Entry > enclosingControlStructures;
|
---|
80 | Label breakLabel;
|
---|
81 | LabelGenerator *generator;
|
---|
82 |
|
---|
83 | template< typename LoopClass >
|
---|
84 | void prehandleLoopStmt( LoopClass * loopStmt );
|
---|
85 |
|
---|
86 | template< typename LoopClass >
|
---|
87 | Statement * posthandleLoopStmt( LoopClass * loopStmt );
|
---|
88 |
|
---|
89 | void fixBlock( std::list< Statement * > &kids );
|
---|
90 | };
|
---|
91 | } // namespace ControlStruct
|
---|
92 |
|
---|
93 | // Local Variables: //
|
---|
94 | // tab-width: 4 //
|
---|
95 | // mode: c++ //
|
---|
96 | // compile-command: "make install" //
|
---|
97 | // End: //
|
---|