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);
79 public void visit(EConstant expression) {
83 public void visit(EEnforce expression) {
84 expression.query.accept(this);
88 public void visit(EError expression) {
92 public void visit(EExternalConstant expression) {
96 public void visit(EFieldAccess expression) {
97 expression.parent.accept(this);
98 expression.accessor.accept(this);
102 public void visit(EGetConstraint expression) {
103 if(expression.evidence != null)
104 expression.evidence.accept(this);
108 public void visit(EIf expression) {
109 expression.condition.accept(this);
110 expression.then_.accept(this);
111 if(expression.else_ != null)
112 expression.else_.accept(this);
116 public void visit(EIntegerLiteral expression) {
117 if(expression.constraint != null)
118 expression.constraint.accept(this);
122 public void visit(ELambda expression) {
123 for(Case case_ : expression.cases)
128 public void visit(EViewPattern expression) {
129 expression.expression.accept(this);
130 expression.pattern.accept(this);
133 public void visit(Case case_) {
134 for(Expression pattern : case_.patterns)
135 pattern.accept(this);
136 case_.value.accept(this);
140 public void visit(ELambdaType expression) {
141 expression.value.accept(this);
145 public void visit(ELet expression) {
146 for(Assignment assignment : expression.assignments)
150 public void visit(Assignment assignment) {
151 assignment.pattern.accept(this);
152 assignment.value.accept(this);
156 public void visit(EListComprehension expression) {
157 expression.head.accept(this);
158 expression.qualifier.accept(this);
162 public void visit(EListLiteral expression) {
163 for(Expression component : expression.components)
164 component.accept(this);
168 public void visit(ELiteral expression) {
172 public void visit(EMatch expression) {
173 for(Expression s : expression.scrutinee)
175 for(Case case_ : expression.cases)
180 public void visit(EPlaceholder expression) {
181 expression.expression.accept(this);
185 public void visit(ERealLiteral expression) {
186 if(expression.constraint != null)
187 expression.constraint.accept(this);
191 public void visit(ERuleset expression) {
192 for(DatalogRule rule : expression.rules)
194 expression.in.accept(this);
197 public void visit(DatalogRule rule) {
198 for(Expression parameter : rule.headParameters)
199 parameter.accept(this);
200 rule.body.accept(this);
204 public void visit(ESelect expression) {
205 expression.query.accept(this);
206 expression.expression.accept(this);
210 public void visit(ECHRSelect expression) {
211 visit(expression.query);
212 expression.expression.accept(this);
216 public void visit(ESimpleLambda expression) {
217 expression.value.accept(this);
221 public void visit(ESimpleLet expression) {
222 expression.value.accept(this);
223 expression.in.accept(this);
227 public void visit(ETransformation expression) {
228 expression.seed.accept(this);
232 public void visit(ETypeAnnotation expression) {
233 expression.value.accept(this);
237 public void visit(EVar expression) {
241 public void visit(EVariable expression) {
245 public void visit(EWhen expression) {
246 expression.query.accept(this);
247 expression.action.accept(this);
251 public void visit(GuardedExpressionGroup expression) {
252 for(GuardedExpression gexp : expression.expressions) {
253 for(Expression guard : gexp.guards)
255 gexp.value.accept(this);
260 public void visit(QAlternative query) {
261 for(Query q : query.queries)
266 public void visit(QAtom query) {
267 for(Expression parameter : query.parameters)
268 parameter.accept(this);
272 public void visit(QMapping query) {
273 for(Expression parameter : query.parameters)
274 parameter.accept(this);
278 public void visit(QConjunction query) {
279 for(Query q : query.queries)
284 public void visit(QDisjunction query) {
285 for(Query q : query.queries)
290 public void visit(QExists query) {
291 query.query.accept(this);
295 public void visit(QNegation query) {
296 query.query.accept(this);
300 public void visit(ExpressionAccessor accessor) {
301 accessor.fieldName.accept(this);
305 public void visit(IdAccessor accessor) {
309 public void visit(StringAccessor accessor) {
313 public void visit(ListAssignment qualifier) {
314 qualifier.pattern.accept(this);
315 qualifier.value.accept(this);
319 public void visit(ListGenerator qualifier) {
320 qualifier.pattern.accept(this);
321 qualifier.value.accept(this);
325 public void visit(ListGuard qualifier) {
326 qualifier.condition.accept(this);
330 public void visit(ListSeq qualifier) {
331 qualifier.a.accept(this);
332 qualifier.b.accept(this);
336 public void visit(ListThen qualifier) {
337 qualifier.left.accept(this);
338 qualifier.transformer.accept(this);
339 if(qualifier.by != null)
340 qualifier.by.accept(this);
344 public void visit(QIf query) {
345 query.condition.accept(this);
346 query.thenQuery.accept(this);
347 query.elseQuery.accept(this);
351 public void visit(ECoveringBranchPoint expression) {
352 expression.expression.accept(this);
356 public void visit(EqBasic equation) {
357 equation.left.accept(this);
358 equation.right.accept(this);
362 public void visit(EqGuard equation) {
363 equation.guard.accept(this);
367 public void visit(EEquations expression) {
368 for(Equation equation : expression.equations)
369 equation.accept(this);
372 public void visit(CHRQuery query) {
373 for(CHRLiteral literal : query.literals)
374 for(Expression parameter : literal.parameters)
375 parameter.accept(this);
378 public void visit(CHRRuleset ruleset) {
379 for(CHRRule rule : ruleset.rules) {
386 public void visit(ECHRRuleset expression) {
387 visit(expression.ruleset);
388 expression.in.accept(this);
392 public void visit(ECHRRulesetConstructor expression) {
393 visit(expression.ruleset);
397 public void visit(EBinary expression) {
398 expression.left.accept(this);
399 for(EBinaryRightSide right : expression.rights)
400 right.right.accept(this);
404 public void visit(EBlock expression) {
405 for(Statement stat : expression.statements)
410 public void visit(EPreLet expression) {
411 for(LetStatement stat : expression.assignments) {
412 stat.pattern.accept(this);
413 stat.value.accept(this);
415 expression.in.accept(this);
419 public void visit(ERange expression) {
420 expression.from.accept(this);
421 expression.to.accept(this);
425 public void visit(ERecord expression) {
426 for(FieldAssignment assignment : expression.fields)
427 assignment.value.accept(this);
432 public void visit(EStringLiteral expression) {
433 for(Expression exp : expression.expressions)
438 public void visit(BindStatement statement) {
439 statement.pattern.accept(this);
440 statement.value.accept(this);
444 public void visit(GuardStatement statement) {
445 statement.value.accept(this);
449 public void visit(LetStatement statement) {
450 statement.value.accept(this);
454 public void visit(RuleStatement statement) {
455 statement.head.accept(this);
456 statement.body.accept(this);
460 public void visit(IncludeStatement statement) {
461 statement.value.accept(this);
465 public void visit(CHRStatement statement) {
466 statement.body.accept(this);
467 statement.head.accept(this);
471 public void visit(CHRAstAtom query) {
472 query.expression.accept(this);
476 public void visit(CHRAstBinds query) {
477 query.left.accept(this);
478 query.right.accept(this);
482 public void visit(CHRAstConjunction query) {
483 for(CHRAstQuery conjunct : query.conjuncts)
484 conjunct.accept(this);
488 public void visit(CHRAstEquals query) {
489 query.left.accept(this);
490 query.right.accept(this);
494 public void visit(CHRAstNegation query) {
495 query.subquery.accept(this);