diff 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
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java	Tue Apr 23 15:02:16 2013 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java	Tue Apr 23 15:07:47 2013 +0200
@@ -135,7 +135,8 @@
     }
 
     /**
-     * Replaces this node with another node.
+     * Replaces this node with another node. If there is a source section (see
+     * {@link #getSourceSection()}) associated with this node, it is transferred to the new node.
      * 
      * @param newNode the new node that is the replacement
      * @param reason a description of the reason for the replacement
@@ -144,6 +145,10 @@
     @SuppressWarnings({"unchecked"})
     public final <T extends Node> T replace(T newNode, String reason) {
         assert this.getParent() != null;
+        if (sourceSection != null) {
+            // Pass on the source section to the new node.
+            newNode.assignSourceSection(sourceSection);
+        }
         return (T) this.getParent().replaceChild(this, newNode);
     }
 
@@ -154,7 +159,8 @@
     }
 
     /**
-     * Replaces this node with another node.
+     * Replaces this node with another node. If there is a source section (see
+     * {@link #getSourceSection()}) associated with this node, it is transferred to the new node.
      * 
      * @param newNode the new node that is the replacement
      * @return the new node