]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRuleset.java
(refs #7375) Fixed implementation of collectEffects
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / chr / CHRRuleset.java
index 13eb8491b529bdeb2943d6b15eb996195d4014ff..55bbcfe34f9c245968083ab39e374b9814fc8908 100644 (file)
@@ -23,7 +23,6 @@ import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
 import org.simantics.scl.compiler.elaboration.expressions.Variable;
-import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure;
 import org.simantics.scl.compiler.elaboration.expressions.block.IncludeStatement;
 import org.simantics.scl.compiler.environment.AmbiguousNameException;
 import org.simantics.scl.compiler.errors.Locations;
@@ -43,7 +42,6 @@ import org.simantics.scl.compiler.types.Types;
 
 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 CHRRuleset extends Symbol {
@@ -123,13 +121,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);
@@ -144,20 +135,6 @@ public class CHRRuleset extends Symbol {
             rule.collectVars(allVars, vars);
     }
 
-    public void forVariables(VariableProcedure procedure) {
-        for(IncludeStatement include : includes)
-            include.value.forVariables(procedure);
-        for(CHRRule rule : rules)
-            rule.forVariables(procedure);
-    }
-
-    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;
@@ -263,7 +240,7 @@ public class CHRRuleset extends Symbol {
     
     public IVal generateCode(CodeWriter w) {
         for(IncludeStatement include : includes) {
-            include.storeVar = include.value.toVal(cachedContext.environment, w);
+            include.storeVar = include.value.toVal(cachedContext, w);
             initialPriorityNumber = Math.max(initialPriorityNumber, include.ruleset.initialPriorityNumber + include.ruleset.priorityCount);
         }
         CHRRulesetObject object = new CHRRulesetObject(runtimeRulesetVariable, this);
@@ -283,7 +260,7 @@ public class CHRRuleset extends Symbol {
                     methodWriter.return_(BooleanConstant.TRUE);
             }
         }
-        if(!includes.isEmpty()) {
+        if(!includes.isEmpty() || extensible) {
             {
                 CodeWriter methodWriter = object.createMethod(w.getModuleWriter(), TVar.EMPTY_ARRAY, Types.PROC, Types.UNIT, new Type[] {Types.CHRContext});
                 initializer = methodWriter.getFunction();
@@ -292,6 +269,10 @@ public class CHRRuleset extends Symbol {
                             new JavaMethod(true, runtimeRulesetClassName, "register", Types.PROC, Types.UNIT, new Type[] {runtimeRulesetType, Types.CHRContext, include.ruleset.runtimeRulesetType}),
                             object.getTarget(), methodWriter.getParameters()[0], include.storeVar);
                 }
+                if(extensible)
+                       methodWriter.apply(Locations.NO_LOCATION,
+                               new JavaMethod(true, runtimeRulesetClassName, "register", Types.PROC, Types.UNIT, new Type[] {runtimeRulesetType, Types.CHRContext}),
+                               object.getTarget(), methodWriter.getParameters()[0]);
                 methodWriter.return_(NoRepConstant.UNIT);
             }
             {
@@ -302,6 +283,10 @@ public class CHRRuleset extends Symbol {
                             new JavaMethod(true, runtimeRulesetClassName, "unregister", Types.PROC, Types.UNIT, new Type[] {runtimeRulesetType, Types.CHRContext, include.ruleset.runtimeRulesetType}),
                             object.getTarget(), methodWriter.getParameters()[0], include.storeVar);
                 }
+                if(extensible)
+                       methodWriter.apply(Locations.NO_LOCATION,
+                               new JavaMethod(true, runtimeRulesetClassName, "unregister", Types.PROC, Types.UNIT, new Type[] {runtimeRulesetType, Types.CHRContext}),
+                               object.getTarget(), methodWriter.getParameters()[0]);
                 methodWriter.return_(NoRepConstant.UNIT);
             }
         }
@@ -324,15 +309,6 @@ public class CHRRuleset extends Symbol {
         return runtimeRulesetVariable;
     }
 
-    public void collectEffects(THashSet<Type> effects) {
-        for(CHRRule rule : rules) {
-            for(CHRLiteral literal : rule.head.literals)
-                literal.collectQueryEffects(effects);
-            for(CHRLiteral literal : rule.head.literals)
-                literal.collectEnforceEffects(effects);
-        }
-    }
-
     public void addRule(CHRRule rule) {
         rules.add(rule);
         rule.parentRuleset = this;