Search in sources :

Example 1 with I2B

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

the class StaticTypesUnaryExpressionHelper method writeBitwiseNegate.

@Override
public void writeBitwiseNegate(final BitwiseNegationExpression expression) {
    expression.getExpression().visit(controller.getAcg());
    ClassNode top = controller.getOperandStack().getTopOperand();
    if (isPrimitiveInt(top) || isPrimitiveLong(top) || isPrimitiveShort(top) || isPrimitiveByte(top) || isPrimitiveChar(top)) {
        bytecodeX(mv -> {
            if (isPrimitiveLong(top)) {
                mv.visitLdcInsn(-1L);
                mv.visitInsn(LXOR);
            } else {
                mv.visitInsn(ICONST_M1);
                mv.visitInsn(IXOR);
                if (isPrimitiveByte(top)) {
                    mv.visitInsn(I2B);
                } else if (isPrimitiveChar(top)) {
                    mv.visitInsn(I2C);
                } else if (isPrimitiveShort(top)) {
                    mv.visitInsn(I2S);
                }
            }
        }).visit(controller.getAcg());
        controller.getOperandStack().remove(1);
    } else {
        super.writeBitwiseNegate(EMPTY_BITWISE_NEGATE);
    }
}
Also used : ClassHelper.isPrimitiveDouble(org.codehaus.groovy.ast.ClassHelper.isPrimitiveDouble) WriterController(org.codehaus.groovy.classgen.asm.WriterController) Label(org.objectweb.asm.Label) I2B(org.objectweb.asm.Opcodes.I2B) IFNE(org.objectweb.asm.Opcodes.IFNE) I2C(org.objectweb.asm.Opcodes.I2C) IXOR(org.objectweb.asm.Opcodes.IXOR) ClassHelper.isPrimitiveShort(org.codehaus.groovy.ast.ClassHelper.isPrimitiveShort) ClassHelper.boolean_TYPE(org.codehaus.groovy.ast.ClassHelper.boolean_TYPE) ClassHelper.isPrimitiveFloat(org.codehaus.groovy.ast.ClassHelper.isPrimitiveFloat) EmptyExpression(org.codehaus.groovy.ast.expr.EmptyExpression) Expression(org.codehaus.groovy.ast.expr.Expression) INEG(org.objectweb.asm.Opcodes.INEG) UnaryMinusExpression(org.codehaus.groovy.ast.expr.UnaryMinusExpression) ICONST_1(org.objectweb.asm.Opcodes.ICONST_1) UnaryPlusExpression(org.codehaus.groovy.ast.expr.UnaryPlusExpression) ICONST_0(org.objectweb.asm.Opcodes.ICONST_0) ClassNode(org.codehaus.groovy.ast.ClassNode) ClassHelper.isPrimitiveInt(org.codehaus.groovy.ast.ClassHelper.isPrimitiveInt) ClassHelper.isPrimitiveLong(org.codehaus.groovy.ast.ClassHelper.isPrimitiveLong) ClassHelper.isPrimitiveBoolean(org.codehaus.groovy.ast.ClassHelper.isPrimitiveBoolean) ICONST_M1(org.objectweb.asm.Opcodes.ICONST_M1) NotExpression(org.codehaus.groovy.ast.expr.NotExpression) TypeChooser(org.codehaus.groovy.classgen.asm.TypeChooser) UnaryExpressionHelper(org.codehaus.groovy.classgen.asm.UnaryExpressionHelper) FNEG(org.objectweb.asm.Opcodes.FNEG) BitwiseNegationExpression(org.codehaus.groovy.ast.expr.BitwiseNegationExpression) GeneralUtils.bytecodeX(org.codehaus.groovy.ast.tools.GeneralUtils.bytecodeX) LXOR(org.objectweb.asm.Opcodes.LXOR) ClassHelper.isPrimitiveChar(org.codehaus.groovy.ast.ClassHelper.isPrimitiveChar) ClassHelper.isPrimitiveByte(org.codehaus.groovy.ast.ClassHelper.isPrimitiveByte) LNEG(org.objectweb.asm.Opcodes.LNEG) GOTO(org.objectweb.asm.Opcodes.GOTO) I2S(org.objectweb.asm.Opcodes.I2S) DNEG(org.objectweb.asm.Opcodes.DNEG) ClassNode(org.codehaus.groovy.ast.ClassNode)

Example 2 with I2B

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

the class StaticTypesUnaryExpressionHelper method writeUnaryMinus.

@Override
public void writeUnaryMinus(final UnaryMinusExpression expression) {
    expression.getExpression().visit(controller.getAcg());
    ClassNode top = controller.getOperandStack().getTopOperand();
    if (isPrimitiveInt(top) || isPrimitiveLong(top) || isPrimitiveShort(top) || isPrimitiveFloat(top) || isPrimitiveDouble(top) || isPrimitiveByte(top) || isPrimitiveChar(top)) {
        bytecodeX(mv -> {
            if (isPrimitiveInt(top) || isPrimitiveShort(top) || isPrimitiveByte(top) || isPrimitiveChar(top)) {
                mv.visitInsn(INEG);
                if (isPrimitiveByte(top)) {
                    mv.visitInsn(I2B);
                } else if (isPrimitiveChar(top)) {
                    mv.visitInsn(I2C);
                } else if (isPrimitiveShort(top)) {
                    mv.visitInsn(I2S);
                }
            } else if (isPrimitiveLong(top)) {
                mv.visitInsn(LNEG);
            } else if (isPrimitiveFloat(top)) {
                mv.visitInsn(FNEG);
            } else if (isPrimitiveDouble(top)) {
                mv.visitInsn(DNEG);
            }
        }).visit(controller.getAcg());
        controller.getOperandStack().remove(1);
    } else {
        super.writeUnaryMinus(EMPTY_UNARY_MINUS);
    }
}
Also used : ClassHelper.isPrimitiveDouble(org.codehaus.groovy.ast.ClassHelper.isPrimitiveDouble) WriterController(org.codehaus.groovy.classgen.asm.WriterController) Label(org.objectweb.asm.Label) I2B(org.objectweb.asm.Opcodes.I2B) IFNE(org.objectweb.asm.Opcodes.IFNE) I2C(org.objectweb.asm.Opcodes.I2C) IXOR(org.objectweb.asm.Opcodes.IXOR) ClassHelper.isPrimitiveShort(org.codehaus.groovy.ast.ClassHelper.isPrimitiveShort) ClassHelper.boolean_TYPE(org.codehaus.groovy.ast.ClassHelper.boolean_TYPE) ClassHelper.isPrimitiveFloat(org.codehaus.groovy.ast.ClassHelper.isPrimitiveFloat) EmptyExpression(org.codehaus.groovy.ast.expr.EmptyExpression) Expression(org.codehaus.groovy.ast.expr.Expression) INEG(org.objectweb.asm.Opcodes.INEG) UnaryMinusExpression(org.codehaus.groovy.ast.expr.UnaryMinusExpression) ICONST_1(org.objectweb.asm.Opcodes.ICONST_1) UnaryPlusExpression(org.codehaus.groovy.ast.expr.UnaryPlusExpression) ICONST_0(org.objectweb.asm.Opcodes.ICONST_0) ClassNode(org.codehaus.groovy.ast.ClassNode) ClassHelper.isPrimitiveInt(org.codehaus.groovy.ast.ClassHelper.isPrimitiveInt) ClassHelper.isPrimitiveLong(org.codehaus.groovy.ast.ClassHelper.isPrimitiveLong) ClassHelper.isPrimitiveBoolean(org.codehaus.groovy.ast.ClassHelper.isPrimitiveBoolean) ICONST_M1(org.objectweb.asm.Opcodes.ICONST_M1) NotExpression(org.codehaus.groovy.ast.expr.NotExpression) TypeChooser(org.codehaus.groovy.classgen.asm.TypeChooser) UnaryExpressionHelper(org.codehaus.groovy.classgen.asm.UnaryExpressionHelper) FNEG(org.objectweb.asm.Opcodes.FNEG) BitwiseNegationExpression(org.codehaus.groovy.ast.expr.BitwiseNegationExpression) GeneralUtils.bytecodeX(org.codehaus.groovy.ast.tools.GeneralUtils.bytecodeX) LXOR(org.objectweb.asm.Opcodes.LXOR) ClassHelper.isPrimitiveChar(org.codehaus.groovy.ast.ClassHelper.isPrimitiveChar) ClassHelper.isPrimitiveByte(org.codehaus.groovy.ast.ClassHelper.isPrimitiveByte) LNEG(org.objectweb.asm.Opcodes.LNEG) GOTO(org.objectweb.asm.Opcodes.GOTO) I2S(org.objectweb.asm.Opcodes.I2S) DNEG(org.objectweb.asm.Opcodes.DNEG) ClassNode(org.codehaus.groovy.ast.ClassNode)

Aggregations

ClassHelper.boolean_TYPE (org.codehaus.groovy.ast.ClassHelper.boolean_TYPE)2 ClassHelper.isPrimitiveBoolean (org.codehaus.groovy.ast.ClassHelper.isPrimitiveBoolean)2 ClassHelper.isPrimitiveByte (org.codehaus.groovy.ast.ClassHelper.isPrimitiveByte)2 ClassHelper.isPrimitiveChar (org.codehaus.groovy.ast.ClassHelper.isPrimitiveChar)2 ClassHelper.isPrimitiveDouble (org.codehaus.groovy.ast.ClassHelper.isPrimitiveDouble)2 ClassHelper.isPrimitiveFloat (org.codehaus.groovy.ast.ClassHelper.isPrimitiveFloat)2 ClassHelper.isPrimitiveInt (org.codehaus.groovy.ast.ClassHelper.isPrimitiveInt)2 ClassHelper.isPrimitiveLong (org.codehaus.groovy.ast.ClassHelper.isPrimitiveLong)2 ClassHelper.isPrimitiveShort (org.codehaus.groovy.ast.ClassHelper.isPrimitiveShort)2 ClassNode (org.codehaus.groovy.ast.ClassNode)2 BitwiseNegationExpression (org.codehaus.groovy.ast.expr.BitwiseNegationExpression)2 EmptyExpression (org.codehaus.groovy.ast.expr.EmptyExpression)2 Expression (org.codehaus.groovy.ast.expr.Expression)2 NotExpression (org.codehaus.groovy.ast.expr.NotExpression)2 UnaryMinusExpression (org.codehaus.groovy.ast.expr.UnaryMinusExpression)2 UnaryPlusExpression (org.codehaus.groovy.ast.expr.UnaryPlusExpression)2 GeneralUtils.bytecodeX (org.codehaus.groovy.ast.tools.GeneralUtils.bytecodeX)2 TypeChooser (org.codehaus.groovy.classgen.asm.TypeChooser)2 UnaryExpressionHelper (org.codehaus.groovy.classgen.asm.UnaryExpressionHelper)2 WriterController (org.codehaus.groovy.classgen.asm.WriterController)2