| java.lang.Object org.antlr.runtime.tree.CommonTreeNodeStream
CommonTreeNodeStream | public class CommonTreeNodeStream implements TreeNodeStream(Code) | | A buffered stream of tree nodes. Nodes can be from a tree of ANY kind.
This node stream sucks all nodes out of the tree specified in
the constructor during construction and makes pointers into
the tree using an array of Object pointers. The stream necessarily
includes pointers to DOWN and UP and EOF nodes.
This stream knows how to mark/release for backtracking.
This stream is most suitable for tree interpreters that need to
jump around a lot or for tree parsers requiring speed (at cost of memory).
There is some duplicated functionality here with UnBufferedTreeNodeStream
but just in bookkeeping, not tree walking etc...
See Also: UnBufferedTreeNodeStream |
Inner Class :protected class StreamIterator implements Iterator | |
Field Summary | |
final public static int | DEFAULT_INITIAL_BUFFER_SIZE | final public static Set | INDEX_ALL If tokenTypesToReverseIndex set to INDEX_ALL then indexing
occurs for all token types. | final public static int | INITIAL_CALL_STACK_SIZE | protected int | _sp Stack pointer for stack of indexes; -1 indicates empty. | TreeAdaptor | adaptor | protected int[] | calls | protected Object | down | protected Object | eof | protected int | lastMarker Track the last mark() call result value for use in rewind(). | protected List | nodes The complete mapping from stream index to tree node.
This buffer includes pointers to DOWN, UP, and EOF nodes.
It is built upon ctor invocation. | protected int | p The index into the nodes list of the current node (next node
to consume). | protected Object | root | protected Map | tokenTypeToStreamIndexesMap During fillBuffer(), we can make a reverse index from a set
of token types of interest to the list of indexes into the
node stream. | protected Set | tokenTypesToReverseIndex A set of token types user would like to index for faster lookup.
If this is INDEX_ALL, then all token types are tracked. | protected TokenStream | tokens IF this tree (root) was created from a token stream, track it. | protected boolean | uniqueNavigationNodes | protected Object | up |
DEFAULT_INITIAL_BUFFER_SIZE | final public static int DEFAULT_INITIAL_BUFFER_SIZE(Code) | | |
INDEX_ALL | final public static Set INDEX_ALL(Code) | | If tokenTypesToReverseIndex set to INDEX_ALL then indexing
occurs for all token types.
|
INITIAL_CALL_STACK_SIZE | final public static int INITIAL_CALL_STACK_SIZE(Code) | | |
_sp | protected int _sp(Code) | | Stack pointer for stack of indexes; -1 indicates empty. Points
at next location to push a value.
|
calls | protected int[] calls(Code) | | Stack of indexes used for push/pop calls
|
lastMarker | protected int lastMarker(Code) | | Track the last mark() call result value for use in rewind().
|
nodes | protected List nodes(Code) | | The complete mapping from stream index to tree node.
This buffer includes pointers to DOWN, UP, and EOF nodes.
It is built upon ctor invocation. The elements are type
Object as we don't what the trees look like.
Load upon first need of the buffer so we can set token types
of interest for reverseIndexing. Slows us down a wee bit to
do all of the if p==-1 testing everywhere though.
|
p | protected int p(Code) | | The index into the nodes list of the current node (next node
to consume). If -1, nodes array not filled yet.
|
tokenTypeToStreamIndexesMap | protected Map tokenTypeToStreamIndexesMap(Code) | | During fillBuffer(), we can make a reverse index from a set
of token types of interest to the list of indexes into the
node stream. This lets us convert a node pointer to a
stream index semi-efficiently for a list of interesting
nodes such as function definition nodes (you'll want to seek
to their bodies for an interpreter). Also useful for doing
dynamic searches; i.e., go find me all PLUS nodes.
|
tokenTypesToReverseIndex | protected Set tokenTypesToReverseIndex(Code) | | A set of token types user would like to index for faster lookup.
If this is INDEX_ALL, then all token types are tracked. If null,
then none are indexed.
|
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
|
CommonTreeNodeStream | public CommonTreeNodeStream(Object tree)(Code) | | |
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) | | |
fillBuffer | protected void fillBuffer()(Code) | | Walk tree with depth-first-search and fill nodes buffer.
Don't do DOWN, UP nodes if its a list (t is isNil).
|
fillReverseIndex | protected void fillReverseIndex(Object node, int streamIndex)(Code) | | Given a node, add this to the reverse index tokenTypeToStreamIndexesMap.
You can override this method to alter how indexing occurs. The
default is to create a
Map>
This data structure allows you to find all nodes with type INT in order.
If you really need to find a node of type, say, FUNC quickly then perhaps
Map>
would be better for you. The interior maps map a tree node to
the index so you don't have to search linearly for a specific node.
If you change this method, you will likely need to change
getNodeIndex(), which extracts information.
|
getNodeIndex | public int getNodeIndex(Object node)(Code) | | Given a node pointer, return its index into the node stream.
This is not its Token stream index. If there is no reverse map
from node to stream index or the map does not contain entries
for node's token type, a linear search of entire stream is used.
Return -1 if exact node pointer not in stream.
|
getNodeIndexLinearly | protected int getNodeIndexLinearly(Object node)(Code) | | |
hasUniqueNavigationNodes | public boolean hasUniqueNavigationNodes()(Code) | | |
pop | public int pop()(Code) | | Seek back to previous index saved during last push() call.
Return top of stack (return index).
|
push | public void push(int index)(Code) | | Make stream jump to a new location, saving old location.
Switch back with pop(). I manage dyanmic array manually
to avoid creating Integer objects all over the place.
|
release | public void release(int marker)(Code) | | |
reverseIndex | public void reverseIndex(int tokenType)(Code) | | Track the indicated token type in the reverse index. Call this
repeatedly for each type or use variant with Set argument to
set all at once.
Parameters: tokenType - |
reverseIndex | public void reverseIndex(Set tokenTypes)(Code) | | Track the indicated token types in the reverse index. Set
to INDEX_ALL to track all token types.
|
rewind | public void rewind(int marker)(Code) | | |
rewind | public void rewind()(Code) | | |
seek | public void seek(int index)(Code) | | |
setUniqueNavigationNodes | public void setUniqueNavigationNodes(boolean uniqueNavigationNodes)(Code) | | |
toString | public String toString()(Code) | | Used for testing, just return the token type stream
|
|
|