comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java @ 16151:76895499bc88

Add facility to create JSON dump of AST creation/rewriting
author Christian Wirth <christian.wirth@oracle.com>
date Fri, 20 Jun 2014 15:13:16 +0200
parents 915ebb306fcc
children 76081918079d
comparison
equal deleted inserted replaced
16150:f98b033b6050 16151:76895499bc88
29 import java.util.*; 29 import java.util.*;
30 import java.util.concurrent.*; 30 import java.util.concurrent.*;
31 31
32 import com.oracle.truffle.api.*; 32 import com.oracle.truffle.api.*;
33 import com.oracle.truffle.api.source.*; 33 import com.oracle.truffle.api.source.*;
34 import com.oracle.truffle.api.utilities.*;
34 35
35 /** 36 /**
36 * Abstract base class for all Truffle nodes. 37 * Abstract base class for all Truffle nodes.
37 */ 38 */
38 public abstract class Node implements Cloneable { 39 public abstract class Node implements Cloneable {
56 @Target({ElementType.FIELD}) 57 @Target({ElementType.FIELD})
57 public @interface Child { 58 public @interface Child {
58 } 59 }
59 60
60 protected Node() { 61 protected Node() {
61 CompilerAsserts.neverPartOfCompilation(); 62 this(null);
62 } 63 }
63 64
64 protected Node(SourceSection sourceSection) { 65 protected Node(SourceSection sourceSection) {
65 CompilerAsserts.neverPartOfCompilation(); 66 CompilerAsserts.neverPartOfCompilation();
66 this.sourceSection = sourceSection; 67 this.sourceSection = sourceSection;
68 if (TruffleOptions.TraceASTJSON) {
69 JSONHelper.dumpNewNode(this);
70 }
67 } 71 }
68 72
69 /** 73 /**
70 * Assigns a link to a guest language source section to this node. 74 * Assigns a link to a guest language source section to this node.
71 * 75 *
167 if (newChild == this) { 171 if (newChild == this) {
168 throw new IllegalStateException("The parent of a node can never be the node itself."); 172 throw new IllegalStateException("The parent of a node can never be the node itself.");
169 } 173 }
170 boolean isInserted = newChild.parent == null; 174 boolean isInserted = newChild.parent == null;
171 newChild.parent = this; 175 newChild.parent = this;
176 if (TruffleOptions.TraceASTJSON) {
177 JSONHelper.dumpNewChild(this, newChild);
178 }
172 newChild.adoptHelper(); 179 newChild.adoptHelper();
173 if (isInserted) { 180 if (isInserted) {
174 newChild.onAdopt(); 181 newChild.onAdopt();
175 } 182 }
176 } 183 }
271 this.parent.adoptHelper(newNode); 278 this.parent.adoptHelper(newNode);
272 } else { 279 } else {
273 this.parent.adoptUnadoptedHelper(newNode); 280 this.parent.adoptUnadoptedHelper(newNode);
274 } 281 }
275 reportReplace(this, newNode, reason); 282 reportReplace(this, newNode, reason);
283 if (TruffleOptions.TraceASTJSON) {
284 JSONHelper.dumpReplaceChild(this, newNode, reason);
285 }
276 onReplace(newNode, reason); 286 onReplace(newNode, reason);
277 } 287 }
278 288
279 /** 289 /**
280 * Checks if this node is properly adopted by a parent and can be replaced. 290 * Checks if this node is properly adopted by a parent and can be replaced.