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