Java Code Examples for com.oracle.truffle.api.nodes.Node#getParent()

The following examples show how to use com.oracle.truffle.api.nodes.Node#getParent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FunctionRootEventHandler.java    From nodeprof.js with Apache License 2.0 6 votes vote down vote up
/**
 * @return the source of the instrumented node (or its closest parent), or null if no source is
 *         available
 */
public Source getSource() {
    if (isRegularExpression() || this.isBuiltin) {
        return null;
    }

    Node n = context.getInstrumentedNode();
    while (n != null && !(n instanceof FunctionBodyNode)) {
        n = n.getParent();
    }

    if (n == null) {
        return null;
    }

    if (n.getSourceSection() == null) {
        return null;
    }

    return n.getSourceSection().getSource();
}
 
Example 2
Source File: HashemLexicalScope.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
private static HashemBlockNode getParentBlock(Node node) {
    HashemBlockNode block;
    Node parent = node.getParent();
    // Find a nearest block node.
    while (parent != null && !(parent instanceof HashemBlockNode)) {
        parent = parent.getParent();
    }
    if (parent != null) {
        block = (HashemBlockNode) parent;
    } else {
        block = null;
    }
    return block;
}
 
Example 3
Source File: UninitializedDispatchNode.java    From mumbler with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Object executeDispatch(VirtualFrame virtualFrame,
        CallTarget callTarget, Object[] arguments) {
    CompilerDirectives.transferToInterpreterAndInvalidate();

    Node cur = this;
    int size = 0;
    while (cur.getParent() instanceof DispatchNode) {
        cur = cur.getParent();
        size++;
    }
    InvokeNode invokeNode = (InvokeNode) cur.getParent();

    DispatchNode replacement;
    if (size < INLINE_CACHE_SIZE) {
        // There's still room in the cache. Add a new DirectDispatchNode.
        DispatchNode next = new UninitializedDispatchNode();
        replacement = new DirectDispatchNode(next, callTarget);
        this.replace(replacement);
    } else {
        replacement = new GenericDispatchNode();
        invokeNode.dispatchNode.replace(replacement);
    }

    // Call function with newly created dispatch node.
    return replacement.executeDispatch(virtualFrame, callTarget, arguments);
}