File tree Expand file tree Collapse file tree 4 files changed +53
-13
lines changed Expand file tree Collapse file tree 4 files changed +53
-13
lines changed Original file line number Diff line number Diff line change @@ -122,22 +122,19 @@ void DataFlowAnalyzer::operator()(ForLoop& _for)
122
122
assignments (_for.post );
123
123
clearValues (assignments.names ());
124
124
125
+ AssignmentsSinceContinue assignmentsSinceCont;
126
+ assignmentsSinceCont (_for.body );
127
+
125
128
visit (*_for.condition );
126
129
(*this )(_for.body );
127
130
(*this )(_for.post );
128
131
129
- clearValues (assignments.names ());
130
- popScope ();
131
- }
132
-
133
- void DataFlowAnalyzer::operator ()(Break&)
134
- {
135
- yulAssert (false , " Not implemented yet." );
136
- }
132
+ if (!assignmentsSinceCont.empty ())
133
+ clearValues (assignmentsSinceCont.names ());
134
+ else
135
+ clearValues (assignments.names ());
137
136
138
- void DataFlowAnalyzer::operator ()(Continue&)
139
- {
140
- yulAssert (false , " Not implemented yet." );
137
+ popScope ();
141
138
}
142
139
143
140
void DataFlowAnalyzer::operator ()(Block& _block)
Original file line number Diff line number Diff line change 23
23
#pragma once
24
24
25
25
#include < libyul/optimiser/ASTWalker.h>
26
+ #include < libyul/optimiser/NameCollector.h>
26
27
#include < libyul/YulString.h>
27
28
28
29
#include < map>
@@ -53,8 +54,6 @@ class DataFlowAnalyzer: public ASTModifier
53
54
void operator ()(Switch& _switch) override ;
54
55
void operator ()(FunctionDefinition&) override ;
55
56
void operator ()(ForLoop&) override ;
56
- void operator ()(Break& _continue) override ;
57
- void operator ()(Continue& _continue) override ;
58
57
void operator ()(Block& _block) override ;
59
58
60
59
protected:
Original file line number Diff line number Diff line change @@ -79,3 +79,23 @@ void Assignments::operator()(Assignment const& _assignment)
79
79
for (auto const & var: _assignment.variableNames )
80
80
m_names.emplace (var.name );
81
81
}
82
+
83
+ void AssignmentsSinceContinue::operator ()(ForLoop const & _forLoop)
84
+ {
85
+ m_forLoopDepth++;
86
+ ASTWalker::operator ()(_forLoop);
87
+ m_forLoopDepth--;
88
+ }
89
+
90
+ void AssignmentsSinceContinue::operator ()(Continue const &)
91
+ {
92
+ if (m_forLoopDepth == 0 )
93
+ m_continueFound = true ;
94
+ }
95
+
96
+ void AssignmentsSinceContinue::operator ()(Assignment const & _assignment)
97
+ {
98
+ if (m_continueFound)
99
+ for (auto const & var: _assignment.variableNames )
100
+ m_names.emplace (var.name );
101
+ }
Original file line number Diff line number Diff line change @@ -81,4 +81,28 @@ class Assignments: public ASTWalker
81
81
std::set<YulString> m_names;
82
82
};
83
83
84
+ /* *
85
+ * Collects all names from a given continue statement on onwards.
86
+ *
87
+ * It makes only sense to be invoked from within a body of an outer for loop, that is,
88
+ * it will only collect all names from the beginning of the first continue statement
89
+ * of the outer-most ForLoop.
90
+ */
91
+ class AssignmentsSinceContinue : public ASTWalker
92
+ {
93
+ public:
94
+ using ASTWalker::operator ();
95
+ void operator ()(ForLoop const & _forLoop) override ;
96
+ void operator ()(Continue const &) override ;
97
+ void operator ()(Assignment const & _assignment) override ;
98
+
99
+ std::set<YulString> const & names () const { return m_names; }
100
+ bool empty () const noexcept { return m_names.empty (); }
101
+
102
+ private:
103
+ int m_forLoopDepth = 0 ;
104
+ bool m_continueFound = false ;
105
+ std::set<YulString> m_names;
106
+ };
107
+
84
108
}
You can’t perform that action at this time.
0 commit comments