X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fexpressions%2FEEquations.java;fp=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fexpressions%2FEEquations.java;h=41cea63ffb212e0aaad8f3eb56feb2d674ddcfb5;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git 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 new file mode 100644 index 000000000..41cea63ff --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEquations.java @@ -0,0 +1,124 @@ +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 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