Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/CreateCastTest.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/CreateCastTest.java@b466199f19e1 |
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 org.junit.*; | |
26 | |
27 import com.oracle.truffle.api.dsl.*; | |
28 import com.oracle.truffle.api.dsl.test.CreateCastTestFactory.CreateCastNode1Factory; | |
29 import com.oracle.truffle.api.dsl.test.CreateCastTestFactory.CreateCastNode2Factory; | |
30 import com.oracle.truffle.api.dsl.test.CreateCastTestFactory.CreateCastNode3Factory; | |
31 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ChildrenNode; | |
32 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; | |
33 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; | |
34 import com.oracle.truffle.api.nodes.*; | |
35 | |
36 @SuppressWarnings("unused") | |
37 public class CreateCastTest { | |
38 | |
39 @Test | |
40 public void testCastNode1() { | |
41 TestRootNode<CreateCastNode1> root = TestHelper.createRoot(CreateCastNode1Factory.getInstance()); | |
42 Assert.assertEquals(1, root.getNode().invocations); | |
43 } | |
44 | |
45 @Test | |
46 public void testCastNode2() { | |
47 TestRootNode<CreateCastNode2> root = TestHelper.createRoot(CreateCastNode2Factory.getInstance()); | |
48 Assert.assertEquals(2, root.getNode().invocations); | |
49 } | |
50 | |
51 @Test | |
52 public void testCastNode3() { | |
53 TestRootNode<CreateCastNode3> root = TestHelper.createRoot(CreateCastNode3Factory.getInstance()); | |
54 Assert.assertEquals(1, root.getNode().invocations); | |
55 } | |
56 | |
57 @NodeChild("a") | |
58 abstract static class CreateCastNode1 extends ValueNode { | |
59 | |
60 int invocations = 0; | |
61 | |
62 @CreateCast({"a"}) | |
63 public ValueNode createCast(ValueNode node) { | |
64 invocations++; | |
65 return node; | |
66 } | |
67 | |
68 @Specialization | |
69 public int doInteger(int a) { | |
70 throw new AssertionError(); | |
71 } | |
72 } | |
73 | |
74 @NodeChildren({@NodeChild("a"), @NodeChild("b")}) | |
75 abstract static class CreateCastNode2 extends ValueNode { | |
76 | |
77 int invocations = 0; | |
78 | |
79 @CreateCast({"a", "b"}) | |
80 public ValueNode createCast(ValueNode node) { | |
81 invocations++; | |
82 return node; | |
83 } | |
84 | |
85 @Specialization | |
86 public int doInteger(int a, int b) { | |
87 throw new AssertionError(); | |
88 } | |
89 } | |
90 | |
91 abstract static class CreateCastNode3 extends ChildrenNode { | |
92 | |
93 int invocations = 0; | |
94 | |
95 @CreateCast("children") | |
96 public ValueNode[] createCast(ValueNode[] node) { | |
97 invocations++; | |
98 return node; | |
99 } | |
100 | |
101 @Specialization | |
102 public int doInteger(int a) { | |
103 throw new AssertionError(); | |
104 } | |
105 } | |
106 | |
107 @NodeChild("a") | |
108 abstract static class CreateCastFailNode1 extends ValueNode { | |
109 | |
110 @ExpectError({"Specified child '' not found."}) | |
111 @CreateCast({""}) | |
112 public ValueNode createCast(Node child) { | |
113 throw new AssertionError(); | |
114 } | |
115 | |
116 @Specialization | |
117 public int doInteger(int a) { | |
118 throw new AssertionError(); | |
119 } | |
120 } | |
121 | |
122 } |