AS3 - improved switch handling

This commit is contained in:
Jindra Petřík
2015-07-04 15:21:47 +02:00
parent d8c25ce3e8
commit 3a22038f03
11 changed files with 192 additions and 22 deletions

View File

@@ -444,7 +444,7 @@ public class AVM2Graph extends Graph {
ret.addAll(output);
return ret;
}
if (((part.nextParts.size() == 2)
if (false && (((part.nextParts.size() == 2)
&& (!stack.isEmpty())
&& (stack.peek() instanceof StrictEqAVM2Item)
&& (part.nextParts.get(0).getHeight() >= 2)
@@ -457,7 +457,7 @@ public class AVM2Graph extends Graph {
&& (part.nextParts.get(1).getHeight() >= 2)
&& (this.avm2code.code.get(this.avm2code.fixIPAfterDebugLine(part.nextParts.get(1).start)).definition instanceof PushIntegerTypeIns)
&& (!part.nextParts.get(1).nextParts.isEmpty())
&& (this.avm2code.code.get(part.nextParts.get(1).nextParts.get(0).end).definition instanceof LookupSwitchIns))) {
&& (this.avm2code.code.get(part.nextParts.get(1).nextParts.get(0).end).definition instanceof LookupSwitchIns)))) {
if (stack.peek() instanceof StrictEqAVM2Item) {
ignoredSwitches2.add(part.nextParts.get(0).nextParts.get(0).end);
@@ -815,6 +815,16 @@ public class AVM2Graph extends Graph {
}
}
if (avm2code.isKilled(ri.regIndex, 0, Integer.MAX_VALUE)) {
if (i + 1 < list.size()) {
if (list.get(i + 1) instanceof SwitchItem) {
SwitchItem si = (SwitchItem) list.get(i + 1);
if (si.switchedObject instanceof LocalRegAVM2Item) {
if (((LocalRegAVM2Item) si.switchedObject).regIndex == ri.regIndex) {
si.switchedObject = ri.value;
}
}
}
}
if (i + 2 < list.size()) {
if ((list.get(i + 1) instanceof IntegerValueAVM2Item) && (list.get(i + 2) instanceof ReturnValueAVM2Item)) {
ReturnValueAVM2Item r = (ReturnValueAVM2Item) list.get(i + 2);

View File

@@ -29,11 +29,12 @@ import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SimpleValue;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.IntegerValueTypeItem;
import com.jpexs.decompiler.graph.model.LocalData;
import java.util.List;
import java.util.Set;
public class IntegerValueAVM2Item extends NumberValueAVM2Item {
public class IntegerValueAVM2Item extends NumberValueAVM2Item implements IntegerValueTypeItem {
public Long value;
@@ -81,4 +82,9 @@ public class IntegerValueAVM2Item extends NumberValueAVM2Item {
return true;
}
@Override
public int intValue() {
return (int) (long) value;
}
}

View File

@@ -125,4 +125,27 @@ public class LocalRegAVM2Item extends AVM2Item {
public boolean hasReturnValue() {
return true;
}
@Override
public int hashCode() {
int hash = 3;
hash = 67 * hash + this.regIndex;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final LocalRegAVM2Item other = (LocalRegAVM2Item) obj;
if (this.regIndex != other.regIndex) {
return false;
}
return true;
}
}

View File

@@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.jumps.IfEqIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.jumps.IfNeIns;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.EqualsTypeItem;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
@@ -32,7 +33,7 @@ import com.jpexs.decompiler.graph.model.BinaryOpItem;
import com.jpexs.decompiler.graph.model.LogicalOpItem;
import java.util.List;
public class EqAVM2Item extends BinaryOpItem implements LogicalOpItem, IfCondition {
public class EqAVM2Item extends BinaryOpItem implements LogicalOpItem, IfCondition, EqualsTypeItem {
public EqAVM2Item(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, PRECEDENCE_EQUALITY, leftSide, rightSide, "==");

View File

@@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.jumps.IfStrictEqIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.jumps.IfStrictNeIns;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.EqualsTypeItem;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
@@ -32,7 +33,7 @@ import com.jpexs.decompiler.graph.model.BinaryOpItem;
import com.jpexs.decompiler.graph.model.LogicalOpItem;
import java.util.List;
public class StrictEqAVM2Item extends BinaryOpItem implements LogicalOpItem, IfCondition {
public class StrictEqAVM2Item extends BinaryOpItem implements LogicalOpItem, IfCondition, EqualsTypeItem {
public StrictEqAVM2Item(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, PRECEDENCE_EQUALITY, leftSide, rightSide, "===");

View File

@@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.swf5.ActionEquals2;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.EqualsTypeItem;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
@@ -29,7 +30,7 @@ import com.jpexs.decompiler.graph.model.BinaryOpItem;
import com.jpexs.decompiler.graph.model.LogicalOpItem;
import java.util.List;
public class EqActionItem extends BinaryOpItem implements LogicalOpItem {
public class EqActionItem extends BinaryOpItem implements LogicalOpItem, EqualsTypeItem {
boolean version2;

View File

@@ -12,13 +12,15 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.swf6.ActionStrictEquals;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.EqualsTypeItem;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
@@ -27,7 +29,7 @@ import com.jpexs.decompiler.graph.model.BinaryOpItem;
import com.jpexs.decompiler.graph.model.LogicalOpItem;
import java.util.List;
public class StrictEqActionItem extends BinaryOpItem implements LogicalOpItem, Inverted, EqualsTypeItem {
public StrictEqActionItem(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, PRECEDENCE_EQUALITY, leftSide, rightSide, "===");