# HG changeset patch # User Christian Humer # Date 1408815093 -7200 # Node ID b879421229db7b2cef5e8336e11bdaaa8001df8f # Parent f8998c828bed9d6c5199adddc600d37e35310557 SL: better toString for SL nodes. diff -r f8998c828bed -r b879421229db graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLStatementNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLStatementNode.java Sat Aug 23 19:31:29 2014 +0200 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLStatementNode.java Sat Aug 23 19:31:33 2014 +0200 @@ -52,6 +52,39 @@ } @Override + public String toString() { + return formatSourceSection(this); + } + + /** + * Formats a source section of a node in human readable form. If no source section could be + * found it looks up the parent hierarchy until it finds a source section. Nodes where this was + * required append a '~' at the end. + * + * @param node the node to format. + * @return a formatted source section string + */ + private static String formatSourceSection(Node node) { + if (node == null) { + return ""; + } + SourceSection section = node.getSourceSection(); + boolean estimated = false; + if (section == null) { + section = node.getEncapsulatingSourceSection(); + estimated = true; + } + + if (section == null || section.getSource() == null) { + return ""; + } else { + String sourceName = new File(section.getSource().getName()).getName(); + int startLine = section.getStartLine(); + return String.format("%s:%d%s", sourceName, startLine, estimated ? "~" : ""); + } + } + + @Override public Probe probe(ExecutionContext context) { Node parent = getParent();