Mercurial > hg > truffle
diff graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java @ 9254:4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 23 Apr 2013 14:59:24 +0200 |
parents | 5e3d1a68664e |
children | cdf10fb20022 |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Tue Apr 23 11:29:55 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Tue Apr 23 14:59:24 2013 +0200 @@ -25,6 +25,8 @@ import java.lang.annotation.*; import java.util.*; +import com.oracle.truffle.api.*; + /** * Abstract base class for all Truffle nodes. */ @@ -37,6 +39,8 @@ private Node parent; + private SourceSection sourceSection; + /** * Marks array fields that are children of this node. */ @@ -54,6 +58,34 @@ } /** + * Assigns a link to a guest language source section to this node. + * + * @param section the object representing a section in guest language source code + */ + public final void assignSourceSection(SourceSection section) { + if (sourceSection != null) { + throw new IllegalStateException("Source section is already assigned."); + } + this.sourceSection = section; + } + + /** + * Clears any previously assigned guest language source code from this node. + */ + public final void clearSourceSection() { + this.sourceSection = null; + } + + /** + * Retrieves the guest language source code section that is currently assigned to this node. + * + * @return the assigned source code section + */ + public final SourceSection getSourceSection() { + return sourceSection; + } + + /** * Method that updates the link to the parent in the array of specified new child nodes to this * node. * @@ -123,7 +155,7 @@ * @return the new node */ @SuppressWarnings({"unchecked"}) - public <T extends Node> T replace(T newNode, String reason) { + public final <T extends Node> T replace(T newNode, String reason) { assert this.getParent() != null; return (T) this.getParent().replaceChild(this, newNode); } @@ -134,7 +166,7 @@ * @param newNode the new node that is the replacement * @return the new node */ - public <T extends Node> T replace(T newNode) { + public final <T extends Node> T replace(T newNode) { return replace(newNode, ""); }