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 collectEffects(THashSet<Type> effects) {
71 for(Equation equation : equations)
72 equation.collectEffects(effects);
76 public void accept(ExpressionVisitor visitor) {
81 public Expression inferType(TypingContext context) {
82 context.declareEffect(this.location, effect);
83 for(Equation equation : equations)
84 equation.checkType(context);
89 public Expression checkIgnoredType(TypingContext context) {
90 return inferType(context);
94 public Expression simplify(SimplificationContext context) {
95 context.getErrorLog().log(location, "Equations should be transformed into other expressions before simplification phase.");
96 return Expressions.tuple();
100 public Expression replace(ReplaceContext context) {
101 Equation[] newEquations = new Equation[equations.length];
102 for(int i=0;i<equations.length;++i)
103 newEquations[i] = equations[i].replace(context);
104 return new EEquations(location, newEquations);