Fix error in transforming classes if missing items found

This commit is contained in:
Alexey Andreev 2015-01-22 14:25:40 +04:00
parent 7d2e323af0
commit 67677494b3
3 changed files with 15 additions and 3 deletions

View File

@ -21,6 +21,7 @@ import org.teavm.dependency.DependencyInfo;
import org.teavm.diagnostics.Diagnostics;
import org.teavm.model.*;
import org.teavm.model.instructions.*;
import org.teavm.optimization.UnreachableBasicBlockEliminator;
/**
*
@ -61,6 +62,7 @@ public class MissingItemsProcessor {
}
}
}
new UnreachableBasicBlockEliminator().optimize(program);
}
private void truncateBlock(BasicBlock block, int index) {

View File

@ -53,6 +53,16 @@ public class UnreachableBasicBlockEliminator {
}
for (int i = 0; i < reachable.length; ++i) {
if (!reachable[i]) {
BasicBlock block = program.basicBlockAt(i);
if (block.getLastInstruction() != null) {
block.getLastInstruction().acceptVisitor(transitionExtractor);
for (BasicBlock successor : transitionExtractor.getTargets()) {
successor.removeIncomingsFrom(block);
}
}
for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) {
tryCatch.getHandler().removeIncomingsFrom(block);
}
program.deleteBasicBlock(i);
}
}

View File

@ -22,12 +22,13 @@ import org.teavm.javascript.ni.Rename;
import org.teavm.javascript.ni.Superclass;
import org.teavm.model.*;
import org.teavm.model.instructions.*;
import org.teavm.model.util.ModelUtils;
/**
*
* @author Alexey Andreev
*/
class ClassRefsRenamer implements InstructionVisitor {
public class ClassRefsRenamer implements InstructionVisitor {
private Mapper<String, String> classNameMapper;
public ClassRefsRenamer(Mapper<String, String> classNameMapper) {
@ -54,8 +55,7 @@ class ClassRefsRenamer implements InstructionVisitor {
renamedCls.addMethod(rename(method));
}
for (FieldHolder field : cls.getFields().toArray(new FieldHolder[0])) {
cls.removeField(field);
renamedCls.addField(field);
renamedCls.addField(ModelUtils.copyField(field));
}
if (cls.getOwnerName() != null) {
renamedCls.setOwnerName(classNameMapper.map(cls.getOwnerName()));