public final class Block extends ExpressionStatement<Block> implements java.lang.Iterable<GoloStatement<?>>
A block defines a scope, and as such maintains its local reference table.
Modifier and Type | Method and Description |
---|---|
void |
accept(GoloIrVisitor visitor)
Accept the visitor.
|
Block |
add(java.lang.Object statement)
Add a statement to this block.
|
static Block |
block(java.lang.Object... statements)
Creates a block containing the given statements.
|
java.util.List<GoloElement<?>> |
children()
Returns a list of all the direct children of this node.
|
static Block |
empty()
Create an empty block.
|
void |
flatten()
Merge nested blocks with this one if they don't define local variables.
|
java.util.Optional<ReferenceTable> |
getLocalReferenceTable() |
ReferenceTable |
getReferenceTable() |
java.util.List<GoloStatement<?>> |
getStatements() |
boolean |
hasOnlyExpression()
Checks if this blocks contains only an expression.
|
boolean |
hasOnlyReturn()
Checks if this block contains only a return statement.
|
boolean |
hasReturn() |
void |
internReferenceTable()
Internal method.
|
boolean |
isEmpty() |
java.util.Iterator<GoloStatement<?>> |
iterator() |
Block |
map(FunctionReference fun)
Creates a new block by applying the given function to the elements of this block.
|
void |
merge(Block other)
Merge two blocks.
|
static Block |
of(java.lang.Object block)
Block coercion.
|
Block |
prepend(java.lang.Object statement) |
Block |
ref(java.lang.Object referenceTable)
Define the reference table of this block.
|
protected void |
replaceElement(GoloElement<?> original,
GoloElement<?> newElement)
Replace a child.
|
protected Block |
self() |
int |
size() |
java.lang.String |
toString() |
void |
walk(GoloIrVisitor visitor)
Walk the visitor through this node children.
|
call, clearDeclarations, declarations, hasLocalDeclarations, with
ancestor, ancestor, ancestorOfType, cantConvert, cantReplace, cantReplace, children, children, descendants, descendants, descendants, documentation, documentation, doesNotContain, enclosingModule, hasParent, hasPosition, makeParentOf, metadata, metadata, next, next, next, ofAST, parent, positionInSourceCode, positionInSourceCode, previous, previous, previous, replaceInParentBy
protected Block self()
self
in class GoloElement<Block>
public static Block of(java.lang.Object block)
if the argument is null
, returns an empty block, otherwise, tries to convert it into a block, wrapping
it in an empty block if necessary.
public static Block block(java.lang.Object... statements)
If the only argument is already a block, returns it unchanged. If no arguments are given, returns an empty block.
statements
- the GoloStatement
s composing the block.public void merge(Block other)
Warning:the statements contained in the other block being move to this one and not copied, the other block references statements but is no more their parent. Therefore, the other block is not in a consistent state and should be dropped, since no more needed.
public ReferenceTable getReferenceTable()
public java.util.Optional<ReferenceTable> getLocalReferenceTable()
getLocalReferenceTable
in class GoloElement<Block>
public Block ref(java.lang.Object referenceTable)
This is a builder method.
referenceTable
- the ReferenceTable
to use in this block.public void internReferenceTable()
public java.util.List<GoloStatement<?>> getStatements()
public java.util.Iterator<GoloStatement<?>> iterator()
iterator
in interface java.lang.Iterable<GoloStatement<?>>
public Block map(FunctionReference fun) throws java.lang.Throwable
java.lang.Throwable
public Block add(java.lang.Object statement)
This is a builder method.
statement
- the statement to add to this blockjava.lang.ClassCastException
- if the statement can't be converted into a GoloStatement
GoloStatement.of(Object)
public void flatten()
public boolean hasReturn()
public int size()
public boolean hasOnlyReturn()
public boolean hasOnlyExpression()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean isEmpty()
public void accept(GoloIrVisitor visitor)
This method should only call the visitor visitXXXX
method.
The children of this node will be visited by the
GoloElement.walk(GoloIrVisitor)
method.
accept
in class GoloElement<Block>
public void walk(GoloIrVisitor visitor)
walk
in class GoloElement<Block>
public java.util.List<GoloElement<?>> children()
children
in class GoloElement<Block>
protected void replaceElement(GoloElement<?> original, GoloElement<?> newElement)
Replace original
with newElement
if original
is a child of this node
and type matches.
replaceElement
in class GoloElement<Block>
original
- the original value to replace. Must be a child of this nodenewElement
- the element to replace with. Type must match.GoloElement.cantReplace()
,
GoloElement.cantReplace(GoloElement, GoloElement)
,
GoloElement.doesNotContain(GoloElement)
,
GoloElement.cantConvert(String, Object)