- All Known Subinterfaces:
AbstractFunctionDefinitionNode,AlignOfNode,AllocationNode,AnyactNode,ArrayDesignatorNode,ArrayLambdaNode,ArrayTypeNode,ArrowNode,AssignsOrReadsNode,AssumesNode,AtomicNode,AtomicTypeNode,BasicTypeNode,BehaviorNode,BlockItemNode,CallEventNode,CastNode,CharacterConstantNode,ChooseStatementNode,CivlForNode,CompletenessNode,CompositeEventNode,CompoundInitializerNode,CompoundLiteralNode,CompoundStatementNode,ConstantNode,ContractNode,DeclarationListNode,DeclarationNode,DependsEventNode,DependsNode,DerivativeExpressionNode,DesignationNode,DesignatorNode,DomainTypeNode,DotNode,EnsuresNode,EnumerationConstantNode,EnumerationTypeNode,EnumeratorDeclarationNode,ExpressionNode,ExpressionStatementNode,ExtendedQuantifiedExpressionNode,FieldDeclarationNode,FieldDesignatorNode,FloatingConstantNode,FocusAssertTransformNode,FocusLoopTransformNode,FocusOrderedTransformNode,FocusTransformNode,ForLoopInitializerNode,ForLoopNode,FunctionCallNode,FunctionDeclarationNode,FunctionDefinitionNode,FunctionTypeNode,GenericAssociationNode,GenericSelectionNode,GotoNode,GuardsNode,HereOrRootNode,IdentifierExpressionNode,IdentifierNode,IfNode,InitializerNode,InsertTransformNode,IntegerConstantNode,InvariantNode,JumpNode,LabeledStatementNode,LabelNode,LambdaNode,LambdaTypeNode,LoopNode,MemoryEventNode,NoactNode,NothingNode,NullStatementNode,ObjectOrRegionOfNode,OmpAtomicNode,OmpDeclarativeNode,OmpEndNode,OmpExecutableNode,OmpForNode,OmpFunctionReductionNode,OmpNode,OmpParallelNode,OmpReductionNode,OmpSimdNode,OmpSymbolReductionNode,OmpSyncNode,OmpWorksharingNode,OperatorNode,OrdinaryDeclarationNode,OrdinaryLabelNode,PairNode<S,,T> PointerTypeNode,PragmaNode,PredicateNode,ProcnullNode,QuantifiedExpressionNode,RegularRangeNode,RemoteOnExpressionNode,RequiresNode,ResultNode,ReturnNode,RunNode,ScopeOfNode,ScopeParameterizedDeclarationNode,SelfNode,SequenceNode<T>,SizeableNode,SizeofNode,SpawnNode,StatementExpressionNode,StatementNode,StatenullNode,StaticAssertionNode,StringLiteralNode,StructureOrUnionTypeNode,SwitchLabelNode,SwitchNode,TransformNode,TypedefDeclarationNode,TypedefNameNode,TypeNode,TypeofNode,UpdateNode,VariableDeclarationNode,WhenNode,WildcardNode
Root of the AST node type hierarchy. All AST nodes implement this interface.
An AST node has some number n of children. Each child
is either an AST node or null. The children are arranged in an
ordered sequences and numbered from 0.
Every AST node has at most one parent. If a node u has a (non-
null) parent v, then it is guaranteed that u is a
child of v. This class is designed so that it is not possible to
violate these invariants.
Nodes are mutable objects. It is possible to modify various aspects of the node, to remove a node from its parent, to add new children to a node, and so on.
At any point in time, a node is either "owned" by an AST or it is "free". A node can be owned by at most one AST. A node starts out as free, and becomes owned by an AST when an AST is created and the node is reachable from the root node used to create the new AST. The nodes of an AST can become free by "releasing" the AST, which essentially dissolves the AST but leaves the nodes intact. Modifications to the tree structure (the parent and child relations) can only occur on free nodes, hence to modify an AST it is necessary to first release it. After the modifications are complete, a new AST can be formed from the modified nodes.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumThe different kind of AST nodes. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAllTransformAnnotations(List<TransformNode> transforms) voidaddTransformAnnotation(TransformNode transform) child(int index) Returns the index-th child node of this AST node.intReturns the index of this node among the children of its parent.children()Returns the sequence of children of this node as an iterable object.copy()Returns a deep copy of this AST node.Returns the first difference between this AST node and that node.booleanIs the given AST node equivalent to me?getAttribute(AttributeKey key) Returns the attribute value associated to the given key, ornullif no value has been set for that key.getOwner()Returns the "owner" of this AST, i.e., the AST to which this node belongs.getScope()Gets the scope in which the syntactic element corresponding to this node occurs.Returns the source object that locates the origin of this program construct in the original source code.intid()ID number unique within the AST to which this node belongs, or -1 if the node is free (not owned by an AST).voidkeepOnly(NodePredicate keep) Removes all children that do not satisfy the predicate and applies this method recursively to the remaining children.nextDFS()Finds next non-null node in AST in DFS order.nodeKind()Returns the node kind: this is an element of the enumerated typeASTNode.NodeKind, which is used to categorize the different kinds of nodes.intReturns the number of child nodes of this AST node.parent()Returns the parent of this node, ornullif this node has no parent.voidprettyPrint(PrintStream out) Pretty-prints this AST node (and its descendants) in a form that should be similar to the actual programming language.Returns the pretty representation of this AST node (and its descendants) in a form that should be similar to the actual programming language.prettyRepresentation(int maxLength) Returns the pretty representation of this AST node (and its descendants) in a form that should be similar to the actual programming language.voidprint(String prefix, PrintStream out, boolean includeSource) Prints a long-form textual representation of this node.voidremove()Removes this node from its parent.removeChild(int index) Removes the child at givenindexfrom this node.voidremoveTransformAnnotation(int index) voidsetAttribute(AttributeKey key, Object value) Sets the attribute value associated to the given key.Sets the child node at the given index.voidsetId(int id) Sets the ID number of this node.voidSets the owner of this node to the given AST.voidSets the scope of this syntactic element.toString()Returns a short textual representation of this node only.
-
Method Details
-
child
Returns the index-th child node of this AST node. The children of a node are ordered and numbered starting from 0.- Parameters:
index- an integer in the range [0,n-1], where n is the number of children of this node, i.e., the value returned bynumChildren()- Returns:
- the index-th child of this node; note that this may be
null. - Throws:
NoSuchElementException- if index is less than 0 or greater than or equal to the number of children
-
childIndex
int childIndex()Returns the index of this node among the children of its parent.
The children of a node are ordered and numbered from 0 to n-1, where n is the number of children. Since an AST is a tree, every node has at most one parent. If this node has a parent, this method returns the index of this node in its parent's children list. If this node does not have a parent, this method returns -1.
- Returns:
- the index of this node it its parent's child list, or -1 if it has no parent
-
children
Returns the sequence of children of this node as an iterable object. Do not attempt to cast the iterable to another type and/or modify it; if you do, all bets are off. Use it only to iterate over the children.- Returns:
- the (ordered) sequence of children nodes of this node; may contain
nullvalues
-
copy
ASTNode copy()Returns a deep copy of this AST node. The node and all of its descendants will be cloned. The cloning does not copy analysis or attribute information.- Returns:
- deep copy of this node
-
getAttribute
Returns the attribute value associated to the given key, ornullif no value has been set for that key. Note that attribute keys are generated using methodNodeFactory.newAttribute(String, Class).- Parameters:
key- an attribute key- Returns:
- the value associated to the key by this node, or
null
-
getOwner
AST getOwner()Returns the "owner" of this AST, i.e., the AST to which this node belongs. This can benull, in which case we say this node is "free".- Returns:
- the owner of this node or
null
-
getScope
Scope getScope()Gets the scope in which the syntactic element corresponding to this node occurs.- Returns:
- the scope
-
getSource
Source getSource()Returns the source object that locates the origin of this program construct in the original source code. This is used for reporting friendly messages to the user. The source element specifies a range of tokens in a token stream and can be used to display file name, line numbers, and character indexes to precisely target a source region.- Returns:
- source object for this node
-
id
int id()ID number unique within the AST to which this node belongs, or -1 if the node is free (not owned by an AST).- Returns:
- if the node is owned by an AST, the node ID number, which is unique among all nodes in this AST; otherwise -1
-
keepOnly
Removes all children that do not satisfy the predicate and applies this method recursively to the remaining children.
"Removing a node" is interpreted as follows: if u is an instance of
SequenceNode, and a child of u does not satisfy the predicate, then the child is removed and all subsequent elements of the sequence are shifted down to remove the gap. If u is not an instance ofSequenceNodeand the child does not satisfy the predicate then the child is replaced bynull.- Parameters:
keep- a node predicate specifying which nodes to keep
-
nodeKind
ASTNode.NodeKind nodeKind()Returns the node kind: this is an element of the enumerated typeASTNode.NodeKind, which is used to categorize the different kinds of nodes.- Returns:
- The node kind
-
numChildren
int numChildren()Returns the number of child nodes of this AST node. This includes children which arenull!- Returns:
- the number of child nodes of this node
-
parent
ASTNode parent()Returns the parent of this node, ornullif this node has no parent.- Returns:
- parent node or
null
-
print
Prints a long-form textual representation of this node. The form usually involves multiple lines.- Parameters:
prefix- a string which should be prepended to every line of output; typically something like "| | " which is used to control indentationout- stream to which to printincludeSource- should the source information be included in the print-out? This incorporates the file name, line number(s), and start and end character indexes for the source code corresponding to this node
-
removeChild
Removes the child at given
indexfrom this node.The index must be in the range [0,n-1], where n is the value returned by
numChildren()in the pre-state (i.e., before this method is invoked). If there is no child at the given index (i.e., child isnull), this is a no-op.If the removed child is non-
null, its parent is set tonull.- Parameters:
index- nonnegative integer in the range [0,n-1], where n is the number of children before executing this method- Returns:
- the child that was removed (may be
null) - Throws:
ASTException- if this node is not free, orindexis not in the range [0,n-1]
-
remove
void remove()Removes this node from its parent. If the parent of this node is alreadynull, this is a no-op. -
setAttribute
Sets the attribute value associated to the given key. This method also checks that the value belongs to the correct class. Note that attribute keys are generated by calling methodNodeFactory.newAttribute(String, Class).- Parameters:
key- the attribute keyvalue- the attribute value
-
setChild
Sets the child node at the given index. This node (i.e.,
this) must be free (not owned by an AST) when this method is called.The child may be
nullor non-null. A non-nullchild must have anullparent, i.e., it must not be the child of another node.If there is already a non-
nullchild of this node in positionindex, the old child is removed, i.e., its parent is set tonull.The caller is responsible for ensuring that the child is of the appropriate kind and type.
The index can be any nonnegative integer. The list of children will be expanded as necessary with
nullvalues in order to incorporate the index.To illustrate how this method could be used, consider the case of swapping two nodes. Supposed
u1andu2are nodes,u1has a non-nullchild in positioni1, andu2has a non-nullchild in positioni2, and we wish to swap the two children. This could be accomplished with the following code:ASTNode v1 = u1.removeChild(i1), v2 = u2.removeChild(i2); u1.setChild(i1, v2); u2.setChild(i2, v1);
- Parameters:
index- any nonnegative integerchild- a node (or null) to be made the index-th child of this node- Returns:
- the old child in position
index(may benull) - Throws:
ASTException- if any of the following hold: (1) this node is not free, (2)indexis negative, or (3)childis notnulland has a non-nullparent.
-
setId
void setId(int id) Sets the ID number of this node.- Parameters:
id- the ID number
-
setOwner
Sets the owner of this node to the given AST.- Parameters:
owner- the AST to make the owner of this node
-
setScope
Sets the scope of this syntactic element.- Parameters:
scope- the scope
-
addTransformAnnotation
-
removeTransformAnnotation
void removeTransformAnnotation(int index) -
addAllTransformAnnotations
-
transformAnnotations
List<TransformNode> transformAnnotations() -
equiv
Is the given AST node equivalent to me?- Parameters:
that- The given AST node to be compared.- Returns:
- True iff this AST node is equivalent with that AST node.
-
diff
Returns the first difference between this AST node and that node.- Parameters:
that- The given AST node to be compared.- Returns:
- The difference of this AST node and that node, null if both nodes are equivalent.
-
toString
String toString()Returns a short textual representation of this node only. -
nextDFS
ASTNode nextDFS()Finds next non-null node in AST in DFS order.- Returns:
- next non-null node in DFS order or null if there is none
-
prettyPrint
Pretty-prints this AST node (and its descendants) in a form that should be similar to the actual programming language.- Parameters:
out- stream to which output should be sent
-
prettyRepresentation
StringBuffer prettyRepresentation()Returns the pretty representation of this AST node (and its descendants) in a form that should be similar to the actual programming language.- Returns:
- the pretty representation of this AST node (and its descendants) in a form that should be similar to the actual programming language.
-
prettyRepresentation
Returns the pretty representation of this AST node (and its descendants) in a form that should be similar to the actual programming language.- Parameters:
maxLength- the maximal length of the string representation of this node; -1 if the length is unlimited- Returns:
- the pretty representation of this AST node (and its descendants) in a form that should be similar to the actual programming language.
-