tests fix

This commit is contained in:
Jindra Petřík
2025-08-22 20:05:29 +02:00
parent 4b48b8408a
commit b2c4b437a4
4 changed files with 41 additions and 13 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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();
}

View File

@@ -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);
}