Alexey Andreev 2014-10-12 18:05:31 +04:00
parent 70338531f5
commit 581cae0ef4
6 changed files with 37 additions and 4 deletions

View File

@ -365,4 +365,9 @@ public class StringBuilderTest {
assertEquals(3, sb.lastIndexOf("345"));
assertEquals(-1, sb.lastIndexOf("35"));
}
@Test
public void substringWithUpperBoundAtEndWorks() {
assertEquals("23", "123".substring(1, 3));
}
}

View File

@ -67,4 +67,20 @@ public class VMTest {
// do nothing
}
}
@Test
public void setsVariableBeforeTryCatch() {
int a = 23;
try {
a = Integer.parseInt("not a number");
} catch (NumberFormatException e) {
// do nothing
}
assertEquals(23, a);
}
@Test
public void surrogateInStringLiteralsWork() {
assertEquals(0xDDC2, "a\uDDC2b".charAt(1));
}
}

View File

@ -245,7 +245,7 @@ public class Decompiler {
if (node >= 0) {
generator.currentBlock = program.basicBlockAt(node);
int tmp = indexer.nodeAt(next);
generator.nextBlock = next < indexer.size() ? program.basicBlockAt(tmp) : null;
generator.nextBlock = tmp >= 0 && next < indexer.size() ? program.basicBlockAt(tmp) : null;
generator.statements.clear();
InstructionLocation lastLocation = null;
NodeLocation nodeLocation = null;

View File

@ -1252,6 +1252,12 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
if (c < ' ') {
sb.append("\\u00").append(Character.forDigit(c / 16, 16))
.append(Character.forDigit(c % 16, 16));
} else if (Character.isLowSurrogate(c) || Character.isHighSurrogate(c)) {
sb.append("\\u")
.append(Character.forDigit(c / 0x1000, 0x10))
.append(Character.forDigit((c / 0x100) % 0x10, 0x10))
.append(Character.forDigit((c / 0x10) % 0x10, 0x10))
.append(Character.forDigit(c % 0x10, 0x10));
} else {
sb.append(c);
}

View File

@ -29,24 +29,6 @@ public final class ProgramUtils {
private ProgramUtils() {
}
public static Graph buildControlFlowGraphWithoutTryCatch(Program program) {
GraphBuilder graphBuilder = new GraphBuilder(program.basicBlockCount());
InstructionTransitionExtractor transitionExtractor = new InstructionTransitionExtractor();
for (int i = 0; i < program.basicBlockCount(); ++i) {
BasicBlock block = program.basicBlockAt(i);
Instruction insn = block.getLastInstruction();
if (insn != null) {
insn.acceptVisitor(transitionExtractor);
if (transitionExtractor.getTargets() != null) {
for (BasicBlock successor : transitionExtractor.getTargets()) {
graphBuilder.addEdge(i, successor.getIndex());
}
}
}
}
return graphBuilder.build();
}
public static Graph buildControlFlowGraph(Program program) {
GraphBuilder graphBuilder = new GraphBuilder(program.basicBlockCount());
InstructionTransitionExtractor transitionExtractor = new InstructionTransitionExtractor();
@ -68,6 +50,30 @@ public final class ProgramUtils {
return graphBuilder.build();
}
public static Graph buildControlFlowGraphWithTryCatch(Program program) {
GraphBuilder graphBuilder = new GraphBuilder(program.basicBlockCount());
InstructionTransitionExtractor transitionExtractor = new InstructionTransitionExtractor();
for (int i = 0; i < program.basicBlockCount(); ++i) {
BasicBlock block = program.basicBlockAt(i);
Instruction insn = block.getLastInstruction();
if (insn != null) {
insn.acceptVisitor(transitionExtractor);
if (transitionExtractor.getTargets() != null) {
for (BasicBlock successor : transitionExtractor.getTargets()) {
graphBuilder.addEdge(i, successor.getIndex());
for (TryCatchBlock succTryCatch : successor.getTryCatchBlocks()) {
graphBuilder.addEdge(i, succTryCatch.getHandler().getIndex());
}
}
}
}
for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) {
graphBuilder.addEdge(i, tryCatch.getHandler().getIndex());
}
}
return graphBuilder.build();
}
public static Map<InstructionLocation, InstructionLocation[]> getLocationCFG(Program program) {
return new LocationGraphBuilder().build(program);
}

View File

@ -49,7 +49,7 @@ public class SSATransformer {
this.variableDebugInfo = variableDebugInfo;
this.arguments = arguments;
variableDebugMap.clear();
cfg = ProgramUtils.buildControlFlowGraphWithoutTryCatch(program);
cfg = ProgramUtils.buildControlFlowGraphWithTryCatch(program);
domTree = GraphUtils.buildDominatorTree(cfg);
domFrontiers = new int[cfg.size()][];
variableMap = new Variable[program.variableCount()];