Simple values are not duplicated with DuplicateItem/SetTemporary.

This commit is contained in:
Jindra Petřík
2025-09-01 09:37:44 +02:00
parent f53ecd8778
commit d51e75d0e7
4 changed files with 91 additions and 19 deletions

View File

@@ -79,9 +79,37 @@ public interface SetTypeIns {
}
//TestChainedAssignments1 both AIR and nonair
if (notCoercedValue instanceof DuplicateItem) {
stack.moveToStack(output);
if (!stack.isEmpty()) {
if (GraphTargetItem.checkDup2(notCoercedValue, stack.peek(), output, stack) >= -1) {
GraphTargetItem newValue = notCoercedValue.getThroughDuplicate();
if ((value instanceof CoerceAVM2Item) || (value instanceof ConvertAVM2Item)) {
result.value.value = newValue;
} else {
result.value = newValue;
}
//Assembled - TestForEach
if (AVM2Item.mustStayIntact2(newValue) && result instanceof SetLocalAVM2Item) {
SetLocalAVM2Item setLocal = (SetLocalAVM2Item) result;
stack.pop();
stack.moveToStack(output);
stack.addToOutput(result);
stack.push(new LocalRegAVM2Item(null, null, setLocal.regIndex, setLocal.value, setLocal.type));
return;
}
stack.pop();
stack.moveToStack(output);
stack.push(result);
return;
}
}
stack.finishBlock(output);
/*if (notCoercedValue instanceof DuplicateItem) {
DuplicateItem d = (DuplicateItem) notCoercedValue;
stack.moveToStack(output);
if (!stack.isEmpty() && stack.peek() instanceof DuplicateSourceItem) {
DuplicateSourceItem ds = (DuplicateSourceItem) stack.peek();
if (ds.tempIndex == d.tempIndex) {
@@ -116,8 +144,10 @@ public interface SetTypeIns {
return;
}
}
stack.finishBlock(output);
}
}*/
stack.addToOutput(result);
if (true) { //FIXME??

View File

@@ -24,9 +24,9 @@ import com.jpexs.decompiler.flash.abc.avm2.graph.AVM2GraphTargetDialect;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.avm2.model.NewActivationAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.SetTypeAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.clauses.ExceptionAVM2Item;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SimpleValue;
import com.jpexs.decompiler.graph.TranslateStack;
import com.jpexs.decompiler.graph.model.DuplicateItem;
import com.jpexs.decompiler.graph.model.DuplicateSourceItem;
@@ -60,7 +60,16 @@ public class DupIns extends InstructionDefinition {
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
GraphTargetItem v = stack.pop();
int temp = 0;
if (v instanceof SimpleValue) {
SimpleValue sv = (SimpleValue) v;
if (sv.isSimpleValue()) {
stack.push(v);
stack.push(v);
return;
}
}
if (v instanceof NewActivationAVM2Item
|| v instanceof ExceptionAVM2Item) {
stack.push(v);

View File

@@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.helpers.hilight.HighlightData;
import com.jpexs.decompiler.graph.model.BinaryOp;
import com.jpexs.decompiler.graph.model.DuplicateItem;
import com.jpexs.decompiler.graph.model.DuplicateSourceItem;
import com.jpexs.decompiler.graph.model.HasTempIndex;
import com.jpexs.decompiler.graph.model.LocalData;
import com.jpexs.decompiler.graph.model.NotItem;
import com.jpexs.decompiler.graph.model.SetTemporaryItem;
@@ -1178,4 +1179,36 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
output.remove(output.size() - 1);
stack.moveToStack(output);
}
/**
* Checks whether items are result of dup instruction and removes SetTemportary from output when neccessary
* @param item1
* @param item2
* @param output
* @param stack
* @return -2 when no duplicate, -1 when equal, >= 0 temp index
*/
public static int checkDup2(GraphTargetItem item1, GraphTargetItem item2, List<GraphTargetItem> output, TranslateStack stack) {
if (item1 == item2) {
return -1;
}
if (!((item1 instanceof DuplicateSourceItem && item2 instanceof DuplicateItem)
|| (item1 instanceof DuplicateItem && item2 instanceof DuplicateSourceItem))
) {
return -2;
}
if (((HasTempIndex) item1).getTempIndex() != ((HasTempIndex) item2).getTempIndex()) {
return -2;
}
if (!output.isEmpty() && output.get(output.size() - 1) instanceof SetTemporaryItem) {
SetTemporaryItem st = (SetTemporaryItem) output.get(output.size() - 1);
if (st.getTempIndex() == ((HasTempIndex) item1).getTempIndex()) {
output.remove(output.size() - 1);
stack.moveToStack(output);
}
}
return ((HasTempIndex) item1).getTempIndex();
}
}