/// 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). /// static pANTLR3_BASE_TREE nextTree(pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream) { ANTLR3_UINT32 n; void * el; n = stream->size(stream); if ( stream->dirty || (stream->cursor >=n && n==1) ) { // if out of elements and size is 1, dup // el = stream->_next(stream); return stream->dup(stream, el); } // test size above then fetch // el = stream->_next(stream); return el; }
/* 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. */ static pANTLR3_BASE_TREE nextNode (pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream) { ANTLR3_UINT32 s; pANTLR3_BASE_TREE el = stream->_next(stream); s = stream->size(stream); if (stream->cursor > s && s == 1) { // We are out of elements and the size is 1, which means we just // dup the node that we have // return stream->adaptor->dupNode(stream->adaptor, el); } // We were not out of nodes, so the one we received is the one to return // return el; }
static pANTLR3_BASE_TREE nextNodeNode(pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream) { return stream->_next(stream); }
/// Get the next token from the list and create a node for it /// This is the implementation for token streams. /// static pANTLR3_BASE_TREE nextNodeToken(pANTLR3_REWRITE_RULE_ELEMENT_STREAM stream) { return stream->adaptor->create(stream->adaptor, stream->_next(stream)); }