8dcfe08639d21dbc0984bb325fe5ae7ecbad9322
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / equation / EqBasic.java
1 package org.simantics.scl.compiler.elaboration.equation;
2
3 import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
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;
9
10 import gnu.trove.map.hash.TObjectIntHashMap;
11 import gnu.trove.set.hash.THashSet;
12 import gnu.trove.set.hash.TIntHashSet;
13
14 public class EqBasic extends Equation {
15     public Expression left;
16     public Expression right;
17     
18     public EqBasic(Expression left, Expression right) {
19         this.left = left;
20         this.right = right;
21     }
22     
23     public EqBasic(long location, Expression left, Expression right) {
24         this(left, right);
25         this.location = location;
26     }
27     
28     @Override
29     public void setLocationDeep(long loc) {
30         if(location == Locations.NO_LOCATION) {
31             location = loc;
32             left.setLocationDeep(loc);
33             right.setLocationDeep(loc);
34         }
35     }
36
37     @Override
38     public void collectFreeVariables(THashSet<Variable> vars) {
39         left.collectFreeVariables(vars);
40         right.collectFreeVariables(vars);
41     }
42
43     @Override
44     public void checkType(TypingContext context) {
45         left = left.inferType(context);
46         right = right.checkType(context, left.getType());
47     }
48
49     @Override
50     public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
51         left.collectVars(allVars, vars);
52         right.collectVars(allVars, vars);
53     }
54
55     @Override
56     public void resolve(TranslationContext context) {
57         left = left.resolve(context);
58         right = right.resolve(context);
59     }
60
61     @Override
62     public void accept(EquationVisitor visitor) {
63         visitor.visit(this);
64     }
65
66     @Override
67     public Equation replace(ReplaceContext context) {
68         return new EqBasic(location, left.replace(context), right.replace(context));
69     }
70 }