From cd977ebf6932dffe9254de656b2325283c2ff854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Thu, 8 May 2014 19:44:49 +0200 Subject: [PATCH] AS3 direct editation improvements - more classes in one script, in operator, negate, ... --- .../com/jpexs/decompiler/flash/abc/ABC.java | 2 +- .../flash/abc/avm2/ConstantPool.java | 3 + .../abc/avm2/model/ConstructAVM2Item.java | 6 + .../flash/abc/avm2/model/InAVM2Item.java | 13 + .../parser/script/AVM2SourceGenerator.java | 166 +++-- .../parser/script/ActionScriptParser.java | 699 ++++++++++-------- .../abc/avm2/parser/script/ClassAVM2Item.java | 9 +- .../abc/avm2/parser/script/ConstAVM2Item.java | 6 +- .../avm2/parser/script/FunctionAVM2Item.java | 4 +- .../avm2/parser/script/GetterAVM2Item.java | 4 +- .../avm2/parser/script/InterfaceAVM2Item.java | 6 +- .../avm2/parser/script/MethodAVM2Item.java | 4 +- .../avm2/parser/script/PackageAVM2Item.java | 7 +- .../avm2/parser/script/PropertyAVM2Item.java | 2 +- .../avm2/parser/script/SetterAVM2Item.java | 4 +- .../abc/avm2/parser/script/SlotAVM2Item.java | 6 +- .../parser/script/UnresolvedAVM2Item.java | 9 +- .../flash/abc/types/MethodInfo.java | 2 +- .../decompiler/flash/abc/types/Namespace.java | 7 + .../flash/gui/abc/ClassesListTreeModel.java | 2 +- .../jpexs/decompiler/flash/RecompileTest.java | 11 + 21 files changed, 579 insertions(+), 393 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java b/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java index 447d26672..36cb793cb 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java @@ -94,7 +94,7 @@ public class ABC { constants.constant_double.add(null); constants.constant_int.add(null); constants.constant_uint.add(null); - constants.constant_string.add(""); + constants.constant_string.add(null); constants.constant_multiname.add(null); constants.constant_namespace.add(null); constants.constant_namespace_set.add(null); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/ConstantPool.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/ConstantPool.java index 37b40c825..68ae3c0d1 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/ConstantPool.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/ConstantPool.java @@ -213,6 +213,9 @@ public class ConstantPool { public int getDoubleId(double value) { for (int i = 1; i < constant_double.size(); i++) { + if(Double.isNaN(value) && Double.isNaN(constant_double.get(i))){ + return i; + } if (Double.compare(constant_double.get(i), value) == 0) { return i; } 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 8c93fbd4f..c9f8ffc52 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 @@ -40,7 +40,13 @@ public class ConstructAVM2Item extends AVM2Item { return object.toString(writer, localData); } writer.append("new "); + if(object.getPrecedence()>getPrecedence()){ + writer.append("("); + } object.toString(writer, localData); + if(object.getPrecedence()>getPrecedence()){ + writer.append(")"); + } writer.spaceBeforeCallParenthesies(args.size()); if(object instanceof InitVectorAVM2Item){ return writer; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/InAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/InAVM2Item.java index e9b730b4b..ea0592a89 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/InAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/InAVM2Item.java @@ -16,11 +16,17 @@ */ 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.other.InIns; 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.List; public class InAVM2Item extends AVM2Item { @@ -49,4 +55,11 @@ public class InAVM2Item extends AVM2Item { public boolean hasReturnValue() { return true; } + + @Override + public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { + return toSourceMerge(localData, generator, object,collection,ins(new InIns())); + } + + } 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 bac91ec84..cc76410d1 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 @@ -73,6 +73,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.IntegerValueAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.LocalRegAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.NanAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.NullAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.ReturnValueAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.ReturnVoidAVM2Item; @@ -130,6 +131,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -1167,30 +1169,31 @@ public class AVM2SourceGenerator implements SourceGenerator { return abc; } - public void generateClass(List sinitVariables, boolean staticNeedsActivation, List staticInit, List openedNamespaces, int namespace, int initScope, PackageAVM2Item pkg, ClassInfo classInfo, InstanceInfo instanceInfo, SourceGeneratorLocalData localData, boolean isInterface, String name, String superName, GraphTargetItem extendsVal, List implementsStr, GraphTargetItem constructor, List traitItems) throws ParseException, CompilationException { - localData.currentClass = pkg.packageName.isEmpty() ? name : pkg.packageName + "." + name; + public void generateClass(List importedClasses,List sinitVariables, boolean staticNeedsActivation, List staticInit, List openedNamespaces, int namespace, int initScope, String pkg, ClassInfo classInfo, InstanceInfo instanceInfo, SourceGeneratorLocalData localData, boolean isInterface, String name, String superName, GraphTargetItem extendsVal, List implementsStr, GraphTargetItem constructor, List traitItems) throws ParseException, CompilationException { + localData.currentClass = pkg == null || pkg.isEmpty() ? name : pkg + "." + name; + localData.pkg = pkg; List ret = new ArrayList<>(); if (extendsVal == null && !isInterface) { extendsVal = new TypeItem("Object"); } ParsedSymbol s = null; - Trait[] it = generateTraitsPhase1(pkg, name, superName, false, localData, traitItems, instanceInfo.instance_traits); - Trait[] st = generateTraitsPhase1(pkg, name, superName, true, localData, traitItems, classInfo.static_traits); - generateTraitsPhase2(pkg.packageName, traitItems, it, openedNamespaces, localData); - generateTraitsPhase2(pkg.packageName, traitItems, st, openedNamespaces, localData); - generateTraitsPhase3(isInterface, initScope, pkg, name, superName, false, localData, traitItems, instanceInfo.instance_traits, it); - generateTraitsPhase3(isInterface, initScope, pkg, name, superName, true, localData, traitItems, classInfo.static_traits, st); + Trait[] it = generateTraitsPhase1(name, superName, false, localData, traitItems, instanceInfo.instance_traits); + Trait[] st = generateTraitsPhase1(name, superName, true, localData, traitItems, classInfo.static_traits); + generateTraitsPhase2(importedClasses,pkg, traitItems, it, openedNamespaces, localData); + generateTraitsPhase2(importedClasses,pkg, traitItems, st, openedNamespaces, localData); + generateTraitsPhase3(initScope,isInterface, name, superName, false, localData, traitItems, instanceInfo.instance_traits, it,new HashMap()); + generateTraitsPhase3(initScope,isInterface, name, superName, true, localData, traitItems, classInfo.static_traits, st,new HashMap()); int init = 0; if (constructor == null || isInterface) { - instanceInfo.iinit_index = init = method(isInterface, new ArrayList(), pkg.packageName, false, new ArrayList(), initScope + 1, false, 0, isInterface ? null : name, extendsVal != null ? extendsVal.toString() : null, true, localData, new ArrayList(), new ArrayList(), new ArrayList(), new ArrayList(), TypeItem.UNBOUNDED/*?? FIXME*/); + instanceInfo.iinit_index = init = method(isInterface, new ArrayList(), pkg, false, new ArrayList(), initScope + 1, false, 0, isInterface ? null : name, extendsVal != null ? extendsVal.toString() : null, true, localData, new ArrayList(), new ArrayList(), new ArrayList(), new ArrayList(), TypeItem.UNBOUNDED/*?? FIXME*/); } else { MethodAVM2Item m = (MethodAVM2Item) constructor; - instanceInfo.iinit_index = init = method(false, new ArrayList(), pkg.packageName, m.needsActivation, m.subvariables, initScope + 1, m.hasRest, m.line, name, extendsVal != null ? extendsVal.toString() : null, true, localData, m.paramTypes, m.paramNames, m.paramValues, m.body, TypeItem.UNBOUNDED/*?? FIXME*/); + instanceInfo.iinit_index = init = method(false, new ArrayList(), pkg, m.needsActivation, m.subvariables, initScope + 1, m.hasRest, m.line, name, extendsVal != null ? extendsVal.toString() : null, true, localData, m.paramTypes, m.paramNames, m.paramValues, m.body, TypeItem.UNBOUNDED/*?? FIXME*/); } //Class initializer - int staticMi = method(false, new ArrayList(), pkg.packageName, staticNeedsActivation, sinitVariables, initScope + 1 + (implementsStr.isEmpty() ? 0 : 1), false, 0, isInterface ? null : name, superName, false, localData, new ArrayList(), new ArrayList(), new ArrayList(), staticInit, TypeItem.UNBOUNDED); + int staticMi = method(false, new ArrayList(), pkg, staticNeedsActivation, sinitVariables, initScope + (implementsStr.isEmpty() ? 0 : 1), false, 0, isInterface ? null : name, superName, false, localData, new ArrayList(), new ArrayList(), new ArrayList(), staticInit, TypeItem.UNBOUNDED); MethodBody sinitBody = abc.findBody(staticMi); List sinitcode = new ArrayList<>(); @@ -1240,7 +1243,7 @@ public class AVM2SourceGenerator implements SourceGenerator { } } sinitBody.markOffsets(); - sinitBody.autoFillStats(abc, initScope + 1 + (implementsStr.isEmpty() ? 0 : 1), true); + sinitBody.autoFillStats(abc, initScope + (implementsStr.isEmpty() ? 0 : 1), true); classInfo.cinit_index = staticMi; if (!isInterface) { @@ -1249,8 +1252,8 @@ public class AVM2SourceGenerator implements SourceGenerator { instanceInfo.interfaces = new int[implementsStr.size()]; for (int i = 0; i < implementsStr.size(); i++) { instanceInfo.interfaces[i] = superIntName(localData,implementsStr.get(i)); - } - + } + instanceInfo.name_index = traitName(namespace, name); } @Override @@ -1268,7 +1271,7 @@ public class AVM2SourceGenerator implements SourceGenerator { return ret; } - public int generateClass(int namespace, ClassInfo ci, InstanceInfo ii, int initScope, PackageAVM2Item pkg, SourceGeneratorLocalData localData, AVM2Item cls) throws ParseException, CompilationException { + public int generateClass(int namespace, ClassInfo ci, InstanceInfo ii, int initScope, String pkg, SourceGeneratorLocalData localData, AVM2Item cls) throws ParseException, CompilationException { /*ClassInfo ci = new ClassInfo(); InstanceInfo ii = new InstanceInfo(); abc.class_info.add(ci); @@ -1276,7 +1279,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 == null ? "Object" : cai.extendsOp.toString(), cai.extendsOp, cai.implementsOp, cai.constructor, cai.traits); + generateClass(cai.importedClasses,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; } @@ -1290,7 +1293,7 @@ public class AVM2SourceGenerator implements SourceGenerator { InterfaceAVM2Item iai = (InterfaceAVM2Item) cls; ii.flags |= InstanceInfo.CLASS_INTERFACE; ii.flags |= InstanceInfo.CLASS_SEALED; - generateClass(new ArrayList(), false, new ArrayList(), iai.openedNamespaces, namespace, initScope, pkg, ci, ii, localData, true, iai.name, null, null, iai.superInterfaces, null, iai.methods); + generateClass(iai.importedClasses,new ArrayList(), false, new ArrayList(), iai.openedNamespaces, namespace, initScope, pkg, ci, ii, localData, true, iai.name, null, null, iai.superInterfaces, null, iai.methods); } return abc.instance_info.size() - 1; @@ -1392,7 +1395,7 @@ public class AVM2SourceGenerator implements SourceGenerator { if (an instanceof UnresolvedAVM2Item) { UnresolvedAVM2Item n = (UnresolvedAVM2Item) an; if (n.resolved == null) { - String fullClass = localData.currentClass == null ? null : (localData.pkg.isEmpty() ? localData.currentClass : localData.pkg + "." + localData.currentClass); + String fullClass = localData.currentClass == null ? null : (localData.pkg==null||pkg.isEmpty() ? localData.currentClass : localData.pkg + "." + localData.currentClass); GraphTargetItem res = n.resolve(new TypeItem(fullClass), paramTypes, paramNames, abc, allABCs, callStack, subvariables); if (res instanceof AssignableAVM2Item) { subvariables.set(i, (AssignableAVM2Item) res); @@ -1413,7 +1416,7 @@ public class AVM2SourceGenerator implements SourceGenerator { List registerNames = new ArrayList<>(); List registerTypes = new ArrayList<>(); if (className != null) { - String fullClassName = pkg.isEmpty() ? className : pkg + "." + className; + String fullClassName = pkg==null||pkg.isEmpty() ? className : pkg + "." + className; registerTypes.add(fullClassName); localData.scopeStack.add(new LocalRegAVM2Item(null, registerNames.size(), null)); registerNames.add("this"); @@ -1740,7 +1743,7 @@ public class AVM2SourceGenerator implements SourceGenerator { return mindex; } - public ValueKind getValueKind(int nsKind, GraphTargetItem type, GraphTargetItem val) { + public ValueKind getValueKind(int ns, GraphTargetItem type, GraphTargetItem val) { if (val instanceof BooleanAVM2Item) { BooleanAVM2Item bi = (BooleanAVM2Item) val; @@ -1765,7 +1768,7 @@ public class AVM2SourceGenerator implements SourceGenerator { if (val instanceof StringAVM2Item) { StringAVM2Item sval = (StringAVM2Item) val; if (isNs) { - return new ValueKind(namespace(nsKind, sval.value), Namespace.KIND_NAMESPACE); + return new ValueKind(namespace(abc.constants.constant_namespace.get(ns).kind, sval.value), Namespace.KIND_NAMESPACE); } else { return new ValueKind(str(sval.value), ValueKind.CONSTANT_Utf8); } @@ -1776,26 +1779,57 @@ public class AVM2SourceGenerator implements SourceGenerator { if (val instanceof FloatValueAVM2Item) { return new ValueKind(abc.constants.getDoubleId(((FloatValueAVM2Item) val).value, true), ValueKind.CONSTANT_Double); } + if(val instanceof NanAVM2Item){ + return new ValueKind(abc.constants.getDoubleId(Double.NaN, true), ValueKind.CONSTANT_Double); + } if (val instanceof NullAVM2Item) { return new ValueKind(0, ValueKind.CONSTANT_Null); } if (val instanceof UndefinedAVM2Item) { return new ValueKind(0, ValueKind.CONSTANT_Undefined); - } + } return null; } - private int genNs(String pkg, String custom, int namespace, List openedNamespaces, SourceGeneratorLocalData localData, int line) throws CompilationException { + private int genNs(List importedClasses,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); + Reference value = new Reference<>(null); prop.resolve(localData, new Reference(null), new Reference(null), new Reference(0), value); boolean resolved = true; if (value.getVal() == null) { resolved = false; - } if (!resolved) { + + String customPkg = ""; + String fullCustom = ""; + for(String imp:importedClasses){ + if(imp.endsWith("."+custom)){ + customPkg = imp.substring(0,imp.lastIndexOf(".")); + fullCustom = imp; + break; + } + } + + List aas=new ArrayList<>(); + aas.add(abc); + aas.addAll(allABCs); + for(ABC a:aas){ + for(ScriptInfo si:a.script_info){ + for(Trait t:si.traits.traits){ + Multiname m = t.getName(a); + if(fullCustom.equals(m.getNameWithNamespace(a.constants))){ + if(t instanceof TraitSlotConst){ + if(((TraitSlotConst)t).isNamespace()){ + return ((TraitSlotConst)t).value_index; + } + } + } + } + } + } + throw new CompilationException("Namespace not defined", line); } namespace = value.getVal().value_index; @@ -1803,7 +1837,7 @@ public class AVM2SourceGenerator implements SourceGenerator { return namespace; } - public void generateTraitsPhase2(String pkg, List items, Trait[] traits, List openedNamespaces, SourceGeneratorLocalData localData) throws CompilationException { + public void generateTraitsPhase2(List importedClasses, String pkg, List items, Trait[] traits, List openedNamespaces, SourceGeneratorLocalData localData) throws CompilationException { for (int k = 0; k < items.size(); k++) { GraphTargetItem item = items.get(k); if (traits[k] == null) { @@ -1813,13 +1847,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(importedClasses,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(importedClasses,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(importedClasses,pkg, ((SlotAVM2Item) item).customNamespace, ((SlotAVM2Item) item).getNamespace(), openedNamespaces, localData, ((SlotAVM2Item) item).line), ((SlotAVM2Item) item).var); } } @@ -1872,7 +1906,7 @@ public class AVM2SourceGenerator implements SourceGenerator { } - public void generateTraitsPhase3(boolean isInterface, int initScope, PackageAVM2Item pkg, String className, String superName, boolean generateStatic, SourceGeneratorLocalData localData, List items, Traits ts, Trait[] traits) throws ParseException, CompilationException { + public void generateTraitsPhase3(int methodInitScope,boolean isInterface, String className, String superName, boolean generateStatic, SourceGeneratorLocalData localData, List items, Traits ts, Trait[] traits,Map initScopes) throws ParseException, CompilationException { //Note: Names must be generated first before accesed in inner subs for (int k = 0; k < items.size(); k++) { GraphTargetItem item = items.get(k); @@ -1880,26 +1914,26 @@ public class AVM2SourceGenerator implements SourceGenerator { continue; } if (item instanceof InterfaceAVM2Item) { - generateClass(((InterfaceAVM2Item) item).namespace, abc.class_info.get(((TraitClass) traits[k]).class_info), abc.instance_info.get(((TraitClass) traits[k]).class_info), initScope, pkg, localData, (InterfaceAVM2Item) item); + generateClass(((InterfaceAVM2Item) item).namespace, abc.class_info.get(((TraitClass) traits[k]).class_info), abc.instance_info.get(((TraitClass) traits[k]).class_info), initScopes.get(traits[k]), ((InterfaceAVM2Item)item).pkg, localData, (InterfaceAVM2Item) item); } if (item instanceof ClassAVM2Item) { - generateClass(((ClassAVM2Item) item).namespace, abc.class_info.get(((TraitClass) traits[k]).class_info), abc.instance_info.get(((TraitClass) traits[k]).class_info), initScope, pkg, localData, (ClassAVM2Item) item); + generateClass(((ClassAVM2Item) item).namespace, abc.class_info.get(((TraitClass) traits[k]).class_info), abc.instance_info.get(((TraitClass) traits[k]).class_info), initScopes.get(traits[k]), ((ClassAVM2Item)item).pkg, localData, (ClassAVM2Item) item); } if ((item instanceof MethodAVM2Item) || (item instanceof GetterAVM2Item) || (item instanceof SetterAVM2Item)) { MethodAVM2Item mai = (MethodAVM2Item) item; if (mai.isStatic() != generateStatic) { continue; } - ((TraitMethodGetterSetter) traits[k]).method_info = method(isInterface, new ArrayList(), pkg.packageName, mai.needsActivation, mai.subvariables, initScope + (mai.isStatic() ? 0 : 1), mai.hasRest, mai.line, className, superName, false, localData, mai.paramTypes, mai.paramNames, mai.paramValues, mai.body, mai.retType); + ((TraitMethodGetterSetter) traits[k]).method_info = method(isInterface, new ArrayList(), mai.pkg, mai.needsActivation, mai.subvariables, methodInitScope + (mai.isStatic() ? 0 : 1), mai.hasRest, mai.line, className, superName, false, localData, mai.paramTypes, mai.paramNames, mai.paramValues, mai.body, mai.retType); } else if (item instanceof FunctionAVM2Item) { FunctionAVM2Item fai = (FunctionAVM2Item) item; - ((TraitFunction) traits[k]).method_info = method(isInterface, new ArrayList(), pkg.packageName, fai.needsActivation, fai.subvariables, initScope, fai.hasRest, fai.line, className, superName, false, localData, fai.paramTypes, fai.paramNames, fai.paramValues, fai.body, fai.retType); + ((TraitFunction) traits[k]).method_info = method(isInterface, new ArrayList(), fai.pkg, fai.needsActivation, fai.subvariables, methodInitScope, fai.hasRest, fai.line, className, superName, false, localData, fai.paramTypes, fai.paramNames, fai.paramValues, fai.body, fai.retType); } } } - public Trait[] generateTraitsPhase1(PackageAVM2Item pkg, String className, String superName, boolean generateStatic, SourceGeneratorLocalData localData, List items, Traits ts) throws ParseException, CompilationException { + public Trait[] generateTraitsPhase1(String className, String superName, boolean generateStatic, SourceGeneratorLocalData localData, List items, Traits ts) throws ParseException, CompilationException { Trait[] traits = new Trait[items.size()]; int slot_id = 1; int disp_id = 3; //1 and 2 are for constructor @@ -1980,8 +2014,8 @@ public class AVM2SourceGenerator implements SourceGenerator { tsc.name_index = traitName(namespace, var); } tsc.type_index = isNamespace ? 0 : (type == null ? 0 : typeName(localData, type)); - - ValueKind vk = getValueKind(abc.constants.constant_namespace.get(namespace).kind, type, val); + + ValueKind vk = getValueKind(namespace, type, val); if (vk == null) { tsc.value_kind = ValueKind.CONSTANT_Undefined; } else { @@ -2023,11 +2057,11 @@ public class AVM2SourceGenerator implements SourceGenerator { return traits; } - public ScriptInfo generateScriptInfo(PackageAVM2Item pkg, SourceGeneratorLocalData localData, List commands) throws ParseException, CompilationException { + public ScriptInfo generateScriptInfo(SourceGeneratorLocalData localData, List commands) throws ParseException, CompilationException { ScriptInfo si = new ScriptInfo(); localData.currentScript = si; - Trait[] traitArr = generateTraitsPhase1(pkg, null, null, false, localData, commands, si.traits); - generateTraitsPhase2(pkg.packageName, commands, traitArr, new ArrayList(), localData); + Trait[] traitArr = generateTraitsPhase1(null, null, false, localData, commands, si.traits); + generateTraitsPhase2(new ArrayList(),null/*FIXME*/, commands, traitArr, new ArrayList(), localData); MethodInfo mi = new MethodInfo(new int[0], 0, 0, 0, new ValueKind[0], new int[0]); MethodBody mb = new MethodBody(); mb.method_info = abc.addMethodInfo(mi); @@ -2037,6 +2071,8 @@ public class AVM2SourceGenerator implements SourceGenerator { int traitScope = 1; + Map initScopes = new HashMap<>(); + for (Trait t : si.traits.traits) { if (t instanceof TraitClass) { TraitClass tc = (TraitClass) t; @@ -2067,6 +2103,8 @@ public class AVM2SourceGenerator implements SourceGenerator { } } mb.code.code.add(ins(new InitPropertyIns(), tc.name_index)); + initScopes.put(t, traitScope); + traitScope = 1; } } @@ -2074,8 +2112,8 @@ public class AVM2SourceGenerator implements SourceGenerator { mb.autoFillStats(abc, localData.documentClass ? 1 : 0, false); abc.addMethodBody(mb); si.init_index = mb.method_info; - localData.pkg = pkg.packageName; - generateTraitsPhase3(false, traitScope, pkg, null, null, false, localData, commands, si.traits, traitArr); + localData.pkg = null; //FIXME: pkg.packageName; + generateTraitsPhase3(1/*??*/,false, null, null, false, localData, commands, si.traits, traitArr,initScopes); return si; } @@ -2124,13 +2162,26 @@ public class AVM2SourceGenerator implements SourceGenerator { return TypeItem.UNBOUNDED; } + private static boolean eq(Object a,Object b){ + if(a==null && b==null){ + return true; + } + if(a == null){ + return false; + } + if(b == null){ + return false; + } + return a.equals(b); + } + 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) { for (ScriptInfo ii : abc.script_info) { for (Trait t : ii.traits.traits) { - if (pkg.equals(t.getName(abc).getNamespace(abc.constants).getName(abc.constants))) { + if (eq(pkg,t.getName(abc).getNamespace(abc.constants).getName(abc.constants))) { if (propertyName.equals(t.getName(abc).getName(abc.constants, new ArrayList()))) { outName.setVal(obj); outNs.setVal(pkg); @@ -2151,7 +2202,7 @@ public class AVM2SourceGenerator implements SourceGenerator { InstanceInfo ii = abc.instance_info.get(i); Multiname clsName = ii.getName(abc.constants); if (obj.equals(clsName.getName(abc.constants, new ArrayList()))) { - if (pkg.equals(clsName.getNamespace(abc.constants).getName(abc.constants))) { + if (eq(pkg,clsName.getNamespace(abc.constants).getName(abc.constants))) { //class found for (Trait t : ii.instance_traits.traits) { @@ -2219,9 +2270,10 @@ public class AVM2SourceGenerator implements SourceGenerator { for (ABC a : abcs) { for (int i = 0; i < a.instance_info.size(); i++) { - Multiname m = a.constants.constant_multiname.get(a.instance_info.get(i).name_index); + Multiname m = a.constants.constant_multiname.get(a.instance_info.get(i).name_index); if (m.getName(a.constants, new ArrayList()).equals(mname.getName(abc.constants, new ArrayList()))) { - if (m.getNamespace(a.constants).getName(a.constants).equals(mname.getNamespace(abc.constants).getName(abc.constants))) { + + if (m.getNamespace(a.constants).hasName(a.constants,mname.getNamespace(abc.constants).getName(abc.constants))) { //Multiname superName = a.constants.constant_multiname.get(a.instance_info.get(i).super_index); abcs.remove(a); if (a.instance_info.get(i).super_index != 0) { @@ -2288,7 +2340,7 @@ public class AVM2SourceGenerator implements SourceGenerator { if (item instanceof UnresolvedAVM2Item) { - String fullClass = localData.currentClass == null ? null : (localData.pkg.isEmpty() ? localData.currentClass : localData.pkg + "." + localData.currentClass); + String fullClass = localData.currentClass == null ? null : (localData.pkg==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) { @@ -2299,7 +2351,7 @@ public class AVM2SourceGenerator implements SourceGenerator { 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); + String fullClass = localData.currentClass == null ? null : (localData.pkg==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()); } @@ -2317,7 +2369,7 @@ public class AVM2SourceGenerator implements SourceGenerator { } for (InstanceInfo ii : abc.instance_info) { Multiname mname = abc.constants.constant_multiname.get(ii.name_index); - if (mname.getName(abc.constants, new ArrayList()).equals(name)) { + if (mname!=null && name.equals(mname.getName(abc.constants, new ArrayList()))) { if (mname.getNamespace(abc.constants).hasName(pkg, abc.constants)) { name_index = ii.name_index; break; @@ -2326,15 +2378,25 @@ 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!=null && name.equals(mname.getName(abc.constants, new ArrayList()))) { if (mname.getNamespace(abc.constants) != null && pkg.equals(mname.getNamespace(abc.constants).getName(abc.constants))) { name_index = i; break; } } } - 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 (name_index == 0) { + if(pkg.equals("") && localData.currentScript!=null /*FIXME!*/){ + for(Trait t:localData.currentScript.traits.traits){ + if(t.getName(abc).getName(abc.constants, new ArrayList()).equals(name)){ + name_index = t.name_index; + break; + } + } + } + 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 (item instanceof ApplyTypeAVM2Item) { 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 dd2f91186..78d36d4f0 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 @@ -69,6 +69,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.operations.LeAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.operations.LtAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.operations.ModuloAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.operations.MultiplyAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.operations.NegAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.operations.NeqAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.operations.PreDecrementAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.operations.PreIncrementAVM2Item; @@ -139,13 +140,13 @@ public class ActionScriptParser { return uniqLast; } - private List commands(Reference needsActivation, List importedClasses, List openedNamespaces, Stack loops, Map loopLabels, HashMap registerVars, boolean inFunction, boolean inMethod, int forinlevel, List variables) throws IOException, ParseException { + private List commands(String pkg,Reference needsActivation, List importedClasses, List openedNamespaces, Stack loops, Map loopLabels, HashMap registerVars, boolean inFunction, boolean inMethod, int forinlevel, List variables) throws IOException, ParseException { List ret = new ArrayList<>(); if (debugMode) { System.out.println("commands:"); } GraphTargetItem cmd = null; - while ((cmd = command(needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)) != null) { + while ((cmd = command(pkg,needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)) != null) { ret.add(cmd); } if (debugMode) { @@ -154,7 +155,7 @@ public class ActionScriptParser { return ret; } - private GraphTargetItem type(Reference needsActivation, List importedClasses, List openedNamespaces, List variables) throws IOException, ParseException { + private GraphTargetItem type(String pkg,Reference needsActivation, List importedClasses, List openedNamespaces, List variables) throws IOException, ParseException { ParsedSymbol s = lex(); if (s.type == SymbolType.MULTIPLY) { return new UnboundedTypeItem(); @@ -164,12 +165,12 @@ public class ActionScriptParser { lexer.pushback(s); } - GraphTargetItem t = name(needsActivation, true, openedNamespaces, null, false, false, variables, importedClasses); - t = applyType(needsActivation, importedClasses, openedNamespaces, t, new HashMap(), false,false, variables); + GraphTargetItem t = name(pkg,needsActivation, true, openedNamespaces, null, false, false, variables, importedClasses); + t = applyType(pkg,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 { + private GraphTargetItem memberOrCall(String pkg,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, SymbolType.BRACKET_OPEN, SymbolType.TYPENAME)) { @@ -178,10 +179,10 @@ public class ActionScriptParser { case DOT: case TYPENAME: lexer.pushback(s); - ret = member(needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables); + ret = member(pkg,needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables); break; case PARENT_OPEN: - ret = new CallAVM2Item(lexer.yyline(), ret, call(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables)); + ret = new CallAVM2Item(lexer.yyline(), ret, call(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables)); break; } @@ -205,34 +206,34 @@ 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 { + + private GraphTargetItem applyType(String pkg,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)); + if (s.type == SymbolType.TYPENAME) { + List params = new ArrayList<>(); + do { + params.add(expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); s = lex(); - }while(s.type == SymbolType.COMMA); - if(s.type == SymbolType.USHIFT_RIGHT){ + } 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){ + if (s.type == SymbolType.SHIFT_RIGHT) { s = new ParsedSymbol(SymbolGroup.OPERATOR, SymbolType.GREATER_THAN); lexer.pushback(s); } - expected(s,lexer.yyline(),SymbolType.GREATER_THAN); + expected(s, lexer.yyline(), SymbolType.GREATER_THAN); ret = new ApplyTypeAVM2Item(null, ret, params); - }else{ + } 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 { + private GraphTargetItem member(String pkg,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, SymbolType.TYPENAME)) { @@ -249,13 +250,12 @@ public class ActionScriptParser { } else { lexer.pushback(s2); } - if(s.type == SymbolType.TYPENAME){ + if (s.type == SymbolType.TYPENAME) { lexer.pushback(s); - ret = applyType(needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables); + ret = applyType(pkg,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); + } else if (s.type == SymbolType.BRACKET_OPEN) { + GraphTargetItem index = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); expectedType(SymbolType.BRACKET_CLOSE); ret = new IndexAVM2Item(attr, ret, index, null, openedNamespaces); s = lex(); @@ -271,7 +271,7 @@ public class ActionScriptParser { variables.add((UnresolvedAVM2Item) ns); s = lex(); if (s.type == SymbolType.BRACKET_OPEN) { - propItem = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); + propItem = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); expectedType(SymbolType.BRACKET_CLOSE); propName = null; } else { @@ -294,7 +294,7 @@ public class ActionScriptParser { return ret; } - private GraphTargetItem name(Reference needsActivation, boolean typeOnly, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, List variables, List importedClasses) throws IOException, ParseException { + private GraphTargetItem name(String pkg,Reference needsActivation, boolean typeOnly, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, List variables, List importedClasses) throws IOException, ParseException { ParsedSymbol s = lex(); String name = ""; if (s.type == SymbolType.ATTRIBUTE) { @@ -342,7 +342,7 @@ public class ActionScriptParser { if (s.type == SymbolType.IDENTIFIER) { nsprop = s.value.toString(); } else if (s.type == SymbolType.BRACKET_OPEN) { - nspropItem = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); + nspropItem = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); expectedType(SymbolType.BRACKET_CLOSE); } if (name.contains(".")) { @@ -352,28 +352,26 @@ public class ActionScriptParser { } s = lex(); } -/* - List params = new ArrayList<>(); - if (s.type == SymbolType.TYPENAME) { - s = lex(); - do { - String p = ""; - expected(s, lexer.yyline(), SymbolType.IDENTIFIER); - p = s.value.toString(); - s = lex(); - while (s.type == SymbolType.DOT) { - s = lex(); - expected(s, lexer.yyline(), SymbolType.IDENTIFIER); - name += "." + s.value.toString(); - s = lex(); - } - params.add(p); - } while (s.type == SymbolType.COMMA); - expected(s, lexer.yyline(), SymbolType.GREATER_THAN); - s = lex(); - }*/ - - + /* + List params = new ArrayList<>(); + if (s.type == SymbolType.TYPENAME) { + s = lex(); + do { + String p = ""; + expected(s, lexer.yyline(), SymbolType.IDENTIFIER); + p = s.value.toString(); + s = lex(); + while (s.type == SymbolType.DOT) { + s = lex(); + expected(s, lexer.yyline(), SymbolType.IDENTIFIER); + name += "." + s.value.toString(); + s = lex(); + } + params.add(p); + } while (s.type == SymbolType.COMMA); + expected(s, lexer.yyline(), SymbolType.GREATER_THAN); + s = lex(); + }*/ GraphTargetItem ret = null; if (name != null) { @@ -397,7 +395,7 @@ public class ActionScriptParser { lexer.pushback(new ParsedSymbol(SymbolGroup.OPERATOR, SymbolType.ATTRIBUTE, "@")); lexer.pushback(new ParsedSymbol(SymbolGroup.OPERATOR, SymbolType.DOT, ".")); } - ret = member(needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables); + ret = member(pkg,needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables); } else { lexer.pushback(s); } @@ -442,7 +440,7 @@ public class ActionScriptParser { return ret; } - private List call(Reference needsActivation, List importedClasses, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, List variables) throws IOException, ParseException { + private List call(String pkg,Reference needsActivation, List importedClasses, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, List variables) throws IOException, ParseException { List ret = new ArrayList<>(); //expected(SymbolType.PARENT_OPEN); //MUST BE HANDLED BY CALLER ParsedSymbol s = lex(); @@ -450,19 +448,19 @@ public class ActionScriptParser { if (s.type != SymbolType.COMMA) { lexer.pushback(s); } - ret.add(expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); + ret.add(expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); s = lex(); expected(s, lexer.yyline(), SymbolType.COMMA, SymbolType.PARENT_CLOSE); } return ret; } - private MethodAVM2Item method(boolean isInterface, String customAccess, Reference needsActivation, List importedClasses, boolean override, boolean isFinal, GraphTargetItem thisType, List openedNamespaces, boolean isStatic, int namespace, String functionName, boolean isMethod, List variables) throws IOException, ParseException { - FunctionAVM2Item f = function(isInterface, needsActivation, importedClasses, namespace, thisType, openedNamespaces, functionName, isMethod, variables); - return new MethodAVM2Item(f.isInterface, customAccess, f.needsActivation, f.hasRest, f.line, override, isFinal, isStatic, f.namespace, functionName, f.paramTypes, f.paramNames, f.paramValues, f.body, f.subvariables, f.retType); + private MethodAVM2Item method(String pkg,boolean isInterface, String customAccess, Reference needsActivation, List importedClasses, boolean override, boolean isFinal, GraphTargetItem thisType, List openedNamespaces, boolean isStatic, int namespace, String functionName, boolean isMethod, List variables) throws IOException, ParseException { + FunctionAVM2Item f = function(pkg,isInterface, needsActivation, importedClasses, namespace, thisType, openedNamespaces, functionName, isMethod, variables); + return new MethodAVM2Item(f.pkg,f.isInterface, customAccess, f.needsActivation, f.hasRest, f.line, override, isFinal, isStatic, f.namespace, functionName, f.paramTypes, f.paramNames, f.paramValues, f.body, f.subvariables, f.retType); } - private FunctionAVM2Item function(boolean isInterface, Reference needsActivation, List importedClasses, int namespace, GraphTargetItem thisType, List openedNamespaces, String functionName, boolean isMethod, List variables) throws IOException, ParseException { + private FunctionAVM2Item function(String pkg,boolean isInterface, Reference needsActivation, List importedClasses, int namespace, GraphTargetItem thisType, List openedNamespaces, String functionName, boolean isMethod, List variables) throws IOException, ParseException { openedNamespaces = new ArrayList<>(openedNamespaces); //local copy int line = lexer.yyline(); ParsedSymbol s; @@ -487,13 +485,13 @@ public class ActionScriptParser { s = lex(); if (!hasRest) { if (s.type == SymbolType.COLON) { - paramTypes.add(type(needsActivation, importedClasses, openedNamespaces, variables)); + paramTypes.add(type(pkg,needsActivation, importedClasses, openedNamespaces, variables)); s = lex(); } else { paramTypes.add(new UnboundedTypeItem()); } if (s.type == SymbolType.ASSIGN) { - paramValues.add(expression(new Reference(false), importedClasses, openedNamespaces, null, isMethod, isMethod, isMethod, variables)); + paramValues.add(expression(pkg,new Reference(false), importedClasses, openedNamespaces, null, isMethod, isMethod, isMethod, variables)); s = lex(); } else { if (!paramValues.isEmpty()) { @@ -512,7 +510,7 @@ public class ActionScriptParser { s = lex(); GraphTargetItem retType; if (s.type == SymbolType.COLON) { - retType = type(needsActivation, importedClasses, openedNamespaces, variables); + retType = type(pkg,needsActivation, importedClasses, openedNamespaces, variables); } else { retType = new UnboundedTypeItem(); lexer.pushback(s); @@ -531,7 +529,7 @@ public class ActionScriptParser { Reference needsActivation2 = new Reference<>(false); if (!isInterface) { expectedType(SymbolType.CURLY_OPEN); - body = commands(needsActivation2, importedClasses, openedNamespaces, new Stack(), new HashMap(), new HashMap(), true, isMethod, 0, subvariables); + body = commands(pkg,needsActivation2, importedClasses, openedNamespaces, new Stack(), new HashMap(), new HashMap(), true, isMethod, 0, subvariables); expectedType(SymbolType.CURLY_CLOSE); } else { expectedType(SymbolType.SEMICOLON); @@ -540,14 +538,17 @@ public class ActionScriptParser { for (int i = 0; i < parCnt; i++) { subvariables.remove(0); } - return new FunctionAVM2Item(isInterface, needsActivation2.getVal(), namespace, hasRest, line, functionName, paramTypes, paramNames, paramValues, body, subvariables, retType); + return new FunctionAVM2Item(pkg,isInterface, needsActivation2.getVal(), namespace, hasRest, line, functionName, paramTypes, paramNames, paramValues, body, subvariables, retType); } - private GraphTargetItem traits(List sinitVariables, Reference sinitNeedsActivation, List staticInitializer, List importedClasses, int privateNs, int protectedNs, int publicNs, int packageInternalNs, int protectedStaticNs, List openedNamespaces, String packageName, String classNameStr, boolean isInterface, List traits) throws ParseException, IOException, CompilationException { + private GraphTargetItem traits(String scriptName,boolean scriptTraits, List sinitVariables, Reference sinitNeedsActivation, List staticInitializer, List importedClasses, int privateNs, int protectedNs, int publicNs, int packageInternalNs, int protectedStaticNs, List openedNamespaces, String pkg, String classNameStr, boolean isInterface, List traits) throws ParseException, IOException, CompilationException { ParsedSymbol s; GraphTargetItem constr = null; - TypeItem thisType = new TypeItem("".equals(packageName) ? classNameStr : packageName + "." + classNameStr); - List constrVariables = new ArrayList<>(); + TypeItem thisType = pkg==null && classNameStr == null?null:new TypeItem(pkg == null || "".equals(pkg) ? classNameStr : pkg + "." + classNameStr); + List constrVariables = new ArrayList<>(); + List originalOpenedNamespaces=openedNamespaces; + int originalPrivateNs = privateNs; + boolean inPkg = pkg!=null; looptrait: while (true) { s = lex(); @@ -560,71 +561,89 @@ public class ActionScriptParser { boolean isDynamic = false; String customAccess = null; - if (s.type == SymbolType.CURLY_OPEN) { - staticInitializer.addAll(commands(sinitNeedsActivation, importedClasses, openedNamespaces, new Stack(), new HashMap(), new HashMap(), true, false, 0, sinitVariables)); - expectedType(SymbolType.CURLY_CLOSE); + if(scriptTraits && s.type == SymbolType.PACKAGE){ + if(inPkg){ + throw new ParseException("No subpackages allowed", lexer.yyline()); + } + openedNamespaces = new ArrayList<>(); + lexer.pushback(s); + PackageAVM2Item p=parsePackage(openedNamespaces); + pkg = p.packageName; + inPkg = true; + publicNs = p.publicNs; + importedClasses = p.importedClasses; s = lex(); } - while (s.isType(SymbolType.STATIC, SymbolType.PUBLIC, SymbolType.PRIVATE, SymbolType.PROTECTED, SymbolType.OVERRIDE, SymbolType.FINAL, SymbolType.DYNAMIC, SymbolType.IDENTIFIER)) { - if (s.type == SymbolType.FINAL) { - if (isFinal) { - throw new ParseException("Only one final keyword allowed", lexer.yyline()); - } - isFinal = true; - } else if (s.type == SymbolType.DYNAMIC) { - if (isDynamic) { - throw new ParseException("Only one dynamic keyword allowed", lexer.yyline()); - } - isDynamic = true; - } else if (s.type == SymbolType.OVERRIDE) { - if (isOverride) { - throw new ParseException("Only one override keyword allowed", lexer.yyline()); - } - isOverride = true; - } else if (s.type == SymbolType.STATIC) { - if (isInterface) { - throw new ParseException("Interface cannot have static traits", lexer.yyline()); - } - if (classNameStr == null) { - throw new ParseException("No static keyword allowed here", lexer.yyline()); - } - if (isStatic) { - throw new ParseException("Only one static keyword allowed", lexer.yyline()); - } - isStatic = true; - } else if (s.type == SymbolType.IDENTIFIER) { - customAccess = s.value.toString(); - namespace = -2; - } else { - if (namespace != -1) { - throw new ParseException("Only one access identifier allowed", lexer.yyline()); - } + if (inPkg || classNameStr!=null) { + if (s.type == SymbolType.CURLY_OPEN) { + staticInitializer.addAll(commands(pkg,sinitNeedsActivation, importedClasses, openedNamespaces, new Stack(), new HashMap(), new HashMap(), true, false, 0, sinitVariables)); + expectedType(SymbolType.CURLY_CLOSE); + s = lex(); } - switch (s.type) { - case PUBLIC: - namespace = publicNs; - if (isInterface) { - throw new ParseException("Interface cannot have public, private or protected modifier", lexer.yyline()); + + while (s.isType(SymbolType.STATIC, SymbolType.PUBLIC, SymbolType.PRIVATE, SymbolType.PROTECTED, SymbolType.OVERRIDE, SymbolType.FINAL, SymbolType.DYNAMIC, SymbolType.IDENTIFIER)) { + if (s.type == SymbolType.FINAL) { + if (isFinal) { + throw new ParseException("Only one final keyword allowed", lexer.yyline()); } - break; - case PRIVATE: - namespace = privateNs; - if (isInterface) { - throw new ParseException("Interface cannot have public, private or protected modifier", lexer.yyline()); + isFinal = true; + } else if (s.type == SymbolType.DYNAMIC) { + if (isDynamic) { + throw new ParseException("Only one dynamic keyword allowed", lexer.yyline()); } - break; - case PROTECTED: - namespace = protectedNs; - if (isInterface) { - throw new ParseException("Interface cannot have public, private or protected modifier", lexer.yyline()); + isDynamic = true; + } else if (s.type == SymbolType.OVERRIDE) { + if (isOverride) { + throw new ParseException("Only one override keyword allowed", lexer.yyline()); } - break; + isOverride = true; + } else if (s.type == SymbolType.STATIC) { + if (isInterface) { + throw new ParseException("Interface cannot have static traits", lexer.yyline()); + } + if (classNameStr == null) { + throw new ParseException("No static keyword allowed here", lexer.yyline()); + } + if (isStatic) { + throw new ParseException("Only one static keyword allowed", lexer.yyline()); + } + isStatic = true; + } else if (s.type == SymbolType.IDENTIFIER) { + customAccess = s.value.toString(); + namespace = -2; + } else { + if (namespace != -1) { + throw new ParseException("Only one access identifier allowed", lexer.yyline()); + } + } + switch (s.type) { + case PUBLIC: + namespace = publicNs; + if (isInterface) { + throw new ParseException("Interface cannot have public, private or protected modifier", lexer.yyline()); + } + break; + case PRIVATE: + namespace = privateNs; + if (isInterface) { + throw new ParseException("Interface cannot have public, private or protected modifier", lexer.yyline()); + } + break; + case PROTECTED: + namespace = protectedNs; + if (isInterface) { + throw new ParseException("Interface cannot have public, private or protected modifier", lexer.yyline()); + } + break; + } + s = lex(); } - s = lex(); + } else { + namespace = privateNs; } if (namespace == -1) { if (isInterface) { - namespace = abc.constants.getNamespaceId(new Namespace(Namespace.KIND_NAMESPACE, abc.constants.getStringId(packageName.isEmpty() ? classNameStr : packageName + ":" + classNameStr, true)), 0, true); + namespace = abc.constants.getNamespaceId(new Namespace(Namespace.KIND_NAMESPACE, abc.constants.getStringId(pkg==null||pkg.isEmpty() ? classNameStr : pkg + ":" + classNameStr, true)), 0, true); } else { namespace = packageInternalNs; } @@ -633,7 +652,12 @@ public class ActionScriptParser { namespace = protectedStaticNs; } switch (s.type) { + /*case PACKAGE: + lexer.pushback(s); + traits.add(parsePackage(openedNamespaces)); + break;*/ case CLASS: + List subNamespaces=new ArrayList<>(openedNamespaces); if (classNameStr != null) { throw new ParseException("Nested classes not supported", lexer.yyline()); } @@ -641,20 +665,20 @@ public class ActionScriptParser { throw new ParseException("Override flag not allowed for classes", lexer.yyline()); } - //GraphTargetItem classTypeStr = type(needsActivation, importedClasses, openedNamespaces, variables); + //GraphTargetItem classTypeStr = type(pkg,needsActivation, importedClasses, openedNamespaces, variables); s = lex(); expected(s, lexer.yyline(), SymbolType.IDENTIFIER); String classTypeStr = s.value.toString(); GraphTargetItem extendsTypeStr = null; s = lex(); if (s.type == SymbolType.EXTENDS) { - extendsTypeStr = type(new Reference(false), importedClasses, openedNamespaces, new ArrayList()); + extendsTypeStr = type(pkg,new Reference(false), importedClasses, subNamespaces, new ArrayList()); s = lex(); } List implementsTypeStrs = new ArrayList<>(); if (s.type == SymbolType.IMPLEMENTS) { do { - GraphTargetItem implementsTypeStr = type(new Reference(false), importedClasses, openedNamespaces, new ArrayList()); + GraphTargetItem implementsTypeStr = type(pkg,new Reference(false), importedClasses, subNamespaces, new ArrayList()); implementsTypeStrs.add(implementsTypeStr); s = lex(); } while (s.type == SymbolType.COMMA); @@ -663,7 +687,7 @@ public class ActionScriptParser { if (customAccess != null) { throw new ParseException("Class cannot have custom namespace", lexer.yyline()); } - traits.add((classTraits(packageInternalNs, importedClasses, privateNs, isDynamic, isFinal, openedNamespaces, packageName, namespace, false, classTypeStr, extendsTypeStr, implementsTypeStrs, new ArrayList()))); + traits.add((classTraits(scriptName,publicNs,pkg,importedClasses, isDynamic, isFinal, subNamespaces, pkg, namespace, false, classTypeStr, extendsTypeStr, implementsTypeStrs, new ArrayList()))); expectedType(SymbolType.CURLY_CLOSE); break; case INTERFACE: @@ -679,7 +703,7 @@ public class ActionScriptParser { if (isDynamic) { throw new ParseException("Dynamic flag not allowed for interfaces", lexer.yyline()); } - //GraphTargetItem interfaceTypeStr = type(needsActivation, importedClasses, openedNamespaces, variables); + //GraphTargetItem interfaceTypeStr = type(pkg,needsActivation, importedClasses, openedNamespaces, variables); s = lex(); expected(s, lexer.yyline(), SymbolType.IDENTIFIER); String intTypeStr = s.value.toString(); @@ -688,7 +712,7 @@ public class ActionScriptParser { if (s.type == SymbolType.EXTENDS) { do { - GraphTargetItem intExtendsTypeStr = type(new Reference(false), importedClasses, openedNamespaces, new ArrayList()); + GraphTargetItem intExtendsTypeStr = type(pkg,new Reference(false), importedClasses, openedNamespaces, new ArrayList()); intExtendsTypeStrs.add(intExtendsTypeStr); s = lex(); } while (s.type == SymbolType.COMMA); @@ -697,7 +721,7 @@ public class ActionScriptParser { if (customAccess != null) { throw new ParseException("Interface cannot have custom namespace", lexer.yyline()); } - traits.add((classTraits(packageInternalNs, importedClasses, privateNs, false, isFinal, openedNamespaces, packageName, namespace, true, intTypeStr, null, intExtendsTypeStrs, new ArrayList()))); + traits.add((classTraits(scriptName,publicNs,pkg,importedClasses, false, isFinal, openedNamespaces, pkg, namespace, true, intTypeStr, null, intExtendsTypeStrs, new ArrayList()))); expectedType(SymbolType.CURLY_CLOSE); break; @@ -739,9 +763,9 @@ public class ActionScriptParser { if (isInterface) { throw new ParseException("Interface cannot have constructor", lexer.yyline()); } - constr = (method(false, customAccess, new Reference(false), importedClasses, false, false, thisType, openedNamespaces, false, namespace, "", true, constrVariables)); + constr = (method(pkg,false, customAccess, new Reference(false), importedClasses, false, false, thisType, openedNamespaces, false, namespace, "", true, constrVariables)); } else { - MethodAVM2Item ft = method(isInterface, customAccess, new Reference(false), importedClasses, isOverride, isFinal, thisType, openedNamespaces, isStatic, namespace, fname, true, new ArrayList()); + MethodAVM2Item ft = method(pkg,isInterface, customAccess, new Reference(false), importedClasses, isOverride, isFinal, thisType, openedNamespaces, isStatic, namespace, fname, true, new ArrayList()); if (isGetter) { if (!ft.paramTypes.isEmpty()) { @@ -762,10 +786,10 @@ public class ActionScriptParser { } GraphTargetItem t; if (isGetter) { - GetterAVM2Item g = new GetterAVM2Item(isInterface, customAccess, ft.needsActivation, ft.hasRest, ft.line, ft.isOverride(), ft.isFinal(), isStatic, ft.namespace, ft.functionName, ft.paramTypes, ft.paramNames, ft.paramValues, ft.body, ft.subvariables, ft.retType); + GetterAVM2Item g = new GetterAVM2Item(ft.pkg,isInterface, customAccess, ft.needsActivation, ft.hasRest, ft.line, ft.isOverride(), ft.isFinal(), isStatic, ft.namespace, ft.functionName, ft.paramTypes, ft.paramNames, ft.paramValues, ft.body, ft.subvariables, ft.retType); t = g; } else if (isSetter) { - SetterAVM2Item st = new SetterAVM2Item(isInterface, customAccess, ft.needsActivation, ft.hasRest, ft.line, ft.isOverride(), ft.isFinal(), isStatic, ft.namespace, ft.functionName, ft.paramTypes, ft.paramNames, ft.paramValues, ft.body, ft.subvariables, ft.retType); + SetterAVM2Item st = new SetterAVM2Item(ft.pkg,isInterface, customAccess, ft.needsActivation, ft.hasRest, ft.line, ft.isOverride(), ft.isFinal(), isStatic, ft.namespace, ft.functionName, ft.paramTypes, ft.paramNames, ft.paramValues, ft.body, ft.subvariables, ft.retType); t = st; } else { t = ft; @@ -791,13 +815,13 @@ public class ActionScriptParser { nval = s.value.toString(); s = lex(); } else { - nval = (packageName.isEmpty() ? classNameStr : packageName + ":" + classNameStr) + "/" + nname; + nval = (pkg==null||pkg.isEmpty() ? classNameStr : pkg + ":" + classNameStr) + "/" + nname; } if (s.type != SymbolType.SEMICOLON) { lexer.pushback(s); } - ConstAVM2Item ns = new ConstAVM2Item(customAccess, true, namespace, nname, new TypeItem("Namespace"), new StringAVM2Item(null, nval), lexer.yyline()); + ConstAVM2Item ns = new ConstAVM2Item(pkg,customAccess, true, namespace, nname, new TypeItem("Namespace"), new StringAVM2Item(null, nval), lexer.yyline()); traits.add(ns); break; case CONST: @@ -822,7 +846,7 @@ public class ActionScriptParser { s = lex(); GraphTargetItem type = null; if (s.type == SymbolType.COLON) { - type = type(new Reference(false), importedClasses, openedNamespaces, new ArrayList()); + type = type(pkg,new Reference(false), importedClasses, openedNamespaces, new ArrayList()); s = lex(); } else { type = TypeItem.UNBOUNDED; @@ -831,14 +855,14 @@ public class ActionScriptParser { GraphTargetItem value = null; if (s.type == SymbolType.ASSIGN) { - value = expression(new Reference(false), importedClasses, openedNamespaces, new HashMap(), false, false, true, isStatic || isConst ? sinitVariables : constrVariables); + value = expression(pkg,new Reference(false), importedClasses, openedNamespaces, new HashMap(), false, false, true, isStatic || isConst ? sinitVariables : constrVariables); s = lex(); } GraphTargetItem tar; if (isConst) { - tar = new ConstAVM2Item(customAccess, isStatic, namespace, vcname, type, value, lexer.yyline()); + tar = new ConstAVM2Item(pkg,customAccess, isStatic, namespace, vcname, type, value, lexer.yyline()); } else { - tar = new SlotAVM2Item(customAccess, isStatic, namespace, vcname, type, value, lexer.yyline()); + tar = new SlotAVM2Item(pkg,customAccess, isStatic, namespace, vcname, type, value, lexer.yyline()); } traits.add(tar); if (s.type != SymbolType.SEMICOLON) { @@ -846,15 +870,22 @@ public class ActionScriptParser { } break; default: - lexer.pushback(s); - break looptrait; + if(s.type == SymbolType.CURLY_CLOSE && inPkg && classNameStr == null){ + inPkg = false; + pkg = null; + openedNamespaces = originalOpenedNamespaces; + privateNs = originalPrivateNs; + }else{ + lexer.pushback(s); + break looptrait; + } } } return constr; } - private GraphTargetItem classTraits(int packageInternalNs, List importedClasses, int privateNs, boolean isDynamic, boolean isFinal, List openedNamespaces, String packageName, int namespace, boolean isInterface, String nameStr, GraphTargetItem extendsStr, List implementsStr, List variables) throws IOException, ParseException, CompilationException { + private GraphTargetItem classTraits(String scriptName,int gpublicNs,String pkg,List importedClasses, boolean isDynamic, boolean isFinal, List openedNamespaces, String packageName, int namespace, boolean isInterface, String nameStr, GraphTargetItem extendsStr, List implementsStr, List variables) throws IOException, ParseException, CompilationException { GraphTargetItem ret = null; @@ -864,21 +895,39 @@ public class ActionScriptParser { String classNameStr = nameStr; openedNamespaces = new ArrayList<>(openedNamespaces); - //openedNamespacesKinds = new ArrayList<>(openedNamespacesKinds); + + int publicNs=0; + int privateNs = 0; + int packageInternalNs = 0; + if(pkg!=null){ + openedNamespaces.add(packageInternalNs = abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE_INTERNAL, abc.constants.getStringId(pkg, true)), 0, true)); + } + if(pkg!=null && !pkg.equals("")){ + openedNamespaces.add(publicNs = abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId("", true)), 0, true)); + }else{ + publicNs = gpublicNs; + } + + openedNamespaces.add(privateNs = abc.constants.addNamespace(new Namespace(Namespace.KIND_PRIVATE, 0))); //abc.constants.getStringId(fileName + "$", true) + + + openedNamespaces.add(abc.constants.getNamespaceId(new Namespace(Namespace.KIND_NAMESPACE, abc.constants.getStringId(AS3_NAMESPACE, true)), 0, true)); + //int privateNs = 0; int protectedNs = 0; - int publicNs = namespace; + //int publicNs = namespace; int protectedStaticNs = 0; - openedNamespaces.add(protectedNs = abc.constants.addNamespace(new Namespace(Namespace.KIND_PROTECTED, abc.constants.getStringId(packageName.isEmpty() ? classNameStr : packageName + ":" + classNameStr, true)))); - openedNamespaces.add(protectedStaticNs = abc.constants.addNamespace(new Namespace(Namespace.KIND_STATIC_PROTECTED, abc.constants.getStringId(packageName.isEmpty() ? classNameStr : packageName + ":" + classNameStr, true)))); + openedNamespaces.add(protectedNs = abc.constants.addNamespace(new Namespace(Namespace.KIND_PROTECTED, abc.constants.getStringId(packageName==null?(scriptName+"$0:"/*FIXME?*/+classNameStr):packageName.isEmpty() ? classNameStr : packageName + ":" + classNameStr, true)))); + openedNamespaces.add(protectedStaticNs = abc.constants.addNamespace(new Namespace(Namespace.KIND_STATIC_PROTECTED, abc.constants.getStringId(packageName==null||packageName.isEmpty() ? classNameStr : packageName + ":" + classNameStr, true)))); if (extendsStr != null) { List indices = new ArrayList<>(); List names = new ArrayList<>(); List namespaces = new ArrayList<>(); - 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); + //FIXME for Private classes in script!!! + 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; @@ -890,12 +939,12 @@ public class ActionScriptParser { Reference staticNeedsActivation = new Reference<>(false); List staticInit = new ArrayList<>(); List sinitVariables = new ArrayList<>(); - GraphTargetItem constr = traits(sinitVariables, staticNeedsActivation, staticInit, importedClasses, privateNs, protectedNs, publicNs, packageInternalNs, protectedStaticNs, openedNamespaces, packageName, classNameStr, isInterface, traits); + GraphTargetItem constr = traits(scriptName,false, sinitVariables, staticNeedsActivation, staticInit, importedClasses, privateNs, protectedNs, publicNs, packageInternalNs, protectedStaticNs, openedNamespaces, packageName, classNameStr, isInterface, traits); if (isInterface) { - return new InterfaceAVM2Item(openedNamespaces, isFinal, namespace, classNameStr, implementsStr, traits); + return new InterfaceAVM2Item(importedClasses,packageName,openedNamespaces, isFinal, namespace, classNameStr, implementsStr, traits); } else { - return new ClassAVM2Item(openedNamespaces, protectedNs, isDynamic, isFinal, namespace, classNameStr, extendsStr, implementsStr, staticInit, staticNeedsActivation.getVal(), sinitVariables, constr, traits); + return new ClassAVM2Item(importedClasses,packageName,openedNamespaces, protectedNs, isDynamic, isFinal, namespace, classNameStr, extendsStr, implementsStr, staticInit, staticNeedsActivation.getVal(), sinitVariables, constr, traits); } } @@ -904,7 +953,7 @@ public class ActionScriptParser { switch (s.type) { /*case INT: expectedType(SymbolType.PARENT_OPEN); - ret = new ToIntegerAVM2Item(null, expression(needsActivation, importedClasses, openedNamespaces,openedNamespacesKinds,registerVars, inFunction, inMethod, true, variables)); + ret = new ToIntegerAVM2Item(null, expression(pkg,needsActivation, importedClasses, openedNamespaces,openedNamespacesKinds,registerVars, inFunction, inMethod, true, variables)); expectedType(SymbolType.PARENT_CLOSE); break; case NUMBER_OP: @@ -915,7 +964,7 @@ public class ActionScriptParser { ret = memberOrCall(vi, registerVars, inFunction, inMethod, variables); } else { expected(s, lexer.yyline(), SymbolType.PARENT_OPEN); - ret = new ToNumberAVM2Item(null, expression(needsActivation, importedClasses, openedNamespaces,openedNamespacesKinds,registerVars, inFunction, inMethod, true, variables)); + ret = new ToNumberAVM2Item(null, expression(pkg,needsActivation, importedClasses, openedNamespaces,openedNamespacesKinds,registerVars, inFunction, inMethod, true, variables)); expectedType(SymbolType.PARENT_CLOSE); } break; @@ -929,7 +978,7 @@ public class ActionScriptParser { ret = memberOrCall(vi2, registerVars, inFunction, inMethod, variables); } else { expected(s, lexer.yyline(), SymbolType.PARENT_OPEN); - ret = new ToStringAVM2Item(null, expression(needsActivation, importedClasses, openedNamespaces,openedNamespacesKinds,registerVars, inFunction, inMethod, true, variables)); + ret = new ToStringAVM2Item(null, expression(pkg,needsActivation, importedClasses, openedNamespaces,openedNamespacesKinds,registerVars, inFunction, inMethod, true, variables)); expectedType(SymbolType.PARENT_CLOSE); ret = memberOrCall(ret, registerVars, inFunction, inMethod, variables); } @@ -995,7 +1044,7 @@ public class ActionScriptParser { } } - private List xmltag(Reference usesVars, List openedTags, Reference closedVarTags, Reference needsActivation, List importedClasses, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, List variables) throws IOException, ParseException { + private List xmltag(String pkg,Reference usesVars, List openedTags, Reference closedVarTags, Reference needsActivation, List importedClasses, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, List variables) throws IOException, ParseException { ParsedSymbol s = null; List rets = new ArrayList<>(); //GraphTargetItem ret = null; @@ -1010,7 +1059,7 @@ public class ActionScriptParser { case XML_ATTRNAMEVAR_BEGIN: //add usesVars.setVal(true); addS(rets, sb); - rets.add(expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); + rets.add(expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); expectedType(SymbolType.CURLY_CLOSE); expectedType(SymbolType.ASSIGN); sb.append("="); @@ -1020,7 +1069,7 @@ public class ActionScriptParser { usesVars.setVal(true); sb.append("\""); addS(rets, sb); - rets.add(new EscapeXAttrAVM2Item(null, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables))); + rets.add(new EscapeXAttrAVM2Item(null, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables))); sb.append("\""); expectedType(SymbolType.CURLY_CLOSE); lexer.yybegin(ActionScriptLexer.XMLOPENTAG); @@ -1028,7 +1077,7 @@ public class ActionScriptParser { case XML_INSTRATTRNAMEVAR_BEGIN: //add usesVars.setVal(true); addS(rets, sb); - rets.add(expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); + rets.add(expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); expectedType(SymbolType.CURLY_CLOSE); expectedType(SymbolType.ASSIGN); sb.append("="); @@ -1038,7 +1087,7 @@ public class ActionScriptParser { usesVars.setVal(true); sb.append("\""); addS(rets, sb); - rets.add(new EscapeXAttrAVM2Item(null, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables))); + rets.add(new EscapeXAttrAVM2Item(null, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables))); sb.append("\""); expectedType(SymbolType.CURLY_CLOSE); lexer.yybegin(ActionScriptLexer.XMLOPENTAG); @@ -1046,7 +1095,7 @@ public class ActionScriptParser { case XML_VAR_BEGIN: //esc_xelem usesVars.setVal(true); addS(rets, sb); - rets.add(new EscapeXElemAVM2Item(null, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables))); + rets.add(new EscapeXElemAVM2Item(null, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables))); expectedType(SymbolType.CURLY_CLOSE); lexer.yybegin(ActionScriptLexer.XML); break; @@ -1056,7 +1105,7 @@ public class ActionScriptParser { sb.append(""); @@ -1067,14 +1116,14 @@ public class ActionScriptParser { //openedTags.add("*"); //ret = add(ret, ); - GraphTargetItem ex = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); + GraphTargetItem ex = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); expectedType(SymbolType.CURLY_CLOSE); lexer.yybegin(ActionScriptLexer.XMLOPENTAG); sub.add("*"); sb.append("<"); addS(rets, sb); rets.add(ex); - rets.addAll(xmltag(subusesvars, sub, subclose, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables)); + rets.addAll(xmltag(pkg,subusesvars, sub, subclose, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables)); closedVarTags.setVal(subclose.getVal() + subclose.getVal()); break; case XML_INSTRVARTAG_BEGIN: //add @@ -1082,13 +1131,13 @@ public class ActionScriptParser { addS(rets, sb); sb.append(" st = xmltag(subusesvars, sub, closedVarTags, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables); + List st = xmltag(pkg,subusesvars, sub, closedVarTags, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables); sb.append(s.value.toString()); addS(rets, sb); rets.addAll(st); @@ -1124,18 +1173,18 @@ public class ActionScriptParser { return rets; } - private GraphTargetItem xml(Reference needsActivation, List importedClasses, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, List variables) throws IOException, ParseException { + private GraphTargetItem xml(String pkg,Reference needsActivation, List importedClasses, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, List variables) throws IOException, ParseException { List openedTags = new ArrayList<>(); int closedVarTags = 0; - GraphTargetItem ret = add(xmltag(new Reference(false), openedTags, new Reference(closedVarTags), needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables)); + GraphTargetItem ret = add(xmltag(pkg,new Reference(false), openedTags, new Reference(closedVarTags), needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables)); ret = new XMLAVM2Item(ret); lexer.yybegin(ActionScriptLexer.YYINITIAL); //TODO: Order of additions as in official compiler return ret; } - private GraphTargetItem command(Reference needsActivation, List importedClasses, List openedNamespaces, Stack loops, Map loopLabels, HashMap registerVars, boolean inFunction, boolean inMethod, int forinlevel, boolean mustBeCommand, List variables) throws IOException, ParseException { + private GraphTargetItem command(String pkg,Reference needsActivation, List importedClasses, List openedNamespaces, Stack loops, Map loopLabels, HashMap registerVars, boolean inFunction, boolean inMethod, int forinlevel, boolean mustBeCommand, List variables) throws IOException, ParseException { LexBufferer buf = new LexBufferer(); lexer.addListener(buf); GraphTargetItem ret = null; @@ -1168,7 +1217,7 @@ public class ActionScriptParser { } else { expectedType(SymbolType.NAMESPACE); expectedType(SymbolType.ASSIGN); - GraphTargetItem ns = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); + GraphTargetItem ns = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); ret = new DefaultXMLNamespace(null, ns); //TODO: use dxns for attribute namespaces instead of dxnslate } @@ -1178,20 +1227,20 @@ public class ActionScriptParser { switch (s.type) { case USE: expectedType(SymbolType.NAMESPACE); - GraphTargetItem ns = type(needsActivation, importedClasses, openedNamespaces, variables); + GraphTargetItem ns = type(pkg,needsActivation, importedClasses, openedNamespaces, variables); openedNamespaces.add(abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE /*FIXME?*/, abc.constants.getStringId(ns.toString(), true)), 0, true)); break; case WITH: needsActivation.setVal(true); expectedType(SymbolType.PARENT_OPEN); - GraphTargetItem wvar = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables);//(name(false, openedNamespaces, registerVars, inFunction, inMethod, variables)); + GraphTargetItem wvar = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables);//(name(false, openedNamespaces, registerVars, inFunction, inMethod, variables)); if (!isNameOrProp(wvar)) { throw new ParseException("Not a property or name", lexer.yyline()); } expectedType(SymbolType.PARENT_CLOSE); expectedType(SymbolType.CURLY_OPEN); List withVars = new ArrayList<>(); - List wcmd = commands(needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, withVars); + List wcmd = commands(pkg,needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, withVars); variables.addAll(withVars); for (AssignableAVM2Item a : withVars) { if (a instanceof UnresolvedAVM2Item) { @@ -1204,7 +1253,7 @@ public class ActionScriptParser { ((WithAVM2Item) ret).subvariables = withVars; break; /*case DELETE: - GraphTargetItem varDel = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables);//name(false, openedNamespaces, registerVars, inFunction, inMethod, variables); + GraphTargetItem varDel = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables);//name(false, openedNamespaces, registerVars, inFunction, inMethod, variables); if(!isNameOrProp(varDel)){ throw new ParseException("Not a property or name", lexer.yyline()); } @@ -1222,7 +1271,7 @@ public class ActionScriptParser { s = lexer.lex(); expected(s, lexer.yyline(), SymbolType.IDENTIFIER); needsActivation.setVal(true); - ret = (function(false, needsActivation, importedClasses, 0/*?*/, TypeItem.UNBOUNDED, openedNamespaces, s.value.toString(), false, variables)); + ret = (function(pkg,false, needsActivation, importedClasses, 0/*?*/, TypeItem.UNBOUNDED, openedNamespaces, s.value.toString(), false, variables)); break; case VAR: s = lex(); @@ -1231,14 +1280,14 @@ public class ActionScriptParser { s = lex(); GraphTargetItem type; if (s.type == SymbolType.COLON) { - type = type(needsActivation, importedClasses, openedNamespaces, variables); + type = type(pkg,needsActivation, importedClasses, openedNamespaces, variables); s = lex(); } else { type = new UnboundedTypeItem(); } if (s.type == SymbolType.ASSIGN) { - GraphTargetItem varval = (expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); + GraphTargetItem varval = (expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); ret = new NameAVM2Item(type, lexer.yyline(), varIdentifier, varval, true, openedNamespaces); variables.add((NameAVM2Item) ret); } else { @@ -1248,12 +1297,12 @@ public class ActionScriptParser { } break; case CURLY_OPEN: - ret = new BlockItem(null, commands(needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, variables)); + ret = new BlockItem(null, commands(pkg,needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, variables)); expectedType(SymbolType.CURLY_CLOSE); break; /*case INCREMENT: //preincrement case DECREMENT: //predecrement - GraphTargetItem varincdec = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables);//name(false, openedNamespaces, registerVars, inFunction, inMethod, variables); + GraphTargetItem varincdec = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables);//name(false, openedNamespaces, registerVars, inFunction, inMethod, variables); if(!isNameOrProp(varincdec)){ throw new ParseException("Not a property or name", lexer.yyline()); } @@ -1266,7 +1315,7 @@ public class ActionScriptParser { case SUPER: //constructor call ParsedSymbol ss2 = lex(); if (ss2.type == SymbolType.PARENT_OPEN) { - List args = call(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables); + List args = call(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables); ret = new ConstructSuperAVM2Item(null, new LocalRegAVM2Item(null, 0, null), args); } else {//no costructor call, but it could be calling parent methods... => handle in expression lexer.pushback(ss2); @@ -1275,16 +1324,16 @@ public class ActionScriptParser { break; case IF: expectedType(SymbolType.PARENT_OPEN); - GraphTargetItem ifExpr = (expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); + GraphTargetItem ifExpr = (expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); expectedType(SymbolType.PARENT_CLOSE); - GraphTargetItem onTrue = command(needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables); + GraphTargetItem onTrue = command(pkg,needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables); List onTrueList = new ArrayList<>(); onTrueList.add(onTrue); s = lex(); List onFalseList = null; if (s.type == SymbolType.ELSE) { onFalseList = new ArrayList<>(); - onFalseList.add(command(needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)); + onFalseList.add(command(pkg,needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)); } else { lexer.pushback(s); } @@ -1293,7 +1342,7 @@ public class ActionScriptParser { case WHILE: expectedType(SymbolType.PARENT_OPEN); List whileExpr = new ArrayList<>(); - whileExpr.add(commaExpression(needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, variables)); + whileExpr.add(commaExpression(pkg,needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, variables)); expectedType(SymbolType.PARENT_CLOSE); List whileBody = new ArrayList<>(); Loop wloop = new Loop(uniqId(), null, null); @@ -1301,7 +1350,7 @@ public class ActionScriptParser { loopLabels.put(wloop, loopLabel); } loops.push(wloop); - whileBody.add(command(needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)); + whileBody.add(command(pkg,needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)); ret = new WhileItem(null, wloop, whileExpr, whileBody); break; case DO: @@ -1311,11 +1360,11 @@ public class ActionScriptParser { if (loopLabel != null) { loopLabels.put(dloop, loopLabel); } - doBody.add(command(needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)); + doBody.add(command(pkg,needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)); expectedType(SymbolType.WHILE); expectedType(SymbolType.PARENT_OPEN); List doExpr = new ArrayList<>(); - doExpr.add(commaExpression(needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, variables)); + doExpr.add(commaExpression(pkg,needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, variables)); expectedType(SymbolType.PARENT_CLOSE); ret = new DoWhileItem(null, dloop, doBody, doExpr); break; @@ -1330,11 +1379,11 @@ public class ActionScriptParser { s = lex(); } expected(s, lexer.yyline(), SymbolType.PARENT_OPEN); - GraphTargetItem firstCommand = command(needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, false, variables); + GraphTargetItem firstCommand = command(pkg,needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, false, variables); if (firstCommand instanceof NameAVM2Item) { NameAVM2Item nai = (NameAVM2Item) firstCommand; if (nai.isDefinition() && nai.getAssignedValue() == null) { - firstCommand = expressionRemainder(needsActivation, openedNamespaces, firstCommand, registerVars, inFunction, inMethod, true, variables, importedClasses); + firstCommand = expressionRemainder(pkg,needsActivation, openedNamespaces, firstCommand, registerVars, inFunction, inMethod, true, variables, importedClasses); } } InAVM2Item inexpr = null; @@ -1356,17 +1405,17 @@ public class ActionScriptParser { GraphTargetItem forExpr = null; List forFirstCommands = new ArrayList<>(); if (!forin) { - //GraphTargetItem firstCommand = command(needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables); + //GraphTargetItem firstCommand = command(pkg,needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables); if (firstCommand != null) { //can be empty command forFirstCommands.add(firstCommand); } - forExpr = (expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); + forExpr = (expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); expectedType(SymbolType.SEMICOLON); - forFinalCommands.add(command(needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)); + forFinalCommands.add(command(pkg,needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)); } expectedType(SymbolType.PARENT_CLOSE); List forBody = new ArrayList<>(); - forBody.add(command(needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forin ? forinlevel + 1 : forinlevel, true, variables)); + forBody.add(command(pkg,needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forin ? forinlevel + 1 : forinlevel, true, variables)); if (forin) { if (each) { ret = new ForEachInAVM2Item(null, floop, inexpr, forBody); @@ -1385,7 +1434,7 @@ public class ActionScriptParser { loopLabels.put(sloop, loopLabel); } expectedType(SymbolType.PARENT_OPEN); - GraphTargetItem switchExpr = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); + GraphTargetItem switchExpr = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); expectedType(SymbolType.PARENT_CLOSE); expectedType(SymbolType.CURLY_OPEN); s = lex(); @@ -1406,7 +1455,7 @@ public class ActionScriptParser { while (s.type == SymbolType.CASE) { List caseExprs = new ArrayList<>(); while (s.type == SymbolType.CASE) { - GraphTargetItem curCaseExpr = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); + GraphTargetItem curCaseExpr = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); caseExprs.add(curCaseExpr); expectedType(SymbolType.COLON); s = lex(); @@ -1415,14 +1464,14 @@ public class ActionScriptParser { } pos++; lexer.pushback(s); - List caseCmd = commands(needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, variables); + List caseCmd = commands(pkg,needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, variables); caseCmds.add(caseCmd); s = lex(); } List defCmd = new ArrayList<>(); if (s.type == SymbolType.DEFAULT) { expectedType(SymbolType.COLON); - defCmd = commands(needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, variables); + defCmd = commands(pkg,needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, variables); s = lexer.lex(); } expected(s, lexer.yyline(), SymbolType.CURLY_CLOSE); @@ -1487,7 +1536,7 @@ public class ActionScriptParser { ret = new ContinueItem(null, cloopId); break; case RETURN: - GraphTargetItem retexpr = expression(needsActivation, importedClasses, openedNamespaces, true, registerVars, inFunction, inMethod, true, variables); + GraphTargetItem retexpr = expression(pkg,needsActivation, importedClasses, openedNamespaces, true, registerVars, inFunction, inMethod, true, variables); if (retexpr == null) { ret = new ReturnVoidAVM2Item(null); } else { @@ -1497,7 +1546,7 @@ public class ActionScriptParser { case TRY: needsActivation.setVal(true); List tryCommands = new ArrayList<>(); - tryCommands.add(command(needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)); + tryCommands.add(command(pkg,needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)); s = lex(); boolean found = false; List> catchCommands = new ArrayList<>(); @@ -1511,7 +1560,7 @@ public class ActionScriptParser { String enamestr = s.value.toString(); expectedType(SymbolType.COLON); - GraphTargetItem etype = type(needsActivation, importedClasses, openedNamespaces, variables); + GraphTargetItem etype = type(pkg,needsActivation, importedClasses, openedNamespaces, variables); NameAVM2Item e = new NameAVM2Item(etype, lexer.yyline(), enamestr, new ExceptionAVM2Item(null)/*?*/, true/*?*/, openedNamespaces); variables.add(e); catchExceptions.add(e); @@ -1520,7 +1569,7 @@ public class ActionScriptParser { expectedType(SymbolType.PARENT_CLOSE); List cc = new ArrayList<>(); List catchVars = new ArrayList<>(); - cc.add(command(needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, catchVars)); + cc.add(command(pkg,needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, catchVars)); catchesVars.add(catchVars); variables.addAll(catchVars); @@ -1566,7 +1615,7 @@ public class ActionScriptParser { List finallyCommands = null; if (s.type == SymbolType.FINALLY) { finallyCommands = new ArrayList<>(); - finallyCommands.add(command(needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)); + finallyCommands.add(command(pkg,needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)); found = true; s = lex(); } @@ -1580,7 +1629,7 @@ public class ActionScriptParser { ret = tai; break; case THROW: - ret = new ThrowAVM2Item(null, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); + ret = new ThrowAVM2Item(null, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); break; default: GraphTargetItem valcmd = expressionCommands(s, registerVars, inFunction, inMethod, forinlevel, variables); @@ -1592,7 +1641,7 @@ public class ActionScriptParser { return null; } lexer.pushback(s); - ret = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); + ret = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); if (debugMode) { System.out.println("/command"); } @@ -1604,7 +1653,7 @@ public class ActionScriptParser { lexer.removeListener(buf); if (ret == null) { //can be popped expression buf.pushAllBack(lexer); - ret = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); + ret = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); } s = lex(); if ((s != null) && (s.type != SymbolType.SEMICOLON)) { @@ -1615,8 +1664,8 @@ public class ActionScriptParser { } - private GraphTargetItem expression(Reference needsActivation, List importedClasses, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, boolean allowRemainder, List variables) throws IOException, ParseException { - return expression(needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, allowRemainder, variables); + private GraphTargetItem expression(String pkg,Reference needsActivation, List importedClasses, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, boolean allowRemainder, List variables) throws IOException, ParseException { + return expression(pkg,needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, allowRemainder, variables); } private GraphTargetItem fixPrecedence(GraphTargetItem expr) { @@ -1637,33 +1686,33 @@ public class ActionScriptParser { return ret; } - private GraphTargetItem expressionRemainder(Reference needsActivation, List openedNamespaces, GraphTargetItem expr, HashMap registerVars, boolean inFunction, boolean inMethod, boolean allowRemainder, List variables, List importedClasses) throws IOException, ParseException { + private GraphTargetItem expressionRemainder(String pkg,Reference needsActivation, List openedNamespaces, GraphTargetItem expr, HashMap registerVars, boolean inFunction, boolean inMethod, boolean allowRemainder, List variables, List importedClasses) throws IOException, ParseException { GraphTargetItem ret = null; ParsedSymbol s = lex(); if (ret == null) { switch (s.type) { case AS: - GraphTargetItem type = type(needsActivation, importedClasses, openedNamespaces, variables); + GraphTargetItem type = type(pkg,needsActivation, importedClasses, openedNamespaces, variables); ret = new AsTypeAVM2Item(null, expr, type); allowRemainder = false; break; case DESCENDANTS: ParsedSymbol d = lex(); - expected(d, lexer.yyline(), SymbolType.IDENTIFIER); - ret = new GetDescendantsAVM2Item(expr, d.value.toString(), openedNamespaces); + expected(d, lexer.yyline(), SymbolType.IDENTIFIER, SymbolType.MULTIPLY); + ret = new GetDescendantsAVM2Item(expr, d.type == SymbolType.MULTIPLY?null:d.value.toString(), openedNamespaces); allowRemainder = true; break; case FILTER: needsActivation.setVal(true); - ret = new XMLFilterAVM2Item(expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables), openedNamespaces); + ret = new XMLFilterAVM2Item(expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables), openedNamespaces); expectedType(SymbolType.PARENT_CLOSE); allowRemainder = true; break; /*case NAMESPACE_OP: s = lex(); if (s.type == SymbolType.BRACKET_OPEN) { - GraphTargetItem index = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); + GraphTargetItem index = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); NameAVM2Item name = new NameAVM2Item(new UnboundedTypeItem(), lexer.yyline(), null, null, false, openedNamespaces); name.setIndex(index); name.setNs(expr); @@ -1671,7 +1720,7 @@ public class ActionScriptParser { expectedType(SymbolType.BRACKET_CLOSE); } else { lexer.pushback(s); - GraphTargetItem name = name(needsActivation, false, openedNamespaces, registerVars, inFunction, inMethod, variables, importedClasses); + GraphTargetItem name = name(pkg,needsActivation, false, openedNamespaces, registerVars, inFunction, inMethod, variables, importedClasses); if (name instanceof UnresolvedAVM2Item) { ((UnresolvedAVM2Item) name).setNs(expr); //((UnresolvedAVM2Item) name).unresolved = false; @@ -1683,52 +1732,52 @@ public class ActionScriptParser { } break;*/ case IN: - ret = new InAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); + ret = new InAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); break; case TERNAR: - GraphTargetItem terOnTrue = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); + GraphTargetItem terOnTrue = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); expectedType(SymbolType.COLON); - GraphTargetItem terOnFalse = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); + GraphTargetItem terOnFalse = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); ret = new TernarOpItem(null, expr, terOnTrue, terOnFalse); break; case SHIFT_LEFT: - ret = new LShiftAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new LShiftAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case SHIFT_RIGHT: - ret = new RShiftAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new RShiftAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case USHIFT_RIGHT: - ret = new URShiftAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new URShiftAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case BITAND: - ret = new BitAndAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new BitAndAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case BITOR: - ret = new BitOrAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new BitOrAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case DIVIDE: - ret = new DivideAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new DivideAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case MODULO: - ret = new ModuloAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new ModuloAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case EQUALS: - ret = new EqAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new EqAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case STRICT_EQUALS: - ret = new StrictEqAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new StrictEqAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case NOT_EQUAL: - ret = new NeqAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new NeqAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case STRICT_NOT_EQUAL: - ret = new StrictNeqAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new StrictNeqAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case LOWER_THAN: - ret = new LtAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new LtAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case LOWER_EQUAL: - ret = new LeAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new LeAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case GREATER_THAN: case XML_STARTVARTAG_BEGIN: @@ -1736,34 +1785,34 @@ public class ActionScriptParser { if (s.type != SymbolType.GREATER_THAN) { lexer.yypushbackstr(s.value.toString().substring(1)); //parse again as GREATER_THAN } - ret = new GtAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new GtAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case GREATER_EQUAL: - ret = new GeAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new GeAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case AND: - ret = new AndItem(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new AndItem(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case OR: - ret = new OrItem(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new OrItem(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case MINUS: - ret = new SubtractAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new SubtractAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case MULTIPLY: - ret = new MultiplyAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new MultiplyAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case PLUS: - ret = new AddAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new AddAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case XOR: - ret = new BitXorAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new BitXorAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case INSTANCEOF: - ret = new InstanceOfAVM2Item(null, expr, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new InstanceOfAVM2Item(null, expr, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); break; case IS: - GraphTargetItem istype = type(needsActivation, importedClasses, openedNamespaces, variables); + GraphTargetItem istype = expression(pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables);//type(pkg,needsActivation, importedClasses, openedNamespaces, variables); ret = new IsTypeAVM2Item(null, expr, istype); allowRemainder = false; break; @@ -1779,7 +1828,7 @@ public class ActionScriptParser { case ASSIGN_SHIFT_RIGHT: case ASSIGN_USHIFT_RIGHT: case ASSIGN_XOR: - GraphTargetItem assigned = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); + GraphTargetItem assigned = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); switch (s.type) { case ASSIGN: //assigned = assigned; @@ -1836,14 +1885,14 @@ public class ActionScriptParser { case BRACKET_OPEN: //member case PARENT_OPEN: //function call lexer.pushback(s); - ret = memberOrCall(needsActivation, importedClasses, openedNamespaces, expr, registerVars, inFunction, inMethod, variables); + ret = memberOrCall(pkg,needsActivation, importedClasses, openedNamespaces, expr, registerVars, inFunction, inMethod, variables); break; default: lexer.pushback(s); if (expr instanceof ParenthesisItem) { if (isType(((ParenthesisItem) expr).value)) { - GraphTargetItem expr2 = expression(needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, true, variables); + GraphTargetItem expr2 = expression(pkg,needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, true, variables); if (expr2 != null) { ret = new CoerceAVM2Item(null, ((ParenthesisItem) expr).value, expr2); } @@ -1884,7 +1933,7 @@ public class ActionScriptParser { return false; } - private int brackets(Reference needsActivation, List importedClasses, List openedNamespaces, List ret, HashMap registerVars, boolean inFunction, boolean inMethod, List variables) throws IOException, ParseException { + private int brackets(String pkg,Reference needsActivation, List importedClasses, List openedNamespaces, List ret, HashMap registerVars, boolean inFunction, boolean inMethod, List variables) throws IOException, ParseException { ParsedSymbol s = lex(); int arrCnt = 0; if (s.type == SymbolType.BRACKET_OPEN) { @@ -1895,7 +1944,7 @@ public class ActionScriptParser { lexer.pushback(s); } arrCnt++; - ret.add(expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); + ret.add(expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); s = lex(); if (!s.isType(SymbolType.COMMA, SymbolType.BRACKET_CLOSE)) { expected(s, lexer.yyline(), SymbolType.COMMA, SymbolType.BRACKET_CLOSE); @@ -1908,12 +1957,12 @@ public class ActionScriptParser { return arrCnt; } - private GraphTargetItem commaExpression(Reference needsActivation, List importedClasses, List openedNamespaces, Stack loops, Map loopLabels, HashMap registerVars, boolean inFunction, boolean inMethod, int forInLevel, List variables) throws IOException, ParseException { + private GraphTargetItem commaExpression(String pkg,Reference needsActivation, List importedClasses, List openedNamespaces, Stack loops, Map loopLabels, HashMap registerVars, boolean inFunction, boolean inMethod, int forInLevel, List variables) throws IOException, ParseException { GraphTargetItem cmd = null; List expr = new ArrayList<>(); ParsedSymbol s; do { - cmd = command(needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forInLevel, false, variables); + cmd = command(pkg,needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forInLevel, false, variables); if (cmd != null) { expr.add(cmd); } @@ -1921,7 +1970,7 @@ public class ActionScriptParser { } while (s.type == SymbolType.COMMA && cmd != null); lexer.pushback(s); if (cmd == null) { - expr.add(expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); + expr.add(expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); } else { if (!cmd.hasReturnValue()) { throw new ParseException("Expression expected", lexer.yyline()); @@ -1930,7 +1979,7 @@ public class ActionScriptParser { return new CommaExpressionItem(null, expr); } - private GraphTargetItem expression(Reference needsActivation, List importedClasses, List openedNamespaces, boolean allowEmpty, HashMap registerVars, boolean inFunction, boolean inMethod, boolean allowRemainder, List variables) throws IOException, ParseException { + private GraphTargetItem expression(String pkg,Reference needsActivation, List importedClasses, List openedNamespaces, boolean allowEmpty, HashMap registerVars, boolean inFunction, boolean inMethod, boolean allowRemainder, List variables) throws IOException, ParseException { if (debugMode) { System.out.println("expression:"); } @@ -1941,13 +1990,18 @@ public class ActionScriptParser { switch (s.type) { case XML_STARTTAG_BEGIN: lexer.pushback(s); - ret = xml(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables); + ret = xml(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables); existsRemainder = true; break; case STRING: ret = new StringAVM2Item(null, s.value.toString()); existsRemainder = true; break; + case NEGATE: + ret = expression(pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables); + ret = new NegAVM2Item(null, ret); + existsRemainder = true; + break; case MINUS: s = lex(); if (s.isType(SymbolType.DOUBLE)) { @@ -1958,7 +2012,7 @@ public class ActionScriptParser { existsRemainder = true; } else { lexer.pushback(s); - GraphTargetItem num = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); + GraphTargetItem num = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); if (num instanceof IntegerValueAVM2Item) { ((IntegerValueAVM2Item) num).value = -((IntegerValueAVM2Item) num).value; ret = num; @@ -1975,8 +2029,8 @@ public class ActionScriptParser { } } break; - case TYPEOF: - ret = new TypeOfAVM2Item(null, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + case TYPEOF: + ret = new TypeOfAVM2Item(null, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); existsRemainder = true; break; case TRUE: @@ -2006,9 +2060,9 @@ public class ActionScriptParser { expected(s, lexer.yyline(), SymbolType.IDENTIFIER, SymbolType.STRING); GraphTargetItem n = new StringAVM2Item(null, s.value.toString()); -//expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, allowRemainder, variables); +//expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, allowRemainder, variables); expectedType(SymbolType.COLON); - GraphTargetItem v = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, allowRemainder, variables); + GraphTargetItem v = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, allowRemainder, variables); NameValuePair nv = new NameValuePair(n, v); nvs.add(nv); @@ -2018,14 +2072,14 @@ public class ActionScriptParser { } } ret = new NewObjectAVM2Item(null, nvs); - ret = memberOrCall(needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables); + ret = memberOrCall(pkg,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); + int arrCnt = brackets(pkg,needsActivation, importedClasses, openedNamespaces, inBrackets, registerVars, inFunction, inMethod, variables); ret = new NewArrayAVM2Item(null, inBrackets); - ret = memberOrCall(needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables); + ret = memberOrCall(pkg,needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables); break; case FUNCTION: @@ -2037,7 +2091,7 @@ public class ActionScriptParser { lexer.pushback(s); } needsActivation.setVal(true); - ret = function(false, needsActivation, importedClasses, 0/*?*/, TypeItem.UNBOUNDED, openedNamespaces, fname, false, variables); + ret = function(pkg,false, needsActivation, importedClasses, 0/*?*/, TypeItem.UNBOUNDED, openedNamespaces, fname, false, variables); break; case NAN: ret = new NanAVM2Item(null); @@ -2056,7 +2110,7 @@ public class ActionScriptParser { existsRemainder = true; break; case DELETE: - GraphTargetItem varDel = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables);//name(false, openedNamespaces, registerVars, inFunction, inMethod, variables); + GraphTargetItem varDel = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables);//name(false, openedNamespaces, registerVars, inFunction, inMethod, variables); if (!isNameOrProp(varDel)) { throw new ParseException("Not a property or name", lexer.yyline()); } @@ -2064,7 +2118,7 @@ public class ActionScriptParser { break; case INCREMENT: case DECREMENT: //preincrement - GraphTargetItem varincdec = expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false/*?*/, variables);//name(false, openedNamespaces, registerVars, inFunction, inMethod, variables); + GraphTargetItem varincdec = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false/*?*/, variables);//name(false, openedNamespaces, registerVars, inFunction, inMethod, variables); if (!isNameOrProp(varincdec)) { throw new ParseException("Not a property or name", lexer.yyline()); } @@ -2077,18 +2131,18 @@ public class ActionScriptParser { existsRemainder = true; break; case NOT: - ret = new NotItem(null, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); + ret = new NotItem(null, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, false, variables)); existsRemainder = true; break; case PARENT_OPEN: - ret = new ParenthesisItem(null, expression(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); + ret = new ParenthesisItem(null, expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); expectedType(SymbolType.PARENT_CLOSE); - ret = memberOrCall(needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables); + ret = memberOrCall(pkg,needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables); existsRemainder = true; break; case NEW: s = lex(); - if(s.type == SymbolType.XML_STARTTAG_BEGIN){ + if (s.type == SymbolType.XML_STARTTAG_BEGIN) { lexer.yypushbackstr(s.value.toString().substring(1), ActionScriptLexer.YYINITIAL); s = new ParsedSymbol(SymbolGroup.OPERATOR, SymbolType.LOWER_THAN); } @@ -2101,22 +2155,29 @@ public class ActionScriptParser { lexer.pushback(s); } needsActivation.setVal(true); - ret = function(false, needsActivation, importedClasses, 0/*?*/, TypeItem.UNBOUNDED, openedNamespaces, ffname, false, variables); - } else if(s.type == SymbolType.LOWER_THAN){ - GraphTargetItem subtype=type(needsActivation, importedClasses, openedNamespaces, variables); + ret = function(pkg,false, needsActivation, importedClasses, 0/*?*/, TypeItem.UNBOUNDED, openedNamespaces, ffname, false, variables); + } else if (s.type == SymbolType.LOWER_THAN) { + GraphTargetItem subtype = type(pkg,needsActivation, importedClasses, openedNamespaces, variables); expectedType(SymbolType.GREATER_THAN); s = lex(); - expected(s,lexer.yyline(),SymbolType.BRACKET_OPEN); + expected(s, lexer.yyline(), SymbolType.BRACKET_OPEN); lexer.pushback(s); 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); + brackets(pkg,needsActivation, importedClasses, openedNamespaces, params, registerVars, inFunction, inMethod, variables); + ret = new InitVectorAVM2Item(subtype, params, openedNamespaces); + } else if (s.type == SymbolType.PARENT_OPEN) { + GraphTargetItem newvar = expression(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); + newvar = applyType(pkg,needsActivation, importedClasses, openedNamespaces, newvar, registerVars, inFunction, inMethod, variables); + expectedType(SymbolType.PARENT_CLOSE); expectedType(SymbolType.PARENT_OPEN); - ret = new ConstructSomethingAVM2Item(lexer.yyline(), openedNamespaces, newvar, call(needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables)); + ret = new ConstructSomethingAVM2Item(lexer.yyline(), openedNamespaces, newvar, call(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables)); + + } else { + lexer.pushback(s); + GraphTargetItem newvar = name(pkg,needsActivation, false /*?*/, openedNamespaces, registerVars, inFunction, inMethod, variables, importedClasses); + newvar = applyType(pkg,needsActivation, importedClasses, openedNamespaces, newvar, registerVars, inFunction, inMethod, variables); + expectedType(SymbolType.PARENT_OPEN); + ret = new ConstructSomethingAVM2Item(lexer.yyline(), openedNamespaces, newvar, call(pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables)); } existsRemainder = true; break; @@ -2125,8 +2186,8 @@ public class ActionScriptParser { case SUPER: case ATTRIBUTE: lexer.pushback(s); - GraphTargetItem var = name(needsActivation, false, openedNamespaces, registerVars, inFunction, inMethod, variables, importedClasses); - var = memberOrCall(needsActivation, importedClasses, openedNamespaces, var, registerVars, inFunction, inMethod, variables); + GraphTargetItem var = name(pkg,needsActivation, false, openedNamespaces, registerVars, inFunction, inMethod, variables, importedClasses); + var = memberOrCall(pkg,needsActivation, importedClasses, openedNamespaces, var, registerVars, inFunction, inMethod, variables); ret = var; existsRemainder = true; break; @@ -2142,7 +2203,7 @@ public class ActionScriptParser { if (allowRemainder && existsRemainder) { GraphTargetItem rem = ret; do { - rem = expressionRemainder(needsActivation, openedNamespaces, rem, registerVars, inFunction, inMethod, assocRight, variables, importedClasses); + rem = expressionRemainder(pkg,needsActivation, openedNamespaces, rem, registerVars, inFunction, inMethod, assocRight, variables, importedClasses); if (rem != null) { ret = rem; } @@ -2157,11 +2218,11 @@ public class ActionScriptParser { private ActionScriptLexer lexer = null; private List constantPool; - private PackageAVM2Item parsePackage(String fileName) throws IOException, ParseException, CompilationException { - ParsedSymbol s = lex(); - expected(s, lexer.yyline(), SymbolType.PACKAGE); + private PackageAVM2Item parsePackage(List openedNamespaces) throws IOException, ParseException, CompilationException { + List items = new ArrayList<>(); + expectedType(SymbolType.PACKAGE); String name = ""; - s = lex(); + ParsedSymbol s = lex(); if (s.type != SymbolType.CURLY_OPEN) { expected(s, lexer.yyline(), SymbolType.IDENTIFIER); name = s.value.toString(); @@ -2174,33 +2235,8 @@ public class ActionScriptParser { name += "." + s.value.toString(); s = lex(); } - List items = new ArrayList<>(); - List openedNamespaces = new ArrayList<>(); - - int privateNs = 0; - int publicNs = 0; - if (fileName.contains("/")) { - fileName = fileName.substring(fileName.lastIndexOf('/') + 1); - } - if (fileName.contains("\\")) { - fileName = fileName.substring(fileName.lastIndexOf('\\') + 1); - } - String className = fileName; - if (className.endsWith(".as")) { - className = className.substring(0, className.length() - 3); - } - openedNamespaces.add(privateNs = abc.constants.addNamespace(new Namespace(Namespace.KIND_PRIVATE, 0))); //abc.constants.getStringId(name + ":" + className, true) - int packageInternalNs = 0; - openedNamespaces.add(packageInternalNs = abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE_INTERNAL, abc.constants.getStringId(name, true)), 0, true)); - openedNamespaces.add(publicNs = abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId("", true)), 0, true)); - - openedNamespaces.add(abc.constants.addNamespace(new Namespace(Namespace.KIND_PRIVATE, 0))); //abc.constants.getStringId(fileName + "$", true) - if (!name.isEmpty()) { - openedNamespaces.add(publicNs = abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId(name, true)), 0, true)); - } - - openedNamespaces.add(abc.constants.getNamespaceId(new Namespace(Namespace.KIND_NAMESPACE, abc.constants.getStringId(AS3_NAMESPACE, true)), 0, true)); + List importedClasses = new ArrayList<>(); s = lex(); @@ -2241,39 +2277,62 @@ public class ActionScriptParser { } lexer.pushback(s); - traits(new ArrayList(), new Reference(false), new ArrayList(), importedClasses, privateNs, 0, publicNs, packageInternalNs, 0, openedNamespaces, name, null, false, items); - expectedType(SymbolType.CURLY_CLOSE); - return new PackageAVM2Item(name, items); + int publicNs; + openedNamespaces.add(publicNs = abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId(name, true)), 0, true)); + + //traits(false, new ArrayList(), new Reference(false), new ArrayList(), importedClasses, privateNs, 0, publicNs, packageInternalNs, 0, openedNamespaces, name, null, false, items); + //expectedType(SymbolType.CURLY_CLOSE); + return new PackageAVM2Item(publicNs,importedClasses,name, items); } - public PackageAVM2Item packageFromString(String str, String fileName) throws ParseException, IOException, CompilationException { + private List parseScript(String fileName) throws IOException, ParseException, CompilationException { + + List openedNamespaces = new ArrayList<>(); + + int scriptPrivateNs = 0; + + if (fileName.contains("/")) { + fileName = fileName.substring(fileName.lastIndexOf('/') + 1); + } + if (fileName.contains("\\")) { + fileName = fileName.substring(fileName.lastIndexOf('\\') + 1); + } + String className = fileName; + if (className.endsWith(".as")) { + className = className.substring(0, className.length() - 3); + } + openedNamespaces.add(scriptPrivateNs = abc.constants.addNamespace(new Namespace(Namespace.KIND_PRIVATE, 0))); //abc.constants.getStringId(name + ":" + className, true) + + int publicNs; + openedNamespaces.add(publicNs = abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId("", true)),0,true)); + + List items = new ArrayList<>(); + traits(fileName,true, new ArrayList(), new Reference<>(false), new ArrayList(), new ArrayList(), scriptPrivateNs, 0, publicNs, 0, 0, openedNamespaces, null, null, false, items); + return items; + } + + public List scriptTraitsFromString(String str, String fileName) throws ParseException, IOException, CompilationException { lexer = new ActionScriptLexer(str); - PackageAVM2Item ret = parsePackage(fileName); + List ret = parseScript(fileName); if (lexer.lex().type != SymbolType.EOF) { throw new ParseException("Parsing finisned before end of the file", lexer.yyline()); } return ret; } - public void addScriptFromTree(PackageAVM2Item pkg, boolean documentClass) throws ParseException, CompilationException { + public void addScriptFromTree(List items, boolean documentClass) throws ParseException, CompilationException { AVM2SourceGenerator gen = new AVM2SourceGenerator(abc, otherABCs); List ret = new ArrayList<>(); SourceGeneratorLocalData localData = new SourceGeneratorLocalData( new HashMap(), 0, Boolean.FALSE, 0); - String className = ""; - for (GraphTargetItem it : pkg.items) { - if (it instanceof ClassAVM2Item) { - className = ((ClassAVM2Item) it).className; - } - } localData.documentClass = documentClass; - abc.script_info.add(gen.generateScriptInfo(pkg, localData, pkg.items)); + abc.script_info.add(gen.generateScriptInfo(localData, items)); } public void addScript(String s, boolean documentClass, String fileName) throws ParseException, IOException, CompilationException { - PackageAVM2Item pkg = packageFromString(s, fileName); - addScriptFromTree(pkg, documentClass); + List traits = scriptTraitsFromString(s, fileName); + addScriptFromTree(traits, documentClass); } public ActionScriptParser(ABC abc, List otherABCs) { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ClassAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ClassAVM2Item.java index d2ff03423..3ca799143 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ClassAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ClassAVM2Item.java @@ -27,7 +27,7 @@ import java.util.ArrayList; import java.util.List; public class ClassAVM2Item extends AVM2Item implements Block { - + public List traits; public GraphTargetItem extendsOp; public List implementsOp; @@ -41,7 +41,10 @@ public class ClassAVM2Item extends AVM2Item implements Block { public List staticInit; public boolean staticInitActivation; public List sinitVariables; + public List importedClasses; + public String pkg; + @Override public List> getSubs() { List> ret = new ArrayList<>(); @@ -51,8 +54,10 @@ public class ClassAVM2Item extends AVM2Item implements Block { return ret; } - public ClassAVM2Item(List openedNamespaces, int protectedNs, boolean isDynamic, boolean isFinal, int namespace, String className, GraphTargetItem extendsOp, List implementsOp, List staticInit, boolean staticInitActivation, List sinitVariables, GraphTargetItem constructor, List traits) { + public ClassAVM2Item(List importedClasses,String pkg,List openedNamespaces, int protectedNs, boolean isDynamic, boolean isFinal, int namespace, String className, GraphTargetItem extendsOp, List implementsOp, List staticInit, boolean staticInitActivation, List sinitVariables, GraphTargetItem constructor, List traits) { super(null, NOPRECEDENCE); + this.importedClasses = importedClasses; + this.pkg = pkg; this.protectedNs = protectedNs; this.className = className; this.traits = traits; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstAVM2Item.java index 1387746f6..80c9f404a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstAVM2Item.java @@ -33,7 +33,8 @@ public class ConstAVM2Item extends AVM2Item { public GraphTargetItem type; public String customNamespace; public int line; - + public String pkg; + public int getNamespace() { return namespace; } @@ -42,8 +43,9 @@ public class ConstAVM2Item extends AVM2Item { return isStatic; } - public ConstAVM2Item(String customNamespace, boolean isStatic, int namespace, String var, GraphTargetItem type, GraphTargetItem value, int line) { + public ConstAVM2Item(String pkg,String customNamespace, boolean isStatic, int namespace, String var, GraphTargetItem type, GraphTargetItem value, int line) { super(null, NOPRECEDENCE); + this.pkg = pkg; this.line = line; this.namespace = namespace; this.value = value; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/FunctionAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/FunctionAVM2Item.java index 2fa25757f..5b4307c0e 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/FunctionAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/FunctionAVM2Item.java @@ -46,9 +46,11 @@ public class FunctionAVM2Item extends AVM2Item { public boolean hasRest; public boolean needsActivation; public boolean isInterface; + public String pkg; - public FunctionAVM2Item(boolean isInterface, boolean needsActivation, int namespace, boolean hasRest, int line, String functionName, List paramTypes, List paramNames, List paramValues, List body, List subvariables, GraphTargetItem retType) { + public FunctionAVM2Item(String pkg,boolean isInterface, boolean needsActivation, int namespace, boolean hasRest, int line, String functionName, List paramTypes, List paramNames, List paramValues, List body, List subvariables, GraphTargetItem retType) { super(null, NOPRECEDENCE); + this.pkg = pkg; this.needsActivation = needsActivation; this.namespace = namespace; this.paramNames = paramNames; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/GetterAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/GetterAVM2Item.java index 41569f6f5..0c23b23b9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/GetterAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/GetterAVM2Item.java @@ -25,8 +25,8 @@ import java.util.List; */ public class GetterAVM2Item extends MethodAVM2Item { - public GetterAVM2Item(boolean isInterface, String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, int namespace, String methodName, List paramTypes, List paramNames, List paramValues, List body, List subvariables, GraphTargetItem retType) { - super(isInterface, customNamespace, needsActivation, hasRest, line, override, isFinal, isStatic, namespace, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType); + public GetterAVM2Item(String pkg, boolean isInterface, String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, int namespace, String methodName, List paramTypes, List paramNames, List paramValues, List body, List subvariables, GraphTargetItem retType) { + super(pkg,isInterface, customNamespace, needsActivation, hasRest, line, override, isFinal, isStatic, namespace, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/InterfaceAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/InterfaceAVM2Item.java index 53fd6ffc8..3d8d8867a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/InterfaceAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/InterfaceAVM2Item.java @@ -35,9 +35,13 @@ public class InterfaceAVM2Item extends AVM2Item { public int namespace; public boolean isFinal; public List openedNamespaces; + public String pkg; + public List importedClasses; - public InterfaceAVM2Item(List openedNamespaces, boolean isFinal, int namespace, String name, List superInterfaces, List traits) { + public InterfaceAVM2Item(List importedClasses,String pkg,List openedNamespaces, boolean isFinal, int namespace, String name, List superInterfaces, List traits) { super(null, NOPRECEDENCE); + this.importedClasses = importedClasses; + this.pkg = pkg; this.name = name; this.superInterfaces = superInterfaces; this.methods = traits; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/MethodAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/MethodAVM2Item.java index fd8b9b24f..3f6ec3ae0 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/MethodAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/MethodAVM2Item.java @@ -33,8 +33,8 @@ public class MethodAVM2Item extends FunctionAVM2Item { public String customNamespace; public boolean isInterface; - public MethodAVM2Item(boolean isInterface, String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, int namespace, String methodName, List paramTypes, List paramNames, List paramValues, List body, List subvariables, GraphTargetItem retType) { - super(isInterface, needsActivation, namespace, hasRest, line, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType); + public MethodAVM2Item(String pkg,boolean isInterface, String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, int namespace, String methodName, List paramTypes, List paramNames, List paramValues, List body, List subvariables, GraphTargetItem retType) { + super(pkg,isInterface, needsActivation, namespace, hasRest, line, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType); this.isStatic = isStatic; this.override = override; this.isFinal = isFinal; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PackageAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PackageAVM2Item.java index e4680b8fe..56e887e8d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PackageAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PackageAVM2Item.java @@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.model.LocalData; import com.jpexs.decompiler.graph.model.UnboundedTypeItem; +import java.util.ArrayList; import java.util.List; /** @@ -31,9 +32,13 @@ public class PackageAVM2Item extends AVM2Item { public List items; public String packageName; + public List importedClasses=new ArrayList(); + public int publicNs = 0; - public PackageAVM2Item(String packageName, List items) { + public PackageAVM2Item(int publicNs,List importedClasses, String packageName, List items) { super(null, NOPRECEDENCE); + this.publicNs = publicNs; + this.importedClasses = importedClasses; this.items = items; this.packageName = packageName; } 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 6bee9d637..e7ab05bed 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 @@ -309,7 +309,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item { for (ABC a : abcs) { for (InstanceInfo ii : a.instance_info) { Multiname m = ii.getName(a.constants); - if (m.getNameWithNamespace(a.constants).equals(objType)) { + if (multinameToType(ii.name_index, a.constants).equals(objType)) { Reference outName = new Reference<>(""); Reference outNs = new Reference<>(""); Reference outPropNs = new Reference<>(""); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SetterAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SetterAVM2Item.java index 89b4d187f..bcb2ad8a3 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SetterAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SetterAVM2Item.java @@ -25,8 +25,8 @@ import java.util.List; */ public class SetterAVM2Item extends MethodAVM2Item { - public SetterAVM2Item(boolean isInterface, String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, int namespace, String methodName, List paramTypes, List paramNames, List paramValues, List body, List subvariables, GraphTargetItem retType) { - super(isInterface, customNamespace, needsActivation, hasRest, line, override, isFinal, isStatic, namespace, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType); + public SetterAVM2Item(String pkg,boolean isInterface, String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, int namespace, String methodName, List paramTypes, List paramNames, List paramValues, List body, List subvariables, GraphTargetItem retType) { + super(pkg,isInterface, customNamespace, needsActivation, hasRest, line, override, isFinal, isStatic, namespace, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SlotAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SlotAVM2Item.java index 37d211d97..3a009721d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SlotAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SlotAVM2Item.java @@ -33,7 +33,8 @@ public class SlotAVM2Item extends AVM2Item { public GraphTargetItem type; public String customNamespace; public int line; - + public String pkg; + public int getNamespace() { return namespace; } @@ -42,8 +43,9 @@ public class SlotAVM2Item extends AVM2Item { return isStatic; } - public SlotAVM2Item(String customNamespace, boolean isStatic, int namespace, String var, GraphTargetItem type, GraphTargetItem value, int line) { + public SlotAVM2Item(String pkg,String customNamespace, boolean isStatic, int namespace, String var, GraphTargetItem type, GraphTargetItem value, int line) { super(null, NOPRECEDENCE); + this.pkg = pkg; this.line = line; this.namespace = namespace; this.value = value; 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 477501ea9..f1951701a 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 @@ -361,7 +361,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { String fname = Helper.joinStrings(parts.subList(0, i + 1), "."); for (ABC a : allAbcs) { for (int c = 0; c < a.instance_info.size(); c++) { - if (fname.equals(a.instance_info.get(c).getName(a.constants).getNameWithNamespace(a.constants))) { + if (a.instance_info.get(c).name_index>0 && fname.equals(a.instance_info.get(c).getName(a.constants).getNameWithNamespace(a.constants))) { if (!subtypes.isEmpty() && parts.size() > i + 1) { continue; } @@ -395,9 +395,14 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { //Search for types in opened namespaces for (int ni : openedNamespaces) { Namespace ons = abc.constants.getNamespace(ni); + if(ons == null){ + continue; + } for (ABC a : allAbcs) { for (int c = 0; c < a.instance_info.size(); c++) { - if ((a == abc && a.instance_info.get(c).getName(a.constants).namespace_index == ni) || (ons.kind != Namespace.KIND_PRIVATE && a.instance_info.get(c).getName(a.constants).getNamespace(a.constants).hasName(ons.getName(abc.constants), a.constants))) { + if ((a.instance_info.get(c).getName(a.constants)!=null && a == abc && a.instance_info.get(c).getName(a.constants).namespace_index == ni) + || + (ons.kind != Namespace.KIND_PRIVATE && a.instance_info.get(c).getName(a.constants)!=null &&a.instance_info.get(c).getName(a.constants).getNamespace(a.constants)!=null && a.instance_info.get(c).getName(a.constants).getNamespace(a.constants).hasName(ons.getName(abc.constants), a.constants))) { String cname = a.instance_info.get(c).getName(a.constants).getName(a.constants, new ArrayList()); if (parts.get(0).equals(cname)) { if (!subtypes.isEmpty() && parts.size() > 1) { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodInfo.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodInfo.java index 689b6f9e2..0289e57d2 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodInfo.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodInfo.java @@ -276,7 +276,7 @@ public class MethodInfo { if (optional != null) { if (i >= param_types.length - optional.length) { int optionalIndex = i - (param_types.length - optional.length); - writer.appendNoHilight("="); + writer.appendNoHilight(" = "); writer.hilightSpecial(optional[optionalIndex].toString(constants), "optional", optionalIndex); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/Namespace.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/Namespace.java index 61c45c063..8333e6c21 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/Namespace.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/Namespace.java @@ -101,6 +101,13 @@ public class Namespace { } return constants.getString(name_index); } + + public boolean hasName(ConstantPool constants,String name){ + if(name == null){ + return name_index == 0; + } + return name.equals(getName(constants)); + } public boolean hasName(String name, ConstantPool constants) { if (name == null && name_index == 0) { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTreeModel.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTreeModel.java index c48d44f9a..d1903ef08 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTreeModel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTreeModel.java @@ -125,7 +125,7 @@ public class ClassesListTreeModel implements TreeModel, TreeElementItem { } } //String nsName = path.contains(".") ? path.substring(path.lastIndexOf(".") + 1) : path; - //String packageName = path.contains(".") ? path.substring(0, path.lastIndexOf(".")) : ""; + //String packageName = path.contains(".") ? path.substring(0, path.lastIndexOf(".")) : ""; classTree.add(item.key.className, item.key.packageStr, item.value); } } diff --git a/trunk/test/com/jpexs/decompiler/flash/RecompileTest.java b/trunk/test/com/jpexs/decompiler/flash/RecompileTest.java index 6e0cc48c0..3e070700c 100644 --- a/trunk/test/com/jpexs/decompiler/flash/RecompileTest.java +++ b/trunk/test/com/jpexs/decompiler/flash/RecompileTest.java @@ -123,14 +123,25 @@ public class RecompileTest { Configuration.autoDeobfuscate.set(false); try{SWF swf = new SWF(new BufferedInputStream(new FileInputStream(TESTDATADIR + File.separator + filename)), false); if (swf.fileAttributes.actionScript3) { + boolean dotest=false; List allAbcs = new ArrayList<>(); for (ABCContainerTag ct : swf.abcList) { allAbcs.add(ct.getABC()); } for (ABC abc : allAbcs) { for (int s = 0; s < abc.script_info.size(); s++) { + + String startAfter=null; HilightedTextWriter htw = new HilightedTextWriter(new CodeFormatting(), false); MyEntry en = abc.script_info.get(s).getPacks(abc, s).get(0); + if(startAfter==null || en.key.toString().equals(startAfter)){ + dotest = true; + } + if(!dotest){ + System.out.println("Skipped:"+en.key.toString()); + continue; + } + System.out.println("Recompiling:"+en.key.toString()+"..."); en.value.toSource(htw, swf.abcList, abc.script_info.get(s).traits.traits, ScriptExportMode.AS, false); String original = htw.toString();