mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-06 18:25:32 +00:00
Merge origin/master
This commit is contained in:
@@ -78,7 +78,7 @@ public abstract class AVM2Item extends GraphTargetItem {
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty) {
|
||||
if (!empty && object != null) {
|
||||
if (object.getPrecedence() > PRECEDENCE_PRIMARY) {
|
||||
writer.append("(");
|
||||
object.toString(writer, localData);
|
||||
|
||||
@@ -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.AbcIndexing;
|
||||
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;
|
||||
@@ -61,8 +62,8 @@ public class InitVectorAVM2Item extends AVM2Item {
|
||||
|
||||
List<NamespaceItem> openedNamespaces;
|
||||
|
||||
private int allNsSet(ABC abc) {
|
||||
return NamespaceItem.getCpoolSetIndex(abc.constants, openedNamespaces);
|
||||
private int allNsSet(AbcIndexing abc) throws CompilationException {
|
||||
return NamespaceItem.getCpoolSetIndex(abc, openedNamespaces);
|
||||
}
|
||||
|
||||
public InitVectorAVM2Item(AVM2Instruction ins, GraphTargetItem subtype, List<GraphTargetItem> arguments) {
|
||||
@@ -113,7 +114,7 @@ public class InitVectorAVM2Item extends AVM2Item {
|
||||
AVM2ConstantPool constants = abc.constants;
|
||||
List<GraphSourceItem> ret = toSourceMerge(localData, generator,
|
||||
ins(AVM2Instructions.FindPropertyStrict, constants.getMultinameId(Multiname.createMultiname(false, constants.getStringId("Vector", true), constants.getNamespaceSetId(new int[]{constants.getNamespaceId(Namespace.KIND_PACKAGE, "__AS3__.vec", 0, true)}, true)), true)),
|
||||
ins(AVM2Instructions.GetProperty, constants.getMultinameId(Multiname.createMultiname(false, constants.getStringId("Vector", true), allNsSet(abc)), true)),
|
||||
ins(AVM2Instructions.GetProperty, constants.getMultinameId(Multiname.createMultiname(false, constants.getStringId("Vector", true), allNsSet(g.abcIndex)), true)),
|
||||
subtype,
|
||||
ins(AVM2Instructions.ApplyType, 1),
|
||||
new IntegerValueAVM2Item(null, (long) arguments.size()),
|
||||
@@ -124,7 +125,7 @@ public class InitVectorAVM2Item extends AVM2Item {
|
||||
ins(AVM2Instructions.Dup),
|
||||
new IntegerValueAVM2Item(null, (long) i),
|
||||
arguments.get(i),
|
||||
ins(AVM2Instructions.SetProperty, constants.getMultinameId(Multiname.createMultinameL(false, NamespaceItem.getCpoolSetIndex(constants, openedNamespaces)), true))
|
||||
ins(AVM2Instructions.SetProperty, constants.getMultinameId(Multiname.createMultinameL(false, NamespaceItem.getCpoolSetIndex(g.abcIndex, openedNamespaces)), true))
|
||||
));
|
||||
}
|
||||
return ret;
|
||||
|
||||
@@ -143,7 +143,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
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);
|
||||
nssa[i] = item.openedNamespaces.get(i).getCpoolIndex(abcIndex);
|
||||
}
|
||||
|
||||
int nsset = constants.getNamespaceSetId(nssa, true);
|
||||
@@ -317,7 +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)));
|
||||
trueBody.add(ins(AVM2Instructions.SetProperty, constants.getMultinameId(Multiname.createMultinameL(false, NamespaceItem.getCpoolSetIndex(constants, item.openedNamespaces)), true)));
|
||||
trueBody.add(ins(AVM2Instructions.SetProperty, constants.getMultinameId(Multiname.createMultinameL(false, NamespaceItem.getCpoolSetIndex(abcIndex, item.openedNamespaces)), true)));
|
||||
forBody.add(ins(AVM2Instructions.IfFalse, insToBytes(trueBody).length));
|
||||
forBody.addAll(trueBody);
|
||||
forBody.add(ins(AVM2Instructions.PopScope));
|
||||
@@ -1167,13 +1167,13 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
}
|
||||
ParsedSymbol s = null;
|
||||
|
||||
Trait[] it = generateTraitsPhase1(name, superName, false, localData, traitItems, instanceInfo.instance_traits, class_index);
|
||||
Trait[] st = generateTraitsPhase1(name, superName, true, localData, traitItems, classInfo.static_traits, class_index);
|
||||
Trait[] it = generateTraitsPhase1(importedClasses, openedNamespaces, name, superName, false, localData, traitItems, instanceInfo.instance_traits, class_index);
|
||||
Trait[] st = generateTraitsPhase1(importedClasses, openedNamespaces, name, superName, true, localData, traitItems, classInfo.static_traits, class_index);
|
||||
generateTraitsPhase2(importedClasses, pkg, traitItems, it, openedNamespaces, localData);
|
||||
generateTraitsPhase2(importedClasses, pkg, traitItems, st, openedNamespaces, localData);
|
||||
abcIndex.refreshSelected();
|
||||
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);
|
||||
generateTraitsPhase3(importedClasses, initScope, isInterface, name, superName, false, localData, traitItems, instanceInfo.instance_traits, it, new HashMap<>(), class_index);
|
||||
generateTraitsPhase3(importedClasses, initScope, isInterface, name, superName, true, localData, traitItems, classInfo.static_traits, st, new HashMap<>(), class_index);
|
||||
int init;
|
||||
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*/);
|
||||
@@ -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).pkg == null ? 0 : ((SlotAVM2Item) ti).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), openedNamespaces, localData, ((SlotAVM2Item) ti).line);
|
||||
ns = genNs(importedClasses, pkg, ((SlotAVM2Item) ti).pkg, 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).pkg == null ? 0 : ((ConstAVM2Item) ti).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), openedNamespaces, localData, ((ConstAVM2Item) ti).line);
|
||||
ns = genNs(importedClasses, pkg, ((ConstAVM2Item) ti).pkg, openedNamespaces, localData, ((ConstAVM2Item) ti).line);
|
||||
tname = ((ConstAVM2Item) ti).var;
|
||||
isConst = true;
|
||||
}
|
||||
@@ -1847,47 +1847,9 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
return null;
|
||||
}
|
||||
|
||||
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);
|
||||
Reference<ABC> outAbc = new Reference<>(null);
|
||||
|
||||
prop.resolve(localData, new Reference<>(null), new Reference<>(null), new Reference<>(0), value, outAbc);
|
||||
boolean resolved = true;
|
||||
if (value.getVal() == null) {
|
||||
resolved = false;
|
||||
}
|
||||
if (!resolved) {
|
||||
|
||||
DottedChain fullCustom = null;
|
||||
for (DottedChain imp : importedClasses) {
|
||||
if (imp.getLast().equals(custom)) {
|
||||
fullCustom = imp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*List<ABC> aas = new ArrayList<>();
|
||||
aas.add(abc);
|
||||
aas.addAll(allABCs);*/
|
||||
AbcIndexing.TraitIndex ti = abcIndex.findScriptProperty(fullCustom);
|
||||
|
||||
if (ti != null) {
|
||||
if (ti.trait instanceof TraitSlotConst) {
|
||||
if (((TraitSlotConst) ti.trait).isNamespace()) {
|
||||
Namespace ns = ti.abc.constants.getNamespace(((TraitSlotConst) ti.trait).value_index);
|
||||
return abcIndex.getSelectedAbc().constants.getNamespaceId(ns.kind, ns.getName(ti.abc.constants), 0, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new CompilationException("Namespace not defined", line);
|
||||
}
|
||||
namespace = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_NAMESPACE,
|
||||
outAbc.getVal().constants.getNamespace(value.getVal().value_index).getName(outAbc.getVal().constants), 0, true);
|
||||
}
|
||||
return namespace;
|
||||
private int genNs(List<DottedChain> importedClasses, DottedChain pkg, NamespaceItem ns, List<NamespaceItem> openedNamespaces, SourceGeneratorLocalData localData, int line) throws CompilationException {
|
||||
ns.resolveCustomNs(abcIndex, importedClasses, pkg, openedNamespaces, localData);
|
||||
return ns.getCpoolIndex(abcIndex);
|
||||
}
|
||||
|
||||
public void generateTraitsPhase2(List<DottedChain> importedClasses, DottedChain pkg, List<GraphTargetItem> items, Trait[] traits, List<NamespaceItem> openedNamespaces, SourceGeneratorLocalData localData) throws CompilationException {
|
||||
@@ -1896,17 +1858,17 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
if (traits[k] == null) {
|
||||
|
||||
} else if (item instanceof InterfaceAVM2Item) {
|
||||
traits[k].name_index = traitName(((InterfaceAVM2Item) item).pkg == null ? 0 : ((InterfaceAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), ((InterfaceAVM2Item) item).name);
|
||||
traits[k].name_index = traitName(((InterfaceAVM2Item) item).pkg == null ? 0 : ((InterfaceAVM2Item) item).pkg.getCpoolIndex(abcIndex), ((InterfaceAVM2Item) item).name);
|
||||
} else if (item instanceof ClassAVM2Item) {
|
||||
traits[k].name_index = traitName(((ClassAVM2Item) item).pkg == null ? 0 : ((ClassAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), ((ClassAVM2Item) item).className);
|
||||
traits[k].name_index = traitName(((ClassAVM2Item) item).pkg == null ? 0 : ((ClassAVM2Item) item).pkg.getCpoolIndex(abcIndex), ((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).pkg == null ? 0 : ((MethodAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), openedNamespaces, localData, ((MethodAVM2Item) item).line), ((MethodAVM2Item) item).functionName);
|
||||
traits[k].name_index = traitName(genNs(importedClasses, pkg, ((MethodAVM2Item) item).pkg, openedNamespaces, localData, ((MethodAVM2Item) item).line), ((MethodAVM2Item) item).functionName);
|
||||
} else if (item instanceof FunctionAVM2Item) {
|
||||
traits[k].name_index = traitName(((FunctionAVM2Item) item).pkg == null ? 0 : ((FunctionAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), ((FunctionAVM2Item) item).functionName);
|
||||
traits[k].name_index = traitName(((FunctionAVM2Item) item).pkg == null ? 0 : ((FunctionAVM2Item) item).pkg.getCpoolIndex(abcIndex), ((FunctionAVM2Item) item).functionName);
|
||||
} else if (item instanceof ConstAVM2Item) {
|
||||
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);
|
||||
traits[k].name_index = traitName(genNs(importedClasses, pkg, ((ConstAVM2Item) item).pkg, 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).pkg == null ? 0 : ((SlotAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), openedNamespaces, localData, ((SlotAVM2Item) item).line), ((SlotAVM2Item) item).var);
|
||||
traits[k].name_index = traitName(genNs(importedClasses, pkg, ((SlotAVM2Item) item).pkg, openedNamespaces, localData, ((SlotAVM2Item) item).line), ((SlotAVM2Item) item).var);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1922,7 +1884,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
Multiname.createQName(
|
||||
false,
|
||||
abcIndex.getSelectedAbc().constants.getStringId(((ClassAVM2Item) item).className, true),
|
||||
((ClassAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants)), true);
|
||||
((ClassAVM2Item) item).pkg.getCpoolIndex(abcIndex)), true);
|
||||
|
||||
if (((ClassAVM2Item) item).extendsOp != null) {
|
||||
instanceInfo.super_index = typeName(localData, ((ClassAVM2Item) item).extendsOp);
|
||||
@@ -1939,7 +1901,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),
|
||||
((InterfaceAVM2Item) item).pkg.getCpoolIndex(constants)), true);
|
||||
((InterfaceAVM2Item) item).pkg.getCpoolIndex(abcIndex)), true);
|
||||
|
||||
instanceInfo.interfaces = new int[((InterfaceAVM2Item) item).superInterfaces.size()];
|
||||
for (int i = 0; i < ((InterfaceAVM2Item) item).superInterfaces.size(); i++) {
|
||||
@@ -1984,7 +1946,8 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void generateTraitsPhase3(int methodInitScope, boolean isInterface, String className, String superName, boolean generateStatic, SourceGeneratorLocalData localData, List<GraphTargetItem> items, Traits ts, Trait[] traits, Map<Trait, Integer> initScopes, Reference<Integer> class_index) throws AVM2ParseException, CompilationException {
|
||||
public void generateTraitsPhase3(List<DottedChain> importedClasses, int methodInitScope, boolean isInterface, String className, String superName, boolean generateStatic, SourceGeneratorLocalData localData, List<GraphTargetItem> items, Traits ts, Trait[] traits, Map<Trait, Integer> initScopes, Reference<Integer> class_index) throws AVM2ParseException, 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);
|
||||
@@ -1992,17 +1955,22 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
continue;
|
||||
}
|
||||
if (item instanceof InterfaceAVM2Item) {
|
||||
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);
|
||||
generateClass(((InterfaceAVM2Item) item).pkg.getCpoolIndex(abcIndex), 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).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);
|
||||
generateClass(((ClassAVM2Item) item).pkg.getCpoolIndex(abcIndex), 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;
|
||||
}
|
||||
for (List<NamespaceItem> ln : mai.allOpenedNamespaces) {
|
||||
for (NamespaceItem n : ln) {
|
||||
n.resolveCustomNs(abcIndex, importedClasses, localData.pkg, ln, localData);
|
||||
}
|
||||
}
|
||||
((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;
|
||||
@@ -2028,7 +1996,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
} else if (ns != null) {
|
||||
switch (ns.kind) {
|
||||
case Namespace.KIND_PACKAGE_INTERNAL:
|
||||
sb.append(pkg.toRawString());
|
||||
sb.append(pkg == null ? "" /*?*/ : pkg.toRawString());
|
||||
break;
|
||||
case Namespace.KIND_PRIVATE:
|
||||
|
||||
@@ -2047,7 +2015,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
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 {
|
||||
public Trait[] generateTraitsPhase1(List<DottedChain> importedClasses, List<NamespaceItem> openedNamespaces, 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;
|
||||
int disp_id = 3; //1 and 2 are for constructor
|
||||
@@ -2083,17 +2051,6 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
tc.class_info = classIndex.getVal();
|
||||
abcIndex.getSelectedAbc().addClass(ci, ii, classIndex.getVal());
|
||||
classIndex.setVal(classIndex.getVal() + 1);
|
||||
//tc.class_info = abc.instance_info.size() - 1;
|
||||
|
||||
/*instanceInfo.name_index = abc.getLastAbc().constants.addMultiname(new Multiname(Multiname.QNAME, abc.getLastAbc().constants.getStringId(((ClassAVM2Item) item).className, true),
|
||||
abc.getLastAbc().constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.getLastAbc().constants.getStringId(pkg.packageName, true)), 0, true), 0, 0, new ArrayList<Integer>()));
|
||||
*/
|
||||
|
||||
/*if (((ClassAVM2Item) item).extendsOp != null) {
|
||||
instanceInfo.super_index = typeName(localData, ((ClassAVM2Item) item).extendsOp);
|
||||
} else {
|
||||
instanceInfo.super_index = abc.getLastAbc().constants.getMultinameId(new Multiname(Multiname.QNAME, str("Object"), namespace(Namespace.KIND_PACKAGE, ""), 0, 0, new ArrayList<Integer>()), true);
|
||||
}*/
|
||||
tc.kindType = Trait.TRAIT_CLASS;
|
||||
// tc.name_index = traitName(((ClassAVM2Item) item).namespace, ((ClassAVM2Item) item).className);
|
||||
tc.slot_id = slot_id++;
|
||||
@@ -2121,7 +2078,10 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
val = sai.value;
|
||||
type = sai.type;
|
||||
isStatic = sai.isStatic();
|
||||
namespace = sai.pkg == null ? 0 : sai.pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants);
|
||||
if (sai.pkg != null) {
|
||||
sai.pkg.resolveCustomNs(abcIndex, importedClasses, localData.pkg, openedNamespaces, localData);
|
||||
}
|
||||
namespace = sai.pkg == null ? 0 : sai.pkg.getCpoolIndex(abcIndex);
|
||||
metadata = generateMetadata(((SlotAVM2Item) item).metadata);
|
||||
}
|
||||
if (item instanceof ConstAVM2Item) {
|
||||
@@ -2132,7 +2092,10 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
var = cai.var;
|
||||
val = cai.value;
|
||||
type = cai.type;
|
||||
namespace = cai.pkg == null ? 0 : cai.pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants);
|
||||
if (cai.pkg != null) {
|
||||
cai.pkg.resolveCustomNs(abcIndex, importedClasses, localData.pkg, openedNamespaces, localData);
|
||||
}
|
||||
namespace = cai.pkg == null ? 0 : cai.pkg.getCpoolIndex(abcIndex);
|
||||
isNamespace = type.toString().equals("Namespace");
|
||||
isStatic = cai.isStatic();
|
||||
metadata = generateMetadata(((ConstAVM2Item) item).metadata);
|
||||
@@ -2161,7 +2124,6 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
}
|
||||
TraitMethodGetterSetter tmgs = new TraitMethodGetterSetter();
|
||||
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() || (className != null && mai.isStatic())) {
|
||||
tmgs.kindFlags |= Trait.ATTR_Final;
|
||||
@@ -2188,11 +2150,11 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
return traits;
|
||||
}
|
||||
|
||||
public ScriptInfo generateScriptInfo(SourceGeneratorLocalData localData, List<GraphTargetItem> commands, int classPos) throws AVM2ParseException, CompilationException {
|
||||
public ScriptInfo generateScriptInfo(List<List<NamespaceItem>> allOpenedNamespaces, SourceGeneratorLocalData localData, List<GraphTargetItem> commands, int classPos) throws AVM2ParseException, CompilationException {
|
||||
Reference<Integer> class_index = new Reference<>(classPos);
|
||||
ScriptInfo si = new ScriptInfo();
|
||||
localData.currentScript = si;
|
||||
Trait[] traitArr = generateTraitsPhase1(null, null, true, localData, commands, si.traits, class_index);
|
||||
Trait[] traitArr = generateTraitsPhase1(new ArrayList<>(), new ArrayList<>(), null, null, true, localData, commands, si.traits, class_index);
|
||||
generateTraitsPhase2(new ArrayList<>(), null/*FIXME*/, commands, traitArr, new ArrayList<>(), localData);
|
||||
|
||||
abcIndex.refreshSelected();
|
||||
@@ -2263,7 +2225,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
abc.addMethodBody(mb);
|
||||
si.init_index = mb.method_info;
|
||||
localData.pkg = DottedChain.EMPTY;
|
||||
generateTraitsPhase3(1/*??*/, false, null, null, true, localData, commands, si.traits, traitArr, initScopes, class_index);
|
||||
generateTraitsPhase3(new ArrayList<>(), 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++) {
|
||||
@@ -2351,7 +2313,13 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
return TypeItem.UNBOUNDED;
|
||||
}
|
||||
|
||||
public static boolean searchPrototypeChain(int privateNs, int protectedNs, boolean instanceOnly, AbcIndexing abc, DottedChain pkg, String obj, String propertyName, Reference<String> outName, Reference<DottedChain> outNs, Reference<DottedChain> outPropNs, Reference<Integer> outPropNsKind, Reference<Integer> outPropNsIndex, Reference<GraphTargetItem> outPropType, Reference<ValueKind> outPropValue, Reference<ABC> outPropValueAbc) {
|
||||
public static boolean searchPrototypeChain(List<Integer> otherNs, int privateNs, int protectedNs, boolean instanceOnly, AbcIndexing abc, DottedChain pkg, String obj, String propertyName, Reference<String> outName, Reference<DottedChain> outNs, Reference<DottedChain> outPropNs, Reference<Integer> outPropNsKind, Reference<Integer> outPropNsIndex, Reference<GraphTargetItem> outPropType, Reference<ValueKind> outPropValue, Reference<ABC> outPropValueAbc) {
|
||||
for (int ns : otherNs) {
|
||||
if (searchPrototypeChain(ns, instanceOnly, abc, pkg, obj, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (searchPrototypeChain(privateNs, instanceOnly, abc, pkg, obj, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -576,4 +576,17 @@ public class AbcIndexing {
|
||||
public ABC getSelectedAbc() {
|
||||
return selectedAbc;
|
||||
}
|
||||
|
||||
public DottedChain nsValueToName(String valueStr) {
|
||||
for (ABC abc : abcs) {
|
||||
DottedChain ret = abc.nsValueToName(valueStr);
|
||||
if (!ret.isEmpty()) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
if (parent != null) {
|
||||
return parent.nsValueToName(valueStr);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ public class ActionScript3Parser {
|
||||
expectedType(SymbolType.PARENT_CLOSE);
|
||||
break;
|
||||
case PARENT_OPEN:
|
||||
ret = new CallAVM2Item(lexer.yyline(), ret, call(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables));
|
||||
ret = new CallAVM2Item(openedNamespaces, lexer.yyline(), ret, call(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables));
|
||||
break;
|
||||
case DESCENDANTS:
|
||||
s = lex();
|
||||
@@ -468,7 +468,7 @@ public class ActionScript3Parser {
|
||||
|
||||
private MethodAVM2Item method(List<List<NamespaceItem>> allOpenedNamespaces, boolean outsidePackage, boolean isPrivate, List<Map.Entry<String, Map<String, String>>> metadata, NamespaceItem pkg, boolean isInterface, String customAccess, Reference<Boolean> needsActivation, List<DottedChain> importedClasses, boolean override, boolean isFinal, TypeItem thisType, List<NamespaceItem> openedNamespaces, boolean isStatic, String functionName, boolean isMethod, List<AssignableAVM2Item> variables) throws IOException, AVM2ParseException {
|
||||
FunctionAVM2Item f = function(allOpenedNamespaces, metadata, pkg, isInterface, needsActivation, importedClasses, thisType, openedNamespaces, functionName, isMethod, variables);
|
||||
return new MethodAVM2Item(outsidePackage, isPrivate, f.metadata, f.pkg, f.isInterface, customAccess, f.needsActivation, f.hasRest, f.line, override, isFinal, isStatic, functionName, f.paramTypes, f.paramNames, f.paramValues, f.body, f.subvariables, f.retType);
|
||||
return new MethodAVM2Item(allOpenedNamespaces, outsidePackage, isPrivate, f.metadata, f.pkg, f.isInterface, customAccess, f.needsActivation, f.hasRest, f.line, override, isFinal, isStatic, functionName, f.paramTypes, f.paramNames, f.paramValues, f.body, f.subvariables, f.retType);
|
||||
}
|
||||
|
||||
private FunctionAVM2Item function(List<List<NamespaceItem>> allOpenedNamespaces, List<Map.Entry<String, Map<String, String>>> metadata, NamespaceItem pkg, boolean isInterface, Reference<Boolean> needsActivation, List<DottedChain> importedClasses, TypeItem thisType, List<NamespaceItem> openedNamespaces, String functionName, boolean isMethod, List<AssignableAVM2Item> variables) throws IOException, AVM2ParseException {
|
||||
@@ -697,6 +697,10 @@ public class ActionScript3Parser {
|
||||
if (namespace == protectedNs && isStatic) {
|
||||
namespace = staticProtectedNs;
|
||||
}
|
||||
if (namespace == null && customNs != null) {
|
||||
//Special: it will be resolved later:
|
||||
namespace = new NamespaceItem(customNs, Namespace.KIND_NAMESPACE);
|
||||
}
|
||||
|
||||
switch (s.type) {
|
||||
case FUNCTION:
|
||||
@@ -766,10 +770,10 @@ public class ActionScript3Parser {
|
||||
}
|
||||
}
|
||||
if (isGetter) {
|
||||
GetterAVM2Item g = new GetterAVM2Item(outsidePackage, ft.isPrivate(), ft.metadata, ft.pkg, isInterface, customNs, ft.needsActivation, ft.hasRest, ft.line, ft.isOverride(), ft.isFinal(), isStatic, ft.functionName, ft.paramTypes, ft.paramNames, ft.paramValues, ft.body, ft.subvariables, ft.retType);
|
||||
GetterAVM2Item g = new GetterAVM2Item(allOpenedNamespaces, outsidePackage, ft.isPrivate(), ft.metadata, ft.pkg, isInterface, customNs, ft.needsActivation, ft.hasRest, ft.line, ft.isOverride(), ft.isFinal(), isStatic, ft.functionName, ft.paramTypes, ft.paramNames, ft.paramValues, ft.body, ft.subvariables, ft.retType);
|
||||
t = g;
|
||||
} else if (isSetter) {
|
||||
SetterAVM2Item st = new SetterAVM2Item(outsidePackage, ft.isPrivate(), ft.metadata, ft.pkg, isInterface, customNs, ft.needsActivation, ft.hasRest, ft.line, ft.isOverride(), ft.isFinal(), isStatic, ft.functionName, ft.paramTypes, ft.paramNames, ft.paramValues, ft.body, ft.subvariables, ft.retType);
|
||||
SetterAVM2Item st = new SetterAVM2Item(allOpenedNamespaces, outsidePackage, ft.isPrivate(), ft.metadata, ft.pkg, isInterface, customNs, ft.needsActivation, ft.hasRest, ft.line, ft.isOverride(), ft.isFinal(), isStatic, ft.functionName, ft.paramTypes, ft.paramNames, ft.paramValues, ft.body, ft.subvariables, ft.retType);
|
||||
t = st;
|
||||
} else {
|
||||
t = ft;
|
||||
@@ -859,8 +863,8 @@ public class ActionScript3Parser {
|
||||
}
|
||||
}
|
||||
|
||||
private void scriptTraits(int scriptIndex, String scriptName, List<GraphTargetItem> traits) throws AVM2ParseException, IOException, CompilationException {
|
||||
List<List<NamespaceItem>> allOpenedNamespaces = new ArrayList<>();
|
||||
private void scriptTraits(List<List<NamespaceItem>> allOpenedNamespaces, int scriptIndex, String scriptName, List<GraphTargetItem> traits) throws AVM2ParseException, IOException, CompilationException {
|
||||
|
||||
while (scriptTraitsBlock(allOpenedNamespaces, scriptIndex, scriptName, traits)) {
|
||||
//empty
|
||||
}
|
||||
@@ -902,7 +906,9 @@ public class ActionScript3Parser {
|
||||
allOpenedNamespaces.add(openedNamespaces);
|
||||
NamespaceItem emptyNs = new NamespaceItem("", Namespace.KIND_PACKAGE);
|
||||
openedNamespaces.add(emptyNs);
|
||||
openedNamespaces.add(new NamespaceItem(AS3_NAMESPACE, Namespace.KIND_NAMESPACE));
|
||||
NamespaceItem as3Ns = new NamespaceItem(AS3_NAMESPACE, Namespace.KIND_NAMESPACE);
|
||||
as3Ns.forceResolve(abcIndex);
|
||||
openedNamespaces.add(as3Ns);
|
||||
|
||||
for (List<NamespaceItem> ln : allOpenedNamespaces) {
|
||||
if (publicNs != null && !ln.contains(publicNs)) {
|
||||
@@ -913,7 +919,7 @@ public class ActionScript3Parser {
|
||||
}
|
||||
}
|
||||
|
||||
List<DottedChain> importedClasses = parseImports(openedNamespaces);
|
||||
List<DottedChain> importedClasses = parseImportsUsages(openedNamespaces);
|
||||
|
||||
boolean isEmpty = true;
|
||||
|
||||
@@ -2393,37 +2399,46 @@ public class ActionScript3Parser {
|
||||
|
||||
private List<String> constantPool;
|
||||
|
||||
private List<DottedChain> parseImports(List<NamespaceItem> openedNamespaces) throws IOException, AVM2ParseException {
|
||||
private List<DottedChain> parseImportsUsages(List<NamespaceItem> openedNamespaces) throws IOException, AVM2ParseException {
|
||||
|
||||
ParsedSymbol s;
|
||||
List<DottedChain> importedClasses = new ArrayList<>();
|
||||
|
||||
s = lex();
|
||||
while (s.type == SymbolType.IMPORT) {
|
||||
while (s.isType(SymbolType.IMPORT, SymbolType.USE)) {
|
||||
boolean all = false;
|
||||
boolean isUse = s.type == SymbolType.USE;
|
||||
if (isUse) {
|
||||
expectedType(SymbolType.NAMESPACE);
|
||||
}
|
||||
s = lex();
|
||||
expected(s, lexer.yyline(), SymbolGroup.IDENTIFIER);
|
||||
DottedChain imp = new DottedChain();
|
||||
imp = imp.add(s.value.toString());
|
||||
DottedChain fullName = new DottedChain();
|
||||
fullName = fullName.add(s.value.toString());
|
||||
s = lex();
|
||||
boolean isStar = false;
|
||||
while (s.type == SymbolType.DOT) {
|
||||
|
||||
s = lex();
|
||||
if (s.type == SymbolType.MULTIPLY) {
|
||||
if (s.type == SymbolType.MULTIPLY && !isUse) {
|
||||
isStar = true;
|
||||
s = lex();
|
||||
break;
|
||||
}
|
||||
expected(s, lexer.yyline(), SymbolGroup.IDENTIFIER);
|
||||
imp = imp.add(s.value.toString());
|
||||
fullName = fullName.add(s.value.toString());
|
||||
s = lex();
|
||||
}
|
||||
|
||||
if (isStar) {
|
||||
openedNamespaces.add(new NamespaceItem(imp, Namespace.KIND_PACKAGE));
|
||||
openedNamespaces.add(new NamespaceItem(fullName, Namespace.KIND_PACKAGE));
|
||||
} else {
|
||||
importedClasses.add(imp);
|
||||
if (isUse) {
|
||||
//Note: in this case, fullName attribute will be changed to real NS insude NamespaceItem
|
||||
openedNamespaces.add(new NamespaceItem(fullName, Namespace.KIND_NAMESPACE));
|
||||
} else {
|
||||
importedClasses.add(fullName);
|
||||
}
|
||||
}
|
||||
|
||||
expected(s, lexer.yyline(), SymbolType.SEMICOLON);
|
||||
@@ -2433,7 +2448,7 @@ public class ActionScript3Parser {
|
||||
return importedClasses;
|
||||
}
|
||||
|
||||
private List<GraphTargetItem> parseScript(int scriptIndex, String fileName) throws IOException, AVM2ParseException, CompilationException {
|
||||
private List<GraphTargetItem> parseScript(List<List<NamespaceItem>> allOpenedNamespaces, int scriptIndex, String fileName) throws IOException, AVM2ParseException, CompilationException {
|
||||
|
||||
//int scriptPrivateNs;
|
||||
if (fileName.contains("/")) {
|
||||
@@ -2442,42 +2457,33 @@ public class ActionScript3Parser {
|
||||
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 = abcIndex.getSelectedAbc().constants.addNamespace(Namespace.KIND_PRIVATE, 0)); //abc.getLastAbc().constants.getStringId(name + ":" + className, true)
|
||||
|
||||
int publicNs;
|
||||
openedNamespaces.add(publicNs = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PACKAGE, "", 0, true));
|
||||
*/
|
||||
List<GraphTargetItem> items = new ArrayList<>();
|
||||
scriptTraits(scriptIndex, fileName, items);
|
||||
//FIXME traits(fileName, true, new ArrayList<>(), new Reference<>(false), new ArrayList<>(), new ArrayList<>(), scriptPrivateNs, 0, publicNs, 0, 0, openedNamespaces, null, null, false, items);
|
||||
scriptTraits(allOpenedNamespaces, scriptIndex, fileName, items);
|
||||
return items;
|
||||
}
|
||||
|
||||
public List<GraphTargetItem> scriptTraitsFromString(String str, String fileName, int scriptIndex) throws AVM2ParseException, IOException, CompilationException {
|
||||
public List<GraphTargetItem> scriptTraitsFromString(List<List<NamespaceItem>> allOpenedNamespaces, String str, String fileName, int scriptIndex) throws AVM2ParseException, IOException, CompilationException {
|
||||
lexer = new ActionScriptLexer(str);
|
||||
|
||||
List<GraphTargetItem> ret = parseScript(scriptIndex, fileName);
|
||||
List<GraphTargetItem> ret = parseScript(allOpenedNamespaces, scriptIndex, fileName);
|
||||
if (lexer.lex().type != SymbolType.EOF) {
|
||||
throw new AVM2ParseException("Parsing finisned before end of the file", lexer.yyline());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void addScriptFromTree(List<GraphTargetItem> items, boolean documentClass, int classPos) throws AVM2ParseException, CompilationException {
|
||||
public void addScriptFromTree(List<List<NamespaceItem>> allOpenedNamespaces, List<GraphTargetItem> items, boolean documentClass, int classPos) throws AVM2ParseException, CompilationException {
|
||||
AVM2SourceGenerator gen = new AVM2SourceGenerator(abcIndex);
|
||||
SourceGeneratorLocalData localData = new SourceGeneratorLocalData(
|
||||
new HashMap<>(), 0, Boolean.FALSE, 0);
|
||||
localData.documentClass = documentClass;
|
||||
abcIndex.getSelectedAbc().script_info.add(gen.generateScriptInfo(localData, items, classPos));
|
||||
abcIndex.getSelectedAbc().script_info.add(gen.generateScriptInfo(allOpenedNamespaces, localData, items, classPos));
|
||||
}
|
||||
|
||||
public void addScript(String s, boolean documentClass, String fileName, int classPos, int scriptIndex) throws AVM2ParseException, IOException, CompilationException {
|
||||
List<GraphTargetItem> traits = scriptTraitsFromString(s, fileName, scriptIndex);
|
||||
addScriptFromTree(traits, documentClass, classPos);
|
||||
List<List<NamespaceItem>> allOpenedNamespaces = new ArrayList<>();
|
||||
List<GraphTargetItem> traits = scriptTraitsFromString(allOpenedNamespaces, s, fileName, scriptIndex);
|
||||
addScriptFromTree(allOpenedNamespaces, traits, documentClass, classPos);
|
||||
}
|
||||
|
||||
public ActionScript3Parser(ABC abc, List<ABC> otherAbcs) {
|
||||
|
||||
@@ -45,9 +45,11 @@ public class CallAVM2Item extends AVM2Item {
|
||||
public List<GraphTargetItem> arguments;
|
||||
|
||||
public int line;
|
||||
public List<NamespaceItem> openedNamespaces;
|
||||
|
||||
public CallAVM2Item(int line, GraphTargetItem name, List<GraphTargetItem> arguments) {
|
||||
public CallAVM2Item(List<NamespaceItem> openedNamespaces, int line, GraphTargetItem name, List<GraphTargetItem> arguments) {
|
||||
super(null, NOPRECEDENCE);
|
||||
this.openedNamespaces = openedNamespaces;
|
||||
this.name = name;
|
||||
this.arguments = arguments;
|
||||
this.line = line;
|
||||
@@ -82,8 +84,13 @@ public class CallAVM2Item extends AVM2Item {
|
||||
Reference<GraphTargetItem> outPropType = new Reference<>(null);
|
||||
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, n.getVariableName(), outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueABC)) {
|
||||
List<Integer> otherNs = new ArrayList<>();
|
||||
for (NamespaceItem on : openedNamespaces) {
|
||||
if (on.isResolved()) {
|
||||
otherNs.add(on.getCpoolIndex(g.abcIndex));
|
||||
}
|
||||
}
|
||||
if (cname != null && AVM2SourceGenerator.searchPrototypeChain(otherNs, localData.privateNs, localData.protectedNs, true, g.abcIndex, pkgName, cname, n.getVariableName(), outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueABC)) {
|
||||
NameAVM2Item nobj = new NameAVM2Item(new TypeItem(localData.getFullClass()), n.line, "this", null, false, n.openedNamespaces);
|
||||
nobj.setRegNumber(0);
|
||||
obj = nobj;
|
||||
@@ -119,7 +126,14 @@ 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.getFullClass().equals(outNs.getVal().add(outName.getVal()).toRawString()))) {
|
||||
List<Integer> otherNs = new ArrayList<>();
|
||||
for (NamespaceItem n : openedNamespaces) {
|
||||
if (n.isResolved()) {
|
||||
otherNs.add(n.getCpoolIndex(g.abcIndex));
|
||||
}
|
||||
}
|
||||
|
||||
if (cname != null && AVM2SourceGenerator.searchPrototypeChain(otherNs, 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;
|
||||
|
||||
@@ -37,7 +37,7 @@ public class ConstructSomethingAVM2Item extends CallAVM2Item {
|
||||
public List<NamespaceItem> openedNamespaces;
|
||||
|
||||
public ConstructSomethingAVM2Item(int line, List<NamespaceItem> openedNamespaces, GraphTargetItem name, List<GraphTargetItem> arguments) {
|
||||
super(line, name, arguments);
|
||||
super(openedNamespaces, line, name, arguments);
|
||||
this.openedNamespaces = openedNamespaces;
|
||||
}
|
||||
|
||||
@@ -46,13 +46,13 @@ public class ConstructSomethingAVM2Item extends CallAVM2Item {
|
||||
return name.returnType();
|
||||
}
|
||||
|
||||
private int allNsSetWithVec(ABC abc) {
|
||||
private int allNsSetWithVec(AbcIndexing abc) throws CompilationException {
|
||||
int[] nssa = new int[openedNamespaces.size() + 1];
|
||||
for (int i = 0; i < openedNamespaces.size(); i++) {
|
||||
nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc.constants);
|
||||
nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc);
|
||||
}
|
||||
nssa[nssa.length - 1] = abc.constants.getNamespaceId(Namespace.KIND_PACKAGE, "__AS3__.vec", 0, true);
|
||||
return abc.constants.getNamespaceSetId(nssa, true);
|
||||
nssa[nssa.length - 1] = abc.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PACKAGE, "__AS3__.vec", 0, true);
|
||||
return abc.getSelectedAbc().constants.getNamespaceSetId(nssa, true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class GetterAVM2Item extends MethodAVM2Item {
|
||||
|
||||
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);
|
||||
public GetterAVM2Item(List<List<NamespaceItem>> allOpenedNamespaces, 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(allOpenedNamespaces, outsidePackage, isPrivate, metadata, pkg, isInterface, customNamespace, needsActivation, hasRest, line, override, isFinal, isStatic, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,12 +54,12 @@ public class IndexAVM2Item extends AssignableAVM2Item {
|
||||
this.attr = attr;
|
||||
}
|
||||
|
||||
private int allNsSet(ABC abc) {
|
||||
private int allNsSet(AbcIndexing abc) throws CompilationException {
|
||||
int[] nssa = new int[openedNamespaces.size()];
|
||||
for (int i = 0; i < nssa.length; i++) {
|
||||
nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc.constants);
|
||||
nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc);
|
||||
}
|
||||
return abc.constants.getNamespaceSetId(nssa, true);
|
||||
return abc.getSelectedAbc().constants.getNamespaceSetId(nssa, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,7 +88,7 @@ public class IndexAVM2Item extends AssignableAVM2Item {
|
||||
Reference<Integer> index_temp = new Reference<>(-1);
|
||||
Reference<Integer> val_temp = new Reference<>(-1);
|
||||
AVM2SourceGenerator g = (AVM2SourceGenerator) generator;
|
||||
int indexPropIndex = g.abcIndex.getSelectedAbc().constants.getMultinameId(Multiname.createMultinameL(attr, allNsSet(g.abcIndex.getSelectedAbc())), true);
|
||||
int indexPropIndex = g.abcIndex.getSelectedAbc().constants.getMultinameId(Multiname.createMultinameL(attr, allNsSet(g.abcIndex)), true);
|
||||
|
||||
return toSourceMerge(localData, generator,
|
||||
object, dupSetTemp(localData, generator, obj_temp),
|
||||
@@ -110,7 +110,7 @@ public class IndexAVM2Item extends AssignableAVM2Item {
|
||||
|
||||
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn, boolean call, List<GraphTargetItem> callargs, boolean delete, boolean construct) throws CompilationException {
|
||||
AVM2SourceGenerator g = (AVM2SourceGenerator) generator;
|
||||
int indexPropIndex = g.abcIndex.getSelectedAbc().constants.getMultinameId(Multiname.createMultinameL(attr, allNsSet(g.abcIndex.getSelectedAbc())), true);
|
||||
int indexPropIndex = g.abcIndex.getSelectedAbc().constants.getMultinameId(Multiname.createMultinameL(attr, allNsSet(g.abcIndex)), true);
|
||||
Reference<Integer> ret_temp = new Reference<>(-1);
|
||||
|
||||
if (assignedValue != null) {
|
||||
|
||||
@@ -45,10 +45,13 @@ public class MethodAVM2Item extends FunctionAVM2Item {
|
||||
|
||||
public String customNamespace;
|
||||
|
||||
public List<List<NamespaceItem>> allOpenedNamespaces;
|
||||
|
||||
//public boolean isInterface;
|
||||
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) {
|
||||
public MethodAVM2Item(List<List<NamespaceItem>> allOpenedNamespaces, 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.allOpenedNamespaces = allOpenedNamespaces;
|
||||
this.isStatic = isStatic;
|
||||
this.override = override;
|
||||
this.isFinal = isFinal;
|
||||
|
||||
@@ -16,9 +16,15 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.avm2.parser.script;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.types.Namespace;
|
||||
import com.jpexs.decompiler.flash.abc.types.ValueKind;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.DottedChain;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -30,6 +36,11 @@ public class NamespaceItem {
|
||||
|
||||
public DottedChain name;
|
||||
public int kind;
|
||||
private int nsIndex = -1;
|
||||
|
||||
public void forceResolve(AbcIndexing abcIndex) {
|
||||
nsIndex = abcIndex.getSelectedAbc().constants.getNamespaceId(kind, name, 0, true);
|
||||
}
|
||||
|
||||
public NamespaceItem(DottedChain name, int kind) {
|
||||
this.name = name;
|
||||
@@ -67,17 +78,76 @@ public class NamespaceItem {
|
||||
return (this.kind == other.kind);
|
||||
}
|
||||
|
||||
public int getCpoolIndex(AVM2ConstantPool cpool) {
|
||||
return cpool.getNamespaceId(kind, name, 0, true);
|
||||
public void resolveCustomNs(AbcIndexing abcIndex, List<DottedChain> importedClasses, DottedChain pkg, List<NamespaceItem> openedNamespaces, SourceGeneratorLocalData localData) throws CompilationException {
|
||||
if (nsIndex > -1) { //already resolved
|
||||
return;
|
||||
}
|
||||
if (kind == Namespace.KIND_NAMESPACE) {
|
||||
String custom = name.toRawString();
|
||||
PropertyAVM2Item prop = new PropertyAVM2Item(null, custom, abcIndex, openedNamespaces, new ArrayList<>());
|
||||
Reference<ValueKind> value = new Reference<>(null);
|
||||
Reference<ABC> outAbc = new Reference<>(null);
|
||||
|
||||
prop.resolve(true, localData, new Reference<>(null), new Reference<>(null), new Reference<>(0), value, outAbc);
|
||||
boolean resolved = true;
|
||||
if (value.getVal() == null) {
|
||||
resolved = false;
|
||||
}
|
||||
if (!resolved) {
|
||||
DottedChain fullCustom = null;
|
||||
for (DottedChain imp : importedClasses) {
|
||||
if (imp.getLast().equals(custom)) {
|
||||
fullCustom = imp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (fullCustom != null) {
|
||||
/*List<ABC> aas = new ArrayList<>();
|
||||
aas.add(abc);
|
||||
aas.addAll(allABCs);*/
|
||||
AbcIndexing.TraitIndex ti = abcIndex.findScriptProperty(fullCustom);
|
||||
|
||||
if (ti != null) {
|
||||
if (ti.trait instanceof TraitSlotConst) {
|
||||
if (((TraitSlotConst) ti.trait).isNamespace()) {
|
||||
Namespace ns = ti.abc.constants.getNamespace(((TraitSlotConst) ti.trait).value_index);
|
||||
nsIndex = abcIndex.getSelectedAbc().constants.getNamespaceId(ns.kind, ns.getName(ti.abc.constants), 0, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new CompilationException("Namespace \"" + name + "\"+not defined", -1);
|
||||
}
|
||||
nsIndex = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_NAMESPACE,
|
||||
outAbc.getVal().constants.getNamespace(value.getVal().value_index).getName(outAbc.getVal().constants), 0, true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static int getCpoolSetIndex(AVM2ConstantPool cpool, List<NamespaceItem> namespaces) {
|
||||
public boolean isResolved() {
|
||||
return nsIndex > -1;
|
||||
}
|
||||
|
||||
public int getCpoolIndex(AbcIndexing abcIndex) throws CompilationException {
|
||||
if (nsIndex > -1) {
|
||||
return nsIndex;
|
||||
}
|
||||
if (kind == Namespace.KIND_NAMESPACE) { //must set manually
|
||||
throw new CompilationException("Namespace \"" + name + "\" unresolved", -1);
|
||||
}
|
||||
nsIndex = abcIndex.getSelectedAbc().constants.getNamespaceId(kind, name, 0, true);
|
||||
return nsIndex;
|
||||
}
|
||||
|
||||
public static int getCpoolSetIndex(AbcIndexing abcIndex, List<NamespaceItem> namespaces) throws CompilationException {
|
||||
int[] nssa = new int[namespaces.size()];
|
||||
for (int i = 0; i < nssa.length; i++) {
|
||||
nssa[i] = namespaces.get(i).getCpoolIndex(cpool);
|
||||
nssa[i] = namespaces.get(i).getCpoolIndex(abcIndex);
|
||||
}
|
||||
|
||||
return cpool.getNamespaceSetId(nssa, true);
|
||||
return abcIndex.getSelectedAbc().constants.getNamespaceSetId(nssa, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -62,12 +62,12 @@ public class NamespacedAVM2Item extends AssignableAVM2Item {
|
||||
this.openedNamespaces = openedNamespaces;
|
||||
}
|
||||
|
||||
private int allNsSet(ABC abc) {
|
||||
private int allNsSet(AbcIndexing abc) throws CompilationException {
|
||||
int[] nssa = new int[openedNamespaces.size()];
|
||||
for (int i = 0; i < nssa.length; i++) {
|
||||
nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc.constants);
|
||||
nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc);
|
||||
}
|
||||
return abc.constants.getNamespaceSetId(nssa, true);
|
||||
return abc.getSelectedAbc().constants.getNamespaceSetId(nssa, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,7 +115,7 @@ public class NamespacedAVM2Item extends AssignableAVM2Item {
|
||||
//Start get original
|
||||
//getTemp(localData, generator, ns_temp), generateCoerce(generator, "Namespace"), ins(AVM2Instructions.FindPropertyStrict, g.abc.getLastAbc().constants.getMultinameId(new Multiname(Multiname.RTQNAME, g.abc.getLastAbc().constants.getStringId(variableName, true), 0, 0, 0, new ArrayList<Integer>()), true)),
|
||||
//getTemp(localData, generator, ns_temp), generateCoerce(generator, "Namespace"),
|
||||
ins(AVM2Instructions.GetProperty, constants.getMultinameId(Multiname.createMultinameL(false, allNsSet(abc)), true)),
|
||||
ins(AVM2Instructions.GetProperty, constants.getMultinameId(Multiname.createMultinameL(false, allNsSet(g.abcIndex)), true)),
|
||||
!isInteger ? ins(AVM2Instructions.ConvertD) : null,
|
||||
//End get original
|
||||
(!post) ? (decrement ? ins(isInteger ? AVM2Instructions.DecrementI : AVM2Instructions.Decrement) : ins(isInteger ? AVM2Instructions.IncrementI : AVM2Instructions.Increment)) : null,
|
||||
@@ -125,7 +125,7 @@ public class NamespacedAVM2Item extends AssignableAVM2Item {
|
||||
getTemp(localData, generator, name_temp),
|
||||
getTemp(localData, generator, ns_temp),
|
||||
getTemp(localData, generator, ret_temp),
|
||||
ins(AVM2Instructions.SetProperty, constants.getMultinameId(Multiname.createMultinameL(false, allNsSet(abc)), true)),
|
||||
ins(AVM2Instructions.SetProperty, constants.getMultinameId(Multiname.createMultinameL(false, allNsSet(g.abcIndex)), true)),
|
||||
killTemp(localData, generator, Arrays.asList(ret_temp, name_temp, ns_temp))
|
||||
);
|
||||
} else {
|
||||
|
||||
@@ -44,6 +44,8 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -82,13 +84,13 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
|
||||
return writer;
|
||||
}
|
||||
|
||||
private int allNsSet(ABC abc) {
|
||||
private int allNsSet(AbcIndexing abc) throws CompilationException {
|
||||
int[] nssa = new int[openedNamespaces.size()];
|
||||
for (int i = 0; i < nssa.length; i++) {
|
||||
nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc.constants);
|
||||
nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc);
|
||||
}
|
||||
|
||||
return abc.constants.getNamespaceSetId(nssa, true);
|
||||
return abc.getSelectedAbc().constants.getNamespaceSetId(nssa, true);
|
||||
}
|
||||
|
||||
public static GraphTargetItem multinameToType(int m_index, AVM2ConstantPool constants) {
|
||||
@@ -108,7 +110,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
|
||||
}
|
||||
}
|
||||
|
||||
public void resolve(SourceGeneratorLocalData localData, Reference<GraphTargetItem> objectType, Reference<GraphTargetItem> propertyType, Reference<Integer> propertyIndex, Reference<ValueKind> propertyValue, Reference<ABC> propertyValueABC) {
|
||||
public void resolve(boolean mustExist, SourceGeneratorLocalData localData, Reference<GraphTargetItem> objectType, Reference<GraphTargetItem> propertyType, Reference<Integer> propertyIndex, Reference<ValueKind> propertyValue, Reference<ABC> propertyValueABC) throws CompilationException {
|
||||
GraphTargetItem thisType = new TypeItem(localData.getFullClass());
|
||||
GraphTargetItem objType = null;
|
||||
GraphTargetItem objSubType = null;
|
||||
@@ -219,7 +221,13 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
|
||||
Reference<GraphTargetItem> outPropType = new Reference<>(null);
|
||||
Reference<ValueKind> outPropValue = new Reference<>(null);
|
||||
Reference<ABC> outPropValueAbc = new Reference<>(null);
|
||||
if (AVM2SourceGenerator.searchPrototypeChain(localData.privateNs, localData.protectedNs, false, abcIndex, ftn.getWithoutLast(), ftn.getLast(), propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) {
|
||||
List<Integer> otherNs = new ArrayList<>();
|
||||
for (NamespaceItem n : openedNamespaces) {
|
||||
if (n.isResolved()) {
|
||||
otherNs.add(n.getCpoolIndex(abcIndex));
|
||||
}
|
||||
}
|
||||
if (AVM2SourceGenerator.searchPrototypeChain(otherNs, localData.privateNs, localData.protectedNs, false, abcIndex, ftn.getWithoutLast(), ftn.getLast(), propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) {
|
||||
objType = new TypeItem(outNs.getVal().add(outName.getVal()));
|
||||
propType = outPropType.getVal();
|
||||
propIndex = constants.getMultinameId(Multiname.createQName(false,
|
||||
@@ -252,7 +260,10 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
|
||||
if (objType == null) {
|
||||
loopobjType:
|
||||
for (int i = 0; i < openedNamespaces.size(); i++) {
|
||||
int nsindex = openedNamespaces.get(i).getCpoolIndex(constants);
|
||||
if (!openedNamespaces.get(i).isResolved()) {
|
||||
continue;
|
||||
}
|
||||
int nsindex = openedNamespaces.get(i).getCpoolIndex(abcIndex);
|
||||
|
||||
int nsKind = openedNamespaces.get(i).kind;
|
||||
DottedChain nsname = openedNamespaces.get(i).name;
|
||||
@@ -317,7 +328,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).getCpoolIndex(constants)), true, true);
|
||||
AbcIndexing.TraitIndex p = abcIndex.findNsProperty(new AbcIndexing.PropertyNsDef(propertyName, nsname, abc, openedNamespaces.get(i).getCpoolIndex(abcIndex)), true, true);
|
||||
|
||||
Reference<String> outName = new Reference<>("");
|
||||
Reference<DottedChain> outNs = new Reference<>(DottedChain.EMPTY);
|
||||
@@ -328,7 +339,13 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
|
||||
Reference<ValueKind> outPropValue = new Reference<>(null);
|
||||
Reference<ABC> outPropValueAbc = new Reference<>(null);
|
||||
if (p != null && (p.objType instanceof TypeItem)) {
|
||||
if (AVM2SourceGenerator.searchPrototypeChain(localData.privateNs, localData.protectedNs, false, abcIndex, nsname, (((TypeItem) p.objType).fullTypeName.getLast()), propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) {
|
||||
List<Integer> otherns = new ArrayList<>();
|
||||
for (NamespaceItem n : openedNamespaces) {
|
||||
if (n.isResolved()) {
|
||||
otherns.add(n.getCpoolIndex(abcIndex));
|
||||
}
|
||||
}
|
||||
if (AVM2SourceGenerator.searchPrototypeChain(otherns, localData.privateNs, localData.protectedNs, false, abcIndex, nsname, (((TypeItem) p.objType).fullTypeName.getLast()), propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) {
|
||||
objType = new TypeItem(outNs.getVal().add(outName.getVal()));
|
||||
propType = p.returnType;
|
||||
propIndex = constants.getMultinameId(Multiname.createQName(false,
|
||||
@@ -353,7 +370,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
|
||||
}
|
||||
}
|
||||
|
||||
if (propIndex == 0) {
|
||||
if (propIndex == 0 && !mustExist) {
|
||||
String pname = propertyName;
|
||||
boolean attr = pname.startsWith("@");
|
||||
if (attr) {
|
||||
@@ -365,7 +382,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
|
||||
constants.getNamespaceSetId(new int[]{constants.getNamespaceId(Namespace.KIND_PACKAGE_INTERNAL, localData.pkg, 0, true)}, true));
|
||||
} else {
|
||||
int name_index = constants.getStringId("*".equals(pname) ? null : pname, true); //Note: name = * is for .@* attribute
|
||||
multiname = Multiname.createMultiname(attr, name_index, allNsSet(abc));
|
||||
multiname = Multiname.createMultiname(attr, name_index, allNsSet(abcIndex));
|
||||
}
|
||||
propIndex = constants.getMultinameId(multiname, true);
|
||||
propType = TypeItem.UNBOUNDED;
|
||||
@@ -381,13 +398,13 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
|
||||
objectType.setVal(objType);
|
||||
}
|
||||
|
||||
public int resolveProperty(SourceGeneratorLocalData localData) {
|
||||
public int resolveProperty(SourceGeneratorLocalData localData) throws CompilationException {
|
||||
Reference<GraphTargetItem> objType = new Reference<>(null);
|
||||
Reference<GraphTargetItem> propType = new Reference<>(null);
|
||||
Reference<Integer> propIndex = new Reference<>(0);
|
||||
Reference<ValueKind> outPropValue = new Reference<>(null);
|
||||
Reference<ABC> outPropValueAbc = new Reference<>(null);
|
||||
resolve(localData, objType, propType, propIndex, outPropValue, outPropValueAbc);
|
||||
resolve(false, localData, objType, propType, propIndex, outPropValue, outPropValueAbc);
|
||||
return propIndex.getVal();
|
||||
}
|
||||
|
||||
@@ -552,15 +569,20 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
|
||||
}*/
|
||||
@Override
|
||||
public GraphTargetItem returnType() {
|
||||
|
||||
Reference<GraphTargetItem> objType = new Reference<>(null);
|
||||
Reference<GraphTargetItem> propType = new Reference<>(null);
|
||||
Reference<Integer> propIndex = new Reference<>(0);
|
||||
Reference<ValueKind> outPropValue = new Reference<>(null);
|
||||
Reference<ABC> outPropValueAbc = new Reference<>(null);
|
||||
try {
|
||||
resolve(false, new SourceGeneratorLocalData(new HashMap<>(), 0, false, 0)/*???*/, objType, propType, propIndex, outPropValue, outPropValueAbc);
|
||||
|
||||
resolve(new SourceGeneratorLocalData(new HashMap<>(), 0, false, 0)/*???*/, objType, propType, propIndex, outPropValue, outPropValueAbc);
|
||||
|
||||
return propType.getVal();
|
||||
return propType.getVal();
|
||||
} catch (CompilationException ex) {
|
||||
Logger.getLogger(PropertyAVM2Item.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException {
|
||||
@@ -571,7 +593,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
|
||||
Reference<ValueKind> outPropValue = new Reference<>(null);
|
||||
Reference<ABC> outPropValueAbc = new Reference<>(null);
|
||||
|
||||
resolve(localData, objType, propType, propIndex, outPropValue, outPropValueAbc);
|
||||
resolve(false, localData, objType, propType, propIndex, outPropValue, outPropValueAbc);
|
||||
|
||||
int propertyId = propIndex.getVal();
|
||||
Object obj = resolveObject(localData, generator);
|
||||
@@ -620,7 +642,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Object resolveObject(SourceGeneratorLocalData localData, SourceGenerator generator) {
|
||||
public Object resolveObject(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
|
||||
Object obj = object;
|
||||
|
||||
if (obj == null) {
|
||||
@@ -638,7 +660,13 @@ 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.getFullClass().equals(outNs.getVal().add(outName.getVal()).toRawString()))) {
|
||||
List<Integer> otherNs = new ArrayList<>();
|
||||
for (NamespaceItem n : openedNamespaces) {
|
||||
if (n.isResolved()) {
|
||||
otherNs.add(n.getCpoolIndex(abcIndex));
|
||||
}
|
||||
}
|
||||
if (!localData.subMethod && cname != null && AVM2SourceGenerator.searchPrototypeChain(otherNs, 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;
|
||||
@@ -649,7 +677,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
|
||||
Reference<ValueKind> propValue = new Reference<>(null);
|
||||
Reference<ABC> propValueAbc = new Reference<>(null);
|
||||
|
||||
resolve(localData, objType, propType, propIndex, outPropValue, propValueAbc);
|
||||
resolve(false, localData, objType, propType, propIndex, outPropValue, propValueAbc);
|
||||
obj = ins(AVM2Instructions.FindPropertyStrict, propIndex.getVal());
|
||||
}
|
||||
}
|
||||
@@ -665,7 +693,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
|
||||
Reference<ValueKind> outPropValue = new Reference<>(null);
|
||||
Reference<ABC> outPropValueAbc = new Reference<>(null);
|
||||
|
||||
resolve(localData, objType, propType, propIndex, outPropValue, outPropValueAbc);
|
||||
resolve(false, localData, objType, propType, propIndex, outPropValue, outPropValueAbc);
|
||||
|
||||
int propertyId = propIndex.getVal();
|
||||
Object obj = resolveObject(localData, generator);
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class SetterAVM2Item extends MethodAVM2Item {
|
||||
|
||||
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);
|
||||
public SetterAVM2Item(List<List<NamespaceItem>> allOpenedNamespaces, 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(allOpenedNamespaces, outsidePackage, isPrivate, metadata, pkg, isInterface, customNamespace, needsActivation, hasRest, line, override, isFinal, isStatic, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,7 +353,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
|
||||
|
||||
//Search for types in opened namespaces
|
||||
for (NamespaceItem n : openedNamespaces) {
|
||||
Namespace ons = abc.getSelectedAbc().constants.getNamespace(n.getCpoolIndex(abc.getSelectedAbc().constants));
|
||||
Namespace ons = abc.getSelectedAbc().constants.getNamespace(n.getCpoolIndex(abc));
|
||||
TypeItem ti = new TypeItem(ons.getName(abc.getSelectedAbc().constants).add(name.get(0)));
|
||||
AbcIndexing.ClassIndex ci = abc.findClass(ti);
|
||||
if (ci != null) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.IdentifiersDeobfuscation;
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.ClassPath;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.AVM2Code;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.AVM2Deobfuscation;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.alchemy.AlchemyTypeIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.construction.NewFunctionIns;
|
||||
@@ -110,15 +111,15 @@ public abstract class Trait implements Cloneable, Serializable {
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected void parseImportsUsagesFromMultiname(ABC abc, List<DottedChain> imports, List<String> uses, Multiname m, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) {
|
||||
protected void parseImportsUsagesFromMultiname(String ignoredCustom, ABC abc, List<DottedChain> imports, List<String> uses, Multiname m, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) {
|
||||
if (m != null) {
|
||||
if (m.kind == Multiname.TYPENAME) {
|
||||
if (m.qname_index != 0) {
|
||||
parseImportsUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(m.qname_index), ignorePackage, fullyQualifiedNames);
|
||||
parseImportsUsagesFromMultiname(ignoredCustom, abc, imports, uses, abc.constants.getMultiname(m.qname_index), ignorePackage, fullyQualifiedNames);
|
||||
}
|
||||
for (Integer i : m.params) {
|
||||
if (i != 0) {
|
||||
parseImportsUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(i), ignorePackage, fullyQualifiedNames);
|
||||
parseImportsUsagesFromMultiname(ignoredCustom, abc, imports, uses, abc.constants.getMultiname(i), ignorePackage, fullyQualifiedNames);
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -127,93 +128,52 @@ public abstract class Trait implements Cloneable, Serializable {
|
||||
String name = m.getName(abc.constants, fullyQualifiedNames, true);
|
||||
NamespaceSet nss = m.getNamespaceSet(abc.constants);
|
||||
if (ns != null) {
|
||||
parseImportsUsagesFromNS(abc, imports, uses, m.namespace_index, ignorePackage, name);
|
||||
parseImportsUsagesFromNS(ignoredCustom, abc, imports, uses, m.namespace_index, ignorePackage, name);
|
||||
}
|
||||
if (nss != null) {
|
||||
for (int n : nss.namespaces) {
|
||||
parseImportsUsagesFromNS(abc, imports, uses, n, ignorePackage, nss.namespaces.length > 1 ? "" : name);
|
||||
parseImportsUsagesFromNS(ignoredCustom, abc, imports, uses, n, ignorePackage, nss.namespaces.length > 1 ? "" : name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean parseUsagesFromNS(ABC abc, List<DottedChain> imports, List<String> uses, int namespace_index, DottedChain ignorePackage, String name) {
|
||||
private boolean parseUsagesFromNS(String ignoredCustom, ABC abc, List<DottedChain> imports, List<String> uses, int namespace_index, DottedChain ignorePackage, String name) {
|
||||
Namespace ns = abc.constants.getNamespace(namespace_index);
|
||||
if (name.isEmpty()) {
|
||||
name = "*";
|
||||
}
|
||||
boolean raw = ns.kind == Namespace.KIND_NAMESPACE;
|
||||
DottedChain newimport = ns.getName(abc.constants);
|
||||
|
||||
//Note: Following is weird and probably wrong - FIXIT!
|
||||
/*if ((ns.kind != Namespace.KIND_PACKAGE)
|
||||
&& (ns.kind != Namespace.KIND_NAMESPACE)
|
||||
&& (ns.kind != Namespace.KIND_STATIC_PROTECTED)) {
|
||||
return false;
|
||||
}*/
|
||||
/*if (ns.kind == Namespace.KIND_NAMESPACE)*/ {
|
||||
DottedChain oldimport = newimport;
|
||||
newimport = new DottedChain();
|
||||
if (ns.kind == Namespace.KIND_NAMESPACE) {
|
||||
String nsVal = ns.getName(abc.constants).toRawString();
|
||||
for (ABCContainerTag abcTag : abc.getAbcTags()) {
|
||||
DottedChain newname = abcTag.getABC().nsValueToName(oldimport.toRawString()); /* why this? */
|
||||
DottedChain nsimport = abcTag.getABC().nsValueToName(nsVal);
|
||||
if (nsimport.equals(AVM2Deobfuscation.BUILTIN)) {
|
||||
return true; //handled, but import/use not added
|
||||
}
|
||||
if (!nsimport.isEmpty()) {
|
||||
|
||||
if (newname.size() == 1 && newname.get(0).equals("-")) {
|
||||
if (!nsimport.getWithoutLast().equals(ignorePackage) && !imports.contains(nsimport)) {
|
||||
imports.add(nsimport);
|
||||
}
|
||||
if (ignoredCustom != null && nsVal.equals(ignoredCustom)) {
|
||||
return true;
|
||||
}
|
||||
if (!uses.contains(nsimport.getLast())) {
|
||||
uses.add(nsimport.getLast());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!newname.isEmpty() && !newname.isTopLevel()) {
|
||||
newimport = newname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* if (newimport.isEmpty()) {
|
||||
newimport = oldimport.add(name);
|
||||
}*/
|
||||
|
||||
if (!newimport.isEmpty() && !newimport.isTopLevel()) {
|
||||
/* if(ns.kind==Namespace.KIND_PACKAGE){
|
||||
newimport+=".*";
|
||||
}*/
|
||||
|
||||
if (!imports.contains(newimport)) {
|
||||
//??
|
||||
/*if (newimport.contains(":")) {
|
||||
return true;
|
||||
}*/
|
||||
DottedChain pkg = newimport.getWithoutLast();
|
||||
String usname = newimport.getLast();
|
||||
if (ns.kind == Namespace.KIND_PACKAGE) {
|
||||
if (!pkg.equals(ignorePackage)) {
|
||||
if (!pkg.equals(InitVectorAVM2Item.VECTOR_PACKAGE)) { //Automatic import
|
||||
imports.add(newimport);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ns.kind == Namespace.KIND_NAMESPACE) {
|
||||
if (!usname.equals("*")) {
|
||||
/*if (!uses.contains(usname)) {
|
||||
uses.add(usname);
|
||||
}*/
|
||||
if (!pkg.equals(ignorePackage)) {
|
||||
imports.add(newimport);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void parseImportsUsagesFromNS(ABC abc, List<DottedChain> imports, List<String> uses, int namespace_index, DottedChain ignorePackage, String name) {
|
||||
protected void parseImportsUsagesFromNS(String ignoredCustom, ABC abc, List<DottedChain> imports, List<String> uses, int namespace_index, DottedChain ignorePackage, String name) {
|
||||
Namespace ns = abc.constants.getNamespace(namespace_index);
|
||||
if (name.isEmpty()) {
|
||||
name = "*";
|
||||
}
|
||||
DottedChain newimport = ns.getName(abc.constants);
|
||||
|
||||
if (parseUsagesFromNS(abc, imports, uses, namespace_index, ignorePackage, name)) {
|
||||
if (parseUsagesFromNS(ignoredCustom, abc, imports, uses, namespace_index, ignorePackage, name)) {
|
||||
return;
|
||||
} else if ((ns.kind != Namespace.KIND_PACKAGE) && (ns.kind != Namespace.KIND_PACKAGE_INTERNAL)) {
|
||||
return;
|
||||
@@ -231,15 +191,15 @@ public abstract class Trait implements Cloneable, Serializable {
|
||||
//}
|
||||
}
|
||||
|
||||
protected void parseUsagesFromMultiname(ABC abc, List<DottedChain> imports, List<String> uses, Multiname m, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) {
|
||||
protected void parseUsagesFromMultiname(String ignoredCustom, ABC abc, List<DottedChain> imports, List<String> uses, Multiname m, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) {
|
||||
if (m != null) {
|
||||
if (m.kind == Multiname.TYPENAME) {
|
||||
if (m.qname_index != 0) {
|
||||
parseUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(m.qname_index), ignorePackage, fullyQualifiedNames);
|
||||
parseUsagesFromMultiname(ignoredCustom, abc, imports, uses, abc.constants.getMultiname(m.qname_index), ignorePackage, fullyQualifiedNames);
|
||||
}
|
||||
for (Integer i : m.params) {
|
||||
if (i != 0) {
|
||||
parseUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(i), ignorePackage, fullyQualifiedNames);
|
||||
parseUsagesFromMultiname(ignoredCustom, abc, imports, uses, abc.constants.getMultiname(i), ignorePackage, fullyQualifiedNames);
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -248,14 +208,14 @@ public abstract class Trait implements Cloneable, Serializable {
|
||||
String name = m.getName(abc.constants, fullyQualifiedNames, false);
|
||||
NamespaceSet nss = m.getNamespaceSet(abc.constants);
|
||||
if (ns != null) {
|
||||
parseUsagesFromNS(abc, imports, uses, m.namespace_index, ignorePackage, name);
|
||||
parseUsagesFromNS(ignoredCustom, abc, imports, uses, m.namespace_index, ignorePackage, name);
|
||||
}
|
||||
if (nss != null) {
|
||||
if (nss.namespaces.length == 1) {
|
||||
parseUsagesFromNS(abc, imports, uses, nss.namespaces[0], ignorePackage, name);
|
||||
parseUsagesFromNS(ignoredCustom, abc, imports, uses, nss.namespaces[0], ignorePackage, name);
|
||||
} else {
|
||||
for (int n : nss.namespaces) {
|
||||
parseUsagesFromNS(abc, imports, uses, n, ignorePackage, "");
|
||||
parseUsagesFromNS(ignoredCustom, abc, imports, uses, n, ignorePackage, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -266,8 +226,14 @@ public abstract class Trait implements Cloneable, Serializable {
|
||||
return getName(abc).getNamespace(abc.constants).getName(abc.constants);
|
||||
}
|
||||
|
||||
public void getImportsUsages(ABC abc, List<DottedChain> imports, List<String> uses, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) {
|
||||
parseUsagesFromMultiname(abc, imports, uses, getName(abc), ignorePackage, fullyQualifiedNames);
|
||||
public void getImportsUsages(String ignoredCustom, ABC abc, List<DottedChain> imports, List<String> uses, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) {
|
||||
if (ignoredCustom == null) {
|
||||
Namespace n = getName(abc).getNamespace(abc.constants);
|
||||
if (n.kind == Namespace.KIND_NAMESPACE) {
|
||||
ignoredCustom = n.getName(abc.constants).toRawString();
|
||||
}
|
||||
}
|
||||
parseUsagesFromMultiname(ignoredCustom, abc, imports, uses, getName(abc), ignorePackage, fullyQualifiedNames);
|
||||
}
|
||||
|
||||
private static final String[] builtInClasses = {"ArgumentError", "arguments", "Array", "Boolean", "Class", "Date", "DefinitionError", "Error", "EvalError", "Function", "int", "JSON", "Math", "Namespace", "Number", "Object", "QName", "RangeError", "ReferenceError", "RegExp", "SecurityError", "String", "SyntaxError", "TypeError", "uint", "URIError", "VerifyError", "XML", "XMLList"};
|
||||
@@ -298,7 +264,12 @@ public abstract class Trait implements Cloneable, Serializable {
|
||||
//imports
|
||||
List<DottedChain> imports = new ArrayList<>();
|
||||
List<String> uses = new ArrayList<>();
|
||||
getImportsUsages(abc, imports, uses, ignorePackage, new ArrayList<>());
|
||||
String customNs = null;
|
||||
Namespace ns = getName(abc).getNamespace(abc.constants);
|
||||
if (ns.kind == Namespace.KIND_NAMESPACE) {
|
||||
customNs = ns.getName(abc.constants).toRawString();
|
||||
}
|
||||
getImportsUsages(customNs, abc, imports, uses, ignorePackage, new ArrayList<>());
|
||||
|
||||
List<String> importnames = new ArrayList<>();
|
||||
importnames.addAll(namesInThisPackage);
|
||||
@@ -346,24 +317,24 @@ public abstract class Trait implements Cloneable, Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
protected void parseImportsUsagesFromMethodInfo(ABC abc, int method_index, List<DottedChain> imports, List<String> uses, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames, List<Integer> visitedMethods) {
|
||||
protected void parseImportsUsagesFromMethodInfo(String ignoredCustom, ABC abc, int method_index, List<DottedChain> imports, List<String> uses, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames, List<Integer> visitedMethods) {
|
||||
if ((method_index < 0) || (method_index >= abc.method_info.size())) {
|
||||
return;
|
||||
}
|
||||
visitedMethods.add(method_index);
|
||||
if (abc.method_info.get(method_index).ret_type != 0) {
|
||||
parseImportsUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(abc.method_info.get(method_index).ret_type), ignorePackage, fullyQualifiedNames);
|
||||
parseImportsUsagesFromMultiname(ignoredCustom, abc, imports, uses, abc.constants.getMultiname(abc.method_info.get(method_index).ret_type), ignorePackage, fullyQualifiedNames);
|
||||
}
|
||||
for (int t : abc.method_info.get(method_index).param_types) {
|
||||
if (t != 0) {
|
||||
parseImportsUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(t), ignorePackage, fullyQualifiedNames);
|
||||
parseImportsUsagesFromMultiname(ignoredCustom, abc, imports, uses, abc.constants.getMultiname(t), ignorePackage, fullyQualifiedNames);
|
||||
}
|
||||
}
|
||||
MethodBody body = abc.findBody(method_index);
|
||||
if (body != null) {
|
||||
body.traits.getImportsUsages(abc, imports, uses, ignorePackage, fullyQualifiedNames);
|
||||
body.traits.getImportsUsages(ignoredCustom, abc, imports, uses, ignorePackage, fullyQualifiedNames);
|
||||
for (ABCException ex : body.exceptions) {
|
||||
parseImportsUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(ex.type_index), ignorePackage, fullyQualifiedNames);
|
||||
parseImportsUsagesFromMultiname(ignoredCustom, abc, imports, uses, abc.constants.getMultiname(ex.type_index), ignorePackage, fullyQualifiedNames);
|
||||
}
|
||||
for (AVM2Instruction ins : body.getCode().code) {
|
||||
if (ins.definition instanceof AlchemyTypeIns) {
|
||||
@@ -375,7 +346,7 @@ public abstract class Trait implements Cloneable, Serializable {
|
||||
if (ins.definition instanceof NewFunctionIns) {
|
||||
if (ins.operands[0] != method_index) {
|
||||
if (!visitedMethods.contains(ins.operands[0])) {
|
||||
parseImportsUsagesFromMethodInfo(abc, ins.operands[0], imports, uses, ignorePackage, fullyQualifiedNames, visitedMethods);
|
||||
parseImportsUsagesFromMethodInfo(ignoredCustom, abc, ins.operands[0], imports, uses, ignorePackage, fullyQualifiedNames, visitedMethods);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -387,7 +358,7 @@ public abstract class Trait implements Cloneable, Serializable {
|
||||
int m = ins.operands[0];
|
||||
if (m != 0) {
|
||||
if (m < abc.constants.getMultinameCount()) {
|
||||
parseImportsUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(m), ignorePackage, fullyQualifiedNames);
|
||||
parseImportsUsagesFromMultiname(ignoredCustom, abc, imports, uses, abc.constants.getMultiname(m), ignorePackage, fullyQualifiedNames);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -395,7 +366,7 @@ public abstract class Trait implements Cloneable, Serializable {
|
||||
if (ins.definition.operands[k] == AVM2Code.DAT_MULTINAME_INDEX) {
|
||||
int multinameIndex = ins.operands[k];
|
||||
if (multinameIndex < abc.constants.getMultinameCount()) {
|
||||
parseUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(multinameIndex), ignorePackage, fullyQualifiedNames);
|
||||
parseUsagesFromMultiname(ignoredCustom, abc, imports, uses, abc.constants.getMultiname(multinameIndex), ignorePackage, fullyQualifiedNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -437,7 +408,7 @@ public abstract class Trait implements Cloneable, Serializable {
|
||||
}
|
||||
|
||||
protected final DottedChain findCustomNs(int link_ns_index, ABC abc) {
|
||||
String nsname = "";
|
||||
String nsname;
|
||||
if (link_ns_index <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -87,32 +87,32 @@ public class TraitClass extends Trait implements TraitWithSlot {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getImportsUsages(ABC abc, List<DottedChain> imports, List<String> uses, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) {
|
||||
super.getImportsUsages(abc, imports, uses, ignorePackage == null ? getPackage(abc) : ignorePackage, fullyQualifiedNames);
|
||||
public void getImportsUsages(String customNs, ABC abc, List<DottedChain> imports, List<String> uses, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) {
|
||||
super.getImportsUsages(customNs, abc, imports, uses, ignorePackage == null ? getPackage(abc) : ignorePackage, fullyQualifiedNames);
|
||||
ClassInfo classInfo = abc.class_info.get(class_info);
|
||||
InstanceInfo instanceInfo = abc.instance_info.get(class_info);
|
||||
DottedChain packageName = instanceInfo.getName(abc.constants).getNamespace(abc.constants).getName(abc.constants); //assume not null name
|
||||
|
||||
parseImportsUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(instanceInfo.name_index), packageName, fullyQualifiedNames);
|
||||
parseImportsUsagesFromMultiname(customNs, abc, imports, uses, abc.constants.getMultiname(instanceInfo.name_index), packageName, fullyQualifiedNames);
|
||||
|
||||
if (instanceInfo.super_index > 0) {
|
||||
parseImportsUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(instanceInfo.super_index), packageName, fullyQualifiedNames);
|
||||
parseImportsUsagesFromMultiname(customNs, abc, imports, uses, abc.constants.getMultiname(instanceInfo.super_index), packageName, fullyQualifiedNames);
|
||||
}
|
||||
for (int i : instanceInfo.interfaces) {
|
||||
parseImportsUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(i), packageName, fullyQualifiedNames);
|
||||
parseImportsUsagesFromMultiname(customNs, abc, imports, uses, abc.constants.getMultiname(i), packageName, fullyQualifiedNames);
|
||||
}
|
||||
|
||||
//static
|
||||
classInfo.static_traits.getImportsUsages(abc, imports, uses, packageName, fullyQualifiedNames);
|
||||
classInfo.static_traits.getImportsUsages(customNs, abc, imports, uses, packageName, fullyQualifiedNames);
|
||||
|
||||
//static initializer
|
||||
parseImportsUsagesFromMethodInfo(abc, classInfo.cinit_index, imports, uses, packageName, fullyQualifiedNames, new ArrayList<>());
|
||||
parseImportsUsagesFromMethodInfo(customNs, abc, classInfo.cinit_index, imports, uses, packageName, fullyQualifiedNames, new ArrayList<>());
|
||||
|
||||
//instance
|
||||
instanceInfo.instance_traits.getImportsUsages(abc, imports, uses, packageName, fullyQualifiedNames);
|
||||
instanceInfo.instance_traits.getImportsUsages(customNs, abc, imports, uses, packageName, fullyQualifiedNames);
|
||||
|
||||
//instance initializer
|
||||
parseImportsUsagesFromMethodInfo(abc, instanceInfo.iinit_index, imports, uses, packageName, fullyQualifiedNames, new ArrayList<>());
|
||||
parseImportsUsagesFromMethodInfo(customNs, abc, instanceInfo.iinit_index, imports, uses, packageName, fullyQualifiedNames, new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -178,16 +178,14 @@ public class TraitClass extends Trait implements TraitWithSlot {
|
||||
if (!instanceInfo.isInterface()) {
|
||||
String modifier = "";
|
||||
Multiname m = abc.constants.getMultiname(instanceInfo.name_index);
|
||||
if (m != null) {
|
||||
Namespace ns = m.getNamespace(abc.constants);
|
||||
if (ns != null) {
|
||||
modifier = ns.getPrefix(abc) + " ";
|
||||
if (modifier.equals(" ")) {
|
||||
modifier = "";
|
||||
}
|
||||
if (modifier.startsWith("private")) { //cannot have private constuctor
|
||||
modifier = "";
|
||||
}
|
||||
Namespace ns = m.getNamespace(abc.constants);
|
||||
if (ns != null) {
|
||||
modifier = ns.getPrefix(abc) + " ";
|
||||
if (modifier.equals(" ")) {
|
||||
modifier = "";
|
||||
}
|
||||
if (modifier.startsWith("private")) { //cannot have private constuctor
|
||||
modifier = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -119,14 +119,14 @@ public class TraitFunction extends Trait implements TraitWithSlot {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getImportsUsages(ABC abc, List<DottedChain> imports, List<String> uses, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) {
|
||||
public void getImportsUsages(String customNs, ABC abc, List<DottedChain> imports, List<String> uses, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) {
|
||||
if (ignorePackage == null) {
|
||||
ignorePackage = getPackage(abc);
|
||||
}
|
||||
super.getImportsUsages(abc, imports, uses, ignorePackage, fullyQualifiedNames);
|
||||
super.getImportsUsages(customNs, abc, imports, uses, ignorePackage, fullyQualifiedNames);
|
||||
//if (method_info != 0)
|
||||
{
|
||||
parseImportsUsagesFromMethodInfo(abc, method_info, imports, uses, ignorePackage, fullyQualifiedNames, new ArrayList<>());
|
||||
parseImportsUsagesFromMethodInfo(customNs, abc, method_info, imports, uses, ignorePackage, fullyQualifiedNames, new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.abc.types.traits;
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.types.ConvertData;
|
||||
import com.jpexs.decompiler.flash.abc.types.MethodBody;
|
||||
import com.jpexs.decompiler.flash.abc.types.Namespace;
|
||||
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.NulWriter;
|
||||
@@ -51,15 +52,21 @@ public class TraitMethodGetterSetter extends Trait {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getImportsUsages(ABC abc, List<DottedChain> imports, List<String> uses, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) {
|
||||
public void getImportsUsages(String customNs, ABC abc, List<DottedChain> imports, List<String> uses, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) {
|
||||
if (ignorePackage == null) {
|
||||
ignorePackage = getPackage(abc);
|
||||
}
|
||||
super.getImportsUsages(customNs, abc, imports, uses, ignorePackage, fullyQualifiedNames);
|
||||
|
||||
super.getImportsUsages(abc, imports, uses, ignorePackage, fullyQualifiedNames);
|
||||
if (customNs == null) {
|
||||
Namespace n = getName(abc).getNamespace(abc.constants);
|
||||
if (n.kind == Namespace.KIND_NAMESPACE) {
|
||||
customNs = n.getName(abc.constants).toRawString();
|
||||
}
|
||||
}
|
||||
//if (method_info != 0)
|
||||
{
|
||||
parseImportsUsagesFromMethodInfo(abc, method_info, imports, uses, ignorePackage, fullyQualifiedNames, new ArrayList<>());
|
||||
parseImportsUsagesFromMethodInfo(customNs, abc, method_info, imports, uses, ignorePackage, fullyQualifiedNames, new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -192,12 +192,12 @@ public class TraitSlotConst extends Trait implements TraitWithSlot {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getImportsUsages(ABC abc, List<DottedChain> imports, List<String> uses, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) {
|
||||
public void getImportsUsages(String customNs, ABC abc, List<DottedChain> imports, List<String> uses, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) {
|
||||
if (ignorePackage == null) {
|
||||
ignorePackage = getPackage(abc);
|
||||
}
|
||||
super.getImportsUsages(abc, imports, uses, ignorePackage, fullyQualifiedNames);
|
||||
parseImportsUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(type_index), getPackage(abc), fullyQualifiedNames);
|
||||
super.getImportsUsages(customNs, abc, imports, uses, ignorePackage, fullyQualifiedNames);
|
||||
parseImportsUsagesFromMultiname(customNs, abc, imports, uses, abc.constants.getMultiname(type_index), getPackage(abc), fullyQualifiedNames);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ public class Traits implements Cloneable, Serializable {
|
||||
}
|
||||
} else {
|
||||
ExecutorService executor = Executors.newFixedThreadPool(Configuration.getParallelThreadCount());
|
||||
List<Future<Void>> futureResults = null;
|
||||
List<Future<Void>> futureResults;
|
||||
|
||||
futureResults = new ArrayList<>();
|
||||
for (int t = 0; t < traits.size(); t++) {
|
||||
@@ -237,9 +237,9 @@ public class Traits implements Cloneable, Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
public void getImportsUsages(ABC abc, List<DottedChain> imports, List<String> uses, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) {
|
||||
public void getImportsUsages(String customNs, ABC abc, List<DottedChain> imports, List<String> uses, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) {
|
||||
for (Trait t : traits) {
|
||||
t.getImportsUsages(abc, imports, uses, ignorePackage, fullyQualifiedNames);
|
||||
t.getImportsUsages(customNs, abc, imports, uses, ignorePackage, fullyQualifiedNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user