1 // Copyright 2006 all rights reserved; see LICENSE file for BSD-style license
3 package edu.berkeley.sbp;
4 import edu.berkeley.sbp.*;
5 import edu.berkeley.sbp.util.*;
6 import edu.berkeley.sbp.Parser.Table.*;
7 import edu.berkeley.sbp.Sequence.Position;
10 import java.lang.reflect.*;
12 final class Result implements GraphViz.ToGraphViz {
16 private GSS.Phase phase;
17 private Position reduction;
18 private HashSet<Node> children = new HashSet<Node>();
19 private boolean destroyed = false;
21 public Position reduction() { return reduction; }
22 public GSS.Phase phase() { return phase; }
23 public Forest getForest() { return f; }
24 public Node parent() { return parent; }
25 public void addChild(Node child) { children.add(child); }
26 public void removeChild(Node child) { children.remove(child); }
28 public boolean usedByAnyNode() { return children.size() > 0; }
29 public boolean usedByNonDoomedNode() {
30 for(Node n : children)
31 if (!n.state().doomed)
36 public String toString() { return super.toString()+"->"+parent(); }
38 public void check() { if (children.size()==0) destroy(); }
39 public void destroy() {
40 if (destroyed) return;
41 if (parent==null) return; // never destroy the "primordeal" result
43 if (parent() != null) {
44 parent().removeChild(this);
48 for(Node n : children) {
58 public Result(Forest f, Node parent, Position reduction) {
60 this.reduction = reduction;
62 if (parent != null) parent.addChild(this);
63 if (parent != null) phase = parent.phase();
66 // GraphViz //////////////////////////////////////////////////////////////////////////////
68 public GraphViz.Node toGraphViz(GraphViz gv) {
69 if (gv.hasNode(this)) return gv.createNode(this);
70 GraphViz.Node n = gv.createNode(this);
72 n.shape = "rectangle";
73 if (parent()!=null) n.edge(parent, "");
76 ((GraphViz.Group)phase().toGraphViz(gv)).add(n);
79 public boolean isTransparent() { return false; }
80 public boolean isHidden() { return false; }