Search in sources :

Example 11 with NodeVisitor

use of com.oracle.truffle.api.nodes.NodeVisitor in project graal by oracle.

the class NodeUtilTest method testForEachChild.

@Test
public void testForEachChild() {
    TestRootNode root = new TestRootNode();
    TestForEachNode testForEachNode = new TestForEachNode(1);
    root.child0 = testForEachNode;
    TestNode testNode1 = new TestNode();
    testForEachNode.firstChild = testNode1;
    TestNode testNode2 = new TestNode();
    testForEachNode.children[0] = testNode2;
    TestNode testNode3 = new TestNode();
    testForEachNode.lastChild = testNode3;
    root.adoptChildren();
    int[] count = new int[1];
    NodeUtil.forEachChild(root, new NodeVisitor() {

        public boolean visit(Node node) {
            Assert.assertSame(testForEachNode, node);
            count[0]++;
            return true;
        }
    });
    Assert.assertEquals(1, count[0]);
    count[0] = 0;
    NodeUtil.forEachChild(testForEachNode, new NodeVisitor() {

        public boolean visit(Node node) {
            ((VisitableNode) node).visited++;
            count[0]++;
            return true;
        }
    });
    Assert.assertEquals(3, count[0]);
    Assert.assertEquals(1, testNode1.visited);
    Assert.assertEquals(1, testNode2.visited);
    Assert.assertEquals(1, testNode3.visited);
}
Also used : Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) NodeVisitor(com.oracle.truffle.api.nodes.NodeVisitor) Test(org.junit.Test)

Aggregations

Node (com.oracle.truffle.api.nodes.Node)11 NodeVisitor (com.oracle.truffle.api.nodes.NodeVisitor)11 RootNode (com.oracle.truffle.api.nodes.RootNode)7 WrapperNode (com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode)3 SLEvalRootNode (com.oracle.truffle.sl.nodes.SLEvalRootNode)3 SLStatementNode (com.oracle.truffle.sl.nodes.SLStatementNode)3 SLBlockNode (com.oracle.truffle.sl.nodes.controlflow.SLBlockNode)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)2 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 Test (org.junit.Test)2 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)1 EventContext (com.oracle.truffle.api.instrumentation.EventContext)1 ExecutionEventListener (com.oracle.truffle.api.instrumentation.ExecutionEventListener)1 SourceSection (com.oracle.truffle.api.source.SourceSection)1 SLBuiltinNode (com.oracle.truffle.sl.builtins.SLBuiltinNode)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1