Mercurial > hg > graal-jvmci-8
comparison 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 |
comparison
equal
deleted
inserted
replaced
18484:e97e1f07a3d6 | 18485:e3c95cbbb50c |
---|---|
56 | 56 |
57 public String printTreeToString(Node node, int maxDepth) { | 57 public String printTreeToString(Node node, int maxDepth) { |
58 return printTreeToString(node, maxDepth, null); | 58 return printTreeToString(node, maxDepth, null); |
59 } | 59 } |
60 | 60 |
61 private static void printTree(PrintWriter p, Node node, int maxDepth, Node markNode, int level) { | 61 protected void printTree(PrintWriter p, Node node, int maxDepth, Node markNode, int level) { |
62 if (node == null) { | 62 if (node == null) { |
63 p.print("null"); | 63 p.print("null"); |
64 return; | 64 return; |
65 } | 65 } |
66 | 66 |
67 p.print(nodeName(node)); | 67 p.print(nodeName(node)); |
68 | 68 |
69 p.print("("); | 69 p.print("("); |
70 | 70 |
71 final SourceSection src = node.getSourceSection(); | 71 if (node instanceof InstrumentationNode) { |
72 if (src != null) { | 72 p.print(instrumentInfo((InstrumentationNode) node)); |
73 if (!(src instanceof NullSourceSection)) { | |
74 p.print(src.getSource().getName() + ":" + src.getStartLine()); | |
75 } | |
76 } | 73 } |
77 if (node instanceof SyntaxTagged) { | 74 |
78 printSyntaxTagged(p, (SyntaxTagged) node); | 75 p.print(sourceInfo(node)); |
79 } | 76 |
77 p.print(NodeUtil.printSyntaxTags(node)); | |
80 | 78 |
81 ArrayList<NodeField> childFields = new ArrayList<>(); | 79 ArrayList<NodeField> childFields = new ArrayList<>(); |
82 | 80 |
83 for (NodeField field : NodeClass.get(node.getClass()).getFields()) { | 81 for (NodeField field : NodeClass.get(node.getClass()).getFields()) { |
84 if (field.getKind() == NodeFieldKind.CHILD || field.getKind() == NodeFieldKind.CHILDREN) { | 82 if (field.getKind() == NodeFieldKind.CHILD || field.getKind() == NodeFieldKind.CHILDREN) { |
122 p.print("}"); | 120 p.print("}"); |
123 } | 121 } |
124 } | 122 } |
125 } | 123 } |
126 | 124 |
127 private static void printSyntaxTagged(PrintWriter p, final SyntaxTagged taggedNode) { | 125 protected void printChildren(PrintWriter p, int maxDepth, Node markNode, int level, NodeField field, Object value) { |
128 p.print("["); | |
129 String prefix = ""; | |
130 for (SyntaxTag tag : taggedNode.getSyntaxTags()) { | |
131 p.print(prefix); | |
132 prefix = ","; | |
133 p.print(tag.toString()); | |
134 } | |
135 p.print("]"); | |
136 } | |
137 | |
138 private static void printChildren(PrintWriter p, int maxDepth, Node markNode, int level, NodeField field, Object value) { | |
139 printNewLine(p, level); | 126 printNewLine(p, level); |
140 p.print(field.getName()); | 127 p.print(field.getName()); |
141 Node[] children = (Node[]) value; | 128 Node[] children = (Node[]) value; |
142 p.print(" = ["); | 129 p.print(" = ["); |
143 String sep = ""; | 130 String sep = ""; |
147 printTree(p, child, maxDepth, markNode, level + 1); | 134 printTree(p, child, maxDepth, markNode, level + 1); |
148 } | 135 } |
149 p.print("]"); | 136 p.print("]"); |
150 } | 137 } |
151 | 138 |
152 private static void printChild(PrintWriter p, int maxDepth, Node markNode, int level, NodeField field, Object value) { | 139 protected void printChild(PrintWriter p, int maxDepth, Node markNode, int level, NodeField field, Object value) { |
153 final Node valueNode = (Node) value; | 140 final Node valueNode = (Node) value; |
154 printNewLine(p, level, valueNode == markNode); | 141 printNewLine(p, level, valueNode == markNode); |
155 p.print(field.getName()); | 142 p.print(field.getName()); |
156 p.print(" = "); | 143 p.print(" = "); |
157 printTree(p, valueNode, maxDepth, markNode, level + 1); | 144 printTree(p, valueNode, maxDepth, markNode, level + 1); |
158 } | 145 } |
159 | 146 |
160 private static void printNewLine(PrintWriter p, int level, boolean mark) { | 147 protected static void printNewLine(PrintWriter p, int level, boolean mark) { |
161 p.println(); | 148 p.println(); |
162 for (int i = 0; i < level; i++) { | 149 for (int i = 0; i < level; i++) { |
163 if (mark && i == 0) { | 150 if (mark && i == 0) { |
164 p.print(" -->"); | 151 p.print(" -->"); |
165 } else { | 152 } else { |
166 p.print(" "); | 153 p.print(" "); |
167 } | 154 } |
168 } | 155 } |
169 } | 156 } |
170 | 157 |
171 private static void printNewLine(PrintWriter p, int level) { | 158 protected static void printNewLine(PrintWriter p, int level) { |
172 printNewLine(p, level, false); | 159 printNewLine(p, level, false); |
173 } | 160 } |
174 | 161 |
175 private static String nodeName(Node node) { | 162 protected static String nodeName(Node node) { |
176 return node.getClass().getSimpleName(); | 163 return node.getClass().getSimpleName(); |
177 } | 164 } |
178 | 165 |
166 protected static String sourceInfo(Node node) { | |
167 final SourceSection src = node.getSourceSection(); | |
168 if (src != null) { | |
169 if (src instanceof NullSourceSection) { | |
170 final NullSourceSection nullSection = (NullSourceSection) src; | |
171 return nullSection.getShortDescription(); | |
172 } else { | |
173 return src.getSource().getName() + ":" + src.getStartLine(); | |
174 } | |
175 } | |
176 return ""; | |
177 } | |
178 | |
179 protected static String instrumentInfo(InstrumentationNode node) { | |
180 final String info = node.instrumentationInfo(); | |
181 return info == null ? "" : info; | |
182 } | |
183 | |
179 } | 184 } |