comparison truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/NodeChildTest.java @ 21951:9c8c0937da41

Moving all sources into truffle subdirectory
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 17 Jun 2015 10:58:08 +0200
parents graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/NodeChildTest.java@18c0f02fa4d2
children dc83cc1f94f2
comparison
equal deleted inserted replaced
21950:2a5011c7e641 21951:9c8c0937da41
1 /*
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.oracle.truffle.api.dsl.test;
24
25 import static com.oracle.truffle.api.dsl.test.TestHelper.*;
26 import static org.junit.Assert.*;
27
28 import org.junit.*;
29
30 import com.oracle.truffle.api.dsl.*;
31 import com.oracle.truffle.api.dsl.test.NodeFieldTestFactory.IntFieldTestNodeFactory;
32 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode;
33
34 public class NodeChildTest {
35
36 @Test
37 public void testIntField() {
38 assertEquals(42, createCallTarget(IntFieldTestNodeFactory.create(42)).call());
39 }
40
41 @NodeChild("child0")
42 abstract static class Base0Node extends ValueNode {
43
44 }
45
46 @NodeChild(value = "child1", type = ValueNode.class)
47 abstract static class Child0Node extends Base0Node {
48
49 @Specialization
50 int intField(int child0, int child1) {
51 return child0 + child1;
52 }
53 }
54
55 @NodeChildren({@NodeChild("child0")})
56 abstract static class Base1Node extends ValueNode {
57
58 }
59
60 @NodeChildren({@NodeChild(value = "child1", type = ValueNode.class)})
61 abstract static class Child1Node extends Base1Node {
62
63 @Specialization
64 int intField(int child0, int child1) {
65 return child0 + child1;
66 }
67 }
68
69 @NodeChildren({@NodeChild("child0"), @NodeChild("child1")})
70 abstract static class Base2Node extends ValueNode {
71
72 }
73
74 @ExpectError("Not enough child node declarations found. Please annotate the node class with addtional @NodeChild annotations or remove all execute methods that do not provide all evaluated values. "
75 + "The following execute methods do not provide all evaluated values for the expected signature size 3:%")
76 @NodeChildren({@NodeChild(value = "child2", type = ValueNode.class)})
77 abstract static class Child2Node extends Base1Node {
78
79 @ExpectError("Method signature (int, int, int) does not match to the expected signature:%")
80 @Specialization
81 int intField(int child0, int child1, int child2) {
82 return child0 + child1 + child2;
83 }
84 }
85
86 @NodeChildren({@NodeChild(value = "receiver", type = ValueNode.class), @NodeChild(value = "arguments", type = ValueNode[].class)})
87 abstract static class BaseNode extends ValueNode {
88 public abstract ValueNode getReceiver();
89
90 public abstract ValueNode[] getArguments();
91 }
92
93 abstract static class UnaryNode extends BaseNode {
94 @Specialization
95 public int doIt(int value) {
96 return value;
97 }
98 }
99
100 abstract static class BinaryNode extends BaseNode {
101 @Specialization
102 public int doIt(int value0, int value1) {
103 return value0 + value1;
104 }
105 }
106
107 abstract static class TernaryNode extends BaseNode {
108 @Specialization
109 public int doIt(int value0, int value1, int value2) {
110 return value0 + value1 + value2;
111 }
112 }
113
114 }