diff 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
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java	Tue May 21 19:22:29 2013 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java	Tue May 21 19:43:53 2013 +0200
@@ -149,6 +149,7 @@
             // Pass on the source section to the new node.
             newNode.assignSourceSection(sourceSection);
         }
+        onReplace(newNode, reason);
         return (T) this.getParent().replaceChild(this, newNode);
     }
 
@@ -170,6 +171,16 @@
     }
 
     /**
+     * Intended to be implemented by subclasses of {@link Node} to receive a notification when the
+     * node is rewritten. This method is invoked before the actual replace has happened.
+     * 
+     * @param newNode the replacement node
+     * @param reason the reason the replace supplied
+     */
+    protected void onReplace(Node newNode, String reason) {
+    }
+
+    /**
      * Invokes the {@link NodeVisitor#visit(Node)} method for this node and recursively also for all
      * child nodes.
      *