diff --git a/CHANGELOG.md b/CHANGELOG.md index 393ce2f23..c5fd2b955 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file. - AS2 - Do not detect classes inside functions - AS1/2 - Slash syntax colon vs ternar operator collision - AS1/2 - Allow nonstandard identifiers in object literal +- AS1/2 - Allow globalfunc names as variable identifiers ## [14.5.2] - 2021-11-20 ### Fixed diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java index 36cd8ca6a..5e1fa43a3 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java @@ -650,6 +650,23 @@ public class ActionScript2Parser { if (s.type == SymbolType.EOF) { return null; } + if (s.group == SymbolGroup.GLOBALFUNC) { + ParsedSymbol s2 = lex(); + if (s2.type != SymbolType.PARENT_OPEN) { + lexer.removeListener(buf); + buf.pushAllBack(lexer); + + ret = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval); + s = lex(); + if ((s != null) && (s.type != SymbolType.SEMICOLON)) { + lexer.pushback(s); + } + return ret; + } else { + lexer.pushback(s2); + } + } + switch (s.type) { case FSCOMMAND: expectedType(SymbolType.PARENT_OPEN); @@ -1638,6 +1655,29 @@ public class ActionScript2Parser { return arrCnt; } + private GraphTargetItem handleVariable(ParsedSymbol s, GraphTargetItem ret, List variables, Reference allowMemberOrCall, boolean inFunction, boolean inMethod, boolean inTellTarget, List functions, Reference hasEval) throws IOException, ActionParseException { + if (s.value.equals("not")) { + ret = new NotItem(null, null, expressionPrimary(false, inFunction, inMethod, inTellTarget, false, variables, functions, true, hasEval)); + } else { + String varName = s.value.toString(); + if (s.type == SymbolType.PATH) { //only with slash syntax + ParsedSymbol s2 = lex(); + while (s2.type == SymbolType.COLON) { + s2 = lex(); + expected(s2, lexer.yyline(), SymbolType.IDENTIFIER); + varName += ":" + s2.value.toString(); + s2 = lex(); + } + lexer.pushback(s2); + } + + ret = new VariableActionItem(varName, null, false); + variables.add((VariableActionItem) ret); + allowMemberOrCall.setVal(true); + } + return ret; + } + private GraphTargetItem expressionPrimary(boolean allowEmpty, boolean inFunction, boolean inMethod, boolean inTellTarget, boolean allowRemainder, List variables, List functions, boolean allowCall, Reference hasEval) throws IOException, ActionParseException { if (debugMode) { System.out.println("primary:"); @@ -1874,40 +1914,34 @@ public class ActionScript2Parser { case THIS: case SUPER: case PATH: - if (s.value.equals("not")) { - ret = new NotItem(null, null, expressionPrimary(false, inFunction, inMethod, inTellTarget, false, variables, functions, true, hasEval)); - } else { - String varName = s.value.toString(); - if (s.type == SymbolType.PATH) { //only with slash syntax - ParsedSymbol s2 = lex(); - while (s2.type == SymbolType.COLON) { - s2 = lex(); - expected(s2, lexer.yyline(), SymbolType.IDENTIFIER); - varName += ":" + s2.value.toString(); - s2 = lex(); - } - lexer.pushback(s2); - } - - /*if (Action.propertyNamesList.contains(varName)) { - ret = new GetPropertyActionItem(null, null, pushConst(""), Action.propertyNamesList.indexOf(varName)); - } else {*/ - ret = new VariableActionItem(varName, null, false); - variables.add((VariableActionItem) ret); - //} - allowMemberOrCall = true; - } + Reference allowMemberOrCallRef = new Reference<>(allowMemberOrCall); + ret = handleVariable(s, ret, variables, allowMemberOrCallRef, inFunction, inMethod, inTellTarget, functions, hasEval); + allowMemberOrCall = allowMemberOrCallRef.getVal(); break; default: - GraphTargetItem excmd = expressionCommands(s, inFunction, inMethod, inTellTarget, -1, variables, functions, hasEval); - if (excmd != null) { - //? - ret = excmd; - allowMemberOrCall = true; //? - break; + + boolean isGlobalFuncVar = false; + if (s.group == SymbolGroup.GLOBALFUNC) { + ParsedSymbol s2 = peekLex(); + if (s2.type != SymbolType.PARENT_OPEN) { + Reference allowMemberOrCallRef2 = new Reference<>(allowMemberOrCall); + ret = handleVariable(s, ret, variables, allowMemberOrCallRef2, inFunction, inMethod, inTellTarget, functions, hasEval); + allowMemberOrCall = allowMemberOrCallRef2.getVal(); + isGlobalFuncVar = true; + } + } + + if (!isGlobalFuncVar) { + GraphTargetItem excmd = expressionCommands(s, inFunction, inMethod, inTellTarget, -1, variables, functions, hasEval); + if (excmd != null) { + //? + ret = excmd; + allowMemberOrCall = true; //? + break; + } + lexer.pushback(s); } - lexer.pushback(s); } if (allowMemberOrCall && ret != null) {