Fixed direct editation - methods and script initializer imports.

This commit is contained in:
Jindra Petřík
2024-08-17 11:03:11 +02:00
parent c8a8ce8b6d
commit 4e89376174
3 changed files with 44 additions and 14 deletions

View File

@@ -343,6 +343,18 @@ public class ScriptPack extends AS3ClassTreeItem {
first = false;
}
List<DottedChain> fullyQualifiedNames = new ArrayList<>();
if (!first) {
writer.newLine();
}
DottedChain ignorePackage = null;
if (isSimple) {
ignorePackage = getPathPackage();
}
Trait.writeImports(null, script_init, abcIndex, scriptIndex, -1, true, abc, writer, ignorePackage, fullyQualifiedNames);
first = true;
//Slot const last
for (int t : traitIndices) {
@@ -378,16 +390,12 @@ public class ScriptPack extends AS3ClassTreeItem {
writer.startTrait(GraphTextWriter.TRAIT_SCRIPT_INITIALIZER);
writer.startMethod(script_init, null);
if (exportMode != ScriptExportMode.AS_METHOD_STUBS) {
if (!scriptInitializerIsEmpty) {
DottedChain ignorePackage = null;
if (isSimple) {
ignorePackage = getPathPackage();
}
List<DottedChain> fullyQualifiedNames = new ArrayList<>();
writer.newLine();
Trait.writeImports(null, script_init, abcIndex, scriptIndex, -1, true, abc, writer, ignorePackage, fullyQualifiedNames);
if (!scriptInitializerIsEmpty) {
List<MethodBody> callStack = new ArrayList<>();
callStack.add(abc.bodies.get(bodyIndex));
if (!first) {
writer.newLine();
}
abc.bodies.get(bodyIndex).toString(callStack, abcIndex, path + "/.scriptinitializer", exportMode, abc, null, writer, fullyQualifiedNames, new HashSet<>());
} else {
writer.append("");

View File

@@ -1263,14 +1263,17 @@ public class ActionScript3Parser {
traits.add(new ConstAVM2Item(metadata, ns, null, true, nname, new TypeItem(DottedChain.NAMESPACE), new StringAVM2Item(null, null, nval), lexer.yyline(), generatedNs));
break;
default:
lexer.pushback(s);
parseImportsUsages(importedClasses, openedNamespaces, numberUsageRef, numberPrecisionRef, numberRoundingRef, abc);
lexer.pushback(s);
if (parseImportsUsages(importedClasses, openedNamespaces, numberUsageRef, numberPrecisionRef, numberRoundingRef, abc)) {
break;
}
GraphTargetItem cmd = command(allOpenedNamespaces, null, publicNs, sinitNeedsActivation, importedClasses, openedNamespaces, sinitLoops, sinitLoopLabels, sinitRegisterVars, true, false, 0, false, sinitVariables, abc);
if (cmd != null) {
traits.add(cmd);
isEmpty = false;
}
break looptrait;
} else {
break looptrait;
}
}
}
@@ -2672,14 +2675,16 @@ public class ActionScript3Parser {
private List<String> constantPool;
private void parseImportsUsages(List<DottedChain> importedClasses, List<NamespaceItem> openedNamespaces, Reference<Integer> numberUsageRef, Reference<Integer> numberPrecisionRef, Reference<Integer> numberRoundingRef, ABC abc) throws IOException, AVM2ParseException, InterruptedException {
private boolean parseImportsUsages(List<DottedChain> importedClasses, List<NamespaceItem> openedNamespaces, Reference<Integer> numberUsageRef, Reference<Integer> numberPrecisionRef, Reference<Integer> numberRoundingRef, ABC abc) throws IOException, AVM2ParseException, InterruptedException {
boolean isEmpty = true;
ParsedSymbol s;
s = lex();
while (s.isType(SymbolType.IMPORT, SymbolType.USE)) {
if (s.isType(SymbolType.IMPORT)) {
isEmpty = false;
s = lex();
expected(s, lexer.yyline(), SymbolGroup.IDENTIFIER);
DottedChain fullName = new DottedChain(new String[]{});
@@ -2707,8 +2712,9 @@ public class ActionScript3Parser {
} else {
importedClasses.add(fullName);
}
expected(s, lexer.yyline(), SymbolType.SEMICOLON);
expected(s, lexer.yyline(), SymbolType.SEMICOLON);
} else if (s.isType(SymbolType.USE)) {
isEmpty = false;
do {
s = lex();
if (s.isType(SymbolType.NAMESPACE)) {
@@ -2811,6 +2817,7 @@ public class ActionScript3Parser {
s = lex();
}
lexer.pushback(s);
return !isEmpty;
}
private List<GraphTargetItem> parseScript(

View File

@@ -16,9 +16,14 @@
*/
package com.jpexs.decompiler.flash.abc.avm2.parser.script;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.model.LocalData;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -120,4 +125,14 @@ public class MethodAVM2Item extends FunctionAVM2Item {
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
return writer; //todo?
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return new ArrayList<>();
}
}