diff --git a/CHANGELOG.md b/CHANGELOG.md index a84981502..4140f08d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. ### Fixed - #1336 AS3 direct editation - Regexp / character escaping - #1615 Turning off Checking for modifications disables SWF loading +- #1100, #1123, #1516 AS1/2/3 direct editation - comma operator ### Changed - #1616 Close SWF menuitem is last in the context menu diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java index 3133e73ad..04873d0d8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java @@ -1465,7 +1465,7 @@ public class AVM2SourceGenerator implements SourceGenerator { } @Override - public List generate(SourceGeneratorLocalData localData, CommaExpressionItem item) throws CompilationException { + public List generate(SourceGeneratorLocalData localData, CommaExpressionItem item, boolean withReturnValue) throws CompilationException { if (item.commands.isEmpty()) { return new ArrayList<>(); } @@ -1475,7 +1475,7 @@ public class AVM2SourceGenerator implements SourceGenerator { GraphTargetItem lastExpr = cmds.remove(cmds.size() - 1); List ret = new ArrayList<>(); ret.addAll(generate(localData, cmds)); - ret.addAll(lastExpr.toSource(localData, this)); + ret.addAll(withReturnValue ? lastExpr.toSource(localData, this) : lastExpr.toSourceIgnoreReturnValue(localData, this)); return ret; } 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 3243b449b..c5dbea844 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 @@ -1512,7 +1512,7 @@ public class ActionScript3Parser { case WHILE: expectedType(SymbolType.PARENT_OPEN); List whileExpr = new ArrayList<>(); - whileExpr.add(commaExpression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, variables)); + whileExpr.add(expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); expectedType(SymbolType.PARENT_CLOSE); List whileBody = new ArrayList<>(); Loop wloop = new Loop(uniqId(), null, null); @@ -1534,7 +1534,7 @@ public class ActionScript3Parser { expectedType(SymbolType.WHILE); expectedType(SymbolType.PARENT_OPEN); List doExpr = new ArrayList<>(); - doExpr.add(commaExpression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, variables)); + doExpr.add(expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); expectedType(SymbolType.PARENT_CLOSE); ret = new DoWhileItem(null, null, dloop, doBody, doExpr); break; @@ -1892,32 +1892,26 @@ public class ActionScript3Parser { return arrCnt; } - private GraphTargetItem commaExpression(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 { - GraphTargetItem cmd = null; - List expr = new ArrayList<>(); - ParsedSymbol s; - do { - cmd = command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forInLevel, false, variables); - if (cmd != null) { - expr.add(cmd); - } - s = lex(); - } while (s.type == SymbolType.COMMA && cmd != null); - lexer.pushback(s); - if (cmd == null) { - expr.add(expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables)); - } else if (!cmd.hasReturnValue()) { - throw new AVM2ParseException("Expression expected", lexer.yyline()); - } - return new CommaExpressionItem(null, null, expr); - } - 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) throws IOException, AVM2ParseException { - GraphTargetItem prim = expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, allowEmpty, registerVars, inFunction, inMethod, allowRemainder, variables); - if (prim == null) { - return null; + + List commaItems = new ArrayList<>(); + ParsedSymbol symb; + do { + GraphTargetItem prim = expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, allowEmpty, registerVars, inFunction, inMethod, allowRemainder, variables); + if (prim == null) { + return null; + } + GraphTargetItem item = expression1(allOpenedNamespaces, prim, GraphTargetItem.NOPRECEDENCE, thisType, pkg, needsActivation, importedClasses, openedNamespaces, allowEmpty, registerVars, inFunction, inMethod, allowRemainder, variables); + commaItems.add(item); + symb = lex(); + } while (symb != null && symb.type == SymbolType.COMMA); + if (symb != null) { + lexer.pushback(symb); } - return expression1(allOpenedNamespaces, prim, GraphTargetItem.NOPRECEDENCE, thisType, pkg, needsActivation, importedClasses, openedNamespaces, allowEmpty, registerVars, inFunction, inMethod, allowRemainder, variables); + if (commaItems.size() == 1) { + return commaItems.get(0); + } + return new CommaExpressionItem(null, null, commaItems); } /** 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 0d11d275e..fd3303a72 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 @@ -1065,7 +1065,7 @@ public class ActionScript2Parser { case WHILE: expectedType(SymbolType.PARENT_OPEN); List whileExpr = new ArrayList<>(); - whileExpr.add(commaExpression(inFunction, inMethod, forinlevel, variables, functions)); + whileExpr.add(expression(inFunction, inMethod, true, variables, functions)); expectedType(SymbolType.PARENT_CLOSE); List whileBody = new ArrayList<>(); whileBody.add(command(inFunction, inMethod, forinlevel, true, variables, functions)); @@ -1077,7 +1077,7 @@ public class ActionScript2Parser { expectedType(SymbolType.WHILE); expectedType(SymbolType.PARENT_OPEN); List doExpr = new ArrayList<>(); - doExpr.add(commaExpression(inFunction, inMethod, forinlevel, variables, functions)); + doExpr.add(expression(inFunction, inMethod, true, variables, functions)); expectedType(SymbolType.PARENT_CLOSE); ret = new DoWhileItem(null, null, null, doBody, doExpr); break; @@ -1314,15 +1314,27 @@ public class ActionScript2Parser { if (debugMode) { System.out.println("expression:"); } - GraphTargetItem prim = expressionPrimary(false, inFunction, inMethod, allowRemainder, variables, functions); - if (prim == null) { - return null; + List commaItems = new ArrayList<>(); + ParsedSymbol symb; + do { + GraphTargetItem prim = expressionPrimary(false, inFunction, inMethod, allowRemainder, variables, functions); + if (prim == null) { + return null; + } + GraphTargetItem expr = expression1(prim, GraphTargetItem.NOPRECEDENCE, inFunction, inMethod, allowRemainder, variables, functions); + commaItems.add(expr); + symb = lex(); + } while (symb != null && symb.type == SymbolType.COMMA); + if (symb != null) { + lexer.pushback(symb); } - GraphTargetItem ret = expression1(prim, GraphTargetItem.NOPRECEDENCE, inFunction, inMethod, allowRemainder, variables, functions); if (debugMode) { System.out.println("/expression"); } - return ret; + if (commaItems.size() == 1) { + return commaItems.get(0); + } + return new CommaExpressionItem(null, null, commaItems); } private ParsedSymbol peekLex() throws IOException, ActionParseException { @@ -1627,26 +1639,6 @@ public class ActionScript2Parser { return arrCnt; } - private GraphTargetItem commaExpression(boolean inFunction, boolean inMethod, int forInLevel, List variables, List functions) throws IOException, ActionParseException { - GraphTargetItem cmd = null; - List expr = new ArrayList<>(); - ParsedSymbol s; - do { - cmd = command(inFunction, inMethod, forInLevel, false, variables, functions); - if (cmd != null) { - expr.add(cmd); - } - s = lex(); - } while (s.type == SymbolType.COMMA && cmd != null); - lexer.pushback(s); - if (cmd == null) { - expr.add(expression(inFunction, inMethod, true, variables, functions)); - } else if (!cmd.hasReturnValue()) { - throw new ActionParseException("Expression expected", lexer.yyline()); - } - return new CommaExpressionItem(null, null, expr); - } - private GraphTargetItem expressionPrimary(boolean allowEmpty, boolean inFunction, boolean inMethod, boolean allowRemainder, List variables, List functions) throws IOException, ActionParseException { if (debugMode) { System.out.println("primary:"); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionSourceGenerator.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionSourceGenerator.java index 588d138e9..4f817a193 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionSourceGenerator.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionSourceGenerator.java @@ -792,7 +792,7 @@ public class ActionSourceGenerator implements SourceGenerator { } @Override - public List generate(SourceGeneratorLocalData localData, CommaExpressionItem item) throws CompilationException { + public List generate(SourceGeneratorLocalData localData, CommaExpressionItem item, boolean withReturnValue) throws CompilationException { if (item.commands.isEmpty()) { return new ArrayList<>(); } @@ -802,7 +802,7 @@ public class ActionSourceGenerator implements SourceGenerator { GraphTargetItem lastExpr = cmds.remove(cmds.size() - 1); List ret = new ArrayList<>(); ret.addAll(generate(localData, cmds)); - ret.addAll(lastExpr.toSource(localData, this)); + ret.addAll(withReturnValue ? lastExpr.toSource(localData, this) : lastExpr.toSourceIgnoreReturnValue(localData, this)); return ret; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/SourceGenerator.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/SourceGenerator.java index 771c696f2..d1cbc9268 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/SourceGenerator.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/SourceGenerator.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.graph; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; @@ -75,7 +76,7 @@ public interface SourceGenerator { public List generate(SourceGeneratorLocalData localData, List commands) throws CompilationException; - public List generate(SourceGeneratorLocalData localData, CommaExpressionItem item) throws CompilationException; + public List generate(SourceGeneratorLocalData localData, CommaExpressionItem item, boolean withReturnValue) throws CompilationException; public List generate(SourceGeneratorLocalData localData, TypeItem item) throws CompilationException; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/CommaExpressionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/CommaExpressionItem.java index 424201fcc..43c9d9fc4 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/CommaExpressionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/CommaExpressionItem.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.graph.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; @@ -58,9 +59,15 @@ public class CommaExpressionItem extends GraphTargetItem { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { - return generator.generate(localData, this); + return generator.generate(localData, this, true); } + @Override + public List toSourceIgnoreReturnValue(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { + return generator.generate(localData, this, false); + } + + @Override public boolean hasReturnValue() { return false;