1 package org.simantics.scl.compiler.elaboration.expressions.block;
\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
13 public class LetStatement extends Statement {
\r
14 public Expression pattern;
\r
15 public Expression value;
\r
17 public LetStatement(Expression pattern, Expression value) {
\r
18 this.pattern = pattern;
\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
27 //return new EPreLet(Arrays.asList(this), in);
\r
28 return new EMatch(location, new Expression[] {value}, new Case[] {new Case(pattern, in)});
\r
32 public void setLocationDeep(long loc) {
\r
33 if(location == Locations.NO_LOCATION) {
\r
35 pattern.setLocationDeep(loc);
\r
36 value.setLocationDeep(loc);
\r
41 public void resolvePattern(TranslationContext context) {
\r
42 pattern = pattern.resolveAsPattern(context);
\r
46 public boolean mayBeRecursive() {
\r
47 return pattern.isFunctionDefinitionLhs();
\r
51 public Statement replace(ReplaceContext context) {
\r
52 return new LetStatement(pattern.replaceInPattern(context), value.replace(context));
\r
56 public void accept(StatementVisitor visitor) {
\r
57 visitor.visit(this);
\r