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