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