From: Hannu Niemistö Date: Fri, 21 Jul 2017 08:00:46 +0000 (+0300) Subject: (refs #7375) Replaced ExpressionDecorator by ExpressionTransformer X-Git-Tag: v1.31.0~264^2~44 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F37%2F737%2F1;p=simantics%2Fplatform.git (refs #7375) Replaced ExpressionDecorator by ExpressionTransformer Change-Id: I4396a632a63902afd38065834d9c96c159bba9c1 --- diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/EqBasic.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/EqBasic.java index 80d2a7578..121166f6b 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/EqBasic.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/EqBasic.java @@ -7,7 +7,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Expression; import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure; import org.simantics.scl.compiler.errors.Locations; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.types.Type; import gnu.trove.map.hash.TObjectIntHashMap; @@ -49,12 +48,6 @@ public class EqBasic extends Equation { right.collectFreeVariables(vars); } - @Override - public void decorate(ExpressionDecorator decorator) { - left = left.decorate(decorator); - right = right.decorate(decorator); - } - @Override public void collectEffects(THashSet effects) { left.collectEffects(effects); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/EqGuard.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/EqGuard.java index c8bf5c120..bbd464139 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/EqGuard.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/EqGuard.java @@ -7,7 +7,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Expression; import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure; import org.simantics.scl.compiler.errors.Locations; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.types.Type; import gnu.trove.map.hash.TObjectIntHashMap; @@ -44,11 +43,6 @@ public class EqGuard extends Equation { guard.collectFreeVariables(vars); } - @Override - public void decorate(ExpressionDecorator decorator) { - guard = guard.decorate(decorator); - } - @Override public void collectEffects(THashSet effects) { guard.collectEffects(effects); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/Equation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/Equation.java index dbd22037f..34ef75395 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/Equation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/Equation.java @@ -5,7 +5,6 @@ import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.parsing.Symbol; import org.simantics.scl.compiler.types.Type; @@ -20,7 +19,6 @@ public abstract class Equation extends Symbol { public abstract void forVariables(VariableProcedure procedure); public abstract void collectFreeVariables(THashSet vars); - public abstract void decorate(ExpressionDecorator decorator); public abstract void collectEffects(THashSet effects); public abstract void checkType(TypingContext context); public abstract void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ASTExpression.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ASTExpression.java index 02db9bdec..a853dfff6 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ASTExpression.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ASTExpression.java @@ -4,7 +4,6 @@ import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; import org.simantics.scl.compiler.elaboration.contexts.TypingContext; 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.exceptions.MatchException; @@ -43,11 +42,6 @@ public abstract class ASTExpression extends SimplifiableExpression { throw new InternalCompilerError(getClass().getSimpleName() + " does not support updateType."); } - @Override - final public Expression decorate(ExpressionDecorator decorator) { - throw new InternalCompilerError(getClass().getSimpleName() + " does not support decorate."); - } - @Override final public void collectEffects(THashSet effects) { throw new InternalCompilerError(getClass().getSimpleName() + " does not support collectEffects."); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Assignment.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Assignment.java index 7cc70aaa7..04b70deb0 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Assignment.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Assignment.java @@ -1,7 +1,6 @@ package org.simantics.scl.compiler.elaboration.expressions; import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.types.Type; public class Assignment { @@ -25,11 +24,6 @@ public class Assignment { return new Assignment(newPattern, newValue); } - public void decorate(ExpressionDecorator decorator) { - pattern = pattern.decorate(decorator); - value = value.decorate(decorator); - } - public void setLocationDeep(long loc) { pattern.setLocationDeep(loc); value.setLocationDeep(loc); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Case.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Case.java index 4a34cebcf..3765fbefc 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Case.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Case.java @@ -5,7 +5,6 @@ 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.errors.Locations; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.parsing.Symbol; import org.simantics.scl.compiler.types.Type; @@ -110,12 +109,6 @@ public class Case extends Symbol { patterns[i] = patterns[i].checkTypeAsPattern(context, parameterTypes[i]); value = value.checkIgnoredType(context); } - - public void decorate(ExpressionDecorator decorator) { - for(int i=0;i effects) { expression.collectEffects(effects); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EAmbiguous.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EAmbiguous.java index 6121a57b1..09cbcf25b 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EAmbiguous.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EAmbiguous.java @@ -6,7 +6,6 @@ import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.errors.ErrorLog; import org.simantics.scl.compiler.errors.Locations; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.types.Skeletons; import org.simantics.scl.compiler.types.TMetaVar; import org.simantics.scl.compiler.types.Type; @@ -189,11 +188,6 @@ public class EAmbiguous extends SimplifiableExpression { location = loc; } - @Override - public Expression decorate(ExpressionDecorator decorator) { - return this; - } - @Override public void collectEffects(THashSet effects) { // TODO Auto-generated method stub diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApply.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApply.java index c7bce4667..2b488068d 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApply.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApply.java @@ -19,7 +19,6 @@ import org.simantics.scl.compiler.elaboration.modules.SCLValue; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.interpreted.IApply; import org.simantics.scl.compiler.internal.interpreted.IExpression; import org.simantics.scl.compiler.internal.interpreted.IListLiteral; @@ -303,16 +302,6 @@ public class EApply extends Expression { return new ESimpleLet(location, null, this, new ELiteral(NoRepConstant.PUNIT)); return this; } - - @Override - public Expression decorate(ExpressionDecorator decorator) { - if(decorator.decorateSubstructure(this)) { - function = function.decorate(decorator); - for(int i=0;i effects) { pattern.collectEffects(effects); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRuleset.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRuleset.java index 65ce2e2df..2f8771930 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRuleset.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRuleset.java @@ -8,7 +8,6 @@ import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.interpreted.IExpression; import org.simantics.scl.compiler.top.ExpressionInterpretationContext; import org.simantics.scl.compiler.types.Type; @@ -84,11 +83,6 @@ public class ECHRRuleset extends Expression { } } @Override - public Expression decorate(ExpressionDecorator decorator) { - in = in.decorate(decorator); - return this; - } - @Override public void collectEffects(THashSet effects) { ruleset.collectEffects(effects); in.collectEffects(effects); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRulesetConstructor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRulesetConstructor.java index 7965b5011..ce0385f81 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRulesetConstructor.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRulesetConstructor.java @@ -9,7 +9,6 @@ import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.interpreted.IExpression; import org.simantics.scl.compiler.top.ExpressionInterpretationContext; import org.simantics.scl.compiler.types.Type; @@ -67,10 +66,6 @@ public class ECHRRulesetConstructor extends Expression { } } @Override - public Expression decorate(ExpressionDecorator decorator) { - return this; - } - @Override public void collectEffects(THashSet effects) { ruleset.collectEffects(effects); } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRSelect.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRSelect.java index 47c007d7f..aa232cdb5 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRSelect.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRSelect.java @@ -17,7 +17,6 @@ import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; -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; @@ -127,12 +126,6 @@ public class ECHRSelect extends Expression { } } - @Override - public Expression decorate(ExpressionDecorator decorator) { - this.expression = decorator.decorate(expression); - return this; - } - @Override public void collectEffects(THashSet effects) { expression.collectEffects(effects); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java index 6b99e6d37..c5b4681a8 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java @@ -17,7 +17,6 @@ import org.simantics.scl.compiler.elaboration.modules.SCLValue; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.interpreted.IConstant; import org.simantics.scl.compiler.internal.interpreted.IExpression; import org.simantics.scl.compiler.top.ExpressionInterpretationContext; @@ -234,11 +233,6 @@ public class EConstant extends Expression { else return applyPUnit(context); } - - @Override - public Expression decorate(ExpressionDecorator decorator) { - return decorator.decorate(this); - } @Override public boolean isEffectful() { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEnforce.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEnforce.java index 53d9037e2..ea657f8b1 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEnforce.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEnforce.java @@ -9,7 +9,6 @@ import org.simantics.scl.compiler.elaboration.query.QExists; import org.simantics.scl.compiler.elaboration.query.Query; import org.simantics.scl.compiler.elaboration.query.compilation.EnforcingContext; 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; @@ -84,11 +83,6 @@ public class EEnforce extends SimplifiableExpression { query = new QExists(variables, query); return this; } - - @Override - public Expression decorate(ExpressionDecorator decorator) { - return decorator.decorate(this); - } @Override public void setLocationDeep(long loc) { 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 3d3132cf9..eec5a5888 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 @@ -6,7 +6,6 @@ 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; @@ -79,15 +78,6 @@ public class EEquations extends SimplifiableExpression { 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) diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EError.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EError.java index b329beb19..fbe8cde2a 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EError.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EError.java @@ -8,7 +8,6 @@ import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; -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; @@ -69,11 +68,6 @@ public class EError extends Expression { return this; } - @Override - public Expression decorate(ExpressionDecorator decorator) { - return this; - } - @Override public void collectEffects(THashSet effects) { } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EExternalConstant.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EExternalConstant.java index 4777b2dfb..1e8341e66 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EExternalConstant.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EExternalConstant.java @@ -8,12 +8,10 @@ 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.environment.Environment; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; import org.simantics.scl.compiler.internal.codegen.writer.ModuleWriter; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.interpreted.IConstant; import org.simantics.scl.compiler.internal.interpreted.IExpression; import org.simantics.scl.compiler.top.ExpressionInterpretationContext; @@ -99,11 +97,6 @@ public class EExternalConstant extends Expression { return this; } - @Override - public Expression decorate(ExpressionDecorator decorator) { - return decorator.decorate(this); - } - @Override public void collectEffects(THashSet effects) { } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EFieldAccess.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EFieldAccess.java index a8d117f5d..da9a7b38b 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EFieldAccess.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EFieldAccess.java @@ -11,7 +11,6 @@ import org.simantics.scl.compiler.elaboration.expressions.EAmbiguous.Alternative import org.simantics.scl.compiler.elaboration.expressions.accessor.FieldAccessor; import org.simantics.scl.compiler.elaboration.expressions.accessor.IdAccessor; import org.simantics.scl.compiler.errors.Locations; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.header.ModuleHeader; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; @@ -167,11 +166,6 @@ public class EFieldAccess extends SimplifiableExpression { return this; } - @Override - public Expression decorate(ExpressionDecorator decorator) { - return decorator.decorate(this); - } - @Override public void collectEffects(THashSet effects) { // FIXME diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EGetConstraint.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EGetConstraint.java index cd34db4b5..fc437cfd8 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EGetConstraint.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EGetConstraint.java @@ -4,7 +4,6 @@ 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.errors.Locations; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.types.TPred; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.exceptions.MatchException; @@ -65,11 +64,6 @@ public class EGetConstraint extends SimplifiableExpression { return this; } - @Override - public Expression decorate(ExpressionDecorator decorator) { - return decorator.decorate(this); - } - @Override public void collectEffects(THashSet effects) { } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIf.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIf.java index 661de4261..1f3dccc3e 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIf.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIf.java @@ -8,7 +8,6 @@ import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.interpreted.IConstant; import org.simantics.scl.compiler.internal.interpreted.IExpression; import org.simantics.scl.compiler.internal.interpreted.IIf; @@ -136,15 +135,6 @@ public class EIf extends Expression { return this; } - @Override - public Expression decorate(ExpressionDecorator decorator) { - condition = condition.decorate(decorator); - then_ = then_.decorate(decorator); - if(else_ != null) - else_ = else_.decorate(decorator); - return decorator.decorate(this); - } - @Override public boolean isEffectful() { return condition.isEffectful() || then_.isEffectful() || (else_ != null && else_.isEffectful()); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIntegerLiteral.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIntegerLiteral.java index 0fbb6a506..17cf6e58e 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIntegerLiteral.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIntegerLiteral.java @@ -12,7 +12,6 @@ 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.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; @@ -118,11 +117,6 @@ public class EIntegerLiteral extends SimplifiableExpression { copy.constraint = (EVariable)constraint.replace(context); return copy; } - - @Override - public Expression decorate(ExpressionDecorator decorator) { - return decorator.decorate(this); - } @Override public boolean isEffectful() { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambda.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambda.java index 67a7e1476..573abfbb8 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambda.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambda.java @@ -5,7 +5,6 @@ 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.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; @@ -173,14 +172,6 @@ public class ELambda extends SimplifiableExpression { context.popEffectUpperBound(); return this; } - - @Override - public Expression decorate(ExpressionDecorator decorator) { - if(decorator.decorateSubstructure(this)) - for(Case case_ : cases) - case_.decorate(decorator); - return decorator.decorate(this); - } @Override public boolean isEffectful() { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambdaType.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambdaType.java index 23733bac6..34464fae4 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambdaType.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambdaType.java @@ -9,7 +9,6 @@ import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.interpreted.IExpression; import org.simantics.scl.compiler.top.ExpressionInterpretationContext; import org.simantics.scl.compiler.types.TVar; @@ -92,12 +91,6 @@ public class ELambdaType extends Expression { public Expression inferType(TypingContext context) { throw new InternalCompilerError("Should not type check " + getClass().getSimpleName() + "."); } - - @Override - public Expression decorate(ExpressionDecorator decorator) { - value = value.decorate(decorator); - return decorator.decorate(this); - } @Override public void collectEffects(THashSet effects) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELet.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELet.java index a90c6186d..de72c0c1c 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELet.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELet.java @@ -14,7 +14,6 @@ import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; import org.simantics.scl.compiler.internal.codegen.writer.RecursiveDefinitionWriter; import org.simantics.scl.compiler.internal.elaboration.decomposed.DecomposedExpression; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.elaboration.utils.StronglyConnectedComponents; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; @@ -213,14 +212,6 @@ public class ELet extends Expression { return this; } - @Override - public Expression decorate(ExpressionDecorator decorator) { - in = in.decorate(decorator); - for(Assignment assignment : assignments) - assignment.decorate(decorator); - return decorator.decorate(this); - } - @Override public void collectEffects(THashSet effects) { for(Assignment assignment : assignments) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListComprehension.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListComprehension.java index 860bc7f8c..7a8b71ebb 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListComprehension.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListComprehension.java @@ -6,7 +6,6 @@ import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.elaboration.expressions.list.CompiledQualifier; import org.simantics.scl.compiler.elaboration.expressions.list.ListQualifier; 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; @@ -101,13 +100,6 @@ public class EListComprehension extends SimplifiableExpression { return this; } - @Override - public Expression decorate(ExpressionDecorator decorator) { - head = head.decorate(decorator); - qualifier.decorate(decorator); - return decorator.decorate(this); - } - @Override public void collectEffects(THashSet effects) { head.collectEffects(effects); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListLiteral.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListLiteral.java index b1075a949..d8d5f7665 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListLiteral.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListLiteral.java @@ -8,7 +8,6 @@ import org.simantics.scl.compiler.elaboration.java.Builtins; import org.simantics.scl.compiler.elaboration.java.ListConstructor; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.utils.Constants; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.interpreted.IExpression; import org.simantics.scl.compiler.internal.interpreted.IListLiteral; import org.simantics.scl.compiler.top.ExpressionInterpretationContext; @@ -114,13 +113,6 @@ public class EListLiteral extends SimplifiableExpression { return this; } - @Override - public Expression decorate(ExpressionDecorator decorator) { - for(int i=0;i effects) { for(Expression component : components) diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELiteral.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELiteral.java index b11c0d667..0d9d844b6 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELiteral.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELiteral.java @@ -11,7 +11,6 @@ import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.interpreted.IConstant; import org.simantics.scl.compiler.internal.interpreted.IExpression; import org.simantics.scl.compiler.top.ExpressionInterpretationContext; @@ -106,11 +105,6 @@ public class ELiteral extends Expression { return this; } - @Override - public Expression decorate(ExpressionDecorator decorator) { - return decorator.decorate(this); - } - @Override public void collectEffects(THashSet effects) { } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EMatch.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EMatch.java index eef72f9de..a7a726879 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EMatch.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EMatch.java @@ -13,7 +13,6 @@ import org.simantics.scl.compiler.internal.codegen.ssa.exits.Throw; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; import org.simantics.scl.compiler.internal.elaboration.matching.PatternMatchingCompiler; import org.simantics.scl.compiler.internal.elaboration.matching.Row; -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.kinds.Kinds; @@ -164,15 +163,6 @@ public class EMatch extends Expression { return this; } - @Override - public Expression decorate(ExpressionDecorator decorator) { - for(int i=0;i effects) { for(Expression s : scrutinee) diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EPlaceholder.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EPlaceholder.java index bd03b30b9..feecc905c 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EPlaceholder.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EPlaceholder.java @@ -2,7 +2,6 @@ package org.simantics.scl.compiler.elaboration.expressions; import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; public class EPlaceholder extends DecoratingExpression { public EPlaceholder(long loc, Expression expression) { @@ -33,9 +32,4 @@ public class EPlaceholder extends DecoratingExpression { public Expression resolveAsPattern(TranslationContext context) { return expression.resolveAsPattern(context); } - - @Override - public Expression decorate(ExpressionDecorator decorator) { - return expression.decorate(decorator); - } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERealLiteral.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERealLiteral.java index 2f85269ac..4860055c1 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERealLiteral.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERealLiteral.java @@ -11,7 +11,6 @@ import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.errors.ErrorLog; 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; @@ -107,11 +106,6 @@ public class ERealLiteral extends SimplifiableExpression { copy.setType(getType().replace(context.tvarMap)); return copy; } - - @Override - public Expression decorate(ExpressionDecorator decorator) { - return decorator.decorate(this); - } @Override public void collectEffects(THashSet effects) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERuleset.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERuleset.java index e784813d6..b9e55d849 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERuleset.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERuleset.java @@ -32,7 +32,6 @@ import org.simantics.scl.compiler.elaboration.query.compilation.DerivateExceptio import org.simantics.scl.compiler.elaboration.relations.LocalRelation; import org.simantics.scl.compiler.elaboration.relations.SCLRelation; import org.simantics.scl.compiler.errors.Locations; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.elaboration.utils.ForcedClosure; import org.simantics.scl.compiler.internal.elaboration.utils.StronglyConnectedComponents; import org.simantics.scl.compiler.top.SCLCompilerConfiguration; @@ -176,11 +175,6 @@ public class ERuleset extends SimplifiableExpression { throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectEffects."); } - @Override - public Expression decorate(ExpressionDecorator decorator) { - return decorator.decorate(this); - } - @Override public Expression resolve(TranslationContext context) { throw new InternalCompilerError(); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESelect.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESelect.java index 7316fe307..34aca4adc 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESelect.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESelect.java @@ -20,7 +20,6 @@ import org.simantics.scl.compiler.elaboration.query.compilation.QueryCompilation import org.simantics.scl.compiler.elaboration.query.compilation.QueryCompilationMode; import org.simantics.scl.compiler.elaboration.query.compilation.UnsolvableQueryException; import org.simantics.scl.compiler.errors.Locations; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.parsing.parser.SCLTerminals; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; @@ -157,11 +156,6 @@ public class ESelect extends SimplifiableExpression { variables = context.popExistentialFrame(); return this; } - - @Override - public Expression decorate(ExpressionDecorator decorator) { - return decorator.decorate(this); - } @Override public void setLocationDeep(long loc) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLambda.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLambda.java index 2e5d4c364..91de49eb2 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLambda.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLambda.java @@ -11,7 +11,6 @@ import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.interpreted.IExpression; import org.simantics.scl.compiler.internal.interpreted.ILambda; import org.simantics.scl.compiler.top.ExpressionInterpretationContext; @@ -198,13 +197,6 @@ public class ESimpleLambda extends Expression { return this; } - @Override - public Expression decorate(ExpressionDecorator decorator) { - if(decorator.decorateSubstructure(this)) - value = value.decorate(decorator); - return decorator.decorate(this); - } - @Override public boolean isEffectful() { return false; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLet.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLet.java index e8fd9cf94..0a5d67651 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLet.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLet.java @@ -8,7 +8,6 @@ import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.interpreted.IExpression; import org.simantics.scl.compiler.internal.interpreted.ILet; import org.simantics.scl.compiler.internal.interpreted.ISeq; @@ -176,13 +175,6 @@ public class ESimpleLet extends Expression { return this; } - @Override - public Expression decorate(ExpressionDecorator decorator) { - value = value.decorate(decorator); - in = in.decorate(decorator); - return decorator.decorate(this); - } - @Override public void collectEffects(THashSet effects) { value.collectEffects(effects); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETransformation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETransformation.java index 65b3f9b2f..e00514151 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETransformation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETransformation.java @@ -10,7 +10,6 @@ import org.simantics.scl.compiler.elaboration.query.Query; import org.simantics.scl.compiler.elaboration.rules.TransformationRule; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.elaboration.transformations.TransformationBuilder; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.top.SCLCompilerConfiguration; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; @@ -102,11 +101,6 @@ public class ETransformation extends SimplifiableExpression { } } - @Override - public Expression decorate(ExpressionDecorator decorator) { - return decorator.decorate(this); - } - @Override public void collectEffects(THashSet effects) { effects.add(Types.PROC); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETypeAnnotation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETypeAnnotation.java index 654b4ef1f..568b3c108 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETypeAnnotation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETypeAnnotation.java @@ -4,7 +4,6 @@ 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.errors.Locations; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.parsing.types.TypeAst; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.exceptions.MatchException; @@ -72,13 +71,7 @@ public class ETypeAnnotation extends SimplifiableExpression { public Expression inferType(TypingContext context) { return value.checkType(context, type); } - - @Override - public Expression decorate(ExpressionDecorator decorator) { - value = value.decorate(decorator); - return decorator.decorate(this); - } - + @Override public void collectEffects(THashSet effects) { value.collectEffects(effects); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EVariable.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EVariable.java index 5311de2f1..761ed0f2f 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EVariable.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EVariable.java @@ -11,7 +11,6 @@ import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.interpreted.IExpression; import org.simantics.scl.compiler.internal.interpreted.IVariable; import org.simantics.scl.compiler.top.ExpressionInterpretationContext; @@ -162,11 +161,6 @@ public class EVariable extends Expression { return context.subsume(this, requiredType); } - @Override - public Expression decorate(ExpressionDecorator decorator) { - return decorator.decorate(this); - } - @Override public boolean isEffectful() { return false; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EViewPattern.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EViewPattern.java index a08ed3923..4997fa592 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EViewPattern.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EViewPattern.java @@ -8,7 +8,6 @@ import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; -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; @@ -106,12 +105,6 @@ public class EViewPattern extends Expression { } } - @Override - public Expression decorate(ExpressionDecorator decorator) { - expression = expression.decorate(decorator); - return this; - } - @Override public void collectEffects(THashSet effects) { expression.collectEffects(effects); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EWhen.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EWhen.java index bf47759de..d8b42fca4 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EWhen.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EWhen.java @@ -11,7 +11,6 @@ import org.simantics.scl.compiler.elaboration.query.compilation.QueryCompilation import org.simantics.scl.compiler.elaboration.query.compilation.QueryCompilationMode; import org.simantics.scl.compiler.elaboration.query.compilation.UnsolvableQueryException; 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; @@ -113,11 +112,6 @@ public class EWhen extends SimplifiableExpression { variables = context.popExistentialFrame(); return this; } - - @Override - public Expression decorate(ExpressionDecorator decorator) { - return decorator.decorate(this); - } @Override public Expression replace(ReplaceContext context) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Expression.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Expression.java index 02590273d..0d48c4a15 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Expression.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Expression.java @@ -19,7 +19,6 @@ import org.simantics.scl.compiler.elaboration.relations.SCLRelation; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; import org.simantics.scl.compiler.internal.elaboration.decomposed.DecomposedExpression; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.interpreted.IExpression; import org.simantics.scl.compiler.internal.parsing.Symbol; import org.simantics.scl.compiler.top.ExpressionInterpretationContext; @@ -331,8 +330,6 @@ public abstract class Expression extends Symbol implements Typed { public Expression applyType(Type type) { return new EApplyType(location, this, type); } - - public abstract Expression decorate(ExpressionDecorator decorator); public boolean isEffectful() { return true; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/GuardedExpression.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/GuardedExpression.java index 9791b068a..fa67162d5 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/GuardedExpression.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/GuardedExpression.java @@ -2,7 +2,6 @@ package org.simantics.scl.compiler.elaboration.expressions; import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext; import org.simantics.scl.compiler.errors.Locations; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.parsing.Symbol; public class GuardedExpression extends Symbol { @@ -20,12 +19,6 @@ public class GuardedExpression extends Symbol { value.replace(context)); } - public void decorate(ExpressionDecorator decorator) { - for(int i=0;i effects) { for(GuardedExpression ge : expressions) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/StandardExpressionTransformer.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/StandardExpressionTransformer.java index 97d409f15..948f7c645 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/StandardExpressionTransformer.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/StandardExpressionTransformer.java @@ -45,6 +45,8 @@ EquationVisitor { @Override public Expression transform(EAmbiguous expression) { + if(expression.resolvedExpression != null) + expression.resolvedExpression = expression.resolvedExpression.accept(this); return expression; } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/accessor/ExpressionAccessor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/accessor/ExpressionAccessor.java index e3a1333c0..793bd0065 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/accessor/ExpressionAccessor.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/accessor/ExpressionAccessor.java @@ -7,7 +7,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Expression; import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure; import org.simantics.scl.compiler.errors.Locations; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.types.Types; import gnu.trove.map.hash.TObjectIntHashMap; @@ -39,11 +38,6 @@ public class ExpressionAccessor extends FieldAccessor { fieldName.collectVars(allVars, vars); } - @Override - public void decorate(ExpressionDecorator decorator) { - fieldName = fieldName.decorate(decorator); - } - @Override public void resolve(TranslationContext context) { fieldName = fieldName.resolve(context); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/accessor/FieldAccessor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/accessor/FieldAccessor.java index ce56da39f..0f0d8417f 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/accessor/FieldAccessor.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/accessor/FieldAccessor.java @@ -6,7 +6,6 @@ import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.elaboration.expressions.Expression; import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.parsing.Symbol; import gnu.trove.map.hash.TObjectIntHashMap; @@ -37,9 +36,6 @@ public abstract class FieldAccessor extends Symbol { public void resolve(TranslationContext context) { } - public void decorate(ExpressionDecorator decorator) { - } - public void checkType(TypingContext context) { } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListAssignment.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListAssignment.java index 89de0ebc3..b1efd2ca9 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListAssignment.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListAssignment.java @@ -9,7 +9,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Expression; import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure; import org.simantics.scl.compiler.errors.Locations; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.types.Type; import gnu.trove.map.hash.TObjectIntHashMap; @@ -80,12 +79,6 @@ public class ListAssignment extends ListQualifier { pattern = pattern.resolveAsPattern(context); } - @Override - public void decorate(ExpressionDecorator decorator) { - value = value.decorate(decorator); - pattern = pattern.decorate(decorator); - } - @Override public void collectEffects(THashSet effects) { pattern.collectEffects(effects); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListGenerator.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListGenerator.java index 7f480d8df..90b68c5dd 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListGenerator.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListGenerator.java @@ -9,7 +9,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Expression; import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure; import org.simantics.scl.compiler.errors.Locations; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.types.TMetaVar; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; @@ -86,12 +85,6 @@ public class ListGenerator extends ListQualifier { pattern = pattern.resolveAsPattern(context); } - @Override - public void decorate(ExpressionDecorator decorator) { - value = value.decorate(decorator); - pattern = pattern.decorate(decorator); - } - @Override public void collectEffects(THashSet effects) { pattern.collectEffects(effects); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListGuard.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListGuard.java index fdd159235..626bd48cb 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListGuard.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListGuard.java @@ -7,7 +7,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Expression; import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure; 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; @@ -55,11 +54,6 @@ public class ListGuard extends ListQualifier { public void resolve(TranslationContext context) { condition = condition.resolve(context); } - - @Override - public void decorate(ExpressionDecorator decorator) { - condition = condition.decorate(decorator); - } @Override public void collectEffects(THashSet effects) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListQualifier.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListQualifier.java index 22e0c6b76..939e6fd66 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListQualifier.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListQualifier.java @@ -5,7 +5,6 @@ import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.parsing.Symbol; import org.simantics.scl.compiler.types.Type; @@ -24,7 +23,6 @@ public abstract class ListQualifier extends Symbol { */ public abstract CompiledQualifier compile(SimplificationContext context); public abstract void resolve(TranslationContext context); - public abstract void decorate(ExpressionDecorator decorator); public abstract void collectEffects(THashSet effects); public abstract void setLocationDeep(long loc); public abstract void accept(ListQualifierVisitor visitor); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListSeq.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListSeq.java index 16fc84f89..f56820d2a 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListSeq.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListSeq.java @@ -7,7 +7,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Expression; import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure; import org.simantics.scl.compiler.errors.Locations; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.types.Type; import gnu.trove.map.hash.TObjectIntHashMap; @@ -76,12 +75,6 @@ public class ListSeq extends ListQualifier { b.resolve(context); } - @Override - public void decorate(ExpressionDecorator decorator) { - a.decorate(decorator); - b.decorate(decorator); - } - @Override public void collectEffects(THashSet effects) { a.collectEffects(effects); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListThen.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListThen.java index f8f3c3dd9..fbc153226 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListThen.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListThen.java @@ -7,7 +7,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Expression; import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure; import org.simantics.scl.compiler.errors.Locations; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.types.TMetaVar; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; @@ -100,14 +99,6 @@ public class ListThen extends ListQualifier { by = by.resolve(context); } - @Override - public void decorate(ExpressionDecorator decorator) { - transformer = transformer.decorate(decorator); - if(by != null) - by = by.decorate(decorator); - left.decorate(decorator); - } - @Override public void collectEffects(THashSet effects) { left.collectEffects(effects); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/utils/ExpressionDecorator.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/utils/ExpressionDecorator.java deleted file mode 100644 index 77e47d10a..000000000 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/utils/ExpressionDecorator.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.simantics.scl.compiler.internal.elaboration.utils; - -import org.simantics.scl.compiler.elaboration.expressions.Expression; - -public interface ExpressionDecorator { - - Expression decorate(Expression expression); - boolean decorateSubstructure(Expression expression); - -} diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ExpressionEvaluator.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ExpressionEvaluator.java index 67f43838d..899ee0418 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ExpressionEvaluator.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ExpressionEvaluator.java @@ -42,7 +42,6 @@ import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; import org.simantics.scl.compiler.internal.codegen.writer.ExternalConstant; import org.simantics.scl.compiler.internal.codegen.writer.ModuleWriter; import org.simantics.scl.compiler.internal.elaboration.decomposed.DecomposedExpression; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.internal.interpreted.IExpression; import org.simantics.scl.compiler.internal.parsing.exceptions.SCLSyntaxErrorException; import org.simantics.scl.compiler.internal.parsing.parser.SCLBlockParser; @@ -300,9 +299,9 @@ public class ExpressionEvaluator { if(!errorLog.hasNoErrors()) throw new SCLExpressionCompilationException(errorLog.getErrors()); if(decorateExpression && Types.canonical(expectedEffect) != Types.NO_EFFECTS) { - ExpressionDecorator decorator = + ToplevelEffectDecorator decorator = new ToplevelEffectDecorator(errorLog, environment); - expression = expression.decorate(decorator); + expression = expression.accept(decorator); } expression = context.solveConstraints(environment, expression); expressionType = expression.getType(); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ToplevelEffectDecorator.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ToplevelEffectDecorator.java index 5a3c39e60..da4ce4feb 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ToplevelEffectDecorator.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ToplevelEffectDecorator.java @@ -4,7 +4,9 @@ import java.util.ArrayList; import org.simantics.scl.compiler.common.names.Name; import org.simantics.scl.compiler.common.names.Names; +import org.simantics.scl.compiler.elaboration.expressions.Case; import org.simantics.scl.compiler.elaboration.expressions.EApply; +import org.simantics.scl.compiler.elaboration.expressions.ECHRRuleset; import org.simantics.scl.compiler.elaboration.expressions.EConstant; import org.simantics.scl.compiler.elaboration.expressions.EEnforce; import org.simantics.scl.compiler.elaboration.expressions.EFieldAccess; @@ -14,17 +16,19 @@ import org.simantics.scl.compiler.elaboration.expressions.ESelect; import org.simantics.scl.compiler.elaboration.expressions.ESimpleLambda; import org.simantics.scl.compiler.elaboration.expressions.EWhen; import org.simantics.scl.compiler.elaboration.expressions.Expression; +import org.simantics.scl.compiler.elaboration.expressions.StandardExpressionTransformer; import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.elaboration.modules.SCLValue; import org.simantics.scl.compiler.environment.Environment; import org.simantics.scl.compiler.errors.ErrorLog; import org.simantics.scl.compiler.errors.Locations; -import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; import org.simantics.scl.compiler.types.TCon; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; -public class ToplevelEffectDecorator implements ExpressionDecorator { +import gnu.trove.map.hash.THashMap; + +public class ToplevelEffectDecorator extends StandardExpressionTransformer { ErrorLog errorLog; Environment environment; @@ -34,92 +38,101 @@ public class ToplevelEffectDecorator implements ExpressionDecorator { this.environment = environment; } - private static Expression decorate(SCLValue transactionFunction, Type effect, Expression expression) { - Variable var = new Variable("_"); - var.setType(Types.UNIT); - Expression trans = new EApply(expression.getLocation(), Types.PROC, - new EConstant(transactionFunction, - expression.getType()), - new ESimpleLambda(Locations.NO_LOCATION, var, effect, expression) - ); - if(expression instanceof EApply) { - EApply apply = (EApply)expression; - trans = apply.toANormalForm(trans); - } - return trans; + @Override + public Expression transform(EEnforce expression) { + return decorateByEffect(expression, expression.getEffect()); + } + + @Override + public Expression transform(EWhen expression) { + return decorateByEffect(expression, expression.getEffect()); + } + + @Override + public Expression transform(ERuleset expression) { + return decorateByEffect(expression, expression.getEffect()); + } + + @Override + public Expression transform(ECHRRuleset expression) { + return decorateByEffect(expression, expression.getEffect()); + } + + @Override + public Expression transform(EFieldAccess expression) { + // Can we encounter EFieldAccess in this transformer? + return decorateByEffect(expression, expression.getEffect()); + } + + @Override + public Expression transform(ESelect expression) { + return decorateByEffect(expression, expression.getEffect()); } - private static final TCon R = Types.con("R/R", "R"); + @Override + public Expression transform(EApply expression) { + return decorateByEffect(super.transform(expression), expression.getLocalEffect()); + } @Override - public Expression decorate(Expression expression) { - if(expression instanceof EApply) - return decorateByEffect(expression, ((EApply)expression).getLocalEffect()); - else if(expression instanceof ESelect - || expression instanceof EEnforce - || expression instanceof EWhen - || expression instanceof EFieldAccess - || expression instanceof ERuleset) - return decorateByEffect(expression, expression.getEffect()); + public Expression transform(ESimpleLambda expression) { + // Never has side effects return expression; } + @Override + public Expression transform(ELambda expression) { + // Never has side effects + return expression; + } + + @Override + protected void transformCases(Case[] cases) { + for(Case case_ : cases) + case_.value = case_.value.accept(this); + } + + private static final THashMap DECORATION_MAP = new THashMap(); + + static { + DECORATION_MAP.put(Types.WRITE_GRAPH, Names.Simantics_DB_syncWrite); + DECORATION_MAP.put(Types.READ_GRAPH, Names.Simantics_DB_syncRead); + DECORATION_MAP.put(Types.con("R/R", "R"), Names.R_R_runR); + DECORATION_MAP.put(Types.RANDOM, Names.Random_runRandom); + } + private Expression decorateByEffect(Expression expression, Type effect) { if(effect == Types.NO_EFFECTS) return expression; - //System.out.println("decorateByEffect(" + expression + ", " + effect + ")"); - ArrayList concreteEffects = new ArrayList(); effect.collectConcreteEffects(concreteEffects); - if(concreteEffects.contains(Types.WRITE_GRAPH)) { - Name name = Names.Simantics_DB_syncWrite; - SCLValue transactionFunction = environment.getValue(name); + for(TCon ce : concreteEffects) { + Name transactionFunctionName = DECORATION_MAP.get(ce); + if(transactionFunctionName == null) + continue; + SCLValue transactionFunction = environment.getValue(transactionFunctionName); if(transactionFunction == null) { - errorLog.log(expression.location, "Cannot locate " + name); - return expression; + errorLog.log(expression.location, "Cannot locate " + transactionFunctionName); + continue; } - - expression = decorate(transactionFunction, Types.WRITE_GRAPH, expression); + expression = decorate(transactionFunction, ce, expression); } - else if(concreteEffects.contains(Types.READ_GRAPH)) { - Name name = Names.Simantics_DB_syncRead; - SCLValue transactionFunction = environment.getValue(name); - if(transactionFunction == null) { - errorLog.log(expression.location, "Cannot locate " + name); - return expression; - } - - expression = decorate(transactionFunction, Types.READ_GRAPH, expression); - } - if(concreteEffects.contains(R)) { - Name name = Names.R_R_runR; - SCLValue transactionFunction = environment.getValue(name); - if(transactionFunction == null) { - errorLog.log(expression.location, "Cannot locate " + name); - return expression; - } - - expression = decorate(transactionFunction, R, expression); - } - if(concreteEffects.contains(Types.RANDOM)) { - Name name = Names.Random_runRandom; - SCLValue transactionFunction = environment.getValue(name); - if(transactionFunction == null) { - errorLog.log(expression.location, "Cannot locate " + name); - return expression; - } - expression = decorate(transactionFunction, Types.RANDOM, expression); - } return expression; } - @Override - public boolean decorateSubstructure(Expression expression) { - if(expression instanceof ELambda || expression instanceof ESimpleLambda) - return false; - return true; + private static Expression decorate(SCLValue transactionFunction, Type effect, Expression expression) { + Variable var = new Variable("_"); + var.setType(effect == Types.RANDOM ? Types.PUNIT : Types.UNIT); + Expression trans = new EApply(expression.getLocation(), Types.PROC, + effect == Types.RANDOM ? new EConstant(transactionFunction, Types.PROC, expression.getType()) : new EConstant(transactionFunction, expression.getType()), + new ESimpleLambda(Locations.NO_LOCATION, var, effect, expression) + ); + if(expression instanceof EApply) { + EApply apply = (EApply)expression; + trans = apply.toANormalForm(trans); + } + return trans; } - }