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(EAmbiguous expression) {
47 public Expression transform(EApply expression) {
48 expression.function = expression.function.accept(this);
49 for(int i=0;i<expression.parameters.length;++i)
50 expression.parameters[i] = expression.parameters[i].accept(this);
55 public Expression transform(EApplyType expression) {
56 expression.expression = expression.expression.accept(this);
61 public Expression transform(EAsPattern expression) {
62 expression.pattern = expression.pattern.accept(this);
67 public Expression transform(EBinary expression) {
68 expression.left = expression.left.accept(this);
69 for(EBinaryRightSide rs : expression.rights)
70 rs.right = rs.right.accept(this);
75 public Expression transform(EBind expression) {
76 expression.pattern = expression.pattern.accept(this);
77 expression.value = expression.value.accept(this);
78 expression.in = expression.in.accept(this);
83 public Expression transform(EBlock expression) {
84 for(Statement statement : expression.statements)
85 statement.accept(this);
90 public void visit(BindStatement statement) {
91 statement.pattern = statement.pattern.accept(this);
92 statement.value = statement.value.accept(this);
96 public void visit(GuardStatement statement) {
97 statement.value = statement.value.accept(this);
101 public void visit(LetStatement statement) {
102 statement.pattern = statement.pattern.accept(this);
103 statement.value = statement.value.accept(this);
107 public void visit(RuleStatement statement) {
108 statement.head = statement.head.accept(this);
109 statement.body = statement.body.accept(this);
113 public Expression transform(EConstant expression) {
118 public Expression transform(EEnforce expression) {
119 expression.query = expression.query.accept(this);
124 public Expression transform(EEntityTypeAnnotation expression) {
125 expression.expression = expression.expression.accept(this);
126 if(expression.query != null)
127 expression.query = expression.query.accept(this);
132 public Expression transform(EError expression) {
137 public Expression transform(EExternalConstant expression) {
142 public Expression transform(EFieldAccess expression) {
143 expression.parent = expression.parent.accept(this);
144 for(FieldAccessor accessor : expression.accessors)
145 if(accessor instanceof ExpressionAccessor) {
146 ExpressionAccessor expAcc = (ExpressionAccessor)accessor;
147 expAcc.fieldName = expAcc.fieldName.accept(this);
153 public Expression transform(EGetConstraint expression) {
158 public Expression transform(EIf expression) {
159 expression.condition = expression.condition.accept(this);
160 expression.then_ = expression.then_.accept(this);
161 expression.else_ = expression.else_.accept(this);
166 public Expression transform(EIntegerLiteral expression) {
170 protected void transformCases(Case[] cases) {
171 for(Case case_ : cases) {
172 for(int i=0;i<case_.patterns.length;++i)
173 case_.patterns[i] = case_.patterns[i].accept(this);
174 case_.value = case_.value.accept(this);
179 public Expression transform(ELambda expression) {
180 transformCases(expression.cases);
185 public Expression transform(ELambdaType expression) {
186 expression.value = expression.value.accept(this);
191 public Expression transform(ELet expression) {
192 expression.in = expression.in.accept(this);
193 for(Assignment assign : expression.assignments) {
194 assign.pattern = assign.pattern.accept(this);
195 assign.value = assign.value.accept(this);
201 public Expression transform(EListComprehension expression) {
202 expression.head = expression.head.accept(this);
203 expression.qualifier = expression.qualifier.accept(this);
208 public Expression transform(EListLiteral expression) {
209 for(int i=0;i<expression.components.length;++i)
210 expression.components[i] = expression.components[i].accept(this);
215 public Expression transform(ELiteral expression) {
220 public Expression transform(EMatch expression) {
221 for(int i=0;i<expression.scrutinee.length;++i)
222 expression.scrutinee[i] = expression.scrutinee[i].accept(this);
223 transformCases(expression.cases);
228 public Expression transform(EPlaceholder expression) {
229 expression.expression = expression.expression.accept(this);
234 public Expression transform(EPreLet expression) {
235 for(LetStatement statement : expression.assignments) {
236 statement.pattern = statement.pattern.accept(this);
237 statement.value = statement.value.accept(this);
239 expression.in = expression.in.accept(this);
244 public Expression transform(EPreRuleset expression) {
245 for(RuleStatement rule : expression.statements) {
246 rule.body = rule.body.accept(this);
247 rule.head = rule.head.accept(this);
249 expression.in = expression.in.accept(this);
254 public Expression transform(ECoveringBranchPoint expression) {
255 expression.expression = expression.expression.accept(this);
260 public Expression transform(ERange expression) {
261 expression.from = expression.from.accept(this);
262 expression.to = expression.to.accept(this);
267 public Expression transform(ERealLiteral expression) {
272 public Expression transform(ERecord expression) {
273 for(FieldAssignment field : expression.fields)
274 if(field.value != null)
275 field.value = field.value.accept(this);
280 public Expression transform(ERuleset expression) {
281 for(ERuleset.DatalogRule rule : expression.rules) {
282 rule.body = rule.body.accept(this);
283 for(int i=0;i<rule.headParameters.length;++i)
284 rule.headParameters[i] = rule.headParameters[i].accept(this);
286 expression.in = expression.in.accept(this);
291 public Expression transform(ESelect expression) {
292 expression.query = expression.query.accept(this);
293 expression.expression = expression.expression.accept(this);
298 public Expression transform(ESimpleLambda expression) {
299 expression.value = expression.value.accept(this);
304 public Expression transform(ESimpleLet expression) {
305 expression.value = expression.value.accept(this);
306 expression.in = expression.in.accept(this);
311 public Expression transform(EStringLiteral expression) {
316 public Expression transform(ETransformation expression) {
317 expression.seed = expression.seed.accept(this);
322 public Expression transform(ETypeAnnotation expression) {
323 expression.value = expression.value.accept(this);
328 public Expression transform(EVar expression) {
333 public Expression transform(EVariable expression) {
338 public Expression transform(EWhen expression) {
339 expression.query = expression.query.accept(this);
340 expression.action = expression.action.accept(this);
345 public Expression transform(GuardedExpressionGroup expression) {
346 for(GuardedExpression ge : expression.expressions) {
347 for(int i=0;i<ge.guards.length;++i)
348 ge.guards[i] = ge.guards[i].accept(this);
349 ge.value = ge.value.accept(this);
355 public ListQualifier transform(ListAssignment qualifier) {
356 qualifier.pattern = qualifier.pattern.accept(this);
357 qualifier.value = qualifier.value.accept(this);
362 public ListQualifier transform(ListGenerator qualifier) {
363 qualifier.pattern = qualifier.pattern.accept(this);
364 qualifier.value = qualifier.value.accept(this);
369 public ListQualifier transform(ListGuard qualifier) {
370 qualifier.condition = qualifier.condition.accept(this);
375 public ListQualifier transform(ListSeq qualifier) {
376 qualifier.a = qualifier.a.accept(this);
377 qualifier.b = qualifier.b.accept(this);
382 public ListQualifier transform(ListThen qualifier) {
383 qualifier.left = qualifier.left.accept(this);
384 qualifier.transformer = qualifier.transformer.accept(this);
385 if(qualifier.by != null)
386 qualifier.by = qualifier.by.accept(this);
391 public Query transform(QAlternative query) {
392 for(int i=0;i<query.queries.length;++i)
393 query.queries[i] = query.queries[i].accept(this);
398 public Query transform(QAtom query) {
399 for(int i=0;i<query.parameters.length;++i)
400 query.parameters[i] = query.parameters[i].accept(this);
405 public Query transform(QConjunction query) {
406 for(int i=0;i<query.queries.length;++i)
407 query.queries[i] = query.queries[i].accept(this);
412 public Query transform(QDisjunction query) {
413 for(int i=0;i<query.queries.length;++i)
414 query.queries[i] = query.queries[i].accept(this);
419 public Query transform(QExists query) {
420 query.query = query.query.accept(this);
425 public Query transform(QIf query) {
426 query.condition = query.condition.accept(this);
427 query.thenQuery = query.thenQuery.accept(this);
428 query.elseQuery = query.elseQuery.accept(this);
433 public Query transform(QMapping query) {
434 for(int i=0;i<query.parameters.length;++i)
435 query.parameters[i] = query.parameters[i].accept(this);
440 public Query transform(QNegation query) {
441 query.query = query.query.accept(this);
446 public Query transform(QPreBinds query) {
447 query.left = query.left.accept(this);
448 query.right = query.right.accept(this);
453 public Query transform(QPreEquals query) {
454 query.left = query.left.accept(this);
455 query.right = query.right.accept(this);
460 public Query transform(QPreExists query) {
461 query.query = query.query.accept(this);
466 public Query transform(QPreGuard query) {
467 query.guard = query.guard.accept(this);
472 public Expression transform(EEquations expression) {
473 for(Equation equation : expression.equations)
474 equation.accept(this);
479 public void visit(EqBasic equation) {
480 equation.left = equation.left.accept(this);
481 equation.right = equation.right.accept(this);
485 public void visit(EqGuard equation) {
486 equation.guard = equation.guard.accept(this);