Package org.apache.calcite.linq4j.tree
Class BlockBuilder
java.lang.Object
org.apache.calcite.linq4j.tree.BlockBuilder
Builder for 
BlockStatement.
 Has methods that help ensure that variable names are unique.
- 
Constructor SummaryConstructorsConstructorDescriptionCreates a non-optimizing BlockBuilder.BlockBuilder(boolean optimizing) Creates a BlockBuilder.BlockBuilder(boolean optimizing, @Nullable BlockBuilder parent) Creates a BlockBuilder.
- 
Method SummaryModifier and TypeMethodDescriptionvoidadd(Expression expression) voidprotected voidappend(String name, BlockStatement block) Appends a block to a list of statements and returns an expression (possibly a variable) that represents the result of the newly added block.append(String name, BlockStatement block, boolean optimize) Appends an expression to a list of statements, optionally optimizing it to a variable if it is used more than once.append(String name, Expression expression) Appends an expression to a list of statements, and returns an expression (possibly a variable) that represents the result of the newly added block.append(String name, Expression expression, boolean optimize) Appends an expression to a list of statements, optionally optimizing if the expression is used more than once.append(Expression expression) @PolyNull ExpressionappendIfNotNull(String name, @PolyNull Expression expression) Appends an expression to a list of statements if it is not null, and returns the expression.voidclear()Clears this BlockBuilder.protected ShuttleCreates a final optimization shuttle.protected ShuttleCreates a shuttle that will be used during block optimization.@Nullable DeclarationStatementReturns the reference to ParameterExpression if given expression was already computed and stored to local variable.booleanhasVariable(String name) protected booleanprotected booleanisSimpleExpression(@Nullable Expression expr) Checks if expression is simple enough to always inline at zero cost.Creates a name for a new variable, unique within this block.toBlock()Returns a block consisting of the current list of statements.withRemoveUnused(boolean removeUnused) 
- 
Constructor Details- 
BlockBuilderpublic BlockBuilder()Creates a non-optimizing BlockBuilder.
- 
BlockBuilderpublic BlockBuilder(boolean optimizing) Creates a BlockBuilder.- Parameters:
- optimizing- Whether to eliminate common sub-expressions
 
- 
BlockBuilderCreates a BlockBuilder.- Parameters:
- optimizing- Whether to eliminate common sub-expressions
 
 
- 
- 
Method Details- 
clearpublic void clear()Clears this BlockBuilder.
- 
appendAppends a block to a list of statements and returns an expression (possibly a variable) that represents the result of the newly added block.
- 
appendAppends an expression to a list of statements, optionally optimizing it to a variable if it is used more than once.- Parameters:
- name- Suggested variable name
- block- Expression
- optimize- Whether to try to optimize by assigning the expression to a variable. Do not do this if the expression has side effects or a time-dependent value.
 
- 
appendAppends an expression to a list of statements, and returns an expression (possibly a variable) that represents the result of the newly added block.
- 
appendIfNotNullAppends an expression to a list of statements if it is not null, and returns the expression.
- 
appendAppends an expression to a list of statements, optionally optimizing if the expression is used more than once.
- 
isSimpleExpressionChecks if expression is simple enough to always inline at zero cost.- Parameters:
- expr- expression to test
- Returns:
- true when given expression is safe to always inline
 
- 
isSafeForReuse
- 
addExpressionForReuse
- 
getComputedExpressionReturns the reference to ParameterExpression if given expression was already computed and stored to local variable.- Parameters:
- expr- expression to test
- Returns:
- existing ParameterExpression or null
 
- 
add
- 
add
- 
toBlockReturns a block consisting of the current list of statements.
- 
createOptimizeShuttleCreates a shuttle that will be used during block optimization. Sub-classes might provide more specific optimizations (e.g. partial evaluation).- Returns:
- shuttle used to optimize the statements when converting to block
 
- 
createFinishingOptimizeShuttleCreates a final optimization shuttle. Typically, the visitor will factor out constant expressions.- Returns:
- shuttle that is used to finalize the optimization
 
- 
newNameCreates a name for a new variable, unique within this block.
- 
hasVariable
- 
append
- 
withRemoveUnused
 
-