ANTLR3C 3.3.1
antlr3rewritestreams.c File Reference

Implementation of token/tree streams that are used by the tree re-write rules to manipulate the tokens and trees produced by rules that are subject to rewrite directives. More...

Include dependency graph for antlr3rewritestreams.c:

Functions

static void * _next (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream)
 Do the work of getting the next element, making sure that it's a tree node or subtree.
static void add (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream, void *el, void(ANTLR3_CDECL *freePtr)(void *))
static pANTLR3_REWRITE_RULE_ELEMENT_STREAM antlr3RewriteRuleElementStreamNewAE (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description)
static pANTLR3_REWRITE_RULE_ELEMENT_STREAM antlr3RewriteRuleElementStreamNewAEE (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description, void *oneElement)
static pANTLR3_REWRITE_RULE_ELEMENT_STREAM antlr3RewriteRuleElementStreamNewAEV (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description, pANTLR3_VECTOR vector)
ANTLR3_API pANTLR3_REWRITE_RULE_NODE_STREAM antlr3RewriteRuleNODEStreamNewAE (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description)
ANTLR3_API pANTLR3_REWRITE_RULE_NODE_STREAM antlr3RewriteRuleNODEStreamNewAEE (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description, void *oneElement)
ANTLR3_API pANTLR3_REWRITE_RULE_NODE_STREAM antlr3RewriteRuleNODEStreamNewAEV (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description, pANTLR3_VECTOR vector)
ANTLR3_API pANTLR3_REWRITE_RULE_SUBTREE_STREAM antlr3RewriteRuleSubtreeStreamNewAE (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description)
ANTLR3_API pANTLR3_REWRITE_RULE_SUBTREE_STREAM antlr3RewriteRuleSubtreeStreamNewAEE (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description, void *oneElement)
ANTLR3_API pANTLR3_REWRITE_RULE_SUBTREE_STREAM antlr3RewriteRuleSubtreeStreamNewAEV (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description, pANTLR3_VECTOR vector)
ANTLR3_API pANTLR3_REWRITE_RULE_TOKEN_STREAM antlr3RewriteRuleTOKENStreamNewAE (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description)
ANTLR3_API pANTLR3_REWRITE_RULE_TOKEN_STREAM antlr3RewriteRuleTOKENStreamNewAEE (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description, void *oneElement)
ANTLR3_API pANTLR3_REWRITE_RULE_TOKEN_STREAM antlr3RewriteRuleTOKENStreamNewAEV (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_RECOGNIZER rec, pANTLR3_UINT8 description, pANTLR3_VECTOR vector)
static void * dupTok (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream, void *el)
 When constructing trees, sometimes we need to dup a token or AST subtree.
static void * dupTree (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream, void *element)
 When constructing trees, sometimes we need to dup a token or AST subtree.
static void * dupTreeNode (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream, void *element)
 When constructing trees, sometimes we need to dup a token or AST subtree.
static void expungeRS (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream)
static void freeNodeRS (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream)
 Do special nilNode reuse detection for node streams.
static void freeRS (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream)
static void * getDescription (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream)
 Returns the description string if there is one available (check for NULL).
static ANTLR3_BOOLEAN hasNext (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream)
 Returns ANTLR3_TRUE if there is a next element available.
static void * next (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream)
 Return the next element in the stream.
static pANTLR3_BASE_TREE nextNode (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream)
 Treat next element as a single node even if it's a subtree.
static pANTLR3_BASE_TREE nextNodeNode (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream)
static pANTLR3_BASE_TREE nextNodeToken (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream)
 Get the next token from the list and create a node for it This is the implementation for token streams.
static void * nextToken (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream)
 Return the next element for a caller that wants just the token.
static pANTLR3_BASE_TREE nextTree (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream)
 Return the next element in the stream.
static void reset (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream)
 Reset the condition of this stream so that it appears we have not consumed any of its elements.
static ANTLR3_UINT32 size (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream)
 Number of elements available in the stream.
static pANTLR3_BASE_TREE toTree (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream, void *element)
 We don;t explicitly convert to a tree unless the call goes to nextTree, which means rewrites are heterogeneous.
static pANTLR3_BASE_TREE toTreeNode (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream, void *element)
 Ensure stream emits trees; tokens must be converted to AST nodes.

Detailed Description

Implementation of token/tree streams that are used by the tree re-write rules to manipulate the tokens and trees produced by rules that are subject to rewrite directives.

Function Documentation

◆ _next()

void * _next ( pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream)
static

Do the work of getting the next element, making sure that it's a tree node or subtree.

Deal with the optimization of single- element list versus list of size > 1. Throw an exception (or something similar) if the stream is empty or we're out of elements and size>1. You can override in a 'subclass' if necessary.

References _next(), ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::cursor, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::elements, ANTLR3_VECTOR_struct::get, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::singleElement, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::size, and ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::toTree.

Referenced by _next(), and antlr3RewriteRuleElementStreamNewAE().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add()

◆ antlr3RewriteRuleElementStreamNewAE()

pANTLR3_REWRITE_RULE_ELEMENT_STREAM antlr3RewriteRuleElementStreamNewAE ( pANTLR3_BASE_TREE_ADAPTOR adaptor,
pANTLR3_BASE_RECOGNIZER rec,
pANTLR3_UINT8 description )
static

References _next(), ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::_next, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::adaptor, add(), ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::add, ANTLR3_FALSE, antlr3RewriteRuleElementStreamNewAE(), ANTLR3_VECTOR_struct::count, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::cursor, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::dirty, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::elementDescription, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::elements, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::free, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::freeElements, freeRS(), ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::getDescription, getDescription(), ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::hasNext, hasNext(), ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::next, next(), ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::nextNode, nextNode(), ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::nextToken, nextToken(), ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::nextTree, nextTree(), ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::rec, ANTLR3_VECTOR_struct::remove, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::reset, reset(), ANTLR3_RECOGNIZER_SHARED_STATE_struct::rStreams, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::singleElement, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::size, size(), ANTLR3_BASE_RECOGNIZER_struct::state, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::toTree, and toTree().

Referenced by antlr3RewriteRuleElementStreamNewAE(), antlr3RewriteRuleElementStreamNewAEE(), antlr3RewriteRuleElementStreamNewAEV(), antlr3RewriteRuleNODEStreamNewAE(), antlr3RewriteRuleSubtreeStreamNewAE(), and antlr3RewriteRuleTOKENStreamNewAE().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ antlr3RewriteRuleElementStreamNewAEE()

◆ antlr3RewriteRuleElementStreamNewAEV()

◆ antlr3RewriteRuleNODEStreamNewAE()

◆ antlr3RewriteRuleNODEStreamNewAEE()

◆ antlr3RewriteRuleNODEStreamNewAEV()

◆ antlr3RewriteRuleSubtreeStreamNewAE()

◆ antlr3RewriteRuleSubtreeStreamNewAEE()

◆ antlr3RewriteRuleSubtreeStreamNewAEV()

◆ antlr3RewriteRuleTOKENStreamNewAE()

◆ antlr3RewriteRuleTOKENStreamNewAEE()

◆ antlr3RewriteRuleTOKENStreamNewAEV()

◆ dupTok()

void * dupTok ( pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream,
void * el )
static

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().

References dupTok().

Referenced by antlr3RewriteRuleTOKENStreamNewAE(), antlr3RewriteRuleTOKENStreamNewAEE(), antlr3RewriteRuleTOKENStreamNewAEV(), and dupTok().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dupTree()

void * dupTree ( pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream,
void * element )
static

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().

References ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::adaptor, ANTLR3_BASE_TREE_ADAPTOR_struct::dupNode, and dupTree().

Here is the call graph for this function:

◆ dupTreeNode()

void * dupTreeNode ( pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream,
void * element )
static

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().

References dupTreeNode().

Referenced by antlr3RewriteRuleNODEStreamNewAE(), antlr3RewriteRuleNODEStreamNewAEE(), antlr3RewriteRuleNODEStreamNewAEV(), and dupTreeNode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ expungeRS()

void expungeRS ( pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream)
static

References ANTLR3_TRUE, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::elements, expungeRS(), and ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::freeElements.

Referenced by expungeRS(), freeNodeRS(), and freeRS().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ freeNodeRS()

◆ freeRS()

◆ getDescription()

void * getDescription ( pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream)
static

Returns the description string if there is one available (check for NULL).

References ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::elementDescription, and getDescription().

Referenced by antlr3RewriteRuleElementStreamNewAE(), and getDescription().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasNext()

Returns ANTLR3_TRUE if there is a next element available.

References ANTLR3_FALSE, ANTLR3_TRUE, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::cursor, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::elements, hasNext(), ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::singleElement, and ANTLR3_VECTOR_struct::size.

Referenced by antlr3RewriteRuleElementStreamNewAE(), and hasNext().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ next()

void * next ( pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream)
static

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].

References ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::_next, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::cursor, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::dup, and ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::size.

Referenced by antlr3RewriteRuleElementStreamNewAE().

Here is the caller graph for this function:

◆ nextNode()

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.

References ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::_next, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::adaptor, ANTLR3_TRUE, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::cursor, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::dirty, ANTLR3_BASE_TREE_ADAPTOR_struct::dupNode, and ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::size.

Referenced by antlr3RewriteRuleElementStreamNewAE(), antlr3RewriteRuleSubtreeStreamNewAE(), antlr3RewriteRuleSubtreeStreamNewAEE(), and antlr3RewriteRuleSubtreeStreamNewAEV().

Here is the caller graph for this function:

◆ nextNodeNode()

References ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::_next, and nextNodeNode().

Referenced by antlr3RewriteRuleNODEStreamNewAE(), antlr3RewriteRuleNODEStreamNewAEE(), antlr3RewriteRuleNODEStreamNewAEV(), and nextNodeNode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nextNodeToken()

Get the next token from the list and create a node for it This is the implementation for token streams.

References ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::_next, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::adaptor, ANTLR3_BASE_TREE_ADAPTOR_struct::create, and nextNodeToken().

Referenced by antlr3RewriteRuleTOKENStreamNewAE(), antlr3RewriteRuleTOKENStreamNewAEE(), antlr3RewriteRuleTOKENStreamNewAEV(), and nextNodeToken().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nextToken()

void * nextToken ( pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream)
static

Return the next element for a caller that wants just the token.

References ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::_next, and nextToken().

Here is the call graph for this function:

◆ nextTree()

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]. Return a duplicate node/subtree if stream is out of elements and size==1. If we've already used the element, dup (dirty bit set).

References ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::_next, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::cursor, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::dirty, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::dup, nextTree(), and ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::size.

Referenced by antlr3RewriteRuleElementStreamNewAE(), and nextTree().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

void reset ( pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream)
static

Reset the condition of this stream so that it appears we have not consumed any of its elements.

Elements themselves are untouched.

References ANTLR3_TRUE, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::cursor, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::dirty, and reset().

Here is the call graph for this function:

◆ size()

Number of elements available in the stream.

Should be a count of one if singleElement is set. I copied this logic from the java implementation, which I suspect is just guarding against someone setting singleElement and forgetting to NULL it out

References ANTLR3_VECTOR_struct::count, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::elements, and ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::singleElement.

Referenced by antlr3RewriteRuleElementStreamNewAE().

Here is the caller graph for this function:

◆ toTree()

pANTLR3_BASE_TREE toTree ( pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream,
void * element )
static

We don;t explicitly convert to a tree unless the call goes to nextTree, which means rewrites are heterogeneous.

References toTree().

Referenced by antlr3RewriteRuleElementStreamNewAE(), and toTree().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toTreeNode()

pANTLR3_BASE_TREE toTreeNode ( pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream,
void * element )
static

Ensure stream emits trees; tokens must be converted to AST nodes.

AST nodes can be passed through unmolested.

References ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::adaptor, ANTLR3_BASE_TREE_ADAPTOR_struct::dupNode, and toTreeNode().

Referenced by antlr3RewriteRuleNODEStreamNewAE(), antlr3RewriteRuleNODEStreamNewAEE(), antlr3RewriteRuleNODEStreamNewAEV(), and toTreeNode().

Here is the call graph for this function:
Here is the caller graph for this function: