Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/CreateCastTest.java @ 14765:365800f2a7aa
SnippetCounter: use own location for counter
author | Bernhard Urban <bernhard.urban@jku.at> |
---|---|
date | Wed, 26 Mar 2014 21:52:45 +0100 |
parents | b466199f19e1 |
children |
rev | line source |
---|---|
13531
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.dsl.test; |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import org.junit.*; |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 import com.oracle.truffle.api.dsl.*; |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import com.oracle.truffle.api.dsl.test.CreateCastTestFactory.CreateCastNode1Factory; |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 import com.oracle.truffle.api.dsl.test.CreateCastTestFactory.CreateCastNode2Factory; |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.dsl.test.CreateCastTestFactory.CreateCastNode3Factory; |
13533
b466199f19e1
Truffle-DSL: fixed bug when using @CreateCast with children arrays.
Christian Humer <christian.humer@gmail.com>
parents:
13531
diff
changeset
|
31 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ChildrenNode; |
13531
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 import com.oracle.truffle.api.nodes.*; |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 @SuppressWarnings("unused") |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 public class CreateCastTest { |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 @Test |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 public void testCastNode1() { |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 TestRootNode<CreateCastNode1> root = TestHelper.createRoot(CreateCastNode1Factory.getInstance()); |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 Assert.assertEquals(1, root.getNode().invocations); |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 } |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 @Test |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 public void testCastNode2() { |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 TestRootNode<CreateCastNode2> root = TestHelper.createRoot(CreateCastNode2Factory.getInstance()); |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 Assert.assertEquals(2, root.getNode().invocations); |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 } |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 @Test |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 public void testCastNode3() { |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 TestRootNode<CreateCastNode3> root = TestHelper.createRoot(CreateCastNode3Factory.getInstance()); |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 Assert.assertEquals(1, root.getNode().invocations); |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 } |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 @NodeChild("a") |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 abstract static class CreateCastNode1 extends ValueNode { |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 int invocations = 0; |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
61 |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
62 @CreateCast({"a"}) |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 public ValueNode createCast(ValueNode node) { |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 invocations++; |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 return node; |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 } |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
67 |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 @Specialization |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 public int doInteger(int a) { |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 throw new AssertionError(); |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 } |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 } |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
74 @NodeChildren({@NodeChild("a"), @NodeChild("b")}) |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 abstract static class CreateCastNode2 extends ValueNode { |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
76 |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 int invocations = 0; |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
78 |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
79 @CreateCast({"a", "b"}) |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
80 public ValueNode createCast(ValueNode node) { |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
81 invocations++; |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
82 return node; |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
83 } |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
84 |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
85 @Specialization |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
86 public int doInteger(int a, int b) { |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
87 throw new AssertionError(); |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
88 } |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
89 } |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
90 |
13533
b466199f19e1
Truffle-DSL: fixed bug when using @CreateCast with children arrays.
Christian Humer <christian.humer@gmail.com>
parents:
13531
diff
changeset
|
91 abstract static class CreateCastNode3 extends ChildrenNode { |
13531
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
92 |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
93 int invocations = 0; |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
94 |
13533
b466199f19e1
Truffle-DSL: fixed bug when using @CreateCast with children arrays.
Christian Humer <christian.humer@gmail.com>
parents:
13531
diff
changeset
|
95 @CreateCast("children") |
13531
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
96 public ValueNode[] createCast(ValueNode[] node) { |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
97 invocations++; |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
98 return node; |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
99 } |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
100 |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
101 @Specialization |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
102 public int doInteger(int a) { |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
103 throw new AssertionError(); |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
104 } |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
105 } |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
106 |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
107 @NodeChild("a") |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
108 abstract static class CreateCastFailNode1 extends ValueNode { |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
109 |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
110 @ExpectError({"Specified child '' not found."}) |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
111 @CreateCast({""}) |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
112 public ValueNode createCast(Node child) { |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
113 throw new AssertionError(); |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
114 } |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
115 |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
116 @Specialization |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
117 public int doInteger(int a) { |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
118 throw new AssertionError(); |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
119 } |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
120 } |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
121 |
1f870eaf1e96
Truffle-DSL: Added test for @CreateCast.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
122 } |