X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fexpressions%2FEVariable.java;h=155aa7578f3821d399e0e2fd227791a65e1850d7;hb=624ab61bd302e999952f792e619a691e027ff1d2;hp=44c03a2acdd8d8ef7279938c67322b81ff7132f7;hpb=80110419efddee4e5eaa0d6f3db4ba69602fb1f9;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EVariable.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EVariable.java index 44c03a2ac..155aa7578 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EVariable.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EVariable.java @@ -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; @@ -20,10 +22,6 @@ 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]; @@ -47,30 +45,25 @@ public class EVariable extends Expression { } @Override - public void collectVars(TObjectIntHashMap allVars, - TIntHashSet vars) { - int id = allVars.get(variable); - if(id >= 0) - vars.add(id); + public Set 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 vars) { - vars.add(variable); + public IVal toVal(CompilationContext context, CodeWriter w) { + return variable.getVal(); } @Override @@ -92,11 +85,6 @@ public class EVariable extends Expression { ArrayList parameters) { } - @Override - public void removeFreeVariables(THashSet vars) { - vars.remove(variable); - } - @Override public Expression resolveAsPattern(TranslationContext context) { return this; @@ -144,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 @@ -154,8 +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 @@ -163,10 +161,6 @@ public class EVariable extends Expression { return false; } - @Override - public void collectEffects(THashSet effects) { - } - @Override public void setLocationDeep(long loc) { if(location == Locations.NO_LOCATION)