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;
10 import gnu.trove.map.hash.TObjectIntHashMap;
11 import gnu.trove.set.hash.THashSet;
12 import gnu.trove.set.hash.TIntHashSet;
14 public class ListSeq extends ListQualifier {
15 public ListQualifier a;
16 public ListQualifier b;
18 public ListSeq(ListQualifier a, ListQualifier b) {
24 public void checkType(TypingContext context) {
30 public void collectVars(TObjectIntHashMap<Variable> allVars,
32 a.collectVars(allVars, vars);
33 b.collectVars(allVars, vars);
37 public void collectFreeVariables(THashSet<Variable> vars) {
38 b.collectFreeVariables(vars);
39 a.collectFreeVariables(vars);
43 public CompiledQualifier compile(SimplificationContext context) {
44 CompiledQualifier cA = a.compile(context);
45 CompiledQualifier cB = b.compile(context);
47 Variable x = new Variable("xTemp", cA.pattern.getType());
48 Variable y = new Variable("yTemp", cB.pattern.getType());
50 Expression value = context.concatMap(
51 context.lambda(context.var(x), context.mapList(
52 context.lambda(context.var(y), context.tuple(context.var(x), context.var(y))),
53 context.match(context.var(x), cA.pattern, cB.value))),
56 value.validateType(context.getEnvironment());
57 } catch (TypeValidationException e) {
60 return new CompiledQualifier(value, context.tuple(cA.pattern, cB.pattern));
64 public void resolve(TranslationContext context) {
70 public void setLocationDeep(long loc) {
71 if(location == Locations.NO_LOCATION) {
73 a.setLocationDeep(loc);
74 b.setLocationDeep(loc);
79 public void accept(ListQualifierVisitor visitor) {
84 public ListQualifier accept(ListQualifierTransformer transformer) {
85 return transformer.transform(this);