AS3 Goto definition of static properties.

Link type enum
This commit is contained in:
Jindra Petřík
2025-05-31 22:53:55 +02:00
parent 6b9d9c9eab
commit 6db921a433
12 changed files with 105 additions and 70 deletions

View File

@@ -80,7 +80,8 @@ public class GetLexIns extends InstructionDefinition {
if (localData.abcIndex != null) {
String currentClassName = localData.classIndex == -1 ? null : localData.abc.instance_info.get(localData.classIndex).getName(localData.abc.constants).getNameWithNamespace(localData.abc.constants, true).toRawString();
if (currentClassName != null) {
localData.abcIndex.findPropertyTypeOrCallType(localData.abc, new TypeItem(currentClassName), multinameStr, localData.abc.constants.getMultiname(multinameIndex).namespace_index, true, true, true, type, callType);
Reference<Boolean> foundStatic = new Reference<>(null);
localData.abcIndex.findPropertyTypeOrCallType(localData.abc, new TypeItem(currentClassName), multinameStr, localData.abc.constants.getMultiname(multinameIndex).namespace_index, true, true, true, type, callType, foundStatic);
}
if (type.getVal().equals(TypeItem.UNKNOWN)) {

View File

@@ -178,7 +178,8 @@ public class GetPropertyIns extends InstructionDefinition {
if (localData.abcIndex != null) {
String currentClassName = localData.classIndex == -1 ? null : localData.abc.instance_info.get(localData.classIndex).getName(localData.abc.constants).getNameWithNamespace(localData.abc.constants, true).toRawString();
if (currentClassName != null) {
localData.abcIndex.findPropertyTypeOrCallType(localData.abc, new TypeItem(currentClassName), multinameStr, localData.abc.constants.getMultiname(multiname.multinameIndex).namespace_index, true, true, true, type, callType);
Reference<Boolean> foundStatic = new Reference<>(null);
localData.abcIndex.findPropertyTypeOrCallType(localData.abc, new TypeItem(currentClassName), multinameStr, localData.abc.constants.getMultiname(multiname.multinameIndex).namespace_index, true, true, true, type, callType, foundStatic);
}
if (type.getVal().equals(TypeItem.UNKNOWN)) {
GraphTargetItem ti = AbcIndexing.multinameToType(multiname.multinameIndex, localData.abc.constants);
@@ -256,7 +257,8 @@ public class GetPropertyIns extends InstructionDefinition {
return;
}
}
localData.abcIndex.findPropertyTypeOrCallType(localData.abc, receiverType, multiname.resolvedMultinameName, localData.abc.constants.getMultiname(multiname.multinameIndex).namespace_index, parentStatic, !parentStatic, false, type, callType);
Reference<Boolean> foundStatic = new Reference<>(null);
localData.abcIndex.findPropertyTypeOrCallType(localData.abc, receiverType, multiname.resolvedMultinameName, localData.abc.constants.getMultiname(multiname.multinameIndex).namespace_index, parentStatic, !parentStatic, false, type, callType, foundStatic);
if (receiverType.equals(new TypeItem("XML")) && !type.getVal().equals(new TypeItem("Function"))) {
type.setVal(new TypeItem("XMLList"));
}

View File

@@ -2520,7 +2520,8 @@ public class AVM2SourceGenerator implements SourceGenerator {
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, true);
Reference<Boolean> foundStatic = new Reference<>(null);
sp = abc.findProperty(new AbcIndexing.PropertyDef(propertyName, new TypeItem(pkg.addWithSuffix(obj)), abc.getSelectedAbc(), selectedNs), !instanceOnly, true, true, foundStatic);
}
if (sp != null) {
if (sp.trait instanceof TraitClass) {

View File

@@ -644,8 +644,8 @@ public final class AbcIndexing {
* @param type Property type
* @param callType Call type
*/
public void findPropertyTypeOrCallType(ABC abc, GraphTargetItem cls, String propName, int ns, boolean findStatic, boolean findInstance, boolean findProtected, Reference<GraphTargetItem> type, Reference<GraphTargetItem> callType) {
TraitIndex traitIndex = findProperty(new PropertyDef(propName, cls, abc, ns), findStatic, findInstance, findProtected);
public void findPropertyTypeOrCallType(ABC abc, GraphTargetItem cls, String propName, int ns, boolean findStatic, boolean findInstance, boolean findProtected, Reference<GraphTargetItem> type, Reference<GraphTargetItem> callType, Reference<Boolean> foundStatic) {
TraitIndex traitIndex = findProperty(new PropertyDef(propName, cls, abc, ns), findStatic, findInstance, findProtected, foundStatic);
if (traitIndex == null) {
type.setVal(TypeItem.UNKNOWN);
callType.setVal(TypeItem.UNKNOWN);
@@ -666,8 +666,8 @@ public final class AbcIndexing {
* @param findProtected Find protected namespace properties
* @return Trait index or null
*/
public GraphTargetItem findPropertyType(ABC abc, GraphTargetItem cls, String propName, int ns, boolean findStatic, boolean findInstance, boolean findProtected) {
TraitIndex traitIndex = findProperty(new PropertyDef(propName, cls, abc, ns), findStatic, findInstance, findProtected);
public GraphTargetItem findPropertyType(ABC abc, GraphTargetItem cls, String propName, int ns, boolean findStatic, boolean findInstance, boolean findProtected, Reference<Boolean> foundStatic) {
TraitIndex traitIndex = findProperty(new PropertyDef(propName, cls, abc, ns), findStatic, findInstance, findProtected, foundStatic);
if (traitIndex == null) {
return TypeItem.UNBOUNDED;
}
@@ -685,8 +685,8 @@ public final class AbcIndexing {
* @param findProtected Find protected namespace properties
* @return Trait index or null
*/
public GraphTargetItem findPropertyCallType(ABC abc, GraphTargetItem cls, String propName, int ns, boolean findStatic, boolean findInstance, boolean findProtected) {
TraitIndex traitIndex = findProperty(new PropertyDef(propName, cls, abc, ns), findStatic, findInstance, findProtected);
public GraphTargetItem findPropertyCallType(ABC abc, GraphTargetItem cls, String propName, int ns, boolean findStatic, boolean findInstance, boolean findProtected, Reference<Boolean> foundStatic) {
TraitIndex traitIndex = findProperty(new PropertyDef(propName, cls, abc, ns), findStatic, findInstance, findProtected, foundStatic);
if (traitIndex == null) {
return TypeItem.UNBOUNDED;
}
@@ -761,9 +761,10 @@ public final class AbcIndexing {
* @param findStatic Find static properties
* @param findInstance Find instance properties
* @param findProtected Find protected namespace properties
* @param foundStatic Whether result is static
* @return Trait index or null
*/
public TraitIndex findProperty(PropertyDef prop, boolean findStatic, boolean findInstance, boolean findProtected) {
public TraitIndex findProperty(PropertyDef prop, boolean findStatic, boolean findInstance, boolean findProtected, Reference<Boolean> foundStatic) {
/*System.out.println("searching " + prop);
for (PropertyDef p : instanceProperties.keySet()) {
if (p.parent.equals(new TypeItem("tests_classes.TestConvertParent"))) {
@@ -776,11 +777,12 @@ public final class AbcIndexing {
if (findStatic && classProperties.containsKey(prop)) {
TraitIndex ti = classProperties.get(prop);
if (ti != null) {
foundStatic.setVal(true);
return ti;
}
if (parent != null) {
TraitIndex ret = parent.findProperty(prop, findStatic, findInstance, findProtected);
if (ret != null) {
TraitIndex ret = parent.findProperty(prop, findStatic, findInstance, findProtected, foundStatic);
if (ret != null) {
return ret;
}
}
@@ -790,11 +792,12 @@ public final class AbcIndexing {
if (findInstance && instanceProperties.containsKey(prop)) {
TraitIndex ti = instanceProperties.get(prop);
if (ti != null) {
foundStatic.setVal(false);
return ti;
}
if (parent != null) {
TraitIndex ret = parent.findProperty(prop, findStatic, findInstance, findProtected);
if (ret != null) {
TraitIndex ret = parent.findProperty(prop, findStatic, findInstance, findProtected, foundStatic);
if (ret != null) {
return ret;
}
}
@@ -805,7 +808,7 @@ public final class AbcIndexing {
if (ci != null && ci.parent != null && (prop.abc == null || prop.propNsIndex == 0)) {
AbcIndexing.ClassIndex ciParent = ci.parent;
DottedChain parentClass = ciParent.abc.instance_info.get(ciParent.index).getName(ciParent.abc.constants).getNameWithNamespace(ciParent.abc.constants, true);
TraitIndex pti = findProperty(new PropertyDef(prop.propName, new TypeItem(parentClass), prop.getPropNsString()), findStatic, findInstance, findProtected);
TraitIndex pti = findProperty(new PropertyDef(prop.propName, new TypeItem(parentClass), prop.getPropNsString()), findStatic, findInstance, findProtected, foundStatic);
if (pti != null) {
return pti;
}
@@ -815,14 +818,14 @@ public final class AbcIndexing {
if (ci != null) {
int protNs = ci.abc.instance_info.get(ci.index).protectedNS;
PropertyDef prop2 = new PropertyDef(prop.propName, prop.parent, ci.abc, protNs);
TraitIndex pti = findProperty(prop2, findStatic, findInstance, false);
TraitIndex pti = findProperty(prop2, findStatic, findInstance, false, foundStatic);
if (pti != null) {
return pti;
}
}
}
if (parent != null) {
TraitIndex pti = parent.findProperty(prop, findStatic, findInstance, findProtected);
TraitIndex pti = parent.findProperty(prop, findStatic, findInstance, findProtected, foundStatic);
if (pti != null) {
return pti;
}

View File

@@ -258,7 +258,8 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
// however this namespace is in the ABC of the super class and not in abcIndex.getSelectedAbc()
AbcIndexing.ClassIndex ci = abcIndex.findClass(objType, null, null/*FIXME?*/);
int superProtectedNs = ci.abc.instance_info.get(ci.index).protectedNS;
AbcIndexing.TraitIndex sp = abcIndex.findProperty(new AbcIndexing.PropertyDef(propertyName, objType, ci.abc, superProtectedNs), false, true, true);
Reference<Boolean> foundStatic = new Reference<>(null);
AbcIndexing.TraitIndex sp = abcIndex.findProperty(new AbcIndexing.PropertyDef(propertyName, objType, ci.abc, superProtectedNs), false, true, true, foundStatic);
if (sp != null) {
objType = sp.objType;
Namespace ns = sp.trait.getName(sp.abc).getNamespace(sp.abc.constants);

View File

@@ -381,7 +381,8 @@ public class TraitClass extends Trait implements TraitWithSlot {
if (sIndex > -1) {
int nsIndex = abc.constants.getNamespaceId(Namespace.KIND_PACKAGE, DottedChain.TOPLEVEL, sIndex, false);
if (nsIndex > -1) {
convertData.thisHasDefaultToPrimitive = null == index.findProperty(new AbcIndexing.PropertyDef("toString", new TypeItem(instanceInfo.getName(abc.constants).getNameWithNamespace(abc.constants, true)), abc, nsIndex), false, true, false);
Reference<Boolean> foundStatic = new Reference<>(null);
convertData.thisHasDefaultToPrimitive = null == index.findProperty(new AbcIndexing.PropertyDef("toString", new TypeItem(instanceInfo.getName(abc.constants).getNameWithNamespace(abc.constants, true)), abc, nsIndex), false, true, false, foundStatic);
} else {
convertData.thisHasDefaultToPrimitive = true;
}