01: package antlr;
02:
03: /* ANTLR Translator Generator
04: * Project led by Terence Parr at http://www.cs.usfca.edu
05: * Software rights: http://www.antlr.org/license.html
06: */
07:
08: import antlr.collections.AST;
09:
10: /** ASTPair: utility class used for manipulating a pair of ASTs
11: * representing the current AST root and current AST sibling.
12: * This exists to compensate for the lack of pointers or 'var'
13: * arguments in Java.
14: */
15: public class ASTPair {
16: public AST root; // current root of tree
17: public AST child; // current child to which siblings are added
18:
19: /** Make sure that child is the last sibling */
20: public final void advanceChildToEnd() {
21: if (child != null) {
22: while (child.getNextSibling() != null) {
23: child = child.getNextSibling();
24: }
25: }
26: }
27:
28: /** Copy an ASTPair. Don't call it clone() because we want type-safety */
29: public ASTPair copy() {
30: ASTPair tmp = new ASTPair();
31: tmp.root = root;
32: tmp.child = child;
33: return tmp;
34: }
35:
36: public String toString() {
37: String r = root == null ? "null" : root.getText();
38: String c = child == null ? "null" : child.getText();
39: return "[" + r + "," + c + "]";
40: }
41: }
|