Fixed Type resolving

This commit is contained in:
Jindra Petřík
2021-12-07 09:31:14 +01:00
parent 9943542f94
commit d943588fbd
6 changed files with 37 additions and 23 deletions

View File

@@ -2612,31 +2612,34 @@ public class AVM2SourceGenerator implements SourceGenerator {
return TypeItem.UNBOUNDED;
}
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) {
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, Reference<Boolean> isType) {
// private and protected namespaces first so we find overriding functions before overridden functions
if (searchPrototypeChain(privateNs, instanceOnly, abc, pkg, obj, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) {
if (searchPrototypeChain(privateNs, instanceOnly, abc, pkg, obj, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc, isType)) {
return true;
}
if (searchPrototypeChain(protectedNs, instanceOnly, abc, pkg, obj, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) {
if (searchPrototypeChain(protectedNs, instanceOnly, abc, pkg, obj, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc, isType)) {
return true;
}
for (int ns : otherNs) {
if (searchPrototypeChain(ns, instanceOnly, abc, pkg, obj, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) {
if (searchPrototypeChain(ns, instanceOnly, abc, pkg, obj, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc, isType)) {
return true;
}
}
return searchPrototypeChain(0, instanceOnly, abc, pkg, obj, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc);
return searchPrototypeChain(0, instanceOnly, abc, pkg, obj, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc, isType);
}
private static boolean searchPrototypeChain(int selectedNs, 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) {
private static boolean searchPrototypeChain(int selectedNs, 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, Reference<Boolean> isType) {
isType.setVal(false);
AbcIndexing.TraitIndex sp = abc.findScriptProperty(pkg.addWithSuffix(propertyName));
if (sp == null) {
sp = abc.findProperty(new AbcIndexing.PropertyDef(propertyName, new TypeItem(pkg.addWithSuffix(obj)), abc.getSelectedAbc(), selectedNs), !instanceOnly, true);
}
if (sp != null) {
if (sp.trait instanceof TraitClass) {
isType.setVal(true);
}
if (sp.objType instanceof TypeItem) {
outName.setVal(((TypeItem) sp.objType).fullTypeName.getLast());
outNs.setVal(((TypeItem) sp.objType).fullTypeName.getWithoutLast());

View File

@@ -91,12 +91,13 @@ public class CallAVM2Item extends AVM2Item {
Reference<ValueKind> outPropValue = new Reference<>(null);
Reference<ABC> outPropValueABC = new Reference<>(null);
List<Integer> otherNs = new ArrayList<>();
Reference<Boolean> isType = new Reference<>(false);
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)) {
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, isType)) {
NameAVM2Item nobj = new NameAVM2Item(new TypeItem(localData.getFullClass()), n.line, "this", null, false, n.openedNamespaces, abcIndex);
nobj.setRegNumber(0);
obj = nobj;
@@ -132,6 +133,7 @@ public class CallAVM2Item extends AVM2Item {
Reference<GraphTargetItem> outPropType = new Reference<>(null);
Reference<ValueKind> outPropValue = new Reference<>(null);
Reference<ABC> outPropValueAbc = new Reference<>(null);
Reference<Boolean> isType = new Reference<>(false);
List<Integer> otherNs = new ArrayList<>();
for (NamespaceItem n : openedNamespaces) {
@@ -140,7 +142,7 @@ public class CallAVM2Item extends AVM2Item {
}
}
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().addWithSuffix(outName.getVal()).toRawString()))) {
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, isType) && (localData.getFullClass().equals(outNs.getVal().addWithSuffix(outName.getVal()).toRawString()))) {
NameAVM2Item nobj = new NameAVM2Item(new TypeItem(localData.getFullClass()), 0, "this", null, false, new ArrayList<>(), abcIndex);
nobj.setRegNumber(0);
obj = nobj;

View File

@@ -89,8 +89,9 @@ public class NamespaceItem {
PropertyAVM2Item prop = new PropertyAVM2Item(null, custom, abcIndex, openedNamespaces, new ArrayList<>());
Reference<ValueKind> value = new Reference<>(null);
Reference<ABC> outAbc = new Reference<>(null);
Reference<Boolean> isType = new Reference<>(false);
prop.resolve(true, localData, new Reference<>(null), new Reference<>(null), new Reference<>(0), value, outAbc);
prop.resolve(true, localData, isType, new Reference<>(null), new Reference<>(null), new Reference<>(0), value, outAbc);
boolean resolved = true;
if (value.getVal() == null) {
resolved = false;

View File

@@ -31,6 +31,7 @@ import com.jpexs.decompiler.flash.abc.types.Namespace;
import com.jpexs.decompiler.flash.abc.types.ScriptInfo;
import com.jpexs.decompiler.flash.abc.types.ValueKind;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.abc.types.traits.TraitClass;
import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
@@ -132,7 +133,8 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
return multinameToType(new HashSet<>(), m_index, constants);
}
public void resolve(boolean mustExist, SourceGeneratorLocalData localData, Reference<GraphTargetItem> objectType, Reference<GraphTargetItem> propertyType, Reference<Integer> propertyIndex, Reference<ValueKind> propertyValue, Reference<ABC> propertyValueABC) throws CompilationException {
public void resolve(boolean mustExist, SourceGeneratorLocalData localData, Reference<Boolean> isType, Reference<GraphTargetItem> objectType, Reference<GraphTargetItem> propertyType, Reference<Integer> propertyIndex, Reference<ValueKind> propertyValue, Reference<ABC> propertyValueABC) throws CompilationException {
isType.setVal(false);
GraphTargetItem thisType = new TypeItem(localData.getFullClass());
GraphTargetItem objType = null;
GraphTargetItem objSubType = null;
@@ -269,7 +271,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
propValueAbc = sp.abc;
}
}
if (propType == null && AVM2SourceGenerator.searchPrototypeChain(otherNs, localData.privateNs, localData.protectedNs, false, abcIndex, ftn.getWithoutLast(), ftn.getLast(), propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) {
if (propType == null && AVM2SourceGenerator.searchPrototypeChain(otherNs, localData.privateNs, localData.protectedNs, false, abcIndex, ftn.getWithoutLast(), ftn.getLast(), propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc, isType)) {
objType = new TypeItem(outNs.getVal().addWithSuffix(outName.getVal()));
propType = outPropType.getVal();
propIndex = constants.getMultinameId(Multiname.createQName(false,
@@ -356,6 +358,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
}
for (Trait t : si.traits.traits) {
if (t.name_index == name_index) {
isType.setVal(t instanceof TraitClass);
objType = new TypeItem(DottedChain.OBJECT);
propType = AVM2SourceGenerator.getTraitReturnType(abcIndex, t);
propIndex = t.name_index;
@@ -387,7 +390,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
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)) {
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, isType)) {
objType = new TypeItem(outNs.getVal().addWithSuffix(outName.getVal()));
propType = p.returnType;
propIndex = constants.getMultinameId(Multiname.createQName(false,
@@ -446,7 +449,8 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
Reference<Integer> propIndex = new Reference<>(0);
Reference<ValueKind> outPropValue = new Reference<>(null);
Reference<ABC> outPropValueAbc = new Reference<>(null);
resolve(false, localData, objType, propType, propIndex, outPropValue, outPropValueAbc);
Reference<Boolean> isType = new Reference<>(false);
resolve(false, localData, isType, objType, propType, propIndex, outPropValue, outPropValueAbc);
return propIndex.getVal();
}
@@ -458,8 +462,9 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
Reference<Integer> propIndex = new Reference<>(0);
Reference<ValueKind> outPropValue = new Reference<>(null);
Reference<ABC> outPropValueAbc = new Reference<>(null);
Reference<Boolean> isType = new Reference<>(false);
try {
resolve(false, new SourceGeneratorLocalData(new HashMap<>(), 0, false, 0)/*???*/, objType, propType, propIndex, outPropValue, outPropValueAbc);
resolve(false, new SourceGeneratorLocalData(new HashMap<>(), 0, false, 0)/*???*/, isType, objType, propType, propIndex, outPropValue, outPropValueAbc);
return propType.getVal();
} catch (CompilationException ex) {
@@ -475,8 +480,9 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
Reference<Integer> propIndex = new Reference<>(0);
Reference<ValueKind> outPropValue = new Reference<>(null);
Reference<ABC> outPropValueAbc = new Reference<>(null);
Reference<Boolean> isType = new Reference<>(false);
resolve(false, localData, objType, propType, propIndex, outPropValue, outPropValueAbc);
resolve(false, localData, isType, objType, propType, propIndex, outPropValue, outPropValueAbc);
int propertyId = propIndex.getVal();
Object obj = resolveObject(localData, generator);
@@ -539,6 +545,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
Reference<GraphTargetItem> outPropType = new Reference<>(null);
Reference<ValueKind> outPropValue = new Reference<>(null);
Reference<ABC> outPropValueAbc = new Reference<>(null);
Reference<Boolean> isType = new Reference<>(false);
/*List<ABC> abcs = new ArrayList<>();
abcs.add(abc);
@@ -549,7 +556,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
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().addWithSuffix(outName.getVal()).toRawString()))) {
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, isType) && (localData.getFullClass().equals(outNs.getVal().addWithSuffix(outName.getVal()).toRawString()))) {
NameAVM2Item nobj = new NameAVM2Item(new TypeItem(localData.getFullClass()), 0, "this", null, false, openedNamespaces, abcIndex);
nobj.setRegNumber(0);
obj = nobj;
@@ -560,7 +567,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
Reference<ValueKind> propValue = new Reference<>(null);
Reference<ABC> propValueAbc = new Reference<>(null);
resolve(false, localData, objType, propType, propIndex, outPropValue, propValueAbc);
resolve(false, localData, isType, objType, propType, propIndex, outPropValue, propValueAbc);
obj = ins(AVM2Instructions.FindPropertyStrict, propIndex.getVal());
}
}
@@ -575,8 +582,9 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
Reference<Integer> propIndex = new Reference<>(0);
Reference<ValueKind> outPropValue = new Reference<>(null);
Reference<ABC> outPropValueAbc = new Reference<>(null);
Reference<Boolean> isType = new Reference<>(false);
resolve(false, localData, objType, propType, propIndex, outPropValue, outPropValueAbc);
resolve(false, localData, isType, objType, propType, propIndex, outPropValue, outPropValueAbc);
int propertyId = propIndex.getVal();
Object obj = resolveObject(localData, generator);

View File

@@ -349,10 +349,11 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
Reference<Integer> propertyIndex = new Reference<>(null);
Reference<ValueKind> propertyValue = new Reference<>(null);
Reference<ABC> propertyValueABC = new Reference<>(null);
Reference<Boolean> isType = new Reference<>(false);
resolvedx.resolve(true, localData, objectType, propertyType, propertyIndex, propertyValue, propertyValueABC);
resolvedx.resolve(true, localData, isType, objectType, propertyType, propertyIndex, propertyValue, propertyValueABC);
if (objectType.getVal() != null && !((objectType.getVal() instanceof TypeItem) && ("".equals(((TypeItem) objectType.getVal()).fullTypeName.toRawString())))) {
if (objectType.getVal() != null && !isType.getVal()) {
isProperty = true;
}
}