Search in sources :

Example 1 with MethodVisitor

use of dyvilx.tools.asm.MethodVisitor in project Dyvil by Dyvil.

the class AnonymousClassLMF method generateToString.

private void generateToString() {
    MethodVisitor mv = this.cw.visitMethod(Modifiers.PUBLIC, "toString", "()Ljava/lang/String;", null, null);
    mv.visitLdcInsn(this.toString);
    mv.visitInsn(Opcodes.ARETURN);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}
Also used : MethodVisitor(dyvilx.tools.asm.MethodVisitor)

Example 2 with MethodVisitor

use of dyvilx.tools.asm.MethodVisitor in project Dyvil by Dyvil.

the class AnonymousClassLMF method generateConstructor.

private void generateConstructor() {
    // Generate constructor
    MethodVisitor ctor = this.cw.visitMethod(PRIVATE, "<init>", this.constructorType.toMethodDescriptorString(), null, null);
    ctor.visitCode();
    ctor.visitVarInsn(ALOAD, 0);
    ctor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
    int parameterCount = this.parameterCount;
    for (int i = 0, lvIndex = 0; i < parameterCount; i++) {
        ctor.visitVarInsn(ALOAD, 0);
        Class<?> argType = this.invokedType.parameterType(i);
        ctor.visitVarInsn(getLoadOpcode(argType), lvIndex + 1);
        lvIndex += getParameterSize(argType);
        ctor.visitFieldInsn(PUTFIELD, this.lambdaClassName, this.argNames[i], this.argDescs[i]);
    }
    ctor.visitInsn(RETURN);
    // Maxs computed by ClassWriter.COMPUTE_MAXS, these arguments ignored
    ctor.visitMaxs(-1, -1);
    ctor.visitEnd();
}
Also used : MethodVisitor(dyvilx.tools.asm.MethodVisitor)

Example 3 with MethodVisitor

use of dyvilx.tools.asm.MethodVisitor in project Dyvil by Dyvil.

the class PropertyReferenceMetafactory method generateConstructor.

private void generateConstructor(@NonNull ClassWriter classWriter) {
    final MethodVisitor ctor = classWriter.visitMethod(PRIVATE, "<init>", this.constructorType.toMethodDescriptorString(), null, null);
    ctor.visitCode();
    ctor.visitVarInsn(ALOAD, 0);
    ctor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
    if (this.receiverType != null) {
        ctor.visitVarInsn(ALOAD, 0);
        ctor.visitVarInsn(ALOAD, 1);
        ctor.visitFieldInsn(PUTFIELD, this.className, RECEIVER_NAME, this.receiverType);
    }
    ctor.visitInsn(RETURN);
    ctor.visitMaxs(-1, -1);
    ctor.visitEnd();
}
Also used : MethodVisitor(dyvilx.tools.asm.MethodVisitor)

Example 4 with MethodVisitor

use of dyvilx.tools.asm.MethodVisitor in project Dyvil by Dyvil.

the class PropertyReferenceMetafactory method generateSetter.

private void generateSetter(@NonNull ClassWriter classWriter) {
    final MethodType setterType = this.setterInfo.getMethodType();
    final Class<?> setterParamType = setterType.parameterType(0);
    final Class<?> setterReturnType = setterType.returnType();
    MethodVisitor setter = classWriter.visitMethod(PUBLIC, "set", "(" + this.refTargetType + ")V", null, null);
    setter.visitCode();
    this.writeReceiver(setter);
    setter.visitVarInsn(TypeConverter.getLoadOpcode(this.refTargetClass), 1);
    TypeConverter.convertType(setter, this.refTargetClass, setterParamType, setterParamType);
    this.writeMethod(setter, this.setterInfo);
    if (setterReturnType != void.class) {
        if (setterReturnType == long.class || setterReturnType == double.class) {
            setter.visitInsn(Opcodes.POP2);
        } else {
            setter.visitInsn(Opcodes.POP);
        }
    }
    setter.visitInsn(Opcodes.RETURN);
    setter.visitMaxs(-1, -1);
    setter.visitEnd();
}
Also used : MethodVisitor(dyvilx.tools.asm.MethodVisitor)

Example 5 with MethodVisitor

use of dyvilx.tools.asm.MethodVisitor in project Dyvil by Dyvil.

the class AnnotationProxyFactory method generateFactory.

private void generateFactory(@NonNull ClassWriter classWriter) {
    final MethodVisitor factory = classWriter.visitMethod(PRIVATE | STATIC, NAME_FACTORY, this.invokedType.toMethodDescriptorString(), null, null);
    factory.visitCode();
    factory.visitTypeInsn(NEW, this.className);
    factory.visitInsn(Opcodes.DUP);
    for (int typeIndex = 0, localIndex = 0; typeIndex < this.parameterCount; typeIndex++) {
        Class<?> argType = this.invokedType.parameterType(typeIndex);
        factory.visitVarInsn(getLoadOpcode(argType), localIndex);
        localIndex += getParameterSize(argType);
    }
    factory.visitMethodInsn(INVOKESPECIAL, this.className, "<init>", this.constructorType.toMethodDescriptorString(), false);
    factory.visitInsn(ARETURN);
    factory.visitMaxs(-1, -1);
    factory.visitEnd();
}
Also used : MethodVisitor(dyvilx.tools.asm.MethodVisitor)

Aggregations

MethodVisitor (dyvilx.tools.asm.MethodVisitor)15 AnnotationVisitor (dyvilx.tools.asm.AnnotationVisitor)1 IValue (dyvilx.tools.compiler.ast.expression.IValue)1 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)1