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