xref: /aosp_15_r20/external/antlr/runtime/C/include/antlr3basetree.h (revision 16467b971bd3e2009fad32dd79016f2c7e421deb)
1*16467b97STreehugger Robot /// \file
2*16467b97STreehugger Robot /// Definition of the ANTLR3 base tree.
3*16467b97STreehugger Robot ///
4*16467b97STreehugger Robot 
5*16467b97STreehugger Robot #ifndef	_ANTLR3_BASE_TREE_H
6*16467b97STreehugger Robot #define	_ANTLR3_BASE_TREE_H
7*16467b97STreehugger Robot 
8*16467b97STreehugger Robot // [The "BSD licence"]
9*16467b97STreehugger Robot // Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC
10*16467b97STreehugger Robot // http://www.temporal-wave.com
11*16467b97STreehugger Robot // http://www.linkedin.com/in/jimidle
12*16467b97STreehugger Robot //
13*16467b97STreehugger Robot // All rights reserved.
14*16467b97STreehugger Robot //
15*16467b97STreehugger Robot // Redistribution and use in source and binary forms, with or without
16*16467b97STreehugger Robot // modification, are permitted provided that the following conditions
17*16467b97STreehugger Robot // are met:
18*16467b97STreehugger Robot // 1. Redistributions of source code must retain the above copyright
19*16467b97STreehugger Robot //    notice, this list of conditions and the following disclaimer.
20*16467b97STreehugger Robot // 2. Redistributions in binary form must reproduce the above copyright
21*16467b97STreehugger Robot //    notice, this list of conditions and the following disclaimer in the
22*16467b97STreehugger Robot //    documentation and/or other materials provided with the distribution.
23*16467b97STreehugger Robot // 3. The name of the author may not be used to endorse or promote products
24*16467b97STreehugger Robot //    derived from this software without specific prior written permission.
25*16467b97STreehugger Robot //
26*16467b97STreehugger Robot // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
27*16467b97STreehugger Robot // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28*16467b97STreehugger Robot // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29*16467b97STreehugger Robot // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
30*16467b97STreehugger Robot // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31*16467b97STreehugger Robot // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32*16467b97STreehugger Robot // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33*16467b97STreehugger Robot // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34*16467b97STreehugger Robot // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35*16467b97STreehugger Robot // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36*16467b97STreehugger Robot 
37*16467b97STreehugger Robot #include    <antlr3defs.h>
38*16467b97STreehugger Robot #include    <antlr3collections.h>
39*16467b97STreehugger Robot #include    <antlr3string.h>
40*16467b97STreehugger Robot 
41*16467b97STreehugger Robot #ifdef __cplusplus
42*16467b97STreehugger Robot extern "C" {
43*16467b97STreehugger Robot #endif
44*16467b97STreehugger Robot 
45*16467b97STreehugger Robot /// A generic tree implementation with no payload.  You must subclass to
46*16467b97STreehugger Robot /// actually have any user data.  ANTLR v3 uses a list of children approach
47*16467b97STreehugger Robot /// instead of the child-sibling approach in v2.  A flat tree (a list) is
48*16467b97STreehugger Robot /// an empty node whose children represent the list.  An empty (as in it does not
49*16467b97STreehugger Robot /// have payload itself), but non-null node is called "nil".
50*16467b97STreehugger Robot ///
51*16467b97STreehugger Robot typedef	struct ANTLR3_BASE_TREE_struct
52*16467b97STreehugger Robot {
53*16467b97STreehugger Robot 
54*16467b97STreehugger Robot     /// Implementers of this interface sometimes require a pointer to their selves.
55*16467b97STreehugger Robot     ///
56*16467b97STreehugger Robot     void    *	    super;
57*16467b97STreehugger Robot 
58*16467b97STreehugger Robot     /// Generic void pointer allows the grammar programmer to attach any structure they
59*16467b97STreehugger Robot     /// like to a tree node, in many cases saving the need to create their own tree
60*16467b97STreehugger Robot     /// and tree adaptors. ANTLR does not use this pointer, but will copy it for you and so on.
61*16467b97STreehugger Robot     ///
62*16467b97STreehugger Robot     void    *	    u;
63*16467b97STreehugger Robot 
64*16467b97STreehugger Robot     /// The list of all the children that belong to this node. They are not part of the node
65*16467b97STreehugger Robot     /// as they belong to the common tree node that implements this.
66*16467b97STreehugger Robot     ///
67*16467b97STreehugger Robot     pANTLR3_VECTOR  children;
68*16467b97STreehugger Robot 
69*16467b97STreehugger Robot     /// This is used to store the current child index position while descending
70*16467b97STreehugger Robot     /// and ascending trees as the tree walk progresses.
71*16467b97STreehugger Robot     ///
72*16467b97STreehugger Robot     ANTLR3_MARKER   savedIndex;
73*16467b97STreehugger Robot 
74*16467b97STreehugger Robot     /// A string factory to produce strings for toString etc
75*16467b97STreehugger Robot     ///
76*16467b97STreehugger Robot     pANTLR3_STRING_FACTORY strFactory;
77*16467b97STreehugger Robot 
78*16467b97STreehugger Robot     /// A pointer to a function that returns the common token pointer
79*16467b97STreehugger Robot     /// for the payload in the supplied tree.
80*16467b97STreehugger Robot     ///
81*16467b97STreehugger Robot     pANTLR3_COMMON_TOKEN                (*getToken)			(struct ANTLR3_BASE_TREE_struct * tree);
82*16467b97STreehugger Robot 
83*16467b97STreehugger Robot     void				(*addChild)			(struct ANTLR3_BASE_TREE_struct * tree, void * child);
84*16467b97STreehugger Robot 
85*16467b97STreehugger Robot     void				(*addChildren)			(struct ANTLR3_BASE_TREE_struct * tree, pANTLR3_LIST kids);
86*16467b97STreehugger Robot 
87*16467b97STreehugger Robot     void    				(*createChildrenList)		(struct ANTLR3_BASE_TREE_struct * tree);
88*16467b97STreehugger Robot 
89*16467b97STreehugger Robot     void    *				(*deleteChild)			(struct ANTLR3_BASE_TREE_struct * tree, ANTLR3_UINT32 i);
90*16467b97STreehugger Robot 
91*16467b97STreehugger Robot     void				(*replaceChildren)		(struct ANTLR3_BASE_TREE_struct * parent, ANTLR3_INT32 startChildIndex, ANTLR3_INT32 stopChildIndex, struct ANTLR3_BASE_TREE_struct * t);
92*16467b97STreehugger Robot 
93*16467b97STreehugger Robot     void    *				(*dupNode)			(struct ANTLR3_BASE_TREE_struct * dupNode);
94*16467b97STreehugger Robot 
95*16467b97STreehugger Robot     void    *				(*dupTree)			(struct ANTLR3_BASE_TREE_struct * tree);
96*16467b97STreehugger Robot 
97*16467b97STreehugger Robot     ANTLR3_UINT32			(*getCharPositionInLine)	(struct ANTLR3_BASE_TREE_struct * tree);
98*16467b97STreehugger Robot 
99*16467b97STreehugger Robot     void    *				(*getChild)			(struct ANTLR3_BASE_TREE_struct * tree, ANTLR3_UINT32 i);
100*16467b97STreehugger Robot 
101*16467b97STreehugger Robot     void    				(*setChildIndex)		(struct ANTLR3_BASE_TREE_struct * tree, ANTLR3_INT32 );
102*16467b97STreehugger Robot 
103*16467b97STreehugger Robot     ANTLR3_INT32			(*getChildIndex)		(struct ANTLR3_BASE_TREE_struct * tree );
104*16467b97STreehugger Robot 
105*16467b97STreehugger Robot     ANTLR3_UINT32			(*getChildCount)		(struct ANTLR3_BASE_TREE_struct * tree);
106*16467b97STreehugger Robot 
107*16467b97STreehugger Robot     struct ANTLR3_BASE_TREE_struct *    (*getParent)			(struct ANTLR3_BASE_TREE_struct * tree);
108*16467b97STreehugger Robot 
109*16467b97STreehugger Robot     void    				(*setParent)			(struct ANTLR3_BASE_TREE_struct * tree, struct ANTLR3_BASE_TREE_struct * parent);
110*16467b97STreehugger Robot 
111*16467b97STreehugger Robot     ANTLR3_UINT32			(*getType)			(struct ANTLR3_BASE_TREE_struct * tree);
112*16467b97STreehugger Robot 
113*16467b97STreehugger Robot     void    *				(*getFirstChildWithType)	(struct ANTLR3_BASE_TREE_struct * tree, ANTLR3_UINT32 type);
114*16467b97STreehugger Robot 
115*16467b97STreehugger Robot     ANTLR3_UINT32			(*getLine)			(struct ANTLR3_BASE_TREE_struct * tree);
116*16467b97STreehugger Robot 
117*16467b97STreehugger Robot     pANTLR3_STRING			(*getText)			(struct ANTLR3_BASE_TREE_struct * tree);
118*16467b97STreehugger Robot 
119*16467b97STreehugger Robot     ANTLR3_BOOLEAN			(*isNilNode)			(struct ANTLR3_BASE_TREE_struct * tree);
120*16467b97STreehugger Robot 
121*16467b97STreehugger Robot     void				(*setChild)			(struct ANTLR3_BASE_TREE_struct * tree, ANTLR3_UINT32 i, void * child);
122*16467b97STreehugger Robot 
123*16467b97STreehugger Robot     pANTLR3_STRING			(*toStringTree)			(struct ANTLR3_BASE_TREE_struct * tree);
124*16467b97STreehugger Robot 
125*16467b97STreehugger Robot     pANTLR3_STRING			(*toString)			(struct ANTLR3_BASE_TREE_struct * tree);
126*16467b97STreehugger Robot 
127*16467b97STreehugger Robot     void				(*freshenPACIndexesAll)		(struct ANTLR3_BASE_TREE_struct * tree);
128*16467b97STreehugger Robot 
129*16467b97STreehugger Robot     void				(*freshenPACIndexes)		(struct ANTLR3_BASE_TREE_struct * tree, ANTLR3_UINT32 offset);
130*16467b97STreehugger Robot 
131*16467b97STreehugger Robot     void                                (*reuse)                        (struct ANTLR3_BASE_TREE_struct * tree);
132*16467b97STreehugger Robot 
133*16467b97STreehugger Robot     void    				(*free)				(struct ANTLR3_BASE_TREE_struct * tree);
134*16467b97STreehugger Robot 
135*16467b97STreehugger Robot }
136*16467b97STreehugger Robot     ANTLR3_BASE_TREE;
137*16467b97STreehugger Robot 
138*16467b97STreehugger Robot #ifdef __cplusplus
139*16467b97STreehugger Robot }
140*16467b97STreehugger Robot #endif
141*16467b97STreehugger Robot 
142*16467b97STreehugger Robot 
143*16467b97STreehugger Robot #endif
144