Added AS3 support for logical AND/OR compound operator

This commit is contained in:
Jindra Petřík
2023-02-28 21:07:59 +01:00
parent e75991bee5
commit 9e6fa2e75b
32 changed files with 706 additions and 568 deletions

View File

@@ -127,8 +127,8 @@ public abstract class SetLocalTypeIns extends InstructionDefinition implements S
SetLocalAVM2Item result = new SetLocalAVM2Item(ins, localData.lineStartInstruction, regId, value, value.returnType());
if (value.getNotCoerced() instanceof CompoundableBinaryOp) {
CompoundableBinaryOp binaryOp = (CompoundableBinaryOp) value.getNotCoerced();
if (binaryOp.getLeftSide() instanceof LocalRegAVM2Item) {
LocalRegAVM2Item loc = (LocalRegAVM2Item) binaryOp.getLeftSide();
if (binaryOp.getLeftSide().getNotCoerced() instanceof LocalRegAVM2Item) {
LocalRegAVM2Item loc = (LocalRegAVM2Item) binaryOp.getLeftSide().getNotCoerced();
if (loc.regIndex == regId) {
result.setCompoundValue(binaryOp.getRightSide());
result.setCompoundOperator(binaryOp.getOperator());

View File

@@ -78,8 +78,8 @@ public class SetPropertyIns extends InstructionDefinition implements SetTypeIns
if (setLocName.regIndex == locName.regIndex) {
if (setLocVal.value instanceof CompoundableBinaryOp) {
CompoundableBinaryOp binaryOp = (CompoundableBinaryOp) setLocVal.value;
if (binaryOp.getLeftSide() instanceof GetPropertyAVM2Item) {
GetPropertyAVM2Item getProp = (GetPropertyAVM2Item) binaryOp.getLeftSide();
if (binaryOp.getLeftSide().getNotCoerced() instanceof GetPropertyAVM2Item) {
GetPropertyAVM2Item getProp = (GetPropertyAVM2Item) binaryOp.getLeftSide().getNotCoerced();
if (((FullMultinameAVM2Item) getProp.propertyName).compareSame(multiname) && Objects.equals(getProp.object, obj)) {
multiname.name = setLocName.value;
result.setCompoundValue(binaryOp.getRightSide());

View File

@@ -158,8 +158,8 @@ public class SetSlotIns extends InstructionDefinition implements SetTypeIns {
if (value.getNotCoerced() instanceof CompoundableBinaryOp) {
if (!obj.hasSideEffect()) {
CompoundableBinaryOp binaryOp = (CompoundableBinaryOp) value.getNotCoerced();
if (binaryOp.getLeftSide() instanceof GetSlotAVM2Item) {
GetSlotAVM2Item getSlot = (GetSlotAVM2Item) binaryOp.getLeftSide();
if (binaryOp.getLeftSide().getNotCoerced() instanceof GetSlotAVM2Item) {
GetSlotAVM2Item getSlot = (GetSlotAVM2Item) binaryOp.getLeftSide().getNotCoerced();
if (Objects.equals(obj, getSlot.scope.getThroughDuplicate()) && slotIndex == getSlot.slotIndex) {
result.compoundValue = binaryOp.getRightSide();
result.compoundOperator = binaryOp.getOperator();

View File

@@ -61,8 +61,8 @@ public class SetSuperIns extends InstructionDefinition implements SetTypeIns {
if (value.getNotCoercedNoDup() instanceof CompoundableBinaryOp) {
if (!obj.hasSideEffect() && !multiname.hasSideEffect()) {
CompoundableBinaryOp binaryOp = (CompoundableBinaryOp) value.getNotCoercedNoDup();
if (binaryOp.getLeftSide() instanceof GetSuperAVM2Item) {
GetSuperAVM2Item getSuper = (GetSuperAVM2Item) binaryOp.getLeftSide();
if (binaryOp.getLeftSide().getNotCoerced() instanceof GetSuperAVM2Item) {
GetSuperAVM2Item getSuper = (GetSuperAVM2Item) binaryOp.getLeftSide().getNotCoerced();
if (Objects.equals(obj, getSuper.object.getThroughDuplicate()) && Objects.equals(multiname, getSuper.propertyName)) {
result.setCompoundValue(binaryOp.getRightSide());
result.setCompoundOperator(binaryOp.getOperator());

View File

@@ -2133,11 +2133,10 @@ public class ActionScript3Parser {
case ASSIGN_SHIFT_RIGHT:
case ASSIGN_USHIFT_RIGHT:
case ASSIGN_XOR:
case ASSIGN_AND:
case ASSIGN_OR:
GraphTargetItem assigned = rhs;
switch (op.type) {
case ASSIGN:
//assigned = assigned;
break;
switch (op.type) {
case ASSIGN_BITAND:
assigned = new BitAndAVM2Item(null, null, lhs, assigned);
break;
@@ -2171,6 +2170,16 @@ public class ActionScript3Parser {
case ASSIGN_XOR:
assigned = new BitXorAVM2Item(null, null, lhs, assigned);
break;
case ASSIGN_AND:
assigned = new AndItem(null, null, lhs, assigned);
break;
case ASSIGN_OR:
assigned = new OrItem(null, null, lhs, assigned);
break;
case ASSIGN:
default:
//assigned = assigned;
break;
}
if (!(lhs instanceof AssignableAVM2Item)) {

View File

@@ -118,6 +118,8 @@ public enum SymbolType {
ASSIGN_SHIFT_LEFT(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_SHIFT_RIGHT(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_USHIFT_RIGHT(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_AND(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_OR(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
AS(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
DELETE(GraphTargetItem.PRECEDENCE_UNARY, false),
INSTANCEOF(GraphTargetItem.PRECEDENCE_RELATIONAL, true),

View File

@@ -0,0 +1,27 @@
/*
* Copyright (C) 2010-2022 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.model;
import com.jpexs.decompiler.graph.model.CompoundableBinaryOp;
/**
* CompoundableBinaryOp but for AS1/2, which does not have &&, || compound operator.
* @author JPEXS
*/
public interface CompoundableBinaryOpAs12 extends CompoundableBinaryOp {
}

View File

@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.model.CompoundableBinaryOpAs12;
import com.jpexs.decompiler.flash.action.swf4.ActionAdd;
import com.jpexs.decompiler.flash.action.swf5.ActionAdd2;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
@@ -38,7 +39,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class AddActionItem extends BinaryOpItem implements CompoundableBinaryOp {
public class AddActionItem extends BinaryOpItem implements CompoundableBinaryOpAs12 {
boolean version2;

View File

@@ -17,6 +17,7 @@
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.model.CompoundableBinaryOpAs12;
import com.jpexs.decompiler.flash.action.swf5.ActionBitAnd;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
@@ -33,7 +34,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class BitAndActionItem extends BinaryOpItem implements CompoundableBinaryOp {
public class BitAndActionItem extends BinaryOpItem implements CompoundableBinaryOpAs12 {
public BitAndActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, lineStartIns, PRECEDENCE_BITWISEAND, leftSide, rightSide, "&", "int", "int");

View File

@@ -17,6 +17,7 @@
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.model.CompoundableBinaryOpAs12;
import com.jpexs.decompiler.flash.action.swf5.ActionBitOr;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
@@ -33,7 +34,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class BitOrActionItem extends BinaryOpItem implements CompoundableBinaryOp {
public class BitOrActionItem extends BinaryOpItem implements CompoundableBinaryOpAs12 {
public BitOrActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, lineStartIns, PRECEDENCE_BITWISEOR, leftSide, rightSide, "|", "int", "int");

View File

@@ -17,6 +17,7 @@
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.model.CompoundableBinaryOpAs12;
import com.jpexs.decompiler.flash.action.model.DirectValueActionItem;
import com.jpexs.decompiler.flash.action.swf5.ActionBitXor;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
@@ -36,7 +37,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class BitXorActionItem extends BinaryOpItem implements CompoundableBinaryOp {
public class BitXorActionItem extends BinaryOpItem implements CompoundableBinaryOpAs12 {
public BitXorActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, lineStartIns, PRECEDENCE_BITWISEXOR, leftSide, rightSide, "^", "int", "int");

View File

@@ -17,6 +17,7 @@
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.model.CompoundableBinaryOpAs12;
import com.jpexs.decompiler.flash.action.swf4.ActionDivide;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
@@ -32,7 +33,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class DivideActionItem extends BinaryOpItem implements CompoundableBinaryOp {
public class DivideActionItem extends BinaryOpItem implements CompoundableBinaryOpAs12 {
public DivideActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, lineStartIns, PRECEDENCE_MULTIPLICATIVE, leftSide, rightSide, "/", "Number", "Number");

View File

@@ -17,6 +17,7 @@
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.model.CompoundableBinaryOpAs12;
import com.jpexs.decompiler.flash.action.swf5.ActionBitLShift;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
@@ -33,7 +34,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class LShiftActionItem extends BinaryOpItem implements CompoundableBinaryOp {
public class LShiftActionItem extends BinaryOpItem implements CompoundableBinaryOpAs12 {
public LShiftActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, lineStartIns, PRECEDENCE_BITWISESHIFT, leftSide, rightSide, "<<", "int", "int");

View File

@@ -17,6 +17,7 @@
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.model.CompoundableBinaryOpAs12;
import com.jpexs.decompiler.flash.action.swf5.ActionModulo;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
@@ -32,7 +33,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class ModuloActionItem extends BinaryOpItem implements CompoundableBinaryOp {
public class ModuloActionItem extends BinaryOpItem implements CompoundableBinaryOpAs12 {
public ModuloActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, lineStartIns, PRECEDENCE_MULTIPLICATIVE, leftSide, rightSide, "%", "Number", "Number");

View File

@@ -17,6 +17,7 @@
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.model.CompoundableBinaryOpAs12;
import com.jpexs.decompiler.flash.action.swf4.ActionMultiply;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
@@ -32,7 +33,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class MultiplyActionItem extends BinaryOpItem implements CompoundableBinaryOp {
public class MultiplyActionItem extends BinaryOpItem implements CompoundableBinaryOpAs12 {
public MultiplyActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, lineStartIns, PRECEDENCE_MULTIPLICATIVE, leftSide, rightSide, "*", "Number", "Number");

View File

@@ -17,6 +17,7 @@
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.model.CompoundableBinaryOpAs12;
import com.jpexs.decompiler.flash.action.swf5.ActionBitRShift;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
@@ -33,7 +34,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class RShiftActionItem extends BinaryOpItem implements CompoundableBinaryOp {
public class RShiftActionItem extends BinaryOpItem implements CompoundableBinaryOpAs12 {
public RShiftActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, lineStartIns, PRECEDENCE_BITWISESHIFT, leftSide, rightSide, ">>", "int", "int");

View File

@@ -17,6 +17,7 @@
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.model.CompoundableBinaryOpAs12;
import com.jpexs.decompiler.flash.action.model.DirectValueActionItem;
import com.jpexs.decompiler.flash.action.swf4.ActionSubtract;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
@@ -35,7 +36,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class SubtractActionItem extends BinaryOpItem implements CompoundableBinaryOp {
public class SubtractActionItem extends BinaryOpItem implements CompoundableBinaryOpAs12 {
public SubtractActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, lineStartIns, PRECEDENCE_ADDITIVE, leftSide, rightSide, "-", "Number", "Number");

View File

@@ -17,6 +17,7 @@
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.model.CompoundableBinaryOpAs12;
import com.jpexs.decompiler.flash.action.swf5.ActionBitURShift;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
@@ -32,7 +33,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class URShiftActionItem extends BinaryOpItem implements CompoundableBinaryOp {
public class URShiftActionItem extends BinaryOpItem implements CompoundableBinaryOpAs12 {
public URShiftActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, lineStartIns, PRECEDENCE_BITWISESHIFT, leftSide, rightSide, ">>>", "Number", "Number");

View File

@@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.BaseLocalData;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.LocalDataArea;
import com.jpexs.decompiler.flash.action.StoreTypeAction;
import com.jpexs.decompiler.flash.action.model.CompoundableBinaryOpAs12;
import com.jpexs.decompiler.flash.action.model.ConstantPool;
import com.jpexs.decompiler.flash.action.model.DecrementActionItem;
import com.jpexs.decompiler.flash.action.model.DirectValueActionItem;
@@ -136,7 +137,7 @@ public class ActionSetVariable extends Action implements StoreTypeAction {
if (inside instanceof StoreRegisterActionItem) {
inside = inside.value;
}
if (inside instanceof CompoundableBinaryOp) {
if (inside instanceof CompoundableBinaryOpAs12) {
if (!name.hasSideEffect()) {
CompoundableBinaryOp binaryOp = (CompoundableBinaryOp) inside;
if (binaryOp.getLeftSide() instanceof GetVariableActionItem) {

View File

@@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.BaseLocalData;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.ActionScriptObject;
import com.jpexs.decompiler.flash.action.LocalDataArea;
import com.jpexs.decompiler.flash.action.model.CompoundableBinaryOpAs12;
import com.jpexs.decompiler.flash.action.model.DecrementActionItem;
import com.jpexs.decompiler.flash.action.model.GetMemberActionItem;
import com.jpexs.decompiler.flash.action.model.IncrementActionItem;
@@ -122,7 +123,7 @@ public class ActionSetMember extends Action {
if (inside instanceof StoreRegisterActionItem) {
inside = inside.value;
}
if (inside instanceof CompoundableBinaryOp) {
if (inside instanceof CompoundableBinaryOpAs12) {
if (!object.hasSideEffect() && !memberName.hasSideEffect()) {
CompoundableBinaryOp binaryOp = (CompoundableBinaryOp) inside;
if (binaryOp.getLeftSide() instanceof GetMemberActionItem) {

View File

@@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.LocalDataArea;
import com.jpexs.decompiler.flash.action.StoreTypeAction;
import com.jpexs.decompiler.flash.action.model.CompoundableBinaryOpAs12;
import com.jpexs.decompiler.flash.action.model.ConstantPool;
import com.jpexs.decompiler.flash.action.model.DecrementActionItem;
import com.jpexs.decompiler.flash.action.model.DirectValueActionItem;
@@ -166,7 +167,7 @@ public class ActionStoreRegister extends Action implements StoreTypeAction {
variables.remove("__register" + registerNumber);
}
StoreRegisterActionItem ret = new StoreRegisterActionItem(this, lineStartAction, rn, value, define);
if (value.getNotCoercedNoDup() instanceof CompoundableBinaryOp) {
if (value.getNotCoercedNoDup() instanceof CompoundableBinaryOpAs12) {
CompoundableBinaryOp binaryOp = (CompoundableBinaryOp) value.getNotCoercedNoDup();
if (binaryOp.getLeftSide() instanceof DirectValueActionItem) {
DirectValueActionItem directValue = (DirectValueActionItem) binaryOp.getLeftSide();

View File

@@ -86,10 +86,10 @@ public class FFDecAs3ScriptReplacer implements As3ScriptReplacerInterface {
abc.pack();//remove old deleted items
((Tag) abc.parentTag).setModified(true);
} catch (AVM2ParseException ex) {
ex.printStackTrace();
//ex.printStackTrace();
throw new As3ScriptReplaceException(new As3ScriptReplaceExceptionItem(null, ex.text, (int) ex.line));
} catch (CompilationException ex) {
ex.printStackTrace();
//ex.printStackTrace();
throw new As3ScriptReplaceException(new As3ScriptReplaceExceptionItem(null, ex.text, (int) ex.line));
}
}

View File

@@ -30,7 +30,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class AndItem extends BinaryOpItem {
public class AndItem extends BinaryOpItem implements CompoundableBinaryOp {
@Override
public List<GraphSourceItemPos> getNeededSources() {

View File

@@ -30,7 +30,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class OrItem extends BinaryOpItem {
public class OrItem extends BinaryOpItem implements CompoundableBinaryOp {
public OrItem(GraphSourceItem src, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(src, lineStartIns, PRECEDENCE_LOGICALOR, leftSide, rightSide, "||", "Boolean", "Boolean");