Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ImportGuardsTest.java @ 19468:6709f8086756
eclipseformat
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Tue, 17 Feb 2015 21:44:55 +0100 |
parents | 259a416388d7 |
children |
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 |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import static com.oracle.truffle.api.dsl.test.TestHelper.*; |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 import org.junit.*; |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 import com.oracle.truffle.api.dsl.*; |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 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
|
31 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 public class ImportGuardsTest { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 |
19285
259a416388d7
Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
35 @ImportStatic(Imports0.class) |
16832
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 @NodeChild("a") |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 static class ImportGuards0 extends ValueNode { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
39 @Specialization(guards = "staticGuard(a)") |
16832
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 int f0(int a) { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 return a; |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 } |
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 @NodeChild("a") |
19285
259a416388d7
Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
46 @ImportStatic(Imports0.class) |
16832
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 static class ImportGuards1 extends ValueNode { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
49 @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
|
50 @Specialization(guards = "nonStaticGuard(a)") |
16832
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 int f1(int a) { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 return a; |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 } |
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 @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
|
56 @Specialization(guards = "protectedGuard(a)") |
16832
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 int f2(int a) { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 return a; |
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 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
61 @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
|
62 @Specialization(guards = "packageGuard(a)") |
16832
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 int f3(int a) { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 return a; |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 } |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
67 @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
|
68 @Specialization(guards = "privateGuard(a)") |
16832
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 int f4(int a) { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 return a; |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 } |
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 public static class Imports0 { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 public static boolean staticGuard(int a) { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
76 return a == 0; |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 } |
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 public boolean nonStaticGuard(int a) { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
80 return a == 0; |
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 |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
83 protected static boolean protectedGuard(int a) { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
84 return a == 0; |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
85 } |
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 static boolean packageGuard(int a) { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
88 return a == 0; |
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 |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
91 @SuppressWarnings("unused") |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
92 private static boolean privateGuard(int a) { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
93 return a == 0; |
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 |
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 @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
|
99 @NodeChild("a") |
19285
259a416388d7
Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
100 @ImportStatic(Imports1.class) |
16832
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
101 static class ImportGuards2 extends ValueNode { |
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 int do1(int a) { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
104 return a; |
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 |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
108 static class Imports1 { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
109 |
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 @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
|
113 @NodeChild("a") |
19285
259a416388d7
Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
114 @ImportStatic(Imports2.class) |
16832
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
115 static class ImportGuards3 extends ValueNode { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
116 |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
117 int do1(int a) { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
118 return a; |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
119 } |
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 @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
|
123 @NodeChild("a") |
19285
259a416388d7
Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
124 @ImportStatic(boolean.class) |
16832
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
125 static class ImportGuards4 extends ValueNode { |
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 int do1(int a) { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
128 return a; |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
129 } |
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 private static class Imports2 { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
133 |
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 @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
|
137 @NodeChild("a") |
19285
259a416388d7
Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
138 @ImportStatic({}) |
16832
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
139 static class ImportGuards5 extends ValueNode { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
140 |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
141 int do1(int a) { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
142 return a; |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
143 } |
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 @Test |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
147 public void testImportGuards6() { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
148 // 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
|
149 assertRuns(ImportGuards6Factory.getInstance(), // |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
150 array(1, 1), // |
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 } |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
153 |
19285
259a416388d7
Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
154 @ImportStatic(Imports0.class) |
16832
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
155 @NodeChild("a") |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
156 static class ImportGuards6 extends ValueNode { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
157 |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
158 static boolean staticGuard(int a) { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
159 return a == 1; |
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 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
162 @Specialization(guards = "staticGuard(a)") |
16832
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
163 int f0(int a) { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
164 return a; |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
165 } |
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 } |