Package schrodinger :: Package application :: Package desmond :: Package antlr3 :: Module tree :: Class BaseTree
[hide private]
[frames] | no frames]

Class BaseTree

object --+    
         |    
      Tree --+
             |
            BaseTree
Known Subclasses:

@brief A generic tree implementation with no payload.

You must subclass to actually have any user data. ANTLR v3 uses a list of children approach instead of the child-sibling approach in v2. A flat tree (a list) is an empty node whose children represent the list. An empty, but non-null node is called "nil".

Instance Methods [hide private]
 
__init__(self, node=None)
Create a new node from an existing node does nothing for BaseTree as there are no fields other than the children list, which cannot be copied as the children are not considered part of this node.
 
getChild(self, i)
 
getChildren(self)
@brief Get the children internal List
 
getFirstChildWithType(self, treeType)
 
getChildCount(self)
 
addChild(self, childTree)
Add t as child of this node.
 
addChildren(self, children)
Add all elements of kids list as children of this node
 
setChild(self, i, t)
Set ith child (0..n-1) to t; t must be non-null and non-nil node
 
deleteChild(self, i)
 
replaceChildren(self, startChildIndex, stopChildIndex, newTree)
Delete children from start to stop and replace with t even if t is a list (nil-root tree).
 
isNil(self)
Indicates the node is a nil node but may still have children, meaning the tree is a flat list.
 
freshenParentAndChildIndexes(self, offset=0)
Set the parent and child index values for all children
 
sanityCheckParentAndChildIndexes(self, parent=None, i=-1)
 
getChildIndex(self)
BaseTree doesn't track child indexes.
 
setChildIndex(self, index)
BaseTree doesn't track child indexes.
 
getParent(self)
BaseTree doesn't track parent pointers.
 
setParent(self, t)
BaseTree doesn't track parent pointers.
 
hasAncestor(self, ttype)
Walk upwards looking for ancestor with this token type.
 
getAncestor(self, ttype)
Walk upwards and get first ancestor with this token type.
 
getAncestors(self)
Return a list of all ancestors of this node.
 
toStringTree(self)
Print out a whole tree not just a node
 
getLine(self)
In case we don't have a token payload, what is the line for errors?
 
getCharPositionInLine(self)
 
toString(self)
Override to say how a node (not a tree) should look as text

Inherited from Tree: dupNode, getText, getTokenStartIndex, getTokenStopIndex, getType, setTokenStartIndex, setTokenStopIndex

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, node=None)
(Constructor)

 

Create a new node from an existing node does nothing for BaseTree as there are no fields other than the children list, which cannot be copied as the children are not considered part of this node.

Overrides: object.__init__

getChild(self, i)

 
Overrides: Tree.getChild

getChildren(self)

 

@brief Get the children internal List

Note that if you directly mess with the list, do so at your own risk.

getChildCount(self)

 
Overrides: Tree.getChildCount

addChild(self, childTree)

 

Add t as child of this node.

Warning: if t has no children, but child does and child isNil then this routine moves children to t via t.children = child.children; i.e., without copying the array.

Overrides: Tree.addChild

setChild(self, i, t)

 

Set ith child (0..n-1) to t; t must be non-null and non-nil node

Overrides: Tree.setChild
(inherited documentation)

deleteChild(self, i)

 
Overrides: Tree.deleteChild

replaceChildren(self, startChildIndex, stopChildIndex, newTree)

 

Delete children from start to stop and replace with t even if t is a list (nil-root tree). num of children can increase or decrease. For huge child lists, inserting children can force walking rest of children to set their childindex; could be slow.

Overrides: Tree.replaceChildren

isNil(self)

 

Indicates the node is a nil node but may still have children, meaning the tree is a flat list.

Overrides: Tree.isNil
(inherited documentation)

freshenParentAndChildIndexes(self, offset=0)

 

Set the parent and child index values for all children

Overrides: Tree.freshenParentAndChildIndexes
(inherited documentation)

getChildIndex(self)

 

BaseTree doesn't track child indexes.

Overrides: Tree.getChildIndex

setChildIndex(self, index)

 

BaseTree doesn't track child indexes.

Overrides: Tree.setChildIndex

getParent(self)

 

BaseTree doesn't track parent pointers.

Overrides: Tree.getParent

setParent(self, t)

 

BaseTree doesn't track parent pointers.

Overrides: Tree.setParent

hasAncestor(self, ttype)

 

Walk upwards looking for ancestor with this token type.

Overrides: Tree.hasAncestor

getAncestor(self, ttype)

 

Walk upwards and get first ancestor with this token type.

Overrides: Tree.getAncestor

getAncestors(self)

 

Return a list of all ancestors of this node.

The first node of list is the root and the last is the parent of this node.

Overrides: Tree.getAncestors

toStringTree(self)

 

Print out a whole tree not just a node

Overrides: Tree.toStringTree

getLine(self)

 

In case we don't have a token payload, what is the line for errors?

Overrides: Tree.getLine
(inherited documentation)

getCharPositionInLine(self)

 
Overrides: Tree.getCharPositionInLine

toString(self)

 

Override to say how a node (not a tree) should look as text

Overrides: Tree.toString