]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEquations.java
Fixed leftover problems in unification of *Array and Vector types
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / expressions / EEquations.java
1 package org.simantics.scl.compiler.elaboration.expressions;
2
3 import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
4 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
5 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
6 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
7 import org.simantics.scl.compiler.elaboration.equation.Equation;
8 import org.simantics.scl.compiler.errors.Locations;
9 import org.simantics.scl.compiler.types.Type;
10 import org.simantics.scl.compiler.types.Types;
11 import org.simantics.scl.compiler.types.exceptions.MatchException;
12
13 public class EEquations extends SimplifiableExpression {
14
15     public Equation[] equations;
16     public Type effect = Types.NO_EFFECTS;
17     
18     public EEquations(Equation[] equations) {
19         this.equations = equations;
20     }
21     
22     public EEquations(long location, Equation[] equations) {
23         this(equations);
24         this.location = location;
25     }
26
27     @Override
28     public Expression resolve(TranslationContext context) {
29         for(Equation equation : equations)
30             equation.resolve(context);       
31         return this;
32     }
33
34     @Override
35     public void setLocationDeep(long loc) {
36         if(location == Locations.NO_LOCATION) {
37             location = loc;
38             for(Equation equation : equations)
39                 equation.setLocationDeep(loc);
40         }
41     }
42
43     @Override
44     public Expression accept(ExpressionTransformer transformer) {
45         return transformer.transform(this);
46     }
47
48     @Override
49     protected void updateType() throws MatchException {
50         setType(Types.UNIT);
51     }
52
53     @Override
54     public void accept(ExpressionVisitor visitor) {
55         visitor.visit(this);
56     }
57     
58     @Override
59     public Expression inferType(TypingContext context) {
60         context.declareEffect(this.location, effect);
61         for(Equation equation : equations)
62             equation.checkType(context);
63         return this;
64     }
65     
66     @Override
67     public Expression checkIgnoredType(TypingContext context) {
68         return inferType(context);
69     }
70
71     @Override
72     public Expression simplify(SimplificationContext context) {
73         context.getErrorLog().log(location, "Equations should be transformed into other expressions before simplification phase.");
74         return Expressions.tuple();
75     }
76     
77     @Override
78     public Expression replace(ReplaceContext context) {
79         Equation[] newEquations = new Equation[equations.length];
80         for(int i=0;i<equations.length;++i)
81             newEquations[i] = equations[i].replace(context);
82         return new EEquations(location, newEquations);
83     }
84
85 }