1 package org.simantics.scl.compiler.elaboration.query;
3 import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
4 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
5 import org.simantics.scl.compiler.elaboration.expressions.Expression;
6 import org.simantics.scl.compiler.elaboration.expressions.QueryTransformer;
7 import org.simantics.scl.compiler.elaboration.expressions.Variable;
8 import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure;
9 import org.simantics.scl.compiler.elaboration.query.compilation.ConstraintCollectionContext;
10 import org.simantics.scl.compiler.elaboration.query.compilation.UnsolvableQueryException;
11 import org.simantics.scl.compiler.errors.Locations;
12 import org.simantics.scl.compiler.types.Types;
14 import gnu.trove.map.hash.TObjectIntHashMap;
15 import gnu.trove.set.hash.THashSet;
16 import gnu.trove.set.hash.TIntHashSet;
18 public class QIf extends Query {
19 public Expression condition;
20 public Query thenQuery;
21 public Query elseQuery;
23 public QIf(Expression condition, Query thenQuery, Query elseQuery) {
24 this.condition = condition;
25 this.thenQuery = thenQuery;
26 this.elseQuery = elseQuery;
30 public void collectFreeVariables(THashSet<Variable> vars) {
31 condition.collectFreeVariables(vars);
32 thenQuery.collectFreeVariables(vars);
33 elseQuery.collectFreeVariables(vars);
37 public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
38 condition.collectRefs(allRefs, refs);
39 thenQuery.collectRefs(allRefs, refs);
40 elseQuery.collectRefs(allRefs, refs);
44 public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
45 condition.collectVars(allVars, vars);
46 thenQuery.collectVars(allVars, vars);
47 elseQuery.collectVars(allVars, vars);
51 public void checkType(TypingContext context) {
52 condition.checkType(context, Types.BOOLEAN);
53 thenQuery.checkType(context);
54 elseQuery.checkType(context);
58 public void collectConstraints(ConstraintCollectionContext context) throws UnsolvableQueryException {
59 // TODO Auto-generated method stub
64 public Query replace(ReplaceContext context) {
66 condition.replace(context),
67 thenQuery.replace(context),
68 elseQuery.replace(context));
72 public void setLocationDeep(long loc) {
73 if(location == Locations.NO_LOCATION) {
75 condition.setLocationDeep(loc);
76 elseQuery.setLocationDeep(loc);
77 thenQuery.setLocationDeep(loc);
82 public void accept(QueryVisitor visitor) {
87 public void forVariables(VariableProcedure procedure) {
88 condition.forVariables(procedure);
89 elseQuery.forVariables(procedure);
90 thenQuery.forVariables(procedure);
94 public Query accept(QueryTransformer transformer) {
95 return transformer.transform(this);