Write line numbers for inlined lambdas
This commit is contained in:
@@ -122,4 +122,8 @@ public class FieldRemapper {
|
|||||||
CapturedParamInfo field = MethodInliner.findCapturedField(node, this);
|
CapturedParamInfo field = MethodInliner.findCapturedField(node, this);
|
||||||
return field.getRemapValue();
|
return field.getRemapValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isInsideInliningLambda() {
|
||||||
|
return !isRoot() && parent.isInsideInliningLambda();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,4 +47,9 @@ public class InlinedLambdaRemapper extends FieldRemapper {
|
|||||||
return parent.findField(fieldInsnNode, captured);
|
return parent.findField(fieldInsnNode, captured);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isInsideInliningLambda() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -229,6 +229,8 @@ public class MethodInliner {
|
|||||||
node.instructions.resetLabels();
|
node.instructions.resetLabels();
|
||||||
MethodNode transformedNode = new MethodNode(node.access, node.name, Type.getMethodDescriptor(returnType, allTypes), node.signature, null) {
|
MethodNode transformedNode = new MethodNode(node.access, node.name, Type.getMethodDescriptor(returnType, allTypes), node.signature, null) {
|
||||||
|
|
||||||
|
private final boolean keepLineNumbers = nodeRemapper.isInsideInliningLambda();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitVarInsn(int opcode, int var) {
|
public void visitVarInsn(int opcode, int var) {
|
||||||
int newIndex;
|
int newIndex;
|
||||||
@@ -255,6 +257,13 @@ public class MethodInliner {
|
|||||||
public void visitMaxs(int maxStack, int maxLocals) {
|
public void visitMaxs(int maxStack, int maxLocals) {
|
||||||
super.visitMaxs(maxStack, maxLocals + capturedParamsSize);
|
super.visitMaxs(maxStack, maxLocals + capturedParamsSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitLineNumber(int line, Label start) {
|
||||||
|
if(keepLineNumbers) {
|
||||||
|
super.visitLineNumber(line, start);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
node.accept(transformedNode);
|
node.accept(transformedNode);
|
||||||
|
|||||||
@@ -33,7 +33,13 @@ public class RemapVisitor extends InstructionAdapter {
|
|||||||
private final boolean remapReturn;
|
private final boolean remapReturn;
|
||||||
private FieldRemapper nodeRemapper;
|
private FieldRemapper nodeRemapper;
|
||||||
|
|
||||||
protected RemapVisitor(MethodVisitor mv, Label end, VarRemapper.ParamRemapper remapper, boolean remapReturn, FieldRemapper nodeRemapper) {
|
protected RemapVisitor(
|
||||||
|
MethodVisitor mv,
|
||||||
|
Label end,
|
||||||
|
VarRemapper.ParamRemapper remapper,
|
||||||
|
boolean remapReturn,
|
||||||
|
FieldRemapper nodeRemapper
|
||||||
|
) {
|
||||||
super(InlineCodegenUtil.API, mv);
|
super(InlineCodegenUtil.API, mv);
|
||||||
this.end = end;
|
this.end = end;
|
||||||
this.remapper = remapper;
|
this.remapper = remapper;
|
||||||
@@ -106,9 +112,4 @@ public class RemapVisitor extends InstructionAdapter {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO not skip for lambdas
|
|
||||||
@Override
|
|
||||||
public void visitLineNumber(int line, Label start) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
inline fun inlineFun(s: () -> Unit) {
|
||||||
|
s()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
inlineFun ({
|
||||||
|
test.lineNumber()
|
||||||
|
})
|
||||||
|
|
||||||
|
inlineFun {
|
||||||
|
test.lineNumber()
|
||||||
|
}
|
||||||
|
|
||||||
|
inlineFun {
|
||||||
|
test.lineNumber()
|
||||||
|
|
||||||
|
inlineFun {
|
||||||
|
test.lineNumber()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -293,6 +293,10 @@ public class LineNumberTest extends TestCaseWithTmpdir {
|
|||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testInlineSimpleCall() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
public void testCompileTimeConstant() {
|
public void testCompileTimeConstant() {
|
||||||
doTestCustom();
|
doTestCustom();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user