

Public Member Functions | |
| UnBufferedTreeNodeStream (Object tree) | |
| UnBufferedTreeNodeStream (TreeAdaptor adaptor, Object tree) | |
| void | reset () |
| Object | get (int i) |
| Object | LT (int k) |
| Object | getTreeSource () |
| String | getSourceName () |
| TokenStream | getTokenStream () |
| void | setTokenStream (TokenStream tokens) |
| void | consume () |
| int | LA (int i) |
| int | mark () |
| void | release (int marker) |
| void | rewind (int marker) |
| void | rewind () |
| void | seek (int index) |
| int | index () |
| int | size () |
| Object | next () |
| TreeAdaptor | getTreeAdaptor () |
| boolean | hasUniqueNavigationNodes () |
| void | setUniqueNavigationNodes (boolean uniqueNavigationNodes) |
| void | replaceChildren (Object parent, int startChildIndex, int stopChildIndex, Object t) |
| String | toString () |
| String | toString (Object start, Object stop) |
Static Public Attributes | |
| static final int | INITIAL_LOOKAHEAD_BUFFER_SIZE = 5 |
Protected Member Functions | |
| void | fill (int k) |
| void | addLookahead (Object node) |
| Object | handleRootNode () |
| Object | visitChild (int child) |
| void | addNavigationNode (final int ttype) |
| void | walkBackToMostRecentNodeWithUnvisitedChildren () |
| int | getLookaheadSize () |
| void | toStringWork (Object p, Object stop, StringBuffer buf) |
Protected Attributes | |
| boolean | uniqueNavigationNodes = false |
| Object | root |
| TokenStream | tokens |
| Stack | nodeStack = new Stack() |
| Stack | indexStack = new Stack() |
| Object | currentNode |
| Object | previousNode |
| int | currentChildIndex |
| int | absoluteNodeIndex |
| Object[] | lookahead = new Object[INITIAL_LOOKAHEAD_BUFFER_SIZE] |
| int | head |
| int | tail |
| List | markers |
| int | markDepth = 0 |
| int | lastMarker |
| Object | down |
| Object | up |
| Object | eof |
Package Attributes | |
| TreeAdaptor | adaptor |
Classes | |
| class | TreeWalkState |
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.
Definition at line 49 of file UnBufferedTreeNodeStream.java.
| org.antlr.runtime.tree.UnBufferedTreeNodeStream.UnBufferedTreeNodeStream | ( | Object | tree | ) |
Definition at line 141 of file UnBufferedTreeNodeStream.java.
| org.antlr.runtime.tree.UnBufferedTreeNodeStream.UnBufferedTreeNodeStream | ( | TreeAdaptor | adaptor, | |
| Object | tree | |||
| ) |
Definition at line 145 of file UnBufferedTreeNodeStream.java.
| void org.antlr.runtime.tree.UnBufferedTreeNodeStream.reset | ( | ) |
Definition at line 154 of file UnBufferedTreeNodeStream.java.
| Object org.antlr.runtime.tree.UnBufferedTreeNodeStream.get | ( | int | i | ) |
Get a tree node at an absolute index i; 0..n-1. If you don't want to buffer up nodes, then this method makes no sense for you.
Implements org.antlr.runtime.tree.TreeNodeStream.
Definition at line 164 of file UnBufferedTreeNodeStream.java.
| Object org.antlr.runtime.tree.UnBufferedTreeNodeStream.LT | ( | int | k | ) |
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. :)
Implements org.antlr.runtime.tree.TreeNodeStream.
Definition at line 178 of file UnBufferedTreeNodeStream.java.
| Object org.antlr.runtime.tree.UnBufferedTreeNodeStream.getTreeSource | ( | ) |
Where is this stream pulling nodes from? This is not the name, but the object that provides node objects.
Implements org.antlr.runtime.tree.TreeNodeStream.
Definition at line 196 of file UnBufferedTreeNodeStream.java.
| String org.antlr.runtime.tree.UnBufferedTreeNodeStream.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.
Implements org.antlr.runtime.IntStream.
Definition at line 200 of file UnBufferedTreeNodeStream.java.
| TokenStream org.antlr.runtime.tree.UnBufferedTreeNodeStream.getTokenStream | ( | ) |
If the tree associated with this stream was created from a TokenStream, you can specify it here. Used to do rule $text attribute in tree parser. Optional unless you use tree parser rule text attribute or output=template and rewrite=true options.
Implements org.antlr.runtime.tree.TreeNodeStream.
Definition at line 204 of file UnBufferedTreeNodeStream.java.
| void org.antlr.runtime.tree.UnBufferedTreeNodeStream.setTokenStream | ( | TokenStream | tokens | ) |
Definition at line 208 of file UnBufferedTreeNodeStream.java.
| void org.antlr.runtime.tree.UnBufferedTreeNodeStream.fill | ( | int | k | ) | [protected] |
Make sure we have at least k symbols in lookahead buffer
Definition at line 213 of file UnBufferedTreeNodeStream.java.
| void org.antlr.runtime.tree.UnBufferedTreeNodeStream.addLookahead | ( | Object | node | ) | [protected] |
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].
Definition at line 226 of file UnBufferedTreeNodeStream.java.
| void org.antlr.runtime.tree.UnBufferedTreeNodeStream.consume | ( | ) |
Implements org.antlr.runtime.IntStream.
Definition at line 247 of file UnBufferedTreeNodeStream.java.
| int org.antlr.runtime.tree.UnBufferedTreeNodeStream.LA | ( | int | i | ) |
Get int at current input pointer + i ahead where i=1 is next int. Negative indexes are allowed. LA(-1) is previous token (token just matched). LA(-i) where i is before first token should yield -1, invalid char / EOF.
Implements org.antlr.runtime.IntStream.
Definition at line 260 of file UnBufferedTreeNodeStream.java.
| int org.antlr.runtime.tree.UnBufferedTreeNodeStream.mark | ( | ) |
Record the current state of the tree walk which includes the current node and stack state as well as the lookahead buffer.
Implements org.antlr.runtime.IntStream.
Definition at line 272 of file UnBufferedTreeNodeStream.java.
| void org.antlr.runtime.tree.UnBufferedTreeNodeStream.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. This will have the same behavior as rewind() except it releases resources without the backward seek. This must throw away resources for all markers back to the marker argument. So if you're nested 5 levels of mark(), and then release(2) you have to release resources for depths 2..5.
Implements org.antlr.runtime.IntStream.
Definition at line 303 of file UnBufferedTreeNodeStream.java.
| void org.antlr.runtime.tree.UnBufferedTreeNodeStream.rewind | ( | int | marker | ) |
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().
Implements org.antlr.runtime.IntStream.
Definition at line 316 of file UnBufferedTreeNodeStream.java.
| void org.antlr.runtime.tree.UnBufferedTreeNodeStream.rewind | ( | ) |
Rewind to the input position of the last marker. Used currently only after a cyclic DFA and just before starting a sem/syn predicate to get the input position back to the start of the decision. Do not "pop" the marker off the state. mark(i) and rewind(i) should balance still. It is like invoking rewind(last marker) but it should not "pop" the marker off. It's like seek(last marker's input position).
Implements org.antlr.runtime.IntStream.
Definition at line 335 of file UnBufferedTreeNodeStream.java.
| void org.antlr.runtime.tree.UnBufferedTreeNodeStream.seek | ( | int | index | ) |
consume() ahead until we hit index. Can't just jump ahead--must spit out the navigation nodes.
Implements org.antlr.runtime.IntStream.
Definition at line 342 of file UnBufferedTreeNodeStream.java.
| int org.antlr.runtime.tree.UnBufferedTreeNodeStream.index | ( | ) |
Return the current input symbol index 0..n where n indicates the last symbol has been read. The index is the symbol about to be read not the most recently read symbol.
Implements org.antlr.runtime.IntStream.
Definition at line 352 of file UnBufferedTreeNodeStream.java.
| int org.antlr.runtime.tree.UnBufferedTreeNodeStream.size | ( | ) |
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.
Implements org.antlr.runtime.IntStream.
Definition at line 361 of file UnBufferedTreeNodeStream.java.
| Object org.antlr.runtime.tree.UnBufferedTreeNodeStream.next | ( | ) |
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. :(
Definition at line 380 of file UnBufferedTreeNodeStream.java.
| Object org.antlr.runtime.tree.UnBufferedTreeNodeStream.handleRootNode | ( | ) | [protected] |
Definition at line 408 of file UnBufferedTreeNodeStream.java.
| Object org.antlr.runtime.tree.UnBufferedTreeNodeStream.visitChild | ( | int | child | ) | [protected] |
Definition at line 427 of file UnBufferedTreeNodeStream.java.
| void org.antlr.runtime.tree.UnBufferedTreeNodeStream.addNavigationNode | ( | final int | ttype | ) | [protected] |
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.
Definition at line 448 of file UnBufferedTreeNodeStream.java.
| void org.antlr.runtime.tree.UnBufferedTreeNodeStream.walkBackToMostRecentNodeWithUnvisitedChildren | ( | ) | [protected] |
Walk upwards looking for a node with more children to walk.
Definition at line 470 of file UnBufferedTreeNodeStream.java.
| TreeAdaptor org.antlr.runtime.tree.UnBufferedTreeNodeStream.getTreeAdaptor | ( | ) |
What adaptor can tell me how to interpret/navigate nodes and trees. E.g., get text of a node.
Implements org.antlr.runtime.tree.TreeNodeStream.
Definition at line 491 of file UnBufferedTreeNodeStream.java.
| boolean org.antlr.runtime.tree.UnBufferedTreeNodeStream.hasUniqueNavigationNodes | ( | ) |
Definition at line 495 of file UnBufferedTreeNodeStream.java.
| void org.antlr.runtime.tree.UnBufferedTreeNodeStream.setUniqueNavigationNodes | ( | boolean | uniqueNavigationNodes | ) |
As we flatten the tree, we use UP, DOWN nodes to represent the tree structure. When debugging we need unique nodes so we have to instantiate new ones. When doing normal tree parsing, it's slow and a waste of memory to create unique navigation nodes. Default should be false;
Implements org.antlr.runtime.tree.TreeNodeStream.
Definition at line 499 of file UnBufferedTreeNodeStream.java.
| void org.antlr.runtime.tree.UnBufferedTreeNodeStream.replaceChildren | ( | Object | parent, | |
| int | startChildIndex, | |||
| int | stopChildIndex, | |||
| Object | t | |||
| ) |
Replace from start to stop child index of parent with t, which might be a list. Number of children may be different after this call. The stream is notified because it is walking the tree and might need to know you are monkeying with the underlying tree. Also, it might be able to modify the node stream to avoid restreaming for future phases.
If parent is null, don't do anything; must be at root of overall tree. Can't replace whatever points to the parent externally. Do nothing.
Implements org.antlr.runtime.tree.TreeNodeStream.
Definition at line 503 of file UnBufferedTreeNodeStream.java.
| String org.antlr.runtime.tree.UnBufferedTreeNodeStream.toString | ( | ) |
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.
Definition at line 511 of file UnBufferedTreeNodeStream.java.
| int org.antlr.runtime.tree.UnBufferedTreeNodeStream.getLookaheadSize | ( | ) | [protected] |
Definition at line 515 of file UnBufferedTreeNodeStream.java.
| String org.antlr.runtime.tree.UnBufferedTreeNodeStream.toString | ( | Object | start, | |
| Object | stop | |||
| ) |
Return the text of all nodes from start to stop, inclusive. If the stream does not buffer all the nodes then it can still walk recursively from start until stop. You can always return null or "" too, but users should not access $ruleLabel.text in an action of course in that case.
Implements org.antlr.runtime.tree.TreeNodeStream.
Definition at line 519 of file UnBufferedTreeNodeStream.java.
| void org.antlr.runtime.tree.UnBufferedTreeNodeStream.toStringWork | ( | Object | p, | |
| Object | stop, | |||
| StringBuffer | buf | |||
| ) | [protected] |
Definition at line 543 of file UnBufferedTreeNodeStream.java.
final int org.antlr.runtime.tree.UnBufferedTreeNodeStream.INITIAL_LOOKAHEAD_BUFFER_SIZE = 5 [static] |
Definition at line 50 of file UnBufferedTreeNodeStream.java.
boolean org.antlr.runtime.tree.UnBufferedTreeNodeStream.uniqueNavigationNodes = false [protected] |
Reuse same DOWN, UP navigation nodes unless this is true
Definition at line 53 of file UnBufferedTreeNodeStream.java.
Object org.antlr.runtime.tree.UnBufferedTreeNodeStream.root [protected] |
Pull nodes from which tree?
Definition at line 56 of file UnBufferedTreeNodeStream.java.
IF this tree (root) was created from a token stream, track it.
Definition at line 59 of file UnBufferedTreeNodeStream.java.
What tree adaptor was used to build these trees
Definition at line 62 of file UnBufferedTreeNodeStream.java.
Stack org.antlr.runtime.tree.UnBufferedTreeNodeStream.nodeStack = new Stack() [protected] |
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.
Definition at line 68 of file UnBufferedTreeNodeStream.java.
Stack org.antlr.runtime.tree.UnBufferedTreeNodeStream.indexStack = new Stack() [protected] |
Track which child index you are visiting for each node we push. TODO: pretty inefficient...use int[] when you have time
Definition at line 73 of file UnBufferedTreeNodeStream.java.
Object org.antlr.runtime.tree.UnBufferedTreeNodeStream.currentNode [protected] |
Which node are we currently visiting?
Definition at line 76 of file UnBufferedTreeNodeStream.java.
Object org.antlr.runtime.tree.UnBufferedTreeNodeStream.previousNode [protected] |
Which node did we visit last? Used for LT(-1) calls.
Definition at line 79 of file UnBufferedTreeNodeStream.java.
Which child are we currently visiting? If -1 we have not visited this node yet; next consume() request will set currentIndex to 0.
Definition at line 84 of file UnBufferedTreeNodeStream.java.
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.
Definition at line 89 of file UnBufferedTreeNodeStream.java.
Object [] org.antlr.runtime.tree.UnBufferedTreeNodeStream.lookahead = new Object[INITIAL_LOOKAHEAD_BUFFER_SIZE] [protected] |
Buffer tree node stream for use with LT(i). This list grows to fit new lookahead depths, but consume() wraps like a circular buffer.
Definition at line 95 of file UnBufferedTreeNodeStream.java.
int org.antlr.runtime.tree.UnBufferedTreeNodeStream.head [protected] |
lookahead[head] is the first symbol of lookahead, LT(1).
Definition at line 98 of file UnBufferedTreeNodeStream.java.
int org.antlr.runtime.tree.UnBufferedTreeNodeStream.tail [protected] |
Add new lookahead at lookahead[tail]. tail wraps around at the end of the lookahead buffer so tail could be less than head.
Definition at line 103 of file UnBufferedTreeNodeStream.java.
List org.antlr.runtime.tree.UnBufferedTreeNodeStream.markers [protected] |
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<TreeWalkState>. Indexed from 1..markDepth. A null is kept @ index 0. Create upon first call to mark().
Definition at line 127 of file UnBufferedTreeNodeStream.java.
int org.antlr.runtime.tree.UnBufferedTreeNodeStream.markDepth = 0 [protected] |
tracks how deep mark() calls are nested
Definition at line 130 of file UnBufferedTreeNodeStream.java.
int org.antlr.runtime.tree.UnBufferedTreeNodeStream.lastMarker [protected] |
Track the last mark() call result value for use in rewind().
Definition at line 133 of file UnBufferedTreeNodeStream.java.
Object org.antlr.runtime.tree.UnBufferedTreeNodeStream.down [protected] |
Definition at line 137 of file UnBufferedTreeNodeStream.java.
Object org.antlr.runtime.tree.UnBufferedTreeNodeStream.up [protected] |
Definition at line 138 of file UnBufferedTreeNodeStream.java.
Object org.antlr.runtime.tree.UnBufferedTreeNodeStream.eof [protected] |
Definition at line 139 of file UnBufferedTreeNodeStream.java.
1.5.5