#include <antlr3rewritestreams.h>
In the C implementation, all tree oriented streams return a pointer to the same type: pANTLR3_BASE_TREE. Anything that has subclassed from this still passes this type, within which there is a super pointer, which points to it's own data and methods. Hence we do not need to implement this as the equivalent of an abstract class, but just fill in the appropriate interface as usual with this model.
Once you start next()ing, do not try to add more elements. It will break the cursor tracking I believe.
TODO: add mechanism to detect/puke on modification after reading from stream
Data Fields | |
void *(* | _next )(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream) |
pANTLR3_BASE_TREE_ADAPTOR | adaptor |
Pointer to the tree adaptor in use for this stream. | |
void(* | add )(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream, void *el, void(ANTLR3_CDECL *freePtr)(void *)) |
Add a new pANTLR3_BASE_TREE to this stream. | |
ANTLR3_UINT32 | cursor |
Cursor 0. | |
ANTLR3_BOOLEAN | dirty |
Once a node / subtree has been used in a stream, it must be dup'ed from then on. | |
void *(* | dup )(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream, void *el) |
When constructing trees, sometimes we need to dup a token or AST subtree. | |
void * | elementDescription |
The element or stream description; usually has name of the token or rule reference that this list tracks. | |
pANTLR3_VECTOR | elements |
The list of tokens or subtrees we are tracking. | |
void(* | free )(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream) |
ANTLR3_BOOLEAN | freeElements |
Indicates whether we should free the vector or it was supplied to us. | |
void *(* | getDescription )(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream) |
Returns the description string if there is one available (check for NULL). | |
ANTLR3_BOOLEAN(* | hasNext )(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream) |
Returns ANTLR3_TRUE if there is a next element available. | |
void *(* | next )(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream) |
Return the next element in the stream. | |
pANTLR3_BASE_TREE(* | nextNode )(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream) |
Treat next element as a single node even if it's a subtree. | |
void *(* | nextToken )(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream) |
pANTLR3_BASE_TREE(* | nextTree )(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream) |
pANTLR3_BASE_RECOGNIZER | rec |
void(* | reset )(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream) |
Reset the condition of this stream so that it appears we have not consumed any of its elements. | |
void * | singleElement |
Track single elements w/o creating a list. | |
ANTLR3_UINT32(* | size )(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream) |
Number of elements available in the stream. | |
pANTLR3_BASE_TREE(* | toTree )(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream, void *el) |
Ensure stream emits trees; tokens must be converted to AST nodes. |
void*(* ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::_next)(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream) |
Referenced by antlr3RewriteRuleElementStreamNewAE(), next(), nextNode(), nextNodeNode(), nextNodeToken(), nextToken(), and nextTree().
Pointer to the tree adaptor in use for this stream.
Referenced by add(), antlr3RewriteRuleElementStreamNewAE(), dupTree(), freeNodeRS(), freeRS(), nextNode(), nextNodeToken(), and toTreeNode().
void(* ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::add)(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream, void *el, void(ANTLR3_CDECL *freePtr)(void *)) |
Add a new pANTLR3_BASE_TREE to this stream.
Referenced by antlr3RewriteRuleElementStreamNewAE(), and antlr3RewriteRuleElementStreamNewAEE().
Cursor 0.
.n-1. If singleElement!=NULL, cursor is 0 until you next(), which bumps it to 1 meaning no more elements.
Referenced by _next(), antlr3RewriteRuleElementStreamNewAE(), hasNext(), next(), nextNode(), nextTree(), and reset().
Once a node / subtree has been used in a stream, it must be dup'ed from then on.
Streams are reset after sub rules so that the streams can be reused in future sub rules. So, reset must set a dirty bit. If dirty, then next() always returns a dup.
Referenced by antlr3RewriteRuleElementStreamNewAE(), nextNode(), nextTree(), and reset().
void*(* ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::dup)(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream, void *el) |
When constructing trees, sometimes we need to dup a token or AST subtree.
Dup'ing a token means just creating another AST node around it. For trees, you must call the adaptor.dupTree().
Referenced by antlr3RewriteRuleNODEStreamNewAE(), antlr3RewriteRuleNODEStreamNewAEE(), antlr3RewriteRuleNODEStreamNewAEV(), antlr3RewriteRuleSubtreeStreamNewAE(), antlr3RewriteRuleSubtreeStreamNewAEE(), antlr3RewriteRuleSubtreeStreamNewAEV(), antlr3RewriteRuleTOKENStreamNewAE(), antlr3RewriteRuleTOKENStreamNewAEE(), antlr3RewriteRuleTOKENStreamNewAEV(), next(), and nextTree().
The element or stream description; usually has name of the token or rule reference that this list tracks.
Can include rulename too, but the exception would track that info.
Referenced by antlr3RewriteRuleElementStreamNewAE(), and getDescription().
The list of tokens or subtrees we are tracking.
Referenced by _next(), add(), antlr3RewriteRuleElementStreamNewAE(), antlr3RewriteRuleElementStreamNewAEV(), expungeRS(), freeNodeRS(), freeRS(), hasNext(), and size().
void(* ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::free)(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream) |
Indicates whether we should free the vector or it was supplied to us.
Referenced by add(), antlr3RewriteRuleElementStreamNewAE(), antlr3RewriteRuleElementStreamNewAEV(), expungeRS(), freeNodeRS(), and freeRS().
void*(* ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::getDescription)(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream) |
Returns the description string if there is one available (check for NULL).
Referenced by antlr3RewriteRuleElementStreamNewAE().
ANTLR3_BOOLEAN(* ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::hasNext)(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream) |
Returns ANTLR3_TRUE if there is a next element available.
Referenced by antlr3RewriteRuleElementStreamNewAE().
void*(* ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::next)(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream) |
Return the next element in the stream.
If out of elements, throw an exception unless size()==1. If size is 1, then return elements[0].
Referenced by antlr3RewriteRuleElementStreamNewAE().
pANTLR3_BASE_TREE(* ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::nextNode)(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream) |
Treat next element as a single node even if it's a subtree.
This is used instead of next() when the result has to be a tree root node. Also prevents us from duplicating recently-added children; e.g., ^(type ID)+ adds ID to type and then 2nd iteration must dup the type node, but ID has been added.
Referencing to a rule result twice is ok; dup entire tree as we can't be adding trees; e.g., expr expr.
Referenced by antlr3RewriteRuleElementStreamNewAE(), antlr3RewriteRuleNODEStreamNewAE(), antlr3RewriteRuleNODEStreamNewAEE(), antlr3RewriteRuleNODEStreamNewAEV(), antlr3RewriteRuleSubtreeStreamNewAE(), antlr3RewriteRuleSubtreeStreamNewAEE(), antlr3RewriteRuleSubtreeStreamNewAEV(), antlr3RewriteRuleTOKENStreamNewAE(), antlr3RewriteRuleTOKENStreamNewAEE(), and antlr3RewriteRuleTOKENStreamNewAEV().
void*(* ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::nextToken)(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream) |
Referenced by antlr3RewriteRuleElementStreamNewAE().
pANTLR3_BASE_TREE(* ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::nextTree)(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream) |
Referenced by antlr3RewriteRuleElementStreamNewAE().
Referenced by antlr3RewriteRuleElementStreamNewAE(), freeNodeRS(), and freeRS().
void(* ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::reset)(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream) |
Reset the condition of this stream so that it appears we have not consumed any of its elements.
Elements themselves are untouched.
Referenced by antlr3RewriteRuleElementStreamNewAE().
Track single elements w/o creating a list.
Upon 2nd add, alloc list
Referenced by _next(), add(), antlr3RewriteRuleElementStreamNewAE(), freeNodeRS(), hasNext(), and size().
ANTLR3_UINT32(* ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::size)(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream) |
Number of elements available in the stream.
Referenced by _next(), antlr3RewriteRuleElementStreamNewAE(), next(), nextNode(), and nextTree().
pANTLR3_BASE_TREE(* ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::toTree)(struct ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct *stream, void *el) |
Ensure stream emits trees; tokens must be converted to AST nodes.
AST nodes can be passed through unmolested.
Referenced by _next(), antlr3RewriteRuleElementStreamNewAE(), antlr3RewriteRuleNODEStreamNewAE(), antlr3RewriteRuleNODEStreamNewAEE(), and antlr3RewriteRuleNODEStreamNewAEV().