X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fexpressions%2FEEquations.java;h=3d3132cf9db7d29b07aabca403556c2c1aaa5ef1;hp=cf3774f2168628edba17b2fef342b761bbbe88ee;hb=refs%2Fchanges%2F38%2F238%2F2;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEquations.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEquations.java index cf3774f21..3d3132cf9 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEquations.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEquations.java @@ -1,129 +1,129 @@ -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 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