Added ability to order the execution of dictionary adapter behaviors.
[castle.git] / Experiments / Attic / Rook / Castle.Rook.Compiler / Parser / antlr / ASTPair.cs
bloba57b5db97ea6686774d09d32a72bf3baaa5b65cf
1 namespace antlr
3 using System;
4 using Queue = System.Collections.Queue;
5 using AST = antlr.collections.AST;
7 /*ANTLR Translator Generator
8 * Project led by Terence Parr at http://www.jGuru.com
9 * Software rights: http://www.antlr.org/license.html
11 * $Id:$
15 // ANTLR C# Code Generator by Micheal Jordan
16 // Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
17 // Anthony Oguntimehin
19 // With many thanks to Eric V. Smith from the ANTLR list.
23 /*ASTPair: utility class used for manipulating a pair of ASTs
24 * representing the current AST root and current AST sibling.
25 * This exists to compensate for the lack of pointers or 'var'
26 * arguments in Java.
29 public class ASTPair
31 static private Queue instancePool_ = new Queue();
33 static public ASTPair GetInstance()
35 if (instancePool_.Count > 0)
37 return (ASTPair) instancePool_.Dequeue();
39 return new ASTPair();
42 static public void PutInstance(ASTPair p)
44 if (p != null)
46 p.reset();
47 instancePool_.Enqueue(p);
51 public AST root; // current root of tree
52 public AST child; // current child to which siblings are added
54 /*Make sure that child is the last sibling */
55 public void advanceChildToEnd()
57 if (child != null)
59 while (child.getNextSibling() != null)
61 child = child.getNextSibling();
66 /*Copy an ASTPair. Don't call it clone() because we want type-safety */
67 public virtual ASTPair copy()
69 ASTPair tmp = ASTPair.GetInstance();
70 tmp.root = root;
71 tmp.child = child;
72 return tmp;
75 private void reset()
77 root = null;
78 child = null;
81 override public string ToString()
83 string r = (root == null) ? "null" : root.getText();
84 string c = (child == null) ? "null" : child.getText();
85 return "[" + r + "," + c + "]";