keep track of which reduction created each result (if any)
[sbp.git] / src / edu / berkeley / sbp / Result.java
index efaad4c..97f467f 100644 (file)
@@ -13,6 +13,7 @@ final class Result implements GraphViz.ToGraphViz {
     private HashSet<Node> successors = new HashSet<Node>();
     private boolean destroyed = false;
     private int usedByNonDoomedNode = 0;
+    private Pos reduction;
 
     public GSS.Phase phase() { return pred==null ? null : pred.phase(); }
     public Forest getForest() { return f; }
@@ -47,16 +48,17 @@ final class Result implements GraphViz.ToGraphViz {
             }
     }
 
-    public Result(Forest f, Node pred, Pos reduction) {
-        this(f, pred, reduction, null);
+    public static void newResult(Forest f, Node pred, Pos reduction, GSS.Phase target) {
+        Result r = new Result(f, pred, reduction);
+        if (reduction == null) return;
+        Parser.Table.State state0 = (Parser.Table.State)pred.state().gotoSetNonTerminals.get(reduction);
+        target.newNodeFromReduction(r, state0, reduction);
     }
-    public Result(Forest f, Node pred, Pos reduction, GSS.Phase target) {
+    public Result(Forest f, Node pred, Pos reduction) {
         this.f = f;
         this.pred = pred;
+        this.reduction = reduction;
         if (pred != null) pred.addSucc(this);
-        if (reduction == null) return;
-        Parser.Table.State state0 = (Parser.Table.State)pred.state().gotoSetNonTerminals.get(reduction);
-        target.newNodeFromReduction(this, state0, reduction);
     }
 
     // GraphViz //////////////////////////////////////////////////////////////////////////////