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