]> gerrit.simantics Code Review - simantics/platform.git/blob
cf927825e176df8bbe2e4f4c87063e9d17adf5ee
[simantics/platform.git] /
1 package org.simantics.scl.compiler.elaboration.java;
2
3 import org.simantics.scl.compiler.constants.BooleanConstant;
4 import org.simantics.scl.compiler.elaboration.expressions.ELiteral;
5 import org.simantics.scl.compiler.elaboration.expressions.EVariable;
6 import org.simantics.scl.compiler.elaboration.expressions.Variable;
7 import org.simantics.scl.compiler.elaboration.query.compilation.QueryCompilationContext;
8 import org.simantics.scl.compiler.elaboration.relations.AbstractRelation;
9 import org.simantics.scl.compiler.types.TVar;
10 import org.simantics.scl.compiler.types.Type;
11 import org.simantics.scl.compiler.types.Types;
12
13 public class CheckRelation extends AbstractRelation {
14     public static final CheckRelation INSTANCE = new CheckRelation();
15     
16     private CheckRelation() {}
17     
18     @Override
19     public TVar[] getTypeVariables() {
20         return TVar.EMPTY_ARRAY;
21     }
22     
23     private static final Type[] PARAMETER_TYPES = new Type[] {Types.BOOLEAN};
24
25     @Override
26     public Type[] getParameterTypes() {
27         return PARAMETER_TYPES;
28     }
29     
30     @Override
31     public int getPhase() {
32         return 0;
33     }
34
35     @Override
36     public double getSelectivity(int boundVariables) {
37         switch(boundVariables) {
38         case F: return 1.0;
39         case B: return 0.1;
40         default: throw new IllegalArgumentException();
41         }
42     }
43     
44     @Override
45     public int getRequiredVariablesMask() {
46         return F;
47     }
48
49     @Override
50     public void generate(long location,
51             QueryCompilationContext context,
52             Type[] typeParameters, Variable[] parameters, int boundVariables) {
53         switch(boundVariables) {
54         case F:
55             context.let(parameters[0], new ELiteral(new BooleanConstant(true)));
56             break;
57         case B:
58             context.condition(new EVariable(parameters[0]));
59             break;
60         default: throw new IllegalArgumentException();
61         }
62     }
63
64     @Override
65     public String toString() {
66         return "Check";
67     }
68     
69 }