decompiler: line mapping for break and continue

master
Egor.Ushakov 10 years ago
parent ce31439c20
commit 9ec79b5701
  1. 12
      src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java
  2. 5
      testData/results/TestClassLoop.dec
  3. 11
      testData/results/TestClassTypes.dec

@ -768,6 +768,16 @@ public class ExprProcessor implements CodeConstants {
.isClassDef()));
}
private static void addDeletedGotoInstructionMapping(Statement stat, BytecodeMappingTracer tracer) {
if (stat instanceof BasicBlockStatement) {
BasicBlock block = ((BasicBlockStatement)stat).getBlock();
List<Integer> offsets = block.getInstrOldOffsets();
if (!offsets.isEmpty() && offsets.size() > block.getSeq().length()) { // some instructions have been deleted, but we still have offsets
tracer.addMapping(offsets.get(offsets.size() - 1)); // add the last offset
}
}
}
public static TextBuffer jmpWrapper(Statement stat, int indent, boolean semicolon, BytecodeMappingTracer tracer) {
TextBuffer buf = stat.toJava(indent, tracer);
@ -779,9 +789,11 @@ public class ExprProcessor implements CodeConstants {
switch (edge.getType()) {
case StatEdge.TYPE_BREAK:
addDeletedGotoInstructionMapping(stat, tracer);
buf.append("break");
break;
case StatEdge.TYPE_CONTINUE:
addDeletedGotoInstructionMapping(stat, tracer);
buf.append("continue");
}

@ -32,7 +32,7 @@ public class TestClassLoop {
} finally {
if(var0) {// 52
System.out.println("3");// 53
continue;
continue;// 54
}
}
}
@ -72,6 +72,7 @@ class 'pkg/TestClassLoop' {
2a 33
2d 33
2f 33
32 34
37 39
3a 39
3c 39
@ -88,7 +89,7 @@ Lines mapping:
49 <-> 30
52 <-> 33
53 <-> 34
54 <-> 35
58 <-> 40
Not mapped:
39
54

@ -27,10 +27,10 @@ public class TestClassTypes {
switch(var1) {// 46
case 88:
System.out.println("1");// 48
break;
break;// 49
case 656:
System.out.println("2");// 51
break;
break;// 52
case 65201:
case 65489:
System.out.println("3");// 55
@ -87,9 +87,11 @@ class 'pkg/TestClassTypes' {
2c 28
2f 28
31 28
34 29
37 31
3a 31
3c 31
3f 32
42 35
45 35
47 35
@ -122,7 +124,9 @@ Lines mapping:
41 <-> 23
46 <-> 27
48 <-> 29
49 <-> 30
51 <-> 32
52 <-> 33
55 <-> 36
57 <-> 39
61 <-> 42
@ -130,6 +134,3 @@ Lines mapping:
64 <-> 44
67 <-> 47
68 <-> 48
Not mapped:
49
52

Loading…
Cancel
Save