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