From 792df044271d2e9e77594d8ad61d93bbf5fad20d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Fri, 18 Nov 2022 18:01:19 +0100 Subject: [PATCH] Fixed #1840 Proper if..continue..break handling --- CHANGELOG.md | 1 + .../src/com/jpexs/decompiler/graph/Graph.java | 55 ++++++++++++++++--- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64521e6b3..803f7eb23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ All notable changes to this project will be documented in this file. - [#1807] Proper parenthesis around call inside another call - [#1840] AS3 - Allow to compile object literal keys with nonstring/numbers in obfuscated code - [#1840] AS3 Direct editation - Type mismatched for a trait +- [#1840] Proper if..continue..break handling ### Changed - GFX - DefineExternalImage2 no longer handled as character diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java index 2fa737481..7194b388a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java @@ -1113,6 +1113,53 @@ public class Graph { } + /* + if (xx) { + A; + continue + } else { + B; + break/exit/continue; + } + + => + + if (xx) { + A; + } else { + B; + break/exit/continue; + } + continue; + + */ + + if ((!onTrue.isEmpty()) && (!onFalse.isEmpty())) { + if ((onFalse.get(onFalse.size() - 1) instanceof ExitItem) || (onFalse.get(onFalse.size() - 1) instanceof BreakItem)) { + if (onTrue.get(onTrue.size() - 1) instanceof ContinueItem) { + list.add(i + 1, onTrue.remove(onTrue.size() - 1)); + } + } + } + + + /* + if (xx) { + A; + break/exit/continue; + } else { + B; + } + + => + + if (xx) { + A; + break/exit/continue; + } + B; + + */ if ((!onTrue.isEmpty()) && (!onFalse.isEmpty())) { GraphTargetItem last = onTrue.get(onTrue.size() - 1); if ((last instanceof ExitItem) || (last instanceof ContinueItem) || (last instanceof BreakItem)) { @@ -1121,13 +1168,7 @@ public class Graph { } } - if ((!onTrue.isEmpty()) && (!onFalse.isEmpty())) { - if ((onFalse.get(onFalse.size() - 1) instanceof ExitItem) || (onFalse.get(onFalse.size() - 1) instanceof BreakItem)) { - if (onTrue.get(onTrue.size() - 1) instanceof ContinueItem) { - list.add(i + 1, onTrue.remove(onTrue.size() - 1)); - } - } - } + //Prefer continue/return/throw/break in onTrue rather than onFalse if (!onFalse.isEmpty()