Java Code Examples for org.springframework.asm.MethodVisitor#visitLdcInsn()

The following examples show how to use org.springframework.asm.MethodVisitor#visitLdcInsn() . 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: IntLiteral.java    From spring-analysis-note 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 2
Source File: OpOr.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=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);
}
 
Example 3
Source File: OpAnd.java    From lams with GNU General Public License v2.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 4
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 5
Source File: IntLiteral.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	int intValue = (Integer) this.value.getValue();
	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 6
Source File: IntLiteral.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	int intValue = (Integer) this.value.getValue();
	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 7
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 8
Source File: TypeReference.java    From lams with GNU General Public License v2.0 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
	if (this.type.isPrimitive()) {
		if (this.type == Integer.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Integer", "TYPE", "Ljava/lang/Class;");
		}
		else 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 == Short.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Short", "TYPE", "Ljava/lang/Class;");
		}
		else if (this.type == Double.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Double", "TYPE", "Ljava/lang/Class;");
		}
		else if (this.type == Character.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Character", "TYPE", "Ljava/lang/Class;");
		}
		else if (this.type == Float.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Float", "TYPE", "Ljava/lang/Class;");
		}
		else if (this.type == Long.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Long", "TYPE", "Ljava/lang/Class;");
		}
		else if (this.type == Boolean.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Boolean", "TYPE", "Ljava/lang/Class;");
        }
	}
	else {
		mv.visitLdcInsn(Type.getType(this.type));
	}
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example 9
Source File: VariableReference.java    From spring4-understanding with Apache License 2.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: TypeReference.java    From spring4-understanding with Apache License 2.0 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
	if (this.type.isPrimitive()) {
		if (this.type == Integer.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Integer", "TYPE", "Ljava/lang/Class;");
		}
		else 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 == Short.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Short", "TYPE", "Ljava/lang/Class;");
		}
		else if (this.type == Double.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Double", "TYPE", "Ljava/lang/Class;");
		}
		else if (this.type == Character.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Character", "TYPE", "Ljava/lang/Class;");
		}
		else if (this.type == Float.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Float", "TYPE", "Ljava/lang/Class;");
		}
		else if (this.type == Long.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Long", "TYPE", "Ljava/lang/Class;");
		}
		else if (this.type == Boolean.TYPE) {
			mv.visitFieldInsn(GETSTATIC, "java/lang/Boolean", "TYPE", "Ljava/lang/Class;");
        }
	}
	else {
		mv.visitLdcInsn(Type.getType(this.type));
	}
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example 11
Source File: ReadMapAccessor.java    From poi-tl with Apache License 2.0 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 12
Source File: LongLiteral.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	mv.visitLdcInsn(this.value.getValue());
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example 13
Source File: FloatLiteral.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	mv.visitLdcInsn(this.value.getValue());
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example 14
Source File: LongLiteral.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	mv.visitLdcInsn(this.value.getValue());
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example 15
Source File: StringLiteral.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	mv.visitLdcInsn(this.value.getValue());
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example 16
Source File: RealLiteral.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	mv.visitLdcInsn(this.value.getValue());
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example 17
Source File: FloatLiteral.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	mv.visitLdcInsn(this.value.getValue());
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example 18
Source File: RealLiteral.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	mv.visitLdcInsn(this.value.getValue());
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example 19
Source File: RealLiteral.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	mv.visitLdcInsn(this.value.getValue());
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example 20
Source File: StringLiteral.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	mv.visitLdcInsn(this.value.getValue());
	cf.pushDescriptor(this.exitTypeDescriptor);
}