source: src/ControlStruct/MLEMutator.h @ d62806c

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since d62806c was d62806c, checked in by Andrew Beach <ajbeach@…>, 4 years ago

Start working on checks to make sure we do not jump out of a finally block.

  • Property mode set to 100644
File size: 4.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//
[0f8e4ac]7// MLEMutator.h --
[51587aa]8//
[843054c2]9// Author           : Rodolfo G. Esteves
[51587aa]10// Created On       : Mon May 18 07:44:20 2015
[d62806c]11// Last Modified By : Andrew Beach
12// Last Modified On : Thr Jan 16 12:46:00 2020
13// Update Count     : 46
[51587aa]14//
[a08ba92]15
[d62806c]16// Can anyone figure out what MLE stands for?
17
[6b0b624]18#pragma once
[51b7345]19
[d180746]20#include <list>                    // for list
21#include <map>                     // for map
22#include <string>                  // for string
[720a007]23#include <set>                     // for unordered_set
[51b7345]24
[94e025a2]25#include "Common/PassVisitor.h"
[d180746]26#include "Common/SemanticError.h"  // for SemanticError
27#include "SynTree/Label.h"         // for Label
28#include "SynTree/Mutator.h"       // for Mutator
29#include "SynTree/SynTree.h"       // for Visitor Nodes
[51b7345]30
31namespace ControlStruct {
[94e025a2]32        class LabelGenerator;
[d180746]33
[720a007]34        class MLEMutator : public WithVisitorRef<MLEMutator>, public WithShortCircuiting, public WithGuards {
[d9a0e76]35          public:
[720a007]36                class Entry;
[a08ba92]37                MLEMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : targetTable( t ), breakLabel(std::string("")), generator( gen ) {}
38                ~MLEMutator();
[d9a0e76]39
[94e025a2]40                void premutate( CompoundStmt *cmpndStmt );
[a16764a6]41                Statement * postmutate( BranchStmt *branchStmt ) throw ( SemanticErrorException );
[94e025a2]42                void premutate( WhileStmt *whileStmt );
43                Statement * postmutate( WhileStmt *whileStmt );
44                void premutate( ForStmt *forStmt );
45                Statement * postmutate( ForStmt *forStmt );
46                void premutate( CaseStmt *caseStmt );
47                void premutate( IfStmt *ifStmt );
48                Statement * postmutate( IfStmt *ifStmt );
49                void premutate( SwitchStmt *switchStmt );
50                Statement * postmutate( SwitchStmt *switchStmt );
[9bdb8b7]51                void premutate( TryStmt *tryStmt );
52                Statement * postmutate( TryStmt *tryStmt );
[d62806c]53                void premutate( FinallyStmt *finallyStmt );
[d9a0e76]54
[a08ba92]55                Statement *mutateLoop( Statement *bodyLoop, Entry &e );
[d9a0e76]56
[a08ba92]57                Label &get_breakLabel() { return breakLabel; }
58                void set_breakLabel( Label newValue ) { breakLabel = newValue; }
[720a007]59
[a08ba92]60                class Entry {
61                  public:
[720a007]62                        // specialized constructors for each combination of statement with labelled break/continue/fallthrough that is valid to cleanup the use cases
63                        explicit Entry( ForStmt *stmt, Label breakExit, Label contExit ) :
64                                stmt( stmt ), breakExit( breakExit ), contExit( contExit ) {}
65
66                        explicit Entry( WhileStmt *stmt, Label breakExit, Label contExit ) :
67                                stmt( stmt ), breakExit( breakExit ), contExit( contExit ) {}
[d9a0e76]68
[720a007]69                        explicit Entry( CompoundStmt *stmt, Label breakExit ) :
70                                stmt( stmt ), breakExit( breakExit ) {}
[d9a0e76]71
[720a007]72                        explicit Entry( IfStmt *stmt, Label breakExit ) :
73                                stmt( stmt ), breakExit( breakExit ) {}
[d9a0e76]74
[720a007]75                        explicit Entry( CaseStmt *stmt, Label fallExit ) :
76                                stmt( stmt ), fallExit( fallExit ) {}
77
78                        explicit Entry( SwitchStmt *stmt, Label breakExit, Label fallDefaultExit ) :
79                                stmt( stmt ), breakExit( breakExit ), fallDefaultExit( fallDefaultExit ) {}
80
[9bdb8b7]81                        explicit Entry( TryStmt *stmt, Label breakExit ) :
82                                stmt( stmt ), breakExit( breakExit ) {}
83
[720a007]84                        bool operator==( const Statement *other ) { return stmt == other; }
85                        bool operator!=( const Statement *other ) { return stmt != other; }
86
87                        bool operator==( const Entry &other ) { return stmt == other.get_controlStructure(); }
88
89                        Statement *get_controlStructure() const { return stmt; }
[51b7345]90
[27de955]91                        Label useContExit() { contUsed = true; return contExit; }
92                        Label useBreakExit() { breakUsed = true; return breakExit; }
[720a007]93                        Label useFallExit() { fallUsed = true; return fallExit; }
94                        Label useFallDefaultExit() { fallDefaultUsed = true; return fallDefaultExit; }
[a08ba92]95
[27de955]96                        bool isContUsed() const { return contUsed; }
97                        bool isBreakUsed() const { return breakUsed; }
[720a007]98                        bool isFallUsed() const { return fallUsed; }
99                        bool isFallDefaultUsed() const { return fallDefaultUsed; }
100                        void seenDefault() { fallDefaultValid = false; }
101                        bool isFallDefaultValid() const { return fallDefaultValid; }
[a08ba92]102                  private:
[720a007]103                        Statement *stmt;
104                        Label breakExit, contExit, fallExit, fallDefaultExit;
105                        bool breakUsed = false, contUsed = false, fallUsed = false, fallDefaultUsed = false;
106                        bool fallDefaultValid = true;
[a08ba92]107                };
108
[720a007]109          private:
[a08ba92]110                std::map< Label, Statement * > *targetTable;
[720a007]111                std::set< Label > fallthroughLabels;
[e39aa0f]112                std::list< Entry > enclosingControlStructures;
[a08ba92]113                Label breakLabel;
114                LabelGenerator *generator;
[be5aa1b]115
[27de955]116                template< typename LoopClass >
[94e025a2]117                void prehandleLoopStmt( LoopClass * loopStmt );
[27de955]118
[94e025a2]119                template< typename LoopClass >
120                Statement * posthandleLoopStmt( LoopClass * loopStmt );
[27de955]121
[720a007]122                void fixBlock( std::list< Statement * > &kids, bool caseClause = false );
[a08ba92]123        };
[51b7345]124} // namespace ControlStruct
125
[51587aa]126// Local Variables: //
127// tab-width: 4 //
128// mode: c++ //
129// compile-command: "make install" //
130// End: //
Note: See TracBrowser for help on using the repository browser.