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.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];
}
@Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- int id = allVars.get(variable);
- if(id >= 0)
- vars.add(id);
+ 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
ArrayList<Expression> parameters) {
}
- @Override
- public void removeFreeVariables(THashSet<Variable> vars) {
- vars.remove(variable);
- }
-
@Override
public Expression resolveAsPattern(TranslationContext context) {
return this;
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
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
return false;
}
- @Override
- public void collectEffects(THashSet<Type> effects) {
- }
-
@Override
public void setLocationDeep(long loc) {
if(location == Locations.NO_LOCATION)