Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java @ 11648:4ab1f371adc8
Do not assign new source section if replacing node already has source section assigned.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sun, 15 Sep 2013 16:31:32 +0200 |
parents | 5f532ea846fb |
children | 793743715dc1 |
comparison
equal
deleted
inserted
replaced
11647:a21a54b7ead1 | 11648:4ab1f371adc8 |
---|---|
73 if (sourceSection != null) { | 73 if (sourceSection != null) { |
74 // Patch this test during the transition to constructor-based | 74 // Patch this test during the transition to constructor-based |
75 // source attribution, which would otherwise trigger this | 75 // source attribution, which would otherwise trigger this |
76 // exception. This method will eventually be deprecated. | 76 // exception. This method will eventually be deprecated. |
77 if (getSourceSection() != section) { | 77 if (getSourceSection() != section) { |
78 throw new IllegalStateException("Source section is already assigned."); | 78 throw new IllegalStateException("Source section is already assigned. Old: " + getSourceSection() + ", new: " + section); |
79 } | 79 } |
80 } | 80 } |
81 this.sourceSection = section; | 81 this.sourceSection = section; |
82 } | 82 } |
83 | 83 |
172 @SuppressWarnings({"unchecked"}) | 172 @SuppressWarnings({"unchecked"}) |
173 public final <T extends Node> T replace(T newNode, String reason) { | 173 public final <T extends Node> T replace(T newNode, String reason) { |
174 if (this.getParent() == null) { | 174 if (this.getParent() == null) { |
175 throw new IllegalStateException("This node cannot be replaced, because it does not yet have a parent."); | 175 throw new IllegalStateException("This node cannot be replaced, because it does not yet have a parent."); |
176 } | 176 } |
177 if (sourceSection != null) { | 177 if (sourceSection != null && newNode.getSourceSection() == null) { |
178 // Pass on the source section to the new node. | 178 // Pass on the source section to the new node. |
179 newNode.assignSourceSection(sourceSection); | 179 newNode.assignSourceSection(sourceSection); |
180 } | 180 } |
181 onReplace(newNode, reason); | 181 onReplace(newNode, reason); |
182 return (T) this.getParent().replaceChild(this, newNode); | 182 return (T) this.getParent().replaceChild(this, newNode); |