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 collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
54 for(Equation equation : equations)
55 equation.collectRefs(allRefs, refs);
59 public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
60 for(Equation equation : equations)
61 equation.collectVars(allVars, vars);
65 protected void updateType() throws MatchException {
70 public void collectFreeVariables(THashSet<Variable> vars) {
71 for(Equation equation : equations)
72 equation.collectFreeVariables(vars);
76 public void collectEffects(THashSet<Type> effects) {
77 for(Equation equation : equations)
78 equation.collectEffects(effects);
82 public void accept(ExpressionVisitor visitor) {
87 public Expression inferType(TypingContext context) {
88 context.declareEffect(this.location, effect);
89 for(Equation equation : equations)
90 equation.checkType(context);
95 public Expression checkIgnoredType(TypingContext context) {
96 return inferType(context);
100 public Expression simplify(SimplificationContext context) {
101 context.getErrorLog().log(location, "Equations should be transformed into other expressions before simplification phase.");
102 return Expressions.tuple();
106 public Expression replace(ReplaceContext context) {
107 Equation[] newEquations = new Equation[equations.length];
108 for(int i=0;i<equations.length;++i)
109 newEquations[i] = equations[i].replace(context);
110 return new EEquations(location, newEquations);