make Result implement GraphViz.ToGraphViz
[sbp.git] / src / edu / berkeley / sbp / Result.java
1 // Copyright 2006 all rights reserved; see LICENSE file for BSD-style license
2
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;
8 import java.io.*;
9 import java.util.*;
10 import java.lang.reflect.*;
11
12 class Result implements GraphViz.ToGraphViz {
13
14     private Forest f;
15     private Node parent;
16     private GSS.Phase phase;
17     private Position reduction;
18
19     public Position reduction() { return reduction; }
20     public GSS.Phase phase() { return phase; }
21     public Forest getForest() { return f; }
22     public Node parent() { return parent; }
23
24     public Result(Forest f, Node parent, Position reduction) {
25         this.f = f;
26         this.reduction = reduction;
27         this.parent = parent;
28         if (parent != null) phase = parent.phase();
29     }
30
31     // GraphViz //////////////////////////////////////////////////////////////////////////////
32
33     public GraphViz.Node toGraphViz(GraphViz gv) {
34         if (gv.hasNode(this)) return gv.createNode(this);
35         GraphViz.Node n = gv.createNode(this);
36         n.label = ""+f;
37         n.shape = "rectangle";
38         if (parent()!=null) n.edge(parent, "");
39         n.color = "blue";
40         if (phase() != null)
41             ((GraphViz.Group)phase().toGraphViz(gv)).add(n);
42         return n;
43     }
44     public boolean isTransparent() { return false; }
45     public boolean isHidden() { return false; }
46
47 }