Fixed AS3: try..catch in do..while vs do..while in try..catch

This commit is contained in:
Jindra Petřík
2021-02-06 08:42:52 +01:00
parent 2a3811cc30
commit 9e07695427
14 changed files with 375 additions and 6 deletions

View File

@@ -1086,6 +1086,45 @@ public class AVM2Graph extends Graph {
return false;
}
@Override
protected boolean canHandleLoop(BaseLocalData localData, GraphPart part, List<Loop> loops) {
Loop toBeLoop = null;
for (Loop el : loops) {
if ((el.loopContinue == part) && (el.phase == 0)) {
toBeLoop = el;
break;
}
}
if (toBeLoop == null) {
return true;
}
AVM2LocalData aLocalData = (AVM2LocalData) localData;
boolean inTry = false;
for (ABCException ex : body.exceptions) {
if (aLocalData.parsedExceptions.contains(ex)) {
continue;
}
int fixStart = avm2code.adr2pos(ex.start, true);
int fixEnd = avm2code.adr2pos(ex.end, true);
if (part.start == fixStart) {
inTry = true;
for (GraphPart be : toBeLoop.backEdges) {
if (be.start < fixStart || be.start >= fixEnd) {
//exists a backedge that is outside of try..catch
return true;
}
}
}
}
if (inTry) {
//it is in try and there's no backedge that's outside try
return false;
}
return true;
}
@Override
protected boolean checkPartOutput(List<GraphTargetItem> currentRet, List<GotoItem> foundGotos, Map<GraphPart, List<GraphTargetItem>> partCodes, Map<GraphPart, Integer> partCodePos, GraphSource code, BaseLocalData localData, Set<GraphPart> allParts, TranslateStack stack, GraphPart parent, GraphPart part, List<GraphPart> stopPart, List<Loop> loops, Loop currentLoop, int staticOperation, String path) throws InterruptedException {
AVM2LocalData aLocalData = (AVM2LocalData) localData;
@@ -1338,7 +1377,7 @@ public class AVM2Graph extends Graph {
if (ft instanceof WithAVM2Item) {
pos++;
List<GraphTargetItem> withCommands = new ArrayList<>();
while (!(w.commands.get(pos) instanceof WithEndAVM2Item)) {
while (pos < w.commands.size() && !(w.commands.get(pos) instanceof WithEndAVM2Item)) {
withCommands.add(w.commands.get(pos));
pos++;
}

View File

@@ -1448,6 +1448,9 @@ public class Graph {
return false;
}
protected boolean canHandleLoop(BaseLocalData localData, GraphPart part, List<Loop> loops) {
return true;
}
protected List<GraphTargetItem> printGraph(List<GotoItem> foundGotos, Map<GraphPart, List<GraphTargetItem>> partCodes, Map<GraphPart, Integer> partCodePos, Set<GraphPart> visited, BaseLocalData localData, TranslateStack stack, Set<GraphPart> allParts, GraphPart parent, GraphPart part, List<GraphPart> stopPart, List<Loop> loops, List<GraphTargetItem> ret, int staticOperation, String path, int recursionLevel) throws InterruptedException {
if (Thread.currentThread().isInterrupted()) {
throw new InterruptedException();
@@ -1495,11 +1498,19 @@ public class Graph {
//List<GraphPart> loopContinues = getLoopsContinues(loops);
boolean isLoop = false;
Loop currentLoop = null;
boolean vCanHandleLoop = canHandleLoop(localData, part, loops);
Loop ignoredLoop = null;
for (Loop el : loops) {
if ((el.loopContinue == part) && (el.phase == 0)) {
currentLoop = el;
currentLoop.phase = 1;
isLoop = true;
if (vCanHandleLoop) {
currentLoop = el;
currentLoop.phase = 1;
isLoop = true;
} else {
ignoredLoop = el;
}
break;
}
}
@@ -1509,6 +1520,12 @@ public class Graph {
}
for (int l = loops.size() - 1; l >= 0; l--) {
Loop el = loops.get(l);
if (el == ignoredLoop) {
if (debugPrintGraph) {
System.err.println("ignoring to be loop " + el);
}
continue;
}
if (el == currentLoop) {
if (debugPrintGraph) {
System.err.println("ignoring current loop " + el);