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