public final class Visitors extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Visitors.DispatchIrVisitor
A special adapter class to ease the creation of IR visitors in Golo.
|
static class |
Visitors.Walk
Define how to walk the tree.
|
Modifier and Type | Method and Description |
---|---|
static Visitors.DispatchIrVisitor |
visitor(FunctionReference function)
Creates a visitor from a unique function.
|
static Visitors.DispatchIrVisitor |
visitor(FunctionReference fun,
Visitors.Walk walk)
Creates a visitor from a unique function.
|
static GoloIrVisitor |
visitor(java.util.Map<java.lang.Class<? extends GoloElement<?>>,FunctionReference> functions)
Creates a visitor from a map of functions.
|
static Visitors.DispatchIrVisitor |
visitor(java.util.Map<java.lang.Class<? extends GoloElement<?>>,FunctionReference> functions,
FunctionReference defaultFunction,
Visitors.Walk walk)
Creates a visitor from a map of functions.
|
public static GoloIrVisitor visitor(java.util.Map<java.lang.Class<? extends GoloElement<?>>,FunctionReference> functions)
This is the same as visitor(functions, null, Walk.PREFIX)
.
public static Visitors.DispatchIrVisitor visitor(java.util.Map<java.lang.Class<? extends GoloElement<?>>,FunctionReference> functions, FunctionReference defaultFunction, Visitors.Walk walk)
The resulting visitor will use the function corresponding to the class of the element to visit. If the class is
not in the map, the default function will be used. If the function is null
, no action will be taken for
the node, but the subtree will be walked if required, according to the walk
parameter.
For instance, the function:
function numberOfAssignement = |irTree| -> Visitors.visitor!(
map[
[AssignmentStatement.class, |acc, elt| -> acc + 1],
[DestructuringAssignment.class, |acc, elt| -> acc + elt: referencesCount()]
],
|acc, elt| -> acc,
Visitors$Walk.PREFIX())
: apply(0, irTree)
counts the number of assignment in an IR tree.functions
- a map from IR classes to the golo functionsdefaultFunction
- the function to apply if the class of the element is not in the map.walk
- when to walk the treepublic static Visitors.DispatchIrVisitor visitor(FunctionReference fun, Visitors.Walk walk)
The resulting visitor will use the given function on each element. It is therefore the function responsibility to match on the element type if necessary.
For instance, the function:
function numberOfAssignement = |irTree| -> Visitors.visitor!(|acc, elt| -> match {
when elt oftype AssignmentStatement.class then acc + 1
when elt oftype DestructuringAssignment.class then acc + elt: referencesCount()
otherwise acc
}, Visitors$Walk.PREFIX())
: apply(0, irTree)
counts the number of assignment in an IR tree.fun
- the golo function to apply to elements in the treewalk
- when to walk the treepublic static Visitors.DispatchIrVisitor visitor(FunctionReference function)
This is the same as visitor(function, Walk.PREFIX)
.