(refs #7375) Replaced collectFreeVariables method by a visitor
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / expressions / visitors / CollectEffectsVisitor.java
1 package org.simantics.scl.compiler.elaboration.expressions.visitors;
2
3 import org.simantics.scl.compiler.elaboration.expressions.EApply;
4 import org.simantics.scl.compiler.elaboration.expressions.ECHRRuleset;
5 import org.simantics.scl.compiler.elaboration.expressions.ECHRSelect;
6 import org.simantics.scl.compiler.elaboration.expressions.EFieldAccess;
7 import org.simantics.scl.compiler.elaboration.expressions.ELambda;
8 import org.simantics.scl.compiler.elaboration.expressions.ESimpleLambda;
9 import org.simantics.scl.compiler.elaboration.expressions.ETransformation;
10 import org.simantics.scl.compiler.types.Type;
11 import org.simantics.scl.compiler.types.Types;
12
13 import gnu.trove.set.hash.THashSet;
14
15 public class CollectEffectsVisitor extends StandardExpressionVisitor {
16     public final THashSet<Type> effects = new THashSet<Type>();
17     
18     @Override
19     public void visit(EApply expression) {
20         effects.add(expression.effect);
21         super.visit(expression);
22     }
23     
24     @Override
25     public void visit(ECHRRuleset expression) {
26         effects.add(Types.PROC);
27         super.visit(expression);
28     }
29     
30     @Override
31     public void visit(ECHRSelect expression) {
32         effects.add(Types.PROC);
33         super.visit(expression);
34     }
35     
36     @Override
37     public void visit(EFieldAccess expression) {
38         // FIXME
39         effects.add(Types.READ_GRAPH);
40         super.visit(expression);
41     }
42     
43     @Override
44     public void visit(ETransformation expression) {
45         // FIXME
46         effects.add(Types.PROC);
47         super.visit(expression);
48     }
49     
50     @Override
51     public void visit(ELambda expression) {
52     }
53     
54     @Override
55     public void visit(ESimpleLambda expression) {
56     }
57     
58     public Type getCombinedEffect() {
59         return Types.union(effects.toArray(new Type[effects.size()]));
60     }
61 }