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.types.Type;
12 import gnu.trove.map.hash.TObjectIntHashMap;
13 import gnu.trove.set.hash.THashSet;
14 import gnu.trove.set.hash.TIntHashSet;
16 public class ListSeq extends ListQualifier {
17 public ListQualifier a;
18 public ListQualifier b;
20 public ListSeq(ListQualifier a, ListQualifier b) {
26 public void checkType(TypingContext context) {
32 public void collectRefs(TObjectIntHashMap<Object> allRefs,
34 a.collectRefs(allRefs, refs);
35 b.collectRefs(allRefs, refs);
39 public void collectVars(TObjectIntHashMap<Variable> allVars,
41 a.collectVars(allVars, vars);
42 b.collectVars(allVars, vars);
46 public void collectFreeVariables(THashSet<Variable> vars) {
47 b.collectFreeVariables(vars);
48 a.collectFreeVariables(vars);
52 public CompiledQualifier compile(SimplificationContext context) {
53 CompiledQualifier cA = a.compile(context);
54 CompiledQualifier cB = b.compile(context);
56 Variable x = new Variable("xTemp", cA.pattern.getType());
57 Variable y = new Variable("yTemp", cB.pattern.getType());
59 Expression value = context.concatMap(
60 context.lambda(context.var(x), context.mapList(
61 context.lambda(context.var(y), context.tuple(context.var(x), context.var(y))),
62 context.match(context.var(x), cA.pattern, cB.value))),
65 value.validateType(context.getEnvironment());
66 } catch (TypeValidationException e) {
69 return new CompiledQualifier(value, context.tuple(cA.pattern, cB.pattern));
73 public void resolve(TranslationContext context) {
79 public void collectEffects(THashSet<Type> effects) {
80 a.collectEffects(effects);
81 b.collectEffects(effects);
85 public void setLocationDeep(long loc) {
86 if(location == Locations.NO_LOCATION) {
88 a.setLocationDeep(loc);
89 b.setLocationDeep(loc);
94 public void accept(ListQualifierVisitor visitor) {
99 public void forVariables(VariableProcedure procedure) {
100 a.forVariables(procedure);
101 b.forVariables(procedure);
105 public ListQualifier accept(ListQualifierTransformer transformer) {
106 return transformer.transform(this);