Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ExecuteMethodTest.java @ 18775:a069a87b9a02
Truffle-DSL: Added tests and verification of overridable generic execute methods.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 05 Jan 2015 01:31:08 +0100 |
parents | |
children | c0fb70634640 |
comparison
equal
deleted
inserted
replaced
18774:674c8a6d5e6c | 18775:a069a87b9a02 |
---|---|
1 /* | |
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.truffle.api.dsl.test; | |
24 | |
25 import com.oracle.truffle.api.dsl.*; | |
26 import com.oracle.truffle.api.nodes.*; | |
27 | |
28 public class ExecuteMethodTest { | |
29 | |
30 private static final String NO_EXECUTE = "No accessible and overridable generic execute method found. Generic execute methods usually have the signature 'public abstract {Type} " | |
31 + "executeGeneric(VirtualFrame)' and must not throw any checked exceptions."; | |
32 | |
33 @TypeSystem({int.class, Object[].class}) | |
34 static class ExecuteTypeSystem { | |
35 | |
36 } | |
37 | |
38 @TypeSystemReference(ExecuteTypeSystem.class) | |
39 abstract static class ValidChildNode extends Node { | |
40 abstract Object execute(); | |
41 } | |
42 | |
43 @TypeSystemReference(ExecuteTypeSystem.class) | |
44 @NodeChild(value = "a", type = ValidChildNode.class) | |
45 @ExpectError(NO_EXECUTE) | |
46 abstract static class ExecuteThis1 extends Node { | |
47 | |
48 @Specialization | |
49 int doInt(int a) { | |
50 return a; | |
51 } | |
52 } | |
53 | |
54 @TypeSystemReference(ExecuteTypeSystem.class) | |
55 @NodeChild(value = "a", type = ValidChildNode.class) | |
56 @ExpectError(NO_EXECUTE) | |
57 abstract static class ExecuteThis2 extends Node { | |
58 | |
59 abstract Object execute() throws UnexpectedResultException; | |
60 | |
61 @Specialization | |
62 int doInt(int a) { | |
63 return a; | |
64 } | |
65 } | |
66 | |
67 @TypeSystemReference(ExecuteTypeSystem.class) | |
68 @NodeChild(value = "a", type = ValidChildNode.class) | |
69 @ExpectError(NO_EXECUTE) | |
70 abstract static class ExecuteThis3 extends Node { | |
71 | |
72 abstract int execute() throws UnexpectedResultException; | |
73 | |
74 @Specialization | |
75 int doInt(int a) { | |
76 return a; | |
77 } | |
78 } | |
79 | |
80 @TypeSystemReference(ExecuteTypeSystem.class) | |
81 @NodeChild(value = "a", type = ValidChildNode.class) | |
82 abstract static class ExecuteThis4 extends Node { | |
83 | |
84 protected abstract Object execute(); | |
85 | |
86 @Specialization | |
87 int doInt(int a) { | |
88 return a; | |
89 } | |
90 } | |
91 | |
92 @TypeSystemReference(ExecuteTypeSystem.class) | |
93 @NodeChild(value = "a", type = ValidChildNode.class) | |
94 abstract static class ExecuteThis5 extends Node { | |
95 | |
96 public abstract Object execute(); | |
97 | |
98 @Specialization | |
99 int doInt(int a) { | |
100 return a; | |
101 } | |
102 } | |
103 | |
104 @TypeSystemReference(ExecuteTypeSystem.class) | |
105 @NodeChild(value = "a", type = ValidChildNode.class) | |
106 @ExpectError(NO_EXECUTE) | |
107 abstract static class ExecuteThis6 extends Node { | |
108 | |
109 @SuppressWarnings({"unused", "static-method"}) | |
110 private Object execute() { | |
111 return 0; | |
112 } | |
113 | |
114 @Specialization | |
115 int doInt(int a) { | |
116 return a; | |
117 } | |
118 } | |
119 | |
120 @TypeSystemReference(ExecuteTypeSystem.class) | |
121 @NodeChild(value = "a", type = ValidChildNode.class) | |
122 @ExpectError(NO_EXECUTE) | |
123 abstract static class ExecuteThis7 extends Node { | |
124 | |
125 @SuppressWarnings("static-method") | |
126 public final int executeInt() { | |
127 return 0; | |
128 } | |
129 | |
130 @Specialization | |
131 int doInt(int a) { | |
132 return a; | |
133 } | |
134 } | |
135 | |
136 @TypeSystemReference(ExecuteTypeSystem.class) | |
137 @NodeChild(value = "a", type = ValidChildNode.class) | |
138 @ExpectError("Multiple accessible and overridable generic execute methods found [executeInt(), executeObject()]. Remove all but one or mark all but one as final.") | |
139 abstract static class ExecuteThis8 extends Node { | |
140 | |
141 abstract int executeInt(); | |
142 | |
143 abstract Object executeObject(); | |
144 | |
145 @Specialization | |
146 int doInt(int a) { | |
147 return a; | |
148 } | |
149 | |
150 } | |
151 | |
152 @TypeSystemReference(ExecuteTypeSystem.class) | |
153 @NodeChild(value = "a", type = ValidChildNode.class) | |
154 abstract static class ExecuteThis9 extends Node { | |
155 | |
156 abstract int executeInt(); | |
157 | |
158 // disambiguate executeObject | |
159 final Object executeObject() { | |
160 return executeInt(); | |
161 } | |
162 | |
163 @Specialization | |
164 int doInt(int a) { | |
165 return a; | |
166 } | |
167 } | |
168 | |
169 } |