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