mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Fix more bugs in try/catch generator
This commit is contained in:
parent
9fac86da7c
commit
45b3805a2d
|
@ -15,13 +15,56 @@
|
||||||
*/
|
*/
|
||||||
package org.teavm.javascript;
|
package org.teavm.javascript;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayDeque;
|
||||||
import org.teavm.common.*;
|
import java.util.ArrayList;
|
||||||
import org.teavm.javascript.ast.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Deque;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import org.teavm.common.Graph;
|
||||||
|
import org.teavm.common.GraphIndexer;
|
||||||
|
import org.teavm.common.Loop;
|
||||||
|
import org.teavm.common.LoopGraph;
|
||||||
|
import org.teavm.common.RangeTree;
|
||||||
|
import org.teavm.javascript.ast.AsyncMethodNode;
|
||||||
|
import org.teavm.javascript.ast.AsyncMethodPart;
|
||||||
|
import org.teavm.javascript.ast.BlockStatement;
|
||||||
|
import org.teavm.javascript.ast.ClassNode;
|
||||||
|
import org.teavm.javascript.ast.FieldNode;
|
||||||
|
import org.teavm.javascript.ast.GotoPartStatement;
|
||||||
|
import org.teavm.javascript.ast.IdentifiedStatement;
|
||||||
|
import org.teavm.javascript.ast.MethodNode;
|
||||||
|
import org.teavm.javascript.ast.NativeMethodNode;
|
||||||
|
import org.teavm.javascript.ast.NodeLocation;
|
||||||
|
import org.teavm.javascript.ast.NodeModifier;
|
||||||
|
import org.teavm.javascript.ast.RegularMethodNode;
|
||||||
|
import org.teavm.javascript.ast.SequentialStatement;
|
||||||
|
import org.teavm.javascript.ast.Statement;
|
||||||
|
import org.teavm.javascript.ast.TryCatchStatement;
|
||||||
|
import org.teavm.javascript.ast.WhileStatement;
|
||||||
import org.teavm.javascript.spi.GeneratedBy;
|
import org.teavm.javascript.spi.GeneratedBy;
|
||||||
import org.teavm.javascript.spi.Generator;
|
import org.teavm.javascript.spi.Generator;
|
||||||
import org.teavm.javascript.spi.InjectedBy;
|
import org.teavm.javascript.spi.InjectedBy;
|
||||||
import org.teavm.model.*;
|
import org.teavm.model.AnnotationHolder;
|
||||||
|
import org.teavm.model.ClassHolder;
|
||||||
|
import org.teavm.model.ClassHolderSource;
|
||||||
|
import org.teavm.model.ElementModifier;
|
||||||
|
import org.teavm.model.FieldHolder;
|
||||||
|
import org.teavm.model.Instruction;
|
||||||
|
import org.teavm.model.InstructionLocation;
|
||||||
|
import org.teavm.model.MethodHolder;
|
||||||
|
import org.teavm.model.MethodReference;
|
||||||
|
import org.teavm.model.Program;
|
||||||
|
import org.teavm.model.TryCatchBlock;
|
||||||
|
import org.teavm.model.ValueType;
|
||||||
|
import org.teavm.model.Variable;
|
||||||
import org.teavm.model.util.AsyncProgramSplitter;
|
import org.teavm.model.util.AsyncProgramSplitter;
|
||||||
import org.teavm.model.util.ProgramUtils;
|
import org.teavm.model.util.ProgramUtils;
|
||||||
|
|
||||||
|
@ -74,6 +117,7 @@ public class Decompiler {
|
||||||
|
|
||||||
static class Block {
|
static class Block {
|
||||||
public Block parent;
|
public Block parent;
|
||||||
|
public int parentOffset;
|
||||||
public final IdentifiedStatement statement;
|
public final IdentifiedStatement statement;
|
||||||
public final List<Statement> body;
|
public final List<Statement> body;
|
||||||
public final int end;
|
public final int end;
|
||||||
|
@ -371,10 +415,13 @@ public class Decompiler {
|
||||||
for (Block newBlock : createBlocks(i)) {
|
for (Block newBlock : createBlocks(i)) {
|
||||||
block.body.add(newBlock.statement);
|
block.body.add(newBlock.statement);
|
||||||
newBlock.parent = block;
|
newBlock.parent = block;
|
||||||
|
newBlock.parentOffset = block.body.size();
|
||||||
stack.push(newBlock);
|
stack.push(newBlock);
|
||||||
block = newBlock;
|
block = newBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateTryCatchBookmarks(generator, generator.currentBlock.getTryCatchBlocks());
|
||||||
|
|
||||||
if (node >= 0) {
|
if (node >= 0) {
|
||||||
generator.statements.clear();
|
generator.statements.clear();
|
||||||
InstructionLocation lastLocation = null;
|
InstructionLocation lastLocation = null;
|
||||||
|
@ -397,7 +444,6 @@ public class Decompiler {
|
||||||
generator.statements.add(stmt);
|
generator.statements.add(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateTryCatchBookmarks(generator, generator.currentBlock.getTryCatchBlocks());
|
|
||||||
block.body.addAll(generator.statements);
|
block.body.addAll(generator.statements);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -424,7 +470,7 @@ public class Decompiler {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (tryCatch.getExceptionVariable() != null && bookmark.exceptionVariable != null &&
|
if (tryCatch.getExceptionVariable() != null && bookmark.exceptionVariable != null &&
|
||||||
tryCatch.getExceptionVariable().getIndex() != bookmark.exceptionVariable.intValue()) {
|
tryCatch.getExceptionVariable().getRegister() != bookmark.exceptionVariable.intValue()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -473,7 +519,7 @@ public class Decompiler {
|
||||||
bookmark.exceptionHandler = tryCatch.getHandler().getIndex();
|
bookmark.exceptionHandler = tryCatch.getHandler().getIndex();
|
||||||
bookmark.exceptionType = tryCatch.getExceptionType();
|
bookmark.exceptionType = tryCatch.getExceptionType();
|
||||||
bookmark.exceptionVariable = tryCatch.getExceptionVariable() != null ?
|
bookmark.exceptionVariable = tryCatch.getExceptionVariable() != null ?
|
||||||
tryCatch.getExceptionVariable().getIndex() : null;
|
tryCatch.getExceptionVariable().getRegister() : null;
|
||||||
bookmark.block.tryCatches.add(bookmark);
|
bookmark.block.tryCatches.add(bookmark);
|
||||||
tryCatchBookmarks.add(bookmark);
|
tryCatchBookmarks.add(bookmark);
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,7 +189,11 @@ public class AsyncProgramSplitter {
|
||||||
copy.createBasicBlock();
|
copy.createBasicBlock();
|
||||||
}
|
}
|
||||||
for (int i = 0; i < program.variableCount(); ++i) {
|
for (int i = 0; i < program.variableCount(); ++i) {
|
||||||
|
Variable var = program.variableAt(i);
|
||||||
copy.createVariable();
|
copy.createVariable();
|
||||||
|
Variable varCopy = copy.variableAt(i);
|
||||||
|
varCopy.setRegister(var.getRegister());
|
||||||
|
varCopy.getDebugNames().addAll(var.getDebugNames());
|
||||||
}
|
}
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user