public class SugarExpansionVisitor extends AbstractGoloIrVisitor
Modify the IR to transform some nodes, in order to expand syntactic sugar, such as case and match statements, foreach loops, list comprehension, and so on.
| Constructor and Description |
|---|
SugarExpansionVisitor() |
| Modifier and Type | Method and Description |
|---|---|
void |
visitBinaryOperation(BinaryOperation op) |
void |
visitBlock(Block block)
Generate the local function corresponding to this closure.
|
void |
visitCaseStatement(CaseStatement caseStatement)
Case expansion.
|
void |
visitClosureReference(ClosureReference closure) |
void |
visitCollectionComprehension(CollectionComprehension collection)
Collection comprehension expansion.
|
void |
visitCollectionLiteral(CollectionLiteral collection)
Literal expansion.
|
void |
visitConstantStatement(ConstantStatement constantStatement)
Converts a literal function reference into a call to
Predefined.fun. |
void |
visitDestructuringAssignment(DestructuringAssignment assignment)
Destructuring assignment expansion.
|
void |
visitForEachLoopStatement(ForEachLoopStatement foreachStatement)
ForEach expansion.
|
void |
visitFunction(GoloFunction function) |
void |
visitFunctionInvocation(FunctionInvocation fun) |
void |
visitMatchExpression(MatchExpression matchExpression)
Match expansion.
|
void |
visitMethodInvocation(MethodInvocation invoke) |
void |
visitModule(GoloModule module) |
void |
visitReferenceLookup(ReferenceLookup ref) |
void |
visitReturnStatement(ReturnStatement ret)
Special returned values.
|
void |
visitStruct(Struct struct)
Add struct factories if they don't already exist.
|
void |
visitTryCatchFinally(TryCatchFinally tryCatchFinally) |
void |
visitUnaryOperation(UnaryOperation op) |
visitAssignmentStatement, visitAugmentation, visitConditionalBranching, visitDecorator, visitLocalReference, visitLoopBreakFlowStatement, visitLoopStatement, visitMacroInvocation, visitMember, visitModuleImport, visitNamedArgument, visitNamedAugmentation, visitNoop, visitThrowStatement, visitToplevelElements, visitUnion, visitUnionValue, visitWhenClausepublic SugarExpansionVisitor()
public void visitModule(GoloModule module)
visitModule in interface GoloIrVisitorvisitModule in class AbstractGoloIrVisitorpublic void visitBlock(Block block)
visitBlock in interface GoloIrVisitorvisitBlock in class AbstractGoloIrVisitorpublic void visitClosureReference(ClosureReference closure)
visitClosureReference in interface GoloIrVisitorvisitClosureReference in class AbstractGoloIrVisitorpublic void visitFunction(GoloFunction function)
visitFunction in interface GoloIrVisitorvisitFunction in class AbstractGoloIrVisitorpublic void visitCaseStatement(CaseStatement caseStatement)
Convert a CaseStatement node into a imbrication of ConditionalBranching, and
replace it in the parent node.
For instance:
case {
when cond1 { block1 }
when cond2 { block2 }
otherwise { block3 }
}
is converted into the equivalent of
if cond1 { block1 }
else if cond2 { block2 }
else { block3 }
visitCaseStatement in interface GoloIrVisitorvisitCaseStatement in class AbstractGoloIrVisitorpublic void visitMatchExpression(MatchExpression matchExpression)
Convert a MatchExpression node into a block containing a CaseStatement.
For instance
match {
when cond1 then val1
when cond2 then val2
otherwise val3
}
is converted into the equivalent of
tmp = null
case {
when cond1 { tmp = val1 }
when cond2 { tmp = val2 }
otherwise { tmp = val3 }
}
tmp
visitMatchExpression in interface GoloIrVisitorvisitMatchExpression in class AbstractGoloIrVisitorpublic void visitReturnStatement(ReturnStatement ret)
Deal with special return cases:
MatchExpression, convert it to a
CaseStatement containing ReturnStatement instead of assignments.
For instance
return match {
when cond1 then val1
when cond2 then val2
otherwise val3
}
is converted into the equivalent of
case {
when cond1 {
return val1
}
when cond2 {
return val2
}
otherwise {
return val3
}
}
This will allows for better optimisations (e.g. TCE).
visitReturnStatement in interface GoloIrVisitorvisitReturnStatement in class AbstractGoloIrVisitorpublic void visitCollectionLiteral(CollectionLiteral collection)
Converts a collection literal into a call to gololang.Predefined.<type>.
visitCollectionLiteral in interface GoloIrVisitorvisitCollectionLiteral in class AbstractGoloIrVisitorpublic void visitConstantStatement(ConstantStatement constantStatement)
Predefined.fun.visitConstantStatement in interface GoloIrVisitorvisitConstantStatement in class AbstractGoloIrVisitorpublic void visitCollectionComprehension(CollectionComprehension collection)
Convert a list comprehension expression into a block initialising a collection from nested loops defined in the comprehension. For instance
list[ f(x, y) foreach x in col1 foreach y in col2 ]
is converted to the equivalent of
let collection = list[]
foreach x in col1 {
foreach y in col2 {
collection: add(f(x, y))
}
}
visitCollectionComprehension in interface GoloIrVisitorvisitCollectionComprehension in class AbstractGoloIrVisitorpublic void visitForEachLoopStatement(ForEachLoopStatement foreachStatement)
Convert a ForEachLoopStatement into a loop using the associated iterator.
For instance:
foreach x in expr {
block
}
is converted to:
for (__$$_iterator_0 = expr: iterator(), __$$_iterator_0: hasNext(),) {
let x = __$$_iterator_0: next()
block
}
visitForEachLoopStatement in interface GoloIrVisitorvisitForEachLoopStatement in class AbstractGoloIrVisitorpublic void visitDestructuringAssignment(DestructuringAssignment assignment)
visitDestructuringAssignment in interface GoloIrVisitorvisitDestructuringAssignment in class AbstractGoloIrVisitorpublic void visitStruct(Struct struct)
visitStruct in interface GoloIrVisitorvisitStruct in class AbstractGoloIrVisitorpublic void visitBinaryOperation(BinaryOperation op)
visitBinaryOperation in interface GoloIrVisitorvisitBinaryOperation in class AbstractGoloIrVisitorpublic void visitUnaryOperation(UnaryOperation op)
visitUnaryOperation in interface GoloIrVisitorvisitUnaryOperation in class AbstractGoloIrVisitorpublic void visitReferenceLookup(ReferenceLookup ref)
visitReferenceLookup in interface GoloIrVisitorvisitReferenceLookup in class AbstractGoloIrVisitorpublic void visitFunctionInvocation(FunctionInvocation fun)
visitFunctionInvocation in interface GoloIrVisitorvisitFunctionInvocation in class AbstractGoloIrVisitorpublic void visitMethodInvocation(MethodInvocation invoke)
visitMethodInvocation in interface GoloIrVisitorvisitMethodInvocation in class AbstractGoloIrVisitorpublic void visitTryCatchFinally(TryCatchFinally tryCatchFinally)
visitTryCatchFinally in interface GoloIrVisitorvisitTryCatchFinally in class AbstractGoloIrVisitor