Packageorg.antlr.runtime.tree
Classpublic class CommonTreeNodeStream
ImplementsTreeNodeStream

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


Public Properties
 PropertyDefined by
  adaptor : TreeAdaptor
What tree adaptor was used to build these trees
CommonTreeNodeStream
  currentSymbol : Object
[read-only]
CommonTreeNodeStream
  hasUniqueNavigationNodes : Boolean
CommonTreeNodeStream
  index : int
[read-only]
CommonTreeNodeStream
  size : int
[read-only]
CommonTreeNodeStream
  sourceName : String
[read-only]
CommonTreeNodeStream
  tokenStream : TokenStream
CommonTreeNodeStream
  treeAdaptor : TreeAdaptor
CommonTreeNodeStream
  treeSource : Object
[read-only]
CommonTreeNodeStream
Protected Properties
 PropertyDefined by
  calls : Array
Stack of indexes used for push/pop calls
CommonTreeNodeStream
  down : Object
CommonTreeNodeStream
  eof : Object
CommonTreeNodeStream
  lastMarker : int
Track the last mark() call result value for use in rewind().
CommonTreeNodeStream
  nodes : Array
The complete mapping from stream index to tree node.
CommonTreeNodeStream
  p : int = -1
The index into the nodes list of the current node (next node to consume).
CommonTreeNodeStream
  root : Object
Pull nodes from which tree?
CommonTreeNodeStream
  tokens : TokenStream
IF this tree (root) was created from a token stream, track it.
CommonTreeNodeStream
  uniqueNavigationNodes : Boolean = false
Reuse same DOWN, UP navigation nodes unless this is true
CommonTreeNodeStream
  up : Object
CommonTreeNodeStream
Public Methods
 MethodDefined by
  
CommonTreeNodeStream(tree:Object, adaptor:TreeAdaptor = null, initialBufferSize:int)
CommonTreeNodeStream
  
consume():void
CommonTreeNodeStream
  
fillBufferTo(t:Object):void
CommonTreeNodeStream
  
getNode(i:int):Object
CommonTreeNodeStream
  
LA(i:int):int
CommonTreeNodeStream
  
LT(k:int):Object
CommonTreeNodeStream
  
mark():int
CommonTreeNodeStream
  
pop():int
Seek back to previous index saved during last push() call.
CommonTreeNodeStream
  
push(index:int):void
Make stream jump to a new location, saving old location.
CommonTreeNodeStream
  
release(marker:int):void
CommonTreeNodeStream
  
replaceChildren(parent:Object, startChildIndex:int, stopChildIndex:int, t:Object):void
CommonTreeNodeStream
  
reset():void
CommonTreeNodeStream
  
rewind():void
CommonTreeNodeStream
  
rewindTo(marker:int):void
CommonTreeNodeStream
  
seek(index:int):void
CommonTreeNodeStream
  
toString():String
Used for testing, just return the token type stream
CommonTreeNodeStream
  
toStringWithRange(start:Object, stop:Object):String
CommonTreeNodeStream
  
toTokenString(start:int, stop:int):String
Debugging
CommonTreeNodeStream
Protected Methods
 MethodDefined by
  
addNavigationNode(ttype:int):void
As we flatten the tree, we use UP, DOWN nodes to represent the tree structure.
CommonTreeNodeStream
  
fillBuffer():void
Walk tree with depth-first-search and fill nodes buffer.
CommonTreeNodeStream
  
getNodeIndex(node:Object):int
What is the stream index for node? 0..n-1 Return -1 if node not found.
CommonTreeNodeStream
  
LB(k:int):Object
Look backwards k nodes
CommonTreeNodeStream
Public Constants
 ConstantDefined by
  DEFAULT_INITIAL_BUFFER_SIZE : int = 100
[static]
CommonTreeNodeStream
  INITIAL_CALL_STACK_SIZE : int = 10
[static]
CommonTreeNodeStream
Property detail
adaptorproperty
public var adaptor:TreeAdaptor

What tree adaptor was used to build these trees

callsproperty 
protected var calls:Array

Stack of indexes used for push/pop calls

currentSymbolproperty 
currentSymbol:Object  [read-only]Implementation
    public function get currentSymbol():Object
downproperty 
protected var down:Object
eofproperty 
protected var eof:Object
hasUniqueNavigationNodesproperty 
hasUniqueNavigationNodes:Boolean  [read-write]Implementation
    public function get hasUniqueNavigationNodes():Boolean
    public function set hasUniqueNavigationNodes(value:Boolean):void
indexproperty 
index:int  [read-only]Implementation
    public function get index():int
lastMarkerproperty 
protected var lastMarker:int

Track the last mark() call result value for use in rewind().

nodesproperty 
protected var nodes:Array

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.

pproperty 
protected var p:int = -1

The index into the nodes list of the current node (next node to consume). If -1, nodes array not filled yet.

rootproperty 
protected var root:Object

Pull nodes from which tree?

sizeproperty 
size:int  [read-only]Implementation
    public function get size():int
sourceNameproperty 
sourceName:String  [read-only]Implementation
    public function get sourceName():String
tokensproperty 
protected var tokens:TokenStream

IF this tree (root) was created from a token stream, track it.

tokenStreamproperty 
tokenStream:TokenStream  [read-write]Implementation
    public function get tokenStream():TokenStream
    public function set tokenStream(value:TokenStream):void
treeAdaptorproperty 
treeAdaptor:TreeAdaptor  [read-write]Implementation
    public function get treeAdaptor():TreeAdaptor
    public function set treeAdaptor(value:TreeAdaptor):void
treeSourceproperty 
treeSource:Object  [read-only]Implementation
    public function get treeSource():Object
uniqueNavigationNodesproperty 
protected var uniqueNavigationNodes:Boolean = false

Reuse same DOWN, UP navigation nodes unless this is true

upproperty 
protected var up:Object
Constructor detail
CommonTreeNodeStream()constructor
public function CommonTreeNodeStream(tree:Object, adaptor:TreeAdaptor = null, initialBufferSize:int)Parameters
tree:Object
 
adaptor:TreeAdaptor (default = null)
 
initialBufferSize:int
Method detail
addNavigationNode()method
protected function addNavigationNode(ttype:int):void

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.

Parameters
ttype:int
consume()method 
public function consume():void
fillBuffer()method 
protected function fillBuffer():void

Walk tree with depth-first-search and fill nodes buffer. Don't do DOWN, UP nodes if its a list (t is isNil).

fillBufferTo()method 
public function fillBufferTo(t:Object):voidParameters
t:Object
getNode()method 
public function getNode(i:int):ObjectParameters
i:int

Returns
Object
getNodeIndex()method 
protected function getNodeIndex(node:Object):int

What is the stream index for node? 0..n-1 Return -1 if node not found.

Parameters
node:Object

Returns
int
LA()method 
public function LA(i:int):intParameters
i:int

Returns
int
LB()method 
protected function LB(k:int):Object

Look backwards k nodes

Parameters
k:int

Returns
Object
LT()method 
public function LT(k:int):ObjectParameters
k:int

Returns
Object
mark()method 
public function mark():int

Returns
int
pop()method 
public function pop():int

Seek back to previous index saved during last push() call. Return top of stack (return index).

Returns
int
push()method 
public function push(index:int):void

Make stream jump to a new location, saving old location. Switch back with pop().

Parameters
index:int
release()method 
public function release(marker:int):voidParameters
marker:int
replaceChildren()method 
public function replaceChildren(parent:Object, startChildIndex:int, stopChildIndex:int, t:Object):voidParameters
parent:Object
 
startChildIndex:int
 
stopChildIndex:int
 
t:Object
reset()method 
public function reset():void
rewind()method 
public function rewind():void
rewindTo()method 
public function rewindTo(marker:int):voidParameters
marker:int
seek()method 
public function seek(index:int):voidParameters
index:int
toString()method 
public function toString():String

Used for testing, just return the token type stream

Returns
String
toStringWithRange()method 
public function toStringWithRange(start:Object, stop:Object):StringParameters
start:Object
 
stop:Object

Returns
String
toTokenString()method 
public function toTokenString(start:int, stop:int):String

Debugging

Parameters
start:int
 
stop:int

Returns
String
Constant detail
DEFAULT_INITIAL_BUFFER_SIZEconstant
public static const DEFAULT_INITIAL_BUFFER_SIZE:int = 100
INITIAL_CALL_STACK_SIZEconstant 
public static const INITIAL_CALL_STACK_SIZE:int = 10