1 package org.simantics.scl.compiler.elaboration.expressions;
3 import org.simantics.scl.compiler.elaboration.equation.EqBasic;
4 import org.simantics.scl.compiler.elaboration.equation.EqGuard;
5 import org.simantics.scl.compiler.elaboration.equation.Equation;
6 import org.simantics.scl.compiler.elaboration.equation.EquationVisitor;
7 import org.simantics.scl.compiler.elaboration.expressions.accessor.ExpressionAccessor;
8 import org.simantics.scl.compiler.elaboration.expressions.accessor.FieldAccessor;
9 import org.simantics.scl.compiler.elaboration.expressions.block.BindStatement;
10 import org.simantics.scl.compiler.elaboration.expressions.block.GuardStatement;
11 import org.simantics.scl.compiler.elaboration.expressions.block.LetStatement;
12 import org.simantics.scl.compiler.elaboration.expressions.block.RuleStatement;
13 import org.simantics.scl.compiler.elaboration.expressions.block.Statement;
14 import org.simantics.scl.compiler.elaboration.expressions.block.StatementVisitor;
15 import org.simantics.scl.compiler.elaboration.expressions.list.ListAssignment;
16 import org.simantics.scl.compiler.elaboration.expressions.list.ListGenerator;
17 import org.simantics.scl.compiler.elaboration.expressions.list.ListGuard;
18 import org.simantics.scl.compiler.elaboration.expressions.list.ListQualifier;
19 import org.simantics.scl.compiler.elaboration.expressions.list.ListQualifierTransformer;
20 import org.simantics.scl.compiler.elaboration.expressions.list.ListSeq;
21 import org.simantics.scl.compiler.elaboration.expressions.list.ListThen;
22 import org.simantics.scl.compiler.elaboration.expressions.records.FieldAssignment;
23 import org.simantics.scl.compiler.elaboration.query.QAlternative;
24 import org.simantics.scl.compiler.elaboration.query.QAtom;
25 import org.simantics.scl.compiler.elaboration.query.QConjunction;
26 import org.simantics.scl.compiler.elaboration.query.QDisjunction;
27 import org.simantics.scl.compiler.elaboration.query.QExists;
28 import org.simantics.scl.compiler.elaboration.query.QIf;
29 import org.simantics.scl.compiler.elaboration.query.QMapping;
30 import org.simantics.scl.compiler.elaboration.query.QNegation;
31 import org.simantics.scl.compiler.elaboration.query.Query;
32 import org.simantics.scl.compiler.elaboration.query.pre.QPreBinds;
33 import org.simantics.scl.compiler.elaboration.query.pre.QPreEquals;
34 import org.simantics.scl.compiler.elaboration.query.pre.QPreExists;
35 import org.simantics.scl.compiler.elaboration.query.pre.QPreGuard;
37 public class StandardExpressionTransformer implements
38 ExpressionTransformer, QueryTransformer, ListQualifierTransformer, StatementVisitor,
42 public Expression transform(EApply expression) {
43 expression.function = expression.function.accept(this);
44 for(int i=0;i<expression.parameters.length;++i)
45 expression.parameters[i] = expression.parameters[i].accept(this);
50 public Expression transform(EApplyType expression) {
51 expression.expression = expression.expression.accept(this);
56 public Expression transform(EAsPattern expression) {
57 expression.pattern = expression.pattern.accept(this);
62 public Expression transform(EBinary expression) {
63 expression.left = expression.left.accept(this);
64 for(EBinaryRightSide rs : expression.rights)
65 rs.right = rs.right.accept(this);
70 public Expression transform(EBind expression) {
71 expression.pattern = expression.pattern.accept(this);
72 expression.value = expression.value.accept(this);
73 expression.in = expression.in.accept(this);
78 public Expression transform(EBlock expression) {
79 for(Statement statement : expression.statements)
80 statement.accept(this);
85 public void visit(BindStatement statement) {
86 statement.pattern = statement.pattern.accept(this);
87 statement.value = statement.value.accept(this);
91 public void visit(GuardStatement statement) {
92 statement.value = statement.value.accept(this);
96 public void visit(LetStatement statement) {
97 statement.pattern = statement.pattern.accept(this);
98 statement.value = statement.value.accept(this);
102 public void visit(RuleStatement statement) {
103 statement.head = statement.head.accept(this);
104 statement.body = statement.body.accept(this);
108 public Expression transform(EConstant expression) {
113 public Expression transform(EEnforce expression) {
114 expression.query = expression.query.accept(this);
119 public Expression transform(EEntityTypeAnnotation expression) {
120 expression.expression = expression.expression.accept(this);
121 if(expression.query != null)
122 expression.query = expression.query.accept(this);
127 public Expression transform(EError expression) {
132 public Expression transform(EExternalConstant expression) {
137 public Expression transform(EFieldAccess expression) {
138 expression.parent = expression.parent.accept(this);
139 for(FieldAccessor accessor : expression.accessors)
140 if(accessor instanceof ExpressionAccessor) {
141 ExpressionAccessor expAcc = (ExpressionAccessor)accessor;
142 expAcc.fieldName = expAcc.fieldName.accept(this);
148 public Expression transform(EGetConstraint expression) {
153 public Expression transform(EIf expression) {
154 expression.condition = expression.condition.accept(this);
155 expression.then_ = expression.then_.accept(this);
156 expression.else_ = expression.else_.accept(this);
161 public Expression transform(EIntegerLiteral expression) {
165 protected void transformCases(Case[] cases) {
166 for(Case case_ : cases) {
167 for(int i=0;i<case_.patterns.length;++i)
168 case_.patterns[i] = case_.patterns[i].accept(this);
169 case_.value = case_.value.accept(this);
174 public Expression transform(ELambda expression) {
175 transformCases(expression.cases);
180 public Expression transform(ELambdaType expression) {
181 expression.value = expression.value.accept(this);
186 public Expression transform(ELet expression) {
187 expression.in = expression.in.accept(this);
188 for(Assignment assign : expression.assignments) {
189 assign.pattern = assign.pattern.accept(this);
190 assign.value = assign.value.accept(this);
196 public Expression transform(EListComprehension expression) {
197 expression.head = expression.head.accept(this);
198 expression.qualifier = expression.qualifier.accept(this);
203 public Expression transform(EListLiteral expression) {
204 for(int i=0;i<expression.components.length;++i)
205 expression.components[i] = expression.components[i].accept(this);
210 public Expression transform(ELiteral expression) {
215 public Expression transform(EMatch expression) {
216 for(int i=0;i<expression.scrutinee.length;++i)
217 expression.scrutinee[i] = expression.scrutinee[i].accept(this);
218 transformCases(expression.cases);
223 public Expression transform(EPlaceholder expression) {
224 expression.expression = expression.expression.accept(this);
229 public Expression transform(EPreLet expression) {
230 for(LetStatement statement : expression.assignments) {
231 statement.pattern = statement.pattern.accept(this);
232 statement.value = statement.value.accept(this);
234 expression.in = expression.in.accept(this);
239 public Expression transform(EPreRuleset expression) {
240 for(RuleStatement rule : expression.statements) {
241 rule.body = rule.body.accept(this);
242 rule.head = rule.head.accept(this);
244 expression.in = expression.in.accept(this);
249 public Expression transform(ECoveringBranchPoint expression) {
250 expression.expression = expression.expression.accept(this);
255 public Expression transform(ERange expression) {
256 expression.from = expression.from.accept(this);
257 expression.to = expression.to.accept(this);
262 public Expression transform(ERealLiteral expression) {
267 public Expression transform(ERecord expression) {
268 for(FieldAssignment field : expression.fields)
269 if(field.value != null)
270 field.value = field.value.accept(this);
275 public Expression transform(ERuleset expression) {
276 for(ERuleset.DatalogRule rule : expression.rules) {
277 rule.body = rule.body.accept(this);
278 for(int i=0;i<rule.headParameters.length;++i)
279 rule.headParameters[i] = rule.headParameters[i].accept(this);
281 expression.in = expression.in.accept(this);
286 public Expression transform(ESelect expression) {
287 expression.query = expression.query.accept(this);
288 expression.expression = expression.expression.accept(this);
293 public Expression transform(ESimpleLambda expression) {
294 expression.value = expression.value.accept(this);
299 public Expression transform(ESimpleLet expression) {
300 expression.value = expression.value.accept(this);
301 expression.in = expression.in.accept(this);
306 public Expression transform(EStringLiteral expression) {
311 public Expression transform(ETransformation expression) {
312 expression.seed = expression.seed.accept(this);
317 public Expression transform(ETypeAnnotation expression) {
318 expression.value = expression.value.accept(this);
323 public Expression transform(EVar expression) {
328 public Expression transform(EVariable expression) {
333 public Expression transform(EWhen expression) {
334 expression.query = expression.query.accept(this);
335 expression.action = expression.action.accept(this);
340 public Expression transform(GuardedExpressionGroup expression) {
341 for(GuardedExpression ge : expression.expressions) {
342 for(int i=0;i<ge.guards.length;++i)
343 ge.guards[i] = ge.guards[i].accept(this);
344 ge.value = ge.value.accept(this);
350 public ListQualifier transform(ListAssignment qualifier) {
351 qualifier.pattern = qualifier.pattern.accept(this);
352 qualifier.value = qualifier.value.accept(this);
357 public ListQualifier transform(ListGenerator qualifier) {
358 qualifier.pattern = qualifier.pattern.accept(this);
359 qualifier.value = qualifier.value.accept(this);
364 public ListQualifier transform(ListGuard qualifier) {
365 qualifier.condition = qualifier.condition.accept(this);
370 public ListQualifier transform(ListSeq qualifier) {
371 qualifier.a = qualifier.a.accept(this);
372 qualifier.b = qualifier.b.accept(this);
377 public ListQualifier transform(ListThen qualifier) {
378 qualifier.left = qualifier.left.accept(this);
379 qualifier.transformer = qualifier.transformer.accept(this);
380 if(qualifier.by != null)
381 qualifier.by = qualifier.by.accept(this);
386 public Query transform(QAlternative query) {
387 for(int i=0;i<query.queries.length;++i)
388 query.queries[i] = query.queries[i].accept(this);
393 public Query transform(QAtom query) {
394 for(int i=0;i<query.parameters.length;++i)
395 query.parameters[i] = query.parameters[i].accept(this);
400 public Query transform(QConjunction query) {
401 for(int i=0;i<query.queries.length;++i)
402 query.queries[i] = query.queries[i].accept(this);
407 public Query transform(QDisjunction query) {
408 for(int i=0;i<query.queries.length;++i)
409 query.queries[i] = query.queries[i].accept(this);
414 public Query transform(QExists query) {
415 query.query = query.query.accept(this);
420 public Query transform(QIf query) {
421 query.condition = query.condition.accept(this);
422 query.thenQuery = query.thenQuery.accept(this);
423 query.elseQuery = query.elseQuery.accept(this);
428 public Query transform(QMapping query) {
429 for(int i=0;i<query.parameters.length;++i)
430 query.parameters[i] = query.parameters[i].accept(this);
435 public Query transform(QNegation query) {
436 query.query = query.query.accept(this);
441 public Query transform(QPreBinds query) {
442 query.left = query.left.accept(this);
443 query.right = query.right.accept(this);
448 public Query transform(QPreEquals query) {
449 query.left = query.left.accept(this);
450 query.right = query.right.accept(this);
455 public Query transform(QPreExists query) {
456 query.query = query.query.accept(this);
461 public Query transform(QPreGuard query) {
462 query.guard = query.guard.accept(this);
467 public Expression transform(EEquations expression) {
468 for(Equation equation : expression.equations)
469 equation.accept(this);
474 public void visit(EqBasic equation) {
475 equation.left = equation.left.accept(this);
476 equation.right = equation.right.accept(this);
480 public void visit(EqGuard equation) {
481 equation.guard = equation.guard.accept(this);