AS3 direct editation - various fixes related to namespaces

FILLSTYLE from SWF version annotations added
This commit is contained in:
Jindra Petřík
2015-11-15 08:16:52 +01:00
parent af62ca403d
commit b5376b19e4
27 changed files with 883 additions and 643 deletions

View File

@@ -52,6 +52,9 @@ public class SourceGeneratorLocalData implements Serializable {
public String currentClass;
public String superClass = null;
public DottedChain superPkg = null;
public int activationReg = 0;
public List<MethodBody> callStack = new ArrayList<>();

View File

@@ -1269,7 +1269,7 @@ public class ABC {
}
List<ABC> otherAbcs = new ArrayList<>(pack.allABCs);
otherAbcs.remove(this);
ActionScript3Parser.compile(as, this, otherAbcs, isDocumentClass, scriptName, newClassIndex);
ActionScript3Parser.compile(as, this, otherAbcs, isDocumentClass, scriptName, newClassIndex, oldIndex);
if (isSimple) {
// Move newly added script to its position

View File

@@ -155,9 +155,9 @@ public class ScriptPack extends AS3ClassTreeItem {
}*/
public void convert(final NulWriter writer, final List<Trait> traits, final ConvertData convertData, final ScriptExportMode exportMode, final boolean parallel) throws InterruptedException {
int script_init = abc.script_info.get(scriptIndex).init_index;
int bodyIndex = abc.findBodyIndex(script_init);
if (bodyIndex != -1) {
int sinit_index = abc.script_info.get(scriptIndex).init_index;
int sinit_bodyIndex = abc.findBodyIndex(sinit_index);
if (sinit_bodyIndex != -1) {
List<Traits> ts = new ArrayList<>();
//initialize all classes traits
for (Trait t : traits) {
@@ -165,9 +165,9 @@ public class ScriptPack extends AS3ClassTreeItem {
ts.add(abc.class_info.get(((TraitClass) t).class_info).static_traits);
}
}
ts.add(abc.script_info.get(scriptIndex).traits);
writer.mark();
abc.bodies.get(bodyIndex).convert(convertData, path +/*packageName +*/ "/.scriptinitializer", exportMode, true, script_init, scriptIndex, -1, abc, null, new ScopeStack(), GraphTextWriter.TRAIT_SCRIPT_INITIALIZER, writer, new ArrayList<>(), ts, true);
abc.bodies.get(sinit_bodyIndex).convert(convertData, path +/*packageName +*/ "/.scriptinitializer", exportMode, true, sinit_index, scriptIndex, -1, abc, null, new ScopeStack(), GraphTextWriter.TRAIT_SCRIPT_INITIALIZER, writer, new ArrayList<>(), ts, true);
scriptInitializerIsEmpty = !writer.getMark();
}

View File

@@ -1937,6 +1937,11 @@ public class AVM2Code implements Cloneable {
if (((TraitSlotConst) t).isConst() || initializerType == GraphTextWriter.TRAIT_CLASS_INITIALIZER || initializerType == GraphTextWriter.TRAIT_SCRIPT_INITIALIZER) {
TraitSlotConst tsc = (TraitSlotConst) t;
if (value != null && !convertData.assignedValues.containsKey(tsc)) {
if (value instanceof NewFunctionAVM2Item) {
NewFunctionAVM2Item f = (NewFunctionAVM2Item) value;
f.functionName = tsc.getName(abc).getName(abc.constants, fullyQualifiedNames, true);
}
AssignedValue av = new AssignedValue(value, initializerType, methodIndex);
convertData.assignedValues.put(tsc, av);
list.remove(i);

View File

@@ -19,6 +19,7 @@ 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.parser.script.AVM2SourceGenerator;
import com.jpexs.decompiler.flash.abc.avm2.parser.script.NamespaceItem;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
@@ -34,12 +35,12 @@ public class GetDescendantsAVM2Item extends AVM2Item {
public GraphTargetItem multiname;
public List<Integer> openedNamespaces;
public List<NamespaceItem> openedNamespaces;
public String nameStr;
//constructor for compiler
public GetDescendantsAVM2Item(GraphTargetItem object, String nameStr, List<Integer> openedNamespaces) {
public GetDescendantsAVM2Item(GraphTargetItem object, String nameStr, List<NamespaceItem> openedNamespaces) {
super(null, PRECEDENCE_PRIMARY);
this.object = object;
this.nameStr = nameStr;

View File

@@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instructions;
import com.jpexs.decompiler.flash.abc.avm2.parser.script.AVM2SourceGenerator;
import com.jpexs.decompiler.flash.abc.avm2.parser.script.NamespaceItem;
import com.jpexs.decompiler.flash.abc.types.Multiname;
import com.jpexs.decompiler.flash.abc.types.Namespace;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
@@ -58,11 +59,10 @@ public class InitVectorAVM2Item extends AVM2Item {
public List<GraphTargetItem> arguments;
List<Integer> openedNamespaces;
List<NamespaceItem> openedNamespaces;
private int allNsSet(ABC abc) {
int[] nssa = Helper.toIntArray(openedNamespaces);
return abc.constants.getNamespaceSetId(nssa, true);
return NamespaceItem.getCpoolSetIndex(abc.constants, openedNamespaces);
}
public InitVectorAVM2Item(AVM2Instruction ins, GraphTargetItem subtype, List<GraphTargetItem> arguments) {
@@ -71,7 +71,7 @@ public class InitVectorAVM2Item extends AVM2Item {
this.arguments = arguments;
}
public InitVectorAVM2Item(GraphTargetItem subtype, List<GraphTargetItem> arguments, List<Integer> openedNamespaces) {
public InitVectorAVM2Item(GraphTargetItem subtype, List<GraphTargetItem> arguments, List<NamespaceItem> openedNamespaces) {
super(null, PRECEDENCE_PRIMARY);
this.subtype = subtype;
this.arguments = arguments;
@@ -120,13 +120,11 @@ public class InitVectorAVM2Item extends AVM2Item {
ins(AVM2Instructions.Construct, 1)
);
for (int i = 0; i < arguments.size(); i++) {
// qname_index == precedence and params == openedNamespaced ???
int[] arr = Helper.toIntArray(openedNamespaces);
ret.addAll(toSourceMerge(localData, generator,
ins(AVM2Instructions.Dup),
new IntegerValueAVM2Item(null, (long) i),
arguments.get(i),
ins(AVM2Instructions.SetProperty, constants.getMultinameId(Multiname.createMultinameL(false, constants.getNamespaceSetId(new int[]{constants.getNamespaceId(Namespace.KIND_PACKAGE, "", 0, true)}, true)), true))
ins(AVM2Instructions.SetProperty, constants.getMultinameId(Multiname.createMultinameL(false, NamespaceItem.getCpoolSetIndex(constants, openedNamespaces)), true))
));
}
return ret;

View File

@@ -139,12 +139,13 @@ public class AVM2SourceGenerator implements SourceGenerator {
}
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, GetDescendantsAVM2Item item) throws CompilationException {
int[] nssa = new int[item.openedNamespaces.size()];
for (int i = 0; i < item.openedNamespaces.size(); i++) {
nssa[i] = item.openedNamespaces.get(i);
}
AVM2ConstantPool constants = abcIndex.getSelectedAbc().constants;
int[] nssa = new int[item.openedNamespaces.size()];
for (int i = 0; i < item.openedNamespaces.size(); i++) {
nssa[i] = item.openedNamespaces.get(i).getCpoolIndex(constants);
}
int nsset = constants.getNamespaceSetId(nssa, true);
return GraphTargetItem.toSourceMerge(localData, this,
@@ -316,8 +317,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
trueBody.addAll(toInsList(AssignableAVM2Item.getTemp(localData, this, xmlListReg)));
trueBody.addAll(toInsList(AssignableAVM2Item.getTemp(localData, this, counterReg)));
trueBody.addAll(toInsList(AssignableAVM2Item.getTemp(localData, this, tempVal1)));
int[] nss = Helper.toIntArray(item.openedNamespaces);
trueBody.add(ins(AVM2Instructions.SetProperty, constants.getMultinameId(Multiname.createMultinameL(false, constants.getNamespaceSetId(nss, true)), true)));
trueBody.add(ins(AVM2Instructions.SetProperty, constants.getMultinameId(Multiname.createMultinameL(false, NamespaceItem.getCpoolSetIndex(constants, item.openedNamespaces)), true)));
forBody.add(ins(AVM2Instructions.IfFalse, insToBytes(trueBody).length));
forBody.addAll(trueBody);
forBody.add(ins(AVM2Instructions.PopScope));
@@ -1157,11 +1157,11 @@ public class AVM2SourceGenerator implements SourceGenerator {
/*public ABC getABC() {
return abc;
}*/
public void generateClass(int privateNs, int protectedNs, List<DottedChain> importedClasses, List<AssignableAVM2Item> sinitVariables, boolean staticNeedsActivation, List<GraphTargetItem> staticInit, List<Integer> openedNamespaces, int namespace, int initScope, DottedChain pkg, ClassInfo classInfo, InstanceInfo instanceInfo, SourceGeneratorLocalData localData, boolean isInterface, String name, String superName, GraphTargetItem extendsVal, List<GraphTargetItem> implementsStr, GraphTargetItem constructor, List<GraphTargetItem> traitItems, Reference<Integer> class_index) throws AVM2ParseException, CompilationException {
public void generateClass(List<DottedChain> importedClasses, List<AssignableAVM2Item> cinitVariables, boolean cinitNeedsActivation, List<GraphTargetItem> cinit, List<NamespaceItem> openedNamespaces, int namespace, int initScope, DottedChain pkg, ClassInfo classInfo, InstanceInfo instanceInfo, SourceGeneratorLocalData localData, boolean isInterface, String name, String superName, GraphTargetItem extendsVal, List<GraphTargetItem> implementsStr, GraphTargetItem iinit, List<AssignableAVM2Item> iinitVariables, boolean iinitNeedsActivation, List<GraphTargetItem> traitItems, Reference<Integer> class_index) throws AVM2ParseException, CompilationException {
localData.currentClass = name;
localData.pkg = pkg;
localData.privateNs = privateNs;
localData.protectedNs = protectedNs;
localData.privateNs = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PRIVATE, pkg.toRawString() + ":" + name, 0, true);
localData.protectedNs = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PROTECTED, pkg.toRawString() + ":" + name, 0, true);
if (extendsVal == null && !isInterface) {
extendsVal = new TypeItem(DottedChain.OBJECT);
}
@@ -1175,16 +1175,16 @@ public class AVM2SourceGenerator implements SourceGenerator {
generateTraitsPhase3(initScope, isInterface, name, superName, false, localData, traitItems, instanceInfo.instance_traits, it, new HashMap<>(), class_index);
generateTraitsPhase3(initScope, isInterface, name, superName, true, localData, traitItems, classInfo.static_traits, st, new HashMap<>(), class_index);
int init;
if (constructor == null || isInterface) {
if (iinit == null || isInterface) {
instanceInfo.iinit_index = init = method(false, 0, false, 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;
MethodAVM2Item m = (MethodAVM2Item) iinit;
instanceInfo.iinit_index = init = method(false, str(pkg.toRawString() + ":" + name + "/" + name), false, 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(true, str(""), false, 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 = abcIndex.getSelectedAbc().findBody(staticMi);
int cinit_index = method(true, str(""), false, false, new ArrayList<>(), pkg, cinitNeedsActivation, cinitVariables, initScope + (implementsStr.isEmpty() ? 0 : 1), false, 0, isInterface ? null : name, superName, false, localData, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), cinit, TypeItem.UNBOUNDED);
MethodBody cinitBody = abcIndex.getSelectedAbc().findBody(cinit_index);
List<AVM2Instruction> sinitcode = new ArrayList<>();
List<AVM2Instruction> initcode = new ArrayList<>();
@@ -1198,13 +1198,13 @@ public class AVM2SourceGenerator implements SourceGenerator {
if (ti instanceof SlotAVM2Item) {
val = ((SlotAVM2Item) ti).value;
isStatic = ((SlotAVM2Item) ti).isStatic();
ns = genNs(importedClasses, pkg, ((SlotAVM2Item) ti).customNamespace, ((SlotAVM2Item) ti).getNamespace(), openedNamespaces, localData, ((SlotAVM2Item) ti).line);
ns = genNs(importedClasses, pkg, ((SlotAVM2Item) ti).customNamespace, ((SlotAVM2Item) ti).pkg == null ? 0 : ((SlotAVM2Item) ti).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), openedNamespaces, localData, ((SlotAVM2Item) ti).line);
tname = ((SlotAVM2Item) ti).var;
}
if (ti instanceof ConstAVM2Item) {
val = ((ConstAVM2Item) ti).value;
isStatic = ((ConstAVM2Item) ti).isStatic();
ns = genNs(importedClasses, pkg, ((ConstAVM2Item) ti).customNamespace, ((ConstAVM2Item) ti).getNamespace(), openedNamespaces, localData, ((ConstAVM2Item) ti).line);
ns = genNs(importedClasses, pkg, ((ConstAVM2Item) ti).customNamespace, ((ConstAVM2Item) ti).pkg == null ? 0 : ((ConstAVM2Item) ti).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), openedNamespaces, localData, ((ConstAVM2Item) ti).line);
tname = ((ConstAVM2Item) ti).var;
isConst = true;
}
@@ -1228,16 +1228,16 @@ public class AVM2SourceGenerator implements SourceGenerator {
MethodBody initBody = null;
if (!isInterface) {
initBody = abcIndex.getSelectedAbc().findBody(init);
initBody.insertAll(constructor == null ? 0 : 2, initcode);//after getlocal0,pushscope
initBody.insertAll(iinit == null ? 0 : 2, initcode);//after getlocal0,pushscope
if (sinitBody.getCode().code.get(sinitBody.getCode().code.size() - 1).definition instanceof ReturnVoidIns) {
sinitBody.insertAll(2, sinitcode); //after getlocal0,pushscope
if (cinitBody.getCode().code.get(cinitBody.getCode().code.size() - 1).definition instanceof ReturnVoidIns) {
cinitBody.insertAll(2, sinitcode); //after getlocal0,pushscope
}
}
sinitBody.markOffsets();
sinitBody.autoFillStats(abcIndex.getSelectedAbc(), initScope + (implementsStr.isEmpty() ? 0 : 1), true);
cinitBody.markOffsets();
cinitBody.autoFillStats(abcIndex.getSelectedAbc(), initScope + (implementsStr.isEmpty() ? 0 : 1), true);
classInfo.cinit_index = staticMi;
classInfo.cinit_index = cinit_index;
if (initBody != null) {
initBody.autoFillStats(abcIndex.getSelectedAbc(), initScope + 1, true);
}
@@ -1270,7 +1270,16 @@ public class AVM2SourceGenerator implements SourceGenerator {
*/
if (cls instanceof ClassAVM2Item) {
ClassAVM2Item cai = (ClassAVM2Item) cls;
generateClass(cai.privateNs, cai.protectedNs, 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, class_index);
//TODO: iinit variables, iinit activation
generateClass(cai.importedClasses, cai.cinitVariables, cai.cinitActivation, 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.iinit,
cai.iinitVariables, cai.iinitActivation, cai.traits, class_index
);
if (!cai.isDynamic) {
ii.flags |= InstanceInfo.CLASS_SEALED;
}
@@ -1278,13 +1287,16 @@ public class AVM2SourceGenerator implements SourceGenerator {
ii.flags |= InstanceInfo.CLASS_FINAL;
}
ii.flags |= InstanceInfo.CLASS_PROTECTEDNS;
ii.protectedNS = cai.protectedNs;
ii.protectedNS = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PROTECTED, pkg.toRawString() + ":" + cai.className, 0, true);
}
if (cls instanceof InterfaceAVM2Item) {
InterfaceAVM2Item iai = (InterfaceAVM2Item) cls;
ii.flags |= InstanceInfo.CLASS_INTERFACE;
ii.flags |= InstanceInfo.CLASS_SEALED;
generateClass(0, 0, 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, class_index);
generateClass(iai.importedClasses, new ArrayList<>(), false, new ArrayList<>(),
iai.openedNamespaces, namespace, initScope, pkg, ci, ii, localData, true, iai.name, null, null, iai.superInterfaces, null, null, false, iai.methods,
class_index
);
}
return abcIndex.getSelectedAbc().instance_info.size() - 1;
@@ -1835,7 +1847,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
return null;
}
private int genNs(List<DottedChain> importedClasses, DottedChain pkg, String custom, int namespace, List<Integer> openedNamespaces, SourceGeneratorLocalData localData, int line) throws CompilationException {
private int genNs(List<DottedChain> importedClasses, DottedChain pkg, String custom, int namespace, List<NamespaceItem> openedNamespaces, SourceGeneratorLocalData localData, int line) throws CompilationException {
if (custom != null) {
PropertyAVM2Item prop = new PropertyAVM2Item(null, custom, abcIndex, openedNamespaces, new ArrayList<>());
Reference<ValueKind> value = new Reference<>(null);
@@ -1878,23 +1890,23 @@ public class AVM2SourceGenerator implements SourceGenerator {
return namespace;
}
public void generateTraitsPhase2(List<DottedChain> importedClasses, DottedChain pkg, List<GraphTargetItem> items, Trait[] traits, List<Integer> openedNamespaces, SourceGeneratorLocalData localData) throws CompilationException {
public void generateTraitsPhase2(List<DottedChain> importedClasses, DottedChain pkg, List<GraphTargetItem> items, Trait[] traits, List<NamespaceItem> openedNamespaces, SourceGeneratorLocalData localData) throws CompilationException {
for (int k = 0; k < items.size(); k++) {
GraphTargetItem item = items.get(k);
if (traits[k] == null) {
} else if (item instanceof InterfaceAVM2Item) {
traits[k].name_index = traitName(((InterfaceAVM2Item) item).namespace, ((InterfaceAVM2Item) item).name);
traits[k].name_index = traitName(((InterfaceAVM2Item) item).pkg == null ? 0 : ((InterfaceAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), ((InterfaceAVM2Item) item).name);
} else if (item instanceof ClassAVM2Item) {
traits[k].name_index = traitName(((ClassAVM2Item) item).namespace, ((ClassAVM2Item) item).className);
traits[k].name_index = traitName(((ClassAVM2Item) item).pkg == null ? 0 : ((ClassAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), ((ClassAVM2Item) item).className);
} else if ((item instanceof MethodAVM2Item) || (item instanceof GetterAVM2Item) || (item instanceof SetterAVM2Item)) {
traits[k].name_index = traitName(genNs(importedClasses, 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).pkg == null ? 0 : ((MethodAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), openedNamespaces, localData, ((MethodAVM2Item) item).line), ((MethodAVM2Item) item).functionName);
} else if (item instanceof FunctionAVM2Item) {
traits[k].name_index = traitName(((FunctionAVM2Item) item).namespace, ((FunctionAVM2Item) item).functionName);
traits[k].name_index = traitName(((FunctionAVM2Item) item).pkg == null ? 0 : ((FunctionAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), ((FunctionAVM2Item) item).functionName);
} else if (item instanceof ConstAVM2Item) {
traits[k].name_index = traitName(genNs(importedClasses, 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).pkg == null ? 0 : ((ConstAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), openedNamespaces, localData, ((ConstAVM2Item) item).line), ((ConstAVM2Item) item).var);
} else if (item instanceof SlotAVM2Item) {
traits[k].name_index = traitName(genNs(importedClasses, 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).pkg == null ? 0 : ((SlotAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), openedNamespaces, localData, ((SlotAVM2Item) item).line), ((SlotAVM2Item) item).var);
}
}
@@ -1910,7 +1922,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
Multiname.createQName(
false,
abcIndex.getSelectedAbc().constants.getStringId(((ClassAVM2Item) item).className, true),
((ClassAVM2Item) item).namespace), true);
((ClassAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants)), true);
if (((ClassAVM2Item) item).extendsOp != null) {
instanceInfo.super_index = typeName(localData, ((ClassAVM2Item) item).extendsOp);
@@ -1927,7 +1939,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
AVM2ConstantPool constants = abc.constants;
InstanceInfo instanceInfo = abc.instance_info.get(((TraitClass) traits[k]).class_info);
instanceInfo.name_index = constants.getMultinameId(Multiname.createQName(false, constants.getStringId(((InterfaceAVM2Item) item).name, true),
constants.getNamespaceId(Namespace.KIND_PACKAGE, ((InterfaceAVM2Item) item).pkg, 0, true)), true);
((InterfaceAVM2Item) item).pkg.getCpoolIndex(constants)), true);
instanceInfo.interfaces = new int[((InterfaceAVM2Item) item).superInterfaces.size()];
for (int i = 0; i < ((InterfaceAVM2Item) item).superInterfaces.size(); i++) {
@@ -1980,25 +1992,61 @@ public class AVM2SourceGenerator implements SourceGenerator {
continue;
}
if (item instanceof InterfaceAVM2Item) {
generateClass(((InterfaceAVM2Item) item).namespace, abcIndex.getSelectedAbc().class_info.get(((TraitClass) traits[k]).class_info), abcIndex.getSelectedAbc().instance_info.get(((TraitClass) traits[k]).class_info), initScopes.get(traits[k]), ((InterfaceAVM2Item) item).pkg, localData, (InterfaceAVM2Item) item, class_index);
generateClass(((InterfaceAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), abcIndex.getSelectedAbc().class_info.get(((TraitClass) traits[k]).class_info), abcIndex.getSelectedAbc().instance_info.get(((TraitClass) traits[k]).class_info), initScopes.get(traits[k]), ((InterfaceAVM2Item) item).pkg.name, localData, (InterfaceAVM2Item) item, class_index);
}
if (item instanceof ClassAVM2Item) {
generateClass(((ClassAVM2Item) item).namespace, abcIndex.getSelectedAbc().class_info.get(((TraitClass) traits[k]).class_info), abcIndex.getSelectedAbc().instance_info.get(((TraitClass) traits[k]).class_info), initScopes.get(traits[k]), ((ClassAVM2Item) item).pkg, localData, (ClassAVM2Item) item, class_index);
generateClass(((ClassAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), abcIndex.getSelectedAbc().class_info.get(((TraitClass) traits[k]).class_info), abcIndex.getSelectedAbc().instance_info.get(((TraitClass) traits[k]).class_info), initScopes.get(traits[k]), ((ClassAVM2Item) item).pkg.name, localData, (ClassAVM2Item) item, class_index);
}
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(mai.isStatic(), abcIndex.getSelectedAbc().constants.getStringId(localData.pkg.toRawString() + ":" + localData.currentClass + "/" + (mai.isPrivate() ? "private:" : "") + mai.functionName, true), false, 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);
((TraitMethodGetterSetter) traits[k]).method_info = method(mai.isStatic(), methodName(mai.outsidePackage, localData.pkg, mai.functionName, mai.pkg, className, mai.customNamespace), false, isInterface, new ArrayList<>(), localData.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(false, abcIndex.getSelectedAbc().constants.getStringId(fai.functionName, true), false, 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);
((TraitFunction) traits[k]).method_info = method(false, methodName(false/*?*/, localData.pkg, fai.functionName, fai.pkg, null, null), false, isInterface, new ArrayList<>(), localData.pkg, fai.needsActivation, fai.subvariables, methodInitScope, fai.hasRest, fai.line, className, superName, false, localData, fai.paramTypes, fai.paramNames, fai.paramValues, fai.body, fai.retType);
}
}
}
private int methodName(boolean outsidePkg, DottedChain pkg, String methodName, NamespaceItem ns, String className, String customNs) {
StringBuilder sb = new StringBuilder();
/*if (ns != null) {
sb.append(ns.name.toRawString());
}*/
if (className != null) {
if (pkg != null && !pkg.isEmpty() && !pkg.isTopLevel()) {
sb.append(pkg.toRawString());
sb.append(":");
}
sb.append(className);
}
if (customNs != null) {
sb.append(customNs);
} else if (ns != null) {
switch (ns.kind) {
case Namespace.KIND_PACKAGE_INTERNAL:
sb.append(pkg.toRawString());
break;
case Namespace.KIND_PRIVATE:
if (!outsidePkg) {
sb.append("/private");
}
break;
case Namespace.KIND_PROTECTED:
case Namespace.KIND_STATIC_PROTECTED:
sb.append("/protected");
break;
}
}
sb.append(":");
sb.append(methodName);
return abcIndex.getSelectedAbc().constants.getStringId(sb.toString(), true);
}
public Trait[] generateTraitsPhase1(String className, String superName, boolean generateStatic, SourceGeneratorLocalData localData, List<GraphTargetItem> items, Traits ts, Reference<Integer> classIndex) throws AVM2ParseException, CompilationException {
Trait[] traits = new Trait[items.size()];
int slot_id = 1;
@@ -2073,7 +2121,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
val = sai.value;
type = sai.type;
isStatic = sai.isStatic();
namespace = sai.getNamespace();
namespace = sai.pkg == null ? 0 : sai.pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants);
metadata = generateMetadata(((SlotAVM2Item) item).metadata);
}
if (item instanceof ConstAVM2Item) {
@@ -2084,7 +2132,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
var = cai.var;
val = cai.value;
type = cai.type;
namespace = cai.getNamespace();
namespace = cai.pkg == null ? 0 : cai.pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants);
isNamespace = type.toString().equals("Namespace");
isStatic = cai.isStatic();
metadata = generateMetadata(((ConstAVM2Item) item).metadata);
@@ -2115,7 +2163,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
tmgs.kindType = (item instanceof GetterAVM2Item) ? Trait.TRAIT_GETTER : ((item instanceof SetterAVM2Item) ? Trait.TRAIT_SETTER : Trait.TRAIT_METHOD);
//tmgs.name_index = traitName(((MethodAVM2Item) item).namespace, ((MethodAVM2Item) item).functionName);
tmgs.disp_id = mai.isStatic() ? disp_id++ : 0; //For a reason, there is disp_id only for static methods (or not?)
if (mai.isFinal() || mai.isStatic()) {
if (mai.isFinal() || (className != null && mai.isStatic())) {
tmgs.kindFlags |= Trait.ATTR_Final;
}
if (mai.isOverride()) {
@@ -2212,12 +2260,45 @@ public class AVM2SourceGenerator implements SourceGenerator {
}
}
mbCode.add(ins(AVM2Instructions.ReturnVoid));
mb.autoFillStats(abc, 1, false);
abc.addMethodBody(mb);
si.init_index = mb.method_info;
localData.pkg = DottedChain.EMPTY; //FIXME: pkg.packageName;
localData.pkg = DottedChain.EMPTY;
generateTraitsPhase3(1/*??*/, false, null, null, true, localData, commands, si.traits, traitArr, initScopes, class_index);
int maxSlotId = 0;
for (int k = 0; k < si.traits.traits.size(); k++) {
if (si.traits.traits.get(k) instanceof TraitSlotConst) {
TraitSlotConst ti = (TraitSlotConst) si.traits.traits.get(k);
if (ti.slot_id > maxSlotId) {
maxSlotId = ti.slot_id;
}
}
}
for (int k = 0; k < si.traits.traits.size(); k++) {
if ((si.traits.traits.get(k) instanceof TraitMethodGetterSetter) && (commands.get(k) instanceof MethodAVM2Item)) {
MethodAVM2Item mai = (MethodAVM2Item) commands.get(k);
if (mai.outsidePackage) {
TraitMethodGetterSetter tmgs = (TraitMethodGetterSetter) si.traits.traits.get(k);
TraitSlotConst nts = new TraitSlotConst();
nts.name_index = si.traits.traits.get(k).name_index;
nts.metadata = si.traits.traits.get(k).metadata;
nts.slot_id = maxSlotId + 1;
maxSlotId++;
nts.type_index = abcIndex.getSelectedAbc().constants.getQnameId("Function", Namespace.KIND_PACKAGE, "", true);
nts.value_index = 0;
nts.value_kind = 0;
int methodinfo = tmgs.method_info;
si.traits.traits.set(k, nts);
mbCode.add(ins(AVM2Instructions.NewFunction, methodinfo));
mbCode.add(ins(AVM2Instructions.InitProperty, nts.name_index));
}
}
}
mbCode.add(ins(AVM2Instructions.ReturnVoid));
mb.autoFillStats(abc, 1, false);
return si;
}

View File

@@ -119,7 +119,7 @@ public class CallAVM2Item extends AVM2Item {
Reference<ValueKind> outPropValue = new Reference<>(null);
Reference<ABC> outPropValueAbc = new Reference<>(null);
if (cname != null && AVM2SourceGenerator.searchPrototypeChain(localData.privateNs, localData.protectedNs, true, g.abcIndex, pkgName, cname, prop.propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc) && (localData.currentClass.equals("".equals(outNs.getVal()) ? outName.getVal() : outNs.getVal() + "." + outName.getVal()))) {
if (cname != null && AVM2SourceGenerator.searchPrototypeChain(localData.privateNs, localData.protectedNs, true, g.abcIndex, pkgName, cname, prop.propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc) && (localData.getFullClass().equals(outNs.getVal().add(outName.getVal()).toRawString()))) {
NameAVM2Item nobj = new NameAVM2Item(new TypeItem(localData.getFullClass()), 0, "this", null, false, new ArrayList<>());
nobj.setRegNumber(0);
obj = nobj;

View File

@@ -38,28 +38,27 @@ public class ClassAVM2Item extends AVM2Item implements Block {
public String className;
public GraphTargetItem constructor;
public int namespace;
public int protectedNs;
public int privateNs;
public GraphTargetItem iinit;
public boolean isDynamic;
public boolean isFinal;
public List<Integer> openedNamespaces;
public List<NamespaceItem> openedNamespaces;
public List<GraphTargetItem> staticInit;
public boolean staticInitActivation;
public boolean cinitActivation;
public List<AssignableAVM2Item> sinitVariables;
public boolean iinitActivation;
public List<AssignableAVM2Item> cinitVariables;
public List<DottedChain> importedClasses;
public DottedChain pkg;
public NamespaceItem pkg;
public List<AssignableAVM2Item> iinitVariables;
public List<Map.Entry<String, Map<String, String>>> metadata;
@@ -72,25 +71,24 @@ public class ClassAVM2Item extends AVM2Item implements Block {
return ret;
}
public ClassAVM2Item(List<Map.Entry<String, Map<String, String>>> metadata, List<DottedChain> importedClasses, DottedChain pkg, List<Integer> openedNamespaces, int privateNs, int protectedNs, boolean isDynamic, boolean isFinal, int namespace, String className, GraphTargetItem extendsOp, List<GraphTargetItem> implementsOp, List<GraphTargetItem> staticInit, boolean staticInitActivation, List<AssignableAVM2Item> sinitVariables, GraphTargetItem constructor, List<GraphTargetItem> traits) {
public ClassAVM2Item(List<Map.Entry<String, Map<String, String>>> metadata, List<DottedChain> importedClasses, NamespaceItem pkg, List<NamespaceItem> openedNamespaces, boolean isFinal, boolean isDynamic, String className, GraphTargetItem extendsOp, List<GraphTargetItem> implementsOp, List<GraphTargetItem> cinit, boolean staticInitActivation, List<AssignableAVM2Item> cinitVariables, GraphTargetItem iinit, List<AssignableAVM2Item> iinitVariables, List<GraphTargetItem> traits, boolean iinitActivation) {
super(null, NOPRECEDENCE);
this.metadata = metadata;
this.importedClasses = importedClasses;
this.pkg = pkg;
this.privateNs = privateNs;
this.protectedNs = protectedNs;
this.className = className;
this.traits = traits;
this.extendsOp = extendsOp;
this.implementsOp = implementsOp;
this.constructor = constructor;
this.namespace = namespace;
this.iinitActivation = iinitActivation;
this.iinit = iinit;
this.isDynamic = isDynamic;
this.isFinal = isFinal;
this.openedNamespaces = openedNamespaces;
this.staticInit = staticInit;
this.staticInitActivation = staticInitActivation;
this.sinitVariables = sinitVariables;
this.staticInit = cinit;
this.cinitActivation = staticInitActivation;
this.cinitVariables = cinitVariables;
this.iinitVariables = iinitVariables;
}
@Override

View File

@@ -30,8 +30,6 @@ import java.util.Map;
*/
public class ConstAVM2Item extends AVM2Item {
private final int namespace;
private final boolean isStatic;
public String var;
@@ -44,23 +42,18 @@ public class ConstAVM2Item extends AVM2Item {
public int line;
public DottedChain pkg;
public int getNamespace() {
return namespace;
}
public NamespaceItem pkg;
public boolean isStatic() {
return isStatic;
}
public ConstAVM2Item(List<Map.Entry<String, Map<String, String>>> metadata, DottedChain pkg, String customNamespace, boolean isStatic, int namespace, String var, GraphTargetItem type, GraphTargetItem value, int line) {
public ConstAVM2Item(List<Map.Entry<String, Map<String, String>>> metadata, NamespaceItem pkg, String customNamespace, boolean isStatic, String var, GraphTargetItem type, GraphTargetItem value, int line) {
super(null, NOPRECEDENCE, value);
this.metadata = metadata;
this.pkg = pkg;
this.line = line;
this.namespace = namespace;
this.isStatic = isStatic;
this.var = var;
this.type = type;

View File

@@ -34,9 +34,9 @@ import java.util.List;
*/
public class ConstructSomethingAVM2Item extends CallAVM2Item {
public List<Integer> openedNamespaces;
public List<NamespaceItem> openedNamespaces;
public ConstructSomethingAVM2Item(int line, List<Integer> openedNamespaces, GraphTargetItem name, List<GraphTargetItem> arguments) {
public ConstructSomethingAVM2Item(int line, List<NamespaceItem> openedNamespaces, GraphTargetItem name, List<GraphTargetItem> arguments) {
super(line, name, arguments);
this.openedNamespaces = openedNamespaces;
}
@@ -49,7 +49,7 @@ public class ConstructSomethingAVM2Item extends CallAVM2Item {
private int allNsSetWithVec(ABC abc) {
int[] nssa = new int[openedNamespaces.size() + 1];
for (int i = 0; i < openedNamespaces.size(); i++) {
nssa[i] = openedNamespaces.get(i);
nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc.constants);
}
nssa[nssa.length - 1] = abc.constants.getNamespaceId(Namespace.KIND_PACKAGE, "__AS3__.vec", 0, true);
return abc.constants.getNamespaceSetId(nssa, true);

View File

@@ -39,8 +39,6 @@ public class FunctionAVM2Item extends AVM2Item {
public String functionName;
public int namespace;
public List<String> paramNames;
public List<GraphTargetItem> body;
@@ -61,17 +59,16 @@ public class FunctionAVM2Item extends AVM2Item {
public boolean isInterface;
public DottedChain pkg;
public NamespaceItem pkg;
public List<Map.Entry<String, Map<String, String>>> metadata;
public FunctionAVM2Item(List<Map.Entry<String, Map<String, String>>> metadata, DottedChain pkg, boolean isInterface, boolean needsActivation, int namespace, boolean hasRest, int line, String functionName, List<GraphTargetItem> paramTypes, List<String> paramNames, List<GraphTargetItem> paramValues, List<GraphTargetItem> body, List<AssignableAVM2Item> subvariables, GraphTargetItem retType) {
public FunctionAVM2Item(List<Map.Entry<String, Map<String, String>>> metadata, NamespaceItem pkg, boolean isInterface, boolean needsActivation, boolean hasRest, int line, String functionName, List<GraphTargetItem> paramTypes, List<String> paramNames, List<GraphTargetItem> paramValues, List<GraphTargetItem> body, List<AssignableAVM2Item> subvariables, GraphTargetItem retType) {
super(null, NOPRECEDENCE);
this.metadata = metadata;
this.pkg = pkg;
this.needsActivation = needsActivation;
this.namespace = namespace;
this.paramNames = paramNames;
this.body = body;
this.functionName = functionName;

View File

@@ -27,7 +27,7 @@ import java.util.Map;
*/
public class GetterAVM2Item extends MethodAVM2Item {
public GetterAVM2Item(boolean isPrivate, List<Map.Entry<String, Map<String, String>>> metadata, DottedChain pkg, boolean isInterface, String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, int namespace, String methodName, List<GraphTargetItem> paramTypes, List<String> paramNames, List<GraphTargetItem> paramValues, List<GraphTargetItem> body, List<AssignableAVM2Item> subvariables, GraphTargetItem retType) {
super(isPrivate, metadata, pkg, isInterface, customNamespace, needsActivation, hasRest, line, override, isFinal, isStatic, namespace, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType);
public GetterAVM2Item(boolean outsidePackage, boolean isPrivate, List<Map.Entry<String, Map<String, String>>> metadata, NamespaceItem pkg, boolean isInterface, String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, String methodName, List<GraphTargetItem> paramTypes, List<String> paramNames, List<GraphTargetItem> paramValues, List<GraphTargetItem> body, List<AssignableAVM2Item> subvariables, GraphTargetItem retType) {
super(outsidePackage, isPrivate, metadata, pkg, isInterface, customNamespace, needsActivation, hasRest, line, override, isFinal, isStatic, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType);
}
}

View File

@@ -38,7 +38,7 @@ import java.util.List;
*/
public class IndexAVM2Item extends AssignableAVM2Item {
private final List<Integer> openedNamespaces;
private final List<NamespaceItem> openedNamespaces;
public GraphTargetItem object;
@@ -46,7 +46,7 @@ public class IndexAVM2Item extends AssignableAVM2Item {
public boolean attr;
public IndexAVM2Item(boolean attr, GraphTargetItem object, GraphTargetItem index, GraphTargetItem storeValue, List<Integer> openedNamespaces) {
public IndexAVM2Item(boolean attr, GraphTargetItem object, GraphTargetItem index, GraphTargetItem storeValue, List<NamespaceItem> openedNamespaces) {
super(storeValue);
this.object = object;
this.index = index;
@@ -55,7 +55,10 @@ public class IndexAVM2Item extends AssignableAVM2Item {
}
private int allNsSet(ABC abc) {
int[] nssa = Helper.toIntArray(openedNamespaces);
int[] nssa = new int[openedNamespaces.size()];
for (int i = 0; i < nssa.length; i++) {
nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc.constants);
}
return abc.constants.getNamespaceSetId(nssa, true);
}

View File

@@ -37,19 +37,17 @@ public class InterfaceAVM2Item extends AVM2Item {
public List<GraphTargetItem> methods;
public int namespace;
public boolean isFinal;
public List<Integer> openedNamespaces;
public List<NamespaceItem> openedNamespaces;
public DottedChain pkg;
public NamespaceItem pkg;
public List<DottedChain> importedClasses;
public List<Map.Entry<String, Map<String, String>>> metadata;
public InterfaceAVM2Item(List<Map.Entry<String, Map<String, String>>> metadata, List<DottedChain> importedClasses, DottedChain pkg, List<Integer> openedNamespaces, boolean isFinal, int namespace, String name, List<GraphTargetItem> superInterfaces, List<GraphTargetItem> traits) {
public InterfaceAVM2Item(List<Map.Entry<String, Map<String, String>>> metadata, List<DottedChain> importedClasses, NamespaceItem pkg, List<NamespaceItem> openedNamespaces, boolean isFinal, String name, List<GraphTargetItem> superInterfaces, List<GraphTargetItem> traits) {
super(null, NOPRECEDENCE);
this.metadata = metadata;
this.importedClasses = importedClasses;
@@ -57,7 +55,6 @@ public class InterfaceAVM2Item extends AVM2Item {
this.name = name;
this.superInterfaces = superInterfaces;
this.methods = traits;
this.namespace = namespace;
this.isFinal = isFinal;
this.openedNamespaces = openedNamespaces;
}

View File

@@ -37,6 +37,8 @@ public class MethodAVM2Item extends FunctionAVM2Item {
private final boolean isPrivate;
public final boolean outsidePackage;
public boolean isPrivate() {
return isPrivate;
}
@@ -44,8 +46,9 @@ public class MethodAVM2Item extends FunctionAVM2Item {
public String customNamespace;
//public boolean isInterface;
public MethodAVM2Item(boolean isPrivate, List<Map.Entry<String, Map<String, String>>> metadata, DottedChain pkg, boolean isInterface, String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, int namespace, String methodName, List<GraphTargetItem> paramTypes, List<String> paramNames, List<GraphTargetItem> paramValues, List<GraphTargetItem> body, List<AssignableAVM2Item> subvariables, GraphTargetItem retType) {
super(metadata, pkg, isInterface, needsActivation, namespace, hasRest, line, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType);
public MethodAVM2Item(boolean outsidePackage, boolean isPrivate, List<Map.Entry<String, Map<String, String>>> metadata, NamespaceItem pkg, boolean isInterface, String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, String methodName, List<GraphTargetItem> paramTypes, List<String> paramNames, List<GraphTargetItem> paramValues, List<GraphTargetItem> body, List<AssignableAVM2Item> subvariables, GraphTargetItem retType) {
super(metadata, pkg, isInterface, needsActivation, hasRest, line, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType);
this.outsidePackage = outsidePackage;
this.isStatic = isStatic;
this.override = override;
this.isFinal = isFinal;

View File

@@ -47,7 +47,7 @@ public class NameAVM2Item extends AssignableAVM2Item {
private int nsKind = -1;
public List<Integer> openedNamespaces;
public List<NamespaceItem> openedNamespaces;
public int line;
@@ -127,7 +127,7 @@ public class NameAVM2Item extends AssignableAVM2Item {
return variableName;
}
public NameAVM2Item(GraphTargetItem type, int line, String variableName, GraphTargetItem storeValue, boolean definition, List<Integer> openedNamespaces) {
public NameAVM2Item(GraphTargetItem type, int line, String variableName, GraphTargetItem storeValue, boolean definition, List<NamespaceItem> openedNamespaces) {
super(storeValue);
this.variableName = variableName;
this.assignedValue = storeValue;
@@ -206,7 +206,7 @@ public class NameAVM2Item extends AssignableAVM2Item {
String name = variableName;
boolean attr = false;
if (name != null && name.startsWith("@")) {
name = name.substring(1);
//name = name.substring(1);
attr = true;
}
AVM2SourceGenerator g = (AVM2SourceGenerator) generator;
@@ -255,18 +255,12 @@ public class NameAVM2Item extends AssignableAVM2Item {
@Override
public boolean hasReturnValue() {
if (definition) {
return false;
}
return true;
return !definition;
}
@Override
public boolean needsSemicolon() {
if (definition) {
return true;
}
return false;
return definition;
}
@Override

View File

@@ -0,0 +1,83 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.parser.script;
import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
import com.jpexs.decompiler.flash.abc.types.Namespace;
import com.jpexs.decompiler.graph.DottedChain;
import java.util.List;
import java.util.Objects;
/**
*
* @author JPEXS
*/
public class NamespaceItem {
public DottedChain name;
public int kind;
public NamespaceItem(DottedChain name, int kind) {
this.name = name;
this.kind = kind;
}
public NamespaceItem(String name, int kind) {
this.name = DottedChain.parse(name);
this.kind = kind;
}
@Override
public String toString() {
return Namespace.kindToStr(kind) + " " + name.toRawString();
}
@Override
public int hashCode() {
int hash = 7;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final NamespaceItem other = (NamespaceItem) obj;
if (!Objects.equals(this.name, other.name)) {
return false;
}
return (this.kind == other.kind);
}
public int getCpoolIndex(AVM2ConstantPool cpool) {
return cpool.getNamespaceId(kind, name, 0, true);
}
public static int getCpoolSetIndex(AVM2ConstantPool cpool, List<NamespaceItem> namespaces) {
int[] nssa = new int[namespaces.size()];
for (int i = 0; i < nssa.length; i++) {
nssa[i] = namespaces.get(i).getCpoolIndex(cpool);
}
return cpool.getNamespaceSetId(nssa, true);
}
}

View File

@@ -50,9 +50,9 @@ public class NamespacedAVM2Item extends AssignableAVM2Item {
public boolean attr;
public List<Integer> openedNamespaces;
public List<NamespaceItem> openedNamespaces;
public NamespacedAVM2Item(GraphTargetItem ns, String name, GraphTargetItem nameItem, GraphTargetItem obj, boolean attr, List<Integer> openedNamespaces, GraphTargetItem storeValue) {
public NamespacedAVM2Item(GraphTargetItem ns, String name, GraphTargetItem nameItem, GraphTargetItem obj, boolean attr, List<NamespaceItem> openedNamespaces, GraphTargetItem storeValue) {
super(storeValue);
this.ns = ns;
this.nameItem = nameItem;
@@ -63,7 +63,10 @@ public class NamespacedAVM2Item extends AssignableAVM2Item {
}
private int allNsSet(ABC abc) {
int[] nssa = Helper.toIntArray(openedNamespaces);
int[] nssa = new int[openedNamespaces.size()];
for (int i = 0; i < nssa.length; i++) {
nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc.constants);
}
return abc.constants.getNamespaceSetId(nssa, true);
}

View File

@@ -58,7 +58,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
public AbcIndexing abcIndex;
private final List<Integer> openedNamespaces;
private final List<NamespaceItem> openedNamespaces;
private final List<MethodBody> callStack;
@@ -70,7 +70,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
return p;
}
public PropertyAVM2Item(GraphTargetItem object, String propertyName, AbcIndexing abcIndex, List<Integer> openedNamespaces, List<MethodBody> callStack) {
public PropertyAVM2Item(GraphTargetItem object, String propertyName, AbcIndexing abcIndex, List<NamespaceItem> openedNamespaces, List<MethodBody> callStack) {
this.propertyName = propertyName;
this.object = object;
this.abcIndex = abcIndex;
@@ -84,7 +84,11 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
}
private int allNsSet(ABC abc) {
int[] nssa = Helper.toIntArray(openedNamespaces);
int[] nssa = new int[openedNamespaces.size()];
for (int i = 0; i < nssa.length; i++) {
nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc.constants);
}
return abc.constants.getNamespaceSetId(nssa, true);
}
@@ -249,10 +253,10 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
if (objType == null) {
loopobjType:
for (int i = 0; i < openedNamespaces.size(); i++) {
int nsindex = openedNamespaces.get(i);
int nsindex = openedNamespaces.get(i).getCpoolIndex(constants);
int nsKind = constants.getNamespace(openedNamespaces.get(i)).kind;
DottedChain nsname = constants.getNamespace(openedNamespaces.get(i)).getName(constants);
int nsKind = openedNamespaces.get(i).kind;
DottedChain nsname = openedNamespaces.get(i).name;
int name_index = 0;
for (int m = 1; m < constants.getMultinameCount(); m++) {
Multiname mname = constants.getMultiname(m);
@@ -314,7 +318,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
}
}
if (nsKind == Namespace.KIND_PACKAGE && propertyName != null) {
AbcIndexing.TraitIndex p = abcIndex.findNsProperty(new AbcIndexing.PropertyNsDef(propertyName, nsname, abc, openedNamespaces.get(i)), true, true);
AbcIndexing.TraitIndex p = abcIndex.findNsProperty(new AbcIndexing.PropertyNsDef(propertyName, nsname, abc, openedNamespaces.get(i).getCpoolIndex(constants)), true, true);
Reference<String> outName = new Reference<>("");
Reference<DottedChain> outNs = new Reference<>(DottedChain.EMPTY);
@@ -577,7 +581,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
GraphTargetItem targetType = propType.getVal();
String srcType = assignedValue.returnType().toString();
GraphTargetItem coerced = assignedValue;
if (!targetType.equals(srcType) && !propertyName.startsWith("@")) {
if (!targetType.toString().equals(srcType) && !propertyName.startsWith("@")) {
coerced = new CoerceAVM2Item(null, assignedValue, targetType);
}
return toSourceMerge(localData, generator, obj, coerced,
@@ -635,7 +639,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
/*List<ABC> abcs = new ArrayList<>();
abcs.add(abc);
abcs.addAll(otherABCs);*/
if (!localData.subMethod && cname != null && AVM2SourceGenerator.searchPrototypeChain(localData.privateNs, localData.protectedNs, true, abcIndex, pkgName, cname, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc) && (localData.currentClass.equals(outNs.getVal().add(outName.getVal())))) {
if (!localData.subMethod && cname != null && AVM2SourceGenerator.searchPrototypeChain(localData.privateNs, localData.protectedNs, true, abcIndex, pkgName, cname, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc) && (localData.getFullClass().equals(outNs.getVal().add(outName.getVal()).toRawString()))) {
NameAVM2Item nobj = new NameAVM2Item(new TypeItem(localData.getFullClass()), 0, "this", null, false, openedNamespaces);
nobj.setRegNumber(0);
obj = nobj;
@@ -670,7 +674,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
Reference<Integer> ret_temp = new Reference<>(-1);
Reference<Integer> obj_temp = new Reference<>(-1);
boolean isInteger = propType.getVal().equals("int");
boolean isInteger = propType.getVal().toString().equals("int");
List<GraphSourceItem> ret = toSourceMerge(localData, generator, obj, dupSetTemp(localData, generator, obj_temp),
//Start get original

View File

@@ -27,7 +27,7 @@ import java.util.Map;
*/
public class SetterAVM2Item extends MethodAVM2Item {
public SetterAVM2Item(boolean isPrivate, List<Map.Entry<String, Map<String, String>>> metadata, DottedChain pkg, boolean isInterface, String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, int namespace, String methodName, List<GraphTargetItem> paramTypes, List<String> paramNames, List<GraphTargetItem> paramValues, List<GraphTargetItem> body, List<AssignableAVM2Item> subvariables, GraphTargetItem retType) {
super(isPrivate, metadata, pkg, isInterface, customNamespace, needsActivation, hasRest, line, override, isFinal, isStatic, namespace, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType);
public SetterAVM2Item(boolean outsidePackage, boolean isPrivate, List<Map.Entry<String, Map<String, String>>> metadata, NamespaceItem pkg, boolean isInterface, String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, String methodName, List<GraphTargetItem> paramTypes, List<String> paramNames, List<GraphTargetItem> paramValues, List<GraphTargetItem> body, List<AssignableAVM2Item> subvariables, GraphTargetItem retType) {
super(outsidePackage, isPrivate, metadata, pkg, isInterface, customNamespace, needsActivation, hasRest, line, override, isFinal, isStatic, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType);
}
}

View File

@@ -30,8 +30,6 @@ import java.util.Map;
*/
public class SlotAVM2Item extends AVM2Item {
private final int namespace;
private final boolean isStatic;
public String var;
@@ -44,22 +42,17 @@ public class SlotAVM2Item extends AVM2Item {
public List<Map.Entry<String, Map<String, String>>> metadata;
public DottedChain pkg;
public int getNamespace() {
return namespace;
}
public NamespaceItem pkg;
public boolean isStatic() {
return isStatic;
}
public SlotAVM2Item(List<Map.Entry<String, Map<String, String>>> metadata, DottedChain pkg, String customNamespace, boolean isStatic, int namespace, String var, GraphTargetItem type, GraphTargetItem value, int line) {
public SlotAVM2Item(List<Map.Entry<String, Map<String, String>>> metadata, NamespaceItem pkg, String customNamespace, boolean isStatic, String var, GraphTargetItem type, GraphTargetItem value, int line) {
super(null, NOPRECEDENCE, value);
this.metadata = metadata;
this.pkg = pkg;
this.line = line;
this.namespace = namespace;
this.isStatic = isStatic;
this.var = var;
this.type = type;

View File

@@ -47,7 +47,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
private int nsKind = -1;
public List<Integer> openedNamespaces;
public List<NamespaceItem> openedNamespaces;
public int line;
@@ -153,7 +153,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
this.name = name;
}
public UnresolvedAVM2Item(List<GraphTargetItem> subtypes, List<DottedChain> importedClasses, boolean mustBeType, GraphTargetItem type, int line, DottedChain name, GraphTargetItem storeValue, List<Integer> openedNamespaces) {
public UnresolvedAVM2Item(List<GraphTargetItem> subtypes, List<DottedChain> importedClasses, boolean mustBeType, GraphTargetItem type, int line, DottedChain name, GraphTargetItem storeValue, List<NamespaceItem> openedNamespaces) {
super(storeValue);
this.name = name;
this.assignedValue = storeValue;
@@ -352,8 +352,8 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
}
//Search for types in opened namespaces
for (int ni : openedNamespaces) {
Namespace ons = abc.getSelectedAbc().constants.getNamespace(ni);
for (NamespaceItem n : openedNamespaces) {
Namespace ons = abc.getSelectedAbc().constants.getNamespace(n.getCpoolIndex(abc.getSelectedAbc().constants));
TypeItem ti = new TypeItem(ons.getName(abc.getSelectedAbc().constants).add(name.get(0)));
AbcIndexing.ClassIndex ci = abc.findClass(ti);
if (ci != null) {
@@ -381,7 +381,23 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
if (thisType == null) {
throw new CompilationException("Cannot use this in that context", line);
}
NameAVM2Item ret = new NameAVM2Item(thisType, line, name.get(0), null, false, openedNamespaces);
boolean isSuper = name.get(0).equals("super");
GraphTargetItem ntype = thisType;
if (isSuper) {
AbcIndexing.ClassIndex ci = abc.findClass(thisType);
if (ci == null) {
throw new CompilationException("This class not found", line);
}
ci = ci.parent;
if (ci == null) {
ntype = new TypeItem("Object");
} else {
ntype = new TypeItem(ci.abc.instance_info.get(ci.index).getName(ci.abc.constants).getNameWithNamespace(ci.abc.constants));
}
}
NameAVM2Item ret = new NameAVM2Item(ntype, line, name.get(0), null, false, openedNamespaces);
resolved = ret;
for (int i = 1; i < name.size(); i++) {
resolved = new PropertyAVM2Item(resolved, name.get(i), abc, openedNamespaces, new ArrayList<>());

View File

@@ -34,11 +34,11 @@ import java.util.List;
*/
public class XMLFilterAVM2Item extends AVM2Item {
public List<Integer> openedNamespaces;
public List<NamespaceItem> openedNamespaces;
public GraphTargetItem object;
public XMLFilterAVM2Item(GraphTargetItem object, GraphTargetItem value, List<Integer> openedNamespaces) {
public XMLFilterAVM2Item(GraphTargetItem object, GraphTargetItem value, List<NamespaceItem> openedNamespaces) {
super(null, NOPRECEDENCE, value);
this.openedNamespaces = openedNamespaces;
this.object = object;

View File

@@ -18,6 +18,8 @@ package com.jpexs.decompiler.flash.abc.types.traits;
import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
import com.jpexs.decompiler.flash.abc.avm2.model.NewFunctionAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.parser.script.FunctionAVM2Item;
import com.jpexs.decompiler.flash.abc.types.AssignedValue;
import com.jpexs.decompiler.flash.abc.types.ConvertData;
import com.jpexs.decompiler.flash.abc.types.Multiname;
@@ -29,6 +31,7 @@ import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
import com.jpexs.decompiler.graph.DottedChain;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.model.LocalData;
import com.jpexs.helpers.Helper;
import java.util.HashMap;
@@ -146,6 +149,12 @@ public class TraitSlotConst extends Trait implements TraitWithSlot {
if (showModifier) {
getModifiers(abc, isStatic, writer);
}
if (convertData.assignedValues.containsKey(this)) {
GraphTargetItem val = convertData.assignedValues.get(this).value;
if (val instanceof NewFunctionAVM2Item) {
return val.toString(writer, LocalData.create(abc.constants, new HashMap<>(), fullyQualifiedNames));
}
}
getNameStr(writer, abc, fullyQualifiedNames);
if (value_kind != 0 || convertData.assignedValues.containsKey(this)) {
writer.appendNoHilight(" = ");

View File

@@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.types.annotations.Conditional;
import com.jpexs.decompiler.flash.types.annotations.ConditionalType;
import com.jpexs.decompiler.flash.types.annotations.Internal;
import com.jpexs.decompiler.flash.types.annotations.SWFType;
import com.jpexs.decompiler.flash.types.annotations.SWFVersion;
import java.io.Serializable;
import java.util.Set;
@@ -40,14 +41,17 @@ public class FILLSTYLE implements NeedsCharacters, Serializable {
public static final int RADIAL_GRADIENT = 0x12;
@SWFVersion(from = 8)
public static final int FOCAL_RADIAL_GRADIENT = 0x13;
public static final int REPEATING_BITMAP = 0x40;
public static final int CLIPPED_BITMAP = 0x41;
@SWFVersion(from = 7)
public static final int NON_SMOOTHED_REPEATING_BITMAP = 0x42;
@SWFVersion(from = 7)
public static final int NON_SMOOTHED_CLIPPED_BITMAP = 0x43;
@Internal