mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-30 14:31:56 +00:00
Issue #40, AS1/2 For..in decompilation
This commit is contained in:
@@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.action.swf4.Null;
|
||||
import com.jpexs.decompiler.flash.action.swf5.ActionEquals2;
|
||||
import com.jpexs.decompiler.flash.action.treemodel.DirectValueTreeItem;
|
||||
import com.jpexs.decompiler.flash.action.treemodel.EnumerateTreeItem;
|
||||
import com.jpexs.decompiler.flash.action.treemodel.SetTypeTreeItem;
|
||||
import com.jpexs.decompiler.flash.action.treemodel.StoreRegisterTreeItem;
|
||||
import com.jpexs.decompiler.flash.action.treemodel.clauses.ForInTreeItem;
|
||||
import com.jpexs.decompiler.flash.action.treemodel.operations.NeqTreeItem;
|
||||
@@ -79,8 +80,8 @@ public class ActionGraph extends Graph {
|
||||
GraphTargetItem it = list.get(t);
|
||||
if (it instanceof WhileItem) {
|
||||
WhileItem wi = (WhileItem) it;
|
||||
if ((!wi.commands.isEmpty()) && (wi.commands.get(0) instanceof StoreRegisterTreeItem)) {
|
||||
StoreRegisterTreeItem srt = (StoreRegisterTreeItem) wi.commands.get(0);
|
||||
if ((!wi.commands.isEmpty()) && (wi.commands.get(0) instanceof SetTypeTreeItem)) {
|
||||
SetTypeTreeItem sti = (SetTypeTreeItem) wi.commands.get(0);
|
||||
if (wi.expression instanceof NeqTreeItem) {
|
||||
NeqTreeItem ne = (NeqTreeItem) wi.expression;
|
||||
if (ne.rightSide instanceof DirectValueTreeItem) {
|
||||
@@ -90,7 +91,7 @@ public class ActionGraph extends Graph {
|
||||
EnumerateTreeItem eti = (EnumerateTreeItem) ne.leftSide;
|
||||
list.remove(t);
|
||||
wi.commands.remove(0);
|
||||
list.add(t, new ForInTreeItem(null, wi.loop, new DirectValueTreeItem(null, 0, srt.register, new ArrayList<String>()), eti.object, wi.commands));
|
||||
list.add(t, new ForInTreeItem(null, wi.loop, sti.getObject(), eti.object, wi.commands));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.jpexs.decompiler.flash.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
|
||||
import java.util.List;
|
||||
|
||||
public class DefineLocalTreeItem extends TreeItem {
|
||||
public class DefineLocalTreeItem extends TreeItem implements SetTypeTreeItem{
|
||||
|
||||
public GraphTargetItem name;
|
||||
public GraphTargetItem value;
|
||||
@@ -46,4 +46,9 @@ public class DefineLocalTreeItem extends TreeItem {
|
||||
ret.addAll(name.getNeededSources());
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphTargetItem getObject() {
|
||||
return new DefineLocalTreeItem(src, name, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class SetMemberTreeItem extends TreeItem implements SetTypeTreeItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeItem getObject() {
|
||||
public GraphTargetItem getObject() {
|
||||
return new GetMemberTreeItem(src, object, objectName);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public class SetPropertyTreeItem extends TreeItem implements SetTypeTreeItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeItem getObject() {
|
||||
public GraphTargetItem getObject() {
|
||||
return new GetPropertyTreeItem(src, target, propertyIndex);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,13 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.action.treemodel;
|
||||
|
||||
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public interface SetTypeTreeItem {
|
||||
|
||||
public TreeItem getObject();
|
||||
public GraphTargetItem getObject();
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class SetVariableTreeItem extends TreeItem implements SetTypeTreeItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeItem getObject() {
|
||||
public GraphTargetItem getObject() {
|
||||
return new GetVariableTreeItem(src, value);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public class StoreRegisterTreeItem extends TreeItem implements SetTypeTreeItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeItem getObject() {
|
||||
public GraphTargetItem getObject() {
|
||||
return new DirectValueTreeItem(src, -1, register, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2013 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.action.treemodel.clauses;
|
||||
|
||||
import com.jpexs.decompiler.flash.action.Action;
|
||||
import com.jpexs.decompiler.flash.action.treemodel.ConstantPool;
|
||||
import com.jpexs.decompiler.flash.action.treemodel.EachTreeItem;
|
||||
import com.jpexs.decompiler.flash.graph.Block;
|
||||
import com.jpexs.decompiler.flash.graph.ContinueItem;
|
||||
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.flash.graph.Loop;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ForEachTreeItem extends LoopTreeItem implements Block {
|
||||
|
||||
public EachTreeItem expression;
|
||||
public List<GraphTargetItem> commands;
|
||||
|
||||
@Override
|
||||
public List<List<GraphTargetItem>> getSubs() {
|
||||
List<List<GraphTargetItem>> ret = new ArrayList<List<GraphTargetItem>>();
|
||||
ret.add(commands);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public ForEachTreeItem(Action instruction, Loop loop, EachTreeItem expression, List<GraphTargetItem> commands) {
|
||||
super(instruction, loop);
|
||||
this.expression = expression;
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(ConstantPool constants) {
|
||||
String ret = "";
|
||||
ret += "loop" + loop.id + ":\r\n";
|
||||
ret += hilight("for ") + expression.toString(constants) + "\r\n{\r\n";
|
||||
for (GraphTargetItem ti : commands) {
|
||||
ret += ti.toString(constants) + "\r\n";
|
||||
}
|
||||
ret += hilight("}") + "\r\n";
|
||||
ret += ":loop" + loop.id;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ContinueItem> getContinues() {
|
||||
List<ContinueItem> ret = new ArrayList<ContinueItem>();
|
||||
for (GraphTargetItem ti : commands) {
|
||||
if (ti instanceof ContinueItem) {
|
||||
ret.add((ContinueItem) ti);
|
||||
}
|
||||
if (ti instanceof Block) {
|
||||
ret.addAll(((Block) ti).getContinues());
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,9 @@
|
||||
package com.jpexs.decompiler.flash.action.treemodel.clauses;
|
||||
|
||||
import com.jpexs.decompiler.flash.action.Action;
|
||||
import com.jpexs.decompiler.flash.action.swf4.RegisterNumber;
|
||||
import com.jpexs.decompiler.flash.action.treemodel.ConstantPool;
|
||||
import com.jpexs.decompiler.flash.action.treemodel.DirectValueTreeItem;
|
||||
import com.jpexs.decompiler.flash.graph.Block;
|
||||
import com.jpexs.decompiler.flash.graph.ContinueItem;
|
||||
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
|
||||
@@ -49,9 +51,9 @@ public class ForInTreeItem extends LoopTreeItem implements Block {
|
||||
public String toString(ConstantPool constants) {
|
||||
String ret = "";
|
||||
ret += "loop" + loop.id + ":\r\n";
|
||||
ret += hilight("for(") + stripQuotes(variableName) + " in " + enumVariable.toString(constants) + ")\r\n{\r\n";
|
||||
ret += hilight("for(") + ((variableName instanceof DirectValueTreeItem)&&(((DirectValueTreeItem)variableName).value instanceof RegisterNumber)?"var ":"")+stripQuotes(variableName) + " in " + enumVariable.toString(constants) + ")\r\n{\r\n";
|
||||
for (GraphTargetItem ti : commands) {
|
||||
ret += ti.toString(constants) + "\r\n";
|
||||
ret += ti.toStringSemicoloned(constants) + "\r\n";
|
||||
}
|
||||
ret += hilight("}") + "\r\n";
|
||||
ret += ":loop" + loop.id;
|
||||
|
||||
Reference in New Issue
Block a user