comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java @ 18485:e3c95cbbb50c

Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Sun, 23 Nov 2014 16:07:23 -0800
parents 65a160d9d259
children cb4d5cc2b52b
comparison
equal deleted inserted replaced
18484:e97e1f07a3d6 18485:e3c95cbbb50c
31 import java.util.*; 31 import java.util.*;
32 32
33 import sun.misc.*; 33 import sun.misc.*;
34 34
35 import com.oracle.truffle.api.*; 35 import com.oracle.truffle.api.*;
36 import com.oracle.truffle.api.instrument.*;
37 import com.oracle.truffle.api.instrument.ProbeNode.WrapperNode;
36 import com.oracle.truffle.api.nodes.Node.Child; 38 import com.oracle.truffle.api.nodes.Node.Child;
37 import com.oracle.truffle.api.nodes.Node.Children; 39 import com.oracle.truffle.api.nodes.Node.Children;
38 import com.oracle.truffle.api.source.*; 40 import com.oracle.truffle.api.source.*;
39 41
40 /** 42 /**
767 if (parent != null) { 769 if (parent != null) {
768 sb.append(getNodeFieldName(parent, node, "")); 770 sb.append(getNodeFieldName(parent, node, ""));
769 } 771 }
770 772
771 sb.append(" (" + node.getClass().getSimpleName() + ") "); 773 sb.append(" (" + node.getClass().getSimpleName() + ") ");
774
775 sb.append(printSyntaxTags(node));
776
772 sb.append(displaySourceAttribution(node)); 777 sb.append(displaySourceAttribution(node));
773 p.println(sb.toString()); 778 p.println(sb.toString());
774 779
775 for (Node child : node.getChildren()) { 780 for (Node child : node.getChildren()) {
776 printSourceAttributionTree(p, node, child, level + 1); 781 printSourceAttributionTree(p, node, child, level + 1);
793 index++; 798 index++;
794 } 799 }
795 } 800 }
796 } 801 }
797 return defaultName; 802 return defaultName;
803 }
804
805 /**
806 * Returns a string listing the {@linkplain SyntaxTag syntax tags}, if any, associated with a
807 * node:
808 * <ul>
809 * <li>"[{@linkplain StandardSyntaxTag#STATEMENT STATEMENT},
810 * {@linkplain StandardSyntaxTag#ASSIGNMENT ASSIGNMENT}]" if tags have been applied;</li>
811 * <li>"[]" if the node supports tags, but none are present; and</li>
812 * <li>"" if the node does not support tags.</li>
813 * </ul>
814 */
815 public static String printSyntaxTags(final Object node) {
816 if (node instanceof WrapperNode) {
817 final Probe probe = ((WrapperNode) node).getProbe();
818 final Collection<SyntaxTag> syntaxTags = probe.getSyntaxTags();
819 final StringBuilder sb = new StringBuilder();
820 String prefix = "";
821 sb.append("[");
822 for (SyntaxTag tag : syntaxTags) {
823 sb.append(prefix);
824 prefix = ",";
825 sb.append(tag.toString());
826 }
827 sb.append("]");
828 return sb.toString();
829 }
830 return "";
798 } 831 }
799 832
800 /** 833 /**
801 * Prints a human readable form of a {@link Node} AST to the given {@link PrintStream}. This 834 * Prints a human readable form of a {@link Node} AST to the given {@link PrintStream}. This
802 * print method does not check for cycles in the node structure. 835 * print method does not check for cycles in the node structure.