Examples of ByteCodeExpression


Examples of org.codehaus.groovy.classgen.BytecodeExpression

            //rhsType = getCastType(rightExpression);
            rhsType = controller.getOperandStack().getTopOperand();
        }
        int rhsValueId = compileStack.defineTemporaryVariable("$rhs", rhsType, true);
        //TODO: if rhs is VariableSlotLoader already, then skip crating a new one
        BytecodeExpression rhsValueLoader = new VariableSlotLoader(rhsType,rhsValueId,operandStack);
       
        // assignment for subscript
        if (leftExpression instanceof BinaryExpression) {
            BinaryExpression leftBinExpr = (BinaryExpression) leftExpression;
            if (leftBinExpr.getOperation().getType() == Types.LEFT_SQUARE_BRACKET) {
                assignToArray(expression, leftBinExpr.getLeftExpression(), leftBinExpr.getRightExpression(), rhsValueLoader);
            }
            compileStack.removeVar(rhsValueId);
            return;
        }
       
        compileStack.pushLHS(true);

        // multiple declaration
        if (leftExpression instanceof TupleExpression) {
            TupleExpression tuple = (TupleExpression) leftExpression;
            int i = 0;
            for (Expression e : tuple.getExpressions()) {
                VariableExpression var = (VariableExpression) e;
                MethodCallExpression call = new MethodCallExpression(
                        rhsValueLoader, "getAt",
                        new ArgumentListExpression(new ConstantExpression(i)));
                call.visit(acg);
                i++;
                if (defineVariable) {
                    operandStack.doGroovyCast(var);
                    compileStack.defineVariable(var, true);
                    operandStack.remove(1);
                } else {
                    acg.visitVariableExpression(var);
                }
            }
        }
        // single declaration
        else if (defineVariable) {
            VariableExpression var = (VariableExpression) leftExpression;
            rhsValueLoader.visit(acg);
            operandStack.doGroovyCast(var);
            compileStack.defineVariable(var, true);
            operandStack.remove(1);
        }
        // normal assignment
        else {
            int mark = operandStack.getStackLength();
            // to leave a copy of the rightExpression value on the stack after the assignment.
            rhsValueLoader.visit(acg);
            leftExpression.visit(acg);
            operandStack.remove(operandStack.getStackLength()-mark);
        }
        compileStack.popLHS();
       
        // return value of assignment
        rhsValueLoader.visit(acg);
        compileStack.removeVar(rhsValueId);
    }
View Full Code Here

Examples of org.codehaus.groovy.classgen.BytecodeExpression

            CompileStack compileStack = controller.getCompileStack();
            BinaryExpression be = (BinaryExpression) expression;
           
            ClassNode methodResultType = operandStack.getTopOperand();
            final int resultIdx = compileStack.defineTemporaryVariable("postfix_" + method, methodResultType, true);
            BytecodeExpression methodResultLoader = new VariableSlotLoader(methodResultType, resultIdx, operandStack);
           
            // execute the assignment, this will leave the right side
            // (here the method call result) on the stack
            assignToArray(be, be.getLeftExpression(), usesSubscript, methodResultLoader);
View Full Code Here

Examples of org.codehaus.groovy.classgen.BytecodeExpression

        final OperandStack operandStack = controller.getOperandStack();
        // at this point the receiver will be already on the stack.
        // in a[1]++ the method will be "++" aka "next" and the receiver a[1]
       
        ClassNode BEType = BinaryExpressionMultiTypeDispatcher.getType(expression,controller.getClassNode());
        Expression callSiteReceiverSwap = new BytecodeExpression(BEType) {
            @Override
            public void visit(MethodVisitor mv) {
                // CallSite is normally not showing up on the
                // operandStack, so we place a dummy here with same
                // slot length.
View Full Code Here

Examples of org.codehaus.groovy.classgen.BytecodeExpression

            for (MapEntryExpression entryExpression : map.getMapEntryExpressions()) {
                int line = entryExpression.getLineNumber();
                int col = entryExpression.getColumnNumber();
                Expression keyExpression = staticCompilationTransformer.transform(entryExpression.getKeyExpression());
                Expression valueExpression = staticCompilationTransformer.transform(entryExpression.getValueExpression());
                BinaryExpression bexp = new BinaryExpression(new PropertyExpression(new BytecodeExpression() {
                            @Override
                            public void visit(final MethodVisitor mv) {
                                mv.visitVarInsn(ALOAD, tmpObj);
                            }
View Full Code Here

Examples of org.codehaus.groovy.classgen.BytecodeExpression

            rhsValueId = compileStack.defineVariable(var, lhsType, true).getIndex();
        } else {
            rhsValueId = compileStack.defineTemporaryVariable("$rhs", rhsType, true);
        }
        //TODO: if rhs is VariableSlotLoader already, then skip crating a new one
        BytecodeExpression rhsValueLoader = new VariableSlotLoader(rhsType,rhsValueId,operandStack);
       
        // assignment for subscript
        if (leftExpression instanceof BinaryExpression) {
            BinaryExpression leftBinExpr = (BinaryExpression) leftExpression;
            if (leftBinExpr.getOperation().getType() == Types.LEFT_SQUARE_BRACKET) {
                assignToArray(expression, leftBinExpr.getLeftExpression(), leftBinExpr.getRightExpression(), rhsValueLoader);
            }
            compileStack.removeVar(rhsValueId);
            return;
        }
       
        compileStack.pushLHS(true);

        // multiple declaration
        if (leftExpression instanceof TupleExpression) {
            TupleExpression tuple = (TupleExpression) leftExpression;
            int i = 0;
            for (Expression e : tuple.getExpressions()) {
                VariableExpression var = (VariableExpression) e;
                MethodCallExpression call = new MethodCallExpression(
                        rhsValueLoader, "getAt",
                        new ArgumentListExpression(new ConstantExpression(i)));
                call.visit(acg);
                i++;
                if (defineVariable) {
                    operandStack.doGroovyCast(var);
                    compileStack.defineVariable(var, true);
                    operandStack.remove(1);
                } else {
                    acg.visitVariableExpression(var);
                }
            }
        }
        // single declaration
        else if (defineVariable) {
            rhsValueLoader.visit(acg);
            operandStack.remove(1);
            compileStack.popLHS();
            return;
        }
        // normal assignment
        else {
            int mark = operandStack.getStackLength();
            // to leave a copy of the rightExpression value on the stack after the assignment.
            rhsValueLoader.visit(acg);
            TypeChooser typeChooser = controller.getTypeChooser();
            ClassNode targetType = typeChooser.resolveType(leftExpression, controller.getClassNode());
            operandStack.doGroovyCast(targetType);
            leftExpression.visit(acg);
            operandStack.remove(operandStack.getStackLength()-mark);
        }
        compileStack.popLHS();
       
        // return value of assignment
        rhsValueLoader.visit(acg);
        compileStack.removeVar(rhsValueId);
    }
View Full Code Here

Examples of org.codehaus.groovy.classgen.BytecodeExpression

            CompileStack compileStack = controller.getCompileStack();
            BinaryExpression be = (BinaryExpression) expression;
           
            ClassNode methodResultType = operandStack.getTopOperand();
            final int resultIdx = compileStack.defineTemporaryVariable("postfix_" + method, methodResultType, true);
            BytecodeExpression methodResultLoader = new VariableSlotLoader(methodResultType, resultIdx, operandStack);
           
            // execute the assignment, this will leave the right side
            // (here the method call result) on the stack
            assignToArray(be, be.getLeftExpression(), usesSubscript, methodResultLoader);
View Full Code Here

Examples of org.codehaus.groovy.classgen.BytecodeExpression

        final OperandStack operandStack = controller.getOperandStack();
        // at this point the receiver will be already on the stack.
        // in a[1]++ the method will be "++" aka "next" and the receiver a[1]
       
        ClassNode BEType = controller.getTypeChooser().resolveType(expression, controller.getClassNode());
        Expression callSiteReceiverSwap = new BytecodeExpression(BEType) {
            @Override
            public void visit(MethodVisitor mv) {
                // CallSite is normally not showing up on the
                // operandStack, so we place a dummy here with same
                // slot length.
View Full Code Here

Examples of org.codehaus.groovy.classgen.BytecodeExpression

    public void writeBitwiseNegate(final BitwiseNegationExpression expression) {
        expression.getExpression().visit(controller.getAcg());
        if (isPrimitiveOnTop()) {
            final ClassNode top = getTopOperand();
            if (top==int_TYPE || top==short_TYPE || top==byte_TYPE || top==char_TYPE || top==long_TYPE) {
                BytecodeExpression bytecodeExpression = new BytecodeExpression() {
                    @Override
                    public void visit(final MethodVisitor 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);
View Full Code Here

Examples of org.codehaus.groovy.classgen.BytecodeExpression

        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 = new BytecodeExpression() {
                @Override
                public void visit(final MethodVisitor 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);
    }
View Full Code Here

Examples of org.codehaus.groovy.classgen.BytecodeExpression

    public void writeUnaryMinus(final UnaryMinusExpression expression) {
        expression.getExpression().visit(controller.getAcg());
        if (isPrimitiveOnTop()) {
            final ClassNode top = getTopOperand();
            if (top!=boolean_TYPE) {
                BytecodeExpression bytecodeExpression = new BytecodeExpression() {
                    @Override
                    public void visit(final MethodVisitor 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
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.