keep track of which reduction created each result (if any)
authoradam <adam@megacz.com>
Sun, 9 Sep 2007 04:16:09 +0000 (00:16 -0400)
committeradam <adam@megacz.com>
Sun, 9 Sep 2007 04:16:09 +0000 (00:16 -0400)
darcs-hash:20070909041609-5007d-4c8a8cd7c6c8db708a41cc38b974b354f7234be2.gz

src/edu/berkeley/sbp/Node.java
src/edu/berkeley/sbp/Reduction.java
src/edu/berkeley/sbp/Result.java

index ccc2516..740d8a6 100644 (file)
@@ -74,7 +74,7 @@ final class Node
         if (r.numPops()!=0)  reduce(r, r.numPops()-1, phase(), only);
         else {
             Input.Region region = phase().getLocation().createRegion(phase().getLocation());
-            new Result(r.rewrite(region), this, r, phase());
+            Result.newResult(r.rewrite(region), this, r, phase());
         }
     }
 
@@ -95,13 +95,13 @@ final class Node
         holder[pos] = old;
     }
 
-    Node(GSS.Phase phase, Result result, State state, boolean fromEmptyReduction) {
+    Node(GSS.Phase phase, Result pred, State state, boolean fromEmptyReduction) {
         this.phase = phase;
         this.state = state;
         this.fromEmptyReduction = fromEmptyReduction;
-        if (phase.hash.get(state, result.phase()) != null) throw new Error("severe problem!");
-        phase.hash.put(state, result.phase(), this);
-        addResult(result);
+        if (phase.hash.get(state, pred.phase()) != null) throw new Error("severe problem!");
+        phase.hash.put(state, pred.phase(), this);
+        addResult(pred);
         state.invokeEpsilonReductions(phase().token, this);
     }
 
index 5eb3f63..4ef2013 100644 (file)
@@ -40,7 +40,9 @@ final class Reduction implements Comparable<Reduction> {
         return 1;
     }
 
-    public void perform() { new Result(forest, pred, reduction, phase); }
+    public void perform() {
+        Result.newResult(forest, pred, reduction, phase);
+    }
     public GSS.Phase predPhase() { return pred.phase(); }
     public Pos reduction() { return reduction; }
     public GSS.Phase targetPhase() { return phase; }
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 //////////////////////////////////////////////////////////////////////////////