2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- // @dart = 2.10
6
-
7
5
import '../common.dart' ;
8
6
import '../elements/jumps.dart' ;
9
7
import '../inferrer/abstract_value_domain.dart' ;
@@ -22,11 +20,24 @@ class _JumpHandlerEntry {
22
20
_JumpHandlerEntry (this .jumpInstruction, this .locals);
23
21
}
24
22
25
- abstract class JumpHandler extends interfaces. JumpHandler {
23
+ abstract class JumpHandler {
26
24
factory JumpHandler (
27
25
interfaces.KernelSsaGraphBuilder builder, JumpTarget target) {
28
26
return TargetJumpHandler (builder, target);
29
27
}
28
+
29
+ void generateBreak (SourceInformation sourceInformation,
30
+ [LabelDefinition ? label]);
31
+ void generateContinue (SourceInformation sourceInformation,
32
+ [LabelDefinition ? label]);
33
+ void forEachBreak (void action (HBreak instruction, LocalsHandler locals));
34
+ void forEachContinue (
35
+ void action (HContinue instruction, LocalsHandler locals));
36
+ bool hasAnyContinue ();
37
+ bool hasAnyBreak ();
38
+ void close ();
39
+ JumpTarget ? get target;
40
+ List <LabelDefinition > get labels;
30
41
}
31
42
32
43
/// Jump handler used to avoid null checks when a target isn't used as the
@@ -39,14 +50,14 @@ class NullJumpHandler implements JumpHandler {
39
50
40
51
@override
41
52
void generateBreak (SourceInformation sourceInformation,
42
- [LabelDefinition label]) {
53
+ [LabelDefinition ? label]) {
43
54
reporter.internalError (CURRENT_ELEMENT_SPANNABLE ,
44
55
'NullJumpHandler.generateBreak should not be called.' );
45
56
}
46
57
47
58
@override
48
59
void generateContinue (SourceInformation sourceInformation,
49
- [LabelDefinition label]) {
60
+ [LabelDefinition ? label]) {
50
61
reporter.internalError (CURRENT_ELEMENT_SPANNABLE ,
51
62
'NullJumpHandler.generateContinue should not be called.' );
52
63
}
@@ -65,7 +76,7 @@ class NullJumpHandler implements JumpHandler {
65
76
@override
66
77
List <LabelDefinition > get labels => const [];
67
78
@override
68
- JumpTarget get target => null ;
79
+ JumpTarget ? get target => null ;
69
80
}
70
81
71
82
/// Jump handler that records breaks until a target block is available.
@@ -88,7 +99,7 @@ class TargetJumpHandler implements JumpHandler {
88
99
89
100
@override
90
101
void generateBreak (SourceInformation sourceInformation,
91
- [LabelDefinition label]) {
102
+ [LabelDefinition ? label]) {
92
103
HInstruction breakInstruction;
93
104
if (label == null ) {
94
105
breakInstruction =
@@ -98,13 +109,13 @@ class TargetJumpHandler implements JumpHandler {
98
109
HBreak .toLabel (_abstractValueDomain, label, sourceInformation);
99
110
}
100
111
LocalsHandler locals = LocalsHandler .from (builder.localsHandler);
101
- builder.close (breakInstruction);
112
+ builder.close (breakInstruction as HJump );
102
113
jumps.add (_JumpHandlerEntry (breakInstruction, locals));
103
114
}
104
115
105
116
@override
106
117
void generateContinue (SourceInformation sourceInformation,
107
- [LabelDefinition label]) {
118
+ [LabelDefinition ? label]) {
108
119
HInstruction continueInstruction;
109
120
if (label == null ) {
110
121
continueInstruction =
@@ -117,23 +128,25 @@ class TargetJumpHandler implements JumpHandler {
117
128
assert (! label.target.isSwitchCase);
118
129
}
119
130
LocalsHandler locals = LocalsHandler .from (builder.localsHandler);
120
- builder.close (continueInstruction);
131
+ builder.close (continueInstruction as HJump );
121
132
jumps.add (_JumpHandlerEntry (continueInstruction, locals));
122
133
}
123
134
124
135
@override
125
136
void forEachBreak (
126
137
void Function (HBreak instruction, LocalsHandler locals) action) {
127
138
for (_JumpHandlerEntry entry in jumps) {
128
- if (entry.isBreak ()) action (entry.jumpInstruction, entry.locals);
139
+ final jumpInstruction = entry.jumpInstruction;
140
+ if (jumpInstruction is HBreak ) action (jumpInstruction, entry.locals);
129
141
}
130
142
}
131
143
132
144
@override
133
145
void forEachContinue (
134
146
void Function (HContinue instruction, LocalsHandler locals) action) {
135
147
for (_JumpHandlerEntry entry in jumps) {
136
- if (entry.isContinue ()) action (entry.jumpInstruction, entry.locals);
148
+ final jumpInstruction = entry.jumpInstruction;
149
+ if (jumpInstruction is HContinue ) action (jumpInstruction, entry.locals);
137
150
}
138
151
}
139
152
@@ -161,7 +174,7 @@ class TargetJumpHandler implements JumpHandler {
161
174
162
175
@override
163
176
List <LabelDefinition > get labels {
164
- List <LabelDefinition > result = null ;
177
+ List <LabelDefinition >? result;
165
178
for (LabelDefinition element in target.labels) {
166
179
result ?? = < LabelDefinition > [];
167
180
result.add (element);
@@ -177,13 +190,11 @@ abstract class SwitchCaseJumpHandler extends TargetJumpHandler {
177
190
/// switch case loop.
178
191
final Map <JumpTarget , int > targetIndexMap = {};
179
192
180
- SwitchCaseJumpHandler (
181
- interfaces.KernelSsaGraphBuilder builder, JumpTarget target)
182
- : super (builder, target);
193
+ SwitchCaseJumpHandler (super .builder, super .target);
183
194
184
195
@override
185
196
void generateBreak (SourceInformation sourceInformation,
186
- [LabelDefinition label]) {
197
+ [LabelDefinition ? label]) {
187
198
if (label == null ) {
188
199
// Creates a special break instruction for the synthetic loop generated
189
200
// for a switch statement with continue statements. See
@@ -193,35 +204,34 @@ abstract class SwitchCaseJumpHandler extends TargetJumpHandler {
193
204
_abstractValueDomain, target, sourceInformation,
194
205
breakSwitchContinueLoop: true );
195
206
LocalsHandler locals = LocalsHandler .from (builder.localsHandler);
196
- builder.close (breakInstruction);
207
+ builder.close (breakInstruction as HJump );
197
208
jumps.add (_JumpHandlerEntry (breakInstruction, locals));
198
209
} else {
199
210
super .generateBreak (sourceInformation, label);
200
211
}
201
212
}
202
213
203
- bool isContinueToSwitchCase (LabelDefinition label) {
214
+ bool isContinueToSwitchCase (LabelDefinition ? label) {
204
215
return label != null && targetIndexMap.containsKey (label.target);
205
216
}
206
217
207
218
@override
208
219
void generateContinue (SourceInformation sourceInformation,
209
- [LabelDefinition label]) {
220
+ [LabelDefinition ? label]) {
210
221
if (isContinueToSwitchCase (label)) {
211
222
// Creates the special instructions 'label = i; continue l;' used in
212
223
// switch statements with continue statements. See
213
224
// [SsaFromAstMixin.buildComplexSwitchStatement] for detail.
214
225
215
- assert (label != null );
216
226
HInstruction value = builder.graph
217
- .addConstantInt (targetIndexMap[label.target], builder.closedWorld);
227
+ .addConstantInt (targetIndexMap[label! .target]! , builder.closedWorld);
218
228
builder.localsHandler.updateLocal (target, value);
219
229
220
230
assert (label.target.labels.contains (label));
221
231
HInstruction continueInstruction =
222
232
HContinue (_abstractValueDomain, target, sourceInformation);
223
233
LocalsHandler locals = LocalsHandler .from (builder.localsHandler);
224
- builder.close (continueInstruction);
234
+ builder.close (continueInstruction as HJump );
225
235
jumps.add (_JumpHandlerEntry (continueInstruction, locals));
226
236
} else {
227
237
super .generateContinue (sourceInformation, label);
0 commit comments