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 collectRefs(TObjectIntHashMap<Object> allRefs,
33 a.collectRefs(allRefs, refs);
34 b.collectRefs(allRefs, refs);
38 public void collectVars(TObjectIntHashMap<Variable> allVars,
40 a.collectVars(allVars, vars);
41 b.collectVars(allVars, vars);
45 public void collectFreeVariables(THashSet<Variable> vars) {
46 b.collectFreeVariables(vars);
47 a.collectFreeVariables(vars);
51 public CompiledQualifier compile(SimplificationContext context) {
52 CompiledQualifier cA = a.compile(context);
53 CompiledQualifier cB = b.compile(context);
55 Variable x = new Variable("xTemp", cA.pattern.getType());
56 Variable y = new Variable("yTemp", cB.pattern.getType());
58 Expression value = context.concatMap(
59 context.lambda(context.var(x), context.mapList(
60 context.lambda(context.var(y), context.tuple(context.var(x), context.var(y))),
61 context.match(context.var(x), cA.pattern, cB.value))),
64 value.validateType(context.getEnvironment());
65 } catch (TypeValidationException e) {
68 return new CompiledQualifier(value, context.tuple(cA.pattern, cB.pattern));
72 public void resolve(TranslationContext context) {
78 public void collectEffects(THashSet<Type> effects) {
79 a.collectEffects(effects);
80 b.collectEffects(effects);
84 public void setLocationDeep(long loc) {
85 if(location == Locations.NO_LOCATION) {
87 a.setLocationDeep(loc);
88 b.setLocationDeep(loc);
93 public void accept(ListQualifierVisitor visitor) {
98 public ListQualifier accept(ListQualifierTransformer transformer) {
99 return transformer.transform(this);