annotate truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ImportGuardsTest.java @ 22157:dc83cc1f94f2

Using fully qualified imports
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 16 Sep 2015 11:33:22 +0200
parents 9c8c0937da41
children 14e6dfb1ef05
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
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
25 import com.oracle.truffle.api.dsl.ImportStatic;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
26 import com.oracle.truffle.api.dsl.NodeChild;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
27 import com.oracle.truffle.api.dsl.Specialization;
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
28 import com.oracle.truffle.api.dsl.test.ImportGuardsTestFactory.ImportGuards6Factory;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
29 import static com.oracle.truffle.api.dsl.test.TestHelper.array;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
30 import static com.oracle.truffle.api.dsl.test.TestHelper.assertRuns;
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
31 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
32 import org.junit.Test;
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
33
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
34 public class ImportGuardsTest {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
35
19285
259a416388d7 Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
36 @ImportStatic(Imports0.class)
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
37 @NodeChild("a")
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
38 static class ImportGuards0 extends ValueNode {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
39
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16851
diff changeset
40 @Specialization(guards = "staticGuard(a)")
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
41 int f0(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
42 return a;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
43 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
44 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
45
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
46 @NodeChild("a")
19285
259a416388d7 Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
47 @ImportStatic(Imports0.class)
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
48 static class ImportGuards1 extends ValueNode {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
49
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16851
diff changeset
50 @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
51 @Specialization(guards = "nonStaticGuard(a)")
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
52 int f1(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
53 return a;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
54 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
55
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16851
diff changeset
56 @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
57 @Specialization(guards = "protectedGuard(a)")
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
58 int f2(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
59 return a;
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
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16851
diff changeset
62 @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
63 @Specialization(guards = "packageGuard(a)")
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
64 int f3(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
65 return a;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
66 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
67
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16851
diff changeset
68 @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
69 @Specialization(guards = "privateGuard(a)")
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
70 int f4(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
71 return a;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
72 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
73 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
74
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
75 public static class Imports0 {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
76 public static boolean staticGuard(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
77 return a == 0;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
78 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
79
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
80 public boolean nonStaticGuard(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
81 return a == 0;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
82 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
83
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
84 protected static boolean protectedGuard(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
85 return a == 0;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
86 }
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 static boolean packageGuard(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
89 return a == 0;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
90 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
91
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
92 @SuppressWarnings("unused")
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
93 private static boolean privateGuard(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
94 return a == 0;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
95 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
96
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 @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
100 @NodeChild("a")
19285
259a416388d7 Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
101 @ImportStatic(Imports1.class)
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
102 static class ImportGuards2 extends ValueNode {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
103
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
104 int do1(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
105 return a;
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 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
108
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
109 static class Imports1 {
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 @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
114 @NodeChild("a")
19285
259a416388d7 Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
115 @ImportStatic(Imports2.class)
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
116 static class ImportGuards3 extends ValueNode {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
117
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
118 int do1(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
119 return a;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
120 }
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 @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
124 @NodeChild("a")
19285
259a416388d7 Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
125 @ImportStatic(boolean.class)
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
126 static class ImportGuards4 extends ValueNode {
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 int do1(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
129 return a;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
130 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
131 }
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 private static class Imports2 {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
134
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 @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
138 @NodeChild("a")
19285
259a416388d7 Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
139 @ImportStatic({})
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
140 static class ImportGuards5 extends ValueNode {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
141
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
142 int do1(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
143 return a;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
144 }
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 @Test
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
148 public void testImportGuards6() {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
149 // 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
150 assertRuns(ImportGuards6Factory.getInstance(), //
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
151 array(1, 1), //
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
152 array(1, 1));
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
153 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
154
19285
259a416388d7 Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
155 @ImportStatic(Imports0.class)
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
156 @NodeChild("a")
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
157 static class ImportGuards6 extends ValueNode {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
158
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
159 static boolean staticGuard(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
160 return a == 1;
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
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16851
diff changeset
163 @Specialization(guards = "staticGuard(a)")
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
164 int f0(int a) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
165 return a;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
166 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
167 }
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 }