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;
11 import gnu.trove.map.hash.TObjectIntHashMap;
12 import gnu.trove.set.hash.THashSet;
13 import gnu.trove.set.hash.TIntHashSet;
15 public class ListSeq extends ListQualifier {
16 public ListQualifier a;
17 public ListQualifier b;
19 public ListSeq(ListQualifier a, ListQualifier b) {
25 public void checkType(TypingContext context) {
31 public void collectVars(TObjectIntHashMap<Variable> allVars,
33 a.collectVars(allVars, vars);
34 b.collectVars(allVars, vars);
38 public void collectFreeVariables(THashSet<Variable> vars) {
39 b.collectFreeVariables(vars);
40 a.collectFreeVariables(vars);
44 public CompiledQualifier compile(SimplificationContext context) {
45 CompiledQualifier cA = a.compile(context);
46 CompiledQualifier cB = b.compile(context);
48 Variable x = new Variable("xTemp", cA.pattern.getType());
49 Variable y = new Variable("yTemp", cB.pattern.getType());
51 Expression value = context.concatMap(
52 context.lambda(context.var(x), context.mapList(
53 context.lambda(context.var(y), context.tuple(context.var(x), context.var(y))),
54 context.match(context.var(x), cA.pattern, cB.value))),
57 value.validateType(context.getEnvironment());
58 } catch (TypeValidationException e) {
61 return new CompiledQualifier(value, context.tuple(cA.pattern, cB.pattern));
65 public void resolve(TranslationContext context) {
71 public void collectEffects(THashSet<Type> effects) {
72 a.collectEffects(effects);
73 b.collectEffects(effects);
77 public void setLocationDeep(long loc) {
78 if(location == Locations.NO_LOCATION) {
80 a.setLocationDeep(loc);
81 b.setLocationDeep(loc);
86 public void accept(ListQualifierVisitor visitor) {
91 public ListQualifier accept(ListQualifierTransformer transformer) {
92 return transformer.transform(this);