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.chr.CHRRuleset;
6 import org.simantics.scl.compiler.elaboration.equation.EqBasic;
7 import org.simantics.scl.compiler.elaboration.equation.EqGuard;
8 import org.simantics.scl.compiler.elaboration.equation.Equation;
9 import org.simantics.scl.compiler.elaboration.equation.EquationVisitor;
10 import org.simantics.scl.compiler.elaboration.expressions.ERuleset.DatalogRule;
11 import org.simantics.scl.compiler.elaboration.expressions.accessor.ExpressionAccessor;
12 import org.simantics.scl.compiler.elaboration.expressions.accessor.FieldAccessorVisitor;
13 import org.simantics.scl.compiler.elaboration.expressions.accessor.IdAccessor;
14 import org.simantics.scl.compiler.elaboration.expressions.accessor.StringAccessor;
15 import org.simantics.scl.compiler.elaboration.expressions.block.BindStatement;
16 import org.simantics.scl.compiler.elaboration.expressions.block.CHRStatement;
17 import org.simantics.scl.compiler.elaboration.expressions.block.GuardStatement;
18 import org.simantics.scl.compiler.elaboration.expressions.block.IncludeStatement;
19 import org.simantics.scl.compiler.elaboration.expressions.block.LetStatement;
20 import org.simantics.scl.compiler.elaboration.expressions.block.RuleStatement;
21 import org.simantics.scl.compiler.elaboration.expressions.block.Statement;
22 import org.simantics.scl.compiler.elaboration.expressions.block.StatementVisitor;
23 import org.simantics.scl.compiler.elaboration.expressions.list.ListAssignment;
24 import org.simantics.scl.compiler.elaboration.expressions.list.ListGenerator;
25 import org.simantics.scl.compiler.elaboration.expressions.list.ListGuard;
26 import org.simantics.scl.compiler.elaboration.expressions.list.ListQualifier;
27 import org.simantics.scl.compiler.elaboration.expressions.list.ListQualifierVisitor;
28 import org.simantics.scl.compiler.elaboration.expressions.list.ListSeq;
29 import org.simantics.scl.compiler.elaboration.expressions.list.ListThen;
30 import org.simantics.scl.compiler.elaboration.expressions.records.FieldAssignment;
31 import org.simantics.scl.compiler.elaboration.query.QAlternative;
32 import org.simantics.scl.compiler.elaboration.query.QAtom;
33 import org.simantics.scl.compiler.elaboration.query.QConjunction;
34 import org.simantics.scl.compiler.elaboration.query.QDisjunction;
35 import org.simantics.scl.compiler.elaboration.query.QExists;
36 import org.simantics.scl.compiler.elaboration.query.QIf;
37 import org.simantics.scl.compiler.elaboration.query.QMapping;
38 import org.simantics.scl.compiler.elaboration.query.QNegation;
39 import org.simantics.scl.compiler.elaboration.query.Query;
40 import org.simantics.scl.compiler.elaboration.query.QueryVisitor;
43 public class StandardExpressionVisitor implements
44 ExpressionVisitor, QueryVisitor, FieldAccessorVisitor, ListQualifierVisitor,
45 EquationVisitor, StatementVisitor {
48 public void visit(EApply expression) {
49 expression.function.accept(this);
50 for(Expression parameter : expression.parameters)
51 parameter.accept(this);
55 public void visit(EApplyType expression) {
56 expression.expression.accept(this);
60 public void visit(EAsPattern expression) {
61 expression.pattern.accept(this);
65 public void visit(EBind expression) {
66 expression.pattern.accept(this);
67 expression.value.accept(this);
68 expression.in.accept(this);
72 public void visit(EConstant expression) {
76 public void visit(EEnforce expression) {
77 expression.query.accept(this);
81 public void visit(EError expression) {
85 public void visit(EExternalConstant expression) {
89 public void visit(EFieldAccess expression) {
90 expression.parent.accept(this);
91 expression.accessor.accept(this);
95 public void visit(EGetConstraint expression) {
96 if(expression.evidence != null)
97 expression.evidence.accept(this);
101 public void visit(EIf expression) {
102 expression.condition.accept(this);
103 expression.then_.accept(this);
104 if(expression.else_ != null)
105 expression.else_.accept(this);
109 public void visit(EIntegerLiteral expression) {
110 if(expression.constraint != null)
111 expression.constraint.accept(this);
115 public void visit(ELambda expression) {
116 for(Case case_ : expression.cases)
121 public void visit(EViewPattern expression) {
122 expression.expression.accept(this);
123 expression.pattern.accept(this);
126 public void visit(Case case_) {
127 for(Expression pattern : case_.patterns)
128 pattern.accept(this);
129 case_.value.accept(this);
133 public void visit(ELambdaType expression) {
134 expression.value.accept(this);
138 public void visit(ELet expression) {
139 for(Assignment assignment : expression.assignments)
143 public void visit(Assignment assignment) {
144 assignment.pattern.accept(this);
145 assignment.value.accept(this);
149 public void visit(EListComprehension expression) {
150 expression.head.accept(this);
151 expression.qualifier.accept(this);
155 public void visit(EListLiteral expression) {
156 for(Expression component : expression.components)
157 component.accept(this);
161 public void visit(ELiteral expression) {
165 public void visit(EMatch expression) {
166 for(Expression s : expression.scrutinee)
168 for(Case case_ : expression.cases)
173 public void visit(EPlaceholder expression) {
174 expression.expression.accept(this);
178 public void visit(ERealLiteral expression) {
179 if(expression.constraint != null)
180 expression.constraint.accept(this);
184 public void visit(ERuleset expression) {
185 for(DatalogRule rule : expression.rules)
187 expression.in.accept(this);
190 public void visit(DatalogRule rule) {
191 for(Expression parameter : rule.headParameters)
192 parameter.accept(this);
193 rule.body.accept(this);
197 public void visit(ESelect expression) {
198 expression.query.accept(this);
199 expression.expression.accept(this);
203 public void visit(ESimpleLambda expression) {
204 expression.value.accept(this);
208 public void visit(ESimpleLet expression) {
209 expression.value.accept(this);
210 expression.in.accept(this);
214 public void visit(ETransformation expression) {
215 expression.seed.accept(this);
219 public void visit(ETypeAnnotation expression) {
220 expression.value.accept(this);
224 public void visit(EVar expression) {
228 public void visit(EVariable expression) {
232 public void visit(EWhen expression) {
233 expression.query.accept(this);
234 expression.action.accept(this);
238 public void visit(GuardedExpressionGroup expression) {
239 for(GuardedExpression gexp : expression.expressions) {
240 for(Expression guard : gexp.guards)
242 gexp.value.accept(this);
247 public void visit(QAlternative query) {
248 for(Query q : query.queries)
253 public void visit(QAtom query) {
254 for(Expression parameter : query.parameters)
255 parameter.accept(this);
259 public void visit(QMapping query) {
260 for(Expression parameter : query.parameters)
261 parameter.accept(this);
265 public void visit(QConjunction query) {
266 for(Query q : query.queries)
271 public void visit(QDisjunction query) {
272 for(Query q : query.queries)
277 public void visit(QExists query) {
278 query.query.accept(this);
282 public void visit(QNegation query) {
283 query.query.accept(this);
287 public void visit(ExpressionAccessor accessor) {
288 accessor.fieldName.accept(this);
292 public void visit(IdAccessor accessor) {
296 public void visit(StringAccessor accessor) {
300 public void visit(ListAssignment qualifier) {
301 qualifier.pattern.accept(this);
302 qualifier.value.accept(this);
306 public void visit(ListGenerator qualifier) {
307 qualifier.pattern.accept(this);
308 qualifier.value.accept(this);
312 public void visit(ListGuard qualifier) {
313 qualifier.condition.accept(this);
317 public void visit(ListSeq qualifier) {
318 qualifier.a.accept(this);
319 qualifier.b.accept(this);
323 public void visit(ListThen qualifier) {
324 qualifier.left.accept(this);
325 qualifier.transformer.accept(this);
326 if(qualifier.by != null)
327 qualifier.by.accept(this);
331 public void visit(QIf query) {
332 query.condition.accept(this);
333 query.thenQuery.accept(this);
334 query.elseQuery.accept(this);
338 public void visit(ECoveringBranchPoint expression) {
339 expression.expression.accept(this);
343 public void visit(EqBasic equation) {
344 equation.left.accept(this);
345 equation.right.accept(this);
349 public void visit(EqGuard equation) {
350 equation.guard.accept(this);
354 public void visit(EEquations expression) {
355 for(Equation equation : expression.equations)
356 equation.accept(this);
359 public void visit(CHRRuleset ruleset) {
360 for(CHRRule rule : ruleset.rules) {
361 for(CHRLiteral literal : rule.head.literals)
362 for(Expression parameter : literal.parameters)
363 parameter.accept(this);
364 for(CHRLiteral literal : rule.body.literals)
365 for(Expression parameter : literal.parameters)
366 parameter.accept(this);
371 public void visit(ECHRRuleset expression) {
372 visit(expression.ruleset);
373 expression.in.accept(this);
377 public void visit(ECHRRulesetConstructor expression) {
378 visit(expression.ruleset);
382 public void visit(EBinary expression) {
383 expression.left.accept(this);
384 for(EBinaryRightSide right : expression.rights)
385 right.right.accept(this);
389 public void visit(EBlock expression) {
390 for(Statement stat : expression.statements)
395 public void visit(EPreLet expression) {
396 for(LetStatement stat : expression.assignments) {
397 stat.pattern.accept(this);
398 stat.value.accept(this);
400 expression.in.accept(this);
404 public void visit(ERange expression) {
405 expression.from.accept(this);
406 expression.to.accept(this);
410 public void visit(ERecord expression) {
411 for(FieldAssignment assignment : expression.fields)
412 assignment.value.accept(this);
417 public void visit(EStringLiteral expression) {
418 for(Expression exp : expression.expressions)
423 public void visit(BindStatement statement) {
424 statement.pattern.accept(this);
425 statement.value.accept(this);
429 public void visit(GuardStatement statement) {
430 statement.value.accept(this);
434 public void visit(LetStatement statement) {
435 statement.value.accept(this);
439 public void visit(RuleStatement statement) {
440 statement.head.accept(this);
441 statement.body.accept(this);
445 public void visit(IncludeStatement statement) {
446 statement.value.accept(this);
450 public void visit(CHRStatement statement) {
451 for(ListQualifier q : statement.body)
453 for(ListQualifier q : statement.head)