correct continue in if handling,

move continue down if possible (invert expression of if when needed)
This commit is contained in:
Jindra Petřík
2021-01-29 20:14:32 +01:00
parent 81d212011f
commit dbad866812
6 changed files with 115 additions and 100 deletions

View File

@@ -289,6 +289,9 @@ public class Graph {
for (Loop l : loops) {
if (l.phase == 1) {
loopContinues.add(l.loopContinue);
if (l.loopPreContinue != null) {
loopContinues.add(l.loopPreContinue);
}
}
}
@@ -327,6 +330,9 @@ public class Graph {
}
}
if (common) {
if (loopContinues.contains(p)) {
return null;
}
return p;
}
}
@@ -889,12 +895,23 @@ public class Graph {
}
if ((!onTrue.isEmpty()) && (!onFalse.isEmpty())) {
if (onFalse.get(onFalse.size() - 1) instanceof ExitItem) {
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 (i < list.size() - 1) {
if ((list.get(i + 1) instanceof BreakItem) && onFalse.isEmpty()) {
if (!onTrue.isEmpty() && (onTrue.get(onTrue.size() - 1) instanceof ContinueItem)) {
ifi.expression = ifi.expression.invert(null);
list.addAll(i + 2, ifi.onTrue);
ifi.onTrue.clear();
ifi.onTrue.add(list.remove(i + 1));
}
}
}
}
}