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.CHRQuery;
5 import org.simantics.scl.compiler.elaboration.chr.CHRRule;
6 import org.simantics.scl.compiler.elaboration.chr.CHRRuleset;
7 import org.simantics.scl.compiler.elaboration.equation.EqBasic;
8 import org.simantics.scl.compiler.elaboration.equation.EqGuard;
9 import org.simantics.scl.compiler.elaboration.equation.Equation;
10 import org.simantics.scl.compiler.elaboration.equation.EquationVisitor;
11 import org.simantics.scl.compiler.elaboration.expressions.accessor.ExpressionAccessor;
12 import org.simantics.scl.compiler.elaboration.expressions.block.BindStatement;
13 import org.simantics.scl.compiler.elaboration.expressions.block.CHRStatement;
14 import org.simantics.scl.compiler.elaboration.expressions.block.GuardStatement;
15 import org.simantics.scl.compiler.elaboration.expressions.block.IncludeStatement;
16 import org.simantics.scl.compiler.elaboration.expressions.block.LetStatement;
17 import org.simantics.scl.compiler.elaboration.expressions.block.RuleStatement;
18 import org.simantics.scl.compiler.elaboration.expressions.block.Statement;
19 import org.simantics.scl.compiler.elaboration.expressions.block.StatementVisitor;
20 import org.simantics.scl.compiler.elaboration.expressions.list.ListAssignment;
21 import org.simantics.scl.compiler.elaboration.expressions.list.ListGenerator;
22 import org.simantics.scl.compiler.elaboration.expressions.list.ListGuard;
23 import org.simantics.scl.compiler.elaboration.expressions.list.ListQualifier;
24 import org.simantics.scl.compiler.elaboration.expressions.list.ListQualifierTransformer;
25 import org.simantics.scl.compiler.elaboration.expressions.list.ListSeq;
26 import org.simantics.scl.compiler.elaboration.expressions.list.ListThen;
27 import org.simantics.scl.compiler.elaboration.expressions.records.FieldAssignment;
28 import org.simantics.scl.compiler.elaboration.query.QAlternative;
29 import org.simantics.scl.compiler.elaboration.query.QAtom;
30 import org.simantics.scl.compiler.elaboration.query.QConjunction;
31 import org.simantics.scl.compiler.elaboration.query.QDisjunction;
32 import org.simantics.scl.compiler.elaboration.query.QExists;
33 import org.simantics.scl.compiler.elaboration.query.QIf;
34 import org.simantics.scl.compiler.elaboration.query.QMapping;
35 import org.simantics.scl.compiler.elaboration.query.QNegation;
36 import org.simantics.scl.compiler.elaboration.query.Query;
37 import org.simantics.scl.compiler.elaboration.query.pre.QPreBinds;
38 import org.simantics.scl.compiler.elaboration.query.pre.QPreEquals;
39 import org.simantics.scl.compiler.elaboration.query.pre.QPreExists;
40 import org.simantics.scl.compiler.elaboration.query.pre.QPreGuard;
42 public class StandardExpressionTransformer implements
43 ExpressionTransformer, QueryTransformer, ListQualifierTransformer, StatementVisitor,
47 public Expression transform(EAmbiguous expression) {
52 public Expression transform(EApply expression) {
53 expression.function = expression.function.accept(this);
54 for(int i=0;i<expression.parameters.length;++i)
55 expression.parameters[i] = expression.parameters[i].accept(this);
60 public Expression transform(EApplyType expression) {
61 expression.expression = expression.expression.accept(this);
66 public Expression transform(EAsPattern expression) {
67 expression.pattern = expression.pattern.accept(this);
72 public Expression transform(EBinary expression) {
73 expression.left = expression.left.accept(this);
74 for(EBinaryRightSide rs : expression.rights)
75 rs.right = rs.right.accept(this);
80 public Expression transform(EBind expression) {
81 expression.pattern = expression.pattern.accept(this);
82 expression.value = expression.value.accept(this);
83 expression.in = expression.in.accept(this);
88 public Expression transform(EViewPattern expression) {
89 expression.expression = expression.expression.accept(this);
90 expression.pattern = expression.pattern.accept(this);
95 public Expression transform(EBlock expression) {
96 for(Statement statement : expression.statements)
97 statement.accept(this);
102 public void visit(BindStatement statement) {
103 statement.pattern = statement.pattern.accept(this);
104 statement.value = statement.value.accept(this);
108 public void visit(GuardStatement statement) {
109 statement.value = statement.value.accept(this);
113 public void visit(LetStatement statement) {
114 statement.pattern = statement.pattern.accept(this);
115 statement.value = statement.value.accept(this);
119 public void visit(RuleStatement statement) {
120 statement.head = statement.head.accept(this);
121 statement.body = statement.body.accept(this);
125 public void visit(IncludeStatement statement) {
126 statement.value = statement.value.accept(this);
129 public void transform(CHRQuery query) {
130 for(CHRLiteral lit : query.literals)
131 for(int i=0;i<lit.parameters.length;++i)
132 lit.parameters[i] = lit.parameters[i].accept(this);
135 public void transform(CHRRuleset ruleset) {
136 for(CHRRule rule : ruleset.rules) {
137 transform(rule.head);
138 transform(rule.body);
143 public Expression transform(ECHRRuleset expression) {
144 expression.in = expression.in.accept(this);
145 transform(expression.ruleset);
150 public Expression transform(ECHRSelect expression) {
151 expression.expression = expression.expression.accept(this);
152 transform(expression.query);
157 public Expression transform(ECHRRulesetConstructor expression) {
158 transform(expression.ruleset);
163 public Expression transform(EConstant expression) {
168 public Expression transform(EEnforce expression) {
169 expression.query = expression.query.accept(this);
174 public Expression transform(EError expression) {
179 public Expression transform(EExternalConstant expression) {
184 public Expression transform(EFieldAccess expression) {
185 expression.parent = expression.parent.accept(this);
186 if(expression.accessor instanceof ExpressionAccessor) {
187 ExpressionAccessor expAcc = (ExpressionAccessor)expression.accessor;
188 expAcc.fieldName = expAcc.fieldName.accept(this);
194 public Expression transform(EGetConstraint expression) {
199 public Expression transform(EIf expression) {
200 expression.condition = expression.condition.accept(this);
201 expression.then_ = expression.then_.accept(this);
202 if(expression.else_ != null)
203 expression.else_ = expression.else_.accept(this);
208 public Expression transform(EIntegerLiteral expression) {
212 protected void transformCases(Case[] cases) {
213 for(Case case_ : cases) {
214 for(int i=0;i<case_.patterns.length;++i)
215 case_.patterns[i] = case_.patterns[i].accept(this);
216 case_.value = case_.value.accept(this);
221 public Expression transform(ELambda expression) {
222 transformCases(expression.cases);
227 public Expression transform(ELambdaType expression) {
228 expression.value = expression.value.accept(this);
233 public Expression transform(ELet expression) {
234 expression.in = expression.in.accept(this);
235 for(Assignment assign : expression.assignments) {
236 assign.pattern = assign.pattern.accept(this);
237 assign.value = assign.value.accept(this);
243 public Expression transform(EListComprehension expression) {
244 expression.head = expression.head.accept(this);
245 expression.qualifier = expression.qualifier.accept(this);
250 public Expression transform(EListLiteral expression) {
251 for(int i=0;i<expression.components.length;++i)
252 expression.components[i] = expression.components[i].accept(this);
257 public Expression transform(ELiteral expression) {
262 public Expression transform(EMatch expression) {
263 for(int i=0;i<expression.scrutinee.length;++i)
264 expression.scrutinee[i] = expression.scrutinee[i].accept(this);
265 transformCases(expression.cases);
270 public Expression transform(EPlaceholder expression) {
271 expression.expression = expression.expression.accept(this);
276 public Expression transform(EPreLet expression) {
277 for(LetStatement statement : expression.assignments) {
278 statement.pattern = statement.pattern.accept(this);
279 statement.value = statement.value.accept(this);
281 expression.in = expression.in.accept(this);
286 public Expression transform(EPreRuleset expression) {
287 for(RuleStatement rule : expression.statements) {
288 rule.body = rule.body.accept(this);
289 rule.head = rule.head.accept(this);
291 expression.in = expression.in.accept(this);
296 public Expression transform(ECoveringBranchPoint expression) {
297 expression.expression = expression.expression.accept(this);
302 public Expression transform(ERange expression) {
303 expression.from = expression.from.accept(this);
304 expression.to = expression.to.accept(this);
309 public Expression transform(ERealLiteral expression) {
314 public Expression transform(ERecord expression) {
315 for(FieldAssignment field : expression.fields)
316 if(field.value != null)
317 field.value = field.value.accept(this);
322 public Expression transform(ERuleset expression) {
323 for(ERuleset.DatalogRule rule : expression.rules) {
324 rule.body = rule.body.accept(this);
325 for(int i=0;i<rule.headParameters.length;++i)
326 rule.headParameters[i] = rule.headParameters[i].accept(this);
328 expression.in = expression.in.accept(this);
333 public Expression transform(ESelect expression) {
334 expression.query = expression.query.accept(this);
335 expression.expression = expression.expression.accept(this);
340 public Expression transform(ESimpleLambda expression) {
341 expression.value = expression.value.accept(this);
346 public Expression transform(ESimpleLet expression) {
347 expression.value = expression.value.accept(this);
348 expression.in = expression.in.accept(this);
353 public Expression transform(EStringLiteral expression) {
358 public Expression transform(ETransformation expression) {
359 expression.seed = expression.seed.accept(this);
364 public Expression transform(ETypeAnnotation expression) {
365 expression.value = expression.value.accept(this);
370 public Expression transform(EVar expression) {
375 public Expression transform(EVariable expression) {
380 public Expression transform(EWhen expression) {
381 expression.query = expression.query.accept(this);
382 expression.action = expression.action.accept(this);
387 public Expression transform(GuardedExpressionGroup expression) {
388 for(GuardedExpression ge : expression.expressions) {
389 for(int i=0;i<ge.guards.length;++i)
390 ge.guards[i] = ge.guards[i].accept(this);
391 ge.value = ge.value.accept(this);
397 public ListQualifier transform(ListAssignment qualifier) {
398 qualifier.pattern = qualifier.pattern.accept(this);
399 qualifier.value = qualifier.value.accept(this);
404 public ListQualifier transform(ListGenerator qualifier) {
405 qualifier.pattern = qualifier.pattern.accept(this);
406 qualifier.value = qualifier.value.accept(this);
411 public ListQualifier transform(ListGuard qualifier) {
412 qualifier.condition = qualifier.condition.accept(this);
417 public ListQualifier transform(ListSeq qualifier) {
418 qualifier.a = qualifier.a.accept(this);
419 qualifier.b = qualifier.b.accept(this);
424 public ListQualifier transform(ListThen qualifier) {
425 qualifier.left = qualifier.left.accept(this);
426 qualifier.transformer = qualifier.transformer.accept(this);
427 if(qualifier.by != null)
428 qualifier.by = qualifier.by.accept(this);
433 public Query transform(QAlternative query) {
434 for(int i=0;i<query.queries.length;++i)
435 query.queries[i] = query.queries[i].accept(this);
440 public Query transform(QAtom query) {
441 for(int i=0;i<query.parameters.length;++i)
442 query.parameters[i] = query.parameters[i].accept(this);
447 public Query transform(QConjunction query) {
448 for(int i=0;i<query.queries.length;++i)
449 query.queries[i] = query.queries[i].accept(this);
454 public Query transform(QDisjunction query) {
455 for(int i=0;i<query.queries.length;++i)
456 query.queries[i] = query.queries[i].accept(this);
461 public Query transform(QExists query) {
462 query.query = query.query.accept(this);
467 public Query transform(QIf query) {
468 query.condition = query.condition.accept(this);
469 query.thenQuery = query.thenQuery.accept(this);
470 query.elseQuery = query.elseQuery.accept(this);
475 public Query transform(QMapping query) {
476 for(int i=0;i<query.parameters.length;++i)
477 query.parameters[i] = query.parameters[i].accept(this);
482 public Query transform(QNegation query) {
483 query.query = query.query.accept(this);
488 public Query transform(QPreBinds query) {
489 query.left = query.left.accept(this);
490 query.right = query.right.accept(this);
495 public Query transform(QPreEquals query) {
496 query.left = query.left.accept(this);
497 query.right = query.right.accept(this);
502 public Query transform(QPreExists query) {
503 query.query = query.query.accept(this);
508 public Query transform(QPreGuard query) {
509 query.guard = query.guard.accept(this);
514 public Expression transform(EEquations expression) {
515 for(Equation equation : expression.equations)
516 equation.accept(this);
521 public void visit(EqBasic equation) {
522 equation.left = equation.left.accept(this);
523 equation.right = equation.right.accept(this);
527 public void visit(EqGuard equation) {
528 equation.guard = equation.guard.accept(this);
532 public void visit(CHRStatement statement) {
533 for(int i=0;i<statement.body.length;++i)
534 statement.body[i] = statement.body[i].accept(this);
535 for(int i=0;i<statement.head.length;++i)
536 statement.head[i] = statement.head[i].accept(this);