From b2c4b437a4e6f6ba33ea625610e4325769d3da27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Fri, 22 Aug 2025 20:05:29 +0200 Subject: [PATCH] tests fix --- .../abc/avm2/graph/AVM2GraphTargetDialect.java | 14 ++++++++++---- .../flash/action/ActionGraphTargetDialect.java | 6 ++++++ .../decompiler/graph/GraphTargetDialect.java | 16 +++++++++++++--- .../decompiler/graph/model/BreakItem.java | 18 ++++++++++++------ 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2GraphTargetDialect.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2GraphTargetDialect.java index cd11cb9f6..ecbbc1dca 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2GraphTargetDialect.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2GraphTargetDialect.java @@ -37,20 +37,21 @@ import java.util.List; /** * AVM2 dialect. + * * @author JPEXS */ public class AVM2GraphTargetDialect extends GraphTargetDialect { public static final GraphTargetDialect INSTANCE = new AVM2GraphTargetDialect(); - + private AVM2GraphTargetDialect() { - + } - + @Override public String getName() { return "AVM2"; - } + } @Override public GraphTargetItem valToItem(Object r) { @@ -101,4 +102,9 @@ public class AVM2GraphTargetDialect extends GraphTargetDialect { } return null; } + + @Override + public boolean doesAllowMultilevelBreaks() { + return true; + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraphTargetDialect.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraphTargetDialect.java index 8fe8edc45..f7a455ac1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraphTargetDialect.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraphTargetDialect.java @@ -32,6 +32,7 @@ import java.util.List; /** * AVM1 dialect. + * * @author JPEXS */ public class ActionGraphTargetDialect extends GraphTargetDialect { @@ -106,4 +107,9 @@ public class ActionGraphTargetDialect extends GraphTargetDialect { } return null; } + + @Override + public boolean doesAllowMultilevelBreaks() { + return false; + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetDialect.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetDialect.java index 689f0cb87..3d0db2942 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetDialect.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetDialect.java @@ -18,21 +18,31 @@ package com.jpexs.decompiler.graph; /** * Dialect - high level language type. + * * @author JPEXS */ public abstract class GraphTargetDialect { /** * Identifier of the dialect. + * * @return Name */ public abstract String getName(); - + /** - * Conversion of ECMA value (that's used in simplifications) - * back to GraphTarget item. + * Conversion of ECMA value (that's used in simplifications) back to + * GraphTarget item. + * * @param value Ecma value * @return GraphTarget item */ public abstract GraphTargetItem valToItem(Object value); + + /** + * Checks whether this dialect allows multi level breaks + * + * @return True when allows + */ + public abstract boolean doesAllowMultilevelBreaks(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/BreakItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/BreakItem.java index c39056f16..034f8fe65 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/BreakItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/BreakItem.java @@ -48,7 +48,7 @@ public class BreakItem extends GraphTargetItem { * Is placed at end of the script (or function) */ public boolean isScriptEnd = false; - + /** * Constructor. * @@ -64,18 +64,24 @@ public class BreakItem extends GraphTargetItem { @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) { - if (isScriptEnd) { - writer.append("return"); - return writer; - } - writer.append("break"); if (writer instanceof NulWriter) { NulWriter nulWriter = (NulWriter) writer; labelRequired = loopId != nulWriter.getLoop(); if (labelRequired) { + if (!dialect.doesAllowMultilevelBreaks() && isScriptEnd) { + writer.append("return"); + return writer; + } nulWriter.setLoopUsed(loopId); } } + if (labelRequired) { + if (!dialect.doesAllowMultilevelBreaks() && isScriptEnd) { + writer.append("return"); + return writer; + } + } + writer.append("break"); if (labelRequired) { writer.append(" loop").append(loopId); }