1 package org.simantics.scl.compiler.elaboration.expressions.list;
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;
13 import gnu.trove.map.hash.TObjectIntHashMap;
14 import gnu.trove.set.hash.THashSet;
15 import gnu.trove.set.hash.TIntHashSet;
17 public class ListGuard extends ListQualifier {
18 public Expression condition;
20 public ListGuard(Expression condition) {
21 this.condition = condition;
25 public void checkType(TypingContext context) {
26 condition.checkType(context, Types.BOOLEAN);
30 public void collectRefs(TObjectIntHashMap<Object> allRefs,
32 condition.collectRefs(allRefs, refs);
36 public void collectVars(TObjectIntHashMap<Variable> allVars,
38 condition.collectVars(allVars, vars);
42 public void collectFreeVariables(THashSet<Variable> vars) {
43 condition.collectFreeVariables(vars);
47 public CompiledQualifier compile(SimplificationContext context) {
48 return new CompiledQualifier(
49 context.guardList(condition.copy()),
54 public void resolve(TranslationContext context) {
55 condition = condition.resolve(context);
59 public void collectEffects(THashSet<Type> effects) {
60 condition.collectEffects(effects);
64 public void setLocationDeep(long loc) {
65 if(location == Locations.NO_LOCATION) {
67 condition.setLocationDeep(loc);
72 public void accept(ListQualifierVisitor visitor) {
77 public void forVariables(VariableProcedure procedure) {
78 condition.forVariables(procedure);
82 public ListQualifier accept(ListQualifierTransformer transformer) {
83 return transformer.transform(this);