Search in sources :

Example 1 with IRETURN

use of org.objectweb.asm.Opcodes.IRETURN in project groovy by apache.

the class RecordTypeASTTransformation method createRecordHashCode.

private void createRecordHashCode(ClassNode cNode) {
    String desc = BytecodeHelper.getMethodDescriptor(ClassHelper.int_TYPE, new ClassNode[] { cNode });
    Statement body = stmt(bytecodeX(ClassHelper.int_TYPE, mv -> {
        mv.visitVarInsn(ALOAD, 0);
        mv.visitInvokeDynamicInsn("hashCode", desc, createBootstrapMethod(), createBootstrapMethodArguments(cNode));
        mv.visitInsn(IRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }));
    addGeneratedMethod(cNode, "hashCode", PUBLIC_FINAL, ClassHelper.int_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, body);
}
Also used : GeneralUtils.stmt(org.codehaus.groovy.ast.tools.GeneralUtils.stmt) RecordComponentNode(org.codehaus.groovy.ast.RecordComponentNode) GeneralUtils.caseS(org.codehaus.groovy.ast.tools.GeneralUtils.caseS) CompilePhase(org.codehaus.groovy.control.CompilePhase) GeneralUtils.params(org.codehaus.groovy.ast.tools.GeneralUtils.params) AnnotatedNode(org.codehaus.groovy.ast.AnnotatedNode) GeneralUtils.classX(org.codehaus.groovy.ast.tools.GeneralUtils.classX) Type(org.objectweb.asm.Type) ACC_ABSTRACT(org.objectweb.asm.Opcodes.ACC_ABSTRACT) GeneralUtils.throwS(org.codehaus.groovy.ast.tools.GeneralUtils.throwS) ClassHelper.make(org.codehaus.groovy.ast.ClassHelper.make) BytecodeHelper(org.codehaus.groovy.classgen.asm.BytecodeHelper) GeneralUtils.propX(org.codehaus.groovy.ast.tools.GeneralUtils.propX) PropertyHandler(groovy.transform.options.PropertyHandler) GeneralUtils.mapEntryX(org.codehaus.groovy.ast.tools.GeneralUtils.mapEntryX) GeneralUtils.ctorX(org.codehaus.groovy.ast.tools.GeneralUtils.ctorX) PropertyNode(org.codehaus.groovy.ast.PropertyNode) LIST_TYPE(org.codehaus.groovy.ast.ClassHelper.LIST_TYPE) GeneralUtils.args(org.codehaus.groovy.ast.tools.GeneralUtils.args) ArgumentListExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression) Collectors(java.util.stream.Collectors) GeneralUtils.callX(org.codehaus.groovy.ast.tools.GeneralUtils.callX) GeneralUtils.plusX(org.codehaus.groovy.ast.tools.GeneralUtils.plusX) InnerClassNode(org.codehaus.groovy.ast.InnerClassNode) List(java.util.List) ClassHelper.makeWithoutCaching(org.codehaus.groovy.ast.ClassHelper.makeWithoutCaching) GeneralUtils.bytecodeX(org.codehaus.groovy.ast.tools.GeneralUtils.bytecodeX) ACC_PUBLIC(org.objectweb.asm.Opcodes.ACC_PUBLIC) Annotation(java.lang.annotation.Annotation) GeneralUtils.hasDeclaredMethod(org.codehaus.groovy.ast.tools.GeneralUtils.hasDeclaredMethod) ClassHelper.getWrapper(org.codehaus.groovy.ast.ClassHelper.getWrapper) ARETURN(org.objectweb.asm.Opcodes.ARETURN) GroovyClassLoader(groovy.lang.GroovyClassLoader) RecordOptions(groovy.transform.RecordOptions) Incubating(org.apache.groovy.lang.annotation.Incubating) ACC_SYNTHETIC(org.objectweb.asm.Opcodes.ACC_SYNTHETIC) Statement(org.codehaus.groovy.ast.stmt.Statement) GeneralUtils.constX(org.codehaus.groovy.ast.tools.GeneralUtils.constX) GeneralUtils.ternaryX(org.codehaus.groovy.ast.tools.GeneralUtils.ternaryX) AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) ClassHelper.int_TYPE(org.codehaus.groovy.ast.ClassHelper.int_TYPE) ACC_FINAL(org.objectweb.asm.Opcodes.ACC_FINAL) ACC_PRIVATE(org.objectweb.asm.Opcodes.ACC_PRIVATE) GeneralUtils.thisPropX(org.codehaus.groovy.ast.tools.GeneralUtils.thisPropX) GeneralUtils.mapX(org.codehaus.groovy.ast.tools.GeneralUtils.mapX) ACC_STATIC(org.objectweb.asm.Opcodes.ACC_STATIC) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) GeneralUtils.switchS(org.codehaus.groovy.ast.tools.GeneralUtils.switchS) GeneralUtils.returnS(org.codehaus.groovy.ast.tools.GeneralUtils.returnS) CompilationUnit(org.codehaus.groovy.control.CompilationUnit) RecordBase(groovy.transform.RecordBase) GeneralUtils.param(org.codehaus.groovy.ast.tools.GeneralUtils.param) ClassNodeUtils.addGeneratedMethod(org.apache.groovy.ast.tools.ClassNodeUtils.addGeneratedMethod) GeneralUtils.getInstanceProperties(org.codehaus.groovy.ast.tools.GeneralUtils.getInstanceProperties) GeneralUtils.varX(org.codehaus.groovy.ast.tools.GeneralUtils.varX) Expression(org.codehaus.groovy.ast.expr.Expression) LinkedList(java.util.LinkedList) Opcodes(org.objectweb.asm.Opcodes) Parameter(org.codehaus.groovy.ast.Parameter) MAP_TYPE(org.codehaus.groovy.ast.ClassHelper.MAP_TYPE) CompilationUnitAware(groovy.transform.CompilationUnitAware) SourceUnit(org.codehaus.groovy.control.SourceUnit) ClassNode(org.codehaus.groovy.ast.ClassNode) ClassHelper(org.codehaus.groovy.ast.ClassHelper) GeneralUtils.listX(org.codehaus.groovy.ast.tools.GeneralUtils.listX) GenericsType(org.codehaus.groovy.ast.GenericsType) MethodNodeUtils(org.apache.groovy.ast.tools.MethodNodeUtils) RecordTypeMode(groovy.transform.RecordTypeMode) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) NamedParam(groovy.transform.NamedParam) GeneralUtils.callThisX(org.codehaus.groovy.ast.tools.GeneralUtils.callThisX) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) SwitchStatement(org.codehaus.groovy.ast.stmt.SwitchStatement) Handle(org.objectweb.asm.Handle) ASTNode(org.codehaus.groovy.ast.ASTNode) FieldNode(org.codehaus.groovy.ast.FieldNode) GenericsUtils(org.codehaus.groovy.ast.tools.GenericsUtils) IRETURN(org.objectweb.asm.Opcodes.IRETURN) MapEntryExpression(org.codehaus.groovy.ast.expr.MapEntryExpression) ALOAD(org.objectweb.asm.Opcodes.ALOAD) Statement(org.codehaus.groovy.ast.stmt.Statement) SwitchStatement(org.codehaus.groovy.ast.stmt.SwitchStatement)

Example 2 with IRETURN

use of org.objectweb.asm.Opcodes.IRETURN in project groovy by apache.

the class RecordTypeASTTransformation method createRecordEquals.

private void createRecordEquals(ClassNode cNode) {
    String desc = BytecodeHelper.getMethodDescriptor(ClassHelper.boolean_TYPE, new ClassNode[] { cNode, ClassHelper.OBJECT_TYPE });
    Statement body = stmt(bytecodeX(ClassHelper.boolean_TYPE, mv -> {
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitInvokeDynamicInsn("equals", desc, createBootstrapMethod(), createBootstrapMethodArguments(cNode));
        mv.visitInsn(IRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }));
    addGeneratedMethod(cNode, "equals", PUBLIC_FINAL, ClassHelper.boolean_TYPE, params(param(ClassHelper.OBJECT_TYPE, "other")), ClassNode.EMPTY_ARRAY, body);
}
Also used : GeneralUtils.stmt(org.codehaus.groovy.ast.tools.GeneralUtils.stmt) RecordComponentNode(org.codehaus.groovy.ast.RecordComponentNode) GeneralUtils.caseS(org.codehaus.groovy.ast.tools.GeneralUtils.caseS) CompilePhase(org.codehaus.groovy.control.CompilePhase) GeneralUtils.params(org.codehaus.groovy.ast.tools.GeneralUtils.params) AnnotatedNode(org.codehaus.groovy.ast.AnnotatedNode) GeneralUtils.classX(org.codehaus.groovy.ast.tools.GeneralUtils.classX) Type(org.objectweb.asm.Type) ACC_ABSTRACT(org.objectweb.asm.Opcodes.ACC_ABSTRACT) GeneralUtils.throwS(org.codehaus.groovy.ast.tools.GeneralUtils.throwS) ClassHelper.make(org.codehaus.groovy.ast.ClassHelper.make) BytecodeHelper(org.codehaus.groovy.classgen.asm.BytecodeHelper) GeneralUtils.propX(org.codehaus.groovy.ast.tools.GeneralUtils.propX) PropertyHandler(groovy.transform.options.PropertyHandler) GeneralUtils.mapEntryX(org.codehaus.groovy.ast.tools.GeneralUtils.mapEntryX) GeneralUtils.ctorX(org.codehaus.groovy.ast.tools.GeneralUtils.ctorX) PropertyNode(org.codehaus.groovy.ast.PropertyNode) LIST_TYPE(org.codehaus.groovy.ast.ClassHelper.LIST_TYPE) GeneralUtils.args(org.codehaus.groovy.ast.tools.GeneralUtils.args) ArgumentListExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression) Collectors(java.util.stream.Collectors) GeneralUtils.callX(org.codehaus.groovy.ast.tools.GeneralUtils.callX) GeneralUtils.plusX(org.codehaus.groovy.ast.tools.GeneralUtils.plusX) InnerClassNode(org.codehaus.groovy.ast.InnerClassNode) List(java.util.List) ClassHelper.makeWithoutCaching(org.codehaus.groovy.ast.ClassHelper.makeWithoutCaching) GeneralUtils.bytecodeX(org.codehaus.groovy.ast.tools.GeneralUtils.bytecodeX) ACC_PUBLIC(org.objectweb.asm.Opcodes.ACC_PUBLIC) Annotation(java.lang.annotation.Annotation) GeneralUtils.hasDeclaredMethod(org.codehaus.groovy.ast.tools.GeneralUtils.hasDeclaredMethod) ClassHelper.getWrapper(org.codehaus.groovy.ast.ClassHelper.getWrapper) ARETURN(org.objectweb.asm.Opcodes.ARETURN) GroovyClassLoader(groovy.lang.GroovyClassLoader) RecordOptions(groovy.transform.RecordOptions) Incubating(org.apache.groovy.lang.annotation.Incubating) ACC_SYNTHETIC(org.objectweb.asm.Opcodes.ACC_SYNTHETIC) Statement(org.codehaus.groovy.ast.stmt.Statement) GeneralUtils.constX(org.codehaus.groovy.ast.tools.GeneralUtils.constX) GeneralUtils.ternaryX(org.codehaus.groovy.ast.tools.GeneralUtils.ternaryX) AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) ClassHelper.int_TYPE(org.codehaus.groovy.ast.ClassHelper.int_TYPE) ACC_FINAL(org.objectweb.asm.Opcodes.ACC_FINAL) ACC_PRIVATE(org.objectweb.asm.Opcodes.ACC_PRIVATE) GeneralUtils.thisPropX(org.codehaus.groovy.ast.tools.GeneralUtils.thisPropX) GeneralUtils.mapX(org.codehaus.groovy.ast.tools.GeneralUtils.mapX) ACC_STATIC(org.objectweb.asm.Opcodes.ACC_STATIC) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) GeneralUtils.switchS(org.codehaus.groovy.ast.tools.GeneralUtils.switchS) GeneralUtils.returnS(org.codehaus.groovy.ast.tools.GeneralUtils.returnS) CompilationUnit(org.codehaus.groovy.control.CompilationUnit) RecordBase(groovy.transform.RecordBase) GeneralUtils.param(org.codehaus.groovy.ast.tools.GeneralUtils.param) ClassNodeUtils.addGeneratedMethod(org.apache.groovy.ast.tools.ClassNodeUtils.addGeneratedMethod) GeneralUtils.getInstanceProperties(org.codehaus.groovy.ast.tools.GeneralUtils.getInstanceProperties) GeneralUtils.varX(org.codehaus.groovy.ast.tools.GeneralUtils.varX) Expression(org.codehaus.groovy.ast.expr.Expression) LinkedList(java.util.LinkedList) Opcodes(org.objectweb.asm.Opcodes) Parameter(org.codehaus.groovy.ast.Parameter) MAP_TYPE(org.codehaus.groovy.ast.ClassHelper.MAP_TYPE) CompilationUnitAware(groovy.transform.CompilationUnitAware) SourceUnit(org.codehaus.groovy.control.SourceUnit) ClassNode(org.codehaus.groovy.ast.ClassNode) ClassHelper(org.codehaus.groovy.ast.ClassHelper) GeneralUtils.listX(org.codehaus.groovy.ast.tools.GeneralUtils.listX) GenericsType(org.codehaus.groovy.ast.GenericsType) MethodNodeUtils(org.apache.groovy.ast.tools.MethodNodeUtils) RecordTypeMode(groovy.transform.RecordTypeMode) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) NamedParam(groovy.transform.NamedParam) GeneralUtils.callThisX(org.codehaus.groovy.ast.tools.GeneralUtils.callThisX) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) SwitchStatement(org.codehaus.groovy.ast.stmt.SwitchStatement) Handle(org.objectweb.asm.Handle) ASTNode(org.codehaus.groovy.ast.ASTNode) FieldNode(org.codehaus.groovy.ast.FieldNode) GenericsUtils(org.codehaus.groovy.ast.tools.GenericsUtils) IRETURN(org.objectweb.asm.Opcodes.IRETURN) MapEntryExpression(org.codehaus.groovy.ast.expr.MapEntryExpression) ALOAD(org.objectweb.asm.Opcodes.ALOAD) Statement(org.codehaus.groovy.ast.stmt.Statement) SwitchStatement(org.codehaus.groovy.ast.stmt.SwitchStatement)

Aggregations

GroovyClassLoader (groovy.lang.GroovyClassLoader)2 CompilationUnitAware (groovy.transform.CompilationUnitAware)2 NamedParam (groovy.transform.NamedParam)2 RecordBase (groovy.transform.RecordBase)2 RecordOptions (groovy.transform.RecordOptions)2 RecordTypeMode (groovy.transform.RecordTypeMode)2 PropertyHandler (groovy.transform.options.PropertyHandler)2 Annotation (java.lang.annotation.Annotation)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ClassNodeUtils.addGeneratedMethod (org.apache.groovy.ast.tools.ClassNodeUtils.addGeneratedMethod)2 MethodNodeUtils (org.apache.groovy.ast.tools.MethodNodeUtils)2 Incubating (org.apache.groovy.lang.annotation.Incubating)2 ASTNode (org.codehaus.groovy.ast.ASTNode)2 AnnotatedNode (org.codehaus.groovy.ast.AnnotatedNode)2 AnnotationNode (org.codehaus.groovy.ast.AnnotationNode)2 ClassHelper (org.codehaus.groovy.ast.ClassHelper)2