comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java @ 10481:29e9a5d18c70

Clean up.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sun, 23 Jun 2013 20:50:18 +0200
parents ba02d19dd3cc
children 6eb8d63cea34
comparison
equal deleted inserted replaced
10480:aa685bff0926 10481:29e9a5d18c70
55 @Retention(RetentionPolicy.RUNTIME) 55 @Retention(RetentionPolicy.RUNTIME)
56 @Target({ElementType.FIELD}) 56 @Target({ElementType.FIELD})
57 public @interface Child { 57 public @interface Child {
58 } 58 }
59 59
60 protected Node() {
61 CompilerAsserts.neverPartOfCompilation();
62 }
63
60 /** 64 /**
61 * Assigns a link to a guest language source section to this node. 65 * Assigns a link to a guest language source section to this node.
62 * 66 *
63 * @param section the object representing a section in guest language source code 67 * @param section the object representing a section in guest language source code
64 */ 68 */
80 * Retrieves the guest language source code section that is currently assigned to this node. 84 * Retrieves the guest language source code section that is currently assigned to this node.
81 * 85 *
82 * @return the assigned source code section 86 * @return the assigned source code section
83 */ 87 */
84 public final SourceSection getSourceSection() { 88 public final SourceSection getSourceSection() {
89 return sourceSection;
90 }
91
92 /**
93 * Retrieves the guest language source code section that is currently assigned to this node.
94 *
95 * @return the assigned source code section
96 */
97 public final SourceSection getEncapsulatingSourceSection() {
98 if (sourceSection == null && getParent() != null) {
99 return getParent().getEncapsulatingSourceSection();
100 }
85 return sourceSection; 101 return sourceSection;
86 } 102 }
87 103
88 /** 104 /**
89 * Method that updates the link to the parent in the array of specified new child nodes to this 105 * Method that updates the link to the parent in the array of specified new child nodes to this
107 * @param newChild the new child whose parent should be updated 123 * @param newChild the new child whose parent should be updated
108 * @return the new child 124 * @return the new child
109 */ 125 */
110 protected final <T extends Node> T adoptChild(T newChild) { 126 protected final <T extends Node> T adoptChild(T newChild) {
111 if (newChild != null) { 127 if (newChild != null) {
128 if (newChild == this) {
129 throw new IllegalStateException("The parent of a node can never be the node itself.");
130 }
112 ((Node) newChild).parent = this; 131 ((Node) newChild).parent = this;
113 } 132 }
114 return newChild; 133 return newChild;
115 } 134 }
116 135
142 * @param reason a description of the reason for the replacement 161 * @param reason a description of the reason for the replacement
143 * @return the new node 162 * @return the new node
144 */ 163 */
145 @SuppressWarnings({"unchecked"}) 164 @SuppressWarnings({"unchecked"})
146 public final <T extends Node> T replace(T newNode, String reason) { 165 public final <T extends Node> T replace(T newNode, String reason) {
147 assert this.getParent() != null; 166 if (this.getParent() == null) {
167 throw new IllegalStateException("This node cannot be replaced, because it does not yet have a parent.");
168 }
148 if (sourceSection != null) { 169 if (sourceSection != null) {
149 // Pass on the source section to the new node. 170 // Pass on the source section to the new node.
150 newNode.assignSourceSection(sourceSection); 171 newNode.assignSourceSection(sourceSection);
151 } 172 }
152 onReplace(newNode, reason); 173 onReplace(newNode, reason);