use of com.oracle.truffle.api.nodes.Node in project graal by oracle.
the class NodeUtilTest method testAccept.
@Test
public void testAccept() {
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];
testForEachNode.accept(new NodeVisitor() {
public boolean visit(Node node) {
((VisitableNode) node).visited++;
count[0]++;
return true;
}
});
Assert.assertEquals(4, count[0]);
Assert.assertEquals(1, testForEachNode.visited);
Assert.assertEquals(1, testNode1.visited);
Assert.assertEquals(1, testNode2.visited);
Assert.assertEquals(1, testNode3.visited);
}
use of com.oracle.truffle.api.nodes.Node in project graal by oracle.
the class NodeUtilTest method iterate.
private static int iterate(Iterator<Node> iterator) {
int iterationCount = 0;
while (iterator.hasNext()) {
Node node = iterator.next();
if (node == null) {
continue;
}
if (node instanceof TestNode) {
((TestNode) node).visited = iterationCount;
} else if (node instanceof TestRootNode) {
((TestRootNode) node).visited = iterationCount;
} else {
throw new AssertionError();
}
iterationCount++;
}
return iterationCount;
}
use of com.oracle.truffle.api.nodes.Node 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);
}
use of com.oracle.truffle.api.nodes.Node in project graal by oracle.
the class RootNodeTest method testNotReplacable3.
@Test(expected = IllegalStateException.class)
@Ignore
public void testNotReplacable3() {
TestRootNode2 rootNode = new TestRootNode2();
rootNode.rootNodeAsChild = new Node() {
};
rootNode.adoptChildren();
rootNode.rootNodeAsChild.replace(new TestRootNode());
}
use of com.oracle.truffle.api.nodes.Node in project graal by oracle.
the class ChildrenNodesTest method testMultipleChildrenFields.
@Test
public void testMultipleChildrenFields() {
TruffleRuntime runtime = Truffle.getRuntime();
TestChildNode firstChild = new TestChildNode();
TestChildNode secondChild = new TestChildNode();
TestChildNode thirdChild = new TestChildNode();
TestChildNode forthChild = new TestChildNode();
TestRootNode rootNode = new TestRoot2Node(new TestChildNode[] { firstChild, secondChild }, new TestChildNode[] { thirdChild, forthChild });
CallTarget target = runtime.createCallTarget(rootNode);
Assert.assertEquals(rootNode, firstChild.getParent());
Assert.assertEquals(rootNode, secondChild.getParent());
Assert.assertEquals(rootNode, thirdChild.getParent());
Assert.assertEquals(rootNode, forthChild.getParent());
Iterator<Node> iterator = rootNode.getChildren().iterator();
Assert.assertEquals(firstChild, iterator.next());
Assert.assertEquals(secondChild, iterator.next());
Assert.assertEquals(thirdChild, iterator.next());
Assert.assertEquals(forthChild, iterator.next());
Assert.assertFalse(iterator.hasNext());
Object result = target.call();
Assert.assertEquals(2 * 42, result);
}
Aggregations