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