| java.lang.Object org.antlr.runtime.tree.UnBufferedTreeNodeStream
UnBufferedTreeNodeStream | public class UnBufferedTreeNodeStream implements TreeNodeStream(Code) | | A stream of tree nodes, accessing nodes from a tree of ANY kind.
No new nodes should be created in tree during the walk. A small buffer
of tokens is kept to efficiently and easily handle LT(i) calls, though
the lookahead mechanism is fairly complicated.
For tree rewriting during tree parsing, this must also be able
to replace a set of children without "losing its place".
That part is not yet implemented. Will permit a rule to return
a different tree and have it stitched into the output tree probably.
See Also: CommonTreeNodeStream |
Inner Class :protected class TreeWalkState | |
INITIAL_LOOKAHEAD_BUFFER_SIZE | final public static int INITIAL_LOOKAHEAD_BUFFER_SIZE(Code) | | |
absoluteNodeIndex | protected int absoluteNodeIndex(Code) | | What node index did we just consume? i=0..n-1 for n node trees.
IntStream.next is hence 1 + this value. Size will be same.
|
currentChildIndex | protected int currentChildIndex(Code) | | Which child are we currently visiting? If -1 we have not visited
this node yet; next consume() request will set currentIndex to 0.
|
currentNode | protected Object currentNode(Code) | | Which node are we currently visiting?
|
head | protected int head(Code) | | lookahead[head] is the first symbol of lookahead, LT(1).
|
indexStack | protected Stack indexStack(Code) | | Track which child index you are visiting for each node we push.
TODO: pretty inefficient...use int[] when you have time
|
lastMarker | protected int lastMarker(Code) | | Track the last mark() call result value for use in rewind().
|
lookahead | protected Object[] lookahead(Code) | | Buffer tree node stream for use with LT(i). This list grows
to fit new lookahead depths, but consume() wraps like a circular
buffer.
|
markDepth | protected int markDepth(Code) | | tracks how deep mark() calls are nested
|
markers | protected List markers(Code) | | Calls to mark() may be nested so we have to track a stack of
them. The marker is an index into this stack.
This is a List. Indexed from 1..markDepth.
A null is kept @ index 0. Create upon first call to mark().
|
nodeStack | protected Stack nodeStack(Code) | | As we walk down the nodes, we must track parent nodes so we know
where to go after walking the last child of a node. When visiting
a child, push current node and current index.
|
previousNode | protected Object previousNode(Code) | | Which node did we visit last? Used for LT(-1) calls.
|
tail | protected int tail(Code) | | Add new lookahead at lookahead[tail]. tail wraps around at the
end of the lookahead buffer so tail could be less than head.
|
tokens | protected TokenStream tokens(Code) | | IF this tree (root) was created from a token stream, track it.
|
uniqueNavigationNodes | protected boolean uniqueNavigationNodes(Code) | | Reuse same DOWN, UP navigation nodes unless this is true
|
UnBufferedTreeNodeStream | public UnBufferedTreeNodeStream(Object tree)(Code) | | |
LT | public Object LT(int k)(Code) | | Get tree node at current input pointer + i ahead where i=1 is next node.
i<0 indicates nodes in the past. So -1 is previous node and -2 is
two nodes ago. LT(0) is undefined. For i>=n, return null.
Return null for LT(0) and any index that results in an absolute address
that is negative.
This is analogus to the LT() method of the TokenStream, but this
returns a tree node instead of a token. Makes code gen identical
for both parser and tree grammars. :)
|
addLookahead | protected void addLookahead(Object node)(Code) | | Add a node to the lookahead buffer. Add at lookahead[tail].
If you tail+1 == head, then we must create a bigger buffer
and copy all the nodes over plus reset head, tail. After
this method, LT(1) will be lookahead[0].
|
addNavigationNode | protected void addNavigationNode(int ttype)(Code) | | As we flatten the tree, we use UP, DOWN nodes to represent
the tree structure. When debugging we need unique nodes
so instantiate new ones when uniqueNavigationNodes is true.
|
consume | public void consume()(Code) | | |
fill | protected void fill(int k)(Code) | | Make sure we have at least k symbols in lookahead buffer
|
getLookaheadSize | protected int getLookaheadSize()(Code) | | |
getTreeSource | public Object getTreeSource()(Code) | | Where is this stream pulling nodes from? This is not the name, but
the object that provides node objects.
|
hasUniqueNavigationNodes | public boolean hasUniqueNavigationNodes()(Code) | | |
mark | public int mark()(Code) | | Record the current state of the tree walk which includes
the current node and stack state as well as the lookahead
buffer.
|
next | public Object next()(Code) | | Return the next node found during a depth-first walk of root.
Also, add these nodes and DOWN/UP imaginary nodes into the lokoahead
buffer as a side-effect. Normally side-effects are bad, but because
we can emit many tokens for every next() call, it's pretty hard to
use a single return value for that. We must add these tokens to
the lookahead buffer.
This does *not* return the DOWN/UP nodes; those are only returned
by the LT() method.
Ugh. This mechanism is much more complicated than a recursive
solution, but it's the only way to provide nodes on-demand instead
of walking once completely through and buffering up the nodes. :(
|
release | public void release(int marker)(Code) | | |
reset | public void reset()(Code) | | |
rewind | public void rewind(int marker)(Code) | | Rewind the current state of the tree walk to the state it
was in when mark() was called and it returned marker. Also,
wipe out the lookahead which will force reloading a few nodes
but it is better than making a copy of the lookahead buffer
upon mark().
|
rewind | public void rewind()(Code) | | |
seek | public void seek(int index)(Code) | | consume() ahead until we hit index. Can't just jump ahead--must
spit out the navigation nodes.
|
setUniqueNavigationNodes | public void setUniqueNavigationNodes(boolean uniqueNavigationNodes)(Code) | | |
size | public int size()(Code) | | Expensive to compute; recursively walk tree to find size;
include navigation nodes and EOF. Reuse functionality
in CommonTreeNodeStream as we only really use this
for testing.
|
toString | public String toString()(Code) | | Print out the entire tree including DOWN/UP nodes. Uses
a recursive walk. Mostly useful for testing as it yields
the token types not text.
|
walkBackToMostRecentNodeWithUnvisitedChildren | protected void walkBackToMostRecentNodeWithUnvisitedChildren()(Code) | | Walk upwards looking for a node with more children to walk.
|
|
|