]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLambda.java
(refs #7375) Replaced collectFreeVariables method by a visitor
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / expressions / ESimpleLambda.java
index 29eff29103dc6a8e2c257c7857b3125c2ccd2982..13c75db78bed5fe0f24cb211009ffb7c04f61b80 100644 (file)
@@ -1,17 +1,17 @@
 package org.simantics.scl.compiler.elaboration.expressions;
 
 import java.util.ArrayList;
+import java.util.Set;
 
 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
+import org.simantics.scl.compiler.compilation.CompilationContext;
 import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
-import org.simantics.scl.compiler.environment.Environment;
 import org.simantics.scl.compiler.errors.Locations;
 import org.simantics.scl.compiler.internal.codegen.references.IVal;
 import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
-import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;
 import org.simantics.scl.compiler.internal.interpreted.IExpression;
 import org.simantics.scl.compiler.internal.interpreted.ILambda;
 import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
@@ -24,7 +24,6 @@ import org.simantics.scl.compiler.types.kinds.Kinds;
 import org.simantics.scl.compiler.types.util.MultiFunction;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class ESimpleLambda extends Expression {
@@ -56,36 +55,26 @@ public class ESimpleLambda extends Expression {
         this.effect = effect;
     }
 
-       public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        value.collectRefs(allRefs, refs);
-    }
-       
-       @Override
-       public void collectVars(TObjectIntHashMap<Variable> allVars,
-               TIntHashSet vars) {
-           value.collectVars(allVars, vars);
-       }
+    @Override
+    public void collectVars(TObjectIntHashMap<Variable> allVars,
+            TIntHashSet vars) {
+        value.collectVars(allVars, vars);
+    }
 
-       public Expression decomposeMatching() {
+    public Expression decomposeMatching() {
         value = value.decomposeMatching();
         return this;
     }
 
-       @Override
-       protected void updateType() throws MatchException {
-           setType(Types.functionE(Types.canonical(parameter.type),
-                   effect, value.getType()));
-       }
-       
-       @Override
-       public IVal toVal(Environment env, CodeWriter w) {
-           return lambdaToVal(env, w);
+    @Override
+    protected void updateType() throws MatchException {
+        setType(Types.functionE(Types.canonical(parameter.type),
+                effect, value.getType()));
     }
 
     @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        value.collectFreeVariables(vars);
-        vars.remove(parameter);
+    public IVal toVal(CompilationContext context, CodeWriter w) {
+        return lambdaToVal(context, w);
     }
 
     @Override
@@ -148,7 +137,7 @@ public class ESimpleLambda extends Expression {
         
         // Free variables;
         ExpressionInterpretationContext innerContext =  context.createNewContext();
-        THashSet<Variable> freeVariables = cur.getFreeVariables();
+        Set<Variable> freeVariables = cur.getFreeVariables();
         for(Variable parameter : parameters)
             freeVariables.remove(parameter);
         int i=0;
@@ -180,11 +169,10 @@ public class ESimpleLambda extends Expression {
             return this;
         }
         
-        effect = mfun.effect;
         context.pushEffectUpperBound(location, mfun.effect);
         parameter.setType(mfun.parameterTypes[0]);
         value = value.checkType(context, mfun.returnType);
-        context.popEffectUpperBound();
+        effect = context.popEffectUpperBound();
         return this;
     }
     
@@ -199,22 +187,11 @@ public class ESimpleLambda extends Expression {
         return this;
     }
 
-    @Override
-    public Expression decorate(ExpressionDecorator decorator) {
-        if(decorator.decorateSubstructure(this))
-            value = value.decorate(decorator);
-        return decorator.decorate(this);
-    }
-
     @Override
     public boolean isEffectful() {
        return false;
     }
     
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-    }
-    
     @Override
     public void setLocationDeep(long loc) {
         if(location == Locations.NO_LOCATION) {
@@ -235,11 +212,6 @@ public class ESimpleLambda extends Expression {
     public Variable getParameter() {
         return parameter;
     }
-
-    @Override
-    public void forVariables(VariableProcedure procedure) {
-        value.forVariables(procedure);
-    }
     
     @Override
     public Expression accept(ExpressionTransformer transformer) {