Java Code Examples for org.codehaus.groovy.classgen.BytecodeExpression#visit()

The following examples show how to use org.codehaus.groovy.classgen.BytecodeExpression#visit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StaticTypesUnaryExpressionHelper.java    From groovy with Apache License 2.0 6 votes vote down vote up
@Override
public void writeNotExpression(final NotExpression expression) {
    TypeChooser typeChooser = controller.getTypeChooser();
    Expression subExpression = expression.getExpression();
    ClassNode classNode = controller.getClassNode();
    if (typeChooser.resolveType(subExpression, classNode) == boolean_TYPE) {
        subExpression.visit(controller.getAcg());
        controller.getOperandStack().doGroovyCast(boolean_TYPE);
        BytecodeExpression bytecodeExpression = bytecodeX(mv -> {
            Label ne = new Label();
            mv.visitJumpInsn(IFNE, ne);
            mv.visitInsn(ICONST_1);
            Label out = new Label();
            mv.visitJumpInsn(GOTO, out);
            mv.visitLabel(ne);
            mv.visitInsn(ICONST_0);
            mv.visitLabel(out);
        });
        bytecodeExpression.visit(controller.getAcg());
        controller.getOperandStack().remove(1);
        return;
    }
    super.writeNotExpression(expression);
}
 
Example 2
Source File: StaticTypesUnaryExpressionHelper.java    From groovy with Apache License 2.0 5 votes vote down vote up
@Override
public void writeBitwiseNegate(final BitwiseNegationExpression expression) {
    expression.getExpression().visit(controller.getAcg());
    if (isPrimitiveOnTop()) {
        ClassNode top = getTopOperand();
        if (top == int_TYPE || top == short_TYPE || top == byte_TYPE || top == char_TYPE || top == long_TYPE) {
            BytecodeExpression bytecodeExpression = bytecodeX(mv -> {
                if (long_TYPE == top) {
                    mv.visitLdcInsn(-1);
                    mv.visitInsn(LXOR);
                } else {
                    mv.visitInsn(ICONST_M1);
                    mv.visitInsn(IXOR);
                    if (byte_TYPE == top) {
                        mv.visitInsn(I2B);
                    } else if (char_TYPE == top) {
                        mv.visitInsn(I2C);
                    } else if (short_TYPE == top) {
                        mv.visitInsn(I2S);
                    }
                }
            });
            bytecodeExpression.visit(controller.getAcg());
            controller.getOperandStack().remove(1);
            return;
        }
    }
    super.writeBitwiseNegate(EMPTY_BITWISE_NEGATE);
}
 
Example 3
Source File: StaticTypesUnaryExpressionHelper.java    From groovy with Apache License 2.0 5 votes vote down vote up
@Override
public void writeUnaryMinus(final UnaryMinusExpression expression) {
    expression.getExpression().visit(controller.getAcg());
    if (isPrimitiveOnTop()) {
        ClassNode top = getTopOperand();
        if (top != boolean_TYPE) {
            BytecodeExpression bytecodeExpression = bytecodeX(mv -> {
                if (int_TYPE == top || short_TYPE == top || byte_TYPE == top || char_TYPE == top) {
                    mv.visitInsn(INEG);
                    if (byte_TYPE == top) {
                        mv.visitInsn(I2B);
                    } else if (char_TYPE == top) {
                        mv.visitInsn(I2C);
                    } else if (short_TYPE == top) {
                        mv.visitInsn(I2S);
                    }
                } else if (long_TYPE == top) {
                    mv.visitInsn(LNEG);
                } else if (float_TYPE == top) {
                    mv.visitInsn(FNEG);
                } else if (double_TYPE == top) {
                    mv.visitInsn(DNEG);
                }
            });
            bytecodeExpression.visit(controller.getAcg());
            controller.getOperandStack().remove(1);
            return;
        }
    }
    // we already visited the sub expression
    super.writeUnaryMinus(EMPTY_UNARY_MINUS);
}