Separate RemapVisitor and MethodBodyVisitor
This commit is contained in:
@@ -22,31 +22,27 @@ import org.jetbrains.org.objectweb.asm.MethodVisitor
|
|||||||
import org.jetbrains.org.objectweb.asm.TypePath
|
import org.jetbrains.org.objectweb.asm.TypePath
|
||||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||||
|
|
||||||
open class MethodBodyVisitor(mv: MethodVisitor, private val visitAnnotationsAndAttributes: Boolean = false) : InstructionAdapter(API, mv) {
|
open class SkipMaxAndEndVisitor(mv: MethodVisitor) : InstructionAdapter(API, mv) {
|
||||||
|
override fun visitMaxs(maxStack: Int, maxLocals: Int) {}
|
||||||
|
|
||||||
override fun visitParameter(name: String, access: Int) {
|
override fun visitEnd() {}
|
||||||
if (visitAnnotationsAndAttributes) super.visitParameter(name, access)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitAnnotationDefault(): AnnotationVisitor? =
|
open class MethodBodyVisitor(mv: MethodVisitor) : MethodVisitor(API, mv) {
|
||||||
if (visitAnnotationsAndAttributes) super.visitAnnotationDefault() else null
|
|
||||||
|
|
||||||
override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? =
|
override fun visitParameter(name: String, access: Int) {}
|
||||||
if (visitAnnotationsAndAttributes) super.visitAnnotation(desc, visible) else null
|
|
||||||
|
|
||||||
override fun visitTypeAnnotation(typeRef: Int, typePath: TypePath, desc: String, visible: Boolean): AnnotationVisitor? =
|
override fun visitAnnotationDefault(): AnnotationVisitor? = null
|
||||||
if (visitAnnotationsAndAttributes) super.visitTypeAnnotation(typeRef, typePath, desc, visible) else null
|
|
||||||
|
|
||||||
override fun visitParameterAnnotation(parameter: Int, desc: String, visible: Boolean): AnnotationVisitor? =
|
override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? = null
|
||||||
if (visitAnnotationsAndAttributes) super.visitParameterAnnotation(parameter, desc, visible) else null
|
|
||||||
|
|
||||||
override fun visitAttribute(attr: Attribute) {
|
override fun visitTypeAnnotation(typeRef: Int, typePath: TypePath, desc: String, visible: Boolean): AnnotationVisitor? = null
|
||||||
if (visitAnnotationsAndAttributes) super.visitAttribute(attr)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitCode() {
|
override fun visitParameterAnnotation(parameter: Int, desc: String, visible: Boolean): AnnotationVisitor? = null
|
||||||
if (visitAnnotationsAndAttributes) super.visitCode()
|
|
||||||
}
|
override fun visitAttribute(attr: Attribute) {}
|
||||||
|
|
||||||
|
override fun visitCode() {}
|
||||||
|
|
||||||
override fun visitMaxs(maxStack: Int, maxLocals: Int) {}
|
override fun visitMaxs(maxStack: Int, maxLocals: Int) {}
|
||||||
|
|
||||||
|
|||||||
@@ -109,13 +109,16 @@ class MethodInliner(
|
|||||||
API, transformedNode.access, transformedNode.name, transformedNode.desc,
|
API, transformedNode.access, transformedNode.name, transformedNode.desc,
|
||||||
transformedNode.signature, transformedNode.exceptions?.toTypedArray()
|
transformedNode.signature, transformedNode.exceptions?.toTypedArray()
|
||||||
)
|
)
|
||||||
val visitor = RemapVisitor(
|
|
||||||
resultNode, remapper, nodeRemapper,
|
val visitor = RemapVisitor(resultNode, remapper, nodeRemapper)
|
||||||
/*copy annotation and attributes*/
|
|
||||||
isTransformingAnonymousObject
|
|
||||||
)
|
|
||||||
try {
|
try {
|
||||||
transformedNode.accept(visitor)
|
transformedNode.accept(
|
||||||
|
if (isTransformingAnonymousObject) {
|
||||||
|
/*keep annotations and attributes during anonymous object transformations*/
|
||||||
|
visitor
|
||||||
|
} else MethodBodyVisitor(visitor)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
catch (e: Throwable) {
|
catch (e: Throwable) {
|
||||||
throw wrapException(e, transformedNode, "couldn't inline method call")
|
throw wrapException(e, transformedNode, "couldn't inline method call")
|
||||||
@@ -132,7 +135,7 @@ class MethodInliner(
|
|||||||
|
|
||||||
processReturns(resultNode, labelOwner, remapReturn, end)
|
processReturns(resultNode, labelOwner, remapReturn, end)
|
||||||
//flush transformed node to output
|
//flush transformed node to output
|
||||||
resultNode.accept(MethodBodyVisitor(adapter, true))
|
resultNode.accept(SkipMaxAndEndVisitor(adapter))
|
||||||
|
|
||||||
sourceMapper.endMapping()
|
sourceMapper.endMapping()
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import org.jetbrains.org.objectweb.asm.tree.FieldInsnNode;
|
|||||||
|
|
||||||
import static org.jetbrains.kotlin.codegen.inline.InlineCodegenUtilsKt.CAPTURED_FIELD_FOLD_PREFIX;
|
import static org.jetbrains.kotlin.codegen.inline.InlineCodegenUtilsKt.CAPTURED_FIELD_FOLD_PREFIX;
|
||||||
|
|
||||||
public class RemapVisitor extends MethodBodyVisitor {
|
public class RemapVisitor extends SkipMaxAndEndVisitor {
|
||||||
private final LocalVarRemapper remapper;
|
private final LocalVarRemapper remapper;
|
||||||
private final FieldRemapper nodeRemapper;
|
private final FieldRemapper nodeRemapper;
|
||||||
private final InstructionAdapter instructionAdapter;
|
private final InstructionAdapter instructionAdapter;
|
||||||
@@ -34,10 +34,9 @@ public class RemapVisitor extends MethodBodyVisitor {
|
|||||||
public RemapVisitor(
|
public RemapVisitor(
|
||||||
@NotNull MethodVisitor mv,
|
@NotNull MethodVisitor mv,
|
||||||
@NotNull LocalVarRemapper remapper,
|
@NotNull LocalVarRemapper remapper,
|
||||||
@NotNull FieldRemapper nodeRemapper,
|
@NotNull FieldRemapper nodeRemapper
|
||||||
boolean copyAnnotationsAndAttributes
|
|
||||||
) {
|
) {
|
||||||
super(mv, copyAnnotationsAndAttributes);
|
super(mv);
|
||||||
this.instructionAdapter = new InstructionAdapter(mv);
|
this.instructionAdapter = new InstructionAdapter(mv);
|
||||||
this.remapper = remapper;
|
this.remapper = remapper;
|
||||||
this.nodeRemapper = nodeRemapper;
|
this.nodeRemapper = nodeRemapper;
|
||||||
|
|||||||
Reference in New Issue
Block a user