mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-05 18:34:45 +00:00
Issue 13: AS3: for..in, for each..in
This commit is contained in:
@@ -1501,8 +1501,22 @@ public HashMap<Integer,String> getLocalRegNamesFromDebug(ABC abc){
|
||||
} else if (isDoWhile) {
|
||||
output.add(new DoWhileTreeItem(ins, currentLoop.loopBreak, currentLoop.loopContinue, loopBody, expression));
|
||||
} else {
|
||||
if (expression instanceof EachTreeItem) {
|
||||
output.add(new ForEachTreeItem(ins, currentLoop.loopBreak, currentLoop.loopContinue, (EachTreeItem) expression, loopBody));
|
||||
if (expression instanceof InTreeItem) {
|
||||
for(int g=ip+1;g<jumpPos;g++)
|
||||
{
|
||||
if(code.get(g).definition instanceof NextValueIns)
|
||||
{
|
||||
output.add(new ForEachInTreeItem(ins, currentLoop.loopBreak, currentLoop.loopContinue, (InTreeItem) expression, loopBody));
|
||||
break;
|
||||
}
|
||||
if(code.get(g).definition instanceof NextNameIns)
|
||||
{
|
||||
output.add(new ForInTreeItem(ins, currentLoop.loopBreak, currentLoop.loopContinue, (InTreeItem) expression, loopBody));
|
||||
break;
|
||||
}
|
||||
}
|
||||
throw new ConvertException("Unknown pattern: hasnext without nextvalue/nextname", ip);
|
||||
|
||||
} else {
|
||||
output.add(new WhileTreeItem(ins, currentLoop.loopBreak, currentLoop.loopContinue, expression, loopBody));
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import com.jpexs.asdec.abc.avm2.AVM2Code; import java.util.HashMap;
|
||||
import com.jpexs.asdec.abc.avm2.ConstantPool;
|
||||
import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.asdec.abc.avm2.instructions.InstructionDefinition;
|
||||
import com.jpexs.asdec.abc.avm2.treemodel.EachTreeItem;
|
||||
import com.jpexs.asdec.abc.avm2.treemodel.InTreeItem;
|
||||
import com.jpexs.asdec.abc.avm2.treemodel.LocalRegTreeItem;
|
||||
import com.jpexs.asdec.abc.avm2.treemodel.TreeItem;
|
||||
import com.jpexs.asdec.abc.types.MethodInfo;
|
||||
@@ -41,6 +41,6 @@ public class HasNext2Ins extends InstructionDefinition {
|
||||
int objectReg = ins.operands[0];
|
||||
int indexReg = ins.operands[1];
|
||||
//stack.push("_loc_" + objectReg + ".hasNext(cnt=_loc_" + indexReg + ")");
|
||||
stack.push(new EachTreeItem(ins, new LocalRegTreeItem(ins, indexReg, localRegs.get(indexReg)), localRegs.get(objectReg)));
|
||||
stack.push(new InTreeItem(ins, new LocalRegTreeItem(ins, indexReg, localRegs.get(indexReg)), localRegs.get(objectReg)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import com.jpexs.asdec.abc.ABC;
|
||||
import com.jpexs.asdec.abc.avm2.ConstantPool;
|
||||
import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.asdec.abc.avm2.instructions.InstructionDefinition;
|
||||
import com.jpexs.asdec.abc.avm2.treemodel.EachTreeItem;
|
||||
import com.jpexs.asdec.abc.avm2.treemodel.InTreeItem;
|
||||
import com.jpexs.asdec.abc.avm2.treemodel.TreeItem;
|
||||
import com.jpexs.asdec.abc.types.MethodInfo;
|
||||
|
||||
@@ -39,7 +39,7 @@ public class HasNextIns extends InstructionDefinition {
|
||||
public void translate(boolean isStatic, int classIndex, java.util.HashMap<Integer, TreeItem> localRegs, Stack<TreeItem> stack, java.util.Stack<TreeItem> scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List<TreeItem> output, com.jpexs.asdec.abc.types.MethodBody body, com.jpexs.asdec.abc.ABC abc, HashMap<Integer,String> localRegNames) {
|
||||
TreeItem curIndex = (TreeItem) stack.pop();
|
||||
TreeItem obj = (TreeItem) stack.pop();
|
||||
stack.push(new EachTreeItem(ins, curIndex, obj));
|
||||
stack.push(new InTreeItem(ins, curIndex, obj));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ import com.jpexs.asdec.abc.avm2.ConstantPool; import java.util.HashMap;
|
||||
import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction;
|
||||
|
||||
|
||||
public class EachTreeItem extends TreeItem {
|
||||
public class InTreeItem extends TreeItem {
|
||||
public TreeItem object;
|
||||
public TreeItem collection;
|
||||
|
||||
public EachTreeItem(AVM2Instruction instruction, TreeItem object, TreeItem collection) {
|
||||
public InTreeItem(AVM2Instruction instruction, TreeItem object, TreeItem collection) {
|
||||
super(instruction, NOPRECEDENCE);
|
||||
this.object = object;
|
||||
this.collection = collection;
|
||||
@@ -33,7 +33,7 @@ public class EachTreeItem extends TreeItem {
|
||||
|
||||
@Override
|
||||
public String toString(ConstantPool constants, HashMap<Integer,String> localRegNames) {
|
||||
return hilight("each (") + object.toString(constants,localRegNames) + hilight(" in ") + collection.toString(constants,localRegNames) + ")";
|
||||
return object.toString(constants,localRegNames) + hilight(" in ") + collection.toString(constants,localRegNames);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ package com.jpexs.asdec.abc.avm2.treemodel.clauses;
|
||||
import com.jpexs.asdec.abc.avm2.ConstantPool; import java.util.HashMap;
|
||||
import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.asdec.abc.avm2.treemodel.ContinueTreeItem;
|
||||
import com.jpexs.asdec.abc.avm2.treemodel.EachTreeItem;
|
||||
import com.jpexs.asdec.abc.avm2.treemodel.InTreeItem;
|
||||
import com.jpexs.asdec.abc.avm2.treemodel.LocalRegTreeItem;
|
||||
import com.jpexs.asdec.abc.avm2.treemodel.SetLocalTreeItem;
|
||||
import com.jpexs.asdec.abc.avm2.treemodel.SetTypeTreeItem;
|
||||
@@ -30,12 +30,12 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class ForEachTreeItem extends LoopTreeItem implements Block {
|
||||
public class ForEachInTreeItem extends LoopTreeItem implements Block {
|
||||
|
||||
public EachTreeItem expression;
|
||||
public InTreeItem expression;
|
||||
public List<TreeItem> commands;
|
||||
|
||||
public ForEachTreeItem(AVM2Instruction instruction, int loopBreak, int loopContinue, EachTreeItem expression, List<TreeItem> commands) {
|
||||
public ForEachInTreeItem(AVM2Instruction instruction, int loopBreak, int loopContinue, InTreeItem expression, List<TreeItem> commands) {
|
||||
super(instruction, loopBreak, loopContinue);
|
||||
TreeItem firstAssign=commands.get(0);
|
||||
if(firstAssign instanceof SetTypeTreeItem){
|
||||
@@ -64,7 +64,7 @@ public class ForEachTreeItem extends LoopTreeItem implements Block {
|
||||
public String toString(ConstantPool constants, HashMap<Integer,String> localRegNames) {
|
||||
String ret = "";
|
||||
ret += "loop" + loopBreak + ":\r\n";
|
||||
ret += hilight("for ") + expression.toString(constants,localRegNames) + "\r\n{\r\n";
|
||||
ret += hilight("for each (") + expression.toString(constants,localRegNames) + ")\r\n{\r\n";
|
||||
for (TreeItem ti : commands) {
|
||||
ret += ti.toStringSemicoloned(constants,localRegNames) + "\r\n";
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2011 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.asdec.abc.avm2.treemodel.clauses;
|
||||
|
||||
import com.jpexs.asdec.abc.avm2.ConstantPool; import java.util.HashMap;
|
||||
import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.asdec.abc.avm2.treemodel.ContinueTreeItem;
|
||||
import com.jpexs.asdec.abc.avm2.treemodel.InTreeItem;
|
||||
import com.jpexs.asdec.abc.avm2.treemodel.LocalRegTreeItem;
|
||||
import com.jpexs.asdec.abc.avm2.treemodel.SetLocalTreeItem;
|
||||
import com.jpexs.asdec.abc.avm2.treemodel.SetTypeTreeItem;
|
||||
import com.jpexs.asdec.abc.avm2.treemodel.TreeItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class ForInTreeItem extends LoopTreeItem implements Block {
|
||||
|
||||
public InTreeItem expression;
|
||||
public List<TreeItem> commands;
|
||||
|
||||
public ForInTreeItem(AVM2Instruction instruction, int loopBreak, int loopContinue, InTreeItem expression, List<TreeItem> commands) {
|
||||
super(instruction, loopBreak, loopContinue);
|
||||
TreeItem firstAssign=commands.get(0);
|
||||
if(firstAssign instanceof SetTypeTreeItem){
|
||||
if(expression.object instanceof LocalRegTreeItem){
|
||||
if(((SetTypeTreeItem)firstAssign).getValue().getNotCoerced() instanceof LocalRegTreeItem)
|
||||
{
|
||||
if(((LocalRegTreeItem)((SetTypeTreeItem)firstAssign).getValue().getNotCoerced()).regIndex==((LocalRegTreeItem)expression.object).regIndex){
|
||||
commands.remove(0);
|
||||
expression.object=((SetTypeTreeItem)firstAssign).getObject();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//locAssign.
|
||||
}
|
||||
this.expression = expression;
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsSemicolon() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(ConstantPool constants, HashMap<Integer,String> localRegNames) {
|
||||
String ret = "";
|
||||
ret += "loop" + loopBreak + ":\r\n";
|
||||
ret += hilight("for (") + expression.toString(constants,localRegNames) + ")\r\n{\r\n";
|
||||
for (TreeItem ti : commands) {
|
||||
ret += ti.toStringSemicoloned(constants,localRegNames) + "\r\n";
|
||||
}
|
||||
ret += hilight("}") + "\r\n";
|
||||
ret += ":loop" + loopBreak;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<ContinueTreeItem> getContinues() {
|
||||
List<ContinueTreeItem> ret = new ArrayList<ContinueTreeItem>();
|
||||
for (TreeItem ti : commands) {
|
||||
if (ti instanceof ContinueTreeItem) {
|
||||
ret.add((ContinueTreeItem) ti);
|
||||
}
|
||||
if (ti instanceof Block) {
|
||||
ret.addAll(((Block) ti).getContinues());
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user