Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java @ 9254:4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 23 Apr 2013 14:59:24 +0200 |
parents | 5e3d1a68664e |
children | cdf10fb20022 |
comparison
equal
deleted
inserted
replaced
9246:ba3dfa9e36d8 | 9254:4497235516df |
---|---|
23 package com.oracle.truffle.api.nodes; | 23 package com.oracle.truffle.api.nodes; |
24 | 24 |
25 import java.lang.annotation.*; | 25 import java.lang.annotation.*; |
26 import java.util.*; | 26 import java.util.*; |
27 | 27 |
28 import com.oracle.truffle.api.*; | |
29 | |
28 /** | 30 /** |
29 * Abstract base class for all Truffle nodes. | 31 * Abstract base class for all Truffle nodes. |
30 */ | 32 */ |
31 public abstract class Node implements Cloneable { | 33 public abstract class Node implements Cloneable { |
32 | 34 |
35 */ | 37 */ |
36 public static final Node[] EMPTY_ARRAY = new Node[0]; | 38 public static final Node[] EMPTY_ARRAY = new Node[0]; |
37 | 39 |
38 private Node parent; | 40 private Node parent; |
39 | 41 |
42 private SourceSection sourceSection; | |
43 | |
40 /** | 44 /** |
41 * Marks array fields that are children of this node. | 45 * Marks array fields that are children of this node. |
42 */ | 46 */ |
43 @Retention(RetentionPolicy.RUNTIME) | 47 @Retention(RetentionPolicy.RUNTIME) |
44 @Target({ElementType.FIELD}) | 48 @Target({ElementType.FIELD}) |
49 * Marks fields that represent child nodes of this node. | 53 * Marks fields that represent child nodes of this node. |
50 */ | 54 */ |
51 @Retention(RetentionPolicy.RUNTIME) | 55 @Retention(RetentionPolicy.RUNTIME) |
52 @Target({ElementType.FIELD}) | 56 @Target({ElementType.FIELD}) |
53 public @interface Child { | 57 public @interface Child { |
58 } | |
59 | |
60 /** | |
61 * Assigns a link to a guest language source section to this node. | |
62 * | |
63 * @param section the object representing a section in guest language source code | |
64 */ | |
65 public final void assignSourceSection(SourceSection section) { | |
66 if (sourceSection != null) { | |
67 throw new IllegalStateException("Source section is already assigned."); | |
68 } | |
69 this.sourceSection = section; | |
70 } | |
71 | |
72 /** | |
73 * Clears any previously assigned guest language source code from this node. | |
74 */ | |
75 public final void clearSourceSection() { | |
76 this.sourceSection = null; | |
77 } | |
78 | |
79 /** | |
80 * Retrieves the guest language source code section that is currently assigned to this node. | |
81 * | |
82 * @return the assigned source code section | |
83 */ | |
84 public final SourceSection getSourceSection() { | |
85 return sourceSection; | |
54 } | 86 } |
55 | 87 |
56 /** | 88 /** |
57 * Method that updates the link to the parent in the array of specified new child nodes to this | 89 * Method that updates the link to the parent in the array of specified new child nodes to this |
58 * node. | 90 * node. |
121 * @param newNode the new node that is the replacement | 153 * @param newNode the new node that is the replacement |
122 * @param reason a description of the reason for the replacement | 154 * @param reason a description of the reason for the replacement |
123 * @return the new node | 155 * @return the new node |
124 */ | 156 */ |
125 @SuppressWarnings({"unchecked"}) | 157 @SuppressWarnings({"unchecked"}) |
126 public <T extends Node> T replace(T newNode, String reason) { | 158 public final <T extends Node> T replace(T newNode, String reason) { |
127 assert this.getParent() != null; | 159 assert this.getParent() != null; |
128 return (T) this.getParent().replaceChild(this, newNode); | 160 return (T) this.getParent().replaceChild(this, newNode); |
129 } | 161 } |
130 | 162 |
131 /** | 163 /** |
132 * Replaces this node with another node. | 164 * Replaces this node with another node. |
133 * | 165 * |
134 * @param newNode the new node that is the replacement | 166 * @param newNode the new node that is the replacement |
135 * @return the new node | 167 * @return the new node |
136 */ | 168 */ |
137 public <T extends Node> T replace(T newNode) { | 169 public final <T extends Node> T replace(T newNode) { |
138 return replace(newNode, ""); | 170 return replace(newNode, ""); |
139 } | 171 } |
140 | 172 |
141 /** | 173 /** |
142 * Invokes the {@link NodeVisitor#visit(Node)} method for this node and recursively also for all | 174 * Invokes the {@link NodeVisitor#visit(Node)} method for this node and recursively also for all |