]> gerrit.simantics Code Review - simantics/platform.git/blob
c9e29ca5b9d8a7b8c2a759929860e49c2472f3bb
[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 collectRefs(TObjectIntHashMap<Object> allRefs,
30             TIntHashSet refs) {
31         condition.collectRefs(allRefs, refs);
32     }
33
34     @Override
35     public void collectVars(TObjectIntHashMap<Variable> allVars,
36             TIntHashSet vars) {
37         condition.collectVars(allVars, vars);
38     }
39
40     @Override
41     public void collectFreeVariables(THashSet<Variable> vars) {
42         condition.collectFreeVariables(vars);
43     }
44
45     @Override
46     public CompiledQualifier compile(SimplificationContext context) {
47         return new CompiledQualifier(
48                 context.guardList(condition.copy()), 
49                 context.tuple());
50     }
51
52     @Override
53     public void resolve(TranslationContext context) {
54         condition = condition.resolve(context);        
55     }
56     
57     @Override
58     public void collectEffects(THashSet<Type> effects) {
59         condition.collectEffects(effects);
60     }
61     
62     @Override
63     public void setLocationDeep(long loc) {
64         if(location == Locations.NO_LOCATION) {
65             location = loc;
66             condition.setLocationDeep(loc);
67         }
68     }
69     
70     @Override
71     public void accept(ListQualifierVisitor visitor) {
72         visitor.visit(this);
73     }
74     
75     @Override
76     public ListQualifier accept(ListQualifierTransformer transformer) {
77         return transformer.transform(this);
78     }
79 }