Issue #114 better loop detection

This commit is contained in:
Jindra Petk
2013-06-26 21:22:19 +02:00
parent 1d64c3e166
commit cdfe475fce
10 changed files with 75 additions and 23 deletions

View File

@@ -30,6 +30,7 @@ import com.jpexs.decompiler.flash.action.swf5.*;
import com.jpexs.decompiler.flash.action.swf7.ActionDefineFunction2;
import com.jpexs.decompiler.flash.action.treemodel.*;
import com.jpexs.decompiler.flash.action.treemodel.clauses.*;
import com.jpexs.decompiler.flash.graph.CommentItem;
import com.jpexs.decompiler.flash.graph.Graph;
import com.jpexs.decompiler.flash.graph.GraphSource;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
@@ -800,7 +801,14 @@ public class Action implements GraphSourceItem {
outs.add(new ArrayList<GraphTargetItem>());
continue;
}
List<GraphTargetItem> out = ActionGraph.translateViaGraph(cnt.getRegNames(), variables, functions, actions.subList(adr2ip(actions, endAddr, version), adr2ip(actions, endAddr + size, version)), version);
List<GraphTargetItem> out;
try {
out = ActionGraph.translateViaGraph(cnt.getRegNames(), variables, functions, actions.subList(adr2ip(actions, endAddr, version), adr2ip(actions, endAddr + size, version)), version);
} catch (RuntimeException re) {
out = new ArrayList<>();
out.add(new CommentItem("Error " + re.getMessage()));
Logger.getLogger(Action.class.getName()).log(Level.SEVERE, "Error during container translation", re);
}
outs.add(out);
endAddr += size;
}

View File

@@ -54,7 +54,7 @@ public class ActionSetProperty extends Action {
if (value.getThroughDuplicate() instanceof IncrementTreeItem) {
GraphTargetItem obj = ((IncrementTreeItem) value).object;
if (!stack.isEmpty()) {
if (stack.peek().equals(obj)) {
if (stack.peek().valueEquals(obj)) {
stack.pop();
stack.push(new PostIncrementTreeItem(this, obj));
return;
@@ -64,7 +64,7 @@ public class ActionSetProperty extends Action {
if (value instanceof DecrementTreeItem) {
GraphTargetItem obj = ((DecrementTreeItem) value).object;
if (!stack.isEmpty()) {
if (stack.peek().equals(obj)) {
if (stack.peek().valueEquals(obj)) {
stack.pop();
stack.push(new PostDecrementTreeItem(this, obj));
return;

View File

@@ -50,7 +50,7 @@ public class ActionSetVariable extends Action {
if (value instanceof IncrementTreeItem) {
GraphTargetItem obj = ((IncrementTreeItem) value).object;
if (!stack.isEmpty()) {
if (stack.peek().equals(obj)) {
if (stack.peek().valueEquals(obj)) {
stack.pop();
stack.push(new PostIncrementTreeItem(this, obj));
return;
@@ -60,7 +60,7 @@ public class ActionSetVariable extends Action {
if (value instanceof DecrementTreeItem) {
GraphTargetItem obj = ((DecrementTreeItem) value).object;
if (!stack.isEmpty()) {
if (stack.peek().equals(obj)) {
if (stack.peek().valueEquals(obj)) {
stack.pop();
stack.push(new PostDecrementTreeItem(this, obj));
return;
@@ -69,7 +69,7 @@ public class ActionSetVariable extends Action {
}
if (value instanceof IncrementTreeItem) {
if (((IncrementTreeItem) value).object instanceof GetVariableTreeItem) {
if (((GetVariableTreeItem) ((IncrementTreeItem) value).object).name.equals(name)) {
if (((GetVariableTreeItem) ((IncrementTreeItem) value).object).name.valueEquals(name)) {
output.add(new PostIncrementTreeItem(this, ((IncrementTreeItem) value).object));
return;
}
@@ -77,7 +77,7 @@ public class ActionSetVariable extends Action {
}
if (value instanceof DecrementTreeItem) {
if (((DecrementTreeItem) value).object instanceof GetVariableTreeItem) {
if (((GetVariableTreeItem) ((DecrementTreeItem) value).object).name.equals(name)) {
if (((GetVariableTreeItem) ((DecrementTreeItem) value).object).name.valueEquals(name)) {
output.add(new PostDecrementTreeItem(this, ((DecrementTreeItem) value).object));
return;
}

View File

@@ -48,7 +48,7 @@ public class ActionSetMember extends Action {
if (value instanceof IncrementTreeItem) {
GraphTargetItem obj = ((IncrementTreeItem) value).object;
if (!stack.isEmpty()) {
if (stack.peek().equals(obj)) {
if (stack.peek().valueEquals(obj)) {
stack.pop();
stack.push(new PostIncrementTreeItem(this, obj));
return;
@@ -58,7 +58,7 @@ public class ActionSetMember extends Action {
if (value instanceof DecrementTreeItem) {
GraphTargetItem obj = ((DecrementTreeItem) value).object;
if (!stack.isEmpty()) {
if (stack.peek().equals(obj)) {
if (stack.peek().valueEquals(obj)) {
stack.pop();
stack.push(new PostDecrementTreeItem(this, obj));
return;
@@ -78,7 +78,7 @@ public class ActionSetMember extends Action {
}
if (value instanceof DecrementTreeItem) {
if (((DecrementTreeItem) value).object instanceof GetMemberTreeItem) {
if (((GetMemberTreeItem) ((DecrementTreeItem) value).object).object.equals(object)) {
if (((GetMemberTreeItem) ((DecrementTreeItem) value).object).object.valueEquals(object)) {
if (((GetMemberTreeItem) ((DecrementTreeItem) value).object).memberName.equals(memberName)) {
output.add(new PostDecrementTreeItem(this, ((DecrementTreeItem) value).object));
return;

View File

@@ -100,7 +100,7 @@ public class ActionStoreRegister extends Action {
if (value instanceof IncrementTreeItem) {
GraphTargetItem obj = ((IncrementTreeItem) value).object;
if (!stack.isEmpty()) {
if (stack.peek().equals(obj)) {
if (stack.peek().valueEquals(obj)) {
stack.pop();
stack.push(new PostIncrementTreeItem(this, obj));
stack.push(obj);
@@ -111,7 +111,7 @@ public class ActionStoreRegister extends Action {
if (value instanceof DecrementTreeItem) {
GraphTargetItem obj = ((DecrementTreeItem) value).object;
if (!stack.isEmpty()) {
if (stack.peek().equals(obj)) {
if (stack.peek().valueEquals(obj)) {
stack.pop();
stack.push(new PostDecrementTreeItem(this, obj));
stack.push(obj);

View File

@@ -195,9 +195,27 @@ public class DirectValueTreeItem extends TreeItem {
@Override
public int hashCode() {
int hash = 7;
hash = 71 * hash + Objects.hashCode(this.value);
hash = 71 * hash + Objects.hashCode(this.constants);
hash = 71 * hash + pos;
return hash;
}
@Override
public boolean valueEquals(GraphTargetItem obj) {
if (obj == null) {
return false;
}
final DirectValueTreeItem other = (DirectValueTreeItem) obj;
if (!Objects.equals(this.value, other.value)) {
return false;
}
if (!Objects.equals(this.constants, other.constants)) {
return false;
}
return true;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {

View File

@@ -343,7 +343,12 @@ public class Graph {
return null;
}
List<GraphPart> loopContinues = getLoopsContinues(loops);
List<GraphPart> loopContinues = new ArrayList<>();//getLoopsContinues(loops);
for (Loop l : loops) {
if (l.phase == 1) {
loopContinues.add(l.loopContinue);
}
}
for (GraphPart p : parts) {
if (loopContinues.contains(p)) {
@@ -417,9 +422,9 @@ public class Graph {
System.out.println("</loops>");*/
getPrecontinues(null, heads.get(0), loops, null);
/*System.out.println("<loopspre>");
for (Loop el : loops) {
System.out.println(el);
}
for (Loop el : loops) {
System.out.println(el);
}
System.out.println("</loopspre>");*/
List<GraphTargetItem> ret = printGraph(new ArrayList<GraphPart>(), localData, stack, allParts, null, heads.get(0), null, loops);
@@ -962,6 +967,9 @@ public class Graph {
}
for (int i = currentLoop.breakCandidates.size() - 1; i >= 0; i--) {
if (spcheck.contains(currentLoop.breakCandidates.get(i))) {
if (currentLoop.breakCandidates.get(i).start >= code.size()) {
continue;
}
currentLoop.breakCandidatesLevels.remove(i);
backupCandidates.add(currentLoop.breakCandidates.remove(i));
}
@@ -1028,7 +1036,7 @@ public class Graph {
}
removed.add(found);
}
} while (found != null);
} while ((found != null) && (currentLoop.breakCandidates.size() > 1));
Map<GraphPart, Integer> count = new HashMap<>();
GraphPart winner = null;
@@ -1237,14 +1245,23 @@ public class Graph {
continue;
}
if (el.loopBreak == part) {
if (currentLoop != null) {
currentLoop.phase = 0;
}
ret.add(new BreakItem(null, el.id));
return ret;
}
if (el.loopPreContinue == part) {
if (currentLoop != null) {
currentLoop.phase = 0;
}
ret.add(new ContinueItem(null, el.id));
return ret;
}
if (el.loopContinue == part) {
if (currentLoop != null) {
currentLoop.phase = 0;
}
ret.add(new ContinueItem(null, el.id));
return ret;
}
@@ -1253,6 +1270,9 @@ public class Graph {
if (stopPart.contains(part)) {
if (currentLoop != null) {
currentLoop.phase = 0;
}
return ret;
}
@@ -1613,14 +1633,18 @@ public class Graph {
List<GraphTargetItem> commands = new ArrayList<>();
loopItem.commands.remove(loopItem.commands.size() - 1);
if (!bodyBranch.isEmpty()) {
/*exprList.addAll(loopItem.commands);
ret.add(index, loopItem);
/*
loopItem.commands.remove(loopItem.commands.size() - 1);
exprList.addAll(loopItem.commands);
commands.addAll(bodyBranch);
exprList.add(expr);
checkContinueAtTheEnd(commands, currentLoop);
ret.add(index, li = new WhileItem(null, currentLoop, exprList, commands));*/
} else {
loopItem.commands.remove(loopItem.commands.size() - 1);
commands.addAll(loopItem.commands);
commands.addAll(bodyBranch);
exprList.add(expr);

View File

@@ -74,7 +74,7 @@ public class GraphPart {
return false;
}
if (l.loopBreak == this) {
return false;
//return false; //?
}
}
}

View File

@@ -162,4 +162,8 @@ public abstract class GraphTargetItem {
public GraphTargetItem getThroughDuplicate() {
return this;
}
public boolean valueEquals(GraphTargetItem target) {
return equals(target);
}
}

View File

@@ -426,9 +426,6 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi
JMenuItem miGotoDocumentClass = new JMenuItem("Go to document class");
miGotoDocumentClass.setActionCommand("GOTODOCUMENTCLASS");
miGotoDocumentClass.addActionListener(this);
if (swf.fileAttributes.actionScript3) {
menuTools.add(miGotoDocumentClass);
}
menuBar.add(menuTools);
JMenu menuSettings = new JMenu("Settings");
@@ -499,6 +496,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi
if (!abcList.isEmpty()) {
addTab(tabPane, abcPanel = new ABCPanel(abcList), "ActionScript3", View.getIcon("as16"));
detailPanel.add(abcPanel.tabbedPane, DETAILCARDAS3NAVIGATOR);
menuTools.add(miGotoDocumentClass);
} else {
actionPanel = new ActionPanel();
addTab(tabPane, actionPanel, "ActionScript", View.getIcon("as16"));