]> gerrit.simantics Code Review - simantics/platform.git/blob
1deaf92fae998d8a1bc2bcb1a83d484f2ba5c1ad
[simantics/platform.git] /
1 package org.simantics.scl.compiler.elaboration.expressions.list;
2
3 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
4 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
5 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
6 import org.simantics.scl.compiler.elaboration.expressions.Expression;
7 import org.simantics.scl.compiler.elaboration.expressions.Variable;
8 import org.simantics.scl.compiler.errors.Locations;
9 import org.simantics.scl.compiler.types.Types;
10
11 import gnu.trove.map.hash.TObjectIntHashMap;
12 import gnu.trove.set.hash.THashSet;
13 import gnu.trove.set.hash.TIntHashSet;
14
15 public class ListGuard extends ListQualifier {
16     public Expression condition;
17
18     public ListGuard(Expression condition) {
19         this.condition = condition;
20     }
21
22     @Override
23     public void checkType(TypingContext context) {
24         condition.checkType(context, Types.BOOLEAN);
25     }
26
27     @Override
28     public void collectVars(TObjectIntHashMap<Variable> allVars,
29             TIntHashSet vars) {
30         condition.collectVars(allVars, vars);
31     }
32
33     @Override
34     public void collectFreeVariables(THashSet<Variable> vars) {
35         condition.collectFreeVariables(vars);
36     }
37
38     @Override
39     public CompiledQualifier compile(SimplificationContext context) {
40         return new CompiledQualifier(
41                 context.guardList(condition.copy()), 
42                 context.tuple());
43     }
44
45     @Override
46     public void resolve(TranslationContext context) {
47         condition = condition.resolve(context);
48     }
49
50     @Override
51     public void setLocationDeep(long loc) {
52         if(location == Locations.NO_LOCATION) {
53             location = loc;
54             condition.setLocationDeep(loc);
55         }
56     }
57     
58     @Override
59     public void accept(ListQualifierVisitor visitor) {
60         visitor.visit(this);
61     }
62     
63     @Override
64     public ListQualifier accept(ListQualifierTransformer transformer) {
65         return transformer.transform(this);
66     }
67 }