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.internal.elaboration.utils.ExpressionDecorator;
11 import org.simantics.scl.compiler.types.Type;
12 import org.simantics.scl.compiler.types.Types;
14 import gnu.trove.map.hash.TObjectIntHashMap;
15 import gnu.trove.set.hash.THashSet;
16 import gnu.trove.set.hash.TIntHashSet;
18 public class ListGuard extends ListQualifier {
19 public Expression condition;
21 public ListGuard(Expression condition) {
22 this.condition = condition;
26 public void checkType(TypingContext context) {
27 condition.checkType(context, Types.BOOLEAN);
31 public void collectRefs(TObjectIntHashMap<Object> allRefs,
33 condition.collectRefs(allRefs, refs);
37 public void collectVars(TObjectIntHashMap<Variable> allVars,
39 condition.collectVars(allVars, vars);
43 public void collectFreeVariables(THashSet<Variable> vars) {
44 condition.collectFreeVariables(vars);
48 public CompiledQualifier compile(SimplificationContext context) {
49 return new CompiledQualifier(
50 context.guardList(condition.copy()),
55 public void resolve(TranslationContext context) {
56 condition = condition.resolve(context);
60 public void decorate(ExpressionDecorator decorator) {
61 condition = condition.decorate(decorator);
65 public void collectEffects(THashSet<Type> effects) {
66 condition.collectEffects(effects);
70 public void setLocationDeep(long loc) {
71 if(location == Locations.NO_LOCATION) {
73 condition.setLocationDeep(loc);
78 public void accept(ListQualifierVisitor visitor) {
83 public void forVariables(VariableProcedure procedure) {
84 condition.forVariables(procedure);
88 public ListQualifier accept(ListQualifierTransformer transformer) {
89 return transformer.transform(this);