From 3e7493d5954451a9dfa254eea47803d27a99bbae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sun, 11 Aug 2024 11:16:50 +0200 Subject: [PATCH] Added: AS3 direct editation - unary plus support --- CHANGELOG.md | 1 + .../flash/abc/avm2/model/CoerceAVM2Item.java | 15 + .../parser/script/ActionScript3Parser.java | 290 +++++++++--------- .../flash/ActionScript3DeobfuscatorTest.java | 2 +- .../flash/gui/tagtree/TagTreeContextMenu.java | 4 +- 5 files changed, 170 insertions(+), 142 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ce7ae131..33f2e85aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. - Better decimal values support (for ABCs minor 17, not standard FP) - Better float values support (for ABCs major 47, minor 16 +, not standard FP) - Non-nullable classes support (not standard FP) +- AS3 direct editation - unary plus support ### Fixed - Hex view for unknown tags was not scrollable diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/CoerceAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/CoerceAVM2Item.java index e326bce98..1879b815a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/CoerceAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/CoerceAVM2Item.java @@ -146,6 +146,8 @@ public class CoerceAVM2Item extends AVM2Item { case "int": case "uint": case "Number": + case "float": + case "float4": return value.isConvertedCompileTime(dependencies); } return false; @@ -215,6 +217,19 @@ public class CoerceAVM2Item extends AVM2Item { case "Number": ins = new AVM2Instruction(0, AVM2Instructions.ConvertD, null); break; + case "float": + ins = new AVM2Instruction(0, AVM2Instructions.ConvertF, null); + break; + case "float4": + ins = new AVM2Instruction(0, AVM2Instructions.ConvertF4, null); + break; + case "decimal": + if (localData.numberContext != null) { + ins = new AVM2Instruction(0, AVM2Instructions.ConvertMP, new int[] {localData.numberContext}); + } else { + ins = new AVM2Instruction(0, AVM2Instructions.ConvertM, null); + } + break; default: int type_index = AVM2SourceGenerator.resolveType(localData, typeObj, ((AVM2SourceGenerator) generator).abcIndex); ins = new AVM2Instruction(0, AVM2Instructions.Coerce, new int[]{type_index}); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java index 0c4aea33c..ca00a940c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java @@ -86,6 +86,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.operations.StrictNeqAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.operations.SubtractAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.operations.TypeOfAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.operations.URShiftAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.operations.UnPlusAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.parser.AVM2ParseException; import com.jpexs.decompiler.flash.abc.types.Float4; import com.jpexs.decompiler.flash.abc.types.Namespace; @@ -117,6 +118,7 @@ import com.jpexs.decompiler.graph.model.PushItem; import com.jpexs.decompiler.graph.model.SwitchItem; import com.jpexs.decompiler.graph.model.TernarOpItem; import com.jpexs.decompiler.graph.model.TrueItem; +import com.jpexs.decompiler.graph.model.UnaryOpItem; import com.jpexs.decompiler.graph.model.WhileItem; import com.jpexs.helpers.Helper; import com.jpexs.helpers.Reference; @@ -156,13 +158,13 @@ public class ActionScript3Parser { return uniqLast; } - private List commands(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, Stack loops, Map loopLabels, HashMap registerVars, boolean inFunction, boolean inMethod, int forinlevel, List variables) throws IOException, AVM2ParseException, InterruptedException { + private List commands(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, Stack loops, Map loopLabels, HashMap registerVars, boolean inFunction, boolean inMethod, int forinlevel, List variables, ABC abc) throws IOException, AVM2ParseException, InterruptedException { List ret = new ArrayList<>(); if (debugMode) { System.out.println("commands:"); } GraphTargetItem cmd; - while ((cmd = command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)) != null) { + while ((cmd = command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables, abc)) != null) { ret.add(cmd); } if (debugMode) { @@ -171,7 +173,7 @@ public class ActionScript3Parser { return ret; } - private GraphTargetItem type(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, List variables) throws IOException, AVM2ParseException, InterruptedException { + private GraphTargetItem type(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, List variables, ABC abc) throws IOException, AVM2ParseException, InterruptedException { ParsedSymbol s = lex(); if (s.type == SymbolType.MULTIPLY) { return TypeItem.UNBOUNDED; @@ -181,12 +183,12 @@ public class ActionScript3Parser { lexer.pushback(s); } - GraphTargetItem t = name(allOpenedNamespaces, thisType, pkg, needsActivation, true, openedNamespaces, null, false, false, variables, importedClasses); - t = applyType(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, t, new HashMap<>(), false, false, variables); + GraphTargetItem t = name(allOpenedNamespaces, thisType, pkg, needsActivation, true, openedNamespaces, null, false, false, variables, importedClasses, abc); + t = applyType(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, t, new HashMap<>(), false, false, variables, abc); return t; } - private GraphTargetItem memberOrCall(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, GraphTargetItem newcmds, HashMap registerVars, boolean inFunction, boolean inMethod, List variables) throws IOException, AVM2ParseException, InterruptedException { + private GraphTargetItem memberOrCall(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, GraphTargetItem newcmds, HashMap registerVars, boolean inFunction, boolean inMethod, List variables, ABC abc) throws IOException, AVM2ParseException, InterruptedException { if (debugMode) { System.out.println("memberOrCall:"); } @@ -198,15 +200,15 @@ public class ActionScript3Parser { case DOT: case TYPENAME: lexer.pushback(s); - ret = member(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables); + ret = member(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables, abc); break; case FILTER: needsActivation.setVal(true); - ret = new XMLFilterAVM2Item(ret, expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, inMethod, variables, true), openedNamespaces); + ret = new XMLFilterAVM2Item(ret, expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, inMethod, variables, true, abc), openedNamespaces); expectedType(SymbolType.PARENT_CLOSE); break; case PARENT_OPEN: - ret = new CallAVM2Item(openedNamespaces, lexer.yyline(), ret, call(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables), abcIndex); + ret = new CallAVM2Item(openedNamespaces, lexer.yyline(), ret, call(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables, abc), abcIndex); break; case DESCENDANTS: s = lex(); @@ -240,7 +242,7 @@ public class ActionScript3Parser { return ret; } - private GraphTargetItem applyType(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, GraphTargetItem obj, HashMap registerVars, boolean inFunction, boolean inMethod, List variables) throws IOException, AVM2ParseException, InterruptedException { + private GraphTargetItem applyType(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, GraphTargetItem obj, HashMap registerVars, boolean inFunction, boolean inMethod, List variables, ABC abc) throws IOException, AVM2ParseException, InterruptedException { GraphTargetItem ret = obj; ParsedSymbol s = lex(); if (s.type == SymbolType.TYPENAME) { @@ -251,7 +253,7 @@ public class ActionScript3Parser { params.add(new NullAVM2Item(null, null)); } else { lexer.pushback(s); - params.add(expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, false, variables)); + params.add(expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, false, variables, abc)); } s = lex(); } while (s.type == SymbolType.COMMA); @@ -272,7 +274,7 @@ public class ActionScript3Parser { return ret; } - private GraphTargetItem member(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, GraphTargetItem obj, HashMap registerVars, boolean inFunction, boolean inMethod, List variables) throws IOException, AVM2ParseException, InterruptedException { + private GraphTargetItem member(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, GraphTargetItem obj, HashMap registerVars, boolean inFunction, boolean inMethod, List variables, ABC abc) throws IOException, AVM2ParseException, InterruptedException { if (debugMode) { System.out.println("member:"); } @@ -293,10 +295,10 @@ public class ActionScript3Parser { } if (s.type == SymbolType.TYPENAME) { lexer.pushback(s); - ret = applyType(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables); + ret = applyType(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables, abc); s = lex(); } else if (s.type == SymbolType.BRACKET_OPEN) { - GraphTargetItem index = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false); + GraphTargetItem index = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc); expectedType(SymbolType.BRACKET_CLOSE); ret = new IndexAVM2Item(attr, ret, index, null, openedNamespaces); s = lex(); @@ -313,7 +315,7 @@ public class ActionScript3Parser { variables.add((UnresolvedAVM2Item) ns); s = lex(); if (s.type == SymbolType.BRACKET_OPEN) { - propItem = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false); + propItem = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc); expectedType(SymbolType.BRACKET_CLOSE); propName = null; } else { @@ -345,7 +347,7 @@ public class ActionScript3Parser { return ret; } - private GraphTargetItem name(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, boolean typeOnly, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, List variables, List importedClasses) throws IOException, AVM2ParseException, InterruptedException { + private GraphTargetItem name(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, boolean typeOnly, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, List variables, List importedClasses, ABC abc) throws IOException, AVM2ParseException, InterruptedException { ParsedSymbol s = lex(); DottedChain name = new DottedChain(new String[]{}, new String[]{""}); boolean attribute = false; @@ -407,7 +409,7 @@ public class ActionScript3Parser { if (s.group == SymbolGroup.IDENTIFIER) { nsprop = s.value.toString(); } else if (s.type == SymbolType.BRACKET_OPEN) { - nspropItem = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false); + nspropItem = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc); expectedType(SymbolType.BRACKET_CLOSE); } name = name.getWithoutLast(); @@ -432,7 +434,7 @@ public class ActionScript3Parser { lexer.pushback(new ParsedSymbol(SymbolGroup.OPERATOR, SymbolType.ATTRIBUTE, "@")); lexer.pushback(new ParsedSymbol(SymbolGroup.OPERATOR, SymbolType.DOT, ".")); } - ret = member(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables); + ret = member(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables, abc); } else { lexer.pushback(s); } @@ -480,7 +482,7 @@ public class ActionScript3Parser { return ret; } - private List call(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, List variables) throws IOException, AVM2ParseException, InterruptedException { + private List call(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, List variables, ABC abc) throws IOException, AVM2ParseException, InterruptedException { List ret = new ArrayList<>(); //expected(SymbolType.PARENT_OPEN); //MUST BE HANDLED BY CALLER ParsedSymbol s = lex(); @@ -488,19 +490,19 @@ public class ActionScript3Parser { if (s.type != SymbolType.COMMA) { lexer.pushback(s); } - ret.add(expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false)); + ret.add(expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc)); s = lex(); expected(s, lexer.yyline(), SymbolType.COMMA, SymbolType.PARENT_CLOSE); } return ret; } - private MethodAVM2Item method(List> allOpenedNamespaces, boolean outsidePackage, boolean isPrivate, List>> metadata, NamespaceItem pkg, boolean isInterface, boolean isNative, String customAccess, Reference needsActivation, List importedClasses, boolean override, boolean isFinal, TypeItem thisType, List openedNamespaces, boolean isStatic, String functionName, boolean isMethod, List variables) throws IOException, AVM2ParseException, InterruptedException { - FunctionAVM2Item f = function(allOpenedNamespaces, metadata, pkg, isInterface, isNative, needsActivation, importedClasses, thisType, openedNamespaces, functionName, isMethod, variables); + private MethodAVM2Item method(List> allOpenedNamespaces, boolean outsidePackage, boolean isPrivate, List>> metadata, NamespaceItem pkg, boolean isInterface, boolean isNative, String customAccess, Reference needsActivation, List importedClasses, boolean override, boolean isFinal, TypeItem thisType, List openedNamespaces, boolean isStatic, String functionName, boolean isMethod, List variables, ABC abc) throws IOException, AVM2ParseException, InterruptedException { + FunctionAVM2Item f = function(allOpenedNamespaces, metadata, pkg, isInterface, isNative, needsActivation, importedClasses, thisType, openedNamespaces, functionName, isMethod, variables, abc); return new MethodAVM2Item(allOpenedNamespaces, outsidePackage, isPrivate, f.metadata, f.pkg, f.isInterface, f.isNative, 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> allOpenedNamespaces, List>> metadata, NamespaceItem pkg, boolean isInterface, boolean isNative, Reference needsActivation, List importedClasses, TypeItem thisType, List openedNamespaces, String functionName, boolean isMethod, List variables) throws IOException, AVM2ParseException, InterruptedException { + private FunctionAVM2Item function(List> allOpenedNamespaces, List>> metadata, NamespaceItem pkg, boolean isInterface, boolean isNative, Reference needsActivation, List importedClasses, TypeItem thisType, List openedNamespaces, String functionName, boolean isMethod, List variables, ABC abc) throws IOException, AVM2ParseException, InterruptedException { openedNamespaces = new ArrayList<>(openedNamespaces); //local copy allOpenedNamespaces.add(openedNamespaces); @@ -528,13 +530,13 @@ public class ActionScript3Parser { if (!hasRest) { GraphTargetItem currentType; if (s.type == SymbolType.COLON) { - paramTypes.add(currentType = type(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, variables)); + paramTypes.add(currentType = type(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, variables, abc)); s = lex(); } else { paramTypes.add(currentType = TypeItem.UNBOUNDED); } if (s.type == SymbolType.ASSIGN) { - GraphTargetItem currentValue = expression(allOpenedNamespaces, thisType, pkg, new Reference<>(false), importedClasses, openedNamespaces, null, isMethod, isMethod, isMethod, variables, false); + GraphTargetItem currentValue = expression(allOpenedNamespaces, thisType, pkg, new Reference<>(false), importedClasses, openedNamespaces, null, isMethod, isMethod, isMethod, variables, false, abc); paramValues.add(currentValue); s = lex(); } else if (!paramValues.isEmpty()) { @@ -552,7 +554,7 @@ public class ActionScript3Parser { s = lex(); GraphTargetItem retType; if (s.type == SymbolType.COLON) { - retType = type(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, variables); + retType = type(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, variables, abc); } else { retType = TypeItem.UNBOUNDED; lexer.pushback(s); @@ -571,7 +573,7 @@ public class ActionScript3Parser { Reference needsActivation2 = new Reference<>(false); if (!isInterface && !isNative) { expectedType(SymbolType.CURLY_OPEN); - body = commands(allOpenedNamespaces, thisType, pkg, needsActivation2, importedClasses, openedNamespaces, new Stack<>(), new HashMap<>(), new HashMap<>(), true, isMethod, 0, subvariables); + body = commands(allOpenedNamespaces, thisType, pkg, needsActivation2, importedClasses, openedNamespaces, new Stack<>(), new HashMap<>(), new HashMap<>(), true, isMethod, 0, subvariables, abc); expectedType(SymbolType.CURLY_CLOSE); } else { expectedType(SymbolType.SEMICOLON); @@ -629,7 +631,7 @@ public class ActionScript3Parser { return metadata; } - private void classTraits(List> allOpenedNamespaces, boolean outsidePackage, List cinitVariables, Reference cinitNeedsActivation, List cinit, List importedClasses, List openedNamespaces, NamespaceItem pkg, String classNameStr, boolean isInterface, List traits, List iinitVariables, Reference iinitNeedsActivation, Reference iinit) throws AVM2ParseException, IOException, CompilationException, InterruptedException { + private void classTraits(List> allOpenedNamespaces, boolean outsidePackage, List cinitVariables, Reference cinitNeedsActivation, List cinit, List importedClasses, List openedNamespaces, NamespaceItem pkg, String classNameStr, boolean isInterface, List traits, List iinitVariables, Reference iinitNeedsActivation, Reference iinit, ABC abc) throws AVM2ParseException, IOException, CompilationException, InterruptedException { NamespaceItem publicNs = new NamespaceItem("", Namespace.KIND_PACKAGE); NamespaceItem privateNs = new NamespaceItem(pkg.name.toRawString().isEmpty() ? classNameStr : pkg.name.toRawString() + ":" + classNameStr, Namespace.KIND_PRIVATE); @@ -666,7 +668,7 @@ public class ActionScript3Parser { ParsedSymbol s = lex(); //static class initializer if (s.type == SymbolType.CURLY_OPEN) { - cinit.addAll(commands(allOpenedNamespaces, thisType, pkg, cinitNeedsActivation, importedClasses, openedNamespaces, new Stack<>(), new HashMap<>(), new HashMap<>(), true, false, 0, cinitVariables)); + cinit.addAll(commands(allOpenedNamespaces, thisType, pkg, cinitNeedsActivation, importedClasses, openedNamespaces, new Stack<>(), new HashMap<>(), new HashMap<>(), true, false, 0, cinitVariables, abc)); expectedType(SymbolType.CURLY_CLOSE); } else { lexer.pushback(s); @@ -808,7 +810,7 @@ public class ActionScript3Parser { if (isInterface) { throw new AVM2ParseException("Interface cannot have constructor", lexer.yyline()); } - iinit.setVal(method(allOpenedNamespaces, outsidePackage, isPrivate, metadata, pkg, false, false, customNs, iinitNeedsActivation, importedClasses, false, false, thisType, openedNamespaces, false, "", true, iinitVariables)); + iinit.setVal(method(allOpenedNamespaces, outsidePackage, isPrivate, metadata, pkg, false, false, customNs, iinitNeedsActivation, importedClasses, false, false, thisType, openedNamespaces, false, "", true, iinitVariables, abc)); } else { GraphTargetItem t; if (classNameStr == null) { @@ -823,7 +825,7 @@ public class ActionScript3Parser { } MethodAVM2Item ft; - ft = method(allOpenedNamespaces, outsidePackage, isPrivate, metadata, namespace, isInterface, isNative, customNs, new Reference<>(false), importedClasses, isOverride, isFinal, thisType, openedNamespaces, isStatic, fname, true, new ArrayList<>()); + ft = method(allOpenedNamespaces, outsidePackage, isPrivate, metadata, namespace, isInterface, isNative, customNs, new Reference<>(false), importedClasses, isOverride, isFinal, thisType, openedNamespaces, isStatic, fname, true, new ArrayList<>(), abc); if (isGetter) { if (!ft.paramTypes.isEmpty()) { @@ -912,7 +914,7 @@ public class ActionScript3Parser { GraphTargetItem type; if (s.type == SymbolType.COLON) { - type = type(allOpenedNamespaces, thisType, pkg, new Reference<>(false), importedClasses, openedNamespaces, new ArrayList<>()); + type = type(allOpenedNamespaces, thisType, pkg, new Reference<>(false), importedClasses, openedNamespaces, new ArrayList<>(), abc); s = lex(); } else { type = TypeItem.UNBOUNDED; @@ -921,7 +923,7 @@ public class ActionScript3Parser { GraphTargetItem value = null; if (s.type == SymbolType.ASSIGN) { - value = expression(allOpenedNamespaces, thisType, pkg, new Reference<>(false), importedClasses, openedNamespaces, new HashMap<>(), false, false, true, isStatic || isConst ? cinitVariables : iinitVariables, false); + value = expression(allOpenedNamespaces, thisType, pkg, new Reference<>(false), importedClasses, openedNamespaces, new HashMap<>(), false, false, true, isStatic || isConst ? cinitVariables : iinitVariables, false, abc); s = lex(); } GraphTargetItem tar; @@ -942,14 +944,14 @@ public class ActionScript3Parser { } } - private void scriptTraits(List> allOpenedNamespaces, int scriptIndex, String scriptName, List traits, Reference numberUsageRef, Reference numberRoundingRef, Reference numberPrecisionRef) throws AVM2ParseException, IOException, CompilationException, InterruptedException { + private void scriptTraits(List> allOpenedNamespaces, int scriptIndex, String scriptName, List traits, Reference numberUsageRef, Reference numberRoundingRef, Reference numberPrecisionRef, ABC abc) throws AVM2ParseException, IOException, CompilationException, InterruptedException { - while (scriptTraitsBlock(allOpenedNamespaces, scriptIndex, scriptName, traits, numberUsageRef, numberRoundingRef, numberPrecisionRef)) { + while (scriptTraitsBlock(allOpenedNamespaces, scriptIndex, scriptName, traits, numberUsageRef, numberRoundingRef, numberPrecisionRef, abc)) { //empty } } - private boolean scriptTraitsBlock(List> allOpenedNamespaces, int scriptIndex, String scriptName, List traits, Reference numberUsageRef, Reference numberRoundingRef, Reference numberPrecisionRef) throws AVM2ParseException, IOException, CompilationException, InterruptedException { + private boolean scriptTraitsBlock(List> allOpenedNamespaces, int scriptIndex, String scriptName, List traits, Reference numberUsageRef, Reference numberRoundingRef, Reference numberPrecisionRef, ABC abc) throws AVM2ParseException, IOException, CompilationException, InterruptedException { ParsedSymbol s; boolean inPackage = false; s = lex(); @@ -1074,12 +1076,12 @@ public class ActionScript3Parser { if (!isInterface) { if (s.type == SymbolType.EXTENDS) { - extendsTypeStr = type(allOpenedNamespaces, null, ns, new Reference<>(false), importedClasses, openedNamespaces, new ArrayList<>()); + extendsTypeStr = type(allOpenedNamespaces, null, ns, new Reference<>(false), importedClasses, openedNamespaces, new ArrayList<>(), abc); s = lex(); } if (s.type == SymbolType.IMPLEMENTS) { do { - GraphTargetItem implementsTypeStr = type(allOpenedNamespaces, null, ns, new Reference<>(false), importedClasses, openedNamespaces, new ArrayList<>()); + GraphTargetItem implementsTypeStr = type(allOpenedNamespaces, null, ns, new Reference<>(false), importedClasses, openedNamespaces, new ArrayList<>(), abc); interfaces.add(implementsTypeStr); s = lex(); } while (s.type == SymbolType.COMMA); @@ -1088,7 +1090,7 @@ public class ActionScript3Parser { } else { if (s.type == SymbolType.EXTENDS) { do { - GraphTargetItem intExtendsTypeStr = type(allOpenedNamespaces, null, ns, new Reference<>(false), importedClasses, openedNamespaces, new ArrayList<>()); + GraphTargetItem intExtendsTypeStr = type(allOpenedNamespaces, null, ns, new Reference<>(false), importedClasses, openedNamespaces, new ArrayList<>(), abc); interfaces.add(intExtendsTypeStr); s = lex(); } while (s.type == SymbolType.COMMA); @@ -1121,7 +1123,7 @@ public class ActionScript3Parser { List subTraits = new ArrayList<>(); - classTraits(allOpenedNamespaces, !inPackage, cinitVariables, cinitNeedsActivation, cinit, importedClasses, subOpenedNamespaces, ns, subNameStr, isInterface, subTraits, iinitVariables, iinitNeedsActivation, iinit); + classTraits(allOpenedNamespaces, !inPackage, cinitVariables, cinitNeedsActivation, cinit, importedClasses, subOpenedNamespaces, ns, subNameStr, isInterface, subTraits, iinitVariables, iinitNeedsActivation, iinit, abc); if (isInterface) { traits.add(new InterfaceAVM2Item(metadata, importedClasses, ns, subOpenedNamespaces, isFinal, subNameStr, interfaces, subTraits, nullable)); @@ -1137,7 +1139,7 @@ public class ActionScript3Parser { expected(s, lexer.yyline(), SymbolGroup.IDENTIFIER); String fname = s.value.toString(); - traits.add(method(allOpenedNamespaces, !inPackage, false, metadata, ns, false, isNative, null, new Reference<>(false), importedClasses, false, isFinal, null, openedNamespaces, true, fname, true, new ArrayList<>())); + traits.add(method(allOpenedNamespaces, !inPackage, false, metadata, ns, false, isNative, null, new Reference<>(false), importedClasses, false, isFinal, null, openedNamespaces, true, fname, true, new ArrayList<>(), abc)); break; case CONST: case VAR: @@ -1153,7 +1155,7 @@ public class ActionScript3Parser { s = lex(); GraphTargetItem type; if (s.type == SymbolType.COLON) { - type = type(allOpenedNamespaces, null, ns, new Reference<>(false), importedClasses, openedNamespaces, new ArrayList<>()); + type = type(allOpenedNamespaces, null, ns, new Reference<>(false), importedClasses, openedNamespaces, new ArrayList<>(), abc); s = lex(); } else { type = TypeItem.UNBOUNDED; @@ -1162,7 +1164,7 @@ public class ActionScript3Parser { GraphTargetItem value = null; if (s.type == SymbolType.ASSIGN) { - value = expression(allOpenedNamespaces, null, ns, new Reference<>(false), importedClasses, openedNamespaces, new HashMap<>(), false, false, true, sinitVariables, false); + value = expression(allOpenedNamespaces, null, ns, new Reference<>(false), importedClasses, openedNamespaces, new HashMap<>(), false, false, true, sinitVariables, false, abc); s = lex(); } GraphTargetItem tar; @@ -1320,7 +1322,7 @@ public class ActionScript3Parser { } } - private List xmltag(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference usesVars, List openedTags, Reference needsActivation, List importedClasses, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, List variables) throws IOException, AVM2ParseException, InterruptedException { + private List xmltag(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference usesVars, List openedTags, Reference needsActivation, List importedClasses, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, List variables, ABC abc) throws IOException, AVM2ParseException, InterruptedException { ParsedSymbol s; List rets = new ArrayList<>(); //GraphTargetItem ret = null; @@ -1334,7 +1336,7 @@ public class ActionScript3Parser { case XML_ATTRNAMEVAR_BEGIN: // {...}= add usesVars.setVal(true); addS(rets, sb); - rets.add(expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false)); + rets.add(expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc)); expectedType(SymbolType.CURLY_CLOSE); expectedType(SymbolType.ASSIGN); sb.append("="); @@ -1344,7 +1346,7 @@ public class ActionScript3Parser { usesVars.setVal(true); sb.append("\""); addS(rets, sb); - rets.add(new EscapeXAttrAVM2Item(null, null, expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false))); + rets.add(new EscapeXAttrAVM2Item(null, null, expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc))); sb.append("\""); expectedType(SymbolType.CURLY_CLOSE); lexer.yybegin(ActionScriptLexer.XMLOPENTAG); @@ -1352,7 +1354,7 @@ public class ActionScript3Parser { case XML_VAR_BEGIN: // {...} esc_xelem usesVars.setVal(true); addS(rets, sb); - rets.add(new EscapeXElemAVM2Item(null, null, expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false))); + rets.add(new EscapeXElemAVM2Item(null, null, expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc))); expectedType(SymbolType.CURLY_CLOSE); lexer.yybegin(ActionScriptLexer.XML); break; @@ -1361,7 +1363,7 @@ public class ActionScript3Parser { sb.append(" add - GraphTargetItem ex = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false); + GraphTargetItem ex = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc); expectedType(SymbolType.CURLY_CLOSE); lexer.yybegin(ActionScriptLexer.XMLOPENTAG); sub.add("*"); sb.append("<"); addS(rets, sb); rets.add(ex); - rets.addAll(xmltag(allOpenedNamespaces, thisType, pkg, subusesvars, sub, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables)); + rets.addAll(xmltag(allOpenedNamespaces, thisType, pkg, subusesvars, sub, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables, abc)); break; case XML_STARTTAG_BEGIN: // sub.add(s.value.toString().trim().substring(1)); //remove < from beginning - List st = xmltag(allOpenedNamespaces, thisType, pkg, subusesvars, sub, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables); + List st = xmltag(allOpenedNamespaces, thisType, pkg, subusesvars, sub, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables, abc); sb.append(s.value.toString()); addS(rets, sb); rets.addAll(st); @@ -1423,9 +1425,9 @@ public class ActionScript3Parser { return rets; } - private GraphTargetItem xml(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, List variables) throws IOException, AVM2ParseException, InterruptedException { + private GraphTargetItem xml(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, List variables, ABC abc) throws IOException, AVM2ParseException, InterruptedException { List openedTags = new ArrayList<>(); - List xmlParts = xmltag(allOpenedNamespaces, thisType, pkg, new Reference<>(false), openedTags, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables); + List xmlParts = xmltag(allOpenedNamespaces, thisType, pkg, new Reference<>(false), openedTags, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables, abc); lexer.setEnableWhiteSpace(true); lexer.begin(ActionScriptLexer.YYINITIAL); ParsedSymbol s = lexer.lex(); @@ -1442,7 +1444,7 @@ public class ActionScript3Parser { return ret; } - private GraphTargetItem command(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, Stack loops, Map loopLabels, HashMap registerVars, boolean inFunction, boolean inMethod, int forinlevel, boolean mustBeCommand, List variables) throws IOException, AVM2ParseException, InterruptedException { + private GraphTargetItem command(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, Stack loops, Map loopLabels, HashMap registerVars, boolean inFunction, boolean inMethod, int forinlevel, boolean mustBeCommand, List variables, ABC abc) throws IOException, AVM2ParseException, InterruptedException { LexBufferer buf = new LexBufferer(); lexer.addListener(buf); GraphTargetItem ret = null; @@ -1474,7 +1476,7 @@ public class ActionScript3Parser { } else { expectedType(SymbolType.NAMESPACE); expectedType(SymbolType.ASSIGN); - GraphTargetItem ns = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false); + GraphTargetItem ns = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc); ret = new DefaultXMLNamespace(null, null, ns); //TODO: use dxns for attribute namespaces instead of dxnslate } @@ -1483,20 +1485,20 @@ public class ActionScript3Parser { switch (s.type) { case USE: expectedType(SymbolType.NAMESPACE); - GraphTargetItem ns = type(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, variables); + GraphTargetItem ns = type(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, variables, abc); openedNamespaces.add(new NamespaceItem(ns.toString(), Namespace.KIND_PACKAGE /*FIXME?*/)); break; case WITH: needsActivation.setVal(true); expectedType(SymbolType.PARENT_OPEN); - GraphTargetItem wvar = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false); + GraphTargetItem wvar = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc); if (!isNameOrProp(wvar)) { throw new AVM2ParseException("Not a property or name", lexer.yyline()); } expectedType(SymbolType.PARENT_CLOSE); expectedType(SymbolType.CURLY_OPEN); List withVars = new ArrayList<>(); - List wcmd = commands(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, withVars); + List wcmd = commands(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, withVars, abc); variables.addAll(withVars); for (AssignableAVM2Item a : withVars) { if (a instanceof UnresolvedAVM2Item) { @@ -1527,7 +1529,7 @@ public class ActionScript3Parser { s = lexer.lex(); expected(s, lexer.yyline(), SymbolGroup.IDENTIFIER); needsActivation.setVal(true); - ret = (function(allOpenedNamespaces, new ArrayList<>(), pkg, false, false, needsActivation, importedClasses, thisType, openedNamespaces, s.value.toString(), false, variables)); + ret = (function(allOpenedNamespaces, new ArrayList<>(), pkg, false, false, needsActivation, importedClasses, thisType, openedNamespaces, s.value.toString(), false, variables, abc)); break; case VAR: s = lex(); @@ -1536,14 +1538,14 @@ public class ActionScript3Parser { s = lex(); GraphTargetItem type; if (s.type == SymbolType.COLON) { - type = type(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, variables); + type = type(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, variables, abc); s = lex(); } else { type = TypeItem.UNBOUNDED; } if (s.type == SymbolType.ASSIGN) { - GraphTargetItem varval = (expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false)); + GraphTargetItem varval = (expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc)); ret = new NameAVM2Item(type, lexer.yyline(), false, varIdentifier, "", varval, true, openedNamespaces, abcIndex); variables.add((NameAVM2Item) ret); } else { @@ -1553,7 +1555,7 @@ public class ActionScript3Parser { } break; case CURLY_OPEN: - ret = new BlockItem(null, null, commands(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, variables)); + ret = new BlockItem(null, null, commands(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, variables, abc)); expectedType(SymbolType.CURLY_CLOSE); break; /*case INCREMENT: //preincrement @@ -1571,7 +1573,7 @@ public class ActionScript3Parser { case SUPER: //constructor call ParsedSymbol ss2 = lex(); if (ss2.type == SymbolType.PARENT_OPEN) { - List args = call(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables); + List args = call(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables, abc); ret = new ConstructSuperAVM2Item(null, null, new LocalRegAVM2Item(null, null, 0, null, new TypeItem("Object") /*?*/), args); } else { //no costructor call, but it could be calling parent methods... => handle in expression lexer.pushback(ss2); @@ -1580,16 +1582,16 @@ public class ActionScript3Parser { break; case IF: expectedType(SymbolType.PARENT_OPEN); - GraphTargetItem ifExpr = (expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false)); + GraphTargetItem ifExpr = (expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc)); expectedType(SymbolType.PARENT_CLOSE); - GraphTargetItem onTrue = command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables); + GraphTargetItem onTrue = command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables, abc); List onTrueList = new ArrayList<>(); onTrueList.add(onTrue); s = lex(); List onFalseList = null; if (s.type == SymbolType.ELSE) { onFalseList = new ArrayList<>(); - onFalseList.add(command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)); + onFalseList.add(command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables, abc)); } else { lexer.pushback(s); } @@ -1598,7 +1600,7 @@ public class ActionScript3Parser { case WHILE: expectedType(SymbolType.PARENT_OPEN); List whileExpr = new ArrayList<>(); - whileExpr.add(expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, true)); + whileExpr.add(expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, true, abc)); expectedType(SymbolType.PARENT_CLOSE); List whileBody = new ArrayList<>(); Loop wloop = new Loop(uniqId(), null, null); @@ -1606,7 +1608,7 @@ public class ActionScript3Parser { loopLabels.put(wloop, loopLabel); } loops.push(wloop); - whileBody.add(command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)); + whileBody.add(command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables, abc)); ret = new WhileItem(null, null, wloop, whileExpr, whileBody); break; case DO: @@ -1616,11 +1618,11 @@ public class ActionScript3Parser { if (loopLabel != null) { loopLabels.put(dloop, loopLabel); } - doBody.add(command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)); + doBody.add(command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables, abc)); expectedType(SymbolType.WHILE); expectedType(SymbolType.PARENT_OPEN); List doExpr = new ArrayList<>(); - doExpr.add(expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, true)); + doExpr.add(expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, true, abc)); expectedType(SymbolType.PARENT_CLOSE); ret = new DoWhileItem(null, null, dloop, doBody, doExpr); break; @@ -1635,11 +1637,11 @@ public class ActionScript3Parser { s = lex(); } expected(s, lexer.yyline(), SymbolType.PARENT_OPEN); - GraphTargetItem firstCommand = command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, false, variables); + GraphTargetItem firstCommand = command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, false, variables, abc); if (firstCommand instanceof NameAVM2Item) { NameAVM2Item nai = (NameAVM2Item) firstCommand; if (nai.isDefinition() && nai.getAssignedValue() == null) { //Declared value in for..in - firstCommand = expression1(allOpenedNamespaces, firstCommand, GraphTargetItem.NOPRECEDENCE, thisType, pkg, needsActivation, importedClasses, openedNamespaces, true, registerVars, inFunction, inMethod, true, variables); + firstCommand = expression1(allOpenedNamespaces, firstCommand, GraphTargetItem.NOPRECEDENCE, thisType, pkg, needsActivation, importedClasses, openedNamespaces, true, registerVars, inFunction, inMethod, true, variables, abc); } } InAVM2Item inexpr = null; @@ -1665,19 +1667,19 @@ public class ActionScript3Parser { } lexer.pushback(s); //GraphTargetItem firstCommand = command(thisType,pkg,needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables); - forExpr = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false); + forExpr = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc); if (forExpr == null) { forExpr = new TrueItem(null, null); } expectedType(SymbolType.SEMICOLON); - GraphTargetItem fcom = command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables); + GraphTargetItem fcom = command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables, abc); if (fcom != null) { forFinalCommands.add(fcom); } } expectedType(SymbolType.PARENT_CLOSE); List forBody = new ArrayList<>(); - forBody.add(command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forin ? forinlevel + 1 : forinlevel, true, variables)); + forBody.add(command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forin ? forinlevel + 1 : forinlevel, true, variables, abc)); if (forin) { if (each) { ret = new ForEachInAVM2Item(null, null, floop, inexpr, forBody); @@ -1696,7 +1698,7 @@ public class ActionScript3Parser { loopLabels.put(sloop, loopLabel); } expectedType(SymbolType.PARENT_OPEN); - GraphTargetItem switchExpr = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false); + GraphTargetItem switchExpr = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc); expectedType(SymbolType.PARENT_CLOSE); expectedType(SymbolType.CURLY_OPEN); s = lex(); @@ -1716,7 +1718,7 @@ public class ActionScript3Parser { int pos = 0; while (s.type == SymbolType.CASE || s.type == SymbolType.DEFAULT) { while (s.type == SymbolType.CASE || s.type == SymbolType.DEFAULT) { - GraphTargetItem curCaseExpr = s.type == SymbolType.DEFAULT ? new DefaultItem() : expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, true); + GraphTargetItem curCaseExpr = s.type == SymbolType.DEFAULT ? new DefaultItem() : expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, true, abc); expectedType(SymbolType.COLON); s = lex(); caseExprsAll.add(curCaseExpr); @@ -1724,7 +1726,7 @@ public class ActionScript3Parser { } pos++; lexer.pushback(s); - List caseCmd = commands(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, variables); + List caseCmd = commands(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, variables, abc); caseCmds.add(caseCmd); s = lex(); } @@ -1790,7 +1792,7 @@ public class ActionScript3Parser { ret = new ContinueItem(null, null, cloopId); break; case RETURN: - GraphTargetItem retexpr = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, true, registerVars, inFunction, inMethod, true, variables, false); + GraphTargetItem retexpr = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, true, registerVars, inFunction, inMethod, true, variables, false, abc); if (retexpr == null) { ret = new ReturnVoidAVM2Item(null, null); } else { @@ -1800,7 +1802,7 @@ public class ActionScript3Parser { case TRY: needsActivation.setVal(true); List tryCommands = new ArrayList<>(); - tryCommands.add(command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)); + tryCommands.add(command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables, abc)); s = lex(); boolean found = false; List> catchCommands = new ArrayList<>(); @@ -1814,7 +1816,7 @@ public class ActionScript3Parser { String enamestr = s.value.toString(); expectedType(SymbolType.COLON); - GraphTargetItem etype = type(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, variables); + GraphTargetItem etype = type(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, variables, abc); NameAVM2Item e = new NameAVM2Item(etype, lexer.yyline(), false, enamestr, "", new ExceptionAVM2Item(null)/*?*/, true/*?*/, openedNamespaces, abcIndex); //variables.add(e); catchExceptions.add(e); @@ -1823,7 +1825,7 @@ public class ActionScript3Parser { expectedType(SymbolType.PARENT_CLOSE); List catchVars = new ArrayList<>(); expectedType(SymbolType.CURLY_OPEN); - List cc = commands(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, catchVars); + List cc = commands(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, catchVars, abc); expectedType(SymbolType.CURLY_CLOSE); catchesVars.add(catchVars); List newVariables = new ArrayList<>(catchVars); @@ -1876,7 +1878,7 @@ public class ActionScript3Parser { List finallyCommands = null; if (s.type == SymbolType.FINALLY) { finallyCommands = new ArrayList<>(); - finallyCommands.add(command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)); + finallyCommands.add(command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables, abc)); found = true; s = lex(); } @@ -1890,7 +1892,7 @@ public class ActionScript3Parser { ret = tai; break; case THROW: - ret = new ThrowAVM2Item(null, null, expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false)); + ret = new ThrowAVM2Item(null, null, expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc)); break; default: GraphTargetItem valcmd = expressionCommands(s, registerVars, inFunction, inMethod, forinlevel, variables); @@ -1902,7 +1904,7 @@ public class ActionScript3Parser { return new EmptyCommand(); } lexer.pushback(s); - ret = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, true); + ret = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, true, abc); if (debugMode) { System.out.println("/command"); } @@ -1914,7 +1916,7 @@ public class ActionScript3Parser { lexer.removeListener(buf); if (ret == null) { //can be popped expression buf.pushAllBack(lexer); - ret = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false); + ret = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc); } s = lex(); if ((s != null) && (s.type != SymbolType.SEMICOLON)) { @@ -1955,7 +1957,7 @@ public class ActionScript3Parser { return (item instanceof NameAVM2Item); } - private int brackets(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, List ret, HashMap registerVars, boolean inFunction, boolean inMethod, List variables) throws IOException, AVM2ParseException, InterruptedException { + private int brackets(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, List ret, HashMap registerVars, boolean inFunction, boolean inMethod, List variables, ABC abc) throws IOException, AVM2ParseException, InterruptedException { ParsedSymbol s = lex(); int arrCnt = 0; if (s.type == SymbolType.BRACKET_OPEN) { @@ -1966,7 +1968,7 @@ public class ActionScript3Parser { lexer.pushback(s); } arrCnt++; - ret.add(expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false)); + ret.add(expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc)); s = lex(); if (!s.isType(SymbolType.COMMA, SymbolType.BRACKET_CLOSE)) { expected(s, lexer.yyline(), SymbolType.COMMA, SymbolType.BRACKET_CLOSE); @@ -1979,20 +1981,20 @@ public class ActionScript3Parser { return arrCnt; } - private GraphTargetItem expression(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, boolean allowRemainder, List variables, boolean allowComma) throws IOException, AVM2ParseException, InterruptedException { - return expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, allowRemainder, variables, allowComma); + private GraphTargetItem expression(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, boolean allowRemainder, List variables, boolean allowComma, ABC abc) throws IOException, AVM2ParseException, InterruptedException { + return expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, allowRemainder, variables, allowComma, abc); } - private GraphTargetItem expression(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, boolean allowEmpty, HashMap registerVars, boolean inFunction, boolean inMethod, boolean allowRemainder, List variables, boolean allowComma) throws IOException, AVM2ParseException, InterruptedException { + private GraphTargetItem expression(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, boolean allowEmpty, HashMap registerVars, boolean inFunction, boolean inMethod, boolean allowRemainder, List variables, boolean allowComma, ABC abc) throws IOException, AVM2ParseException, InterruptedException { List commaItems = new ArrayList<>(); ParsedSymbol symb; do { - GraphTargetItem prim = expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, allowEmpty, registerVars, inFunction, inMethod, allowRemainder, variables); + GraphTargetItem prim = expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, allowEmpty, registerVars, inFunction, inMethod, allowRemainder, variables, abc); if (prim == null) { return null; } - GraphTargetItem item = expression1(allOpenedNamespaces, prim, GraphTargetItem.NOPRECEDENCE, thisType, pkg, needsActivation, importedClasses, openedNamespaces, allowEmpty, registerVars, inFunction, inMethod, allowRemainder, variables); + GraphTargetItem item = expression1(allOpenedNamespaces, prim, GraphTargetItem.NOPRECEDENCE, thisType, pkg, needsActivation, importedClasses, openedNamespaces, allowEmpty, registerVars, inFunction, inMethod, allowRemainder, variables, abc); commaItems.add(item); symb = lex(); } while (allowComma && symb != null && symb.type == SymbolType.COMMA); @@ -2052,7 +2054,7 @@ public class ActionScript3Parser { return lookahead; } - private GraphTargetItem expression1(List> allOpenedNamespaces, GraphTargetItem lhs, int min_precedence, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, boolean allowEmpty, HashMap registerVars, boolean inFunction, boolean inMethod, boolean allowRemainder, List variables) throws IOException, AVM2ParseException, InterruptedException { + private GraphTargetItem expression1(List> allOpenedNamespaces, GraphTargetItem lhs, int min_precedence, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, boolean allowEmpty, HashMap registerVars, boolean inFunction, boolean inMethod, boolean allowRemainder, List variables, ABC abc) throws IOException, AVM2ParseException, InterruptedException { if (debugMode) { System.out.println("expression1:"); } @@ -2074,14 +2076,14 @@ public class ActionScript3Parser { if (debugMode) { System.out.println("ternar-middle:"); } - mhs = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, allowRemainder, variables, false); + mhs = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, allowRemainder, variables, false, abc); expectedType(SymbolType.COLON); if (debugMode) { System.out.println("/ternar-middle"); } } - rhs = expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, allowEmpty, registerVars, inFunction, inMethod, allowRemainder, variables); + rhs = expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, allowEmpty, registerVars, inFunction, inMethod, allowRemainder, variables, abc); if (rhs == null) { lexer.pushback(op); break; @@ -2090,7 +2092,7 @@ public class ActionScript3Parser { lookahead = peekExprToken(); while ((lookahead.type.isBinary() && lookahead.type.getPrecedence() < /* > on wiki */ op.type.getPrecedence()) || (lookahead.type.isRightAssociative() && lookahead.type.getPrecedence() == op.type.getPrecedence())) { - rhs = expression1(allOpenedNamespaces, rhs, lookahead.type.getPrecedence(), thisType, pkg, needsActivation, importedClasses, openedNamespaces, allowEmpty, registerVars, inFunction, inMethod, allowRemainder, variables); + rhs = expression1(allOpenedNamespaces, rhs, lookahead.type.getPrecedence(), thisType, pkg, needsActivation, importedClasses, openedNamespaces, allowEmpty, registerVars, inFunction, inMethod, allowRemainder, variables, abc); lookahead = peekExprToken(); } @@ -2256,7 +2258,7 @@ public class ActionScript3Parser { } } if (lhs instanceof ParenthesisItem) { - GraphTargetItem coerced = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, allowRemainder, variables, false); + GraphTargetItem coerced = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, allowRemainder, variables, false, abc); if (coerced != null && isType(((ParenthesisItem) lhs).value)) { lhs = new CoerceAVM2Item(null, null, ((ParenthesisItem) lhs).value, coerced); } @@ -2268,7 +2270,7 @@ public class ActionScript3Parser { return lhs; } - private GraphTargetItem expressionPrimary(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, boolean allowEmpty, HashMap registerVars, boolean inFunction, boolean inMethod, boolean allowRemainder, List variables) throws IOException, AVM2ParseException, InterruptedException { + private GraphTargetItem expressionPrimary(List> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference needsActivation, List importedClasses, List openedNamespaces, boolean allowEmpty, HashMap registerVars, boolean inFunction, boolean inMethod, boolean allowRemainder, List variables, ABC abc) throws IOException, AVM2ParseException, InterruptedException { if (debugMode) { System.out.println("primary:"); } @@ -2281,36 +2283,36 @@ public class ActionScript3Parser { switch ("" + s.value) { //AS3 case "hasnext": - GraphTargetItem hnIndex = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false); + GraphTargetItem hnIndex = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc); expectedType(SymbolType.COMMA); - GraphTargetItem hnObject = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false); + GraphTargetItem hnObject = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc); ret = new HasNextAVM2Item(null, null, hnIndex, hnObject); break; case "newactivation": ret = new NewActivationAVM2Item(null, null); break; case "nextname": - GraphTargetItem nnIndex = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false); + GraphTargetItem nnIndex = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc); expectedType(SymbolType.COMMA); - GraphTargetItem nnObject = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false); + GraphTargetItem nnObject = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc); ret = new NextNameAVM2Item(null, null, nnIndex, nnObject); allowMemberOrCall = true; break; case "nextvalue": - GraphTargetItem nvIndex = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false); + GraphTargetItem nvIndex = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc); expectedType(SymbolType.COMMA); - GraphTargetItem nvObject = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false); + GraphTargetItem nvObject = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc); ret = new NextNameAVM2Item(null, null, nvIndex, nvObject); allowMemberOrCall = true; break; //Both ASs case "dup": - ret = new DuplicateItem(null, null, expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false)); + ret = new DuplicateItem(null, null, expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc)); break; case "push": - ret = new PushItem(expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false)); + ret = new PushItem(expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc)); break; case "pop": ret = new PopItem(null, null); @@ -2338,16 +2340,24 @@ public class ActionScript3Parser { case XML_CDATA: case XML_COMMENT: lexer.pushback(s); - ret = xml(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables); + ret = xml(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables, abc); break; case STRING: ret = new StringAVM2Item(null, null, s.value.toString()); allowMemberOrCall = true; break; case NEGATE: - ret = expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, false, variables); + ret = expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, false, variables, abc); ret = new BitNotAVM2Item(null, null, ret); + break; + case PLUS: + GraphTargetItem nump = expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, true, variables, abc); + if (abc.hasFloatSupport()) { + ret = new UnPlusAVM2Item(null, null, nump); + } else { + ret = new CoerceAVM2Item(null, null, nump, TypeItem.NUMBER); + } break; case MINUS: s = lex(); @@ -2357,11 +2367,11 @@ public class ActionScript3Parser { ret = new IntegerValueAVM2Item(null, null, -(Integer) s.value); } else if (s.isType(SymbolType.DECIMAL)) { ret = new DecimalValueAVM2Item(null, null, ((Decimal128) s.value).multiply(Decimal128.NEG1)); - } else if (s.isType(SymbolType.FLOAT)) { + } else if (s.isType(SymbolType.FLOAT)) { ret = new FloatValueAVM2Item(null, null, -(Float) s.value); } else { lexer.pushback(s); - GraphTargetItem num = expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, true, variables); + GraphTargetItem num = expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, true, variables, abc); if (num instanceof IntegerValueAVM2Item) { ((IntegerValueAVM2Item) num).value = -((IntegerValueAVM2Item) num).value; ((IntegerValueAVM2Item) num).detectFormat(); @@ -2380,7 +2390,7 @@ public class ActionScript3Parser { } break; case TYPEOF: - ret = new TypeOfAVM2Item(null, null, expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, false, variables)); + ret = new TypeOfAVM2Item(null, null, expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, false, variables, abc)); break; case TRUE: ret = new BooleanAVM2Item(null, null, true); @@ -2410,13 +2420,13 @@ public class ActionScript3Parser { GraphTargetItem n; if (s.type == SymbolType.PARENT_OPEN) { //special for obfuscated SWFs - n = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, allowRemainder, variables, false); + n = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, allowRemainder, variables, false, abc); expectedType(SymbolType.PARENT_CLOSE); } else { n = new StringAVM2Item(null, null, s.value.toString()); } expectedType(SymbolType.COLON); - GraphTargetItem v = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, allowRemainder, variables, false); + GraphTargetItem v = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, allowRemainder, variables, false, abc); NameValuePair nv = new NameValuePair(n, v); nvs.add(nv); @@ -2431,7 +2441,7 @@ public class ActionScript3Parser { case BRACKET_OPEN: //Array literal or just brackets lexer.pushback(s); List inBrackets = new ArrayList<>(); - int arrCnt = brackets(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, inBrackets, registerVars, inFunction, inMethod, variables); + int arrCnt = brackets(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, inBrackets, registerVars, inFunction, inMethod, variables, abc); ret = new NewArrayAVM2Item(null, null, inBrackets); allowMemberOrCall = true; @@ -2445,7 +2455,7 @@ public class ActionScript3Parser { lexer.pushback(s); } needsActivation.setVal(true); - ret = function(allOpenedNamespaces, new ArrayList<>(), pkg, false, false, needsActivation, importedClasses, thisType, openedNamespaces, fname, false, variables); + ret = function(allOpenedNamespaces, new ArrayList<>(), pkg, false, false, needsActivation, importedClasses, thisType, openedNamespaces, fname, false, variables, abc); allowMemberOrCall = true; break; case NAN: @@ -2477,7 +2487,7 @@ public class ActionScript3Parser { allowMemberOrCall = true; break; case DELETE: - GraphTargetItem varDel = expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, true, variables); + GraphTargetItem varDel = expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, true, variables, abc); if (!isNameOrProp(varDel)) { throw new AVM2ParseException("Not a property or name", lexer.yyline()); } @@ -2485,7 +2495,7 @@ public class ActionScript3Parser { break; case INCREMENT: case DECREMENT: //preincrement - GraphTargetItem varincdec = expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, false/*?*/, variables); + GraphTargetItem varincdec = expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, false/*?*/, variables, abc); if (!isNameOrProp(varincdec)) { throw new AVM2ParseException("Not a property or name", lexer.yyline()); } @@ -2498,11 +2508,11 @@ public class ActionScript3Parser { break; case NOT: - ret = new NotItem(null, null, expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, false, variables)); + ret = new NotItem(null, null, expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, false, variables, abc)); break; case PARENT_OPEN: - ret = new ParenthesisItem(null, null, expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, true)); + ret = new ParenthesisItem(null, null, expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, true, abc)); expectedType(SymbolType.PARENT_CLOSE); if (ret.value == null) { throw new AVM2ParseException("Expression in parenthesis expected", lexer.yyline()); @@ -2524,29 +2534,29 @@ public class ActionScript3Parser { lexer.pushback(s); } needsActivation.setVal(true); - ret = function(allOpenedNamespaces, new ArrayList<>(), pkg, false, false, needsActivation, importedClasses, thisType, openedNamespaces, ffname, false, variables); + ret = function(allOpenedNamespaces, new ArrayList<>(), pkg, false, false, needsActivation, importedClasses, thisType, openedNamespaces, ffname, false, variables, abc); } else if (s.type == SymbolType.LOWER_THAN) { - GraphTargetItem subtype = type(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, variables); + GraphTargetItem subtype = type(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, variables, abc); expectedType(SymbolType.GREATER_THAN); s = lex(); expected(s, lexer.yyline(), SymbolType.BRACKET_OPEN); lexer.pushback(s); List params = new ArrayList<>(); - brackets(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, params, registerVars, inFunction, inMethod, variables); + brackets(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, params, registerVars, inFunction, inMethod, variables, abc); ret = new InitVectorAVM2Item(subtype, params, openedNamespaces); } else if (s.type == SymbolType.PARENT_OPEN) { - GraphTargetItem newvar = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false); - newvar = applyType(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, newvar, registerVars, inFunction, inMethod, variables); + GraphTargetItem newvar = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc); + newvar = applyType(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, newvar, registerVars, inFunction, inMethod, variables, abc); expectedType(SymbolType.PARENT_CLOSE); expectedType(SymbolType.PARENT_OPEN); - ret = new ConstructSomethingAVM2Item(lexer.yyline(), openedNamespaces, newvar, call(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables), abcIndex); + ret = new ConstructSomethingAVM2Item(lexer.yyline(), openedNamespaces, newvar, call(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables, abc), abcIndex); } else { lexer.pushback(s); - GraphTargetItem newvar = name(allOpenedNamespaces, thisType, pkg, needsActivation, false /*?*/, openedNamespaces, registerVars, inFunction, inMethod, variables, importedClasses); - newvar = applyType(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, newvar, registerVars, inFunction, inMethod, variables); + GraphTargetItem newvar = name(allOpenedNamespaces, thisType, pkg, needsActivation, false /*?*/, openedNamespaces, registerVars, inFunction, inMethod, variables, importedClasses, abc); + newvar = applyType(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, newvar, registerVars, inFunction, inMethod, variables, abc); expectedType(SymbolType.PARENT_OPEN); - ret = new ConstructSomethingAVM2Item(lexer.yyline(), openedNamespaces, newvar, call(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables), abcIndex); + ret = new ConstructSomethingAVM2Item(lexer.yyline(), openedNamespaces, newvar, call(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables, abc), abcIndex); } allowMemberOrCall = true; break; @@ -2555,7 +2565,7 @@ public class ActionScript3Parser { case SUPER: case ATTRIBUTE: lexer.pushback(s); - ret = name(allOpenedNamespaces, thisType, pkg, needsActivation, false, openedNamespaces, registerVars, inFunction, inMethod, variables, importedClasses); + ret = name(allOpenedNamespaces, thisType, pkg, needsActivation, false, openedNamespaces, registerVars, inFunction, inMethod, variables, importedClasses, abc); allowMemberOrCall = true; //var = memberOrCall(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, var, registerVars, inFunction, inMethod, variables); @@ -2572,7 +2582,7 @@ public class ActionScript3Parser { lexer.pushback(s); } if (allowMemberOrCall && ret != null) { - ret = memberOrCall(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables); + ret = memberOrCall(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, ret, registerVars, inFunction, inMethod, variables, abc); } if (debugMode) { System.out.println("/primary"); @@ -2722,7 +2732,7 @@ public class ActionScript3Parser { return importedClasses; } - private List parseScript(List> allOpenedNamespaces, int scriptIndex, String fileName, Reference numberContextRef) throws IOException, AVM2ParseException, CompilationException, InterruptedException { + private List parseScript(List> allOpenedNamespaces, int scriptIndex, String fileName, Reference numberContextRef, ABC abc) throws IOException, AVM2ParseException, CompilationException, InterruptedException { //int scriptPrivateNs; if (fileName.contains("/")) { @@ -2735,7 +2745,7 @@ public class ActionScript3Parser { Reference numberUsageRef = new Reference<>(NumberContext.USE_NUMBER); Reference numberRoundingRef = new Reference<>(NumberContext.ROUND_HALF_EVEN); Reference numberPrecisionRef = new Reference<>(34); - scriptTraits(allOpenedNamespaces, scriptIndex, fileName, items, numberUsageRef, numberRoundingRef, numberPrecisionRef); + scriptTraits(allOpenedNamespaces, scriptIndex, fileName, items, numberUsageRef, numberRoundingRef, numberPrecisionRef, abc); NumberContext nc = new NumberContext(numberUsageRef.getVal(), numberPrecisionRef.getVal(), numberRoundingRef.getVal()); if (!nc.isDefault()) { @@ -2751,16 +2761,17 @@ public class ActionScript3Parser { * @param fileName File name * @param scriptIndex Script index * @param numberContextRef Number context reference + * @param abc ABC * @return List of script traits * @throws AVM2ParseException On parsing error * @throws IOException On I/O error * @throws CompilationException On compilation error * @throws InterruptedException On interrupt */ - public List scriptTraitsFromString(List> allOpenedNamespaces, String str, String fileName, int scriptIndex, Reference numberContextRef) throws AVM2ParseException, IOException, CompilationException, InterruptedException { + public List scriptTraitsFromString(List> allOpenedNamespaces, String str, String fileName, int scriptIndex, Reference numberContextRef, ABC abc) throws AVM2ParseException, IOException, CompilationException, InterruptedException { lexer = new ActionScriptLexer(str); - List ret = parseScript(allOpenedNamespaces, scriptIndex, fileName, numberContextRef); + List ret = parseScript(allOpenedNamespaces, scriptIndex, fileName, numberContextRef, abc); if (lexer.lex().type != SymbolType.EOF) { throw new AVM2ParseException("Parsing finisned before end of the file", lexer.yyline()); } @@ -2802,15 +2813,16 @@ public class ActionScript3Parser { * @param classPos Class position * @param scriptIndex Script index * @param documentClass Document class + * @param abc ABC * @throws AVM2ParseException On parsing error * @throws IOException On I/O error * @throws CompilationException On compilation error * @throws InterruptedException On interrupt */ - public void addScript(String s, String fileName, int classPos, int scriptIndex, String documentClass) throws AVM2ParseException, IOException, CompilationException, InterruptedException { + public void addScript(String s, String fileName, int classPos, int scriptIndex, String documentClass, ABC abc) throws AVM2ParseException, IOException, CompilationException, InterruptedException { List> allOpenedNamespaces = new ArrayList<>(); Reference numberContextRef = new Reference<>(null); - List traits = scriptTraitsFromString(allOpenedNamespaces, s, fileName, scriptIndex, numberContextRef); + List traits = scriptTraitsFromString(allOpenedNamespaces, s, fileName, scriptIndex, numberContextRef, abc); addScriptFromTree(allOpenedNamespaces, traits, classPos, documentClass, numberContextRef.getVal()); } @@ -2848,7 +2860,7 @@ public class ActionScript3Parser { boolean success = false; ABC originalAbc = ((ABCContainerTag) ((Tag) abc.parentTag).cloneTag()).getABC(); try { - parser.addScript(src, fileName, classPos, scriptIndex, documentClass); + parser.addScript(src, fileName, classPos, scriptIndex, documentClass, abc); success = true; } finally { if (!success) { @@ -2881,7 +2893,7 @@ public class ActionScript3Parser { AbcIndexing abcIndex = swf.getAbcIndex(); abcIndex.selectAbc(abc); ActionScript3Parser parser = new ActionScript3Parser(abcIndex); - parser.addScript(new String(Helper.readFile(srcFile), Utf8Helper.charset), srcFile, classPos, scriptIndex, swf.getDocumentClass()); + parser.addScript(new String(Helper.readFile(srcFile), Utf8Helper.charset), srcFile, classPos, scriptIndex, swf.getDocumentClass(), abc); try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(new File(destFile)))) { abc.saveToStream(fos); } diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DeobfuscatorTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DeobfuscatorTest.java index 0dc50f753..f22c9777c 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DeobfuscatorTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DeobfuscatorTest.java @@ -135,7 +135,7 @@ public class ActionScript3DeobfuscatorTest extends ActionScriptTestBase { index.rebuildPkgToObjectsNameMap(); ActionScript3Parser par = new ActionScript3Parser(index); HighlightedTextWriter writer = new HighlightedTextWriter(new CodeFormatting(), false); - par.addScript(str, "Test.as", 0, 0, swf.getDocumentClass()); + par.addScript(str, "Test.as", 0, 0, swf.getDocumentClass(), abc); abc.script_info.get(0).getPacks(abc, 0, "", new ArrayList<>()).get(0).toSource(swf.getAbcIndex(), writer, abc.script_info.get(0).traits.traits, new ConvertData(), ScriptExportMode.AS, false, false); writer.finishHilights(); diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java index 6babd8263..c0c51ae97 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java @@ -2906,7 +2906,7 @@ public class TagTreeContextMenu extends JPopupMenu { + "public class " + IdentifiersDeobfuscation.printIdentifier(true, classSimpleName) + (parentClassName.isEmpty() ? "" : " extends " + parentClassName) + " {" + " }" + "}"; - parser.addScript(script, fileName, 0, 0, swf.getDocumentClass()); + parser.addScript(script, fileName, 0, 0, swf.getDocumentClass(), selectedAbcContainer.getABC()); } catch (IOException | InterruptedException | AVM2ParseException | CompilationException ex) { Logger.getLogger(TagTreeContextMenu.class.getName()).log(Level.SEVERE, "Error during script compilation", ex); } @@ -3106,7 +3106,7 @@ public class TagTreeContextMenu extends JPopupMenu { + "public class " + IdentifiersDeobfuscation.printIdentifier(true, classSimpleName) + " {" + " }" + "}"; - parser.addScript(script, fileName, 0, 0, swf.getDocumentClass()); + parser.addScript(script, fileName, 0, 0, swf.getDocumentClass(), doAbc.getABC()); } catch (IOException | InterruptedException | AVM2ParseException | CompilationException ex) { Logger.getLogger(TagTreeContextMenu.class.getName()).log(Level.SEVERE, "Error during script compilation", ex); }