For in break detection with inner switch statement

This commit is contained in:
Jindra Petřík
2018-05-27 22:10:54 +02:00
parent 6c998254b9
commit f61772c8f7
6 changed files with 54 additions and 1 deletions

View File

@@ -56,6 +56,7 @@ import com.jpexs.decompiler.graph.model.ContinueItem;
import com.jpexs.decompiler.graph.model.DefaultItem;
import com.jpexs.decompiler.graph.model.IfItem;
import com.jpexs.decompiler.graph.model.SwitchItem;
import com.jpexs.decompiler.graph.model.UniversalLoopItem;
import com.jpexs.decompiler.graph.model.WhileItem;
import com.jpexs.helpers.Helper;
import java.util.ArrayList;
@@ -140,6 +141,24 @@ public class ActionGraph extends Graph {
}
}
@Override
protected boolean canBeBreakCandidate(GraphPart part) {
if (part.refs.size() <= 1) {
return true;
}
boolean isSwitch = true;
for (GraphPart r : part.refs) {
if (code.get(r.end) instanceof ActionIf) {
if (!(r.start < r.end - 1 && (code.get(r.end - 1) instanceof ActionStrictEquals))) {
isSwitch = false;
}
} else {
isSwitch = false;
}
}
return !isSwitch;
}
@Override
protected void finalProcess(List<GraphTargetItem> list, int level, FinalProcessLocalData localData, String path) throws InterruptedException {

View File

@@ -20,7 +20,9 @@ import com.jpexs.decompiler.flash.BaseLocalData;
import com.jpexs.decompiler.flash.FinalProcessLocalData;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.model.FunctionActionItem;
import com.jpexs.decompiler.flash.action.swf4.ActionIf;
import com.jpexs.decompiler.flash.action.swf5.ActionDefineFunction;
import com.jpexs.decompiler.flash.action.swf6.ActionStrictEquals;
import com.jpexs.decompiler.flash.action.swf7.ActionDefineFunction2;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.model.AndItem;
@@ -1309,6 +1311,10 @@ public class Graph {
clearLoops(loops);
}
protected boolean canBeBreakCandidate(GraphPart part) {
return true;
}
private void getLoops(BaseLocalData localData, GraphPart part, List<Loop> loops, List<GraphPart> stopPart, boolean first, int level, List<GraphPart> visited) throws InterruptedException {
if (part == null) {
@@ -1339,7 +1345,7 @@ public class Graph {
}
}
if (lastP1 != null) {
if (lastP1 != null && canBeBreakCandidate(part)) {
if (lastP1.breakCandidates.contains(part)) {
lastP1.breakCandidates.add(part);
lastP1.breakCandidatesLevels.add(level);