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.internal.elaboration.utils.ExpressionDecorator;
10 import org.simantics.scl.compiler.types.Type;
11 import org.simantics.scl.compiler.types.Types;
12 import org.simantics.scl.compiler.types.exceptions.MatchException;
14 import gnu.trove.map.hash.TObjectIntHashMap;
15 import gnu.trove.set.hash.THashSet;
16 import gnu.trove.set.hash.TIntHashSet;
18 public class EEquations extends SimplifiableExpression {
20 public Equation[] equations;
21 public Type effect = Types.NO_EFFECTS;
23 public EEquations(Equation[] equations) {
24 this.equations = equations;
27 public EEquations(long location, Equation[] equations) {
29 this.location = location;
33 public Expression resolve(TranslationContext context) {
34 for(Equation equation : equations)
35 equation.resolve(context);
40 public void setLocationDeep(long loc) {
41 if(location == Locations.NO_LOCATION) {
43 for(Equation equation : equations)
44 equation.setLocationDeep(loc);
49 public Expression accept(ExpressionTransformer transformer) {
50 return transformer.transform(this);
54 public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
55 for(Equation equation : equations)
56 equation.collectRefs(allRefs, refs);
60 public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
61 for(Equation equation : equations)
62 equation.collectVars(allVars, vars);
66 public void forVariables(VariableProcedure procedure) {
67 for(Equation equation : equations)
68 equation.forVariables(procedure);
72 protected void updateType() throws MatchException {
77 public void collectFreeVariables(THashSet<Variable> vars) {
78 for(Equation equation : equations)
79 equation.collectFreeVariables(vars);
83 public Expression decorate(ExpressionDecorator decorator) {
84 if(decorator.decorateSubstructure(this)) {
85 for(Equation equation : equations)
86 equation.decorate(decorator);
92 public void collectEffects(THashSet<Type> effects) {
93 for(Equation equation : equations)
94 equation.collectEffects(effects);
98 public void accept(ExpressionVisitor visitor) {
103 public Expression inferType(TypingContext context) {
104 context.declareEffect(this.location, effect);
105 for(Equation equation : equations)
106 equation.checkType(context);
111 public Expression checkIgnoredType(TypingContext context) {
112 return inferType(context);
116 public Expression simplify(SimplificationContext context) {
117 context.getErrorLog().log(location, "Equations should be transformed into other expressions before simplification phase.");
118 return Expressions.tuple();
122 public Expression replace(ReplaceContext context) {
123 Equation[] newEquations = new Equation[equations.length];
124 for(int i=0;i<equations.length;++i)
125 newEquations[i] = equations[i].replace(context);
126 return new EEquations(location, newEquations);