package org.simantics.scl.compiler.elaboration.java; import org.simantics.scl.compiler.constants.BooleanConstant; import org.simantics.scl.compiler.elaboration.expressions.ELiteral; import org.simantics.scl.compiler.elaboration.expressions.EVariable; import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.elaboration.query.compilation.QueryCompilationContext; import org.simantics.scl.compiler.elaboration.relations.AbstractRelation; import org.simantics.scl.compiler.types.TVar; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; public class CheckRelation extends AbstractRelation { public static final CheckRelation INSTANCE = new CheckRelation(); private CheckRelation() {} @Override public TVar[] getTypeVariables() { return TVar.EMPTY_ARRAY; } private static final Type[] PARAMETER_TYPES = new Type[] {Types.BOOLEAN}; @Override public Type[] getParameterTypes() { return PARAMETER_TYPES; } @Override public int getPhase() { return 0; } @Override public double getSelectivity(int boundVariables) { switch(boundVariables) { case F: return 1.0; case B: return 0.1; default: throw new IllegalArgumentException(); } } @Override public int getRequiredVariablesMask() { return F; } @Override public void generate(long location, QueryCompilationContext context, Type[] typeParameters, Variable[] parameters, int boundVariables) { switch(boundVariables) { case F: context.let(parameters[0], new ELiteral(new BooleanConstant(true))); break; case B: context.condition(new EVariable(parameters[0])); break; default: throw new IllegalArgumentException(); } } @Override public String toString() { return "Check"; } }