mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-11 02:03:17 +00:00
Fixed AS1/2 Set property increment/decrement
This commit is contained in:
@@ -29,6 +29,7 @@ import com.jpexs.decompiler.graph.GraphTargetVisitorInterface;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import com.jpexs.decompiler.graph.model.LocalData;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -40,6 +41,8 @@ public class GetPropertyActionItem extends ActionItem {
|
||||
|
||||
public int propertyIndex;
|
||||
|
||||
public boolean useGetPropertyFunction = true;
|
||||
|
||||
@Override
|
||||
public void visit(GraphTargetVisitorInterface visitor) {
|
||||
visitor.visit(target);
|
||||
@@ -57,6 +60,13 @@ public class GetPropertyActionItem extends ActionItem {
|
||||
return writer.append(Action.propertyNames[propertyIndex]);
|
||||
}
|
||||
|
||||
if (!useGetPropertyFunction) {
|
||||
target.appendToNoQuotes(writer, localData);
|
||||
writer.append(":");
|
||||
writer.append(Action.propertyNames[propertyIndex]);
|
||||
return writer;
|
||||
}
|
||||
|
||||
writer.append("getProperty");
|
||||
writer.spaceBeforeCallParenthesies(2);
|
||||
writer.append("(");
|
||||
@@ -67,6 +77,35 @@ public class GetPropertyActionItem extends ActionItem {
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 79 * hash + Objects.hashCode(this.target);
|
||||
hash = 79 * hash + this.propertyIndex;
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final GetPropertyActionItem other = (GetPropertyActionItem) obj;
|
||||
if (this.propertyIndex != other.propertyIndex) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.target, other.target)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GraphSourceItemPos> getNeededSources() {
|
||||
List<GraphSourceItemPos> ret = super.getNeededSources();
|
||||
|
||||
@@ -85,7 +85,59 @@ public class ActionSetProperty extends Action {
|
||||
indexInt = (int) Math.round((Float) ((DirectValueActionItem) index).value);
|
||||
}
|
||||
}
|
||||
if (value.getThroughDuplicate() instanceof IncrementActionItem) {
|
||||
GraphTargetItem obj = ((IncrementActionItem) value).object;
|
||||
if (!stack.isEmpty() && stack.peek().valueEquals(obj)) {
|
||||
stack.pop();
|
||||
|
||||
if (obj instanceof GetPropertyActionItem) {
|
||||
((GetPropertyActionItem) obj).useGetPropertyFunction = false;
|
||||
}
|
||||
stack.push(new PostIncrementActionItem(this, lineStartAction, obj));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (value.getThroughDuplicate() instanceof DecrementActionItem) {
|
||||
GraphTargetItem obj = ((DecrementActionItem) value).object;
|
||||
if (!stack.isEmpty() && stack.peek().valueEquals(obj)) {
|
||||
stack.pop();
|
||||
if (obj instanceof GetPropertyActionItem) {
|
||||
((GetPropertyActionItem) obj).useGetPropertyFunction = false;
|
||||
}
|
||||
stack.push(new PostDecrementActionItem(this, lineStartAction, obj));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
GraphTargetItem ret = new SetPropertyActionItem(this, lineStartAction, target, indexInt, value);
|
||||
|
||||
if (value instanceof StoreRegisterActionItem) {
|
||||
StoreRegisterActionItem sr = (StoreRegisterActionItem) value;
|
||||
if (sr.define) {
|
||||
value = sr.getValue();
|
||||
((SetPropertyActionItem) ret).setValue(value);
|
||||
if (value instanceof IncrementActionItem) {
|
||||
if (((IncrementActionItem) value).object instanceof GetPropertyActionItem) {
|
||||
if (((GetPropertyActionItem) ((IncrementActionItem) value).object).valueEquals(((SetPropertyActionItem) ret).getObject())) {
|
||||
((GetPropertyActionItem) ((IncrementActionItem) value).object).useGetPropertyFunction = false;
|
||||
ret = new PreIncrementActionItem(this, lineStartAction, ((IncrementActionItem) value).object);
|
||||
}
|
||||
}
|
||||
} else if (value instanceof DecrementActionItem) {
|
||||
if (((DecrementActionItem) value).object instanceof GetPropertyActionItem) {
|
||||
if (((GetPropertyActionItem) ((DecrementActionItem) value).object).valueEquals(((SetPropertyActionItem) ret).getObject())) {
|
||||
((GetPropertyActionItem) ((DecrementActionItem) value).object).useGetPropertyFunction = false;
|
||||
ret = new PreDecrementActionItem(this, lineStartAction, ((DecrementActionItem) value).object);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sr.temporary = true;
|
||||
((SetPropertyActionItem) ret).setValue(sr);
|
||||
}
|
||||
variables.put("__register" + sr.register.number, new TemporaryRegister(sr.register.number, ret));
|
||||
return;
|
||||
}
|
||||
}
|
||||
output.add(ret);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user