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.TIntHashSet;
16 public class EEquations extends SimplifiableExpression {
18 public Equation[] equations;
19 public Type effect = Types.NO_EFFECTS;
21 public EEquations(Equation[] equations) {
22 this.equations = equations;
25 public EEquations(long location, Equation[] equations) {
27 this.location = location;
31 public Expression resolve(TranslationContext context) {
32 for(Equation equation : equations)
33 equation.resolve(context);
38 public void setLocationDeep(long loc) {
39 if(location == Locations.NO_LOCATION) {
41 for(Equation equation : equations)
42 equation.setLocationDeep(loc);
47 public Expression accept(ExpressionTransformer transformer) {
48 return transformer.transform(this);
52 public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
53 for(Equation equation : equations)
54 equation.collectVars(allVars, vars);
58 protected void updateType() throws MatchException {
63 public void accept(ExpressionVisitor visitor) {
68 public Expression inferType(TypingContext context) {
69 context.declareEffect(this.location, effect);
70 for(Equation equation : equations)
71 equation.checkType(context);
76 public Expression checkIgnoredType(TypingContext context) {
77 return inferType(context);
81 public Expression simplify(SimplificationContext context) {
82 context.getErrorLog().log(location, "Equations should be transformed into other expressions before simplification phase.");
83 return Expressions.tuple();
87 public Expression replace(ReplaceContext context) {
88 Equation[] newEquations = new Equation[equations.length];
89 for(int i=0;i<equations.length;++i)
90 newEquations[i] = equations[i].replace(context);
91 return new EEquations(location, newEquations);