1 package org.simantics.scl.compiler.elaboration.expressions;
3 import org.simantics.scl.compiler.elaboration.chr.CHRLiteral;
4 import org.simantics.scl.compiler.elaboration.chr.CHRRule;
5 import org.simantics.scl.compiler.elaboration.equation.EqBasic;
6 import org.simantics.scl.compiler.elaboration.equation.EqGuard;
7 import org.simantics.scl.compiler.elaboration.equation.Equation;
8 import org.simantics.scl.compiler.elaboration.equation.EquationVisitor;
9 import org.simantics.scl.compiler.elaboration.expressions.accessor.ExpressionAccessor;
10 import org.simantics.scl.compiler.elaboration.expressions.accessor.FieldAccessor;
11 import org.simantics.scl.compiler.elaboration.expressions.block.BindStatement;
12 import org.simantics.scl.compiler.elaboration.expressions.block.GuardStatement;
13 import org.simantics.scl.compiler.elaboration.expressions.block.LetStatement;
14 import org.simantics.scl.compiler.elaboration.expressions.block.RuleStatement;
15 import org.simantics.scl.compiler.elaboration.expressions.block.Statement;
16 import org.simantics.scl.compiler.elaboration.expressions.block.StatementVisitor;
17 import org.simantics.scl.compiler.elaboration.expressions.list.ListAssignment;
18 import org.simantics.scl.compiler.elaboration.expressions.list.ListGenerator;
19 import org.simantics.scl.compiler.elaboration.expressions.list.ListGuard;
20 import org.simantics.scl.compiler.elaboration.expressions.list.ListQualifier;
21 import org.simantics.scl.compiler.elaboration.expressions.list.ListQualifierTransformer;
22 import org.simantics.scl.compiler.elaboration.expressions.list.ListSeq;
23 import org.simantics.scl.compiler.elaboration.expressions.list.ListThen;
24 import org.simantics.scl.compiler.elaboration.expressions.records.FieldAssignment;
25 import org.simantics.scl.compiler.elaboration.query.QAlternative;
26 import org.simantics.scl.compiler.elaboration.query.QAtom;
27 import org.simantics.scl.compiler.elaboration.query.QConjunction;
28 import org.simantics.scl.compiler.elaboration.query.QDisjunction;
29 import org.simantics.scl.compiler.elaboration.query.QExists;
30 import org.simantics.scl.compiler.elaboration.query.QIf;
31 import org.simantics.scl.compiler.elaboration.query.QMapping;
32 import org.simantics.scl.compiler.elaboration.query.QNegation;
33 import org.simantics.scl.compiler.elaboration.query.Query;
34 import org.simantics.scl.compiler.elaboration.query.pre.QPreBinds;
35 import org.simantics.scl.compiler.elaboration.query.pre.QPreEquals;
36 import org.simantics.scl.compiler.elaboration.query.pre.QPreExists;
37 import org.simantics.scl.compiler.elaboration.query.pre.QPreGuard;
39 public class StandardExpressionTransformer implements
40 ExpressionTransformer, QueryTransformer, ListQualifierTransformer, StatementVisitor,
44 public Expression transform(EAmbiguous expression) {
49 public Expression transform(EApply expression) {
50 expression.function = expression.function.accept(this);
51 for(int i=0;i<expression.parameters.length;++i)
52 expression.parameters[i] = expression.parameters[i].accept(this);
57 public Expression transform(EApplyType expression) {
58 expression.expression = expression.expression.accept(this);
63 public Expression transform(EAsPattern expression) {
64 expression.pattern = expression.pattern.accept(this);
69 public Expression transform(EBinary expression) {
70 expression.left = expression.left.accept(this);
71 for(EBinaryRightSide rs : expression.rights)
72 rs.right = rs.right.accept(this);
77 public Expression transform(EBind expression) {
78 expression.pattern = expression.pattern.accept(this);
79 expression.value = expression.value.accept(this);
80 expression.in = expression.in.accept(this);
85 public Expression transform(EViewPattern expression) {
86 expression.expression = expression.expression.accept(this);
87 expression.pattern = expression.pattern.accept(this);
92 public Expression transform(EBlock expression) {
93 for(Statement statement : expression.statements)
94 statement.accept(this);
99 public void visit(BindStatement statement) {
100 statement.pattern = statement.pattern.accept(this);
101 statement.value = statement.value.accept(this);
105 public void visit(GuardStatement statement) {
106 statement.value = statement.value.accept(this);
110 public void visit(LetStatement statement) {
111 statement.pattern = statement.pattern.accept(this);
112 statement.value = statement.value.accept(this);
116 public void visit(RuleStatement statement) {
117 statement.head = statement.head.accept(this);
118 statement.body = statement.body.accept(this);
122 public Expression transform(ECHRRuleset expression) {
123 expression.in = expression.in.accept(this);
124 for(CHRRule rule : expression.ruleset.rules) {
125 for(CHRLiteral lit : rule.head.literals)
126 for(int i=0;i<lit.parameters.length;++i)
127 lit.parameters[i] = lit.parameters[i].accept(this);
128 for(CHRLiteral lit : rule.body.literals)
129 for(int i=0;i<lit.parameters.length;++i)
130 lit.parameters[i] = lit.parameters[i].accept(this);
136 public Expression transform(EConstant expression) {
141 public Expression transform(EEnforce expression) {
142 expression.query = expression.query.accept(this);
147 public Expression transform(EEntityTypeAnnotation expression) {
148 expression.expression = expression.expression.accept(this);
149 if(expression.query != null)
150 expression.query = expression.query.accept(this);
155 public Expression transform(EError expression) {
160 public Expression transform(EExternalConstant expression) {
165 public Expression transform(EFieldAccess expression) {
166 expression.parent = expression.parent.accept(this);
167 for(FieldAccessor accessor : expression.accessors)
168 if(accessor instanceof ExpressionAccessor) {
169 ExpressionAccessor expAcc = (ExpressionAccessor)accessor;
170 expAcc.fieldName = expAcc.fieldName.accept(this);
176 public Expression transform(EGetConstraint expression) {
181 public Expression transform(EIf expression) {
182 expression.condition = expression.condition.accept(this);
183 expression.then_ = expression.then_.accept(this);
184 if(expression.else_ != null)
185 expression.else_ = expression.else_.accept(this);
190 public Expression transform(EIntegerLiteral expression) {
194 protected void transformCases(Case[] cases) {
195 for(Case case_ : cases) {
196 for(int i=0;i<case_.patterns.length;++i)
197 case_.patterns[i] = case_.patterns[i].accept(this);
198 case_.value = case_.value.accept(this);
203 public Expression transform(ELambda expression) {
204 transformCases(expression.cases);
209 public Expression transform(ELambdaType expression) {
210 expression.value = expression.value.accept(this);
215 public Expression transform(ELet expression) {
216 expression.in = expression.in.accept(this);
217 for(Assignment assign : expression.assignments) {
218 assign.pattern = assign.pattern.accept(this);
219 assign.value = assign.value.accept(this);
225 public Expression transform(EListComprehension expression) {
226 expression.head = expression.head.accept(this);
227 expression.qualifier = expression.qualifier.accept(this);
232 public Expression transform(EListLiteral expression) {
233 for(int i=0;i<expression.components.length;++i)
234 expression.components[i] = expression.components[i].accept(this);
239 public Expression transform(ELiteral expression) {
244 public Expression transform(EMatch expression) {
245 for(int i=0;i<expression.scrutinee.length;++i)
246 expression.scrutinee[i] = expression.scrutinee[i].accept(this);
247 transformCases(expression.cases);
252 public Expression transform(EPlaceholder expression) {
253 expression.expression = expression.expression.accept(this);
258 public Expression transform(EPreLet expression) {
259 for(LetStatement statement : expression.assignments) {
260 statement.pattern = statement.pattern.accept(this);
261 statement.value = statement.value.accept(this);
263 expression.in = expression.in.accept(this);
268 public Expression transform(EPreRuleset expression) {
269 for(RuleStatement rule : expression.statements) {
270 rule.body = rule.body.accept(this);
271 rule.head = rule.head.accept(this);
273 expression.in = expression.in.accept(this);
278 public Expression transform(ECoveringBranchPoint expression) {
279 expression.expression = expression.expression.accept(this);
284 public Expression transform(ERange expression) {
285 expression.from = expression.from.accept(this);
286 expression.to = expression.to.accept(this);
291 public Expression transform(ERealLiteral expression) {
296 public Expression transform(ERecord expression) {
297 for(FieldAssignment field : expression.fields)
298 if(field.value != null)
299 field.value = field.value.accept(this);
304 public Expression transform(ERuleset expression) {
305 for(ERuleset.DatalogRule rule : expression.rules) {
306 rule.body = rule.body.accept(this);
307 for(int i=0;i<rule.headParameters.length;++i)
308 rule.headParameters[i] = rule.headParameters[i].accept(this);
310 expression.in = expression.in.accept(this);
315 public Expression transform(ESelect expression) {
316 expression.query = expression.query.accept(this);
317 expression.expression = expression.expression.accept(this);
322 public Expression transform(ESimpleLambda expression) {
323 expression.value = expression.value.accept(this);
328 public Expression transform(ESimpleLet expression) {
329 expression.value = expression.value.accept(this);
330 expression.in = expression.in.accept(this);
335 public Expression transform(EStringLiteral expression) {
340 public Expression transform(ETransformation expression) {
341 expression.seed = expression.seed.accept(this);
346 public Expression transform(ETypeAnnotation expression) {
347 expression.value = expression.value.accept(this);
352 public Expression transform(EVar expression) {
357 public Expression transform(EVariable expression) {
362 public Expression transform(EWhen expression) {
363 expression.query = expression.query.accept(this);
364 expression.action = expression.action.accept(this);
369 public Expression transform(GuardedExpressionGroup expression) {
370 for(GuardedExpression ge : expression.expressions) {
371 for(int i=0;i<ge.guards.length;++i)
372 ge.guards[i] = ge.guards[i].accept(this);
373 ge.value = ge.value.accept(this);
379 public ListQualifier transform(ListAssignment qualifier) {
380 qualifier.pattern = qualifier.pattern.accept(this);
381 qualifier.value = qualifier.value.accept(this);
386 public ListQualifier transform(ListGenerator qualifier) {
387 qualifier.pattern = qualifier.pattern.accept(this);
388 qualifier.value = qualifier.value.accept(this);
393 public ListQualifier transform(ListGuard qualifier) {
394 qualifier.condition = qualifier.condition.accept(this);
399 public ListQualifier transform(ListSeq qualifier) {
400 qualifier.a = qualifier.a.accept(this);
401 qualifier.b = qualifier.b.accept(this);
406 public ListQualifier transform(ListThen qualifier) {
407 qualifier.left = qualifier.left.accept(this);
408 qualifier.transformer = qualifier.transformer.accept(this);
409 if(qualifier.by != null)
410 qualifier.by = qualifier.by.accept(this);
415 public Query transform(QAlternative query) {
416 for(int i=0;i<query.queries.length;++i)
417 query.queries[i] = query.queries[i].accept(this);
422 public Query transform(QAtom query) {
423 for(int i=0;i<query.parameters.length;++i)
424 query.parameters[i] = query.parameters[i].accept(this);
429 public Query transform(QConjunction query) {
430 for(int i=0;i<query.queries.length;++i)
431 query.queries[i] = query.queries[i].accept(this);
436 public Query transform(QDisjunction query) {
437 for(int i=0;i<query.queries.length;++i)
438 query.queries[i] = query.queries[i].accept(this);
443 public Query transform(QExists query) {
444 query.query = query.query.accept(this);
449 public Query transform(QIf query) {
450 query.condition = query.condition.accept(this);
451 query.thenQuery = query.thenQuery.accept(this);
452 query.elseQuery = query.elseQuery.accept(this);
457 public Query transform(QMapping query) {
458 for(int i=0;i<query.parameters.length;++i)
459 query.parameters[i] = query.parameters[i].accept(this);
464 public Query transform(QNegation query) {
465 query.query = query.query.accept(this);
470 public Query transform(QPreBinds query) {
471 query.left = query.left.accept(this);
472 query.right = query.right.accept(this);
477 public Query transform(QPreEquals query) {
478 query.left = query.left.accept(this);
479 query.right = query.right.accept(this);
484 public Query transform(QPreExists query) {
485 query.query = query.query.accept(this);
490 public Query transform(QPreGuard query) {
491 query.guard = query.guard.accept(this);
496 public Expression transform(EEquations expression) {
497 for(Equation equation : expression.equations)
498 equation.accept(this);
503 public void visit(EqBasic equation) {
504 equation.left = equation.left.accept(this);
505 equation.right = equation.right.accept(this);
509 public void visit(EqGuard equation) {
510 equation.guard = equation.guard.accept(this);