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,
BlockBuilder parent)
Creates a BlockBuilder.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Expression expression) |
void |
add(Statement statement) |
protected void |
addExpresisonForReuse(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.
|
Expression |
appendIfNotNull(String name,
Expression expression)
Appends an expression to a list of statements, if it is not null.
|
void |
clear()
Clears this BlockBuilder.
|
protected Visitor |
createFinishingOptimizeVisitor()
Creates a final optimization visitor.
|
protected Visitor |
createOptimizeVisitor()
Creates a visitor that will be used during block optimization.
|
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(Expression expr)
Checks if experssion is simple enough for always inline
|
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.
|
public BlockBuilder()
public BlockBuilder(boolean optimizing)
optimizing
- Whether to eliminate common sub-expressionspublic BlockBuilder(boolean optimizing, 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 Expression appendIfNotNull(String name, Expression expression)
public Expression append(String name, Expression expression, boolean optimize)
protected boolean isSimpleExpression(Expression expr)
expr
- expression to testprotected boolean isSafeForReuse(DeclarationStatement decl)
protected void addExpresisonForReuse(DeclarationStatement decl)
public DeclarationStatement getComputedExpression(Expression expr)
expr
- expression to testpublic void add(Statement statement)
public void add(Expression expression)
public BlockStatement toBlock()
protected Visitor createOptimizeVisitor()
protected Visitor createFinishingOptimizeVisitor()
public String newName(String suggestion)
public boolean hasVariable(String name)
public BlockBuilder append(Expression expression)
Copyright © 2012-2014 Julian Hyde. All Rights Reserved.