Mercurial > hg > truffle
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java @ 9782:ba02d19dd3cc
Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 21 May 2013 19:43:53 +0200 |
parents | 9640bb930327 |
children | 29e9a5d18c70 |
comparison
equal
deleted
inserted
replaced
9781:c15fd053efb6 | 9782:ba02d19dd3cc |
---|---|
147 assert this.getParent() != null; | 147 assert this.getParent() != null; |
148 if (sourceSection != null) { | 148 if (sourceSection != null) { |
149 // Pass on the source section to the new node. | 149 // Pass on the source section to the new node. |
150 newNode.assignSourceSection(sourceSection); | 150 newNode.assignSourceSection(sourceSection); |
151 } | 151 } |
152 onReplace(newNode, reason); | |
152 return (T) this.getParent().replaceChild(this, newNode); | 153 return (T) this.getParent().replaceChild(this, newNode); |
153 } | 154 } |
154 | 155 |
155 private <T extends Node> T replaceChild(T oldChild, T newChild) { | 156 private <T extends Node> T replaceChild(T oldChild, T newChild) { |
156 NodeUtil.replaceChild(this, oldChild, newChild); | 157 NodeUtil.replaceChild(this, oldChild, newChild); |
165 * @param newNode the new node that is the replacement | 166 * @param newNode the new node that is the replacement |
166 * @return the new node | 167 * @return the new node |
167 */ | 168 */ |
168 public final <T extends Node> T replace(T newNode) { | 169 public final <T extends Node> T replace(T newNode) { |
169 return replace(newNode, ""); | 170 return replace(newNode, ""); |
171 } | |
172 | |
173 /** | |
174 * Intended to be implemented by subclasses of {@link Node} to receive a notification when the | |
175 * node is rewritten. This method is invoked before the actual replace has happened. | |
176 * | |
177 * @param newNode the replacement node | |
178 * @param reason the reason the replace supplied | |
179 */ | |
180 protected void onReplace(Node newNode, String reason) { | |
170 } | 181 } |
171 | 182 |
172 /** | 183 /** |
173 * Invokes the {@link NodeVisitor#visit(Node)} method for this node and recursively also for all | 184 * Invokes the {@link NodeVisitor#visit(Node)} method for this node and recursively also for all |
174 * child nodes. | 185 * child nodes. |