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