void setExitTypeDescriptor(String descriptor) { // If this property or field access would return a primitive - and yet // it is also marked null safe - then the exit type descriptor must be // promoted to the box type to allow a null value to be passed on if (this.nullSafe && CodeFlow.isPrimitive(descriptor)) { this.originalPrimitiveExitTypeDescriptor = descriptor; this.exitTypeDescriptor = CodeFlow.toBoxedDescriptor(descriptor); } else { this.exitTypeDescriptor = descriptor; } }
/** * For use in mathematical operators, handles converting from a (possibly boxed) * number on the stack to a primitive numeric type. * <p>For example, from a Integer to a double, just need to call 'Number.doubleValue()' * but from an int to a double, need to use the bytecode 'i2d'. * @param mv the method visitor when instructions should be appended * @param stackDescriptor a descriptor of the operand on the stack * @param targetDescriptor a primitive type descriptor */ public static void insertNumericUnboxOrPrimitiveTypeCoercion( MethodVisitor mv, @Nullable String stackDescriptor, char targetDescriptor) { if (!CodeFlow.isPrimitive(stackDescriptor)) { CodeFlow.insertUnboxNumberInsns(mv, targetDescriptor, stackDescriptor); } else { CodeFlow.insertAnyNecessaryTypeConversionBytecodes(mv, targetDescriptor, stackDescriptor); } }
void setExitTypeDescriptor(String descriptor) { // If this property or field access would return a primitive - and yet // it is also marked null safe - then the exit type descriptor must be // promoted to the box type to allow a null value to be passed on if (this.nullSafe && CodeFlow.isPrimitive(descriptor)) { this.originalPrimitiveExitTypeDescriptor = descriptor; this.exitTypeDescriptor = CodeFlow.toBoxedDescriptor(descriptor); } else { this.exitTypeDescriptor = descriptor; } }
/** * 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(); }
private void updateExitTypeDescriptor() { CachedMethodExecutor executorToCheck = this.cachedExecutor; if (executorToCheck != null && executorToCheck.get() instanceof ReflectiveMethodExecutor) { Method method = ((ReflectiveMethodExecutor) executorToCheck.get()).getMethod(); String descriptor = CodeFlow.toDescriptor(method.getReturnType()); if (this.nullSafe && CodeFlow.isPrimitive(descriptor)) { this.originalPrimitiveExitTypeDescriptor = descriptor; this.exitTypeDescriptor = CodeFlow.toBoxedDescriptor(descriptor); } else { this.exitTypeDescriptor = descriptor; } } }
/** * For use in mathematical operators, handles converting from a (possibly boxed) * number on the stack to a primitive numeric type. * <p>For example, from a Integer to a double, just need to call 'Number.doubleValue()' * but from an int to a double, need to use the bytecode 'i2d'. * @param mv the method visitor when instructions should be appended * @param stackDescriptor a descriptor of the operand on the stack * @param targetDescriptor a primitive type descriptor */ public static void insertNumericUnboxOrPrimitiveTypeCoercion( MethodVisitor mv, @Nullable String stackDescriptor, char targetDescriptor) { if (!CodeFlow.isPrimitive(stackDescriptor)) { CodeFlow.insertUnboxNumberInsns(mv, targetDescriptor, stackDescriptor); } else { CodeFlow.insertAnyNecessaryTypeConversionBytecodes(mv, targetDescriptor, stackDescriptor); } }
@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"); }
if (CodeFlow.isPrimitive(descriptor)) { CodeFlow.insertBoxIfNecessary(mv, descriptor.charAt(0));
/** * 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(); }
String lastDesc = cf.lastDescriptor(); Assert.state(lastDesc != null, "No last descriptor"); if (!CodeFlow.isPrimitive(lastDesc)) { CodeFlow.insertUnboxInsns(mv, 'Z', lastDesc); cf.enterCompilationScope(); this.children[1].generateCode(mv, cf); if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) { lastDesc = cf.lastDescriptor(); Assert.state(lastDesc != null, "No last descriptor"); cf.enterCompilationScope(); this.children[2].generateCode(mv, cf); if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) { lastDesc = cf.lastDescriptor(); Assert.state(lastDesc != null, "No last descriptor");
private void updateExitTypeDescriptor() { CachedMethodExecutor executorToCheck = this.cachedExecutor; if (executorToCheck != null && executorToCheck.get() instanceof ReflectiveMethodExecutor) { Method method = ((ReflectiveMethodExecutor) executorToCheck.get()).getMethod(); String descriptor = CodeFlow.toDescriptor(method.getReturnType()); if (this.nullSafe && CodeFlow.isPrimitive(descriptor)) { this.originalPrimitiveExitTypeDescriptor = descriptor; this.exitTypeDescriptor = CodeFlow.toBoxedDescriptor(descriptor); } else { this.exitTypeDescriptor = descriptor; } } }
String leftDesc = getLeftOperand().exitTypeDescriptor; String rightDesc = getRightOperand().exitTypeDescriptor; boolean leftPrim = CodeFlow.isPrimitive(leftDesc); boolean rightPrim = CodeFlow.isPrimitive(rightDesc);
if (CodeFlow.isPrimitive(stackDescriptor)) { char stackTop = stackDescriptor.charAt(0); if (stackTop == 'I' || stackTop == 'B' || stackTop == 'S' || stackTop == 'C') {
@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"); }
this.children[c].generateCode(mv, codeflow); String lastDesc = codeflow.lastDescriptor(); if (CodeFlow.isPrimitive(lastDesc)) { CodeFlow.insertBoxIfNecessary(mv, lastDesc.charAt(0));
cf.enterCompilationScope(); this.children[1].generateCode(mv, cf); if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) { lastDesc = cf.lastDescriptor(); Assert.state(lastDesc != null, "No last descriptor");
String leftDesc = getLeftOperand().exitTypeDescriptor; String rightDesc = getRightOperand().exitTypeDescriptor; boolean leftPrim = CodeFlow.isPrimitive(leftDesc); boolean rightPrim = CodeFlow.isPrimitive(rightDesc);
String rightDesc = right.exitTypeDescriptor; boolean unboxLeft = !CodeFlow.isPrimitive(leftDesc); boolean unboxRight = !CodeFlow.isPrimitive(rightDesc); DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility( leftDesc, rightDesc, this.leftActualDescriptor, this.rightActualDescriptor);
cf.enterCompilationScope(); this.children[1].generateCode(mv, cf); if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) { lastDesc = cf.lastDescriptor(); Assert.state(lastDesc != null, "No last descriptor");
this.children[c].generateCode(mv, codeflow); String lastDesc = codeflow.lastDescriptor(); if (CodeFlow.isPrimitive(lastDesc)) { CodeFlow.insertBoxIfNecessary(mv, lastDesc.charAt(0));