]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EVariable.java
(refs #7375) Replaced collectFreeVariables method by a visitor
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / expressions / EVariable.java
index 669867ff6ca0e825f83c3906b50e3e63a652530f..fccc62e9869cfc4f5469d2804588d4ed465baf41 100644 (file)
@@ -1,6 +1,8 @@
 package org.simantics.scl.compiler.elaboration.expressions;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Set;
 
 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
 import org.simantics.scl.compiler.compilation.CompilationContext;
@@ -21,7 +23,6 @@ import org.simantics.scl.compiler.types.kinds.Kinds;
 import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EVariable extends Expression {
@@ -46,34 +47,34 @@ public class EVariable extends Expression {
         this.variable = variable;
     }
 
-       public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-    }
-       
-       @Override
-       public void collectVars(TObjectIntHashMap<Variable> allVars,
-               TIntHashSet vars) {
-           int id = allVars.get(variable);
-           if(id >= 0)
-               vars.add(id);
-       }
+    @Override
+    public void collectVars(TObjectIntHashMap<Variable> allVars,
+            TIntHashSet vars) {
+        int id = allVars.get(variable);
+        if(id >= 0)
+            vars.add(id);
+    }
+    
+    @Override
+    public Set<Variable> getFreeVariables() {
+        if(variable == null)
+            return Collections.emptySet();
+        else
+            return Collections.singleton(variable);
+    }
 
-       public void toString(StringBuilder b, TypeUnparsingContext tuc) {
+    public void toString(StringBuilder b, TypeUnparsingContext tuc) {
         b.append(variable == null ? "???" : variable.toString());
     }
 
-       @Override
-       protected void updateType() throws MatchException {
-           setType(variable.getType());
-       }
-       
-       @Override
-       public IVal toVal(CompilationContext context, CodeWriter w) {
-        return variable.getVal();
+    @Override
+    protected void updateType() throws MatchException {
+        setType(variable.getType());
     }
 
     @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        vars.add(variable);
+    public IVal toVal(CompilationContext context, CodeWriter w) {
+        return variable.getVal();
     }
 
     @Override
@@ -95,11 +96,6 @@ public class EVariable extends Expression {
             ArrayList<Expression> parameters) {
     }
     
-    @Override
-    public void removeFreeVariables(THashSet<Variable> vars) {
-        vars.remove(variable);
-    }
-    
     @Override
     public Expression resolveAsPattern(TranslationContext context) {
         return this;
@@ -166,10 +162,6 @@ public class EVariable extends Expression {
        return false;
     }
     
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-    }
-    
     @Override
     public void setLocationDeep(long loc) {
         if(location == Locations.NO_LOCATION)