Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/NullLiteralGuardsTest.java @ 21591:6c5327245831
LinearScan: fix intervals context.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Fri, 29 May 2015 10:59:03 +0200 |
parents | f83fd99b2962 |
children |
rev | line source |
---|---|
20939
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.dsl.test; |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import static com.oracle.truffle.api.dsl.test.TestHelper.*; |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 import static org.junit.Assert.*; |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import org.junit.*; |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.*; |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 import com.oracle.truffle.api.dsl.*; |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 import com.oracle.truffle.api.dsl.test.NullLiteralGuardsTestFactory.CompareNotNullNodeFactory; |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 import com.oracle.truffle.api.dsl.test.NullLiteralGuardsTestFactory.CompareObjectsNullNodeFactory; |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 import com.oracle.truffle.api.dsl.test.NullLiteralGuardsTestFactory.CompareStringNullNodeFactory; |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ChildrenNode; |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 @SuppressWarnings("unused") |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 public class NullLiteralGuardsTest { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 @Test |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 public void testCompareObjectsNull() { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 CallTarget root = createCallTarget(CompareObjectsNullNodeFactory.getInstance()); |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 assertEquals("do1", root.call((Object) null)); |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 assertEquals("do2", root.call("42")); |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 abstract static class CompareObjectsNullNode extends ChildrenNode { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 @Specialization(guards = "value == null") |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 String do1(Object value) { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 return "do1"; |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 @Specialization |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 String do2(Object value) { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 return "do2"; |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 @Test |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 public void testCompareStringNull() { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
61 CallTarget root = createCallTarget(CompareStringNullNodeFactory.getInstance()); |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
62 assertEquals("do1", root.call("42")); |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 assertEquals("do2", root.call((Object) null)); |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 abstract static class CompareStringNullNode extends ChildrenNode { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
67 @Specialization(guards = "value != null") |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 String do1(String value) { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 return "do1"; |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 @Specialization |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 String do2(Object value) { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
74 return "do2"; |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
76 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
78 @Test |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
79 public void testCompareNotNull() { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
80 CallTarget root = createCallTarget(CompareNotNullNodeFactory.getInstance()); |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
81 assertEquals("do1", root.call("42")); |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
82 assertEquals("do2", root.call((Object) null)); |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
83 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
84 |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
85 abstract static class CompareNotNullNode extends ChildrenNode { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
86 @Specialization(guards = "value != null") |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
87 String do1(Object value) { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
88 return "do1"; |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
89 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
90 |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
91 @Specialization |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
92 String do2(Object value) { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
93 return "do2"; |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
94 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
95 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
96 |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
97 abstract static class ErrorNullIntComparison1 extends ChildrenNode { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
98 @ExpectError("Error parsing expression 'value == null': Incompatible operand types int and null.") |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
99 @Specialization(guards = "value == null") |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
100 String do1(int value) { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
101 return "do1"; |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
102 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
103 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
104 |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
105 abstract static class ErrorNullIntComparison2 extends ChildrenNode { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
106 @ExpectError("Error parsing expression '1 == null': Incompatible operand types int and null.") |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
107 @Specialization(guards = "1 == null") |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
108 String do1(int value) { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
109 return "do1"; |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
110 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
111 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
112 |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
113 abstract static class ErrorNullNullComparison extends ChildrenNode { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
114 @ExpectError("Error parsing expression 'null == null': The operator == is undefined for the argument type(s) null null.") |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
115 @Specialization(guards = "null == null") |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
116 String do1(int value) { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
117 return "do1"; |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
118 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
119 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
120 |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
121 abstract static class ErrorObjectVoidComparison extends ChildrenNode { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
122 protected static void returnVoid() { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
123 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
124 |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
125 @ExpectError("Error parsing expression 'value == returnVoid()': Incompatible operand types Object and void.") |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
126 @Specialization(guards = "value == returnVoid()") |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
127 String do1(Object value) { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
128 return "do1"; |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
129 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
130 } |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
131 |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
132 } |