Fixed: #1450 AS3 direct editation - handling types from same package

Fixed: AS3 goto definition for types in another ABC tag
This commit is contained in:
Jindra Petřík
2021-02-26 19:30:45 +01:00
parent 429b96f040
commit 76a5fe169b
7 changed files with 48 additions and 20 deletions

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2;
import com.jpexs.decompiler.flash.abc.ABCVersionRequirements;
@@ -556,14 +557,15 @@ public class AVM2ConstantPool implements Cloneable {
* @param origConst
* @return
*/
*/
public List<Integer> getMultinameIds(Multiname val, AVM2ConstantPool origConst) {
List<Integer> ret = new ArrayList<>();
for (int i = 1; i < getMultinameCount(); i++) {
if (getMultiname(i).qnameEquals(this, val, origConst)) {
if (getMultiname(i).qnameEquals(this, val, origConst)) {
ret.add(i);
}
}
}
return ret;
}
public int getStringId(String val, boolean add) {

View File

@@ -1622,7 +1622,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
UnresolvedAVM2Item n = (UnresolvedAVM2Item) an;
if (n.resolved == null) {
String fullClass = localData.getFullClass();
GraphTargetItem res = n.resolve(new TypeItem(fullClass), paramTypes, paramNames, abcIndex, callStack, subvariables);
GraphTargetItem res = n.resolve(localData.currentClass, new TypeItem(fullClass), paramTypes, paramNames, abcIndex, callStack, subvariables);
if (res instanceof AssignableAVM2Item) {
subvariables.set(i, (AssignableAVM2Item) res);
} else {
@@ -1639,7 +1639,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
UnresolvedAVM2Item n = (UnresolvedAVM2Item) an;
if (n.resolved == null) {
String fullClass = localData.getFullClass();
GraphTargetItem res = n.resolve(new TypeItem(fullClass), paramTypes, paramNames, abcIndex, callStack, subvariables);
GraphTargetItem res = n.resolve(localData.currentClass, new TypeItem(fullClass), paramTypes, paramNames, abcIndex, callStack, subvariables);
paramTypes.set(t, res);
}
}
@@ -2132,7 +2132,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
continue;
}
if (item instanceof ClassAVM2Item) {
localData.currentClass = ((ClassAVM2Item) item).pkg.name.addWithSuffix(((ClassAVM2Item) item).className).toRawString();
InstanceInfo instanceInfo = abcIndex.getSelectedAbc().instance_info.get(((TraitClass) traits[k]).class_info);
instanceInfo.name_index = abcIndex.getSelectedAbc().constants.getMultinameId(
Multiname.createQName(
@@ -2149,8 +2149,10 @@ public class AVM2SourceGenerator implements SourceGenerator {
for (int i = 0; i < ((ClassAVM2Item) item).implementsOp.size(); i++) {
instanceInfo.interfaces[i] = superIntName(localData, ((ClassAVM2Item) item).implementsOp.get(i));
}
localData.currentClass = null;
}
if (item instanceof InterfaceAVM2Item) {
localData.currentClass = ((InterfaceAVM2Item) item).pkg.name.addWithSuffix(((InterfaceAVM2Item) item).name).toRawString();
ABC abc = abcIndex.getSelectedAbc();
AVM2ConstantPool constants = abc.constants;
InstanceInfo instanceInfo = abc.instance_info.get(((TraitClass) traits[k]).class_info);
@@ -2162,13 +2164,14 @@ public class AVM2SourceGenerator implements SourceGenerator {
GraphTargetItem un = ((InterfaceAVM2Item) item).superInterfaces.get(i);
instanceInfo.interfaces[i] = superIntName(localData, un);
}
localData.currentClass = null;
}
}
}
public int superIntName(SourceGeneratorLocalData localData, GraphTargetItem un) throws CompilationException {
if (un instanceof UnresolvedAVM2Item) {
((UnresolvedAVM2Item) un).resolve(null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), new ArrayList<>());
((UnresolvedAVM2Item) un).resolve(localData.currentClass, null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), new ArrayList<>());
un = ((UnresolvedAVM2Item) un).resolved;
}
if (!(un instanceof TypeItem)) { //not applyType
@@ -2703,7 +2706,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
if (item instanceof UnresolvedAVM2Item) {
String fullClass = localData.getFullClass();
item = ((UnresolvedAVM2Item) item).resolve(new TypeItem(fullClass), new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), new ArrayList<>());
item = ((UnresolvedAVM2Item) item).resolve(localData.currentClass, new TypeItem(fullClass), new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), new ArrayList<>());
}
if (item instanceof TypeItem) {
typeItem = item;
@@ -2716,7 +2719,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
}
if (typeItem instanceof UnresolvedAVM2Item) {
String fullClass = localData.getFullClass();
typeItem = ((UnresolvedAVM2Item) typeItem).resolve(new TypeItem(fullClass), new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), new ArrayList<>());
typeItem = ((UnresolvedAVM2Item) typeItem).resolve(localData.currentClass, new TypeItem(fullClass), new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), new ArrayList<>());
}
if (!(typeItem instanceof TypeItem)) {

View File

@@ -880,8 +880,8 @@ public class ActionScript3Parser {
List<AssignableAVM2Item> sinitVariables = new ArrayList<>();
NamespaceItem publicNs;
NamespaceItem packageInternalNs;
DottedChain pkgName = DottedChain.TOPLEVEL;
if (s.type == SymbolType.PACKAGE) {
DottedChain pkgName = DottedChain.TOPLEVEL;
s = lex();
if (s.type != SymbolType.CURLY_OPEN) {
expected(s, lexer.yyline(), SymbolGroup.IDENTIFIER);
@@ -1008,7 +1008,7 @@ public class ActionScript3Parser {
List<String> names = new ArrayList<>();
List<String> namespaces = new ArrayList<>();
//FIXME for Private classes in script (?)
AVM2SourceGenerator.parentNamesAddNames(abcIndex, AVM2SourceGenerator.resolveType(new SourceGeneratorLocalData(new HashMap<>(), 0, false, 0), ((TypeItem) ((UnresolvedAVM2Item) extendsTypeStr).resolve(null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), new ArrayList<>())), abcIndex), indices, names, namespaces);
AVM2SourceGenerator.parentNamesAddNames(abcIndex, AVM2SourceGenerator.resolveType(new SourceGeneratorLocalData(new HashMap<>(), 0, false, 0), ((TypeItem) ((UnresolvedAVM2Item) extendsTypeStr).resolve(pkgName.addWithSuffix(subNameStr).toRawString(), null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), new ArrayList<>())), abcIndex), indices, names, namespaces);
for (int i = 0; i < names.size(); i++) {
if (namespaces.get(i) == null || namespaces.get(i).isEmpty()) {
continue;
@@ -1744,7 +1744,7 @@ public class ActionScript3Parser {
UnresolvedAVM2Item ui = (UnresolvedAVM2Item) a;
if (ui.getVariableName().equals(DottedChain.parseWithSuffix(e.getVariableName()))) {
try {
ui.resolve(null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), variables);
ui.resolve(null, null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), variables);
} catch (CompilationException ex) {
// ignore
}
@@ -1767,7 +1767,7 @@ public class ActionScript3Parser {
for (NameAVM2Item e : catchExceptions) {
if (ui.getVariableName().equals(DottedChain.parseWithSuffix(e.getVariableName()))) {
try {
ui.resolve(null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), variables);
ui.resolve(null, null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), variables);
} catch (CompilationException ex) {
// ignore
}

View File

@@ -287,7 +287,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
throw new RuntimeException("Cannot assign");
}
public GraphTargetItem resolve(GraphTargetItem thisType, List<GraphTargetItem> paramTypes, List<String> paramNames, AbcIndexing abc, List<MethodBody> callStack, List<AssignableAVM2Item> variables) throws CompilationException {
public GraphTargetItem resolve(String currentClass, GraphTargetItem thisType, List<GraphTargetItem> paramTypes, List<String> paramNames, AbcIndexing abc, List<MethodBody> callStack, List<AssignableAVM2Item> variables) throws CompilationException {
if (scopeStack.isEmpty()) { //Everything is multiname property in with command
//search for variable
@@ -315,6 +315,27 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
}
}
}
if (currentClass != null) {
DottedChain classChain = DottedChain.parseWithSuffix(currentClass);
DottedChain pkg = classChain.getWithoutLast();
TypeItem ti = new TypeItem(pkg.addWithSuffix(name.get(0)));
AbcIndexing.ClassIndex ci = abc.findClass(ti);
if (ci != null) {
resolved = ti;
for (int i = 1; i < name.size(); i++) {
resolved = new PropertyAVM2Item(resolved, name.get(i), abc, openedNamespaces, new ArrayList<>());
if (i == name.size() - 1) {
((PropertyAVM2Item) resolved).assignedValue = assignedValue;
}
}
return resolvedRoot = ti;
}
}
//Search for types in imported classes
for (DottedChain imp : importedClasses) {
String impName = imp.getLast();

View File

@@ -414,7 +414,7 @@ public class Multiname {
}
}
}
String name = getName(constants, null, false, false);
String name = getName(constants, null, true, false);
if (ns != null) {
return ns.getName(constants).add(name, withSuffix ? getNamespaceSuffix() : "");
}