]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EVariable.java
Updated release engineering instructions for 1.31.0 release.
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / expressions / EVariable.java
index a4010303ca75ed20a23cb12f7780cf3e70f2fad6..155aa7578f3821d399e0e2fd227791a65e1850d7 100644 (file)
@@ -1,17 +1,18 @@
 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;
 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.IVariable;
 import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
@@ -21,14 +22,10 @@ import org.simantics.scl.compiler.types.exceptions.MatchException;
 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 {
     public static final EVariable[] EMPTY_ARRAY = new EVariable[0];
     
-    Variable variable;
+    public Variable variable;
     
     public EVariable(Variable variable) {
         this.variable = variable;
@@ -47,34 +44,26 @@ 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 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(Environment env, 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
@@ -96,11 +85,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;
@@ -148,8 +132,13 @@ public class EVariable extends Expression {
             variable.setType(Types.metaVar(Kinds.STAR));
             return this;
         }
-        else
+        else {
+            if(variable.getType() == null) {
+                context.getErrorLog().log(location, "Type of the variable is not defined.");
+                variable.setType(Types.metaVar(Kinds.STAR));
+            }
             return applyPUnit(context);
+        }
     }
     
     @Override
@@ -158,13 +147,13 @@ public class EVariable extends Expression {
             variable.setType(requiredType);
             return this;
         }
-        else
+        else {
+            if(variable.getType() == null) {
+                context.getErrorLog().log(location, "Type of the variable is not defined.");
+                variable.setType(Types.metaVar(Kinds.STAR));
+            }
             return context.subsume(this, requiredType);
-    }
-    
-    @Override
-    public Expression decorate(ExpressionDecorator decorator) {     
-        return decorator.decorate(this);
+        }
     }
     
     @Override
@@ -172,10 +161,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)
@@ -186,12 +171,6 @@ public class EVariable extends Expression {
     public void accept(ExpressionVisitor visitor) {
         visitor.visit(this);
     }
-
-    @Override
-    public void forVariables(VariableProcedure procedure) {
-        if(variable != null)
-            procedure.execute(location, variable);
-    }
     
     @Override
     public boolean isPattern(int arity) {