Skip to content
Snippets Groups Projects
Commit 90354bb8 authored by Lukas Stadler's avatar Lukas Stadler
Browse files

Merge pull request #562 in G/fastr from ~LUKAS.STADLER_ORACLE.COM/fastr:feature/dump to master

* commit '2283c3f2':
  more concise FastRSyntaxTree
  more resilient Utils.dumpFrame
parents 03f5e547 2283c3f2
No related branches found
No related tags found
No related merge requests found
......@@ -62,7 +62,7 @@ import com.oracle.truffle.r.runtime.nodes.RSyntaxVisitor;
* Only nodes that return {@code true} to {@link RSyntaxNode#isSyntax()} are processed. N.B. This
* will reach nodes that implement {@link RSyntaxNode} but are used in {@link RSyntaxNode#INTERNAL}
* mode</li>
* <li><b<syntaxelement</b>: Use the {@link RSyntaxVisitor} to visit the "logical" syntax tree.</li>
* <li><b>syntaxelement</b>: Use the {@link RSyntaxVisitor} to visit the "logical" syntax tree.</li>
* </ol>
*
*/
......@@ -71,7 +71,7 @@ public abstract class FastRSyntaxTree extends RBuiltinNode {
@Override
public Object[] getDefaultParameterValues() {
return new Object[]{RMissing.instance, "rsyntaxnode", RRuntime.LOGICAL_FALSE, RRuntime.LOGICAL_FALSE};
return new Object[]{RMissing.instance, "syntaxelement", RRuntime.LOGICAL_FALSE, RRuntime.LOGICAL_FALSE};
}
@Override
......@@ -110,12 +110,18 @@ public abstract class FastRSyntaxTree extends RBuiltinNode {
@Override
protected Void visit(RSyntaxCall element) {
printIndent(depth);
writeString(element.getClass().getSimpleName(), false);
RSyntaxElement lhs = element.getSyntaxLHS();
if (lhs instanceof RSyntaxLookup) {
writeString(element.getClass().getSimpleName() + " " + ((RSyntaxLookup) lhs).getIdentifier(), false);
} else {
writeString(element.getClass().getSimpleName(), false);
}
processSourceSection(element.getSourceSection(), printSource);
printnl();
RSyntaxElement lhs = element.getSyntaxLHS();
RSyntaxElement[] arguments = element.getSyntaxArguments();
accept(lhs);
if (!(lhs instanceof RSyntaxLookup)) {
accept(lhs);
}
for (RSyntaxElement arg : arguments) {
depth++;
accept(arg);
......
......@@ -550,48 +550,58 @@ public final class Utils {
}
private static void dumpFrame(StringBuilder str, CallTarget callTarget, Frame frame, boolean printFrameSlots, boolean isVirtual) {
if (str.length() > 0) {
str.append("\n");
}
Frame unwrapped = RArguments.unwrap(frame);
if (!RArguments.isRFrame(unwrapped)) {
if (unwrapped.getArguments().length == 0) {
str.append("<empty frame>");
} else {
str.append("<unknown frame>");
}
} else {
if (callTarget.toString().equals("<promise>")) {
/* these have the same depth as the next frame, and add no useful info. */
return;
}
RCaller call = RArguments.getCall(unwrapped);
if (call != null) {
String callSrc = call.isValidCaller() ? RContext.getRRuntimeASTAccess().getCallerSource(call) : "<invalid call>";
int depth = RArguments.getDepth(unwrapped);
str.append("Frame(d=").append(depth).append("): ").append(callTarget).append(isVirtual ? " (virtual)" : "");
str.append(" (called as: ").append(callSrc).append(')');
try {
CompilerAsserts.neverPartOfCompilation();
if (str.length() > 0) {
str.append("\n");
}
if (printFrameSlots) {
FrameDescriptor frameDescriptor = unwrapped.getFrameDescriptor();
for (FrameSlot s : frameDescriptor.getSlots()) {
str.append("\n ").append(s.getIdentifier()).append(" = ");
Object value = unwrapped.getValue(s);
try {
if (value instanceof RAbstractContainer && ((RAbstractContainer) value).getLength() > 32) {
str.append('<').append(value.getClass().getSimpleName()).append(" with ").append(((RAbstractContainer) value).getLength()).append(" elements>");
} else {
String text = String.valueOf(value);
str.append(text.length() < 256 ? text : text.substring(0, 256) + "...");
Frame unwrapped = RArguments.unwrap(frame);
if (!RArguments.isRFrame(unwrapped)) {
if (unwrapped.getArguments().length == 0) {
str.append("<empty frame>");
} else {
str.append("<unknown frame>");
}
} else {
if (callTarget.toString().equals("<promise>")) {
/* these have the same depth as the next frame, and add no useful info. */
return;
}
RCaller call = RArguments.getCall(unwrapped);
if (call != null) {
String callSrc = call.isValidCaller() ? RContext.getRRuntimeASTAccess().getCallerSource(call) : "<invalid call>";
int depth = RArguments.getDepth(unwrapped);
str.append("Frame(d=").append(depth).append("): ").append(callTarget).append(isVirtual ? " (virtual)" : "");
str.append(" (called as: ").append(callSrc).append(')');
}
if (printFrameSlots) {
FrameDescriptor frameDescriptor = unwrapped.getFrameDescriptor();
for (FrameSlot s : frameDescriptor.getSlots()) {
str.append("\n ").append(s.getIdentifier()).append(" = ");
Object value;
try {
value = unwrapped.getValue(s);
} catch (Throwable t) {
str.append("<exception ").append(t.getClass().getSimpleName()).append(" while acquiring slot ").append(s.getIdentifier()).append(">");
continue;
}
try {
if (value instanceof RAbstractContainer && ((RAbstractContainer) value).getLength() > 32) {
str.append('<').append(value.getClass().getSimpleName()).append(" with ").append(((RAbstractContainer) value).getLength()).append(" elements>");
} else {
String text = String.valueOf(value);
str.append(text.length() < 256 ? text : text.substring(0, 256) + "...");
}
} catch (Throwable t) {
// RLanguage values may not react kindly to getLength() calls
str.append("<exception ").append(t.getClass().getSimpleName()).append(" while printing value of type ").append(
value == null ? "null" : value.getClass().getSimpleName()).append('>');
}
} catch (Throwable t) {
// RLanguage values may not react kindly to getLength() calls
str.append("<exception ").append(t.getClass().getSimpleName()).append(" while printing value of type ").append(
value == null ? "null" : value.getClass().getSimpleName()).append(
'>');
}
}
}
} catch (Throwable t) {
str.append("<exception ").append(t.getMessage()).append(" ").append(t.getClass().getSimpleName()).append("<");
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment