1 /** \file
2  * This is the standard tree adaptor used by the C runtime unless the grammar
3  * source file says to use anything different. It embeds a BASE_TREE to which
4  * it adds its own implementation of anything that the base tree is not
5  * good for, plus a number of methods that any other adaptor type
6  * needs to implement too.
7  * \ingroup pANTLR3_COMMON_TREE_ADAPTOR
8  */
9 
10 // [The "BSD licence"]
11 // Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC
12 // http://www.temporal-wave.com
13 // http://www.linkedin.com/in/jimidle
14 //
15 // All rights reserved.
16 //
17 // Redistribution and use in source and binary forms, with or without
18 // modification, are permitted provided that the following conditions
19 // are met:
20 // 1. Redistributions of source code must retain the above copyright
21 //    notice, this list of conditions and the following disclaimer.
22 // 2. Redistributions in binary form must reproduce the above copyright
23 //    notice, this list of conditions and the following disclaimer in the
24 //    documentation and/or other materials provided with the distribution.
25 // 3. The name of the author may not be used to endorse or promote products
26 //    derived from this software without specific prior written permission.
27 //
28 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
29 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
30 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
32 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
33 // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
37 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 
39 #include    <antlr3commontreeadaptor.h>
40 
41 #ifdef	ANTLR3_WINDOWS
42 #pragma warning( disable : 4100 )
43 #endif
44 
45 /* BASE_TREE_ADAPTOR overrides... */
46 static	pANTLR3_BASE_TREE		dupNode					(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE treeNode);
47 static	pANTLR3_BASE_TREE		create					(pANTLR3_BASE_TREE_ADAPTOR adpator, pANTLR3_COMMON_TOKEN payload);
48 static	pANTLR3_BASE_TREE		dbgCreate				(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_COMMON_TOKEN payload);
49 static	pANTLR3_COMMON_TOKEN	createToken				(pANTLR3_BASE_TREE_ADAPTOR adaptor, ANTLR3_UINT32 tokenType, pANTLR3_UINT8 text);
50 static	pANTLR3_COMMON_TOKEN	createTokenFromToken	(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_COMMON_TOKEN fromToken);
51 static	pANTLR3_COMMON_TOKEN    getToken				(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t);
52 static	pANTLR3_STRING			getText					(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t);
53 static	ANTLR3_UINT32			getType					(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t);
54 static	pANTLR3_BASE_TREE		getChild				(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t, ANTLR3_UINT32 i);
55 static	ANTLR3_UINT32			getChildCount			(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t);
56 static	void					replaceChildren			(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE parent, ANTLR3_INT32 startChildIndex, ANTLR3_INT32 stopChildIndex, pANTLR3_BASE_TREE t);
57 static	void					setDebugEventListener	(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_DEBUG_EVENT_LISTENER debugger);
58 static  void					setChildIndex			(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t, ANTLR3_INT32 i);
59 static  ANTLR3_INT32			getChildIndex			(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t);
60 static	void					setParent				(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE child, pANTLR3_BASE_TREE parent);
61 static	pANTLR3_BASE_TREE    	getParent				(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE child);
62 static  void					setChild				(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t, ANTLR3_UINT32 i, pANTLR3_BASE_TREE child);
63 static	void					deleteChild				(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t, ANTLR3_UINT32 i);
64 static	pANTLR3_BASE_TREE		errorNode				(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_TOKEN_STREAM ctnstream, pANTLR3_COMMON_TOKEN startToken, pANTLR3_COMMON_TOKEN stopToken, pANTLR3_EXCEPTION e);
65 /* Methods specific to each tree adaptor
66  */
67 static	void			setTokenBoundaries		(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t, pANTLR3_COMMON_TOKEN startToken, pANTLR3_COMMON_TOKEN stopToken);
68 static	void			dbgSetTokenBoundaries	(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t, pANTLR3_COMMON_TOKEN startToken, pANTLR3_COMMON_TOKEN stopToken);
69 static	ANTLR3_MARKER   getTokenStartIndex		(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t);
70 static  ANTLR3_MARKER   getTokenStopIndex		(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t);
71 
72 static	void		ctaFree			(pANTLR3_BASE_TREE_ADAPTOR adaptor);
73 
74 /** Create a new tree adaptor. Note that despite the fact that this is
75  *  creating a new COMMON_TREE adaptor, we return the address of the
76  *  BASE_TREE interface, as should any other adaptor that wishes to be
77  *  used as the tree element of a tree parse/build. It needs to be given the
78  *  address of a valid string factory as we do not know what the originating
79  *  input stream encoding type was. This way we can rely on just using
80  *  the original input stream's string factory or one of the correct type
81  *  which the user supplies us.
82  */
83 ANTLR3_API pANTLR3_BASE_TREE_ADAPTOR
ANTLR3_TREE_ADAPTORNew(pANTLR3_STRING_FACTORY strFactory)84 ANTLR3_TREE_ADAPTORNew(pANTLR3_STRING_FACTORY strFactory)
85 {
86 	pANTLR3_COMMON_TREE_ADAPTOR	cta;
87 
88 	// First job is to create the memory we need for the tree adaptor interface.
89 	//
90 	cta	= (pANTLR3_COMMON_TREE_ADAPTOR) ANTLR3_MALLOC((size_t)(sizeof(ANTLR3_COMMON_TREE_ADAPTOR)));
91 
92 	if	(cta == NULL)
93 	{
94 		return	NULL;
95 	}
96 
97 	// Memory is initialized, so initialize the base tree adaptor
98 	//
99 	antlr3BaseTreeAdaptorInit(&(cta->baseAdaptor), NULL);
100 
101 	// Install our interface overrides. Strangeness is to allow generated code to treat them
102     // as returning void *
103 	//
104 	cta->baseAdaptor.dupNode				=  (void * (*) (pANTLR3_BASE_TREE_ADAPTOR, void *))
105 													dupNode;
106 	cta->baseAdaptor.create					=  (void * (*) (pANTLR3_BASE_TREE_ADAPTOR, pANTLR3_COMMON_TOKEN))
107 													create;
108 	cta->baseAdaptor.createToken			=
109 													createToken;
110 	cta->baseAdaptor.createTokenFromToken   =
111 													createTokenFromToken;
112 	cta->baseAdaptor.setTokenBoundaries	    =  (void   (*) (pANTLR3_BASE_TREE_ADAPTOR, void *, pANTLR3_COMMON_TOKEN, pANTLR3_COMMON_TOKEN))
113 													setTokenBoundaries;
114 	cta->baseAdaptor.getTokenStartIndex	    =  (ANTLR3_MARKER  (*) (pANTLR3_BASE_TREE_ADAPTOR, void *))
115                                                     getTokenStartIndex;
116 	cta->baseAdaptor.getTokenStopIndex	    =  (ANTLR3_MARKER  (*) (pANTLR3_BASE_TREE_ADAPTOR, void *))
117                                                     getTokenStopIndex;
118 	cta->baseAdaptor.getText				=  (pANTLR3_STRING (*) (pANTLR3_BASE_TREE_ADAPTOR, void *))
119                                                     getText;
120 	cta->baseAdaptor.getType				=  (ANTLR3_UINT32  (*) (pANTLR3_BASE_TREE_ADAPTOR, void *))
121                                                     getType;
122 	cta->baseAdaptor.getChild				=  (void * (*) (pANTLR3_BASE_TREE_ADAPTOR, void *, ANTLR3_UINT32))
123                                                     getChild;
124 	cta->baseAdaptor.setChild				=  (void   (*) (pANTLR3_BASE_TREE_ADAPTOR, void *, ANTLR3_UINT32, void *))
125                                                     setChild;
126 	cta->baseAdaptor.setParent				=  (void   (*) (pANTLR3_BASE_TREE_ADAPTOR, void *, void *))
127                                                     setParent;
128     cta->baseAdaptor.getParent				=  (void * (*) (pANTLR3_BASE_TREE_ADAPTOR, void *))
129                                                     getParent;
130 	cta->baseAdaptor.setChildIndex			=  (void   (*) (pANTLR3_BASE_TREE_ADAPTOR, void *, ANTLR3_UINT32))
131                                                     setChildIndex;
132 	cta->baseAdaptor.deleteChild			=  (void   (*) (pANTLR3_BASE_TREE_ADAPTOR, void *, ANTLR3_UINT32))
133                                                     deleteChild;
134 	cta->baseAdaptor.getChildCount			=  (ANTLR3_UINT32  (*) (pANTLR3_BASE_TREE_ADAPTOR, void *))
135                                                     getChildCount;
136 	cta->baseAdaptor.getChildIndex			=  (ANTLR3_INT32  (*) (pANTLR3_BASE_TREE_ADAPTOR, void *))
137                                                     getChildIndex;
138 	cta->baseAdaptor.free					=  (void  (*) (pANTLR3_BASE_TREE_ADAPTOR))
139                                                     ctaFree;
140 	cta->baseAdaptor.setDebugEventListener	=
141 													setDebugEventListener;
142 	cta->baseAdaptor.replaceChildren		=  (void   (*) (pANTLR3_BASE_TREE_ADAPTOR, void *, ANTLR3_INT32, ANTLR3_INT32, void *))
143                                                     replaceChildren;
144 	cta->baseAdaptor.errorNode				=  (void * (*) (pANTLR3_BASE_TREE_ADAPTOR, pANTLR3_TOKEN_STREAM, pANTLR3_COMMON_TOKEN, pANTLR3_COMMON_TOKEN, pANTLR3_EXCEPTION))
145                                                     errorNode;
146 
147 	// Install the super class pointer
148 	//
149 	cta->baseAdaptor.super	    = cta;
150 
151 	// Install a tree factory for creating new tree nodes
152 	//
153 	cta->arboretum  = antlr3ArboretumNew(strFactory);
154 
155 	// Install a token factory for imaginary tokens, these imaginary
156 	// tokens do not require access to the input stream so we can
157 	// dummy the creation of it, but they will need a string factory.
158 	//
159 	cta->baseAdaptor.tokenFactory						= antlr3TokenFactoryNew(NULL);
160 	cta->baseAdaptor.tokenFactory->unTruc.strFactory	= strFactory;
161 
162 	// Allow the base tree adaptor to share the tree factory's string factory.
163 	//
164 	cta->baseAdaptor.strFactory	= strFactory;
165 
166 	// Return the address of the base adaptor interface.
167 	//
168 	return  &(cta->baseAdaptor);
169 }
170 
171 /// Debugging version of the tree adaptor (not normally called as generated code
172 /// calls setDebugEventListener instead which changes a normal token stream to
173 /// a debugging stream and means that a user's instantiation code does not need
174 /// to be changed just to debug with AW.
175 ///
176 ANTLR3_API pANTLR3_BASE_TREE_ADAPTOR
ANTLR3_TREE_ADAPTORDebugNew(pANTLR3_STRING_FACTORY strFactory,pANTLR3_DEBUG_EVENT_LISTENER debugger)177 ANTLR3_TREE_ADAPTORDebugNew(pANTLR3_STRING_FACTORY strFactory, pANTLR3_DEBUG_EVENT_LISTENER	debugger)
178 {
179 	pANTLR3_BASE_TREE_ADAPTOR	ta;
180 
181 	// Create a normal one first
182 	//
183 	ta	= ANTLR3_TREE_ADAPTORNew(strFactory);
184 
185 	if	(ta != NULL)
186 	{
187 		// Reinitialize as a debug version
188 		//
189 		antlr3BaseTreeAdaptorInit(ta, debugger);
190 		ta->create				= (void * (*) (pANTLR3_BASE_TREE_ADAPTOR, pANTLR3_COMMON_TOKEN))
191 									dbgCreate;
192 		ta->setTokenBoundaries	= (void   (*) (pANTLR3_BASE_TREE_ADAPTOR, void *, pANTLR3_COMMON_TOKEN, pANTLR3_COMMON_TOKEN))
193 									dbgSetTokenBoundaries;
194 	}
195 
196 	return	ta;
197 }
198 
199 /// Causes an existing common tree adaptor to become a debug version
200 ///
201 static	void
setDebugEventListener(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_DEBUG_EVENT_LISTENER debugger)202 setDebugEventListener	(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_DEBUG_EVENT_LISTENER debugger)
203 {
204 	// Reinitialize as a debug version
205 	//
206 	antlr3BaseTreeAdaptorInit(adaptor, debugger);
207 
208 	adaptor->create				= (void * (*) (pANTLR3_BASE_TREE_ADAPTOR, pANTLR3_COMMON_TOKEN))
209                                     dbgCreate;
210 	adaptor->setTokenBoundaries	= (void   (*) (pANTLR3_BASE_TREE_ADAPTOR, void *, pANTLR3_COMMON_TOKEN, pANTLR3_COMMON_TOKEN))
211                                     dbgSetTokenBoundaries;
212 
213 }
214 
215 static void
ctaFree(pANTLR3_BASE_TREE_ADAPTOR adaptor)216 ctaFree(pANTLR3_BASE_TREE_ADAPTOR adaptor)
217 {
218     pANTLR3_COMMON_TREE_ADAPTOR cta;
219 
220     cta	= (pANTLR3_COMMON_TREE_ADAPTOR)(adaptor->super);
221 
222     /* Free the tree factory we created
223      */
224     cta->arboretum->close(((pANTLR3_COMMON_TREE_ADAPTOR)(adaptor->super))->arboretum);
225 
226     /* Free the token factory we created
227      */
228     adaptor->tokenFactory->close(adaptor->tokenFactory);
229 
230     /* Free the super pointer, as it is this that was allocated
231      * and is the common tree structure.
232      */
233     ANTLR3_FREE(adaptor->super);
234 }
235 
236 /* BASE_TREE_ADAPTOR overrides */
237 
238 static	pANTLR3_BASE_TREE
errorNode(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_TOKEN_STREAM ctnstream,pANTLR3_COMMON_TOKEN startToken,pANTLR3_COMMON_TOKEN stopToken,pANTLR3_EXCEPTION e)239 errorNode				(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_TOKEN_STREAM ctnstream, pANTLR3_COMMON_TOKEN startToken, pANTLR3_COMMON_TOKEN stopToken, pANTLR3_EXCEPTION e)
240 {
241 	// Use the supplied common tree node stream to get another tree from the factory
242 	// TODO: Look at creating the erronode as in Java, but this is complicated by the
243 	// need to track and free the memory allocated to it, so for now, we just
244 	// want something in the tree that isn't a NULL pointer.
245 	//
246 	return adaptor->createTypeText(adaptor, ANTLR3_TOKEN_INVALID, (pANTLR3_UINT8)"Tree Error Node");
247 
248 }
249 
250 /** Duplicate the supplied node.
251  */
252 static	pANTLR3_BASE_TREE
dupNode(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_BASE_TREE treeNode)253 dupNode		(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE treeNode)
254 {
255 	return  treeNode == NULL ? NULL : treeNode->dupNode(treeNode);
256 }
257 
258 static	pANTLR3_BASE_TREE
create(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_COMMON_TOKEN payload)259 create		(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_COMMON_TOKEN payload)
260 {
261     pANTLR3_BASE_TREE	ct;
262 
263     /* Create a new common tree as this is what this adaptor deals with
264      */
265     ct = ((pANTLR3_COMMON_TREE_ADAPTOR)(adaptor->super))->arboretum->newFromToken(((pANTLR3_COMMON_TREE_ADAPTOR)(adaptor->super))->arboretum, payload);
266 
267     /* But all adaptors return the pointer to the base interface.
268      */
269     return  ct;
270 }
271 static	pANTLR3_BASE_TREE
dbgCreate(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_COMMON_TOKEN payload)272 dbgCreate		(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_COMMON_TOKEN payload)
273 {
274 	pANTLR3_BASE_TREE	ct;
275 
276 	ct = create(adaptor, payload);
277 	adaptor->debugger->createNode(adaptor->debugger, ct);
278 
279 	return ct;
280 }
281 
282 /** Tell me how to create a token for use with imaginary token nodes.
283  *  For example, there is probably no input symbol associated with imaginary
284  *  token DECL, but you need to create it as a payload or whatever for
285  *  the DECL node as in ^(DECL type ID).
286  *
287  *  If you care what the token payload objects' type is, you should
288  *  override this method and any other createToken variant.
289  */
290 static	pANTLR3_COMMON_TOKEN
createToken(pANTLR3_BASE_TREE_ADAPTOR adaptor,ANTLR3_UINT32 tokenType,pANTLR3_UINT8 text)291 createToken		(pANTLR3_BASE_TREE_ADAPTOR adaptor, ANTLR3_UINT32 tokenType, pANTLR3_UINT8 text)
292 {
293     pANTLR3_COMMON_TOKEN    newToken;
294 
295     newToken	= adaptor->tokenFactory->newToken(adaptor->tokenFactory);
296 
297     if	(newToken != NULL)
298     {
299 		newToken->textState		= ANTLR3_TEXT_CHARP;
300 		newToken->tokText.chars = (pANTLR3_UCHAR)text;
301 		newToken->setType(newToken, tokenType);
302 		newToken->input				= adaptor->tokenFactory->input;
303         newToken->strFactory        = adaptor->strFactory;
304     }
305     return  newToken;
306 }
307 
308 /** Tell me how to create a token for use with imaginary token nodes.
309  *  For example, there is probably no input symbol associated with imaginary
310  *  token DECL, but you need to create it as a payload or whatever for
311  *  the DECL node as in ^(DECL type ID).
312  *
313  *  This is a variant of createToken where the new token is derived from
314  *  an actual real input token.  Typically this is for converting '{'
315  *  tokens to BLOCK etc...  You'll see
316  *
317  *    r : lc='{' ID+ '}' -> ^(BLOCK[$lc] ID+) ;
318  *
319  *  If you care what the token payload objects' type is, you should
320  *  override this method and any other createToken variant.
321  *
322  * NB: this being C it is not so easy to extend the types of creaeteToken.
323  *     We will have to see if anyone needs to do this and add any variants to
324  *     this interface.
325  */
326 static	pANTLR3_COMMON_TOKEN
createTokenFromToken(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_COMMON_TOKEN fromToken)327 createTokenFromToken	(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_COMMON_TOKEN fromToken)
328 {
329     pANTLR3_COMMON_TOKEN    newToken;
330 
331     newToken	= adaptor->tokenFactory->newToken(adaptor->tokenFactory);
332 
333     if	(newToken != NULL)
334     {
335 		// Create the text using our own string factory to avoid complicating
336 		// commontoken.
337 		//
338 		pANTLR3_STRING	text;
339 
340 		newToken->toString  = fromToken->toString;
341 
342 		if	(fromToken->textState == ANTLR3_TEXT_CHARP)
343 		{
344 			newToken->textState		= ANTLR3_TEXT_CHARP;
345 			newToken->tokText.chars	= fromToken->tokText.chars;
346 		}
347 		else
348 		{
349 			text						= fromToken->getText(fromToken);
350 			newToken->textState			= ANTLR3_TEXT_STRING;
351 			newToken->tokText.text	    = adaptor->strFactory->newPtr(adaptor->strFactory, text->chars, text->len);
352 		}
353 
354 		newToken->setLine				(newToken, fromToken->getLine(fromToken));
355 		newToken->setTokenIndex			(newToken, fromToken->getTokenIndex(fromToken));
356 		newToken->setCharPositionInLine	(newToken, fromToken->getCharPositionInLine(fromToken));
357 		newToken->setChannel			(newToken, fromToken->getChannel(fromToken));
358 		newToken->setType				(newToken, fromToken->getType(fromToken));
359     }
360 
361     return  newToken;
362 }
363 
364 /* Specific methods for a TreeAdaptor */
365 
366 /** Track start/stop token for subtree root created for a rule.
367  *  Only works with CommonTree nodes.  For rules that match nothing,
368  *  seems like this will yield start=i and stop=i-1 in a nil node.
369  *  Might be useful info so I'll not force to be i..i.
370  */
371 static	void
setTokenBoundaries(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_BASE_TREE t,pANTLR3_COMMON_TOKEN startToken,pANTLR3_COMMON_TOKEN stopToken)372 setTokenBoundaries	(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t, pANTLR3_COMMON_TOKEN startToken, pANTLR3_COMMON_TOKEN stopToken)
373 {
374 	ANTLR3_MARKER   start;
375 	ANTLR3_MARKER   stop;
376 
377 	pANTLR3_COMMON_TREE	    ct;
378 
379 	if	(t == NULL)
380 	{
381 		return;
382 	}
383 
384 	if	( startToken != NULL)
385 	{
386 		start = startToken->getTokenIndex(startToken);
387 	}
388 	else
389 	{
390 		start = 0;
391 	}
392 
393 	if	( stopToken != NULL)
394 	{
395 		stop = stopToken->getTokenIndex(stopToken);
396 	}
397 	else
398 	{
399 		stop = 0;
400 	}
401 
402 	ct	= (pANTLR3_COMMON_TREE)(t->super);
403 
404 	ct->startIndex  = start;
405 	ct->stopIndex   = stop;
406 
407 }
408 static	void
dbgSetTokenBoundaries(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_BASE_TREE t,pANTLR3_COMMON_TOKEN startToken,pANTLR3_COMMON_TOKEN stopToken)409 dbgSetTokenBoundaries	(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t, pANTLR3_COMMON_TOKEN startToken, pANTLR3_COMMON_TOKEN stopToken)
410 {
411 	setTokenBoundaries(adaptor, t, startToken, stopToken);
412 
413 	if	(t != NULL && startToken != NULL && stopToken != NULL)
414 	{
415 		adaptor->debugger->setTokenBoundaries(adaptor->debugger, t, startToken->getTokenIndex(startToken), stopToken->getTokenIndex(stopToken));
416 	}
417 }
418 
419 static	ANTLR3_MARKER
getTokenStartIndex(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_BASE_TREE t)420 getTokenStartIndex	(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t)
421 {
422     return  ((pANTLR3_COMMON_TREE)(t->super))->startIndex;
423 }
424 
425 static	ANTLR3_MARKER
getTokenStopIndex(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_BASE_TREE t)426 getTokenStopIndex	(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t)
427 {
428     return  ((pANTLR3_COMMON_TREE)(t->super))->stopIndex;
429 }
430 
431 static	pANTLR3_STRING
getText(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_BASE_TREE t)432 getText		(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t)
433 {
434     return  t->getText(t);
435 }
436 
437 static	ANTLR3_UINT32
getType(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_BASE_TREE t)438 getType		(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t)
439 {
440     return  t->getType(t);
441 }
442 
443 static	void
replaceChildren(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_BASE_TREE parent,ANTLR3_INT32 startChildIndex,ANTLR3_INT32 stopChildIndex,pANTLR3_BASE_TREE t)444 replaceChildren
445 (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE parent, ANTLR3_INT32 startChildIndex, ANTLR3_INT32 stopChildIndex, pANTLR3_BASE_TREE t)
446 {
447 	if	(parent != NULL)
448 	{
449 		parent->replaceChildren(parent, startChildIndex, stopChildIndex, t);
450 	}
451 }
452 
453 static	pANTLR3_BASE_TREE
getChild(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_BASE_TREE t,ANTLR3_UINT32 i)454 getChild				(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t, ANTLR3_UINT32 i)
455 {
456 	return t->getChild(t, i);
457 }
458 static  void
setChild(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_BASE_TREE t,ANTLR3_UINT32 i,pANTLR3_BASE_TREE child)459 setChild				(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t, ANTLR3_UINT32 i, pANTLR3_BASE_TREE child)
460 {
461 	t->setChild(t, i, child);
462 }
463 
464 static	void
deleteChild(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_BASE_TREE t,ANTLR3_UINT32 i)465 deleteChild				(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t, ANTLR3_UINT32 i)
466 {
467 	t->deleteChild(t, i);
468 }
469 
470 static	ANTLR3_UINT32
getChildCount(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_BASE_TREE t)471 getChildCount			(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t)
472 {
473 	return t->getChildCount(t);
474 }
475 
476 static  void
setChildIndex(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_BASE_TREE t,ANTLR3_INT32 i)477 setChildIndex			(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t, ANTLR3_INT32 i)
478 {
479 	t->setChildIndex(t, i);
480 }
481 
482 static  ANTLR3_INT32
getChildIndex(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_BASE_TREE t)483 getChildIndex			(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t)
484 {
485 	return t->getChildIndex(t);
486 }
487 static	void
setParent(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_BASE_TREE child,pANTLR3_BASE_TREE parent)488 setParent				(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE child, pANTLR3_BASE_TREE parent)
489 {
490 	child->setParent(child, parent);
491 }
492 static	pANTLR3_BASE_TREE
getParent(pANTLR3_BASE_TREE_ADAPTOR adaptor,pANTLR3_BASE_TREE child)493 getParent				(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE child)
494 {
495 	return child->getParent(child);
496 }
497