]> gerrit.simantics Code Review - simantics/platform.git/blob
f56820d2a3e9496af3cdb5b6b67c85d1b92401f7
[simantics/platform.git] /
1 package org.simantics.scl.compiler.elaboration.expressions.list;
2
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;
11
12 import gnu.trove.map.hash.TObjectIntHashMap;
13 import gnu.trove.set.hash.THashSet;
14 import gnu.trove.set.hash.TIntHashSet;
15
16 public class ListSeq extends ListQualifier {
17     public ListQualifier a;
18     public ListQualifier b;
19     
20     public ListSeq(ListQualifier a, ListQualifier b) {
21         this.a = a;
22         this.b = b;
23     }
24
25     @Override
26     public void checkType(TypingContext context) {
27         a.checkType(context);
28         b.checkType(context);  
29     }
30     
31     @Override
32     public void collectRefs(TObjectIntHashMap<Object> allRefs,
33             TIntHashSet refs) {
34         a.collectRefs(allRefs, refs);
35         b.collectRefs(allRefs, refs);
36     }
37
38     @Override
39     public void collectVars(TObjectIntHashMap<Variable> allVars,
40             TIntHashSet vars) {
41         a.collectVars(allVars, vars);
42         b.collectVars(allVars, vars);
43     }
44
45     @Override
46     public void collectFreeVariables(THashSet<Variable> vars) {
47         b.collectFreeVariables(vars);
48         a.collectFreeVariables(vars);
49     }
50
51     @Override
52     public CompiledQualifier compile(SimplificationContext context) {
53         CompiledQualifier cA = a.compile(context);
54         CompiledQualifier cB = b.compile(context);      
55         
56         Variable x = new Variable("xTemp", cA.pattern.getType());
57         Variable y = new Variable("yTemp", cB.pattern.getType());
58         
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))), 
63                         cA.value);
64         /*try {
65             value.validateType(context.getEnvironment());
66         } catch (TypeValidationException e) {
67             e.printStackTrace();
68         }*/
69         return new CompiledQualifier(value, context.tuple(cA.pattern, cB.pattern));
70     }
71
72     @Override
73     public void resolve(TranslationContext context) {
74         a.resolve(context);
75         b.resolve(context);
76     }
77     
78     @Override
79     public void collectEffects(THashSet<Type> effects) {
80         a.collectEffects(effects);
81         b.collectEffects(effects);
82     }
83     
84     @Override
85     public void setLocationDeep(long loc) {
86         if(location == Locations.NO_LOCATION) {
87             location = loc;
88             a.setLocationDeep(loc);
89             b.setLocationDeep(loc);
90         }
91     }
92     
93     @Override
94     public void accept(ListQualifierVisitor visitor) {
95         visitor.visit(this);
96     }
97     
98     @Override
99     public void forVariables(VariableProcedure procedure) {
100         a.forVariables(procedure);
101         b.forVariables(procedure);
102     }
103     
104     @Override
105     public ListQualifier accept(ListQualifierTransformer transformer) {
106         return transformer.transform(this);
107     }
108 }