mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-09 22:54:51 +00:00
Loop detection Fix
This commit is contained in:
@@ -752,7 +752,7 @@ public class Graph {
|
||||
}
|
||||
}
|
||||
}
|
||||
part.level = level;
|
||||
|
||||
if (!visited.contains(part)) {
|
||||
visited.add(part);
|
||||
}
|
||||
@@ -840,11 +840,11 @@ public class Graph {
|
||||
|
||||
private void getLoops(GraphPart part, List<Loop> loops, List<GraphPart> stopPart) {
|
||||
clearLoops(loops);
|
||||
getLoops(part, loops, stopPart, true);
|
||||
getLoops(part, loops, stopPart, true,1);
|
||||
clearLoops(loops);
|
||||
}
|
||||
|
||||
private void getLoops(GraphPart part, List<Loop> loops, List<GraphPart> stopPart, boolean first) {
|
||||
private void getLoops(GraphPart part, List<Loop> loops, List<GraphPart> stopPart, boolean first,int level) {
|
||||
boolean debugMode = false;
|
||||
|
||||
if (stopPart == null) {
|
||||
@@ -853,6 +853,7 @@ public class Graph {
|
||||
if (part == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (debugMode) {
|
||||
System.err.println("getloops: " + part);
|
||||
}
|
||||
@@ -870,6 +871,7 @@ public class Graph {
|
||||
if (lastP1 != null) {
|
||||
if (lastP1.breakCandidates.contains(part)) {
|
||||
lastP1.breakCandidates.add(part);
|
||||
lastP1.breakCandidatesLevels.add(level);
|
||||
return;
|
||||
} else {
|
||||
List<GraphPart> loopContinues2 = new ArrayList<>(loopContinues);
|
||||
@@ -878,6 +880,7 @@ public class Graph {
|
||||
loops2.remove(lastP1);
|
||||
if (!part.leadsTo(code, lastP1.loopContinue, loops2)) {
|
||||
lastP1.breakCandidates.add(part);
|
||||
lastP1.breakCandidatesLevels.add(level);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -892,6 +895,7 @@ public class Graph {
|
||||
if (stopPart.contains(part)) {
|
||||
return;
|
||||
}
|
||||
part.level = level;
|
||||
|
||||
boolean isLoop = part.leadsTo(code, part, loops);
|
||||
Loop currentLoop = null;
|
||||
@@ -909,13 +913,13 @@ public class Graph {
|
||||
stopPart2.add(next);
|
||||
}
|
||||
if (next != part.nextParts.get(0)) {
|
||||
getLoops(part.nextParts.get(0), loops, stopPart2, false);
|
||||
getLoops(part.nextParts.get(0), loops, stopPart2, false,level+1);
|
||||
}
|
||||
if (next != part.nextParts.get(1)) {
|
||||
getLoops(part.nextParts.get(1), loops, stopPart2, false);
|
||||
getLoops(part.nextParts.get(1), loops, stopPart2, false,level+1);
|
||||
}
|
||||
if (next != null) {
|
||||
getLoops(next, loops, stopPart, false);
|
||||
getLoops(next, loops, stopPart, false,level);
|
||||
}
|
||||
}
|
||||
if (part.nextParts.size() > 2) {
|
||||
@@ -936,15 +940,15 @@ public class Graph {
|
||||
}
|
||||
}
|
||||
if (next != p) {
|
||||
getLoops(p, loops, stopPart2, false);
|
||||
getLoops(p, loops, stopPart2, false,level+1);
|
||||
}
|
||||
}
|
||||
if (next != null) {
|
||||
getLoops(next, loops, stopPart, false);
|
||||
getLoops(next, loops, stopPart, false,level);
|
||||
}
|
||||
}
|
||||
if (part.nextParts.size() == 1) {
|
||||
getLoops(part.nextParts.get(0), loops, stopPart, false);
|
||||
getLoops(part.nextParts.get(0), loops, stopPart, false,level);
|
||||
}
|
||||
|
||||
|
||||
@@ -958,6 +962,7 @@ public class Graph {
|
||||
}
|
||||
for (int i = currentLoop.breakCandidates.size() - 1; i >= 0; i--) {
|
||||
if (spcheck.contains(currentLoop.breakCandidates.get(i))) {
|
||||
currentLoop.breakCandidatesLevels.remove(i);
|
||||
backupCandidates.add(currentLoop.breakCandidates.remove(i));
|
||||
}
|
||||
}
|
||||
@@ -991,14 +996,36 @@ public class Graph {
|
||||
/*if (cand.path.equals(cand2.path)) {
|
||||
found = cand2;
|
||||
} else {*/
|
||||
found = cand;
|
||||
int lev1=Integer.MAX_VALUE;
|
||||
int lev2=Integer.MAX_VALUE;
|
||||
for(int i=0;i<currentLoop.breakCandidates.size();i++){
|
||||
if(currentLoop.breakCandidates.get(i)==cand){
|
||||
if(currentLoop.breakCandidatesLevels.get(i)<lev1){
|
||||
lev1=currentLoop.breakCandidatesLevels.get(i);
|
||||
}
|
||||
}
|
||||
if(currentLoop.breakCandidates.get(i)==cand2){
|
||||
if(currentLoop.breakCandidatesLevels.get(i)<lev2){
|
||||
lev2=currentLoop.breakCandidatesLevels.get(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(lev1<lev2){
|
||||
found=cand2;
|
||||
}else{
|
||||
found = cand;
|
||||
}
|
||||
//}
|
||||
break loopcand;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found != null) {
|
||||
currentLoop.breakCandidates.remove(found);
|
||||
while(currentLoop.breakCandidates.contains(found)){
|
||||
int ind=currentLoop.breakCandidates.indexOf(found);
|
||||
currentLoop.breakCandidates.remove(ind);
|
||||
currentLoop.breakCandidatesLevels.remove(ind);
|
||||
}
|
||||
removed.add(found);
|
||||
}
|
||||
} while (found != null);
|
||||
@@ -1062,7 +1089,7 @@ public class Graph {
|
||||
}
|
||||
}
|
||||
for (GraphPart r : removed) {
|
||||
getLoops(r, loops, stopPart, false);
|
||||
getLoops(r, loops, stopPart, false,1/*FIXME?*/);
|
||||
}
|
||||
start = false;
|
||||
for (int l = 0; l < loops.size(); l++) {
|
||||
@@ -1075,7 +1102,7 @@ public class Graph {
|
||||
}
|
||||
}
|
||||
//currentLoop.phase = 2;
|
||||
getLoops(currentLoop.loopBreak, loops, stopPart, false);
|
||||
getLoops(currentLoop.loopBreak, loops, stopPart, false,level);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ public class Loop {
|
||||
public GraphPart loopBreak;
|
||||
public GraphPart loopPreContinue;
|
||||
public List<GraphPart> breakCandidates = new ArrayList<>();
|
||||
public List<Integer> breakCandidatesLevels = new ArrayList<>();
|
||||
public long id;
|
||||
public boolean used = false;
|
||||
public boolean finished = false;
|
||||
|
||||
Reference in New Issue
Block a user