source: src/ControlStruct/MLEMutator.h@ adcc065

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since adcc065 was adcc065, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

add labelled break to if statement, update comment formatting, add random number test

  • Property mode set to 100644
File size: 3.0 KB
Line 
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 : Wed Jul 6 16:49:52 2016
13// Update Count : 31
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
29namespace 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 CompoundStmt *mutate( CompoundStmt *cmpndStmt );
38 virtual Statement *mutate( WhileStmt *whileStmt ) override;
39 virtual Statement *mutate( ForStmt *forStmt ) override;
40 virtual Statement *mutate( BranchStmt *branchStmt ) throw ( SemanticError ) override;
41
42 virtual Statement *mutate( CaseStmt *caseStmt ) override;
43 virtual Statement *mutate( IfStmt *ifStmt ) override;
44 virtual Statement *mutate( SwitchStmt *switchStmt ) override;
45 virtual Statement *mutate( ChooseStmt *switchStmt ) override;
46
47 Statement *mutateLoop( Statement *bodyLoop, Entry &e );
48
49 Label &get_breakLabel() { return breakLabel; }
50 void set_breakLabel( Label newValue ) { breakLabel = newValue; }
51 private:
52 class Entry {
53 public:
54 explicit Entry( Statement *_loop, Label _breakExit, Label _contExit = Label("") ) :
55 loop( _loop ), breakExit( _breakExit ), contExit( _contExit ), breakUsed(false), contUsed(false) {}
56
57 bool operator==( const Statement *stmt ) { return ( loop == stmt ); }
58 bool operator!=( const Statement *stmt ) { return ( loop != stmt ); }
59
60 bool operator==( const Entry &other ) { return ( loop == other.get_controlStructure() ); }
61
62 Statement *get_controlStructure() const { return loop; }
63
64 Label useContExit() { contUsed = true; return contExit; }
65 Label useBreakExit() { breakUsed = true; return breakExit; }
66
67 bool isContUsed() const { return contUsed; }
68 bool isBreakUsed() const { return breakUsed; }
69 private:
70 Statement *loop;
71 Label breakExit, contExit;
72 bool breakUsed, contUsed;
73 };
74
75 std::map< Label, Statement * > *targetTable;
76 std::list< Entry > enclosingControlStructures;
77 Label breakLabel;
78 LabelGenerator *generator;
79
80 template< typename LoopClass >
81 Statement *handleLoopStmt( LoopClass *loopStmt );
82
83 template< typename IfClass >
84 Statement *handleIfStmt( IfClass *switchStmt );
85
86 template< typename SwitchClass >
87 Statement *handleSwitchStmt( SwitchClass *switchStmt );
88
89 void fixBlock( std::list< Statement * > &kids );
90 };
91} // namespace ControlStruct
92
93#endif // MLE_MUTATOR_H
94
95// Local Variables: //
96// tab-width: 4 //
97// mode: c++ //
98// compile-command: "make install" //
99// End: //
Note: See TracBrowser for help on using the repository browser.