2 /// Definition of the ANTLR3 base tree.
\r
5 #ifndef _ANTLR3_BASE_TREE_H
\r
6 #define _ANTLR3_BASE_TREE_H
\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
13 // All rights reserved.
\r
15 // Redistribution and use in source and binary forms, with or without
\r
16 // modification, are permitted provided that the following conditions
\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
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
37 #include <antlr3defs.h>
\r
38 #include <antlr3collections.h>
\r
39 #include <antlr3string.h>
\r
45 /// A generic tree implementation with no payload. You must subclass to
\r
46 /// actually have any user data. ANTLR v3 uses a list of children approach
\r
47 /// instead of the child-sibling approach in v2. A flat tree (a list) is
\r
48 /// an empty node whose children represent the list. An empty (as in it does not
\r
49 /// have payload itself), but non-null node is called "nil".
\r
51 typedef struct ANTLR3_BASE_TREE_struct
\r
54 /// Implementers of this interface sometimes require a pointer to their selves.
\r
58 /// Generic void pointer allows the grammar programmer to attach any structure they
\r
59 /// like to a tree node, in many cases saving the need to create their own tree
\r
60 /// and tree adaptors. ANTLR does not use this pointer, but will copy it for you and so on.
\r
64 /// The list of all the children that belong to this node. They are not part of the node
\r
65 /// as they belong to the common tree node that implements this.
\r
67 pANTLR3_VECTOR children;
\r
69 /// This is used to store the current child index position while descending
\r
70 /// and ascending trees as the tree walk progresses.
\r
72 ANTLR3_MARKER savedIndex;
\r
74 /// A string factory to produce strings for toString etc
\r
76 pANTLR3_STRING_FACTORY strFactory;
\r
78 /// A pointer to a function that returns the common token pointer
\r
79 /// for the payload in the supplied tree.
\r
81 pANTLR3_COMMON_TOKEN (*getToken) (struct ANTLR3_BASE_TREE_struct * tree);
\r
83 void (*addChild) (struct ANTLR3_BASE_TREE_struct * tree, void * child);
\r
85 void (*addChildren) (struct ANTLR3_BASE_TREE_struct * tree, pANTLR3_LIST kids);
\r
87 void (*createChildrenList) (struct ANTLR3_BASE_TREE_struct * tree);
\r
89 void * (*deleteChild) (struct ANTLR3_BASE_TREE_struct * tree, ANTLR3_UINT32 i);
\r
91 void (*replaceChildren) (struct ANTLR3_BASE_TREE_struct * parent, ANTLR3_INT32 startChildIndex, ANTLR3_INT32 stopChildIndex, struct ANTLR3_BASE_TREE_struct * t);
\r
93 void * (*dupNode) (struct ANTLR3_BASE_TREE_struct * dupNode);
\r
95 void * (*dupTree) (struct ANTLR3_BASE_TREE_struct * tree);
\r
97 ANTLR3_UINT32 (*getCharPositionInLine) (struct ANTLR3_BASE_TREE_struct * tree);
\r
99 void * (*getChild) (struct ANTLR3_BASE_TREE_struct * tree, ANTLR3_UINT32 i);
\r
101 void (*setChildIndex) (struct ANTLR3_BASE_TREE_struct * tree, ANTLR3_INT32 );
\r
103 ANTLR3_INT32 (*getChildIndex) (struct ANTLR3_BASE_TREE_struct * tree );
\r
105 ANTLR3_UINT32 (*getChildCount) (struct ANTLR3_BASE_TREE_struct * tree);
\r
107 struct ANTLR3_BASE_TREE_struct * (*getParent) (struct ANTLR3_BASE_TREE_struct * tree);
\r
109 void (*setParent) (struct ANTLR3_BASE_TREE_struct * tree, struct ANTLR3_BASE_TREE_struct * parent);
\r
111 ANTLR3_UINT32 (*getType) (struct ANTLR3_BASE_TREE_struct * tree);
\r
113 void * (*getFirstChildWithType) (struct ANTLR3_BASE_TREE_struct * tree, ANTLR3_UINT32 type);
\r
115 ANTLR3_UINT32 (*getLine) (struct ANTLR3_BASE_TREE_struct * tree);
\r
117 pANTLR3_STRING (*getText) (struct ANTLR3_BASE_TREE_struct * tree);
\r
119 ANTLR3_BOOLEAN (*isNilNode) (struct ANTLR3_BASE_TREE_struct * tree);
\r
121 void (*setChild) (struct ANTLR3_BASE_TREE_struct * tree, ANTLR3_UINT32 i, void * child);
\r
123 pANTLR3_STRING (*toStringTree) (struct ANTLR3_BASE_TREE_struct * tree);
\r
125 pANTLR3_STRING (*toString) (struct ANTLR3_BASE_TREE_struct * tree);
\r
127 void (*freshenPACIndexesAll) (struct ANTLR3_BASE_TREE_struct * tree);
\r
129 void (*freshenPACIndexes) (struct ANTLR3_BASE_TREE_struct * tree, ANTLR3_UINT32 offset);
\r
131 void (*reuse) (struct ANTLR3_BASE_TREE_struct * tree);
\r
133 void (*free) (struct ANTLR3_BASE_TREE_struct * tree);
\r