xref: /aosp_15_r20/external/antlr/runtime/C/include/antlr3basetreeadaptor.h (revision 16467b971bd3e2009fad32dd79016f2c7e421deb)
1*16467b97STreehugger Robot /** \file
2*16467b97STreehugger Robot  * Definition of the ANTLR3 base tree adaptor.
3*16467b97STreehugger Robot  */
4*16467b97STreehugger Robot 
5*16467b97STreehugger Robot #ifndef	_ANTLR3_BASE_TREE_ADAPTOR_H
6*16467b97STreehugger Robot #define	_ANTLR3_BASE_TREE_ADAPTOR_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 #include    <antlr3basetree.h>
41*16467b97STreehugger Robot #include    <antlr3commontoken.h>
42*16467b97STreehugger Robot #include	<antlr3debugeventlistener.h>
43*16467b97STreehugger Robot 
44*16467b97STreehugger Robot #ifdef __cplusplus
45*16467b97STreehugger Robot extern "C" {
46*16467b97STreehugger Robot #endif
47*16467b97STreehugger Robot 
48*16467b97STreehugger Robot typedef	struct ANTLR3_BASE_TREE_ADAPTOR_struct
49*16467b97STreehugger Robot {
50*16467b97STreehugger Robot     /** Pointer to any enclosing structure/interface that
51*16467b97STreehugger Robot      *  contains this structure.
52*16467b97STreehugger Robot      */
53*16467b97STreehugger Robot     void							* super;
54*16467b97STreehugger Robot 
55*16467b97STreehugger Robot     /** We need a string factory for creating imaginary tokens, we take this
56*16467b97STreehugger Robot      *  from the stream we are supplied to walk.
57*16467b97STreehugger Robot      */
58*16467b97STreehugger Robot     pANTLR3_STRING_FACTORY			strFactory;
59*16467b97STreehugger Robot 
60*16467b97STreehugger Robot     /* And we also need a token factory for creating imaginary tokens
61*16467b97STreehugger Robot      * this is also taken from the input source.
62*16467b97STreehugger Robot      */
63*16467b97STreehugger Robot     pANTLR3_TOKEN_FACTORY			tokenFactory;
64*16467b97STreehugger Robot 
65*16467b97STreehugger Robot 	/// If set to something other than NULL, then this structure is
66*16467b97STreehugger Robot 	/// points to an instance of the debugger interface. In general, the
67*16467b97STreehugger Robot 	/// debugger is only referenced internally in recovery/error operations
68*16467b97STreehugger Robot 	/// so that it does not cause overhead by having to check this pointer
69*16467b97STreehugger Robot 	/// in every function/method
70*16467b97STreehugger Robot 	///
71*16467b97STreehugger Robot 	pANTLR3_DEBUG_EVENT_LISTENER	debugger;
72*16467b97STreehugger Robot 
73*16467b97STreehugger Robot     void *	   		 		(*nilNode)				(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor);
74*16467b97STreehugger Robot 
75*16467b97STreehugger Robot 
76*16467b97STreehugger Robot     void *	   		 		(*dupTree)				(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * tree);
77*16467b97STreehugger Robot     void *	   		 		(*dupTreeTT)			(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t, void * tree);
78*16467b97STreehugger Robot 
79*16467b97STreehugger Robot     void					(*addChild)				(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t, void * child);
80*16467b97STreehugger Robot     void					(*addChildToken)		(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t, pANTLR3_COMMON_TOKEN child);
81*16467b97STreehugger Robot     void					(*setParent)			(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * child, void * parent);
82*16467b97STreehugger Robot     void *					(*getParent)			(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * child);
83*16467b97STreehugger Robot 
84*16467b97STreehugger Robot 	void *					(*errorNode)			(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, pANTLR3_TOKEN_STREAM tnstream, pANTLR3_COMMON_TOKEN startToken, pANTLR3_COMMON_TOKEN stopToken, pANTLR3_EXCEPTION e);
85*16467b97STreehugger Robot 	ANTLR3_BOOLEAN			(*isNilNode)			(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t);
86*16467b97STreehugger Robot 
87*16467b97STreehugger Robot     void *	    			(*becomeRoot)			(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * newRoot, void * oldRoot);
88*16467b97STreehugger Robot 
89*16467b97STreehugger Robot     void *	   			 	(*rulePostProcessing)	(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * root);
90*16467b97STreehugger Robot 
91*16467b97STreehugger Robot     void *	   			 	(*becomeRootToken)		(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * newRoot, void * oldRoot);
92*16467b97STreehugger Robot 
93*16467b97STreehugger Robot     void *	   		 		(*create)				(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, pANTLR3_COMMON_TOKEN payload);
94*16467b97STreehugger Robot     void *	   		 		(*createTypeToken)		(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, ANTLR3_UINT32 tokenType, pANTLR3_COMMON_TOKEN fromToken);
95*16467b97STreehugger Robot     void *	   				(*createTypeTokenText)	(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, ANTLR3_UINT32 tokenType, pANTLR3_COMMON_TOKEN fromToken, pANTLR3_UINT8 text);
96*16467b97STreehugger Robot     void *	    			(*createTypeText)		(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, ANTLR3_UINT32 tokenType, pANTLR3_UINT8 text);
97*16467b97STreehugger Robot 
98*16467b97STreehugger Robot     void *	    			(*dupNode)				(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * treeNode);
99*16467b97STreehugger Robot 
100*16467b97STreehugger Robot     ANTLR3_UINT32			(*getType)				(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t);
101*16467b97STreehugger Robot 
102*16467b97STreehugger Robot     void					(*setType)				(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t, ANTLR3_UINT32 type);
103*16467b97STreehugger Robot 
104*16467b97STreehugger Robot     pANTLR3_STRING			(*getText)				(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t);
105*16467b97STreehugger Robot 
106*16467b97STreehugger Robot     void					(*setText)				(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, pANTLR3_STRING t);
107*16467b97STreehugger Robot     void					(*setText8)				(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, pANTLR3_UINT8 t);
108*16467b97STreehugger Robot 
109*16467b97STreehugger Robot     void *	    			(*getChild)				(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t, ANTLR3_UINT32 i);
110*16467b97STreehugger Robot     void					(*setChild)				(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t, ANTLR3_UINT32 i, void * child);
111*16467b97STreehugger Robot     void					(*deleteChild)			(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t, ANTLR3_UINT32 i);
112*16467b97STreehugger Robot     void				    (*setChildIndex)		(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t, ANTLR3_UINT32 i);
113*16467b97STreehugger Robot     ANTLR3_INT32		    (*getChildIndex)		(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t);
114*16467b97STreehugger Robot 
115*16467b97STreehugger Robot     ANTLR3_UINT32			(*getChildCount)		(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void *);
116*16467b97STreehugger Robot 
117*16467b97STreehugger Robot     ANTLR3_UINT32			(*getUniqueID)			(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void *);
118*16467b97STreehugger Robot 
119*16467b97STreehugger Robot     pANTLR3_COMMON_TOKEN    (*createToken)			(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, ANTLR3_UINT32 tokenType, pANTLR3_UINT8 text);
120*16467b97STreehugger Robot     pANTLR3_COMMON_TOKEN    (*createTokenFromToken)	(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, pANTLR3_COMMON_TOKEN fromToken);
121*16467b97STreehugger Robot     pANTLR3_COMMON_TOKEN    (*getToken)				(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t);
122*16467b97STreehugger Robot 
123*16467b97STreehugger Robot     void					(*setTokenBoundaries)	(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t, pANTLR3_COMMON_TOKEN startToken, pANTLR3_COMMON_TOKEN stopToken);
124*16467b97STreehugger Robot 
125*16467b97STreehugger Robot     ANTLR3_MARKER			(*getTokenStartIndex)	(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t);
126*16467b97STreehugger Robot 
127*16467b97STreehugger Robot     ANTLR3_MARKER			(*getTokenStopIndex)	(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * t);
128*16467b97STreehugger Robot 
129*16467b97STreehugger Robot 	void					(*setDebugEventListener)(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, pANTLR3_DEBUG_EVENT_LISTENER debugger);
130*16467b97STreehugger Robot 
131*16467b97STreehugger Robot 	/// Produce a DOT (see graphviz freeware suite) from a base tree
132*16467b97STreehugger Robot 	///
133*16467b97STreehugger Robot 	pANTLR3_STRING			(*makeDot)				(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * theTree);
134*16467b97STreehugger Robot 
135*16467b97STreehugger Robot 	/// Replace from start to stop child index of parent with t, which might
136*16467b97STreehugger Robot 	/// be a list.  Number of children may be different
137*16467b97STreehugger Robot 	/// after this call.
138*16467b97STreehugger Robot 	///
139*16467b97STreehugger Robot 	/// If parent is null, don't do anything; must be at root of overall tree.
140*16467b97STreehugger Robot 	/// Can't replace whatever points to the parent externally.  Do nothing.
141*16467b97STreehugger Robot 	///
142*16467b97STreehugger Robot 	void					(*replaceChildren)		(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor, void * parent, ANTLR3_INT32 startChildIndex, ANTLR3_INT32 stopChildIndex, void * t);
143*16467b97STreehugger Robot 
144*16467b97STreehugger Robot     void					(*free)					(struct ANTLR3_BASE_TREE_ADAPTOR_struct * adaptor);
145*16467b97STreehugger Robot 
146*16467b97STreehugger Robot }
147*16467b97STreehugger Robot     ANTLR3_TREE_ADAPTOR, *pANTLR3_TREE_ADAPTOR;
148*16467b97STreehugger Robot #ifdef __cplusplus
149*16467b97STreehugger Robot }
150*16467b97STreehugger Robot #endif
151*16467b97STreehugger Robot 
152*16467b97STreehugger Robot #endif
153