source: src/ControlStruct/MLEMutator.h @ 27de955

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 27de955 was 27de955, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

fix multi-level exit code (labeled break and continue)

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