org.springframework.expression.spel.CodeFlow Java Examples

The following examples show how to use org.springframework.expression.spel.CodeFlow. 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: OpPlus.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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, SpelNodeImpl operand) {
	if (operand instanceof OpPlus) {
		OpPlus plus = (OpPlus)operand;
		walk(mv, cf, plus.getLeftOperand());
		walk(mv, cf, plus.getRightOperand());
	}
	else {
		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);
	}
}
 
Example #2
Source File: SpelNodeImpl.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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();
}
 
Example #3
Source File: IntLiteral.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	Integer intValue = (Integer) this.value.getValue();
	Assert.state(intValue != null, "No int value");
	if (intValue == -1) {
		// Not sure we can get here because -1 is OpMinus
		mv.visitInsn(ICONST_M1);
	}
	else if (intValue >= 0 && intValue < 6) {
		mv.visitInsn(ICONST_0 + intValue);
	}
	else {
		mv.visitLdcInsn(intValue);
	}
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #4
Source File: OpAnd.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #5
Source File: VariableReference.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	if (this.name.equals(ROOT)) {
		mv.visitVarInsn(ALOAD,1);
	}
	else {
		mv.visitVarInsn(ALOAD, 2);
		mv.visitLdcInsn(this.name);
		mv.visitMethodInsn(INVOKEINTERFACE, "org/springframework/expression/EvaluationContext", "lookupVariable", "(Ljava/lang/String;)Ljava/lang/Object;",true);
	}
	CodeFlow.insertCheckCast(mv, this.exitTypeDescriptor);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #6
Source File: MethodReference.java    From spring-analysis-note with MIT License 5 votes vote down vote up
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: InlineList.java    From spring-analysis-note with MIT License 5 votes vote down vote up
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 #8
Source File: OpModulus.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	getLeftOperand().generateCode(mv, cf);
	String leftDesc = getLeftOperand().exitTypeDescriptor;
	CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, leftDesc, this.exitTypeDescriptor.charAt(0));
	if (this.children.length > 1) {
		cf.enterCompilationScope();
		getRightOperand().generateCode(mv, cf);
		String rightDesc = getRightOperand().exitTypeDescriptor;
		cf.exitCompilationScope();
		CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, rightDesc, this.exitTypeDescriptor.charAt(0));
		switch (this.exitTypeDescriptor.charAt(0)) {
			case 'I':
				mv.visitInsn(IREM);
				break;
			case 'J':
				mv.visitInsn(LREM);
				break;
			case 'F': 
				mv.visitInsn(FREM);
				break;
			case 'D':
				mv.visitInsn(DREM);
				break;				
			default:
				throw new IllegalStateException(
						"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
		}
	}
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #9
Source File: VariableReference.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	if (this.name.equals(ROOT)) {
		mv.visitVarInsn(ALOAD,1);
	}
	else {
		mv.visitVarInsn(ALOAD, 2);
		mv.visitLdcInsn(name);
		mv.visitMethodInsn(INVOKEINTERFACE, "org/springframework/expression/EvaluationContext", "lookupVariable", "(Ljava/lang/String;)Ljava/lang/Object;",true);
	}
	CodeFlow.insertCheckCast(mv,this.exitTypeDescriptor);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #10
Source File: OpEQ.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	Object left = getLeftOperand().getValueInternal(state).getValue();
	Object right = getRightOperand().getValueInternal(state).getValue();
	this.leftActualDescriptor = CodeFlow.toDescriptorFromObject(left);
	this.rightActualDescriptor = CodeFlow.toDescriptorFromObject(right);
	return BooleanTypedValue.forValue(equalityCheck(state.getEvaluationContext(), left, right));
}
 
Example #11
Source File: OpDivide.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	getLeftOperand().generateCode(mv, cf);
	String leftDesc = getLeftOperand().exitTypeDescriptor;
	String exitDesc = this.exitTypeDescriptor;
	Assert.state(exitDesc != null, "No exit type descriptor");
	char targetDesc = exitDesc.charAt(0);
	CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, leftDesc, targetDesc);
	if (this.children.length > 1) {
		cf.enterCompilationScope();
		getRightOperand().generateCode(mv, cf);
		String rightDesc = getRightOperand().exitTypeDescriptor;
		cf.exitCompilationScope();
		CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, rightDesc, targetDesc);
		switch (targetDesc) {
			case 'I':
				mv.visitInsn(IDIV);
				break;
			case 'J':
				mv.visitInsn(LDIV);
				break;
			case 'F':
				mv.visitInsn(FDIV);
				break;
			case 'D':
				mv.visitInsn(DDIV);
				break;
			default:
				throw new IllegalStateException(
						"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
		}
	}
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #12
Source File: InlineList.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow codeflow) {
	final String constantFieldName = "inlineList$" + codeflow.nextFieldId();
	final String className = codeflow.getClassName();

	codeflow.registerNewField((cw, cflow) ->
			cw.visitField(ACC_PRIVATE | ACC_STATIC | ACC_FINAL, constantFieldName, "Ljava/util/List;", null, null));

	codeflow.registerNewClinit((mVisitor, cflow) ->
			generateClinitCode(className, constantFieldName, mVisitor, cflow, false));

	mv.visitFieldInsn(GETSTATIC, className, constantFieldName, "Ljava/util/List;");
	codeflow.pushDescriptor("Ljava/util/List");
}
 
Example #13
Source File: ConstructorReference.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	ReflectiveConstructorExecutor executor = ((ReflectiveConstructorExecutor) this.cachedExecutor);
	Constructor<?> constructor = executor.getConstructor();		
	String classDesc = constructor.getDeclaringClass().getName().replace('.', '/');
	mv.visitTypeInsn(NEW, classDesc);
	mv.visitInsn(DUP);
	// children[0] is the type of the constructor, don't want to include that in argument processing
	SpelNodeImpl[] arguments = new SpelNodeImpl[children.length - 1];
	System.arraycopy(children, 1, arguments, 0, children.length - 1);
	generateCodeForArguments(mv, cf, constructor, arguments);	
	mv.visitMethodInsn(INVOKESPECIAL, classDesc, "<init>", CodeFlow.createSignatureDescriptor(constructor), false);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #14
Source File: OperatorNot.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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);
}
 
Example #15
Source File: TypeReference.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	// TODO Future optimization - if followed by a static method call, skip generating code here
	Assert.state(this.type != null, "No type available");
	if (this.type.isPrimitive()) {
		if (this.type == Boolean.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Boolean", "TYPE", "Ljava/lang/Class;");
		}
		else if (this.type == Byte.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Byte", "TYPE", "Ljava/lang/Class;");
		}
		else if (this.type == Character.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Character", "TYPE", "Ljava/lang/Class;");
		}
		else if (this.type == Double.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Double", "TYPE", "Ljava/lang/Class;");
		}
		else if (this.type == Float.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Float", "TYPE", "Ljava/lang/Class;");
		}
		else if (this.type == Integer.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Integer", "TYPE", "Ljava/lang/Class;");
		}
		else if (this.type == Long.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Long", "TYPE", "Ljava/lang/Class;");
		}
		else if (this.type == Short.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Short", "TYPE", "Ljava/lang/Class;");
		}
	}
	else {
		mv.visitLdcInsn(Type.getType(this.type));
	}
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #16
Source File: OpNE.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	Object leftValue = getLeftOperand().getValueInternal(state).getValue();
	Object rightValue = getRightOperand().getValueInternal(state).getValue();
	this.leftActualDescriptor = CodeFlow.toDescriptorFromObject(leftValue);
	this.rightActualDescriptor = CodeFlow.toDescriptorFromObject(rightValue);
	return BooleanTypedValue.forValue(!equalityCheck(state.getEvaluationContext(), leftValue, rightValue));
}
 
Example #17
Source File: OpNE.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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 #18
Source File: Ternary.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public boolean isCompilable() {
	SpelNodeImpl condition = this.children[0];
	SpelNodeImpl left = this.children[1];
	SpelNodeImpl right = this.children[2];
	return (condition.isCompilable() && left.isCompilable() && right.isCompilable() &&
			CodeFlow.isBooleanCompatible(condition.exitTypeDescriptor) &&
			left.exitTypeDescriptor != null && right.exitTypeDescriptor != null);
}
 
Example #19
Source File: BooleanLiteral.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	if (this.value == BooleanTypedValue.TRUE) {
		mv.visitLdcInsn(1);
	}
	else {
		mv.visitLdcInsn(0);
	}
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #20
Source File: OpEQ.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	Object left = getLeftOperand().getValueInternal(state).getValue();
	Object right = getRightOperand().getValueInternal(state).getValue();
	this.leftActualDescriptor = CodeFlow.toDescriptorFromObject(left);
	this.rightActualDescriptor = CodeFlow.toDescriptorFromObject(right);
	return BooleanTypedValue.forValue(equalityCheck(state, left, right));
}
 
Example #21
Source File: MapAccessor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void generateCode(String propertyName, MethodVisitor mv, CodeFlow cf) {
	String descriptor = cf.lastDescriptor();
	if (descriptor == null || !descriptor.equals("Ljava/util/Map")) {
		if (descriptor == null) {
			cf.loadTarget(mv);
		}
		CodeFlow.insertCheckCast(mv, "Ljava/util/Map");
	}
	mv.visitLdcInsn(propertyName);
	mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "get","(Ljava/lang/Object;)Ljava/lang/Object;",true);
}
 
Example #22
Source File: Elvis.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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 #23
Source File: Ternary.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isCompilable() {
	SpelNodeImpl condition = this.children[0];
	SpelNodeImpl left = this.children[1];
	SpelNodeImpl right = this.children[2];
	return (condition.isCompilable() && left.isCompilable() && right.isCompilable() &&
			CodeFlow.isBooleanCompatible(condition.exitTypeDescriptor) &&
			left.exitTypeDescriptor != null && right.exitTypeDescriptor != null);
}
 
Example #24
Source File: OpDivide.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	getLeftOperand().generateCode(mv, cf);
	String leftDesc = getLeftOperand().exitTypeDescriptor;
	CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, leftDesc, this.exitTypeDescriptor.charAt(0));
	if (this.children.length > 1) {
		cf.enterCompilationScope();
		getRightOperand().generateCode(mv, cf);
		String rightDesc = getRightOperand().exitTypeDescriptor;
		cf.exitCompilationScope();
		CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, rightDesc, this.exitTypeDescriptor.charAt(0));
		switch (this.exitTypeDescriptor.charAt(0)) {
			case 'I':
				mv.visitInsn(IDIV);
				break;
			case 'J':
				mv.visitInsn(LDIV);
				break;
			case 'F': 
				mv.visitInsn(FDIV);
				break;
			case 'D':
				mv.visitInsn(DDIV);
				break;				
			default:
				throw new IllegalStateException(
						"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
		}
	}
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #25
Source File: PropertyOrFieldReference.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public TypedValue getValue() {
	TypedValue value = this.ref.getValueInternal(this.contextObject, this.evalContext, this.autoGrowNullReferences);
	if (this.ref.cachedReadAccessor instanceof CompilablePropertyAccessor) {
		CompilablePropertyAccessor accessor = (CompilablePropertyAccessor) this.ref.cachedReadAccessor;
		this.ref.exitTypeDescriptor = CodeFlow.toDescriptor(accessor.getPropertyType());
	}
	return value;
}
 
Example #26
Source File: CompoundExpression.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #27
Source File: PropertyOrFieldReference.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	TypedValue tv = getValueInternal(state.getActiveContextObject(), state.getEvaluationContext(),
			state.getConfiguration().isAutoGrowNullReferences());
	PropertyAccessor accessorToUse = this.cachedReadAccessor;
	if (accessorToUse instanceof CompilablePropertyAccessor) {
		CompilablePropertyAccessor accessor = (CompilablePropertyAccessor) accessorToUse;
		setExitTypeDescriptor(CodeFlow.toDescriptor(accessor.getPropertyType()));
	}
	return tv;
}
 
Example #28
Source File: Ternary.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 #29
Source File: OpEQ.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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 #30
Source File: OpEQ.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	Object left = getLeftOperand().getValueInternal(state).getValue();
	Object right = getRightOperand().getValueInternal(state).getValue();
	this.leftActualDescriptor = CodeFlow.toDescriptorFromObject(left);
	this.rightActualDescriptor = CodeFlow.toDescriptorFromObject(right);
	return BooleanTypedValue.forValue(
			equalityCheck(state.getEvaluationContext(), left, right));
}