comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLStatementNode.java @ 16913:b879421229db

SL: better toString for SL nodes.
author Christian Humer <christian.humer@gmail.com>
date Sat, 23 Aug 2014 19:31:33 +0200
parents 7661cc464239
children 826c172a048f
comparison
equal deleted inserted replaced
16912:f8998c828bed 16913:b879421229db
50 public SLStatementNode getNonWrapperNode() { 50 public SLStatementNode getNonWrapperNode() {
51 return this; 51 return this;
52 } 52 }
53 53
54 @Override 54 @Override
55 public String toString() {
56 return formatSourceSection(this);
57 }
58
59 /**
60 * Formats a source section of a node in human readable form. If no source section could be
61 * found it looks up the parent hierarchy until it finds a source section. Nodes where this was
62 * required append a <code>'~'</code> at the end.
63 *
64 * @param node the node to format.
65 * @return a formatted source section string
66 */
67 private static String formatSourceSection(Node node) {
68 if (node == null) {
69 return "<unknown>";
70 }
71 SourceSection section = node.getSourceSection();
72 boolean estimated = false;
73 if (section == null) {
74 section = node.getEncapsulatingSourceSection();
75 estimated = true;
76 }
77
78 if (section == null || section.getSource() == null) {
79 return "<unknown source>";
80 } else {
81 String sourceName = new File(section.getSource().getName()).getName();
82 int startLine = section.getStartLine();
83 return String.format("%s:%d%s", sourceName, startLine, estimated ? "~" : "");
84 }
85 }
86
87 @Override
55 public Probe probe(ExecutionContext context) { 88 public Probe probe(ExecutionContext context) {
56 Node parent = getParent(); 89 Node parent = getParent();
57 90
58 if (parent == null) 91 if (parent == null)
59 throw new IllegalStateException("Cannot probe a node without a parent"); 92 throw new IllegalStateException("Cannot probe a node without a parent");