Package org.codehaus.groovy.classgen.asm

Examples of org.codehaus.groovy.classgen.asm.WriterController


            return declaringClass;
        }

        @Override
        public void visit(final MethodVisitor mv) {
            final WriterController controller = acg.getController();
            final OperandStack operandStack = controller.getOperandStack();
            final CompileStack compileStack = controller.getCompileStack();

            // create a temporary variable to store the constructed object
            final int tmpObj = compileStack.defineTemporaryVariable("tmpObj", declaringClass, false);
            String classInternalName = BytecodeHelper.getClassInternalName(declaringClass);
            mv.visitTypeInsn(NEW, classInternalName);
View Full Code Here


        @Override
        public void visit(final GroovyCodeVisitor visitor) {
            if (visitor instanceof AsmClassGenerator) {
                AsmClassGenerator acg = (AsmClassGenerator) visitor;
                WriterController controller = acg.getController();
                OperandStack os = controller.getOperandStack();

                if (type.equals(ClassHelper.boolean_TYPE)) {
                    expression.visit(visitor);
                    os.doGroovyCast(ClassHelper.boolean_TYPE);
                    return;
                }
                if (type.equals(ClassHelper.Boolean_TYPE)) {
                    MethodVisitor mv = controller.getMethodVisitor();
                    expression.visit(visitor);
                    Label unbox = new Label();
                    Label exit = new Label();
                    // check for null
                    mv.visitInsn(DUP);
                    mv.visitJumpInsn(IFNONNULL, unbox);
                    mv.visitInsn(POP);
                    mv.visitInsn(ICONST_0);
                    mv.visitJumpInsn(GOTO, exit);
                    mv.visitLabel(unbox);
                    // unbox
                    // GROOVY-6270
                    if (!os.getTopOperand().equals(type)) BytecodeHelper.doCast(mv, type);
                    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
                    mv.visitLabel(exit);
                    os.replace(ClassHelper.boolean_TYPE);
                    return;
                }
                ClassNode top = type;
                if (ClassHelper.isPrimitiveType(top)) {
                    expression.visit(visitor);
                    // in case of null safe invocation, it is possible that what was supposed to be a primitive type
                    // becomes the "null" constant, so we need to recheck
                    top = controller.getOperandStack().getTopOperand();
                    if (ClassHelper.isPrimitiveType(top)) {
                        if (top.equals(ClassHelper.int_TYPE) || top.equals(ClassHelper.byte_TYPE)
                                || top.equals(ClassHelper.short_TYPE) || top.equals(ClassHelper.char_TYPE)) {
                            // int on stack
                        } else if (top.equals(ClassHelper.long_TYPE)) {
                            MethodVisitor mv = controller.getMethodVisitor();
                            mv.visitInsn(L2I);
                            controller.getOperandStack().replace(ClassHelper.boolean_TYPE);
                        } else if (top.equals(ClassHelper.float_TYPE)) {
                            MethodVisitor mv = controller.getMethodVisitor();
                            mv.visitInsn(F2I);
                            controller.getOperandStack().replace(ClassHelper.boolean_TYPE);
                        } else if (top.equals(ClassHelper.double_TYPE)) {
                            MethodVisitor mv = controller.getMethodVisitor();
                            mv.visitInsn(D2I);
                            controller.getOperandStack().replace(ClassHelper.boolean_TYPE);
                        }
                        return;
                    }
                }
                List<MethodNode> asBoolean = findDGMMethodsByNameAndArguments(controller.getSourceUnit().getClassLoader(), top, "asBoolean", ClassNode.EMPTY_ARRAY);
                if (asBoolean.size() == 1) {
                    MethodNode node = asBoolean.get(0);
                    if (node instanceof ExtensionMethodNode) {
                        MethodNode dgmNode = ((ExtensionMethodNode) node).getExtensionMethodNode();
                        ClassNode owner = dgmNode.getParameters()[0].getType();
View Full Code Here

    @Override
    public void visit(final GroovyCodeVisitor visitor) {
        if (visitor instanceof AsmClassGenerator) {
            AsmClassGenerator acg = (AsmClassGenerator) visitor;
            WriterController controller = acg.getController();
            MethodVisitor mv = controller.getMethodVisitor();
            objectExpression.visit(acg);
            ClassNode top = controller.getOperandStack().getTopOperand();
            if (ClassHelper.isPrimitiveType(top)) {
                controller.getOperandStack().pop();
                mv.visitInsn(ICONST_0);
                controller.getOperandStack().push(ClassHelper.boolean_TYPE);
                return;
            }
            Label zero = new Label();
            mv.visitJumpInsn(equalsNull ? IFNONNULL : IFNULL, zero);
            mv.visitInsn(ICONST_1);
            Label end = new Label();
            mv.visitJumpInsn(GOTO, end);
            mv.visitLabel(zero);
            mv.visitInsn(ICONST_0);
            mv.visitLabel(end);
            controller.getOperandStack().replace(ClassHelper.boolean_TYPE);
        } else {
            super.visit(visitor);
        }
    }
View Full Code Here

    // GroovyClassVisitor interface
    //-------------------------------------------------------------------------
    public void visitClass(ClassNode classNode) {
        referencedClasses.clear();
        WriterControllerFactory factory = (WriterControllerFactory) classNode.getNodeMetaData(WriterControllerFactory.class);
        WriterController normalController = new WriterController();
        if (factory!=null) {
            this.controller = factory.makeController(normalController);
        } else {
            this.controller = normalController;
        }
View Full Code Here

    @Override
    public void visit(final GroovyCodeVisitor visitor) {
        if (visitor instanceof AsmClassGenerator) {
            if (variable==null) {
                AsmClassGenerator acg = (AsmClassGenerator) visitor;
                WriterController controller = acg.getController();
                variable = new ExpressionAsVariableSlot(controller, expression);
            }
            variable.visit(visitor);
        } else {
            expression.visit(visitor);
View Full Code Here

    @Override
    public void visit(final GroovyCodeVisitor visitor) {
        if (visitor instanceof AsmClassGenerator) {
            AsmClassGenerator acg = (AsmClassGenerator) visitor;
            WriterController controller = acg.getController();
            ClassNode leftType = controller.getTypeChooser().resolveType(leftExpression, controller.getClassNode());
            ClassNode rightType = controller.getTypeChooser().resolveType(rightExpression, controller.getClassNode());
            if (ClassHelper.isPrimitiveType(leftType) || ClassHelper.isPrimitiveType(rightType)) {
                throw new IllegalArgumentException("Both operands of a CompareIdentityExpression must be objects");
            }
            MethodVisitor mv = controller.getMethodVisitor();
            leftExpression.visit(acg);
            rightExpression.visit(acg);
            Label l1 = new Label();
            mv.visitJumpInsn(IF_ACMPNE, l1);
            mv.visitInsn(ICONST_1);
            Label l2 = new Label();
            mv.visitJumpInsn(GOTO, l2);
            mv.visitLabel(l1);
            mv.visitInsn(ICONST_0);
            mv.visitLabel(l2);
            controller.getOperandStack().replace(ClassHelper.boolean_TYPE, 2);
        } else {
            super.visit(visitor);
        }
    }
View Full Code Here

TOP

Related Classes of org.codehaus.groovy.classgen.asm.WriterController

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.