Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java @ 19141:67d9e635102f
Truffle/Instrumentation: refine checks for safe node replacement
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Tue, 03 Feb 2015 11:48:25 -0800 |
parents | c7e57dffc5ad |
children | 128586040207 |
comparison
equal
deleted
inserted
replaced
19103:ccabd82be35c | 19141:67d9e635102f |
---|---|
288 reportReplace(this, newNode, reason); | 288 reportReplace(this, newNode, reason); |
289 onReplace(newNode, reason); | 289 onReplace(newNode, reason); |
290 } | 290 } |
291 | 291 |
292 /** | 292 /** |
293 * Checks if this node is properly adopted by its parent. | 293 * Checks if this node can be replaced by another node: tree structure & type. |
294 * | |
295 * @return {@code true} if it is structurally safe to replace this node. | |
296 */ | |
297 public final boolean isReplaceable() { | |
298 if (getParent() != null) { | |
299 for (Node sibling : getParent().getChildren()) { | |
300 if (sibling == this) { | |
301 return true; | |
302 } | |
303 } | |
304 } | |
305 return false; | |
306 } | |
307 | |
308 /** | |
309 * Checks if this node can be replaced by another node, both structurally and with type safety. | |
310 */ | 294 */ |
311 public final boolean isSafelyReplaceableBy(Node newNode) { | 295 public final boolean isSafelyReplaceableBy(Node newNode) { |
312 return isReplaceable() && NodeUtil.isReplacementSafe(getParent(), this, newNode); | 296 return NodeUtil.isReplacementSafe(getParent(), this, newNode); |
313 } | 297 } |
314 | 298 |
315 private void reportReplace(Node oldNode, Node newNode, CharSequence reason) { | 299 private void reportReplace(Node oldNode, Node newNode, CharSequence reason) { |
316 Node node = this; | 300 Node node = this; |
317 while (node != null) { | 301 while (node != null) { |