package org.simantics.scl.compiler.elaboration.expressions; import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext; import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.elaboration.equation.Equation; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; import org.simantics.scl.compiler.types.exceptions.MatchException; import gnu.trove.map.hash.TObjectIntHashMap; import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class EEquations extends SimplifiableExpression { public Equation[] equations; public Type effect = Types.NO_EFFECTS; public EEquations(Equation[] equations) { this.equations = equations; } public EEquations(long location, Equation[] equations) { this(equations); this.location = location; } @Override public Expression resolve(TranslationContext context) { for(Equation equation : equations) equation.resolve(context); return this; } @Override public void setLocationDeep(long loc) { if(location == Locations.NO_LOCATION) { location = loc; for(Equation equation : equations) equation.setLocationDeep(loc); } } @Override public Expression accept(ExpressionTransformer transformer) { return transformer.transform(this); } @Override public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { for(Equation equation : equations) equation.collectRefs(allRefs, refs); } @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { for(Equation equation : equations) equation.collectVars(allVars, vars); } @Override public void forVariables(VariableProcedure procedure) { for(Equation equation : equations) equation.forVariables(procedure); } @Override protected void updateType() throws MatchException { setType(Types.UNIT); } @Override public void collectFreeVariables(THashSet vars) { for(Equation equation : equations) equation.collectFreeVariables(vars); } @Override public Expression decorate(ExpressionDecorator decorator) { if(decorator.decorateSubstructure(this)) { for(Equation equation : equations) equation.decorate(decorator); } return this; } @Override public void collectEffects(THashSet effects) { for(Equation equation : equations) equation.collectEffects(effects); } @Override public void accept(ExpressionVisitor visitor) { visitor.visit(this); } @Override public Expression inferType(TypingContext context) { context.declareEffect(this.location, effect); for(Equation equation : equations) equation.checkType(context); return this; } @Override public Expression checkIgnoredType(TypingContext context) { return inferType(context); } @Override public Expression simplify(SimplificationContext context) { context.getErrorLog().log(location, "Equations should be transformed into other expressions before simplification phase."); return Expressions.tuple(); } @Override public Expression replace(ReplaceContext context) { Equation[] newEquations = new Equation[equations.length]; for(int i=0;i