block.append(loadBoolean((Boolean) value)); block.append(loadInt(((Number) value).intValue())); block.append(loadLong((Long) value)); block.append(loadFloat((Float) value)); block.append(loadDouble((Double) value)); block.append(loadString((String) value));
public static Constant loadNumber(Number value) { requireNonNull(value, "value is null"); if (value instanceof Byte) { return loadInt((value).intValue()); } if (value instanceof Short) { return loadInt((value).intValue()); } if (value instanceof Integer) { return loadInt((Integer) value); } if (value instanceof Long) { return loadLong((Long) value); } if (value instanceof Float) { return loadFloat((Float) value); } if (value instanceof Double) { return loadDouble((Double) value); } throw new IllegalStateException("Unsupported number type " + value.getClass().getSimpleName()); }
@Override public BytecodeNode generateExpression(Signature signature, BytecodeGeneratorContext generatorContext, Type returnType, List<RowExpression> arguments, Optional<Variable> outputBlockVariable) { Preconditions.checkArgument(arguments.size() == 1); RowExpression argument = arguments.get(0); if (argument.getType().equals(UNKNOWN)) { return loadBoolean(true); } BytecodeNode value = generatorContext.generate(argument, Optional.empty()); // evaluate the expression, pop the produced value, and load the null flag Variable wasNull = generatorContext.wasNull(); BytecodeBlock block = new BytecodeBlock() .comment("is null") .append(value) .pop(argument.getType().getJavaType()) .append(wasNull); // clear the null flag block.append(wasNull.set(constantFalse())); outputBlockVariable.ifPresent(output -> block.append(generateWrite(generatorContext, returnType, output))); return block; } }
public BytecodeBlock push(int value) { nodes.add(loadInt(value)); return this; }
public BytecodeBlock push(String value) { nodes.add(Constant.loadString(value)); return this; }
public static BytecodeExpression constantFloat(float value) { return new ConstantBytecodeExpression(float.class, loadFloat(value)); }
public static BytecodeExpression constantDouble(double value) { return new ConstantBytecodeExpression(double.class, loadDouble(value)); }
public static BytecodeExpression constantLong(long value) { return new ConstantBytecodeExpression(long.class, loadLong(value)); }
public BytecodeBlock push(Class<?> type) { nodes.add(loadClass(type)); return this; }
@Override public void accept(MethodVisitor visitor, MethodGenerationContext generationContext) { loadDouble(value).accept(visitor, generationContext); invokeStatic(Double.class, "valueOf", Double.class, double.class).accept(visitor, generationContext); }
@Override public String toString() { return toStringHelper(this) .add("value", getValue()) .toString(); }
case 'C': case 'I': nodes.add(loadInt(0)); break; case 'F': nodes.add(loadFloat(0)); break; case 'D': nodes.add(loadDouble(0)); break; case 'J': nodes.add(loadLong(0)); break; default: nodes.add(Constant.loadNull());
public BytecodeBlock push(boolean value) { nodes.add(loadBoolean(value)); return this; }
public BytecodeBlock putVariable(Variable variable, int value) { nodes.add(loadInt(value)); putVariable(variable); return this; }
public static BytecodeExpression constantString(String value) { return new ConstantBytecodeExpression(String.class, loadString(value)); }
public BytecodeBlock push(ParameterizedType type) { nodes.add(loadClass(type)); return this; }
@Override public void accept(MethodVisitor visitor, MethodGenerationContext generationContext) { loadInt(value).accept(visitor, generationContext); invokeStatic(Integer.class, "valueOf", Integer.class, int.class).accept(visitor, generationContext); }
@Override protected String formatOneLine() { return renderConstant(value.getValue()); }
return block.append(loadBoolean((Boolean) value)); return block.append(loadInt(((Number) value).intValue())); return block.append(loadLong((Long) value)); return block.append(loadFloat((Float) value)); return block.append(loadDouble((Double) value)); return block.append(loadString((String) value));
public BytecodeBlock putVariable(Variable variable, boolean value) { nodes.add(loadBoolean(value)); putVariable(variable); return this; }