Mercurial > hg > truffle
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java @ 9256:9640bb930327
Preserve the source section during node rewrites.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 23 Apr 2013 15:07:47 +0200 |
parents | cdf10fb20022 |
children | ba02d19dd3cc |
comparison
equal
deleted
inserted
replaced
9255:cdf10fb20022 | 9256:9640bb930327 |
---|---|
133 public final Node getParent() { | 133 public final Node getParent() { |
134 return parent; | 134 return parent; |
135 } | 135 } |
136 | 136 |
137 /** | 137 /** |
138 * Replaces this node with another node. | 138 * Replaces this node with another node. If there is a source section (see |
139 * {@link #getSourceSection()}) associated with this node, it is transferred to the new node. | |
139 * | 140 * |
140 * @param newNode the new node that is the replacement | 141 * @param newNode the new node that is the replacement |
141 * @param reason a description of the reason for the replacement | 142 * @param reason a description of the reason for the replacement |
142 * @return the new node | 143 * @return the new node |
143 */ | 144 */ |
144 @SuppressWarnings({"unchecked"}) | 145 @SuppressWarnings({"unchecked"}) |
145 public final <T extends Node> T replace(T newNode, String reason) { | 146 public final <T extends Node> T replace(T newNode, String reason) { |
146 assert this.getParent() != null; | 147 assert this.getParent() != null; |
148 if (sourceSection != null) { | |
149 // Pass on the source section to the new node. | |
150 newNode.assignSourceSection(sourceSection); | |
151 } | |
147 return (T) this.getParent().replaceChild(this, newNode); | 152 return (T) this.getParent().replaceChild(this, newNode); |
148 } | 153 } |
149 | 154 |
150 private <T extends Node> T replaceChild(T oldChild, T newChild) { | 155 private <T extends Node> T replaceChild(T oldChild, T newChild) { |
151 NodeUtil.replaceChild(this, oldChild, newChild); | 156 NodeUtil.replaceChild(this, oldChild, newChild); |
152 adoptChild(newChild); | 157 adoptChild(newChild); |
153 return newChild; | 158 return newChild; |
154 } | 159 } |
155 | 160 |
156 /** | 161 /** |
157 * Replaces this node with another node. | 162 * Replaces this node with another node. If there is a source section (see |
163 * {@link #getSourceSection()}) associated with this node, it is transferred to the new node. | |
158 * | 164 * |
159 * @param newNode the new node that is the replacement | 165 * @param newNode the new node that is the replacement |
160 * @return the new node | 166 * @return the new node |
161 */ | 167 */ |
162 public final <T extends Node> T replace(T newNode) { | 168 public final <T extends Node> T replace(T newNode) { |