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