Fixed: #2324 AS3 direct editation - nested loop continue/break (with labels)

This commit is contained in:
Jindra Petřík
2024-09-26 19:22:31 +02:00
parent 3829caad24
commit 4efa3191e7
3 changed files with 17 additions and 5 deletions

View File

@@ -397,14 +397,20 @@ public class AVM2SourceGenerator implements SourceGenerator {
pos += ins.getBytesLength();
if (ins.definition instanceof JumpIns) {
if (ins.definition instanceof ContinueJumpIns) {
if (continueOffset != Integer.MAX_VALUE) {
ins.operands[0] = (-pos + continueOffset);
ins.definition = AVM2Code.instructionSet[AVM2Instructions.Jump];
ContinueJumpIns cji = (ContinueJumpIns) ins.definition;
if (cji.getLoopId() == loopId) {
if (continueOffset != Integer.MAX_VALUE) {
ins.operands[0] = (-pos + continueOffset);
ins.definition = AVM2Code.instructionSet[AVM2Instructions.Jump];
}
}
}
if (ins.definition instanceof BreakJumpIns) {
ins.operands[0] = (-pos + breakOffset);
ins.definition = AVM2Code.instructionSet[AVM2Instructions.Jump];
BreakJumpIns bji = (BreakJumpIns) ins.definition;
if (bji.getLoopId() == loopId) {
ins.operands[0] = (-pos + breakOffset);
ins.definition = AVM2Code.instructionSet[AVM2Instructions.Jump];
}
}
}
}

View File

@@ -1711,6 +1711,7 @@ public class ActionScript3Parser {
loops.push(wloop);
whileBody.add(command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables, abc));
ret = new WhileItem(null, null, wloop, whileExpr, whileBody);
loops.pop();
break;
case DO:
List<GraphTargetItem> doBody = new ArrayList<>();
@@ -1726,6 +1727,7 @@ public class ActionScript3Parser {
doExpr.add(expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, true, abc));
expectedType(SymbolType.PARENT_CLOSE);
ret = new DoWhileItem(null, null, dloop, doBody, doExpr);
loops.pop();
break;
case FOR:
s = lex();
@@ -1791,6 +1793,7 @@ public class ActionScript3Parser {
} else {
ret = new ForItem(null, null, floop, forFirstCommands, forExpr, forFinalCommands, forBody);
}
loops.pop();
break;
case SWITCH:
Loop sloop = new Loop(-uniqId(), null, null); //negative id marks switch = no continue
@@ -1833,6 +1836,7 @@ public class ActionScript3Parser {
}
expected(s, lexer.yyline(), SymbolType.CURLY_CLOSE);
ret = new SwitchItem(null, null, sloop, switchExpr, caseExprsAll, caseCmds, valueMapping);
loops.pop();
break;
case BREAK:
s = lex();