1 package org.simantics.scl.compiler.elaboration.expressions.list;
\r
3 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
\r
4 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
\r
5 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
\r
6 import org.simantics.scl.compiler.elaboration.expressions.Expression;
\r
7 import org.simantics.scl.compiler.elaboration.expressions.Variable;
\r
8 import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure;
\r
9 import org.simantics.scl.compiler.errors.Locations;
\r
10 import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;
\r
11 import org.simantics.scl.compiler.types.Type;
\r
13 import gnu.trove.map.hash.TObjectIntHashMap;
\r
14 import gnu.trove.set.hash.THashSet;
\r
15 import gnu.trove.set.hash.TIntHashSet;
\r
17 public class ListSeq extends ListQualifier {
\r
18 public ListQualifier a;
\r
19 public ListQualifier b;
\r
21 public ListSeq(ListQualifier a, ListQualifier b) {
\r
27 public void checkType(TypingContext context) {
\r
28 a.checkType(context);
\r
29 b.checkType(context);
\r
33 public void collectRefs(TObjectIntHashMap<Object> allRefs,
\r
35 a.collectRefs(allRefs, refs);
\r
36 b.collectRefs(allRefs, refs);
\r
40 public void collectVars(TObjectIntHashMap<Variable> allVars,
\r
42 a.collectVars(allVars, vars);
\r
43 b.collectVars(allVars, vars);
\r
47 public void collectFreeVariables(THashSet<Variable> vars) {
\r
48 b.collectFreeVariables(vars);
\r
49 a.collectFreeVariables(vars);
\r
53 public CompiledQualifier compile(SimplificationContext context) {
\r
54 CompiledQualifier cA = a.compile(context);
\r
55 CompiledQualifier cB = b.compile(context);
\r
57 Variable x = new Variable("xTemp", cA.pattern.getType());
\r
58 Variable y = new Variable("yTemp", cB.pattern.getType());
\r
60 Expression value = context.concatMap(
\r
61 context.lambda(context.var(x), context.mapList(
\r
62 context.lambda(context.var(y), context.tuple(context.var(x), context.var(y))),
\r
63 context.match(context.var(x), cA.pattern, cB.value))),
\r
66 value.validateType(context.getEnvironment());
\r
67 } catch (TypeValidationException e) {
\r
68 e.printStackTrace();
\r
70 return new CompiledQualifier(value, context.tuple(cA.pattern, cB.pattern));
\r
74 public void resolve(TranslationContext context) {
\r
80 public void decorate(ExpressionDecorator decorator) {
\r
81 a.decorate(decorator);
\r
82 b.decorate(decorator);
\r
86 public void collectEffects(THashSet<Type> effects) {
\r
87 a.collectEffects(effects);
\r
88 b.collectEffects(effects);
\r
92 public void setLocationDeep(long loc) {
\r
93 if(location == Locations.NO_LOCATION) {
\r
95 a.setLocationDeep(loc);
\r
96 b.setLocationDeep(loc);
\r
101 public void accept(ListQualifierVisitor visitor) {
\r
102 visitor.visit(this);
\r
106 public void forVariables(VariableProcedure procedure) {
\r
107 a.forVariables(procedure);
\r
108 b.forVariables(procedure);
\r
112 public ListQualifier accept(ListQualifierTransformer transformer) {
\r
113 return transformer.transform(this);
\r