Reuse TransformationMethodVisitor in ABI gen plugin
This commit is contained in:
@@ -33,8 +33,9 @@ abstract class TransformationMethodVisitor(
|
||||
name: String,
|
||||
desc: String,
|
||||
signature: String?,
|
||||
exceptions: Array<String>?
|
||||
) : MethodVisitor(Opcodes.ASM5) {
|
||||
exceptions: Array<out String>?,
|
||||
api: Int = Opcodes.ASM5
|
||||
) : MethodVisitor(api) {
|
||||
|
||||
private val methodNode = MethodNode(access, name, desc, signature, exceptions).apply {
|
||||
localVariables = ArrayList(5)
|
||||
|
||||
@@ -30,9 +30,14 @@ internal class AbiClassBuilder(private val cv: ClassVisitor) : AbstractClassBuil
|
||||
// but non-inline functions can be thrown out
|
||||
if (descriptor is FunctionDescriptor && descriptor.isInline) return mv
|
||||
|
||||
// getArgumentsAndReturnSizes returns `(argSize << 2) | retSize`, where argSize includes `this`
|
||||
val maxLocals = (Type.getArgumentsAndReturnSizes(desc) shr 2) - 1
|
||||
return ReplaceWithEmptyMethodVisitor(maxLocals, mv, AbiExtensionAsmApiVersion)
|
||||
return ReplaceWithEmptyMethodVisitor(
|
||||
delegate = mv,
|
||||
access = access,
|
||||
name = name,
|
||||
desc = desc,
|
||||
signature = signature,
|
||||
exceptions = exceptions
|
||||
)
|
||||
}
|
||||
|
||||
override fun newField(
|
||||
|
||||
+11
-28
@@ -5,36 +5,19 @@
|
||||
|
||||
package org.jetbrains.kotlin.jvm.abi.asm
|
||||
|
||||
import org.jetbrains.kotlin.codegen.TransformationMethodVisitor
|
||||
import org.jetbrains.org.objectweb.asm.*
|
||||
import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
||||
|
||||
internal class ReplaceWithEmptyMethodVisitor(
|
||||
private val newMaxLocals: Int,
|
||||
private val delegate: MethodVisitor,
|
||||
api: Int
|
||||
) : MethodVisitor(api, null) {
|
||||
override fun visitCode() {
|
||||
delegate.visitCode()
|
||||
delegate.visitMaxs(0, newMaxLocals)
|
||||
delegate.visitEnd()
|
||||
}
|
||||
|
||||
override fun visitParameter(name: String?, access: Int) {
|
||||
delegate.visitParameter(name, access)
|
||||
}
|
||||
|
||||
override fun visitParameterAnnotation(parameter: Int, desc: String?, visible: Boolean): AnnotationVisitor =
|
||||
delegate.visitParameterAnnotation(parameter, desc, visible)
|
||||
|
||||
override fun visitAnnotationDefault(): AnnotationVisitor =
|
||||
delegate.visitAnnotationDefault()
|
||||
|
||||
override fun visitAnnotation(desc: String?, visible: Boolean): AnnotationVisitor =
|
||||
delegate.visitAnnotation(desc, visible)
|
||||
|
||||
override fun visitTypeAnnotation(typeRef: Int, typePath: TypePath?, desc: String?, visible: Boolean): AnnotationVisitor =
|
||||
delegate.visitTypeAnnotation(typeRef, typePath, desc, visible)
|
||||
|
||||
override fun visitAttribute(attr: Attribute?) {
|
||||
delegate.visitAttribute(attr)
|
||||
delegate: MethodVisitor,
|
||||
access: Int,
|
||||
name: String,
|
||||
desc: String,
|
||||
signature: String?,
|
||||
exceptions: Array<out String>?
|
||||
) : TransformationMethodVisitor(delegate, access, name, desc, signature, exceptions, api = AbiExtensionAsmApiVersion) {
|
||||
override fun performTransformations(methodNode: MethodNode) {
|
||||
methodNode.instructions.clear()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user