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 collectRefs(TObjectIntHashMap<Object> allRefs,
31 condition.collectRefs(allRefs, refs);
35 public void collectVars(TObjectIntHashMap<Variable> allVars,
37 condition.collectVars(allVars, vars);
41 public void collectFreeVariables(THashSet<Variable> vars) {
42 condition.collectFreeVariables(vars);
46 public CompiledQualifier compile(SimplificationContext context) {
47 return new CompiledQualifier(
48 context.guardList(condition.copy()),
53 public void resolve(TranslationContext context) {
54 condition = condition.resolve(context);
58 public void collectEffects(THashSet<Type> effects) {
59 condition.collectEffects(effects);
63 public void setLocationDeep(long loc) {
64 if(location == Locations.NO_LOCATION) {
66 condition.setLocationDeep(loc);
71 public void accept(ListQualifierVisitor visitor) {
76 public ListQualifier accept(ListQualifierTransformer transformer) {
77 return transformer.transform(this);