diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java b/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java index 54c258b94..713468410 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java @@ -463,6 +463,21 @@ public class Graph { return ret; } + private void markBranchEnd(List items) { + if (!items.isEmpty()) { + if (items.get(items.size() - 1) instanceof BreakItem) { + return; + } + if (items.get(items.size() - 1) instanceof ContinueItem) { + return; + } + if (items.get(items.size() - 1) instanceof ExitItem) { + return; + } + } + items.add(new MarkItem("finish")); + } + protected List printGraph(List visited, List localData, Stack stack, List allParts, GraphPart parent, GraphPart part, GraphPart stopPart, List loops, HashMap> forFinalCommands) { if (visited.contains(part)) { //return new ArrayList(); @@ -862,6 +877,9 @@ public class Graph { System.err.println("ONTRUE: (inside " + part + ")"); } onTrue = printGraph(visited, prepareBranchLocalData(localData), trueStack, allParts, part, part.nextParts.get(1), next == null ? stopPart : next, loops, forFinalCommands); + if (next == null) { + markBranchEnd(onTrue); + } if (debugMode) { System.err.println("/ONTRUE (inside " + part + ")"); } @@ -880,6 +898,9 @@ public class Graph { onFalse = new ArrayList(); } else { onFalse = (printGraph(visited, prepareBranchLocalData(localData), falseStack, allParts, part, part.nextParts.get(0), next == null ? stopPart : next, loops, forFinalCommands)); + if (next == null) { + markBranchEnd(onFalse); + } } if (debugMode) { System.err.println("/ONFALSE (inside " + part + ")"); @@ -991,7 +1012,7 @@ public class Graph { List nextcmds = new ArrayList(); if ((!loopBody.isEmpty()) && (loopBody.get(loopBody.size() - 1) instanceof IfItem)) { IfItem ift = (IfItem) loopBody.get(loopBody.size() - 1); - if ((!ift.onFalse.isEmpty()) && (ift.onFalse.get(ift.onFalse.size() - 1) instanceof ExitItem)) {//((ift.onFalse.size() == 1) && (ift.onFalse.get(0) instanceof ContinueItem) && (((ContinueItem) ift.onFalse.get(0)).loopId == currentLoop.id))) { + if ((!ift.onFalse.isEmpty()) && ((ift.onFalse.get(ift.onFalse.size() - 1) instanceof ExitItem) || ((ift.onFalse.get(ift.onFalse.size() - 1) instanceof MarkItem) && ((MarkItem) (ift.onFalse.get(ift.onFalse.size() - 1))).getMark().equals("finish")))) {//((ift.onFalse.size() == 1) && (ift.onFalse.get(0) instanceof ContinueItem) && (((ContinueItem) ift.onFalse.get(0)).loopId == currentLoop.id))) { if (ift.expression != null) { expr = ift.expression; /*if (expr instanceof LogicalOpItem) { @@ -1004,7 +1025,7 @@ public class Graph { newBody = ift.onTrue; loopBody.remove(loopBody.size() - 1); - } else if ((!ift.onTrue.isEmpty()) && (ift.onTrue.get(ift.onTrue.size() - 1) instanceof ExitItem)) {//((ift.onTrue.size() == 1) && (ift.onTrue.get(0) instanceof ContinueItem) && (((ContinueItem) ift.onTrue.get(0)).loopId == currentLoop.id))) { + } else if ((!ift.onTrue.isEmpty()) && ((ift.onTrue.get(ift.onTrue.size() - 1) instanceof ExitItem) || ((ift.onTrue.get(ift.onTrue.size() - 1) instanceof MarkItem) && ((MarkItem) (ift.onTrue.get(ift.onTrue.size() - 1))).getMark().equals("finish")))) {//((ift.onTrue.size() == 1) && (ift.onTrue.get(0) instanceof ContinueItem) && (((ContinueItem) ift.onTrue.get(0)).loopId == currentLoop.id))) { if (ift.expression != null) { expr = ift.expression; if (expr instanceof LogicalOpItem) { @@ -1135,13 +1156,16 @@ public class Graph { } } if ((nearestLoop != null)) {// && (nearestLoop.loopBreak != null)) { - GraphPart oldCont = nearestLoop.loopContinue; + List finalCommands = printGraph(visited, localData, stack, allParts, part, p, nearestLoop.loopContinue, loops, forFinalCommands); nearestLoop.loopContinue = p; - List finalCommands = printGraph(visited, localData, stack, allParts, part, p, oldCont, loops, forFinalCommands); forFinalCommands.put(nearestLoop, finalCommands); ContinueItem cti = new ContinueItem(null, nearestLoop.id); ret.add(cti); + } else { + //ret.add(new MarkItem("nextloop_notfound")); } + } else { + //ret.add(new MarkItem("stoppart_reached")); } } } else { diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/MarkItem.java b/trunk/src/com/jpexs/decompiler/flash/graph/MarkItem.java new file mode 100644 index 000000000..16c5921a3 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/graph/MarkItem.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2013 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.graph; + +import java.util.List; + +/** + * + * @author JPEXS + */ +public class MarkItem extends GraphTargetItem { + + private String mark; + + public MarkItem(String mark) { + super(null, NOPRECEDENCE); + this.mark = mark; + } + + @Override + public String toString(List localData) { + return "//decompiler mark:" + mark; + } + + public String getMark() { + return mark; + } + + @Override + public boolean isEmpty() { + return true; + } +}