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