annotate truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ImportGuardsTest.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
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
8 *
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
13 * accompanied this code).
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
14 *
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
18 *
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
21 * questions.
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
22 */
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
23 package com.oracle.truffle.api.dsl.test;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
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.array;
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.assertRuns;
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
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 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
29 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
30 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
31
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
32 import com.oracle.truffle.api.dsl.ImportStatic;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
33 import com.oracle.truffle.api.dsl.NodeChild;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
34 import com.oracle.truffle.api.dsl.Specialization;
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
35 import com.oracle.truffle.api.dsl.test.ImportGuardsTestFactory.ImportGuards6Factory;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
36 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
37 import com.oracle.truffle.api.dsl.test.utilities.InstrumentationTestMode;
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
38
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
39 public class ImportGuardsTest {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
40
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
41 @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
42 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
43 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
44 }
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
45
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
46 @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
47 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
48 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
49 }
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
50
19285
259a416388d7 Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
51 @ImportStatic(Imports0.class)
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
52 @NodeChild("a")
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
53 static class ImportGuards0 extends ValueNode {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
54
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16851
diff changeset
55 @Specialization(guards = "staticGuard(a)")
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
56 int f0(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
57 return a;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
58 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
59 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
60
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
61 @NodeChild("a")
19285
259a416388d7 Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
62 @ImportStatic(Imports0.class)
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
63 static class ImportGuards1 extends ValueNode {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
64
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16851
diff changeset
65 @ExpectError("Error parsing expression 'nonStaticGuard(a)': The method nonStaticGuard is undefined for the enclosing scope.")
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16851
diff changeset
66 @Specialization(guards = "nonStaticGuard(a)")
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
67 int f1(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
68 return a;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
69 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
70
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16851
diff changeset
71 @ExpectError("Error parsing expression 'protectedGuard(a)': The method protectedGuard is undefined for the enclosing scope.")
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16851
diff changeset
72 @Specialization(guards = "protectedGuard(a)")
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
73 int f2(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
74 return a;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
75 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
76
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16851
diff changeset
77 @ExpectError("Error parsing expression 'packageGuard(a)': The method packageGuard is undefined for the enclosing scope.")
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16851
diff changeset
78 @Specialization(guards = "packageGuard(a)")
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
79 int f3(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
80 return a;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
81 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
82
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16851
diff changeset
83 @ExpectError("Error parsing expression 'privateGuard(a)': The method privateGuard is undefined for the enclosing scope.")
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16851
diff changeset
84 @Specialization(guards = "privateGuard(a)")
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
85 int f4(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
86 return a;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
87 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
88 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
89
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
90 public static class Imports0 {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
91 public static boolean staticGuard(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
92 return a == 0;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
93 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
94
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
95 public boolean nonStaticGuard(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
96 return a == 0;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
97 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
98
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
99 protected static boolean protectedGuard(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
100 return a == 0;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
101 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
102
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
103 static boolean packageGuard(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
104 return a == 0;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
105 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
106
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
107 @SuppressWarnings("unused")
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
108 private static boolean privateGuard(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
109 return a == 0;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
110 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
111
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
112 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
113
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
114 @ExpectError("The specified import guard class 'com.oracle.truffle.api.dsl.test.ImportGuardsTest.Imports1' must be public.")
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
115 @NodeChild("a")
19285
259a416388d7 Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
116 @ImportStatic(Imports1.class)
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
117 static class ImportGuards2 extends ValueNode {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
118
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
119 int do1(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
120 return a;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
121 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
122 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
123
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
124 static class Imports1 {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
125
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
126 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
127
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
128 @ExpectError("The specified import guard class 'com.oracle.truffle.api.dsl.test.ImportGuardsTest.Imports2' must be public.")
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
129 @NodeChild("a")
19285
259a416388d7 Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
130 @ImportStatic(Imports2.class)
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
131 static class ImportGuards3 extends ValueNode {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
132
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
133 int do1(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
134 return a;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
135 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
136 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
137
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
138 @ExpectError("The specified import guard class 'boolean' is not a declared type.")
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
139 @NodeChild("a")
19285
259a416388d7 Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
140 @ImportStatic(boolean.class)
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
141 static class ImportGuards4 extends ValueNode {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
142
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
143 int do1(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
144 return a;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
145 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
146 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
147
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
148 private static class Imports2 {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
149
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
150 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
151
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
152 @ExpectError("At least import guard classes must be specified.")
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
153 @NodeChild("a")
19285
259a416388d7 Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
154 @ImportStatic({})
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
155 static class ImportGuards5 extends ValueNode {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
156
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
157 int do1(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
158 return a;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
159 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
160 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
161
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
162 @Test
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
163 public void testImportGuards6() {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
164 // should use the guar declared in the node instead of the imported one.
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
165 assertRuns(ImportGuards6Factory.getInstance(), //
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
166 array(1, 1), //
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
167 array(1, 1));
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
168 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
169
19285
259a416388d7 Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
170 @ImportStatic(Imports0.class)
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
171 @NodeChild("a")
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
172 static class ImportGuards6 extends ValueNode {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
173
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
174 static boolean staticGuard(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
175 return a == 1;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
176 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
177
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16851
diff changeset
178 @Specialization(guards = "staticGuard(a)")
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
179 int f0(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
180 return a;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
181 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
182 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
183
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
184 }