]> gerrit.simantics Code Review - simantics/platform.git/blob
557dbbc882b66bd6dccf8bfa6bc0ca79395a30db
[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.EBind;
7 import org.simantics.scl.compiler.elaboration.expressions.ESimpleLet;
8 import org.simantics.scl.compiler.elaboration.expressions.EVariable;
9 import org.simantics.scl.compiler.elaboration.expressions.Expression;
10 import org.simantics.scl.compiler.elaboration.expressions.Variable;
11 import org.simantics.scl.compiler.errors.Locations;
12
13 public class GuardStatement extends Statement {
14     public Expression value;
15     
16     public GuardStatement(Expression value) {
17         this.value = value;
18     }
19
20     @Override
21     public Expression toExpression(EnvironmentalContext context, boolean monadic, Expression in) {
22         if(monadic) {
23             Variable var = new Variable("_");
24             return new EBind(location, new EVariable(location, var), value, in);
25         }
26         else
27             return new ESimpleLet(location, null, value, in);
28     }
29     
30     @Override
31     public void setLocationDeep(long loc) {
32         if(location == Locations.NO_LOCATION) {
33             location = loc;
34             value.setLocationDeep(loc);
35         }
36     }
37     
38     @Override
39     public void resolvePattern(TranslationContext context) {
40     }
41     
42     @Override
43     public boolean mayBeRecursive() {
44         return false;
45     }
46     
47     @Override
48     public Statement replace(ReplaceContext context) {
49         return new GuardStatement(value.replace(context));
50     }
51     
52     @Override
53     public void accept(StatementVisitor visitor) {
54         visitor.visit(this);
55     }
56
57     @Override
58     public StatementGroup getStatementGroup() {
59         return null;
60     }
61 }