|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.antlr.runtime.tree.BufferedTreeNodeStream
public class BufferedTreeNodeStream
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... TARGET DEVELOPERS: This is the old CommonTreeNodeStream that buffered up entire node stream. No need to implement really as new CommonTreeNodeStream is much better and covers what we need.
CommonTreeNodeStream
Nested Class Summary | |
---|---|
protected class |
BufferedTreeNodeStream.StreamIterator
|
Field Summary | |
---|---|
protected IntArray |
calls
Stack of indexes used for push/pop calls |
static int |
DEFAULT_INITIAL_BUFFER_SIZE
|
protected java.lang.Object |
down
|
protected java.lang.Object |
eof
|
static int |
INITIAL_CALL_STACK_SIZE
|
protected int |
lastMarker
Track the last mark() call result value for use in rewind(). |
protected java.util.List |
nodes
The complete mapping from stream index to tree node. |
protected int |
p
The index into the nodes list of the current node (next node to consume). |
protected java.lang.Object |
root
Pull nodes from which tree? |
protected TokenStream |
tokens
IF this tree (root) was created from a token stream, track it. |
protected boolean |
uniqueNavigationNodes
Reuse same DOWN, UP navigation nodes unless this is true |
protected java.lang.Object |
up
|
Constructor Summary | |
---|---|
BufferedTreeNodeStream(java.lang.Object tree)
|
|
BufferedTreeNodeStream(TreeAdaptor adaptor,
java.lang.Object tree)
|
|
BufferedTreeNodeStream(TreeAdaptor adaptor,
java.lang.Object tree,
int initialBufferSize)
|
Method Summary | |
---|---|
protected void |
addNavigationNode(int ttype)
As we flatten the tree, we use UP, DOWN nodes to represent the tree structure. |
void |
consume()
|
protected void |
fillBuffer()
Walk tree with depth-first-search and fill nodes buffer. |
void |
fillBuffer(java.lang.Object t)
|
java.lang.Object |
get(int i)
Get a tree node at an absolute index i; 0..n-1. |
java.lang.Object |
getCurrentSymbol()
|
protected int |
getNodeIndex(java.lang.Object node)
What is the stream index for node? 0..n-1 Return -1 if node not found. |
java.lang.String |
getSourceName()
Where are you getting symbols from? Normally, implementations will pass the buck all the way to the lexer who can ask its input stream for the file name or whatever. |
TokenStream |
getTokenStream()
If the tree associated with this stream was created from a TokenStream, you can specify it here. |
TreeAdaptor |
getTreeAdaptor()
What adaptor can tell me how to interpret/navigate nodes and trees. |
java.lang.Object |
getTreeSource()
Where is this stream pulling nodes from? This is not the name, but the object that provides node objects. |
boolean |
hasUniqueNavigationNodes()
|
int |
index()
Return the current input symbol index 0..n where n indicates the last symbol has been read. |
java.util.Iterator |
iterator()
|
int |
LA(int i)
Get int at current input pointer + i ahead where i=1 is next int. |
protected java.lang.Object |
LB(int k)
Look backwards k nodes |
java.lang.Object |
LT(int k)
Get tree node at current input pointer + i ahead where i=1 is next node. |
int |
mark()
Tell the stream to start buffering if it hasn't already. |
int |
pop()
Seek back to previous index saved during last push() call. |
void |
push(int index)
Make stream jump to a new location, saving old location. |
void |
release(int marker)
You may want to commit to a backtrack but don't want to force the stream to keep bookkeeping objects around for a marker that is no longer necessary. |
void |
replaceChildren(java.lang.Object parent,
int startChildIndex,
int stopChildIndex,
java.lang.Object t)
Replace from start to stop child index of parent with t, which might be a list. |
void |
reset()
Reset the tree node stream in such a way that it acts like a freshly constructed stream. |
void |
rewind()
Rewind to the input position of the last marker. |
void |
rewind(int marker)
Reset the stream so that next call to index would return marker. |
void |
seek(int index)
Set the input cursor to the position indicated by index. |
void |
setTokenStream(TokenStream tokens)
|
void |
setTreeAdaptor(TreeAdaptor adaptor)
|
void |
setUniqueNavigationNodes(boolean uniqueNavigationNodes)
As we flatten the tree, we use UP, DOWN nodes to represent the tree structure. |
int |
size()
Only makes sense for streams that buffer everything up probably, but might be useful to display the entire stream or for testing. |
java.lang.String |
toString(java.lang.Object start,
java.lang.Object stop)
Return the text of all nodes from start to stop, inclusive. |
java.lang.String |
toTokenString(int start,
int stop)
Debugging |
java.lang.String |
toTokenTypeString()
Used for testing, just return the token type stream |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_INITIAL_BUFFER_SIZE
public static final int INITIAL_CALL_STACK_SIZE
protected java.lang.Object down
protected java.lang.Object up
protected java.lang.Object eof
protected java.util.List nodes
protected java.lang.Object root
protected TokenStream tokens
protected boolean uniqueNavigationNodes
protected int p
protected int lastMarker
protected IntArray calls
Constructor Detail |
---|
public BufferedTreeNodeStream(java.lang.Object tree)
public BufferedTreeNodeStream(TreeAdaptor adaptor, java.lang.Object tree)
public BufferedTreeNodeStream(TreeAdaptor adaptor, java.lang.Object tree, int initialBufferSize)
Method Detail |
---|
protected void fillBuffer()
public void fillBuffer(java.lang.Object t)
protected int getNodeIndex(java.lang.Object node)
protected void addNavigationNode(int ttype)
public java.lang.Object get(int i)
TreeNodeStream
get
in interface TreeNodeStream
public java.lang.Object LT(int k)
TreeNodeStream
LT
in interface TreeNodeStream
public java.lang.Object getCurrentSymbol()
protected java.lang.Object LB(int k)
public java.lang.Object getTreeSource()
TreeNodeStream
getTreeSource
in interface TreeNodeStream
public java.lang.String getSourceName()
IntStream
getSourceName
in interface IntStream
public TokenStream getTokenStream()
TreeNodeStream
getTokenStream
in interface TreeNodeStream
public void setTokenStream(TokenStream tokens)
public TreeAdaptor getTreeAdaptor()
TreeNodeStream
getTreeAdaptor
in interface TreeNodeStream
public void setTreeAdaptor(TreeAdaptor adaptor)
public boolean hasUniqueNavigationNodes()
public void setUniqueNavigationNodes(boolean uniqueNavigationNodes)
TreeNodeStream
setUniqueNavigationNodes
in interface TreeNodeStream
public void consume()
consume
in interface IntStream
public int LA(int i)
IntStream
LA
in interface IntStream
public int mark()
IntStream
mark
in interface IntStream
public void release(int marker)
IntStream
release
in interface IntStream
public int index()
IntStream
index
in interface IntStream
public void rewind(int marker)
IntStream
rewind
in interface IntStream
public void rewind()
IntStream
rewind
in interface IntStream
public void seek(int index)
IntStream
seek
in interface IntStream
public void push(int index)
public int pop()
public void reset()
TreeNodeStream
reset
in interface TreeNodeStream
public int size()
IntStream
size
in interface IntStream
public java.util.Iterator iterator()
public void replaceChildren(java.lang.Object parent, int startChildIndex, int stopChildIndex, java.lang.Object t)
TreeNodeStream
replaceChildren
in interface TreeNodeStream
public java.lang.String toTokenTypeString()
public java.lang.String toTokenString(int start, int stop)
public java.lang.String toString(java.lang.Object start, java.lang.Object stop)
TreeNodeStream
toString
in interface TreeNodeStream
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |