| 1 | <html> |
| 2 | <body> |
| 3 | |
| 4 | xtc's support for abstract syntax trees and for traversing them with |
| 5 | visitors. This package defines the {@link xtc.tree.Node base class} |
| 6 | for all abstract syntax tree nodes and the {@link xtc.tree.Visitor |
| 7 | base class} for all visitors. It also defines a {@link xtc.tree.GNode |
| 8 | generic node class}. |
| 9 | |
| 10 | <p />In contrast to the original visitor pattern, node visitors do not |
| 11 | implement a fixed interface. Rather, the appropriate method is |
| 12 | selected through reflection-based dynamic dispatch, based on the type |
| 13 | of a node. On invocation of {@link xtc.tree.Visitor#dispatch}, the |
| 14 | dynamic dispatch mechanism tries to find a method |
| 15 | name <code>visit()</code> that takes either the specified node, any of |
| 16 | its interfaces, or any of its superclaseses as its only argument. The |
| 17 | search starts with the class of the node, then checks for all |
| 18 | implemented interfaces, then for the superclass, then for all |
| 19 | interfaces of the superclass, and so on until it |
| 20 | reaches <code>java.lang.Object</code>, which is <i>not</i> considered. |
| 21 | |
| 22 | <p />For {@link xtc.tree.GNode generic nodes} the appropriate |
| 23 | <code>visit()</code> method is selected based on the name of the |
| 24 | generic node. For example, if the target name is <i>Node</i>, then |
| 25 | the dynamic dispatch mechanism tries to locate a method |
| 26 | <code>visitNode(GNode)</code>. If no such method exists, the dynamic |
| 27 | dispatch mechanism also tries to locate a <code>visit(GNode)</code> |
| 28 | and <code>visit(Node)</code> method (in that order). |
| 29 | |
| 30 | <p />Note that to improve the performance of dynamic dispatch, our |
| 31 | implementation uses a static method lookup cache that is <i>not</i> |
| 32 | thread-safe. Source-to-source transformers thus cannot be |
| 33 | multi-threaded. |
| 34 | |
| 35 | </body> |
| 36 | </html> |