public final class DotFormatter
extends java.lang.Object
DotFormatter prints out a dot file of the Abstract Syntax Tree. For a detailed description of the dot format and visualization tool refer to Graphviz.
Typical usage of this class
System.out.println(new DotFormatter().toDot(node));
This class is not thread safe and should not be used without proper external synchronization.
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
ARROW |
private java.util.HashMap<Node,java.lang.Integer> |
assignments |
private java.lang.Appendable |
builder |
private ControlFlowGraph<Node> |
cfg |
private static java.lang.String |
INDENT |
private int |
keyCount |
private static java.lang.String |
LINE |
private boolean |
printAnnotations |
Modifier | Constructor and Description |
---|---|
private |
DotFormatter()
For Testing Only
|
private |
DotFormatter(Node n,
ControlFlowGraph<Node> cfg,
java.lang.Appendable builder,
boolean printAnnotations) |
Modifier and Type | Method and Description |
---|---|
(package private) static void |
appendDot(Node n,
ControlFlowGraph<Node> inCFG,
java.lang.Appendable builder)
Converts an AST to dot representation and appends it to the given buffer.
|
private void |
formatConclusion() |
private static java.lang.String |
formatNodeName(java.lang.Integer key) |
private void |
formatPreamble() |
(package private) int |
key(Node n) |
private static java.lang.String |
name(Node n) |
(package private) static DotFormatter |
newInstanceForTesting()
Creates a DotFormatter purely for testing DotFormatter's internal methods.
|
static java.lang.String |
toDot(GraphvizGraph graph)
Outputs a string in DOT format that presents the graph.
|
static java.lang.String |
toDot(Node n)
Converts an AST to dot representation.
|
(package private) static java.lang.String |
toDot(Node n,
ControlFlowGraph<Node> inCFG)
Converts an AST to dot representation.
|
private void |
traverseNodes(Node parent) |
private static final java.lang.String INDENT
private static final java.lang.String ARROW
private static final java.lang.String LINE
private final java.util.HashMap<Node,java.lang.Integer> assignments
private int keyCount
private final java.lang.Appendable builder
private final ControlFlowGraph<Node> cfg
private final boolean printAnnotations
private DotFormatter()
private DotFormatter(Node n, ControlFlowGraph<Node> cfg, java.lang.Appendable builder, boolean printAnnotations) throws java.io.IOException
java.io.IOException
public static java.lang.String toDot(Node n) throws java.io.IOException
n
- the root of the AST described in the dot formatted stringjava.io.IOException
static java.lang.String toDot(Node n, ControlFlowGraph<Node> inCFG) throws java.io.IOException
n
- the root of the AST described in the dot formatted stringinCFG
- Control Flow Graph.java.io.IOException
static void appendDot(Node n, ControlFlowGraph<Node> inCFG, java.lang.Appendable builder) throws java.io.IOException
n
- the root of the AST described in the dot formatted stringinCFG
- Control Flow Graph.builder
- A place to dump the graph.java.io.IOException
static DotFormatter newInstanceForTesting()
private void traverseNodes(Node parent) throws java.io.IOException
java.io.IOException
int key(Node n) throws java.io.IOException
java.io.IOException
private static java.lang.String name(Node n)
private static java.lang.String formatNodeName(java.lang.Integer key)
private void formatPreamble() throws java.io.IOException
java.io.IOException
private void formatConclusion() throws java.io.IOException
java.io.IOException
public static java.lang.String toDot(GraphvizGraph graph)
graph
- Input graph.