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.errors.Locations;
9 import org.simantics.scl.compiler.types.Type;
10 import org.simantics.scl.compiler.types.Types;
12 import gnu.trove.map.hash.TObjectIntHashMap;
13 import gnu.trove.set.hash.THashSet;
14 import gnu.trove.set.hash.TIntHashSet;
16 public class ListGuard extends ListQualifier {
17 public Expression condition;
19 public ListGuard(Expression condition) {
20 this.condition = condition;
24 public void checkType(TypingContext context) {
25 condition.checkType(context, Types.BOOLEAN);
29 public void collectVars(TObjectIntHashMap<Variable> allVars,
31 condition.collectVars(allVars, vars);
35 public void collectFreeVariables(THashSet<Variable> vars) {
36 condition.collectFreeVariables(vars);
40 public CompiledQualifier compile(SimplificationContext context) {
41 return new CompiledQualifier(
42 context.guardList(condition.copy()),
47 public void resolve(TranslationContext context) {
48 condition = condition.resolve(context);
52 public void collectEffects(THashSet<Type> effects) {
53 condition.collectEffects(effects);
57 public void setLocationDeep(long loc) {
58 if(location == Locations.NO_LOCATION) {
60 condition.setLocationDeep(loc);
65 public void accept(ListQualifierVisitor visitor) {
70 public ListQualifier accept(ListQualifierTransformer transformer) {
71 return transformer.transform(this);