X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FResult.java;h=6054fa150065eacf1cc81f47965485e85b51057d;hb=fcc038ff693cf2b3e91efcd348ea3a3b7fbb1829;hp=9db5aeeb1abbfd7df1d9627195b3f2d5bad93ba3;hpb=954c6edf9a45f16463c4afc2a2f1abe940c6b184;p=sbp.git diff --git a/src/edu/berkeley/sbp/Result.java b/src/edu/berkeley/sbp/Result.java index 9db5aee..6054fa1 100644 --- a/src/edu/berkeley/sbp/Result.java +++ b/src/edu/berkeley/sbp/Result.java @@ -1,22 +1,20 @@ -// Copyright 2006 all rights reserved; see LICENSE file for BSD-style license +// Copyright 2006-2007 all rights reserved; see LICENSE file for BSD-style license package edu.berkeley.sbp; import edu.berkeley.sbp.util.*; -import edu.berkeley.sbp.Sequence.Position; +import edu.berkeley.sbp.Sequence.Pos; +import edu.berkeley.sbp.Sequence.Pos; import java.util.*; final class Result implements GraphViz.ToGraphViz { private Forest f; private Node parent; - private GSS.Phase phase; - private Position reduction; private HashSet children = new HashSet(); private boolean destroyed = false; private int usedByNonDoomedNode = 0; - public Position reduction() { return reduction; } - public GSS.Phase phase() { return phase; } + public GSS.Phase phase() { return parent==null ? null : parent.phase(); } public Forest getForest() { return f; } public Node parent() { return parent; } public void addChild(Node child) { @@ -24,8 +22,10 @@ final class Result implements GraphViz.ToGraphViz { usedByNonDoomedNode += child.state().doomed ? 0 : 1; } public void removeChild(Node child) { + if (!children.contains(child)) return; children.remove(child); usedByNonDoomedNode -= child.state().doomed ? 0 : 1; + check(); } public boolean usedByAnyNode() { return children.size() > 0; } @@ -38,27 +38,25 @@ final class Result implements GraphViz.ToGraphViz { if (destroyed) return; if (parent==null) return; // never destroy the "primordeal" result destroyed = true; - if (parent() != null) { - parent().removeChild(this); - parent().check(); - } - OUTER: while(true) { + parent.removeChild(this); + while(children.size() > 0) for(Node n : children) { - children.remove(n); + removeChild(n); n.removeResult(this); - n.check(); - continue OUTER; + break; } - break; - } } - public Result(Forest f, Node parent, Position reduction) { + public Result(Forest f, Node parent, Pos reduction) { + this(f, parent, reduction, null); + } + public Result(Forest f, Node parent, Pos reduction, GSS.Phase target) { this.f = f; - this.reduction = reduction; this.parent = parent; if (parent != null) parent.addChild(this); - if (parent != null) phase = parent.phase(); + if (reduction == null) return; + Parser.Table.State state0 = (Parser.Table.State)parent.state().gotoSetNonTerminals.get(reduction); + target.newNodeFromReduction(this, state0, reduction); } // GraphViz //////////////////////////////////////////////////////////////////////////////