Mercurial > hg > graal-jvmci-8
diff graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java @ 11951:c0c616fe3588
Back out changeset be0a33a631fa.
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Thu, 10 Oct 2013 03:23:40 +0200 |
parents | be0a33a631fa |
children | 57b8a41c0e18 |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Wed Oct 09 22:21:49 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Thu Oct 10 03:23:40 2013 +0200 @@ -39,8 +39,6 @@ private SourceSection sourceSection; - private Node replacedWith; - /** * Marks array fields that are children of this node. */ @@ -172,8 +170,8 @@ * @param reason a description of the reason for the replacement * @return the new node */ + @SuppressWarnings({"unchecked"}) public final <T extends Node> T replace(T newNode, String reason) { - CompilerDirectives.transferToInterpreter(); if (this.getParent() == null) { throw new IllegalStateException("This node cannot be replaced, because it does not yet have a parent."); } @@ -182,31 +180,13 @@ newNode.assignSourceSection(sourceSection); } onReplace(newNode, reason); - if (NodeUtil.replaceChild(parent, this, newNode)) { - parent.adoptChild(newNode); - this.replacedWith = newNode; - } else if (replacedWith != null) { - replaceFailedHelper(newNode); - } else { - throw new IllegalStateException("Child not found in parent."); - } - return newNode; + return (T) this.getParent().replaceChild(this, newNode); } - private void replaceFailedHelper(Node newNode) { - Node lastReplacedWith = replacedWith; - assert lastReplacedWith != this; - while (lastReplacedWith.replacedWith != null) { - lastReplacedWith = lastReplacedWith.replacedWith; - assert lastReplacedWith != this; - } - newNode.parent = parent; - newNode.replacedWith = lastReplacedWith; - for (Node child : newNode.getChildren()) { - if (child != null) { - child.parent = lastReplacedWith; - } - } + private <T extends Node> T replaceChild(T oldChild, T newChild) { + NodeUtil.replaceChild(this, oldChild, newChild); + adoptChild(newChild); + return newChild; } /**