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