1 package org.simantics.scl.compiler.elaboration.java;
3 import org.simantics.scl.compiler.common.names.Names;
4 import org.simantics.scl.compiler.elaboration.expressions.EApply;
5 import org.simantics.scl.compiler.elaboration.expressions.EVariable;
6 import org.simantics.scl.compiler.elaboration.expressions.Expression;
7 import org.simantics.scl.compiler.elaboration.expressions.Variable;
8 import org.simantics.scl.compiler.elaboration.query.compilation.QueryCompilationContext;
9 import org.simantics.scl.compiler.elaboration.relations.AbstractRelation;
10 import org.simantics.scl.compiler.types.TVar;
11 import org.simantics.scl.compiler.types.Type;
12 import org.simantics.scl.compiler.types.Types;
13 import org.simantics.scl.compiler.types.kinds.Kinds;
15 public class OptionalRelation extends AbstractRelation {
16 public static final OptionalRelation INSTANCE = new OptionalRelation();
18 private OptionalRelation() {}
20 private static final TVar A = Types.var(Kinds.STAR);
22 private static final TVar[] TYPE_VARIABLES = new TVar[] {A};
25 public TVar[] getTypeVariables() {
26 return TYPE_VARIABLES;
29 private static final Type[] PARAMETER_TYPES = new Type[] {A, Types.apply(Types.MAYBE, A)};
32 public Type[] getParameterTypes() {
33 return PARAMETER_TYPES;
37 public int getPhase() {
42 public double getSelectivity(int boundVariables) {
43 switch(boundVariables) {
45 case BF: return Double.POSITIVE_INFINITY;
48 default: throw new IllegalArgumentException();
53 public int getRequiredVariablesMask() {
58 public void generate(long location,
59 QueryCompilationContext context,
60 Type[] typeParameters, Variable[] parameters, int boundVariables) {
61 switch(boundVariables) {
63 context.iterateMaybe(parameters[0], new EVariable(parameters[1]));
68 context.getConstant(Names.Prelude_elemMaybe, typeParameters),
70 new EVariable(parameters[0]),
71 new EVariable(parameters[1])
75 default: throw new IllegalArgumentException();
80 public String toString() {