]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.databoard/cpp/DataBoardTest/libantlr3c-3.2/include/antlr3rewritestreams.h b/bundles/org.simantics.databoard/cpp/DataBoardTest/libantlr3c-3.2/include/antlr3rewritestreams.h
new file mode 100644 (file)
index 0000000..5e722c6
--- /dev/null
@@ -0,0 +1,180 @@
+#ifndef        ANTLR3REWRITESTREAM_H\r
+#define        ANTLR3REWRITESTREAM_H\r
+\r
+// [The "BSD licence"]\r
+// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC\r
+// http://www.temporal-wave.com\r
+// http://www.linkedin.com/in/jimidle\r
+//\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions\r
+// are met:\r
+// 1. Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+// 2. Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the distribution.\r
+// 3. The name of the author may not be used to endorse or promote products\r
+//    derived from this software without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+#include    <antlr3defs.h>\r
+#include    <antlr3collections.h>\r
+#include    <antlr3commontreeadaptor.h>\r
+#include       <antlr3baserecognizer.h>\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/// A generic list of elements tracked in an alternative to be used in\r
+/// a -> rewrite rule.  \r
+///\r
+/// In the C implementation, all tree oriented streams return a pointer to \r
+/// the same type: pANTLR3_BASE_TREE. Anything that has subclassed from this\r
+/// still passes this type, within which there is a super pointer, which points\r
+/// to it's own data and methods. Hence we do not need to implement this as\r
+/// the equivalent of an abstract class, but just fill in the appropriate interface\r
+/// as usual with this model.\r
+///\r
+/// Once you start next()ing, do not try to add more elements.  It will\r
+/// break the cursor tracking I believe.\r
+///\r
+/// \r
+/// \see #pANTLR3_REWRITE_RULE_NODE_STREAM\r
+/// \see #pANTLR3_REWRITE_RULE_ELEMENT_STREAM\r
+/// \see #pANTLR3_REWRITE_RULE_SUBTREE_STREAM\r
+///\r
+/// TODO: add mechanism to detect/puke on modification after reading from stream\r
+///\r
+typedef struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct\r
+{\r
+\r
+    /// Cursor 0..n-1.  If singleElement!=NULL, cursor is 0 until you next(),\r
+    /// which bumps it to 1 meaning no more elements.\r
+    ///\r
+    ANTLR3_UINT32                cursor;\r
+\r
+    /// Track single elements w/o creating a list.  Upon 2nd add, alloc list \r
+    ///\r
+    void                       * singleElement;\r
+\r
+    /// The list of tokens or subtrees we are tracking \r
+    ///\r
+    pANTLR3_VECTOR               elements;\r
+\r
+    /// Indicates whether we should free the vector or it was supplied to us\r
+    ///\r
+    ANTLR3_BOOLEAN               freeElements;\r
+\r
+    /// The element or stream description; usually has name of the token or\r
+    /// rule reference that this list tracks.  Can include rulename too, but\r
+    /// the exception would track that info.\r
+    ///\r
+    void                               * elementDescription;\r
+\r
+       /// Pointer to the tree adaptor in use for this stream\r
+       ///\r
+    pANTLR3_BASE_TREE_ADAPTOR    adaptor;\r
+\r
+       /// Once a node / subtree has been used in a stream, it must be dup'ed\r
+       /// from then on.  Streams are reset after sub rules so that the streams\r
+       /// can be reused in future sub rules.  So, reset must set a dirty bit.\r
+       /// If dirty, then next() always returns a dup.\r
+       ///\r
+       ANTLR3_BOOLEAN                          dirty;\r
+\r
+       // Pointer to the recognizer shared state to which this stream belongs\r
+       //\r
+       pANTLR3_BASE_RECOGNIZER         rec;\r
+\r
+    //   Methods \r
+\r
+    /// Reset the condition of this stream so that it appears we have\r
+    ///  not consumed any of its elements.  Elements themselves are untouched.\r
+    ///\r
+    void               (*reset)                                (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream); \r
+\r
+    /// Add a new pANTLR3_BASE_TREE to this stream\r
+    ///\r
+    void               (*add)                                  (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream, void *el, void (ANTLR3_CDECL *freePtr)(void *));\r
+\r
+    /// Return the next element in the stream.  If out of elements, throw\r
+    /// an exception unless size()==1.  If size is 1, then return elements[0].\r
+    ///\r
+       void *                                  (*next)                                 (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream);\r
+    pANTLR3_BASE_TREE          (*nextTree)                             (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream);\r
+    void *                                     (*nextToken)                    (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream);\r
+    void *                                     (*_next)                                (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream);\r
+\r
+    /// When constructing trees, sometimes we need to dup a token or AST\r
+    ///        subtree.  Dup'ing a token means just creating another AST node\r
+    /// around it.  For trees, you must call the adaptor.dupTree().\r
+    ///\r
+    void *             (*dup)                                  (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream, void * el);\r
+\r
+    /// Ensure stream emits trees; tokens must be converted to AST nodes.\r
+    /// AST nodes can be passed through unmolested.\r
+    ///\r
+    pANTLR3_BASE_TREE  (*toTree)               (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream, void * el);\r
+\r
+    /// Returns ANTLR3_TRUE if there is a next element available\r
+    ///\r
+    ANTLR3_BOOLEAN     (*hasNext)                      (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream);\r
+\r
+    /// Treat next element as a single node even if it's a subtree.\r
+    /// This is used instead of next() when the result has to be a\r
+    /// tree root node.  Also prevents us from duplicating recently-added\r
+    /// children; e.g., ^(type ID)+ adds ID to type and then 2nd iteration\r
+    /// must dup the type node, but ID has been added.\r
+    ///\r
+    /// Referencing to a rule result twice is ok; dup entire tree as\r
+    /// we can't be adding trees; e.g., expr expr. \r
+    ///\r
+    pANTLR3_BASE_TREE  (*nextNode)             (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream);\r
+\r
+    /// Number of elements available in the stream\r
+    ///\r
+    ANTLR3_UINT32      (*size)                         (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream);\r
+\r
+    /// Returns the description string if there is one available (check for NULL).\r
+    ///\r
+    void *                     (*getDescription)       (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream);\r
+\r
+    void               (*free)                                 (struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct * stream);\r
+\r
+}\r
+    ANTLR3_REWRITE_RULE_ELEMENT_STREAM;\r
+\r
+/// This is an implementation of a token stream, which is basically an element\r
+///  stream that deals with tokens only.\r
+///\r
+typedef struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct ANTLR3_REWRITE_RULE_TOKEN_STREAM;\r
+\r
+/// This is an implementation of a subtree stream which is a set of trees\r
+///  modelled as an element stream.\r
+///\r
+typedef struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct ANTLR3_REWRITE_RULE_SUBTREE_STREAM;\r
+\r
+/// This is an implementation of a node stream, which is basically an element\r
+///  stream that deals with tree nodes only.\r
+///\r
+typedef struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct ANTLR3_REWRITE_RULE_NODE_STREAM;\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r