public class BlockBuilder extends Object
BlockStatement.
Has methods that help ensure that variable names are unique.
| Constructor and Description |
|---|
BlockBuilder()
Creates a non-optimizing BlockBuilder.
|
BlockBuilder(boolean optimizing)
Creates a BlockBuilder.
|
BlockBuilder(boolean optimizing,
@Nullable BlockBuilder parent)
Creates a BlockBuilder.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(Expression expression) |
void |
add(Statement statement) |
protected void |
addExpressionForReuse(DeclarationStatement decl) |
BlockBuilder |
append(Expression expression) |
Expression |
append(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.
|
Expression |
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.
|
Expression |
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.
|
Expression |
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.
|
@PolyNull Expression |
appendIfNotNull(String name,
@PolyNull Expression expression)
Appends an expression to a list of statements if it is not null,
and returns the expression.
|
void |
clear()
Clears this BlockBuilder.
|
protected Shuttle |
createFinishingOptimizeShuttle()
Creates a final optimization shuttle.
|
protected Shuttle |
createOptimizeShuttle()
Creates a shuttle that will be used during block optimization.
|
@Nullable DeclarationStatement |
getComputedExpression(Expression expr)
Returns the reference to ParameterExpression if given expression was
already computed and stored to local variable.
|
boolean |
hasVariable(String name) |
protected boolean |
isSafeForReuse(DeclarationStatement decl) |
protected boolean |
isSimpleExpression(@Nullable Expression expr)
Checks if expression is simple enough to always inline at zero cost.
|
String |
newName(String suggestion)
Creates a name for a new variable, unique within this block.
|
BlockStatement |
toBlock()
Returns a block consisting of the current list of statements.
|
BlockBuilder |
withRemoveUnused(boolean removeUnused) |
public BlockBuilder()
public BlockBuilder(boolean optimizing)
optimizing - Whether to eliminate common sub-expressionspublic BlockBuilder(boolean optimizing,
@Nullable BlockBuilder parent)
optimizing - Whether to eliminate common sub-expressionspublic void clear()
public Expression append(String name, BlockStatement block)
public Expression append(String name, BlockStatement block, boolean optimize)
name - Suggested variable nameblock - Expressionoptimize - 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.public Expression append(String name, Expression expression)
public @PolyNull Expression appendIfNotNull(String name, @PolyNull Expression expression)
public Expression append(String name, Expression expression, boolean optimize)
protected boolean isSimpleExpression(@Nullable Expression expr)
expr - expression to testprotected boolean isSafeForReuse(DeclarationStatement decl)
protected void addExpressionForReuse(DeclarationStatement decl)
public @Nullable DeclarationStatement getComputedExpression(Expression expr)
expr - expression to testpublic void add(Statement statement)
public void add(Expression expression)
public BlockStatement toBlock()
protected Shuttle createOptimizeShuttle()
protected Shuttle createFinishingOptimizeShuttle()
public String newName(String suggestion)
public boolean hasVariable(String name)
public BlockBuilder append(Expression expression)
public BlockBuilder withRemoveUnused(boolean removeUnused)
Copyright © 2012-2021 Apache Software Foundation. All Rights Reserved.