]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QIf.java
62ff9583ce97317519fe2074254f818b61cf6027
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / query / QIf.java
1 package org.simantics.scl.compiler.elaboration.query;
2
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;
13
14 import gnu.trove.map.hash.TObjectIntHashMap;
15 import gnu.trove.set.hash.THashSet;
16 import gnu.trove.set.hash.TIntHashSet;
17
18 public class QIf extends Query {
19     public Expression condition;
20     public Query thenQuery;
21     public Query elseQuery;
22     
23     public QIf(Expression condition, Query thenQuery, Query elseQuery) {
24         this.condition = condition;
25         this.thenQuery = thenQuery;
26         this.elseQuery = elseQuery;
27     }
28
29     @Override
30     public void collectFreeVariables(THashSet<Variable> vars) {
31         condition.collectFreeVariables(vars);
32         thenQuery.collectFreeVariables(vars);
33         elseQuery.collectFreeVariables(vars);
34     }
35
36     @Override
37     public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
38         condition.collectRefs(allRefs, refs);
39         thenQuery.collectRefs(allRefs, refs);
40         elseQuery.collectRefs(allRefs, refs);
41     }
42
43     @Override
44     public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
45         condition.collectVars(allVars, vars);
46         thenQuery.collectVars(allVars, vars);
47         elseQuery.collectVars(allVars, vars);
48     }
49
50     @Override
51     public void checkType(TypingContext context) {
52         condition.checkType(context, Types.BOOLEAN);
53         thenQuery.checkType(context);
54         elseQuery.checkType(context);
55     }
56
57     @Override
58     public void collectConstraints(ConstraintCollectionContext context) throws UnsolvableQueryException {
59         // TODO Auto-generated method stub
60         
61     }
62
63     @Override
64     public Query replace(ReplaceContext context) {
65         return new QIf(
66                 condition.replace(context),
67                 thenQuery.replace(context),
68                 elseQuery.replace(context));
69     }
70
71     @Override
72     public void setLocationDeep(long loc) {
73         if(location == Locations.NO_LOCATION) {
74             this.location = loc;
75             condition.setLocationDeep(loc);
76             elseQuery.setLocationDeep(loc);
77             thenQuery.setLocationDeep(loc);
78         }
79     }
80
81     @Override
82     public void accept(QueryVisitor visitor) {
83         visitor.visit(this);
84     }
85
86     @Override
87     public void forVariables(VariableProcedure procedure) {
88         condition.forVariables(procedure);
89         elseQuery.forVariables(procedure);
90         thenQuery.forVariables(procedure);
91     }
92     
93     @Override
94     public Query accept(QueryTransformer transformer) {
95         return transformer.transform(this);
96     }
97     
98 }