2 * Definition of the ANTLR3 base tree adaptor.
5 #ifndef _ANTLR3_BASE_TREE_ADAPTOR_H
6 #define _ANTLR3_BASE_TREE_ADAPTOR_H
9 // Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC
10 // http://www.temporal-wave.com
11 // http://www.linkedin.com/in/jimidle
13 // All rights reserved.
15 // Redistribution and use in source and binary forms, with or without
16 // modification, are permitted provided that the following conditions
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.
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.
37 #include <antlr3defs.h>
38 #include <antlr3collections.h>
39 #include <antlr3string.h>
40 #include <antlr3basetree.h>
41 #include <antlr3commontoken.h>
42 #include <antlr3debugeventlistener.h>
48 typedef struct ANTLR3_BASE_TREE_ADAPTOR_struct
50 /** Pointer to any enclosing structure/interface that
51 * contains this structure.
55 /** We need a string factory for creating imaginary tokens, we take this
56 * from the stream we are supplied to walk.
58 pANTLR3_STRING_FACTORY strFactory
;
60 /* And we also need a token factory for creating imaginary tokens
61 * this is also taken from the input source.
63 pANTLR3_TOKEN_FACTORY tokenFactory
;
65 /// If set to something other than NULL, then this structure is
66 /// points to an instance of the debugger interface. In general, the
67 /// debugger is only referenced internally in recovery/error operations
68 /// so that it does not cause overhead by having to check this pointer
69 /// in every function/method
71 pANTLR3_DEBUG_EVENT_LISTENER debugger
;
73 void * (*nilNode
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
);
76 void * (*dupTree
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * tree
);
77 void * (*dupTreeTT
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * t
, void * tree
);
79 void (*addChild
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * t
, void * child
);
80 void (*addChildToken
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * t
, pANTLR3_COMMON_TOKEN child
);
81 void (*setParent
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * child
, void * parent
);
82 void * (*getParent
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * child
);
84 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 ANTLR3_BOOLEAN (*isNilNode
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * t
);
87 void * (*becomeRoot
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * newRoot
, void * oldRoot
);
89 void * (*rulePostProcessing
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * root
);
91 void * (*becomeRootToken
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * newRoot
, void * oldRoot
);
93 void * (*create
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, pANTLR3_COMMON_TOKEN payload
);
94 void * (*createTypeToken
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, ANTLR3_UINT32 tokenType
, pANTLR3_COMMON_TOKEN fromToken
);
95 void * (*createTypeTokenText
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, ANTLR3_UINT32 tokenType
, pANTLR3_COMMON_TOKEN fromToken
, pANTLR3_UINT8 text
);
96 void * (*createTypeText
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, ANTLR3_UINT32 tokenType
, pANTLR3_UINT8 text
);
98 void * (*dupNode
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * treeNode
);
100 ANTLR3_UINT32 (*getType
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * t
);
102 void (*setType
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * t
, ANTLR3_UINT32 type
);
104 pANTLR3_STRING (*getText
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * t
);
106 void (*setText
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, pANTLR3_STRING t
);
107 void (*setText8
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, pANTLR3_UINT8 t
);
109 void * (*getChild
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * t
, ANTLR3_UINT32 i
);
110 void (*setChild
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * t
, ANTLR3_UINT32 i
, void * child
);
111 void (*deleteChild
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * t
, ANTLR3_UINT32 i
);
112 void (*setChildIndex
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * t
, ANTLR3_UINT32 i
);
113 ANTLR3_INT32 (*getChildIndex
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * t
);
115 ANTLR3_UINT32 (*getChildCount
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void *);
117 ANTLR3_UINT32 (*getUniqueID
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void *);
119 pANTLR3_COMMON_TOKEN (*createToken
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, ANTLR3_UINT32 tokenType
, pANTLR3_UINT8 text
);
120 pANTLR3_COMMON_TOKEN (*createTokenFromToken
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, pANTLR3_COMMON_TOKEN fromToken
);
121 pANTLR3_COMMON_TOKEN (*getToken
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * t
);
123 void (*setTokenBoundaries
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * t
, pANTLR3_COMMON_TOKEN startToken
, pANTLR3_COMMON_TOKEN stopToken
);
125 ANTLR3_MARKER (*getTokenStartIndex
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * t
);
127 ANTLR3_MARKER (*getTokenStopIndex
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * t
);
129 void (*setDebugEventListener
)(struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, pANTLR3_DEBUG_EVENT_LISTENER debugger
);
131 /// Produce a DOT (see graphviz freeware suite) from a base tree
133 pANTLR3_STRING (*makeDot
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * theTree
);
135 /// Replace from start to stop child index of parent with t, which might
136 /// be a list. Number of children may be different
139 /// If parent is null, don't do anything; must be at root of overall tree.
140 /// Can't replace whatever points to the parent externally. Do nothing.
142 void (*replaceChildren
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
, void * parent
, ANTLR3_INT32 startChildIndex
, ANTLR3_INT32 stopChildIndex
, void * t
);
144 void (*free
) (struct ANTLR3_BASE_TREE_ADAPTOR_struct
* adaptor
);
147 ANTLR3_TREE_ADAPTOR
, *pANTLR3_TREE_ADAPTOR
;