diff graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/impl/DefaultASTPrinter.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 36bc37806c61
children 5b7db8941fd7
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/impl/DefaultASTPrinter.java	Fri Nov 21 13:16:02 2014 +0100
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/impl/DefaultASTPrinter.java	Sun Nov 23 16:07:23 2014 -0800
@@ -58,7 +58,7 @@
         return printTreeToString(node, maxDepth, null);
     }
 
-    private static void printTree(PrintWriter p, Node node, int maxDepth, Node markNode, int level) {
+    protected void printTree(PrintWriter p, Node node, int maxDepth, Node markNode, int level) {
         if (node == null) {
             p.print("null");
             return;
@@ -68,15 +68,13 @@
 
         p.print("(");
 
-        final SourceSection src = node.getSourceSection();
-        if (src != null) {
-            if (!(src instanceof NullSourceSection)) {
-                p.print(src.getSource().getName() + ":" + src.getStartLine());
-            }
+        if (node instanceof InstrumentationNode) {
+            p.print(instrumentInfo((InstrumentationNode) node));
         }
-        if (node instanceof SyntaxTagged) {
-            printSyntaxTagged(p, (SyntaxTagged) node);
-        }
+
+        p.print(sourceInfo(node));
+
+        p.print(NodeUtil.printSyntaxTags(node));
 
         ArrayList<NodeField> childFields = new ArrayList<>();
 
@@ -124,18 +122,7 @@
         }
     }
 
-    private static void printSyntaxTagged(PrintWriter p, final SyntaxTagged taggedNode) {
-        p.print("[");
-        String prefix = "";
-        for (SyntaxTag tag : taggedNode.getSyntaxTags()) {
-            p.print(prefix);
-            prefix = ",";
-            p.print(tag.toString());
-        }
-        p.print("]");
-    }
-
-    private static void printChildren(PrintWriter p, int maxDepth, Node markNode, int level, NodeField field, Object value) {
+    protected void printChildren(PrintWriter p, int maxDepth, Node markNode, int level, NodeField field, Object value) {
         printNewLine(p, level);
         p.print(field.getName());
         Node[] children = (Node[]) value;
@@ -149,7 +136,7 @@
         p.print("]");
     }
 
-    private static void printChild(PrintWriter p, int maxDepth, Node markNode, int level, NodeField field, Object value) {
+    protected void printChild(PrintWriter p, int maxDepth, Node markNode, int level, NodeField field, Object value) {
         final Node valueNode = (Node) value;
         printNewLine(p, level, valueNode == markNode);
         p.print(field.getName());
@@ -157,7 +144,7 @@
         printTree(p, valueNode, maxDepth, markNode, level + 1);
     }
 
-    private static void printNewLine(PrintWriter p, int level, boolean mark) {
+    protected static void printNewLine(PrintWriter p, int level, boolean mark) {
         p.println();
         for (int i = 0; i < level; i++) {
             if (mark && i == 0) {
@@ -168,12 +155,30 @@
         }
     }
 
-    private static void printNewLine(PrintWriter p, int level) {
+    protected static void printNewLine(PrintWriter p, int level) {
         printNewLine(p, level, false);
     }
 
-    private static String nodeName(Node node) {
+    protected static String nodeName(Node node) {
         return node.getClass().getSimpleName();
     }
 
+    protected static String sourceInfo(Node node) {
+        final SourceSection src = node.getSourceSection();
+        if (src != null) {
+            if (src instanceof NullSourceSection) {
+                final NullSourceSection nullSection = (NullSourceSection) src;
+                return nullSection.getShortDescription();
+            } else {
+                return src.getSource().getName() + ":" + src.getStartLine();
+            }
+        }
+        return "";
+    }
+
+    protected static String instrumentInfo(InstrumentationNode node) {
+        final String info = node.instrumentationInfo();
+        return info == null ? "" : info;
+    }
+
 }