Java Code Examples for org.springframework.expression.spel.CodeFlow#isPrimitive()
The following examples show how to use
org.springframework.expression.spel.CodeFlow#isPrimitive() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Ternary.java From spring4-understanding with Apache License 2.0 | 6 votes |
private void computeExitTypeDescriptor() { if (this.exitTypeDescriptor == null && this.children[1].exitTypeDescriptor != null && this.children[2].exitTypeDescriptor != null) { String leftDescriptor = this.children[1].exitTypeDescriptor; String rightDescriptor = this.children[2].exitTypeDescriptor; if (leftDescriptor.equals(rightDescriptor)) { this.exitTypeDescriptor = leftDescriptor; } else if (leftDescriptor.equals("Ljava/lang/Object") && !CodeFlow.isPrimitive(rightDescriptor)) { this.exitTypeDescriptor = rightDescriptor; } else if (rightDescriptor.equals("Ljava/lang/Object") && !CodeFlow.isPrimitive(leftDescriptor)) { this.exitTypeDescriptor = leftDescriptor; } else { // Use the easiest to compute common super type this.exitTypeDescriptor = "Ljava/lang/Object"; } } }
Example 2
Source File: Elvis.java From spring4-understanding with Apache License 2.0 | 6 votes |
private void computeExitTypeDescriptor() { if (this.exitTypeDescriptor == null && this.children[0].exitTypeDescriptor != null && this.children[1].exitTypeDescriptor != null) { String conditionDescriptor = this.children[0].exitTypeDescriptor; String ifNullValueDescriptor = this.children[1].exitTypeDescriptor; if (conditionDescriptor.equals(ifNullValueDescriptor)) { this.exitTypeDescriptor = conditionDescriptor; } else if (conditionDescriptor.equals("Ljava/lang/Object") && !CodeFlow.isPrimitive(ifNullValueDescriptor)) { this.exitTypeDescriptor = ifNullValueDescriptor; } else if (ifNullValueDescriptor.equals("Ljava/lang/Object") && !CodeFlow.isPrimitive(conditionDescriptor)) { this.exitTypeDescriptor = conditionDescriptor; } else { // Use the easiest to compute common super type this.exitTypeDescriptor = "Ljava/lang/Object"; } } }
Example 3
Source File: Elvis.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { // exit type descriptor can be null if both components are literal expressions computeExitTypeDescriptor(); this.children[0].generateCode(mv, cf); CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor().charAt(0)); Label elseTarget = new Label(); Label endOfIf = new Label(); mv.visitInsn(DUP); mv.visitJumpInsn(IFNULL, elseTarget); // Also check if empty string, as per the code in the interpreted version mv.visitInsn(DUP); mv.visitLdcInsn(""); mv.visitInsn(SWAP); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z",false); mv.visitJumpInsn(IFEQ, endOfIf); // if not empty, drop through to elseTarget mv.visitLabel(elseTarget); mv.visitInsn(POP); this.children[1].generateCode(mv, cf); if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) { CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor().charAt(0)); } mv.visitLabel(endOfIf); cf.pushDescriptor(this.exitTypeDescriptor); }
Example 4
Source File: OpNE.java From spring-analysis-note with MIT License | 5 votes |
@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); // Invert the boolean Label notZero = new Label(); Label end = new Label(); mv.visitJumpInsn(IFNE, notZero); mv.visitInsn(ICONST_1); mv.visitJumpInsn(GOTO, end); mv.visitLabel(notZero); mv.visitInsn(ICONST_0); mv.visitLabel(end); cf.pushDescriptor("Z"); }
Example 5
Source File: Ternary.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { // May reach here without it computed if all elements are literals computeExitTypeDescriptor(); cf.enterCompilationScope(); this.children[0].generateCode(mv, cf); if (!CodeFlow.isPrimitive(cf.lastDescriptor())) { CodeFlow.insertUnboxInsns(mv, 'Z', cf.lastDescriptor()); } cf.exitCompilationScope(); Label elseTarget = new Label(); Label endOfIf = new Label(); mv.visitJumpInsn(IFEQ, elseTarget); cf.enterCompilationScope(); this.children[1].generateCode(mv, cf); if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) { CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor().charAt(0)); } cf.exitCompilationScope(); mv.visitJumpInsn(GOTO, endOfIf); mv.visitLabel(elseTarget); cf.enterCompilationScope(); this.children[2].generateCode(mv, cf); if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) { CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor().charAt(0)); } cf.exitCompilationScope(); mv.visitLabel(endOfIf); cf.pushDescriptor(this.exitTypeDescriptor); }
Example 6
Source File: MethodReference.java From spring-analysis-note with MIT License | 5 votes |
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; } } }
Example 7
Source File: PropertyOrFieldReference.java From spring-analysis-note with MIT License | 5 votes |
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; } }
Example 8
Source File: OpNE.java From lams with GNU General Public License v2.0 | 5 votes |
@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); // Invert the boolean Label notZero = new Label(); Label end = new Label(); mv.visitJumpInsn(IFNE, notZero); mv.visitInsn(ICONST_1); mv.visitJumpInsn(GOTO, end); mv.visitLabel(notZero); mv.visitInsn(ICONST_0); mv.visitLabel(end); cf.pushDescriptor("Z"); }
Example 9
Source File: InlineList.java From java-technology-stack with MIT License | 5 votes |
void generateClinitCode(String clazzname, String constantFieldName, MethodVisitor mv, CodeFlow codeflow, boolean nested) { mv.visitTypeInsn(NEW, "java/util/ArrayList"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V", false); if (!nested) { mv.visitFieldInsn(PUTSTATIC, clazzname, constantFieldName, "Ljava/util/List;"); } int childCount = getChildCount(); for (int c = 0; c < childCount; c++) { if (!nested) { mv.visitFieldInsn(GETSTATIC, clazzname, constantFieldName, "Ljava/util/List;"); } else { mv.visitInsn(DUP); } // The children might be further lists if they are not constants. In this // situation do not call back into generateCode() because it will register another clinit adder. // Instead, directly build the list here: if (this.children[c] instanceof InlineList) { ((InlineList)this.children[c]).generateClinitCode(clazzname, constantFieldName, mv, codeflow, true); } else { this.children[c].generateCode(mv, codeflow); String lastDesc = codeflow.lastDescriptor(); if (CodeFlow.isPrimitive(lastDesc)) { CodeFlow.insertBoxIfNecessary(mv, lastDesc.charAt(0)); } } mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true); mv.visitInsn(POP); } }
Example 10
Source File: InlineList.java From lams with GNU General Public License v2.0 | 5 votes |
void generateClinitCode(String clazzname, String constantFieldName, MethodVisitor mv, CodeFlow codeflow, boolean nested) { mv.visitTypeInsn(NEW, "java/util/ArrayList"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V", false); if (!nested) { mv.visitFieldInsn(PUTSTATIC, clazzname, constantFieldName, "Ljava/util/List;"); } int childCount = getChildCount(); for (int c = 0; c < childCount; c++) { if (!nested) { mv.visitFieldInsn(GETSTATIC, clazzname, constantFieldName, "Ljava/util/List;"); } else { mv.visitInsn(DUP); } // The children might be further lists if they are not constants. In this // situation do not call back into generateCode() because it will register another clinit adder. // Instead, directly build the list here: if (children[c] instanceof InlineList) { ((InlineList)children[c]).generateClinitCode(clazzname, constantFieldName, mv, codeflow, true); } else { children[c].generateCode(mv, codeflow); if (CodeFlow.isPrimitive(codeflow.lastDescriptor())) { CodeFlow.insertBoxIfNecessary(mv, codeflow.lastDescriptor().charAt(0)); } } mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true); mv.visitInsn(POP); } }
Example 11
Source File: OpNE.java From java-technology-stack with MIT License | 5 votes |
@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); // Invert the boolean Label notZero = new Label(); Label end = new Label(); mv.visitJumpInsn(IFNE, notZero); mv.visitInsn(ICONST_1); mv.visitJumpInsn(GOTO, end); mv.visitLabel(notZero); mv.visitInsn(ICONST_0); mv.visitLabel(end); cf.pushDescriptor("Z"); }
Example 12
Source File: OpEQ.java From java-technology-stack with MIT License | 5 votes |
@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"); }
Example 13
Source File: Elvis.java From java-technology-stack with MIT License | 5 votes |
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { // exit type descriptor can be null if both components are literal expressions computeExitTypeDescriptor(); cf.enterCompilationScope(); this.children[0].generateCode(mv, cf); String lastDesc = cf.lastDescriptor(); Assert.state(lastDesc != null, "No last descriptor"); CodeFlow.insertBoxIfNecessary(mv, lastDesc.charAt(0)); cf.exitCompilationScope(); Label elseTarget = new Label(); Label endOfIf = new Label(); mv.visitInsn(DUP); mv.visitJumpInsn(IFNULL, elseTarget); // Also check if empty string, as per the code in the interpreted version mv.visitInsn(DUP); mv.visitLdcInsn(""); mv.visitInsn(SWAP); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z",false); mv.visitJumpInsn(IFEQ, endOfIf); // if not empty, drop through to elseTarget mv.visitLabel(elseTarget); mv.visitInsn(POP); cf.enterCompilationScope(); this.children[1].generateCode(mv, cf); if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) { lastDesc = cf.lastDescriptor(); Assert.state(lastDesc != null, "No last descriptor"); CodeFlow.insertBoxIfNecessary(mv, lastDesc.charAt(0)); } cf.exitCompilationScope(); mv.visitLabel(endOfIf); cf.pushDescriptor(this.exitTypeDescriptor); }
Example 14
Source File: PropertyOrFieldReference.java From java-technology-stack with MIT License | 5 votes |
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; } }
Example 15
Source File: InlineList.java From spring-analysis-note with MIT License | 5 votes |
void generateClinitCode(String clazzname, String constantFieldName, MethodVisitor mv, CodeFlow codeflow, boolean nested) { mv.visitTypeInsn(NEW, "java/util/ArrayList"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V", false); if (!nested) { mv.visitFieldInsn(PUTSTATIC, clazzname, constantFieldName, "Ljava/util/List;"); } int childCount = getChildCount(); for (int c = 0; c < childCount; c++) { if (!nested) { mv.visitFieldInsn(GETSTATIC, clazzname, constantFieldName, "Ljava/util/List;"); } else { mv.visitInsn(DUP); } // The children might be further lists if they are not constants. In this // situation do not call back into generateCode() because it will register another clinit adder. // Instead, directly build the list here: if (this.children[c] instanceof InlineList) { ((InlineList)this.children[c]).generateClinitCode(clazzname, constantFieldName, mv, codeflow, true); } else { this.children[c].generateCode(mv, codeflow); String lastDesc = codeflow.lastDescriptor(); if (CodeFlow.isPrimitive(lastDesc)) { CodeFlow.insertBoxIfNecessary(mv, lastDesc.charAt(0)); } } mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true); mv.visitInsn(POP); } }
Example 16
Source File: MethodReference.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { CachedMethodExecutor executorToCheck = this.cachedExecutor; if (executorToCheck == null || !(executorToCheck.get() instanceof ReflectiveMethodExecutor)) { throw new IllegalStateException("No applicable cached executor found: " + executorToCheck); } ReflectiveMethodExecutor methodExecutor = (ReflectiveMethodExecutor) executorToCheck.get(); Method method = methodExecutor.getMethod(); boolean isStaticMethod = Modifier.isStatic(method.getModifiers()); String descriptor = cf.lastDescriptor(); if (descriptor == null) { if (!isStaticMethod) { // Nothing on the stack but something is needed cf.loadTarget(mv); } } else { if (isStaticMethod) { // Something on the stack when nothing is needed mv.visitInsn(POP); } } if (CodeFlow.isPrimitive(descriptor)) { CodeFlow.insertBoxIfNecessary(mv, descriptor.charAt(0)); } String classDesc = (Modifier.isPublic(method.getDeclaringClass().getModifiers()) ? method.getDeclaringClass().getName().replace('.', '/') : methodExecutor.getPublicDeclaringClass().getName().replace('.', '/')); if (!isStaticMethod) { if (descriptor == null || !descriptor.substring(1).equals(classDesc)) { CodeFlow.insertCheckCast(mv, "L" + classDesc); } } generateCodeForArguments(mv, cf, method, this.children); mv.visitMethodInsn((isStaticMethod ? INVOKESTATIC : INVOKEVIRTUAL), classDesc, method.getName(), CodeFlow.createSignatureDescriptor(method), method.getDeclaringClass().isInterface()); cf.pushDescriptor(this.exitTypeDescriptor); }
Example 17
Source File: OpEQ.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { String leftDesc = getLeftOperand().exitTypeDescriptor; String rightDesc = getRightOperand().exitTypeDescriptor; Label elseTarget = new Label(); Label endOfIf = new Label(); boolean leftPrim = CodeFlow.isPrimitive(leftDesc); boolean rightPrim = CodeFlow.isPrimitive(rightDesc); DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(leftDesc, rightDesc, this.leftActualDescriptor, this.rightActualDescriptor); if (dc.areNumbers && dc.areCompatible) { char targetType = dc.compatibleType; getLeftOperand().generateCode(mv, cf); if (!leftPrim) { CodeFlow.insertUnboxInsns(mv, targetType, leftDesc); } cf.enterCompilationScope(); getRightOperand().generateCode(mv, cf); cf.exitCompilationScope(); if (!rightPrim) { CodeFlow.insertUnboxInsns(mv, targetType, rightDesc); } // assert: SpelCompiler.boxingCompatible(leftDesc, rightDesc) if (targetType=='D') { mv.visitInsn(DCMPL); mv.visitJumpInsn(IFNE, elseTarget); } else if (targetType=='F') { mv.visitInsn(FCMPL); mv.visitJumpInsn(IFNE, elseTarget); } else if (targetType=='J') { mv.visitInsn(LCMP); mv.visitJumpInsn(IFNE, elseTarget); } else if (targetType=='I' || targetType=='Z') { mv.visitJumpInsn(IF_ICMPNE, elseTarget); } else { throw new IllegalStateException("Unexpected descriptor "+leftDesc); } } else { getLeftOperand().generateCode(mv, cf); if (leftPrim) { CodeFlow.insertBoxIfNecessary(mv, leftDesc.charAt(0)); } getRightOperand().generateCode(mv, cf); if (rightPrim) { CodeFlow.insertBoxIfNecessary(mv, rightDesc.charAt(0)); } Label leftNotNull = new Label(); mv.visitInsn(DUP_X1); // Dup right on the top of the stack mv.visitJumpInsn(IFNONNULL,leftNotNull); // Right is null! mv.visitInsn(SWAP); mv.visitInsn(POP); // remove it Label rightNotNull = new Label(); mv.visitJumpInsn(IFNONNULL, rightNotNull); // Left is null too mv.visitInsn(ICONST_1); mv.visitJumpInsn(GOTO, endOfIf); mv.visitLabel(rightNotNull); mv.visitInsn(ICONST_0); mv.visitJumpInsn(GOTO,endOfIf); mv.visitLabel(leftNotNull); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z", false); mv.visitLabel(endOfIf); cf.pushDescriptor("Z"); return; } mv.visitInsn(ICONST_1); mv.visitJumpInsn(GOTO,endOfIf); mv.visitLabel(elseTarget); mv.visitInsn(ICONST_0); mv.visitLabel(endOfIf); cf.pushDescriptor("Z"); }
Example 18
Source File: Operator.java From java-technology-stack with MIT License | 4 votes |
/** * Numeric comparison operators share very similar generated code, only differing in * two comparison instructions. */ protected void generateComparisonCode(MethodVisitor mv, CodeFlow cf, int compInstruction1, int compInstruction2) { SpelNodeImpl left = getLeftOperand(); SpelNodeImpl right = getRightOperand(); String leftDesc = left.exitTypeDescriptor; String rightDesc = right.exitTypeDescriptor; boolean unboxLeft = !CodeFlow.isPrimitive(leftDesc); boolean unboxRight = !CodeFlow.isPrimitive(rightDesc); DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility( leftDesc, rightDesc, this.leftActualDescriptor, this.rightActualDescriptor); char targetType = dc.compatibleType; // CodeFlow.toPrimitiveTargetDesc(leftDesc); cf.enterCompilationScope(); left.generateCode(mv, cf); cf.exitCompilationScope(); if (unboxLeft) { CodeFlow.insertUnboxInsns(mv, targetType, leftDesc); } cf.enterCompilationScope(); right.generateCode(mv, cf); cf.exitCompilationScope(); if (unboxRight) { CodeFlow.insertUnboxInsns(mv, targetType, rightDesc); } // assert: SpelCompiler.boxingCompatible(leftDesc, rightDesc) Label elseTarget = new Label(); Label endOfIf = new Label(); if (targetType == 'D') { mv.visitInsn(DCMPG); mv.visitJumpInsn(compInstruction1, elseTarget); } else if (targetType == 'F') { mv.visitInsn(FCMPG); mv.visitJumpInsn(compInstruction1, elseTarget); } else if (targetType == 'J') { mv.visitInsn(LCMP); mv.visitJumpInsn(compInstruction1, elseTarget); } else if (targetType == 'I') { mv.visitJumpInsn(compInstruction2, elseTarget); } else { throw new IllegalStateException("Unexpected descriptor " + leftDesc); } // Other numbers are not yet supported (isCompilable will not have returned true) mv.visitInsn(ICONST_1); mv.visitJumpInsn(GOTO,endOfIf); mv.visitLabel(elseTarget); mv.visitInsn(ICONST_0); mv.visitLabel(endOfIf); cf.pushDescriptor("Z"); }
Example 19
Source File: Operator.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Numeric comparison operators share very similar generated code, only differing in * two comparison instructions. */ protected void generateComparisonCode(MethodVisitor mv, CodeFlow cf, int compInstruction1, int compInstruction2) { String leftDesc = getLeftOperand().exitTypeDescriptor; String rightDesc = getRightOperand().exitTypeDescriptor; boolean unboxLeft = !CodeFlow.isPrimitive(leftDesc); boolean unboxRight = !CodeFlow.isPrimitive(rightDesc); DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility( leftDesc, rightDesc, this.leftActualDescriptor, this.rightActualDescriptor); char targetType = dc.compatibleType; // CodeFlow.toPrimitiveTargetDesc(leftDesc); cf.enterCompilationScope(); getLeftOperand().generateCode(mv, cf); cf.exitCompilationScope(); if (unboxLeft) { CodeFlow.insertUnboxInsns(mv, targetType, leftDesc); } cf.enterCompilationScope(); getRightOperand().generateCode(mv, cf); cf.exitCompilationScope(); if (unboxRight) { CodeFlow.insertUnboxInsns(mv, targetType, rightDesc); } // assert: SpelCompiler.boxingCompatible(leftDesc, rightDesc) Label elseTarget = new Label(); Label endOfIf = new Label(); if (targetType == 'D') { mv.visitInsn(DCMPG); mv.visitJumpInsn(compInstruction1, elseTarget); } else if (targetType == 'F') { mv.visitInsn(FCMPG); mv.visitJumpInsn(compInstruction1, elseTarget); } else if (targetType == 'J') { mv.visitInsn(LCMP); mv.visitJumpInsn(compInstruction1, elseTarget); } else if (targetType == 'I') { mv.visitJumpInsn(compInstruction2, elseTarget); } else { throw new IllegalStateException("Unexpected descriptor " + leftDesc); } // Other numbers are not yet supported (isCompilable will not have returned true) mv.visitInsn(ICONST_1); mv.visitJumpInsn(GOTO,endOfIf); mv.visitLabel(elseTarget); mv.visitInsn(ICONST_0); mv.visitLabel(endOfIf); cf.pushDescriptor("Z"); }
Example 20
Source File: OpNE.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { String leftDesc = getLeftOperand().exitTypeDescriptor; String rightDesc = getRightOperand().exitTypeDescriptor; Label elseTarget = new Label(); Label endOfIf = new Label(); boolean leftPrim = CodeFlow.isPrimitive(leftDesc); boolean rightPrim = CodeFlow.isPrimitive(rightDesc); DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(leftDesc, rightDesc, leftActualDescriptor, rightActualDescriptor); if (dc.areNumbers && dc.areCompatible) { char targetType = dc.compatibleType; getLeftOperand().generateCode(mv, cf); if (!leftPrim) { CodeFlow.insertUnboxInsns(mv, targetType, leftDesc); } cf.enterCompilationScope(); getRightOperand().generateCode(mv, cf); cf.exitCompilationScope(); if (!rightPrim) { CodeFlow.insertUnboxInsns(mv, targetType, rightDesc); } // assert: SpelCompiler.boxingCompatible(leftDesc, rightDesc) if (targetType == 'D') { mv.visitInsn(DCMPL); mv.visitJumpInsn(IFEQ, elseTarget); } else if (targetType == 'F') { mv.visitInsn(FCMPL); mv.visitJumpInsn(IFEQ, elseTarget); } else if (targetType == 'J') { mv.visitInsn(LCMP); mv.visitJumpInsn(IFEQ, elseTarget); } else if (targetType == 'I' || targetType == 'Z') { mv.visitJumpInsn(IF_ICMPEQ, elseTarget); } else { throw new IllegalStateException("Unexpected descriptor "+leftDesc); } } else { getLeftOperand().generateCode(mv, cf); getRightOperand().generateCode(mv, cf); mv.visitJumpInsn(IF_ACMPEQ, elseTarget); } mv.visitInsn(ICONST_1); mv.visitJumpInsn(GOTO,endOfIf); mv.visitLabel(elseTarget); mv.visitInsn(ICONST_0); mv.visitLabel(endOfIf); cf.pushDescriptor("Z"); }