source: src/ControlStruct/MLEMutator.h@ 63be52cd

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox 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 63be52cd was 6b0b624, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

change #ifndef to #pragma once

  • Property mode set to 100644
File size: 2.9 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 : Sat Jul 22 09:19:59 2017
13// Update Count : 35
14//
15
16#pragma once
17
18#include <map>
19#include <list>
20
21#include "Common/utility.h"
22#include "SynTree/SynTree.h"
23#include "SynTree/Mutator.h"
24#include "SynTree/Label.h"
25
26#include "LabelGenerator.h"
27
28namespace ControlStruct {
29 class MLEMutator : public Mutator {
30 class Entry;
31 typedef Mutator Parent;
32 public:
33 MLEMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : targetTable( t ), breakLabel(std::string("")), generator( gen ) {}
34 ~MLEMutator();
35
36 virtual CompoundStmt *mutate( CompoundStmt *cmpndStmt ) override;
37 virtual Statement *mutate( WhileStmt *whileStmt ) override;
38 virtual Statement *mutate( ForStmt *forStmt ) override;
39 virtual Statement *mutate( BranchStmt *branchStmt ) throw ( SemanticError ) override;
40 virtual Statement *mutate( CaseStmt *caseStmt ) override;
41 virtual Statement *mutate( IfStmt *ifStmt ) override;
42 virtual Statement *mutate( SwitchStmt *switchStmt ) override;
43
44 Statement *mutateLoop( Statement *bodyLoop, Entry &e );
45
46 Label &get_breakLabel() { return breakLabel; }
47 void set_breakLabel( Label newValue ) { breakLabel = newValue; }
48 private:
49 class Entry {
50 public:
51 explicit Entry( Statement *_loop, Label _breakExit, Label _contExit = Label("") ) :
52 loop( _loop ), breakExit( _breakExit ), contExit( _contExit ), breakUsed(false), contUsed(false) {}
53
54 bool operator==( const Statement *stmt ) { return ( loop == stmt ); }
55 bool operator!=( const Statement *stmt ) { return ( loop != stmt ); }
56
57 bool operator==( const Entry &other ) { return ( loop == other.get_controlStructure() ); }
58
59 Statement *get_controlStructure() const { return loop; }
60
61 Label useContExit() { contUsed = true; return contExit; }
62 Label useBreakExit() { breakUsed = true; return breakExit; }
63
64 bool isContUsed() const { return contUsed; }
65 bool isBreakUsed() const { return breakUsed; }
66 private:
67 Statement *loop;
68 Label breakExit, contExit;
69 bool breakUsed, contUsed;
70 };
71
72 std::map< Label, Statement * > *targetTable;
73 std::list< Entry > enclosingControlStructures;
74 Label breakLabel;
75 LabelGenerator *generator;
76
77 template< typename LoopClass >
78 Statement *handleLoopStmt( LoopClass *loopStmt );
79
80 template< typename IfClass >
81 Statement *handleIfStmt( IfClass *switchStmt );
82
83 template< typename SwitchClass >
84 Statement *handleSwitchStmt( SwitchClass *switchStmt );
85
86 void fixBlock( std::list< Statement * > &kids );
87 };
88} // namespace ControlStruct
89
90// Local Variables: //
91// tab-width: 4 //
92// mode: c++ //
93// compile-command: "make install" //
94// End: //
Note: See TracBrowser for help on using the repository browser.