]> 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 aa278928239ea4efd2ee0d6cb9e336c129541110..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 {
@@ -53,24 +54,27 @@ public class EVariable extends Expression {
         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) {
         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
@@ -92,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;