AS1/2/3 direct editation - +- 1 as decrement/increment

This commit is contained in:
Jindra Petk
2014-04-21 09:44:17 +02:00
parent 8390d0b2de
commit caf965b9ec
2 changed files with 22 additions and 0 deletions

View File

@@ -19,6 +19,8 @@ package com.jpexs.decompiler.flash.abc.avm2.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.arithmetic.AddIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.arithmetic.IncrementIns;
import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.ecma.EcmaType;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
@@ -69,6 +71,14 @@ public class AddAVM2Item extends BinaryOpItem {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
if (rightSide instanceof IntegerValueAVM2Item) {
IntegerValueAVM2Item iv = (IntegerValueAVM2Item) rightSide;
if (iv.value == 1) {
return toSourceMerge(localData, generator, leftSide,
new AVM2Instruction(0, new IncrementIns(), new int[]{}, new byte[0])
);
}
}
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new AddIns(), new int[]{}, new byte[0])
);

View File

@@ -18,12 +18,16 @@ package com.jpexs.decompiler.flash.abc.avm2.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.arithmetic.DecrementIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.arithmetic.IncrementIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.arithmetic.SubtractIns;
import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import static com.jpexs.decompiler.graph.GraphTargetItem.toSourceMerge;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.model.BinaryOpItem;
import com.jpexs.decompiler.graph.model.LocalData;
@@ -65,6 +69,14 @@ public class SubtractAVM2Item extends BinaryOpItem {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
if (rightSide instanceof IntegerValueAVM2Item) {
IntegerValueAVM2Item iv = (IntegerValueAVM2Item) rightSide;
if (iv.value == 1) {
return toSourceMerge(localData, generator, leftSide,
new AVM2Instruction(0, new DecrementIns(), new int[]{}, new byte[0])
);
}
}
return toSourceMerge(localData, generator, leftSide, rightSide,
new AVM2Instruction(0, new SubtractIns(), new int[]{}, new byte[0])
);