From 8cf79c4b9e5a26ef65bd4af600946b45dbf28a8a Mon Sep 17 00:00:00 2001 From: adam Date: Sun, 9 Sep 2007 00:16:09 -0400 Subject: [PATCH] keep track of which reduction created each result (if any) darcs-hash:20070909041609-5007d-4c8a8cd7c6c8db708a41cc38b974b354f7234be2.gz --- src/edu/berkeley/sbp/Node.java | 10 +++++----- src/edu/berkeley/sbp/Reduction.java | 4 +++- src/edu/berkeley/sbp/Result.java | 14 ++++++++------ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/edu/berkeley/sbp/Node.java b/src/edu/berkeley/sbp/Node.java index ccc2516..740d8a6 100644 --- a/src/edu/berkeley/sbp/Node.java +++ b/src/edu/berkeley/sbp/Node.java @@ -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); } diff --git a/src/edu/berkeley/sbp/Reduction.java b/src/edu/berkeley/sbp/Reduction.java index 5eb3f63..4ef2013 100644 --- a/src/edu/berkeley/sbp/Reduction.java +++ b/src/edu/berkeley/sbp/Reduction.java @@ -40,7 +40,9 @@ final class Reduction implements Comparable { 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; } diff --git a/src/edu/berkeley/sbp/Result.java b/src/edu/berkeley/sbp/Result.java index efaad4c..97f467f 100644 --- a/src/edu/berkeley/sbp/Result.java +++ b/src/edu/berkeley/sbp/Result.java @@ -13,6 +13,7 @@ final class Result implements GraphViz.ToGraphViz { private HashSet successors = new HashSet(); 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 ////////////////////////////////////////////////////////////////////////////// -- 1.7.10.4