]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
(refs #7375) Replaced collectFreeVariables method by a visitor 55/755/2
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Mon, 24 Jul 2017 11:19:26 +0000 (14:19 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Mon, 24 Jul 2017 11:23:43 +0000 (14:23 +0300)
Change-Id: I89817b8a075d6261b351fbbd70c40d9f9ccc59cc

72 files changed:
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRLiteral.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRQuery.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRule.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRuleset.java
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/Case.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/EBlock.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/EPreLet.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EPreRuleset.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/GuardedExpressionGroup.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/accessor/ExpressionAccessor.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/visitors/CollectEffectsVisitor.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectFreeVariablesVisitor.java [new file with mode: 0644]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectRefsVisitor.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/ForVariablesUsesVisitor.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/StandardExpressionTransformer.java [moved from bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/StandardExpressionTransformer.java with 83% similarity]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/StandardExpressionVisitor.java [moved from bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/StandardExpressionVisitor.java with 78% similarity]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QAbstractCombiner.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QAbstractModifier.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QAtom.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QExists.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QIf.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QMapping.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/Query.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/pre/PreQuery.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/profiling/BranchPointInjector.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ToplevelEffectDecorator.java

index 2697ea08fe287bc36c441e39c8ba738316346ba1..3cbebd49d83e6038b4fb1a6e1ffad56134bfc3d4 100644 (file)
@@ -148,19 +148,6 @@ public class CHRLiteral extends Symbol {
                 parameter.collectVars(allVars, vars);
     }
 
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        if(relation == SpecialCHRRelation.ASSIGN) {
-            parameters[1].collectFreeVariables(vars);
-        }
-        else {
-            for(Expression parameter : parameters)
-                parameter.collectFreeVariables(vars);
-            if(typeConstraintEvidenceParameters != null)
-                for(Expression parameter : typeConstraintEvidenceParameters)
-                    parameter.collectFreeVariables(vars);
-        }
-    }
-
     public void setLocationDeep(long loc) {
         if(location == Locations.NO_LOCATION) {
             this.location = loc;
index 8bba6697d9bb3832782ee20ab4dd5af493219ab1..5c0fdaea20f929f1a38ecfd93e29dab950ab1ea0 100644 (file)
@@ -4,7 +4,6 @@ import org.simantics.scl.compiler.elaboration.chr.plan.PostCommitOp;
 import org.simantics.scl.compiler.elaboration.chr.plan.PreCommitOp;
 import org.simantics.scl.compiler.elaboration.chr.planning.QueryPlanningContext;
 import org.simantics.scl.compiler.elaboration.chr.relations.CHRConstraint;
-import org.simantics.scl.compiler.elaboration.chr.relations.SpecialCHRRelation;
 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
@@ -40,15 +39,7 @@ public class CHRQuery extends Symbol {
         for(CHRLiteral literal : literals)
             literal.collectVars(allVars, vars);
     }
-
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        for(CHRLiteral literal : literals)
-            literal.collectFreeVariables(vars);
-        for(CHRLiteral literal : literals)
-            if(literal.relation == SpecialCHRRelation.ASSIGN)
-                literal.parameters[0].removeFreeVariables(vars);
-    }
-
+    
     public void setLocationDeep(long loc) {
         if(location == Locations.NO_LOCATION) {
             this.location = loc;
index 67b30b221c78f2e992791f27563df094d8091a8c..78224ebb0d75d876f0da2528a4ab8fba56a33129 100644 (file)
@@ -18,7 +18,6 @@ import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.kinds.Kinds;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class CHRRule extends Symbol {
@@ -69,11 +68,6 @@ public class CHRRule extends Symbol {
         body.collectVars(allVars, vars);
     }
 
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        head.collectFreeVariables(vars);
-        body.collectFreeVariables(vars);
-    }
-
     public void setLocationDeep(long loc) {
         if(location == Locations.NO_LOCATION) {
             this.location = loc;
index 805e781e74a6eff0f2876ea43df82b86443395ca..2a405952219e15b92866fd073020eed2e91f93c1 100644 (file)
@@ -136,13 +136,6 @@ public class CHRRuleset extends Symbol {
             rule.collectVars(allVars, vars);
     }
 
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        for(IncludeStatement include : includes)
-            include.value.collectFreeVariables(vars);
-        for(CHRRule rule : rules)
-            rule.collectFreeVariables(vars);
-    }
-
     public void setLocationDeep(long loc) {
         if(location == Locations.NO_LOCATION) {
             this.location = loc;
index 8dcfe08639d21dbc0984bb325fe5ae7ecbad9322..71dcd04251e2609a7449a119e165a1639ad30354 100644 (file)
@@ -8,7 +8,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Variable;
 import org.simantics.scl.compiler.errors.Locations;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EqBasic extends Equation {
@@ -34,12 +33,6 @@ public class EqBasic extends Equation {
         }
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        left.collectFreeVariables(vars);
-        right.collectFreeVariables(vars);
-    }
-
     @Override
     public void checkType(TypingContext context) {
         left = left.inferType(context);
index 8b10872e94ff7052a8d25c18c6cf17cf89c8d7b4..aa66cd8906fa9dd7149996d665dc93b1385aa45a 100644 (file)
@@ -8,7 +8,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Variable;
 import org.simantics.scl.compiler.errors.Locations;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EqGuard extends Equation {
@@ -31,11 +30,6 @@ public class EqGuard extends Equation {
         }
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        guard.collectFreeVariables(vars);
-    }
-
     @Override
     public void checkType(TypingContext context) {
         guard = guard.checkIgnoredType(context);
index 94283436a628e49a115ff70c37a11230f824d4cd..5b4268691e73e1bc32ab0c92cc90f644c550f3bb 100644 (file)
@@ -7,7 +7,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Variable;
 import org.simantics.scl.compiler.internal.parsing.Symbol;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public abstract class Equation extends Symbol {
@@ -15,7 +14,6 @@ public abstract class Equation extends Symbol {
 
     public abstract void setLocationDeep(long loc);
 
-    public abstract void collectFreeVariables(THashSet<Variable> vars);
     public abstract void checkType(TypingContext context);
     public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
     public abstract void resolve(TranslationContext context);
index 7e804c2a26b325cd3bde3f9c0fe927c926958d83..2858a579c3938d8ebdfb44c24ac05d02bf03bab5 100644 (file)
@@ -8,7 +8,6 @@ import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public abstract class ASTExpression extends SimplifiableExpression {
@@ -20,11 +19,6 @@ public abstract class ASTExpression extends SimplifiableExpression {
         throw new InternalCompilerError(getClass().getSimpleName() + " does not support simplify.");
     }
     
-    @Override
-    final public void collectFreeVariables(THashSet<Variable> vars) {
-        throw new InternalCompilerError(getClass().getSimpleName() + " does not support collectFreeVariables.");
-    }
-    
     @Override
     final public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index c8f0eb893e15f7f58e5a6751b2435b05944b53c2..2669b4733fc328fc5376a2c310990cf24fe45c9c 100644 (file)
@@ -9,7 +9,6 @@ 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;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class Case extends Symbol {
@@ -40,12 +39,6 @@ public class Case extends Symbol {
         value.collectVars(allVars, vars);
     }
 
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        value.collectFreeVariables(vars);
-        for(int i=patterns.length-1;i>=0;--i)
-            patterns[i].removeFreeVariables(vars);
-    }
-
     public void resolve(TranslationContext context) {
         context.pushFrame();
         for(int i=0;i<patterns.length;++i)
index 97b223d56b0e1cbf65b18134a8d7200c35ab88a7..c531b854745540fb0f87930b2a25706820a9a6d0 100644 (file)
@@ -16,7 +16,6 @@ import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public abstract class DecoratingExpression extends SimplifiableExpression {
@@ -38,11 +37,6 @@ public abstract class DecoratingExpression extends SimplifiableExpression {
         setType(expression.getType());        
     }
     
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        expression.collectFreeVariables(vars);
-    }
-
     @Override
     public Expression simplify(SimplificationContext context) {
         expression = expression.simplify(context);
index d52cc3f2ef4c3d493170fb3205c7e5238ea55b1c..0826bbbca5727b925b57155190985f4269e6defa 100644 (file)
@@ -17,7 +17,6 @@ import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
 
 import gnu.trove.map.hash.THashMap;
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EAmbiguous extends SimplifiableExpression {
@@ -27,7 +26,7 @@ public class EAmbiguous extends SimplifiableExpression {
     boolean[] active;
     int activeCount;
     transient TypingContext context;
-    Expression resolvedExpression;
+    public Expression resolvedExpression;
     
     public abstract static class Alternative {
         public abstract Type getType();
@@ -163,10 +162,6 @@ public class EAmbiguous extends SimplifiableExpression {
         listenType();
         return this;
     }
-    
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-    }
 
     @Override
     public Expression resolve(TranslationContext context) {
index d45e7fc8c4a6ee2917b2c55cabdfadc7a52e5f9e..14366a4c9a366ea4e84711e20a319a79ae1998d4 100644 (file)
@@ -33,7 +33,6 @@ import org.simantics.scl.compiler.types.kinds.Kinds;
 import org.simantics.scl.compiler.types.util.MultiFunction;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EApply extends Expression {
@@ -102,13 +101,6 @@ public class EApply extends Expression {
         effect = Types.simplifyFinalEffect(effect);
         return w.applyWithEffect(location, effect, type, functionVal, parameterVals);
     }
-
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        function.collectFreeVariables(vars);
-        for(Expression parameter : parameters)
-            parameter.collectFreeVariables(vars);
-    }
     
     private void combineApplications() {
         if(function instanceof EApply) {
@@ -186,13 +178,6 @@ public class EApply extends Expression {
         for(Expression parameter : this.parameters)
             parameters.add(parameter);
     }
-    
-    @Override
-    public void removeFreeVariables(THashSet<Variable> vars) {
-        function.removeFreeVariables(vars);
-        for(Expression parameter : parameters)
-            parameter.removeFreeVariables(vars);
-    }
 
     @Override
     public Expression replace(ReplaceContext context) {
index df945eabb157a2ea6a4cfda55b0b08caf4d80687..f9426f21ac500cf7bb1e4f72988f0d1c5007b97f 100644 (file)
@@ -16,11 +16,10 @@ import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EApplyType extends Expression {    
-    Expression expression;
+    public Expression expression;
     Type parameter;
     
     public EApplyType(Expression expression, Type parameter) {
@@ -65,11 +64,6 @@ public class EApplyType extends Expression {
         return val.createSpecialization(parameter);
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        expression.collectFreeVariables(vars);
-    }
-
     @Override
     public Expression simplify(SimplificationContext context) {
         expression = expression.simplify(context);
@@ -85,11 +79,6 @@ public class EApplyType extends Expression {
         expression = expression.resolve(context);
         return this;
     }
-    
-    @Override
-    public void removeFreeVariables(THashSet<Variable> vars) {
-        expression.removeFreeVariables(vars);
-    }
 
     @Override
     public Expression replace(ReplaceContext context) {
index 6d29526ea76b223d73f5ba6d998248fb4e10a65d..59538d603f72e2c7322460fb01b9de3cfe945c75 100644 (file)
@@ -13,7 +13,6 @@ import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EAsPattern extends Expression {
@@ -48,17 +47,6 @@ public class EAsPattern extends Expression {
             vars.add(id);
         pattern.collectVars(allVars, vars);
     }
-
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        throw new InternalCompilerError(location, "Cannot collect free variables for a pattern.");
-    }
-    
-    @Override
-    public void removeFreeVariables(THashSet<Variable> vars) {
-        vars.remove(var);
-        pattern.removeFreeVariables(vars);
-    }
     
     @Override
     public Expression simplify(SimplificationContext context) {
index 2d3a7ce920a8e113107f0297d7853406b291d2ac..ce72e282aa2a58b1d1e59030d739fe8f89c46c27 100644 (file)
@@ -16,14 +16,13 @@ import org.simantics.scl.compiler.types.exceptions.UnificationException;
 import org.simantics.scl.compiler.types.kinds.Kinds;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EBind extends SimplifiableExpression {
     public Expression pattern;
     public Expression value;
     public Expression in;
-    EVariable monadEvidence;
+    public EVariable monadEvidence;
     SCLValue bindFunction;
     Type monadType;
     Type valueContentType;
@@ -110,13 +109,6 @@ public class EBind extends SimplifiableExpression {
         return simplified.simplify(context);
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        in.collectFreeVariables(vars);
-        value.collectFreeVariables(vars);
-        pattern.removeFreeVariables(vars);
-    }
-
     @Override
     public Expression resolve(TranslationContext context) {
         value = value.resolve(context);
index b7f943c07f47009c2ed7596dbcbdee9a95c49449..ea47c57b23a5cb90fe33be40fd626590ee910261 100644 (file)
@@ -20,7 +20,7 @@ import org.simantics.scl.compiler.errors.Locations;
 
 public class EBlock extends ASTExpression {
 
-    ArrayList<Statement> statements = new ArrayList<Statement>();
+    public ArrayList<Statement> statements = new ArrayList<Statement>();
     boolean monadic;
     
     public EBlock() {
index 12165399321a2496a6148ff77b8d48422a73c164..e1495588adecf3cd8e5142da1b3be98f5f39913e 100644 (file)
@@ -13,12 +13,11 @@ import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class ECHRRuleset extends Expression {
-    CHRRuleset ruleset;
-    Expression in;
+    public CHRRuleset ruleset;
+    public Expression in;
     
     public ECHRRuleset(CHRRuleset ruleset, Expression in) {
         this.ruleset = ruleset;
@@ -42,12 +41,6 @@ public class ECHRRuleset extends Expression {
         return in.toVal(context, w);
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        ruleset.collectFreeVariables(vars);
-        in.collectFreeVariables(vars);
-    }
-
     @Override
     public Expression resolve(TranslationContext context) {
         if(context.currentRuleset != null) {
index 7df6fb595732f88b26c12b826673905679bfceb7..5d7b490e70c7d2617d6ac00de39cdd88c491e70c 100644 (file)
@@ -14,11 +14,10 @@ import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class ECHRRulesetConstructor extends Expression {
-    CHRRuleset ruleset;
+    public CHRRuleset ruleset;
     
     public ECHRRulesetConstructor(CHRRuleset ruleset) {
         this.ruleset = ruleset;
@@ -39,11 +38,6 @@ public class ECHRRulesetConstructor extends Expression {
         return ruleset.generateCode(w);
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        ruleset.collectFreeVariables(vars);
-    }
-
     @Override
     public Expression resolve(TranslationContext context) {
         context.pushFrame();
index d1873e4e6f3240bcf07307e2ec17a54be940232a..71c4a43e02df08078e6c6b16aa43731ba5bcae32 100644 (file)
@@ -22,13 +22,12 @@ import org.simantics.scl.compiler.types.exceptions.MatchException;
 import org.simantics.scl.compiler.types.kinds.Kinds;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class ECHRSelect extends Expression {
-    CHRQuery query;
-    Variable[] existentialVariables;
-    Expression expression;
+    public CHRQuery query;
+    public Variable[] existentialVariables;
+    public Expression expression;
     private ArrayList<PlanOp> planOps;
     private CHRRuleset currentRuleset;
     
@@ -84,15 +83,6 @@ public class ECHRSelect extends Expression {
         return w.apply(location, context.getValue(Names.MList_freeze).getValue(), list);
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        query.collectFreeVariables(vars);
-        expression.collectFreeVariables(vars);
-        if(existentialVariables != null)
-            for(Variable variable : existentialVariables)
-                vars.remove(variable);
-    }
-
     @Override
     public Expression resolve(TranslationContext context) {
         currentRuleset = context.currentRuleset;
index 1bab4ff646da38ab5c03c0327fd5cf6abe3b5cc3..9fcb4ca46ebb5190018b5b15b4d6e16c3a242624 100644 (file)
@@ -1,6 +1,8 @@
 package org.simantics.scl.compiler.elaboration.expressions;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Set;
 
 import org.simantics.scl.compiler.common.names.Name;
 import org.simantics.scl.compiler.common.precedence.Precedence;
@@ -31,7 +33,6 @@ import org.simantics.scl.compiler.types.util.MultiFunction;
 import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EConstant extends Expression {
@@ -87,6 +88,11 @@ public class EConstant extends Expression {
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {   
     }
+    
+    @Override
+    public Set<Variable> getFreeVariables() {
+        return Collections.emptySet();
+    }
 
     public void toString(StringBuilder b, TypeUnparsingContext tuc) {
         Name name = value.getName();
@@ -106,17 +112,13 @@ public class EConstant extends Expression {
         setType(Types.instantiate(value.getType(), typeParameters));
     }
     
-       @Override
-       public IVal toVal(CompilationContext context, CodeWriter w) {
-           IVal val = value.getValue();                
-           if(typeParameters.length > 0) {
-               val = val.createSpecialization(typeParameters);
-           }
-           return val;
-    }
-
     @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
+    public IVal toVal(CompilationContext context, CodeWriter w) {
+        IVal val = value.getValue();           
+        if(typeParameters.length > 0) {
+            val = val.createSpecialization(typeParameters);
+        }
+        return val;
     }
 
     @Override
@@ -151,10 +153,6 @@ public class EConstant extends Expression {
     public Expression resolveAsPattern(TranslationContext context) {
         return this;
     }
-       
-    @Override
-    public void removeFreeVariables(THashSet<Variable> vars) {     
-    }
 
     @Override
     public Expression replace(ReplaceContext context) {
index 9b0a13b20180da7026c5e4ad232931d2d7d7ca03..3bd337963807aef4beacc3774c58045b4d78db6c 100644 (file)
@@ -13,12 +13,11 @@ import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EEnforce extends SimplifiableExpression {
     
-    Query query;
+    public Query query;
     
     public EEnforce(Query query) {
         this.query = query;
@@ -50,11 +49,6 @@ public class EEnforce extends SimplifiableExpression {
         return query.generateEnforce(new EnforcingContext(context));
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        query.collectFreeVariables(vars);
-    }
-
     @Override
     public Expression simplify(SimplificationContext context) {
         /*query = query.simplify(context);
index d2d31713bbf966a48a6b6c3b14d00343354e8f42..268cc24977d14fcd806b1ffc434ab50b167c382c 100644 (file)
@@ -11,7 +11,6 @@ import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EEquations extends SimplifiableExpression {
@@ -60,12 +59,6 @@ public class EEquations extends SimplifiableExpression {
         setType(Types.UNIT);
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        for(Equation equation : equations)
-            equation.collectFreeVariables(vars);
-    }
-
     @Override
     public void accept(ExpressionVisitor visitor) {
         visitor.visit(this);
index 82c6d5d527faf20232eb2a0f46290c91b73c5513..def4087169b67abe35e91f15dd907e40864885e5 100644 (file)
@@ -14,7 +14,6 @@ import org.simantics.scl.compiler.types.exceptions.MatchException;
 import org.simantics.scl.compiler.types.kinds.Kinds;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EError extends Expression {
@@ -46,10 +45,6 @@ public class EError extends Expression {
         throw new UnsupportedOperationException();
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-    }
-
     @Override
     public Expression simplify(SimplificationContext context) {
         return this;
index 213c30bf198b323da9806fa973827f36d68a7be7..0321ae3fcb37796603da7dc161c7246a5b7d4585 100644 (file)
@@ -20,7 +20,6 @@ import org.simantics.scl.compiler.types.exceptions.MatchException;
 import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EExternalConstant extends Expression {
@@ -55,11 +54,6 @@ public class EExternalConstant extends Expression {
         return mw.getExternalConstant(value, getType());
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-    }
-
-
     @Override
     public Expression simplify(SimplificationContext context) {
         return this;
@@ -85,10 +79,6 @@ public class EExternalConstant extends Expression {
         return new EExternalConstant(value, getType().replace(context.tvarMap));
     }
     
-    @Override
-    public void removeFreeVariables(THashSet<Variable> vars) {     
-    }
-    
     @Override
     public Expression inferType(TypingContext context) {
         return this;
index c5ee9bc7a1642aa570e2ef01448709835dfebca1..668c05393d0f29444823b70833479d600fb86f33 100644 (file)
@@ -17,15 +17,14 @@ import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EFieldAccess extends SimplifiableExpression {
 
     private static final Type VARIABLE = Types.con("Simantics/Variables", "Variable");
     
-    Expression parent;
-    FieldAccessor accessor;
+    public Expression parent;
+    public FieldAccessor accessor;
     boolean lastAccessor = true;
 
     public EFieldAccess(Expression parent, FieldAccessor accessor) {
@@ -112,12 +111,6 @@ public class EFieldAccess extends SimplifiableExpression {
         return this;
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        parent.collectFreeVariables(vars);
-        accessor.collectFreeVariables(vars);
-    }
-
     @Override
     public Expression simplify(SimplificationContext context) {
         // Simplify subexpressions
index 95948d45c391e17841a64244576a6b8f6bb1271a..a070ba8da9817771e5913f5b8539e10c7ebde87b 100644 (file)
@@ -8,12 +8,11 @@ import org.simantics.scl.compiler.types.TPred;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EGetConstraint extends SimplifiableExpression {
     TPred constraint;
-    EVariable evidence;
+    public EVariable evidence;
         
     public EGetConstraint(long loc, TPred constraint) {
         super(loc);
@@ -42,12 +41,6 @@ public class EGetConstraint extends SimplifiableExpression {
         setType(constraint);
     }
     
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        if(evidence != null)
-            evidence.collectFreeVariables(vars);
-    }
-    
     @Override
     public Expression simplify(SimplificationContext context) {
         return evidence.simplify(context);
index 7b56d22fa2991bba35ef28d73240015326917c8e..a6574824398e5965299d7e545afcf04d19a48613 100644 (file)
@@ -18,7 +18,6 @@ import org.simantics.scl.compiler.types.exceptions.MatchException;
 import org.simantics.scl.runtime.tuple.Tuple0;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EIf extends Expression {
@@ -75,14 +74,6 @@ public class EIf extends Expression {
         return w.getParameters()[0];
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        condition.collectFreeVariables(vars);
-        then_.collectFreeVariables(vars);
-        if(else_ != null)
-            else_.collectFreeVariables(vars);
-    }
-
     @Override
     public Expression simplify(SimplificationContext context) {
         condition = condition.simplify(context);
index a70e5016060830f4e3ca8160d04213cab2e4e2ec..fa4db7ff1c4e1c50c2e5a7ed2f93852660cc4853 100644 (file)
@@ -17,12 +17,11 @@ import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EIntegerLiteral extends SimplifiableExpression {
     public String value;
-    EVariable constraint;
+    public EVariable constraint;
 
     public EIntegerLiteral(String value) {
         this.value = value;
@@ -74,10 +73,6 @@ public class EIntegerLiteral extends SimplifiableExpression {
         throw new InternalCompilerError();
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-    }
-
     @Override
     public Expression simplify(SimplificationContext context) {
         try {
index 5aa77046eacac57eaaa6c499687eb07750b5339d..bc3e925b05f6887914db8a4fcf086df5cc3597b7 100644 (file)
@@ -13,7 +13,6 @@ import org.simantics.scl.compiler.types.kinds.Kinds;
 import org.simantics.scl.compiler.types.util.MultiFunction;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class ELambda extends SimplifiableExpression {
@@ -98,12 +97,6 @@ public class ELambda extends SimplifiableExpression {
            return decomposeMatching().simplify(context);
        }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        for(Case case_ : cases)
-            case_.collectFreeVariables(vars);
-    }
-
     @Override
     public Expression resolve(TranslationContext context) {
         for(Case case_ : cases)
index fec64d6d00ae477160d0dc87c028f5130edfc489..9aed4450e4c1a6eb55b41b84312419cb6becfee7 100644 (file)
@@ -16,7 +16,6 @@ import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class ELambdaType extends Expression {
@@ -45,11 +44,6 @@ public class ELambdaType extends Expression {
         return lambdaToVal(context, w);
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        value.collectFreeVariables(vars);
-    }
-
     @Override
     public Expression simplify(SimplificationContext context) {
         value = value.simplify(context);
index 71ee13076912142a36c43451b6d3411aa7360347..71195352405ecf2c2ce35ba5010bd5e814982162 100644 (file)
@@ -21,7 +21,6 @@ import org.simantics.scl.compiler.types.exceptions.MatchException;
 import org.simantics.scl.compiler.types.kinds.Kinds;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 /**
@@ -118,15 +117,6 @@ public class ELet extends Expression {
         return result;
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        in.collectFreeVariables(vars);
-        for(Assignment assign : assignments)
-            assign.value.collectFreeVariables(vars);
-        for(Assignment assign : assignments) 
-            assign.pattern.removeFreeVariables(vars);
-    }
-
     @Override
     public Expression resolve(TranslationContext context) {
         throw new InternalCompilerError("ELet should be already resolved.");
index 102d6465825a4cbee8d8bca1625598fae837c2df..a6d79e817fcdb087bde2a0276492885cd63f2537 100644 (file)
@@ -11,7 +11,6 @@ import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EListComprehension extends SimplifiableExpression {
@@ -57,12 +56,6 @@ public class EListComprehension extends SimplifiableExpression {
         setType(Types.list(head.getType()));
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        head.collectFreeVariables(vars);
-        qualifier.collectFreeVariables(vars);
-    }
-
     @Override
     public Expression simplify(SimplificationContext context) {
         context.pushLocation(location);
index 478d7b31195cf7deb793a0d7e1a7e7114aa16725..797dbc2e5e654c33e9e5ab2b0ffb3bc0a9166e17 100644 (file)
@@ -16,12 +16,11 @@ import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EListLiteral extends SimplifiableExpression {
 
-    Expression[] components;
+    public Expression[] components;
     Type componentType;
 
     public EListLiteral(Expression[] components) {
@@ -44,12 +43,6 @@ public class EListLiteral extends SimplifiableExpression {
             component.collectVars(allVars, vars);
     }
     
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        for(Expression component : components)
-            component.collectFreeVariables(vars);
-    }
-    
     @Override
     public Expression simplify(SimplificationContext context) {
         context.pushLocation(location);
index 388fbb37a1f426c1e435f77b9f12ba03a224cf84..3f65de3b6f0a19249c99e49d28fc2f30ffa4ce0e 100644 (file)
@@ -1,6 +1,8 @@
 package org.simantics.scl.compiler.elaboration.expressions;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Set;
 
 import org.simantics.scl.compiler.compilation.CompilationContext;
 import org.simantics.scl.compiler.constants.Constant;
@@ -18,7 +20,6 @@ import org.simantics.scl.compiler.types.exceptions.MatchException;
 import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class ELiteral extends Expression {
@@ -42,6 +43,11 @@ public class ELiteral extends Expression {
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {            
     }
+    
+    @Override
+    public Set<Variable> getFreeVariables() {
+        return Collections.emptySet();
+    }
 
     public void toString(StringBuilder b, TypeUnparsingContext tuc) {
         b.append(value);
@@ -57,11 +63,6 @@ public class ELiteral extends Expression {
         return value;
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-    }
-
-
     @Override
     public Expression simplify(SimplificationContext context) {
         return this;
@@ -87,10 +88,6 @@ public class ELiteral extends Expression {
         return new ELiteral(value);
     }
     
-    @Override
-    public void removeFreeVariables(THashSet<Variable> vars) {     
-    }
-    
     @Override
     public IExpression toIExpression(ExpressionInterpretationContext target) {
         return new IConstant(value.realizeValue(target.localClassBuilder));
index 18f89ccdf7dcb885eb943176f6cdbf136d3e0a4e..ba9cee65edc0cc7daa1bfc8cfb652514da64933c 100644 (file)
@@ -18,7 +18,6 @@ import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.kinds.Kinds;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EMatch extends Expression {
@@ -72,14 +71,6 @@ public class EMatch extends Expression {
         w.continueAs(joinPoint);
         return w.getParameters()[0];
     }
-
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        for(Expression s : scrutinee)
-            s.collectFreeVariables(vars);
-        for(Case case_ : cases)
-            case_.collectFreeVariables(vars);
-    }
     
     @Override
     public Expression simplify(SimplificationContext context) {
index c7624039e6e75fdc9f5f4a986c499934eb109942..1578928aae032cb3a9386415e4b6a3b1f8368292 100644 (file)
@@ -18,8 +18,8 @@ import gnu.trove.procedure.TObjectObjectProcedure;
  */
 public class EPreLet extends ASTExpression {
 
-    List<LetStatement> assignments;
-    Expression in;
+    public List<LetStatement> assignments;
+    public Expression in;
     
     public EPreLet(List<LetStatement> assignments, Expression in) {
         this.assignments = assignments;
index 41880a0224bd2fb960f9acd7cc3f05bf03c0c093..c287f3ba1a26e73b66f8a84390cbee35cc8c1ef3 100644 (file)
@@ -10,8 +10,8 @@ import gnu.trove.map.hash.THashMap;
 
 public class EPreRuleset extends ASTExpression {
 
-    RuleStatement[] statements;
-    Expression in;
+    public RuleStatement[] statements;
+    public Expression in;
     
     public EPreRuleset(RuleStatement[] statements, Expression in) {
         this.statements = statements;
index 5312c7543fa4fb23024342c55d4dba6912e93331..8c861004cadbd2cb88fbddd1bacab331d311534d 100644 (file)
@@ -16,12 +16,11 @@ import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class ERealLiteral extends SimplifiableExpression {
     public String value;
-    EVariable constraint;
+    public EVariable constraint;
 
     public ERealLiteral(String value) {
         this.value = value;
@@ -68,10 +67,6 @@ public class ERealLiteral extends SimplifiableExpression {
     protected void updateType() throws MatchException {
         throw new InternalCompilerError("TODO");
     }
-    
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-    }
 
     @Override
     public Expression simplify(SimplificationContext context) {
index e84e0500c41bb045547266a9f924ea62b22d9b10..dadf52797d28052416c24961a166ee66657b6c78 100644 (file)
@@ -43,13 +43,12 @@ import org.simantics.scl.compiler.types.kinds.Kinds;
 import gnu.trove.impl.Constants;
 import gnu.trove.map.hash.THashMap;
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class ERuleset extends SimplifiableExpression {
     LocalRelation[] relations;
-    DatalogRule[] rules;
-    Expression in;
+    public DatalogRule[] rules;
+    public Expression in;
     
     public ERuleset(LocalRelation[] relations, DatalogRule[] rules, Expression in) {
         this.relations = relations;
@@ -129,18 +128,6 @@ public class ERuleset extends SimplifiableExpression {
         in = in.checkIgnoredType(context);
         return compile(context);
     }
-    
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        for(DatalogRule rule : rules) {
-            for(Expression parameter : rule.headParameters)
-                parameter.collectFreeVariables(vars);
-            rule.body.collectFreeVariables(vars);
-            for(Variable var : rule.variables)
-                vars.remove(var);
-        }
-        in.collectFreeVariables(vars);
-    }
 
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
index 473c403da7aa85e54db07258b2d1a888efc10cf3..09079377f0a0a11afe61147fb0827865300c4ba1 100644 (file)
@@ -27,7 +27,6 @@ import org.simantics.scl.compiler.types.exceptions.MatchException;
 import org.simantics.scl.compiler.types.kinds.Kinds;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class ESelect extends SimplifiableExpression {
@@ -35,9 +34,9 @@ public class ESelect extends SimplifiableExpression {
     private final Type ARRAY_LIST = Types.con("ArrayList", "T"); 
     
     int selectVariant;
-    Expression expression;
-    Query query;
-    Variable[] variables;
+    public Expression expression;
+    public Query query;
+    public Variable[] variables;
     
     public ESelect(int selectVariant, Expression expression, Query query) {
         this.selectVariant = selectVariant;
@@ -128,14 +127,6 @@ public class ESelect extends SimplifiableExpression {
         return loc(location, result);
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        expression.collectFreeVariables(vars);
-        query.collectFreeVariables(vars);
-        for(Variable variable : variables)
-            vars.remove(variable);
-    }
-
     @Override
     public Expression resolve(TranslationContext context) {
         context.pushExistentialFrame();
index 9b3ee8df77bcdb7812f8ef3f8472cbe83bf34bec..13c75db78bed5fe0f24cb211009ffb7c04f61b80 100644 (file)
@@ -1,6 +1,7 @@
 package org.simantics.scl.compiler.elaboration.expressions;
 
 import java.util.ArrayList;
+import java.util.Set;
 
 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
 import org.simantics.scl.compiler.compilation.CompilationContext;
@@ -23,7 +24,6 @@ import org.simantics.scl.compiler.types.kinds.Kinds;
 import org.simantics.scl.compiler.types.util.MultiFunction;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class ESimpleLambda extends Expression {
@@ -66,21 +66,15 @@ public class ESimpleLambda extends Expression {
         return this;
     }
 
-       @Override
-       protected void updateType() throws MatchException {
-           setType(Types.functionE(Types.canonical(parameter.type),
-                   effect, value.getType()));
-       }
-       
-       @Override
-       public IVal toVal(CompilationContext context, CodeWriter w) {
-           return lambdaToVal(context, w);
+    @Override
+    protected void updateType() throws MatchException {
+        setType(Types.functionE(Types.canonical(parameter.type),
+                effect, value.getType()));
     }
 
     @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        value.collectFreeVariables(vars);
-        vars.remove(parameter);
+    public IVal toVal(CompilationContext context, CodeWriter w) {
+        return lambdaToVal(context, w);
     }
 
     @Override
@@ -143,7 +137,7 @@ public class ESimpleLambda extends Expression {
         
         // Free variables;
         ExpressionInterpretationContext innerContext =  context.createNewContext();
-        THashSet<Variable> freeVariables = cur.getFreeVariables();
+        Set<Variable> freeVariables = cur.getFreeVariables();
         for(Variable parameter : parameters)
             freeVariables.remove(parameter);
         int i=0;
index e69a271218a82b620230be5c9d2a131f396e6702..4957b578dd9597c8ae9f70d08d6f843d7d686a3f 100644 (file)
@@ -16,13 +16,12 @@ import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class ESimpleLet extends Expression {
-    Variable variable; // may be null
-    Expression value;
-    Expression in;
+    public Variable variable; // may be null
+    public Expression value;
+    public Expression in;
     
     public ESimpleLet(Variable variable, Expression value, Expression in) {
         if(value == null)
@@ -65,13 +64,6 @@ public class ESimpleLet extends Expression {
         return in.toVal(context, w);
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        value.collectFreeVariables(vars);
-        in.collectFreeVariables(vars);
-        vars.remove(variable);
-    }
-
     @Override
     public Expression simplify(SimplificationContext context) {
         value = value.simplify(context);
index 7617416584b373de0194fa5aad56e05fdede578c..e6f57ac861ce2b0440400c90bbbdfdee82283b06 100644 (file)
@@ -15,7 +15,6 @@ import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class ETransformation extends SimplifiableExpression {
@@ -39,11 +38,6 @@ public class ETransformation extends SimplifiableExpression {
     protected void updateType() throws MatchException {
         setType(Types.UNIT);
     }
-
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        seed.collectFreeVariables(vars);
-    }
     
     @Override
     public Expression inferType(TypingContext context) {
index 89caebad08877fcffa11d911c19fa2640ea3bf01..872da88f11c313659c247106f1b266c4f2cddd5d 100644 (file)
@@ -9,11 +9,10 @@ import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class ETypeAnnotation extends SimplifiableExpression {
-    Expression value;
+    public Expression value;
     Type type;
     TypeAst typeAst;
         
@@ -39,11 +38,6 @@ public class ETypeAnnotation extends SimplifiableExpression {
         setType(type);
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        value.collectFreeVariables(vars);
-    }
-
     @Override
     public Expression simplify(SimplificationContext context) {
         return value.simplify(context);
index aa278928239ea4efd2ee0d6cb9e336c129541110..fccc62e9869cfc4f5469d2804588d4ed465baf41 100644 (file)
@@ -1,6 +1,8 @@
 package org.simantics.scl.compiler.elaboration.expressions;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Set;
 
 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
 import org.simantics.scl.compiler.compilation.CompilationContext;
@@ -21,7 +23,6 @@ import org.simantics.scl.compiler.types.kinds.Kinds;
 import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EVariable extends Expression {
@@ -53,24 +54,27 @@ public class EVariable extends Expression {
         if(id >= 0)
             vars.add(id);
     }
+    
+    @Override
+    public Set<Variable> getFreeVariables() {
+        if(variable == null)
+            return Collections.emptySet();
+        else
+            return Collections.singleton(variable);
+    }
 
     public void toString(StringBuilder b, TypeUnparsingContext tuc) {
         b.append(variable == null ? "???" : variable.toString());
     }
 
-       @Override
-       protected void updateType() throws MatchException {
-           setType(variable.getType());
-       }
-       
-       @Override
-       public IVal toVal(CompilationContext context, CodeWriter w) {
-        return variable.getVal();
+    @Override
+    protected void updateType() throws MatchException {
+        setType(variable.getType());
     }
 
     @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        vars.add(variable);
+    public IVal toVal(CompilationContext context, CodeWriter w) {
+        return variable.getVal();
     }
 
     @Override
@@ -92,11 +96,6 @@ public class EVariable extends Expression {
             ArrayList<Expression> parameters) {
     }
     
-    @Override
-    public void removeFreeVariables(THashSet<Variable> vars) {
-        vars.remove(variable);
-    }
-    
     @Override
     public Expression resolveAsPattern(TranslationContext context) {
         return this;
index c0dfb5a75158d3f5c03181aabf27a11192ae8175..f2a017edda95d9aa15581b8bf22658e84b32558e 100644 (file)
@@ -13,7 +13,6 @@ import org.simantics.scl.compiler.types.exceptions.MatchException;
 import org.simantics.scl.compiler.types.util.MultiFunction;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EViewPattern extends Expression {
@@ -59,17 +58,6 @@ public class EViewPattern extends Expression {
         throw new InternalCompilerError(location, "EViewPattern.toVal should not be invoked.");
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        throw new InternalCompilerError(location, "Cannot collect free variables for a pattern.");
-    }
-    
-    @Override
-    public void removeFreeVariables(THashSet<Variable> vars) {
-        expression.collectFreeVariables(vars);
-        pattern.removeFreeVariables(vars);
-    }
-
     @Override
     public Expression resolve(TranslationContext context) {
         context.getErrorLog().log("View pattern cannot occur only in patterns. Maybe you are missing '\\' in front of a lambda experssion?");
index 9ea5ddb1ecf7a94a4f8e6fb29a070b191e806d99..55ea86baf443c1d5b72704239309be61924e18db 100644 (file)
@@ -17,14 +17,13 @@ import org.simantics.scl.compiler.types.exceptions.UnificationException;
 import org.simantics.scl.compiler.types.kinds.Kinds;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EWhen extends SimplifiableExpression {
 
     public Query query;
     public Expression action;
-    Variable[] variables;
+    public Variable[] variables;
     
     public EWhen(Query query, Expression action) {
         this.query = query;
@@ -83,14 +82,6 @@ public class EWhen extends SimplifiableExpression {
         }
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        action.collectFreeVariables(vars);
-        query.collectFreeVariables(vars);
-        for(Variable var : variables)
-            vars.remove(var);
-    }
-
     @Override
     public Expression resolve(TranslationContext context) {
         context.pushExistentialFrame();
index 507d335e3479379ce7cd4ae1a66e196493e5c920..5b60dad423c942ddbb2a0ff4d03906a5e327b0cb 100644 (file)
@@ -1,6 +1,7 @@
 package org.simantics.scl.compiler.elaboration.expressions;
 
 import java.util.ArrayList;
+import java.util.Set;
 
 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
 import org.simantics.scl.compiler.common.precedence.Precedence;
@@ -15,8 +16,10 @@ 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.CollectFreeVariablesVisitor;
 import org.simantics.scl.compiler.elaboration.expressions.visitors.CollectRefsVisitor;
 import org.simantics.scl.compiler.elaboration.expressions.visitors.ForVariablesUsesVisitor;
+import org.simantics.scl.compiler.elaboration.expressions.visitors.StandardExpressionVisitor;
 import org.simantics.scl.compiler.elaboration.query.QAtom;
 import org.simantics.scl.compiler.elaboration.relations.SCLRelation;
 import org.simantics.scl.compiler.internal.codegen.references.IVal;
@@ -36,7 +39,6 @@ import org.simantics.scl.compiler.types.kinds.Kinds;
 import org.simantics.scl.compiler.types.util.Typed;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public abstract class Expression extends Symbol implements Typed {
@@ -212,8 +214,6 @@ public abstract class Expression extends Symbol implements Typed {
         return new ELambdaType(vars, this);
        }
     
-    public abstract void collectFreeVariables(THashSet<Variable> vars);
-    
     public Expression simplify(SimplificationContext context) {
         System.out.println("#############################");
         System.out.println(this);
@@ -246,10 +246,6 @@ public abstract class Expression extends Symbol implements Typed {
         context.getErrorLog().log(location, "Pattern was expected here.");
         return new EError();
     }
-
-    public void removeFreeVariables(THashSet<Variable> vars) {
-        throw new InternalCompilerError(getClass().getSimpleName() + " is not a pattern.");
-    }
     
     public Expression checkTypeAsPattern(TypingContext context, Type requiredType) {
         if(context.isInPattern())
@@ -263,10 +259,10 @@ public abstract class Expression extends Symbol implements Typed {
     /**
      * Used during simplification and in toIExpression
      */
-    public THashSet<Variable> getFreeVariables() {
-        THashSet<Variable> result = new THashSet<Variable>();
-        collectFreeVariables(result);
-        return result;
+    public Set<Variable> getFreeVariables() {
+        CollectFreeVariablesVisitor visitor = new CollectFreeVariablesVisitor(); 
+        accept(visitor);
+        return visitor.getFreeVariables();
     }
 
     public static Expression[] concat(Expression[] a, Expression[] b) {
index 62bbe45b94f1988d7dfebf87b906d44e4d3bd6ae..90e13d7507f1d858b48c56485a84b90bcd3c8125 100644 (file)
@@ -15,7 +15,6 @@ import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class GuardedExpressionGroup extends Expression {
@@ -52,15 +51,6 @@ public class GuardedExpressionGroup extends Expression {
         //throw new InternalCompilerError("GuardedExpressionGroup should be handled in match compilation.");
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        for(GuardedExpression expression : expressions) {
-            for(Expression guard : expression.guards)
-                guard.collectFreeVariables(vars);
-            expression.value.collectFreeVariables(vars);
-        }
-    }
-
     @Override
     public Expression simplify(SimplificationContext context) {
         for(GuardedExpression expression : expressions) {
index 12c9a917013ac1edca998fdec2372f1e9a36048e..2febc404f2e967f87d71f28573bf578e74196dfe 100644 (file)
@@ -9,7 +9,6 @@ import org.simantics.scl.compiler.errors.Locations;
 import org.simantics.scl.compiler.types.Types;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class ExpressionAccessor extends FieldAccessor {
@@ -20,11 +19,6 @@ public class ExpressionAccessor extends FieldAccessor {
         this.fieldName = fieldName;
     }
     
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        fieldName.collectFreeVariables(vars);
-    }
-    
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index 2477a4f5fdc6ee4b45a407f1c490dd2619ab9155..47aeef1a5c40b9e05e91296257afc1c9a4875d0d 100644 (file)
@@ -1,5 +1,7 @@
 package org.simantics.scl.compiler.elaboration.expressions.list;
 
+import java.util.Set;
+
 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
@@ -10,7 +12,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Variable;
 import org.simantics.scl.compiler.errors.Locations;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class ListAssignment extends ListQualifier {
@@ -34,18 +35,12 @@ public class ListAssignment extends ListQualifier {
         value.collectVars(allVars, vars);
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        value.collectFreeVariables(vars);
-        pattern.collectFreeVariables(vars);
-    }
-
     @Override
     public CompiledQualifier compile(SimplificationContext context) {
         if(pattern instanceof EVariable)
             return new CompiledQualifier(context.singletonList(value), pattern);
         else {
-            THashSet<Variable> variables = pattern.getFreeVariables();
+            Set<Variable> variables = pattern.getFreeVariables();
             Variable[] variableArray = variables.toArray(new Variable[variables.size()]);
             Expression[] variableExps = new Expression[variableArray.length];
             for(int i=0;i<variableArray.length;++i)
index 59f45bb365c0118f905add1a30bdafcf0e312ce2..959e3bf3d5d71afec0f61d5817f201946eb73e00 100644 (file)
@@ -1,5 +1,7 @@
 package org.simantics.scl.compiler.elaboration.expressions.list;
 
+import java.util.Set;
+
 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
@@ -13,7 +15,6 @@ import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.kinds.Kinds;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class ListGenerator extends ListQualifier {
@@ -38,18 +39,12 @@ public class ListGenerator extends ListQualifier {
         value.collectVars(allVars, vars);
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        value.collectFreeVariables(vars);
-        pattern.collectFreeVariables(vars);
-    }
-
     @Override
     public CompiledQualifier compile(SimplificationContext context) {
         if(pattern instanceof EVariable)
             return new CompiledQualifier(value, pattern);
         else {
-            THashSet<Variable> variables = pattern.getFreeVariables();
+            Set<Variable> variables = pattern.getFreeVariables();
             Variable[] variableArray = variables.toArray(new Variable[variables.size()]);
             Expression[] variableExps = new Expression[variableArray.length];
             for(int i=0;i<variableArray.length;++i)
index 1deaf92fae998d8a1bc2bcb1a83d484f2ba5c1ad..9a5c37bdc3fc494f164a45f85efa08177084fb1e 100644 (file)
@@ -9,7 +9,6 @@ import org.simantics.scl.compiler.errors.Locations;
 import org.simantics.scl.compiler.types.Types;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class ListGuard extends ListQualifier {
@@ -30,11 +29,6 @@ public class ListGuard extends ListQualifier {
         condition.collectVars(allVars, vars);
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        condition.collectFreeVariables(vars);
-    }
-
     @Override
     public CompiledQualifier compile(SimplificationContext context) {
         return new CompiledQualifier(
index 352c7514e7087f40bbc3f66933874bc477b6f861..9365e6a87f5d48a7ebd7146abf48afad34df083d 100644 (file)
@@ -7,14 +7,12 @@ import org.simantics.scl.compiler.elaboration.expressions.Variable;
 import org.simantics.scl.compiler.internal.parsing.Symbol;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public abstract class ListQualifier extends Symbol {
 
     public abstract void checkType(TypingContext context);
     public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
-    public abstract void collectFreeVariables(THashSet<Variable> vars);
     /**
      * Called in simplification.
      */
index 50de4a7dd564f1b71184e64ef9396372db820d4a..6bab8c91e0f52dba74b85b84ee7e40e076b6748b 100644 (file)
@@ -8,7 +8,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Variable;
 import org.simantics.scl.compiler.errors.Locations;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class ListSeq extends ListQualifier {
@@ -33,12 +32,6 @@ public class ListSeq extends ListQualifier {
         b.collectVars(allVars, vars);
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        b.collectFreeVariables(vars);
-        a.collectFreeVariables(vars);
-    }
-
     @Override
     public CompiledQualifier compile(SimplificationContext context) {
         CompiledQualifier cA = a.compile(context);
index 706611bbb9c9753c927ebc8c3a31b35690a4fc3f..b8bd395668b2be7a046a3191e29c44e6af6778c5 100644 (file)
@@ -13,7 +13,6 @@ import org.simantics.scl.compiler.types.exceptions.UnificationException;
 import org.simantics.scl.compiler.types.kinds.Kinds;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class ListThen extends ListQualifier {
@@ -56,14 +55,6 @@ public class ListThen extends ListQualifier {
             by.collectVars(allVars, vars);
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        left.collectFreeVariables(vars);
-        transformer.collectFreeVariables(vars);
-        if(by != null)
-            by.collectFreeVariables(vars);
-    }
-
     @Override
     public CompiledQualifier compile(SimplificationContext context) {
         CompiledQualifier q = left.compile(context);
index aec3d84dc99e0ab6cd593d6556b1f3ffc81a4e81..118d4de1aea7bdd94bb3f95e06ad74d672e14e6f 100644 (file)
@@ -7,7 +7,6 @@ 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;
 
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectFreeVariablesVisitor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectFreeVariablesVisitor.java
new file mode 100644 (file)
index 0000000..04f6791
--- /dev/null
@@ -0,0 +1,184 @@
+package org.simantics.scl.compiler.elaboration.expressions.visitors;
+
+import org.simantics.scl.compiler.elaboration.chr.CHRLiteral;
+import org.simantics.scl.compiler.elaboration.chr.CHRQuery;
+import org.simantics.scl.compiler.elaboration.chr.CHRRule;
+import org.simantics.scl.compiler.elaboration.chr.relations.SpecialCHRRelation;
+import org.simantics.scl.compiler.elaboration.expressions.Assignment;
+import org.simantics.scl.compiler.elaboration.expressions.Case;
+import org.simantics.scl.compiler.elaboration.expressions.EAsPattern;
+import org.simantics.scl.compiler.elaboration.expressions.EBind;
+import org.simantics.scl.compiler.elaboration.expressions.ECHRSelect;
+import org.simantics.scl.compiler.elaboration.expressions.ELet;
+import org.simantics.scl.compiler.elaboration.expressions.ERuleset.DatalogRule;
+import org.simantics.scl.compiler.elaboration.expressions.ESelect;
+import org.simantics.scl.compiler.elaboration.expressions.ESimpleLambda;
+import org.simantics.scl.compiler.elaboration.expressions.ESimpleLet;
+import org.simantics.scl.compiler.elaboration.expressions.EVariable;
+import org.simantics.scl.compiler.elaboration.expressions.EViewPattern;
+import org.simantics.scl.compiler.elaboration.expressions.EWhen;
+import org.simantics.scl.compiler.elaboration.expressions.Expression;
+import org.simantics.scl.compiler.elaboration.expressions.Variable;
+import org.simantics.scl.compiler.elaboration.expressions.list.ListAssignment;
+import org.simantics.scl.compiler.elaboration.expressions.list.ListGenerator;
+import org.simantics.scl.compiler.elaboration.query.QExists;
+
+import gnu.trove.set.hash.THashSet;
+
+public class CollectFreeVariablesVisitor extends StandardExpressionVisitor {
+    private THashSet<Variable> freeVariables = new THashSet<Variable>();
+    
+    private StandardExpressionVisitor collectBoundVariablesVisitor = new StandardExpressionVisitor() {
+        @Override
+        public void visit(EVariable expression) {
+            if(expression.variable != null)
+                freeVariables.remove(expression.variable);
+        }
+        
+        
+        @Override
+        public void visit(EAsPattern expression) {
+            freeVariables.remove(expression.var);
+            expression.pattern.accept(this);
+        }
+        
+        @Override
+        public void visit(EViewPattern expression) {
+            expression.expression.accept(CollectFreeVariablesVisitor.this);
+            expression.pattern.accept(this);
+        }
+    };
+    
+    @Override
+    public void visit(EVariable expression) {
+        if(expression.variable != null)
+            freeVariables.add(expression.variable);
+    }
+    
+    @Override
+    public void visit(EBind expression) {
+        if(expression.monadEvidence != null)
+            visit(expression.monadEvidence);
+        expression.in.accept(this);
+        expression.value.accept(this);
+        expression.pattern.accept(collectBoundVariablesVisitor);
+    }
+    
+    @Override
+    public void visit(Assignment assignment) {
+        assignment.value.accept(this);
+        assignment.pattern.accept(collectBoundVariablesVisitor);
+    }
+    
+    @Override
+    public void visit(ELet expression) {
+        expression.in.accept(this);
+        for(int i=expression.assignments.length-1;i>=0;--i)
+            visit(expression.assignments[i]);
+    }
+    
+    @Override
+    public void visit(Case case_) {
+        case_.value.accept(this);
+        for(Expression pattern : case_.patterns)
+            pattern.accept(collectBoundVariablesVisitor);
+    }
+    
+    @Override
+    public void visit(ESimpleLambda expression) {
+        expression.value.accept(this);
+        freeVariables.remove(expression.parameter);
+    }
+    
+    @Override
+    public void visit(ESimpleLet expression) {
+        expression.in.accept(this);
+        expression.value.accept(this);
+        freeVariables.remove(expression.variable);
+    }
+    
+    @Override
+    public void visit(ECHRSelect expression) {
+        expression.expression.accept(this);
+        visit(expression.query);
+        for(Variable variable : expression.existentialVariables)
+            freeVariables.remove(variable);
+    }
+    
+    @Override
+    public void visit(ESelect expression) {
+        expression.expression.accept(this);
+        expression.query.accept(this);
+        for(Variable variable : expression.variables)
+            freeVariables.remove(variable);
+    }
+    
+    @Override
+    public void visit(EWhen expression) {
+        expression.action.accept(this);
+        expression.query.accept(this);
+        for(Variable variable : expression.variables)
+            freeVariables.remove(variable);
+    }
+
+    @Override
+    public void visit(DatalogRule rule) {
+        for(Expression parameter : rule.headParameters)
+            parameter.accept(this);
+        rule.body.accept(this);
+        for(Variable variable : rule.variables)
+            freeVariables.remove(variable);
+    }
+    
+    @Override
+    public void visit(ListGenerator qualifier) {
+        qualifier.pattern.accept(collectBoundVariablesVisitor);
+        qualifier.value.accept(this);
+    }
+    
+    @Override
+    public void visit(ListAssignment qualifier) {
+        qualifier.pattern.accept(collectBoundVariablesVisitor);
+        qualifier.value.accept(this);
+    }
+    
+    @Override
+    public void visit(CHRLiteral literal) {
+        if(literal.relation == SpecialCHRRelation.ASSIGN) {
+            literal.parameters[0].accept(collectBoundVariablesVisitor);
+            literal.parameters[1].accept(this);
+        }
+        else {
+            for(Expression parameter : literal.parameters)
+                parameter.accept(this);
+            if(literal.typeConstraintEvidenceParameters != null)
+                for(Expression parameter : literal.typeConstraintEvidenceParameters)
+                    parameter.accept(this);
+        }
+    }
+    
+    @Override
+    public void visit(CHRQuery query) {
+        for(int i=query.literals.length-1;i>=0;--i) {
+            visit(query.literals[i]);
+        }
+    }
+    
+    @Override
+    public void visit(CHRRule rule) {
+        super.visit(rule);
+        for(Variable variable : rule.existentialVariables)
+            freeVariables.remove(variable);
+    }
+    
+    @Override
+    public void visit(QExists query) {
+        query.query.accept(this);
+        for(Variable variable : query.variables)
+            freeVariables.remove(variable);
+    }
+    
+    public THashSet<Variable> getFreeVariables() {
+        return freeVariables;
+    }
+}
index 366dc514bb690fde4fdd83d2311eb762b8f9048c..5445f08926b7b9115b7b72b81dc58d8d5ed6e8ac 100644 (file)
@@ -2,7 +2,6 @@ package org.simantics.scl.compiler.elaboration.expressions.visitors;
 
 import org.simantics.scl.compiler.elaboration.expressions.EConstant;
 import org.simantics.scl.compiler.elaboration.expressions.ETransformation;
-import org.simantics.scl.compiler.elaboration.expressions.StandardExpressionVisitor;
 import org.simantics.scl.compiler.elaboration.query.QAtom;
 import org.simantics.scl.compiler.elaboration.relations.CompositeRelation;
 import org.simantics.scl.compiler.elaboration.relations.SCLRelation;
index b4d1fd4fe2d558f8e4efc6c48938aaa63c749ffb..57befad98a0c3317803628eb449cc229c7d3d670 100644 (file)
@@ -2,7 +2,6 @@ package org.simantics.scl.compiler.elaboration.expressions.visitors;
 
 import org.simantics.scl.compiler.elaboration.expressions.EAsPattern;
 import org.simantics.scl.compiler.elaboration.expressions.EVariable;
-import org.simantics.scl.compiler.elaboration.expressions.StandardExpressionVisitor;
 import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure;
 
 public class ForVariablesUsesVisitor extends StandardExpressionVisitor {
@@ -1,4 +1,4 @@
-package org.simantics.scl.compiler.elaboration.expressions;
+package org.simantics.scl.compiler.elaboration.expressions.visitors;
 
 import org.simantics.scl.compiler.elaboration.chr.CHRLiteral;
 import org.simantics.scl.compiler.elaboration.chr.CHRQuery;
@@ -15,6 +15,58 @@ import org.simantics.scl.compiler.elaboration.equation.EqBasic;
 import org.simantics.scl.compiler.elaboration.equation.EqGuard;
 import org.simantics.scl.compiler.elaboration.equation.Equation;
 import org.simantics.scl.compiler.elaboration.equation.EquationVisitor;
+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;
+import org.simantics.scl.compiler.elaboration.expressions.EBinary;
+import org.simantics.scl.compiler.elaboration.expressions.EBinaryRightSide;
+import org.simantics.scl.compiler.elaboration.expressions.EBind;
+import org.simantics.scl.compiler.elaboration.expressions.EBlock;
+import org.simantics.scl.compiler.elaboration.expressions.ECHRRuleset;
+import org.simantics.scl.compiler.elaboration.expressions.ECHRRulesetConstructor;
+import org.simantics.scl.compiler.elaboration.expressions.ECHRSelect;
+import org.simantics.scl.compiler.elaboration.expressions.EConstant;
+import org.simantics.scl.compiler.elaboration.expressions.ECoveringBranchPoint;
+import org.simantics.scl.compiler.elaboration.expressions.EEnforce;
+import org.simantics.scl.compiler.elaboration.expressions.EEquations;
+import org.simantics.scl.compiler.elaboration.expressions.EError;
+import org.simantics.scl.compiler.elaboration.expressions.EExternalConstant;
+import org.simantics.scl.compiler.elaboration.expressions.EFieldAccess;
+import org.simantics.scl.compiler.elaboration.expressions.EGetConstraint;
+import org.simantics.scl.compiler.elaboration.expressions.EIf;
+import org.simantics.scl.compiler.elaboration.expressions.EIntegerLiteral;
+import org.simantics.scl.compiler.elaboration.expressions.ELambda;
+import org.simantics.scl.compiler.elaboration.expressions.ELambdaType;
+import org.simantics.scl.compiler.elaboration.expressions.ELet;
+import org.simantics.scl.compiler.elaboration.expressions.EListComprehension;
+import org.simantics.scl.compiler.elaboration.expressions.EListLiteral;
+import org.simantics.scl.compiler.elaboration.expressions.ELiteral;
+import org.simantics.scl.compiler.elaboration.expressions.EMatch;
+import org.simantics.scl.compiler.elaboration.expressions.EPlaceholder;
+import org.simantics.scl.compiler.elaboration.expressions.EPreLet;
+import org.simantics.scl.compiler.elaboration.expressions.EPreRuleset;
+import org.simantics.scl.compiler.elaboration.expressions.ERange;
+import org.simantics.scl.compiler.elaboration.expressions.ERealLiteral;
+import org.simantics.scl.compiler.elaboration.expressions.ERecord;
+import org.simantics.scl.compiler.elaboration.expressions.ERuleset;
+import org.simantics.scl.compiler.elaboration.expressions.ESelect;
+import org.simantics.scl.compiler.elaboration.expressions.ESimpleLambda;
+import org.simantics.scl.compiler.elaboration.expressions.ESimpleLet;
+import org.simantics.scl.compiler.elaboration.expressions.EStringLiteral;
+import org.simantics.scl.compiler.elaboration.expressions.ETransformation;
+import org.simantics.scl.compiler.elaboration.expressions.ETypeAnnotation;
+import org.simantics.scl.compiler.elaboration.expressions.EVar;
+import org.simantics.scl.compiler.elaboration.expressions.EVariable;
+import org.simantics.scl.compiler.elaboration.expressions.EViewPattern;
+import org.simantics.scl.compiler.elaboration.expressions.EWhen;
+import org.simantics.scl.compiler.elaboration.expressions.Expression;
+import org.simantics.scl.compiler.elaboration.expressions.ExpressionTransformer;
+import org.simantics.scl.compiler.elaboration.expressions.GuardedExpression;
+import org.simantics.scl.compiler.elaboration.expressions.GuardedExpressionGroup;
+import org.simantics.scl.compiler.elaboration.expressions.QueryTransformer;
 import org.simantics.scl.compiler.elaboration.expressions.accessor.ExpressionAccessor;
 import org.simantics.scl.compiler.elaboration.expressions.block.BindStatement;
 import org.simantics.scl.compiler.elaboration.expressions.block.CHRStatement;
@@ -1,4 +1,4 @@
-package org.simantics.scl.compiler.elaboration.expressions;
+package org.simantics.scl.compiler.elaboration.expressions.visitors;
 
 import org.simantics.scl.compiler.elaboration.chr.CHRLiteral;
 import org.simantics.scl.compiler.elaboration.chr.CHRQuery;
@@ -15,7 +15,57 @@ import org.simantics.scl.compiler.elaboration.equation.EqBasic;
 import org.simantics.scl.compiler.elaboration.equation.EqGuard;
 import org.simantics.scl.compiler.elaboration.equation.Equation;
 import org.simantics.scl.compiler.elaboration.equation.EquationVisitor;
+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;
+import org.simantics.scl.compiler.elaboration.expressions.EBinary;
+import org.simantics.scl.compiler.elaboration.expressions.EBinaryRightSide;
+import org.simantics.scl.compiler.elaboration.expressions.EBind;
+import org.simantics.scl.compiler.elaboration.expressions.EBlock;
+import org.simantics.scl.compiler.elaboration.expressions.ECHRRuleset;
+import org.simantics.scl.compiler.elaboration.expressions.ECHRRulesetConstructor;
+import org.simantics.scl.compiler.elaboration.expressions.ECHRSelect;
+import org.simantics.scl.compiler.elaboration.expressions.EConstant;
+import org.simantics.scl.compiler.elaboration.expressions.ECoveringBranchPoint;
+import org.simantics.scl.compiler.elaboration.expressions.EEnforce;
+import org.simantics.scl.compiler.elaboration.expressions.EEquations;
+import org.simantics.scl.compiler.elaboration.expressions.EError;
+import org.simantics.scl.compiler.elaboration.expressions.EExternalConstant;
+import org.simantics.scl.compiler.elaboration.expressions.EFieldAccess;
+import org.simantics.scl.compiler.elaboration.expressions.EGetConstraint;
+import org.simantics.scl.compiler.elaboration.expressions.EIf;
+import org.simantics.scl.compiler.elaboration.expressions.EIntegerLiteral;
+import org.simantics.scl.compiler.elaboration.expressions.ELambda;
+import org.simantics.scl.compiler.elaboration.expressions.ELambdaType;
+import org.simantics.scl.compiler.elaboration.expressions.ELet;
+import org.simantics.scl.compiler.elaboration.expressions.EListComprehension;
+import org.simantics.scl.compiler.elaboration.expressions.EListLiteral;
+import org.simantics.scl.compiler.elaboration.expressions.ELiteral;
+import org.simantics.scl.compiler.elaboration.expressions.EMatch;
+import org.simantics.scl.compiler.elaboration.expressions.EPlaceholder;
+import org.simantics.scl.compiler.elaboration.expressions.EPreLet;
+import org.simantics.scl.compiler.elaboration.expressions.ERange;
+import org.simantics.scl.compiler.elaboration.expressions.ERealLiteral;
+import org.simantics.scl.compiler.elaboration.expressions.ERecord;
+import org.simantics.scl.compiler.elaboration.expressions.ERuleset;
 import org.simantics.scl.compiler.elaboration.expressions.ERuleset.DatalogRule;
+import org.simantics.scl.compiler.elaboration.expressions.ESelect;
+import org.simantics.scl.compiler.elaboration.expressions.ESimpleLambda;
+import org.simantics.scl.compiler.elaboration.expressions.ESimpleLet;
+import org.simantics.scl.compiler.elaboration.expressions.EStringLiteral;
+import org.simantics.scl.compiler.elaboration.expressions.ETransformation;
+import org.simantics.scl.compiler.elaboration.expressions.ETypeAnnotation;
+import org.simantics.scl.compiler.elaboration.expressions.EVar;
+import org.simantics.scl.compiler.elaboration.expressions.EVariable;
+import org.simantics.scl.compiler.elaboration.expressions.EViewPattern;
+import org.simantics.scl.compiler.elaboration.expressions.EWhen;
+import org.simantics.scl.compiler.elaboration.expressions.Expression;
+import org.simantics.scl.compiler.elaboration.expressions.ExpressionVisitor;
+import org.simantics.scl.compiler.elaboration.expressions.GuardedExpression;
+import org.simantics.scl.compiler.elaboration.expressions.GuardedExpressionGroup;
 import org.simantics.scl.compiler.elaboration.expressions.accessor.ExpressionAccessor;
 import org.simantics.scl.compiler.elaboration.expressions.accessor.FieldAccessorVisitor;
 import org.simantics.scl.compiler.elaboration.expressions.accessor.IdAccessor;
@@ -372,17 +422,24 @@ EquationVisitor, StatementVisitor, CHRAstQueryVisitor {
             equation.accept(this);
     }
     
+    public void visit(CHRLiteral literal) {
+        for(Expression parameter : literal.parameters)
+            parameter.accept(this);
+    }
+    
     public void visit(CHRQuery query) {
         for(CHRLiteral literal : query.literals)
-            for(Expression parameter : literal.parameters)
-                parameter.accept(this);
+            visit(literal);
+    }
+    
+    public void visit(CHRRule rule) {
+        visit(rule.head);
+        visit(rule.body);
     }
     
     public void visit(CHRRuleset ruleset) {
-        for(CHRRule rule : ruleset.rules) {
-            visit(rule.head);
-            visit(rule.body);
-        }
+        for(CHRRule rule : ruleset.rules)
+            visit(rule);
         for(IncludeStatement include : ruleset.includes)
             include.value.accept(this);
     }
index 459711a8d20bd00f8d9d3ca36bb385acac260d75..e711d372cf9a490d29461fd5f02e8ada68d6ca1d 100644 (file)
@@ -13,7 +13,6 @@ import org.simantics.scl.compiler.elaboration.query.pre.QPreGuard;
 import org.simantics.scl.compiler.errors.Locations;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public abstract class QAbstractCombiner extends Query {
@@ -22,11 +21,6 @@ public abstract class QAbstractCombiner extends Query {
     public QAbstractCombiner(Query[] queries) {
         this.queries = queries;
     }
-
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        for(Query query : queries)
-            query.collectFreeVariables(vars);
-    }
     
     @Override
     public Query resolve(TranslationContext context) {
index 421bf833ecc0513cf47b352216b1772d91845a1e..234c8b615a97b0f91076388e0579d9e3a903ec6d 100644 (file)
@@ -6,7 +6,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Variable;
 import org.simantics.scl.compiler.errors.Locations;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public abstract class QAbstractModifier extends Query {
@@ -15,10 +14,6 @@ public abstract class QAbstractModifier extends Query {
     public QAbstractModifier(Query query) {
         this.query = query;
     }
-
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        query.collectFreeVariables(vars);
-    }
     
     @Override
     public Query resolve(TranslationContext context) {
index c988aed56d82acfc5c1862ff8f806116fb118f12..208513b21bff747d28700e4d2ac2b58a37cffa66 100644 (file)
@@ -28,7 +28,6 @@ import org.simantics.scl.compiler.types.Types;
 import gnu.trove.map.hash.THashMap;
 import gnu.trove.map.hash.TIntObjectHashMap;
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class QAtom extends Query {
@@ -47,12 +46,6 @@ public class QAtom extends Query {
         this.parameters = parameters;
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        for(Expression parameter : parameters)
-            parameter.collectFreeVariables(vars);
-    }
-
     @Override
     public void checkType(TypingContext context) {
         // Type parameters
index 293c8bf707ba55142a9bbfc28ed9d899a69e1e87..2f9c0c50705a7e0baf21cd367612a299ed499da9 100644 (file)
@@ -17,10 +17,9 @@ import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.kinds.Kinds;
 
 import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
 
 public class QExists extends QAbstractModifier {
-    Variable[] variables;
+    public Variable[] variables;
     
     public QExists(Variable[] variables, Query query) {
         super(query);
@@ -31,13 +30,6 @@ public class QExists extends QAbstractModifier {
         this(variables.toArray(new Variable[variables.size()]), query);
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        super.collectFreeVariables(vars);
-        for(Variable variable : variables)
-            vars.remove(variable);
-    }
-
     @Override
     public void checkType(TypingContext context) {
         for(Variable var : variables)
index d148339a46946132187f04a1ed9433056ff3401a..85950c24a9b2d65b597a2c1b69347c79f3134d46 100644 (file)
@@ -11,7 +11,6 @@ import org.simantics.scl.compiler.errors.Locations;
 import org.simantics.scl.compiler.types.Types;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class QIf extends Query {
@@ -25,13 +24,6 @@ public class QIf extends Query {
         this.elseQuery = elseQuery;
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        condition.collectFreeVariables(vars);
-        thenQuery.collectFreeVariables(vars);
-        elseQuery.collectFreeVariables(vars);
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
         condition.collectVars(allVars, vars);
index 08d72563ece32a40f1c6256286305c496166d37b..428ed922cdf17d4611efe656375ec06e08c42c62 100644 (file)
@@ -13,7 +13,6 @@ 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;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class QMapping extends Query {
@@ -25,12 +24,6 @@ public class QMapping extends Query {
         this.parameters = parameters;
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        for(Expression parameter : parameters)
-            parameter.collectFreeVariables(vars);
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index 7b610756a6eb9dc65f2c7a1e94ff7314af61adee..cea31bbe8d1ccbcf8d41bb6fbaf0ad2671f8a197 100644 (file)
@@ -10,12 +10,12 @@ import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
 import org.simantics.scl.compiler.elaboration.expressions.EError;
 import org.simantics.scl.compiler.elaboration.expressions.Expression;
 import org.simantics.scl.compiler.elaboration.expressions.QueryTransformer;
-import org.simantics.scl.compiler.elaboration.expressions.StandardExpressionVisitor;
 import org.simantics.scl.compiler.elaboration.expressions.Variable;
 import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure;
 import org.simantics.scl.compiler.elaboration.expressions.printing.ExpressionToStringVisitor;
 import org.simantics.scl.compiler.elaboration.expressions.visitors.CollectRefsVisitor;
 import org.simantics.scl.compiler.elaboration.expressions.visitors.ForVariablesUsesVisitor;
+import org.simantics.scl.compiler.elaboration.expressions.visitors.StandardExpressionVisitor;
 import org.simantics.scl.compiler.elaboration.query.compilation.ConstraintCollectionContext;
 import org.simantics.scl.compiler.elaboration.query.compilation.DerivateException;
 import org.simantics.scl.compiler.elaboration.query.compilation.DynamicProgrammingOrdering;
@@ -31,13 +31,11 @@ import org.simantics.scl.compiler.internal.parsing.Symbol;
 import gnu.trove.map.hash.THashMap;
 import gnu.trove.map.hash.TIntObjectHashMap;
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public abstract class Query extends Symbol {
     public static final Query[] EMPTY_ARRAY = new Query[0];
     
-    public abstract void collectFreeVariables(THashSet<Variable> vars);
     public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
     public abstract void checkType(TypingContext context);
     
index 859690ec816265ce327596859246a4404a260a8d..b7b9f964bec4dd70320903f103722804791c3834 100644 (file)
@@ -6,7 +6,6 @@ import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
 import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
 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.elaboration.query.QConjunction;
 import org.simantics.scl.compiler.elaboration.query.QExists;
 import org.simantics.scl.compiler.elaboration.query.Query;
@@ -14,7 +13,6 @@ import org.simantics.scl.compiler.elaboration.query.QueryVisitor;
 import org.simantics.scl.compiler.elaboration.query.compilation.ConstraintCollectionContext;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 /**
@@ -24,11 +22,6 @@ public abstract class PreQuery extends Query {
 
     public ArrayList<Variable> extraVariables = new ArrayList<Variable>(2);
     public ArrayList<Query> sideQueries = new ArrayList<Query>(2);
-        
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectFreeVariables.");
-    }
     
     @Override
     public void checkType(TypingContext context) {
index 6f3ff3be93150e8685e05495f1104173dfd865f6..eed6d85552c62cf63f4b2028d84fd5990597b0dc 100644 (file)
@@ -46,7 +46,6 @@ import org.simantics.scl.compiler.elaboration.expressions.EWhen;
 import org.simantics.scl.compiler.elaboration.expressions.Expression;
 import org.simantics.scl.compiler.elaboration.expressions.GuardedExpression;
 import org.simantics.scl.compiler.elaboration.expressions.GuardedExpressionGroup;
-import org.simantics.scl.compiler.elaboration.expressions.StandardExpressionTransformer;
 import org.simantics.scl.compiler.elaboration.expressions.block.BindStatement;
 import org.simantics.scl.compiler.elaboration.expressions.block.GuardStatement;
 import org.simantics.scl.compiler.elaboration.expressions.block.LetStatement;
@@ -57,6 +56,7 @@ import org.simantics.scl.compiler.elaboration.expressions.list.ListGuard;
 import org.simantics.scl.compiler.elaboration.expressions.list.ListQualifier;
 import org.simantics.scl.compiler.elaboration.expressions.list.ListSeq;
 import org.simantics.scl.compiler.elaboration.expressions.list.ListThen;
+import org.simantics.scl.compiler.elaboration.expressions.visitors.StandardExpressionTransformer;
 import org.simantics.scl.compiler.elaboration.query.QAlternative;
 import org.simantics.scl.compiler.elaboration.query.QAtom;
 import org.simantics.scl.compiler.elaboration.query.QConjunction;
index da4ce4febc22363f8ba3dd02d5b6a54893433d97..491d88e41b95ef6d3f254ae7472d9e54d9134fda 100644 (file)
@@ -16,8 +16,8 @@ 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.expressions.visitors.StandardExpressionTransformer;
 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
 import org.simantics.scl.compiler.environment.Environment;
 import org.simantics.scl.compiler.errors.ErrorLog;