# HG changeset patch # User Andreas Woess # Date 1381368220 -7200 # Node ID c0c616fe3588b33a2a5f72fadfb2210c68364797 # Parent be0a33a631fa4f855d7dd92924673e9f6b1e4330 Back out changeset be0a33a631fa. diff -r be0a33a631fa -r c0c616fe3588 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java --- 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 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 replaceChild(T oldChild, T newChild) { + NodeUtil.replaceChild(this, oldChild, newChild); + adoptChild(newChild); + return newChild; } /**