diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/AVM2Code.java b/trunk/src/com/jpexs/asdec/abc/avm2/AVM2Code.java index 3bc644222..888e9df57 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/AVM2Code.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/AVM2Code.java @@ -1501,8 +1501,22 @@ public HashMap 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 localRegs, Stack stack, java.util.Stack scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List output, com.jpexs.asdec.abc.types.MethodBody body, com.jpexs.asdec.abc.ABC abc, HashMap 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)); } diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/EachTreeItem.java b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/InTreeItem.java similarity index 78% rename from trunk/src/com/jpexs/asdec/abc/avm2/treemodel/EachTreeItem.java rename to trunk/src/com/jpexs/asdec/abc/avm2/treemodel/InTreeItem.java index 87dbe6309..7474963a9 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/EachTreeItem.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/InTreeItem.java @@ -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 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); } diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/ForEachTreeItem.java b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/ForEachInTreeItem.java similarity index 86% rename from trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/ForEachTreeItem.java rename to trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/ForEachInTreeItem.java index 8e87c09ae..7a2c09c56 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/ForEachTreeItem.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/ForEachInTreeItem.java @@ -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 commands; - public ForEachTreeItem(AVM2Instruction instruction, int loopBreak, int loopContinue, EachTreeItem expression, List commands) { + public ForEachInTreeItem(AVM2Instruction instruction, int loopBreak, int loopContinue, InTreeItem expression, List 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 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"; } diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/ForInTreeItem.java b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/ForInTreeItem.java new file mode 100644 index 000000000..fab98dc5b --- /dev/null +++ b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/ForInTreeItem.java @@ -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 . + */ + +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 commands; + + public ForInTreeItem(AVM2Instruction instruction, int loopBreak, int loopContinue, InTreeItem expression, List 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 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 getContinues() { + List ret = new ArrayList(); + for (TreeItem ti : commands) { + if (ti instanceof ContinueTreeItem) { + ret.add((ContinueTreeItem) ti); + } + if (ti instanceof Block) { + ret.addAll(((Block) ti).getContinues()); + } + } + return ret; + } +}