(refs #7375) Replace collectRefs by CollectRefsVisitor 51/751/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Mon, 24 Jul 2017 08:15:12 +0000 (11:15 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Mon, 24 Jul 2017 08:15:12 +0000 (11:15 +0300)
Change-Id: I77bf548a062bb365f43284778845678fb50341d5

63 files changed:
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/TypeChecking.java
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/ECHRRuleset.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRulesetConstructor.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRSelect.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEnforce.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEquations.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EError.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EExternalConstant.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EFieldAccess.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EGetConstraint.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIf.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIntegerLiteral.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambda.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambdaType.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELet.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListComprehension.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListLiteral.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELiteral.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EMatch.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERealLiteral.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERuleset.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESelect.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLambda.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLet.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETransformation.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETypeAnnotation.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EVariable.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EViewPattern.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EWhen.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Expression.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/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/accessor/FieldAccessor.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/CollectRefsVisitor.java [new file with mode: 0644]
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/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

index 58bb98a417e0d9255e77310c74d5f6feb6c8430a..52b8692d8f9fcc72394af1bbd0b059399367f077 100644 (file)
@@ -408,7 +408,7 @@ public class TypeChecking {
                 for(TransformationRule rule : module.getRules())
                     for(Query[] queries : rule.sections.values())
                         for(Query query : queries)
-                            query.collectRefs(allRefs, refs);                
+                            query.collectRefs(allRefs, refs);
             }
             
             @Override
index e8bb00a6e1b7a7a66dca38f7e7e3a28bf8a9cb77..2697ea08fe287bc36c441e39c8ba738316346ba1 100644 (file)
@@ -112,14 +112,6 @@ public class CHRLiteral extends Symbol {
         }
     }
 
-    public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        for(Expression parameter : parameters)
-            parameter.collectRefs(allRefs, refs);
-        if(typeConstraintEvidenceParameters != null)
-            for(Expression parameter : typeConstraintEvidenceParameters)
-                parameter.collectRefs(allRefs, refs);
-    }
-
     public void checkType(TypingContext context) {
         if(relation == SpecialCHRRelation.EXECUTE) {
             if(parameters.length != 1)
index 777dc9f6c4b8847ed24c15e64f6c7336020aff32..8bba6697d9bb3832782ee20ab4dd5af493219ab1 100644 (file)
@@ -31,11 +31,6 @@ public class CHRQuery extends Symbol {
             literal.resolve(context);
     }
 
-    public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        for(CHRLiteral literal : literals)
-            literal.collectRefs(allRefs, refs);
-    }
-
     public void checkType(TypingContext context) {
         for(CHRLiteral literal : literals)
             literal.checkType(context);
index 31d0ec48c1e185700fcfb393a465490511277be9..67b30b221c78f2e992791f27563df094d8091a8c 100644 (file)
@@ -57,11 +57,6 @@ public class CHRRule extends Symbol {
         existentialVariables = context.popExistentialFrame();
     }
 
-    public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        head.collectRefs(allRefs, refs);
-        body.collectRefs(allRefs, refs);
-    }
-
     public void checkType(TypingContext context) {
         for(Variable variable : existentialVariables)
             variable.setType(Types.metaVar(Kinds.STAR));
index 9eca12aa9b32e57be811635db7fee9e76460128d..805e781e74a6eff0f2876ea43df82b86443395ca 100644 (file)
@@ -122,13 +122,6 @@ public class CHRRuleset extends Symbol {
         }*/
     }
 
-    public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        for(IncludeStatement include : includes)
-            include.value.collectRefs(allRefs, refs);
-        for(CHRRule rule : rules)
-            rule.collectRefs(allRefs, refs);
-    }
-
     public void checkType(TypingContext context) {
         for(IncludeStatement include : includes)
             include.value = include.value.checkType(context, include.ruleset.runtimeRulesetType);
index 67608de2d89bbe25dd6d180393ae7d6f4c162ae1..08b1a07267bc5ecebc910b0cebad30398766cccc 100644 (file)
@@ -53,12 +53,6 @@ public class EqBasic extends Equation {
         right = right.checkType(context, left.getType());
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        left.collectRefs(allRefs, refs);
-        right.collectRefs(allRefs, refs);
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
         left.collectVars(allVars, vars);
index 2e434b461296433feeaf3e00af7e58870caaaab7..5dac9fce44b452e9239ecdfd5a0fbf6d4b2c809e 100644 (file)
@@ -48,11 +48,6 @@ public class EqGuard extends Equation {
         guard = guard.checkIgnoredType(context);
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        guard.collectRefs(allRefs, refs);
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
         guard.collectVars(allVars, vars);
index dcf11a3e6ec3aef54726f14aef1eec2da2e36efb..ca4102c96b6588d50b946432417a3281ea0217f6 100644 (file)
@@ -4,7 +4,6 @@ import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
 import org.simantics.scl.compiler.elaboration.expressions.Variable;
-import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure;
 import org.simantics.scl.compiler.internal.parsing.Symbol;
 import org.simantics.scl.compiler.types.Type;
 
@@ -20,7 +19,6 @@ public abstract class Equation extends Symbol {
     public abstract void collectFreeVariables(THashSet<Variable> vars);
     public abstract void collectEffects(THashSet<Type> effects);
     public abstract void checkType(TypingContext context);
-    public abstract void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs);
     public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
     public abstract void resolve(TranslationContext context);
     public abstract void accept(EquationVisitor visitor);
index 4a65459b864d615493b6141540610beb26c18efe..fa54f8ab28e3acf80b3044375b38c4d35b1d7dc1 100644 (file)
@@ -25,12 +25,6 @@ public abstract class ASTExpression extends SimplifiableExpression {
         throw new InternalCompilerError(getClass().getSimpleName() + " does not support collectFreeVariables.");
     }
     
-    @Override
-    final public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        throw new InternalCompilerError(getClass().getSimpleName() + " does not support collectRefs.");
-    }
-    
     @Override
     final public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index 54be27b3cc2de0e0d23170ecc0567d8498acf10f..c8f0eb893e15f7f58e5a6751b2435b05944b53c2 100644 (file)
@@ -35,10 +35,6 @@ public class Case extends Symbol {
         return lhs;
     }
 
-       public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        value.collectRefs(allRefs, refs);
-    }
-
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
         value.collectVars(allVars, vars);
index 9b6c2645cd95e1fb0fd6e5265ee655e1214248b8..796a41c69c421103430da9c1fa32ff6989f09000 100644 (file)
@@ -26,11 +26,6 @@ public abstract class DecoratingExpression extends SimplifiableExpression {
         super(loc);
         this.expression = expression;
     }
-
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        expression.collectRefs(allRefs, refs);
-    }
     
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
index 73c4fa3a0b88877209185020de6e52b0c5c59dcb..2b5c813a13db19dc6591d193353763c2f6c15e97 100644 (file)
@@ -42,11 +42,6 @@ public class EAmbiguous extends SimplifiableExpression {
         this.activeCount = alternatives.length;
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index 375039e0b6ec76173e300bc0e000175b1d7e395e..4065f463ac4d8436a60a74b81e7e5a8cc4871fcd 100644 (file)
@@ -76,13 +76,6 @@ public class EApply extends Expression {
         return parameters;
     }
     
-
-    public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        function.collectRefs(allRefs, refs);
-        for(Expression parameter : parameters)
-            parameter.collectRefs(allRefs, refs);
-    }
-    
     public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
         function.collectVars(allVars, vars);
         for(Expression parameter : parameters)
index cd54a44d6b30531fa803442bcf87bb8322200f84..f441a1be5880254123eb7be77a1e116a31decbae 100644 (file)
@@ -50,21 +50,17 @@ public class EApplyType extends Expression {
         return parameter;
     }
 
-       public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        expression.collectRefs(allRefs, refs);
+    public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
+        expression.collectVars(allVars, vars);
     }
-       
-       public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
-           expression.collectVars(allVars, vars);
-       }
 
-       @Override
-       protected void updateType() throws MatchException {
-           setType(Types.instantiate(expression.getType(), parameter));
-       }
-       
-       @Override
-       public IVal toVal(CompilationContext context, CodeWriter w) {
+    @Override
+    protected void updateType() throws MatchException {
+        setType(Types.instantiate(expression.getType(), parameter));
+    }
+
+    @Override
+    public IVal toVal(CompilationContext context, CodeWriter w) {
         IVal val = expression.toVal(context, w);
         return val.createSpecialization(parameter);
     }
index 1a4a5bbd04c3e2c8091a8f01c4b4d2063edc647c..98c54844c037661b6fe34ab7f12f07567cfd61de 100644 (file)
@@ -40,12 +40,6 @@ public class EAsPattern extends Expression {
         return pattern;
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        pattern.collectRefs(allRefs, refs);
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index b4d824caaaa8d9d02d22c51173e01781dc42110e..3bec2aaa13ecafde91be4380559df456779b6953 100644 (file)
@@ -43,12 +43,6 @@ public class EBind extends SimplifiableExpression {
         this.value = value;
         this.in = in;
     }
-
-    @Override
-    public void collectRefs(final TObjectIntHashMap<Object> allRefs, final TIntHashSet refs) {
-        value.collectRefs(allRefs, refs);
-        in.collectRefs(allRefs, refs);
-    }
     
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
index d23b2e4cee3b19710a8bf1d855c3144c153fa295..a8ad1480d1be35af8115d493629e3f93724b8db5 100644 (file)
@@ -26,30 +26,29 @@ public class ECHRRuleset extends Expression {
         this.in = in;
     }
     
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        ruleset.collectRefs(allRefs, refs);
-        in.collectRefs(allRefs, refs);
-    }
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
         ruleset.collectVars(allVars, vars);
         in.collectVars(allVars, vars);
     }
+
     @Override
     protected void updateType() throws MatchException {
         setType(in.getType());
     }
+
     @Override
     public IVal toVal(CompilationContext context, CodeWriter w) {
         ruleset.generateCode(w);
         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 25ae61345d77f5e7c085591d6a414699e58d1068..734fd71b439f20a5c43d9cd1aec54a4968d82202 100644 (file)
@@ -24,27 +24,27 @@ public class ECHRRulesetConstructor extends Expression {
     public ECHRRulesetConstructor(CHRRuleset ruleset) {
         this.ruleset = ruleset;
     }
-    
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        ruleset.collectRefs(allRefs, refs);
-    }
+
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
         ruleset.collectVars(allVars, vars);
     }
+
     @Override
     protected void updateType() throws MatchException {
         throw new InternalCompilerError("Type of ECHRRulesetConstructor should be already given.");
     }
+
     @Override
     public IVal toVal(CompilationContext context, CodeWriter w) {
         return ruleset.generateCode(w);
     }
+
     @Override
     public void collectFreeVariables(THashSet<Variable> vars) {
         ruleset.collectFreeVariables(vars);
     }
+
     @Override
     public Expression resolve(TranslationContext context) {
         context.pushFrame();
index 6b4a7fe8625e99d120221c113428b6e5ae14062a..fbaff1200124dfd88ffe71b815af1d8b691bf44f 100644 (file)
@@ -38,12 +38,6 @@ public class ECHRSelect extends Expression {
         this.query = query;
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        query.collectRefs(allRefs, refs);
-        expression.collectRefs(allRefs, refs);
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
         query.collectVars(allVars, vars);
index 037144a4c63d20f15157410640c1e1a313ddea8d..4a2e07f431cd9410889c2275980aaf70819dc55f 100644 (file)
@@ -35,7 +35,7 @@ import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class EConstant extends Expression {
-    SCLValue value;
+    public SCLValue value;
     Type[] typeParameters;
     
     public EConstant(SCLValue value, Type ... typeParameters) {
@@ -83,23 +83,17 @@ public class EConstant extends Expression {
         return this;
     }
 
-       public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        int id = allRefs.get(value);
-        if(id >= 0)
-            refs.add(id);
+    @Override
+    public void collectVars(TObjectIntHashMap<Variable> allVars,
+            TIntHashSet vars) {   
     }
-       
-       @Override
-       public void collectVars(TObjectIntHashMap<Variable> allVars,
-               TIntHashSet vars) {   
-       }
 
-       public void toString(StringBuilder b, TypeUnparsingContext tuc) {
-           Name name = value.getName();
-           if(name.module.equals("Builtin") || name.module.equals("Prelude"))
-               b.append(name.name);
-           else
-               b.append(name);
+    public void toString(StringBuilder b, TypeUnparsingContext tuc) {
+        Name name = value.getName();
+        if(name.module.equals("Builtin") || name.module.equals("Prelude"))
+            b.append(name.name);
+        else
+            b.append(name);
         /*for(Type type : typeParameters) {
             b.append(" <");
             b.append(type.toString(tuc));
index 49d010bceef46bff083648434ab92d6483e69ae1..bfaf699ed4c81081c32281ae5b12eeeb2e57fe62 100644 (file)
@@ -29,12 +29,6 @@ public class EEnforce extends SimplifiableExpression {
         return query;
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        query.collectRefs(allRefs, refs);
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index dd1a7e415d1adecef3d59aae92cd1242fa50b186..bffb7f026e6116264babd76540ba0303410b3cbc 100644 (file)
@@ -49,12 +49,6 @@ public class EEquations extends SimplifiableExpression {
         return transformer.transform(this);
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        for(Equation equation : equations)
-            equation.collectRefs(allRefs, refs);        
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
         for(Equation equation : equations)
index c7ea89b30678c8d15037241108028c509fdbe4de..b3f4f648897b7a4c1469722606ab6d0c545b3091 100644 (file)
@@ -24,28 +24,25 @@ public class EError extends Expression {
         setType(type);
     }
     
-    public EError() {     
+    public EError() {
     }
     
     public EError(long loc) {
         this(loc, Types.metaVar(Kinds.STAR));
     }
 
-       public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+    @Override
+    public void collectVars(TObjectIntHashMap<Variable> allVars,
+            TIntHashSet vars) {
     }
-       
-       @Override
-       public void collectVars(TObjectIntHashMap<Variable> allVars,
-               TIntHashSet vars) {    
-       }
 
-       @Override
-       protected void updateType() throws MatchException {
-           setType(Types.metaVar(Kinds.STAR));     
-       }
-       
-       @Override
-       public IVal toVal(CompilationContext context, CodeWriter w) {
+    @Override
+    protected void updateType() throws MatchException {
+        setType(Types.metaVar(Kinds.STAR));
+    }
+
+    @Override
+    public IVal toVal(CompilationContext context, CodeWriter w) {
         throw new UnsupportedOperationException();
     }
 
index 611e96d368ea3fa33c939b18d575fa5b061b3c6c..0b5678f99eb15a9995e23ca7f5c6c82cd0493690 100644 (file)
@@ -35,27 +35,24 @@ public class EExternalConstant extends Expression {
         return value;
     }
 
-       public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+    @Override
+    public void collectVars(TObjectIntHashMap<Variable> allVars,
+            TIntHashSet vars) {            
     }
 
-       @Override
-       public void collectVars(TObjectIntHashMap<Variable> allVars,
-               TIntHashSet vars) {         
-       }
-       
-       public void toString(StringBuilder b, TypeUnparsingContext tuc) {
+    public void toString(StringBuilder b, TypeUnparsingContext tuc) {
         b.append(value);
     }
 
-       @Override
-       protected void updateType() throws MatchException {
-           throw new InternalCompilerError("EExternalConstants must have explicitly defined type.");
-       }
-       
-       @Override
-       public IVal toVal(CompilationContext context, CodeWriter w) {
-               ModuleWriter mw = w.getModuleWriter();
-               return mw.getExternalConstant(value, getType());
+    @Override
+    protected void updateType() throws MatchException {
+        throw new InternalCompilerError("EExternalConstants must have explicitly defined type.");
+    }
+
+    @Override
+    public IVal toVal(CompilationContext context, CodeWriter w) {
+        ModuleWriter mw = w.getModuleWriter();
+        return mw.getExternalConstant(value, getType());
     }
 
     @Override
index 0bc8a431788d530b0aed43e5f91070014d966fec..0a4d0ee165186b404055f7c540c7cfa057135bb0 100644 (file)
@@ -35,13 +35,6 @@ public class EFieldAccess extends SimplifiableExpression {
                ((EFieldAccess)parent).lastAccessor = false;
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        parent.collectRefs(allRefs, refs);
-        accessor.collectRefs(allRefs, refs);
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index 5f9a1eb59adbe1002189f376dd19092d3b8199b5..8534f462409fc2b131e1059774fe3ee8300d0e75 100644 (file)
@@ -20,11 +20,6 @@ public class EGetConstraint extends SimplifiableExpression {
         super(loc);
         this.constraint = constraint;
     }
-
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-    }
     
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
index 418ba69c9cda9c2e3b1c352daedc02176e8b1570..ea64ac034c152e120f6472902233a246e1fcb5cf 100644 (file)
@@ -39,29 +39,22 @@ public class EIf extends Expression {
         this.else_ = else_;
     }
 
-       public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        condition.collectRefs(allRefs, refs);
-        then_.collectRefs(allRefs, refs);
-        if(else_ != null)
-            else_.collectRefs(allRefs, refs);
-    }
-
-       @Override
-       public void collectVars(TObjectIntHashMap<Variable> allVars,
-               TIntHashSet vars) {
-           condition.collectVars(allVars, vars);
+    @Override
+    public void collectVars(TObjectIntHashMap<Variable> allVars,
+            TIntHashSet vars) {
+        condition.collectVars(allVars, vars);
         then_.collectVars(allVars, vars);
         if(else_ != null)
             else_.collectVars(allVars, vars);
-       }
+    }
 
-       @Override
-       protected void updateType() throws MatchException {
-           setType(then_.getType());
-       }
-       
-       @Override
-       public IVal toVal(CompilationContext context, CodeWriter w) {
+    @Override
+    protected void updateType() throws MatchException {
+        setType(then_.getType());
+    }
+
+    @Override
+    public IVal toVal(CompilationContext context, CodeWriter w) {
         IVal conditionVal = condition.toVal(context, w); 
         CodeWriter joinPoint = w.createBlock(getType());
         CodeWriter thenBlock = w.createBlock();
index 0b5d1a16dd8ec64671c22750480277fe792b0872..856dcd37123e20cb745af694063e06a421b8cd7c 100644 (file)
@@ -28,11 +28,6 @@ public class EIntegerLiteral extends SimplifiableExpression {
         this.value = value;
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index 5138ec596290fe0f32e524e4e36f09cfe8a8f7ad..51b1f909e34624e164cb528ec9680d35854132ab 100644 (file)
@@ -37,20 +37,15 @@ public class ELambda extends SimplifiableExpression {
         this(loc, new Case(new Expression[] {pat}, exp));
     }
 
-       public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+    @Override
+    public void collectVars(TObjectIntHashMap<Variable> allVars,
+            TIntHashSet vars) {
         for(Case case_ : cases)
-            case_.collectRefs(allRefs, refs);
-    }
-       
-       @Override
-       public void collectVars(TObjectIntHashMap<Variable> allVars,
-               TIntHashSet vars) {
-           for(Case case_ : cases)
             case_.collectVars(allVars, vars);
-       }
+    }
 
-       public Expression decomposeMatching() {
-           Expression[] patterns = cases[0].patterns;
+    public Expression decomposeMatching() {
+        Expression[] patterns = cases[0].patterns;
         int arity = patterns.length;
         
         // Simple cases
index d413b8c35ecd4d9767ed1f649d636ca36dfdb174..b06f7b77035079d04c92a80e6469bd89e4b40806 100644 (file)
@@ -30,22 +30,18 @@ public class ELambdaType extends Expression {
         this.value = value;
     }
 
-       public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        value.collectRefs(allRefs, refs);
+    @Override
+    public void collectVars(TObjectIntHashMap<Variable> allVars,
+            TIntHashSet vars) {
+        value.collectVars(allVars, vars);
     }
-       
-       @Override
-       public void collectVars(TObjectIntHashMap<Variable> allVars,
-               TIntHashSet vars) {
-           value.collectVars(allVars, vars);
-       }
-       
-       @Override
-       protected void updateType() throws MatchException {
-           setType(Types.forAll(parameters, value.getType()));
-       }
 
-       @Override
+    @Override
+    protected void updateType() throws MatchException {
+        setType(Types.forAll(parameters, value.getType()));
+    }
+
+    @Override
     public IVal toVal(CompilationContext context, CodeWriter w) {
         return lambdaToVal(context, w);
     }
index 5bde43500f6d7c3ab2c07b41c9d61bbf316de801..7b7338a78e2f07efe17b4731a80b709c7635aa35 100644 (file)
@@ -36,13 +36,6 @@ public class ELet extends Expression {
         this.assignments = assignments;
         this.in = in;
     }
-
-    @Override
-    public void collectRefs(final TObjectIntHashMap<Object> allRefs, final TIntHashSet refs) {
-        for(Assignment assign : assignments)
-            assign.value.collectRefs(allRefs, refs);
-        in.collectRefs(allRefs, refs);
-    }
     
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
index fa21346f1202528560cf5878dd39b9e5945a3d76..a06100dd719f925e4c44abfb058b19c10d19b4c8 100644 (file)
@@ -31,13 +31,6 @@ public class EListComprehension extends SimplifiableExpression {
         this.qualifier = qualifier;
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        head.collectRefs(allRefs, refs);
-        qualifier.collectRefs(allRefs, refs);
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index 5c2a0d9d4c07e5f4e1a51f08bee1f95703f8bfe6..d2a1d3509b65ace91caf56e25e3b47a8bd5473ac 100644 (file)
@@ -36,13 +36,6 @@ public class EListLiteral extends SimplifiableExpression {
     public Expression[] getComponents() {
         return components;
     }
-    
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        for(Expression component : components)
-            component.collectRefs(allRefs, refs);
-    }
 
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
index d2a671a1d96cdd1a3a60b451061acd897b42d067..14bd02344e4d52e56b009adc9bd8cacd1b7535f8 100644 (file)
@@ -39,25 +39,22 @@ public class ELiteral extends Expression {
         return value;
     }
 
-       public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+    @Override
+    public void collectVars(TObjectIntHashMap<Variable> allVars,
+            TIntHashSet vars) {            
     }
 
-       @Override
-       public void collectVars(TObjectIntHashMap<Variable> allVars,
-               TIntHashSet vars) {         
-       }
-       
-       public void toString(StringBuilder b, TypeUnparsingContext tuc) {
+    public void toString(StringBuilder b, TypeUnparsingContext tuc) {
         b.append(value);
     }
-       
-       @Override
-       protected void updateType() throws MatchException {
-           setType(value.getType());       
-       }
 
-       @Override
-       public IVal toVal(CompilationContext context, CodeWriter w) {
+    @Override
+    protected void updateType() throws MatchException {
+        setType(value.getType());          
+    }
+
+    @Override
+    public IVal toVal(CompilationContext context, CodeWriter w) {
         return value;
     }
 
index 4ad8135c43803367f9584fe3e3158a45f92d106a..0ca1d54427d13a636ca11eca672ea330dd688cef 100644 (file)
@@ -41,43 +41,36 @@ public class EMatch extends Expression {
         this.cases = cases;
     }
 
-       public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+    @Override
+    public void collectVars(TObjectIntHashMap<Variable> allVars,
+            TIntHashSet vars) {
         for(Expression s : scrutinee)
-            s.collectRefs(allRefs, refs);
-        for(Case case_ : cases)
-            case_.collectRefs(allRefs, refs);
-    }
-       
-       @Override
-       public void collectVars(TObjectIntHashMap<Variable> allVars,
-               TIntHashSet vars) {
-           for(Expression s : scrutinee)
             s.collectVars(allVars, vars);
-           for(Case case_ : cases)
+        for(Case case_ : cases)
             case_.collectVars(allVars, vars);
-       }
-       
-       @Override
-       protected void updateType() {
-           setType(cases[0].value.getType());
-       }
+    }
+
+    @Override
+    protected void updateType() {
+        setType(cases[0].value.getType());
+    }
+
+    @Override
+    public IVal toVal(CompilationContext context, CodeWriter w) {
+        ArrayList<Row> rows = new ArrayList<Row>(cases.length);
+        for(Case case_ : cases)
+            rows.add(new Row(case_.patterns, case_.value));
+
+        IVal[] scrutineeVals = new IVal[scrutinee.length];
+        for(int i=0;i<scrutinee.length;++i)
+            scrutineeVals[i] = scrutinee[i].toVal(context, w);
 
-       @Override
-       public IVal toVal(CompilationContext context, CodeWriter w) {
-           ArrayList<Row> rows = new ArrayList<Row>(cases.length);
-           for(Case case_ : cases)
-               rows.add(new Row(case_.patterns, case_.value));
-           
-           IVal[] scrutineeVals = new IVal[scrutinee.length];
-           for(int i=0;i<scrutinee.length;++i)
-               scrutineeVals[i] = scrutinee[i].toVal(context, w);
-           
-           CodeWriter joinPoint = w.createBlock(getType());
-           CodeWriter failurePoint = w.createBlock(); // TODO generate only one failurePoint per function
-           PatternMatchingCompiler.split(w, context, scrutineeVals, joinPoint.getContinuation(), failurePoint.getContinuation(), rows);
-           failurePoint.throw_(location, Throw.MatchingException, "Matching failure at: " + toString());
-           w.continueAs(joinPoint);
-           return w.getParameters()[0];
+        CodeWriter joinPoint = w.createBlock(getType());
+        CodeWriter failurePoint = w.createBlock(); // TODO generate only one failurePoint per function
+        PatternMatchingCompiler.split(w, context, scrutineeVals, joinPoint.getContinuation(), failurePoint.getContinuation(), rows);
+        failurePoint.throw_(location, Throw.MatchingException, "Matching failure at: " + toString());
+        w.continueAs(joinPoint);
+        return w.getParameters()[0];
     }
 
     @Override
index 9468342bb899bbb870521ffb73100faaac4617c9..5f274dadde72c9cee3dc0f0aad471efe39ad5808 100644 (file)
@@ -27,11 +27,6 @@ public class ERealLiteral extends SimplifiableExpression {
         this.value = value;
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index 41d43dd067987bcc6a33c74ebaf870c0324b0e98..1a133b6f9dc61e7b0ee283c4e8ed77614d15939a 100644 (file)
@@ -141,18 +141,7 @@ public class ERuleset extends SimplifiableExpression {
         }
         in.collectFreeVariables(vars);
     }
-    
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        for(DatalogRule rule : rules) {
-            for(Expression parameter : rule.headParameters)
-                parameter.collectRefs(allRefs, refs);
-            rule.body.collectRefs(allRefs, refs);
-        }
-        in.collectRefs(allRefs, refs);
-    }
-    
+
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
@@ -163,7 +152,7 @@ public class ERuleset extends SimplifiableExpression {
         }
         in.collectVars(allVars, vars);
     }
-    
+
     @Override
     public void collectEffects(THashSet<Type> effects) {
         throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectEffects.");
index 42fdc6f106536465ad0350fbbd66c794392074ee..ce4d66bd7567e268f395d12835a23a9258a906fa 100644 (file)
@@ -45,13 +45,6 @@ public class ESelect extends SimplifiableExpression {
         this.query = query;
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        expression.collectRefs(allRefs, refs);
-        query.collectRefs(allRefs, refs);
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index 0038dbf384c759541b8e6e29ce56a53750384b71..8f59b3b4429c77f22d94a0482fba310a190929ec 100644 (file)
@@ -55,17 +55,13 @@ public class ESimpleLambda extends Expression {
         this.effect = effect;
     }
 
-       public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        value.collectRefs(allRefs, refs);
+    @Override
+    public void collectVars(TObjectIntHashMap<Variable> allVars,
+            TIntHashSet vars) {
+        value.collectVars(allVars, vars);
     }
-       
-       @Override
-       public void collectVars(TObjectIntHashMap<Variable> allVars,
-               TIntHashSet vars) {
-           value.collectVars(allVars, vars);
-       }
 
-       public Expression decomposeMatching() {
+    public Expression decomposeMatching() {
         value = value.decomposeMatching();
         return this;
     }
index 1a084b3666283ae79e6fa5758e6fec82d047aceb..422bbea119f76aad1020317235258a1fd97ef4b7 100644 (file)
@@ -45,28 +45,23 @@ public class ESimpleLet extends Expression {
         this.in = in;
     }
 
-       public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        value.collectRefs(allRefs, refs);
-        in.collectRefs(allRefs, refs);
+    @Override
+    public void collectVars(TObjectIntHashMap<Variable> allVars,
+            TIntHashSet vars) {
+        value.collectVars(allVars, vars);
+        in.collectVars(allVars, vars);
     }
-       
-       @Override
-       public void collectVars(TObjectIntHashMap<Variable> allVars,
-               TIntHashSet vars) {
-           value.collectVars(allVars, vars);
-           in.collectVars(allVars, vars);
-       }
 
     @Override
     protected void updateType() throws MatchException {
         setType(in.getType());
     }
-    
-       @Override
-       public IVal toVal(CompilationContext context, CodeWriter w) {
-           IVal valueVal = value.toVal(context, w);
-           if(variable != null)
-               variable.setVal(valueVal);
+
+    @Override
+    public IVal toVal(CompilationContext context, CodeWriter w) {
+        IVal valueVal = value.toVal(context, w);
+        if(variable != null)
+            variable.setVal(valueVal);
         return in.toVal(context, w);
     }
 
index 3e8f61b036cf8f932895bfaca47879836835210d..346e46cd3cc9fe2d735c4a2ba70345962a76bd9f 100644 (file)
@@ -30,17 +30,6 @@ public class ETransformation extends SimplifiableExpression {
         this.seed = seed;
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        {
-            int ref = allRefs.get(TRANSFORMATION_RULES_TYPECHECKED);
-            if(ref >= 0)
-                refs.add(ref);
-        }
-        seed.collectRefs(allRefs, refs);
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index 6452812fc370f82989e662b643cb7675f85a65ac..10c8e6f7a47e4511bc177e4d3cfd29071a08cbfc 100644 (file)
@@ -28,20 +28,16 @@ public class ETypeAnnotation extends SimplifiableExpression {
         this.type = type;
     }
 
-       public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        value.collectRefs(allRefs, refs);
+    @Override
+    public void collectVars(TObjectIntHashMap<Variable> allVars,
+            TIntHashSet vars) {
+        value.collectVars(allVars, vars);
     }
-       
-       @Override
-       public void collectVars(TObjectIntHashMap<Variable> allVars,
-               TIntHashSet vars) {
-           value.collectVars(allVars, vars);
-       }
 
-       @Override
-       protected void updateType() throws MatchException {
-           setType(type);
-       }
+    @Override
+    protected void updateType() throws MatchException {
+        setType(type);
+    }
 
     @Override
     public void collectFreeVariables(THashSet<Variable> vars) {
index 669867ff6ca0e825f83c3906b50e3e63a652530f..44c03a2acdd8d8ef7279938c67322b81ff7132f7 100644 (file)
@@ -46,18 +46,15 @@ public class EVariable extends Expression {
         this.variable = variable;
     }
 
-       public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+    @Override
+    public void collectVars(TObjectIntHashMap<Variable> allVars,
+            TIntHashSet vars) {
+        int id = allVars.get(variable);
+        if(id >= 0)
+            vars.add(id);
     }
-       
-       @Override
-       public void collectVars(TObjectIntHashMap<Variable> allVars,
-               TIntHashSet vars) {
-           int id = allVars.get(variable);
-           if(id >= 0)
-               vars.add(id);
-       }
 
-       public void toString(StringBuilder b, TypeUnparsingContext tuc) {
+    public void toString(StringBuilder b, TypeUnparsingContext tuc) {
         b.append(variable == null ? "???" : variable.toString());
     }
 
index 2561e63b979fefef95900181133391600f8de844..a2a0a02c5bc04b90b715ede54a0d9be0ca7e6055 100644 (file)
@@ -26,12 +26,6 @@ public class EViewPattern extends Expression {
         this.pattern = pattern;
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        expression.collectRefs(allRefs, refs);
-        pattern.collectRefs(allRefs, refs);
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
         expression.collectVars(allVars, vars);
index 9cdb6eab222ae3f22d99f8932b073b552f33a255..a9fd0367bbcaee69ce36f415e0c41565b1a1c7e9 100644 (file)
@@ -43,13 +43,6 @@ public class EWhen extends SimplifiableExpression {
         this.variables = variables;
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        query.collectRefs(allRefs, refs);
-        action.collectRefs(allRefs, refs);
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index da3afdbfa08ea1df7ccef191f859790b1d34f0d9..221bc8067ac454a479b88d33c5a7d72d65f9b84f 100644 (file)
@@ -14,6 +14,7 @@ import org.simantics.scl.compiler.elaboration.errors.NotPatternException;
 import org.simantics.scl.compiler.elaboration.expressions.lhstype.LhsType;
 import org.simantics.scl.compiler.elaboration.expressions.lhstype.PatternMatchingLhs;
 import org.simantics.scl.compiler.elaboration.expressions.printing.ExpressionToStringVisitor;
+import org.simantics.scl.compiler.elaboration.expressions.visitors.CollectRefsVisitor;
 import org.simantics.scl.compiler.elaboration.expressions.visitors.ForVariablesUsesVisitor;
 import org.simantics.scl.compiler.elaboration.query.QAtom;
 import org.simantics.scl.compiler.elaboration.relations.SCLRelation;
@@ -103,23 +104,23 @@ public abstract class Expression extends Symbol implements Typed {
             expression = new ESimpleLet(location, null, expression, new ELiteral(NoRepConstant.PUNIT));
         return expression;
     }
-       
-       /**
-        * Checks the type of the expression against the given type. Adds type
-        * applications and lambdas if needed.
-        */
-       public final Expression checkType(TypingContext context, Type requiredType) {
-           //System.out.println("checkType: " + this + " :: " + requiredType);
-           if(!context.isInPattern()) {
-               requiredType = Types.canonical(requiredType);
-           if(requiredType instanceof TForAll) {
+
+    /**
+     * Checks the type of the expression against the given type. Adds type
+     * applications and lambdas if needed.
+     */
+    public final Expression checkType(TypingContext context, Type requiredType) {
+        //System.out.println("checkType: " + this + " :: " + requiredType);
+        if(!context.isInPattern()) {
+            requiredType = Types.canonical(requiredType);
+            if(requiredType instanceof TForAll) {
                 TForAll forAll = (TForAll)requiredType;
                 TVar var = forAll.var;
                 TVar newVar = Types.var(var.getKind());
                 requiredType = Types.canonical(forAll.type).replace(var, newVar);
                 return new ELambdaType(new TVar[] {newVar}, checkType(context, requiredType));
             }
-           while(requiredType instanceof TFun) {
+            while(requiredType instanceof TFun) {
                 TFun fun = (TFun)requiredType;
                 if(fun.domain instanceof TPred) { // No need to canonicalize
                     ArrayList<Variable> constraints = new ArrayList<Variable>(2);
@@ -143,7 +144,7 @@ public abstract class Expression extends Symbol implements Typed {
                     context.pushEffectUpperBound(location, fun.effect);
                     Expression expr = checkType(context, fun.range);
                     context.popEffectUpperBound();       
-                    
+
                     // Wrap
                     Variable var = new Variable("punit", Types.PUNIT);
                     return new ESimpleLambda(location, var, fun.effect, expr);
@@ -151,14 +152,17 @@ public abstract class Expression extends Symbol implements Typed {
                 else
                     break;
             }
-           }
-           return checkBasicType(context, requiredType); 
-       }
+        }
+        return checkBasicType(context, requiredType); 
+    }
+
+    public final void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+        accept(new CollectRefsVisitor(allRefs, refs));
+    }
 
-       public abstract void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs);
-       public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
+    public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
 
-    public void forVariableUses(VariableProcedure procedure) {
+    public final void forVariableUses(VariableProcedure procedure) {
         accept(new ForVariablesUsesVisitor(procedure));
     }
 
index 07fbc50a6f8b5f578833003a5d59840308552ad0..1e2cd05c422791ffe3c73a7257b2d39c42759e1c 100644 (file)
@@ -25,16 +25,6 @@ public class GuardedExpressionGroup extends Expression {
         this.expressions = expressions;
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        for(GuardedExpression expression : expressions) {
-            for(Expression guard : expression.guards)
-                guard.collectRefs(allRefs, refs);
-            expression.value.collectRefs(allRefs, refs);
-        }
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index e4cdd0937f7027e0498f270d79a0126de5676488..12c9a917013ac1edca998fdec2372f1e9a36048e 100644 (file)
@@ -25,12 +25,6 @@ public class ExpressionAccessor extends FieldAccessor {
         fieldName.collectFreeVariables(vars);
     }
     
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        fieldName.collectRefs(allRefs, refs);
-    }
-    
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index aaf80610aaa9bd369dd36353adb48cac461e0ce6..21c892ce4697ce2d6e94947b9e83bbd16462e701 100644 (file)
@@ -18,10 +18,6 @@ public abstract class FieldAccessor extends Symbol {
         this.accessSeparator = accessSeparator;
     }
 
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-    }
-
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
     }
index a0073b889d62e6e23b50f1bd99176eb9d8006c2e..1283cc059b7124b4af7e3737437525c9f2ea8f30 100644 (file)
@@ -29,12 +29,6 @@ public class ListAssignment extends ListQualifier {
         pattern.checkTypeAsPattern(context, value.getType());
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        value.collectRefs(allRefs, refs);
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index c7f89ba7678e86fadec291186f7f3173d3978260..db12689c862b69d250bba2336a59c3a447eee49a 100644 (file)
@@ -33,12 +33,6 @@ public class ListGenerator extends ListQualifier {
         pattern.checkTypeAsPattern(context, componentType);
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        value.collectRefs(allRefs, refs);
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index c9e29ca5b9d8a7b8c2a759929860e49c2472f3bb..2fe49150f6473d581a29c839507ec3675e8e3320 100644 (file)
@@ -25,12 +25,6 @@ public class ListGuard extends ListQualifier {
         condition.checkType(context, Types.BOOLEAN);
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        condition.collectRefs(allRefs, refs);
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index 048b525f7edb1362474dc9a304aba08d260d8456..47c9cf6d8d9e384a9ab7032ce2e62632c554c663 100644 (file)
@@ -14,7 +14,6 @@ import gnu.trove.set.hash.TIntHashSet;
 public abstract class ListQualifier extends Symbol {
 
     public abstract void checkType(TypingContext context);
-    public abstract void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs);
     public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
     public abstract void collectFreeVariables(THashSet<Variable> vars);
     /**
index 5d633d8d01aaf5b47326600c94f24c66a612b72f..a802a80accbc1ea64cda833701aa1788ad427f63 100644 (file)
@@ -26,13 +26,6 @@ public class ListSeq extends ListQualifier {
         a.checkType(context);
         b.checkType(context);  
     }
-    
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        a.collectRefs(allRefs, refs);
-        b.collectRefs(allRefs, refs);
-    }
 
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
index 451493ba3f6764965c8ec1662b2c1a34059abe93..e1061564f767391b576c00e26a6329ba55246da5 100644 (file)
@@ -47,15 +47,6 @@ public class ListThen extends ListQualifier {
         }
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        left.collectRefs(allRefs, refs);
-        transformer.collectRefs(allRefs, refs);
-        if(by != null)
-            by.collectRefs(allRefs, refs);
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectRefsVisitor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectRefsVisitor.java
new file mode 100644 (file)
index 0000000..366dc51
--- /dev/null
@@ -0,0 +1,56 @@
+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;
+
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.set.hash.TIntHashSet;
+
+public class CollectRefsVisitor extends StandardExpressionVisitor {
+    private final TObjectIntHashMap<Object> allRefs;
+    private final TIntHashSet refs;
+    
+    public CollectRefsVisitor(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+        this.allRefs = allRefs;
+        this.refs = refs;
+    }
+    
+    @Override
+    public void visit(ETransformation expression) {
+        {
+            int ref = allRefs.get(ETransformation.TRANSFORMATION_RULES_TYPECHECKED);
+            if(ref >= 0)
+                refs.add(ref);
+        }
+        super.visit(expression);
+    }
+    
+    @Override
+    public void visit(EConstant expression) {
+        int id = allRefs.get(expression.value);
+        if(id >= 0)
+            refs.add(id);
+    }
+    
+    @Override
+    public void visit(QAtom query) {
+        collectRelationRefs(query.relation);
+        super.visit(query);
+    }
+    
+    private void collectRelationRefs(SCLRelation relation) {
+        if(relation instanceof CompositeRelation) {
+            for(SCLRelation subrelation : ((CompositeRelation) relation).getSubrelations())
+                collectRelationRefs(subrelation);
+        }
+        else {
+            int id = allRefs.get(relation);
+            if(id >= 0)
+                refs.add(id);
+        }
+    }
+}
index 52a59585f1b88b375b8db78f499f290937f7301e..459711a8d20bd00f8d9d3ca36bb385acac260d75 100644 (file)
@@ -74,12 +74,6 @@ public abstract class QAbstractCombiner extends Query {
             query.checkType(context);
     }
     
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        for(Query query : queries)
-            query.collectRefs(allRefs, refs);
-    }
-    
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
         for(Query query : queries)
index 2b6c6771135ba2ace7d009a153870d6bc21340ae..421bf833ecc0513cf47b352216b1772d91845a1e 100644 (file)
@@ -31,12 +31,6 @@ public abstract class QAbstractModifier extends Query {
         query.checkType(context);
     }
     
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        query.collectRefs(allRefs, refs);
-    }
-    
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index 7a20ae3c5f2df7f003392ac25d56afe4cfaf73eb..c988aed56d82acfc5c1862ff8f806116fb118f12 100644 (file)
@@ -147,27 +147,6 @@ public class QAtom extends Query {
         }
     }
 
-    private static void collectRefs(SCLRelation relation, TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        if(relation instanceof CompositeRelation) {
-            for(SCLRelation subrelation : ((CompositeRelation) relation).getSubrelations())
-                collectRefs(subrelation, allRefs, refs);
-        }
-        else {
-            int id = allRefs.get(relation);
-            if(id >= 0)
-                refs.add(id);
-        }
-    }
-
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        collectRefs(relation, allRefs, refs);
-        for(Expression parameter : parameters)
-            parameter.collectRefs(allRefs, refs);
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index 719f474b6b115d3d800d65c801cadb4f55ce8c9a..d148339a46946132187f04a1ed9433056ff3401a 100644 (file)
@@ -32,13 +32,6 @@ public class QIf extends Query {
         elseQuery.collectFreeVariables(vars);
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        condition.collectRefs(allRefs, refs);
-        thenQuery.collectRefs(allRefs, refs);
-        elseQuery.collectRefs(allRefs, refs);
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
         condition.collectVars(allVars, vars);
index 12da9da3b8ddc5dfe3d7073d08c053616c7fdc11..08d72563ece32a40f1c6256286305c496166d37b 100644 (file)
@@ -31,13 +31,6 @@ public class QMapping extends Query {
             parameter.collectFreeVariables(vars);
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        for(Expression parameter : parameters)
-            parameter.collectRefs(allRefs, refs);
-    }
-
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {
index 0b804caf356cada38c2d35d14e6a04158b646b10..7b610756a6eb9dc65f2c7a1e94ff7314af61adee 100644 (file)
@@ -14,6 +14,7 @@ import org.simantics.scl.compiler.elaboration.expressions.StandardExpressionVisi
 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.query.compilation.ConstraintCollectionContext;
 import org.simantics.scl.compiler.elaboration.query.compilation.DerivateException;
@@ -37,7 +38,6 @@ 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 collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs);
     public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
     public abstract void checkType(TypingContext context);
     
@@ -159,4 +159,7 @@ public abstract class Query extends Symbol {
     public void forVariables(VariableProcedure procedure) {
         accept(new ForVariablesUsesVisitor(procedure));
     }
+    public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+        accept(new CollectRefsVisitor(allRefs, refs));
+    }
 }
index dc398f85768ca6eaedc4c927ec63c720f3cf98f6..859690ec816265ce327596859246a4404a260a8d 100644 (file)
@@ -40,12 +40,6 @@ public abstract class PreQuery extends Query {
         throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectConstraints.");
     }
     
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectRefs.");
-    }
-    
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars,
             TIntHashSet vars) {