better duplicate handling

This commit is contained in:
Jindra Petk
2013-05-25 19:53:04 +02:00
parent 0836232014
commit acbaa19dac
13 changed files with 129 additions and 41 deletions

View File

@@ -61,11 +61,11 @@ public abstract class SetLocalTypeIns extends InstructionDefinition implements S
return;
}
if (value.getNotCoerced() instanceof IncrementTreeItem) {
GraphTargetItem inside = ((IncrementTreeItem) value.getNotCoerced()).object.getNotCoerced();
GraphTargetItem inside = ((IncrementTreeItem) value.getNotCoerced()).object.getNotCoerced().getThroughDuplicate();
if (inside instanceof LocalRegTreeItem) {
if (((LocalRegTreeItem) inside).regIndex == regId) {
if (stack.size() > 0) {
GraphTargetItem top = stack.peek().getNotCoerced();
GraphTargetItem top = stack.peek().getNotCoerced().getThroughDuplicate();
if (top == inside) {
stack.pop();
stack.push(new PostIncrementTreeItem(ins, inside));
@@ -84,11 +84,11 @@ public abstract class SetLocalTypeIns extends InstructionDefinition implements S
}
if (value.getNotCoerced() instanceof DecrementTreeItem) {
GraphTargetItem inside = ((DecrementTreeItem) value.getNotCoerced()).object.getNotCoerced();
GraphTargetItem inside = ((DecrementTreeItem) value.getNotCoerced()).object.getNotCoerced().getThroughDuplicate();
if (inside instanceof LocalRegTreeItem) {
if (((LocalRegTreeItem) inside).regIndex == regId) {
if (stack.size() > 0) {
GraphTargetItem top = stack.peek().getNotCoerced();
GraphTargetItem top = stack.peek().getNotCoerced().getThroughDuplicate();
if (top == inside) {
stack.pop();
stack.push(new PostDecrementTreeItem(ins, inside));

View File

@@ -51,18 +51,18 @@ public class SetPropertyIns extends InstructionDefinition implements SetTypeIns
GraphTargetItem value = (GraphTargetItem) stack.pop();
FullMultinameTreeItem multiname = resolveMultiname(stack, constants, multinameIndex, ins);
GraphTargetItem obj = (GraphTargetItem) stack.pop();
if (value.getThroughRegister() instanceof IncrementTreeItem) {
GraphTargetItem inside = ((IncrementTreeItem) value.getThroughRegister()).object.getThroughRegister().getNotCoerced();
if (value.getThroughDuplicate().getThroughRegister().getThroughDuplicate() instanceof IncrementTreeItem) {
GraphTargetItem inside = ((IncrementTreeItem) value.getThroughDuplicate().getThroughRegister().getThroughDuplicate()).object.getThroughRegister().getNotCoerced().getThroughDuplicate();
if (inside instanceof GetPropertyTreeItem) {
GetPropertyTreeItem insideProp = ((GetPropertyTreeItem) inside);
if (insideProp.propertyName.compareSame(multiname)) {
GraphTargetItem insideObj = obj;
GraphTargetItem insideObj = obj.getThroughDuplicate();
if (insideObj instanceof LocalRegTreeItem) {
insideObj = ((LocalRegTreeItem) insideObj).computedValue.getThroughNotCompilable();
insideObj = ((LocalRegTreeItem) insideObj).computedValue.getThroughNotCompilable().getThroughDuplicate();
}
if (insideProp.object == insideObj) {
if (insideProp.object.getThroughDuplicate() == insideObj) {
if (stack.size() > 0) {
GraphTargetItem top = stack.peek().getNotCoerced();
GraphTargetItem top = stack.peek().getNotCoerced().getThroughDuplicate();
if (top == insideProp) {
stack.pop();
stack.push(new PostIncrementTreeItem(ins, insideProp));
@@ -81,18 +81,18 @@ public class SetPropertyIns extends InstructionDefinition implements SetTypeIns
}
}
if (value.getThroughRegister() instanceof DecrementTreeItem) {
GraphTargetItem inside = ((DecrementTreeItem) value.getThroughRegister()).object.getThroughRegister().getNotCoerced();
if (value.getThroughDuplicate().getThroughRegister().getThroughDuplicate() instanceof DecrementTreeItem) {
GraphTargetItem inside = ((DecrementTreeItem) value.getThroughDuplicate().getThroughRegister().getThroughDuplicate()).object.getThroughRegister().getNotCoerced().getThroughDuplicate();
if (inside instanceof GetPropertyTreeItem) {
GetPropertyTreeItem insideProp = ((GetPropertyTreeItem) inside);
if (insideProp.propertyName.compareSame(multiname)) {
GraphTargetItem insideObj = obj;
GraphTargetItem insideObj = obj.getThroughDuplicate();
if (insideObj instanceof LocalRegTreeItem) {
insideObj = ((LocalRegTreeItem) insideObj).computedValue.getThroughNotCompilable();
insideObj = ((LocalRegTreeItem) insideObj).computedValue.getThroughNotCompilable().getThroughDuplicate();
}
if (insideProp.object == insideObj) {
if (insideProp.object.getThroughDuplicate() == insideObj) {
if (stack.size() > 0) {
GraphTargetItem top = stack.peek().getNotCoerced();
GraphTargetItem top = stack.peek().getNotCoerced().getThroughDuplicate();
if (top == insideProp) {
stack.pop();
stack.push(new PostDecrementTreeItem(ins, insideProp));

View File

@@ -96,14 +96,14 @@ public class SetSlotIns extends InstructionDefinition implements SetTypeIns {
};
}
if (value.getNotCoerced() instanceof IncrementTreeItem) {
GraphTargetItem inside = ((IncrementTreeItem) value.getNotCoerced()).object.getThroughRegister().getNotCoerced();
if (value.getNotCoerced().getThroughDuplicate() instanceof IncrementTreeItem) {
GraphTargetItem inside = ((IncrementTreeItem) value.getNotCoerced()).object.getThroughRegister().getNotCoerced().getThroughDuplicate();
if (inside instanceof GetSlotTreeItem) {
GetSlotTreeItem slotItem = (GetSlotTreeItem) inside;
if ((slotItem.scope.getThroughRegister() == obj.getThroughRegister())
&& (slotItem.slotName == slotname)) {
if (stack.size() > 0) {
GraphTargetItem top = stack.peek().getNotCoerced();
GraphTargetItem top = stack.peek().getNotCoerced().getThroughDuplicate();
if (top == inside) {
stack.pop();
stack.push(new PostIncrementTreeItem(ins, inside));
@@ -121,14 +121,14 @@ public class SetSlotIns extends InstructionDefinition implements SetTypeIns {
}
}
if (value.getNotCoerced() instanceof DecrementTreeItem) {
GraphTargetItem inside = ((DecrementTreeItem) value.getNotCoerced()).object.getThroughRegister().getNotCoerced();
if (value.getNotCoerced().getThroughDuplicate() instanceof DecrementTreeItem) {
GraphTargetItem inside = ((DecrementTreeItem) value.getNotCoerced()).object.getThroughRegister().getNotCoerced().getThroughDuplicate();
if (inside instanceof GetSlotTreeItem) {
GetSlotTreeItem slotItem = (GetSlotTreeItem) inside;
if ((slotItem.scope.getThroughRegister() == obj.getThroughRegister())
&& (slotItem.slotName == slotname)) {
if (stack.size() > 0) {
GraphTargetItem top = stack.peek().getNotCoerced();
GraphTargetItem top = stack.peek().getNotCoerced().getThroughDuplicate();
if (top == inside) {
stack.pop();
stack.push(new PostDecrementTreeItem(ins, inside));

View File

@@ -22,7 +22,7 @@ import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.flash.graph.GraphSourceItemPos;
import com.jpexs.decompiler.flash.graph.DuplicateItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import java.util.HashMap;
import java.util.List;
@@ -45,8 +45,8 @@ public class DupIns extends InstructionDefinition {
public void translate(boolean isStatic, int scriptIndex, int classIndex, java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, java.util.Stack<GraphTargetItem> scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List<GraphTargetItem> output, com.jpexs.decompiler.flash.abc.types.MethodBody body, com.jpexs.decompiler.flash.abc.ABC abc, HashMap<Integer, String> localRegNames, List<String> fullyQualifiedNames) {
GraphTargetItem v = stack.pop();
stack.push(v);
stack.push(v);
v.moreSrc.add(new GraphSourceItemPos(ins, 0));
stack.push(new DuplicateItem(ins, v));
//v.moreSrc.add(new GraphSourceItemPos(ins, 0));
}

View File

@@ -41,6 +41,6 @@ public class CoerceTreeItem extends TreeItem {
@Override
public GraphTargetItem getNotCoerced() {
return value;
return value.getNotCoerced();
}
}

View File

@@ -41,6 +41,6 @@ public class ConvertTreeItem extends TreeItem {
@Override
public GraphTargetItem getNotCoerced() {
return value;
return value.getNotCoerced();
}
}

View File

@@ -97,26 +97,38 @@ public class FullMultinameTreeItem extends TreeItem {
return false;
}
GraphTargetItem tiName = name;
if (name != null) {
name = name.getThroughDuplicate();
}
while (tiName instanceof LocalRegTreeItem) {
tiName = ((LocalRegTreeItem) tiName).computedValue.getThroughNotCompilable();
tiName = ((LocalRegTreeItem) tiName).computedValue.getThroughNotCompilable().getThroughDuplicate();
}
GraphTargetItem tiName2 = other.name;
if (tiName2 != null) {
tiName2 = tiName2.getThroughDuplicate();
}
while (tiName2 instanceof LocalRegTreeItem) {
tiName2 = ((LocalRegTreeItem) tiName2).computedValue.getThroughNotCompilable();
tiName2 = ((LocalRegTreeItem) tiName2).computedValue.getThroughNotCompilable().getThroughDuplicate();
}
if (tiName != tiName2) {
return false;
}
GraphTargetItem tiNameSpace = namespace;
if (tiNameSpace != null) {
tiNameSpace = tiNameSpace.getThroughDuplicate();
}
while (tiNameSpace instanceof LocalRegTreeItem) {
tiNameSpace = ((LocalRegTreeItem) tiNameSpace).computedValue.getThroughNotCompilable();
tiNameSpace = ((LocalRegTreeItem) tiNameSpace).computedValue.getThroughNotCompilable().getThroughDuplicate();
}
GraphTargetItem tiNameSpace2 = other.namespace;
if (tiNameSpace2 != null) {
tiNameSpace2 = tiNameSpace2.getThroughDuplicate();
}
while (tiNameSpace2 instanceof LocalRegTreeItem) {
tiNameSpace2 = ((LocalRegTreeItem) tiNameSpace2).computedValue.getThroughNotCompilable();
tiNameSpace2 = ((LocalRegTreeItem) tiNameSpace2).computedValue.getThroughNotCompilable().getThroughDuplicate();
}
if (tiNameSpace != tiNameSpace2) {
return false;

View File

@@ -42,16 +42,16 @@ public class ActionSetProperty extends Action {
@Override
public void translate(Stack<GraphTargetItem> stack, List<GraphTargetItem> output, java.util.HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions) {
GraphTargetItem value = stack.pop();
GraphTargetItem index = stack.pop();
GraphTargetItem target = stack.pop();
GraphTargetItem value = stack.pop().getThroughDuplicate();
GraphTargetItem index = stack.pop().getThroughDuplicate();
GraphTargetItem target = stack.pop().getThroughDuplicate();
int indexInt = 0;
if (index instanceof DirectValueTreeItem) {
if (((DirectValueTreeItem) index).value instanceof Long) {
indexInt = (int) (long) (Long) ((DirectValueTreeItem) index).value;
}
}
if (value instanceof IncrementTreeItem) {
if (value.getThroughDuplicate() instanceof IncrementTreeItem) {
GraphTargetItem obj = ((IncrementTreeItem) value).object;
if (!stack.isEmpty()) {
if (stack.peek().equals(obj)) {

View File

@@ -44,7 +44,7 @@ public class ActionSetVariable extends Action {
@Override
public void translate(Stack<GraphTargetItem> stack, List<GraphTargetItem> output, java.util.HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions) {
GraphTargetItem value = stack.pop();
GraphTargetItem value = stack.pop().getThroughDuplicate();
GraphTargetItem name = stack.pop();
variables.put(Highlighting.stripHilights(name.toStringNoQuotes((ConstantPool) null)), value);
if (value instanceof IncrementTreeItem) {

View File

@@ -42,7 +42,7 @@ public class ActionSetMember extends Action {
@Override
public void translate(Stack<GraphTargetItem> stack, List<GraphTargetItem> output, java.util.HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions) {
GraphTargetItem value = stack.pop();
GraphTargetItem value = stack.pop().getThroughDuplicate();
GraphTargetItem memberName = stack.pop();
GraphTargetItem object = stack.pop();
if (value instanceof IncrementTreeItem) {

View File

@@ -0,0 +1,71 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.graph;
import java.util.List;
/**
*
* @author JPEXS
*/
public class DuplicateItem extends GraphTargetItem {
public DuplicateItem(GraphSourceItem src, GraphTargetItem value) {
super(src, value.precedence);
this.value = value;
}
@Override
public boolean toBoolean() {
return value.toBoolean();
}
@Override
public double toNumber() {
return value.toNumber();
}
@Override
public String toString(List localData) {
return value.toString(localData);
}
@Override
public GraphTargetItem getNotCoerced() {
return value.getNotCoerced();
}
@Override
public GraphTargetItem getThroughRegister() {
return value.getThroughRegister();
}
@Override
public GraphTargetItem getThroughDuplicate() {
return value.getThroughDuplicate();
}
@Override
public boolean isCompileTime() {
return value.isCompileTime();
}
@Override
public boolean isVariableComputed() {
return value.isVariableComputed();
}
}

View File

@@ -594,9 +594,10 @@ public class Graph {
if ((ti = checkLoop(next, stopPart, loops)) != null) {
ret.add(ti);
} else {
GraphTargetItem first = stack.pop();
printGraph(visited, localData, stack, allParts, parent, next, reversed ? sp1 : sp0, loops, forFinalCommands);
GraphTargetItem second = stack.pop();
GraphTargetItem first = stack.pop();
if (!reversed) {
AndItem a = new AndItem(null, first, second);
stack.push(a);
@@ -642,10 +643,10 @@ public class Graph {
if ((ti = checkLoop(next, stopPart, loops)) != null) {
ret.add(ti);
} else {
printGraph(visited, localData, stack, allParts, parent, next, reversed ? sp1 : sp0, loops, forFinalCommands);
GraphTargetItem second = stack.pop();
GraphTargetItem first = stack.pop();
printGraph(visited, localData, stack, allParts, parent, next, reversed ? sp1 : sp0, loops, forFinalCommands);
GraphTargetItem second = stack.pop();
if (reversed) {
AndItem a = new AndItem(null, first, second);

View File

@@ -158,4 +158,8 @@ public abstract class GraphTargetItem {
public GraphTargetItem getThroughNotCompilable() {
return this;
}
public GraphTargetItem getThroughDuplicate() {
return this;
}
}