Package com.jogamp.gluegen.cgram
Class TNode
java.lang.Object
CommonAST
com.jogamp.gluegen.cgram.TNode
- All Implemented Interfaces:
ASTLocusTag.ASTLocusTagProvider
Class TNode is an implementation of the AST interface
and adds many useful features:
It is double-linked for reverse searching.
(this is currently incomplete, in that method doubleLink() must
be called after any changes to the tree to maintain the
reverse links).
It can store a definition node (defNode), so that nodes such
as scoped names can refer to the node that defines the name.
It stores line numbers for nodes.
Searches for parents and children of a tree can be done
based on their type.
The tree can be printed to System.out using a lisp-style syntax.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSibling(AST node) add the new node as a new sibling, inserting it ahead of any existing next sibling.deepCopy()return a deep copy of this node, and all sub nodes.return a deep copy of this node, all sub nodes, and right siblings.voidset up reverse links between this node and its first child and its first sibling, and link those as wellfirstChildOfType(int type) find the first child of the node of the given type, return null on failurefirstSiblingOfType(int type) find the first sibling of the node of the given type, return null on failuregetAllChildrenText(String name) Returns the text for this node, its children and siblings.Returns this instance'sASTLocusTag, if available, otherwise returnsnull.getAttribute(String attrName) lookup the attribute name in the attribute table.get the hashtable that holds attribute values.return the def node for this nodereturn the first sibling of this node, which is this if the prev sibling is nullreturn the last child of this node, or null if there is nonereturn the last sibling of this node, which is this if the next sibling is nullintGet the line number for this node.intbooleanGet the marker value for this node.static StringgetNameForType(int t) converts an int tree token type to a name.return the parent node of this nodegetText()Get the token text for this nodeintgetType()Get the token type for this nodevoidinitialize(AST tr) voidinitialize(Token token) intreturn the number of children of this nodeparentOfType(int type) find first parent of the given type, return null on failureprotected static voidprintASTNode(AST t, int indent) protected method that does the work of printingstatic voidprintTree(AST t) print given tree to System.outvoidremove this node from the tree, resetting sibling and parent pointers as necessary.voidsetAttribute(String attrName, Object value) set an attribute in the attribute table.voidsetDefNode(TNode n) set the def node for this nodevoidsetLineNum(int lineNum_) Set the line number for this nodevoidsetMarker(boolean marker_) Set the marker value for this node.voidSet the token text for this nodestatic voidSet the token vocabulary to a tokentypes class generated by antlr.voidsetType(int ttype_) Set the token type for this nodetoString()return a short string representation of the node
-
Field Details
-
ttype
protected int ttype -
text
-
lineNum
protected int lineNum -
defNode
-
up
-
left
-
marker
protected boolean marker -
attributes
-
-
Constructor Details
-
TNode
public TNode()
-
-
Method Details
-
getASTLocusTag
Returns this instance'sASTLocusTag, if available, otherwise returnsnull.If source is not available, implementation returns
null.- Specified by:
getASTLocusTagin interfaceASTLocusTag.ASTLocusTagProvider
-
setTokenVocabulary
Set the token vocabulary to a tokentypes class generated by antlr. -
initialize
public void initialize(Token token) -
initialize
public void initialize(AST tr) -
getType
public int getType()Get the token type for this node -
setType
public void setType(int ttype_) Set the token type for this node -
getMarker
public boolean getMarker()Get the marker value for this node. This member is a general-use marker. -
setMarker
public void setMarker(boolean marker_) Set the marker value for this node. This property is a general-use boolean marker. -
getAttributesTable
get the hashtable that holds attribute values. -
setAttribute
set an attribute in the attribute table. -
getAttribute
lookup the attribute name in the attribute table. If the value does not exist, it returns null. -
getLineNum
public int getLineNum()Get the line number for this node. If the line number is 0, search for a non-zero line num among children -
getLocalLineNum
public int getLocalLineNum() -
setLineNum
public void setLineNum(int lineNum_) Set the line number for this node -
getText
Get the token text for this node -
setText
Set the token text for this node -
getAllChildrenText
Returns the text for this node, its children and siblings.Implementation converts the AST LISP notation to serialized form.
-
getLastChild
return the last child of this node, or null if there is none -
getLastSibling
return the last sibling of this node, which is this if the next sibling is null -
getFirstSibling
return the first sibling of this node, which is this if the prev sibling is null -
getParent
return the parent node of this node -
addSibling
public void addSibling(AST node) add the new node as a new sibling, inserting it ahead of any existing next sibling. This method maintains double-linking. if node is null, nothing happens. If the node has siblings, then they are added in as well. -
numberOfChildren
public int numberOfChildren()return the number of children of this node -
removeSelf
public void removeSelf()remove this node from the tree, resetting sibling and parent pointers as necessary. This method maintains double-linking -
getDefNode
return the def node for this node -
setDefNode
set the def node for this node -
deepCopy
return a deep copy of this node, and all sub nodes. New tree is doubleLinked, with no parent or siblings. Marker value is not copied! -
deepCopyWithRightSiblings
return a deep copy of this node, all sub nodes, and right siblings. New tree is doubleLinked, with no parent or left siblings. defNode is not copied -
toString
return a short string representation of the node -
printTree
public static void printTree(AST t) print given tree to System.out -
printASTNode
protected static void printASTNode(AST t, int indent) protected method that does the work of printing -
getNameForType
converts an int tree token type to a name. Does this by reflecting on nsdidl.IDLTreeTokenTypes, and is dependent on how ANTLR 2.00 outputs that class. -
doubleLink
public void doubleLink()set up reverse links between this node and its first child and its first sibling, and link those as well -
parentOfType
find first parent of the given type, return null on failure -
firstChildOfType
find the first child of the node of the given type, return null on failure -
firstSiblingOfType
find the first sibling of the node of the given type, return null on failure
-