|
| 1 | +/* |
| 2 | + * Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. This |
| 3 | + * code is released under a tri EPL/GPL/LGPL license. You can use it, |
| 4 | + * redistribute it and/or modify it under the terms of the: |
| 5 | + * |
| 6 | + * Eclipse Public License version 2.0, or |
| 7 | + * GNU General Public License version 2, or |
| 8 | + * GNU Lesser General Public License version 2.1. |
| 9 | + */ |
| 10 | +package org.truffleruby.language.arguments; |
| 11 | + |
| 12 | +import com.oracle.truffle.api.nodes.DirectCallNode; |
| 13 | +import com.oracle.truffle.api.nodes.IndirectCallNode; |
| 14 | +import com.oracle.truffle.api.nodes.Node; |
| 15 | + |
| 16 | +import org.truffleruby.RubyContext; |
| 17 | +import org.truffleruby.language.FrameAndVariablesSendingNode; |
| 18 | +import org.truffleruby.language.RubyNode; |
| 19 | + |
| 20 | +public interface CallerDataReadingNode { |
| 21 | + public void startSending(FrameAndVariablesSendingNode node); |
| 22 | + |
| 23 | + public static boolean notifyCallerToSendData(RubyContext context, Node callerNode, CallerDataReadingNode reader) { |
| 24 | + if (callerNode instanceof DirectCallNode || callerNode instanceof IndirectCallNode) { |
| 25 | + Node parent = callerNode.getParent(); |
| 26 | + while (parent != null) { |
| 27 | + if (parent instanceof FrameAndVariablesSendingNode) { |
| 28 | + reader.startSending((FrameAndVariablesSendingNode) parent); |
| 29 | + return true; |
| 30 | + } |
| 31 | + if (parent instanceof RubyNode) { |
| 32 | + // A node with source info representing Ruby code, we could not find the FrameAndVariablesSendingNode |
| 33 | + return false; |
| 34 | + } |
| 35 | + parent = parent.getParent(); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + return false; |
| 40 | + } |
| 41 | +} |
0 commit comments