annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/SourceSectionTest.java @ 16921:f5541b01f374

Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
author Christian Humer <christian.humer@gmail.com>
date Mon, 25 Aug 2014 15:56:32 +0200
parents
children c5db657d93c1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16921
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
8 *
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
13 * accompanied this code).
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
14 *
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
18 *
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
21 * questions.
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
22 */
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
23 package com.oracle.truffle.api.dsl.test;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
24
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
25 import static com.oracle.truffle.api.dsl.test.TestHelper.*;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
26 import static org.hamcrest.CoreMatchers.*;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
27 import static org.junit.Assert.*;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
28
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
29 import org.junit.experimental.theories.*;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
30 import org.junit.runner.*;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
31
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
32 import com.oracle.truffle.api.dsl.*;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
33 import com.oracle.truffle.api.dsl.test.SourceSectionTestFactory.SourceSection0Factory;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
34 import com.oracle.truffle.api.dsl.test.TypeSystemTest.*;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
35 import com.oracle.truffle.api.nodes.*;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
36 import com.oracle.truffle.api.source.*;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
37
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
38 @RunWith(Theories.class)
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
39 public class SourceSectionTest {
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
40
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
41 @DataPoints public static final int[] data = new int[]{1, 2, 3, 4};
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
42
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
43 @Theory
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
44 public void testSourceSections(int value0, int value1, int value2) {
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
45 TestRootNode<SourceSection0> root = createRoot(SourceSection0Factory.getInstance());
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
46 SourceSection section = new NullSourceSection("a", "b");
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
47 root.getNode().assignSourceSection(section);
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
48 expectSourceSection(root.getNode(), section);
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
49 assertThat((int) executeWith(root, value0), is(value0));
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
50 expectSourceSection(root.getNode(), section);
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
51 assertThat((int) executeWith(root, value1), is(value1));
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
52 expectSourceSection(root.getNode(), section);
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
53 assertThat((int) executeWith(root, value2), is(value2));
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
54 expectSourceSection(root.getNode(), section);
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
55 }
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
56
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
57 private void expectSourceSection(Node root, SourceSection section) {
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
58 assertThat(root.getSourceSection(), is(sameInstance(section)));
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
59 for (Node child : root.getChildren()) {
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
60 if (child instanceof ArgumentNode) {
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
61 continue;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
62 }
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
63 if (child != null) {
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
64 expectSourceSection(child, section);
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
65 }
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
66 }
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
67 }
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
68
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
69 @NodeChild("a")
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
70 static class SourceSection0 extends ValueNode {
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
71
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
72 boolean isOne(int a) {
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
73 return a == 1;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
74 }
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
75
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
76 boolean isTwo(int a) {
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
77 return a == 2;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
78 }
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
79
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
80 boolean isThree(int a) {
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
81 return a == 3;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
82 }
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
83
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
84 @Specialization(guards = "isOne")
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
85 int do1(int a) {
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
86 return a;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
87 }
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
88
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
89 @Specialization(guards = "isTwo")
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
90 int do2(int a) {
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
91 return a;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
92 }
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
93
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
94 @Specialization(guards = "isThree")
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
95 int do3(int a) {
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
96 return a;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
97 }
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
98
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
99 @Fallback
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
100 Object do4(Object a) {
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
101 return a; // the generic answer to all questions
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
102 }
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
103 }
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
104 }