mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-26 12:20:51 +00:00
Fix TestIncDec1 and 2
This commit is contained in:
+2
@@ -891,11 +891,13 @@ public abstract class InstructionDefinition implements Serializable {
|
||||
if (hasConvert && standalone) {
|
||||
return new PostIncrementAVM2Item(ins, localData.lineStartInstruction, getProperty);
|
||||
}
|
||||
//TestIncDec3 with result
|
||||
return new PreIncrementAVM2Item(ins, localData.lineStartInstruction, getProperty);
|
||||
} else {
|
||||
if (hasConvert && standalone) {
|
||||
return new PostDecrementAVM2Item(ins, localData.lineStartInstruction, getProperty);
|
||||
}
|
||||
//TestIncDec3 with result
|
||||
return new PreDecrementAVM2Item(ins, localData.lineStartInstruction, getProperty);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -65,6 +65,7 @@ public interface SetTypeIns {
|
||||
* @param type Type
|
||||
*/
|
||||
public static void handleResult(GraphTargetItem value, TranslateStack stack, List<GraphTargetItem> output, AVM2LocalData localData, GraphTargetItem result, int regId, GraphTargetItem type) {
|
||||
//stack.addToOutput(result);
|
||||
GraphTargetItem notCoercedValue = value;
|
||||
if ((value instanceof CoerceAVM2Item) || (value instanceof ConvertAVM2Item)) {
|
||||
notCoercedValue = value.value;
|
||||
@@ -121,6 +122,6 @@ public interface SetTypeIns {
|
||||
}
|
||||
}
|
||||
}
|
||||
stack.addToOutput(result);
|
||||
stack.addToOutput(result);
|
||||
}
|
||||
}
|
||||
|
||||
+21
-8
@@ -38,7 +38,9 @@ import com.jpexs.decompiler.graph.TranslateStack;
|
||||
import com.jpexs.decompiler.graph.model.CommaExpressionItem;
|
||||
import com.jpexs.decompiler.graph.model.CompoundableBinaryOp;
|
||||
import com.jpexs.decompiler.graph.model.DuplicateItem;
|
||||
import com.jpexs.decompiler.graph.model.DuplicateSourceItem;
|
||||
import com.jpexs.decompiler.graph.model.PopItem;
|
||||
import com.jpexs.decompiler.graph.model.SetTemporaryItem;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -99,18 +101,24 @@ public abstract class SetLocalTypeIns extends InstructionDefinition implements S
|
||||
GraphTargetItem inside = ((IncrementAVM2Item) value.getNotCoerced()).value.getNotCoerced().getThroughDuplicate();
|
||||
if (inside instanceof LocalRegAVM2Item) {
|
||||
if (((LocalRegAVM2Item) inside).regIndex == regId) {
|
||||
if (stack.size() > 0) {
|
||||
if (!stack.isEmpty()) {
|
||||
GraphTargetItem top = stack.peek().getNotCoerced().getThroughDuplicate();
|
||||
if (top == inside) {
|
||||
stack.pop();
|
||||
if (top == inside) {
|
||||
GraphTargetItem.checkDup(stack, output, stack.pop(), value.getNotCoerced().value);
|
||||
//stack.pop();
|
||||
//TestIncDec2 with result
|
||||
stack.push(new PostIncrementAVM2Item(ins, localData.lineStartInstruction, inside));
|
||||
} else if ((top instanceof IncrementAVM2Item) && (((IncrementAVM2Item) top).value == inside)) {
|
||||
stack.pop();
|
||||
|
||||
} else if ((top instanceof IncrementAVM2Item) && (((IncrementAVM2Item) top).value == inside)) {
|
||||
GraphTargetItem.checkDup(stack, output, stack.pop(), value);
|
||||
//stack.pop();
|
||||
//TestIncDec1 with result
|
||||
stack.push(new PreIncrementAVM2Item(ins, localData.lineStartInstruction, inside));
|
||||
} else {
|
||||
stack.addToOutput(new PostIncrementAVM2Item(ins, localData.lineStartInstruction, inside));
|
||||
}
|
||||
} else {
|
||||
//TestIncDec1 no result
|
||||
stack.addToOutput(new PostIncrementAVM2Item(ins, localData.lineStartInstruction, inside));
|
||||
}
|
||||
return;
|
||||
@@ -122,18 +130,23 @@ public abstract class SetLocalTypeIns extends InstructionDefinition implements S
|
||||
GraphTargetItem inside = ((DecrementAVM2Item) value.getNotCoerced()).value.getNotCoerced().getThroughDuplicate();
|
||||
if (inside instanceof LocalRegAVM2Item) {
|
||||
if (((LocalRegAVM2Item) inside).regIndex == regId) {
|
||||
if (stack.size() > 0) {
|
||||
if (!stack.isEmpty()) {
|
||||
GraphTargetItem top = stack.peek().getNotCoerced().getThroughDuplicate();
|
||||
if (top == inside) {
|
||||
stack.pop();
|
||||
GraphTargetItem.checkDup(stack, output, stack.pop(), value.getNotCoerced().value);
|
||||
//stack.pop();
|
||||
//TestIncDec2 with result
|
||||
stack.push(new PostDecrementAVM2Item(ins, localData.lineStartInstruction, inside));
|
||||
} else if ((top instanceof DecrementAVM2Item) && (((DecrementAVM2Item) top).value == inside)) {
|
||||
stack.pop();
|
||||
GraphTargetItem.checkDup(stack, output, stack.pop(), value);
|
||||
//stack.pop();
|
||||
//TestIncDec1 with result
|
||||
stack.push(new PreDecrementAVM2Item(ins, localData.lineStartInstruction, inside));
|
||||
} else {
|
||||
stack.addToOutput(new PostDecrementAVM2Item(ins, localData.lineStartInstruction, inside));
|
||||
}
|
||||
} else {
|
||||
//TestIncDec1 no result
|
||||
stack.addToOutput(new PostDecrementAVM2Item(ins, localData.lineStartInstruction, inside));
|
||||
}
|
||||
return;
|
||||
|
||||
+1
-3
@@ -70,12 +70,10 @@ public class DupIns extends InstructionDefinition {
|
||||
} else {
|
||||
temp = localData.maxTempIndex.getVal() + 1;
|
||||
localData.maxTempIndex.setVal(temp);
|
||||
/*
|
||||
//TODO: somehow implement this. Currently it fails many tests:-(
|
||||
stack.finishBlock(output);
|
||||
stack.addToOutput(new SetTemporaryItem(AVM2GraphTargetDialect.INSTANCE, ins, localData.lineStartInstruction, v, temp, "dup"));
|
||||
stack.finishBlock(output);
|
||||
*/
|
||||
|
||||
stack.push(new DuplicateSourceItem(AVM2GraphTargetDialect.INSTANCE, ins, localData.lineStartInstruction, v, temp));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1046,10 +1046,10 @@ public class Graph {
|
||||
SetTemporaryItem s = (SetTemporaryItem) item;
|
||||
s.declaration = true;
|
||||
}
|
||||
if (item instanceof DuplicateSourceItem) {
|
||||
/*if (item instanceof DuplicateSourceItem) {
|
||||
DuplicateSourceItem s = (DuplicateSourceItem) item;
|
||||
s.declaration = true;
|
||||
}
|
||||
}*/
|
||||
|
||||
Reference<Integer> iRef = new Reference<>(i);
|
||||
item.visitRecursivelyNoBlock(new AbstractGraphTargetRecursiveVisitor() {
|
||||
@@ -1062,13 +1062,13 @@ public class Graph {
|
||||
items.add(iRef.getVal(), dec);
|
||||
iRef.setVal(iRef.getVal() + 1);
|
||||
}
|
||||
if (item instanceof DuplicateSourceItem) {
|
||||
/*if (item instanceof DuplicateSourceItem) {
|
||||
DuplicateSourceItem st = (DuplicateSourceItem) item;
|
||||
SetTemporaryItem dec = new SetTemporaryItem(dialect, null, null, null, st.tempIndex, "");
|
||||
dec.declaration = true;
|
||||
items.add(iRef.getVal(), dec);
|
||||
iRef.setVal(iRef.getVal() + 1);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
});
|
||||
i = iRef.getVal();
|
||||
|
||||
@@ -24,8 +24,11 @@ import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
|
||||
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.LocalData;
|
||||
import com.jpexs.decompiler.graph.model.NotItem;
|
||||
import com.jpexs.decompiler.graph.model.SetTemporaryItem;
|
||||
import com.jpexs.helpers.CancellableWorker;
|
||||
import com.jpexs.helpers.LinkedIdentityHashSet;
|
||||
import com.jpexs.helpers.Reference;
|
||||
@@ -1140,5 +1143,39 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
|
||||
}
|
||||
}
|
||||
return o1.equals(o2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks set temporary at the end of output and expected dupSource, dup.
|
||||
* Then removes the last output command when neccessary.
|
||||
* @param stack Stack
|
||||
* @param output Output
|
||||
* @param dupSource Expected DuplicateSourceItem, if not, the command won't do anything
|
||||
* @param dup Expected DuplicateItem, if not the command won't do anything
|
||||
*/
|
||||
public static void checkDup(TranslateStack stack, List<GraphTargetItem> output, GraphTargetItem dupSource, GraphTargetItem dup) {
|
||||
if (output.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (!(output.get(output.size() - 1) instanceof SetTemporaryItem)) {
|
||||
return;
|
||||
}
|
||||
dupSource = dupSource.getNotCoercedNoDup();
|
||||
if (!(dupSource instanceof DuplicateSourceItem)) {
|
||||
return;
|
||||
}
|
||||
dup = dup.getNotCoercedNoDup();
|
||||
if (!(dup instanceof DuplicateItem)) {
|
||||
return;
|
||||
}
|
||||
DuplicateSourceItem ds = (DuplicateSourceItem) dupSource;
|
||||
DuplicateItem d = (DuplicateItem) dup;
|
||||
SetTemporaryItem st = (SetTemporaryItem) output.get(output.size() - 1);
|
||||
if (ds.tempIndex != d.tempIndex || d.tempIndex != st.tempIndex) {
|
||||
return;
|
||||
}
|
||||
|
||||
output.remove(output.size() - 1);
|
||||
stack.moveToStack(output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public class TranslateStack extends Stack<GraphTargetItem> {
|
||||
@Override
|
||||
public GraphTargetItem push(GraphTargetItem item) {
|
||||
if (!outputQueue.isEmpty()) {
|
||||
if (item instanceof FindPropertyAVM2Item) {
|
||||
if ((item instanceof FindPropertyAVM2Item) || isDupsOnly()) {
|
||||
finishBlock(connectedOutput);
|
||||
} else {
|
||||
outputQueue.add(item);
|
||||
@@ -106,6 +106,19 @@ public class TranslateStack extends Stack<GraphTargetItem> {
|
||||
return super.push(item);
|
||||
}
|
||||
|
||||
private boolean isDupsOnly() {
|
||||
for (GraphTargetItem item : this) {
|
||||
if (item instanceof DuplicateItem) {
|
||||
continue;
|
||||
}
|
||||
if (item instanceof DuplicateSourceItem) {
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets mark.
|
||||
* @param name Name
|
||||
@@ -247,11 +260,11 @@ public class TranslateStack extends Stack<GraphTargetItem> {
|
||||
SetTemporaryItem st = (SetTemporaryItem) pi.value;
|
||||
connectedOutput.set(i, st);
|
||||
return new TemporaryItem(pi.dialect, pi.value.getSrc(), pi.value.getLineStartItem(), pi.value, st.tempIndex);
|
||||
} else if (pi.value instanceof DuplicateSourceItem) {
|
||||
DuplicateSourceItem ds = (DuplicateSourceItem) pi.value;
|
||||
connectedOutput.set(i, new SetTemporaryItem(pi.dialect, ds.getSrc(), ds.getLineStartItem(), ds.value, ds.tempIndex,"push"));
|
||||
} /*else if (pi.value instanceof DuplicateSourceItem) {
|
||||
//DuplicateSourceItem ds = (DuplicateSourceItem) pi.value;
|
||||
//connectedOutput.set(i, new SetTemporaryItem(pi.dialect, ds.getSrc(), ds.getLineStartItem(), ds.value, ds.tempIndex,"push"));
|
||||
return new TemporaryItem(pi.dialect, pi.value.getSrc(), pi.value.getLineStartItem(), ds.value, ds.tempIndex);
|
||||
} /*else if (pi.value instanceof DuplicateItem) {
|
||||
} else if (pi.value instanceof DuplicateItem) {
|
||||
DuplicateItem d = (DuplicateItem) pi.value;
|
||||
//connectedOutput.remove(i);
|
||||
connectedOutput.set(i, new SetTemporaryItem(pi.dialect, d.getSrc(), d.getLineStartItem(), d.value, d.tempIndex));
|
||||
@@ -486,5 +499,5 @@ public class TranslateStack extends Stack<GraphTargetItem> {
|
||||
push(pi2.value);
|
||||
push(ti.value);
|
||||
//moveToStack(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,8 +79,9 @@ public class DuplicateSourceItem extends GraphTargetItem implements SimpleValue,
|
||||
if (declaration) {
|
||||
return dialect.writeTemporaryDeclaration(writer, localData, "", tempIndex, val);
|
||||
}
|
||||
writer.append("_temp_").append(tempIndex).append(" = ");
|
||||
val.appendTry(writer, localData);
|
||||
writer.append("_temp_").append(tempIndex);
|
||||
//.append(" = ");
|
||||
//val.appendTry(writer, localData);
|
||||
return writer;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user