]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/cpp/DataBoardTest/libantlr3c-3.2/include/antlr3commontree.h
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / cpp / DataBoardTest / libantlr3c-3.2 / include / antlr3commontree.h
1 /** Interface for an ANTLR3 common tree which is what gets\r
2  *  passed around by the AST producing parser.\r
3  */\r
4 \r
5 #ifndef _ANTLR3_COMMON_TREE_H\r
6 #define _ANTLR3_COMMON_TREE_H\r
7 \r
8 // [The "BSD licence"]\r
9 // Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC\r
10 // http://www.temporal-wave.com\r
11 // http://www.linkedin.com/in/jimidle\r
12 //\r
13 // All rights reserved.\r
14 //\r
15 // Redistribution and use in source and binary forms, with or without\r
16 // modification, are permitted provided that the following conditions\r
17 // are met:\r
18 // 1. Redistributions of source code must retain the above copyright\r
19 //    notice, this list of conditions and the following disclaimer.\r
20 // 2. Redistributions in binary form must reproduce the above copyright\r
21 //    notice, this list of conditions and the following disclaimer in the\r
22 //    documentation and/or other materials provided with the distribution.\r
23 // 3. The name of the author may not be used to endorse or promote products\r
24 //    derived from this software without specific prior written permission.\r
25 //\r
26 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
27 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
28 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
29 // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
30 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
31 // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
32 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
33 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
34 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
35 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
36 \r
37 #include    <antlr3defs.h>\r
38 #include    <antlr3basetree.h>\r
39 #include    <antlr3commontoken.h>\r
40 \r
41 #ifdef __cplusplus\r
42 extern "C" {\r
43 #endif\r
44 \r
45 typedef struct ANTLR3_COMMON_TREE_struct\r
46 {\r
47 \r
48         /// Not used by ANTLR, but if a super structure is created above\r
49     /// this structure, it can be used to point to the start of the super\r
50     /// structure, where additional data and function pointers can be stored.\r
51     ///\r
52     void                                        * super;\r
53 \r
54     /// Start token index that encases this tree\r
55     ///\r
56     ANTLR3_MARKER                         startIndex;\r
57 \r
58     /// End token that encases this tree\r
59     ///\r
60     ANTLR3_MARKER                         stopIndex;\r
61 \r
62     /// A single token, this is the payload for the tree\r
63     ///\r
64     pANTLR3_COMMON_TOKEN      token;\r
65 \r
66         /// Points to the node that has this node as a child.\r
67         /// If this is NULL, then this is the root node.\r
68         ///\r
69         pANTLR3_COMMON_TREE               parent;\r
70 \r
71         /// What index is this particular node in the child list it\r
72         /// belongs to?\r
73         ///\r
74         ANTLR3_INT32                      childIndex;\r
75         \r
76         /// Pointer to the tree factory that manufactured this\r
77         /// token. This can be used by duplication methods and so on\r
78         /// to manufacture another auto-tracked common tree structure\r
79         ///\r
80         pANTLR3_ARBORETUM       factory;\r
81 \r
82     /// An encapsulated BASE TREE structure (NOT a pointer)\r
83     /// that performs a lot of the dirty work of node management\r
84     /// To this we add just a few functions that are specific to the \r
85     /// payload. You can further abstract common tree so long\r
86     /// as you always have a baseTree pointer in the top structure\r
87     /// and copy it from the next one down. \r
88     /// So, lets say we have a structure JIMS_TREE. \r
89     /// It needs an ANTLR3_BASE_TREE that will support all the\r
90     /// general tree duplication stuff.\r
91     /// It needs a ANTLR3_COMMON_TREE structure embedded or completely\r
92     /// provides the equivalent interface.\r
93     /// It provides it's own methods and data.\r
94     /// To create a new one of these, the function provided to\r
95     /// the tree adaptor (see comments there) should allocate the\r
96     /// memory for a new JIMS_TREE structure, then call\r
97     /// antlr3InitCommonTree(<addressofembeddedCOMMON_TREE>)\r
98     /// antlr3BaseTreeNew(<addressofBASETREE>)\r
99     /// The interfaces for BASE_TREE and COMMON_TREE will then\r
100     /// be initialized. You then call and you can override them or just init\r
101     /// JIMS_TREE (note that the base tree in common tree will be ignored)\r
102     /// just the top level base tree is used). Codegen will take care of the rest.\r
103     /// \r
104     ANTLR3_BASE_TREE        baseTree;\r
105      \r
106 }\r
107     ANTLR3_COMMON_TREE;\r
108 \r
109 /// \brief ANTLR3 Tree factory interface to create lots of trees efficiently\r
110 ///  rather than creating and freeing lots of little bits of memory.\r
111 ///\r
112 typedef struct ANTLR3_ARBORETUM_struct\r
113 {\r
114     /// Pointers to the array of tokens that this factory has produced so far\r
115     ///\r
116     pANTLR3_COMMON_TREE    *pools;\r
117 \r
118     /// Current pool tokens we are allocating from\r
119     ///\r
120     ANTLR3_INT32                        thisPool;\r
121 \r
122     /// The next token to throw out from the pool, will cause a new pool allocation\r
123     ///  if this exceeds the available tokenCount\r
124     ///\r
125     ANTLR3_UINT32                       nextTree;\r
126 \r
127     /// Trick to initialize tokens and their API quickly, we set up this token when the\r
128     /// factory is created, then just copy the memory it uses into the new token.\r
129     ///\r
130     ANTLR3_COMMON_TREE      unTruc;\r
131 \r
132     /// Pointer to a vector factory that is used to create child list vectors\r
133     /// for any child nodes that need them. This means that we auto track the\r
134     /// vectors and auto free them when we close the factory. It also means\r
135     /// that all rewriting trees can use the same tree factory and the same\r
136     /// vector factory and we do not dup any nodes unless we must do so\r
137     /// explicitly because of context such as an empty rewrite stream and\r
138     /// ->IMAGINARY[ID] so on. This makes memory tracking much simpler and\r
139     /// tempts no errors.\r
140     ///\r
141     pANTLR3_VECTOR_FACTORY   vFactory;\r
142 \r
143     /// A resuse stack for reclaiming Nil nodes that were used in rewrites\r
144     /// and are now dead. The nilNode() method will eat one of these before\r
145     /// creating a new node.\r
146     ///\r
147     pANTLR3_STACK           nilStack;\r
148 \r
149     /// Pointer to a function that returns a new tree\r
150     ///\r
151     pANTLR3_BASE_TREE       (*newTree)          (struct ANTLR3_ARBORETUM_struct * factory);\r
152     pANTLR3_BASE_TREE       (*newFromTree)      (struct ANTLR3_ARBORETUM_struct * factory, pANTLR3_COMMON_TREE tree);\r
153     pANTLR3_BASE_TREE       (*newFromToken)     (struct ANTLR3_ARBORETUM_struct * factory, pANTLR3_COMMON_TOKEN token);\r
154 \r
155     /// Pointer to a function the destroys the factory\r
156     ///\r
157     void                    (*close)        (struct ANTLR3_ARBORETUM_struct * factory);\r
158 }\r
159     ANTLR3_ARBORETUM;\r
160 \r
161 #ifdef __cplusplus\r
162 }\r
163 #endif\r
164 \r
165 #endif\r
166 \r
167 \r