annotate truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/SourceSectionTest.java @ 22241:14e6dfb1ef05

Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation" - Caused by lack of a "vm" known to the Accessor during most testing, making the Instrumenter unavailable, which is now required to create a CallTarget - Modified the Instrumenter/Accessor with a static field that can be reflectively "poked" with a vm value for testing - Create a pair of methods to globally enable/disable testing mode to modify that static field and restore it when tests complete.
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Tue, 22 Sep 2015 20:31:19 -0700
parents dc83cc1f94f2
children 0d36601f233e
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
22241
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
25 import static com.oracle.truffle.api.dsl.test.TestHelper.createRoot;
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
26 import static com.oracle.truffle.api.dsl.test.TestHelper.createRootPrefix;
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
27 import static com.oracle.truffle.api.dsl.test.TestHelper.executeWith;
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
28 import static org.hamcrest.CoreMatchers.is;
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
29 import static org.hamcrest.CoreMatchers.sameInstance;
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
30 import static org.junit.Assert.assertNull;
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
31 import static org.junit.Assert.assertThat;
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
32
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
33 import org.junit.After;
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
34 import org.junit.Before;
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
35 import org.junit.Test;
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
36 import org.junit.experimental.theories.DataPoints;
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
37 import org.junit.experimental.theories.Theories;
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
38 import org.junit.experimental.theories.Theory;
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
39 import org.junit.runner.RunWith;
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
40
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21987
diff changeset
41 import com.oracle.truffle.api.dsl.CreateCast;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21987
diff changeset
42 import com.oracle.truffle.api.dsl.Fallback;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21987
diff changeset
43 import com.oracle.truffle.api.dsl.NodeChild;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21987
diff changeset
44 import com.oracle.truffle.api.dsl.Specialization;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21987
diff changeset
45 import com.oracle.truffle.api.dsl.internal.SpecializationNode;
16921
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
46 import com.oracle.truffle.api.dsl.test.SourceSectionTestFactory.SourceSection0Factory;
16967
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
47 import com.oracle.truffle.api.dsl.test.SourceSectionTestFactory.SourceSection1Factory;
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
48 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ArgumentNode;
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
49 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode;
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
50 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode;
22241
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
51 import com.oracle.truffle.api.dsl.test.utilities.InstrumentationTestMode;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21987
diff changeset
52 import com.oracle.truffle.api.nodes.Node;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21987
diff changeset
53 import com.oracle.truffle.api.source.SourceSection;
16921
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
54
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
55 @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
56 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
57
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
58 @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
59
22241
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
60 @Before
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
61 public void before() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
62 InstrumentationTestMode.set(true);
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
63 }
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
64
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
65 @After
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
66 public void after() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
67 InstrumentationTestMode.set(false);
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
68 }
14e6dfb1ef05 Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
69
16921
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
70 @Theory
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
71 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
72 TestRootNode<SourceSection0> root = createRoot(SourceSection0Factory.getInstance());
21987
b2d1c8ff592a Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
73 SourceSection section = SourceSection.createUnavailable("a", "b");
16921
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
74 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
75 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
76 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
77 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
78 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
79 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
80 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
81 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
82 }
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
83
16967
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
84 private static void expectSourceSection(Node root, SourceSection section) {
16921
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
85 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
86 for (Node child : root.getChildren()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 16967
diff changeset
87 if (child instanceof ArgumentNode || child instanceof SpecializationNode) {
16921
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
88 continue;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
89 }
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
90 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
91 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
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 }
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
95
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
96 @NodeChild("a")
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
97 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
98
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
99 @Specialization(guards = "a == 1")
16921
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
100 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
101 return a;
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
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
104 @Specialization(guards = "a == 2")
16921
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
105 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
106 return a;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
107 }
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
108
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
109 @Specialization(guards = "a == 3")
16921
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
110 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
111 return a;
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
112 }
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
113
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
114 @Fallback
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
115 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
116 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
117 }
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
118 }
16967
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
119
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
120 @Test
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
121 public void testCreateCast() {
21987
b2d1c8ff592a Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
122 SourceSection section = SourceSection.createUnavailable("a", "b");
b2d1c8ff592a Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
123 assertNull(section.getSource());
16967
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
124 TestRootNode<SourceSection1> root = createRootPrefix(SourceSection1Factory.getInstance(), true, section);
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
125 expectSourceSection(root.getNode(), section);
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
126 assertThat((int) executeWith(root, 1), is(1));
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
127 expectSourceSection(root.getNode(), section);
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
128 }
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
129
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
130 @NodeChild("a")
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
131 static class SourceSection1 extends ValueNode {
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
132
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
133 public SourceSection1(SourceSection section) {
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
134 super(section);
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
135 }
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
136
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
137 @CreateCast("a")
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
138 public ValueNode cast(ValueNode node) {
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
139 assert getSourceSection() != null;
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
140 return node;
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
141 }
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
142
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
143 @Specialization
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
144 int do0(int a) {
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
145 return a;
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
146 }
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
147
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16921
diff changeset
148 }
16921
f5541b01f374 Truffle-DSL: fixed lost source sections for polymorphic specializations. (GRAAL-851 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
149 }