public class DumpTree
extends java.lang.Object
AST
to stdout
or to
a user-defined output stream.
Each node prints the symbolic text name of the token type rather than the integer representation. The token text, line and column number information for the AST will also be rendered.
Modifier and Type | Field and Description |
---|---|
private static boolean |
DEFAULT_DUMP_ANNOTATIONS
Default value for dump annotations information.
|
private boolean |
dumpAnnotations
Debug aid to dump annotations information.
|
private java.io.PrintStream |
out
The destination of all dumped output.
|
private static int |
TAB_SIZE
The size of indentation in spaces.
|
Constructor and Description |
---|
DumpTree()
Default constructor which uses
stdout . |
DumpTree(java.io.PrintStream out)
Constructs an instance and allows control over the output destination.
|
Modifier and Type | Method and Description |
---|---|
private void |
printIndent(int tabs)
Prints a 3 space indent for every additional nested level in the tree.
|
void |
setDumpAnnotations(boolean dumpAnnotations)
Enable/disable the output of annotations for each visited node.
|
void |
setOutputStream(java.io.PrintStream out)
Allows the current output stream to be switched for a user-defined
stream.
|
void |
visit(Aast node)
Prints out a text-based representation of an
Aast and
all children. |
private static final boolean DEFAULT_DUMP_ANNOTATIONS
private static final int TAB_SIZE
private java.io.PrintStream out
private boolean dumpAnnotations
public DumpTree()
stdout
.public DumpTree(java.io.PrintStream out)
null
it will be set to System.out
.out
- The new stream to use as the output destination.public void setOutputStream(java.io.PrintStream out)
null
, System.out
will
be used. The caller must close this stream when done!out
- The new stream to use as the output destination.private void printIndent(int tabs)
tabs
- The numbers of TAB to print.public void visit(Aast node)
Aast
and
all children. This method relies upon the fact that all tree nodes
represent a full tree themselves, even if they have no children. An
iterator is obtained that allows a simple depth-first, left-right
walk of the tree in a single loop.node
- The root of the tree or subtree which should be printed.public void setDumpAnnotations(boolean dumpAnnotations)
dumpAnnotations
- if true
then the annotations for each node will be printed in the output
stream