startOfBlock
Constructor and Description |
---|
LoopEmitter(parsii.tokenizer.Position startOfBlock)
Creates a new emitter for the given position.
|
Modifier and Type | Method and Description |
---|---|
Emitter |
copy()
Creates a deep copy of this emitter.
|
protected void |
emitToContext(LocalRenderContext context)
Actually produces the output while relying on the caller to properly handle any exception.
|
Expression |
getIterableExpression()
Returns the expression which yields the items to iterate through.
|
int |
getLocalIndex()
Contains the stack index being written to.
|
int |
getLoopStateIndex()
Contains the stack index which contains the loop state or -1 to indicate that the loop state is unused.
|
Emitter |
propagateVisitor(EmitterVisitor visitor)
Invokes the visitor on all sub emitters and on this emitter itself.
|
Emitter |
reduce()
Performs static optimizations at compile time.
|
void |
setIterableExpression(Expression iterableExpression)
Specifies the expression to evaluate which yields the items to iterate over.
|
void |
setLocalIndex(int localIndex)
Updates the stack index being written to.
|
void |
setLoop(Emitter loop)
Sets the body to emit once per item in the list of items to output.
|
void |
setLoopStateIndex(int loopStateIndex)
Updates the stack index of the loop state.
|
String |
toString() |
void |
verify(CompilationContext compilationContext)
Verifies the consistency of the emitter.
|
void |
visitExpressions(Function<parsii.tokenizer.Position,ExpressionVisitor> visitorSupplier)
Visits all expressions contained in this emitter or its children.
|
emit, getStartOfBlock
public LoopEmitter(parsii.tokenizer.Position startOfBlock)
startOfBlock
- the position where the emitter was declared.public void setIterableExpression(Expression iterableExpression)
iterableExpression
- the expression which evaluates to the list of items to processpublic void setLoop(Emitter loop)
loop
- the loop body to emit per itempublic Emitter copy()
Emitter
When templates are inlined, the parameters are propagated and constant expressions and conditions are evaluated at compile time. This yields faster and more efficient templates. In order to perform these optimizations, we need a copy of the template and all its emitters which can safely be modified.
public Emitter reduce()
Emitter
Certain emitters can perform optimizations (evaluate constant expressions, combine constant outputs etc.) to create more efficient templates. This is especially important when a template is inlined, as this most probably provides a higher level of optimizations.
public void verify(CompilationContext compilationContext)
compilationContext
- the context used to report errors topublic Emitter propagateVisitor(EmitterVisitor visitor)
Emitter
propagateVisitor
in class Emitter
visitor
- the visitor to invokepublic void visitExpressions(Function<parsii.tokenizer.Position,ExpressionVisitor> visitorSupplier)
Emitter
visitExpressions
in class Emitter
visitorSupplier
- a function which generates an ExpressionVisitor
while supplying the current position (for
improved error messages).protected void emitToContext(LocalRenderContext context) throws Exception
Emitter
emitToContext
in class Emitter
context
- the render context which provides access to the local and global environment and also the target
for the generated textException
- all thrown exceptions are caught and converted into a RenderException
public Expression getIterableExpression()
public void setLoopStateIndex(int loopStateIndex)
When inlining a template, the stack has to be transferred to the callee and therefore the stack indices might change.
loopStateIndex
- the new stack index to usepublic int getLoopStateIndex()
public int getLocalIndex()
public void setLocalIndex(int localIndex)
When inlining a template, the stack has to be transferred to the callee and therefore the stack indices might change.
localIndex
- the new stack index to useCopyright © 2018. All rights reserved.