27206
|
1 |
/*
|
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package jdk.nashorn.internal.codegen;
|
|
27 |
|
|
28 |
import static jdk.nashorn.internal.ir.Node.NO_FINISH;
|
|
29 |
import static jdk.nashorn.internal.ir.Node.NO_LINE_NUMBER;
|
|
30 |
import static jdk.nashorn.internal.ir.Node.NO_TOKEN;
|
|
31 |
|
|
32 |
import java.util.ArrayDeque;
|
|
33 |
import java.util.ArrayList;
|
|
34 |
import java.util.Arrays;
|
|
35 |
import java.util.Collections;
|
|
36 |
import java.util.Deque;
|
|
37 |
import java.util.List;
|
|
38 |
import java.util.Objects;
|
|
39 |
import jdk.nashorn.internal.ir.AccessNode;
|
|
40 |
import jdk.nashorn.internal.ir.BinaryNode;
|
|
41 |
import jdk.nashorn.internal.ir.Block;
|
|
42 |
import jdk.nashorn.internal.ir.BlockLexicalContext;
|
|
43 |
import jdk.nashorn.internal.ir.BreakNode;
|
|
44 |
import jdk.nashorn.internal.ir.CallNode;
|
|
45 |
import jdk.nashorn.internal.ir.CaseNode;
|
|
46 |
import jdk.nashorn.internal.ir.ContinueNode;
|
|
47 |
import jdk.nashorn.internal.ir.Expression;
|
|
48 |
import jdk.nashorn.internal.ir.ExpressionStatement;
|
|
49 |
import jdk.nashorn.internal.ir.FunctionNode;
|
|
50 |
import jdk.nashorn.internal.ir.FunctionNode.CompilationState;
|
|
51 |
import jdk.nashorn.internal.ir.GetSplitState;
|
|
52 |
import jdk.nashorn.internal.ir.IdentNode;
|
|
53 |
import jdk.nashorn.internal.ir.IfNode;
|
|
54 |
import jdk.nashorn.internal.ir.JumpStatement;
|
28690
|
55 |
import jdk.nashorn.internal.ir.JumpToInlinedFinally;
|
27206
|
56 |
import jdk.nashorn.internal.ir.LiteralNode;
|
|
57 |
import jdk.nashorn.internal.ir.Node;
|
|
58 |
import jdk.nashorn.internal.ir.ReturnNode;
|
|
59 |
import jdk.nashorn.internal.ir.SetSplitState;
|
|
60 |
import jdk.nashorn.internal.ir.SplitNode;
|
|
61 |
import jdk.nashorn.internal.ir.SplitReturn;
|
|
62 |
import jdk.nashorn.internal.ir.Statement;
|
|
63 |
import jdk.nashorn.internal.ir.SwitchNode;
|
|
64 |
import jdk.nashorn.internal.ir.VarNode;
|
|
65 |
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
|
66 |
import jdk.nashorn.internal.parser.Token;
|
|
67 |
import jdk.nashorn.internal.parser.TokenType;
|
|
68 |
|
|
69 |
/**
|
|
70 |
* A node visitor that replaces {@link SplitNode}s with anonymous function invocations and some additional constructs
|
|
71 |
* to support control flow across splits. By using this transformation, split functions are translated into ordinary
|
|
72 |
* JavaScript functions with nested anonymous functions. The transformations however introduce several AST nodes that
|
|
73 |
* have no JavaScript source representations ({@link GetSplitState}, {@link SetSplitState}, and {@link SplitReturn}),
|
|
74 |
* and therefore such function is no longer reparseable from its source. For that reason, split functions and their
|
|
75 |
* fragments are serialized in-memory and deserialized when they need to be recompiled either for deoptimization or
|
|
76 |
* for type specialization.
|
|
77 |
* NOTE: all {@code leave*()} methods for statements are returning their input nodes. That way, they will not mutate
|
|
78 |
* the original statement list in the block containing the statement, which is fine, as it'll be replaced by the
|
|
79 |
* lexical context when the block is left. If we returned something else (e.g. null), we'd cause a mutation in the
|
|
80 |
* enclosing block's statement list that is otherwise overwritten later anyway.
|
|
81 |
*/
|
|
82 |
final class SplitIntoFunctions extends NodeVisitor<BlockLexicalContext> {
|
|
83 |
private static final int FALLTHROUGH_STATE = -1;
|
|
84 |
private static final int RETURN_STATE = 0;
|
|
85 |
private static final int BREAK_STATE = 1;
|
|
86 |
private static final int FIRST_JUMP_STATE = 2;
|
|
87 |
|
|
88 |
private static final String THIS_NAME = CompilerConstants.THIS.symbolName();
|
|
89 |
private static final String RETURN_NAME = CompilerConstants.RETURN.symbolName();
|
|
90 |
// Used as the name of the formal parameter for passing the current value of :return symbol into a split fragment.
|
|
91 |
private static final String RETURN_PARAM_NAME = RETURN_NAME + "-in";
|
|
92 |
|
|
93 |
private final Deque<FunctionState> functionStates = new ArrayDeque<>();
|
|
94 |
private final Deque<SplitState> splitStates = new ArrayDeque<>();
|
|
95 |
private final Namespace namespace;
|
|
96 |
|
|
97 |
private boolean artificialBlock = false;
|
|
98 |
|
|
99 |
// -1 is program; we need to use negative ones
|
|
100 |
private int nextFunctionId = -2;
|
|
101 |
|
|
102 |
public SplitIntoFunctions(final Compiler compiler) {
|
|
103 |
super(new BlockLexicalContext() {
|
|
104 |
@Override
|
|
105 |
protected Block afterSetStatements(Block block) {
|
|
106 |
for(Statement stmt: block.getStatements()) {
|
|
107 |
assert !(stmt instanceof SplitNode);
|
|
108 |
}
|
|
109 |
return block;
|
|
110 |
}
|
|
111 |
});
|
|
112 |
namespace = new Namespace(compiler.getScriptEnvironment().getNamespace());
|
|
113 |
}
|
|
114 |
|
|
115 |
@Override
|
|
116 |
public boolean enterFunctionNode(final FunctionNode functionNode) {
|
|
117 |
functionStates.push(new FunctionState(functionNode));
|
|
118 |
return true;
|
|
119 |
}
|
|
120 |
|
|
121 |
@Override
|
|
122 |
public Node leaveFunctionNode(final FunctionNode functionNode) {
|
|
123 |
functionStates.pop();
|
|
124 |
return functionNode;
|
|
125 |
}
|
|
126 |
|
|
127 |
@Override
|
|
128 |
protected Node leaveDefault(final Node node) {
|
|
129 |
if (node instanceof Statement) {
|
|
130 |
appendStatement((Statement)node);
|
|
131 |
}
|
|
132 |
return node;
|
|
133 |
}
|
|
134 |
|
|
135 |
@Override
|
|
136 |
public boolean enterSplitNode(final SplitNode splitNode) {
|
|
137 |
getCurrentFunctionState().splitDepth++;
|
|
138 |
splitStates.push(new SplitState(splitNode));
|
|
139 |
return true;
|
|
140 |
}
|
|
141 |
|
|
142 |
@Override
|
|
143 |
public Node leaveSplitNode(final SplitNode splitNode) {
|
|
144 |
// Replace the split node with an anonymous function expression call.
|
|
145 |
|
|
146 |
final FunctionState fnState = getCurrentFunctionState();
|
|
147 |
|
|
148 |
final String name = splitNode.getName();
|
|
149 |
Block body = splitNode.getBody();
|
|
150 |
final int firstLineNumber = body.getFirstStatementLineNumber();
|
|
151 |
final long token = body.getToken();
|
|
152 |
final int finish = body.getFinish();
|
|
153 |
|
|
154 |
final FunctionNode originalFn = fnState.fn;
|
|
155 |
assert originalFn == lc.getCurrentFunction();
|
|
156 |
final boolean isProgram = originalFn.isProgram();
|
|
157 |
|
|
158 |
// Change SplitNode({...}) into "function () { ... }", or "function (:return-in) () { ... }" (for program)
|
|
159 |
final long newFnToken = Token.toDesc(TokenType.FUNCTION, nextFunctionId--, 0);
|
|
160 |
final FunctionNode fn = new FunctionNode(
|
|
161 |
originalFn.getSource(),
|
|
162 |
body.getFirstStatementLineNumber(),
|
|
163 |
newFnToken,
|
|
164 |
finish,
|
|
165 |
newFnToken,
|
|
166 |
NO_TOKEN,
|
|
167 |
namespace,
|
|
168 |
createIdent(name),
|
|
169 |
originalFn.getName() + "$" + name,
|
|
170 |
isProgram ? Collections.singletonList(createReturnParamIdent()) : Collections.<IdentNode>emptyList(),
|
|
171 |
FunctionNode.Kind.NORMAL,
|
|
172 |
// We only need IS_SPLIT conservatively, in case it contains any array units so that we force
|
|
173 |
// the :callee's existence, to force :scope to never be in a slot lower than 2. This is actually
|
|
174 |
// quite a horrible hack to do with CodeGenerator.fixScopeSlot not trampling other parameters
|
|
175 |
// and should go away once we no longer have array unit handling in codegen. Note however that
|
|
176 |
// we still use IS_SPLIT as the criteria in CompilationPhase.SERIALIZE_SPLIT_PHASE.
|
|
177 |
FunctionNode.IS_ANONYMOUS | FunctionNode.USES_ANCESTOR_SCOPE | FunctionNode.IS_SPLIT,
|
|
178 |
body,
|
|
179 |
CompilationState.INITIALIZED,
|
|
180 |
null
|
|
181 |
)
|
|
182 |
.setCompileUnit(lc, splitNode.getCompileUnit())
|
|
183 |
.copyCompilationState(lc, originalFn);
|
|
184 |
|
|
185 |
// Call the function:
|
|
186 |
// either "(function () { ... }).call(this)"
|
|
187 |
// or "(function (:return-in) { ... }).call(this, :return)"
|
|
188 |
// NOTE: Function.call() has optimized linking that basically does a pass-through to the function being invoked.
|
|
189 |
// NOTE: CompilationPhase.PROGRAM_POINT_PHASE happens after this, so these calls are subject to optimistic
|
|
190 |
// assumptions on their return value (when they return a value), as they should be.
|
|
191 |
final IdentNode thisIdent = createIdent(THIS_NAME);
|
|
192 |
final CallNode callNode = new CallNode(firstLineNumber, token, finish, new AccessNode(NO_TOKEN, NO_FINISH, fn, "call"),
|
|
193 |
isProgram ? Arrays.<Expression>asList(thisIdent, createReturnIdent())
|
|
194 |
: Collections.<Expression>singletonList(thisIdent),
|
|
195 |
false);
|
|
196 |
|
|
197 |
final SplitState splitState = splitStates.pop();
|
|
198 |
fnState.splitDepth--;
|
|
199 |
|
|
200 |
final Expression callWithReturn;
|
|
201 |
final boolean hasReturn = splitState.hasReturn;
|
|
202 |
if (hasReturn && fnState.splitDepth > 0) {
|
|
203 |
final SplitState parentSplit = splitStates.peek();
|
|
204 |
if (parentSplit != null) {
|
|
205 |
// Propagate hasReturn to parent split
|
|
206 |
parentSplit.hasReturn = true;
|
|
207 |
}
|
|
208 |
}
|
|
209 |
if (hasReturn || isProgram) {
|
|
210 |
// capture return value: ":return = (function () { ... })();"
|
|
211 |
callWithReturn = new BinaryNode(Token.recast(token, TokenType.ASSIGN), createReturnIdent(), callNode);
|
|
212 |
} else {
|
|
213 |
// no return value, just call : "(function () { ... })();"
|
|
214 |
callWithReturn = callNode;
|
|
215 |
}
|
|
216 |
appendStatement(new ExpressionStatement(firstLineNumber, token, finish, callWithReturn));
|
|
217 |
|
|
218 |
Statement splitStateHandler;
|
|
219 |
|
|
220 |
final List<JumpStatement> jumpStatements = splitState.jumpStatements;
|
|
221 |
final int jumpCount = jumpStatements.size();
|
|
222 |
// There are jumps (breaks or continues) that need to be propagated outside the split node. We need to
|
|
223 |
// set up a switch statement for them:
|
|
224 |
// switch(:scope.getScopeState()) { ... }
|
|
225 |
if (jumpCount > 0) {
|
|
226 |
final List<CaseNode> cases = new ArrayList<>(jumpCount + (hasReturn ? 1 : 0));
|
|
227 |
if (hasReturn) {
|
|
228 |
// If the split node also contained a return, we'll slip it as a case in the switch statement
|
|
229 |
addCase(cases, RETURN_STATE, createReturnFromSplit());
|
|
230 |
}
|
|
231 |
int i = FIRST_JUMP_STATE;
|
|
232 |
for (final JumpStatement jump: jumpStatements) {
|
|
233 |
addCase(cases, i++, enblockAndVisit(jump));
|
|
234 |
}
|
|
235 |
splitStateHandler = new SwitchNode(NO_LINE_NUMBER, token, finish, GetSplitState.INSTANCE, cases, null);
|
|
236 |
} else {
|
|
237 |
splitStateHandler = null;
|
|
238 |
}
|
|
239 |
|
|
240 |
// As the switch statement itself is breakable, an unlabelled break can't be in the switch statement,
|
|
241 |
// so we need to test for it separately.
|
|
242 |
if (splitState.hasBreak) {
|
|
243 |
// if(:scope.getScopeState() == Scope.BREAK) { break; }
|
|
244 |
splitStateHandler = makeIfStateEquals(firstLineNumber, token, finish, BREAK_STATE,
|
|
245 |
enblockAndVisit(new BreakNode(NO_LINE_NUMBER, token, finish, null)), splitStateHandler);
|
|
246 |
}
|
|
247 |
|
|
248 |
// Finally, if the split node had a return statement, but there were no external jumps, we didn't have
|
|
249 |
// the switch statement to handle the return, so we need a separate if for it.
|
|
250 |
if (hasReturn && jumpCount == 0) {
|
|
251 |
// if (:scope.getScopeState() == Scope.RETURN) { return :return; }
|
|
252 |
splitStateHandler = makeIfStateEquals(NO_LINE_NUMBER, token, finish, RETURN_STATE,
|
|
253 |
createReturnFromSplit(), splitStateHandler);
|
|
254 |
}
|
|
255 |
|
|
256 |
if (splitStateHandler != null) {
|
|
257 |
appendStatement(splitStateHandler);
|
|
258 |
}
|
|
259 |
|
|
260 |
return splitNode;
|
|
261 |
}
|
|
262 |
|
|
263 |
private static void addCase(final List<CaseNode> cases, final int i, final Block body) {
|
|
264 |
cases.add(new CaseNode(NO_TOKEN, NO_FINISH, intLiteral(i), body));
|
|
265 |
}
|
|
266 |
|
|
267 |
private static LiteralNode<Number> intLiteral(final int i) {
|
|
268 |
return LiteralNode.newInstance(NO_TOKEN, NO_FINISH, i);
|
|
269 |
}
|
|
270 |
|
|
271 |
private static Block createReturnFromSplit() {
|
|
272 |
return new Block(NO_TOKEN, NO_FINISH, createReturnReturn());
|
|
273 |
}
|
|
274 |
|
|
275 |
private static ReturnNode createReturnReturn() {
|
|
276 |
return new ReturnNode(NO_LINE_NUMBER, NO_TOKEN, NO_FINISH, createReturnIdent());
|
|
277 |
}
|
|
278 |
|
|
279 |
private static IdentNode createReturnIdent() {
|
|
280 |
return createIdent(RETURN_NAME);
|
|
281 |
}
|
|
282 |
|
|
283 |
private static IdentNode createReturnParamIdent() {
|
|
284 |
return createIdent(RETURN_PARAM_NAME);
|
|
285 |
}
|
|
286 |
|
|
287 |
private static IdentNode createIdent(final String name) {
|
|
288 |
return new IdentNode(NO_TOKEN, NO_FINISH, name);
|
|
289 |
}
|
|
290 |
|
|
291 |
private Block enblockAndVisit(final JumpStatement jump) {
|
|
292 |
artificialBlock = true;
|
|
293 |
final Block block = (Block)new Block(NO_TOKEN, NO_FINISH, jump).accept(this);
|
|
294 |
artificialBlock = false;
|
|
295 |
return block;
|
|
296 |
}
|
|
297 |
|
|
298 |
private static IfNode makeIfStateEquals(final int lineNumber, final long token, final int finish,
|
|
299 |
final int value, final Block pass, final Statement fail) {
|
|
300 |
return new IfNode(lineNumber, token, finish,
|
|
301 |
new BinaryNode(Token.recast(token, TokenType.EQ_STRICT),
|
|
302 |
GetSplitState.INSTANCE, intLiteral(value)),
|
|
303 |
pass,
|
|
304 |
fail == null ? null : new Block(NO_TOKEN, NO_FINISH, fail));
|
|
305 |
}
|
|
306 |
|
|
307 |
@Override
|
|
308 |
public boolean enterVarNode(VarNode varNode) {
|
|
309 |
if (!inSplitNode()) {
|
|
310 |
return super.enterVarNode(varNode);
|
|
311 |
}
|
|
312 |
assert !varNode.isBlockScoped(); //TODO: we must handle these too, but we currently don't
|
|
313 |
|
|
314 |
final Expression init = varNode.getInit();
|
|
315 |
if (varNode.isAnonymousFunctionDeclaration()) {
|
|
316 |
// We ain't moving anonymous function declarations.
|
|
317 |
return super.enterVarNode(varNode);
|
|
318 |
}
|
|
319 |
|
|
320 |
// Move a declaration-only var statement to the top of the outermost function.
|
|
321 |
getCurrentFunctionState().varStatements.add(varNode.setInit(null));
|
|
322 |
// If it had an initializer, replace it with an assignment expression statement. Note that "var" is a
|
|
323 |
// statement, so it doesn't contribute to :return of the programs, therefore we are _not_ adding a
|
|
324 |
// ":return = ..." assignment around the original assignment.
|
|
325 |
if (init != null) {
|
|
326 |
final long token = Token.recast(varNode.getToken(), TokenType.ASSIGN);
|
|
327 |
new ExpressionStatement(varNode.getLineNumber(), token, varNode.getFinish(),
|
|
328 |
new BinaryNode(token, varNode.getName(), varNode.getInit())).accept(this);
|
|
329 |
}
|
|
330 |
|
|
331 |
return false;
|
|
332 |
}
|
|
333 |
|
|
334 |
@Override
|
|
335 |
public Node leaveBlock(final Block block) {
|
|
336 |
if (!artificialBlock) {
|
|
337 |
if (lc.isFunctionBody()) {
|
|
338 |
// Prepend declaration-only var statements to the top of the statement list.
|
|
339 |
lc.prependStatements(getCurrentFunctionState().varStatements);
|
|
340 |
} else if (lc.isSplitBody()) {
|
|
341 |
appendSplitReturn(FALLTHROUGH_STATE, NO_LINE_NUMBER);
|
|
342 |
if (getCurrentFunctionState().fn.isProgram()) {
|
|
343 |
// If we're splitting the program, make sure every shard ends with "return :return" and
|
|
344 |
// begins with ":return = :return-in;".
|
|
345 |
lc.prependStatement(new ExpressionStatement(NO_LINE_NUMBER, NO_TOKEN, NO_FINISH,
|
|
346 |
new BinaryNode(Token.toDesc(TokenType.ASSIGN, 0, 0), createReturnIdent(), createReturnParamIdent())));
|
|
347 |
}
|
|
348 |
}
|
|
349 |
}
|
|
350 |
return block;
|
|
351 |
}
|
|
352 |
|
|
353 |
@Override
|
|
354 |
public Node leaveBreakNode(final BreakNode breakNode) {
|
|
355 |
return leaveJumpNode(breakNode);
|
|
356 |
}
|
|
357 |
|
|
358 |
@Override
|
|
359 |
public Node leaveContinueNode(final ContinueNode continueNode) {
|
|
360 |
return leaveJumpNode(continueNode);
|
|
361 |
}
|
|
362 |
|
28690
|
363 |
@Override
|
|
364 |
public Node leaveJumpToInlinedFinally(final JumpToInlinedFinally jumpToInlinedFinally) {
|
|
365 |
return leaveJumpNode(jumpToInlinedFinally);
|
|
366 |
}
|
|
367 |
|
27206
|
368 |
private JumpStatement leaveJumpNode(final JumpStatement jump) {
|
|
369 |
if (inSplitNode()) {
|
|
370 |
final SplitState splitState = getCurrentSplitState();
|
|
371 |
final SplitNode splitNode = splitState.splitNode;
|
|
372 |
if (lc.isExternalTarget(splitNode, jump.getTarget(lc))) {
|
|
373 |
appendSplitReturn(splitState.getSplitStateIndex(jump), jump.getLineNumber());
|
|
374 |
return jump;
|
|
375 |
}
|
|
376 |
}
|
|
377 |
appendStatement(jump);
|
|
378 |
return jump;
|
|
379 |
}
|
|
380 |
|
|
381 |
private void appendSplitReturn(final int splitState, final int lineNumber) {
|
|
382 |
appendStatement(new SetSplitState(splitState, lineNumber));
|
|
383 |
if (getCurrentFunctionState().fn.isProgram()) {
|
|
384 |
// If we're splitting the program, make sure every fragment passes back :return
|
|
385 |
appendStatement(createReturnReturn());
|
|
386 |
} else {
|
|
387 |
appendStatement(SplitReturn.INSTANCE);
|
|
388 |
}
|
|
389 |
}
|
|
390 |
|
|
391 |
@Override
|
|
392 |
public Node leaveReturnNode(final ReturnNode returnNode) {
|
|
393 |
if(inSplitNode()) {
|
|
394 |
appendStatement(new SetSplitState(RETURN_STATE, returnNode.getLineNumber()));
|
|
395 |
getCurrentSplitState().hasReturn = true;
|
|
396 |
}
|
|
397 |
appendStatement(returnNode);
|
|
398 |
return returnNode;
|
|
399 |
}
|
|
400 |
|
|
401 |
private void appendStatement(final Statement statement) {
|
|
402 |
lc.appendStatement(statement);
|
|
403 |
}
|
|
404 |
|
|
405 |
private boolean inSplitNode() {
|
|
406 |
return getCurrentFunctionState().splitDepth > 0;
|
|
407 |
}
|
|
408 |
|
|
409 |
private FunctionState getCurrentFunctionState() {
|
|
410 |
return functionStates.peek();
|
|
411 |
}
|
|
412 |
|
|
413 |
private SplitState getCurrentSplitState() {
|
|
414 |
return splitStates.peek();
|
|
415 |
}
|
|
416 |
|
|
417 |
private static class FunctionState {
|
|
418 |
final FunctionNode fn;
|
|
419 |
final List<Statement> varStatements = new ArrayList<>();
|
|
420 |
int splitDepth;
|
|
421 |
|
|
422 |
FunctionState(final FunctionNode fn) {
|
|
423 |
this.fn = fn;
|
|
424 |
}
|
|
425 |
}
|
|
426 |
|
|
427 |
private static class SplitState {
|
|
428 |
final SplitNode splitNode;
|
|
429 |
boolean hasReturn;
|
|
430 |
boolean hasBreak;
|
|
431 |
|
|
432 |
final List<JumpStatement> jumpStatements = new ArrayList<>();
|
|
433 |
|
|
434 |
int getSplitStateIndex(final JumpStatement jump) {
|
|
435 |
if (jump instanceof BreakNode && jump.getLabelName() == null) {
|
|
436 |
// Unlabelled break is a special case
|
|
437 |
hasBreak = true;
|
|
438 |
return BREAK_STATE;
|
|
439 |
}
|
|
440 |
|
|
441 |
int i = 0;
|
|
442 |
for(final JumpStatement exJump: jumpStatements) {
|
|
443 |
if (jump.getClass() == exJump.getClass() && Objects.equals(jump.getLabelName(), exJump.getLabelName())) {
|
|
444 |
return i + FIRST_JUMP_STATE;
|
|
445 |
}
|
|
446 |
++i;
|
|
447 |
}
|
|
448 |
jumpStatements.add(jump);
|
|
449 |
return i + FIRST_JUMP_STATE;
|
|
450 |
}
|
|
451 |
|
|
452 |
SplitState(final SplitNode splitNode) {
|
|
453 |
this.splitNode = splitNode;
|
|
454 |
}
|
|
455 |
}
|
|
456 |
}
|