From 2b34d9073829b0cd4b3c5ad391143d0287a6476b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sat, 20 Apr 2013 18:13:02 +0200 Subject: [PATCH] AS1/2 parser fix... expressions --- .../src/com/jpexs/decompiler/flash/Main.java | 2 +- .../parser/script/ActionScriptParser.java | 269 ++++++++++-------- .../action/treemodel/AsciiToCharTreeItem.java | 2 +- .../action/treemodel/CharToAsciiTreeItem.java | 2 +- 4 files changed, 147 insertions(+), 128 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/Main.java b/trunk/src/com/jpexs/decompiler/flash/Main.java index 57f66f2ec..07dd168f5 100644 --- a/trunk/src/com/jpexs/decompiler/flash/Main.java +++ b/trunk/src/com/jpexs/decompiler/flash/Main.java @@ -644,7 +644,7 @@ public class Main { } if (SystemTray.isSupported()) { SystemTray tray = SystemTray.getSystemTray(); - trayIcon = new TrayIcon(View.loadImage("proxy16"), vendor+" "+shortApplicationName+" Proxy"); + trayIcon = new TrayIcon(View.loadImage("proxy16"), vendor + " " + shortApplicationName + " Proxy"); trayIcon.setImageAutoSize(true); PopupMenu trayPopup = new PopupMenu(); diff --git a/trunk/src/com/jpexs/decompiler/flash/action/parser/script/ActionScriptParser.java b/trunk/src/com/jpexs/decompiler/flash/action/parser/script/ActionScriptParser.java index 8574ac323..a78ff9cae 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/parser/script/ActionScriptParser.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/parser/script/ActionScriptParser.java @@ -647,6 +647,117 @@ public class ActionScriptParser { return ret; } + private List expressionCommands(ParsedSymbol s, HashMap registerVars, boolean inFunction, boolean inMethod, int forinlevel) throws IOException, ParseException { + List ret = new ArrayList(); + switch (s.type) { + case MBORD: + expected(SymbolType.PARENT_OPEN); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); + expected(SymbolType.PARENT_CLOSE); + ret.add(new ActionMBCharToAscii()); + break; + case MBCHR: + expected(SymbolType.PARENT_OPEN); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); + expected(SymbolType.PARENT_CLOSE); + ret.add(new ActionMBAsciiToChar()); + break; + case MBLENGTH: + expected(SymbolType.PARENT_OPEN); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); + expected(SymbolType.PARENT_CLOSE); + ret.add(new ActionMBStringLength()); + break; + case MBSUBSTRING: + expected(SymbolType.PARENT_OPEN); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); + expected(SymbolType.COMMA); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); + expected(SymbolType.COMMA); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); + expected(SymbolType.PARENT_CLOSE); + ret.add(new ActionMBStringExtract()); + break; + case SUBSTR: + expected(SymbolType.PARENT_OPEN); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); + expected(SymbolType.COMMA); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); + expected(SymbolType.COMMA); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); + expected(SymbolType.PARENT_CLOSE); + ret.add(new ActionStringExtract()); + break; + case LENGTH: + expected(SymbolType.PARENT_OPEN); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); + expected(SymbolType.PARENT_CLOSE); + ret.add(new ActionStringLength()); + break; + case RANDOM: + expected(SymbolType.PARENT_OPEN); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); + expected(SymbolType.PARENT_CLOSE); + ret.add(new ActionRandomNumber()); + break; + case INT: + expected(SymbolType.PARENT_OPEN); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); + expected(SymbolType.PARENT_CLOSE); + ret.add(new ActionToInteger()); + break; + + case TARGETPATH: + expected(SymbolType.PARENT_OPEN); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); + expected(SymbolType.PARENT_CLOSE); + ret.add(new ActionTargetPath()); + break; + case NUMBER_OP: + expected(SymbolType.PARENT_OPEN); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); + expected(SymbolType.PARENT_CLOSE); + ret.add(new ActionToNumber()); + break; + case STRING_OP: + expected(SymbolType.PARENT_OPEN); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); + expected(SymbolType.PARENT_CLOSE); + ret.add(new ActionToString()); + break; + case ORD: + expected(SymbolType.PARENT_OPEN); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); + expected(SymbolType.PARENT_CLOSE); + ret.add(new ActionCharToAscii()); + break; + case CHR: + expected(SymbolType.PARENT_OPEN); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); + expected(SymbolType.PARENT_CLOSE); + ret.add(new ActionAsciiToChar()); + break; + case DUPLICATEMOVIECLIP: + expected(SymbolType.PARENT_OPEN); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); + expected(SymbolType.COMMA); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); + expected(SymbolType.COMMA); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); + expected(SymbolType.PARENT_CLOSE); + ret.add(new ActionCloneSprite()); + break; + case GETTIMER: + expected(SymbolType.PARENT_OPEN); + expected(SymbolType.PARENT_CLOSE); + ret.add(new ActionGetTime()); + break; + default: + return null; + } + return ret; + } + private List command(HashMap registerVars, boolean inFunction, boolean inMethod, int forinlevel) throws IOException, ParseException { List ret = new ArrayList(); if (debugMode) { @@ -659,18 +770,18 @@ public class ActionScriptParser { switch (s.type) { case TRACE: expected(SymbolType.PARENT_OPEN); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); ret.add(new ActionTrace()); expected(SymbolType.PARENT_CLOSE); break; case GETURL: expected(SymbolType.PARENT_OPEN); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); s = lex(); expected(s, lexer.yyline(), SymbolType.PARENT_CLOSE, SymbolType.COMMA); int getuMethod = 1; if (s.type == SymbolType.COMMA) { - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); s = lex(); if (s.type == SymbolType.COMMA) { s = lex(); @@ -694,11 +805,11 @@ public class ActionScriptParser { break; case GOTOANDSTOP: expected(SymbolType.PARENT_OPEN); - List gtsFrame = expression(registerVars, inFunction, inMethod, inMethod); + List gtsFrame = expression(registerVars, inFunction, inMethod, true); s = lex(); if (s.type == SymbolType.COMMA) { s = lex(); - gtsFrame = expression(registerVars, inFunction, inMethod, inMethod); + gtsFrame = expression(registerVars, inFunction, inMethod, true); } else { lexer.pushback(s); } @@ -723,7 +834,7 @@ public class ActionScriptParser { break; case TELLTARGET: expected(SymbolType.PARENT_OPEN); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); expected(SymbolType.PARENT_CLOSE); ret.add(new ActionSetTarget2()); break; @@ -742,47 +853,18 @@ public class ActionScriptParser { expected(SymbolType.PARENT_CLOSE); ret.add(new ActionToggleQuality()); break; - case ORD: - expected(SymbolType.PARENT_OPEN); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); - expected(SymbolType.PARENT_CLOSE); - ret.add(new ActionCharToAscii()); - ret.add(new ActionPop()); - break; - case CHR: - expected(SymbolType.PARENT_OPEN); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); - expected(SymbolType.PARENT_CLOSE); - ret.add(new ActionAsciiToChar()); - ret.add(new ActionPop()); - break; - case DUPLICATEMOVIECLIP: - expected(SymbolType.PARENT_OPEN); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); - expected(SymbolType.COMMA); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); - expected(SymbolType.COMMA); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); - expected(SymbolType.PARENT_CLOSE); - ret.add(new ActionCloneSprite()); - ret.add(new ActionPop()); - break; + case STOPDRAG: expected(SymbolType.PARENT_OPEN); expected(SymbolType.PARENT_CLOSE); ret.add(new ActionEndDrag()); break; - case GETTIMER: - expected(SymbolType.PARENT_OPEN); - expected(SymbolType.PARENT_CLOSE); - ret.add(new ActionGetTime()); - ret.add(new ActionPop()); - break; + case LOADVARIABLES: expected(SymbolType.PARENT_OPEN); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); expected(SymbolType.COMMA); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); s = lex(); expected(s, lexer.yyline(), SymbolType.PARENT_CLOSE, SymbolType.COMMA); int lvmethod = 1; @@ -804,7 +886,7 @@ public class ActionScriptParser { break; case LOADMOVIE: expected(SymbolType.PARENT_OPEN); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); s = lex(); expected(s, lexer.yyline(), SymbolType.PARENT_CLOSE, SymbolType.COMMA); int method = 1; @@ -826,11 +908,11 @@ public class ActionScriptParser { break; case GOTOANDPLAY: expected(SymbolType.PARENT_OPEN); - List gtpFrame = expression(registerVars, inFunction, inMethod, inMethod); + List gtpFrame = expression(registerVars, inFunction, inMethod, true); s = lex(); if (s.type == SymbolType.COMMA) { s = lex(); - gtpFrame = expression(registerVars, inFunction, inMethod, inMethod); + gtpFrame = expression(registerVars, inFunction, inMethod, true); } else { lexer.pushback(s); } @@ -838,83 +920,32 @@ public class ActionScriptParser { ret.add(new ActionGotoFrame2(true, false, (int) (long) (Long) s.value)); expected(SymbolType.PARENT_CLOSE); break; - case MBORD: - expected(SymbolType.PARENT_OPEN); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); - expected(SymbolType.PARENT_CLOSE); - ret.add(new ActionMBCharToAscii()); - ret.add(new ActionPop()); - break; - case MBCHR: - expected(SymbolType.PARENT_OPEN); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); - expected(SymbolType.PARENT_CLOSE); - ret.add(new ActionMBAsciiToChar()); - ret.add(new ActionPop()); - break; - case MBLENGTH: - expected(SymbolType.PARENT_OPEN); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); - expected(SymbolType.PARENT_CLOSE); - ret.add(new ActionMBStringLength()); - ret.add(new ActionPop()); - break; - case MBSUBSTRING: - expected(SymbolType.PARENT_OPEN); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); - expected(SymbolType.COMMA); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); - expected(SymbolType.COMMA); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); - expected(SymbolType.PARENT_CLOSE); - ret.add(new ActionMBStringExtract()); - ret.add(new ActionPop()); - break; - case SUBSTR: - expected(SymbolType.PARENT_OPEN); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); - expected(SymbolType.COMMA); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); - expected(SymbolType.COMMA); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); - expected(SymbolType.PARENT_CLOSE); - ret.add(new ActionStringExtract()); - ret.add(new ActionPop()); - break; - /*case LENGTH: - break;*/ - case RANDOM: - expected(SymbolType.PARENT_OPEN); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); - expected(SymbolType.PARENT_CLOSE); - ret.add(new ActionRandomNumber()); - ret.add(new ActionPop()); - break; + case REMOVEMOVIECLIP: expected(SymbolType.PARENT_OPEN); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); expected(SymbolType.PARENT_CLOSE); ret.add(new ActionRemoveSprite()); break; case STARTDRAG: expected(SymbolType.PARENT_OPEN); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); s = lex(); if (s.type == SymbolType.COMMA) { - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); s = lex(); if (s.type == SymbolType.COMMA) { ret.add(new ActionPush(Boolean.TRUE)); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); s = lex(); if (s.type == SymbolType.COMMA) { - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); s = lex(); if (s.type == SymbolType.COMMA) { - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); s = lex(); if (s.type == SymbolType.COMMA) { - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); } else { lexer.pushback(s); ret.add(new ActionPush(new Long(0))); @@ -942,33 +973,10 @@ public class ActionScriptParser { expected(SymbolType.PARENT_CLOSE); ret.add(new ActionStartDrag()); break; - case INT: - expected(SymbolType.PARENT_OPEN); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); - expected(SymbolType.PARENT_CLOSE); - ret.add(new ActionToInteger()); - ret.add(new ActionPop()); - break; - case TARGETPATH: - break; - case NUMBER_OP: - expected(SymbolType.PARENT_OPEN); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); - expected(SymbolType.PARENT_CLOSE); - ret.add(new ActionToNumber()); - ret.add(new ActionPop()); - break; - case STRING_OP: - expected(SymbolType.PARENT_OPEN); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); - expected(SymbolType.PARENT_CLOSE); - ret.add(new ActionToString()); - ret.add(new ActionPop()); - break; case IFFRAMELOADED: expected(SymbolType.PARENT_OPEN); - ret.addAll(expression(registerVars, inFunction, inMethod, inMethod)); + ret.addAll(expression(registerVars, inFunction, inMethod, true)); expected(SymbolType.PARENT_CLOSE); expected(SymbolType.CURLY_OPEN); List iflComs = commands(registerVars, inFunction, inMethod, forinlevel); @@ -1543,6 +1551,12 @@ public class ActionScriptParser { ret.add(new ActionThrow()); break; default: + List valcmd = expressionCommands(s, registerVars, inFunction, inMethod, forinlevel); + if (valcmd != null) { + ret.addAll(valcmd); + ret.add(new ActionPop()); + break; + } if (s.type != SymbolType.SEMICOLON) { lexer.pushback(s); } @@ -1937,6 +1951,11 @@ public class ActionScriptParser { } break; default: + List excmd = expressionCommands(s, registerVars, inFunction, inMethod, -1); + if (excmd != null) { + ret.addAll(excmd); + break; + } lexer.pushback(s); } List rem = new ArrayList(); diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/AsciiToCharTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/AsciiToCharTreeItem.java index 7d2079c12..fe7b070b3 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/AsciiToCharTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/AsciiToCharTreeItem.java @@ -31,7 +31,7 @@ public class AsciiToCharTreeItem extends TreeItem { @Override public String toString(ConstantPool constants) { - return hilight("ord(") + value.toString(constants) + hilight(")"); + return hilight("chr(") + value.toString(constants) + hilight(")"); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CharToAsciiTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CharToAsciiTreeItem.java index 97e03a4ae..218e8b9f0 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CharToAsciiTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CharToAsciiTreeItem.java @@ -31,7 +31,7 @@ public class CharToAsciiTreeItem extends TreeItem { @Override public String toString(ConstantPool constants) { - return hilight("chr(") + value.toString(constants) + hilight(")"); + return hilight("ord(") + value.toString(constants) + hilight(")"); } @Override