Fixed #1840 Proper if..continue..break handling

This commit is contained in:
Jindra Petřík
2022-11-18 18:01:19 +01:00
parent 2b7434d488
commit 792df04427
2 changed files with 49 additions and 7 deletions

View File

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