annotate truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/UnsupportedSpecializationTest.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/UnsupportedSpecializationTest.java@28479abd1a69
children dc83cc1f94f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13812
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
8 *
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
13 * accompanied this code).
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
14 *
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
18 *
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
21 * questions.
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
22 */
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
23 package com.oracle.truffle.api.dsl.test;
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
24
13861
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
25 import java.util.*;
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
26
13812
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
27 import org.junit.*;
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
28
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
29 import com.oracle.truffle.api.dsl.*;
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
30 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode;
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
31 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode;
13861
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
32 import com.oracle.truffle.api.dsl.test.UnsupportedSpecializationTestFactory.Unsupported1Factory;
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
33 import com.oracle.truffle.api.dsl.test.UnsupportedSpecializationTestFactory.Unsupported2Factory;
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
34 import com.oracle.truffle.api.nodes.*;
13812
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
35
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
36 public class UnsupportedSpecializationTest {
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
37
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
38 @Test
13861
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
39 public void testUnsupported1() {
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
40 TestRootNode<Unsupported1> root = TestHelper.createRoot(Unsupported1Factory.getInstance());
13812
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
41 try {
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
42 TestHelper.executeWith(root, "");
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
43 Assert.fail();
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
44 } catch (UnsupportedSpecializationException e) {
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
45 Assert.assertNotNull(e.getSuppliedValues());
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
46 Assert.assertEquals(1, e.getSuppliedValues().length);
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
47 Assert.assertEquals("", e.getSuppliedValues()[0]);
13861
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
48 Assert.assertSame(root.getNode().getChildren().iterator().next(), e.getSuppliedNodes()[0]);
13812
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
49 Assert.assertEquals(root.getNode(), e.getNode());
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
50 }
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
51 }
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
52
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
53 @NodeChild("a")
13861
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
54 abstract static class Unsupported1 extends ValueNode {
13812
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
55
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
56 @Specialization
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
57 public int doInteger(@SuppressWarnings("unused") int a) {
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
58 throw new AssertionError();
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
59 }
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
60 }
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
61
13861
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
62 @Test
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
63 public void testUnsupported2() {
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
64 TestRootNode<Unsupported2> root = TestHelper.createRoot(Unsupported2Factory.getInstance());
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
65 try {
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
66 TestHelper.executeWith(root, "", 1);
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
67 Assert.fail();
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
68 } catch (UnsupportedSpecializationException e) {
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
69 Assert.assertNotNull(e.getSuppliedValues());
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
70 Assert.assertNotNull(e.getSuppliedNodes());
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
71 Assert.assertEquals(3, e.getSuppliedValues().length);
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
72 Assert.assertEquals(3, e.getSuppliedNodes().length);
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
73 Assert.assertEquals("", e.getSuppliedValues()[0]);
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
74 Assert.assertEquals(false, e.getSuppliedValues()[1]);
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
75 Assert.assertEquals(null, e.getSuppliedValues()[2]);
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
76 List<Node> children = NodeUtil.findNodeChildren(root.getNode());
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
77 Assert.assertSame(children.get(0), e.getSuppliedNodes()[0]);
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
78 Assert.assertNull(e.getSuppliedNodes()[1]);
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
79 Assert.assertSame(children.get(1), e.getSuppliedNodes()[2]);
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
80 Assert.assertEquals(root.getNode(), e.getNode());
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
81 }
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
82 }
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
83
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
84 @SuppressWarnings("unused")
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
85 @NodeChildren({@NodeChild("a"), @NodeChild("b")})
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
86 abstract static class Unsupported2 extends ValueNode {
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
87
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
88 @ShortCircuit("b")
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
89 public boolean needsB(Object a) {
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
90 return false;
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
91 }
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
92
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
93 @Specialization
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
94 public int doInteger(int a, boolean hasB, int b) {
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
95 throw new AssertionError();
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
96 }
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
97 }
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
98
13812
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
99 }