--- /dev/null
+/** Interface for an ANTLR3 common tree which is what gets\r
+ * passed around by the AST producing parser.\r
+ */\r
+\r
+#ifndef _ANTLR3_COMMON_TREE_H\r
+#define _ANTLR3_COMMON_TREE_H\r
+\r
+// [The "BSD licence"]\r
+// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC\r
+// http://www.temporal-wave.com\r
+// http://www.linkedin.com/in/jimidle\r
+//\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions\r
+// are met:\r
+// 1. Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+// 2. Redistributions in binary form must reproduce the above copyright\r
+// notice, this list of conditions and the following disclaimer in the\r
+// documentation and/or other materials provided with the distribution.\r
+// 3. The name of the author may not be used to endorse or promote products\r
+// derived from this software without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+#include <antlr3defs.h>\r
+#include <antlr3basetree.h>\r
+#include <antlr3commontoken.h>\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct ANTLR3_COMMON_TREE_struct\r
+{\r
+\r
+ /// Not used by ANTLR, but if a super structure is created above\r
+ /// this structure, it can be used to point to the start of the super\r
+ /// structure, where additional data and function pointers can be stored.\r
+ ///\r
+ void * super;\r
+\r
+ /// Start token index that encases this tree\r
+ ///\r
+ ANTLR3_MARKER startIndex;\r
+\r
+ /// End token that encases this tree\r
+ ///\r
+ ANTLR3_MARKER stopIndex;\r
+\r
+ /// A single token, this is the payload for the tree\r
+ ///\r
+ pANTLR3_COMMON_TOKEN token;\r
+\r
+ /// Points to the node that has this node as a child.\r
+ /// If this is NULL, then this is the root node.\r
+ ///\r
+ pANTLR3_COMMON_TREE parent;\r
+\r
+ /// What index is this particular node in the child list it\r
+ /// belongs to?\r
+ ///\r
+ ANTLR3_INT32 childIndex;\r
+ \r
+ /// Pointer to the tree factory that manufactured this\r
+ /// token. This can be used by duplication methods and so on\r
+ /// to manufacture another auto-tracked common tree structure\r
+ ///\r
+ pANTLR3_ARBORETUM factory;\r
+\r
+ /// An encapsulated BASE TREE structure (NOT a pointer)\r
+ /// that performs a lot of the dirty work of node management\r
+ /// To this we add just a few functions that are specific to the \r
+ /// payload. You can further abstract common tree so long\r
+ /// as you always have a baseTree pointer in the top structure\r
+ /// and copy it from the next one down. \r
+ /// So, lets say we have a structure JIMS_TREE. \r
+ /// It needs an ANTLR3_BASE_TREE that will support all the\r
+ /// general tree duplication stuff.\r
+ /// It needs a ANTLR3_COMMON_TREE structure embedded or completely\r
+ /// provides the equivalent interface.\r
+ /// It provides it's own methods and data.\r
+ /// To create a new one of these, the function provided to\r
+ /// the tree adaptor (see comments there) should allocate the\r
+ /// memory for a new JIMS_TREE structure, then call\r
+ /// antlr3InitCommonTree(<addressofembeddedCOMMON_TREE>)\r
+ /// antlr3BaseTreeNew(<addressofBASETREE>)\r
+ /// The interfaces for BASE_TREE and COMMON_TREE will then\r
+ /// be initialized. You then call and you can override them or just init\r
+ /// JIMS_TREE (note that the base tree in common tree will be ignored)\r
+ /// just the top level base tree is used). Codegen will take care of the rest.\r
+ /// \r
+ ANTLR3_BASE_TREE baseTree;\r
+ \r
+}\r
+ ANTLR3_COMMON_TREE;\r
+\r
+/// \brief ANTLR3 Tree factory interface to create lots of trees efficiently\r
+/// rather than creating and freeing lots of little bits of memory.\r
+///\r
+typedef struct ANTLR3_ARBORETUM_struct\r
+{\r
+ /// Pointers to the array of tokens that this factory has produced so far\r
+ ///\r
+ pANTLR3_COMMON_TREE *pools;\r
+\r
+ /// Current pool tokens we are allocating from\r
+ ///\r
+ ANTLR3_INT32 thisPool;\r
+\r
+ /// The next token to throw out from the pool, will cause a new pool allocation\r
+ /// if this exceeds the available tokenCount\r
+ ///\r
+ ANTLR3_UINT32 nextTree;\r
+\r
+ /// Trick to initialize tokens and their API quickly, we set up this token when the\r
+ /// factory is created, then just copy the memory it uses into the new token.\r
+ ///\r
+ ANTLR3_COMMON_TREE unTruc;\r
+\r
+ /// Pointer to a vector factory that is used to create child list vectors\r
+ /// for any child nodes that need them. This means that we auto track the\r
+ /// vectors and auto free them when we close the factory. It also means\r
+ /// that all rewriting trees can use the same tree factory and the same\r
+ /// vector factory and we do not dup any nodes unless we must do so\r
+ /// explicitly because of context such as an empty rewrite stream and\r
+ /// ->IMAGINARY[ID] so on. This makes memory tracking much simpler and\r
+ /// tempts no errors.\r
+ ///\r
+ pANTLR3_VECTOR_FACTORY vFactory;\r
+\r
+ /// A resuse stack for reclaiming Nil nodes that were used in rewrites\r
+ /// and are now dead. The nilNode() method will eat one of these before\r
+ /// creating a new node.\r
+ ///\r
+ pANTLR3_STACK nilStack;\r
+\r
+ /// Pointer to a function that returns a new tree\r
+ ///\r
+ pANTLR3_BASE_TREE (*newTree) (struct ANTLR3_ARBORETUM_struct * factory);\r
+ pANTLR3_BASE_TREE (*newFromTree) (struct ANTLR3_ARBORETUM_struct * factory, pANTLR3_COMMON_TREE tree);\r
+ pANTLR3_BASE_TREE (*newFromToken) (struct ANTLR3_ARBORETUM_struct * factory, pANTLR3_COMMON_TOKEN token);\r
+\r
+ /// Pointer to a function the destroys the factory\r
+ ///\r
+ void (*close) (struct ANTLR3_ARBORETUM_struct * factory);\r
+}\r
+ ANTLR3_ARBORETUM;\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
+\r
+\r