diff --git a/trunk/src/com/jpexs/asdec/abc/ABC.java b/trunk/src/com/jpexs/asdec/abc/ABC.java index 527fd1acc..155510dc2 100644 --- a/trunk/src/com/jpexs/asdec/abc/ABC.java +++ b/trunk/src/com/jpexs/asdec/abc/ABC.java @@ -371,7 +371,7 @@ public class ABC { } } - private void parseImportFromMultiname(List imports, Multiname m) { + private void parseImportFromMultiname(List imports, Multiname m, String ignorePackage) { if (m != null) { Namespace ns = m.getNamespace(constants); String name = m.getName(constants); @@ -386,7 +386,10 @@ public class ABC { return; } if (!imports.contains(newimport)) { - imports.add(newimport); + String pkg = newimport.substring(0,newimport.lastIndexOf(".")); + if (!pkg.equals(ignorePackage)) { + imports.add(newimport); + } } } } @@ -400,69 +403,106 @@ public class ABC { //parseImportFromMultiname(imports, constants.constant_multiname[instance_info[instanceIndex].name_index]); + String packageName = instance_info[instanceIndex].getName(constants).getNamespace(constants).getName(constants); + if (instance_info[instanceIndex].super_index > 0) { - parseImportFromMultiname(imports, constants.constant_multiname[instance_info[instanceIndex].super_index]); + parseImportFromMultiname(imports, constants.constant_multiname[instance_info[instanceIndex].super_index],packageName); } for (int i : instance_info[instanceIndex].interfaces) { - parseImportFromMultiname(imports, constants.constant_multiname[i]); + parseImportFromMultiname(imports, constants.constant_multiname[i],packageName); } + + + MethodBody body; + + + + //static for (Trait t : class_info[instanceIndex].static_traits.traits) { //parseImportFromMultiname(imports, t.getMultiName(constants)); if (t instanceof TraitMethodGetterSetter) { TraitMethodGetterSetter tm = (TraitMethodGetterSetter) t; if (tm.method_info != 0) { - MethodBody body = findBody(tm.method_info); + body = findBody(tm.method_info); if (body != null) { for (AVM2Instruction ins : body.code.code) { for (int k = 0; k < ins.definition.operands.length; k++) { if (ins.definition.operands[k] == AVM2Code.DAT_MULTINAME_INDEX) { int multinameIndex = ins.operands[k]; - parseImportFromMultiname(imports, constants.constant_multiname[multinameIndex]); + parseImportFromMultiname(imports, constants.constant_multiname[multinameIndex],packageName); } } } } for (int p = 0; p < method_info[tm.method_info].param_types.length; p++) { if (method_info[tm.method_info].param_types[p] != 0) { - parseImportFromMultiname(imports, constants.constant_multiname[method_info[tm.method_info].param_types[p]]); + parseImportFromMultiname(imports, constants.constant_multiname[method_info[tm.method_info].param_types[p]],packageName); } if (method_info[tm.method_info].ret_type != 0) { - parseImportFromMultiname(imports, constants.constant_multiname[method_info[tm.method_info].ret_type]); + parseImportFromMultiname(imports, constants.constant_multiname[method_info[tm.method_info].ret_type],packageName); } } } } } + + //static initializer + body = findBody(class_info[instanceIndex].cinit_index); + if (body != null) { + for (AVM2Instruction ins : body.code.code) { + for (int k = 0; k < ins.definition.operands.length; k++) { + if (ins.definition.operands[k] == AVM2Code.DAT_MULTINAME_INDEX) { + int multinameIndex = ins.operands[k]; + parseImportFromMultiname(imports, constants.constant_multiname[multinameIndex],packageName); + } + } + } + } + //instance for (Trait t : instance_info[instanceIndex].instance_traits.traits) { //parseImportFromMultiname(imports, t.getMultiName(constants)); if (t instanceof TraitMethodGetterSetter) { TraitMethodGetterSetter tm = (TraitMethodGetterSetter) t; if (tm.method_info != 0) { - MethodBody body = findBody(tm.method_info); + body = findBody(tm.method_info); if (body != null) { for (AVM2Instruction ins : body.code.code) { for (int k = 0; k < ins.definition.operands.length; k++) { if (ins.definition.operands[k] == AVM2Code.DAT_MULTINAME_INDEX) { int multinameIndex = ins.operands[k]; - parseImportFromMultiname(imports, constants.constant_multiname[multinameIndex]); + parseImportFromMultiname(imports, constants.constant_multiname[multinameIndex],packageName); } } } } for (int p = 0; p < method_info[tm.method_info].param_types.length; p++) { if (method_info[tm.method_info].param_types[p] != 0) { - parseImportFromMultiname(imports, constants.constant_multiname[method_info[tm.method_info].param_types[p]]); + parseImportFromMultiname(imports, constants.constant_multiname[method_info[tm.method_info].param_types[p]],packageName); } if (method_info[tm.method_info].ret_type != 0) { - parseImportFromMultiname(imports, constants.constant_multiname[method_info[tm.method_info].ret_type]); + parseImportFromMultiname(imports, constants.constant_multiname[method_info[tm.method_info].ret_type],packageName); } } } } } + + //instance initializer + body = findBody(instance_info[instanceIndex].iinit_index); + if (body != null) { + for (AVM2Instruction ins : body.code.code) { + for (int k = 0; k < ins.definition.operands.length; k++) { + if (ins.definition.operands[k] == AVM2Code.DAT_MULTINAME_INDEX) { + int multinameIndex = ins.operands[k]; + parseImportFromMultiname(imports, constants.constant_multiname[multinameIndex],packageName); + } + } + } + } + return imports; } @@ -681,16 +721,18 @@ public class ABC { String bodyStr = ""; int bodyIndex = findBodyIndex(class_info[i].cinit_index); if (bodyIndex != -1) { - bodyStr = addTabs(bodies[bodyIndex].toString(pcode, true, i, this, constants, method_info, new Stack(), highlight), 3); + bodyStr = bodies[bodyIndex].toString(pcode, true, i, this, constants, method_info, new Stack(), true, highlight); + } + if (Highlighting.stripHilights(bodyStr).equals("")) { + toPrint = addTabs(bodyStr, 3); + } else { + toPrint = IDENT_STRING + IDENT_STRING + "{\r\n" + addTabs(bodyStr, 3) + "\r\n" + IDENT_STRING + IDENT_STRING + "}"; } - // if (!bodyStr.equals("")) { - toPrint = IDENT_STRING + IDENT_STRING + "{\r\n" + bodyStr + "\r\n" + IDENT_STRING + IDENT_STRING + "}"; if (highlight) { toPrint = Highlighting.hilighTrait(toPrint, class_info[i].static_traits.traits.length + instance_info[i].instance_traits.traits.length + 1); } outTraits.add(toPrint); //} - //} //constructor //if (instance_info[i].iinit_index != 0) { @@ -710,7 +752,7 @@ public class ABC { bodyStr = ""; bodyIndex = findBodyIndex(instance_info[i].iinit_index); if (bodyIndex != -1) { - bodyStr = addTabs(bodies[bodyIndex].toString(pcode, false, i, this, constants, method_info, new Stack(), highlight), 3); + bodyStr = addTabs(bodies[bodyIndex].toString(pcode, false, i, this, constants, method_info, new Stack(), false, highlight), 3); constructorParams = method_info[instance_info[i].iinit_index].getParamStr(constants, bodies[bodyIndex], this); } else { constructorParams = method_info[instance_info[i].iinit_index].getParamStr(constants, null, this); @@ -731,7 +773,7 @@ public class ABC { bodyStr = ""; bodyIndex = findBodyIndex(tm.method_info); if (bodyIndex != -1) { - bodyStr = addTabs(bodies[bodyIndex].toString(pcode, true, i, this, constants, method_info, new Stack(), highlight), 3); + bodyStr = addTabs(bodies[bodyIndex].toString(pcode, true, i, this, constants, method_info, new Stack(), false, highlight), 3); } toPrint = IDENT_STRING + IDENT_STRING + tm.convert(method_info, this, true) + " {\r\n" + bodyStr + "\r\n" + IDENT_STRING + IDENT_STRING + "}"; } @@ -760,7 +802,7 @@ public class ABC { bodyStr = ""; bodyIndex = findBodyIndex(tm.method_info); if (bodyIndex != -1) { - bodyStr = addTabs(bodies[bodyIndex].toString(pcode, false, i, this, constants, method_info, new Stack(), highlight), 3); + bodyStr = addTabs(bodies[bodyIndex].toString(pcode, false, i, this, constants, method_info, new Stack(), false, highlight), 3); } toPrint = IDENT_STRING + IDENT_STRING + tm.convert(method_info, this, false) + " {\r\n" + bodyStr + "\r\n" + IDENT_STRING + IDENT_STRING + "}"; } diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/AVM2Code.java b/trunk/src/com/jpexs/asdec/abc/avm2/AVM2Code.java index 2877b8308..4c6226e56 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/AVM2Code.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/AVM2Code.java @@ -1610,8 +1610,8 @@ public class AVM2Code { return ret; } - public String toSource(boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], MethodBody body, HashMap localRegNames, Stack scopeStack) { - return toSource(isStatic, classIndex, abc, constants, method_info, body, false, localRegNames, scopeStack); + public String toSource(boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], MethodBody body, HashMap localRegNames, Stack scopeStack,boolean isStaticInitializer) { + return toSource(isStatic, classIndex, abc, constants, method_info, body, false, localRegNames, scopeStack,isStaticInitializer); } public List toTree(boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], MethodBody body, HashMap localRegNames) { @@ -1689,7 +1689,7 @@ public class AVM2Code { } } - public String toSource(boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], MethodBody body, boolean hilighted, HashMap localRegNames, Stack scopeStack) { + public String toSource(boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], MethodBody body, boolean hilighted, HashMap localRegNames, Stack scopeStack,boolean isStaticInitializer) { toSourceCount = 0; loopList = new ArrayList(); unknownJumps = new ArrayList(); @@ -1712,7 +1712,23 @@ public class AVM2Code { try { list = toSource(isStatic, classIndex, localRegs, new Stack(), scopeStack, abc, constants, method_info, body, 0, code.size() - 1, localRegNames).output; - + if(isStaticInitializer){ + + List newList=new ArrayList(); + for(TreeItem ti:list){ + if(!(ti instanceof ReturnVoidTreeItem)){ + if(!(ti instanceof InitPropertyTreeItem)){ + if(!(ti instanceof SetPropertyTreeItem)){ + newList.add(ti); + } + } + } + } + list=newList; + if(list.isEmpty()){ + return ""; + } + } //Declarations boolean declaredRegisters[] = new boolean[regCount]; for (int b = 0; b < declaredRegisters.length; b++) { diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/construction/NewFunctionIns.java b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/construction/NewFunctionIns.java index c0ca141cf..6fd877f41 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/construction/NewFunctionIns.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/construction/NewFunctionIns.java @@ -43,7 +43,7 @@ public class NewFunctionIns extends InstructionDefinition { String bodyStr = ""; String paramStr = ""; if (mybody != null) { - bodyStr = Highlighting.hilighMethodEnd() + mybody.toString(false, isStatic, classIndex, abc, constants, method_info, scopeStack, true) + Highlighting.hilighMethodBegin(body.method_info); + bodyStr = Highlighting.hilighMethodEnd() + mybody.toString(false, isStatic, classIndex, abc, constants, method_info, new Stack()/*scopeStack*/, false,true) + Highlighting.hilighMethodBegin(body.method_info); paramStr = method_info[methodIndex].getParamStr(constants, mybody, abc); } stack.push(new NewFunctionTreeItem(ins, paramStr, method_info[methodIndex].getReturnTypeStr(constants), bodyStr)); diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/GetGlobalScopeIns.java b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/GetGlobalScopeIns.java index c15c6efed..c2a2065f7 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/GetGlobalScopeIns.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/GetGlobalScopeIns.java @@ -21,6 +21,7 @@ import com.jpexs.asdec.abc.avm2.ConstantPool; import com.jpexs.asdec.abc.avm2.LocalDataArea; import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction; import com.jpexs.asdec.abc.avm2.instructions.InstructionDefinition; +import com.jpexs.asdec.abc.avm2.treemodel.ClassTreeItem; import com.jpexs.asdec.abc.avm2.treemodel.TreeItem; import com.jpexs.asdec.abc.types.MethodInfo; import java.util.HashMap; @@ -40,6 +41,10 @@ public class GetGlobalScopeIns extends InstructionDefinition { @Override public void translate(boolean isStatic, int classIndex, java.util.HashMap 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) { + if(scopeStack.isEmpty()){ + stack.push(new ClassTreeItem(abc.instance_info[classIndex].getName(constants))); + return; + } stack.push(scopeStack.get(0)); } diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/GetScopeObjectIns.java b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/GetScopeObjectIns.java index a7ac0d8f5..0f8e2eeea 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/GetScopeObjectIns.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/GetScopeObjectIns.java @@ -39,7 +39,7 @@ public class GetScopeObjectIns extends InstructionDefinition { /* System.out.println("Getting scope object"+index+":"); for(TreeItem ti:scopeStack){ System.out.println(ti.toString(constants)); - }*/ + }*/ stack.push(scopeStack.get(index)); } diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/SetSlotIns.java b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/SetSlotIns.java index a240fe1da..02d034d43 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/SetSlotIns.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/SetSlotIns.java @@ -66,12 +66,9 @@ public class SetSlotIns extends InstructionDefinition implements SetTypeIns { } - //if new activation sets params of the function - if (obj.getThroughRegister() instanceof NewActivationTreeItem) { - if (localRegNames.containsValue(slotname.getName(constants))) { - return; - } - } + if (localRegNames.containsValue(slotname.getName(constants))) { + return; + }; if (value.getNotCoerced() instanceof IncrementTreeItem) { TreeItem inside = ((IncrementTreeItem) value.getNotCoerced()).object.getThroughRegister().getNotCoerced(); diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/stack/PopIns.java b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/stack/PopIns.java index d771f4d27..e8a2b199e 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/stack/PopIns.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/stack/PopIns.java @@ -22,6 +22,7 @@ import com.jpexs.asdec.abc.avm2.LocalDataArea; import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction; import com.jpexs.asdec.abc.avm2.instructions.InstructionDefinition; import com.jpexs.asdec.abc.avm2.treemodel.*; +import com.jpexs.asdec.abc.avm2.treemodel.clauses.AssignmentTreeItem; import com.jpexs.asdec.abc.types.MethodInfo; import java.util.HashMap; import java.util.List; @@ -52,6 +53,8 @@ public class PopIns extends InstructionDefinition { output.add(top); } else if (top instanceof CallTreeItem) { output.add(top); + } else if (top instanceof AssignmentTreeItem) { + output.add(top); } } } diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/InitPropertyTreeItem.java b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/InitPropertyTreeItem.java index e13ba694f..6dda585d1 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/InitPropertyTreeItem.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/InitPropertyTreeItem.java @@ -18,9 +18,10 @@ package com.jpexs.asdec.abc.avm2.treemodel; import com.jpexs.asdec.abc.avm2.ConstantPool; import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.asdec.abc.avm2.treemodel.clauses.AssignmentTreeItem; import java.util.HashMap; -public class InitPropertyTreeItem extends TreeItem implements SetTypeTreeItem { +public class InitPropertyTreeItem extends TreeItem implements SetTypeTreeItem,AssignmentTreeItem { public TreeItem object; public FullMultinameTreeItem propertyName; diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/PostDecrementTreeItem.java b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/PostDecrementTreeItem.java index 9b160cc6a..b80d4fe41 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/PostDecrementTreeItem.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/PostDecrementTreeItem.java @@ -18,9 +18,10 @@ package com.jpexs.asdec.abc.avm2.treemodel; import com.jpexs.asdec.abc.avm2.ConstantPool; import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.asdec.abc.avm2.treemodel.clauses.AssignmentTreeItem; import java.util.HashMap; -public class PostDecrementTreeItem extends TreeItem { +public class PostDecrementTreeItem extends TreeItem implements AssignmentTreeItem { public TreeItem object; diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/PostIncrementTreeItem.java b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/PostIncrementTreeItem.java index a045a23e8..821cb6c31 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/PostIncrementTreeItem.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/PostIncrementTreeItem.java @@ -18,9 +18,10 @@ package com.jpexs.asdec.abc.avm2.treemodel; import com.jpexs.asdec.abc.avm2.ConstantPool; import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.asdec.abc.avm2.treemodel.clauses.AssignmentTreeItem; import java.util.HashMap; -public class PostIncrementTreeItem extends TreeItem { +public class PostIncrementTreeItem extends TreeItem implements AssignmentTreeItem { public TreeItem object; diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/SetLocalTreeItem.java b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/SetLocalTreeItem.java index ccd328e71..e0ccb3a84 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/SetLocalTreeItem.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/SetLocalTreeItem.java @@ -18,9 +18,10 @@ package com.jpexs.asdec.abc.avm2.treemodel; import com.jpexs.asdec.abc.avm2.ConstantPool; import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.asdec.abc.avm2.treemodel.clauses.AssignmentTreeItem; import java.util.HashMap; -public class SetLocalTreeItem extends TreeItem implements SetTypeTreeItem { +public class SetLocalTreeItem extends TreeItem implements SetTypeTreeItem,AssignmentTreeItem { public int regIndex; public TreeItem value; diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/SetPropertyTreeItem.java b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/SetPropertyTreeItem.java index ab6f234a7..a23232008 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/SetPropertyTreeItem.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/SetPropertyTreeItem.java @@ -18,9 +18,10 @@ package com.jpexs.asdec.abc.avm2.treemodel; import com.jpexs.asdec.abc.avm2.ConstantPool; import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.asdec.abc.avm2.treemodel.clauses.AssignmentTreeItem; import java.util.HashMap; -public class SetPropertyTreeItem extends TreeItem implements SetTypeTreeItem { +public class SetPropertyTreeItem extends TreeItem implements SetTypeTreeItem,AssignmentTreeItem { public TreeItem object; public FullMultinameTreeItem propertyName; diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/SetSlotTreeItem.java b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/SetSlotTreeItem.java index 3f313b015..bfd80b2ed 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/SetSlotTreeItem.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/SetSlotTreeItem.java @@ -18,10 +18,11 @@ package com.jpexs.asdec.abc.avm2.treemodel; import com.jpexs.asdec.abc.avm2.ConstantPool; import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.asdec.abc.avm2.treemodel.clauses.AssignmentTreeItem; import com.jpexs.asdec.abc.types.Multiname; import java.util.HashMap; -public class SetSlotTreeItem extends TreeItem implements SetTypeTreeItem { +public class SetSlotTreeItem extends TreeItem implements SetTypeTreeItem,AssignmentTreeItem { public Multiname slotName; public TreeItem value; @@ -36,8 +37,14 @@ public class SetSlotTreeItem extends TreeItem implements SetTypeTreeItem { @Override public String toString(ConstantPool constants, HashMap localRegNames) { + + return getName(constants,localRegNames)+ hilight("=") + value.toString(constants, localRegNames); + } + + public String getName(ConstantPool constants, HashMap localRegNames){ String ret = ""; + /*ret = scope.toString(constants, localRegNames) + "."; if (!(scope instanceof NewActivationTreeItem)) { ret = scope.toString(constants, localRegNames) + "."; } @@ -47,8 +54,8 @@ public class SetSlotTreeItem extends TreeItem implements SetTypeTreeItem { ret = ""; } } - } - return ret + hilight(slotName.getName(constants)) + hilight("=") + value.toString(constants, localRegNames); + }*/ + return ret + hilight(slotName.getName(constants)); } public TreeItem getObject() { diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/AssignmentTreeItem.java b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/AssignmentTreeItem.java new file mode 100644 index 000000000..5ad7f3fce --- /dev/null +++ b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/AssignmentTreeItem.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2012 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +package com.jpexs.asdec.abc.avm2.treemodel.clauses; + +/** + * + * @author JPEXS + */ +public interface AssignmentTreeItem { + +} diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/DeclarationTreeItem.java b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/DeclarationTreeItem.java index 4c8b7bfe5..eddd5fcb1 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/DeclarationTreeItem.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/DeclarationTreeItem.java @@ -60,19 +60,8 @@ public class DeclarationTreeItem extends TreeItem { return "var " + hilight(localRegName(localRegNames, lti.regIndex) + ":" + type + " = ") + lti.value.toString(constants, localRegNames); } if (assignment instanceof SetSlotTreeItem) { - SetSlotTreeItem ssti = (SetSlotTreeItem) assignment; - String ret = ""; - if (!(ssti.scope instanceof NewActivationTreeItem)) { - ret = ssti.scope.toString(constants, localRegNames) + "."; - } - if (ssti.scope instanceof LocalRegTreeItem) { - if (((LocalRegTreeItem) ssti.scope).computedValue != null) { - if (((LocalRegTreeItem) ssti.scope).computedValue instanceof NewActivationTreeItem) { - ret = ""; - } - } - } - return "var " + ret + hilight(ssti.slotName.getName(constants)) + ":" + type + hilight(" = ") + ssti.value.toString(constants, localRegNames); + SetSlotTreeItem ssti = (SetSlotTreeItem) assignment; + return "var " + ssti.getName(constants, localRegNames) + ":" + type + hilight(" = ") + ssti.value.toString(constants, localRegNames); } return "var " + assignment.toString(constants, localRegNames); } diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/ForEachInTreeItem.java b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/ForEachInTreeItem.java index 2e8bd92e3..4ac8cfa25 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/ForEachInTreeItem.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/ForEachInTreeItem.java @@ -30,18 +30,20 @@ public class ForEachInTreeItem extends LoopTreeItem implements Block { 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) { - 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(); + if (!commands.isEmpty()) { + 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. } - //locAssign. } this.expression = expression; this.commands = commands; 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 index be07af764..1e2ebb3d6 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/ForInTreeItem.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/clauses/ForInTreeItem.java @@ -30,18 +30,20 @@ public class ForInTreeItem extends LoopTreeItem implements Block { 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(); + if (!commands.isEmpty()) { + 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. } - //locAssign. } this.expression = expression; this.commands = commands; diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/operations/PreDecrementTreeItem.java b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/operations/PreDecrementTreeItem.java index 928bb8b26..b37de3978 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/operations/PreDecrementTreeItem.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/operations/PreDecrementTreeItem.java @@ -18,8 +18,9 @@ package com.jpexs.asdec.abc.avm2.treemodel.operations; import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction; import com.jpexs.asdec.abc.avm2.treemodel.TreeItem; +import com.jpexs.asdec.abc.avm2.treemodel.clauses.AssignmentTreeItem; -public class PreDecrementTreeItem extends UnaryOpTreeItem { +public class PreDecrementTreeItem extends UnaryOpTreeItem implements AssignmentTreeItem { public PreDecrementTreeItem(AVM2Instruction instruction, TreeItem object) { super(instruction, PRECEDENCE_UNARY, object, "--"); diff --git a/trunk/src/com/jpexs/asdec/abc/types/MethodBody.java b/trunk/src/com/jpexs/asdec/abc/types/MethodBody.java index 09c55acc3..4aa4489a8 100644 --- a/trunk/src/com/jpexs/asdec/abc/types/MethodBody.java +++ b/trunk/src/com/jpexs/asdec/abc/types/MethodBody.java @@ -73,11 +73,11 @@ public class MethodBody implements Cloneable { return ret; } - public String toString(boolean pcode, boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], Stack scopeStack) { - return toString(pcode, isStatic, classIndex, abc, constants, method_info, scopeStack, false); - } + /*public String toString(boolean pcode, boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], Stack scopeStack, boolean isStaticInitializer) { + return toString(pcode, isStatic, classIndex, abc, constants, method_info, scopeStack, isStaticInitializer,false); + }*/ - public String toString(boolean pcode, boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], Stack scopeStack, boolean hilight) { + public String toString(boolean pcode, boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], Stack scopeStack, boolean isStaticInitializer,boolean hilight) { String s = ""; //s+="method_info="+method_info+" max_stack="+max_stack+" max_regs="+max_regs+" scope_depth="+scope_depth+" max_scope="+max_scope; @@ -86,7 +86,7 @@ public class MethodBody implements Cloneable { s += code.toASMSource(constants, this); } else { try { - s += code.toSource(isStatic, classIndex, abc, constants, method_info, this, hilight, getLocalRegNames(abc), scopeStack); + s += code.toSource(isStatic, classIndex, abc, constants, method_info, this, hilight, getLocalRegNames(abc), scopeStack,isStaticInitializer); s = s.trim(); if (hilight) { s = Highlighting.hilighMethod(s, this.method_info);