1 package org.simantics.scl.compiler.elaboration.expressions;
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;
13 import gnu.trove.map.hash.TObjectIntHashMap;
14 import gnu.trove.set.hash.THashSet;
15 import gnu.trove.set.hash.TIntHashSet;
17 public class EEquations extends SimplifiableExpression {
19 public Equation[] equations;
20 public Type effect = Types.NO_EFFECTS;
22 public EEquations(Equation[] equations) {
23 this.equations = equations;
26 public EEquations(long location, Equation[] equations) {
28 this.location = location;
32 public Expression resolve(TranslationContext context) {
33 for(Equation equation : equations)
34 equation.resolve(context);
39 public void setLocationDeep(long loc) {
40 if(location == Locations.NO_LOCATION) {
42 for(Equation equation : equations)
43 equation.setLocationDeep(loc);
48 public Expression accept(ExpressionTransformer transformer) {
49 return transformer.transform(this);
53 public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
54 for(Equation equation : equations)
55 equation.collectVars(allVars, vars);
59 protected void updateType() throws MatchException {
64 public void collectFreeVariables(THashSet<Variable> vars) {
65 for(Equation equation : equations)
66 equation.collectFreeVariables(vars);
70 public void accept(ExpressionVisitor visitor) {
75 public Expression inferType(TypingContext context) {
76 context.declareEffect(this.location, effect);
77 for(Equation equation : equations)
78 equation.checkType(context);
83 public Expression checkIgnoredType(TypingContext context) {
84 return inferType(context);
88 public Expression simplify(SimplificationContext context) {
89 context.getErrorLog().log(location, "Equations should be transformed into other expressions before simplification phase.");
90 return Expressions.tuple();
94 public Expression replace(ReplaceContext context) {
95 Equation[] newEquations = new Equation[equations.length];
96 for(int i=0;i<equations.length;++i)
97 newEquations[i] = equations[i].replace(context);
98 return new EEquations(location, newEquations);