Packageorg.antlr.runtime.tree
Classpublic class BaseTreeAdaptor
ImplementsTreeAdaptor
SubclassesCommonTreeAdaptor

A TreeAdaptor that works with any Tree implementation.



Protected Properties
 PropertyDefined by
  treeToUniqueIDMap : Dictionary
System.identityHashCode() is not always unique; we have to track ourselves.
BaseTreeAdaptor
  uniqueNodeID : int = 1
BaseTreeAdaptor
Public Methods
 MethodDefined by
  
addChild(t:Object, child:Object):void
Add a child to the tree t.
BaseTreeAdaptor
  
becomeRoot(newRoot:Object, oldRoot:Object):Object
If oldRoot is a nil root, just copy or move the children to newRoot.
BaseTreeAdaptor
  
create(... args):Object
BaseTreeAdaptor
  
createFromToken(tokenType:int, fromToken:Token, text:String = null):Object
BaseTreeAdaptor
  
createFromType(tokenType:int, text:String):Object
BaseTreeAdaptor
  
createToken(fromToken:Token):Token
Tell me how to create a token for use with imaginary token nodes.
BaseTreeAdaptor
  
createTokenFromType(tokenType:int, text:String):Token
Tell me how to create a token for use with imaginary token nodes.
BaseTreeAdaptor
  
createWithPayload(payload:Token):Object
BaseTreeAdaptor
  
deleteChild(t:Object, i:int):Object
BaseTreeAdaptor
  
dupNode(t:Object):Object
BaseTreeAdaptor
  
dupTree(tree:Object):Object
BaseTreeAdaptor
  
dupTreeWithParent(t:Object, parent:Object):Object
This is generic in the sense that it will work with any kind of tree (not just Tree interface).
BaseTreeAdaptor
  
errorNode(input:TokenStream, start:Token, stop:Token, e:RecognitionException):Object
create tree node that holds the start and stop tokens associated with an error.
BaseTreeAdaptor
  
getChild(t:Object, i:int):Object
BaseTreeAdaptor
  
getChildCount(t:Object):int
BaseTreeAdaptor
  
getChildIndex(t:Object):int
BaseTreeAdaptor
  
getParent(t:Object):Object
BaseTreeAdaptor
  
getText(t:Object):String
BaseTreeAdaptor
  
getToken(t:Object):Token
BaseTreeAdaptor
  
getTokenStartIndex(t:Object):int
BaseTreeAdaptor
  
getTokenStopIndex(t:Object):int
BaseTreeAdaptor
  
getType(t:Object):int
BaseTreeAdaptor
  
getUniqueID(node:Object):int
BaseTreeAdaptor
  
isNil(tree:Object):Boolean
BaseTreeAdaptor
  
nil():Object
BaseTreeAdaptor
  
replaceChildren(parent:Object, startChildIndex:int, stopChildIndex:int, t:Object):void
BaseTreeAdaptor
  
rulePostProcessing(root:Object):Object
Transform ^(nil x) to x and nil to null
BaseTreeAdaptor
  
setChild(t:Object, i:int, child:Object):void
BaseTreeAdaptor
  
setChildIndex(t:Object, index:int):void
BaseTreeAdaptor
  
setParent(t:Object, parent:Object):void
BaseTreeAdaptor
  
setText(t:Object, text:String):void
BaseTreeAdaptor
  
setTokenBoundaries(t:Object, startToken:Token, stopToken:Token):void
BaseTreeAdaptor
  
setType(t:Object, type:int):void
BaseTreeAdaptor
Property detail
treeToUniqueIDMapproperty
protected var treeToUniqueIDMap:Dictionary

System.identityHashCode() is not always unique; we have to track ourselves. That's ok, it's only for debugging, though it's expensive: we have to create a hashtable with all tree nodes in it.

uniqueNodeIDproperty 
protected var uniqueNodeID:int = 1
Method detail
addChild()method
public function addChild(t:Object, child:Object):void

Add a child to the tree t. If child is a flat tree (a list), make all in list children of t. Warning: if t has no children, but child does and child isNil then you can decide it is ok to move children to t via t.children = child.children; i.e., without copying the array. Just make sure that this is consistent with have the user will build ASTs.

Parameters
t:Object
 
child:Object
becomeRoot()method 
public function becomeRoot(newRoot:Object, oldRoot:Object):Object

If oldRoot is a nil root, just copy or move the children to newRoot. If not a nil root, make oldRoot a child of newRoot. old=^(nil a b c), new=r yields ^(r a b c) old=^(a b c), new=r yields ^(r ^(a b c)) If newRoot is a nil-rooted single child tree, use the single child as the new root node. old=^(nil a b c), new=^(nil r) yields ^(r a b c) old=^(a b c), new=^(nil r) yields ^(r ^(a b c)) If oldRoot was null, it's ok, just return newRoot (even if isNil). old=null, new=r yields r old=null, new=^(nil r) yields ^(nil r) Return newRoot. Throw an exception if newRoot is not a simple node or nil root with a single child node--it must be a root node. If newRoot is ^(nil x) return x as newRoot. Be advised that it's ok for newRoot to point at oldRoot's children; i.e., you don't have to copy the list. We are constructing these nodes so we should have this control for efficiency.

Parameters
newRoot:Object
 
oldRoot:Object

Returns
Object
create()method 
public function create(... args):ObjectParameters
... args

Returns
Object
createFromToken()method 
public function createFromToken(tokenType:int, fromToken:Token, text:String = null):ObjectParameters
tokenType:int
 
fromToken:Token
 
text:String (default = null)

Returns
Object
createFromType()method 
public function createFromType(tokenType:int, text:String):ObjectParameters
tokenType:int
 
text:String

Returns
Object
createToken()method 
public function createToken(fromToken:Token):Token

Tell me how to create a token for use with imaginary token nodes. For example, there is probably no input symbol associated with imaginary token DECL, but you need to create it as a payload or whatever for the DECL node as in ^(DECL type ID). This is a variant of createToken where the new token is derived from an actual real input token. Typically this is for converting '{' tokens to BLOCK etc... You'll see r : lc='{' ID+ '}' -> ^(BLOCK[$lc] ID+) ; If you care what the token payload objects' type is, you should override this method and any other createToken variant.

Parameters
fromToken:Token

Returns
Token
createTokenFromType()method 
public function createTokenFromType(tokenType:int, text:String):Token

Tell me how to create a token for use with imaginary token nodes. For example, there is probably no input symbol associated with imaginary token DECL, but you need to create it as a payload or whatever for the DECL node as in ^(DECL type ID). If you care what the token payload objects' type is, you should override this method and any other createToken variant.

Parameters
tokenType:int
 
text:String

Returns
Token
createWithPayload()method 
public function createWithPayload(payload:Token):ObjectParameters
payload:Token

Returns
Object
deleteChild()method 
public function deleteChild(t:Object, i:int):ObjectParameters
t:Object
 
i:int

Returns
Object
dupNode()method 
public function dupNode(t:Object):ObjectParameters
t:Object

Returns
Object
dupTree()method 
public function dupTree(tree:Object):ObjectParameters
tree:Object

Returns
Object
dupTreeWithParent()method 
public function dupTreeWithParent(t:Object, parent:Object):Object

This is generic in the sense that it will work with any kind of tree (not just Tree interface). It invokes the adaptor routines not the tree node routines to do the construction.

Parameters
t:Object
 
parent:Object

Returns
Object
errorNode()method 
public function errorNode(input:TokenStream, start:Token, stop:Token, e:RecognitionException):Object

create tree node that holds the start and stop tokens associated with an error. If you specify your own kind of tree nodes, you will likely have to override this method. CommonTree returns Token.INVALID_TOKEN_TYPE if no token payload but you might have to set token type for diff node type.

Parameters
input:TokenStream
 
start:Token
 
stop:Token
 
e:RecognitionException

Returns
Object
getChild()method 
public function getChild(t:Object, i:int):ObjectParameters
t:Object
 
i:int

Returns
Object
getChildCount()method 
public function getChildCount(t:Object):intParameters
t:Object

Returns
int
getChildIndex()method 
public function getChildIndex(t:Object):intParameters
t:Object

Returns
int
getParent()method 
public function getParent(t:Object):ObjectParameters
t:Object

Returns
Object
getText()method 
public function getText(t:Object):StringParameters
t:Object

Returns
String
getToken()method 
public function getToken(t:Object):TokenParameters
t:Object

Returns
Token
getTokenStartIndex()method 
public function getTokenStartIndex(t:Object):intParameters
t:Object

Returns
int
getTokenStopIndex()method 
public function getTokenStopIndex(t:Object):intParameters
t:Object

Returns
int
getType()method 
public function getType(t:Object):intParameters
t:Object

Returns
int
getUniqueID()method 
public function getUniqueID(node:Object):intParameters
node:Object

Returns
int
isNil()method 
public function isNil(tree:Object):BooleanParameters
tree:Object

Returns
Boolean
nil()method 
public function nil():Object

Returns
Object
replaceChildren()method 
public function replaceChildren(parent:Object, startChildIndex:int, stopChildIndex:int, t:Object):voidParameters
parent:Object
 
startChildIndex:int
 
stopChildIndex:int
 
t:Object
rulePostProcessing()method 
public function rulePostProcessing(root:Object):Object

Transform ^(nil x) to x and nil to null

Parameters
root:Object

Returns
Object
setChild()method 
public function setChild(t:Object, i:int, child:Object):voidParameters
t:Object
 
i:int
 
child:Object
setChildIndex()method 
public function setChildIndex(t:Object, index:int):voidParameters
t:Object
 
index:int
setParent()method 
public function setParent(t:Object, parent:Object):voidParameters
t:Object
 
parent:Object
setText()method 
public function setText(t:Object, text:String):voidParameters
t:Object
 
text:String
setTokenBoundaries()method 
public function setTokenBoundaries(t:Object, startToken:Token, stopToken:Token):voidParameters
t:Object
 
startToken:Token
 
stopToken:Token
setType()method 
public function setType(t:Object, type:int):voidParameters
t:Object
 
type:int