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;
13 import gnu.trove.map.hash.TObjectIntHashMap;
14 import gnu.trove.set.hash.THashSet;
15 import gnu.trove.set.hash.TIntHashSet;
17 public class ListSeq extends ListQualifier {
18 public ListQualifier a;
19 public ListQualifier b;
21 public ListSeq(ListQualifier a, ListQualifier b) {
27 public void checkType(TypingContext context) {
33 public void collectRefs(TObjectIntHashMap<Object> allRefs,
35 a.collectRefs(allRefs, refs);
36 b.collectRefs(allRefs, refs);
40 public void collectVars(TObjectIntHashMap<Variable> allVars,
42 a.collectVars(allVars, vars);
43 b.collectVars(allVars, vars);
47 public void collectFreeVariables(THashSet<Variable> vars) {
48 b.collectFreeVariables(vars);
49 a.collectFreeVariables(vars);
53 public CompiledQualifier compile(SimplificationContext context) {
54 CompiledQualifier cA = a.compile(context);
55 CompiledQualifier cB = b.compile(context);
57 Variable x = new Variable("xTemp", cA.pattern.getType());
58 Variable y = new Variable("yTemp", cB.pattern.getType());
60 Expression value = context.concatMap(
61 context.lambda(context.var(x), context.mapList(
62 context.lambda(context.var(y), context.tuple(context.var(x), context.var(y))),
63 context.match(context.var(x), cA.pattern, cB.value))),
66 value.validateType(context.getEnvironment());
67 } catch (TypeValidationException e) {
70 return new CompiledQualifier(value, context.tuple(cA.pattern, cB.pattern));
74 public void resolve(TranslationContext context) {
80 public void decorate(ExpressionDecorator decorator) {
81 a.decorate(decorator);
82 b.decorate(decorator);
86 public void collectEffects(THashSet<Type> effects) {
87 a.collectEffects(effects);
88 b.collectEffects(effects);
92 public void setLocationDeep(long loc) {
93 if(location == Locations.NO_LOCATION) {
95 a.setLocationDeep(loc);
96 b.setLocationDeep(loc);
101 public void accept(ListQualifierVisitor visitor) {
106 public void forVariables(VariableProcedure procedure) {
107 a.forVariables(procedure);
108 b.forVariables(procedure);
112 public ListQualifier accept(ListQualifierTransformer transformer) {
113 return transformer.transform(this);