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.chr.ast.CHRAstAtom;
8 import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstBinds;
9 import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstConjunction;
10 import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstEquals;
11 import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstNegation;
12 import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstQuery;
13 import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstQueryVisitor;
14 import org.simantics.scl.compiler.elaboration.equation.EqBasic;
15 import org.simantics.scl.compiler.elaboration.equation.EqGuard;
16 import org.simantics.scl.compiler.elaboration.equation.Equation;
17 import org.simantics.scl.compiler.elaboration.equation.EquationVisitor;
18 import org.simantics.scl.compiler.elaboration.expressions.ERuleset.DatalogRule;
19 import org.simantics.scl.compiler.elaboration.expressions.accessor.ExpressionAccessor;
20 import org.simantics.scl.compiler.elaboration.expressions.accessor.FieldAccessorVisitor;
21 import org.simantics.scl.compiler.elaboration.expressions.accessor.IdAccessor;
22 import org.simantics.scl.compiler.elaboration.expressions.accessor.StringAccessor;
23 import org.simantics.scl.compiler.elaboration.expressions.block.BindStatement;
24 import org.simantics.scl.compiler.elaboration.expressions.block.CHRStatement;
25 import org.simantics.scl.compiler.elaboration.expressions.block.GuardStatement;
26 import org.simantics.scl.compiler.elaboration.expressions.block.IncludeStatement;
27 import org.simantics.scl.compiler.elaboration.expressions.block.LetStatement;
28 import org.simantics.scl.compiler.elaboration.expressions.block.RuleStatement;
29 import org.simantics.scl.compiler.elaboration.expressions.block.Statement;
30 import org.simantics.scl.compiler.elaboration.expressions.block.StatementVisitor;
31 import org.simantics.scl.compiler.elaboration.expressions.list.ListAssignment;
32 import org.simantics.scl.compiler.elaboration.expressions.list.ListGenerator;
33 import org.simantics.scl.compiler.elaboration.expressions.list.ListGuard;
34 import org.simantics.scl.compiler.elaboration.expressions.list.ListQualifierVisitor;
35 import org.simantics.scl.compiler.elaboration.expressions.list.ListSeq;
36 import org.simantics.scl.compiler.elaboration.expressions.list.ListThen;
37 import org.simantics.scl.compiler.elaboration.expressions.records.FieldAssignment;
38 import org.simantics.scl.compiler.elaboration.query.QAlternative;
39 import org.simantics.scl.compiler.elaboration.query.QAtom;
40 import org.simantics.scl.compiler.elaboration.query.QConjunction;
41 import org.simantics.scl.compiler.elaboration.query.QDisjunction;
42 import org.simantics.scl.compiler.elaboration.query.QExists;
43 import org.simantics.scl.compiler.elaboration.query.QIf;
44 import org.simantics.scl.compiler.elaboration.query.QMapping;
45 import org.simantics.scl.compiler.elaboration.query.QNegation;
46 import org.simantics.scl.compiler.elaboration.query.Query;
47 import org.simantics.scl.compiler.elaboration.query.QueryVisitor;
50 public class StandardExpressionVisitor implements
51 ExpressionVisitor, QueryVisitor, FieldAccessorVisitor, ListQualifierVisitor,
52 EquationVisitor, StatementVisitor, CHRAstQueryVisitor {
55 public void visit(EApply expression) {
56 expression.function.accept(this);
57 for(Expression parameter : expression.parameters)
58 parameter.accept(this);
62 public void visit(EApplyType expression) {
63 expression.expression.accept(this);
67 public void visit(EAsPattern expression) {
68 expression.pattern.accept(this);
72 public void visit(EBind expression) {
73 expression.pattern.accept(this);
74 expression.value.accept(this);
75 expression.in.accept(this);
76 if(expression.monadEvidence != null)
77 visit(expression.monadEvidence);
81 public void visit(EConstant expression) {
85 public void visit(EEnforce expression) {
86 expression.query.accept(this);
90 public void visit(EError expression) {
94 public void visit(EExternalConstant expression) {
98 public void visit(EFieldAccess expression) {
99 expression.parent.accept(this);
100 expression.accessor.accept(this);
104 public void visit(EGetConstraint expression) {
105 if(expression.evidence != null)
106 expression.evidence.accept(this);
110 public void visit(EIf expression) {
111 expression.condition.accept(this);
112 expression.then_.accept(this);
113 if(expression.else_ != null)
114 expression.else_.accept(this);
118 public void visit(EIntegerLiteral expression) {
119 if(expression.constraint != null)
120 expression.constraint.accept(this);
124 public void visit(ELambda expression) {
125 for(Case case_ : expression.cases)
130 public void visit(EViewPattern expression) {
131 expression.expression.accept(this);
132 expression.pattern.accept(this);
135 public void visit(Case case_) {
136 for(Expression pattern : case_.patterns)
137 pattern.accept(this);
138 case_.value.accept(this);
142 public void visit(ELambdaType expression) {
143 expression.value.accept(this);
147 public void visit(ELet expression) {
148 for(Assignment assignment : expression.assignments)
150 expression.in.accept(this);
153 public void visit(Assignment assignment) {
154 assignment.pattern.accept(this);
155 assignment.value.accept(this);
159 public void visit(EListComprehension expression) {
160 expression.head.accept(this);
161 expression.qualifier.accept(this);
165 public void visit(EListLiteral expression) {
166 for(Expression component : expression.components)
167 component.accept(this);
171 public void visit(ELiteral expression) {
175 public void visit(EMatch expression) {
176 for(Expression s : expression.scrutinee)
178 for(Case case_ : expression.cases)
183 public void visit(EPlaceholder expression) {
184 expression.expression.accept(this);
188 public void visit(ERealLiteral expression) {
189 if(expression.constraint != null)
190 expression.constraint.accept(this);
194 public void visit(ERuleset expression) {
195 for(DatalogRule rule : expression.rules)
197 expression.in.accept(this);
200 public void visit(DatalogRule rule) {
201 for(Expression parameter : rule.headParameters)
202 parameter.accept(this);
203 rule.body.accept(this);
207 public void visit(ESelect expression) {
208 expression.query.accept(this);
209 expression.expression.accept(this);
213 public void visit(ECHRSelect expression) {
214 visit(expression.query);
215 expression.expression.accept(this);
219 public void visit(ESimpleLambda expression) {
220 expression.value.accept(this);
224 public void visit(ESimpleLet expression) {
225 expression.value.accept(this);
226 expression.in.accept(this);
230 public void visit(ETransformation expression) {
231 expression.seed.accept(this);
235 public void visit(ETypeAnnotation expression) {
236 expression.value.accept(this);
240 public void visit(EVar expression) {
244 public void visit(EVariable expression) {
248 public void visit(EWhen expression) {
249 expression.query.accept(this);
250 expression.action.accept(this);
254 public void visit(GuardedExpressionGroup expression) {
255 for(GuardedExpression gexp : expression.expressions) {
256 for(Expression guard : gexp.guards)
258 gexp.value.accept(this);
263 public void visit(QAlternative query) {
264 for(Query q : query.queries)
269 public void visit(QAtom query) {
270 for(Expression parameter : query.parameters)
271 parameter.accept(this);
275 public void visit(QMapping query) {
276 for(Expression parameter : query.parameters)
277 parameter.accept(this);
281 public void visit(QConjunction query) {
282 for(Query q : query.queries)
287 public void visit(QDisjunction query) {
288 for(Query q : query.queries)
293 public void visit(QExists query) {
294 query.query.accept(this);
298 public void visit(QNegation query) {
299 query.query.accept(this);
303 public void visit(ExpressionAccessor accessor) {
304 accessor.fieldName.accept(this);
308 public void visit(IdAccessor accessor) {
312 public void visit(StringAccessor accessor) {
316 public void visit(ListAssignment qualifier) {
317 qualifier.pattern.accept(this);
318 qualifier.value.accept(this);
322 public void visit(ListGenerator qualifier) {
323 qualifier.pattern.accept(this);
324 qualifier.value.accept(this);
328 public void visit(ListGuard qualifier) {
329 qualifier.condition.accept(this);
333 public void visit(ListSeq qualifier) {
334 qualifier.a.accept(this);
335 qualifier.b.accept(this);
339 public void visit(ListThen qualifier) {
340 qualifier.left.accept(this);
341 qualifier.transformer.accept(this);
342 if(qualifier.by != null)
343 qualifier.by.accept(this);
347 public void visit(QIf query) {
348 query.condition.accept(this);
349 query.thenQuery.accept(this);
350 query.elseQuery.accept(this);
354 public void visit(ECoveringBranchPoint expression) {
355 expression.expression.accept(this);
359 public void visit(EqBasic equation) {
360 equation.left.accept(this);
361 equation.right.accept(this);
365 public void visit(EqGuard equation) {
366 equation.guard.accept(this);
370 public void visit(EEquations expression) {
371 for(Equation equation : expression.equations)
372 equation.accept(this);
375 public void visit(CHRQuery query) {
376 for(CHRLiteral literal : query.literals)
377 for(Expression parameter : literal.parameters)
378 parameter.accept(this);
381 public void visit(CHRRuleset ruleset) {
382 for(CHRRule rule : ruleset.rules) {
386 for(IncludeStatement include : ruleset.includes)
387 include.value.accept(this);
391 public void visit(ECHRRuleset expression) {
392 visit(expression.ruleset);
393 expression.in.accept(this);
397 public void visit(ECHRRulesetConstructor expression) {
398 visit(expression.ruleset);
402 public void visit(EBinary expression) {
403 expression.left.accept(this);
404 for(EBinaryRightSide right : expression.rights)
405 right.right.accept(this);
409 public void visit(EBlock expression) {
410 for(Statement stat : expression.statements)
415 public void visit(EPreLet expression) {
416 for(LetStatement stat : expression.assignments) {
417 stat.pattern.accept(this);
418 stat.value.accept(this);
420 expression.in.accept(this);
424 public void visit(ERange expression) {
425 expression.from.accept(this);
426 expression.to.accept(this);
430 public void visit(ERecord expression) {
431 for(FieldAssignment assignment : expression.fields)
432 assignment.value.accept(this);
437 public void visit(EStringLiteral expression) {
438 for(Expression exp : expression.expressions)
443 public void visit(BindStatement statement) {
444 statement.pattern.accept(this);
445 statement.value.accept(this);
449 public void visit(GuardStatement statement) {
450 statement.value.accept(this);
454 public void visit(LetStatement statement) {
455 statement.value.accept(this);
459 public void visit(RuleStatement statement) {
460 statement.head.accept(this);
461 statement.body.accept(this);
465 public void visit(IncludeStatement statement) {
466 statement.value.accept(this);
470 public void visit(CHRStatement statement) {
471 statement.body.accept(this);
472 statement.head.accept(this);
476 public void visit(CHRAstAtom query) {
477 query.expression.accept(this);
481 public void visit(CHRAstBinds query) {
482 query.left.accept(this);
483 query.right.accept(this);
487 public void visit(CHRAstConjunction query) {
488 for(CHRAstQuery conjunct : query.conjuncts)
489 conjunct.accept(this);
493 public void visit(CHRAstEquals query) {
494 query.left.accept(this);
495 query.right.accept(this);
499 public void visit(CHRAstNegation query) {
500 query.subquery.accept(this);