xtc.tree |
xtc's support for abstract syntax trees and for traversing them with
visitors. This package defines the {@link xtc.tree.Node base class}
for all abstract syntax tree nodes and the {@link xtc.tree.Visitor
base class} for all visitors. It also defines a {@link xtc.tree.GNode
generic node class}.
In contrast to the original visitor pattern, node visitors do not
implement a fixed interface. Rather, the appropriate method is
selected through reflection-based dynamic dispatch, based on the type
of a node. On invocation of {@link xtc.tree.Visitor#dispatch}, the
dynamic dispatch mechanism tries to find a method
name visit() that takes either the specified node, any of
its interfaces, or any of its superclaseses as its only argument. The
search starts with the class of the node, then checks for all
implemented interfaces, then for the superclass, then for all
interfaces of the superclass, and so on until it
reaches java.lang.Object , which is not considered.
For {@link xtc.tree.GNode generic nodes} the appropriate
visit() method is selected based on the name of the
generic node. For example, if the target name is Node, then
the dynamic dispatch mechanism tries to locate a method
visitNode(GNode) . If no such method exists, the dynamic
dispatch mechanism also tries to locate a visit(GNode)
and visit(Node) method (in that order).
Note that to improve the performance of dynamic dispatch, our
implementation uses a static method lookup cache that is not
thread-safe. Source-to-source transformers thus cannot be
multi-threaded.
|
Java Source File Name | Type | Comment |
Annotation.java | Class | The superclass of all annotations. |
Attribute.java | Class | A name/value pair. |
Comment.java | Class | A source code comment. |
Formatting.java | Class | An annotation capturing source code formatting. |
GNode.java | Class | A generic node in an abstract syntax tree.
A note on memory conservation: Generic nodes created through
the
GNode.create(String) or
GNode.create(String,int) methods
can have a variable number of children. |
LineMarker.java | Class | A line marker (as used by GCC). |
LineupPrinter.java | Class | A printer that guarantees that each Node is printed at the exact
file, line, and column specified by its location. |
Locatable.java | Interface | The interface to objects with a source location. |
Location.java | Class | The location in a source file. |
Node.java | Class | A node in an abstract syntax tree or DAG. |
ParseTreePrinter.java | Class | Visitor to print parse trees. |
ParseTreeStripper.java | Class | Visitor to strip parse trees. |
Pragma.java | Class | A pragma. |
Printer.java | Class | A node pretty printing utility. |
Relocator.java | Class | Visitor to relocate an abstract syntax tree. |
SourceIdentity.java | Class | A source identity marker. |
Token.java | Class | A token. |
Transducer.java | Class | Visitor to convert trees of generic nodes into methods that
programmatically create the trees. |
TraversalException.java | Class | The superclass of exceptions signaled during visitor dispatch. |
Utility.java | Class | The superclass of all utilities. |
VisitingException.java | Class | A visiting exception is thrown to indicate an exceptional condition
while visiting a node. |
Visitor.java | Class | A node visitor. |
VisitorException.java | Class | A visitor exception is thrown when no appropriate
visit() or process() method can be found. |