comparison truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLASTPrinter.java @ 21951:9c8c0937da41

Moving all sources into truffle subdirectory
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 17 Jun 2015 10:58:08 +0200
parents graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLASTPrinter.java@8dc73c226c63
children c07e64ecb528
comparison
equal deleted inserted replaced
21950:2a5011c7e641 21951:9c8c0937da41
1 /*
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.oracle.truffle.sl.nodes.instrument;
24
25 import java.io.*;
26 import java.util.*;
27
28 import com.oracle.truffle.api.instrument.*;
29 import com.oracle.truffle.api.instrument.impl.*;
30 import com.oracle.truffle.api.nodes.*;
31 import com.oracle.truffle.api.nodes.NodeFieldAccessor.NodeFieldKind;
32
33 /**
34 * SLASTPrinter is used to print for SL's internal Truffle AST. This is used by
35 * {@link SLDefaultVisualizer} to provide a means of displaying the internal Truffle AST
36 */
37 public final class SLASTPrinter extends DefaultASTPrinter {
38
39 public SLASTPrinter() {
40 }
41
42 @Override
43 protected void printTree(PrintWriter p, Node node, int maxDepth, Node markNode, int level) {
44 if (node == null) {
45 p.print("null");
46 return;
47 }
48
49 p.print(nodeName(node));
50
51 p.print("(");
52
53 if (node instanceof InstrumentationNode) {
54 p.print(instrumentInfo((InstrumentationNode) node));
55 }
56
57 p.print(sourceInfo(node));
58
59 p.print(NodeUtil.printSyntaxTags(node));
60
61 ArrayList<NodeFieldAccessor> childFields = new ArrayList<>();
62
63 for (NodeFieldAccessor field : NodeClass.get(node.getClass()).getFields()) {
64 if (field.getKind() == NodeFieldKind.CHILD || field.getKind() == NodeFieldKind.CHILDREN) {
65 childFields.add(field);
66 } else if (field.getKind() == NodeFieldKind.DATA) {
67 // p.print(sep);
68 // sep = ", ";
69 //
70 // final String fieldName = field.getName();
71 // switch (fieldName) {
72 //
73 // }
74 // p.print(fieldName);
75 // p.print(" = ");
76 // p.print(field.loadValue(node));
77 }
78 }
79 p.print(")");
80
81 if (level <= maxDepth) {
82
83 if (childFields.size() != 0) {
84 p.print(" {");
85 for (NodeFieldAccessor field : childFields) {
86
87 Object value = field.loadValue(node);
88 if (value == null) {
89 printNewLine(p, level);
90 p.print(field.getName());
91 p.print(" = null ");
92 } else if (field.getKind() == NodeFieldKind.CHILD) {
93 printChild(p, maxDepth, markNode, level, field, value);
94 } else if (field.getKind() == NodeFieldKind.CHILDREN) {
95 printChildren(p, maxDepth, markNode, level, field, value);
96 } else {
97 printNewLine(p, level);
98 p.print(field.getName());
99 }
100 }
101 printNewLine(p, level - 1);
102 p.print("}");
103 }
104 }
105 }
106
107 }