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.
|