Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeClass.java @ 22403:5033b980cc68
The (public!?) NodeClass constructor accepted Class parameter in truffle-0.9 version
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Fri, 20 Nov 2015 17:13:09 +0100 |
parents | efbc311e9ff2 |
children | fd53ccebb10b |
rev | line source |
---|---|
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. Oracle designates this |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * particular file as subject to the "Classpath" exception as provided |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * by Oracle in the LICENSE file that accompanied this code. |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * accompanied this code). |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU General Public License version |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 * or visit www.oracle.com if you need additional information or have any |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 * questions. |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 */ |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 package com.oracle.truffle.api.nodes; |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
27 import java.security.AccessController; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
28 import java.security.PrivilegedAction; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
29 import java.util.Iterator; |
22398
07c98b5a9496
NodeClass: avoid unnecessary array copying during initialization
Andreas Woess <andreas.woess@oracle.com>
parents:
22372
diff
changeset
|
30 |
22372
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
31 /** |
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
32 * Information about a {@link Node} class. A single instance of this class is allocated for every |
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
33 * subclass of {@link Node} that is used. |
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
34 */ |
22399
efbc311e9ff2
Turning NodeClass into abstract class to allow its independent implementations.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22398
diff
changeset
|
35 public abstract class NodeClass { |
22372
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
36 private static final ClassValue<NodeClass> nodeClasses = new ClassValue<NodeClass>() { |
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
37 @SuppressWarnings("unchecked") |
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
38 @Override |
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
39 protected NodeClass computeValue(final Class<?> clazz) { |
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
40 assert Node.class.isAssignableFrom(clazz); |
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
41 return AccessController.doPrivileged(new PrivilegedAction<NodeClass>() { |
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
42 public NodeClass run() { |
22399
efbc311e9ff2
Turning NodeClass into abstract class to allow its independent implementations.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22398
diff
changeset
|
43 return new NodeClassImpl((Class<? extends Node>) clazz); |
22372
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
44 } |
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
45 }); |
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
46 } |
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
47 }; |
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
48 |
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
49 public static NodeClass get(Class<? extends Node> clazz) { |
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
50 return nodeClasses.get(clazz); |
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
51 } |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 |
22372
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
53 public static NodeClass get(Node node) { |
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
54 return node.getNodeClass(); |
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
55 } |
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
56 |
22403
5033b980cc68
The (public!?) NodeClass constructor accepted Class parameter in truffle-0.9 version
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22399
diff
changeset
|
57 @SuppressWarnings("unused") |
5033b980cc68
The (public!?) NodeClass constructor accepted Class parameter in truffle-0.9 version
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22399
diff
changeset
|
58 public NodeClass(Class<? extends Node> clazz) { |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 } |
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 |
22399
efbc311e9ff2
Turning NodeClass into abstract class to allow its independent implementations.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22398
diff
changeset
|
61 public abstract NodeFieldAccessor getNodeClassField(); |
22372
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
62 |
22399
efbc311e9ff2
Turning NodeClass into abstract class to allow its independent implementations.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22398
diff
changeset
|
63 public abstract NodeFieldAccessor[] getCloneableFields(); |
22372
6598b9b7aafd
Backed out changeset: 0d4b0e4263ee
Christian Wirth <christian.wirth@oracle.com>
parents:
22368
diff
changeset
|
64 |
22399
efbc311e9ff2
Turning NodeClass into abstract class to allow its independent implementations.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22398
diff
changeset
|
65 public abstract NodeFieldAccessor[] getFields(); |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 |
22399
efbc311e9ff2
Turning NodeClass into abstract class to allow its independent implementations.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22398
diff
changeset
|
67 public abstract NodeFieldAccessor getParentField(); |
efbc311e9ff2
Turning NodeClass into abstract class to allow its independent implementations.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22398
diff
changeset
|
68 |
efbc311e9ff2
Turning NodeClass into abstract class to allow its independent implementations.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22398
diff
changeset
|
69 public abstract NodeFieldAccessor[] getChildFields(); |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 |
22399
efbc311e9ff2
Turning NodeClass into abstract class to allow its independent implementations.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22398
diff
changeset
|
71 public abstract NodeFieldAccessor[] getChildrenFields(); |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 |
22399
efbc311e9ff2
Turning NodeClass into abstract class to allow its independent implementations.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22398
diff
changeset
|
73 public abstract Iterator<Node> makeIterator(Node node); |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
74 } |