Class NodeLibrary
- All Implemented Interfaces:
NodeInterface, Cloneable
Node
location. The receiver of this library must be an
instrumentable
Node
that has a root node
.- Since:
- 20.3
-
Nested Class Summary
Nested classes/interfaces inherited from class Node
Node.Child, Node.Children
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic LibraryFactory
<NodeLibrary> Returns the library factory for the node library.getReceiverMember
(Object node, Frame frame) Returns an object that represents the receiver name when available.getRootInstance
(Object node, Frame frame) Returns the current instance of guest language representation of the root node (e.g.Get an object representing a local scope containing variables visible at the node location.static NodeLibrary
Returns the uncached automatically dispatched version of the node library.static NodeLibrary
getUncached
(Object node) Returns the uncached manually dispatched version of the node library.Wraps the value to filter or add scoping specific information for values associated with the current language and location in the code.boolean
hasReceiverMember
(Object node, Frame frame) Returnstrue
, if there is a named receiver object, elsefalse
.boolean
hasRootInstance
(Object node, Frame frame) Returnstrue
, if a current instance of the guest language representation of the root node (e.g.boolean
Returnstrue
, if the node is in a scope containing local variables, elsefalse
.Methods inherited from class Node
accept, adoptChildren, atomic, atomic, copy, deepCopy, getChildren, getCost, getDebugProperties, getDescription, getEncapsulatingSourceSection, getLock, getParent, getRootNode, getSourceSection, insert, insert, isAdoptable, isSafelyReplaceableBy, notifyInserted, onReplace, replace, replace, reportPolymorphicSpecialize, reportReplace, toString
-
Constructor Details
-
NodeLibrary
protected NodeLibrary()- Since:
- 20.3
-
-
Method Details
-
hasScope
Returnstrue
, if the node is in a scope containing local variables, elsefalse
.This method must not cause any observable side-effects. If this method is implemented then also
getScope(Object, Frame, boolean)
must be implemented.- Parameters:
node
- a Node, nevernull
frame
- aFrame
, can benull
in case of lexical access.- Since:
- 20.3
- See Also:
-
getScope
public Object getScope(Object node, Frame frame, boolean nodeEnter) throws UnsupportedMessageException Get an object representing a local scope containing variables visible at the node location. The returned object must respondtrue
toInteropLibrary.isScope(Object)
. The scope object exposes all locally visible variables as flattenedmembers
, including all parent scopes (for example block, closure, lexical or dynamic scopes). Local scopes are associated with aFrame
. SeeInteropLibrary.isScope(Object)
for details.This method must not cause any observable side-effects. If this method is implemented then also
hasScope(Object, Frame)
must be implemented.A returned scope is only valid while the regular guest language execution on this thread is suspended. If the guest execution is continued e.g. if a new instrumentation event occurs, the scope is invalid and should be discarded.
- Parameters:
node
- a Node, nevernull
frame
- aFrame
, can benull
in case of lexical access.nodeEnter
- whentrue
, the location that determines scope variables is at the enter to the node execution, elsefalse
. Usetrue
when called e.g. by instruments fromExecutionEventNode.onEnter(VirtualFrame)
andfalse
when called e.g. fromExecutionEventNode.onReturnValue(VirtualFrame, Object)
. This argument helps to determine visible variables in case that some variables are added during the node execution.- Returns:
- An interop object with
InteropLibrary.isScope(Object)
being true. - Throws:
UnsupportedMessageException
- if and only ifhasScope(Object, Frame)
returnsfalse
for the same node and frame.- Since:
- 20.3
-
hasReceiverMember
Returnstrue
, if there is a named receiver object, elsefalse
.This method must not cause any observable side-effects. If this method is implemented then also
getReceiverMember(Object, Frame)
must be implemented.- Parameters:
node
- a Node, nevernull
frame
- aFrame
, can benull
in case of lexical access.- Since:
- 20.3
- See Also:
-
getReceiverMember
Returns an object that represents the receiver name when available. The returned value is guaranteed to return true forInteropLibrary.isString(Object)
. Examples for receiver names arethis
in Java or self in Ruby or Python. The value of the receiver object can be retrieved from thescope
by converting the member to a string usingInteropLibrary.isString(Object)
. The return value of this method is an Object intentionally to allow the member to have additional interop traits.This method must not cause any observable side-effects. If this method is implemented then also
hasReceiverMember(Object, Frame)
must be implemented.- Parameters:
node
- a Node, nevernull
frame
- aFrame
, can benull
in case of lexical access.- Returns:
- an
interop string object
. - Throws:
UnsupportedMessageException
- if and only ifhasReceiverMember(Object, Frame)
returnsfalse
for the same node and frame.- Since:
- 20.3
- See Also:
-
hasRootInstance
Returnstrue
, if a current instance of the guest language representation of the root node (e.g. the enclosing guest language function) is available, elsefalse
.Guest languages will likely require a context lookup to resolve the root instance object. This method must not cause any observable side-effects. If this method is implemented then also
getRootInstance(Object, Frame)
must be implemented.- Parameters:
node
- a Node, nevernull
frame
- aFrame
, can benull
in case of lexical access, in which case the instance would likely not be available.- Since:
- 20.3
- See Also:
-
getRootInstance
Returns the current instance of guest language representation of the root node (e.g. the enclosing guest language function), when available.This method must not cause any observable side-effects. If this method is implemented then also
hasRootInstance(Object, Frame)
must be implemented.- Parameters:
node
- a Node, nevernull
frame
- aFrame
, can benull
in case of lexical access, in which case the instance would likely not be available.- Returns:
- the root instance value which must be an
interop
andexecutable
value. - Throws:
UnsupportedMessageException
- if and only ifhasRootInstance(Object, Frame)
returnsfalse
for the same node and frame.- Since:
- 20.3
- See Also:
-
getView
Wraps the value to filter or add scoping specific information for values associated with the current language and location in the code. Allows the language to augment the perspective tools have on values depending on location and frame. This may be useful to apply local specific visibility rules. By default this method does return the passed value, not applying any scope information to the value. If a language does not implement any scoping and/or has not concept of visibility then this method typically can stay without an implementation. A typical implementation of this method may do the following:- Apply visibility and scoping rules to the value hiding or removing members from the object.
- Add or remove implicit members that are only available within this source location.
This method is only invoked with values that are associated with the current
language
. For values without language thelanguage view
is requested first before the scoped view is requested. If this method needs an implementation thenTruffleLanguage.getLanguageView(Object, Object)
should be implemented as well.Scoped views may be implemented in a very similar way to
language views
. Please refer to the examples from this method.- Parameters:
node
- the current source location. Guaranteed to be a node from aRootNode
associated with this language. Nevernull
.frame
- the current active frame. Guaranteed to be a frame from aRootNode
associated with this language. Nevernull
.value
- the value to provide scope information for. Nevernull
. Always associated with this language.- Since:
- 20.3
- See Also:
-
getFactory
Returns the library factory for the node library. Short-cut forResolvedLibrary.resolve(NodeLibrary.class)
.- Since:
- 20.3
- See Also:
-
getUncached
Returns the uncached automatically dispatched version of the node library. This is a short-cut for callingNodeLibrary.getFactory().getUncached()
.- Since:
- 20.3
- See Also:
-
getUncached
Returns the uncached manually dispatched version of the node library. This is a short-cut for callingNodeLibrary.getFactory().getUncached(v)
.- Since:
- 20.3
- See Also:
-