]> gerrit.simantics Code Review - simantics/platform.git/blob
c704497fdcedcf8b12f139ada9d0a8b18915b00c
[simantics/platform.git] /
1 package org.simantics.scl.compiler.elaboration.expressions.block;
2
3 import org.simantics.scl.compiler.elaboration.contexts.EnvironmentalContext;
4 import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
5 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
6 import org.simantics.scl.compiler.elaboration.expressions.Expression;
7 import org.simantics.scl.compiler.elaboration.query.Query;
8 import org.simantics.scl.compiler.errors.Locations;
9
10 public class RuleStatement extends Statement {
11
12     public Expression head;
13     public Query body;
14
15     public RuleStatement(Expression head, Query body) {
16         this.head = head;
17         this.body = body;
18     }
19
20     @Override
21     public Expression toExpression(EnvironmentalContext context, boolean monadic,
22             Expression in) {
23         throw new UnsupportedOperationException();
24     }
25     
26     @Override
27     public void setLocationDeep(long loc) {
28         if(location == Locations.NO_LOCATION) {
29             location = loc;
30             head.setLocationDeep(loc);
31             body.setLocationDeep(loc);
32         }
33     }
34     
35     @Override
36     public void resolvePattern(TranslationContext context) {
37         head = head.resolveAsPattern(context);
38     }
39     
40     @Override
41     public boolean mayBeRecursive() {
42         return true;
43     }
44     
45     @Override
46     public Statement replace(ReplaceContext context) {
47         return new RuleStatement(head.replaceInPattern(context), body.replace(context));
48     }
49     
50     @Override
51     public void accept(StatementVisitor visitor) {
52         visitor.visit(this);
53     }
54
55     @Override
56     public StatementGroup getStatementGroup() {
57         return StatementGroup.Rule;
58     }
59 }