static BytecodeNode generateWrite(BytecodeGeneratorContext context, Type returnType, Variable outputBlock) { return BytecodeUtils.generateWrite( context.getCallSiteBinder(), context.getScope(), context.getScope().getVariable("wasNull"), returnType, outputBlock); } }
@Override public BytecodeNode visitVariableReference(VariableReferenceExpression reference, Context context) { BytecodeNode variableReferenceByteCode = fieldReferenceCompiler.visitVariableReference(reference, context.getScope()); if (!context.getOutputBlockVariable().isPresent()) { return variableReferenceByteCode; } return new BytecodeBlock() .append(variableReferenceByteCode) .append(generateWrite( callSiteBinder, context.getScope(), context.getScope().getVariable("wasNull"), reference.getType(), context.getOutputBlockVariable().get())); } }
@Override public BytecodeNode visitInputReference(InputReferenceExpression node, Context context) { BytecodeNode inputReferenceBytecode = fieldReferenceCompiler.visitInputReference(node, context.getScope()); if (!context.getOutputBlockVariable().isPresent()) { return inputReferenceBytecode; } return new BytecodeBlock() .append(inputReferenceBytecode) .append(generateWrite( callSiteBinder, context.getScope(), context.getScope().getVariable("wasNull"), node.getType(), context.getOutputBlockVariable().get())); }
switch (bestChoice.getReturnPlaceConvention()) { case STACK: block.append(generateWrite(binder, scope, scope.getVariable("wasNull"), outputBlockVariableAndType.get().getType(), outputBlockVariableAndType.get().getOutputBlockVariable())); break; case PROVIDED_BLOCKBUILDER:
block.append(generateWrite( callSiteBinder, context.getScope(),
.comment("evaluate projection: " + projection.toString()) .append(projection.accept(visitor, scope)) .append(generateWrite(callSiteBinder, scope, wasNullVariable, projection.getType())) .ret(); return method;
private void generateProjectMethod(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, CachedInstanceBinder cachedInstanceBinder, String methodName, RowExpression projection) { Map<CallExpression, MethodDefinition> tryMethodMap = generateTryMethods(classDefinition, callSiteBinder, cachedInstanceBinder, projection, methodName); Parameter session = arg("session", ConnectorSession.class); Parameter cursor = arg("cursor", RecordCursor.class); Parameter output = arg("output", BlockBuilder.class); MethodDefinition method = classDefinition.declareMethod(a(PUBLIC), methodName, type(void.class), session, cursor, output); method.comment("Projection: %s", projection.toString()); Scope scope = method.getScope(); Variable wasNullVariable = scope.declareVariable(type(boolean.class), "wasNull"); BytecodeBlock body = method.getBody() .comment("boolean wasNull = false;") .putVariable(wasNullVariable, false); BytecodeExpressionVisitor visitor = new BytecodeExpressionVisitor( callSiteBinder, cachedInstanceBinder, fieldReferenceCompiler(cursor, wasNullVariable), metadata.getFunctionRegistry(), ImmutableList.of(session, cursor, wasNullVariable), tryMethodMap); body.getVariable(output) .comment("evaluate projection: " + projection.toString()) .append(projection.accept(visitor, scope)) .append(generateWrite(callSiteBinder, scope, wasNullVariable, projection.getType())) .ret(); }