antlr3rewritestreams.c File Reference


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.

#include <antlr3rewritestreams.h>

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.

Function Documentation

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

Here is the caller graph for this function:

static void add ( pANTLR3_REWRITE_RULE_ELEMENT_STREAM  stream,
void *  el,
void(ANTLR3_CDECL *freePtr)(void *)   
) [static]

static 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, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::add, ANTLR3_FALSE, ANTLR3_MALLOC, 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(), getDescription(), ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::getDescription, hasNext(), ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::hasNext, next(), ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::next, nextNode(), ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::nextNode, nextToken(), ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::nextToken, nextTree(), ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::nextTree, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::rec, ANTLR3_VECTOR_struct::remove, reset(), ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::reset, ANTLR3_RECOGNIZER_SHARED_STATE_struct::rStreams, ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::singleElement, size(), ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::size, ANTLR3_BASE_RECOGNIZER_struct::state, toTree(), and ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::toTree.

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

Here is the call graph for this function:

Here is the caller graph for this function:

static pANTLR3_REWRITE_RULE_ELEMENT_STREAM antlr3RewriteRuleElementStreamNewAEE ( pANTLR3_BASE_TREE_ADAPTOR  adaptor,
pANTLR3_BASE_RECOGNIZER  rec,
pANTLR3_UINT8  description,
void *  oneElement 
) [static]

References ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::add, and antlr3RewriteRuleElementStreamNewAE().

Referenced by antlr3RewriteRuleNODEStreamNewAEE(), antlr3RewriteRuleSubtreeStreamNewAEE(), and antlr3RewriteRuleTOKENStreamNewAEE().

Here is the call graph for this function:

Here is the caller graph for this function:

static pANTLR3_REWRITE_RULE_ELEMENT_STREAM antlr3RewriteRuleElementStreamNewAEV ( pANTLR3_BASE_TREE_ADAPTOR  adaptor,
pANTLR3_BASE_RECOGNIZER  rec,
pANTLR3_UINT8  description,
pANTLR3_VECTOR  vector 
) [static]

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 
) [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_FPRINTF.

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

Here is the caller graph for this function:

static 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, and ANTLR3_BASE_TREE_ADAPTOR_struct::dupNode.

static 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 ANTLR3_FPRINTF.

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

Here is the caller graph for this function:

static void expungeRS ( pANTLR3_REWRITE_RULE_ELEMENT_STREAM  stream  )  [static]

static void freeNodeRS ( pANTLR3_REWRITE_RULE_ELEMENT_STREAM  stream  )  [static]

static void freeRS ( pANTLR3_REWRITE_RULE_ELEMENT_STREAM  stream  )  [static]

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

Referenced by antlr3RewriteRuleElementStreamNewAE().

Here is the caller graph for this function:

static ANTLR3_BOOLEAN hasNext ( pANTLR3_REWRITE_RULE_ELEMENT_STREAM  stream  )  [static]

static 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 antlr3ExceptionFree(), and antlr3RewriteRuleElementStreamNewAE().

Here is the caller graph for this function:

static pANTLR3_BASE_TREE nextNode ( pANTLR3_REWRITE_RULE_ELEMENT_STREAM  stream  )  [static]

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(), antlr3RewriteRuleSubtreeStreamNewAEV(), intTrieAdd(), and intTrieGet().

Here is the caller graph for this function:

static pANTLR3_BASE_TREE nextNodeNode ( pANTLR3_REWRITE_RULE_ELEMENT_STREAM  stream  )  [static]

static pANTLR3_BASE_TREE nextNodeToken ( pANTLR3_REWRITE_RULE_ELEMENT_STREAM  stream  )  [static]

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, and ANTLR3_BASE_TREE_ADAPTOR_struct::create.

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

Here is the caller graph for this function:

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

static pANTLR3_BASE_TREE nextTree ( 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]. 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, and ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::size.

Referenced by antlr3RewriteRuleElementStreamNewAE().

Here is the caller graph for this function:

static 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, and ANTLR3_REWRITE_RULE_ELEMENT_STREAM_struct::dirty.

static ANTLR3_UINT32 size ( pANTLR3_REWRITE_RULE_ELEMENT_STREAM  stream  )  [static]

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.

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

Referenced by antlr3RewriteRuleElementStreamNewAE().

Here is the caller graph for this function:

static 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, and ANTLR3_BASE_TREE_ADAPTOR_struct::dupNode.

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

Here is the caller graph for this function:


Generated on Mon Nov 29 17:23:49 2010 for ANTLR3C by  doxygen 1.5.5