Write line numbers for inlined lambdas
This commit is contained in:
@@ -122,4 +122,8 @@ public class FieldRemapper {
|
||||
CapturedParamInfo field = MethodInliner.findCapturedField(node, this);
|
||||
return field.getRemapValue();
|
||||
}
|
||||
|
||||
public boolean isInsideInliningLambda() {
|
||||
return !isRoot() && parent.isInsideInliningLambda();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,4 +47,9 @@ public class InlinedLambdaRemapper extends FieldRemapper {
|
||||
return parent.findField(fieldInsnNode, captured);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isInsideInliningLambda() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,6 +229,8 @@ public class MethodInliner {
|
||||
node.instructions.resetLabels();
|
||||
MethodNode transformedNode = new MethodNode(node.access, node.name, Type.getMethodDescriptor(returnType, allTypes), node.signature, null) {
|
||||
|
||||
private final boolean keepLineNumbers = nodeRemapper.isInsideInliningLambda();
|
||||
|
||||
@Override
|
||||
public void visitVarInsn(int opcode, int var) {
|
||||
int newIndex;
|
||||
@@ -255,6 +257,13 @@ public class MethodInliner {
|
||||
public void visitMaxs(int maxStack, int maxLocals) {
|
||||
super.visitMaxs(maxStack, maxLocals + capturedParamsSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLineNumber(int line, Label start) {
|
||||
if(keepLineNumbers) {
|
||||
super.visitLineNumber(line, start);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
node.accept(transformedNode);
|
||||
|
||||
@@ -33,7 +33,13 @@ public class RemapVisitor extends InstructionAdapter {
|
||||
private final boolean remapReturn;
|
||||
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);
|
||||
this.end = end;
|
||||
this.remapper = remapper;
|
||||
@@ -106,9 +112,4 @@ public class RemapVisitor extends InstructionAdapter {
|
||||
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();
|
||||
}
|
||||
|
||||
public void testInlineSimpleCall() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testCompileTimeConstant() {
|
||||
doTestCustom();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user