]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
(refs #7375) Replaced collectEffects by CollectEffectsVisitor 53/753/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Mon, 24 Jul 2017 10:02:04 +0000 (13:02 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Mon, 24 Jul 2017 10:02:04 +0000 (13:02 +0300)
Change-Id: I41b489ad872140bf7a0f0a83714a50431b48c3a6

51 files changed:
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/EqBasic.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/EqGuard.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/Equation.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ASTExpression.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/DecoratingExpression.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EAmbiguous.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApply.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApplyType.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EAsPattern.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBind.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRuleset.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRulesetConstructor.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRSelect.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEnforce.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEquations.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EError.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EExternalConstant.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EFieldAccess.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EGetConstraint.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIf.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIntegerLiteral.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambda.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambdaType.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELet.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListComprehension.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListLiteral.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELiteral.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EMatch.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERealLiteral.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERuleset.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESelect.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLambda.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLet.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETransformation.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETypeAnnotation.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EVariable.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EViewPattern.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EWhen.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Expression.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ExpressionVisitor.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/GuardedExpressionGroup.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/StandardExpressionVisitor.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListAssignment.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListGenerator.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListGuard.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListQualifier.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListSeq.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListThen.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/printing/ExpressionToStringVisitor.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectEffectsVisitor.java [new file with mode: 0644]

index 08b1a07267bc5ecebc910b0cebad30398766cccc..8dcfe08639d21dbc0984bb325fe5ae7ecbad9322 100644 (file)
@@ -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.errors.Locations;
-import org.simantics.scl.compiler.types.Type;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
 import gnu.trove.set.hash.THashSet;
@@ -41,12 +40,6 @@ public class EqBasic extends Equation {
         right.collectFreeVariables(vars);
     }
 
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        left.collectEffects(effects);
-        right.collectEffects(effects);
-    }
-
     @Override
     public void checkType(TypingContext context) {
         left = left.inferType(context);
index 5dac9fce44b452e9239ecdfd5a0fbf6d4b2c809e..8b10872e94ff7052a8d25c18c6cf17cf89c8d7b4 100644 (file)
@@ -5,9 +5,7 @@ import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
 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.errors.Locations;
-import org.simantics.scl.compiler.types.Type;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
 import gnu.trove.set.hash.THashSet;
@@ -38,11 +36,6 @@ public class EqGuard extends Equation {
         guard.collectFreeVariables(vars);
     }
 
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        guard.collectEffects(effects);
-    }
-
     @Override
     public void checkType(TypingContext context) {
         guard = guard.checkIgnoredType(context);
index ca4102c96b6588d50b946432417a3281ea0217f6..94283436a628e49a115ff70c37a11230f824d4cd 100644 (file)
@@ -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.internal.parsing.Symbol;
-import org.simantics.scl.compiler.types.Type;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
 import gnu.trove.set.hash.THashSet;
@@ -17,7 +16,6 @@ public abstract class Equation extends Symbol {
     public abstract void setLocationDeep(long loc);
 
     public abstract void collectFreeVariables(THashSet<Variable> vars);
-    public abstract void collectEffects(THashSet<Type> effects);
     public abstract void checkType(TypingContext context);
     public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
     public abstract void resolve(TranslationContext context);
index fa54f8ab28e3acf80b3044375b38c4d35b1d7dc1..7e804c2a26b325cd3bde3f9c0fe927c926958d83 100644 (file)
@@ -36,11 +36,6 @@ public abstract class ASTExpression extends SimplifiableExpression {
         throw new InternalCompilerError(getClass().getSimpleName() + " does not support updateType.");
     }
     
-    @Override
-    final public void collectEffects(THashSet<Type> effects) {
-        throw new InternalCompilerError(getClass().getSimpleName() + " does not support collectEffects.");
-    }
-    
     @Override
     public void accept(ExpressionVisitor visitor) {
         throw new InternalCompilerError(getClass().getSimpleName() + " does not support accept.");
index 796a41c69c421103430da9c1fa32ff6989f09000..97b223d56b0e1cbf65b18134a8d7200c35ab88a7 100644 (file)
@@ -81,11 +81,6 @@ public abstract class DecoratingExpression extends SimplifiableExpression {
     public int getFunctionDefinitionPatternArity() throws NotPatternException {
         return expression.getFunctionDefinitionPatternArity();
     }
-
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        expression.collectEffects(effects);
-    }
     
     @Override
     public void setLocationDeep(long loc) {
index 2b5c813a13db19dc6591d193353763c2f6c15e97..d52cc3f2ef4c3d493170fb3205c7e5238ea55b1c 100644 (file)
@@ -179,14 +179,9 @@ public class EAmbiguous extends SimplifiableExpression {
             location = loc;
     }
 
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        // TODO Auto-generated method stub
-    }
-
     @Override
     public void accept(ExpressionVisitor visitor) {
-        // TODO Auto-generated method stub
+        visitor.visit(this);
     }
     
     @Override
index 4065f463ac4d8436a60a74b81e7e5a8cc4871fcd..d45e7fc8c4a6ee2917b2c55cabdfadc7a52e5f9e 100644 (file)
@@ -39,7 +39,7 @@ import gnu.trove.set.hash.TIntHashSet;
 public class EApply extends Expression {
     public Expression function;
     public Expression[] parameters;
-    Type effect = Types.NO_EFFECTS;
+    public Type effect = Types.NO_EFFECTS;
     
     public EApply(Expression function, Expression ... parameters) {
         this.function = function;
@@ -340,14 +340,6 @@ public class EApply extends Expression {
         return function.isConstructorApplication();
     }
 
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        effects.add(effect);
-        function.collectEffects(effects);
-        for(Expression parameter : parameters)
-            parameter.collectEffects(effects);
-    }
-
     @Override
     public void accept(ExpressionVisitor visitor) {
         visitor.visit(this);
index f441a1be5880254123eb7be77a1e116a31decbae..df945eabb157a2ea6a4cfda55b0b08caf4d80687 100644 (file)
@@ -111,11 +111,6 @@ public class EApplyType extends Expression {
     public boolean isEffectful() {
        return expression.isEffectful();
     }
-
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        expression.collectEffects(effects);
-    }
     
     @Override
     public void setLocationDeep(long loc) {
index 98c54844c037661b6fe34ab7f12f07567cfd61de..6d29526ea76b223d73f5ba6d998248fb4e10a65d 100644 (file)
@@ -117,11 +117,6 @@ public class EAsPattern extends Expression {
         
         return result;
     }
-
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        pattern.collectEffects(effects);
-    }
     
     @Override
     public void setLocationDeep(long loc) {
index 3bec2aaa13ecafde91be4380559df456779b6953..2d3a7ce920a8e113107f0297d7853406b291d2ac 100644 (file)
@@ -131,13 +131,6 @@ public class EBind extends SimplifiableExpression {
         return this; 
     }
     
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        pattern.collectEffects(effects);
-        value.collectEffects(effects);
-        in.collectEffects(effects);
-    }
-    
     @Override
     public void setLocationDeep(long loc) {
         if(location == Locations.NO_LOCATION) {
index a8ad1480d1be35af8115d493629e3f93724b8db5..12165399321a2496a6148ff77b8d48422a73c164 100644 (file)
@@ -10,7 +10,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.interpreted.IExpression;
 import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
-import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
@@ -76,11 +75,7 @@ public class ECHRRuleset extends Expression {
             in.setLocationDeep(loc);
         }
     }
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        ruleset.collectEffects(effects);
-        in.collectEffects(effects);
-    }
+    
     @Override
     public void accept(ExpressionVisitor visitor) {
         visitor.visit(this);
index 734fd71b439f20a5c43d9cd1aec54a4968d82202..7df6fb595732f88b26c12b826673905679bfceb7 100644 (file)
@@ -11,7 +11,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.interpreted.IExpression;
 import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
-import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
@@ -62,10 +61,6 @@ public class ECHRRulesetConstructor extends Expression {
         }
     }
     @Override
-    public void collectEffects(THashSet<Type> effects) {
-        ruleset.collectEffects(effects);
-    }
-    @Override
     public void accept(ExpressionVisitor visitor) {
         visitor.visit(this);
     }
index fbaff1200124dfd88ffe71b815af1d8b691bf44f..d1873e4e6f3240bcf07307e2ec17a54be940232a 100644 (file)
@@ -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.types.Type;
 import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 import org.simantics.scl.compiler.types.kinds.Kinds;
@@ -114,13 +113,6 @@ public class ECHRSelect extends Expression {
         }
     }
 
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        expression.collectEffects(effects);
-        query.collectQueryEffects(effects);
-        effects.add(Types.PROC);
-    }
-
     @Override
     public void accept(ExpressionVisitor visitor) {
         visitor.visit(this);
index 4a2e07f431cd9410889c2275980aaf70819dc55f..1bab4ff646da38ab5c03c0327fd5cf6abe3b5cc3 100644 (file)
@@ -230,11 +230,7 @@ public class EConstant extends Expression {
     
     @Override
     public boolean isEffectful() {
-       return false;
-    }
-
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
+        return false;
     }
     
     @Override
index bfaf699ed4c81081c32281ae5b12eeeb2e57fe62..9b0a13b20180da7026c5e4ad232931d2d7d7ca03 100644 (file)
@@ -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.types.Type;
 import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
@@ -34,11 +33,6 @@ public class EEnforce extends SimplifiableExpression {
             TIntHashSet vars) {
         query.collectVars(allVars, vars);
     }
-    
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectEffects.");
-    }
 
     @Override
     protected void updateType() throws MatchException {
index bffb7f026e6116264babd76540ba0303410b3cbc..d2d31713bbf966a48a6b6c3b14d00343354e8f42 100644 (file)
@@ -66,12 +66,6 @@ public class EEquations extends SimplifiableExpression {
             equation.collectFreeVariables(vars);
     }
 
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        for(Equation equation : equations)
-            equation.collectEffects(effects);
-    }
-
     @Override
     public void accept(ExpressionVisitor visitor) {
         visitor.visit(this);
index b3f4f648897b7a4c1469722606ab6d0c545b3091..82c6d5d527faf20232eb2a0f46290c91b73c5513 100644 (file)
@@ -64,10 +64,6 @@ public class EError extends Expression {
     public Expression inferType(TypingContext context) {
         return this;
     }
-
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-    }
     
     @Override
     public void setLocationDeep(long loc) {
index 0b5678f99eb15a9995e23ca7f5c6c82cd0493690..213c30bf198b323da9806fa973827f36d68a7be7 100644 (file)
@@ -93,10 +93,6 @@ public class EExternalConstant extends Expression {
     public Expression inferType(TypingContext context) {
         return this;
     }
-
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-    }
     
     @Override
     public void setLocationDeep(long loc) {
index 0a4d0ee165186b404055f7c540c7cfa057135bb0..c5ee9bc7a1642aa570e2ef01448709835dfebca1 100644 (file)
@@ -158,12 +158,6 @@ public class EFieldAccess extends SimplifiableExpression {
         accessor.resolve(context);
         return this;
     }
-
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        // FIXME
-        effects.add(Types.READ_GRAPH);
-    }
     
     @Override
     public void setLocationDeep(long loc) {
index 8534f462409fc2b131e1059774fe3ee8300d0e75..95948d45c391e17841a64244576a6b8f6bb1271a 100644 (file)
@@ -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.errors.Locations;
 import org.simantics.scl.compiler.types.TPred;
-import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
@@ -59,10 +58,6 @@ public class EGetConstraint extends SimplifiableExpression {
         return this;
     }
     
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-    }
-    
     @Override
     public void setLocationDeep(long loc) {
         if(location == Locations.NO_LOCATION) {
index ea64ac034c152e120f6472902233a246e1fcb5cf..7b56d22fa2991bba35ef28d73240015326917c8e 100644 (file)
@@ -132,14 +132,6 @@ public class EIf extends Expression {
     public boolean isEffectful() {
        return condition.isEffectful() || then_.isEffectful() || (else_ != null && else_.isEffectful());
     }
-
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        condition.collectEffects(effects);
-        then_.collectEffects(effects);
-        if(else_ != null)
-            else_.collectEffects(effects);
-    }
     
     @Override
     public void setLocationDeep(long loc) {
index 856dcd37123e20cb745af694063e06a421b8cd7c..a70e5016060830f4e3ca8160d04213cab2e4e2ec 100644 (file)
@@ -117,10 +117,6 @@ public class EIntegerLiteral extends SimplifiableExpression {
     public boolean isEffectful() {
        return false;
     }
-
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-    }
     
     @Override
     public void setLocationDeep(long loc) {
index 51b1f909e34624e164cb528ec9680d35854132ab..5aa77046eacac57eaaa6c499687eb07750b5339d 100644 (file)
@@ -172,15 +172,6 @@ public class ELambda extends SimplifiableExpression {
     public boolean isEffectful() {
        return false;
     }
-
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        for(Case case_ : cases) {
-            for(Expression pattern : case_.patterns)
-                pattern.collectEffects(effects);
-            case_.value.collectEffects(effects);
-        }
-    }
     
     @Override
     public void accept(ExpressionVisitor visitor) {
index b06f7b77035079d04c92a80e6469bd89e4b40806..fec64d6d00ae477160d0dc87c028f5130edfc489 100644 (file)
@@ -12,7 +12,6 @@ import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
 import org.simantics.scl.compiler.internal.interpreted.IExpression;
 import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
 import org.simantics.scl.compiler.types.TVar;
-import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
@@ -87,10 +86,6 @@ public class ELambdaType extends Expression {
     public Expression inferType(TypingContext context) {
         throw new InternalCompilerError("Should not type check " + getClass().getSimpleName() + ".");
     }
-
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-    }
     
     @Override
     public void setLocationDeep(long loc) {
index 7b7338a78e2f07efe17b4731a80b709c7635aa35..71ee13076912142a36c43451b6d3411aa7360347 100644 (file)
@@ -204,15 +204,6 @@ public class ELet extends Expression {
         in = in.checkIgnoredType(context);
         return this;
     }
-
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        for(Assignment assignment : assignments) {
-            assignment.pattern.collectEffects(effects);
-            assignment.value.collectEffects(effects);
-        }
-        in.collectEffects(effects);
-    }
     
     @Override
     public void setLocationDeep(long loc) {
index a06100dd719f925e4c44abfb058b19c10d19b4c8..102d6465825a4cbee8d8bca1625598fae837c2df 100644 (file)
@@ -93,12 +93,6 @@ public class EListComprehension extends SimplifiableExpression {
         return this;
     }
 
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        head.collectEffects(effects);
-        qualifier.collectEffects(effects);
-    }
-
     @Override
     public void setLocationDeep(long loc) {
         if(location == Locations.NO_LOCATION) {
index d2a1d3509b65ace91caf56e25e3b47a8bd5473ac..478d7b31195cf7deb793a0d7e1a7e7114aa16725 100644 (file)
@@ -106,12 +106,6 @@ public class EListLiteral extends SimplifiableExpression {
         return this;
     }
 
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        for(Expression component : components)
-            component.collectEffects(effects);
-    }
-
     @Override
     public void setLocationDeep(long loc) {
         if(location == Locations.NO_LOCATION) {
index 14bd02344e4d52e56b009adc9bd8cacd1b7535f8..388fbb37a1f426c1e435f77b9f12ba03a224cf84 100644 (file)
@@ -14,7 +14,6 @@ import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
 import org.simantics.scl.compiler.internal.interpreted.IConstant;
 import org.simantics.scl.compiler.internal.interpreted.IExpression;
 import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
-import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
 
@@ -101,10 +100,6 @@ public class ELiteral extends Expression {
     public Expression inferType(TypingContext context) {
         return this;
     }
-
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-    }
     
     @Override
     public void setLocationDeep(long loc) {
index 0ca1d54427d13a636ca11eca672ea330dd688cef..18f89ccdf7dcb885eb943176f6cdbf136d3e0a4e 100644 (file)
@@ -155,17 +155,6 @@ public class EMatch extends Expression {
         setType(Types.UNIT);
         return this;
     }
-
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        for(Expression s : scrutinee)
-            s.collectEffects(effects);
-        for(Case case_ : cases) {
-            for(Expression pattern : case_.patterns)
-                pattern.collectEffects(effects);
-            case_.value.collectEffects(effects);
-        }
-    }
     
     @Override
     public void accept(ExpressionVisitor visitor) {
index 5f274dadde72c9cee3dc0f0aad471efe39ad5808..5312c7543fa4fb23024342c55d4dba6912e93331 100644 (file)
@@ -101,10 +101,6 @@ public class ERealLiteral extends SimplifiableExpression {
         copy.setType(getType().replace(context.tvarMap));
         return copy;
     }
-
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-    }
     
     @Override
     public void setLocationDeep(long loc) {
index 1a133b6f9dc61e7b0ee283c4e8ed77614d15939a..e84e0500c41bb045547266a9f924ea62b22d9b10 100644 (file)
@@ -152,11 +152,6 @@ public class ERuleset extends SimplifiableExpression {
         }
         in.collectVars(allVars, vars);
     }
-
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectEffects.");
-    }
     
     @Override
     public Expression resolve(TranslationContext context) {
index ce4d66bd7567e268f395d12835a23a9258a906fa..473c403da7aa85e54db07258b2d1a888efc10cf3 100644 (file)
@@ -51,11 +51,6 @@ public class ESelect extends SimplifiableExpression {
         expression.collectVars(allVars, vars);
         query.collectVars(allVars, vars);
     }
-    
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectEffects.");
-    }
 
     @Override
     protected void updateType() throws MatchException {
index 8f59b3b4429c77f22d94a0482fba310a190929ec..9b3ee8df77bcdb7812f8ef3f8472cbe83bf34bec 100644 (file)
@@ -198,10 +198,6 @@ public class ESimpleLambda extends Expression {
        return false;
     }
     
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-    }
-    
     @Override
     public void setLocationDeep(long loc) {
         if(location == Locations.NO_LOCATION) {
index 422bbea119f76aad1020317235258a1fd97ef4b7..e69a271218a82b620230be5c9d2a131f396e6702 100644 (file)
@@ -169,12 +169,6 @@ public class ESimpleLet extends Expression {
         in = in.checkIgnoredType(context);
         return this;
     }
-
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        value.collectEffects(effects);
-        in.collectEffects(effects);
-    }
     
     @Override
     public void accept(ExpressionVisitor visitor) {
index 346e46cd3cc9fe2d735c4a2ba70345962a76bd9f..7617416584b373de0194fa5aad56e05fdede578c 100644 (file)
@@ -11,7 +11,6 @@ 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.top.SCLCompilerConfiguration;
-import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
@@ -90,12 +89,6 @@ public class ETransformation extends SimplifiableExpression {
         }
     }
 
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        effects.add(Types.PROC);
-        //seed.collectEffects(Query.RW, effects); // FIXME
-    }
-
     @Override
     public void accept(ExpressionVisitor visitor) {
         visitor.visit(this);
index 10c8e6f7a47e4511bc177e4d3cfd29071a08cbfc..89caebad08877fcffa11d911c19fa2640ea3bf01 100644 (file)
@@ -68,11 +68,6 @@ public class ETypeAnnotation extends SimplifiableExpression {
         return value.checkType(context, type);
     }
     
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        value.collectEffects(effects);
-    }
-    
     @Override
     public void setLocationDeep(long loc) {
         if(location == Locations.NO_LOCATION) {
index 44c03a2acdd8d8ef7279938c67322b81ff7132f7..aa278928239ea4efd2ee0d6cb9e336c129541110 100644 (file)
@@ -163,10 +163,6 @@ public class EVariable extends Expression {
        return false;
     }
     
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-    }
-    
     @Override
     public void setLocationDeep(long loc) {
         if(location == Locations.NO_LOCATION)
index a2a0a02c5bc04b90b715ede54a0d9be0ca7e6055..c0dfb5a75158d3f5c03181aabf27a11192ae8175 100644 (file)
@@ -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.types.Type;
 import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 import org.simantics.scl.compiler.types.util.MultiFunction;
@@ -93,11 +92,6 @@ public class EViewPattern extends Expression {
         }
     }
 
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        expression.collectEffects(effects);
-    }
-
     @Override
     public void accept(ExpressionVisitor visitor) {
         visitor.visit(this);
index a9fd0367bbcaee69ce36f415e0c41565b1a1c7e9..9ea5ddb1ecf7a94a4f8e6fb29a070b191e806d99 100644 (file)
@@ -1,6 +1,5 @@
 package org.simantics.scl.compiler.elaboration.expressions;
 
-import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
 import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
@@ -49,11 +48,6 @@ public class EWhen extends SimplifiableExpression {
         query.collectVars(allVars, vars);
         action.collectVars(allVars, vars);
     }
-    
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectEffects.");
-    }
 
     @Override
     protected void updateType() throws MatchException {
index 221bc8067ac454a479b88d33c5a7d72d65f9b84f..507d335e3479379ce7cd4ae1a66e196493e5c920 100644 (file)
@@ -14,6 +14,7 @@ import org.simantics.scl.compiler.elaboration.errors.NotPatternException;
 import org.simantics.scl.compiler.elaboration.expressions.lhstype.LhsType;
 import org.simantics.scl.compiler.elaboration.expressions.lhstype.PatternMatchingLhs;
 import org.simantics.scl.compiler.elaboration.expressions.printing.ExpressionToStringVisitor;
+import org.simantics.scl.compiler.elaboration.expressions.visitors.CollectEffectsVisitor;
 import org.simantics.scl.compiler.elaboration.expressions.visitors.CollectRefsVisitor;
 import org.simantics.scl.compiler.elaboration.expressions.visitors.ForVariablesUsesVisitor;
 import org.simantics.scl.compiler.elaboration.query.QAtom;
@@ -351,12 +352,10 @@ public abstract class Expression extends Symbol implements Typed {
         return false;
     }
     
-    public abstract void collectEffects(THashSet<Type> effects);
-    
     public Type getEffect() {
-        THashSet<Type> effects = new THashSet<Type>();
-        collectEffects(effects);
-        return Types.union(effects.toArray(new Type[effects.size()]));
+        CollectEffectsVisitor visitor = new CollectEffectsVisitor();
+        accept(visitor);
+        return visitor.getCombinedEffect();
     }
     
     public abstract void accept(ExpressionVisitor visitor);
index 861cf48a7daa3146abb26c018b00b3efcb082551..7dbcf69e2af48a1a93976dff5eefeda2d074911e 100644 (file)
@@ -2,6 +2,7 @@ package org.simantics.scl.compiler.elaboration.expressions;
 
 
 public interface ExpressionVisitor {
+    void visit(EAmbiguous eAmbiguous);
     void visit(EApply expression);
     void visit(EApplyType expression);
     void visit(EAsPattern expression);
index 1e2cd05c422791ffe3c73a7257b2d39c42759e1c..62bbe45b94f1988d7dfebf87b906d44e4d3bd6ae 100644 (file)
@@ -126,15 +126,6 @@ public class GuardedExpressionGroup extends Expression {
             newExpressions[i] = expressions[i].replace(context);
         return new GuardedExpressionGroup(newExpressions);            
     }
-
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        for(GuardedExpression ge : expressions) {
-            for(Expression guard : ge.guards)
-                guard.collectEffects(effects);
-            ge.value.collectEffects(effects);
-        }
-    }
     
     @Override
     public void setLocationDeep(long loc) {
index 3cdb32b72c93e12c3ad65a722260b8dc29926a3b..7ef827fb692520ed89792c1363f2ba6356c37643 100644 (file)
@@ -499,4 +499,10 @@ EquationVisitor, StatementVisitor, CHRAstQueryVisitor {
     public void visit(CHRAstNegation query) {
         query.subquery.accept(this);
     }
+
+    @Override
+    public void visit(EAmbiguous expression) {
+        if(expression.resolvedExpression != null)
+            expression.resolvedExpression.accept(this);
+    }
 }
index 1283cc059b7124b4af7e3737437525c9f2ea8f30..2477a4f5fdc6ee4b45a407f1c490dd2619ab9155 100644 (file)
@@ -8,7 +8,6 @@ import org.simantics.scl.compiler.elaboration.expressions.EVariable;
 import org.simantics.scl.compiler.elaboration.expressions.Expression;
 import org.simantics.scl.compiler.elaboration.expressions.Variable;
 import org.simantics.scl.compiler.errors.Locations;
-import org.simantics.scl.compiler.types.Type;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
 import gnu.trove.set.hash.THashSet;
@@ -72,12 +71,6 @@ public class ListAssignment extends ListQualifier {
         pattern = pattern.resolveAsPattern(context);
     }
 
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        pattern.collectEffects(effects);
-        value.collectEffects(effects);
-    }
-    
     @Override
     public void setLocationDeep(long loc) {
         if(location == Locations.NO_LOCATION) {
index db12689c862b69d250bba2336a59c3a447eee49a..59f45bb365c0118f905add1a30bdafcf0e312ce2 100644 (file)
@@ -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.errors.Locations;
 import org.simantics.scl.compiler.types.TMetaVar;
-import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.kinds.Kinds;
 
@@ -77,13 +76,7 @@ public class ListGenerator extends ListQualifier {
         value = value.resolve(context);
         pattern = pattern.resolveAsPattern(context);
     }
-    
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        pattern.collectEffects(effects);
-        value.collectEffects(effects);
-    }
-    
+
     @Override
     public void setLocationDeep(long loc) {
         if(location == Locations.NO_LOCATION) {
index 2fe49150f6473d581a29c839507ec3675e8e3320..1deaf92fae998d8a1bc2bcb1a83d484f2ba5c1ad 100644 (file)
@@ -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.errors.Locations;
-import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.Types;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
@@ -45,14 +44,9 @@ public class ListGuard extends ListQualifier {
 
     @Override
     public void resolve(TranslationContext context) {
-        condition = condition.resolve(context);        
+        condition = condition.resolve(context);
     }
-    
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        condition.collectEffects(effects);
-    }
-    
+
     @Override
     public void setLocationDeep(long loc) {
         if(location == Locations.NO_LOCATION) {
index 47c9cf6d8d9e384a9ab7032ce2e62632c554c663..352c7514e7087f40bbc3f66933874bc477b6f861 100644 (file)
@@ -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.internal.parsing.Symbol;
-import org.simantics.scl.compiler.types.Type;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
 import gnu.trove.set.hash.THashSet;
@@ -21,7 +20,6 @@ public abstract class ListQualifier extends Symbol {
      */
     public abstract CompiledQualifier compile(SimplificationContext context);
     public abstract void resolve(TranslationContext context);
-    public abstract void collectEffects(THashSet<Type> effects);
     public abstract void setLocationDeep(long loc);
     public abstract void accept(ListQualifierVisitor visitor);
     public abstract ListQualifier accept(ListQualifierTransformer transformer);
index a802a80accbc1ea64cda833701aa1788ad427f63..50de4a7dd564f1b71184e64ef9396372db820d4a 100644 (file)
@@ -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.errors.Locations;
-import org.simantics.scl.compiler.types.Type;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
 import gnu.trove.set.hash.THashSet;
@@ -67,12 +66,6 @@ public class ListSeq extends ListQualifier {
         b.resolve(context);
     }
     
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        a.collectEffects(effects);
-        b.collectEffects(effects);
-    }
-    
     @Override
     public void setLocationDeep(long loc) {
         if(location == Locations.NO_LOCATION) {
index e1061564f767391b576c00e26a6329ba55246da5..706611bbb9c9753c927ebc8c3a31b35690a4fc3f 100644 (file)
@@ -89,14 +89,6 @@ public class ListThen extends ListQualifier {
             by = by.resolve(context);
     }
 
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        left.collectEffects(effects);
-        transformer.collectEffects(effects);
-        if(by != null)
-            by.collectEffects(effects);
-    }
-    
     @Override
     public void setLocationDeep(long loc) {
         if(location == Locations.NO_LOCATION) {
index edf951711c2c247f763fa7a23ab3e4eee0482652..b1a05d70e2e42a6541d180bfe38d085d8dc9d319 100644 (file)
@@ -8,6 +8,7 @@ import org.simantics.scl.compiler.elaboration.chr.CHRRule;
 import org.simantics.scl.compiler.elaboration.chr.relations.CHRConstraint;
 import org.simantics.scl.compiler.elaboration.expressions.Assignment;
 import org.simantics.scl.compiler.elaboration.expressions.Case;
+import org.simantics.scl.compiler.elaboration.expressions.EAmbiguous;
 import org.simantics.scl.compiler.elaboration.expressions.EApply;
 import org.simantics.scl.compiler.elaboration.expressions.EApplyType;
 import org.simantics.scl.compiler.elaboration.expressions.EAsPattern;
@@ -612,4 +613,9 @@ public class ExpressionToStringVisitor implements ExpressionVisitor, QueryVisito
         }
         b.append('"');
     }
+
+    @Override
+    public void visit(EAmbiguous eAmbiguous) {
+        b.append("EAmbigious");
+    }
 }
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectEffectsVisitor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectEffectsVisitor.java
new file mode 100644 (file)
index 0000000..aec3d84
--- /dev/null
@@ -0,0 +1,62 @@
+package org.simantics.scl.compiler.elaboration.expressions.visitors;
+
+import org.simantics.scl.compiler.elaboration.expressions.EApply;
+import org.simantics.scl.compiler.elaboration.expressions.ECHRRuleset;
+import org.simantics.scl.compiler.elaboration.expressions.ECHRSelect;
+import org.simantics.scl.compiler.elaboration.expressions.EFieldAccess;
+import org.simantics.scl.compiler.elaboration.expressions.ELambda;
+import org.simantics.scl.compiler.elaboration.expressions.ESimpleLambda;
+import org.simantics.scl.compiler.elaboration.expressions.ETransformation;
+import org.simantics.scl.compiler.elaboration.expressions.StandardExpressionVisitor;
+import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.compiler.types.Types;
+
+import gnu.trove.set.hash.THashSet;
+
+public class CollectEffectsVisitor extends StandardExpressionVisitor {
+    public final THashSet<Type> effects = new THashSet<Type>();
+    
+    @Override
+    public void visit(EApply expression) {
+        effects.add(expression.effect);
+        super.visit(expression);
+    }
+    
+    @Override
+    public void visit(ECHRRuleset expression) {
+        effects.add(Types.PROC);
+        super.visit(expression);
+    }
+    
+    @Override
+    public void visit(ECHRSelect expression) {
+        effects.add(Types.PROC);
+        super.visit(expression);
+    }
+    
+    @Override
+    public void visit(EFieldAccess expression) {
+        // FIXME
+        effects.add(Types.READ_GRAPH);
+        super.visit(expression);
+    }
+    
+    @Override
+    public void visit(ETransformation expression) {
+        // FIXME
+        effects.add(Types.PROC);
+        super.visit(expression);
+    }
+    
+    @Override
+    public void visit(ELambda expression) {
+    }
+    
+    @Override
+    public void visit(ESimpleLambda expression) {
+    }
+    
+    public Type getCombinedEffect() {
+        return Types.union(effects.toArray(new Type[effects.size()]));
+    }
+}