]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/cpp/DataBoardTest/libantlr3c-3.2/include/antlr3rewritestreams.h
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / cpp / DataBoardTest / libantlr3c-3.2 / include / antlr3rewritestreams.h
1 #ifndef ANTLR3REWRITESTREAM_H\r
2 #define ANTLR3REWRITESTREAM_H\r
3 \r
4 // [The "BSD licence"]\r
5 // Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC\r
6 // http://www.temporal-wave.com\r
7 // http://www.linkedin.com/in/jimidle\r
8 //\r
9 // All rights reserved.\r
10 //\r
11 // Redistribution and use in source and binary forms, with or without\r
12 // modification, are permitted provided that the following conditions\r
13 // are met:\r
14 // 1. Redistributions of source code must retain the above copyright\r
15 //    notice, this list of conditions and the following disclaimer.\r
16 // 2. Redistributions in binary form must reproduce the above copyright\r
17 //    notice, this list of conditions and the following disclaimer in the\r
18 //    documentation and/or other materials provided with the distribution.\r
19 // 3. The name of the author may not be used to endorse or promote products\r
20 //    derived from this software without specific prior written permission.\r
21 //\r
22 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
23 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
24 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
25 // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
27 // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
31 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
32 \r
33 #include    <antlr3defs.h>\r
34 #include    <antlr3collections.h>\r
35 #include    <antlr3commontreeadaptor.h>\r
36 #include        <antlr3baserecognizer.h>\r
37 \r
38 #ifdef __cplusplus\r
39 extern "C" {\r
40 #endif\r
41 \r
42 /// A generic list of elements tracked in an alternative to be used in\r
43 /// a -> rewrite rule.  \r
44 ///\r
45 /// In the C implementation, all tree oriented streams return a pointer to \r
46 /// the same type: pANTLR3_BASE_TREE. Anything that has subclassed from this\r
47 /// still passes this type, within which there is a super pointer, which points\r
48 /// to it's own data and methods. Hence we do not need to implement this as\r
49 /// the equivalent of an abstract class, but just fill in the appropriate interface\r
50 /// as usual with this model.\r
51 ///\r
52 /// Once you start next()ing, do not try to add more elements.  It will\r
53 /// break the cursor tracking I believe.\r
54 ///\r
55 /// \r
56 /// \see #pANTLR3_REWRITE_RULE_NODE_STREAM\r
57 /// \see #pANTLR3_REWRITE_RULE_ELEMENT_STREAM\r
58 /// \see #pANTLR3_REWRITE_RULE_SUBTREE_STREAM\r
59 ///\r
60 /// TODO: add mechanism to detect/puke on modification after reading from stream\r
61 ///\r
62 typedef struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct\r
63 {\r
64 \r
65     /// Cursor 0..n-1.  If singleElement!=NULL, cursor is 0 until you next(),\r
66     /// which bumps it to 1 meaning no more elements.\r
67     ///\r
68     ANTLR3_UINT32                 cursor;\r
69 \r
70     /// Track single elements w/o creating a list.  Upon 2nd add, alloc list \r
71     ///\r
72     void                        * singleElement;\r
73 \r
74     /// The list of tokens or subtrees we are tracking \r
75     ///\r
76     pANTLR3_VECTOR                elements;\r
77 \r
78     /// Indicates whether we should free the vector or it was supplied to us\r
79     ///\r
80     ANTLR3_BOOLEAN                freeElements;\r
81 \r
82     /// The element or stream description; usually has name of the token or\r
83     /// rule reference that this list tracks.  Can include rulename too, but\r
84     /// the exception would track that info.\r
85     ///\r
86     void                                * elementDescription;\r
87 \r
88         /// Pointer to the tree adaptor in use for this stream\r
89         ///\r
90     pANTLR3_BASE_TREE_ADAPTOR     adaptor;\r
91 \r
92         /// Once a node / subtree has been used in a stream, it must be dup'ed\r
93         /// from then on.  Streams are reset after sub rules so that the streams\r
94         /// can be reused in future sub rules.  So, reset must set a dirty bit.\r
95         /// If dirty, then next() always returns a dup.\r
96         ///\r
97         ANTLR3_BOOLEAN                          dirty;\r
98 \r
99         // Pointer to the recognizer shared state to which this stream belongs\r
100         //\r
101         pANTLR3_BASE_RECOGNIZER         rec;\r
102 \r
103     //   Methods \r
104 \r
105     /// Reset the condition of this stream so that it appears we have\r
106     ///  not consumed any of its elements.  Elements themselves are untouched.\r
107     ///\r
108     void                (*reset)                                (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream); \r
109 \r
110     /// Add a new pANTLR3_BASE_TREE to this stream\r
111     ///\r
112     void                (*add)                                  (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream, void *el, void (ANTLR3_CDECL *freePtr)(void *));\r
113 \r
114     /// Return the next element in the stream.  If out of elements, throw\r
115     /// an exception unless size()==1.  If size is 1, then return elements[0].\r
116     ///\r
117         void *                                  (*next)                                 (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream);\r
118     pANTLR3_BASE_TREE           (*nextTree)                             (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream);\r
119     void *                                      (*nextToken)                    (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream);\r
120     void *                                      (*_next)                                (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream);\r
121 \r
122     /// When constructing trees, sometimes we need to dup a token or AST\r
123     /// subtree.  Dup'ing a token means just creating another AST node\r
124     /// around it.  For trees, you must call the adaptor.dupTree().\r
125     ///\r
126     void *              (*dup)                                  (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream, void * el);\r
127 \r
128     /// Ensure stream emits trees; tokens must be converted to AST nodes.\r
129     /// AST nodes can be passed through unmolested.\r
130     ///\r
131     pANTLR3_BASE_TREE   (*toTree)               (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream, void * el);\r
132 \r
133     /// Returns ANTLR3_TRUE if there is a next element available\r
134     ///\r
135     ANTLR3_BOOLEAN      (*hasNext)                      (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream);\r
136 \r
137     /// Treat next element as a single node even if it's a subtree.\r
138     /// This is used instead of next() when the result has to be a\r
139     /// tree root node.  Also prevents us from duplicating recently-added\r
140     /// children; e.g., ^(type ID)+ adds ID to type and then 2nd iteration\r
141     /// must dup the type node, but ID has been added.\r
142     ///\r
143     /// Referencing to a rule result twice is ok; dup entire tree as\r
144     /// we can't be adding trees; e.g., expr expr. \r
145     ///\r
146     pANTLR3_BASE_TREE   (*nextNode)             (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream);\r
147 \r
148     /// Number of elements available in the stream\r
149     ///\r
150     ANTLR3_UINT32       (*size)                         (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream);\r
151 \r
152     /// Returns the description string if there is one available (check for NULL).\r
153     ///\r
154     void *                      (*getDescription)       (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream);\r
155 \r
156     void                (*free)                                 (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream);\r
157 \r
158 }\r
159     ANTLR3_REWRITE_RULE_ELEMENT_STREAM;\r
160 \r
161 /// This is an implementation of a token stream, which is basically an element\r
162 ///  stream that deals with tokens only.\r
163 ///\r
164 typedef struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct ANTLR3_REWRITE_RULE_TOKEN_STREAM;\r
165 \r
166 /// This is an implementation of a subtree stream which is a set of trees\r
167 ///  modelled as an element stream.\r
168 ///\r
169 typedef struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct ANTLR3_REWRITE_RULE_SUBTREE_STREAM;\r
170 \r
171 /// This is an implementation of a node stream, which is basically an element\r
172 ///  stream that deals with tree nodes only.\r
173 ///\r
174 typedef struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct ANTLR3_REWRITE_RULE_NODE_STREAM;\r
175 \r
176 #ifdef __cplusplus\r
177 }\r
178 #endif\r
179 \r
180 #endif\r