private VariableSlotLoader loadWithSubscript(Expression expression) { final OperandStack operandStack = controller.getOperandStack(); // if we have a BinaryExpression, let us check if it is with // subscription if (expression instanceof BinaryExpression) { BinaryExpression be = (BinaryExpression) expression; if (be.getOperation().getType()==Types.LEFT_SQUARE_BRACKET) { // right expression is the subscript expression // we store the result of the subscription on the stack Expression subscript = be.getRightExpression(); subscript.visit(controller.getAcg()); ClassNode subscriptType = operandStack.getTopOperand(); int id = controller.getCompileStack().defineTemporaryVariable("$subscript", subscriptType, true); VariableSlotLoader subscriptExpression = new VariableSlotLoader(subscriptType, id, operandStack); // do modified visit BinaryExpression newBe = new BinaryExpression(be.getLeftExpression(), be.getOperation(), subscriptExpression); newBe.copyNodeMetaData(be); newBe.setSourcePosition(be); newBe.visit(controller.getAcg()); return subscriptExpression; } } // normal loading of expression expression.visit(controller.getAcg()); return null; }
@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(equalsNull ? ICONST_0 : ICONST_1); 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); } } }
@Override public void visit(final GroovyCodeVisitor visitor) { if (visitor instanceof AsmClassGenerator) { AsmClassGenerator acg = (AsmClassGenerator) visitor; WriterController controller = acg.getController(); controller.getTypeChooser().resolveType(leftExpression, controller.getClassNode()); controller.getTypeChooser().resolveType(rightExpression, controller.getClassNode()); MethodVisitor mv = controller.getMethodVisitor(); leftExpression.visit(acg); controller.getOperandStack().box(); rightExpression.visit(acg); controller.getOperandStack().box(); 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); } } }
); bexp.setSourcePosition(entryExpression); bexp.visit(acg);
private VariableSlotLoader loadWithSubscript(Expression expression) { final OperandStack operandStack = controller.getOperandStack(); // if we have a BinaryExpression, let us check if it is with // subscription if (expression instanceof BinaryExpression) { BinaryExpression be = (BinaryExpression) expression; if (be.getOperation().getType()==Types.LEFT_SQUARE_BRACKET) { // right expression is the subscript expression // we store the result of the subscription on the stack Expression subscript = be.getRightExpression(); subscript.visit(controller.getAcg()); ClassNode subscriptType = operandStack.getTopOperand(); int id = controller.getCompileStack().defineTemporaryVariable("$subscript", subscriptType, true); VariableSlotLoader subscriptExpression = new VariableSlotLoader(subscriptType, id, operandStack); // do modified visit BinaryExpression newBe = new BinaryExpression(be.getLeftExpression(), be.getOperation(), subscriptExpression); newBe.copyNodeMetaData(be); newBe.setSourcePosition(be); newBe.visit(controller.getAcg()); return subscriptExpression; } } // normal loading of expression expression.visit(controller.getAcg()); return null; }