comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java @ 14991:64dcb92ee75a

Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sun, 06 Apr 2014 17:46:24 +0200
parents ba52fbec5b6c
children 1cd02b4d90d1
comparison
equal deleted inserted replaced
14989:a0dbb3628f2a 14991:64dcb92ee75a
65 this.sourceSection = sourceSection; 65 this.sourceSection = sourceSection;
66 } 66 }
67 67
68 /** 68 /**
69 * Assigns a link to a guest language source section to this node. 69 * Assigns a link to a guest language source section to this node.
70 * 70 *
71 * @param section the object representing a section in guest language source code 71 * @param section the object representing a section in guest language source code
72 */ 72 */
73 public final void assignSourceSection(SourceSection section) { 73 public final void assignSourceSection(SourceSection section) {
74 if (sourceSection != null) { 74 if (sourceSection != null) {
75 // Patch this test during the transition to constructor-based 75 // Patch this test during the transition to constructor-based
105 this.sourceSection = null; 105 this.sourceSection = null;
106 } 106 }
107 107
108 /** 108 /**
109 * Retrieves the guest language source code section that is currently assigned to this node. 109 * Retrieves the guest language source code section that is currently assigned to this node.
110 * 110 *
111 * @return the assigned source code section 111 * @return the assigned source code section
112 */ 112 */
113 public final SourceSection getSourceSection() { 113 public final SourceSection getSourceSection() {
114 return sourceSection; 114 return sourceSection;
115 } 115 }
116 116
117 /** 117 /**
118 * Retrieves the guest language source code section that is currently assigned to this node. 118 * Retrieves the guest language source code section that is currently assigned to this node.
119 * 119 *
120 * @return the assigned source code section 120 * @return the assigned source code section
121 */ 121 */
122 @CompilerDirectives.SlowPath 122 @CompilerDirectives.SlowPath
123 public final SourceSection getEncapsulatingSourceSection() { 123 public final SourceSection getEncapsulatingSourceSection() {
124 if (sourceSection == null && getParent() != null) { 124 if (sourceSection == null && getParent() != null) {
128 } 128 }
129 129
130 /** 130 /**
131 * Method that updates the link to the parent in the array of specified new child nodes to this 131 * Method that updates the link to the parent in the array of specified new child nodes to this
132 * node. 132 * node.
133 * 133 *
134 * @param newChildren the array of new children whose parent should be updated 134 * @param newChildren the array of new children whose parent should be updated
135 * @return the array of new children 135 * @return the array of new children
136 */ 136 */
137 @SuppressWarnings("static-method") 137 @SuppressWarnings("static-method")
138 @Deprecated 138 @Deprecated
140 return newChildren; 140 return newChildren;
141 } 141 }
142 142
143 /** 143 /**
144 * Method that updates the link to the parent in the specified new child node to this node. 144 * Method that updates the link to the parent in the specified new child node to this node.
145 * 145 *
146 * @param newChild the new child whose parent should be updated 146 * @param newChild the new child whose parent should be updated
147 * @return the new child 147 * @return the new child
148 */ 148 */
149 @SuppressWarnings("static-method") 149 @SuppressWarnings("static-method")
150 @Deprecated 150 @Deprecated
153 } 153 }
154 154
155 /** 155 /**
156 * Method that updates the link to the parent in the array of specified new child nodes to this 156 * Method that updates the link to the parent in the array of specified new child nodes to this
157 * node. 157 * node.
158 * 158 *
159 * @param newChildren the array of new children whose parent should be updated 159 * @param newChildren the array of new children whose parent should be updated
160 * @return the array of new children 160 * @return the array of new children
161 */ 161 */
162 protected final <T extends Node> T[] insert(final T[] newChildren) { 162 protected final <T extends Node> T[] insert(final T[] newChildren) {
163 CompilerDirectives.transferToInterpreterAndInvalidate(); 163 CompilerDirectives.transferToInterpreterAndInvalidate();
168 return newChildren; 168 return newChildren;
169 } 169 }
170 170
171 /** 171 /**
172 * Method that updates the link to the parent in the specified new child node to this node. 172 * Method that updates the link to the parent in the specified new child node to this node.
173 * 173 *
174 * @param newChild the new child whose parent should be updated 174 * @param newChild the new child whose parent should be updated
175 * @return the new child 175 * @return the new child
176 */ 176 */
177 protected final <T extends Node> T insert(final T newChild) { 177 protected final <T extends Node> T insert(final T newChild) {
178 CompilerDirectives.transferToInterpreterAndInvalidate(); 178 CompilerDirectives.transferToInterpreterAndInvalidate();
223 } 223 }
224 224
225 /** 225 /**
226 * Returns properties of this node interesting for debugging and can be overwritten by 226 * Returns properties of this node interesting for debugging and can be overwritten by
227 * subclasses to add their own custom properties. 227 * subclasses to add their own custom properties.
228 * 228 *
229 * @return the properties as a key/value hash map 229 * @return the properties as a key/value hash map
230 */ 230 */
231 public Map<String, Object> getDebugProperties() { 231 public Map<String, Object> getDebugProperties() {
232 Map<String, Object> properties = new HashMap<>(); 232 Map<String, Object> properties = new HashMap<>();
233 return properties; 233 return properties;
234 } 234 }
235 235
236 /** 236 /**
237 * The current parent node of this node. 237 * The current parent node of this node.
238 * 238 *
239 * @return the parent node 239 * @return the parent node
240 */ 240 */
241 public final Node getParent() { 241 public final Node getParent() {
242 return parent; 242 return parent;
243 } 243 }
244 244
245 /** 245 /**
246 * Replaces this node with another node. If there is a source section (see 246 * Replaces this node with another node. If there is a source section (see
247 * {@link #getSourceSection()}) associated with this node, it is transferred to the new node. 247 * {@link #getSourceSection()}) associated with this node, it is transferred to the new node.
248 * 248 *
249 * @param newNode the new node that is the replacement 249 * @param newNode the new node that is the replacement
250 * @param reason a description of the reason for the replacement 250 * @param reason a description of the reason for the replacement
251 * @return the new node 251 * @return the new node
252 */ 252 */
253 public final <T extends Node> T replace(final T newNode, final CharSequence reason) { 253 public final <T extends Node> T replace(final T newNode, final CharSequence reason) {
261 } 261 }
262 262
263 /** 263 /**
264 * Replaces this node with another node. If there is a source section (see 264 * Replaces this node with another node. If there is a source section (see
265 * {@link #getSourceSection()}) associated with this node, it is transferred to the new node. 265 * {@link #getSourceSection()}) associated with this node, it is transferred to the new node.
266 * 266 *
267 * @param newNode the new node that is the replacement 267 * @param newNode the new node that is the replacement
268 * @return the new node 268 * @return the new node
269 */ 269 */
270 public final <T extends Node> T replace(T newNode) { 270 public final <T extends Node> T replace(T newNode) {
271 return replace(newNode, ""); 271 return replace(newNode, "");
292 onReplace(newNode, reason); 292 onReplace(newNode, reason);
293 } 293 }
294 294
295 /** 295 /**
296 * Checks if this node is properly adopted by a parent and can be replaced. 296 * Checks if this node is properly adopted by a parent and can be replaced.
297 * 297 *
298 * @return {@code true} if it is safe to replace this node. 298 * @return {@code true} if it is safe to replace this node.
299 */ 299 */
300 public final boolean isReplaceable() { 300 public final boolean isReplaceable() {
301 if (getParent() != null) { 301 if (getParent() != null) {
302 for (Node sibling : getParent().getChildren()) { 302 for (Node sibling : getParent().getChildren()) {
319 } 319 }
320 320
321 /** 321 /**
322 * Intended to be implemented by subclasses of {@link Node} to receive a notification when the 322 * Intended to be implemented by subclasses of {@link Node} to receive a notification when the
323 * node is rewritten. This method is invoked before the actual replace has happened. 323 * node is rewritten. This method is invoked before the actual replace has happened.
324 * 324 *
325 * @param newNode the replacement node 325 * @param newNode the replacement node
326 * @param reason the reason the replace supplied 326 * @param reason the reason the replace supplied
327 */ 327 */
328 protected void onReplace(Node newNode, CharSequence reason) { 328 protected void onReplace(Node newNode, CharSequence reason) {
329 if (TruffleOptions.TraceRewrites) { 329 if (TruffleOptions.TraceRewrites) {
394 } 394 }
395 395
396 /** 396 /**
397 * Invokes the {@link NodeVisitor#visit(Node)} method for this node and recursively also for all 397 * Invokes the {@link NodeVisitor#visit(Node)} method for this node and recursively also for all
398 * child nodes. 398 * child nodes.
399 * 399 *
400 * @param nodeVisitor the visitor 400 * @param nodeVisitor the visitor
401 */ 401 */
402 public final void accept(NodeVisitor nodeVisitor) { 402 public final void accept(NodeVisitor nodeVisitor) {
403 if (nodeVisitor.visit(this)) { 403 if (nodeVisitor.visit(this)) {
404 for (Node child : this.getChildren()) { 404 for (Node child : this.getChildren()) {
409 } 409 }
410 } 410 }
411 411
412 /** 412 /**
413 * Iterator over the children of this node. 413 * Iterator over the children of this node.
414 * 414 *
415 * @return the iterator 415 * @return the iterator
416 */ 416 */
417 public final Iterable<Node> getChildren() { 417 public final Iterable<Node> getChildren() {
418 final Node node = this; 418 final Node node = this;
419 return new Iterable<Node>() { 419 return new Iterable<Node>() {
424 }; 424 };
425 } 425 }
426 426
427 /** 427 /**
428 * Creates a shallow copy of this node. 428 * Creates a shallow copy of this node.
429 * 429 *
430 * @return the new copy 430 * @return the new copy
431 */ 431 */
432 public Node copy() { 432 public Node copy() {
433 try { 433 try {
434 return (Node) super.clone(); 434 return (Node) super.clone();
447 throw new IllegalStateException("This method should never be called, use the copy method instead!"); 447 throw new IllegalStateException("This method should never be called, use the copy method instead!");
448 } 448 }
449 449
450 /** 450 /**
451 * Get the root node of the tree a node belongs to. 451 * Get the root node of the tree a node belongs to.
452 * 452 *
453 * @return the {@link RootNode} or {@code null} if there is none. 453 * @return the {@link RootNode} or {@code null} if there is none.
454 */ 454 */
455 public final RootNode getRootNode() { 455 public final RootNode getRootNode() {
456 Node rootNode = this; 456 Node rootNode = this;
457 while (rootNode.getParent() != null) { 457 while (rootNode.getParent() != null) {