source: src/ControlStruct/MLEMutator.h @ fbd7ad6

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since fbd7ad6 was 4e06c1e, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

changes for switch and choose statements

  • Property mode set to 100644
File size: 3.0 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//
[0f8e4ac]7// MLEMutator.h --
[51587aa]8//
[843054c2]9// Author           : Rodolfo G. Esteves
[51587aa]10// Created On       : Mon May 18 07:44:20 2015
[adcc065]11// Last Modified By : Peter A. Buhr
[4e06c1e]12// Last Modified On : Tue Jul 12 17:37:01 2016
13// Update Count     : 34
[51587aa]14//
[a08ba92]15
[51b7345]16#ifndef MLE_MUTATOR_H
17#define MLE_MUTATOR_H
18
19#include <map>
20#include <list>
21
[d3b7937]22#include "Common/utility.h"
[51b7345]23#include "SynTree/SynTree.h"
24#include "SynTree/Mutator.h"
[0f8e4ac]25#include "SynTree/Label.h"
[51b7345]26
27#include "LabelGenerator.h"
28
29namespace ControlStruct {
[a08ba92]30        class MLEMutator : public Mutator {
31                class Entry;
[adcc065]32                typedef Mutator Parent;
[d9a0e76]33          public:
[a08ba92]34                MLEMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : targetTable( t ), breakLabel(std::string("")), generator( gen ) {}
35                ~MLEMutator();
[d9a0e76]36
[6a37d13]37                virtual CompoundStmt *mutate( CompoundStmt *cmpndStmt ) override;
[adcc065]38                virtual Statement *mutate( WhileStmt *whileStmt ) override;
39                virtual Statement *mutate( ForStmt *forStmt ) override;
40                virtual Statement *mutate( BranchStmt *branchStmt ) throw ( SemanticError ) override;
[99f11dd]41                virtual Statement *mutate( CaseStmt *caseStmt ) override;
[adcc065]42                virtual Statement *mutate( IfStmt *ifStmt ) override;
43                virtual Statement *mutate( SwitchStmt *switchStmt ) override;
[d9a0e76]44
[a08ba92]45                Statement *mutateLoop( Statement *bodyLoop, Entry &e );
[d9a0e76]46
[a08ba92]47                Label &get_breakLabel() { return breakLabel; }
48                void set_breakLabel( Label newValue ) { breakLabel = newValue; }
49          private:
50                class Entry {
51                  public:
[27de955]52                        explicit Entry( Statement *_loop, Label _breakExit, Label _contExit = Label("") ) :
53                                loop( _loop ), breakExit( _breakExit ), contExit( _contExit ), breakUsed(false), contUsed(false) {}
[d9a0e76]54
[a08ba92]55                        bool operator==( const Statement *stmt ) { return ( loop == stmt ); }
56                        bool operator!=( const Statement *stmt ) { return ( loop != stmt ); }
[d9a0e76]57
[e39aa0f]58                        bool operator==( const Entry &other ) { return ( loop == other.get_controlStructure() ); }
[d9a0e76]59
[e39aa0f]60                        Statement *get_controlStructure() const { return loop; }
[51b7345]61
[27de955]62                        Label useContExit() { contUsed = true; return contExit; }
63                        Label useBreakExit() { breakUsed = true; return breakExit; }
[a08ba92]64
[27de955]65                        bool isContUsed() const { return contUsed; }
66                        bool isBreakUsed() const { return breakUsed; }
[a08ba92]67                  private:
68                        Statement *loop;
[27de955]69                        Label breakExit, contExit;
70                        bool breakUsed, contUsed;
[a08ba92]71                };
72
73                std::map< Label, Statement * > *targetTable;
[e39aa0f]74                std::list< Entry > enclosingControlStructures;
[a08ba92]75                Label breakLabel;
76                LabelGenerator *generator;
[be5aa1b]77
[27de955]78                template< typename LoopClass >
79                Statement *handleLoopStmt( LoopClass *loopStmt );
80
[adcc065]81                template< typename IfClass >
82                Statement *handleIfStmt( IfClass *switchStmt );
83
[0f8e4ac]84                template< typename SwitchClass >
[27de955]85                Statement *handleSwitchStmt( SwitchClass *switchStmt );
86
87                void fixBlock( std::list< Statement * > &kids );
[a08ba92]88        };
[51b7345]89} // namespace ControlStruct
90
[a08ba92]91#endif // MLE_MUTATOR_H
[51b7345]92
[51587aa]93// Local Variables: //
94// tab-width: 4 //
95// mode: c++ //
96// compile-command: "make install" //
97// End: //
Note: See TracBrowser for help on using the repository browser.