]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRule.java
(refs #7250) Refactoring CHR implementation
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / chr / CHRRule.java
index 48aefbdac541459f783c7becb5d013bd488d6a9b..9846ebd4807db5342ace21ceec9027b41ba4c5f5 100644 (file)
@@ -1,8 +1,9 @@
 package org.simantics.scl.compiler.elaboration.chr;
 
+import java.util.ArrayList;
+
 import org.simantics.scl.compiler.compilation.CompilationContext;
-import org.simantics.scl.compiler.elaboration.chr.plan.PlanOp;
-import org.simantics.scl.compiler.elaboration.chr.plan.PrioritizedPlan;
+import org.simantics.scl.compiler.elaboration.chr.plan.CHRSearchPlan;
 import org.simantics.scl.compiler.elaboration.chr.planning.QueryPlanningContext;
 import org.simantics.scl.compiler.elaboration.chr.relations.CHRConstraint;
 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
@@ -31,6 +32,12 @@ public class CHRRule extends Symbol {
     public int firstPriorityExecuted;
     public int lastPriorityExecuted;
     
+    // Plans
+    public ArrayList<CHRSearchPlan> plans = new ArrayList<CHRSearchPlan>();
+    
+    // Code generation, move to CHRPriority
+    public String containerClassName;
+    
     public CHRRule(long location, CHRQuery head, CHRQuery body, Variable[] existentialVariables) {
         this.location = location;
         this.head = head;
@@ -98,7 +105,7 @@ public class CHRRule extends Symbol {
             if(!head.createQueryPlan(context, new EVariable(activeFact), i))
                 return;
             body.createEnforcePlan(context, priority);
-            constraint.plans.add(new PrioritizedPlan(priority, activeFact, context.getPlanOps()));
+            addPlan(new CHRSearchPlan(constraint, activeFact, context.getPlanOps()));
             
             hasActiveLiteral = true;
         }
@@ -111,10 +118,15 @@ public class CHRRule extends Symbol {
             /*System.out.println(this);
             for(PlanOp planOp : context.getPlanOps())
                 System.out.println("    " + planOp);*/
-            initConstraint.plans.add(new PrioritizedPlan(priority, activeFact, context.getPlanOps()));
+            addPlan(new CHRSearchPlan(initConstraint, activeFact, context.getPlanOps()));
         }
     }
     
+    private void addPlan(CHRSearchPlan plan) {
+        plans.add(plan);
+        plan.constraint.minimumPriority = Math.min(plan.constraint.minimumPriority, priority);
+    }
+
     public String toString() {
         StringBuilder b = new StringBuilder();
         ExpressionToStringVisitor visitor = new ExpressionToStringVisitor(b);