diff --git a/trunk/lib/jsyntaxpane-0.9.5.jar b/trunk/lib/jsyntaxpane-0.9.5.jar index 76ce6f7b0..4bb581a71 100644 Binary files a/trunk/lib/jsyntaxpane-0.9.5.jar and b/trunk/lib/jsyntaxpane-0.9.5.jar differ diff --git a/trunk/libsrc/jsyntaxpane/jsyntaxpane/src/main/jflex/jsyntaxpane/lexers/actionscript.flex b/trunk/libsrc/jsyntaxpane/jsyntaxpane/src/main/jflex/jsyntaxpane/lexers/actionscript.flex index a62b72238..198006e0d 100644 --- a/trunk/libsrc/jsyntaxpane/jsyntaxpane/src/main/jflex/jsyntaxpane/lexers/actionscript.flex +++ b/trunk/libsrc/jsyntaxpane/jsyntaxpane/src/main/jflex/jsyntaxpane/lexers/actionscript.flex @@ -97,6 +97,8 @@ FLit2 = \. [0-9]+ FLit3 = [0-9]+ Exponent = [eE] [+-]? [0-9]+ +NewVector = "new" {WhiteSpace}* "<" + /* string and character literals */ StringCharacter = [^\r\n\"\\] SingleCharacter = [^\r\n\'\\] @@ -215,6 +217,7 @@ SingleCharacter = [^\r\n\'\\] "new" | "typeof" | "void" | + {NewVector} | "@" { return token(TokenType.OPERATOR); } /* string literal */ diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index e7293ac7c..e3a74104a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -187,10 +187,14 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.xml.DXNSIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.xml.DXNSLateIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.xml.EscXAttrIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.xml.EscXElemIns; +import com.jpexs.decompiler.flash.abc.avm2.model.ApplyTypeAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.BooleanAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.ConstructAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.FullMultinameAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.HasNextAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.InitPropertyAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.InitVectorAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.LocalRegAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.NewFunctionAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.ReturnValueAVM2Item; @@ -202,6 +206,8 @@ import com.jpexs.decompiler.flash.abc.avm2.model.WithAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.clauses.DeclarationAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.parser.ParseException; import com.jpexs.decompiler.flash.abc.avm2.parser.pcode.ASM3Parser; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.AVM2SourceGenerator; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.PropertyAVM2Item; import com.jpexs.decompiler.flash.abc.types.ABCException; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.MethodInfo; @@ -223,6 +229,7 @@ import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.NotCompileTimeItem; import com.jpexs.decompiler.graph.TranslateException; +import com.jpexs.decompiler.graph.TypeItem; import com.jpexs.decompiler.graph.model.LocalData; import com.jpexs.decompiler.graph.model.ScriptEndItem; import com.jpexs.helpers.Helper; @@ -1376,7 +1383,7 @@ public class AVM2Code implements Serializable { //addr = pos2adr(ip); insAfter = code.get(ip + 1); } - + boolean isAnd; if (processJumps && (insAfter.definition instanceof IfFalseIns)) { //stack.add("(" + stack.pop() + ")&&"); @@ -1525,8 +1532,8 @@ public class AVM2Code implements Serializable { return maxRegister + 1; } - public HashMap getLocalRegTypes(ConstantPool constants, List fullyQualifiedNames) { - HashMap ret = new HashMap<>(); + public HashMap getLocalRegTypes(ConstantPool constants, List fullyQualifiedNames) { + HashMap ret = new HashMap<>(); AVM2Instruction prev = null; for (AVM2Instruction ins : code) { if (ins.definition instanceof SetLocalTypeIns) { @@ -1653,11 +1660,11 @@ public class AVM2Code implements Serializable { SetSlotAVM2Item ssti = (SetSlotAVM2Item) ti; Slot sl = new Slot(ssti.scope, ssti.slotName); if (!declaredSlots.contains(sl)) { - String type = "*"; + GraphTargetItem type = TypeItem.UNBOUNDED; for (int t = 0; t < body.traits.traits.size(); t++) { if (body.traits.traits.get(t).getName(abc) == sl.multiname) { if (body.traits.traits.get(t) instanceof TraitSlotConst) { - type = ((TraitSlotConst) body.traits.traits.get(t)).getType(constants, fullyQualifiedNames); + type = PropertyAVM2Item.multinameToType(((TraitSlotConst) body.traits.traits.get(t)).type_index,abc.constants); } } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetPropertyIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetPropertyIns.java index b2b333f6b..c54b34e49 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetPropertyIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetPropertyIns.java @@ -23,10 +23,13 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; import com.jpexs.decompiler.flash.abc.avm2.instructions.SetTypeIns; import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.ApplyTypeAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.ConstructAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.DecrementAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.FullMultinameAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.GetPropertyAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.IncrementAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.InitVectorAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.LocalRegAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.PostDecrementAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.PostIncrementAVM2Item; @@ -36,6 +39,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.operations.PreIncrementAVM2Item import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.graph.GraphTargetItem; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Stack; @@ -115,7 +119,28 @@ public class SetPropertyIns extends InstructionDefinition implements SetTypeIns } } } + + if(obj.getThroughDuplicate() instanceof ConstructAVM2Item){ + ConstructAVM2Item c = (ConstructAVM2Item)obj.getThroughDuplicate(); + if(c.object instanceof ApplyTypeAVM2Item){ + ApplyTypeAVM2Item at = (ApplyTypeAVM2Item)c.object; + c.args.clear(); + List vals=new ArrayList<>(); + vals.add(value); + c.object = new InitVectorAVM2Item(c.instruction,at.params.get(0),vals); + return; + } + else + if(c.object instanceof InitVectorAVM2Item){ + InitVectorAVM2Item iv = (InitVectorAVM2Item)c.object; + iv.arguments.add(value); + return; + } + } + output.add(new SetPropertyAVM2Item(ins, obj, multiname, value)); + + } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/CoerceAIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/CoerceAIns.java index daec32e3a..ce3e3a6fb 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/CoerceAIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/CoerceAIns.java @@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.CoerceAVM2Item; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.decompiler.graph.TypeItem; import java.util.HashMap; import java.util.List; import java.util.Stack; @@ -57,7 +58,7 @@ public class CoerceAIns extends InstructionDefinition implements CoerceOrConvert } @Override - public String getTargetType(ConstantPool constants, AVM2Instruction ins, List fullyQualifiedNames) { - return "*"; + public GraphTargetItem getTargetType(ConstantPool constants, AVM2Instruction ins, List fullyQualifiedNames) { + return TypeItem.UNBOUNDED; } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/CoerceIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/CoerceIns.java index d70ac462a..70541b7d3 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/CoerceIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/CoerceIns.java @@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; import com.jpexs.decompiler.flash.abc.avm2.model.CoerceAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.PropertyAVM2Item; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.graph.GraphTargetItem; @@ -45,13 +46,13 @@ public class CoerceIns extends InstructionDefinition implements CoerceOrConvertT @Override public void translate(boolean isStatic, int scriptIndex, int classIndex, java.util.HashMap localRegs, Stack stack, java.util.Stack scopeStack, ConstantPool constants, AVM2Instruction ins, List method_info, List output, MethodBody body, ABC abc, HashMap localRegNames, List fullyQualifiedNames, String path, HashMap localRegsAssignmentIps, int ip, HashMap> refs, AVM2Code code) { int multinameIndex = ins.operands[0]; - stack.push(new CoerceAVM2Item(ins, (GraphTargetItem) stack.pop(), constants.getMultiname(multinameIndex).getName(constants, fullyQualifiedNames))); + stack.push(new CoerceAVM2Item(ins, (GraphTargetItem) stack.pop(),PropertyAVM2Item.multinameToType(multinameIndex,constants))); } @Override - public String getTargetType(ConstantPool constants, AVM2Instruction ins, List fullyQualifiedNames) { + public GraphTargetItem getTargetType(ConstantPool constants, AVM2Instruction ins, List fullyQualifiedNames) { int multinameIndex = ins.operands[0]; - return constants.getMultiname(multinameIndex).getName(constants, fullyQualifiedNames); + return PropertyAVM2Item.multinameToType(multinameIndex, constants); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/CoerceOrConvertTypeIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/CoerceOrConvertTypeIns.java index e77f2f0dc..61d155e82 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/CoerceOrConvertTypeIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/CoerceOrConvertTypeIns.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.abc.avm2.instructions.types; import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.graph.GraphTargetItem; import java.util.List; /** @@ -26,5 +27,5 @@ import java.util.List; */ public interface CoerceOrConvertTypeIns { - public String getTargetType(ConstantPool constants, AVM2Instruction ins, List fullyQualifiedNames); + public GraphTargetItem getTargetType(ConstantPool constants, AVM2Instruction ins, List fullyQualifiedNames); } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/CoerceSIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/CoerceSIns.java index bcc1057c6..f2a269559 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/CoerceSIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/CoerceSIns.java @@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.CoerceAVM2Item; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.decompiler.graph.TypeItem; import java.util.HashMap; import java.util.List; import java.util.Stack; @@ -53,7 +54,7 @@ public class CoerceSIns extends InstructionDefinition implements CoerceOrConvert } @Override - public String getTargetType(ConstantPool constants, AVM2Instruction ins, List fullyQualifiedNames) { - return "String"; + public GraphTargetItem getTargetType(ConstantPool constants, AVM2Instruction ins, List fullyQualifiedNames) { + return new TypeItem("String"); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertBIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertBIns.java index 0df3194c9..521a60500 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertBIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertBIns.java @@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.ConvertAVM2Item; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.decompiler.graph.TypeItem; import java.util.HashMap; import java.util.List; import java.util.Stack; @@ -63,7 +64,7 @@ public class ConvertBIns extends InstructionDefinition implements CoerceOrConver } @Override - public String getTargetType(ConstantPool constants, AVM2Instruction ins, List fullyQualifiedNames) { - return "Boolean"; + public GraphTargetItem getTargetType(ConstantPool constants, AVM2Instruction ins, List fullyQualifiedNames) { + return new TypeItem("Boolean"); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertDIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertDIns.java index 714fd8b24..f70fd7161 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertDIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertDIns.java @@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.ConvertAVM2Item; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.decompiler.graph.TypeItem; import java.util.HashMap; import java.util.List; import java.util.Stack; @@ -71,7 +72,7 @@ public class ConvertDIns extends InstructionDefinition implements CoerceOrConver } @Override - public String getTargetType(ConstantPool constants, AVM2Instruction ins, List fullyQualifiedNames) { - return "Number"; + public GraphTargetItem getTargetType(ConstantPool constants, AVM2Instruction ins, List fullyQualifiedNames) { + return new TypeItem("Number"); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertIIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertIIns.java index bba2c7d33..5b57f436b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertIIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertIIns.java @@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.ConvertAVM2Item; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.decompiler.graph.TypeItem; import java.util.HashMap; import java.util.List; import java.util.Stack; @@ -69,7 +70,7 @@ public class ConvertIIns extends InstructionDefinition implements CoerceOrConver } @Override - public String getTargetType(ConstantPool constants, AVM2Instruction ins, List fullyQualifiedNames) { - return "int"; + public GraphTargetItem getTargetType(ConstantPool constants, AVM2Instruction ins, List fullyQualifiedNames) { + return new TypeItem("int"); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertOIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertOIns.java index 74e630bea..57ac1973e 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertOIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertOIns.java @@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.ConvertAVM2Item; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.decompiler.graph.TypeItem; import java.util.HashMap; import java.util.List; import java.util.Stack; @@ -52,7 +53,7 @@ public class ConvertOIns extends InstructionDefinition implements CoerceOrConver } @Override - public String getTargetType(ConstantPool constants, AVM2Instruction ins, List fullyQualifiedNames) { - return "Object"; + public GraphTargetItem getTargetType(ConstantPool constants, AVM2Instruction ins, List fullyQualifiedNames) { + return new TypeItem("Object"); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertSIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertSIns.java index 92a2c7806..760a41acd 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertSIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertSIns.java @@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.ConvertAVM2Item; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.decompiler.graph.TypeItem; import java.util.HashMap; import java.util.List; import java.util.Stack; @@ -53,7 +54,7 @@ public class ConvertSIns extends InstructionDefinition implements CoerceOrConver } @Override - public String getTargetType(ConstantPool constants, AVM2Instruction ins, List fullyQualifiedNames) { - return "String"; + public GraphTargetItem getTargetType(ConstantPool constants, AVM2Instruction ins, List fullyQualifiedNames) { + return new TypeItem("String"); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertUIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertUIns.java index 67efcbda1..5e37c6b7c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertUIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/types/ConvertUIns.java @@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.ConvertAVM2Item; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.decompiler.graph.TypeItem; import java.util.HashMap; import java.util.List; import java.util.Stack; @@ -52,7 +53,7 @@ public class ConvertUIns extends InstructionDefinition implements CoerceOrConver } @Override - public String getTargetType(ConstantPool constants, AVM2Instruction ins, List fullyQualifiedNames) { - return "uint"; + public GraphTargetItem getTargetType(ConstantPool constants, AVM2Instruction ins, List fullyQualifiedNames) { + return new TypeItem("uint"); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/ApplyTypeAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/ApplyTypeAVM2Item.java index e5ecbcc50..3c8a49336 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/ApplyTypeAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/ApplyTypeAVM2Item.java @@ -16,11 +16,22 @@ */ package com.jpexs.decompiler.flash.abc.avm2.model; +import com.jpexs.decompiler.flash.SourceGeneratorLocalData; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.abc.avm2.instructions.construction.ConstructPropIns; +import com.jpexs.decompiler.flash.abc.avm2.instructions.other.FindPropertyStrictIns; +import com.jpexs.decompiler.flash.abc.avm2.instructions.other.GetLexIns; +import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ApplyTypeIns; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.AVM2SourceGenerator; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; +import com.jpexs.decompiler.graph.CompilationException; +import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; +import static com.jpexs.decompiler.graph.GraphTargetItem.toSourceMerge; +import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.TypeItem; import com.jpexs.decompiler.graph.model.LocalData; +import java.util.ArrayList; import java.util.List; public class ApplyTypeAVM2Item extends AVM2Item { @@ -63,5 +74,21 @@ public class ApplyTypeAVM2Item extends AVM2Item { @Override public boolean hasReturnValue() { return true; + } + + @Override + public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { + //int qname = AVM2SourceGenerator.resolveType(localData,object,((AVM2SourceGenerator)generator).abc,((AVM2SourceGenerator)generator).allABCs); + List nparams=new ArrayList<>(); + for(GraphTargetItem i:params){ + nparams.addAll(i.toSource(localData, generator));//ins(new GetLexIns(),AVM2SourceGenerator.resolveType(localData,i,((AVM2SourceGenerator)generator).abc,((AVM2SourceGenerator)generator).allABCs))); + } + return toSourceMerge(localData, generator, + object, + nparams, + ins(new ApplyTypeIns(),params.size()) + ); } + + } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/CoerceAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/CoerceAVM2Item.java index 55cbfd25f..7f3531778 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/CoerceAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/CoerceAVM2Item.java @@ -41,14 +41,14 @@ import java.util.Set; public class CoerceAVM2Item extends AVM2Item { //public GraphTargetItem value; - public String type; + //public GraphTargetItem type; public GraphTargetItem typeObj; - public CoerceAVM2Item(AVM2Instruction instruction, GraphTargetItem value, String type) { + /*public CoerceAVM2Item(AVM2Instruction instruction, GraphTargetItem value, String type) { super(instruction, value.getPrecedence()); this.value = value; this.type = type; - } + }*/ public CoerceAVM2Item(AVM2Instruction instruction, GraphTargetItem value, GraphTargetItem typeObj) { super(instruction, value.getPrecedence()); @@ -79,7 +79,7 @@ public class CoerceAVM2Item extends AVM2Item { @Override public Object getResult() { Object ret = value.getResult(); - switch (type) { + switch (typeObj.toString()) { case "String": if (ret instanceof Null) { return ret; @@ -97,7 +97,7 @@ public class CoerceAVM2Item extends AVM2Item { @Override public GraphTargetItem returnType() { - return new TypeItem(type); + return new TypeItem(typeObj.toString()); } @Override @@ -112,7 +112,7 @@ public class CoerceAVM2Item extends AVM2Item { return toSourceMerge(localData, generator, value); }*/ AVM2Instruction ins; - switch (type) { + switch (typeObj.toString()) { case "*": ins = new AVM2Instruction(0, new CoerceAIns(), new int[]{}, new byte[0]); break; @@ -132,7 +132,7 @@ public class CoerceAVM2Item extends AVM2Item { ins = new AVM2Instruction(0, new ConvertDIns(), new int[]{}, new byte[0]); break; default: - int type_index = AVM2SourceGenerator.resolveType(new TypeItem(type), (((AVM2SourceGenerator) generator).abc)); + int type_index = AVM2SourceGenerator.resolveType(localData, typeObj, ((AVM2SourceGenerator) generator).abc,(((AVM2SourceGenerator) generator).allABCs)); ins = new AVM2Instruction(0, new CoerceIns(), new int[]{type_index}, new byte[0]); break; } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/ConstructAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/ConstructAVM2Item.java index d0366366d..8c93fbd4f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/ConstructAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/ConstructAVM2Item.java @@ -42,6 +42,9 @@ public class ConstructAVM2Item extends AVM2Item { writer.append("new "); object.toString(writer, localData); writer.spaceBeforeCallParenthesies(args.size()); + if(object instanceof InitVectorAVM2Item){ + return writer; + } writer.append("("); for (int a = 0; a < args.size(); a++) { if (a > 0) { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/ConvertAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/ConvertAVM2Item.java index f6a162464..84cf60db9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/ConvertAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/ConvertAVM2Item.java @@ -27,9 +27,9 @@ import java.util.Set; public class ConvertAVM2Item extends AVM2Item { //public GraphTargetItem value; - public String type; + public GraphTargetItem type; - public ConvertAVM2Item(AVM2Instruction instruction, GraphTargetItem value, String type) { + public ConvertAVM2Item(AVM2Instruction instruction, GraphTargetItem value, GraphTargetItem type) { super(instruction, NOPRECEDENCE); this.value = value; this.type = type; @@ -47,7 +47,7 @@ public class ConvertAVM2Item extends AVM2Item { @Override public Object getResult() { - switch (type) { + switch (type.toString()) { case "Boolean": return EcmaScript.toBoolean(value.getResult()); case "Number": @@ -76,7 +76,7 @@ public class ConvertAVM2Item extends AVM2Item { @Override public GraphTargetItem returnType() { - return new TypeItem(type); + return type; } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/InitVectorAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/InitVectorAVM2Item.java new file mode 100644 index 000000000..e8e3c2f1d --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/InitVectorAVM2Item.java @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2014 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.decompiler.flash.abc.avm2.model; + +import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.abc.avm2.instructions.construction.ConstructIns; +import com.jpexs.decompiler.flash.abc.avm2.instructions.other.FindPropertyStrictIns; +import com.jpexs.decompiler.flash.abc.avm2.instructions.other.GetPropertyIns; +import com.jpexs.decompiler.flash.abc.avm2.instructions.other.SetPropertyIns; +import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.DupIns; +import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ApplyTypeIns; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.AVM2SourceGenerator; +import com.jpexs.decompiler.flash.abc.types.Multiname; +import com.jpexs.decompiler.flash.abc.types.Namespace; +import com.jpexs.decompiler.flash.abc.types.NamespaceSet; +import com.jpexs.decompiler.flash.helpers.GraphTextWriter; +import com.jpexs.decompiler.graph.CompilationException; +import com.jpexs.decompiler.graph.GraphSourceItem; +import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.decompiler.graph.SourceGenerator; +import com.jpexs.decompiler.graph.TypeItem; +import com.jpexs.decompiler.graph.model.LocalData; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author JPEXS + */ +public class InitVectorAVM2Item extends AVM2Item{ + + public GraphTargetItem subtype; + public List arguments; + List openedNamespaces; + + private int allNsSet(ABC abc) { + int nssa[] = new int[openedNamespaces.size()]; + for (int i = 0; i < openedNamespaces.size(); i++) { + nssa[i] = openedNamespaces.get(i); + } + return abc.constants.getNamespaceSetId(new NamespaceSet(nssa), true); + } + + public InitVectorAVM2Item(AVM2Instruction ins, GraphTargetItem subtype,List arguments){ + super(ins,PRECEDENCE_PRIMARY); + this.subtype = subtype; + this.arguments = arguments; + } + + public InitVectorAVM2Item(GraphTargetItem subtype,List arguments, List openedNamespaces) { + super(null, PRECEDENCE_PRIMARY); + this.subtype = subtype; + this.arguments = arguments; + this.openedNamespaces = openedNamespaces; + } + + @Override + public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { + writer.append("<"); + subtype.appendTo(writer, localData); + writer.append(">"); + writer.append("["); + for(int i=0;i0){ + writer.append(","); + } + arguments.get(i).appendTo(writer, localData); + } + writer.append("]"); + return writer; + } + + @Override + public boolean hasReturnValue() { + return true; + } + + @Override + public GraphTargetItem returnType() { + List pars=new ArrayList<>(); + pars.add(subtype); + return new ApplyTypeAVM2Item(null,new TypeItem("__AS3__.vec.Vector"), pars); + } + + @Override + public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { + AVM2SourceGenerator g=(AVM2SourceGenerator)generator; + List ret= toSourceMerge(localData, generator, + ins(new FindPropertyStrictIns(),g.abc.constants.getMultinameId(new Multiname(Multiname.MULTINAME, g.abc.constants.getStringId("Vector", true), 0, g.abc.constants.getNamespaceSetId(new NamespaceSet(new int[]{g.abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, g.abc.constants.getStringId("__AS3__.vec", true)), 0,true)}), true), 0, new ArrayList()), true)), + ins(new GetPropertyIns(),g.abc.constants.getMultinameId(new Multiname(Multiname.MULTINAME, g.abc.constants.getStringId("Vector", true), 0, allNsSet(g.abc), 0, new ArrayList()), true)), + subtype, + ins(new ApplyTypeIns(),1), + new IntegerValueAVM2Item(null, (long)arguments.size()), + ins(new ConstructIns(),1) + ); + for(int i=0;i(), true,false); + } + if(p instanceof NamespacedAVM2Item){ + NamespacedAVM2Item n=(NamespacedAVM2Item)p; + return n.toSource(localData, generator, true, false, new ArrayList(), true,false); + } + + throw new CompilationException("Not a property", line); //TODO: handle line better way } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java index 3d14a9650..bac91ec84 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java @@ -67,6 +67,7 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.types.CoerceAIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertBIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.xml.CheckFilterIns; import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.ApplyTypeAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.BooleanAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.FloatValueAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.GetDescendantsAVM2Item; @@ -300,7 +301,7 @@ public class AVM2SourceGenerator implements SourceGenerator { AssignableAVM2Item.setTemp(localData, this, counterReg), item.object, ins(new CheckFilterIns()), - NameAVM2Item.generateCoerce(this, TypeItem.UNBOUNDED), + NameAVM2Item.generateCoerce(localData,this, TypeItem.UNBOUNDED), AssignableAVM2Item.setTemp(localData, this, collectionReg), ins(new GetLexIns(), abc.constants.getMultinameId(new Multiname(Multiname.QNAME, abc.constants.getStringId("XMLList", true), abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId("", true)), 0, true), 0, 0, new ArrayList()), true)), ins(new PushStringIns(), abc.constants.getStringId("", true)), @@ -446,7 +447,7 @@ public class AVM2SourceGenerator implements SourceGenerator { ins(new PushByteIns(), 0), AssignableAVM2Item.setTemp(localData, this, counterReg), collection, - NameAVM2Item.generateCoerce(this, TypeItem.UNBOUNDED), + NameAVM2Item.generateCoerce(localData,this, TypeItem.UNBOUNDED), AssignableAVM2Item.setTemp(localData, this, collectionReg) )); @@ -1247,7 +1248,7 @@ public class AVM2SourceGenerator implements SourceGenerator { } instanceInfo.interfaces = new int[implementsStr.size()]; for (int i = 0; i < implementsStr.size(); i++) { - instanceInfo.interfaces[i] = superIntName(implementsStr.get(i)); + instanceInfo.interfaces[i] = superIntName(localData,implementsStr.get(i)); } } @@ -1275,7 +1276,7 @@ public class AVM2SourceGenerator implements SourceGenerator { */ if (cls instanceof ClassAVM2Item) { ClassAVM2Item cai = (ClassAVM2Item) cls; - generateClass(cai.sinitVariables, cai.staticInitActivation, cai.staticInit, cai.openedNamespaces, namespace, initScope, pkg, ci, ii, localData, false, cai.className, cai.extendsOp.toString(), cai.extendsOp, cai.implementsOp, cai.constructor, cai.traits); + generateClass(cai.sinitVariables, cai.staticInitActivation, cai.staticInit, cai.openedNamespaces, namespace, initScope, pkg, ci, ii, localData, false, cai.className, cai.extendsOp == null ? "Object" : cai.extendsOp.toString(), cai.extendsOp, cai.implementsOp, cai.constructor, cai.traits); if (!cai.isDynamic) { ii.flags |= InstanceInfo.CLASS_SEALED; } @@ -1304,17 +1305,9 @@ public class AVM2SourceGenerator implements SourceGenerator { return 0; } - if (type instanceof UnresolvedAVM2Item) { - String fullClass = localData.currentClass == null ? null : (localData.pkg.isEmpty() ? localData.currentClass : localData.pkg + "." + localData.currentClass); - type = ((UnresolvedAVM2Item) type).resolve(new TypeItem(fullClass), new ArrayList(), new ArrayList(), abc, allABCs, new ArrayList(), new ArrayList()); - } - - String pkg = ""; - String name = type.toString(); - if ("*".equals(name)) { - return 0; - } - + + return resolveType(localData,type, abc,allABCs); + /* TypeItem nameItem = (TypeItem) type; name = nameItem.fullTypeName; if (name.contains(".")) { @@ -1323,19 +1316,14 @@ public class AVM2SourceGenerator implements SourceGenerator { } if (!nameItem.subtypes.isEmpty()) { //It's vector => TypeName List params = new ArrayList<>(); - for (String p : nameItem.subtypes) { - String ppkg = ""; - if (p.contains(".")) { - ppkg = p.substring(0, p.lastIndexOf('.')); - p = p.substring(p.lastIndexOf('.') + 1); - } - params.add(abc.constants.getMultinameId(new Multiname(Multiname.QNAME, str(p), namespace(Namespace.KIND_PACKAGE/*?*/, ppkg), 0, 0, new ArrayList()), true)); + for (GraphTargetItem p : nameItem.subtypes) { + params.add(typeName(localData, p));//abc.constants.getMultinameId(new Multiname(Multiname.QNAME, str(p), namespace(Namespace.KIND_PACKAGE, ppkg), 0, 0, new ArrayList()), true)); } - int qname = abc.constants.getMultinameId(new Multiname(Multiname.QNAME, str(name), namespace(Namespace.KIND_PACKAGE/*?*/, pkg), 0, 0, new ArrayList()), true); + int qname = abc.constants.getMultinameId(new Multiname(Multiname.QNAME, str(name), namespace(Namespace.KIND_PACKAGE, pkg), 0, 0, new ArrayList()), true); return abc.constants.getMultinameId(new Multiname(Multiname.TYPENAME, 0, 0, 0, qname, params), true); } else { - return abc.constants.getMultinameId(new Multiname(Multiname.QNAME, str(name), namespace(Namespace.KIND_PACKAGE/*?*/, pkg), 0, 0, new ArrayList()), true); - } + return abc.constants.getMultinameId(new Multiname(Multiname.QNAME, str(name), namespace(Namespace.KIND_PACKAGE, pkg), 0, 0, new ArrayList()), true); + }*/ } public int ident(GraphTargetItem name) { @@ -1431,8 +1419,8 @@ public class AVM2SourceGenerator implements SourceGenerator { registerNames.add("this"); } else { - registerTypes.add("*"); - registerNames.add("--nothis"); + registerTypes.add("global"); + registerNames.add("this"); } for (GraphTargetItem t : paramTypes) { registerTypes.add(t.toString()); @@ -1440,6 +1428,12 @@ public class AVM2SourceGenerator implements SourceGenerator { } registerNames.addAll(paramNames); slotNames.addAll(paramNames); + for (GraphTargetItem p : paramTypes) { + slotTypes.add("" + p); + } + if (hasRest) { + slotTypes.add("*"); + } localData.registerVars.clear(); for (AssignableAVM2Item an : subvariables) { if (an instanceof NameAVM2Item) { @@ -1657,16 +1651,16 @@ public class AVM2SourceGenerator implements SourceGenerator { abcs.add(abc); abcs.addAll(allABCs); - int parentConstMinAC = 0; + int parentConstMinAC = 0; for (ABC a : abcs) { int ci = a.findClassByName(superType); if (ci > -1) { MethodInfo pmi = a.method_info.get(a.instance_info.get(ci).iinit_index); parentConstMinAC = pmi.param_types.length; - if(pmi.flagHas_optional()){ + if (pmi.flagHas_optional()) { parentConstMinAC -= pmi.optional.length; - } + } } } @@ -1791,17 +1785,17 @@ public class AVM2SourceGenerator implements SourceGenerator { return null; } - private int genNs(String pkg,String custom, int namespace, List openedNamespaces, SourceGeneratorLocalData localData,int line) throws CompilationException { + private int genNs(String pkg, String custom, int namespace, List openedNamespaces, SourceGeneratorLocalData localData, int line) throws CompilationException { if (custom != null) { PropertyAVM2Item prop = new PropertyAVM2Item(null, custom, abc, allABCs, openedNamespaces, new ArrayList()); Reference value = new Reference<>(null); - prop.resolve(localData, new Reference(""), new Reference(""), new Reference(0), value); + prop.resolve(localData, new Reference(null), new Reference(null), new Reference(0), value); boolean resolved = true; - if(value.getVal() == null){ + if (value.getVal() == null) { resolved = false; - + } - if(!resolved){ + if (!resolved) { throw new CompilationException("Namespace not defined", line); } namespace = value.getVal().value_index; @@ -1819,13 +1813,13 @@ public class AVM2SourceGenerator implements SourceGenerator { } else if (item instanceof ClassAVM2Item) { traits[k].name_index = traitName(((ClassAVM2Item) item).namespace, ((ClassAVM2Item) item).className); } else if ((item instanceof MethodAVM2Item) || (item instanceof GetterAVM2Item) || (item instanceof SetterAVM2Item)) { - traits[k].name_index = traitName(genNs(pkg,((MethodAVM2Item) item).customNamespace, ((MethodAVM2Item) item).namespace, openedNamespaces, localData,((MethodAVM2Item)item).line), ((MethodAVM2Item) item).functionName); + traits[k].name_index = traitName(genNs(pkg, ((MethodAVM2Item) item).customNamespace, ((MethodAVM2Item) item).namespace, openedNamespaces, localData, ((MethodAVM2Item) item).line), ((MethodAVM2Item) item).functionName); } else if (item instanceof FunctionAVM2Item) { traits[k].name_index = traitName(((FunctionAVM2Item) item).namespace, ((FunctionAVM2Item) item).functionName); } else if (item instanceof ConstAVM2Item) { - traits[k].name_index = traitName(genNs(pkg,((ConstAVM2Item) item).customNamespace, ((ConstAVM2Item) item).getNamespace(), openedNamespaces, localData,((ConstAVM2Item)item).line), ((ConstAVM2Item) item).var); + traits[k].name_index = traitName(genNs(pkg, ((ConstAVM2Item) item).customNamespace, ((ConstAVM2Item) item).getNamespace(), openedNamespaces, localData, ((ConstAVM2Item) item).line), ((ConstAVM2Item) item).var); } else if (item instanceof SlotAVM2Item) { - traits[k].name_index = traitName(genNs(pkg,((SlotAVM2Item) item).customNamespace, ((SlotAVM2Item) item).getNamespace(), openedNamespaces, localData,((SlotAVM2Item)item).line), ((SlotAVM2Item) item).var); + traits[k].name_index = traitName(genNs(pkg, ((SlotAVM2Item) item).customNamespace, ((SlotAVM2Item) item).getNamespace(), openedNamespaces, localData, ((SlotAVM2Item) item).line), ((SlotAVM2Item) item).var); } } @@ -1846,7 +1840,7 @@ public class AVM2SourceGenerator implements SourceGenerator { } instanceInfo.interfaces = new int[((ClassAVM2Item) item).implementsOp.size()]; for (int i = 0; i < ((ClassAVM2Item) item).implementsOp.size(); i++) { - instanceInfo.interfaces[i] = superIntName(((ClassAVM2Item) item).implementsOp.get(i)); + instanceInfo.interfaces[i] = superIntName(localData,((ClassAVM2Item) item).implementsOp.get(i)); } } if (item instanceof InterfaceAVM2Item) { @@ -1857,22 +1851,22 @@ public class AVM2SourceGenerator implements SourceGenerator { instanceInfo.interfaces = new int[((InterfaceAVM2Item) item).superInterfaces.size()]; for (int i = 0; i < ((InterfaceAVM2Item) item).superInterfaces.size(); i++) { GraphTargetItem un = ((InterfaceAVM2Item) item).superInterfaces.get(i); - instanceInfo.interfaces[i] = superIntName(un); + instanceInfo.interfaces[i] = superIntName(localData,un); } } } } - public int superIntName(GraphTargetItem un) throws CompilationException { + public int superIntName(SourceGeneratorLocalData localData,GraphTargetItem un) throws CompilationException { if (un instanceof UnresolvedAVM2Item) { ((UnresolvedAVM2Item) un).resolve(null, new ArrayList(), new ArrayList(), abc, allABCs, new ArrayList(), new ArrayList()); un = ((UnresolvedAVM2Item) un).resolved; } - if (!(un instanceof TypeItem)) { + if (!(un instanceof TypeItem)) { //not applyType throw new CompilationException("Invalid type", 0); } TypeItem sup = (TypeItem) un; - int propId = resolveType(sup, abc); + int propId = resolveType(localData,sup, abc,allABCs); int nss[] = new int[]{abc.constants.constant_multiname.get(propId).namespace_index}; return abc.constants.getMultinameId(new Multiname(Multiname.MULTINAME, abc.constants.constant_multiname.get(propId).name_index, 0, abc.constants.getNamespaceSetId(new NamespaceSet(nss), true), 0, new ArrayList()), true); @@ -2113,15 +2107,15 @@ public class AVM2SourceGenerator implements SourceGenerator { if (tsc.type_index == 0) { return TypeItem.UNBOUNDED; } - return new TypeItem(abc.constants.constant_multiname.get(tsc.type_index).getNameWithNamespace(abc.constants)); + return PropertyAVM2Item.multinameToType(tsc.type_index,abc.constants); } if (t instanceof TraitMethodGetterSetter) { TraitMethodGetterSetter tmgs = (TraitMethodGetterSetter) t; if (tmgs.kindType == Trait.TRAIT_GETTER) { - return new TypeItem(abc.constants.constant_multiname.get(abc.method_info.get(tmgs.method_info).ret_type).getNameWithNamespace(abc.constants)); + return PropertyAVM2Item.multinameToType(abc.method_info.get(tmgs.method_info).ret_type,abc.constants); } if (tmgs.kindType == Trait.TRAIT_SETTER) { - return new TypeItem(abc.constants.constant_multiname.get(abc.method_info.get(tmgs.method_info).param_types[0]).getNameWithNamespace(abc.constants)); + return PropertyAVM2Item.multinameToType(abc.method_info.get(tmgs.method_info).param_types[0],abc.constants); } } if (t instanceof TraitFunction) { @@ -2130,7 +2124,7 @@ public class AVM2SourceGenerator implements SourceGenerator { return TypeItem.UNBOUNDED; } - public static boolean searchPrototypeChain(boolean instanceOnly, List abcs, String pkg, String obj, String propertyName, Reference outName, Reference outNs, Reference outPropNs, Reference outPropNsKind, Reference outPropType, Reference outPropValue) { + public static boolean searchPrototypeChain(boolean instanceOnly, List abcs, String pkg, String obj, String propertyName, Reference outName, Reference outNs, Reference outPropNs, Reference outPropNsKind, Reference outPropType, Reference outPropValue) { for (ABC abc : abcs) { if (!instanceOnly) { @@ -2142,7 +2136,7 @@ public class AVM2SourceGenerator implements SourceGenerator { outNs.setVal(pkg); outPropNs.setVal(t.getName(abc).getNamespace(abc.constants).getName(abc.constants)); outPropNsKind.setVal(t.getName(abc).getNamespace(abc.constants).kind); - outPropType.setVal(getTraitReturnType(abc, t).toString()); + outPropType.setVal(getTraitReturnType(abc, t)); if (t instanceof TraitSlotConst) { TraitSlotConst tsc = (TraitSlotConst) t; outPropValue.setVal(new ValueKind(tsc.value_index, tsc.value_kind)); @@ -2160,8 +2154,8 @@ public class AVM2SourceGenerator implements SourceGenerator { if (pkg.equals(clsName.getNamespace(abc.constants).getName(abc.constants))) { //class found - for (Trait t : ii.instance_traits.traits) { - if(t.getName(abc) == null){ //in traits phase 2 + for (Trait t : ii.instance_traits.traits) { + if (t.getName(abc) == null) { //in traits phase 2 continue; } if (propertyName.equals(t.getName(abc).getName(abc.constants, new ArrayList()))) { @@ -2169,7 +2163,7 @@ public class AVM2SourceGenerator implements SourceGenerator { outNs.setVal(pkg); outPropNs.setVal(t.getName(abc).getNamespace(abc.constants).getName(abc.constants)); outPropNsKind.setVal(t.getName(abc).getNamespace(abc.constants).kind); - outPropType.setVal(getTraitReturnType(abc, t).toString()); + outPropType.setVal(getTraitReturnType(abc, t)); if (t instanceof TraitSlotConst) { TraitSlotConst tsc = (TraitSlotConst) t; outPropValue.setVal(new ValueKind(tsc.value_index, tsc.value_kind)); @@ -2180,7 +2174,7 @@ public class AVM2SourceGenerator implements SourceGenerator { if (!instanceOnly) { for (Trait t : abc.class_info.get(i).static_traits.traits) { - if(t.getName(abc) == null){ //in traits phase 2 + if (t.getName(abc) == null) { //in traits phase 2 continue; } if (propertyName.equals(t.getName(abc).getName(abc.constants, new ArrayList()))) { @@ -2188,7 +2182,7 @@ public class AVM2SourceGenerator implements SourceGenerator { outNs.setVal(pkg); outPropNs.setVal(t.getName(abc).getNamespace(abc.constants).getName(abc.constants)); outPropNsKind.setVal(t.getName(abc).getNamespace(abc.constants).kind); - outPropType.setVal(getTraitReturnType(abc, t).toString()); + outPropType.setVal(getTraitReturnType(abc, t)); if (t instanceof TraitSlotConst) { TraitSlotConst tsc = (TraitSlotConst) t; outPropValue.setVal(new ValueKind(tsc.value_index, tsc.value_kind)); @@ -2247,7 +2241,7 @@ public class AVM2SourceGenerator implements SourceGenerator { /* public void calcRegisters(Reference activationReg, SourceGeneratorLocalData localData, boolean needsActivation, List funParamNames,List funSubVariables,List funBody, Reference hasArguments) throws ParseException { }*/ - public int resolveType(String objType) { + /*public int resolveType(String objType) { if (objType.equals("*")) { return 0; } @@ -2264,7 +2258,7 @@ public class AVM2SourceGenerator implements SourceGenerator { } } return 0; - } + }*/ @Override public List generate(SourceGeneratorLocalData localData, TypeItem item) throws CompilationException { @@ -2284,14 +2278,39 @@ public class AVM2SourceGenerator implements SourceGenerator { } return GraphTargetItem.toSourceMerge(localData, this, ins(new GetGlobalScopeIns()), ins(new GetSlotIns(), slotId)); } else { - return GraphTargetItem.toSourceMerge(localData, this, ins(new GetLexIns(), resolveType(item, abc))); + return GraphTargetItem.toSourceMerge(localData, this, ins(new GetLexIns(), resolveType(localData,item, abc,allABCs))); } } - public static int resolveType(TypeItem type, ABC abc) { + public static int resolveType(SourceGeneratorLocalData localData,GraphTargetItem item, ABC abc,List allABCs) throws CompilationException { + int name_index = 0; + GraphTargetItem typeItem = null; + + + if (item instanceof UnresolvedAVM2Item) { + String fullClass = localData.currentClass == null ? null : (localData.pkg.isEmpty() ? localData.currentClass : localData.pkg + "." + localData.currentClass); + item = ((UnresolvedAVM2Item) item).resolve(new TypeItem(fullClass), new ArrayList(), new ArrayList(), abc, allABCs, new ArrayList(), new ArrayList()); + } + if (item instanceof TypeItem) { + typeItem = item; + } else if (item instanceof ApplyTypeAVM2Item) { + typeItem = ((ApplyTypeAVM2Item) item).object; + } else { + throw new CompilationException("Invalid type:"+item.getClass().getName(), 0/*??*/); + } + if (typeItem instanceof UnresolvedAVM2Item) { + String fullClass = localData.currentClass == null ? null : (localData.pkg.isEmpty() ? localData.currentClass : localData.pkg + "." + localData.currentClass); + typeItem = ((UnresolvedAVM2Item) typeItem).resolve(new TypeItem(fullClass), new ArrayList(), new ArrayList(), abc, allABCs, new ArrayList(), new ArrayList()); + } + + if (!(typeItem instanceof TypeItem)) { + throw new CompilationException("Invalid type", 0/*??*/); + } + + TypeItem type = (TypeItem) typeItem; + String name = type.fullTypeName; String pkg = ""; - int name_index = 0; if (name.contains(".")) { pkg = name.substring(0, name.lastIndexOf('.')); name = name.substring(name.lastIndexOf('.') + 1); @@ -2300,7 +2319,7 @@ public class AVM2SourceGenerator implements SourceGenerator { Multiname mname = abc.constants.constant_multiname.get(ii.name_index); if (mname.getName(abc.constants, new ArrayList()).equals(name)) { if (mname.getNamespace(abc.constants).hasName(pkg, abc.constants)) { - name_index = ii.name_index; + name_index = ii.name_index; break; } } @@ -2308,7 +2327,7 @@ public class AVM2SourceGenerator implements SourceGenerator { for (int i = 1; i < abc.constants.constant_multiname.size(); i++) { Multiname mname = abc.constants.constant_multiname.get(i); if (name.equals(mname.getName(abc.constants, new ArrayList()))) { - if (mname.getNamespace(abc.constants)!=null && pkg.equals(mname.getNamespace(abc.constants).getName(abc.constants))) { + if (mname.getNamespace(abc.constants) != null && pkg.equals(mname.getNamespace(abc.constants).getName(abc.constants))) { name_index = i; break; } @@ -2317,13 +2336,16 @@ public class AVM2SourceGenerator implements SourceGenerator { if (name_index == 0) { name_index = abc.constants.getMultinameId(new Multiname(Multiname.QNAME, abc.constants.getStringId(name, true), abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId(pkg, true)), 0, true), 0, 0, new ArrayList()), true); } - if (type.subtypes.isEmpty()) { - return name_index; + + if (item instanceof ApplyTypeAVM2Item) { + ApplyTypeAVM2Item atype = (ApplyTypeAVM2Item) item; + List params = new ArrayList<>(); + for (GraphTargetItem s : atype.params) { + params.add(resolveType(localData, s, abc,allABCs)); + } + return abc.constants.getMultinameId(new Multiname(Multiname.TYPENAME, 0, 0, 0, name_index, params), true); } - List params = new ArrayList<>(); - for (String s : type.subtypes) { - params.add(resolveType(new TypeItem(s), abc)); - } - return abc.constants.getMultinameId(new Multiname(Multiname.TYPENAME, 0, 0, 0, name_index, params), true); + + return name_index; } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java index d613bf5a6..da18798d5 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java @@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.abc.avm2.model.ApplyTypeAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.BooleanAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.CoerceAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.ConstructSuperAVM2Item; @@ -31,6 +32,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.FloatValueAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.GetDescendantsAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.GetPropertyAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.InAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.InitVectorAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.LocalRegAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.NameValuePair; @@ -130,6 +132,8 @@ public class ActionScriptParser { private ABC abc; private List otherABCs; + private static List playerABCs = new ArrayList<>(); + private long uniqId() { uniqLast++; return uniqLast; @@ -160,15 +164,19 @@ public class ActionScriptParser { lexer.pushback(s); } - return name(needsActivation, true, openedNamespaces, null, false, false, variables, importedClasses); + GraphTargetItem t = name(needsActivation, true, openedNamespaces, null, false, false, variables, importedClasses); + t = applyType(needsActivation, importedClasses, openedNamespaces, t, new HashMap(), false,false, variables); + return t; } private GraphTargetItem memberOrCall(Reference needsActivation, List importedClasses, List openedNamespaces, GraphTargetItem newcmds, HashMap registerVars, boolean inFunction, boolean inMethod, List variables) throws IOException, ParseException { ParsedSymbol s = lex(); GraphTargetItem ret = newcmds; - while (s.isType(SymbolType.DOT, SymbolType.PARENT_OPEN)) { + while (s.isType(SymbolType.DOT, SymbolType.PARENT_OPEN, SymbolType.BRACKET_OPEN, SymbolType.TYPENAME)) { switch (s.type) { + case BRACKET_OPEN: case DOT: + case TYPENAME: lexer.pushback(s); ret = member(needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables); break; @@ -197,11 +205,37 @@ public class ActionScriptParser { lexer.pushback(s); return ret; } + + private GraphTargetItem applyType(Reference needsActivation, List importedClasses, List openedNamespaces, GraphTargetItem obj, HashMap registerVars, boolean inFunction, boolean inMethod, List variables) throws IOException, ParseException { + GraphTargetItem ret = obj; + ParsedSymbol s = lex(); + if(s.type == SymbolType.TYPENAME){ + List params=new ArrayList<>(); + do{ + params.add(expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + s = lex(); + }while(s.type == SymbolType.COMMA); + if(s.type == SymbolType.USHIFT_RIGHT){ + s = new ParsedSymbol(SymbolGroup.OPERATOR, SymbolType.GREATER_THAN); + lexer.pushback(s); + lexer.pushback(s); + } + if(s.type == SymbolType.SHIFT_RIGHT){ + s = new ParsedSymbol(SymbolGroup.OPERATOR, SymbolType.GREATER_THAN); + lexer.pushback(s); + } + expected(s,lexer.yyline(),SymbolType.GREATER_THAN); + ret = new ApplyTypeAVM2Item(null, ret, params); + }else{ + lexer.pushback(s); + } + return ret; + } private GraphTargetItem member(Reference needsActivation, List importedClasses, List openedNamespaces, GraphTargetItem obj, HashMap registerVars, boolean inFunction, boolean inMethod, List variables) throws IOException, ParseException { GraphTargetItem ret = obj; ParsedSymbol s = lex(); - while (s.isType(SymbolType.DOT, SymbolType.BRACKET_OPEN)) { + while (s.isType(SymbolType.DOT, SymbolType.BRACKET_OPEN, SymbolType.TYPENAME)) { ParsedSymbol s2 = lex(); boolean attr = false; if (s.type == SymbolType.DOT) { @@ -215,7 +249,12 @@ public class ActionScriptParser { } else { lexer.pushback(s2); } - if (s.type == SymbolType.BRACKET_OPEN) { + if(s.type == SymbolType.TYPENAME){ + lexer.pushback(s); + ret = applyType(needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables); + s = lex(); + } + else if (s.type == SymbolType.BRACKET_OPEN) { GraphTargetItem index = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); expectedType(SymbolType.BRACKET_CLOSE); ret = new IndexAVM2Item(attr, ret, index, null, openedNamespaces); @@ -228,23 +267,23 @@ public class ActionScriptParser { s = lex(); GraphTargetItem ns = null; if (s.type == SymbolType.NAMESPACE_OP) { - ns = new UnresolvedAVM2Item(new ArrayList(), importedClasses, false, null, lexer.yyline(), propName, null, openedNamespaces); + ns = new UnresolvedAVM2Item(new ArrayList(), importedClasses, false, null, lexer.yyline(), propName, null, openedNamespaces); variables.add((UnresolvedAVM2Item) ns); s = lex(); - if(s.type == SymbolType.BRACKET_OPEN){ + if (s.type == SymbolType.BRACKET_OPEN) { propItem = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); expectedType(SymbolType.BRACKET_CLOSE); propName = null; - }else{ - expected(s, lexer.yyline(), SymbolType.IDENTIFIER); + } else { + expected(s, lexer.yyline(), SymbolType.IDENTIFIER); propName = s.value.toString(); propItem = null; - } + } } else { lexer.pushback(s); } if (ns != null) { - ret = new NamespacedAVM2Item(ns, propName,propItem, ret, attr, openedNamespaces, null); + ret = new NamespacedAVM2Item(ns, propName, propItem, ret, attr, openedNamespaces, null); } else { ret = new PropertyAVM2Item(ret, (attr ? "@" : "") + propName, abc, otherABCs, openedNamespaces, new ArrayList()); } @@ -273,8 +312,8 @@ public class ActionScriptParser { if (s.type == SymbolType.ATTRIBUTE) { name += "@"; s = lex(); - if(s.type == SymbolType.MULTIPLY){ - name += s.value.toString(); + if (s.type == SymbolType.MULTIPLY) { + name += s.value.toString(); } else if (s.type == SymbolType.IDENTIFIER) { name += s.value.toString(); } else { @@ -302,7 +341,7 @@ public class ActionScriptParser { s = lex(); if (s.type == SymbolType.IDENTIFIER) { nsprop = s.value.toString(); - } else if(s.type == SymbolType.BRACKET_OPEN){ + } else if (s.type == SymbolType.BRACKET_OPEN) { nspropItem = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); expectedType(SymbolType.BRACKET_CLOSE); } @@ -313,8 +352,8 @@ public class ActionScriptParser { } s = lex(); } - - List params = new ArrayList<>(); +/* + List params = new ArrayList<>(); if (s.type == SymbolType.TYPENAME) { s = lex(); do { @@ -332,22 +371,13 @@ public class ActionScriptParser { } while (s.type == SymbolType.COMMA); expected(s, lexer.yyline(), SymbolType.GREATER_THAN); s = lex(); - /*if(!openedNamespaces.contains(AS3vecNs)){ - openedNamespaces.add(AS3vecNs); - } */ - } - /*GraphTargetItem index = null; - if (s.type == SymbolType.BRACKET_OPEN) { - index = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); - expectedType(SymbolType.BRACKET_CLOSE); - } else { - lexer.pushback(s); - }*/ -// lexer.pushback(s); + }*/ + + GraphTargetItem ret = null; if (name != null) { - UnresolvedAVM2Item unr = new UnresolvedAVM2Item(params, importedClasses, typeOnly, null, lexer.yyline(), name, null, openedNamespaces); + UnresolvedAVM2Item unr = new UnresolvedAVM2Item(new ArrayList(), importedClasses, typeOnly, null, lexer.yyline(), name, null, openedNamespaces); //unr.setIndex(index); variables.add(unr); ret = unr; @@ -357,7 +387,7 @@ public class ActionScriptParser { if (attr) { nsname = nsname.substring(1); } - UnresolvedAVM2Item ns = new UnresolvedAVM2Item(params, importedClasses, typeOnly, null, lexer.yyline(), nsname, null, openedNamespaces); + UnresolvedAVM2Item ns = new UnresolvedAVM2Item(new ArrayList(), importedClasses, typeOnly, null, lexer.yyline(), nsname, null, openedNamespaces); variables.add(ns); ret = new NamespacedAVM2Item(ns, nsprop, nspropItem, ret, attr, openedNamespaces, null); } @@ -711,7 +741,7 @@ public class ActionScriptParser { } constr = (method(false, customAccess, new Reference(false), importedClasses, false, false, thisType, openedNamespaces, false, namespace, "", true, constrVariables)); } else { - MethodAVM2Item ft = method(false, customAccess, new Reference(false), importedClasses, isOverride, isFinal, thisType, openedNamespaces, isStatic, namespace, fname, true, new ArrayList()); + MethodAVM2Item ft = method(isInterface, customAccess, new Reference(false), importedClasses, isOverride, isFinal, thisType, openedNamespaces, isStatic, namespace, fname, true, new ArrayList()); if (isGetter) { if (!ft.paramTypes.isEmpty()) { @@ -767,7 +797,7 @@ public class ActionScriptParser { lexer.pushback(s); } - ConstAVM2Item ns = new ConstAVM2Item(customAccess, true, namespace, nname, new TypeItem("Namespace"), new StringAVM2Item(null, nval),lexer.yyline()); + ConstAVM2Item ns = new ConstAVM2Item(customAccess, true, namespace, nname, new TypeItem("Namespace"), new StringAVM2Item(null, nval), lexer.yyline()); traits.add(ns); break; case CONST: @@ -806,9 +836,9 @@ public class ActionScriptParser { } GraphTargetItem tar; if (isConst) { - tar = new ConstAVM2Item(customAccess, isStatic, namespace, vcname, type, value,lexer.yyline()); + tar = new ConstAVM2Item(customAccess, isStatic, namespace, vcname, type, value, lexer.yyline()); } else { - tar = new SlotAVM2Item(customAccess, isStatic, namespace, vcname, type, value,lexer.yyline()); + tar = new SlotAVM2Item(customAccess, isStatic, namespace, vcname, type, value, lexer.yyline()); } traits.add(tar); if (s.type != SymbolType.SEMICOLON) { @@ -848,7 +878,7 @@ public class ActionScriptParser { List indices = new ArrayList<>(); List names = new ArrayList<>(); List namespaces = new ArrayList<>(); - AVM2SourceGenerator.parentNamesAddNames(abc, otherABCs, AVM2SourceGenerator.resolveType(((TypeItem) ((UnresolvedAVM2Item) extendsStr).resolve(null, new ArrayList(), new ArrayList(), abc, otherABCs, new ArrayList(), new ArrayList())), abc), indices, names, namespaces); + AVM2SourceGenerator.parentNamesAddNames(abc, otherABCs, AVM2SourceGenerator.resolveType(new SourceGeneratorLocalData(new HashMap(), 0, false, 0),((TypeItem) ((UnresolvedAVM2Item) extendsStr).resolve(null, new ArrayList(), new ArrayList(), abc, otherABCs, new ArrayList(), new ArrayList())), abc, otherABCs), indices, names, namespaces); for (int i = 0; i < names.size(); i++) { if (namespaces.get(i).isEmpty()) { continue; @@ -1990,12 +2020,15 @@ public class ActionScriptParser { } } ret = new NewObjectAVM2Item(null, nvs); + ret = memberOrCall(needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables); break; case BRACKET_OPEN: //Array literal or just brackets lexer.pushback(s); List inBrackets = new ArrayList<>(); int arrCnt = brackets(needsActivation, importedClasses, openedNamespaces, inBrackets, registerVars, inFunction, inMethod, variables); ret = new NewArrayAVM2Item(null, inBrackets); + ret = memberOrCall(needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables); + break; case FUNCTION: s = lexer.lex(); @@ -2057,7 +2090,11 @@ public class ActionScriptParser { break; case NEW: s = lex(); - if(s.type == SymbolType.FUNCTION){ + if(s.type == SymbolType.XML_STARTTAG_BEGIN){ + lexer.yypushbackstr(s.value.toString().substring(1), ActionScriptLexer.YYINITIAL); + s = new ParsedSymbol(SymbolGroup.OPERATOR, SymbolType.LOWER_THAN); + } + if (s.type == SymbolType.FUNCTION) { s = lexer.lex(); String ffname = ""; if (s.isType(SymbolType.IDENTIFIER)) { @@ -2067,9 +2104,19 @@ public class ActionScriptParser { } needsActivation.setVal(true); ret = function(false, needsActivation, importedClasses, 0/*?*/, TypeItem.UNBOUNDED, openedNamespaces, ffname, false, variables); - }else{ + } else if(s.type == SymbolType.LOWER_THAN){ + GraphTargetItem subtype=type(needsActivation, importedClasses, openedNamespaces, variables); + expectedType(SymbolType.GREATER_THAN); + s = lex(); + expected(s,lexer.yyline(),SymbolType.BRACKET_OPEN); lexer.pushback(s); - GraphTargetItem newvar = name(needsActivation, true, openedNamespaces, registerVars, inFunction, inMethod, variables, importedClasses); + List params = new ArrayList<>(); + brackets(needsActivation, importedClasses, openedNamespaces, params, registerVars, inFunction, inMethod, variables); + ret = new InitVectorAVM2Item(subtype, params, openedNamespaces); + } else{ + lexer.pushback(s); + GraphTargetItem newvar = name(needsActivation, false /*?*/, openedNamespaces, registerVars, inFunction, inMethod, variables, importedClasses); + newvar = applyType(needsActivation, importedClasses, openedNamespaces, newvar, registerVars, inFunction, inMethod, variables); expectedType(SymbolType.PARENT_OPEN); ret = new ConstructSomethingAVM2Item(lexer.yyline(), openedNamespaces, newvar, call(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables)); } @@ -2202,7 +2249,7 @@ public class ActionScriptParser { } public PackageAVM2Item packageFromString(String str, String fileName) throws ParseException, IOException, CompilationException { - lexer = new ActionScriptLexer(new StringReader(str)); + lexer = new ActionScriptLexer(str); PackageAVM2Item ret = parsePackage(fileName); if (lexer.lex().type != SymbolType.EOF) { @@ -2236,33 +2283,31 @@ public class ActionScriptParser { this.otherABCs = otherABCs; } - public static void compile(String src, ABC abc, List otherABCs,boolean documentClass, String fileName) throws ParseException, IOException, InterruptedException, CompilationException { - SWC swc = new SWC(new FileInputStream(Configuration.getPlayerSWC())); - SWF swf = new SWF(swc.getSWF("library.swf"), true); - List playerABCs = new ArrayList<>(); - for (Tag t : swf.tags) { - if (t instanceof ABCContainerTag) { - playerABCs.add(((ABCContainerTag) t).getABC()); + private static void initPlayer() throws IOException, InterruptedException { + if (playerABCs.isEmpty()) { + SWC swc = new SWC(new FileInputStream(Configuration.getPlayerSWC())); + SWF swf = new SWF(swc.getSWF("library.swf"), true); + for (Tag t : swf.tags) { + if (t instanceof ABCContainerTag) { + playerABCs.add(((ABCContainerTag) t).getABC()); + } } } - List parABCs=new ArrayList<>(); + } + + public static void compile(String src, ABC abc, List otherABCs, boolean documentClass, String fileName) throws ParseException, IOException, InterruptedException, CompilationException { + List parABCs = new ArrayList<>(); + initPlayer(); parABCs.addAll(playerABCs); parABCs.addAll(otherABCs); ActionScriptParser parser = new ActionScriptParser(abc, parABCs); parser.addScript(src, documentClass, fileName); } - public static void compile(String src, String dst) { + public static void compile(SWF swf, String src, String dst) { System.err.println("WARNING: AS3 compiler is not finished yet. This is only used for debuggging!"); try { - SWC swc = new SWC(new FileInputStream(Configuration.getPlayerSWC())); - SWF swf = new SWF(swc.getSWF("library.swf"), true); - List playerABCs = new ArrayList<>(); - for (Tag t : swf.tags) { - if (t instanceof ABCContainerTag) { - playerABCs.add(((ABCContainerTag) t).getABC()); - } - } + initPlayer(); ABC abc = new ABC(swf); ActionScriptParser parser = new ActionScriptParser(abc, playerABCs); parser.addScript(new String(Helper.readFile(src), "UTF-8"), true, src); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/CallAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/CallAVM2Item.java index 52d08ae0e..410fa2baf 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/CallAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/CallAVM2Item.java @@ -19,9 +19,11 @@ package com.jpexs.decompiler.flash.abc.avm2.parser.script; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.abc.avm2.instructions.executing.CallIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.executing.CallPropVoidIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.executing.CallPropertyIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.other.FindPropertyStrictIns; +import com.jpexs.decompiler.flash.abc.avm2.instructions.other.GetGlobalScopeIns; import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.ValueKind; @@ -84,7 +86,7 @@ public class CallAVM2Item extends AVM2Item { Reference outNs = new Reference<>(""); Reference outPropNs = new Reference<>(""); Reference outPropNsKind = new Reference<>(1); - Reference outPropType = new Reference<>(""); + Reference outPropType = new Reference<>(null); Reference outPropValue = new Reference<>(null); if (cname!=null && AVM2SourceGenerator.searchPrototypeChain(true, allAbcs, pkgName, cname, n.getVariableName(), outName, outNs, outPropNs, outPropNsKind, outPropType, outPropValue)) { NameAVM2Item nobj = new NameAVM2Item(new TypeItem(localData.currentClass), n.line, "this", null, false, n.openedNamespaces); @@ -99,7 +101,7 @@ public class CallAVM2Item extends AVM2Item { int propIndex = -1; if (callable instanceof TypeItem) { TypeItem t = (TypeItem) callable; - propIndex = AVM2SourceGenerator.resolveType(t, ((AVM2SourceGenerator) generator).abc); + propIndex = AVM2SourceGenerator.resolveType(localData,t, ((AVM2SourceGenerator) generator).abc,((AVM2SourceGenerator) generator).allABCs); } Object obj = null; @@ -122,7 +124,7 @@ public class CallAVM2Item extends AVM2Item { Reference outNs = new Reference<>(""); Reference outPropNs = new Reference<>(""); Reference outPropNsKind = new Reference<>(1); - Reference outPropType = new Reference<>(""); + Reference outPropType = new Reference<>(null); Reference outPropValue = new Reference<>(null); if (cname!=null && AVM2SourceGenerator.searchPrototypeChain(true, allAbcs, pkgName, cname, prop.propertyName, outName, outNs, outPropNs, outPropNsKind, outPropType, outPropValue) && (localData.currentClass.equals("".equals(outNs.getVal()) ? outName.getVal() : outNs.getVal() + "." + outName.getVal()))) { NameAVM2Item nobj = new NameAVM2Item(new TypeItem(localData.currentClass), 0, "this", null, false, new ArrayList()); @@ -143,13 +145,13 @@ public class CallAVM2Item extends AVM2Item { } if(callable instanceof IndexAVM2Item){ - return ((IndexAVM2Item)callable).toSource(localData, generator, needsReturn, true, arguments); + return ((IndexAVM2Item)callable).toSource(localData, generator, needsReturn, true, arguments,false,false); } if(callable instanceof NamespacedAVM2Item){ - return ((NamespacedAVM2Item)callable).toSource(localData, generator, needsReturn, true, arguments); + return ((NamespacedAVM2Item)callable).toSource(localData, generator, needsReturn, true, arguments,false,false); } - throw new CompilationException("Not a callable", line); + return toSourceMerge(localData, generator, callable, ins(new GetGlobalScopeIns()),arguments,ins(new CallIns(),arguments.size())); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstructSomethingAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstructSomethingAVM2Item.java index f55aed062..35b314193 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstructSomethingAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstructSomethingAVM2Item.java @@ -69,41 +69,36 @@ public class ConstructSomethingAVM2Item extends CallAVM2Item { GraphTargetItem resname = name; if (resname instanceof UnresolvedAVM2Item) { resname = ((UnresolvedAVM2Item) resname).resolved; - } + } + if (resname instanceof TypeItem) { - TypeItem prop = (TypeItem) resname; - if (!prop.subtypes.isEmpty()) { //It's Vector - TypeName - //int qname = ((AVM2SourceGenerator) generator).resolveType(prop.fullTypeName); - String name = prop.fullTypeName.substring(prop.fullTypeName.lastIndexOf('.') + 1); - ABC abc = ((AVM2SourceGenerator) generator).abc; - int qname = abc.constants.getMultinameId(new Multiname(Multiname.MULTINAME, abc.constants.getStringId(name, true), 0, allNsSetWithVec(abc), 0, new ArrayList()), true); - List params = new ArrayList<>(); - for (String p : prop.subtypes) { - params.add(((AVM2SourceGenerator) generator).resolveType(p)); - } - List ret = new ArrayList<>(); - ret.add(ins(new GetLexIns(), qname)); - for (int p : params) { - ret.add(ins(new GetLexIns(), p)); - } - ret.add(ins(new ApplyTypeIns(), params.size())); - ret.addAll(toSourceMerge(localData, generator, arguments, - ins(new ConstructIns(), arguments.size()) - )); - return ret; - - } else { - int type_index = ((AVM2SourceGenerator) generator).resolveType(resname.toString()); - return toSourceMerge(localData, generator, - new AVM2Instruction(0, new FindPropertyStrictIns(), new int[]{type_index, arguments.size()}, new byte[0]), arguments, - new AVM2Instruction(0, new ConstructPropIns(), new int[]{type_index, arguments.size()}, new byte[0]) - ); - } + TypeItem prop = (TypeItem) resname; + int type_index = AVM2SourceGenerator.resolveType(localData,resname,((AVM2SourceGenerator)generator).abc,((AVM2SourceGenerator)generator).allABCs); + return toSourceMerge(localData, generator, + new AVM2Instruction(0, new FindPropertyStrictIns(), new int[]{type_index, arguments.size()}, new byte[0]), arguments, + new AVM2Instruction(0, new ConstructPropIns(), new int[]{type_index, arguments.size()}, new byte[0]) + ); } + + if (resname instanceof PropertyAVM2Item) { + PropertyAVM2Item prop=(PropertyAVM2Item)resname; + return toSourceMerge(localData, generator, prop.resolveObject(localData, generator),arguments, + ins(new ConstructPropIns(), prop.resolveProperty(localData),arguments.size()) + ); + } + if (resname instanceof NameAVM2Item) { - //TODO + return toSourceMerge(localData, generator, resname,arguments,ins(new ConstructIns(),arguments.size())); } - return new ArrayList<>(); + + if(resname instanceof IndexAVM2Item){ + return ((IndexAVM2Item)resname).toSource(localData, generator, true, false, arguments, false, true); + } + + if(resname instanceof NamespacedAVM2Item){ + return ((NamespacedAVM2Item)resname).toSource(localData, generator, true, false, arguments, false, true); + } + return toSourceMerge(localData, generator, resname, arguments, ins(new ConstructIns(),arguments.size())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/IndexAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/IndexAVM2Item.java index 6194eb23a..da820fb89 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/IndexAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/IndexAVM2Item.java @@ -20,7 +20,9 @@ import com.jpexs.decompiler.flash.SourceGeneratorLocalData; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.avm2.instructions.arithmetic.DecrementIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.arithmetic.IncrementIns; +import com.jpexs.decompiler.flash.abc.avm2.instructions.construction.ConstructPropIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.executing.CallIns; +import com.jpexs.decompiler.flash.abc.avm2.instructions.other.DeletePropertyIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.other.GetPropertyIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.other.SetPropertyIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.DupIns; @@ -116,8 +118,10 @@ public class IndexAVM2Item extends AssignableAVM2Item { ); } + + - public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn, boolean call, List callargs) throws CompilationException { + public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn, boolean call, List callargs, boolean delete, boolean construct) throws CompilationException { AVM2SourceGenerator g = (AVM2SourceGenerator) generator; int indexPropIndex = g.abc.constants.getMultinameId(new Multiname(attr ? Multiname.MULTINAMELA : Multiname.MULTINAMEL, 0, 0, allNsSet(g.abc), 0, new ArrayList()), true); Reference ret_temp = new Reference<>(-1); @@ -136,9 +140,10 @@ public class IndexAVM2Item extends AssignableAVM2Item { object, call?ins(new DupIns()):null, index, - ins(new GetPropertyIns(), indexPropIndex), + construct?callargs:null, + ins(construct?new ConstructPropIns():delete?new DeletePropertyIns():new GetPropertyIns(), indexPropIndex, construct?callargs.size():null), call?callargs:null, - call?ins(new CallIns(),callargs.size()):null, + call?ins(new CallIns(),callargs.size()):null, needsReturn ? null : ins(new PopIns())); } @@ -146,12 +151,12 @@ public class IndexAVM2Item extends AssignableAVM2Item { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { - return toSource(localData, generator, true, false, new ArrayList()); + return toSource(localData, generator, true, false, new ArrayList(),false,false); } @Override public List toSourceIgnoreReturnValue(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { - return toSource(localData, generator, false, false, new ArrayList()); + return toSource(localData, generator, false, false, new ArrayList(),false,false); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NameAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NameAVM2Item.java index 7334b1521..5183ff096 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NameAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NameAVM2Item.java @@ -181,7 +181,7 @@ public class NameAVM2Item extends AssignableAVM2Item { } } - public static AVM2Instruction generateCoerce(SourceGenerator generator, GraphTargetItem ttype) { + public static AVM2Instruction generateCoerce(SourceGeneratorLocalData localData, SourceGenerator generator, GraphTargetItem ttype) throws CompilationException { if (ttype instanceof UnresolvedAVM2Item) { ttype = ((UnresolvedAVM2Item) ttype).resolved; } @@ -189,33 +189,26 @@ public class NameAVM2Item extends AssignableAVM2Item { if (ttype instanceof UnboundedTypeItem) { ins = ins(new CoerceAIns()); } else { - TypeItem type = (TypeItem) ttype; - - if (type.subtypes.isEmpty()) { - switch (type.fullTypeName) { - case "int": - ins = ins(new ConvertIIns()); - break; - case "*": - ins = ins(new CoerceAIns()); - break; - case "String": - ins = ins(new CoerceSIns()); - break; - case "Boolean": - ins = ins(new ConvertBIns()); - break; - case "uint": - ins = ins(new ConvertUIns()); - break; - default: - int type_index = AVM2SourceGenerator.resolveType(type, ((AVM2SourceGenerator) generator).abc); - ins = ins(new CoerceIns(), type_index); - break; - } - } else { - int type_index = AVM2SourceGenerator.resolveType(type, ((AVM2SourceGenerator) generator).abc); - ins = ins(new CoerceIns(), type_index); + switch (ttype.toString()) { + case "int": + ins = ins(new ConvertIIns()); + break; + case "*": + ins = ins(new CoerceAIns()); + break; + case "String": + ins = ins(new CoerceSIns()); + break; + case "Boolean": + ins = ins(new ConvertBIns()); + break; + case "uint": + ins = ins(new ConvertUIns()); + break; + default: + int type_index = AVM2SourceGenerator.resolveType(localData,ttype, ((AVM2SourceGenerator) generator).abc,((AVM2SourceGenerator) generator).allABCs); + ins = ins(new CoerceIns(), type_index); + break; } } return ins; @@ -223,7 +216,7 @@ public class NameAVM2Item extends AssignableAVM2Item { private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { if (variableName != null && regNumber == -1 && slotNumber == -1 && ns == null) { - throw new RuntimeException("No register or slot set for " + variableName); + throw new CompilationException("No register or slot set for " + variableName, line); } if (definition && assignedValue == null) { return new ArrayList<>(); @@ -244,7 +237,7 @@ public class NameAVM2Item extends AssignableAVM2Item { if (slotNumber > -1) { return toSourceMerge(localData, generator, ins(new GetScopeObjectIns(), slotScope), - assignedValue, !(("" + assignedValue.returnType()).equals("" + type) && (basicTypes.contains("" + type))) ? generateCoerce(generator, type) : null, needsReturn + assignedValue, !(("" + assignedValue.returnType()).equals("" + type) && (basicTypes.contains("" + type))) ? generateCoerce(localData,generator, type) : null, needsReturn ? dupSetTemp(localData, generator, ret_temp) : null, generateSetLoc(regNumber), slotNumber > -1 ? ins(new SetSlotIns(), slotNumber) : null, @@ -252,7 +245,7 @@ public class NameAVM2Item extends AssignableAVM2Item { killTemp(localData, generator, Arrays.asList(ret_temp))); } else { - return toSourceMerge(localData, generator, assignedValue, !(("" + assignedValue.returnType()).equals("" + type) && (basicTypes.contains("" + type))) ? generateCoerce(generator, type) : null, needsReturn + return toSourceMerge(localData, generator, assignedValue, !(("" + assignedValue.returnType()).equals("" + type) && (basicTypes.contains("" + type))) ? generateCoerce(localData,generator, type) : null, needsReturn ? ins(new DupIns()) : null, generateSetLoc(regNumber)); } } else { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NamespacedAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NamespacedAVM2Item.java index 9a92771ae..68e4aea61 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NamespacedAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NamespacedAVM2Item.java @@ -22,7 +22,9 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.arithmetic.DecrementIIns import com.jpexs.decompiler.flash.abc.avm2.instructions.arithmetic.DecrementIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.arithmetic.IncrementIIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.arithmetic.IncrementIns; +import com.jpexs.decompiler.flash.abc.avm2.instructions.construction.ConstructPropIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.executing.CallIns; +import com.jpexs.decompiler.flash.abc.avm2.instructions.other.DeletePropertyIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.other.FindPropertyStrictIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.other.GetPropertyIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.other.SetPropertyIns; @@ -116,10 +118,10 @@ public class NamespacedAVM2Item extends AssignableAVM2Item { */ if (name != null) { return toSourceMerge(localData, generator, - ns, generateCoerce(generator, new TypeItem("Namespace")), + ns, generateCoerce(localData, generator, new TypeItem("Namespace")), ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList()), true)), dupSetTemp(localData, generator, name_temp), - ns, generateCoerce(generator, new TypeItem("Namespace")), + ns, generateCoerce(localData, generator, new TypeItem("Namespace")), dupSetTemp(localData, generator, ns_temp), //Start get original //getTemp(localData, generator, ns_temp), generateCoerce(generator, "Namespace"), ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAME, g.abc.constants.getStringId(variableName, true), 0, 0, 0, new ArrayList()), true)), @@ -157,7 +159,7 @@ public class NamespacedAVM2Item extends AssignableAVM2Item { return TypeItem.UNBOUNDED; } - public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn, boolean call, List callargs) throws CompilationException { + public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn, boolean call, List callargs, boolean delete,boolean construct) throws CompilationException { AVM2SourceGenerator g = (AVM2SourceGenerator) generator; Reference ns_temp = new Reference<>(-1); Reference index_temp = new Reference<>(-1); @@ -168,8 +170,8 @@ public class NamespacedAVM2Item extends AssignableAVM2Item { if (name == null) { if (assignedValue != null) { return toSourceMerge(localData, generator, - obj == null ? ns : null, obj == null ? generateCoerce(generator, new TypeItem("Namespace")) : null, nameItem, ins(new ConvertSIns()), obj != null ? obj : ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAMEL, 0, 0, 0, 0, new ArrayList()), true)), - ns, generateCoerce(generator, new TypeItem("Namespace")), nameItem, ins(new ConvertSIns()), assignedValue, + obj == null ? ns : null, obj == null ? generateCoerce(localData, generator, new TypeItem("Namespace")) : null, nameItem, ins(new ConvertSIns()), obj != null ? obj : ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAMEL, 0, 0, 0, 0, new ArrayList()), true)), + ns, generateCoerce(localData, generator, new TypeItem("Namespace")), nameItem, ins(new ConvertSIns()), assignedValue, needsReturn ? dupSetTemp(localData, generator, ret_temp) : null, ins(new SetPropertyIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAMEL, 0, 0, 0, 0, new ArrayList()), true)), needsReturn ? getTemp(localData, generator, ret_temp) : null, @@ -177,9 +179,11 @@ public class NamespacedAVM2Item extends AssignableAVM2Item { ); } else { return toSourceMerge(localData, generator, - obj == null ? ns : null, obj == null ? generateCoerce(generator, new TypeItem("Namespace")) : null, nameItem, ins(new ConvertSIns()), obj != null ? obj : ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAMEL, 0, 0, 0, 0, new ArrayList()), true)), + obj == null ? ns : null, obj == null ? generateCoerce(localData, generator, new TypeItem("Namespace")) : null, nameItem, ins(new ConvertSIns()), obj != null ? obj : ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAMEL, 0, 0, 0, 0, new ArrayList()), true)), call ? dupSetTemp(localData, generator, obj_temp) : null, - ns, generateCoerce(generator, new TypeItem("Namespace")), nameItem, ins(new ConvertSIns()), ins(new GetPropertyIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAMEL, 0, 0, 0, 0, new ArrayList()), true)), + ns, generateCoerce(localData,generator, new TypeItem("Namespace")), nameItem, ins(new ConvertSIns()), + construct?callargs:null, + ins(construct?new ConstructPropIns():delete?new DeletePropertyIns():new GetPropertyIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAMEL, 0, 0, 0, 0, new ArrayList()), true),construct?callargs.size():null), call ? getTemp(localData, generator, obj_temp) : null, call ? callargs : null, call ? ins(new CallIns(), callargs.size()) : null, @@ -190,8 +194,8 @@ public class NamespacedAVM2Item extends AssignableAVM2Item { } else { if (assignedValue != null) { return toSourceMerge(localData, generator, - obj == null ? ns : null, obj == null ? generateCoerce(generator, new TypeItem("Namespace")) : null, obj != null ? obj : ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(attr ? Multiname.RTQNAMEA : Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList()), true)), - ns, generateCoerce(generator, new TypeItem("Namespace")), assignedValue, + obj == null ? ns : null, obj == null ? generateCoerce(localData,generator, new TypeItem("Namespace")) : null, obj != null ? obj : ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(attr ? Multiname.RTQNAMEA : Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList()), true)), + ns, generateCoerce(localData,generator, new TypeItem("Namespace")), assignedValue, needsReturn ? dupSetTemp(localData, generator, ret_temp) : null, ins(new SetPropertyIns(), g.abc.constants.getMultinameId(new Multiname(attr ? Multiname.RTQNAMEA : Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList()), true)), needsReturn ? getTemp(localData, generator, ret_temp) : null, @@ -199,9 +203,11 @@ public class NamespacedAVM2Item extends AssignableAVM2Item { ); } else { return toSourceMerge(localData, generator, - obj == null ? ns : null, obj == null ? generateCoerce(generator, new TypeItem("Namespace")) : null, obj != null ? obj : ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(attr ? Multiname.RTQNAMEA : Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList()), true)), + obj == null ? ns : null, obj == null ? generateCoerce(localData,generator, new TypeItem("Namespace")) : null, obj != null ? obj : ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(attr ? Multiname.RTQNAMEA : Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList()), true)), call ? dupSetTemp(localData, generator, obj_temp) : null, - ns, generateCoerce(generator, new TypeItem("Namespace")), ins(new GetPropertyIns(), g.abc.constants.getMultinameId(new Multiname(attr ? Multiname.RTQNAMEA : Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList()), true)), + ns, generateCoerce(localData,generator, new TypeItem("Namespace")), + construct?callargs:null, + ins(construct?new ConstructPropIns():delete?new DeletePropertyIns():new GetPropertyIns(), g.abc.constants.getMultinameId(new Multiname(attr ? Multiname.RTQNAMEA : Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList()), true),construct?callargs.size():null), call ? getTemp(localData, generator, obj_temp) : null, call ? callargs : null, call ? ins(new CallIns(), callargs.size()) : null, @@ -214,12 +220,12 @@ public class NamespacedAVM2Item extends AssignableAVM2Item { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { - return toSource(localData, generator, true, false, new ArrayList()); + return toSource(localData, generator, true, false, new ArrayList(),false,false); } @Override public List toSourceIgnoreReturnValue(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { - return toSource(localData, generator, false, false, new ArrayList()); + return toSource(localData, generator, false, false, new ArrayList(),false,false); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java index b8949de22..6bee9d637 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.abc.avm2.parser.script; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; import com.jpexs.decompiler.flash.abc.avm2.instructions.arithmetic.DecrementIIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.arithmetic.DecrementIns; @@ -30,6 +31,7 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.other.SetPropertyIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.DupIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PopIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertDIns; +import com.jpexs.decompiler.flash.abc.avm2.model.ApplyTypeAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.CoerceAVM2Item; import com.jpexs.decompiler.flash.abc.types.InstanceInfo; import com.jpexs.decompiler.flash.abc.types.MethodBody; @@ -49,6 +51,7 @@ import com.jpexs.decompiler.graph.TypeItem; import com.jpexs.decompiler.graph.model.LocalData; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; /** @@ -93,9 +96,27 @@ public class PropertyAVM2Item extends AssignableAVM2Item { return abc.constants.getNamespaceSetId(new NamespaceSet(nssa), true); } - public void resolve(SourceGeneratorLocalData localData, Reference objectType, Reference propertyType, Reference propertyIndex, Reference propertyValue) { - String objType = null; - String objSubType = null; + + public static GraphTargetItem multinameToType(int m_index,ConstantPool constants){ + if(m_index == 0){ + return TypeItem.UNBOUNDED; + } + Multiname m = constants.constant_multiname.get(m_index); + if(m.kind == Multiname.TYPENAME){ + GraphTargetItem obj = multinameToType(m.qname_index,constants); + List params =new ArrayList<>(); + for(int pm:m.params){ + params.add(multinameToType(pm, constants)); + } + return new ApplyTypeAVM2Item(null, obj, params); + }else { + return new TypeItem(m.getNameWithNamespace(constants)); + } + } + + public void resolve(SourceGeneratorLocalData localData, Reference objectType, Reference propertyType, Reference propertyIndex, Reference propertyValue) { + GraphTargetItem objType = null; + GraphTargetItem objSubType = null; ValueKind propValue = null; if (object != null) { GraphTargetItem oretType = object.returnType(); @@ -103,17 +124,17 @@ public class PropertyAVM2Item extends AssignableAVM2Item { UnresolvedAVM2Item ur = (UnresolvedAVM2Item) oretType; oretType = ur.resolved; } - if (oretType instanceof TypeItem) { + if (oretType instanceof ApplyTypeAVM2Item) { + ApplyTypeAVM2Item t = (ApplyTypeAVM2Item) oretType; + objType = t; + } else if (oretType instanceof TypeItem) { TypeItem t = (TypeItem) oretType; - objType = t.fullTypeName; - if (!t.subtypes.isEmpty()) { - objSubType = t.subtypes.get(0); - } + objType = t; } else { - objType = oretType.toString(); + objType = new TypeItem(oretType.toString()); } } - String propType = ""; + GraphTargetItem propType = null; int propIndex = 0; if (!propertyName.startsWith("@")) { @@ -165,8 +186,8 @@ public class PropertyAVM2Item extends AssignableAVM2Item { if (t.getName(abc).getName(abc.constants, new ArrayList()).equals(propertyName)) { if (t instanceof TraitSlotConst) { TraitSlotConst tsc = (TraitSlotConst) t; - objType = "Function"; - propType = tsc.type_index == 0 ? "*" : abc.constants.constant_multiname.get(tsc.type_index).getNameWithNamespace(abc.constants); + objType = new TypeItem("Function"); + propType = multinameToType(tsc.type_index, abc.constants); propIndex = tsc.name_index; if (!localData.traitUsages.containsKey(b)) { localData.traitUsages.put(b, new ArrayList()); @@ -194,8 +215,8 @@ public class PropertyAVM2Item extends AssignableAVM2Item { for (int c = 0; c < abc.instance_info.size(); c++) { for (Trait t : abc.instance_info.get(c).instance_traits.traits) { if (t.name_index == name_index) { - objType = abc.instance_info.get(c).getName(abc.constants).getNameWithNamespace(abc.constants); - propType = AVM2SourceGenerator.getTraitReturnType(abc, t).toString(); + objType = multinameToType(abc.instance_info.get(c).name_index, abc.constants); + propType = AVM2SourceGenerator.getTraitReturnType(abc, t); propIndex = t.name_index; if (t instanceof TraitSlotConst) { TraitSlotConst tsc = (TraitSlotConst) t; @@ -206,8 +227,8 @@ public class PropertyAVM2Item extends AssignableAVM2Item { } for (Trait t : abc.class_info.get(c).static_traits.traits) { if (t.name_index == name_index) { - objType = abc.instance_info.get(c).getName(abc.constants).getNameWithNamespace(abc.constants); - propType = AVM2SourceGenerator.getTraitReturnType(abc, t).toString(); + objType = multinameToType(abc.instance_info.get(c).name_index,abc.constants); + propType = AVM2SourceGenerator.getTraitReturnType(abc, t); propIndex = t.name_index; if (t instanceof TraitSlotConst) { TraitSlotConst tsc = (TraitSlotConst) t; @@ -215,14 +236,14 @@ public class PropertyAVM2Item extends AssignableAVM2Item { } break loopobjType; } - } + } } - - for(ScriptInfo si:abc.script_info){ - for (Trait t :si.traits.traits) { + + for (ScriptInfo si : abc.script_info) { + for (Trait t : si.traits.traits) { if (t.name_index == name_index) { - objType = "Object"; - propType = AVM2SourceGenerator.getTraitReturnType(abc, t).toString(); + objType = new TypeItem("Object"); + propType = AVM2SourceGenerator.getTraitReturnType(abc, t); propIndex = t.name_index; if (t instanceof TraitSlotConst) { TraitSlotConst tsc = (TraitSlotConst) t; @@ -247,10 +268,10 @@ public class PropertyAVM2Item extends AssignableAVM2Item { Reference outNs = new Reference<>(""); Reference outPropNs = new Reference<>(""); Reference outPropNsKind = new Reference<>(1); - Reference outPropType = new Reference<>(""); + Reference outPropType = new Reference<>(null); Reference outPropValue = new Reference<>(null); - if (propertyName!=null && AVM2SourceGenerator.searchPrototypeChain(false, abcs, nsname, n.getName(a.constants, new ArrayList()), propertyName, outName, outNs, outPropNs, outPropNsKind, outPropType, outPropValue)) { - objType = "".equals(outNs.getVal()) ? outName.getVal() : outNs.getVal() + "." + outName.getVal(); + if (propertyName != null && AVM2SourceGenerator.searchPrototypeChain(false, abcs, nsname, n.getName(a.constants, new ArrayList()), propertyName, outName, outNs, outPropNs, outPropNsKind, outPropType, outPropValue)) { + objType = new TypeItem("".equals(outNs.getVal()) ? outName.getVal() : outNs.getVal() + "." + outName.getVal()); propType = outPropType.getVal(); propIndex = abc.constants.getMultinameId(new Multiname(Multiname.QNAME, abc.constants.getStringId(propertyName, true), @@ -270,14 +291,18 @@ public class PropertyAVM2Item extends AssignableAVM2Item { abcs.add(abc); abcs.addAll(otherABCs); if (objType.equals("__AS3__.vec.Vector")) { - if ("int".equals(objSubType)) { - objType = "__AS3__.vec.Vector$int"; - } else if ("Number".equals(objSubType)) { - objType = "__AS3__.vec.Vector$double"; - } else if ("uint".equals(objSubType)) { - objType = "__AS3__.vec.Vector$uint"; - } else { - objType = "__AS3__.vec.Vector$object"; + switch ("" + objSubType) { + case "int": + objType = new TypeItem("__AS3__.vec.Vector$int"); + break; + case "Number": + objType = new TypeItem("__AS3__.vec.Vector$double"); + break; + case "uint": + objType = new TypeItem("__AS3__.vec.Vector$uint"); + break; + default: + objType = new TypeItem("__AS3__.vec.Vector$object"); } } loopa: @@ -289,10 +314,10 @@ public class PropertyAVM2Item extends AssignableAVM2Item { Reference outNs = new Reference<>(""); Reference outPropNs = new Reference<>(""); Reference outPropNsKind = new Reference<>(1); - Reference outPropType = new Reference<>(""); + Reference outPropType = new Reference<>(null); Reference outPropValue = new Reference<>(null); if (AVM2SourceGenerator.searchPrototypeChain(false, abcs, m.getNamespace(a.constants).getName(a.constants), m.getName(a.constants, new ArrayList()), propertyName, outName, outNs, outPropNs, outPropNsKind, outPropType, outPropValue)) { - objType = "".equals(outNs.getVal()) ? outName.getVal() : outNs.getVal() + "." + outName.getVal(); + objType = new TypeItem("".equals(outNs.getVal()) ? outName.getVal() : outNs.getVal() + "." + outName.getVal()); propType = outPropType.getVal(); propIndex = abc.constants.getMultinameId(new Multiname(Multiname.QNAME, abc.constants.getStringId(propertyName, true), @@ -316,10 +341,10 @@ public class PropertyAVM2Item extends AssignableAVM2Item { pname = pname.substring(1); } propIndex = abc.constants.getMultinameId(new Multiname(attr ? (pname.isEmpty() ? Multiname.MULTINAMELA : Multiname.MULTINAMEA) : Multiname.MULTINAME, - abc.constants.getStringId("*".equals(pname)?null:pname, true), 0, //Note: name = * is for .@* attribute + abc.constants.getStringId("*".equals(pname) ? null : pname, true), 0, //Note: name = * is for .@* attribute attr && pname.isEmpty() ? abc.constants.getNamespaceSetId(new NamespaceSet(new int[]{abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE_INTERNAL, abc.constants.getStringId(localData.pkg, true)), 0, true)}), true) : allNsSet(), 0, new ArrayList()), true); - propType = "*"; - objType = "*"; + propType = TypeItem.UNBOUNDED; + objType = TypeItem.UNBOUNDED; propValue = null; } @@ -330,8 +355,8 @@ public class PropertyAVM2Item extends AssignableAVM2Item { } public int resolveProperty(SourceGeneratorLocalData localData) { - Reference objType = new Reference<>(""); - Reference propType = new Reference<>(""); + Reference objType = new Reference<>(null); + Reference propType = new Reference<>(null); Reference propIndex = new Reference<>(0); Reference outPropValue = new Reference<>(null); resolve(localData, objType, propType, propIndex, outPropValue); @@ -499,19 +524,19 @@ public class PropertyAVM2Item extends AssignableAVM2Item { }*/ @Override public GraphTargetItem returnType() { - Reference objType = new Reference<>(""); - Reference propType = new Reference<>(""); + Reference objType = new Reference<>(null); + Reference propType = new Reference<>(null); Reference propIndex = new Reference<>(0); Reference outPropValue = new Reference<>(null); - resolve(null, objType, propType, propIndex, outPropValue); + resolve(new SourceGeneratorLocalData(new HashMap(), 0, false, 0)/*???*/, objType, propType, propIndex, outPropValue); - return new TypeItem(propType.getVal()); + return propType.getVal(); } public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { - Reference objType = new Reference<>(""); - Reference propType = new Reference<>(""); + Reference objType = new Reference<>(null); + Reference propType = new Reference<>(null); Reference propIndex = new Reference<>(0); Reference outPropValue = new Reference<>(null); resolve(localData, objType, propType, propIndex, outPropValue); @@ -520,7 +545,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item { Object obj = resolveObject(localData, generator); Reference ret_temp = new Reference<>(-1); if (assignedValue != null) { - String targetType = propType.getVal(); + GraphTargetItem targetType = propType.getVal(); String srcType = assignedValue.returnType().toString(); GraphTargetItem coerced = assignedValue; if (!targetType.equals(srcType) && !propertyName.startsWith("@")) { @@ -563,7 +588,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item { return true; } - private Object resolveObject(SourceGeneratorLocalData localData, SourceGenerator generator) { + public Object resolveObject(SourceGeneratorLocalData localData, SourceGenerator generator) { Object obj = object; if (obj == null) { @@ -578,7 +603,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item { Reference outNs = new Reference<>(""); Reference outPropNs = new Reference<>(""); Reference outPropNsKind = new Reference<>(1); - Reference outPropType = new Reference<>(""); + Reference outPropType = new Reference<>(null); Reference outPropValue = new Reference<>(null); List abcs = new ArrayList<>(); abcs.add(abc); @@ -588,8 +613,8 @@ public class PropertyAVM2Item extends AssignableAVM2Item { nobj.setRegNumber(0); obj = nobj; } else { - Reference objType = new Reference<>(""); - Reference propType = new Reference<>(""); + Reference objType = new Reference<>(null); + Reference propType = new Reference<>(null); Reference propIndex = new Reference<>(0); Reference propValue = new Reference<>(null); resolve(localData, objType, propType, propIndex, outPropValue); @@ -602,8 +627,8 @@ public class PropertyAVM2Item extends AssignableAVM2Item { @Override public List toSourceChange(SourceGeneratorLocalData localData, SourceGenerator generator, boolean post, boolean decrement, boolean needsReturn) throws CompilationException { - Reference objType = new Reference<>(""); - Reference propType = new Reference<>(""); + Reference objType = new Reference<>(null); + Reference propType = new Reference<>(null); Reference propIndex = new Reference<>(0); Reference outPropValue = new Reference<>(null); resolve(localData, objType, propType, propIndex, outPropValue); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java index b8641bfcc..477501ea9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java @@ -61,7 +61,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { private boolean mustBeType; public List importedClasses; public List scopeStack = new ArrayList(); - public List subtypes; + public List subtypes; @Override public AssignableAVM2Item copy() { @@ -150,7 +150,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { this.name = name; } - public UnresolvedAVM2Item(List subtypes, List importedClasses, boolean mustBeType, GraphTargetItem type, int line, String name, GraphTargetItem storeValue, List openedNamespaces) { + public UnresolvedAVM2Item(List subtypes, List importedClasses, boolean mustBeType, GraphTargetItem type, int line, String name, GraphTargetItem storeValue, List openedNamespaces) { super(storeValue); this.name = name; this.assignedValue = storeValue; @@ -199,9 +199,9 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { } } - public static AVM2Instruction generateCoerce(SourceGenerator generator, String type) { + public static AVM2Instruction generateCoerce(SourceGeneratorLocalData localData, SourceGenerator generator, GraphTargetItem type) throws CompilationException { AVM2Instruction ins; - switch (type) { + switch (type.toString()) { case "int": ins = ins(new ConvertIIns()); break; @@ -212,7 +212,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { ins = ins(new CoerceSIns()); break; default: - int type_index = AVM2SourceGenerator.resolveType(new TypeItem(type), ((AVM2SourceGenerator) generator).abc); + int type_index = AVM2SourceGenerator.resolveType(localData, type, ((AVM2SourceGenerator) generator).abc,((AVM2SourceGenerator) generator).allABCs); ins = ins(new CoerceIns(), type_index); break; } @@ -327,7 +327,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { } if (impName.equals(parts.get(0))) { TypeItem ret = new TypeItem(imp); - for (String s : subtypes) { + /*for (GraphTargetItem s : subtypes) { if (!subtypes.isEmpty() && parts.size() > 1) { continue; } @@ -338,7 +338,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { } TypeItem st = (TypeItem) su.resolved; ret.subtypes.add(st.fullTypeName); - } + }*/ resolved = ret; for (int i = 1; i < parts.size(); i++) { resolved = new PropertyAVM2Item(resolved, parts.get(i), abc, otherAbcs, openedNamespaces, new ArrayList()); @@ -366,7 +366,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { continue; } TypeItem ret = new TypeItem(fname); - for (String s : subtypes) { + /*for (String s : subtypes) { UnresolvedAVM2Item su = new UnresolvedAVM2Item(new ArrayList(), importedClasses, true, null, line, s, null, openedNamespaces); su.resolve(thisType, paramTypes, paramNames, abc, otherAbcs, callStack, variables); if (!(su.resolved instanceof TypeItem)) { @@ -374,7 +374,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { } TypeItem st = (TypeItem) su.resolved; ret.subtypes.add(st.fullTypeName); - } + }*/ resolved = ret; for (int j = i + 1; j < parts.size(); j++) { resolved = new PropertyAVM2Item(resolved, parts.get(j), abc, otherAbcs, openedNamespaces, new ArrayList()); @@ -404,7 +404,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { continue; } TypeItem ret = new TypeItem(a.instance_info.get(c).getName(a.constants).getNameWithNamespace(a.constants)); - for (String s : subtypes) { + /*for (String s : subtypes) { UnresolvedAVM2Item su = new UnresolvedAVM2Item(new ArrayList(), importedClasses, true, null, line, s, null, openedNamespaces); su.resolve(thisType, paramTypes, paramNames, abc, otherAbcs, callStack, variables); if (!(su.resolved instanceof TypeItem)) { @@ -412,7 +412,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { } TypeItem st = (TypeItem) su.resolved; ret.subtypes.add(st.fullTypeName); - } + }*/ resolved = ret; for (int i = 1; i < parts.size(); i++) { resolved = new PropertyAVM2Item(resolved, parts.get(i), abc, otherAbcs, openedNamespaces, new ArrayList()); @@ -435,7 +435,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { if (thisType == null) { throw new CompilationException("Cannot use this in that context", line); } - GraphTargetItem ret = new NameAVM2Item(thisType, line, parts.get(0), null, false, openedNamespaces); + NameAVM2Item ret = new NameAVM2Item(thisType, line, parts.get(0), null, false, openedNamespaces); resolved = ret; for (int i = 1; i < parts.size(); i++) { resolved = new PropertyAVM2Item(resolved, parts.get(i), abc, otherAbcs, openedNamespaces, new ArrayList()); @@ -444,7 +444,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { } } if (parts.size() == 1) { - ((NameAVM2Item) ret).setAssignedValue(assignedValue); + ret.setAssignedValue(assignedValue); } return resolvedRoot=ret; } @@ -472,9 +472,10 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { return resolvedRoot=ret; } - if (!subtypes.isEmpty() && parts.size() == 1 && parts.get(0).equals("Vector")) { + + if (/*!subtypes.isEmpty() && */parts.size() == 1 && parts.get(0).equals("Vector")) { TypeItem ret = new TypeItem("__AS3__.vec.Vector"); - for (String s : subtypes) { + /*for (String s : subtypes) { UnresolvedAVM2Item su = new UnresolvedAVM2Item(new ArrayList(), importedClasses, true, null, line, s, null, openedNamespaces); su.resolve(thisType, paramTypes, paramNames, abc, otherAbcs, callStack, variables); if (!(su.resolved instanceof TypeItem)) { @@ -482,7 +483,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { } TypeItem st = (TypeItem) su.resolved; ret.subtypes.add(st.fullTypeName); - } + }*/ resolved = ret; return resolvedRoot=ret; } diff --git a/trunk/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/trunk/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index fcf113d53..a92def373 100644 --- a/trunk/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/trunk/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -288,7 +288,7 @@ public class CommandLineArgumentParser { } else if (nextParam.equals("-dumpswf")) { parseDumpSwf(args); } else if (nextParam.equals("-as3compiler")) { - ActionScriptParser.compile(args.remove(), args.remove()); + ActionScriptParser.compile(null /*?*/,args.remove(), args.remove()); } else if (nextParam.equals("-help") || nextParam.equals("--help") || nextParam.equals("/?")) { printHeader(); printCmdLineUsage(); diff --git a/trunk/src/com/jpexs/decompiler/graph/TypeItem.java b/trunk/src/com/jpexs/decompiler/graph/TypeItem.java index 64c37ab36..5aa4dfb26 100644 --- a/trunk/src/com/jpexs/decompiler/graph/TypeItem.java +++ b/trunk/src/com/jpexs/decompiler/graph/TypeItem.java @@ -37,16 +37,14 @@ public class TypeItem extends GraphTargetItem { public static UnboundedTypeItem UNBOUNDED = new UnboundedTypeItem(); public String fullTypeName; - public List subtypes = new ArrayList<>(); public TypeItem(String fullTypeName) { - this(fullTypeName, new ArrayList()); + this(fullTypeName, new ArrayList()); } - public TypeItem(String fullTypeName, List subtypes) { + public TypeItem(String fullTypeName, List subtypes) { super(null, NOPRECEDENCE); this.fullTypeName = fullTypeName; - this.subtypes.addAll(subtypes); } @Override @@ -73,7 +71,16 @@ public class TypeItem extends GraphTargetItem { @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { - writer.append(fullTypeName); + if(localData.fullyQualifiedNames.contains(fullTypeName)){ + writer.append(fullTypeName); + }else{ + String simpleName = fullTypeName; + if(simpleName.contains(".")){ + simpleName = simpleName.substring(simpleName.lastIndexOf(".")+1); + } + writer.append(simpleName); + } + return writer; } @@ -89,13 +96,7 @@ public class TypeItem extends GraphTargetItem { @Override public String toString() { - String add = ""; - if (!subtypes.isEmpty()) { - add += ".<"; - add += Helper.joinStrings(subtypes, ","); - add += ">"; - } - return fullTypeName + add; + return fullTypeName; } @Override diff --git a/trunk/test/com/jpexs/decompiler/flash/RecompileTest.java b/trunk/test/com/jpexs/decompiler/flash/RecompileTest.java index ed611afb3..d5bbbf070 100644 --- a/trunk/test/com/jpexs/decompiler/flash/RecompileTest.java +++ b/trunk/test/com/jpexs/decompiler/flash/RecompileTest.java @@ -120,6 +120,7 @@ public class RecompileTest { @Test(dataProvider = "provideFiles") public void testDirectEditing(String filename) throws IOException, InterruptedException, com.jpexs.decompiler.flash.abc.avm2.parser.ParseException, CompilationException { + Configuration.autoDeobfuscate.set(false); try{SWF swf = new SWF(new BufferedInputStream(new FileInputStream(TESTDATADIR + File.separator + filename)), false); if (swf.fileAttributes.actionScript3) { List allAbcs = new ArrayList<>();