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 public void forVariables(VariableProcedure procedure) {
66 for(Equation equation : equations)
67 equation.forVariables(procedure);
71 protected void updateType() throws MatchException {
76 public void collectFreeVariables(THashSet<Variable> vars) {
77 for(Equation equation : equations)
78 equation.collectFreeVariables(vars);
82 public void collectEffects(THashSet<Type> effects) {
83 for(Equation equation : equations)
84 equation.collectEffects(effects);
88 public void accept(ExpressionVisitor visitor) {
93 public Expression inferType(TypingContext context) {
94 context.declareEffect(this.location, effect);
95 for(Equation equation : equations)
96 equation.checkType(context);
101 public Expression checkIgnoredType(TypingContext context) {
102 return inferType(context);
106 public Expression simplify(SimplificationContext context) {
107 context.getErrorLog().log(location, "Equations should be transformed into other expressions before simplification phase.");
108 return Expressions.tuple();
112 public Expression replace(ReplaceContext context) {
113 Equation[] newEquations = new Equation[equations.length];
114 for(int i=0;i<equations.length;++i)
115 newEquations[i] = equations[i].replace(context);
116 return new EEquations(location, newEquations);