@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { for (int i = 0; i < this.children.length;i++) { this.children[i].generateCode(mv, cf); } cf.pushDescriptor(this.exitTypeDescriptor); }
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { for (int i = 0; i < this.children.length;i++) { this.children[i].generateCode(mv, cf); } cf.pushDescriptor(this.exitTypeDescriptor); }
/** * Ask an argument to generate its bytecode and then follow it up * with any boxing/unboxing/checkcasting to ensure it matches the expected parameter descriptor. */ protected static void generateCodeForArgument(MethodVisitor mv, CodeFlow cf, SpelNodeImpl argument, String paramDesc) { cf.enterCompilationScope(); argument.generateCode(mv, cf); String lastDesc = cf.lastDescriptor(); Assert.state(lastDesc != null, "No last descriptor"); boolean primitiveOnStack = CodeFlow.isPrimitive(lastDesc); // Check if need to box it for the method reference? if (primitiveOnStack && paramDesc.charAt(0) == 'L') { CodeFlow.insertBoxIfNecessary(mv, lastDesc.charAt(0)); } else if (paramDesc.length() == 1 && !primitiveOnStack) { CodeFlow.insertUnboxInsns(mv, paramDesc.charAt(0), lastDesc); } else if (!paramDesc.equals(lastDesc)) { // This would be unnecessary in the case of subtyping (e.g. method takes Number but Integer passed in) CodeFlow.insertCheckCast(mv, paramDesc); } cf.exitCompilationScope(); }
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { cf.loadEvaluationContext(mv); String leftDesc = getLeftOperand().exitTypeDescriptor; String rightDesc = getRightOperand().exitTypeDescriptor; boolean leftPrim = CodeFlow.isPrimitive(leftDesc); boolean rightPrim = CodeFlow.isPrimitive(rightDesc); cf.enterCompilationScope(); getLeftOperand().generateCode(mv, cf); cf.exitCompilationScope(); if (leftPrim) { CodeFlow.insertBoxIfNecessary(mv, leftDesc.charAt(0)); } cf.enterCompilationScope(); getRightOperand().generateCode(mv, cf); cf.exitCompilationScope(); if (rightPrim) { CodeFlow.insertBoxIfNecessary(mv, rightDesc.charAt(0)); } String operatorClassName = Operator.class.getName().replace('.', '/'); String evaluationContextClassName = EvaluationContext.class.getName().replace('.', '/'); mv.visitMethodInsn(INVOKESTATIC, operatorClassName, "equalityCheck", "(L" + evaluationContextClassName + ";Ljava/lang/Object;Ljava/lang/Object;)Z", false); cf.pushDescriptor("Z"); }
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { getLeftOperand().generateCode(mv, cf); CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor()); Assert.state(this.type != null, "No type available"); if (this.type.isPrimitive()) { // always false - but left operand code always driven // in case it had side effects mv.visitInsn(POP); mv.visitInsn(ICONST_0); // value of false } else { mv.visitTypeInsn(INSTANCEOF, Type.getInternalName(this.type)); } cf.pushDescriptor(this.exitTypeDescriptor); }
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { getLeftOperand().generateCode(mv, cf); String leftDesc = getLeftOperand().exitTypeDescriptor; String exitDesc = this.exitTypeDescriptor; if (this.children.length > 1) { cf.enterCompilationScope(); getRightOperand().generateCode(mv, cf); String rightDesc = getRightOperand().exitTypeDescriptor; cf.exitCompilationScope();
/** * Walk through a possible tree of nodes that combine strings and append * them all to the same (on stack) StringBuilder. */ private void walk(MethodVisitor mv, CodeFlow cf, @Nullable SpelNodeImpl operand) { if (operand instanceof OpPlus) { OpPlus plus = (OpPlus)operand; walk(mv, cf, plus.getLeftOperand()); walk(mv, cf, plus.getRightOperand()); } else if (operand != null) { cf.enterCompilationScope(); operand.generateCode(mv,cf); if (!"Ljava/lang/String".equals(cf.lastDescriptor())) { mv.visitTypeInsn(CHECKCAST, "java/lang/String"); } cf.exitCompilationScope(); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false); } }
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { getLeftOperand().generateCode(mv, cf); String leftDesc = getLeftOperand().exitTypeDescriptor; String exitDesc = this.exitTypeDescriptor; if (this.children.length > 1) { cf.enterCompilationScope(); getRightOperand().generateCode(mv, cf); String rightDesc = getRightOperand().exitTypeDescriptor; cf.exitCompilationScope();
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { getLeftOperand().generateCode(mv, cf); String leftDesc = getLeftOperand().exitTypeDescriptor; String exitDesc = this.exitTypeDescriptor; if (this.children.length > 1) { cf.enterCompilationScope(); getRightOperand().generateCode(mv, cf); String rightDesc = getRightOperand().exitTypeDescriptor; cf.exitCompilationScope();
this.children[0].generateCode(mv, cf); String lastDesc = cf.lastDescriptor(); Assert.state(lastDesc != null, "No last descriptor"); mv.visitJumpInsn(IFEQ, elseTarget); cf.enterCompilationScope(); this.children[1].generateCode(mv, cf); if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) { lastDesc = cf.lastDescriptor(); mv.visitLabel(elseTarget); cf.enterCompilationScope(); this.children[2].generateCode(mv, cf); if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) { lastDesc = cf.lastDescriptor();
this.children[0].generateCode(mv, cf); String leftDesc = this.children[0].exitTypeDescriptor; String exitDesc = this.exitTypeDescriptor; if (this.children.length > 1) { cf.enterCompilationScope(); this.children[1].generateCode(mv, cf); String rightDesc = this.children[1].exitTypeDescriptor; cf.exitCompilationScope();
getLeftOperand().generateCode(mv, cf); cf.exitCompilationScope(); if (leftPrim) { getRightOperand().generateCode(mv, cf); cf.exitCompilationScope(); if (rightPrim) {
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { getLeftOperand().generateCode(mv, cf); String leftDesc = getLeftOperand().exitTypeDescriptor; String exitDesc = this.exitTypeDescriptor; if (this.children.length > 1) { cf.enterCompilationScope(); getRightOperand().generateCode(mv, cf); String rightDesc = getRightOperand().exitTypeDescriptor; cf.exitCompilationScope();
this.children[0].generateCode(mv, cf); String lastDesc = cf.lastDescriptor(); Assert.state(lastDesc != null, "No last descriptor"); mv.visitInsn(POP); cf.enterCompilationScope(); this.children[1].generateCode(mv, cf); if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) { lastDesc = cf.lastDescriptor();
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { // Pseudo: if (!leftOperandValue) { result=false; } else { result=rightOperandValue; } Label elseTarget = new Label(); Label endOfIf = new Label(); cf.enterCompilationScope(); getLeftOperand().generateCode(mv, cf); cf.unboxBooleanIfNecessary(mv); cf.exitCompilationScope(); mv.visitJumpInsn(IFNE, elseTarget); mv.visitLdcInsn(0); // FALSE mv.visitJumpInsn(GOTO,endOfIf); mv.visitLabel(elseTarget); cf.enterCompilationScope(); getRightOperand().generateCode(mv, cf); cf.unboxBooleanIfNecessary(mv); cf.exitCompilationScope(); mv.visitLabel(endOfIf); cf.pushDescriptor(this.exitTypeDescriptor); }
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { // pseudo: if (leftOperandValue) { result=true; } else { result=rightOperandValue; } Label elseTarget = new Label(); Label endOfIf = new Label(); cf.enterCompilationScope(); getLeftOperand().generateCode(mv, cf); cf.unboxBooleanIfNecessary(mv); cf.exitCompilationScope(); mv.visitJumpInsn(IFEQ, elseTarget); mv.visitLdcInsn(1); // TRUE mv.visitJumpInsn(GOTO,endOfIf); mv.visitLabel(elseTarget); cf.enterCompilationScope(); getRightOperand().generateCode(mv, cf); cf.unboxBooleanIfNecessary(mv); cf.exitCompilationScope(); mv.visitLabel(endOfIf); cf.pushDescriptor(this.exitTypeDescriptor); }
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { this.children[0].generateCode(mv, cf); cf.unboxBooleanIfNecessary(mv); Label elseTarget = new Label(); Label endOfIf = new Label(); mv.visitJumpInsn(IFNE,elseTarget); mv.visitInsn(ICONST_1); // TRUE mv.visitJumpInsn(GOTO,endOfIf); mv.visitLabel(elseTarget); mv.visitInsn(ICONST_0); // FALSE mv.visitLabel(endOfIf); cf.pushDescriptor(this.exitTypeDescriptor); }
expressionToCompile.generateCode(mv, cf);
this.children[c].generateCode(mv, codeflow); String lastDesc = codeflow.lastDescriptor(); if (CodeFlow.isPrimitive(lastDesc)) {
left.generateCode(mv, cf); cf.exitCompilationScope(); if (unboxLeft) { right.generateCode(mv, cf); cf.exitCompilationScope(); if (unboxRight) {