Package com.oracle.truffle.api.nodes
Class Node
java.lang.Object
com.oracle.truffle.api.nodes.Node
- All Implemented Interfaces:
NodeInterface
,Cloneable
- Direct Known Subclasses:
DirectCallNode
,IndirectCallNode
,LoopNode
,ProbeNode
,RootNode
Abstract base class for all Truffle nodes.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interface
Marks fields that represent child nodes of this node.static @interface
Marks array fields that are children of this node. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal void
accept
(NodeVisitor nodeVisitor) Invokes theNodeVisitor.visit(Node)
method for this node and recursively also for all child nodes.final void
final void
assignSourceSection
(SourceSection section) Assigns a link to a guest language source section to this node.final void
final <T> T
final void
Clears any previously assigned guest language source code from this node.protected final Object
clone()
Deprecated.copy()
Creates a shallow copy of this node.Iterator over the children of this node.getCost()
Returns a rough estimate for the cost of thisNode
.Returns properties of this node interesting for debugging and can be overwritten by subclasses to add their own custom properties.Returns a user-readable description of the purpose of the Node, or "" if no description is available.final SourceSection
Retrieves the guest language source code section that is currently assigned to this node.Returns a string representing the language this node has been implemented for.final Node
The current parent node of this node.final RootNode
Get the root node of the tree a node belongs to.final SourceSection
Retrieves the guest language source code section that is currently assigned to this node.protected final <T extends Node>
Tinsert
(T newChild) Method that updates the link to the parent in the specified new child node to this node.protected final <T extends Node>
T[]insert
(T[] newChildren) Method that updates the link to the parent in the array of specified new child nodes to this node.final boolean
Checks if this node is properly adopted by a parent and can be replaced.protected void
onAdopt()
Subclasses ofNode
can implement this method to execute extra functionality when a node is effectively inserted into the AST.protected void
onReplace
(Node newNode, CharSequence reason) Intended to be implemented by subclasses ofNode
to receive a notification when the node is rewritten.final <T extends Node>
Treplace
(T newNode) Replaces this node with another node.final <T extends Node>
Treplace
(T newNode, CharSequence reason) Replaces this node with another node.toString()
Converts this node to a textual representation useful for debugging.
-
Constructor Details
-
Node
protected Node() -
Node
-
-
Method Details
-
assignSourceSection
Assigns a link to a guest language source section to this node.- Parameters:
section
- the object representing a section in guest language source code
-
getCost
Returns a rough estimate for the cost of thisNode
. This estimate can be used by runtime systems or guest languages to implement heuristics based on Truffle ASTs. This method is intended to be overridden by subclasses. The default implementation returns the value ofNodeInfo.cost()
of theNodeInfo
annotation declared at the subclass. If noNodeInfo
annotation is declared the method returnsNodeCost.MONOMORPHIC
as a default value. -
clearSourceSection
public final void clearSourceSection()Clears any previously assigned guest language source code from this node. -
getSourceSection
Retrieves the guest language source code section that is currently assigned to this node.- Returns:
- the assigned source code section
-
getEncapsulatingSourceSection
Retrieves the guest language source code section that is currently assigned to this node.- Returns:
- the assigned source code section
-
insert
Method that updates the link to the parent in the array of specified new child nodes to this node.- Parameters:
newChildren
- the array of new children whose parent should be updated- Returns:
- the array of new children
-
insert
Method that updates the link to the parent in the specified new child node to this node.- Parameters:
newChild
- the new child whose parent should be updated- Returns:
- the new child
-
adoptChildren
public final void adoptChildren() -
getDebugProperties
Returns properties of this node interesting for debugging and can be overwritten by subclasses to add their own custom properties.- Returns:
- the properties as a key/value hash map
-
getParent
The current parent node of this node.- Returns:
- the parent node
-
replace
Replaces this node with another node. If there is a source section (seegetSourceSection()
) associated with this node, it is transferred to the new node.- Parameters:
newNode
- the new node that is the replacementreason
- a description of the reason for the replacement- Returns:
- the new node
-
replace
Replaces this node with another node. If there is a source section (seegetSourceSection()
) associated with this node, it is transferred to the new node.- Parameters:
newNode
- the new node that is the replacement- Returns:
- the new node
-
isReplaceable
public final boolean isReplaceable()Checks if this node is properly adopted by a parent and can be replaced.- Returns:
true
if it is safe to replace this node.
-
onReplace
Intended to be implemented by subclasses ofNode
to receive a notification when the node is rewritten. This method is invoked before the actual replace has happened.- Parameters:
newNode
- the replacement nodereason
- the reason the replace supplied
-
onAdopt
protected void onAdopt()Subclasses ofNode
can implement this method to execute extra functionality when a node is effectively inserted into the AST. TheonAdopt
callback is called after the node has been effectively inserted, and it is guaranteed to be called only once for any given node. -
accept
Invokes theNodeVisitor.visit(Node)
method for this node and recursively also for all child nodes.- Parameters:
nodeVisitor
- the visitor
-
getChildren
Iterator over the children of this node.- Returns:
- the iterator
-
copy
Creates a shallow copy of this node.- Returns:
- the new copy
-
clone
Deprecated.This method must never be called. It enforces thatObject.clone()
is not directly called by subclasses. Use thecopy()
method instead.- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-
getRootNode
Get the root node of the tree a node belongs to.- Returns:
- the
RootNode
ornull
if there is none.
-
toString
Converts this node to a textual representation useful for debugging. -
atomic
-
atomic
-
getDescription
Returns a user-readable description of the purpose of the Node, or "" if no description is available. -
getLanguage
Returns a string representing the language this node has been implemented for. If the language is unknown, returns "".
-