InlineIfBytecodeExpression(BytecodeExpression condition, BytecodeExpression ifTrue, BytecodeExpression ifFalse) { super(ifTrue.getType()); this.condition = condition; this.ifTrue = requireNonNull(ifTrue, "ifTrue is null"); this.ifFalse = requireNonNull(ifFalse, "ifFalse is null"); checkArgument(condition.getType().getPrimitiveType() == boolean.class, "Expected condition to be type boolean but is %s", condition.getType()); checkArgument(ifTrue.getType().equals(ifFalse.getType()), "Expected ifTrue and ifFalse to be the same type"); }
OrBytecodeExpression(BytecodeExpression left, BytecodeExpression right) { super(type(boolean.class)); this.left = requireNonNull(left, "left is null"); checkArgument(left.getType().getPrimitiveType() == boolean.class, "Expected left to be type boolean but is %s", left.getType()); this.right = requireNonNull(right, "right is null"); checkArgument(right.getType().getPrimitiveType() == boolean.class, "Expected right to be type boolean but is %s", right.getType()); }
AndBytecodeExpression(BytecodeExpression left, BytecodeExpression right) { super(type(boolean.class)); this.left = requireNonNull(left, "left is null"); checkArgument(left.getType().getPrimitiveType() == boolean.class, "Expected left to be type boolean but is %s", left.getType()); this.right = requireNonNull(right, "right is null"); checkArgument(right.getType().getPrimitiveType() == boolean.class, "Expected right to be type boolean but is %s", right.getType()); }
private static Class<?> getPrimitiveType(BytecodeExpression expression, String name) { requireNonNull(expression, name + " is null"); Class<?> leftType = expression.getType().getPrimitiveType(); checkArgument(leftType != null, name + " is not a primitive"); checkArgument(leftType != void.class, name + " is void"); return leftType; }
NegateBytecodeExpression(BytecodeExpression value) { super(requireNonNull(value, "value is null").getType()); this.value = value; Class<?> type = value.getType().getPrimitiveType(); checkArgument(type != null, "value is not a primitive"); checkArgument(type != void.class, "value is void"); checkArgument(type == int.class || type == long.class || type == float.class || type == double.class, "value argument must be int, long, float, or double, but is %s", type); negateOpCode = getNumericOpCode("Negate", OpCode.INEG, type); }
private static Class<?> getPrimitiveType(BytecodeExpression expression, String name) { requireNonNull(expression, name + " is null"); Class<?> leftType = expression.getType().getPrimitiveType(); checkArgument(leftType != null, name + " is not a primitive"); checkArgument(leftType != void.class, name + " is void"); return leftType; }
public SetArrayElementBytecodeExpression(BytecodeExpression instance, BytecodeExpression index, BytecodeExpression value) { super(type(void.class)); this.instance = requireNonNull(instance, "instance is null"); this.index = requireNonNull(index, "index is null"); this.value = requireNonNull(value, "value is null"); ParameterizedType componentType = instance.getType().getArrayComponentType(); checkArgument(index.getType().getPrimitiveType() == int.class, "index must be int type, but is " + index.getType()); checkArgument(componentType.equals(value.getType()), "value must be %s type, but is %s", componentType, value.getType()); this.arrayStoreInstruction = getArrayOpCode(componentType).getStore(); }
public CastBytecodeExpression(BytecodeExpression instance, ParameterizedType type) { super(type); this.instance = requireNonNull(instance, "instance is null"); checkArgument(type.getPrimitiveType() != void.class, "Type %s can not be cast to %s", instance.getType(), type); // Call generateBytecode to run the validation logic. The result is thrown away. // Duplicating the validation logic here is error-prone and introduces duplicate code. generateBytecode(instance.getType(), getType()); }
public GetElementBytecodeExpression(BytecodeExpression instance, BytecodeExpression index) { super(instance.getType().getArrayComponentType()); this.instance = requireNonNull(instance, "instance is null"); this.index = requireNonNull(index, "index is null"); checkArgument(index.getType().getPrimitiveType() == int.class, "index must be int type, but is " + index.getType()); this.arrayLoadInstruction = getArrayOpCode(instance.getType().getArrayComponentType()).getLoad(); }
public final BytecodeExpression pop() { if (this.getType().getPrimitiveType() == void.class) { return this; } return new PopBytecodeExpression(this); }
public static BytecodeExpression isNull(BytecodeExpression value) { return equal(value, constantNull(value.getType())); }
public final BytecodeExpression getField(String name, Class<?> type) { return new GetFieldBytecodeExpression(this, this.getType(), name, type(type)); }
public static BytecodeExpression isNotNull(BytecodeExpression value) { return notEqual(value, constantNull(value.getType())); }
public static BytecodeExpression createArithmeticBytecodeExpression(OpCode baseOpCode, BytecodeExpression left, BytecodeExpression right) { requireNonNull(baseOpCode, "baseOpCode is null"); String name = getName(baseOpCode); String infixSymbol = getInfixSymbol(baseOpCode); checkArgumentTypes(baseOpCode, name, left, right); OpCode opCode = getNumericOpCode(name, baseOpCode, left.getType().getPrimitiveType()); return new ArithmeticBytecodeExpression(infixSymbol, left.getType(), opCode, left, right); }
public Variable declareVariable(String variableName, BytecodeBlock block, BytecodeExpression initialValue) { Variable variable = declareVariable(initialValue.getType(), variableName); block.append(variable.set(initialValue)); return variable; } }
@Override public BytecodeNode getBytecode(MethodGenerationContext generationContext) { return new BytecodeBlock() .append(instance.getBytecode(generationContext)) .pop(instance.getType()); }
public static void assertBytecodeExpression(BytecodeExpression expression, Object expected, String expectedRendering, Optional<ClassLoader> parentClassLoader) throws Exception { assertEquals(expression.toString(), expectedRendering); assertBytecodeNode(expression.ret(), expression.getType(), expected, parentClassLoader); }
@Override public BytecodeNode getBytecode(MethodGenerationContext generationContext) { return new BytecodeBlock() .append(instance.getBytecode(generationContext)) .append(generateBytecode(instance.getType(), getType())); }
public static void assertCast(BytecodeExpression expression, Object expectedValue, Class<?> castToType) throws Exception { BytecodeExpression castExpression = expression.cast(castToType); assertBytecodeExpression(castExpression, expectedValue, expectedCastRendering(expression.toString(), castToType)); assertEquals(castExpression.getType().getJavaClassName(), castToType.getName()); }