source: src/ControlStruct/MLEMutator.h@ 2316525

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 2316525 was d62806c, checked in by Andrew Beach <ajbeach@…>, 6 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
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 : Andrew Beach
12// Last Modified On : Thr Jan 16 12:46:00 2020
13// Update Count : 46
14//
15
16// Can anyone figure out what MLE stands for?
17
18#pragma once
19
20#include <list> // for list
21#include <map> // for map
22#include <string> // for string
23#include <set> // for unordered_set
24
25#include "Common/PassVisitor.h"
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
30
31namespace ControlStruct {
32 class LabelGenerator;
33
34 class MLEMutator : public WithVisitorRef<MLEMutator>, public WithShortCircuiting, public WithGuards {
35 public:
36 class Entry;
37 MLEMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : targetTable( t ), breakLabel(std::string("")), generator( gen ) {}
38 ~MLEMutator();
39
40 void premutate( CompoundStmt *cmpndStmt );
41 Statement * postmutate( BranchStmt *branchStmt ) throw ( SemanticErrorException );
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 );
51 void premutate( TryStmt *tryStmt );
52 Statement * postmutate( TryStmt *tryStmt );
53 void premutate( FinallyStmt *finallyStmt );
54
55 Statement *mutateLoop( Statement *bodyLoop, Entry &e );
56
57 Label &get_breakLabel() { return breakLabel; }
58 void set_breakLabel( Label newValue ) { breakLabel = newValue; }
59
60 class Entry {
61 public:
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 ) {}
68
69 explicit Entry( CompoundStmt *stmt, Label breakExit ) :
70 stmt( stmt ), breakExit( breakExit ) {}
71
72 explicit Entry( IfStmt *stmt, Label breakExit ) :
73 stmt( stmt ), breakExit( breakExit ) {}
74
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
81 explicit Entry( TryStmt *stmt, Label breakExit ) :
82 stmt( stmt ), breakExit( breakExit ) {}
83
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; }
90
91 Label useContExit() { contUsed = true; return contExit; }
92 Label useBreakExit() { breakUsed = true; return breakExit; }
93 Label useFallExit() { fallUsed = true; return fallExit; }
94 Label useFallDefaultExit() { fallDefaultUsed = true; return fallDefaultExit; }
95
96 bool isContUsed() const { return contUsed; }
97 bool isBreakUsed() const { return breakUsed; }
98 bool isFallUsed() const { return fallUsed; }
99 bool isFallDefaultUsed() const { return fallDefaultUsed; }
100 void seenDefault() { fallDefaultValid = false; }
101 bool isFallDefaultValid() const { return fallDefaultValid; }
102 private:
103 Statement *stmt;
104 Label breakExit, contExit, fallExit, fallDefaultExit;
105 bool breakUsed = false, contUsed = false, fallUsed = false, fallDefaultUsed = false;
106 bool fallDefaultValid = true;
107 };
108
109 private:
110 std::map< Label, Statement * > *targetTable;
111 std::set< Label > fallthroughLabels;
112 std::list< Entry > enclosingControlStructures;
113 Label breakLabel;
114 LabelGenerator *generator;
115
116 template< typename LoopClass >
117 void prehandleLoopStmt( LoopClass * loopStmt );
118
119 template< typename LoopClass >
120 Statement * posthandleLoopStmt( LoopClass * loopStmt );
121
122 void fixBlock( std::list< Statement * > &kids, bool caseClause = false );
123 };
124} // namespace ControlStruct
125
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.