1 package org.simantics.scl.compiler.elaboration.expressions.block;
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.Case;
7 import org.simantics.scl.compiler.elaboration.expressions.EMatch;
8 import org.simantics.scl.compiler.elaboration.expressions.ESimpleLet;
9 import org.simantics.scl.compiler.elaboration.expressions.EVariable;
10 import org.simantics.scl.compiler.elaboration.expressions.Expression;
11 import org.simantics.scl.compiler.errors.Locations;
13 public class LetStatement extends Statement {
14 public Expression pattern;
15 public Expression value;
17 public LetStatement(Expression pattern, Expression value) {
18 this.pattern = pattern;
23 public Expression toExpression(EnvironmentalContext context, boolean monadic, Expression in) {
24 if(pattern instanceof EVariable)
25 return new ESimpleLet(((EVariable)pattern).getVariable(), value, in);
27 //return new EPreLet(Arrays.asList(this), in);
28 return new EMatch(location, new Expression[] {value}, new Case[] {new Case(pattern, in)});
32 public void setLocationDeep(long loc) {
33 if(location == Locations.NO_LOCATION) {
35 pattern.setLocationDeep(loc);
36 value.setLocationDeep(loc);
41 public void resolvePattern(TranslationContext context) {
42 pattern = pattern.resolveAsPattern(context);
46 public boolean mayBeRecursive() {
47 return pattern.isFunctionDefinitionLhs();
51 public Statement replace(ReplaceContext context) {
52 return new LetStatement(pattern.replaceInPattern(context), value.replace(context));
56 public void accept(StatementVisitor visitor) {
61 public StatementGroup getStatementGroup() {
62 if(pattern.isFunctionPattern())
63 return StatementGroup.LetFunction;