import org.simantics.scl.compiler.elaboration.expressions.lhstype.LhsType;
import org.simantics.scl.compiler.elaboration.expressions.lhstype.PatternMatchingLhs;
import org.simantics.scl.compiler.elaboration.expressions.printing.ExpressionToStringVisitor;
+import org.simantics.scl.compiler.elaboration.expressions.visitors.CollectRefsVisitor;
+import org.simantics.scl.compiler.elaboration.expressions.visitors.ForVariablesUsesVisitor;
import org.simantics.scl.compiler.elaboration.query.QAtom;
import org.simantics.scl.compiler.elaboration.relations.SCLRelation;
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.decomposed.DecomposedExpression;
-import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;
import org.simantics.scl.compiler.internal.interpreted.IExpression;
import org.simantics.scl.compiler.internal.parsing.Symbol;
import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
expression = new ESimpleLet(location, null, expression, new ELiteral(NoRepConstant.PUNIT));
return expression;
}
-
- /**
- * Checks the type of the expression against the given type. Adds type
- * applications and lambdas if needed.
- */
- public final Expression checkType(TypingContext context, Type requiredType) {
- //System.out.println("checkType: " + this + " :: " + requiredType);
- if(!context.isInPattern()) {
- requiredType = Types.canonical(requiredType);
- if(requiredType instanceof TForAll) {
+
+ /**
+ * Checks the type of the expression against the given type. Adds type
+ * applications and lambdas if needed.
+ */
+ public final Expression checkType(TypingContext context, Type requiredType) {
+ //System.out.println("checkType: " + this + " :: " + requiredType);
+ if(!context.isInPattern()) {
+ requiredType = Types.canonical(requiredType);
+ if(requiredType instanceof TForAll) {
TForAll forAll = (TForAll)requiredType;
TVar var = forAll.var;
TVar newVar = Types.var(var.getKind());
requiredType = Types.canonical(forAll.type).replace(var, newVar);
return new ELambdaType(new TVar[] {newVar}, checkType(context, requiredType));
}
- while(requiredType instanceof TFun) {
+ while(requiredType instanceof TFun) {
TFun fun = (TFun)requiredType;
if(fun.domain instanceof TPred) { // No need to canonicalize
ArrayList<Variable> constraints = new ArrayList<Variable>(2);
context.pushEffectUpperBound(location, fun.effect);
Expression expr = checkType(context, fun.range);
context.popEffectUpperBound();
-
+
// Wrap
Variable var = new Variable("punit", Types.PUNIT);
return new ESimpleLambda(location, var, fun.effect, expr);
else
break;
}
- }
- return checkBasicType(context, requiredType);
- }
+ }
+ return checkBasicType(context, requiredType);
+ }
- public abstract void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs);
- public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
- public abstract void forVariables(VariableProcedure procedure);
-
- public Expression decomposeMatching() {
+ public final void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+ accept(new CollectRefsVisitor(allRefs, refs));
+ }
+
+ public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
+
+ public final void forVariableUses(VariableProcedure procedure) {
+ accept(new ForVariablesUsesVisitor(procedure));
+ }
+
+ public Expression decomposeMatching() {
return this;
}
THashSet<Variable> result = new THashSet<Variable>();
collectFreeVariables(result);
return result;
- }
+ }
public static Expression[] concat(Expression[] a, Expression[] b) {
if(a.length == 0)
public Expression applyType(Type type) {
return new EApplyType(location, this, type);
}
-
- public abstract Expression decorate(ExpressionDecorator decorator);
public boolean isEffectful() {
return true;