mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-05 13:57:22 +00:00
Fixed - AS3: return in finally
This commit is contained in:
@@ -150,7 +150,6 @@ public class AVM2Graph extends Graph {
|
||||
avm2LocalData.setLocalPosToGetLocalPos = setLocalPosToGetLocalPos;
|
||||
}
|
||||
|
||||
|
||||
public Map<Integer, Set<Integer>> calculateLocalRegsUsage(String path, Set<GraphPart> allParts) {
|
||||
logger.fine("--- " + path + " ---");
|
||||
Map<Integer, Set<Integer>> setLocalPosToGetLocalPos = new TreeMap<>();
|
||||
@@ -253,7 +252,6 @@ public class AVM2Graph extends Graph {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
visited.add(q);
|
||||
|
||||
for (GraphPart r : q.refs) {
|
||||
@@ -609,8 +607,7 @@ public class AVM2Graph extends Graph {
|
||||
ret.addAll(output);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ((part.nextParts.size() == 2) && (!stack.isEmpty()) && (stack.peek() instanceof StrictEqAVM2Item)) {
|
||||
GraphSourceItem switchStartItem = code.get(part.start);
|
||||
|
||||
@@ -634,7 +631,7 @@ public class AVM2Graph extends Graph {
|
||||
int cnt = 1;
|
||||
while (part.nextParts.size() > 1
|
||||
&& part.nextParts.get(1).getHeight() > 1
|
||||
&& ((AVM2Instruction)code.get(part.nextParts.get(1).end >= code.size() ? code.size() - 1 : part.nextParts.get(1).end)).definition instanceof IfStrictEqIns
|
||||
&& ((AVM2Instruction) code.get(part.nextParts.get(1).end >= code.size() ? code.size() - 1 : part.nextParts.get(1).end)).definition instanceof IfStrictEqIns
|
||||
&& ((top = translatePartGetStack(localData, part.nextParts.get(1), stack, staticOperation)) instanceof StrictEqAVM2Item)) {
|
||||
cnt++;
|
||||
part = part.nextParts.get(1);
|
||||
@@ -645,59 +642,49 @@ public class AVM2Graph extends Graph {
|
||||
caseValuesMapRight.add(set.rightSide);
|
||||
}
|
||||
List<GraphTargetItem> caseValuesMap = caseValuesMapLeft;
|
||||
|
||||
|
||||
|
||||
//determine whether local register are on left or on right side of === operator
|
||||
// -1 = there's no register,
|
||||
// -2 = there are mixed registers,
|
||||
// N = there is always register number N
|
||||
int leftReg = -1;
|
||||
int rightReg = -1;
|
||||
for(int cv=0;cv<caseValuesMapLeft.size();cv++){
|
||||
if(caseValuesMapLeft.get(cv) instanceof LocalRegAVM2Item)
|
||||
{
|
||||
int reg = ((LocalRegAVM2Item)caseValuesMapLeft.get(cv)).regIndex;
|
||||
if(leftReg == -1)
|
||||
{
|
||||
for (int cv = 0; cv < caseValuesMapLeft.size(); cv++) {
|
||||
if (caseValuesMapLeft.get(cv) instanceof LocalRegAVM2Item) {
|
||||
int reg = ((LocalRegAVM2Item) caseValuesMapLeft.get(cv)).regIndex;
|
||||
if (leftReg == -1) {
|
||||
leftReg = reg;
|
||||
}else{
|
||||
if(leftReg != reg)
|
||||
{
|
||||
} else {
|
||||
if (leftReg != reg) {
|
||||
leftReg = -2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(caseValuesMapRight.get(cv) instanceof LocalRegAVM2Item)
|
||||
{
|
||||
int reg = ((LocalRegAVM2Item)caseValuesMapRight.get(cv)).regIndex;
|
||||
if(rightReg == -1)
|
||||
{
|
||||
if (caseValuesMapRight.get(cv) instanceof LocalRegAVM2Item) {
|
||||
int reg = ((LocalRegAVM2Item) caseValuesMapRight.get(cv)).regIndex;
|
||||
if (rightReg == -1) {
|
||||
rightReg = reg;
|
||||
}else{
|
||||
if(rightReg != reg)
|
||||
{
|
||||
} else {
|
||||
if (rightReg != reg) {
|
||||
rightReg = -2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(leftReg > 0) {
|
||||
|
||||
if (leftReg > 0) {
|
||||
switchedObject = new LocalRegAVM2Item(null, null, leftReg, null);
|
||||
caseValuesMap = caseValuesMapRight;
|
||||
} else if (rightReg > 0) {
|
||||
switchedObject = new LocalRegAVM2Item(null, null, rightReg, null);
|
||||
}
|
||||
else if(rightReg > 0)
|
||||
{
|
||||
switchedObject = new LocalRegAVM2Item(null, null, rightReg, null);
|
||||
}
|
||||
|
||||
|
||||
if ((leftReg < 0 && rightReg < 0) || (cnt == 1)) {
|
||||
stack.push(set);
|
||||
} else {
|
||||
part = part.nextParts.get(1);
|
||||
GraphPart defaultPart = part;
|
||||
if (code.size() > defaultPart.start && ((AVM2Instruction)code.get(defaultPart.start)).definition instanceof JumpIns) {
|
||||
if (code.size() > defaultPart.start && ((AVM2Instruction) code.get(defaultPart.start)).definition instanceof JumpIns) {
|
||||
defaultPart = defaultPart.nextParts.get(0);
|
||||
}
|
||||
|
||||
@@ -880,12 +867,12 @@ public class AVM2Graph extends Graph {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GraphPart checkPart(TranslateStack stack, BaseLocalData localData, GraphPart next, Set<GraphPart> allParts) {
|
||||
protected GraphPart checkPart(TranslateStack stack, BaseLocalData localData, GraphPart prev, GraphPart next, Set<GraphPart> allParts) {
|
||||
AVM2LocalData aLocalData = (AVM2LocalData) localData;
|
||||
if (aLocalData.finallyJumps == null) {
|
||||
aLocalData.finallyJumps = new HashMap<>();
|
||||
@@ -950,6 +937,16 @@ public class AVM2Graph extends Graph {
|
||||
}
|
||||
}
|
||||
|
||||
if (prev != null) {
|
||||
for (int swip : ignoredSwitches.values()) {
|
||||
if (swip > -1) {
|
||||
if (prev.end == swip) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
@@ -970,7 +967,6 @@ public class AVM2Graph extends Graph {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected GraphTargetItem checkLoop(List<GraphTargetItem> output, LoopItem loopItem, BaseLocalData localData, List<Loop> loops) {
|
||||
AVM2LocalData aLocalData = (AVM2LocalData) localData;
|
||||
@@ -1131,7 +1127,6 @@ public class AVM2Graph extends Graph {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (gti instanceof NextValueAVM2Item) {
|
||||
return new ForEachInAVM2Item(w.getSrc(), w.getLineStartItem(), w.loop, new InAVM2Item(hn.getInstruction(), hn.getLineStartIns(), varName, collection), w.commands);
|
||||
} else if (gti instanceof NextNameAVM2Item) {
|
||||
|
||||
@@ -180,12 +180,12 @@ public class Graph {
|
||||
}
|
||||
}
|
||||
|
||||
private void getReachableParts(GraphPart part, LinkedHashSet<GraphPart> ret, List<Loop> loops, List<GraphPartEdge> gotoParts) {
|
||||
private void getReachableParts(BaseLocalData localData, GraphPart part, LinkedHashSet<GraphPart> ret, List<Loop> loops, List<GraphPartEdge> gotoParts) {
|
||||
// use LinkedHashSet to preserve order
|
||||
getReachableParts(part, ret, loops, true, gotoParts);
|
||||
getReachableParts(localData, part, ret, loops, true, gotoParts);
|
||||
}
|
||||
|
||||
private void getReachableParts(GraphPart part, LinkedHashSet<GraphPart> ret, List<Loop> loops, boolean first, List<GraphPartEdge> gotoParts) {
|
||||
private void getReachableParts(BaseLocalData localData, GraphPart part, LinkedHashSet<GraphPart> ret, List<Loop> loops, boolean first, List<GraphPartEdge> gotoParts) {
|
||||
// todo: honfika: why call with first = true parameter always?
|
||||
Stack<GraphPartQueue> stack = new Stack<>();
|
||||
GraphPartQueue queue = new GraphPartQueue();
|
||||
@@ -239,7 +239,13 @@ public class Graph {
|
||||
|
||||
GraphPartQueue newParts = new GraphPartQueue();
|
||||
loopnext:
|
||||
for (GraphPart next : part.nextParts) {
|
||||
for (GraphPart nextRaw : part.nextParts) {
|
||||
|
||||
GraphPart next = checkPart(null, localData, part, nextRaw, null);
|
||||
if (next == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (gotoParts.contains(new GraphPartEdge(part, next))) {
|
||||
continue;
|
||||
}
|
||||
@@ -314,19 +320,12 @@ public class Graph {
|
||||
List<Set<GraphPart>> reachable = new ArrayList<>();
|
||||
for (GraphPart p : parts) {
|
||||
LinkedHashSet<GraphPart> r1 = new LinkedHashSet<>();
|
||||
getReachableParts(p, r1, loops, gotoParts);
|
||||
getReachableParts(localData, p, r1, loops, gotoParts);
|
||||
r1.add(p);
|
||||
reachable.add(r1);
|
||||
}
|
||||
Set<GraphPart> first = reachable.get(0);
|
||||
for (GraphPart p : first) {
|
||||
/*if (ignored.contains(p)) {
|
||||
continue;
|
||||
}*/
|
||||
p = checkPart(null, localData, p, null);
|
||||
if (p == null) {
|
||||
continue;
|
||||
}
|
||||
boolean common = true;
|
||||
for (Set<GraphPart> r : reachable) {
|
||||
if (!r.contains(p)) {
|
||||
@@ -392,7 +391,7 @@ public class Graph {
|
||||
List<Set<GraphPart>> reachable = new ArrayList<>();
|
||||
for (GraphPart p : parts) {
|
||||
LinkedHashSet<GraphPart> r1 = new LinkedHashSet<>();
|
||||
getReachableParts(p, r1, loops, gotoParts);
|
||||
getReachableParts(localData, p, r1, loops, gotoParts);
|
||||
Set<GraphPart> r2 = new LinkedHashSet<>();
|
||||
r2.add(p);
|
||||
r2.addAll(r1);
|
||||
@@ -1745,7 +1744,7 @@ public class Graph {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected GraphPart checkPart(TranslateStack stack, BaseLocalData localData, GraphPart part, Set<GraphPart> allParts) {
|
||||
protected GraphPart checkPart(TranslateStack stack, BaseLocalData localData, GraphPart prev, GraphPart part, Set<GraphPart> allParts) {
|
||||
return part;
|
||||
}
|
||||
|
||||
@@ -1847,7 +1846,7 @@ public class Graph {
|
||||
return;
|
||||
}
|
||||
|
||||
part = checkPart(null, localData, part, null);
|
||||
part = checkPart(null, localData, null, part, null);
|
||||
if (part == null) {
|
||||
return;
|
||||
}
|
||||
@@ -1984,7 +1983,7 @@ public class Graph {
|
||||
do {
|
||||
found = null;
|
||||
for (int i = 0; i < currentLoop.breakCandidates.size(); i++) {
|
||||
GraphPart ch = checkPart(null, localData, currentLoop.breakCandidates.get(i), null);
|
||||
GraphPart ch = checkPart(null, localData, null, currentLoop.breakCandidates.get(i), null);
|
||||
if (ch == null) {
|
||||
currentLoop.breakCandidates.remove(i);
|
||||
i--;
|
||||
@@ -2150,7 +2149,7 @@ public class Graph {
|
||||
if (part == null) {
|
||||
return ret;
|
||||
}
|
||||
part = checkPart(stack, localData, part, allParts);
|
||||
part = checkPart(stack, localData, parent, part, allParts);
|
||||
if (part == null) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -125,17 +125,17 @@ public class GraphPart implements Serializable {
|
||||
return time;
|
||||
}
|
||||
|
||||
private boolean leadsTo(BaseLocalData localData, Graph gr, GraphSource code, GraphPart part, HashSet<GraphPart> visited, List<Loop> loops) throws InterruptedException {
|
||||
private boolean leadsTo(BaseLocalData localData, Graph gr, GraphSource code, GraphPart prev, GraphPart part, HashSet<GraphPart> visited, List<Loop> loops) throws InterruptedException {
|
||||
if (Thread.currentThread().isInterrupted()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
|
||||
GraphPart tpart = gr.checkPart(null, localData, this, null);
|
||||
GraphPart tpart = gr.checkPart(null, localData, prev, this, null);
|
||||
if (tpart == null) {
|
||||
return false;
|
||||
}
|
||||
if (tpart != this) {
|
||||
return tpart.leadsTo(localData, gr, code, part, visited, loops);
|
||||
return tpart.leadsTo(localData, gr, code, null, part, visited, loops);
|
||||
}
|
||||
Loop currentLoop = null;
|
||||
for (Loop l : loops) {
|
||||
@@ -172,14 +172,14 @@ public class GraphPart implements Serializable {
|
||||
for (GraphPart p : nextParts) {
|
||||
if (p == part) {
|
||||
return true;
|
||||
} else if (p.leadsTo(localData, gr, code, part, visited, loops)) {
|
||||
} else if (p.leadsTo(localData, gr, code, this, part, visited, loops)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (GraphPart p : throwParts) {
|
||||
if (p == part) {
|
||||
return true;
|
||||
} else if (p.leadsTo(localData, gr, code, part, visited, loops)) {
|
||||
} else if (p.leadsTo(localData, gr, code, this, part, visited, loops)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -193,7 +193,7 @@ public class GraphPart implements Serializable {
|
||||
for (Loop l : loops) {
|
||||
l.leadsToMark = 0;
|
||||
}
|
||||
return leadsTo(localData, gr, code, part, new HashSet<>(), loops);
|
||||
return leadsTo(localData, gr, code, null /*???*/, part, new HashSet<>(), loops);
|
||||
}
|
||||
|
||||
public GraphPart(int start, int end) {
|
||||
|
||||
Reference in New Issue
Block a user